Skip to content

Fix cwd-changing worktree shims stranding the caller; self-repair disabled rc blocks#46

Merged
drabaioli merged 3 commits into
mainfrom
cdd_worktree_cwd_regression
Jul 4, 2026
Merged

Fix cwd-changing worktree shims stranding the caller; self-repair disabled rc blocks#46
drabaioli merged 3 commits into
mainfrom
cdd_worktree_cwd_regression

Conversation

@drabaioli

Copy link
Copy Markdown
Owner

Summary

The ~/.local/bin PATH shims for the three cwd-changing worktree commands (cdd-worktree, cdd-worktree-resume, cdd-worktree-done) previously did source-and-dispatch. But a shim runs in a subshell, whose cd cannot reach the caller's shell — so cdd-worktree-done, invoked via the shim (e.g. from a non-interactive shell where the sourced function isn't loaded), silently stranded the user in the just-removed worktree while printing success.

  • Refuse loudly: the three cwd-changing shims now print guidance (source the helper / open a new shell) and exit 1 instead of dispatching. Only cdd-worktree-list, which changes no cwd, keeps a real source+dispatch shim (as does cdd-state).
  • Self-repair: both installers (cdd-worktree.sh, cdd-state.sh) now key "already wired" on the active source line — a regex anchored to line-start, so a commented-out block can't match — rather than a bare marker grep. Re-running install therefore re-enables a disabled/mangled rc block instead of skipping it.

Testing

scripts/install-smoke-assert.sh extended to cover both behaviors:

  • the cwd-changing shim (cdd-worktree-done) fails loudly rather than silently no-op'ing the cd;
  • install self-repairs a disabled managed block back to a single active source line, for both the worktree and state helpers.

All pre-PR gates pass: bash -n, shellcheck, command-set drift, prompt-seam, install smoke, worktree-resume, e2e bootstrap smoke, demo seed-overlay.

Docs

Process doc §2.8 (worktree helper) updated to describe refuse-loudly + self-repair; roadmap Phase 8 records the fix.

🤖 Generated with Claude Code

drabaioli and others added 2 commits July 4, 2026 14:52
cdd-worktree-done (and cdd-worktree/-resume) `cd` the caller's shell, so they
only work as sourced functions. The install shims dispatched into a subshell,
whose `cd` can't reach the parent — when the command resolved to the shim
(function not loaded, e.g. a commented-out rc block) the caller was silently
left in the just-removed worktree while the shim printed success.

- Ship a refuse-shim for the three cwd-changing commands: reaching it means the
  function isn't loaded, so it fails loudly with guidance instead of dispatching.
  cdd-worktree-list keeps its source-and-dispatch shim (it changes no cwd).
- Make install self-repairing: key the idempotency guard on the active source
  line, not a bare marker match, so a present-but-disabled (commented-out) block
  is rewritten as an active one instead of skipped. Same fix in cdd-state.sh.
- Fix the shim-loop comment that omitted cdd-worktree-done from the cwd-sensitive
  commands.
- Extend install-smoke-assert.sh: disabled block is repaired on re-install (both
  helpers), and a cwd-changing shim fails loudly rather than silently no-op'ing.
- Document the refuse-shim behavior and self-repair in process doc §2.8.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds a checked Phase 8 bug-fix entry for the cwd-changing shim regression
and the installer self-repair, reconciling the roadmap with what landed in
this branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread doc/knowledge_base/roadmap.md Outdated
Comment thread doc/knowledge_base/claude-driven-development.md Outdated
Comment thread tools/cdd-worktree.sh Outdated
…mments (PR #46 review)

Addresses review feedback on PR #46:
- roadmap.md: collapse the verbose worktree-shim fix entry to a one-liner.
- claude-driven-development.md §2.8: trim the worktree-helper paragraph
  back to a high-level description, dropping the shim internals this PR
  had added.
- cdd-worktree.sh / cdd-state.sh: shorten the rc self-repair and PATH-shim
  comment blocks, keeping the load-bearing "why" without the repetition.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@drabaioli drabaioli merged commit 271cf6b into main Jul 4, 2026
1 check passed
@drabaioli drabaioli deleted the cdd_worktree_cwd_regression branch July 4, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant