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.

fix(blueprints): blueprint add links each starter it files [S1,I1]

Corey Olson86f89b861654
diff --git a/docs/api.md b/docs/api.md
index a73e5819..31025772 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -293,7 +293,7 @@ To answer a pending question row (`<ask>: <default>. Choices: a, b.`, as `bluepr
To approve new wording, the person uses `spec approve <one-id> --text "exact proposed text"`, or `spec-approve` with `args: {ids: "G1", text: "exact proposed text"}`. This records the same exact-row receipt; files wait for coordinator apply. Text must be one nonempty line without a field separator. Pre-commit checks the staged row against that person decision or a verified staged SSH sign-off; unstaged receipts cannot authorize a commit.
-`blueprint starters <name or file>` lists a blueprint's starter items and whether each is on this board. Each entry in `starters` is `{ key, title, filed, id, status }`: a filed starter is the item that carries its title, with its id and status, and an unfiled one has `id` and `status` null. It reads the board and changes nothing. A repeat `blueprint add` of a version already on the board returns `marked: true` with empty `rows` and `items`, changes no file and records no board event. `init --blueprint` adds `blueprint.marked` and `blueprint.waitingRows`, every row that waits for the person as `{ id, status, text, file }`: the blueprint's new SPEC.md rows, then each draft or pending doctrine row, such as an inherited standard rule.
+`blueprint starters <name or file>` lists a blueprint's starter items and whether each is on this board. Each entry in `starters` is `{ key, title, filed, id, status }`: a filed starter is the item this blueprint's add filed for it, with its id and status, and an unfiled one has `id` and `status` null. When `blueprint add` files a starter it appends a `note` fact to the item, `blueprint starter: {"blueprint":"<name>","version":<version>,"key":"<key>"}`, and `blueprint starters` counts only items whose link names the same blueprint, version and starter key. An item with no such fact, filed before adds recorded one, counts only when no linked item names the starter and it carries the starter's title and cites exactly the rows that blueprint's add numbered for the starter's keys. `blueprint starters` reads the board and changes nothing. A repeat `blueprint add` of a version already on the board returns `marked: true` with empty `rows` and `items`, changes no file and records no board event. `init --blueprint` adds `blueprint.marked` and `blueprint.waitingRows`, every row that waits for the person as `{ id, status, text, file }`: the blueprint's new SPEC.md rows, then each draft or pending doctrine row, such as an inherited standard rule.
A coordinator criterion or check correction on a live claim remains pending until its holder or the coordinator runs `pullboard refreeze <id>`. Renewal and submission refuse with `PENDING_REFREEZE` until then. This refreeze keeps the holder, lease and claim base, and returns `retainedClaim: true` in JSON.
diff --git a/src/blueprint-report.js b/src/blueprint-report.js
index b89a715a..470f1499 100644
--- a/src/blueprint-report.js
+++ b/src/blueprint-report.js
@@ -28,31 +28,75 @@ export function blueprintRowIds(blueprint, spec) {
return Object.fromEntries(keys.flatMap((key, index) => (rows[index] ? [[key, rows[index].id]] : [])));
}
+/** The start of the note fact blueprint add records on each starter item it files. */
+const STARTER_LINK = 'blueprint starter: ';
+
+/**
+ * The note fact text blueprint add records on a starter item it files: the blueprint's name and
+ * version and the starter's key, as JSON after a fixed prefix. Why a fact: an item's title and
+ * citations can repeat across blueprint versions and unrelated items, so the add itself records
+ * which starter of which version this item is, and blueprint starters reads that record back.
+ *
+ * @param {{ name: string, version: number }} blueprint
+ * @param {string} key - The starter's key in the blueprint.
+ * @returns {string}
+ */
+export function starterLinkText(blueprint, key) {
+ return `${STARTER_LINK}${JSON.stringify({ blueprint: blueprint.name, version: blueprint.version, key })}`;
+}
+
+/**
+ * The starter link an item's thread records, or null when its add recorded none, as on an item
+ * filed by hand or by an add from before links were recorded.
+ *
+ * @param {{ type: string, kind?: string, text?: string }[]} thread - The item's thread, from store.itemThread.
+ * @returns {{ blueprint: string, version: number, key: string } | null}
+ */
+export function starterLink(thread) {
+ for (const entry of thread) {
+ if (entry.type !== 'fact' || entry.kind !== 'note' || !entry.text?.startsWith(STARTER_LINK)) continue;
+ try {
+ const link = JSON.parse(entry.text.slice(STARTER_LINK.length));
+ if (typeof link?.blueprint === 'string' && Number.isInteger(link.version) && typeof link.key === 'string') return link;
+ } catch (error) {
+ // A note that only starts like a link is someone's own words; it links nothing.
+ if (!(error instanceof SyntaxError)) throw error;
+ }
+ }
+ return null;
+}
+
/**
* Each of a blueprint's starter items and whether its add filed it on this board. An item is the
- * starter only when it carries the starter's title and cites exactly the rows this blueprint's add
- * gave the starter's keys, the same identity a resumed add uses to find starters already filed.
- * Why both: a title alone also names an unrelated item someone filed under the same words, and
- * that item must never be reported as the starter. A starter that cites no rows has no citation
- * to link it, so its item must also carry the starter's criterion, which add stores as written.
- * When several items match, a live one is named before a withdrawn one, then the oldest.
+ * starter when the link its add recorded names this blueprint, this version and the starter's key.
+ * An item with no recorded link at all, filed before adds recorded one, counts only when it carries
+ * the starter's title and cites exactly the rows this blueprint's add gave the starter's keys, the
+ * identity a resumed add uses; a starter that cites no rows must also match its criterion. That
+ * fallback is used only when no linked item names the starter, and an item linked to another
+ * blueprint, version or starter never counts. When several items match, a live one is named
+ * before a withdrawn one, then the oldest.
*
- * @param {{ items: { key: string, title: string, cites?: string[], criterion?: string }[] }} blueprint
+ * @param {{ name: string, version: number, items: { key: string, title: string, cites?: string[], criterion?: string }[] }} blueprint
* @param {Record<string, any>[]} items - Every item on the board, as store.listItems returns them.
* @param {Record<string, string>} rowIds - Row id by rule or question key, from blueprintRowIds.
+ * @param {Map<number, { blueprint: string, version: number, key: string } | null>} links - Each item's recorded link, by item id.
* @returns {StarterState[]}
*/
-export function starterStates(blueprint, items, rowIds) {
+export function starterStates(blueprint, items, rowIds, links) {
+ const order = (a, b) => Number(a.item_status === 'withdrawn') - Number(b.item_status === 'withdrawn') || a.item_id - b.item_id;
return blueprint.items.map((starter) => {
const title = starter.title.trim();
+ const own = items.filter((item) => {
+ const link = links.get(item.item_id);
+ return link && link.blueprint === blueprint.name && link.version === blueprint.version && link.key === starter.key;
+ });
const cites = starter.cites ?? [];
const specIds = cites.map((key) => rowIds[key]).filter(Boolean).join(',');
- const linked = cites.length
+ const cited = cites.length
? (item) => specIds.length > 0 && item.item_spec_ids === specIds
: (item) => item.item_spec_ids === '' && item.item_criterion === (starter.criterion ?? '');
- const matches = items.filter((item) => item.item_title === title && linked(item))
- .sort((a, b) => Number(a.item_status === 'withdrawn') - Number(b.item_status === 'withdrawn') || a.item_id - b.item_id);
- const found = matches[0];
+ const unlinked = items.filter((item) => !links.get(item.item_id) && item.item_title === title && cited(item));
+ const found = (own.length ? own : unlinked).sort(order)[0];
const status = found?.item_status ?? null;
return { key: starter.key, title, filed: Boolean(found), id: found?.item_id ?? null, status };
});
diff --git a/src/cli.js b/src/cli.js
index 5359405e..3fd2f5f4 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -65,7 +65,7 @@ import { briefFiles } from './brief.js';
import { commitFirst, commitOwnerLines, commitOwners, coordinatorInbox, coordinatorInboxLines, inboxFirst } from './resume.js';
import { checkBaseline, prepareCheckBaseline, sayCheckBaseline } from './check-baseline.js';
import { retryCheckBaselines, startCheckBaseline } from './check-baseline-worker.js';
-import { blueprintRowIds, starterLines, starterStates, waitingRowLines, waitingRows } from './blueprint-report.js';
+import { blueprintRowIds, starterLines, starterLink, starterLinkText, starterStates, waitingRowLines, waitingRows } from './blueprint-report.js';
import { compareMainFailures, mainRedMessage, mainRedReworkItems } from './main-red.js';
import { runItems } from './run.js';
import { parseProblems, sweepItems } from './sweep.js';
@@ -2432,6 +2432,8 @@ async function addBlueprint(ctx, board, me, blueprint, { report = true } = {}) {
item.after = afterKeys.map((before) => byKey[before]).filter(Boolean);
const id = await ordered(ctx, board, 'addItem', [item]);
byKey[key] = id;
+ // The link blueprint starters reads back: this blueprint, this version, this starter (#734).
+ await ordered(ctx, board, 'appendFact', [id, { agentId: me.id, kind: 'note', text: starterLinkText(blueprint, key) }]);
added.push({ id, key, title: item.title, lane: item.lane, ...(asked ? { askedLane: asked } : {}), specIds: item.specIds, after: item.after, ...(item.check ? { check: item.check } : {}) });
}
} catch (error) {
@@ -3861,7 +3863,10 @@ async function runCommand(argv, io) {
const blueprint = readBlueprint(second, io.cwd);
const ctx = context(io);
const rowIds = blueprintRowIds(blueprint, loadSpec(ctx.info.root, ctx.config));
- const starters = withBoard(ctx, (board) => starterStates(blueprint, store.listItems(board, { all: true }), rowIds));
+ const starters = withBoard(ctx, (board) => {
+ const items = store.listItems(board, { all: true });
+ return starterStates(blueprint, items, rowIds, new Map(items.map((item) => [item.item_id, starterLink(store.itemThread(board, item.item_id))])));
+ });
io.result?.({ blueprint: { name: blueprint.name, title: blueprint.title, version: blueprint.version }, starters });
starterLines(blueprint, starters).forEach((line) => io.say(line));
return 0;
diff --git a/src/help.js b/src/help.js
index ec271cbf..8c48fb7b 100644
--- a/src/help.js
+++ b/src/help.js
@@ -167,7 +167,7 @@ Spec
pullboard blueprint save [file] [--name <name>] [--title "<title>"] write approved rules and answered questions as a blueprint
never items, notes, paths, emails or names; file defaults to <project>.blueprint.json
pullboard blueprint starters <name or file> list a blueprint's starter items and whether each is filed
- a filed starter shows its item id and status
+ a filed starter shows its item id and status; add links each starter it files with a note fact
pullboard spec signers add [--key <path>] [--by <principal>] opt into SSH-signed sign-offs
principal defaults to Git user.email; --by overrides it
pullboard spec approve <ids> | decline <ids> --reason "why" the person's exact-row decision
diff --git a/test/blueprint.test.js b/test/blueprint.test.js
index 6873ccba..f388e909 100644
--- a/test/blueprint.test.js
+++ b/test/blueprint.test.js
@@ -430,6 +430,10 @@ test('blueprint commands say what they did [S1,I1]', () => {
const box = freshBoard();
const decoy = json(box, 'add', 'coordinator', PUBLISHED.items[0].title).item;
assert.equal(decoy.item_spec_ids ?? '', '', 'the unrelated item cites no row');
+ // A row that exists before the add, and an older item under another starter's title citing it.
+ const existingRow = json(box, 'spec', 'draft', 'A requirement written before the blueprint').id;
+ const citing = json(box, 'add', 'coordinator', PUBLISHED.items[1].title, '--specs', existingRow).item;
+ assert.equal(citing.item_spec_ids, existingRow, 'the second unrelated item cites the row that was there first');
const unfiled = json(box, 'blueprint', 'starters', 'web-app');
assert.deepEqual(unfiled.blueprint, { name: 'web-app', title: 'Web app', version: 1 });
assert.deepEqual(unfiled.starters.map((starter) => [starter.title, starter.filed, starter.id]), PUBLISHED.items.map((item) => [item.title, false, null]));
@@ -463,6 +467,20 @@ test('blueprint commands say what they did [S1,I1]', () => {
assert.ok(filedText.includes(` #${own.id} open ${item.title}`), `${item.title} shows its id:\n${filedText.join('\n')}`);
}
assert.ok(!filedText.some((line) => line.startsWith(` #${decoy.item_id} `)), `the unrelated item is never listed:\n${filedText.join('\n')}`);
+ assert.ok(!filed.some((starter) => starter.id === citing.item_id), 'an item citing a row from before the add is never the starter');
+
+ // Two versions of one blueprint, the same title and starter: each version names the item it filed.
+ const versioned = join(box.dir, 'versioned.json');
+ const firstVersion = { ...PUBLISHED, name: 'versioned', title: 'Versioned plan', version: 1, items: [PUBLISHED.items[0]] };
+ writeFileSync(versioned, JSON.stringify(firstVersion));
+ const one = json(box, 'blueprint', 'add', versioned).items[0];
+ writeFileSync(versioned, JSON.stringify({ ...firstVersion, version: 2 }));
+ const two = json(box, 'blueprint', 'add', versioned).items[0];
+ assert.notEqual(two.id, one.id, 'version 2 files its own starter');
+ const forTwo = json(box, 'blueprint', 'starters', versioned);
+ assert.deepEqual([forTwo.blueprint.version, forTwo.starters[0].id], [2, two.id], 'version 2 names the item version 2 filed');
+ writeFileSync(versioned, JSON.stringify(firstVersion));
+ assert.equal(json(box, 'blueprint', 'starters', versioned).starters[0].id, one.id, 'version 1 names the item version 1 filed');
// init --blueprint lists every row that waits for the person, the inherited doctrine row PB7 included.
const started = emptyRepo();