Commit 6c014b5
authored
fix(pi-bash-bg): stop replacing the bash tool so shellCommandPrefix keeps working (#43)
## 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:
```ts
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`:
```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:
```markdown
## 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`.
Co-authored-by: mgabor3141 <mgabor3141@users.noreply.github.com>1 parent fd663da commit 6c014b5
4 files changed
Lines changed: 96 additions & 29 deletions
File tree
- .changeset
- packages/bash-bg
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 29 | | |
36 | 30 | | |
37 | 31 | | |
| |||
42 | 36 | | |
43 | 37 | | |
44 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
4 | 27 | | |
5 | 28 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
14 | 43 | | |
| 44 | + | |
| 45 | + | |
15 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
16 | 59 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
22 | 79 | | |
23 | | - | |
| 80 | + | |
24 | 81 | | |
25 | 82 | | |
0 commit comments