context + repl + config: per-class system_prompt override (closes #86)

Small local models follow precise structured instructions better than
natural language. Per-routing-class system_prompt override gives them
tighter instructions for THAT request while preserving ambient context.

Changes:

- Context:to_messages(opts) — opts.system_prompt_override REPLACES
  the base system_prompt for THIS render only (state unchanged).
  Dynamic blocks ([background], [project], [earlier summary], NORRIS
  suffix) still compose on top. opts is optional; nil-safe for old
  callers.

- repl.lua ask_ai — captures req_class from router.classify_model
  (already returned by Phase 5; previously discarded after the
  status line). Looks up config.routing.system_prompts[req_class];
  passes as opts.system_prompt_override to ctx:to_messages each
  iteration of the tool-sub-loop.

- Gating: override fires only when routing.auto is on (no class ->
  no override). If system_prompts[class] absent for a class, fall
  through to the default system_prompt (no surprise).

- Norris unaffected: safety.norris_step builds its own messages
  array; doesn't go through this path.

- config.lua gains a commented-out example showing routing.system_
  prompts with the code/default examples from the FR body.

Smoke verified:
  - 12-case context.lua unit test: opts nil/absent/present, override
    replaces base, dynamic blocks still compose, state unchanged
    after call, Norris-mode coexistence (suffix still present;
    background still suppressed).
  - E2E against cloud broker with routing.system_prompts.code set:
    triple-backtick prompt -> code class -> override fires; model
    emits terse code-only output. Non-code prompt -> default class
    -> no override -> normal verbose-ish reply.

Regression: test_safety 87/87, test_router_model 31/31, repl loads.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 05:41:15 +00:00
parent df59ee2f2c
commit 047d629a66
3 changed files with 47 additions and 3 deletions
+10 -2
View File
@@ -228,8 +228,16 @@ The user will be prompted to confirm destructive actions; expect their
verdict in the next turn as a synthesized "[aish] ... skipped by user"
message if they declined.]]
function Context:to_messages()
local sys_content = self.system_prompt
function Context:to_messages(opts)
-- Phase 10 (#86): per-call system_prompt_override. Replaces the
-- BASE system_prompt for THIS render only (state unchanged); the
-- dynamic blocks ([background], [project], [earlier summary],
-- NORRIS suffix) still compose on top. Used by ask_ai's routing
-- path when cfg.routing.system_prompts[class] is set — gives
-- small local models tighter instructions while preserving
-- ambient memory/project context.
local sys_content = (opts and opts.system_prompt_override)
or self.system_prompt
-- Phase 4 [background] memory block + Phase 6 [project] file-tree
-- block + Phase 5 [earlier summary] block. All suppressed during
-- Norris (R-C1 / R-C4 — avoid redundant tokens per planning