Repository navigation
Description
Epic: W2 Blocked by: #990 Tier: mechanical Doc: W2 PLAN §4 (template sync seam), §5 I-2, §7 D14
Why
computeTemplateChanges (src/lib/templates.ts:194-225) walks the entire templates tree with no skip list, so templates/opencode/** is mapped 1:1 to .claude/opencode/**. But the only real producer of the opencode shim is init (src/commands/init.ts:145-175, :300-330), which renders templates/opencode/command.md ({{PHASE}}) into .opencode/commands/<phase>.md and writes the plugin to .opencode/plugin/. Nothing in src/, templates/ or bin/ reads .claude/opencode/. Meanwhile sync's apply path is copyTemplates (templates.ts:600-665) with a fixed directory list — skills, agents, hooks, memory, scripts, settings.json — that does not include opencode at all.
One root cause, four symptoms:
| Symptom | Effect |
|---|---|
sync --dry-run lists files that sync never writes |
dry-run ≠ apply — a direct violation of the ownership invariant (I-2: every decision visible in --dry-run before the write) |
serve / version-preflight warns N file(s) differ from bundled content on every project that ran init before the shim existed |
permanent nag on every downstream project since 2.13 |
update "fixes" the nag by writing unrendered templates ({{PHASE}} ×4) to a path nothing reads |
junk under .claude/opencode/ |
sync never refreshes the real .opencode/ shim for projects that use --agent opencode |
shim drifts silently across releases |
Motivating example (verbatim, downstream project on 2.11.0 → 2.14.0, 2026-09-10; prompts stripped)
$ sequant sync --dry-run
Summary (dry-run):
New files: 4
Modified: 11
Customizable (preserved): 1
New files:
.claude/hooks/capture-tokens.sh
.claude/opencode/command.md
.claude/opencode/plugins/lib/sequant-hooks-core.ts
.claude/opencode/plugins/sequant-hooks.ts
$ sequant sync
preserved: .claude/memory/constitution.md — run `sync --force` to replace
✔ Synced to v2.14.0
$ npx sequant@latest serve
! Version current, but 3 file(s) differ from bundled content
Run: npx sequant sync --force (or npx sequant update)
$ npx sequant update
Summary:
New files: 3
Modified: 0
✓ Unchanged: 56
New files:
.claude/opencode/command.md
.claude/opencode/plugins/lib/sequant-hooks-core.ts
.claude/opencode/plugins/sequant-hooks.ts
✔ Updated 3 files
After this, grep -c '{{' .claude/opencode/command.md → 4 in the downstream project. The three files were removed by hand.
Scope
- may touch:
src/lib/templates.ts(computeTemplateChanges,copyTemplates),src/commands/sync.ts,src/commands/update.ts,src/commands/init.ts(extract the shim renderer so one producer owns.opencode/),src/commands/version-preflight.ts; tests:src/lib/templates.test.ts,src/commands/sync.test.ts,src/commands/update.test.ts(new if absent),src/commands/sync-source-invocation.integration.test.ts. - not in scope: opencode driver behavior; the
.opencode/layout itself; fix(sync): never rewrite a user-owned AGENTS.md or write a machine-specific scripts/dev symlink (absorbs #991) #990's AGENTS.md / symlink work (this issue is blocked by it because both edittemplates.tsandsync.ts— land after, rebase onto its merge). - design call for the spec: either (a)
sync/updatereuseinit's renderer for.opencode/when the project already has.opencode/, or (b)templates/opencodeis excluded from drift with a one-line reason and the shim isinit-only. Pick one; both satisfy the ACs.
Acceptance criteria
- AC-1: what
sync --dry-runlists is exactly whatsyncthen writes (same set of paths, customizable files excluded on both sides) — Verify:npx vitest run src/commands/sync.test.ts -t "dry-run matches apply"→ on a temp project, the dry-run change set equals the post-sync diff of the tree. Mutation: add a template dir thatcopyTemplatesskips → fails; restore. - AC-2: no path under
.claude/opencode/is ever produced bycomputeTemplateChanges,syncorupdate— Verify:npx vitest run src/lib/templates.test.ts -t "opencode"→ change set contains no.claude/opencodeentry; on a temp project afterupdate,test ! -e .claude/opencode. - AC-3: the shim has one producer — on a project with
.opencode/,syncandupdaterefresh.opencode/commands/<phase>.mdrendered (no{{PHASE}}) and.opencode/plugin/**; on a project without.opencode/, they write nothing there — Verify:npx vitest run src/commands/sync.test.ts -t "opencode shim"→ both cases;grep -rc '{{' <tmp>/.opencode/commands/→0for every file. - AC-4: the version-preflight "differ from bundled content" count only counts files the apply path can write — a fresh
initproject (no opencode) followed byserveprints no differ warning — Verify:npx vitest run src/commands/sync-source-invocation.integration.test.ts -t "no phantom drift"→ stderr has nodiffer from bundled content. Mutation: re-add the unfiltered walk → fails; restore. - AC-5: no file written by
init,syncorupdatecontains an unrendered{{…}}placeholder — Verify:npx vitest run src/lib/templates.test.ts -t "no unrendered placeholders"→ walks the temp project after each command, zero matches for\{\{[A-Z_]+\}\}. - AC-6: suite green — Verify:
npm run build && npm test→ pass.
Done when
--dry-run lists exactly what sync/update write, nothing ever lands under .claude/opencode/, and the opencode shim has exactly one producer that renders it.
Activity
admarble commentedon Sep 10, 2026
Scope addition from #990 (runner, 2026-09-10, W2 D16). #990's AC-6 originally required
sequant update --dry-runto print theAGENTS.mddecision andscripts/devlink-target changes.update's apply path never regeneratesAGENTS.mdand never re-linksscripts/dev(it writes rendered template files only), so a dry-run that printed those decisions would itself violate I-2 (dry-run ≠ apply) — this issue's subject. The clause therefore lands here: onceupdate's apply path is reconciled withsync(design call (a) or (b) in the body),update --dry-runmust show the sameAGENTS.md/scripts/devdecisionssync --dry-runshows (#990 AC-6,decideAgentsMdSync+previewScriptsSymlinkTargetsinsrc/commands/sync.ts), or explicitly state thatupdatedoes not manage those files.fix(#990): doctor never recommends sync --force for a bad scripts/dev…
docs(graph): wave-1 execution record — D15–D17, post-wave ledger, han…
docs(graph): wave-2 plan — node 09 (#1030), D14–D17, and the wave-1 e…
fix(sync): never rewrite a user-owned AGENTS.md or write a machine-sp…
admarble commentedon Sep 10, 2026
Runner context — W2 wave 2 launch (2026-09-10). Node 09, mechanical tier. Base:
mainat 6783356 (v2.14.0 + wave 1: #980/#982/#990/#1032 merged). Stop-at-PR: open the PR, do not merge. Gate tests needMutation-verified:records in the PR body withfailedTestas<test file path> > <test name>(CLAUDE.md; a describe title alone is rejected). Foreground only: run every check in the foreground with a timeout (timeout 600 npm test 2>&1 | tail -80); the pre-tool hook now blocksMonitorandrun_in_backgroundunder the orchestrator (#1032) — nothing will wake you, the phase ends when your turn ends. Commit a WIP within 5 minutes and every ~10 minutes; every phase has a hard 30-minute wall.CHANGELOG.md[Unreleased]: append one bullet under the matching###heading, never a second heading of the same name.sync --dry-runnow prints theAGENTS.mddecision andscripts/devlink changes viadecideAgentsMdSync/previewScriptsSymlinkTargetsinsrc/commands/sync.ts. Per the D16 comment above,update --dry-runmust either show the same decisions once its apply path is reconciled withsync, or state explicitly thatupdatedoes not manage those files — pick design (a) or (b) in the spec and say which.src/commands/update.test.tsmay not exist yet; create it if the ACs need it.sync-source-invocation.integration.test.tsexists.CHANGELOG.mdis shared.admarble commentedon Sep 10, 2026
Complexity: Standard (6 ACs, 2 directories)
AC Quality Check
All 6 AC declare explicit
Evidence:verify commands (vitest target + assertion); AC-1/AC-4 carryMutation:clauses. No vague/unmeasurable/open-ended language, no title/body tension.Scope Assessment
Non-Goals (from issue body): opencode driver behavior; the
.opencode/layout itself; #990's AGENTS.md/symlink work (blocked-by, now merged).src/lib,src/commands)Verdict: ✅ SCOPE_OK — every AC maps to the same fix, not independent features; AC-count sits at the yellow line but the issue's own Scope section already bounds it tightly.
Dependencies: #990 merged (
6783356a) — not a live blocker;decideAgentsMdSync/previewScriptsSymlinkTargetsnow exist as the reuse pattern below. Worktrees for #1024/#1025 exist but carry no diff yet;CHANGELOG.mdis the only shared file across the wave (append-only, low risk).Root Cause
templateDestination()(src/lib/templates.ts:318) already routes two paths tonull— untracked by the generic diff/copy engine:templates/mcp.json,templates/relay/**. It has no case fortemplates/opencode/**(the only gap — every other top-leveltemplates/dir is either copied bycopyTemplatesor already excluded), so it falls through to the generic rule and gets diffed/reported despitecopyTemplatesnever writing it.The real shim already has one set of producers —
writeOpencodeCommands/Agents/Plugin/McpConfig(src/commands/init.ts:153,276,309,338), exported, called only frominit --agent opencode.writeOpencodeCommandsrenderstemplates/opencode/command.mdper-phase ({{PHASE}}substituted in a loop) — the generic single-pass renderer can never do this correctly, which is why unrendered{{PHASE}}landed under.claude/opencode/in the motivating example.update.ts:194writesapplySetdirectly (nocopyTemplatescall), so it needs its own call site, not a shared one. Version-preflight's drift count (computeContentDrift→computeTemplateChanges) is fully derived from the same diff — AC-4 falls out for free once AC-2 lands.Acceptance Criteria
AC-1: dry-run lists exactly what sync then writes
Verification: Integration Test
Scenario: Given a temp project mid-upgrade → When
sync --dry-runthensyncrun in sequence → Then the reported path set equals the post-apply diff, including the opencode-shim decision when.opencode/exists.Assumptions: The opencode-shim preview (Phase 2) is wired into the same dry-run block as AGENTS.md/scripts, or this AC stays false for
--agent opencodeprojects even after AC-2/AC-3.AC-2: no
.claude/opencode/path produced by the generic engineVerification: Unit Test
Scenario: Given
templateDestination("templates/opencode/command.md")→ When called → Then returnsnull;computeTemplateChangesoutput has zero.claude/opencodeentries; post-updatetemp project has no.claude/opencodepath.AC-3: the shim has exactly one producer
Verification: Integration Test
Scenario: Given a project with
.opencode/→ Whensync/updateruns → Then.opencode/commands/<phase>.md(rendered) and.opencode/plugin/**refresh via the same functionsinituses. Given no.opencode/→ Whensync/updateruns → Then nothing is written there.Assumptions: Presence detected via
existsSync(".opencode")— sync/update don't know the project's driver choice, only the directory's existence (design (a), see Open Questions).AC-4: no phantom "differ from bundled content" warning
Verification: Integration Test
Scenario: Given a fresh
initproject (no--agent opencode) → Whenserveruns preflight → Then no "differ from bundled content" line.Assumptions: Falls out of AC-2; this test guards the regression per its own mutation clause.
AC-5: no unrendered
{{...}}placeholder anywhereVerification: Unit Test
Scenario: Given
init(±--agent opencode), thensync, thenupdate→ When walking every written file → Then zero matches for\{\{[A-Z_]+\}\}.AC-6: suite green
Verification: Integration Test
Scenario: Given the full change set → When
npm run build && npm test→ Then it passes.Implementation Plan
Phase 1: Exclude
templates/opencode/**from the generic enginesrc/lib/templates.ts— add atemplates/opencode/case totemplateDestination()returningnull, alongsidemcp.json/relay/; extend the doc comment with the rationale (bespoke per-phase render, not a flat copy).copyTemplates()(never had an opencode path) orversion-preflight.ts(derives throughcomputeTemplateChanges).Phase 2: One producer, refreshed by
sync/updatewhen.opencode/existssrc/commands/sync.tsapply path — aftercopyTemplates(), guarded byexistsSync(join(process.cwd(), ".opencode")), call the fourwriteOpencode*functions to refresh the shim.src/commands/sync.tsdry-run path — adddecideOpencodeShimSync()(shape ofdecideAgentsMdSync) returning"none"/"refresh"; report it next to the AGENTS.md/scripts preview lines so AC-1 holds for opencode projects.src/commands/update.ts— mirror both: guarded refresh after theapplySetwrite loop, and the same decision under--dry-run.Phase 3: Tests
src/lib/templates.test.ts— exclusion cases (AC-2); no-unrendered-placeholder sweep (AC-5).src/commands/sync.test.ts— "dry-run matches apply" (AC-1); "opencode shim" with/without.opencode/(AC-3).src/commands/update.test.ts(new) — same two cases forupdate.src/commands/sync-source-invocation.integration.test.ts— "no phantom drift" (AC-4).npm run build && npm test(AC-6).Design Review
templateDestinationalready owns "does the generic walk touch this path" (2 precedents); the shim's render logic stays ininit.ts'swriteOpencode*functions — sync/update become a second caller, not a second implementation.null-routing exclusion (likemcp.json/relay/) plus a preview-before-write decision function (likedecideAgentsMdSync) surfaced in--dry-runbefore apply.templates/opencode/and inline strings ininit.ts?" — becausesync/updateneed to re-render the same content later (AC-3); a shared template file is the right shape, only the generic walk needs to skip it.Notable: the four
writeOpencode*functions unconditionallyensureDir+write — the sync/update call sites must gate onexistsSync(".opencode")themselves, or a plainsyncwould create the directory on a project that never opted in.init.ts's post-write reminder (git add .opencode && git commit) should apply to the refresh path too.Open Questions
.opencode/exists); (b) (exclude-only, shim is init-only forever) leaves the issue's own symptom 4 ("shim drifts silently") unresolved. Impact if wrong: Phase 2 (steps 3-5) and AC-3's refresh assertions drop out; AC-3's test becomes "never touched either way" — smaller change, but the drift symptom stays open.commands/init.tsintosync.ts/update.tsis a commands→commands import. Recommendation: import directly unless it creates a cycle; if so, hoist tosrc/lib/opencode-shim.ts. Impact if wrong: minor structural churn only.Recommended Workflow
Phases: spec → testgen → exec → qa
Quality Loop: disabled
Reasoning: Every AC declares vitest evidence (unit/integration) — testgen stubs warranted despite the
buglabel, since declared evidence outranks the label heuristic (#938). Mechanical tier, single root cause, mutation-verified ACs already specify their own failure mode.Label Review
Current: bug, cli, graph-2026-09-w2
Recommended: no changes beyond
planned.Reason: existing labels already describe the change; no UI surface, no complexity beyond what's scoped.
Quality Loop: Won't auto-enable — SCOPE_OK, mechanical tier, self-verifying ACs.
→
gh issue edit 1030 --add-label plannedadmarble commentedon Sep 11, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 0/1 met
Gaps:
Suggestions:
sync.tscallsdecideOpencodeShimSync()twice (lines 396, 580) on mutually exclusive paths;update.tscomputes once and reuses. Harmless, but theupdateform is cleaner.update's✔ Updated 0 filesafterRefreshed opencode shimundercounts — the shim files aren't in the tally.fix(#1030): content-aware opencode shim decision — 'current' is nothi…
fix(#1030): the version-current fast path reports a stale opencode sh…
admarble commentedon Sep 11, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
fix(sync): exclude templates/opencode from the generic diff/copy engi…