fix(bash): honor explicit working directories

This commit is contained in:
jb
2026-09-04 16:47:41 -04:00
parent 3d68f7c6bf
commit 328faa03e0
13 changed files with 316 additions and 21 deletions
+16 -15
View File
@@ -3,8 +3,8 @@
## Status
- Status: active
- Current phase: 5. Implement owned slices
- Next safe action: implement and verify the approved optional `cwd` Bash argument.
- Current phase: 6. Verify the integrated worktree
- Next safe action: commit the focused implementation, then run the full repository test suite.
## Request and scope
@@ -22,14 +22,14 @@
## Acceptance criteria
- [ ] `@jbcode/pi-bash-cwd` overrides the built-in `bash` tool with one backward-compatible optional `cwd` argument while preserving the existing command, timeout, output, truncation, cancellation, session-environment, and renderer contracts.
- [ ] Absolute and relative `cwd` values resolve from the live session `ctx.cwd`; omitted `cwd` retains the session directory.
- [ ] The requested directory is validated before delegating command execution.
- [ ] A regression test executes `pwd` from both a disposable hidden worktree root and a nested workspace package directory and observes the requested directory.
- [ ] A missing requested working directory fails before the shell command can create a sentinel side effect.
- [ ] Package inventory, README guidance, and the upstream Pi 0.85.0 packaging blocker TODO are synchronized.
- [x] `@jbcode/pi-bash-cwd` overrides the built-in `bash` tool with one backward-compatible optional `cwd` argument while preserving the existing command, timeout, output, truncation, cancellation, session-environment, and renderer contracts.
- [x] Absolute and relative `cwd` values resolve from the live session `ctx.cwd`; omitted `cwd` retains the session directory.
- [x] The requested directory is validated before delegating command execution.
- [x] A regression test executes `pwd` from both a disposable hidden worktree root and a nested workspace package directory and observes the requested directory.
- [x] A missing requested working directory fails before the shell command can create a sentinel side effect.
- [x] Package inventory, README guidance, and the upstream Pi 0.85.0 packaging blocker TODO are synchronized.
- [ ] Existing repository typecheck and test suites pass.
- [ ] The resolved Bash cwd TODO and temporary workaround language are removed or updated without changing unrelated historical evidence.
- [x] The resolved Bash cwd TODO and temporary workaround language are removed or updated without changing unrelated historical evidence.
## Approved implementation plan and gates
@@ -45,7 +45,7 @@
| --- | --- | --- | --- | --- | --- |
| Workflow setup and research | parent Pi session `01a06e08-8d07-76a7-a116-d7e3baf55b87` | 15 minutes | workflow record only | Before: clean `main` at `7e7cfdb`; after: clean feature worktree at `5f853dc` | Complete |
| Initial dependency-plan implementation | parent Pi session `01a06e08-8d07-76a7-a116-d7e3baf55b87` | 15 minutes | `package.json`, `bun.lock`, focused test, workflow record | Before: clean feature worktree at `9d68d5f`; after: Pi 0.85.0 upgrade restored; focused red test retained unstaged | Paused and replanned after upstream packaging blocker |
| Local override implementation | parent Pi session `01a06e08-8d07-76a7-a116-d7e3baf55b87` | 15 minutes | `extensions/bash-cwd/**`, `scripts/bash-cwd.test.mjs` removal, `package.json`, `scripts/package-workspaces.test.mjs`, `README.md`, `docs/npm-packages.md`, `docs/todos.md`, `docs/workflow/skill-led-development-workflow-plan.md`, workflow record | Before: feature worktree at `f61f197` with inspected product changes | In progress under corrected approval |
| Local override implementation | parent Pi session `01a06e08-8d07-76a7-a116-d7e3baf55b87` | 15 minutes | `extensions/bash-cwd/**`, `scripts/bash-cwd.test.mjs` removal, `package.json`, `scripts/package-workspaces.test.mjs`, `README.md`, `docs/npm-packages.md`, `docs/todos.md`, `docs/workflow/skill-led-development-workflow-plan.md`, workflow record | Before: feature worktree at `3d68f7c` with inspected product changes; after: focused checks pass, product commit pending | Complete |
## Verification matrix
@@ -53,10 +53,11 @@
| --- | --- | --- | --- |
| Source/cache preflight | `git status --short --branch`; `opensrc path ...` | 0 | Clean source; Pi 0.84.4 and 0.85.0 source available locally. |
| Focused cwd reproduction | inline Node harness against Pi 0.84.4 | 0 (asserted buggy outcome) | Both hidden-worktree requests observed the primary checkout; a missing requested cwd still executed a sentinel command. |
| Focused cwd regression | pending repository test | pending | pending |
| Typecheck | `bun run typecheck` | pending | pending |
| Focused cwd regression | `bun run --filter '@jbcode/pi-bash-cwd' test` | 0 | Three tests pass: explicit absolute hidden-worktree cwd, relative nested-package cwd, omitted cwd/session environment, schema compatibility, missing cwd sentinel, and missing context. |
| Package contract | `bun run test:packages`; `bun pm pack --destination /tmp --ignore-scripts --quiet` | 0 | Workspace inventory and package contents pass; package tarball created. |
| Typecheck | `bun run typecheck` | 0 | Repository TypeScript check passes. |
| Full tests | `bun run test` | pending | pending |
| Fresh-process integration | pending | pending | pending |
| Fresh-process integration | focused test's delegated real Bash subprocesses | 0 | Commands execute through Pi 0.84.4's built-in Bash definition with session metadata preserved. |
## Review
@@ -81,6 +82,6 @@
## Checkpoints and blockers
- Last committed valid checkpoint: corrected-plan record commit `PENDING`
- Last committed valid checkpoint: corrected-plan approval commit `3d68f7c`
- Blockers: none.
- Exact next safe action: implement the optional `cwd` schema, path preflight, and explicit-argument regression cases.
- Exact next safe action: checkpoint the focused implementation and run `bun run test`.
@@ -100,7 +100,7 @@ Reuse rather than wrap:
- `artifact-presenter`: plan and long-artifact review.
- Git worktrees and normal project commands: isolation, commits, verification, rebase, and integration.
Known harness defects are workflow constraints, not footnotes. Until fixed, launch subagents directly rather than through `multi_tool_use.parallel`; never park the parent solely on an expected callback; and verify that each result was delivered. For shell work inside hidden worktrees, use explicit `cd <worktree> && ...` or `git -C <worktree> ...`, then verify `pwd` or Git's top-level path before mutation because the Bash tool has previously ignored its configured working directory.
Known harness defects are workflow constraints, not footnotes. Until fixed, launch subagents directly rather than through `multi_tool_use.parallel`; never park the parent solely on an expected callback; and verify that each result was delivered. `@jbcode/pi-bash-cwd` adds validated per-call Bash working directories on Pi 0.84.x. Shell mutations inside hidden worktrees still use explicit `cd <worktree> && ...` or `git -C <worktree> ...`, followed by `pwd` or Git top-level verification, as defense-in-depth.
Before starting the full path, preflight required capabilities. Git worktree operations, a writable retained record, an explicit human interaction channel, target-interface validation when applicable, and a Git-capable independent reviewer are mandatory. Todo-herdr and artifact-presenter may degrade to the retained record and a reported artifact path, but their absence cannot bypass a gate. In print or JSON mode, or whenever a mandatory gate or validator cannot run, emit the pending decision or validation instructions and stop before product mutation.
@@ -144,7 +144,7 @@ When uncertain, use the full path. Record why the light path is safe when a chan
1. Read repository instructions, relevant docs, ADRs, tests, and current Git state.
2. Record the source branch and exact base commit.
3. Create `./.worktrees/<feature>` on a descriptive feature branch before feature edits.
4. Prove every subsequent shell command's location with explicit `cd` or `git -C`; do not rely on the Bash tool's configured `cwd` until its tracked defect is fixed.
4. Prove every subsequent shell command's location with explicit `cd` or `git -C`; treat the Bash cwd override as protection against fallback execution, not a replacement for the location proof.
5. If the source checkout is dirty, explain exactly which changes the new worktree omits and ask before proceeding.
6. Atomically create the unique workflow record in the worktree and create a task tree in the session.
7. Run applicable documentation checks, then commit the initial record as a pre-mutation recovery checkpoint.