Skip to content

Practical patterns, starters & CLI tools for loop engineering with AI coding agents. Design systems that prompt and orchestrate agents (inspired by Addy Osmani and Boris Cherny). Includes loop-audit, loop-init, loop-cost.

fix(loop-cost): reject zero cadence intervals (#526)

s4kuradd2ac8afb498
diff --git a/tools/loop-cost/dist/estimator.js b/tools/loop-cost/dist/estimator.js
index 8e83acf..9014665 100644
--- a/tools/loop-cost/dist/estimator.js
+++ b/tools/loop-cost/dist/estimator.js
@@ -47,7 +47,11 @@ export function parseInterval(token) {
if (!m)
throw new Error(`Invalid cadence interval: ${token}`);
const unit = m[2];
- return Number(m[1]) * INTERVAL_MS[unit];
+ const value = Number(m[1]);
+ if (value <= 0) {
+ throw new Error(`Invalid cadence interval: ${token}. The interval value must be greater than zero.`);
+ }
+ return value * INTERVAL_MS[unit];
}
/** Runs per day for a single interval like 15m or 1d. */
export function runsPerDayForInterval(interval) {
diff --git a/tools/loop-cost/src/estimator.ts b/tools/loop-cost/src/estimator.ts
index a7fd91a..8341584 100644
--- a/tools/loop-cost/src/estimator.ts
+++ b/tools/loop-cost/src/estimator.ts
@@ -113,7 +113,11 @@ export function parseInterval(token: string): number {
const m = token.match(/^(\d+)([mhd])$/);
if (!m) throw new Error(`Invalid cadence interval: ${token}`);
const unit = m[2] as keyof typeof INTERVAL_MS;
- return Number(m[1]) * INTERVAL_MS[unit];
+ const value = Number(m[1]);
+ if (value <= 0) {
+ throw new Error(`Invalid cadence interval: ${token}. The interval value must be greater than zero.`);
+ }
+ return value * INTERVAL_MS[unit];
}
/** Runs per day for a single interval like 15m or 1d. */
diff --git a/tools/loop-cost/test/estimator.test.mjs b/tools/loop-cost/test/estimator.test.mjs
index cd65a86..992839c 100644
--- a/tools/loop-cost/test/estimator.test.mjs
+++ b/tools/loop-cost/test/estimator.test.mjs
@@ -30,6 +30,10 @@ test('runsPerDayForInterval: 1d = 1', () => {
assert.equal(runsPerDayForInterval('1d'), 1);
});
+test('runsPerDayForInterval rejects a zero cadence', () => {
+ assert.throws(() => runsPerDayForInterval('0m'), /greater than zero/);
+});
+
test('cadenceToRunsPerDay: range uses fastest by default', () => {
assert.equal(cadenceToRunsPerDay('5m-15m'), 288);
});