Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
feat(core): format stats durations [R1,R2,N19]
Corey Olson0bbcdb6c943c
diff --git a/src/stats-flow.js b/src/stats-flow.jsindex 9509dab7..cf3e336d 100644--- a/src/stats-flow.js+++ b/src/stats-flow.js@@ -136,8 +136,10 @@ function recommendation(stage, { activeAgents, queues, openByLane, accepted, couconst lane = [...openByLane].sort(([a, first], [b, second]) => second - first || a.localeCompare(b))[0]?.[0];return lane ? `add a builder in ${lane}` : 'add a builder when open work is available';}- if (stage === 'review') return `reviews are slow (median ${stages.review.medianMinutes ?? 'unmeasured'} min): check how long the frozen checks take`;- return accepted.length ? `land the accepted items: ${accepted.map(id => `#${id}`).join(', ')}` : 'land the accepted items (none waiting)';+ if (stage === 'review') return `reviews are slow (median ${duration(stages.review.medianMinutes)}): check how long the frozen checks take`;+ const named = accepted.slice(0, 3).map(id => `#${id}`).join(', ');+ const more = accepted.length > 3 ? ` +${accepted.length - 3} more` : '';+ return accepted.length ? `land the accepted items: ${named}${more}` : 'land the accepted items (none waiting)';}/** Derive flow from the same immutable history used for counts, with an injectable observation time for fixtures. */@@ -206,23 +208,33 @@ export function flowStats(history, boundary, now, counts) {submitsPerMerged: completedItems ? counts.submissions / completedItems : 0, activeAgents, bottleneck };}-/** Format measured minutes for people while JSON retains the original numeric precision. */-function minutes(value) { return value === null ? 'unmeasured' : String(Number(value.toFixed(2))); }+/** Format elapsed minutes in rounded human units while JSON retains its original numeric precision. */+function duration(value) {+ if (value === null) return 'unmeasured';+ const rounded = Math.round(value);+ if (rounded < 60) return `${rounded} min`;+ if (rounded < 24 * 60) return `${Math.floor(rounded / 60)} h ${rounded % 60} min`;+ const hours = Math.floor(rounded / 60);+ return `${Math.floor(hours / 24)} d ${hours % 24} h`;+}++/** Keep dimensionless counts and percentages compact without changing JSON values. */+function number(value) { return value === null ? 'unmeasured' : String(Number(value.toFixed(2))); }/** Render all flow dimensions and the evidence behind the single recommended action. */export function flowLines(flow) {const lines = STAGES.map(stage => {const row = flow.stages[stage];- return `${LABELS[stage]}: average ${minutes(row.averageMinutes)} min · median ${minutes(row.medianMinutes)} min · ${row.count} measured; ${row.unmeasuredCompleted} of ${flow.bottleneck.completedItems} completed items unmeasured`;+ return `${LABELS[stage]}: average ${duration(row.averageMinutes)} · median ${duration(row.medianMinutes)} · ${row.count} measured; ${row.unmeasuredCompleted} of ${flow.bottleneck.completedItems} completed items unmeasured`;});for (const [state, queue] of Object.entries(flow.queues)) {- lines.push(`${state} queue: ${queue.size} · oldest ${queue.oldest ? `#${queue.oldest.id} (${minutes(queue.oldest.ageMinutes)} min)` : 'none'}`);+ lines.push(`${state} queue: ${queue.size} · oldest ${queue.oldest ? `#${queue.oldest.id} (${duration(queue.oldest.ageMinutes)})` : 'none'}`);}lines.push(`per day: ${flow.daily.map(row => `${row.date}: ${row.added} added, ${row.merged} merged`).join('; ') || 'none'}`);- lines.push(`${minutes(flow.submitsPerMerged)} submissions per merged item`);+ lines.push(`${number(flow.submitsPerMerged)} submissions per merged item`);lines.push(`active in the last hour: ${flow.activeAgents.total} agents · roles ${Object.entries(flow.activeAgents.roles).map(([role, count]) => `${role} ${count}`).join(', ')} · lanes ${Object.entries(flow.activeAgents.lanes).map(([lane, count]) => `${lane} ${count}`).join(', ') || 'none'}`);const bottleneck = flow.bottleneck;- lines.push(`bottleneck: ${bottleneck.message}${bottleneck.share === null ? '' : ` (${minutes(bottleneck.share * 100)}%)`}${bottleneck.lowConfidence ? ' · low confidence' : ''}`);+ lines.push(`bottleneck: ${bottleneck.message}${bottleneck.share === null ? '' : ` (${number(bottleneck.share * 100)}%)`}${bottleneck.lowConfidence ? ' · low confidence' : ''}`);if (bottleneck.recommendation) lines.push(`next: ${bottleneck.recommendation}`);return lines;}@@ -232,11 +244,11 @@ export function flowAlertLine(flow) {const average = flow.stages.reviewWait.averageMinutes;const oldest = flow.unreviewed.oldest;const thresholds = [];- if (average > 60) thresholds.push(`review wait average ${minutes(average)} min (${flow.stages.reviewWait.count} measured; > 60 min)`);- if (oldest?.ageMinutes > 180) thresholds.push(`unreviewed #${oldest.id} waiting ${minutes(oldest.ageMinutes)} min (> 180 min)`);+ if (average > 60) thresholds.push(`review wait average ${duration(average)} (${flow.stages.reviewWait.count} measured; > 60 min)`);+ if (oldest?.ageMinutes > 180) thresholds.push(`unreviewed #${oldest.id} waiting ${duration(oldest.ageMinutes)} (> 180 min)`);if (!thresholds.length) return null;const bottleneck = flow.bottleneck;const measured = bottleneck.stage === null ? 'bottleneck: not measured yet' :- `bottleneck: ${LABELS[bottleneck.stage]} (${minutes(bottleneck.share * 100)}% of ${minutes(bottleneck.totalCycleMinutes)} measured cycle min); next: ${bottleneck.recommendation}`;+ `bottleneck: ${LABELS[bottleneck.stage]} (${number(bottleneck.share * 100)}% of ${duration(bottleneck.totalCycleMinutes)} measured cycle time); next: ${bottleneck.recommendation}`;return `flow: ${thresholds.join('; ')}; ${measured}`;}diff --git a/test/resume-flow.test.js b/test/resume-flow.test.jsindex 5155b837..958f554b 100644--- a/test/resume-flow.test.js+++ b/test/resume-flow.test.js@@ -94,7 +94,7 @@ function alert(text, expected) {test('coordinator resume ends with the exact measured-average flow alert [N32,R1,R2]', async t => {const box = fixture(t, { wait: 61 });- alert(await box.run(['resume']), 'flow: review wait average 61 min (1 measured; > 60 min); bottleneck: build (66.67% of 300 measured cycle min); next: add a builder when open work is available');+ alert(await box.run(['resume']), 'flow: review wait average 1 h 1 min (1 measured; > 60 min); bottleneck: build (66.67% of 5 h 0 min measured cycle time); next: add a builder when open work is available');const json = await box.run(['resume', '--json']);assert.deepEqual(json.flow, box.stats().flow, 'resume uses precisely the stats observation, stage and action');const stats = await box.run(['stats', '--json']);@@ -104,13 +104,13 @@ test('coordinator resume ends with the exact measured-average flow alert [N32,R1test('coordinator resume alerts for the oldest unreviewed submission alone [N32,R1,R2]', async t => {const box = fixture(t, { wait: 10, age: 181 });- alert(await box.run(['resume']), 'flow: unreviewed #2 waiting 181 min (> 180 min); bottleneck: build (66.67% of 300 measured cycle min); next: add a builder when open work is available');+ alert(await box.run(['resume']), 'flow: unreviewed #2 waiting 3 h 1 min (> 180 min); bottleneck: build (66.67% of 5 h 0 min measured cycle time); next: add a builder when open work is available');assert.deepEqual(box.stats().flow.unreviewed, { size: 1, oldest: { id: 2, since: '2026-10-10T05:19:00.000Z', ageMinutes: 181 } });});test('coordinator resume keeps both threshold trips in one final flow line [N32,R1,R2]', async t => {const box = fixture(t, { wait: 61, age: 181 });- alert(await box.run(['resume']), 'flow: review wait average 61 min (1 measured; > 60 min); unreviewed #2 waiting 181 min (> 180 min); bottleneck: build (66.67% of 300 measured cycle min); next: add a builder when open work is available');+ alert(await box.run(['resume']), 'flow: review wait average 1 h 1 min (1 measured; > 60 min); unreviewed #2 waiting 3 h 1 min (> 180 min); bottleneck: build (66.67% of 5 h 0 min measured cycle time); next: add a builder when open work is available');});test('coordinator resume adds no alert at exact healthy threshold boundaries [N32,R1,R2]', async t => {@@ -128,13 +128,13 @@ test('coordinator resume adds no alert to an unmeasured healthy board [N32,R1,R2test('coordinator resume names an old waiting item without inventing a measured bottleneck [N32,R1,R2]', async t => {const box = fixture(t, { age: 181 });- alert(await box.run(['resume']), 'flow: unreviewed #1 waiting 181 min (> 180 min); bottleneck: not measured yet');+ alert(await box.run(['resume']), 'flow: unreviewed #1 waiting 3 h 1 min (> 180 min); bottleneck: not measured yet');});for (const reservation of ['expired', 'released']) {test(`coordinator resume counts an ${reservation} review as unreserved from final submit [N32,R1,R2]`, async t => {const box = fixture(t, { age: 181, reservation });- alert(await box.run(['resume']), 'flow: unreviewed #1 waiting 181 min (> 180 min); bottleneck: not measured yet');+ alert(await box.run(['resume']), 'flow: unreviewed #1 waiting 3 h 1 min (> 180 min); bottleneck: not measured yet');});}@@ -156,6 +156,6 @@ test('agent resume keeps its next step without a coordinator flow alert [N32,R1,test('coordinator resume finds the oldest unreserved item behind an older live review [N32,R1,R2]', async t => {const box = fixture(t, { age: 190, otherAge: 181, reservation: 'live' });- alert(await box.run(['resume']), 'flow: unreviewed #2 waiting 181 min (> 180 min); bottleneck: not measured yet');+ alert(await box.run(['resume']), 'flow: unreviewed #2 waiting 3 h 1 min (> 180 min); bottleneck: not measured yet');assert.deepEqual(box.stats().flow.unreviewed, { size: 1, oldest: { id: 2, since: '2026-10-10T05:19:00.000Z', ageMinutes: 181 } });});diff --git a/test/stats-cli.test.js b/test/stats-cli.test.jsindex cff6f1e0..51b30333 100644--- a/test/stats-cli.test.js+++ b/test/stats-cli.test.js@@ -69,7 +69,7 @@ test('[R1,R2,A1] stats JSON is versioned, text states the same proof numbers andassert.ok(text.stdout.includes(expected.firstEventAt));assert.ok(text.stdout.includes(expected.lastEventAt));assert.match(text.stdout, /build: average 0 min · median 0 min · 1 measured/u);- assert.match(text.stdout, /review: average unmeasured min · median unmeasured min · 0 measured; 1 of 1 completed items unmeasured/u);+ assert.match(text.stdout, /review: average unmeasured · median unmeasured · 0 measured; 1 of 1 completed items unmeasured/u);assert.match(text.stdout, /not enough measured flow to name a bottleneck \(1 items completed since the beginning, none with every stage measured\)/u);assert.deepEqual(store.events(board), before, 'reading statistics appends no move');});diff --git a/test/stats-flow.test.js b/test/stats-flow.test.jsindex 169417da..a241e1f9 100644--- a/test/stats-flow.test.js+++ b/test/stats-flow.test.js@@ -120,11 +120,11 @@ test('flow numbers match a hand computation through rework, released reviews andassert.equal(result.flow.bottleneck.recommendation, 'add a builder in core');assert.deepEqual(result.flow.bottleneck.completedItems, 2);assert.deepEqual(flowLines(result.flow), [- 'build: average 33.75 min · median 25 min · 4 measured; 0 of 2 completed items unmeasured',+ 'build: average 34 min · median 25 min · 4 measured; 0 of 2 completed items unmeasured','review wait: average 15 min · median 10 min · 3 measured; 0 of 2 completed items unmeasured','review: average 15 min · median 10 min · 3 measured; 0 of 2 completed items unmeasured','merge wait: average 40 min · median 40 min · 2 measured; 0 of 2 completed items unmeasured',- 'open queue: 3 · oldest #3 (160 min)', 'claimed queue: 1 · oldest #6 (25 min)',+ 'open queue: 3 · oldest #3 (2 h 40 min)', 'claimed queue: 1 · oldest #6 (25 min)','submitted queue: 1 · oldest #7 (10 min)', 'accepted queue: 1 · oldest #8 (5 min)','per day: 2026-10-10: 8 added, 2 merged', '2.5 submissions per merged item','active in the last hour: 6 agents · roles builder 4, verifier 1, coordinator 1, unknown 0 · lanes coordinator 1, core 4, review 1',@@ -210,7 +210,7 @@ test('every bottleneck recommendation follows its documented rule and ties choos[180, 'coordinator', 'add', 6, { lane: 'core' }], [185, 'core-6', 'claim', 6, { leaseUntil: at(1000) }]], 'review the oldest submission first (#2)'],[[20, 1, 1, 1], [[185, 'review-1', 'reserve', 2, { until: at(1000) }], [190, 'review-1', 'reject', 2, { commit: '2'.repeat(40) }]], 'tighten criteria or briefs: 1 of 3 submissions were sent back'],[[20, 1, 1, 1], [], 'add a builder in core'],- [[1, 1, 20, 1], [], 'reviews are slow (median 12.5 min): check how long the frozen checks take'],+ [[1, 1, 20, 1], [], 'reviews are slow (median 13 min): check how long the frozen checks take'],[[1, 1, 1, 20], [], 'land the accepted items: #3'],[[20, 20, 20, 20], [], 'add a builder in core'],]) {@@ -226,6 +226,39 @@ test('every bottleneck recommendation follows its documented rule and ties choos}});+test('stats sentences read times in human units [R1,R2]', t => {+ for (const [review, expected] of [[42, '42 min'], [213.9, '3 h 34 min'], [5707.5, '3 d 23 h']]) {+ const entries = cycle(1, [1, 1, review, 1]);+ for (const entry of entries) {+ if (entry[4]?.leaseUntil) entry[4].leaseUntil = at(10_000);+ if (entry[4]?.until) entry[4].until = at(10_000);+ }+ const { stats } = fixture(t, entries, Math.ceil(review + 10));+ const flow = stats().flow;+ assert.equal(flow.stages.review.averageMinutes, review, 'JSON keeps measured numeric precision');+ assert.equal(flow.bottleneck.recommendation, `reviews are slow (median ${expected}): check how long the frozen checks take`);+ assert.ok(flowLines(flow).includes(`review: average ${expected} · median ${expected} · 1 measured; 0 of 1 completed items unmeasured`));+ assert.ok(flowLines(flow).includes(`next: ${flow.bottleneck.recommendation}`), 'text output uses the same rounded recommendation');+ }+ const empty = fixture(t, []).stats().flow;+ assert.ok(flowLines(empty).includes('build: average unmeasured · median unmeasured · 0 measured; 0 of 0 completed items unmeasured'));+});++test('a recommendation names at most three items [R1,R2]', t => {+ const accepted = Array.from({ length: 5 }, (_, index) => {+ const id = index + 1, start = index * 10, commit = String(id).repeat(40);+ return [+ [start, 'coordinator', 'add', id, { lane: 'core' }], [start + 1, `core-${id}`, 'claim', id, { leaseUntil: at(1000) }],+ [start + 2, `core-${id}`, 'submit', id, { commit }], [start + 3, 'review-1', 'reserve', id, { until: at(1000) }],+ [start + 4, 'review-1', 'accept', id, { commit }],+ ];+ }).flat();+ const entries = [...accepted, ...cycle(6, [1, 1, 1, 20], 60)];+ const flow = fixture(t, entries).stats().flow;+ assert.equal(flow.queues.accepted.size, 5, 'the five named recommendation targets remain genuinely accepted');+ assert.equal(flow.bottleneck.recommendation, 'land the accepted items: #1, #2, #3 +2 more');+});+test('flow reports no evidence instead of inventing a bottleneck or missing review time [R1,R2]', t => {const empty = fixture(t, []).stats().flow;assert.equal(empty.bottleneck.stage, null);