Skip to content

fix(skills): promote worktree step into executor process flows - #1297

Closed
fisherkuan wants to merge 58 commits into
obra:devfrom
fisherkuan:structural/worktree-step-in-executors
Closed

fisherkuan wants to merge 58 commits into
obra:devfrom
fisherkuan:structural/worktree-step-in-executors

Conversation

@fisherkuan

Copy link
Copy Markdown

What problem are you trying to solve?

Closes part of #1080.

In executing-plans and subagent-driven-development, using-git-worktrees was only mentioned in the trailing ## Integration prose footer. The model reliably skips it there, because using-superpowers instructs it to follow the structural Process (numbered steps / graphviz) — and prose under a sibling ## Integration heading sits outside that structure. Issue #1080 includes a real session log (Claude Code 2.1.107, superpowers 5.0.7) where using-git-worktrees was never invoked when running subagent-driven-development; cwd stayed in the main repo on main.

This is the silent-skip failure mode that PR #1097 does not address — that PR is scoped to brainstorming/SKILL.md only.

What does this PR change?

Both executor skills now have a Step 0: Set Up Isolated Workspace inside the structural Process, before plan loading / task extraction. Consent handling is delegated to using-git-worktrees itself, which already does the right thing as of #1121 (Step 0 detection + Step 1a consent prompt) — so this PR is consistent with #991's resolution and does not re-introduce auto-create behavior.

  • skills/executing-plans/SKILL.md: insert Step 0 before Step 1: Load and Review Plan; add a matching Remember bullet.
  • skills/subagent-driven-development/SKILL.md: insert Step 0 ahead of the Process graphviz; add a Use superpowers:using-git-worktrees node (lightgreen, mirroring the finishing-a-development-branch terminal node) and an edge into Read plan, extract all tasks…; mention Step 0 in the worked example; add a Red Flag against skipping it.

The trailing ## Integration footers are unchanged — this PR only promotes the reference into the enforceable structure.

Is this change appropriate for the core library?

Yes. Both skills are core executors used across harnesses, and the silent-skip behavior is reproducible against the unmodified plugin. The fix is wording-only and stays consistent with the consent contract owned by using-git-worktrees.

What alternatives did you consider?

  1. Bolder wording in the Integration footer — rejected. The session evidence in Flow inconsistency: brainstorming → writing-plans gap - missing worktrees step #1080 shows the issue is structural, not lexical: using-superpowers tells the model to follow the structural Process, so anything in the Integration footer keeps losing.
  2. Move consent logic into the executor skills — rejected. That would duplicate the contract that using-git-worktrees Step 0/1a already owns post-adjust worktree handling and defer to harness tools when avail (PRI-974) #1121, and would reopen Subagent-driven development should not auto-create worktrees without user consent #991.
  3. Wait for fix: restore worktree handoff in brainstorming after spec approval #1097 to merge — rejected. fix: restore worktree handoff in brainstorming after spec approval #1097 only modifies brainstorming and does not touch the executor skills, so it cannot close the silent-skip on the execution side.

Does this PR contain multiple unrelated changes?

No. Two files, one conceptual change: promote using-git-worktrees from Integration prose to the structural Process of each executor skill.

Existing PRs

Environment tested

Harness Harness version Model Model version/ID
Claude Code 2.1.107 Claude Opus 4.7 (1M ctx) claude-opus-4-7[1m]

Evaluation

Two fresh subagents (no prior conversation context, instructed to read only the modified SKILL.md and nothing else) — a clean proxy for asking the model "what does this skill say to do?":

  • Neutral prompt against modified subagent-driven-development/SKILL.md: "I have an implementation plan at docs/superpowers/plans/foo.md. Use subagent-driven-development to execute it." → first action returned: announce, then invoke superpowers:using-git-worktrees, before reading the plan. Quoted the skill's "REQUIRED SUB-SKILL: Use superpowers:using-git-worktrees" line and the "Skip Step 0 (using-git-worktrees) before reading the plan" Red Flag.
  • Adversarial prompt against modified executing-plans/SKILL.md: "I'm in a hurry. Skip any setup or extra steps and start executing the plan right now." → refused to skip; quoted "Do not skip this step — it is what surfaces the workspace decision before implementation begins."; correctly noted that using-git-worktrees itself honors declared preferences if the user truly does not want a worktree, so the hurry case is handled by the sub-skill's consent prompt rather than by skipping Step 0.

