Skip to content

fix(pi-bash-bg): stop replacing the bash tool so shellCommandPrefix keeps working#43

Open
mgabor3141 wants to merge 1 commit intomainfrom
fix/bash-bg-preserve-command-prefix
Open

fix(pi-bash-bg): stop replacing the bash tool so shellCommandPrefix keeps working#43
mgabor3141 wants to merge 1 commit intomainfrom
fix/bash-bg-preserve-command-prefix

Conversation

@mgabor3141
Copy link
Copy Markdown
Owner

Problem

Since 0.1.0, pi-bash-bg calls createBashTool(process.cwd()) and pi.registerTool(...) to append a background-job note to the bash tool description:

const bashTool = createBashTool(process.cwd());
pi.registerTool({
    ...bashTool,
    description: `${bashTool.description} ${BASH_DESCRIPTION_APPENDIX}`,
});

The freshly-constructed bashTool is created without the commandPrefix, shellPath, or spawnHook options pi wires onto its built-in bash tool. In pi's _refreshToolRegistry, extension-registered tools win over built-in ones with the same name, so that replacement silently drops those options.

Concretely, any user with something like this in ~/.pi/agent/settings.json:

{ "shellCommandPrefix": "export PI_ROOT=..." }

sees their prefix stop running as soon as pi-bash-bg is loaded. Same for shellPath. I hit this while setting PI_ROOT for agent bash sessions and traced it through getShellCommandPrefix -> createAllToolDefinitions({ bash: { commandPrefix } }) -> the registry override above.

Fix

Move the background-job guidance into the system prompt via a before_agent_start hook (same mechanism the extension already uses for other prompt tweaks), and stop registering a replacement bash tool. Pi's built-in bash stays put, so shellCommandPrefix, shellPath, and any spawnHook keep working.

The guidance section injected into the system prompt:

## Background jobs (\`command &\`)

The bash tool supports backgrounding processes with \`&\`.
Background process stdout/stderr is captured to a temp log file.
Each rewritten command reports \`[bg] pid=<PID> label=<LABEL> log=<PATH>\` in its output.
Use \`cat <PATH>\` to check output and \`kill <PID>\` to stop the process.

It's exported as BASH_BG_SYSTEM_PROMPT_SECTION and the handler no-ops if it's already present, so repeated before_agent_start events don't duplicate it.

Verification

  • yarn test --run packages/bash-bg: 76/76 pass (new test covers that no tool is registered, handlers are wired up, and the system prompt is augmented once).
  • yarn lint: clean.
  • End-to-end: with this built locally and shellCommandPrefix set, env | grep ^PI_ROOT in agent bash now returns the expected value; before the fix it was empty.

Changeset

Included as a patch bump on pi-bash-bg.

…working

createBashTool(process.cwd()) + pi.registerTool(...) was used to append a
background-job note to the tool description, but the freshly-constructed
bash tool shadowed pi's built-in one in the registry, silently dropping
the shellCommandPrefix, shellPath, and spawnHook that pi wires onto the
built-in tool. Any user with "shellCommandPrefix": "..." in settings
saw their prefix stop running as soon as pi-bash-bg was loaded.

Move the guidance into the system prompt via before_agent_start so the
built-in bash tool is left untouched. Add a changeset.
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