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(cli): retain specific refusal recovery footers [P4,I1,I2,V1]

Corey Olson6ebc9cdfb6de
diff --git a/src/cli.js b/src/cli.js
index 3bddb06f..01a93f9d 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -850,14 +850,15 @@ function agentRefusalText(message, code, name) {
return patterns[code] ? message.replace(patterns[code], (_, before, id, after) => `${before}${name(id)}${after}`) : message;
}
-/** Read current display settings for text refusals; the structured error retains its stable identifiers. */
+/** Render the refusal body without its existing final footer; structured errors retain the message. */
function displayedRefusal(io, error) {
- if (!['ALREADY_JOINED', 'HELD', 'ITEM_HELD', 'LANE_HELD', 'REVIEW_HELD', 'NOT_YOURS', 'NOT_YOUR_DECISION', 'NO_AGENT', 'NOT_YOUR_CHECKOUT', 'FACT_JUDGEMENT', 'RELAY_PERSON_ONLY', 'RELAY_SENDER_MISMATCH', 'SELF_SHOUT', 'NO_READER'].includes(error.code)) return error.message;
+ const message = error.message.replace(/\r?\nnext:[ \t]*[^\r\n]*\S[ \t]*(?:\r?\n)*$/u, '');
+ if (!['ALREADY_JOINED', 'HELD', 'ITEM_HELD', 'LANE_HELD', 'REVIEW_HELD', 'NOT_YOURS', 'NOT_YOUR_DECISION', 'NO_AGENT', 'NOT_YOUR_CHECKOUT', 'FACT_JUDGEMENT', 'RELAY_PERSON_ONLY', 'RELAY_SENDER_MISMATCH', 'SELF_SHOUT', 'NO_READER'].includes(error.code)) return message;
try {
const ctx = context(io);
const agents = withBoard(ctx, (board) => store.listAgents(board));
- return agentRefusalText(error.message, error.code, (id) => agentDisplayName(agents, ctx.config, id));
- } catch { return error.message; }
+ return agentRefusalText(message, error.code, (id) => agentDisplayName(agents, ctx.config, id));
+ } catch { return message; }
}
/** Label the holder at the start of a generated wait reason without rewriting its quoted reason. */
diff --git a/src/next-steps.js b/src/next-steps.js
index ffa34e60..44098f29 100644
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@ -359,8 +359,8 @@ function stepInMessage(message) {
}
/**
- * The next step for one refusal: the step its raise site passed, else the one its message spells
- * out, else this code's row. Unknown remote codes ask the service owner about the displayed refusal.
+ * The next step for one refusal: its existing final next line, else the step its raise site passed,
+ * else prose guidance or this code's row. Unknown remote codes name the service owner and rule.
*
* @param {{ code?: string, next?: string } | null | undefined} error
* @param {string} message
@@ -368,6 +368,8 @@ function stepInMessage(message) {
*/
export function nextStepFor(error, message) {
const code = typeof error?.code === 'string' ? error.code : '';
+ const finalStep = /(?:^|\r?\n)next:[ \t]*([^\r\n]*\S)[ \t]*(?:\r?\n)*$/u.exec(String(message))?.[1];
+ if (finalStep) return finalStep.trim();
if (typeof error?.next === 'string' && error.next.trim()) return error.next.trim();
if (code === 'SPEC_BEHIND_MAIN') return NEXT_STEPS.SPEC_BEHIND_MAIN;
return stepInMessage(message) ?? NEXT_STEPS[code]
diff --git a/test/main-red.test.js b/test/main-red.test.js
index 6438e506..faced5f1 100644
--- a/test/main-red.test.js
+++ b/test/main-red.test.js
@@ -113,6 +113,7 @@ function inheritedMessage(result, { row, item, testFile = 'test/inherited.test.j
if (row && item) {
assert.match(result.err, new RegExp(`approved row ${row} .*open rework #${item} owns it`, 'u'));
assert.ok(result.err.trimEnd().endsWith(`next: land #${item} first, then submit again`));
+ assert.equal((result.err.match(/^next: /gmu) ?? []).length, 1, 'the specific recovery is printed once');
} else {
assert.doesNotMatch(result.err, /approved row|open rework #\d+/u);
}
diff --git a/test/refusal-next-steps.test.js b/test/refusal-next-steps.test.js
index 31ec205e..885c6319 100644
--- a/test/refusal-next-steps.test.js
+++ b/test/refusal-next-steps.test.js
@@ -44,6 +44,21 @@ test('every refusal names a next step that works [P4,I1,I2]', async () => {
assert.equal(refusalDocument(new Refused('REMOTE_COORDINATOR_MODEL',
"the coordinator's model is declared on its own checkout; run pullboard join coordinator there")).error.next,
'run pullboard join coordinator there', 'a coordinator description does not hide the later recovery action');
+ assert.equal(refusalDocument(new Refused('PENDING_REFREEZE',
+ 'item #12 has a pending correction.\nnext: pullboard refreeze 12')).error.next,
+ 'pullboard refreeze 12', 'an existing specific next line survives serialization');
+ assert.equal(refusalDocument(new Refused('GATE_RED',
+ 'the submission proof is red.\nnext: land #12 first, then submit again', 'fix the gate and retry')).error.next,
+ 'land #12 first, then submit again', 'an inherited failure retains its specific recovery');
+ assert.equal(refusalDocument(new Refused('GATE_RED',
+ 'the submission proof is red.\nnext: land #12 first, then submit again')).error.message,
+ 'the submission proof is red.\nnext: land #12 first, then submit again', 'JSON retains the original message');
+ assert.equal(refusalDocument(new Refused('GATE_RED',
+ 'reported output:\nnext: an unrelated printed line\nend of report', 'repair this fixture')).error.next,
+ 'repair this fixture', 'nonterminal report text cannot override contextual recovery');
+ assert.equal(refusalDocument(new Refused('GATE_RED',
+ 'the submission proof is red.', 'repair this fixture, commit, and submit again')).error.next,
+ 'repair this fixture, commit, and submit again', 'contextual recovery remains explicit without a message next line');
const box = e2e.sandbox();
box.env.PULLBOARD_MODEL = 'Refusal Fixture Model';
@@ -85,6 +100,7 @@ test('every refusal names a next step that works [P4,I1,I2]', async () => {
assert.equal((red.err.match(/\[GATE_RED\]/gu) ?? []).length, 1, `${red.out}\n${red.err}`);
assert.equal((red.err.match(/GATE_FAILURE_MARKER/gu) ?? []).length, 1, `the failure report appears once\n${red.out}\n${red.err}`);
assert.match(red.err, /next: .*fix.*commit.*submit/iu);
+ assert.equal((red.err.match(/^next: /gmu) ?? []).length, 1, 'plain refusals print one recovery footer');
rmSync(join(gateWeb, 'web', 'RED'));
gateBox.git(gateWeb, 'add', '-u');
gateBox.git(gateWeb, 'commit', '-q', '-m', 'test: fix gate fixture [G1]');