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): share the person needs projection [N26]

Corey Olson85fe1d2f044c
diff --git a/src/cockpit.js b/src/cockpit.js
index 6175c4f0..2e1854a1 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -4,6 +4,7 @@ import {
MACHINE,
} from './machine.js';
import { commandPhrases } from './help.js';
+import { personNeeds } from './needs.js';
/** The CLI's default phrases, ordered by depth for the existing prose inventory guard. */
export const PULLBOARD_COMMANDS = Object.freeze(commandPhrases().sort((left, right) => right.split(' ').length - left.split(' ').length));
@@ -599,14 +600,11 @@ const count = (n, one, many = one) => n + ' ' + (n === 1 ? one : many);
// and the line under the project says so without counting it.
const needCount = (x) => x.ok && !x.loading ? x.decisions + x.pending + x.drafts + x.holds : 0;
const doing = (x) => [x.decisions && count(x.decisions, 'decision', 'decisions'), x.pending && count(x.pending, 'question', 'questions'), x.drafts && count(x.drafts, 'draft row', 'draft rows'), x.holds && count(x.holds, 'lane held', 'lanes held'), x.sentBack && count(x.sentBack, 'sent back'), x.awaiting && count(x.awaiting, 'to verify'), x.building && count(x.building, 'building')].filter(Boolean).join(' · ') || (x.open ? count(x.open, 'item open', 'items open') : 'nothing open');
-/** The person's calls in one repo, as its Needs-you panel shows them, reused by a combined project view. */
+// Embed the standalone shared builder for live, exported and relay pages.
+const personNeeds = (${personNeeds.toString()});
+/** The person's calls in one repo, reused by a combined project view. */
function projectNeeds(p) {
- return [
- ...p.decisions.map((d) => ({ ref: agentName(d.shout_from, p), text: d.shout_text, what: 'decision', at: d.shout_at })),
- ...p.spec.filter((row) => row.status === 'pending' && !row.decision).map((row) => ({ ref: row.id, text: row.text, what: 'answer in SPEC.md' })),
- ...p.holds.map((hold) => ({ ref: hold.hold_lane, text: hold.hold_reason, what: 'lane held by ' + agentName(hold.hold_by, p) })),
- ...(p.spec.some((row) => row.status === 'draft' && !row.decision) ? [{ ref: String(p.spec.filter((row) => row.status === 'draft' && !row.decision).length), text: 'draft spec rows to approve or drop', what: 'review in SPEC.md', target: 'tab:spec' }] : []),
- ];
+ return personNeeds(p);
}
// The item lifecycle as pullboard declares it in src/machine.js, embedded when the page is served.
const FLOW = ${JSON.stringify(lifecycle()).replaceAll('<', '\\u003c')};
@@ -987,6 +985,9 @@ function renderPersonRequests(project) {
/** A board's sidebar counts, derived from the same API state the page displays. */
function boardSummary(board, state) {
+ const needs = personNeeds(state);
+ /** Count the calls, with draft rows retaining their individual count in the sidebar. */
+ const calls = (kind) => needs.filter((row) => row.kind === kind).reduce((total, row) => total + (row.count ?? 1), 0);
/** Count one item state for the sidebar. */
const count = (test) => state.items.filter(test).length;
return {
@@ -996,10 +997,10 @@ function boardSummary(board, state) {
sentBack: count((item) => item.status === 'open' && item.verdict && item.verdict.decision === 'REJECT'),
open: count((item) => item.status === 'open'),
verified: count((item) => item.status === 'verified'),
- pending: state.spec.filter((row) => row.status === 'pending' && !row.decision).length,
- drafts: state.spec.filter((row) => row.status === 'draft' && !row.decision).length,
- holds: state.holds.length,
- decisions: state.decisions.length,
+ pending: calls('pending'),
+ drafts: calls('draft'),
+ holds: calls('hold'),
+ decisions: calls('decision'),
// What each item's state reads from, so another repo's roadmap can show it as this board's
// Items tab does, sent back included, and open it here.
items: state.items.map((item) => ({ id: item.id, title: item.title, status: item.status, merged: Boolean(item.merged), verdict: item.verdict && { decision: item.verdict.decision } })),
@@ -1992,12 +1993,13 @@ function render() {
// What needs the person, first, and only the person's calls (B26): the decisions passed up to them,
// questions in the spec, held lanes, then draft rows. Work waiting for a verdict or sent back shows
// on the board with who holds it; it is the agents' to move.
- const needs = [
- ...p.decisions.map((d) => ['decide:' + d.shout_id, agentName(d.shout_from, p), d.shout_text, 'decide', d.shout_at]),
- ...p.spec.filter((r) => r.status === 'pending' && !r.decision).map((r) => ['spec:' + r.id, r.id, r.text, 'answer in SPEC.md']),
- ...p.holds.map((h) => ['tab:shouts', h.hold_lane, h.hold_reason, 'lane held by ' + agentName(h.hold_by), h.hold_at]),
- ];
- const drafts = p.spec.filter((r) => r.status === 'draft' && !r.decision).length;
+ const personalNeeds = personNeeds(p);
+ // Adapt display targets and the existing hold age without reimplementing which calls belong here.
+ const needs = personalNeeds.filter((row) => row.kind !== 'draft').map((row) => row.kind === 'decision'
+ ? ['decide:' + row.id, row.ref, row.text, 'decide', row.at]
+ : row.kind === 'pending' ? ['spec:' + row.id, row.ref, row.text, row.what]
+ : ['tab:shouts', row.ref, row.text, row.what, p.holds.find((hold) => hold.hold_lane === row.id)?.hold_at]);
+ const drafts = personalNeeds.find((row) => row.kind === 'draft')?.count ?? 0;
// Each of the person's calls is a row at the head of Active, shaped like an item: what it is first, then NEEDS YOU and
// its kind where an item has its lane, and what to do at the right. Every call is a row; the draft rows are one row
// with their count. Read-only, a row is its words, opening nothing.
diff --git a/src/serve.js b/src/serve.js
index df76370a..0f96d6ad 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -58,6 +58,8 @@ import {
} from './projects.js';
import { fetchLocal } from './local-fetch.js';
import { Refused } from './refused.js';
+import { personNeeds } from './needs.js';
+import { projectRowDecisions } from './row-decisions.js';
import { loadSpec } from './spec.js';
/** The page's styles (N26), read once: the page links them, so it needs no inline style. */
@@ -334,7 +336,7 @@ export function projectState(root, { seen = null, board: providedBoard = null, i
const log = store.events(board);
// When each agent last moved on the board: the log is in order, so the last write wins.
const lastMove = new Map(log.map((event) => [event.event_by, event.event_at]));
- return {
+ const state = projectRowDecisions(store.rowDecisions(board), {
root: info.root,
releaseNotes: viewReleaseNotes(),
rowAgesAt: { [config.spec]: head, [doctrine.name]: head },
@@ -362,7 +364,9 @@ export function projectState(root, { seen = null, board: providedBoard = null, i
unseen: seen === null ? null : { since: seen, count: board.db.prepare('SELECT COUNT(*) AS n FROM shout WHERE shout_id > ?').get(seen).n },
// Each product's progress, counted as pullboard status counts it (N28).
products: productSummaries(config, loadSpec(info.root, config), all),
- };
+ });
+ // Pending person decisions govern the calls on the API, sealed relay and exported page alike.
+ return { ...state, needs: personNeeds(state) };
}, providedBoard);
}
diff --git a/test/cockpit/needs.test.js b/test/cockpit/needs.test.js
index fe31815c..0b14efcc 100644
--- a/test/cockpit/needs.test.js
+++ b/test/cockpit/needs.test.js
@@ -1,10 +1,86 @@
/** Cockpit needs checks, using the shared real-board fixtures [N26]. */
import assert from 'node:assert/strict';
-import { mkdtempSync, rmSync } from 'node:fs';
+import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
+import { createServer } from 'node:http';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
-import { SPEC, machine, project, build, sendBack, startView, styleOf, element, openPage, projectRows, agentEntries, needEntries, itemRow, shoutNameText, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, chooseFilter } from './fixture.js';
+import { SPEC, machine, project, build, sendBack, startView, styleOf, element, openPage, projectRows, agentEntries, needEntries, itemRow, shoutNameText, chromeExecutable, openSnapshotChrome, closeSnapshotChrome, chooseFilter, boardId, boardOf, fetchLive, serveFolder } from './fixture.js';
+import { cockpitPage } from '../../src/cockpit.js';
+import { personNeeds } from '../../src/needs.js';
+
+test("the page's Needs-you comes from the shared builder [N26]", { timeout: 180_000 }, async (t) => { // budget: hang ceiling for private board/API setup and the two real browser modes, not a throughput claim.
+ const box = machine();
+ const alpha = project(box, 'shared needs', `${SPEC}- G3 [pending] Choose the greeting. | gate: review\n- G4 [draft, must] Keep the footer. | gate: review\n- G5 [draft, aim] Keep the header. | gate: review\n`);
+ box.run(alpha.repo, 'shout', 'person', 'Ship the greeting?', '--decision');
+ box.run(alpha.web, 'shout', 'coordinator', 'An agent-only question?', '--decision');
+ box.run(alpha.repo, 'hold', 'web', '--reason', 'Wait for the greeting decision');
+ const view = await startView(box);
+ let snapshotHost, relayServer, chrome;
+ const profiles = [];
+ try {
+ const id = await boardId(view, alpha.repo);
+ const approved = await fetchLive(view.base + '/api/v1/boards/' + id + '/moves', {
+ method: 'POST', headers: { 'content-type': 'application/json', 'x-pullboard-key': view.key },
+ body: JSON.stringify({ verb: 'spec-approve', args: { ids: 'G5' } }),
+ });
+ assert.equal(approved.status, 200, 'the real private view records the person approval');
+ const state = await boardOf(view, alpha.repo);
+ const expected = personNeeds(state);
+ assert.deepEqual(state.needs, expected, 'the actual API carries the shared builder output after pending person decisions');
+ assert.deepEqual(expected.map(row => [row.kind, row.id, row.count ?? null]), [
+ ['decision', 1, null], ['pending', 'G3', null], ['hold', 'web', null], ['draft', 'drafts', 1],
+ ], 'agent questions and already-approved rows are excluded; the remaining draft count is exact');
+ const page = await openPage(view);
+ assert.deepEqual(JSON.parse(page.run('JSON.stringify(projectNeeds(data.project))')), expected, 'the live page uses the same builder');
+ assert.equal(needEntries(page.show('needs')).length, expected.length, 'the panel has one row per shared entry');
+ assert.deepEqual(JSON.parse(page.run('JSON.stringify((({decisions,pending,holds,drafts}) => ({decisions,pending,holds,drafts}))(boardSummary({},data.project)))')),
+ { decisions: 1, pending: 1, holds: 1, drafts: 1 }, 'summary counts describe those same entries');
+ assert.equal(page.run('document.title'), '(4) shared needs · Pullboard');
+ assert.ok(needEntries(page.show('needs')).some(row => row[3] === 'lane held by coordinator (unknown)'), 'the hold retains its human-readable attribution');
+
+ const output = join(box.dir, 'needs-export');
+ box.run(alpha.repo, 'view', '--export', output);
+ const listing = JSON.parse(readFileSync(join(output, 'api/v1/boards.json'), 'utf8'));
+ const exported = JSON.parse(readFileSync(join(output, 'api/v1/boards', listing.boards[0].id, 'state.json'), 'utf8')).state;
+ assert.deepEqual(exported.needs, expected, 'the real export carries the same calls');
+ const executable = chromeExecutable();
+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for exported and relay page parity.');
+ snapshotHost = await serveFolder(output, '/snapshot/');
+ // This transport reads the real isolated API; no board state or Needs-you result is mocked.
+ const transport = `export async function createTransport() { return { async request(path) { const reply = await fetch('/upstream' + path); if (!reply.ok) throw new Error('private board read failed'); return reply.json(); } }; }`;
+ relayServer = createServer(async (request, response) => {
+ const url = new URL(request.url, 'http://127.0.0.1');
+ try {
+ if (url.pathname === '/') return response.writeHead(200, { 'content-type': 'text/html' }).end(cockpitPage('', { readOnly: true, transportModule: '/transport.js', stylesheet: '/view.css' }));
+ if (url.pathname === '/transport.js') return response.writeHead(200, { 'content-type': 'text/javascript' }).end(transport);
+ if (url.pathname === '/view.css') return response.writeHead(200, { 'content-type': 'text/css' }).end(readFileSync(new URL('../../src/view.css', import.meta.url)));
+ if (url.pathname.startsWith('/upstream/')) {
+ const reply = await fetchLive(view.base + url.pathname.slice('/upstream'.length) + url.search, { headers: { 'x-pullboard-key': view.key } });
+ return response.writeHead(reply.status, { 'content-type': 'application/json' }).end(await reply.text());
+ }
+ response.writeHead(404).end();
+ } catch { response.writeHead(500).end('private API unavailable'); }
+ });
+ await new Promise(resolve => relayServer.listen(0, '127.0.0.1', resolve));
+ for (const [mode, address] of [['export', snapshotHost.base + '/snapshot/'], ['relay page', 'http://127.0.0.1:' + relayServer.address().port + '/']]) {
+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-shared-needs-')); profiles.push(profile);
+ chrome = await openSnapshotChrome(executable, address, profile);
+ await chrome.waitFor("data?.project?.needs?.length === 4 && document.querySelectorAll('#needs > .row').length === 4");
+ assert.deepEqual(JSON.parse(await chrome.stable('JSON.stringify(projectNeeds(data.project))')), expected, mode + ' computes identical entries');
+ assert.deepEqual(JSON.parse(await chrome.stable('JSON.stringify([...document.querySelectorAll("#needs > .row .t")].map(row => row.textContent))')),
+ ['Ship the greeting?', 'G3Choose the greeting.', 'webWait for the greeting decision', '1draft spec rows to approve or drop'], mode + ' renders the same calls');
+ assert.deepEqual(chrome.exceptions, [], mode + ' has no uncaught exception');
+ await closeSnapshotChrome(chrome); chrome = null;
+ }
+ } finally {
+ if (chrome) await closeSnapshotChrome(chrome);
+ if (relayServer) await new Promise(resolve => relayServer.close(resolve));
+ if (snapshotHost) await snapshotHost.close();
+ for (const profile of profiles) rmSync(profile, { recursive: true, force: true });
+ await view.stop();
+ }
+});
test('a decision waits in needs-you until the view answers it [B21, B26, N27]', async () => {