Repository navigation
fix(wrappers): borrow a projection in the openspec wrapper for a linked worktree - #204
Merged
Merged
Conversation
…ed worktree The openspec wrapper only walked upward for a projection of its own, so a linked worktree that mate wrap never ran in ended at the refusal. It now borrows as the TypeScript resolver does: from the main worktree first, then from each linked worktree that points back to its record, and it uses the worktree's root as the repository. In a Companion Repository the refusal now points to a wrapped Working Repository checkout instead of telling the operator to run mate wrap there.
…nfirm The openspec wrapper took the folder beside the shared Git folder as the main worktree whenever git could not read the config, so a bare clone or one with core.worktree set could lend where the TypeScript resolver returns null. It now lends from the main worktree only when git itself reports core.bare as false. A record folder without a gitdir file, or a stray file under worktrees/, no longer prints a bash error. Two tests cover the bare check and the record that does not point back, and the test helper fails on a Git error and drops an inherited GIT_DIR.
…per-borrows-in-worktree
The openspec wrapper looped forever when it started in a folder that was deleted. bash leaves PWD empty there, so the two upward walks never reached "/", and pwd -P gave the borrow path an empty root. All three now end, and the wrapper refuses as it does without a Mate context. The borrow path now tests a worktree record's folder for a projection before the point-back check, which starts several processes per record. The main worktree rule moved into _mate_git_confirmed_main_worktree. The tests take their Git fixtures from test/git-checkouts.ts, which also gives them relative worktree paths. A new group pins the wrapper to resolveProjection: it may refuse or agree, and never picks another lender.
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
The
openspecwrapper refused with "no mate context here" in a linked worktree thatmate wrapnever ran in, for example one made bymate working worktreewhose wrap was skipped. It only walked upward for a projection of its own. The TypeScript resolver (borrowedProjectioninsrc/runtime/projection.ts) borrows in that case, and the specs require the same of wrapper scripts.The borrow is a fallback only: a resolution that worked before is unchanged. A Companion Repository still resolves no context without a launch.
Fixes friction reports
43c9f44a,809b4f56,0f9c6f0f.OpenSpec change:
openspec-wrapper-borrows-in-worktree(schemamate-minimal, capabilitycli-wrapper-packaging, two added requirements). It is not submitted yet. It has no scenario for a deleted folder.Not in this PR:
wrappers/bin/graphifyhas the same walk and is left untouched. #188 removes graphify from mate-core, so a change there would be a modify/delete conflict.Second commit: review round
gititself reportscore.bareasfalse. Agitthat cannot run no longer makes the folder beside the shared Git folder count as the main worktree.gitdirfile, or a stray file underworktrees/, no longer prints a raw bash error.Third commit: finishing round
mainalready loops there when the environment carries noPWD: bash leavesPWDempty, and the upward walk never reaches/. The first two commits added the same loop twice (pwd -Pwith an empty result, and the Companion Repository check). All three walks now end, and the wrapper refuses.projection.envbefore the point-back check, which starts several processes per record. A record without a projection now starts no process._mate_git_confirmed_main_worktree.test/git-checkouts.ts, which also gives relative worktree paths where Git supports them. A new group pins the wrapper toresolveProjection: the wrapper may refuse or agree, and never picks another lender. The fixture now writesprojection.yamlandprojection.envtogether, asmate wrapdoes.Known gaps, not fixed here
acme/.claude/worktrees/fixresolvesacmeas the repository, and a worktree inside another project's checkout resolves that project's companion.mainbehaves the same. A follow-up change is agreed..mate/is used, not borrowed. The resolver borrows instead. Unchanged frommain.projection.envalone. The resolver readsprojection.yaml. Mate writes both files as one unit. When they disagree, the wrapper refuses where the resolver lends (env file names no companion), or lends where the resolver skips (no validprojection.yaml).core.barekey lends nothing from the main worktree.git initandgit clonealways write the key.gitdirrecord with a trailing slash lends nothing. Git writes none.gitdir: C:/...path is not read as absolute, so nothing is borrowed. Derived from the code, not run.Evidence
Before: the three tests of the first commit fail against the
mainwrapper (49 pass, 3 fail):After:
bun run test -- src/wrappers.test.ts→ 56 pass, 0 fail.Each guard has a test that goes red alone. One line broken in the wrapper, the other 55 tests stay green:
In the real CLI, isolated run with an
acme-appfixture linked toacme-companion, wrapped withmate wrap, wrapper started with no Mate launch environment:main(fc74b09)acme-fix,openspec templatesno mate context hereacme-companionacme-fix,openspec listno mate context hereNo active changes found., plus the existing store pointer hintacme-companion,openspec listrun mate wrap in this repositoryPWDsetPWDOther files that run the wrappers (
unmanaged-session-guardrail,openspec-store.integration,package-packaging,capabilities/graphify,capabilities/graphify-secrets): 82 pass, 0 fail.bun run typecheck,bun run lintandbun run format:checkinpackages/mate-corepass. Lint prints one warning insrc/runtime/skill-prefix.ts, which this PR does not touch.Speed of the record loop, measured by a reviewer on a scratch fixture with 26 worktree records and an equivalent edit: 5.24 s → 0.38 s per call.
Not exercised: the wrapper inside a real agent session in a linked worktree; a missing
gitand a setcore.worktreeafter the move into_mate_git_confirmed_main_worktree; the "different mate install" refusal for a borrowed projection; the speed of the final script; the fullpackages/mate-coresuite locally; Windows.Second opinion: 0 blockers found, 0 fixed without review, 0 open
Merge Danger
Door: two-way
Reverting the commits restores the old refusal. Nothing is written to disk: the wrapper copies no projection into the worktree.
Blast Radius: narrow
Only the
openspecwrapper. Two things change for a call that worked or refused before:PWDis an absolute path before the upward walk. A shell that started the wrapper with a relativePWDwould now get the refusal; bash sets an absolutePWDitself.The borrow path starts
git configtwice to readcore.bareandcore.worktreefrom the shared Git folder; without a workinggitonly a linked worktree can lend. The new tests needgitin/usr/binor/bin, because the test harness gives the wrapper thatPATH.