Skip to content

fix(pi-extension): preserve systemPrompt array instead of comma-collapsing it#211

Open
noamsiegel wants to merge 1 commit into
DietrichGebert:mainfrom
noamsiegel:fix/pi-extension-systemprompt-array
Open

fix(pi-extension): preserve systemPrompt array instead of comma-collapsing it#211
noamsiegel wants to merge 1 commit into
DietrichGebert:mainfrom
noamsiegel:fix/pi-extension-systemprompt-array

Conversation

@noamsiegel

Copy link
Copy Markdown

Problem

The pi extension's before_agent_start handler builds the injected prompt with a template string:

return { systemPrompt: `${event.systemPrompt}\n\n${getPonytailInstructions(currentMode)}` };

Some hosts pass event.systemPrompt as a string[] rather than a string (e.g. Oh My Pi, a pi fork — its BeforeAgentStartEvent.systemPrompt is typed string[], and the runner accepts either a string or an array back). Interpolating an array stringifies it, joining the host's base-prompt sections with commas and collapsing them into one section. Ponytail's rules still get injected, but the host's base system prompt loses its section boundaries on every turn.

Repro (mirrors the host's merge): a base of ["SECTION_A", "SECTION_B", "SECTION_C"] comes back as a single element beginning "SECTION_A,SECTION_B,SECTION_C\n\nPONYTAIL MODE ACTIVE …".

Fix

Guard on Array.isArray — append the instructions as a new element for array hosts, keep the existing string behavior otherwise:

return Array.isArray(event.systemPrompt)
  ? { systemPrompt: [...event.systemPrompt, instructions] }
  : { systemPrompt: `${event.systemPrompt}\n\n${instructions}` };

The string path is untouched, so string hosts behave exactly as before.

Tests

  • Existing string-path tests are unchanged (they pass { systemPrompt: "BASE" }).
  • New regression test asserts an array input keeps its elements and appends the instructions as the last element.
  • node --test pi-extension/test/*.test.js → 13/13 pass; node scripts/check-rule-copies.js clean.

…psing it

Some hosts (e.g. Oh My Pi) pass before_agent_start systemPrompt as a
string[]. The handler interpolated it into a template string, which
stringifies the array and joins the host's base-prompt sections with
commas, collapsing them into a single section. Guard on Array.isArray:
append the instructions as a new element for array hosts, keep the
existing string behavior otherwise. Adds a regression test.
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