Author SHA1 Message Date
bchanot d9f0f427c6 feat(model-router): advisor note on main-loop plan/reflect skill loads
The mod prepends a one-call-per-run advisor rule to the body of main-loop skill loads whose row is plan or reflect; effort-shift § Advisor gains point 4 (Per run).
2026-11-24 13:35:46 +01:00
3 changed files with 159 additions and 2 deletions

No files matched your search

+12
View File
@@ -134,6 +134,18 @@ triggers in CLAUDE.global.md § Workflow):
reuses the last run's answer, or its skip, and names any code commit reuses the last run's answer, or its skip, and names any code commit
made after it (doc and memory commits excepted). Elsewhere the made after it (doc and memory commits excepted). Elsewhere the
answer is reported only and a fix it calls for is a new run. answer is reported only and a fix it calls for is a new run.
4. **Per run.** A main-loop run of a skill whose model-router row is
`plan` or `reflect` (the rows that put main on Fable before BDR-150)
makes one call on its settled plan, diagnosis or fix, before it
executes or reports (at load when it starts from a settled plan). A
call this run made at point 1, 2 or 3 counts as this one. Only the
placed-decision skip (`lib/challenge-plan.md` § SKIP) and point 3's
skips waive it; any other skipped challenge step (hotfix's cosmetic
guard, an audit-only or conservative mode, a clean stop) gets the
call where that step would have run. A skill loaded inside a
plan/reflect skill's run makes none; under another row or none, it
calls. The model-router mod prepends this rule to the skill body on a
main-loop load, never on a sub-agent's.
Inside a skill run, the points above also cover the triggers of Inside a skill run, the points above also cover the triggers of
CLAUDE.global.md § Workflow; no second call for the same recommendation. CLAUDE.global.md § Workflow; no second call for the same recommendation.
+107
View File
@@ -7744,3 +7744,110 @@ test('GUARD: an isError Skill answer leaves the latch closed', async (
await $.tool.call({ tool: 'Skill', skill: 'diagram' } as never) await $.tool.call({ tool: 'Skill', skill: 'diagram' } as never)
expect(denied(await write($, `${ROOT}/src/a.ts`))).toContain(GUARD) expect(denied(await write($, `${ROOT}/src/a.ts`))).toContain(GUARD)
}) })
// ---- advisor note: one main-loop advisor call per plan/reflect run ------
// duplicated on purpose: register.ts exports no constant
const NOTE = 'Advisor (`~/.claude/lib/effort-shift.md` § Advisor, **Per run**)'
const noteWorld = () => newWorld({
edit: f => {
Object.assign(f.skills as Rec, {
'writing-plans': 'plan',
'pack-design:frontend-design': 'reflect',
capitalize: 'apply',
})
},
})
/**
* A rig whose bottom Skill tool loads the skill body through skill.prompt,
* as the engine does, and answers the loaded text as `commandName`.
*/
async function noteRig($: Engine, on: On, gate?: Promise<void>) {
on('tool.call', { tool: 'Skill' }, async (_api, e) => {
if (e.agentId === undefined) await gate
const out = await $.skill.prompt({ skill: String(e.skill), text: 'BODY' })
return { result: { success: true, commandName: out.text } }
})
await bootRig($, on, FABLE, 1000, noteWorld())
}
/** The body a Skill call loaded, as the bottom tool answered it. */
async function bodyOf(
$: Engine,
skill: string,
agentId?: string,
): Promise<string> {
const out = await loadSkill($, skill, agentId)
return (out as unknown as { result: { commandName: string } })
.result.commandName
}
test('advisor note: a main feat load carries it', async ($, on) => {
await noteRig($, on)
const body = await bodyOf($, 'feat')
expect(body.startsWith(NOTE)).toBe(true)
expect(body.endsWith('\n\nBODY')).toBe(true)
})
test('advisor note: a main plan row carries it', async ($, on) => {
await noteRig($, on)
expect(await bodyOf($, 'writing-plans')).toContain(NOTE)
})
test('advisor note: a prefixed reflect row carries it', async ($, on) => {
await noteRig($, on)
expect(await bodyOf($, 'pack-design:frontend-design')).toContain(NOTE)
})
test('advisor note: a sub-agent load carries none', async ($, on) => {
await noteRig($, on)
expect(await bodyOf($, 'feat', 'a1')).toBe('BODY')
})
test('advisor note: a preload carries none', async ($, on) => {
await noteRig($, on)
await $.agent.spawn(spawnOf('feater'))
expect((await skillPrompt($, 'feat')).text).toBe('x')
})
test('advisor note: an apply row carries none', async ($, on) => {
await noteRig($, on)
expect(await bodyOf($, 'capitalize')).toBe('BODY')
})
test('advisor note: a mechanical row carries none', async ($, on) => {
await noteRig($, on)
expect(await bodyOf($, 'status')).toBe('BODY')
})
test('advisor note: an unrowed skill carries none', async ($, on) => {
await noteRig($, on)
expect(await bodyOf($, 'diagram')).toBe('BODY')
})
test('advisor note: /route off carries none', async ($, on) => {
await noteRig($, on)
await route($, 'off')
expect(await bodyOf($, 'feat')).toBe('BODY')
})
test('advisor note: a typed /feat carries it', async ($, on) => {
await noteRig($, on)
await typed($, '/feat add a thing')
const out = await skillPrompt($, 'feat')
expect(out.text.startsWith(NOTE)).toBe(true)
expect(out.text.endsWith('\n\nx')).toBe(true)
})
test('advisor note: a sub-agent load ending mid-call keeps the main one', async (
$, on) => {
let release: () => void = () => undefined
const gate = new Promise<void>(resolve => { release = resolve })
await noteRig($, on, gate)
const main = bodyOf($, 'feat')
expect(await bodyOf($, 'status', 'a1')).toBe('BODY')
release()
expect(await main).toContain(NOTE)
})
+40 -2
View File
@@ -95,6 +95,7 @@ type State = {
loops: Map<string, Loop> // agentId -> that loop's routing loops: Map<string, Loop> // agentId -> that loop's routing
explicitEffort: Map<string, Level> // Agent tool_use_id -> effort param explicitEffort: Map<string, Level> // Agent tool_use_id -> effort param
skillCalls: number // Skill tool calls in flight skillCalls: number // Skill tool calls in flight
advisorSkill: string | null // main-loop Skill load awaiting its note
off: boolean // /route off or config: every hook passes through off: boolean // /route off or config: every hook passes through
offConfig: boolean // `off` comes from the config key `enabled` offConfig: boolean // `off` comes from the config key `enabled`
spinner: string // "model/effort" of the last main step of this turn spinner: string // "model/effort" of the last main step of this turn
@@ -192,6 +193,18 @@ const INHERITING_AGENTS: ReadonlySet<string> = new Set(['general-purpose'])
const REFERENCE_SKILLS: ReadonlySet<string> = new Set([ const REFERENCE_SKILLS: ReadonlySet<string> = new Set([
'modern-web-guidance', 'find-docs', 'modern-web-guidance', 'find-docs',
]) ])
// Rows whose skill run makes one main-loop advisor call (effort-shift.md
// § Advisor, point 4); ADVISOR_NOTE is the rule, prepended to the body.
const ADVISOR_PHASES: ReadonlySet<string> = new Set(['plan', 'reflect'])
const ADVISOR_NOTE =
'Advisor (`~/.claude/lib/effort-shift.md` § Advisor, **Per run**): when ' +
'the `advisor` tool is listed, this skill run makes one main-loop ' +
'advisor call on its settled plan, diagnosis or fix, before it executes ' +
'or reports. A call this run already made at an advisor point counts. ' +
'Only `~/.claude/lib/challenge-plan.md` § SKIP and the end-of-run skips ' +
'waive it; any other skipped challenge step still gets the call where ' +
'it would have run. Loaded inside another plan/reflect skill\'s run: no ' +
'call of its own.\n\n'
// PostModelSwitch sources a person chose (auto and resume are not). // PostModelSwitch sources a person chose (auto and resume are not).
const USER_SWITCH: ReadonlySet<string> = new Set([ const USER_SWITCH: ReadonlySet<string> = new Set([
'command', 'picker', 'sdk', 'command', 'picker', 'sdk',
@@ -1026,6 +1039,7 @@ function newState(cfg: Config, source: string): State {
loops: new Map(), loops: new Map(),
explicitEffort: new Map(), explicitEffort: new Map(),
skillCalls: 0, skillCalls: 0,
advisorSkill: null,
off: false, off: false,
offConfig: false, offConfig: false,
spinner: '', spinner: '',
@@ -3754,6 +3768,12 @@ function skillRow(st: State, skill: string): Picked | undefined {
return phase !== undefined && route ? { phase, route } : undefined return phase !== undefined && route ? { phase, route } : undefined
} }
/** Whether a skill's row phase owes its run one advisor call. */
function advisorDue(st: State, skill: string): boolean {
const phase = skillRow(st, skill)?.phase
return phase !== undefined && ADVISOR_PHASES.has(phase)
}
/** The run slot's model outranks the route's: a helper moves effort only. */ /** The run slot's model outranks the route's: a helper moves effort only. */
function belowRun(st: State, route: Route): boolean { function belowRun(st: State, route: Route): boolean {
const mine = resolveRoute(st, route) const mine = resolveRoute(st, route)
@@ -4634,6 +4654,13 @@ function registerSkills(on: On, st: State): void {
if (e.agentId === undefined && skillRow(st, skill)) { if (e.agentId === undefined && skillRow(st, skill)) {
await tierAsk($, st, st.turnMain, `Skill /${clean(skill, NAME_CAP)}`) await tierAsk($, st, st.turnMain, `Skill /${clean(skill, NAME_CAP)}`)
} }
// shortcut: one marker, so accepted gaps: a same-name sub-agent load
// during a main call takes the note (the main load loses it); two
// concurrent main calls keep the last marker. skill.prompt has no
// agentId. Upgrade path: key the marker by tool_use_id.
if (e.agentId === undefined && advisorDue(st, skill)) {
st.advisorSkill = skill
}
const out = await next(e) const out = await next(e)
const refused = typeof out !== 'object' || out === null || const refused = typeof out !== 'object' || out === null ||
'deny' in out || (out as { isError?: unknown }).isError === true 'deny' in out || (out as { isError?: unknown }).isError === true
@@ -4642,6 +4669,7 @@ function registerSkills(on: On, st: State): void {
return out return out
} finally { } finally {
st.skillCalls -= 1 st.skillCalls -= 1
if (e.agentId === undefined) st.advisorSkill = null
} }
}).catch(($, e, next) => { }).catch(($, e, next) => {
warnOnce(st, $, 'Skill', next.error.kind) warnOnce(st, $, 'Skill', next.error.kind)
@@ -4649,14 +4677,24 @@ function registerSkills(on: On, st: State): void {
}) })
on('skill.prompt', async ($, e, next) => { on('skill.prompt', async ($, e, next) => {
await ensureConfig($, st) await ensureConfig($, st)
if (st.off || st.skillCalls > 0) return next(e) if (st.off) return next(e)
if (st.skillCalls > 0) {
const out = await next(e)
if (st.advisorSkill !== e.skill) return out
st.advisorSkill = null
return { ...out, text: ADVISOR_NOTE + out.text }
}
const { row, typed } = armed($, st, e.skill) const { row, typed } = armed($, st, e.skill)
if (typed) { if (typed) {
const size = { points: pointsOf([e.text]), unknown: false } const size = { points: pointsOf([e.text]), unknown: false }
await addEstimate($, st, size, false) await addEstimate($, st, size, false)
} }
if (row) await confirmSkill($, st, e.skill, row) if (row) await confirmSkill($, st, e.skill, row)
return next(e) const out = await next(e)
// shortcut: a typed slash landing while a Skill call is in flight
// takes the in-call branch above and loses its note.
if (!typed || !advisorDue(st, e.skill)) return out
return { ...out, text: ADVISOR_NOTE + out.text }
}).catch(($, e, next) => { }).catch(($, e, next) => {
warnOnce(st, $, 'skill.prompt', next.error.kind) warnOnce(st, $, 'skill.prompt', next.error.kind)
return next(e) return next(e)