Skip to content

feat(backends): honor replace-vs-append prompt intent, or refuse it loudly - #120

Merged
drewstone merged 2 commits into
mainfrom
feat/prompt-intent-replace-vs-append
Aug 5, 2026
Merged

feat(backends): honor replace-vs-append prompt intent, or refuse it loudly#120
drewstone merged 2 commits into
mainfrom
feat/prompt-intent-replace-vs-append

Conversation

@drewstone

Copy link
Copy Markdown
Owner

Every backend now either honors the caller's system-prompt intent with a real control, or throws BackendError[not_configured] before spawning anything. No intent is silently turned into the other one.

Measured on the real wire against the installed CLIs (claude 2.1.222 · codex 0.146.0 · gemini 0.26.0 · opencode 1.17.18 · pi 0.83.0):

harness replace append
claude-code honored — built-in 27,673 B → 20 B honored — built-in intact, text at tail
codex honored — developer msg 17,599 B → 113 B refused
opencode refused honored — built-in intact, text inside the system message
pi honored — 2,582 B → 160 B honored — built-in intact + marker
gemini honored — .gemini/system.md replaces wholesale refused

Zero silent downgrades in ten cells.

Also fixed: the guard that does this work had no test coverage — deleting it left 26/26 prompt-intent tests passing. Ten new tests drive each backend's own chat() with an intent it cannot execute and assert the error kind, the message, and zero spawns (a spawner that throws if reached; a real unix socket for the backend that spawns nothing). Deleting the guard now fails 9 of 10. One negative control ensures a blanket refusal fails too.

Suite 668 → 678 passing, typecheck clean.

…e it

renderLocalHarnessProfilePreamble folded agent_profile.prompt.systemPrompt
into a preamble that claude sent through --append-system-prompt and every
other local backend flattened into the user turn. systemPrompt means DELETE
the harness's own prompt; both paths kept it running. The caller saw a
successful turn either way, so a profile written to replace claude-code's
27,673-byte built-in prompt silently ran on top of it instead.

Bind each intent to the control that performs it. claude passes
plan.systemPrompt to --system-prompt and merges plan.appendSystemPrompt
into the single --append-system-prompt block; pi writes each intent to its
own file under the request-scoped profile directory and passes
--system-prompt / --append-system-prompt, with the profile's addition
ordered ahead of the AGENTS.md loader that shares the flag. codex,
opencode and gemini receive their intents through the materializer's files
and flags. The preamble now carries no prompt text at all — only the
skills/MCP/resources/permission summary that was always informational.

One --append-system-prompt, never two: claude-code takes the LAST
occurrence and discards earlier ones (verified on the wire — two values
arrive as only the second), so a second occurrence would silently drop
whichever source lost. Everything additive composes into one block, and
composeStdinInput mirrors it exactly, since it exists to predict whether
that same block fits argv; the profile is provisioned before it runs so
both see the same bytes.

assertProfilePromptIntentsSupported is the shared refusal. acp, factory and
nanoclaw never materialize a plan, so the materializer's fail-closed record
never reaches them and an intent would vanish without a word. Unknown
backend names refuse both intents, so a backend added later cannot inherit
a capability by omission.

The per-backend controls are measured, not documented: claude-code 2.1.222
--system-prompt drops the built-in prompt from the request while
--append-system-prompt leaves it in place; pi 0.83.0 matches, and its flags
inline a file's bytes without sending the path; codex 0.146.0 has a
replacement config key and no additive control at all.
…lly passes it

assertProfilePromptIntentsSupported was tested only by calling it directly.
Deleting its one call site in resolvePromptMessages left all 26 prompt-intent
tests green: acp, factory, nanoclaw, hermes and kimi-code each accepted a
profile carrying an intent they cannot execute, spawned, and ran the turn with
the intent gone — the exact silent downgrade the assertion exists to stop, and
the suite could not see it.

Drive each backend's own chat path with a profile it must refuse, and assert
the BackendError code together with a spawn count of zero, measured by a
spawner that throws if it is ever reached. nanoclaw launches nothing of its
own, so its equivalent is a listening socket that must receive no connection.
codex and opencode carry the two cells their materializer would also catch a
layer later; asserting this seam's wording proves the refusal lands before any
workspace is touched, which the empty-cwd assertion checks directly.

One case runs the other way: codex with a replacement and opencode with an
addition pass the seam untouched, so a blanket refusal fails too.
@drewstone
drewstone merged commit d1b615e into main Aug 5, 2026
1 check failed
@drewstone
drewstone deleted the feat/prompt-intent-replace-vs-append branch August 5, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant