fix(opencode): pass absolute worktree path to every subagent dispatch

Subagents do not inherit the orchestrator's `cd`, so dispatched prompts
that referred to files relative to the worktree were resolved against
the bare repo root and failed with "file not found" (observed when
@check tried to read src/main.rs after Phase 3).

Phase 3 now captures `WORKTREE_PATH="$(pwd)"` after entering the
worktree. A new "Subagent Dispatch Convention" section requires every
dispatch in phases 5, 7, 8, 9, and 10 to open with `Worktree: <path>`
and pass file references as absolute paths under `$WORKTREE_PATH/`.
Phase 9's diff command uses `git -C "$WORKTREE_PATH"` rather than
relying on shell CWD, and @pm updates receive the explicit absolute
path to `$WORKTREE_PATH/TODO.md`.
This commit is contained in:
Harald Hoyer 2026-05-06 15:56:45 +02:00
parent d22acf6906
commit 28c7785816

View file

@ -49,7 +49,21 @@ From `$BARE_REPO_ROOT`:
2. Compute worktree directory: replace all `/` with `-` in the branch name (e.g. `feat/abc-1-foo` becomes `feat-abc-1-foo`)
3. Check if worktree directory already exists. If yes, enter it and verify `git status --porcelain` is empty. If dirty, stop: "Worktree exists but has uncommitted changes. Clean it up first."
4. If worktree does not exist: `git worktree add <dir-name> -b <branch-name> "$DEFAULT_BRANCH"`
5. Change working directory to the new worktree. From here on, `./TODO.md` in the worktree is the **live, writable** copy that Phase 10 will update.
5. Change working directory to the new worktree and capture its absolute path: `WORKTREE_PATH="$(pwd)"`. From here on, `$WORKTREE_PATH/TODO.md` is the **live, writable** copy that Phase 10 will update.
---
## Subagent Dispatch Convention
**Subagents do not inherit the orchestrator's `cd`.** When opencode dispatches `@check`, `@simplify`, `@test`, `@make`, or `@pm`, each starts with a fresh shell in an unspecified working directory and may resolve relative paths against the bare repo root rather than the worktree. This produces silent "file not found" failures for paths like `src/main.rs`.
**Every dispatch prompt in Phases 5, 7, 8, 9, and 10 must:**
1. Open with the header `Worktree: <absolute path>` using the captured `$WORKTREE_PATH`.
2. State explicitly: "All file paths in this prompt are relative to that worktree. Read files via their absolute path (`<worktree>/<rel>`); do not rely on the current working directory."
3. Pass any file reference (in code context, diff snippets, file lists) as an absolute path under `$WORKTREE_PATH/`.
`@pm` invocations that update TODO.md must receive `$WORKTREE_PATH/TODO.md` as the live path. `@pm` invocations that only read from a git ref (Phase 2) instead receive `$BARE_REPO_ROOT` and the ref name.
---
@ -77,7 +91,7 @@ The plan should include:
## Phase 5: Review Plan
Dispatch `@check` and `@simplify` in parallel to review the plan.
Dispatch `@check` and `@simplify` in parallel to review the plan. Each dispatch prompt must follow the **Subagent Dispatch Convention** (header `Worktree: $WORKTREE_PATH`, absolute paths only).
Reviewers should evaluate testability:
- `@check`: Is the design testable? Are the right behaviors identified? (Review Framework §8)
@ -120,10 +134,10 @@ Include **Test Design** from Phase 4 when available, attached to the relevant ta
## Phase 7: Write Tests
For each task from Phase 6, dispatch `@test` with:
For each task from Phase 6, dispatch `@test` with (per the **Subagent Dispatch Convention**`Worktree: $WORKTREE_PATH`, absolute paths):
- The task spec (acceptance criteria, code context, files to modify)
- The Test Design section from the plan (if provided)
- The test file path to create (following colocated pattern)
- The test file path to create as an absolute path under `$WORKTREE_PATH/` (following colocated pattern)
`@test` writes failing tests and verifies RED with structured failure codes.
@ -156,9 +170,9 @@ If any non-matching file appears: discard `@test` output, report violation.
## Phase 8: Implement
Execute each task by dispatching `@make` with:
Execute each task by dispatching `@make` with (per the **Subagent Dispatch Convention**`Worktree: $WORKTREE_PATH`, absolute paths):
- The task spec (from Phase 6)
- Relevant code context (actual snippets)
- Relevant code context (actual snippets, with absolute file paths under `$WORKTREE_PATH/`)
- **Pre-written failing tests and handoff from `@test` (if TESTS_READY)**
`@make` runs in TDD mode when tests are provided:
@ -186,11 +200,11 @@ After all tasks complete, verify overall integration:
## Phase 9: Final Review
Dispatch `@check` and `@simplify` in parallel to review the full implementation (all changes across all files).
Dispatch `@check` and `@simplify` in parallel to review the full implementation (all changes across all files). Each dispatch prompt must follow the **Subagent Dispatch Convention** (header `Worktree: $WORKTREE_PATH`, absolute paths only).
Provide reviewers with:
- The original plan
- The full diff (`git diff "$DEFAULT_BRANCH"...HEAD`)
- The full diff (`git -C "$WORKTREE_PATH" diff "$DEFAULT_BRANCH"...HEAD`)
- Any decisions or deviations from the plan
**Review loop (max 3 cycles):**
@ -213,7 +227,7 @@ The workflow is forge-agnostic. It commits locally and stops. **Do not push, and
- If changes are large/varied, use multiple atomic commits (one per logical unit)
### TODO Update
- Use `@pm` to update the issue in `./TODO.md` (worktree-local; this is the live, writable copy):
- Dispatch `@pm` (per the **Subagent Dispatch Convention**) and pass the live path `$WORKTREE_PATH/TODO.md` so it edits the worktree's writable copy. Ask it to:
- Set **Branch** to the worktree branch name
- Set **Status** to `In Review`
- Add a comment with the branch name, latest commit SHA, and a one-line summary
@ -241,7 +255,7 @@ At any phase, if an unrecoverable error occurs:
1. Write `.opencode/workflow-summary.md` (in the worktree, if one exists) with what was completed and what failed
2. If any code was written, commit it with message `wip: incomplete workflow run for <issue-id>`
3. Leave the branch and worktree intact for the user to inspect — do not push, do not delete
4. If a worktree exists, use `@pm` to add a comment on the issue in `./TODO.md` summarising what failed
4. If a worktree exists, dispatch `@pm` (with header `Worktree: $WORKTREE_PATH` and the absolute path `$WORKTREE_PATH/TODO.md`) to add a comment on the issue summarising what failed
5. Stop execution
**Never hang on interactive prompts.** If any command appears to require input, treat it as a failure and follow the above procedure.