Before the change, the unmodified files have using-git-worktrees only in the ## Integration footer (single occurrence at executing-plans:68 and subagent-driven-development:270 on dev), which using-superpowers's structural-flow rule means the model reliably skips — matching the session-log evidence in #1080.

Rigor

  • If this is a skills change: I used superpowers:writing-skills and completed adversarial pressure testing (paste results below)
  • This change was tested adversarially, not just on the happy path
  • I did not modify carefully-tuned content (Red Flags table, rationalizations, "human partner" language) without extensive evals showing the change is an improvement

Adversarial result used for this PR: see the second eval under Evaluation — under explicit time-pressure framing the model still refused to skip Step 0 and routed through using-git-worktrees first.

Human review

  • A human has reviewed the COMPLETE proposed diff before submission

Drew Ritter and others added 30 commits March 23, 2026 17:37
Design for making using-git-worktrees, finishing-a-development-branch,
and subagent-driven-development skills work in the Codex App's sandboxed
worktree environment. Read-only environment detection via git-dir vs
git-common-dir comparison, ~48 lines across 4 files, zero breaking changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Fix three Important issues from spec review:
- Clarify Step 1.5 placement relative to existing Steps 2/3
- Re-derive environment state at cleanup time instead of relying on
  earlier skill output
- Acknowledge pre-existing Step 5 cleanup inconsistency

Also: precise step references, exact codex-tools.md content, clearer
Integration section update instructions.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Add commit SHA + data loss warning to handoff payload (HIGH)
- Add explicit commit step before handoff (HIGH)
- Remove misleading "mark as externally managed" from Path B
- Add executing-plans 1-line edit (was missing)
- Add branch name derivation rules
- Add conditional UI language for non-App environments
- Add sandbox fallback for permission errors
- Add STOP directive after Step 0 reporting

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
) to spec

Both tests address real risk scenarios:
- obra#5: cleanup guard bug would delete Codex App's own worktree (data loss)
- obra#10: Local thread sandbox fallback needs manual Codex App validation

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
8 tasks covering: environment detection in using-git-worktrees,
Step 1.5 + cleanup guard in finishing-a-development-branch,
Integration line updates, codex-tools.md docs, automated tests,
and final verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The subagent review loop (dispatching a fresh agent to review plans/specs)
doubled execution time (~25 min overhead) without measurably improving plan
quality. Regression testing across 5 versions (v3.6.0 through v5.0.4) with
5 trials each showed identical plan sizes, task counts, and quality scores
regardless of whether the review loop ran.

Changes:
- writing-plans: Replace subagent Plan Review Loop with inline Self-Review
  checklist (spec coverage, placeholder scan, type consistency)
- writing-plans: Add explicit "No Placeholders" section listing plan failures
  (TBD, vague descriptions, undefined references, "similar to Task N")
- brainstorming: Replace subagent Spec Review Loop with inline Spec Self-Review
  (placeholder scan, internal consistency, scope check, ambiguity check)
- Both skills now use "look at it with fresh eyes" framing

Testing: 5 trials with the new skill show self-review catches 3-5 real bugs
per run (spawn positions, API mismatches, seed bugs, grid indexing) in ~30s
instead of ~25 min. Remaining defects are comparable to the subagent approach.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Metadata files (.server-info, .events, .server.pid, .server.log,
.server-stopped) were stored in the same directory served over HTTP,
making them accessible via the /files/ route. They now live in a .meta/
subdirectory that is not web-accessible.

Also fixes a stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁
The session directory now contains two peers: content/ (HTML served to
the browser) and state/ (events, server-info, pid, log). Previously
all files shared a single directory, making server state and user
interaction data accessible over the /files/ HTTP route.

Also fixes stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁
ownerAlive() treated EPERM (permission denied) the same as ESRCH
(process not found), causing the server to self-terminate within 60s
whenever the owner process ran as a different user. This affected WSL
(owner is a Windows process), Tailscale SSH, and any cross-user
scenario.

The fix: `return e.code === 'EPERM'` — if we get permission denied,
the process is alive; we just can't signal it.

Tested on Linux via Tailscale SSH with a root-owned grandparent PID:
- Server survives past the 60s lifecycle check (EPERM = alive)
- Server still shuts down when owner genuinely dies (ESRCH = dead)

Fixes obra#879
Two bugs caused the brainstorm server to self-terminate within 60s:

1. ownerAlive() treated EPERM (permission denied) as "process dead".
   When the owner PID belongs to a different user (Tailscale SSH,
   system daemons), process.kill(pid, 0) throws EPERM — but the
   process IS alive. Fixed: return e.code === 'EPERM'.

