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:
+2
-2
@@ -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
@@ -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]`
|
||||
|
||||
@@ -5,10 +5,12 @@ import {
|
||||
decide,
|
||||
heuristic,
|
||||
taskText,
|
||||
rewritePrompt,
|
||||
onFail,
|
||||
parseBrief,
|
||||
parseVerdict,
|
||||
rewriteTier,
|
||||
REWRITE_MARK,
|
||||
skipReason,
|
||||
validTimeout,
|
||||
verifierFor,
|
||||
@@ -1386,3 +1388,43 @@ test('#10: a new file created while round 1 is verified counts as new in round 2
|
||||
expect(w.verifierPrompts[1]).toContain('new file: tests/test_named_absence.py')
|
||||
expect(w.verifierPrompts[1]).not.toContain('new file: old_notes.md')
|
||||
})
|
||||
|
||||
// ---------- #11: the rewrite prompt keeps its issues under hook header lines ----------
|
||||
|
||||
const GUARD_HEADER = 'Pipeline-Role: dev\nPipeline-Guard: v3 (EV-13)\n'
|
||||
|
||||
test('#11: a rewrite marker under guard header lines starts the stored rewrite, issues and all (EV-13 T9)', async ($, on) => {
|
||||
const w = fresh()
|
||||
w.diffs = ['d1', 'd2']
|
||||
w.verdicts = [
|
||||
'{"verdict":"FAIL","issues":["P1/P2 not in the N2 check"]}',
|
||||
'{"verdict":"FAIL","issues":["P4 arm-at-send assert","R1 kill not shown"]}',
|
||||
]
|
||||
const clock = world(on, w)
|
||||
const r = await $.agent.spawn({ prompt: devBrief(), description: 'ev13' } as never)
|
||||
await finish($, clock, r.agentId as string)
|
||||
await finish($, clock, r.agentId as string)
|
||||
expect(w.told[1]).toContain('[router-rewrite T1]')
|
||||
|
||||
await $.agent.spawn({ prompt: `${GUARD_HEADER}[router-rewrite T1]`, description: 'rewrite' } as never)
|
||||
const p = w.spawned[1]?.prompt ?? ''
|
||||
expect(p).toContain('- P4 arm-at-send assert')
|
||||
expect(p).toContain('- R1 kill not shown')
|
||||
expect(p).toContain(`Their work is in the clone ${DEV}`)
|
||||
expect(p.startsWith('Pipeline-Role: dev\nPipeline-Guard: v3 (EV-13)')).toBe(true)
|
||||
expect(w.spawned[1]?.model).toBe('opus') // the rewrite's tier, not a fresh routing
|
||||
const log = (await $.command.run({ command: 'router', args: '' } as never)).text ?? ''
|
||||
expect(log).not.toContain('T2') // the same task, no new number
|
||||
})
|
||||
|
||||
test('#11: header lines are not doubled, text after the marker is guidance, mid-line mentions are no marker', async () => {
|
||||
const stored = 'Pipeline-Role: dev\nClone: /x/clones/EV-13-dev\nDo it.\n\n## Previous attempts rejected\nIssues:\n- a'
|
||||
const p = rewritePrompt('Pipeline-Role: dev\nPipeline-Guard: v3\n\n[router-rewrite T9]\nKeep the P4 test.', stored)
|
||||
expect(p.split('Pipeline-Role: dev').length).toBe(2) // once
|
||||
expect(p.startsWith('Pipeline-Guard: v3\n\nPipeline-Role: dev')).toBe(true)
|
||||
expect(p).toContain('- a')
|
||||
expect(p.endsWith('Additional guidance from the orchestrator:\nKeep the P4 test.')).toBe(true)
|
||||
expect(rewritePrompt('[router-rewrite T9]', stored)).toBe(stored)
|
||||
expect('Call Agent with prompt [router-rewrite T9] now'.match(REWRITE_MARK)).toBe(null)
|
||||
expect('> [router-rewrite T9]'.match(REWRITE_MARK)?.[1]).toBe('T9')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user