Skip to content

fix(pi): subagent processes follow the parent's mode and PONYTAIL_SUBAGENT_MATCHER - #1534

Open
marcioazam wants to merge 1 commit into
DietrichGebert:mainfrom
marcioazam:upstream-proposal
Open

marcioazam wants to merge 1 commit into
DietrichGebert:mainfrom
marcioazam:upstream-proposal

Conversation

@marcioazam

Copy link
Copy Markdown

Fixes #1533

A child pi process started by pi-code's subagent tool read the saved default mode instead of the parent's session mode, so /ponytail off (or lite) in the parent did not reach it, and PONYTAIL_SUBAGENT_MATCHER only applied to the Claude Code SubagentStart hook.

What changes (pi-extension/index.js):

  • The extension exports the current mode as PONYTAIL_PARENT_MODE (on /ponytail <mode> and on session_start).
  • A child (PI_CODE_SUBAGENT=1) starts in that mode. If PONYTAIL_SUBAGENT_MATCHER is set and does not match the agent name (parsed from --system-prompt .../prompt-<name>.md), it starts off.
  • Same matcher semantics as hooks/ponytail-subagent.js: unanchored, case-insensitive, fail open on a bad regex, an unknown name, or a timeout (same 100 ms vm timeout, PONYTAIL_SUBAGENT_MATCHER compiled into RegExp without validation (crash on invalid pattern + ReDoS) #658).
  • The child mode is not persisted with appendEntry.
  • One sentence in INSTALL.md (Pi section).

This is an extension fix only: no change to skills/, AGENTS.md or any rule copy, so no benchmark applies (CONTRIBUTING, "Everything else").

Tests: new pi-extension/test/subagent.test.js (name parsing, parent-mode inheritance, matcher, fail-open incl. a catastrophic-backtracking regex, child session_start neither injects nor persists); extension.test.js clears the subagent env vars so a run inside a pi subagent does not change its result.

npm test                              # 144 pass, 0 fail (with pandas installed for the csv benchmark test)
node scripts/check-rule-copies.js     # Rule copies match AGENTS.md
node scripts/check-versions.js        # All 7 version files pinned at 5.3.3

Not verified: behavior inside a real pi-code subagent run (covered by unit tests with the same argv/env shape only).

…AGENT_MATCHER

A child pi process started by pi-code's subagent tool read the saved default
mode instead of the parent's session mode, so `/ponytail off` (or `lite`) in
the parent did not reach it, and PONYTAIL_SUBAGENT_MATCHER only applied to
the Claude Code SubagentStart hook.

The extension now exports the current mode as PONYTAIL_PARENT_MODE. A child
(PI_CODE_SUBAGENT=1) starts in that mode and turns it off when
PONYTAIL_SUBAGENT_MATCHER is set and does not match the agent name read from
the `--system-prompt .../prompt-<name>.md` argument. Same semantics as the
hook: unanchored, case-insensitive, fail open on a bad regex, an unknown name
or a matcher that times out (100 ms vm timeout, DietrichGebert#658). The child mode is
never persisted.
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.

pi extension: subagent (child pi) processes ignore the parent's mode and PONYTAIL_SUBAGENT_MATCHER

1 participant