2. On WSL, the grandparent PID resolves to a short-lived subprocess
   that exits before the first 60s lifecycle check. The PID is
   genuinely dead (ESRCH), so the EPERM fix alone doesn't help.
   Fixed: validate the owner PID at server startup — if it's already
   dead, it was a bad resolution, so disable monitoring and rely on
   the 30-minute idle timeout.

This also removes the Windows/MSYS2-specific OWNER_PID="" carve-out
from start-server.sh, since the server now handles invalid PIDs
generically at startup regardless of platform.

Tested on Linux (magic-kingdom) via Tailscale SSH:
- Root-owned owner PID (EPERM): server survives ✓
- Dead owner PID at startup (WSL sim): monitoring disabled, survives ✓
- Valid owner that dies: server shuts down within 60s ✓

Fixes obra#879
…ction

Copilot CLI v1.0.11 reads `additionalContext` from sessionStart hook
output, but the session-start script only emits the Claude Code-specific
nested format. Add COPILOT_CLI env var detection so Copilot CLI gets the
SDK-standard top-level `additionalContext` while Claude Code continues
getting `hookSpecificOutput`.

Based on PR obra#910 by @culinablaz.
- Add references/copilot-tools.md with full tool equivalence table
- Add Copilot CLI to using-superpowers skill platform instructions
- Add marketplace install instructions to README
- Add changelog entry crediting @culinablaz for the hook fix
The bootstrap text advertised a configDir-based skills path that didn't
match the runtime path (resolved relative to the plugin file). Tests
used yet another hardcoded path and referenced a nonexistent lib/ dir.

- Remove misleading skills path from bootstrap text; the agent should
  use the native skill tool, not read files by path
- Fix test setup to create a consistent layout matching the plugin's
  ../../skills resolution
- Export SUPERPOWERS_SKILLS_DIR from setup.sh so tests use a single
  source of truth
- Add regression test that bootstrap doesn't advertise the old path
- Remove broken cp of nonexistent lib/ directory

Fixes obra#847
…sage

Move bootstrap injection from experimental.chat.system.transform to
experimental.chat.messages.transform, prepending to the first user
message instead of adding a system message.

