feat(workspace): bootstrap worktrees by default (closes #50)#51
Merged
Conversation
c69c9ce to
0bb064f
Compare
`worktree add` now runs detected setup after creating the checkout so it
is immediately test/build-ready. Each step is skipped gracefully when
its trigger file or tool is missing:
1. `git submodule update --init --recursive` when `.gitmodules` exists
2. Package-manager install based on lockfile priority (pnpm > bun > yarn > npm):
pnpm-lock.yaml → pnpm install --frozen-lockfile
bun.lockb/.lock → bun install --frozen-lockfile
yarn.lock → yarn install --immutable
package-lock.json → npm ci
3. `composer install --no-interaction --prefer-dist` when `composer.lock` exists
Defaults to on because worktrees are overwhelmingly created to do branch
work — run tests, build, commit, push — not to read code. Read-only
consumers should use the primary checkout (which is already read-only by
default). Pass `--skip-bootstrap` to create a bare worktree when you
really only need to read.
A failed bootstrap step is surfaced in the result with exit code and
output tail, but does NOT roll back the worktree. The checkout stays
created so the user can retry manually.
Changes:
- New `DataMachineCode\\Workspace\\WorktreeBootstrapper` class (pure PHP,
no WP dependency) with detect / bootstrap / format helpers.
- `Workspace::worktree_add()` gains a `$bootstrap` param (default true).
- Ability `datamachine/workspace-worktree-add` gains a `bootstrap` input
(default true) and surfaces a `bootstrap` object in the output schema.
- CLI `worktree add` gains `--skip-bootstrap` (matches the existing
`--skip-context-injection` convention).
- Success output includes a `Bootstrap: ok` block listing each step.
Tests:
- `tests/smoke-worktree-bootstrap.php` — 30 pure-PHP assertions covering
detection priority, skip behavior, a real-repo submodule run, and
failure formatting.
- `tests/TESTING.md` — new section 3a with CLI smoke steps for both
default-on and `--skip-bootstrap` paths.
Follow-ups (out of scope per issue #50):
- `.datamachine/worktree.yml` manifest for repo-declared custom chains
- Teardown on `worktree remove`
- pnpm-style content-addressed `node_modules` sharing
0bb064f to
73527eb
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
worktree addnow runs detected setup steps by default so the new checkout is immediately test/build-ready. Pass--skip-bootstrapto opt out for pure-read use. Closes #50.Why on by default
The earlier draft of this PR shipped
--bootstrapas opt-in (matching the wording in the issue). Reconsidered after discussion: worktrees are overwhelmingly created to do branch work (run tests, build, commit, push), not to read code. Read-only consumers can use the primary checkout, which is already read-only by default. Making bootstrap opt-in forces every new agent to know about the flag or they silently hit the exact trap the issue describes (vitest can't load spec,sh: nx: command not found).Making it on-by-default with a
--skip-bootstrapescape hatch mirrors the existinginject_context=true+--skip-context-injectionconvention for agent-memory injection from #45. Consistent mental model across worktree setup surfaces.What bootstrap does
Three independent steps, in order, each skipped gracefully when trigger file or tool is missing:
git submodule update --init --recursive— if.gitmodulesexistspnpm-lock.yaml→pnpm install --frozen-lockfilebun.lockb/bun.lock→bun install --frozen-lockfileyarn.lock→yarn install --immutablepackage-lock.json→npm cicomposer install --no-interaction --prefer-dist— ifcomposer.lockexistsA repo with
package.jsonbut no lockfile is treated as "no package-manager step" — we never guess which manager to use.Safety model
$PATHreportsskippedwith a reason, not an error. Missing trigger file = skipped.FAILEDin the result and shown as a CLI warning, but the worktree itself stays created so the user can retry manually. Matches the existingcontext_injected=false + context_skip_reason=…precedent from Inject site-agent context into worktrees on creation #45.WorktreeBootstrapperis a pure class sotests/smoke-worktree-bootstrap.phpexercises it without a WP bootstrap.Output
Files
inc/Workspace/WorktreeBootstrapper.php— detect + bootstrap + format helperstests/smoke-worktree-bootstrap.php— 30 assertions covering detection priority, skip behavior, real-repo submodule run, failure formattinginc/Workspace/Workspace.php— new$bootstrapparam onworktree_add()(defaulttrue)inc/Abilities/WorkspaceAbilities.php—bootstrapinput ondatamachine/workspace-worktree-add(defaulttrue) + output schemainc/Cli/Commands/WorkspaceCommand.php—--skip-bootstrapflag, help block, result renderingtests/TESTING.md— new section 3a for the CLI smokeTesting
Pure smokes (62/62 passing):
Covers: detect() priority (pnpm > bun > yarn > npm), skip on empty dir, real-repo submodule run, format() output shape (ran + failed + skipped markers, failure output tail).
Live CLI tests on
intelligence-chubes4Studio site:data-machinenpm ciran,composer installran,node_modules/+vendor/populated--skip-bootstrapdata-machine-codevendor/in worktreedata-machine-code--skip-context-injectiondefault-bootstrapdata-machine-codeOut of scope (follow-ups)
.datamachine/worktree.yml) for custom chains likenx build shared-types— option 3 in Worktree add doesn't bootstrap dependencies (node_modules, submodules) #50worktree removenode_modulessharing across worktreesAI assistance
--skip-bootstrapescape hatch. Chris ran live worktree-add scenarios ondata-machineanddata-machine-codefrom theintelligence-chubes4Studio site to confirm end-to-end behavior for both defaults and the escape hatch.