feat(plugins): add appendContext to before_prompt_build hook#193
Merged
dgarson merged 1 commit intodgarson/forkfrom Mar 3, 2026
Merged
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d9471caad
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
8d9471c to
da43291
Compare
Cherry-picked from da43291 with conflict resolution. Conflict resolved in src/agents/pi-embedded-runner/run/attempt.ts: - Added appendContext handling after prependContext - Added legacySystemPrompt override support - Changed systemPromptText from const to let to allow reassignment Original commit message: Plugins returning prependContext from before_prompt_build inject text before the user prompt, which is part of the stable system-prompt prefix and benefits from prompt caching. However, transient or per-turn context (e.g. enforcement nudges, dynamic warnings) inserted via prependContext invalidates the cached prefix for the entire block. Add appendContext as the counterpart: text returned in appendContext is appended after the user prompt, leaving the stable prefix intact and preserving prompt cache hits for the prependContext portion. Merge semantics mirror prependContext — multiple hooks' appendContext values are concatenated with "\n\n" separators. Empty results are coerced to undefined to avoid polluting the return type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
da43291 to
3371142
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prependContext, which prepends text before the user prompt. This invalidates the stable system-prompt prefix and breaks prompt caching for that block and everything after it.prependContextportion of the system prompt, even though the rest (role instructions, fleet status, etc.) is stable turn-over-turn.appendContextfield toPluginHookBeforePromptBuildResult. Text returned inappendContextis appended after the user prompt, leaving the stableprependContextprefix intact and preserving prompt cache hits. Merge semantics mirrorprependContext-- multiple hooks' values are concatenated with "\n\n". Empty results are coerced toundefined.prependContextbehavior is unchanged.systemPromptbehavior is unchanged. No existing plugin behavior is affected -- this is purely additive.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
None -- discovered during agent-orchestrator enforcement work where memory-search nudges were breaking prompt caching.
User-visible / Behavior Changes
None. This is a new opt-in capability for plugin authors. No existing behavior changes.
Security Impact (required)
Repro + Verification
Steps
{ appendContext: "some transient text" }from abefore_prompt_buildhookprependContextfrom other hooks is unaffectedExpected
appendContexttext appears after the user promptprependContextprefix remains cache-stable across turnsActual
Evidence
attempt.test.tswhich validatesresolvePromptBuildHookResultappendContextfor nudge injection (in consuming branch)Human Verification (required)
appendContextonly,prependContextonly, both, neither. Multiple hooks returningappendContext(merge concatenation).appendContextcoerced toundefined(no empty string pollution). Legacybefore_agent_starthookappendContextmerged correctly.Compatibility / Migration
Failure Recovery (if this breaks)
src/plugins/types.ts,src/plugins/hooks.ts,src/agents/pi-embedded-runner/run/attempt.tsappendContexttext missing from agent prompt (would indicate merge regression)Risks and Mitigations
None -- purely additive type field with no behavioral impact on existing code paths.