Fix #11: a rewrite prompt keeps its FAIL issues under hook header lines

The rewrite marker was only recognised as the first thing in the prompt.
pipeline-guard put header lines above it, so the router started the agent as a
new brief: header lines and a bare marker, no issues (EV-13 T9).

- [router-rewrite Tn] is recognised at the start of any line (also after > - *).
- Lines above it stay on top, once (lines the stored prompt has are dropped);
  the stored prompt with the issues follows; text after it is guidance.
- The rewrite keeps its task number and tier.

2 tests; 5 mutations, all caught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MdqPWvuDpbpRvDEdURoAwo
This commit is contained in:
2026-11-24 02:08:16 +00:00
co-authored by Claude Opus 5.5
parent df6e0d1694
commit 2184024fe7
3 changed files with 64 additions and 3 deletions
+2 -2
View File
@@ -12,6 +12,7 @@ import {
} from './pricing'
import {
REWRITE_MARK,
rewritePrompt,
asTier,
clip,
decide,
@@ -790,8 +791,7 @@ export const register: Register = (on, options) => {
if (markId && pending) {
taskId = markId
const extra = e.prompt.replace(REWRITE_MARK, '').trim()
prompt = pending.prompt + (extra ? `\n\nAdditional guidance from the orchestrator:\n${extra}` : '')
prompt = rewritePrompt(e.prompt, pending.prompt)
tier = pending.tier
fails = pending.fails
critical = pending.critical
+20 -1
View File
@@ -325,7 +325,26 @@ export const parseVerdict = (text: string): Reading => {
return { isReadable: false, preview: text.slice(0, 300) }
}
export const REWRITE_MARK = /^\s*\[router-rewrite (T\d+)\]/
// At the start of any line: hooks such as pipeline-guard put header lines above it (#11).
export const REWRITE_MARK = /^[ \t>*-]*\[router-rewrite (T\d+)\][ \t]*/m
/**
* The prompt for a router rewrite: lines a hook put above the marker stay on
* top (once: lines the stored prompt already has are dropped), the stored
* prompt with the FAIL issues follows, and text after the marker is guidance.
*/
export const rewritePrompt = (given: string, stored: string): string => {
const m = given.match(REWRITE_MARK)
if (!m || m.index === undefined) return stored
const has = new Set(stored.split('\n').map(l => l.trim()).filter(Boolean))
const header = given
.slice(0, m.index)
.split('\n')
.filter(l => l.trim() && !has.has(l.trim()))
.join('\n')
const extra = given.slice(m.index + m[0].length).trim()
return [header, stored, extra ? `Additional guidance from the orchestrator:\n${extra}` : ''].filter(Boolean).join('\n\n')
}
export const clip = (s: string, n: number) =>
s.length <= n ? s : s.slice(0, n) + `\n... [${s.length - n} more characters cut]`