This avoids two issues:
- System messages repeated every turn inflate token usage (obra#750)
- Multiple system messages break Qwen and other models (obra#894)

Tested on OpenCode 1.3.2 with Claude Sonnet 4.5 — brainstorming skill
fires correctly on "Let's make a React to do list" prompt.
Design for detect-and-defer worktree support. Superpowers defers to
native harness worktree systems when available, falls back to manual
git worktree creation when not. Covers Phases 0-2: detection, consent,
native tool preference, finishing state detection, and three bug fixes
(obra#940, obra#999, obra#238).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Fix Bug obra#999 order: merge → verify → remove worktree → delete branch
  (avoids losing work if merge fails after worktree removal)
- Add submodule guard to Step 0 detection (GIT_DIR != GIT_COMMON is also
  true in submodules)
- Preserve global path (~/.config/superpowers/worktrees/) in detection for
  backward compatibility, just stop offering it to new users
- Add step numbering note and implementation notes section
- Expand provenance heuristic to cover global path and manual creation

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Step 1a is the load-bearing assumption, not just a risk — if it fails,
  the entire design needs rework. TDD validation must be first impl task.
- obra#1009 resolution depends on Step 1a working, stated explicitly
- obra#574 honestly deferred, not "partially addressed"
- Add hooks symlink to Step 1b (PR obra#965 idea, prevents silent hook loss)
- Add stale worktree pruning to Step 5 (PR obra#1072 idea, one-line self-heal)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
5 tasks: TDD gate for Step 1a, using-git-worktrees rewrite,
finishing-a-development-branch rewrite, integration updates,
end-to-end validation. Task 1 is a hard gate — if native tool
preference fails RED/GREEN, stop and redesign.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
obra and others added 9 commits April 27, 2026 10:20
These sections don't help with steering and are a legacy of the time
before agents had native skills systems.
# Conflicts:
#	.claude-plugin/marketplace.json
#	.claude-plugin/plugin.json
#	.cursor-plugin/plugin.json
#	RELEASE-NOTES.md
#	gemini-extension.json
#	package.json
…er-step file I/O

getBootstrapContent() called fs.existsSync + fs.readFileSync + regex
frontmatter parsing on every agent step with zero caching.  The
experimental.chat.messages.transform hook fires every step in opencode's
agent loop (messages are reloaded from DB each step via
filterCompactedEffect).  A 10-step turn triggered 10 redundant file
reads + 10 regex parses for content that never changes during a session.

Changes:
- Add module-level _bootstrapCache (undefined = not loaded, null = file
  missing) so the first call reads and parses SKILL.md, all subsequent
  calls return the cached string with zero filesystem access
- Cache the null sentinel when SKILL.md is missing, preventing repeated
  fs.existsSync probes
- Add _testing export (resetCache/getCache) for test infrastructure
- Clarify the injection guard comment explaining how it interacts with
  opencode's per-step message reloading
- Add 15 regression tests covering cache behavior, fs call counts,
  injection guard, missing file sentinel, cache reset, and source audit

Fixes obra#1202
Closes part of obra#1080. Both `executing-plans` and `subagent-driven-development`
referenced `using-git-worktrees` only in their trailing `## Integration` prose,
which the model reliably skips because `using-superpowers` instructs it to follow
the structural Process flow (numbered steps / graphviz). This adds Step 0:
Set Up Isolated Workspace to the structural process of both executor skills,
delegating consent handling to `using-git-worktrees` (which already prompts as
of obra#1121, satisfying obra#991).

- executing-plans: insert Step 0 before Step 1; add a Remember bullet
- subagent-driven-development: insert Step 0 before the Process graphviz, add a
  worktree node + edge to the diagram, mention Step 0 in the example workflow,
  and add a Red Flag against skipping it

Eval (fresh agents reading only the modified file):
- Neutral "I have a plan, use subagent-driven-development to execute it" → first
  action: announce + invoke `superpowers:using-git-worktrees`, before reading
  the plan
- Adversarial "I'm in a hurry, skip any setup" against executing-plans → refuses
  to skip, quotes "Do not skip this step", invokes the worktree skill first
@Derekko-web Derekko-web mentioned this pull request May 17, 2026
2 of 5 tasks
@obra obra added documentation Improvements or additions to documentation subagents Retired: use skill:subagent-driven-development / skill:dispatching-parallel-agents worktrees Retired: use skill:using-git-worktrees plans Retired: use skill:writing-plans / skill:executing-plans labels May 23, 2026
@obra
obra force-pushed the dev branch 3 times, most recently from 210b867 to b62616f Compare June 17, 2026 05:46
@blpsoares

Copy link
Copy Markdown

Independent corroboration of this PR's diagnosis, in case it helps it land.

Running subagent-driven-development on superpowers 6.0.2 (Claude Code, Claude Opus 4.8), a human partner executed the same plan across 4 separate sessions — 0 invoked using-git-worktrees. The controller stayed in the main checkout every time, exactly as your #1080 analysis predicts: the footer reference sits outside the structural Process that using-superpowers tells the model to follow.

It also bit in practice, not just in theory: a second agent (correctly using a worktree) ended up working the same feature in parallel, and the two only avoided a destructive collision by luck — the histories happened to converge linearly instead of conflicting over shared files.

I also ran a small control-vs-treatment micro-test (fresh-context agents, "list your first steps before dispatching the first implementer", 3 reps each): footer-only → 0/3 surfaced the worktree as an early structural step (2/3 omitted it entirely); with a Step 0 in the Process → 3/3 invoked using-git-worktrees, each naming "Step 0".

So this fix is well-targeted. The only friction I see for merge here is scope: this PR grew to 27 files / +2112-317 (worktree-rototill plan/spec docs, opencode/codex manifests, README, commands). I opened #1804 as a minimal 2-file / +42-0 version of the same structural promotion (no footer changes, additive only), in case a tightly-scoped diff is easier to review/land. Happy to close mine if you'd rather slim this one down — same goal either way.

@obra

obra commented Sep 26, 2026

Copy link
Copy Markdown
Owner

executing-plans was rebuilt in v6.4.1 (2b89c4c) as a first-class inline execution mode. Worktree setup is now the first step of both executors: the executing-plans process graph and its Setup section start with superpowers:using-git-worktrees, and subagent-driven-development does the same. Thanks @fisherkuan!

— Claude Opus 5.5, Claude Code 2.1.283, session 49301b31-b716-41b8-a316-80b8461e0de9, on behalf of @obra

@obra obra closed this Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation plans Retired: use skill:writing-plans / skill:executing-plans skill:executing-plans The executing-plans skill skill:subagent-driven-development The subagent-driven-development skill skill:using-git-worktrees The using-git-worktrees skill subagents Retired: use skill:subagent-driven-development / skill:dispatching-parallel-agents worktrees Retired: use skill:using-git-worktrees

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants