Skip to content

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.

feat(view): an item's history is a timeline of its states [N26]

Corey Olson8edd7f0eb307
diff --git a/src/cockpit.js b/src/cockpit.js
index 519e67b8..fa690ce2 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -181,9 +181,16 @@ input, select { border: 1px solid var(--line-strong); background: var(--surface)
.sentback h3 { color: var(--reject); }
.sentback .verdict { border-left: 0; padding: 0; margin: 0; }
.meta .why { flex-basis: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--reject); }
-.hist { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; font-size: 12.5px; }
-.hist div { display: contents; }
-.hist time, .feed time { color: var(--ink-faint); font: 12px var(--mono); }
+.tl { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
+.tl li { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 10px; padding: 0 0 12px 20px; --c: var(--line-strong); }
+.tl li::before { content: ''; position: absolute; left: 0; top: 4px; width: 10px; height: 10px; border-radius: 50%; box-sizing: border-box; border: 2px solid var(--c); background: var(--c); }
+.tl li.tl-quiet::before { background: var(--surface); }
+.tl li::after { content: ''; position: absolute; left: 4px; top: 16px; bottom: 0; width: 2px; border-radius: 2px; background: var(--c); opacity: .55; }
+.tl li:last-child { padding-bottom: 0; } .tl li:last-child::after { display: none; }
+.tl .tl-claimed { --c: var(--blue); } .tl .tl-submitted { --c: var(--warn); } .tl .tl-verified { --c: var(--accent); } .tl .tl-withdrawn { --c: var(--ink-faint); } .tl .tl-back { --c: var(--reject); }
+.tl b { font-weight: 600; }
+.tl small { grid-column: 2; color: var(--ink-faint); font-size: 12px; }
+.tl time, .feed time { color: var(--ink-faint); font: 12px var(--mono); }
.rowref { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; font-size: 13px; padding: 3px 0; }
.rowref code { font-weight: 600; }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
@@ -350,32 +357,71 @@ const doing = (x) => [x.sentBack && count(x.sentBack, 'sent back'), x.awaiting &
const FLOW = ${JSON.stringify(lifecycle()).replaceAll('<', '\\u003c')};
/**
- * How often each move was made on this board, keyed from>to:verb, by replaying every item's history
- * through the lifecycle. The board logs a move under its verb, and a claim on a claimed item as
- * renew, but never the clock's lapse: an event that cannot start where the replay stands, or an item
- * that reads otherwise than where its history leaves it, means the clock moved first.
+ * An item's history replayed through the lifecycle: each event with the state it found the item in
+ * and the move it made, if it made one. The board logs a move under its verb, and a claim on a
+ * claimed item as renew, but never the clock's lapse: an event that cannot start where the replay
+ * stands, or an item that reads otherwise than where its history leaves it, means the clock moved
+ * first, and the replay puts that lapse in, with no time of its own.
*/
+function replay(item) {
+ const clock = FLOW.moves.filter((m) => m.by.includes('clock'));
+ const steps = [];
+ let at = FLOW.initial;
+ const step = (move, e) => {
+ steps.push({ from: at, move, at: e ? e.at : null, by: e ? e.by : 'the clock', kind: e ? e.kind : move.verb });
+ if (move) at = move.to;
+ };
+ for (const e of item.history) {
+ const verb = e.kind === 'renew' ? 'claim' : e.kind;
+ // A renew is the claim that stays claimed; a claim logged as such is the one that arrives.
+ const fits = (s) => FLOW.moves.find((m) => m.verb === verb && m.from.includes(s) && (verb !== 'claim' || (e.kind === 'renew') === (m.to === s)));
+ const lapse = fits(at) ? null : clock.find((m) => m.from.includes(at) && fits(m.to));
+ if (lapse) step(lapse, null);
+ step(fits(at) || null, e);
+ }
+ const lapse = at === item.status ? null : clock.find((m) => m.from.includes(at) && m.to === item.status);
+ if (lapse) step(lapse, null);
+ return steps;
+}
+
+/** How often each move was made on this board, keyed from>to:verb, from every item's replay. */
function moveCounts(items) {
const counts = new Map();
- const bump = (from, move) => counts.set(from + '>' + move.to + ':' + move.verb, (counts.get(from + '>' + move.to + ':' + move.verb) || 0) + 1);
- const clock = FLOW.moves.filter((m) => m.by.includes('clock'));
for (const item of items) {
- let at = FLOW.initial;
- for (const e of item.history) {
- const verb = e.kind === 'renew' ? 'claim' : e.kind;
- // A renew is the claim that stays claimed; a claim logged as such is the one that arrives.
- const fits = (s) => FLOW.moves.find((m) => m.verb === verb && m.from.includes(s) && (verb !== 'claim' || (e.kind === 'renew') === (m.to === s)));
- const lapse = fits(at) ? null : clock.find((m) => m.from.includes(at) && fits(m.to));
- if (lapse) { bump(at, lapse); at = lapse.to; }
- const move = fits(at);
- if (move) { bump(at, move); at = move.to; }
+ for (const s of replay(item)) {
+ if (s.move) counts.set(s.from + '>' + s.move.to + ':' + s.move.verb, (counts.get(s.from + '>' + s.move.to + ':' + s.move.verb) || 0) + 1);
}
- const lapse = at === item.status ? null : clock.find((m) => m.from.includes(at) && m.to === item.status);
- if (lapse) bump(at, lapse);
}
return counts;
}
+// A finished stay as the timeline says it: 45m, 3h 20m, 2d 4h.
+const span = (ms) => {
+ const m = Math.max(0, Math.round(ms / 60000));
+ return m < 1 ? 'under a minute' : m < 60 ? m + 'm' : m < 1440 ? Math.floor(m / 60) + 'h' + (m % 60 ? ' ' + (m % 60) + 'm' : '') : Math.floor(m / 1440) + 'd' + (Math.floor((m % 1440) / 60) ? ' ' + Math.floor((m % 1440) / 60) + 'h' : '');
+};
+
+/**
+ * An item's history drawn as a timeline. Each move is a dot in the colour of the state it led to, a
+ * reject in the colour of work sent back, and the item's creation (logged as add) one in the start
+ * state's colour; an event that moves nothing is a hollow dot. Between the dots runs a line in the
+ * colour of the state the item stayed in, and under each dot that began a stay, how long it lasted,
+ * or how long so far while the item can still leave. A lapse has a row but no time.
+ */
+function timeline(item) {
+ const steps = replay(item);
+ return '<ol class="tl">' + steps.map((s, i) => {
+ const enters = s.move ? s.move.to : s.kind === 'add' ? FLOW.initial : null;
+ const state = enters || s.from;
+ const final = FLOW.states.some((f) => f.id === state && f.final);
+ const next = steps.slice(i + 1).find((n) => n.move);
+ const named = s.kind === 'reject' ? 'sent back' : state;
+ // A stay after a lapse has no start to count from, and one that ends in a lapse no end.
+ const stay = !enters || !s.at || final ? '' : !next ? esc(named) + ' for ' + age(s.at) + ' so far' : next.at ? esc(named + ' for ' + span(Date.parse(next.at) - Date.parse(s.at))) : '';
+ return '<li class="tl-' + esc(state) + (s.kind === 'reject' ? ' tl-back' : '') + (enters ? '' : ' tl-quiet') + '"><time>' + (s.at ? when(s.at) : '') + '</time><span><b>' + esc(s.kind) + '</b> ' + esc(s.by) + '</span>' + (stay ? '<small>' + stay + '</small>' : '') + '</li>';
+ }).join('') + '</ol>';
+}
+
/**
* The lifecycle drawn as SVG with this board's counts. The longest way from the start to a final
* state runs along a row, the first-declared final winning a tie, and any other state sits below,
@@ -583,7 +629,7 @@ function render() {
+ (item.brief ? '<div><h3>Brief</h3><div class="text muted">' + esc(item.brief) + '</div></div>' : '')
+ '<div><h3>People and commits</h3><dl class="kv">' + (item.owner && s === 'building' ? '<dt>holding</dt><dd>' + esc(item.owner) + '</dd>' : '') + (item.builtBy ? '<dt>built by</dt><dd>' + esc(item.builtBy) + '</dd>' : '') + (item.verifiedBy ? '<dt>verified by</dt><dd>' + esc(item.verifiedBy) + '</dd>' : '') + (item.commit ? '<dt>commit</dt><dd><code>' + esc(item.commit.slice(0, 12)) + '</code></dd>' : '') + (item.merged ? '<dt>merged</dt><dd><code>' + esc(item.merged.slice(0, 12)) + '</code></dd>' : '') + (item.blockedBy.length ? '<dt>waits on</dt><dd>' + item.blockedBy.map((id) => '#' + id).join(', ') + '</dd>' : '') + '</dl></div>'
+ (back && !earlier.length ? '' : '<div><h3>' + (back ? 'Earlier verdicts' : 'Verdicts') + '</h3>' + (earlier.length ? earlier.map(verdictHtml).join('') : '<div class="muted">None yet.</div>') + '</div>')
- + '<div><h3>History</h3><div class="hist">' + item.history.map((e) => '<div><time>' + when(e.at) + '</time><span>' + esc(e.by) + ' ' + esc(e.kind) + '</span></div>').join('') + '</div></div>'
+ + '<div><h3>History</h3>' + timeline(item) + '</div>'
+ '<div class="links"><button data-shout="' + esc(item.lane) + '" data-about="' + item.id + '" type="button">Shout the ' + esc(item.lane) + ' lane about #' + item.id + '</button><button data-new type="button">New item</button></div></div>';
}
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index 8c3aebcd..a31ffcce 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -413,6 +413,70 @@ test("the sidebar shows each product's progress [N28]", async () => {
await view.stop();
}
});
+/**
+ * An item's timeline as rows: the state classes on its dot, its time, its event, who made it, and the
+ * stay it began, with any running age read as its text.
+ */
+function timelineRows(html) {
+ return [...html.matchAll(/<li class="([^"]*)"><time>([^<]*)<\/time><span><b>([^<]*)<\/b> ([^<]*)<\/span>(?:<small>(.*?)<\/small>)?<\/li>/g)].map((match) => ({
+ dot: match[1],
+ time: match[2],
+ event: `${match[3]} ${match[4]}`,
+ stay: (match[5] ?? '').replace(/<time data-ago="[^"]+">([^<]*)<\/time>/, '$1'),
+ }));
+}
+
+test("the history is a timeline of the item's states [N26]", async () => {
+ const box = machine();
+ const alpha = project(box, 'alpha');
+ box.run(alpha.repo, 'add', 'web', 'Greeting', '--specs', 'G1', '--criterion', 'greets');
+ box.run(alpha.repo, 'add', 'web', 'Farewell', '--specs', 'G2', '--criterion', 'says goodbye');
+ build(box, alpha, 1, 'greeting.html');
+ sendBack(box, alpha, 1, 'no greeting');
+ build(box, alpha, 1, 'greeting-again.html');
+ accept(box, alpha, 1);
+ box.run(alpha.repo, 'merged', '1', box.git(alpha.repo, 'rev-parse', alpha.branch));
+ box.run(alpha.web, 'claim', '2');
+ const view = await startView(box);
+ try {
+ const page = await openPage(view);
+ await page.click({ go: 'item:1' });
+ const done = timelineRows(page.show('detail'));
+ assert.deepEqual(done.map((row) => [row.dot, row.event]), [
+ ['tl-open', 'add coordinator'],
+ ['tl-claimed', 'claim web-1'],
+ ['tl-submitted', 'submit web-1'],
+ ['tl-open tl-back', 'reject coordinator'],
+ ['tl-claimed', 'claim web-1'],
+ ['tl-submitted', 'submit web-1'],
+ ['tl-verified', 'accept coordinator'],
+ ['tl-verified tl-quiet', 'merged coordinator'],
+ ], 'a dot per event in the colour of the state it led to; a merge moves nothing');
+ assert.deepEqual(done.map((row) => row.stay.replace(/ for .*/, ' for')), ['open for', 'claimed for', 'submitted for', 'sent back for', 'claimed for', 'submitted for', '', ''], 'each stay until the next move; a final state has none');
+ assert.ok(done.slice(0, 6).every((row) => / for (under a minute|\d+m)$/.test(row.stay)), done.map((row) => row.stay).join(', '));
+ assert.ok(done.every((row) => /^\d\d:\d\d$/.test(row.time)), 'every event keeps its time');
+
+ await page.click({ go: 'item:2' });
+ assert.deepEqual(timelineRows(page.show('detail')).map((row) => [row.dot, row.stay]).slice(1), [['tl-claimed', 'claimed for now so far']]);
+ const later = await openPage(view, { later: 1 });
+ await later.click({ go: 'item:2' });
+ assert.deepEqual(timelineRows(later.show('detail')).map((row) => row.stay).slice(1), ['claimed for 24h so far'], 'the stay so far counts on');
+
+ // A claim logged on an item the replay holds claimed: the clock lapsed the first claim between.
+ const at = (minute) => new Date(Date.UTC(2026, 9, 6, 12, minute)).toISOString();
+ const item = { status: 'claimed', history: [{ kind: 'add', by: 'web-1', at: at(0) }, { kind: 'claim', by: 'web-1', at: at(5) }, { kind: 'claim', by: 'web-2', at: at(200) }] };
+ const lapsed = timelineRows(page.run(`timeline(${JSON.stringify(item)})`));
+ assert.deepEqual(lapsed.map((row) => [row.dot, row.event, row.time === '']), [
+ ['tl-open', 'add web-1', false],
+ ['tl-claimed', 'claim web-1', false],
+ ['tl-open', 'lapse the clock', true],
+ ['tl-claimed', 'claim web-2', false],
+ ]);
+ assert.deepEqual(lapsed.map((row) => row.stay.replace(/ for .*/, ' for')), ['open for', '', '', 'claimed for'], 'a stay that ends in a lapse, or starts with one, has no length to show');
+ } finally {
+ await view.stop();
+ }
+});
/**
* The agents the panel shows: id, the path on hover, its last move, what it holds and whether it
* reads idle, and its entry's text with the tags taken out.