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): show API proof totals on a stats card [V2,N26]

Corey Olsonca61f2060566
diff --git a/src/cockpit.js b/src/cockpit.js
index 7738df50..7a3aabde 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -105,6 +105,7 @@ export function cockpitPage(key = '', { snapshot = false, readOnly = false, requ
<section class="card-panel person-requests" id="person-requests" aria-label="Your requests" aria-live="polite" hidden></section>
<section data-pane="items" class="two">
<div class="primary">
+ <section class="card-panel proof-stats" id="proof-stats" aria-label="Board proof stats" hidden></section>
<div class="card-panel toolbar"><div class="seg" id="state-chips" role="group" aria-label="Show"></div><select class="lane-pick" id="lane-pick" aria-label="Lane"></select><button class="go" id="new-item" type="button">New item</button></div>
<div class="card-panel list-card"><ol class="needs" id="needs" aria-label="What needs you" hidden></ol><ol class="chain" id="chain" aria-label="Items"></ol></div>
</div>
@@ -729,6 +730,35 @@ function boardSummary(board, state) {
};
}
+/** Render the event-log totals already supplied by the shared stats API [V2]. */
+function proofStatsCard(stats) {
+ if (!stats) return '<span class="muted">Stats unavailable</span>';
+ const families = stats.families || [];
+ const agents = stats.agents || [];
+ const percentage = (Number(stats.rejectionShare) * 100).toFixed(1) + '%';
+ const familyDetail = families.map((family) => family.name + ' (' + family.agents + ' agents, ' + family.moves + ' moves)').join(' · ') || 'none';
+ const agentDetail = agents.map((agent) => agent.id + ' (' + agent.families.join('/') + '; ' + agent.moves + ' moves)').join(' · ') || 'none';
+ /** Format an API timestamp for the card without recalculating event statistics.
+ * @param {string|number|null} value
+ * @returns {string}
+ */
+ const dateText = (value) => value ? new Date(value).toLocaleDateString([], { year: 'numeric', month: 'short', day: 'numeric' }) : 'none';
+ const firstAt = stats.firstEventAt ?? '';
+ const lastAt = stats.lastEventAt ?? '';
+ return '<div class="proof-stats-head"><b>Proof stats</b><span>from recorded moves</span></div>'
+ + '<div class="proof-stats-grid">'
+ + '<div><span>Submissions</span><b data-stat="submissions" data-value="' + esc(stats.submissions) + '">' + esc(stats.submissions) + '</b></div>'
+ + '<div><span>Rejections</span><b data-stat="rejections" data-value="' + esc(stats.rejections) + '">' + esc(stats.rejections) + '</b></div>'
+ + '<div><span>Sent back</span><b data-stat="rejectionShare" data-value="' + esc(percentage) + '">' + esc(percentage) + '</b></div>'
+ + '<div><span>Merged</span><b data-stat="merged" data-value="' + esc(stats.merged) + '">' + esc(stats.merged) + '</b></div>'
+ + '<div><span>Without accept</span><b data-stat="mergedWithoutAccept" data-value="' + esc(stats.mergedWithoutAccept) + '">' + esc(stats.mergedWithoutAccept) + '</b></div>'
+ + '<div><span>Agents</span><b data-stat="agentCount" data-value="' + esc(stats.agentCount) + '">' + esc(stats.agentCount) + '</b></div>'
+ + '<div><span>Families</span><b data-stat="familyCount" data-value="' + esc(stats.familyCount) + '">' + esc(stats.familyCount) + '</b></div>'
+ + '<div><span>First · latest</span><small><time data-stat="firstEventAt" data-value="' + esc(firstAt) + '" datetime="' + esc(firstAt) + '">' + esc(dateText(firstAt)) + '</time> · <time data-stat="lastEventAt" data-value="' + esc(lastAt) + '" datetime="' + esc(lastAt) + '">' + esc(dateText(lastAt)) + '</time></small></div>'
+ + '</div><details class="proof-stats-detail"><summary>Agents and families</summary>'
+ + '<p><b>Families:</b> ' + esc(familyDetail) + '</p><p><b>Agents:</b> ' + esc(agentDetail) + '</p></details>';
+}
+
/** Resolve a displayed repo to the persistent board identity supplied by API v1. */
function boardPath(root) {
const board = data && data.projects.find((entry) => entry.root === root && entry.ok);
@@ -1221,6 +1251,8 @@ function render() {
const p = data.project;
const group = data.group;
renderSide();
+ $('proof-stats').hidden = true;
+ $('proof-stats').innerHTML = '';
if (view.answering && view.answering.root !== view.root) answer(null);
// Until the first board arrives the page shows no tabs or panes, so a machine with none never
// flashes them; with no board to show, one message says how a board starts, in their place.
@@ -1234,6 +1266,8 @@ function render() {
renderCredentials();
if (group) { renderGroup(group); return; }
if (!p) return;
+ $('proof-stats').hidden = false;
+ $('proof-stats').innerHTML = proofStatsCard(p.proofStats);
// Each product's progress (N28): the rows an accepted item cites, and its items by state.
$('prod-list').innerHTML = p.products.map((x) => {
const states = [['open', '', x.items.open], ['building', 'building', x.items.claimed], ['to verify', 'verify', x.items.submitted], ['verified', 'verified', x.items.verified]].filter(([, , n]) => n);
diff --git a/src/view.css b/src/view.css
index fc487256..5709e4ba 100644
--- a/src/view.css
+++ b/src/view.css
@@ -675,3 +675,18 @@ code.inline.long { white-space: break-spaces; overflow-wrap: anywhere; }
.credential dt { color: var(--ink-muted); }
.credential dd { margin: 0; overflow-wrap: anywhere; }
.credential > button { justify-self: start; min-height: 44px; }
+
+.proof-stats { padding: 10px 12px; display: grid; gap: 7px; }
+.proof-stats[hidden] { display: none; }
+.proof-stats-head { display: flex; align-items: baseline; gap: 8px; }
+.proof-stats-head b { font-size: 13px; }
+.proof-stats-head > span, .proof-stats-grid > div > span { color: var(--ink-muted); font-size: 11px; }
+.proof-stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px 12px; }
+.proof-stats-grid > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
+.proof-stats-grid b { font-size: 14px; font-variant-numeric: tabular-nums; }
+.proof-stats-grid small { overflow-wrap: anywhere; font-size: 11px; color: var(--ink-muted); }
+.proof-stats-detail { border-top: 1px solid var(--line); padding-top: 5px; font-size: 11px; }
+.proof-stats-detail summary { min-height: var(--tap); align-content: center; cursor: pointer; color: var(--ink-muted); }
+.proof-stats-detail p { margin: 5px 0 0; overflow-wrap: anywhere; }
+
+@media (width < 480px) { .proof-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index d383b191..ee4a0c83 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -8035,3 +8035,71 @@ test('local agents panel inventories and phone-revokes a scoped credential [H2,H
await view.stop();
}
});
+
+test('[V2,N26] real Chrome shows matching proof stats at phone width and clears on a group [V2,N26]', { timeout: 90_000 }, async (t) => {
+ const executable = chromeExecutable();
+ assert.ok(executable, 'Chrome is required for the proof stats card criterion.');
+
+ const box = machine();
+ const alpha = project(box, 'stats-phone', SPEC, { project: 'Proof project' });
+ project(box, 'stats-other', SPEC, { project: 'Proof project' });
+ box.run(alpha.repo, 'add', 'web', 'Reworked item', '--specs', 'G1', '--criterion', 'survives rework');
+ build(box, alpha, 1, 'reworked.txt');
+ sendBack(box, alpha, 1, 'the first submission needs another pass');
+ build(box, alpha, 1, 'reworked-again.txt');
+ accept(box, alpha, 1);
+ box.git(alpha.repo, 'merge', '--no-ff', '-m', 'chore: merge accepted fixture', alpha.branch);
+ box.run(alpha.repo, 'merged', '1', box.git(alpha.repo, 'rev-parse', 'HEAD'));
+ box.run(alpha.repo, 'add', 'web', 'Second accepted merge', '--specs', 'G1', '--criterion', 'records the merge');
+ build(box, alpha, 2, 'second-accepted-merge.txt');
+ accept(box, alpha, 2);
+ box.git(alpha.repo, 'merge', '--no-ff', '-m', 'chore: merge second accepted fixture', alpha.branch);
+ box.run(alpha.repo, 'merged', '2', box.git(alpha.repo, 'rev-parse', 'HEAD'));
+ const expected = JSON.parse(box.run(alpha.repo, 'stats', '--json')).stats;
+ assert.deepEqual([expected.submissions, expected.rejections, expected.rejectionShare, expected.merged, expected.mergedWithoutAccept], [3, 1, 1 / 3, 2, 0], 'known real rejection, rework and two accepted merges');
+ const view = await startView(box);
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-proof-stats-chrome-'));
+ let chrome;
+ try {
+ chrome = await openSnapshotChrome(executable, view.link.href, profile);
+ await chrome.waitFor("!!data?.project?.proofStats && document.querySelector('#proof-stats [data-stat=\"submissions\"]')");
+ await chrome.evaluate(`document.querySelector('[data-root=${JSON.stringify(alpha.repo)}]').click()`);
+ await chrome.waitFor(`data?.project?.root === ${JSON.stringify(alpha.repo)} && !!document.querySelector('#proof-stats [data-stat="submissions"]')`);
+ const keys = ['submissions', 'rejections', 'rejectionShare', 'merged', 'mergedWithoutAccept', 'agentCount', 'familyCount', 'firstEventAt', 'lastEventAt'];
+ const expectedValues = Object.fromEntries(keys.map((key) => [key, key === 'rejectionShare' ? `${(expected[key] * 100).toFixed(1)}%` : String(expected[key] ?? '')]));
+ for (const scheme of ['light', 'dark']) for (const width of [375, 1280]) {
+ await chrome.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: scheme }] });
+ await chrome.send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });
+ const actual = JSON.parse(await chrome.evaluate(`JSON.stringify((() => {
+ const card = document.querySelector('#proof-stats'), rect = card.getBoundingClientRect();
+ const grid = getComputedStyle(card.querySelector('.proof-stats-grid'));
+ return { hidden:card.hidden || !!card.closest('[hidden]'), display:getComputedStyle(card).display,
+ width:rect.width, height:rect.height, right:rect.right, viewport:document.documentElement.clientWidth,
+ columns:grid.gridTemplateColumns.split(' ').length,
+ values:Object.fromEntries(${JSON.stringify(keys)}.map(key => { const node=card.querySelector('[data-stat="' + key + '"]'); return [key, node?.getAttribute('data-value') ?? null]; })),
+ text:Object.fromEntries(${JSON.stringify(keys)}.map(key => [key, card.querySelector('[data-stat="' + key + '"]')?.textContent ?? null])) };
+ })())`));
+ assert.equal(actual.hidden, false, `${width}: selected board's stats card is visible`);
+ assert.equal(actual.display, 'grid', `${width}: stats card uses its computed grid layout`);
+ assert.ok(actual.width > 0 && actual.height > 0 && actual.right <= actual.viewport + 1, `${width}: card has visible bounds inside the viewport`);
+ assert.equal(actual.columns, width < 480 ? 2 : 4, `${width}: compact stats grid adapts to the viewport`);
+ assert.deepEqual(actual.values, expectedValues, `${width}: every visible value matches pullboard stats --json`);
+ const expectedText = JSON.parse(await chrome.evaluate(`JSON.stringify(Object.fromEntries(${JSON.stringify(keys)}.map(key => {
+ const value = ${JSON.stringify(expected)}[key];
+ const date = key === 'firstEventAt' || key === 'lastEventAt';
+ return [key, date ? (value ? new Date(value).toLocaleDateString([], { year:'numeric', month:'short', day:'numeric' }) : 'none') : ${JSON.stringify(expectedValues)}[key]];
+ })))`));
+ assert.deepEqual(actual.text, expectedText, `${width}: visible text also matches the stats response`);
+ }
+ await chrome.evaluate(`document.querySelector('[data-root="group:Proof project"]').click()`);
+ await chrome.waitFor("data?.group?.name === 'Proof project' && document.querySelector('#group-view:not([hidden])') && document.querySelector('#proof-stats').hidden");
+ assert.equal(await chrome.evaluate("document.querySelector('#proof-stats').innerHTML"), '', 'a grouped view cannot retain a prior repo\'s stats');
+ const { flow: currentFlow, ...currentTotals } = (await boardOf(view, alpha.repo)).proofStats;
+ const { flow: expectedFlow, ...expectedTotals } = expected;
+ assert.deepEqual(currentTotals, expectedTotals, 'the comparison reads the same live API stats source; queue ages may advance');
+ } finally {
+ if (chrome) await closeSnapshotChrome(chrome);
+ await view.stop();
+ rmSync(profile, { recursive: true, force: true });
+ }
+});