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): starters name only the item their add filed [S1,I1]

Corey Olson13be3447514c
diff --git a/src/blueprint-report.js b/src/blueprint-report.js
index 9d915eeb..b89a715a 100644
--- a/src/blueprint-report.js
+++ b/src/blueprint-report.js
@@ -4,25 +4,53 @@
* @typedef {object} StarterState
* @property {string} key - The starter's key in the blueprint.
* @property {string} title - The starter's title.
- * @property {boolean} filed - An item with this title is on the board.
+ * @property {boolean} filed - The blueprint's own add filed this starter on the board.
* @property {number | null} id - The filed item's id, or null when it is not filed.
* @property {string | null} status - The filed item's status, or null when it is not filed.
*/
/**
- * Each of a blueprint's starter items and whether it is on the board. A starter is filed when an
- * item carries its title; blueprint add files a starter under its title, and the title is what a
- * person reads in pullboard list. When several items share the title, a live one is named before a
- * withdrawn one, then the oldest, so a starter withdrawn and filed again shows the item in work.
+ * The row id each rule and question key of a blueprint got on this board, read from its SPEC.md
+ * section. Blueprint add numbers the rules, then the questions, in blueprint order, as the first
+ * rows of a section named after the blueprint's title; a row the person rewords or declines keeps
+ * its id, so the positions still name the same keys. Empty when the blueprint has no section here.
*
- * @param {{ items: { key: string, title: string }[] }} blueprint
+ * @param {{ title: string, rules: { key: string }[], questions: { key: string }[] }} blueprint
+ * @param {{ sections: { name: string }[], rows: { id: string, section: string }[] }} spec - loadSpec's result.
+ * @returns {Record<string, string>}
+ */
+export function blueprintRowIds(blueprint, spec) {
+ const section = spec.sections.find((entry) => /^[A-Z][A-Z0-9]*\s*[·.:-]/u.test(entry.name)
+ && entry.name.replace(/^[A-Z][A-Z0-9]*\s*[·.:-]\s*/u, '') === blueprint.title.trim());
+ if (!section) return {};
+ const rows = spec.rows.filter((row) => row.section === section.name);
+ const keys = [...blueprint.rules, ...blueprint.questions].map((entry) => entry.key);
+ return Object.fromEntries(keys.flatMap((key, index) => (rows[index] ? [[key, rows[index].id]] : [])));
+}
+
+/**
+ * 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.
+ *
+ * @param {{ 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.
* @returns {StarterState[]}
*/
-export function starterStates(blueprint, items) {
+export function starterStates(blueprint, items, rowIds) {
return blueprint.items.map((starter) => {
const title = starter.title.trim();
- const matches = items.filter((item) => item.item_title === title)
+ const cites = starter.cites ?? [];
+ const specIds = cites.map((key) => rowIds[key]).filter(Boolean).join(',');
+ const linked = 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 status = found?.item_status ?? null;
diff --git a/src/cli.js b/src/cli.js
index 176fad41..c3241304 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -63,7 +63,7 @@ import { answerQuestion, bundledBlueprints, planBlueprint, readBlueprint, saveBl
import { briefFiles } from './brief.js';
import { checkBaseline, prepareCheckBaseline, sayCheckBaseline } from './check-baseline.js';
import { retryCheckBaselines, startCheckBaseline } from './check-baseline-worker.js';
-import { starterLines, starterStates, waitingRowLines, waitingRows } from './blueprint-report.js';
+import { blueprintRowIds, starterLines, 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';
@@ -3843,7 +3843,9 @@ async function runCommand(argv, io) {
if (command === 'blueprint' && first === 'starters') {
if (!second || rest.length) throw new Refused('USAGE', `pullboard blueprint starters <name or file>; bundled: ${bundledBlueprints().join(', ')}`);
const blueprint = readBlueprint(second, io.cwd);
- const starters = withBoard(context(io), (board) => starterStates(blueprint, store.listItems(board, { all: true })));
+ 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));
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/test/blueprint.test.js b/test/blueprint.test.js
index 50ced06b..9ddfe05f 100644
--- a/test/blueprint.test.js
+++ b/test/blueprint.test.js
@@ -365,8 +365,11 @@ test('blueprint commands say what they did [S1,I1]', () => {
return { files, events: json(box, 'log').events };
};
- // Before any add, every starter is listed and none is filed.
+ // Before any add, every starter is listed and none is filed, even with an older unrelated item
+ // filed under a starter's title that cites no blueprint row (review 12394).
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');
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]));
@@ -375,7 +378,8 @@ test('blueprint commands say what they did [S1,I1]', () => {
for (const item of PUBLISHED.items) assert.ok(unfiledText.stdout.split('\n').includes(` not filed ${item.title}`), `${item.title} is listed as not filed:\n${unfiledText.stdout}`);
// A second add says it is already there, and no file byte and no board event changes.
- json(box, 'blueprint', 'add', 'web-app');
+ const firstAdd = json(box, 'blueprint', 'add', 'web-app');
+ assert.equal(firstAdd.items.length, PUBLISHED.items.length, 'the add files every starter');
const before = snapshot(box);
const again = box.run('blueprint', 'add', 'web-app');
assert.equal(again.status, 0, again.stdout + again.stderr);
@@ -387,17 +391,18 @@ test('blueprint commands say what they did [S1,I1]', () => {
assert.deepEqual(after.files, before.files, 'a second add changes no file bytes');
assert.deepEqual(after.events, before.events, 'a second add records no board event');
- // Once added, each starter is filed and names its item id and status.
- const items = json(box, 'list', '--all').items;
+ // Once added, each starter names the item its add filed, never the unrelated same-title item.
const filed = json(box, 'blueprint', 'starters', 'web-app').starters;
assert.equal(filed.length, PUBLISHED.items.length, 'every starter is listed');
const filedText = box.run('blueprint', 'starters', 'web-app').stdout.split('\n');
for (const [index, item] of PUBLISHED.items.entries()) {
- const onBoard = items.find((entry) => entry.item_title === item.title);
- assert.ok(onBoard, `${item.title} is on the board`);
- assert.deepEqual([filed[index].title, filed[index].filed, filed[index].id, filed[index].status], [item.title, true, onBoard.item_id, 'open']);
- assert.ok(filedText.includes(` #${onBoard.item_id} open ${item.title}`), `${item.title} shows its id:\n${filedText.join('\n')}`);
+ const own = firstAdd.items.find((entry) => entry.key === item.key);
+ assert.ok(own && own.id !== decoy.item_id, `${item.title} was filed by the add as its own item`);
+ assert.notEqual(filed[index].id, decoy.item_id, `${item.title} never names the unrelated item #${decoy.item_id}`);
+ assert.deepEqual([filed[index].title, filed[index].filed, filed[index].id, filed[index].status], [item.title, true, own.id, 'open']);
+ 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')}`);
// init --blueprint lists every row that waits for the person, the inherited doctrine row PB7 included.
const started = emptyRepo();