You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes a cwd-mismatch bug in resumed pi sessions caused by pi-bash-bg overriding the built-in bash tool with one whose cwd was captured at extension-load time.
The previous version did:
constbashTool=createBashTool(process.cwd());// snapshot at loadpi.registerTool({ ...bashTool,description: ... });// overrides built-in
process.cwd() is the launcher's cwd at extension-load time, not the resumed session's cwd. The cwd was baked into the spawn closure, so after pi --resume from a different directory, bash commands kept running in the launcher's directory while the rest of pi (including the footer) tracked the session's cwd.
The extension only ever needed to rewrite background commands; the registerTool call existed to attach a description appendix. Dropping it lets pi's built-in bash tool (which is wired to AgentSession._cwd) execute the command, and the tool_call handler still mutates event.input.command in place to perform the rewrite.
Changes
packages/bash-bg/src/index.ts: remove registerTool and the createBashTool import; keep only the tool_call rewrite.
packages/bash-bg/test/index.test.ts: replace the description-appendix test with regression tests that assert the extension does not call registerTool, that it registers a tool_call handler, and that the handler rewrites bg commands while leaving non-bg / non-bash calls alone.
packages/bash-bg/README.md: drop the description-appendix mentions.
AGENTS.md: small guidance update asking for one-line changeset summaries.
Trade-off
The bash tool description no longer carries a "background jobs continue running…" hint to the model. The rewritten command's [bg] pid=... log=... output is self-explanatory in practice, and is well-aligned with how bash backgrounding is conventionally communicated.
Fixes a cwd-mismatch bug in resumed pi sessions by removing the registerTool call that was snapshotting process.cwd() at extension-load time and baking it into the bash-tool's spawn closure. The extension now only registers a tool_call handler that mutates event.input.command in place, letting the built-in bash tool (which tracks the live session cwd) execute the command.
Confidence Score: 5/5
Safe to merge — targeted removal of the cwd-snapshotting registerTool call with good regression test coverage.
The change is minimal and well-scoped: one import removed, one block deleted, tests updated to match. The root cause (process.cwd() captured at load time) and fix (delegate cwd handling to the built-in tool) are clearly correct. New tests directly verify the regression-prone behavior.
No files require special attention.
Important Files Changed
Filename
Overview
packages/bash-bg/src/index.ts
Removes registerTool/createBashTool call that baked in a fixed cwd; retains only the tool_call handler for command rewriting. Clean, focused fix.
packages/bash-bg/test/index.test.ts
Replaces the description-appendix test with 4 targeted regression tests covering: no registerTool call, handler registration, bg-command rewriting, and pass-through for non-bg/non-bash events.
packages/bash-bg/README.md
Removes mentions of the description-appendix feature to align with the new implementation.
.changeset/bash-bg-fix-resume-cwd.md
Adds patch-level changeset entry for the cwd bug fix in pi-bash-bg.
AGENTS.md
Minor doc update asking for single-line changeset summaries; no code impact.
Sequence Diagram
sequenceDiagram
participant Agent
participant pi as pi (built-in bash tool)
participant ext as bash-bg extension
participant Shell
Note over ext: extension load — no registerTool call,<br/>no cwd snapshot taken
Agent->>pi: tool_call { name: "bash", command: "sleep 300 &" }
pi->>ext: emit tool_call event
ext->>ext: detectBackground(command)
ext->>ext: rewriteCommand() → mutate event.input.command in place
ext-->>pi: (returns, no result override)
pi->>Shell: exec rewritten command (using session's live cwd)
Shell-->>pi: "[bg] pid=... log=..."
pi-->>Agent: tool result
Closing in favor of #43, which already fixes the same root cause (pi.registerTool(...) override clobbering the built-in bash tool), plus preserves the background-jobs guidance via a before_agent_start system-prompt hook. I missed #43 when opening this; my apologies for the duplicate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a cwd-mismatch bug in resumed pi sessions caused by
pi-bash-bgoverriding the built-in bash tool with one whose cwd was captured at extension-load time.The previous version did:
process.cwd()is the launcher's cwd at extension-load time, not the resumed session's cwd. The cwd was baked into the spawn closure, so afterpi --resumefrom a different directory, bash commands kept running in the launcher's directory while the rest of pi (including the footer) tracked the session's cwd.The extension only ever needed to rewrite background commands; the
registerToolcall existed to attach a description appendix. Dropping it lets pi's built-in bash tool (which is wired toAgentSession._cwd) execute the command, and thetool_callhandler still mutatesevent.input.commandin place to perform the rewrite.Changes
packages/bash-bg/src/index.ts: removeregisterTooland thecreateBashToolimport; keep only thetool_callrewrite.packages/bash-bg/test/index.test.ts: replace the description-appendix test with regression tests that assert the extension does not callregisterTool, that it registers atool_callhandler, and that the handler rewrites bg commands while leaving non-bg / non-bash calls alone.packages/bash-bg/README.md: drop the description-appendix mentions..changeset/bash-bg-fix-resume-cwd.md: patch entry.AGENTS.md: small guidance update asking for one-line changeset summaries.Trade-off
The bash tool description no longer carries a "background jobs continue running…" hint to the model. The rewritten command's
[bg] pid=... log=...output is self-explanatory in practice, and is well-aligned with how bash backgrounding is conventionally communicated.Context
Related upstream issue: earendil-works/pi#4006