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(products): products group spec rows, beside lanes [S11,S12]

Corey Olsond4d8e0875bd7
diff --git a/src/cli.js b/src/cli.js
index 1f93ee67..ef531621 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -20,6 +20,7 @@ import {
prePushProblems,
} from './hooks.js';
import { initRepo } from './init.js';
+import { productLine, productProblems, productSummaries } from './products.js';
import { isLane, laneNames, laneOf, outOfLane } from './lanes.js';
import { Refused } from './refused.js';
import { commitCitations, committedIds } from './history.js';
@@ -697,6 +698,10 @@ function readCommands(io, { first, values }) {
io.say(`${summary.me.id}: ${summary.unread} unread shouts; holding ${summary.mine.map((item) => `#${item.item_id}`).join(', ') || 'nothing'}`);
io.say(`board: ${items.open} open, ${items.claimed} claimed, ${items.submitted} awaiting verification, ${items.verified} verified, ${items.withdrawn} withdrawn`);
io.say(`verdicts: ${accepted} accepted, ${rejected} rejected`);
+ if (Object.keys(ctx.config.products).length) {
+ const all = withBoard(ctx, (board) => store.listItems(board, { all: true }));
+ productSummaries(ctx.config, loadSpec(ctx.info.root, ctx.config), all).forEach((product) => io.say(productLine(product)));
+ }
return 0;
},
inbox: () => {
@@ -1138,6 +1143,9 @@ function specCommand(io, { first, second, rest, values }) {
errors += fileErrors;
io.say(`${name}: ${parsed.rows.length} rows, ${fileErrors} errors, ${findings.length + lost.length - fileErrors} warnings`);
}
+ const unnamed = productProblems(ctx.config, spec);
+ unnamed.forEach((problem) => io.say(`${ctx.config.spec}: error: ${problem}`));
+ errors += unnamed.length;
return errors ? 1 : 0;
}
const signoffs = readSignoffs(ctx.info.root);
diff --git a/src/config.js b/src/config.js
index 885a4957..83e62e24 100644
--- a/src/config.js
+++ b/src/config.js
@@ -39,6 +39,7 @@ export function defaults() {
lease: '2h',
verify: 'any',
lanes: {},
+ products: {},
shared: [],
fix: [],
commits: {
@@ -141,6 +142,14 @@ export function configProblems(config) {
} else {
for (const [name, lane] of Object.entries(config.lanes)) problems.push(...laneProblems(name, lane));
}
+ const products = config.products;
+ if (typeof products !== 'object' || products === null || Array.isArray(products)) {
+ problems.push('"products" maps product names to lists of spec ids or section letters, like { "CLI": ["B", "N26"] }');
+ } else {
+ for (const [name, entries] of Object.entries(products)) {
+ if (!name.trim() || !isStringList(entries) || !entries.length) problems.push(`product "${name}": a list of spec ids or section letters, like ["B", "N26"]`);
+ }
+ }
if (!isStringList(config.commits.types)) problems.push('"commits.types" is a list of words');
if (!isStringList(config.commits.requireIds)) problems.push('"commits.requireIds" is a list of types');
if (!isStringList(config.commits.banned)) problems.push('"commits.banned" is a list of words');
diff --git a/src/products.js b/src/products.js
new file mode 100644
index 00000000..137c39f7
--- /dev/null
+++ b/src/products.js
@@ -0,0 +1,129 @@
+/**
+ * Products: named groups of spec rows, declared in pullboard.json beside the lanes (S11).
+ *
+ * Nothing stores which product a row, an item or a lane belongs to. It is read from the spec and
+ * the config each time (S12), so changing a product's list moves everything that depends on it at
+ * once, and no copy can drift.
+ */
+
+/** Spec statuses that leave a row out of a product's count: decided against, or no longer in force. */
+const OUT_OF_FORCE = ['wont', 'retired'];
+
+/**
+ * True when a product's or a lane's entry names this spec id: the id itself and its sub-ids (N26
+ * names N26 and N26.1), or a whole section by its letters (B names B1 to B16, not BX1).
+ *
+ * @param {string} entry
+ * @param {string} id
+ * @returns {boolean}
+ */
+export function names(entry, id) {
+ if (/^[A-Za-z]+$/.test(entry)) return /^[A-Za-z]+/.exec(id)?.[0] === entry;
+ return id === entry || id.startsWith(`${entry}.`);
+}
+
+/**
+ * The spec ids an item cites.
+ *
+ * @param {any} item
+ * @returns {string[]}
+ */
+const citedBy = (item) => (item.item_spec_ids ?? '').split(',').filter(Boolean);
+
+/**
+ * The products that name any of these spec ids, in the order pullboard.json declares them.
+ *
+ * @param {any} config
+ * @param {string[]} ids
+ * @returns {string[]}
+ */
+function productsNaming(config, ids) {
+ return Object.entries(config.products ?? {})
+ .filter(([, entries]) => ids.some((id) => entries.some((entry) => names(entry, id))))
+ .map(([name]) => name);
+}
+
+/**
+ * The products a spec row belongs to.
+ *
+ * @param {any} config
+ * @param {string} id
+ * @returns {string[]}
+ */
+export function productsOfRow(config, id) {
+ return productsNaming(config, [id]);
+}
+
+/**
+ * The products an item belongs to: those of the rows it cites.
+ *
+ * @param {any} config
+ * @param {any} item
+ * @returns {string[]}
+ */
+export function productsOfItem(config, item) {
+ return productsNaming(config, citedBy(item));
+}
+
+/**
+ * The products a lane works for: those that name a row the lane's own spec list names.
+ *
+ * @param {any} config
+ * @param {{ rows: { id: string }[] }} spec
+ * @param {string} lane
+ * @returns {string[]}
+ */
+export function productsOfLane(config, spec, lane) {
+ const entries = config.lanes?.[lane]?.specs ?? [];
+ return productsNaming(config, spec.rows.filter((row) => entries.some((entry) => names(entry, row.id))).map((row) => row.id));
+}
+
+/**
+ * Each product's standing: its rows in force, how many are approved, how many an accepted item
+ * cites, and its items by state. Withdrawn items are left out.
+ *
+ * @param {any} config
+ * @param {{ rows: { id: string, status: string }[] }} spec
+ * @param {any[]} items - As the board lists them, with lapsed claims read as open.
+ * @returns {{ name: string, rows: number, approved: number, proven: number, items: { open: number, claimed: number, submitted: number, verified: number } }[]}
+ */
+export function productSummaries(config, spec, items) {
+ return Object.entries(config.products ?? {}).map(([name, entries]) => {
+ const rows = spec.rows.filter((row) => !OUT_OF_FORCE.includes(row.status) && entries.some((entry) => names(entry, row.id)));
+ const ids = new Set(rows.map((row) => row.id));
+ const mine = items.filter((item) => citedBy(item).some((id) => ids.has(id)));
+ const accepted = items.filter((item) => item.item_status === 'verified');
+ const count = (state) => mine.filter((item) => item.item_status === state).length;
+ return {
+ name,
+ rows: rows.length,
+ approved: rows.filter((row) => row.status === 'approved').length,
+ proven: rows.filter((row) => accepted.some((item) => citedBy(item).includes(row.id))).length,
+ items: { open: count('open'), claimed: count('claimed'), submitted: count('submitted'), verified: count('verified') },
+ };
+ });
+}
+
+/**
+ * Every entry in a product's list that names no row of the spec, so a typo cannot quietly leave
+ * rows out of a product.
+ *
+ * @param {any} config
+ * @param {{ rows: { id: string }[] }} spec
+ * @returns {string[]}
+ */
+export function productProblems(config, spec) {
+ return Object.entries(config.products ?? {}).flatMap(([name, entries]) =>
+ entries.filter((entry) => !spec.rows.some((row) => names(entry, row.id))).map((entry) => `product "${name}": "${entry}" names no row in the spec`),
+ );
+}
+
+/**
+ * One product's standing as a line of text.
+ *
+ * @param {ReturnType<typeof productSummaries>[number]} product
+ * @returns {string}
+ */
+export function productLine({ name, rows, approved, proven, items }) {
+ return `product ${name}: ${rows} rows, ${approved} approved, ${proven} cited by accepted items; items ${items.open} open, ${items.claimed} building, ${items.submitted} awaiting verification, ${items.verified} verified`;
+}
diff --git a/test/products.test.js b/test/products.test.js
new file mode 100644
index 00000000..96dba528
--- /dev/null
+++ b/test/products.test.js
@@ -0,0 +1,162 @@
+/**
+ * Products (S11, S12): named groups of spec rows in pullboard.json. Which product a row, an item or
+ * a lane belongs to is read from the spec each time; status prints each product's standing, and
+ * spec check catches an entry that names no row.
+ */
+import assert from 'node:assert/strict';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+import { after, test } from 'node:test';
+import * as store from '../src/board.js';
+import { configProblems, defaults } from '../src/config.js';
+import { names, productProblems, productsOfItem, productsOfLane, productsOfRow, productSummaries } from '../src/products.js';
+import { parseSpec } from '../src/spec.js';
+
+const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
+const SHA = 'a'.repeat(40);
+
+const SPEC = `# Demo spec
+
+## B · Board
+- B1 [approved, must] Claims are leases. | gate: test
+- B2 [draft, must] Two agents never hold one item.
+- B3 [wont] Items can be deleted.
+
+## BX · Extras
+- BX1 [draft, must] A row in a section whose letters start the same.
+
+## N · Commands
+- N1 [approved, must] next claims work. | gate: test
+- N26 [draft, must] The view lists projects.
+- N26.1 [draft, aim] The view lists them in a sidebar.
+`;
+
+const PRODUCTS = { Core: ['B', 'N1'], View: ['N26'] };
+
+const CONFIG = {
+ ...defaults(),
+ gate: 'true',
+ lanes: { board: { owns: ['src/'], specs: ['B'] }, web: { owns: ['web/'], specs: ['N26'] } },
+ products: PRODUCTS,
+};
+
+const dirs = [];
+after(() => {
+ for (const dir of dirs) rmSync(dir, { recursive: true, force: true });
+});
+
+/**
+ * A freeze that digests the title, as the real one digests the criterion.
+ *
+ * @param {any} item
+ * @returns {{ text: string, digest: string }}
+ */
+const freeze = (item) => ({ text: item.item_title, digest: `digest:${item.item_title}` });
+
+test('an entry names a row by its id and sub-ids, or a whole section by its letters [S11]', () => {
+ assert.equal(names('B', 'B1'), true);
+ assert.equal(names('B', 'B16'), true);
+ assert.equal(names('B', 'BX1'), false, 'section letters name their own section only');
+ assert.equal(names('N26', 'N26'), true);
+ assert.equal(names('N26', 'N26.1'), true, 'an id names its sub-ids');
+ assert.equal(names('N26', 'N261'), false);
+ assert.equal(names('N2', 'N26'), false);
+});
+
+test('rows, items and lanes belong to the products that name them, and nothing stores it [S12]', () => {
+ const spec = parseSpec(SPEC);
+ assert.deepEqual(productsOfRow(CONFIG, 'B2'), ['Core']);
+ assert.deepEqual(productsOfRow(CONFIG, 'N26.1'), ['View']);
+ assert.deepEqual(productsOfRow(CONFIG, 'BX1'), []);
+ assert.deepEqual(productsOfItem(CONFIG, { item_spec_ids: 'B1,N26' }), ['Core', 'View']);
+ assert.deepEqual(productsOfItem(CONFIG, { item_spec_ids: '' }), []);
+ assert.deepEqual(productsOfLane(CONFIG, spec, 'board'), ['Core']);
+ assert.deepEqual(productsOfLane(CONFIG, spec, 'web'), ['View']);
+ const moved = { ...CONFIG, products: { Core: ['B', 'N1', 'N26'], View: [] } };
+ assert.deepEqual(productsOfItem(moved, { item_spec_ids: 'N26.1' }), ['Core'], 'changing the list moves the item, with nothing else to update');
+ assert.deepEqual(productsOfLane(moved, spec, 'web'), ['Core']);
+});
+
+test('config refuses products that are not named lists of spec ids or section letters [S11]', () => {
+ const problems = (products) => configProblems({ ...defaults(), products });
+ assert.deepEqual(problems({ Core: ['B'] }).filter((problem) => problem.includes('product')), []);
+ assert.ok(problems(['B']).some((problem) => problem.startsWith('"products" maps product names')));
+ assert.ok(problems({ Core: 'B' }).some((problem) => problem.startsWith('product "Core"')));
+ assert.ok(problems({ Core: [] }).some((problem) => problem.startsWith('product "Core"')));
+ assert.ok(problems({ Core: ['B', 7] }).some((problem) => problem.startsWith('product "Core"')));
+ assert.deepEqual(productProblems({ products: { Core: ['B', 'Q9'] } }, parseSpec(SPEC)), ['product "Core": "Q9" names no row in the spec']);
+});
+
+test('in a real repo, status prints each product, and spec check fails on an entry that names no row [S11, S12]', () => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-products-')));
+ dirs.push(dir);
+ const repo = join(dir, 'repo');
+ mkdirSync(repo);
+ const env = {
+ ...process.env,
+ GIT_CONFIG_GLOBAL: '/dev/null',
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'Test Agent',
+ GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Test Agent',
+ GIT_COMMITTER_EMAIL: '[email protected]',
+ PULLBOARD_HOME: join(dir, 'home'),
+ };
+ const git = (...args) => execFileSync('git', args, { cwd: repo, env, encoding: 'utf8', stdio: 'pipe' });
+ const run = (...args) => spawnSync(process.execPath, [BIN, ...args], { cwd: repo, env, encoding: 'utf8' });
+ const writeConfig = (products) => writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ gate: 'true', lanes: CONFIG.lanes, products }, null, 2));
+ git('init', '-q', '-b', 'main');
+ writeConfig(PRODUCTS);
+ writeFileSync(join(repo, 'SPEC.md'), SPEC);
+ git('add', '-A');
+ git('commit', '-q', '-m', 'chore: a spec with two products');
+
+ const board = store.openBoard(join(repo, '.git', 'pullboard', 'board.sqlite'));
+ try {
+ store.register(board, { lane: 'coordinator', path: repo });
+ store.register(board, { lane: 'board', path: join(dir, 'board-1') });
+ store.register(board, { lane: 'web', path: join(dir, 'web-1') });
+ const add = (lane, title, specs) => store.addItem(board, { by: 'coordinator', lane, title, specIds: specs });
+ const claim = (id, agentId, lane) => store.claim(board, id, { agentId, lane, leaseMs: 7_200_000, freeze });
+ const leases = add('board', 'Leases', ['B1']);
+ claim(leases, 'board-1', 'board');
+ store.submit(board, leases, { agentId: 'board-1', commit: SHA, tree: 't' });
+ store.verify(board, leases, { agentId: 'web-1', decision: 'ACCEPT', head: SHA, digest: 'digest:Leases', policy: 'any', note: 'reverted the lease check; its test went red; restored' });
+ claim(add('board', 'Holders', ['B2']), 'board-1', 'board');
+ const sidebar = add('web', 'Sidebar', ['N26.1']);
+ claim(sidebar, 'web-1', 'web');
+ store.submit(board, sidebar, { agentId: 'web-1', commit: SHA, tree: 't' });
+ add('web', 'Projects', ['N26']);
+ add('board', 'Next', ['N1']);
+ } finally {
+ store.closeBoard(board);
+ }
+
+ const status = run('status');
+ assert.equal(status.status, 0, status.stderr);
+ assert.match(status.stdout, /^product Core: 3 rows, 2 approved, 1 cited by accepted items; items 1 open, 1 building, 0 awaiting verification, 1 verified$/m);
+ assert.match(status.stdout, /^product View: 2 rows, 0 approved, 0 cited by accepted items; items 1 open, 0 building, 1 awaiting verification, 0 verified$/m);
+
+ assert.equal(run('spec', 'check').status, 0);
+ writeConfig({ ...PRODUCTS, View: ['N26', 'Q9'] });
+ const typo = run('spec', 'check');
+ assert.equal(typo.status, 1);
+ assert.match(typo.stdout, /error: product "View": "Q9" names no row in the spec/);
+
+ writeConfig({});
+ assert.doesNotMatch(run('status').stdout, /^product /m, 'no products, no product lines');
+});
+
+test('a product counts rows in force only, and items by the state the board reads [S12]', () => {
+ const spec = parseSpec(SPEC);
+ const items = [
+ { item_spec_ids: 'B1', item_status: 'verified' },
+ { item_spec_ids: 'B3', item_status: 'open' },
+ { item_spec_ids: 'N26', item_status: 'withdrawn' },
+ ];
+ const [core, view] = productSummaries(CONFIG, spec, items);
+ assert.deepEqual(core, { name: 'Core', rows: 3, approved: 2, proven: 1, items: { open: 0, claimed: 0, submitted: 0, verified: 1 } }, 'B3 is wont: out of the rows, and the item citing only it is out too');
+ assert.deepEqual(view.items, { open: 0, claimed: 0, submitted: 0, verified: 0 }, 'withdrawn items are left out');
+});