Repository navigation
fix(#822): getTemplatesDir resolves from both compiled and source layouts - #829
Merged
admarble merged 2 commits intoJul 27, 2026
Merged
Conversation
getTemplatesDir() resolved templates/ at a fixed ../../../ offset calibrated for the compiled layout (dist/src/lib -> package root). Run from source under tsx, __dirname is <repo>/src/lib, so three up landed one directory above the repo. copyDir's ENOENT skip then swallowed every copy, the version marker was written anyway, and sync printed "Synced" having installed nothing but .claude/skills/.sequant-version. Resolution now probes two bounded candidates (compiled first, so consumers are unaffected) and ranks them: a candidate whose parent holds a package.json named "sequant" wins outright, since the two offsets are not mutually exclusive — from <repo>/src/lib the compiled offset resolves to <repo>/../templates, and a bare existence probe would bind to any unrelated templates/ beside the checkout. A merely-existing candidate is still accepted as a fallback so no working layout regresses. SEQUANT_TEMPLATES_DIR remains the unconditional first choice. A missing templates root now fails loudly: sync and init exit non-zero naming the resolved path. sync's guard sits ahead of the version fast path, which would otherwise diff against the same missing directory and report "already up to date" over an empty tree. init's sits ahead of every prompt and write. The per-subdirectory ENOENT skip is untouched and now pinned by a test. Resolution is memoized: it is now stat-backed and getTemplateContent calls it once per template file, which added ~2ms to each drift scan. Fixes #822
AC-2 names both `sync` and `init`, but only sync's failure branch had a regression test. init's guard was covered solely by the unit-level mock, which stubs assertTemplatesDirExists out entirely — so removing the guard from init.ts left the suite green. Adds a source-invoked `init --yes --skip-setup` case asserting non-zero exit, the missing path in the output, and that no settings.json was written (the guard sits ahead of every write, so a broken install must not half-provision). Verified by mutation: without the guard, init exits 0 and the new test fails.
3 tasks
admarble
deleted the
feature/822-fix-templates-gettemplatesdir-resolves-one-lev
branch
July 27, 2026 14:43
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
getTemplatesDir()resolved the bundledtemplates/at a fixed../../../offset calibrated for the compiled layout (dist/src/lib→ package root). Run from source undertsx,__dirnameis<repo>/src/lib, so three up landed one directory above the repo.copyDir's ENOENT skip then swallowed every copy, the version marker was written anyway, andsyncprinted✔ Syncedhaving installed nothing but.claude/skills/.sequant-version.<repo>/src/libthe compiled offset resolves to<repo>/../templates, so a bare existence probe would bind to any unrelatedtemplates/sitting beside the checkout. A candidate whose parent holds apackage.jsonnamedsequantwins outright (the same anchorversion.ts,manifest.tsandbin/preflight.tsalready use); a merely-existing candidate is still accepted as a fallback so no working layout regresses.sync's guard sits ahead of the version fast path — that path diffs against the same missing directory, sees no drift, and reports "already up to date" over an empty tree.init's sits ahead of every prompt and write, including--upgrade-skills.memory/must still copy cleanly.getTemplateContentcalls it once per template file, which added ~2ms to each drift scan (measured 2.10ms → 0.02ms).Consumers were never affected — this was a trap for contributors testing
sync/initfrom source.AC verification
resolveTemplatesDirFromtakes an injectable ranker (a test cannot relocateimport.meta.url); 6 unit tests pin compiled, source, stray-ancestor, both-valid, exists-fallback, neither-exists. Live:tsx bin/cli.ts sync→ 21 skills;node dist/bin/cli.js sync→ 21 skillssync/initexit non-zero naming the path; per-subdir skips stay non-fatal/nope/templates. Integration tests cover both commands;initcase also asserts nosettings.jsonwas written. Unit test pins that a templates tree withoutagents//hooks/still copies cleanlysync-source-invocation.integration.test.tsspawns the real CLI undertsxwithSEQUANT_TEMPLATES_DIRcleared, assertsnot.toEqual([".sequant-version"])plus each core skillEvery new test was mutation-verified. Restoring the original one-line bug reproduced the exact issue signature and failed the AC-3 assertion with
expected [ '.sequant-version' ] to not deeply equal [ '.sequant-version' ]; removing the source offset failed 3 tests; removinginit's guard failed the init case (it exits 0 without it).Test plan
npm run build— cleannpm run lint— cleannpm test— 206 files, 4275 passed, 1 expected fail, 2 skippedsyncin a scratch project → 21 skills installed (was: marker only)node dist/bin/cli.js sync→ 21 skills (unregressed)syncandinitwith a missing templates root → exit 1, path named, no✔ Syncedconstitution.md(fix(sync): plain sync overwrites CUSTOMIZABLE_FILES (constitution) — copyDir ignores force and never consults isCustomizableFile #814 protection holds)Behavior change worth noting
The same root cause silently disabled the post-command auto-sync in
bin/cli.tsfor source invocations. With resolution fixed, a source-invoked command in a project with a stale version marker now performs a real auto-sync where it previously no-opped and only bumped the marker (verified: 1 → 22 entries). This is restored parity with the compiled binary, which has always behaved this way — and #814's protection still holds, so in-place customizations are preserved (verified).Non-Goals honored
Distribution layout unchanged;
#814customizable-files handling untouched.SEQUANT_TEMPLATES_DIRremains the unconditional first choice, returned verbatim and never probed — the new guard validates whatever root was resolved, override included, which is what AC-2 asks for.Closes #822
🤖 Generated with Claude Code