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(spec): approving an answered row keeps the answer [S1,E3]

Corey Olsonc08d953e2845
diff --git a/src/cli.js b/src/cli.js
index ccf54309..0bbfffdd 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -17,7 +17,7 @@ import { doctrineHistory, loadDoctrine } from './doctrine.js';
import { checkRulesAt, doctrineReport, hasSubmitRules, holdDoctrine, ruleLine } from './doctrine-checks.js';
import { agentSessionDigest, requirePersonChannel } from './person.js';
import { bindLocalSession, localSessionMatches } from './agent-session.js';
-import { decisionAnswer, decisionProjection, handAnsweredQuestions, planRowApply, prepareRowDecisions, restoreRowApply, writeRowApply } from './row-decisions.js';
+import { decisionAnswer, decisionProjection, handAnsweredQuestions, pendingAnswers, planRowApply, prepareRowDecisions, restoreRowApply, writeRowApply } from './row-decisions.js';
import { digestOf, gateReport, refuseSandboxBlocked, runGate, runProfiledShell, runSubmitGate, submitGateReport, timingDigest, withGateSlot } from './gate.js';
import { checkNeedsBrowser } from './browser-admission.js';
import { bareWorktreeFinding, codeIsFromMain, contains, differFromHead, git, gitChildEnv, headCommit, headTree, invalidateGitFacts, isClean, mainCheckout, patchId, repoInfo, resolveCommit, tryGit, untracked, withGitFacts } from './git.js';
@@ -3422,10 +3422,19 @@ async function specCommand(io, { first, second, rest, values }) {
const me = whoAmI(ctx, board);
if (!ctx.info.isMain || me.id !== COORDINATOR) throw new Refused('B26_PERSON_APPROVAL', 'only the person from the main checkout approves or declines rows; use pullboard view for the person to decide');
const ids = [second, ...rest].filter(Boolean).flatMap((text) => text.split(/[\s,]+/u)).filter(Boolean);
- const records = prepareRowDecisions(ctx.info.root, ctx.config, { ids, decision: first, reason: values.reason, text: values.text, by: values.by, on: new Date().toISOString(), commit: headCommit(ctx.info.root) ?? '' });
+ // An approve keeps a pending answer: plain, it approves the answered text; --text says what it replaces.
+ const kept = first === 'approve' ? pendingAnswers(ctx.info.root, ctx.config, ids, store.rowDecisions(board)) : new Map();
+ const decide = { decision: first, reason: values.reason, by: values.by, on: new Date().toISOString(), commit: headCommit(ctx.info.root) ?? '' };
+ const records = values.text === undefined && kept.size ? ids.flatMap((id) => prepareRowDecisions(ctx.info.root, ctx.config, { ...decide, ids: [id], text: kept.get(id)?.text }))
+ : prepareRowDecisions(ctx.info.root, ctx.config, { ...decide, ids, text: values.text });
const decisions = await ordered(ctx, board, 'recordRowDecisions', [{ agentId: store.PERSON, channel: io.personChannel ?? 'terminal', decisions: records }]);
io.result?.({ decisions });
- decisions.forEach((record) => io.say(`${record.kind === 'doctrine' ? 'doctrine:' : ''}${record.id}: ${first === 'approve' ? 'approved' : 'declined'}, pending apply`));
+ decisions.forEach((record) => {
+ const old = record.kind === 'spec' ? kept.get(record.id) : undefined;
+ const now = decisionAnswer(record);
+ if (old && old.text !== record.text) io.say(`${record.id}: this text replaces the pending answer ${old.answer} with ${now === null ? `"${record.text}"` : `the answer ${now}`}`);
+ io.say(`${record.kind === 'doctrine' ? 'doctrine:' : ''}${record.id}: ${first === 'approve' ? (old && old.text === record.text ? `approved with the answer ${old.answer}` : 'approved') : 'declined'}, pending apply`);
+ });
return 0;
});
}
diff --git a/src/row-decisions.js b/src/row-decisions.js
index 3357325c..e7addd9a 100644
--- a/src/row-decisions.js
+++ b/src/row-decisions.js
@@ -45,6 +45,27 @@ export function prepareRowDecisions(root, config, { ids, decision, reason = '',
});
}
+/**
+ * The pending answers the named spec rows carry, by id: each answer's signed text and the answer
+ * read back from it. Why: an approve without --text approves the answered text, so a person who
+ * answers a question and then approves it keeps their answer instead of the original default [S1,P6].
+ *
+ * @param {string} root
+ * @param {any} config
+ * @param {string[]} ids - The ids named to approve; doctrine ids carry no answer.
+ * @param {any[]} records - The board's current row decisions.
+ * @returns {Map<string, { text: string, answer: string }>}
+ */
+export function pendingAnswers(root, config, ids, records) {
+ const { rows } = loadSpec(root, config);
+ return new Map(ids.filter((id) => !id.startsWith('doctrine:')).flatMap((id) => {
+ const matches = rows.filter((row) => row.id === id);
+ const record = matches.length === 1 ? pendingRowDecision(records, matches[0], 'spec') : undefined;
+ const answer = record ? decisionAnswer(record) : null;
+ return answer === null ? [] : [[id, { text: record.text, answer }]];
+ }));
+}
+
/** Compare a decision with the current row, excluding inherited standard rows from file edits. */
export function pendingRowDecision(records, row, kind) {
return records.find((record) => record.kind === kind && record.id === row.id && !record.applied
diff --git a/test/spec.test.js b/test/spec.test.js
index e3dc5785..4eaa14b6 100644
--- a/test/spec.test.js
+++ b/test/spec.test.js
@@ -604,6 +604,48 @@ test("spec answer records the person's choice [S1,E3,P6]", (t) => {
assert.notEqual(error.next, RECORDED_GENERIC_NEXT);
});
+test('approving an answered row keeps the answer [S1,E3]', (t) => {
+ const box = specBox(t, { specSource: QUESTION_SPEC });
+ const line = (id) => readFileSync(join(box.root, box.specName), 'utf8').split('\n').find((text) => text.startsWith(`- ${id} `));
+ assert.equal(box.run('answer', 'B1', 'Postgres').status, 0);
+ assert.equal(box.run('answer', 'B2', 'Redis on the host').status, 0);
+ const agent = runIn(box, box.root, ['spec', 'approve', 'B1', '--json'], { ...box.env, CLAUDECODE: '1' });
+ assert.equal(JSON.parse(agent.stdout).error.code, 'B26_PERSON_CHANNEL', 'an agent still cannot approve an answered row');
+ const approved = box.run('approve', 'B1', 'B2', 'B3');
+ assert.equal(approved.status, 0, approved.stdout + approved.stderr);
+ const shown = box.run('show', 'B1').stdout;
+ const applied = box.run('apply');
+ assert.equal(applied.status, 0, applied.stdout + applied.stderr);
+ assert.equal(line('B1'), '- B1 [approved, must] Which store holds the data: Postgres. Choices: SQLite, Postgres. | gate: review',
+ 'apply writes the answered choice');
+ assert.doesNotMatch(line('B1'), /data: SQLite\./u, 'the original default is gone');
+ assert.equal(line('B2'), '- B2 [approved, must] Which store holds the cache: Redis on the host. Choices: SQLite, Postgres, Redis on the host. | gate: review');
+ assert.equal(line('B3'), '- B3 [approved, must] Which store holds the logs: SQLite. Choices: SQLite, Postgres. | gate: review');
+ assert.match(shown, /answered Postgres, pending apply/u, 'spec show still names the pending answer');
+ assert.match(approved.stdout, /^B1: approved with the answer Postgres, pending apply$/mu, 'the approve names the answer it keeps');
+ assert.match(approved.stdout, /^B2: approved with the answer Redis on the host, pending apply$/mu);
+ assert.match(approved.stdout, /^B3: approved, pending apply$/mu, 'a row with no answer approves as it reads');
+});
+
+test('approve --text names the answer it replaces [S1,E3]', (t) => {
+ const box = specBox(t, { specSource: QUESTION_SPEC });
+ const line = (id) => readFileSync(join(box.root, box.specName), 'utf8').split('\n').find((text) => text.startsWith(`- ${id} `));
+ assert.equal(box.run('answer', 'B1', 'Postgres').status, 0);
+ assert.equal(box.run('answer', 'B2', 'Postgres').status, 0);
+ const choice = box.run('approve', 'B1', '--text', 'Which store holds the data: SQLite. Choices: SQLite, Postgres.');
+ assert.equal(choice.status, 0, choice.stdout + choice.stderr);
+ assert.match(choice.stdout, /^B1: this text replaces the pending answer Postgres with the answer SQLite$/mu, 'both answers are named');
+ const free = box.run('approve', 'B2', '--text', 'The cache lives in memory.');
+ assert.equal(free.status, 0, free.stdout + free.stderr);
+ assert.match(free.stdout, /^B2: this text replaces the pending answer Postgres with "The cache lives in memory\."$/mu, 'a text that is no answer is named whole');
+ assert.equal(box.run('answer', 'B3', 'Postgres').status, 0);
+ const same = box.run('approve', 'B3', '--text', 'Which store holds the logs: Postgres. Choices: SQLite, Postgres.');
+ assert.doesNotMatch(same.stdout, /replaces/u, 'the same text as the answer replaces nothing');
+ assert.equal(box.run('apply').status, 0);
+ assert.equal(line('B1'), '- B1 [approved, must] Which store holds the data: SQLite. Choices: SQLite, Postgres. | gate: review', 'the --text wins');
+ assert.equal(line('B2'), '- B2 [approved, must] The cache lives in memory. | gate: review');
+});
+
test('an agent cannot answer a pending row [P6,B26,E3]', (t) => {
const box = specBox(t, { specSource: QUESTION_SPEC });
const file = join(box.root, box.specName);