Skip to content

Keep later prompt sections when adding memory, agents and styles - #407

Merged
ilovepixelart merged 1 commit into
mainfrom
fix/keep-prompt-sections
Oct 22, 2026
Merged

ilovepixelart merged 1 commit into
mainfrom
fix/keep-prompt-sections

Conversation

@ilovepixelart

Copy link
Copy Markdown
Owner

The subagent roster, the memory index and the active output style were added by returning a whole systemPrompt from before_agent_start. pi treats a returned prompt as fixed text, so sections that extensions loaded afterwards add to the prompt options never reached the model. pi's MCP extension loads after pi-code and lists servers whose tools are deferred or codemode in an mcp_servers section; with a discoverable subagent (the built-in agents count) that section was dropped from every request.

  • Prompt options instead of a fixed prompt (extensions/internal/prompt-options.ts): the roster and the memory index become the subagents and memory sections. A style that keeps the coding instructions becomes the output_style section, and one that replaces them sets customPrompt, which replaces the same preamble, tools, rules and docs sections applyStyle cut.
  • Behavior change: on a re-rendering pi the three additions render as <subagents>, <memory> and <output_style> blocks instead of ## Subagents, ## Memory and ## Output Style headings appended at the end.
  • Fallback unchanged: on a pi that does not re-render the prompt from its options, or after an earlier handler forced a prompt, the handlers return the appended systemPrompt as before and leave the options as found.

Tests run the handlers through pi's own buildSystemPrompt followed by a handler that adds mcp_servers, and assert both reach the final prompt. Measured with real pi 1.2.0 and all pi-code extensions plus a deferred server in pi's mcp.json: on main the request carried no mcp_servers section; with this change it lists the server.

Needed for #406, where pi-code's own servers become deferred.

  • npm run check passes (Biome, strict tsc, Vitest)
  • Tests cover the change

The subagent roster, the memory index and the active output style were
added by returning a whole systemPrompt from before_agent_start. pi
treats a returned prompt as fixed text, so sections that extensions
loaded afterwards add to the prompt options never reached the model.
pi's MCP extension loads after pi-code and lists servers with deferred
or codemode tools in an mcp_servers section, which was dropped on every
turn a subagent was discoverable.

The three handlers now edit the prompt options instead: the roster and
the memory index become the subagents and memory sections, a style that
keeps the coding instructions becomes the output_style section, and a
style that replaces them sets customPrompt, which replaces the same
preamble, tools, rules and docs sections applyStyle cut. Where pi does
not re-render the prompt from its options, or an earlier handler forced
a prompt, they return the appended systemPrompt as before.
@sonarqubecloud

Copy link
Copy Markdown

@ilovepixelart
ilovepixelart merged commit 0a8aa29 into main Oct 22, 2026
13 checks passed
@ilovepixelart
ilovepixelart deleted the fix/keep-prompt-sections branch November 4, 2026 15: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