Repository navigation
Description
What happens
#1090's ownership gate has two sides. Side (b) asserts that an explicit NON_TEMPLATE_DESTINATIONS list is exhaustive against the writeFile( targets in init.ts, sync.ts and update.ts. Its QA (PR #1105) found the scan is coarser than the claim, in three ways that are all latent today (verified 0 occurrences) but are exactly the recurrence paths for the clobbering class:
- Keyed by enclosing function, deduped by site. A second
await writeFile(added inside an already-registered function, writing a new destination, passes silently. Today every registered function writes one destination (upgradeSkills's two both target.claude/skills/). - Matches
await writeFile(only. A non-awaitedwriteFile((fire-and-forget, orvoid writeFile(...)) is not scanned. - Enclosing-function regex matches top-level
functiondeclarations only. A writer added asconst foo = async () => { … }inherits the previous function's key.
Deferred out of #1090 on the runner's call so that PR stays reviewable.
Fix shape (open to spec)
Register per write site, not per function: each writeFile( occurrence (awaited or not, in any function form) maps to the destination expression it writes, and every distinct destination must resolve to a declared policy. A fixture-driven test with a synthetic source string covering the three shapes above keeps the gate honest without touching the real writers.
Release-graph plan — guard-2026-09 (2026-09-20)
Graph: guard-2026-09 Tier: mechanical Wave: 1
May touch: new src/lib/ownership-gate.ts (the per-site scan helper) and new src/lib/ownership-gate.test.ts (the three synthetic cases + the real-writer run); src/lib/templates.test.ts only to delete the old side-(b) block (#1053 appends cases to this file in the same wave, PLAN D-9); CHANGELOG.md
The npm run build && npm test AC is verified by the runner from a clean shell after the PR opens (PLAN I-1); the agent runs only the test files its ACs name. Mutation markers use failedTest starting with the test file path (I-4). #1090 merged as PR #1105, so no blocker remains. The AC-1 command npx vitest run src/lib -t "1106" still matches the new file.
Acceptance Criteria
- AC-1: gate side (b) registers every
writeFile(call site individually, awaited or not — Evidence:npx vitest run src/lib -t "1106" 2>&1 | grep -E "Tests +([3-9]|[1-9][0-9]+) passed"prints a passed line (AC-1..AC-3 are three cases named with1106, each feeding a synthetic source string to the scan and asserting the undeclared destination is named in the failure) - AC-2: a second write inside an already-registered function, to a new destination, fails the gate naming that destination — Evidence: covered by the AC-1 command, as its own case
- AC-3: a writer declared as
const name = async () => {…}is attributed to itself, not to the preceding function — Evidence: covered by the AC-1 command, as its own case - AC-4: the real three writers still pass the tightened gate unchanged, or every newly surfaced destination is declared — Evidence:
npx vitest run src/lib/templates.test.ts -t "ownership policy covers" 2>&1 | grep -E "Tests +[2-9][0-9]* passed"prints a passed line
AC-1 is a gate test: mutation-verify (revert the scan to await writeFile( only → AC-1's non-awaited case fails) and record the marker with failedTest starting with the test file path.
Activity
admarble commentedon Sep 20, 2026
Runner context — guard-2026-09 launch, 2026-09-20. Base:
origin/mainatda9ed6e8(2.16.0 plus the plan docs). These rules override the exec skill's defaults for this run:npm testin the worktree. Run only the test files this issue's ACs name. The runner runs the full suite once per PR from a clean shell. Undersequant runthe suite is not hermetic againstSEQUANT_*(bug(test): suite isn't hermetic against the SEQUANT_* env phases inject — exec sees red tests it didn't cause and opens no PR #1086), so a full run shows red files you did not cause.env -u SEQUANT_ORCHESTRATOR -u SEQUANT_WORKTREE -u SEQUANT_PHASE -u SEQUANT_ISSUE -u SEQUANT_RELAY -u SEQUANT_RELAY_FRAME npx vitest run <file>. If it is still red, the PR body names the issue number and the base-vs-head result for that test.<!-- SEQUANT_MUTATION: {"ac":"AC-N","mutation":"<what you deleted>","failedTest":"<test file path> > <describe> > <case>"} -->in the PR body.failedTestMUST start with the test file path, or the qa classifier reports it Failed. Commit before mutating.timeout.git commit -m "...", noCo-Authored-By. Never rebase or force-push after pushing. One AC per line in the PR body, idsAC-Nonly.Issue-specific: In
src/lib/templates.test.tsdelete the old side-(b) block only; #1053 appends cases at the end of the same file concurrently, so touch nothing else there. The scan helper and its tests are new files (src/lib/ownership-gate.ts,src/lib/ownership-gate.test.ts).admarble commentedon Sep 20, 2026
Complexity: Standard (4 ACs, 2 directories)
AC Quality Check
No vague/unmeasurable/open-ended wording. AC-2 and AC-3 are "covered by the AC-1 command", so they have no independent count; AC-1's⚠️ AC-4 cannot pass as written. See Open Question 1.
[3-9]|[1-9][0-9]+ passedfloor is what proves all three cases exist.Scope Assessment
Non-Goals: not stated. Inferred from "May touch": no changes to the real writers (
init.ts/sync.ts/update.ts), no changes totemplates.ts, and nothing intemplates.test.tsbeyond removing side (b).src/lib, rootCHANGELOG.md)Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: every
writeFile(site registered individually, awaited or notVerification: Unit Test
Scenario: Given a synthetic source with
void writeFile(join(d,"x.json"), …)(noawait) and no matching registry entry → When the scan + check run → Then the failure namesx.json's destination expression.Assumptions: Case names contain
1106. The command runs-t "1106"across all ofsrc/lib, so no other test there may carry that string.AC-2: second write in a registered function, to a new destination, fails
Verification: Unit Test
Scenario: Given a synthetic function registered for
join(d,"a")that also writesjoin(d,"b")→ Then the gate fails namingjoin(d,"b").AC-3:
const name = async () => {…}attributed to itselfVerification: Unit Test
Scenario: Given a top-level
function first(){…}followed byconst second = async () => { await writeFile(…) }→ Then the site key is…#second, not…#first.AC-4: real writers pass the tightened gate unchanged (or new destinations are declared)
Verification: Integration Test (reads the real⚠️ see Open Question 1.
init.ts/sync.ts/update.ts)Scenario: Given the current sources → When the real-writer run executes → Then no undeclared site or destination, and the run is a test whose name matches
ownership policy covers.Assumptions:
Implementation Plan
Phase 1: the scan helper —
src/lib/ownership-gate.ts(new)scanWriteSites(source, file)→{ site: "file#fn", destination: "<normalized first-arg expr>", line }[]. Match\bwriteFile\s*\((awaited,void, bare,fs.writeFile). Parse the first argument with balanced parens/brackets, skipping string/template/comment contents. This also covers the multi-line calls atinit.ts:294and:953, where the destination is on the next line.functionline seen". Recognisefunction f,async function f,export …, andconst|let f = [async] (…) =>/= [async] function. Anonymous callbacks inherit the enclosing named scope. This fixes shape 3, and also a nested closure inheriting the wrong key after an inner function closes.checkWriteSites(sites, registry, declared)→{ undeclaredSites, undeclaredDestinations }. The registry is keyedfile#fn#destExpr → destination. A second write with a new expression in a registered function therefore has no entry and is reported by expression. Two sites with the same expression dedupe legitimately.Phase 2: tests —
src/lib/ownership-gate.test.ts(new)#1106cases (AC-1, AC-2, AC-3) on synthetic strings; each asserts the failure message names the destination/expression.DECIDEDandb3assertions across fromtemplates.test.tsunchanged in meaning. The registry is re-keyed per site (about 13 entries;upgradeSkills's two sites are already distinct expressions). Guard the guard: assertscanWriteSitesfinds exactly as many sites as a naive/\bwriteFile\(/gcount of the same file, so a tokenizer mistake (e.g. a regex literal containing a quote) fails loudly rather than silently dropping sites.Phase 3: retire the old block, changelog
templates.test.tsremove only the side-(b)it(…)(lines ~232–354).fileURLToPath,NON_TEMPLATE_DESTINATIONSandOwnershipPolicy(lines 12, 27, 29) become unused; drop them sonpm run lint --max-warnings 0stays green. fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 only appends after line ~1215, so the two edits don't overlap textually.CHANGELOG.mdUnreleased entry.Mutation record (AC-1, gate test): commit first, then revert the match to
await writeFile(only → the AC-1 non-awaited case must fail. Marker:failedTest=src/lib/ownership-gate.test.ts > <describe> > <case>. Also mutate the enclosing-scope logic to last-function-line → AC-3 must fail; and remove one registry entry → the real-writer run must fail.Design Review
src/lib/ownership-gate.ts(string in → sites out), so synthetic fixtures need no filesystem. Only tests import it, so it ships indistbut has no runtime caller.typescriptpackage is available, but this is a dev-time gate, and adding an AST dependency tosrc/libis heavier than a ~80-line scanner with a count cross-check); keeping the line-regex and patching the three shapes one by one (the same class of hole returns at the next shape).Feature Quality Planning
Standard checks pass. Notable items:
writeFile(.writeFileSync,appendFile,copyFile,symlink,renameare not scanned. Verified 0 occurrences of these in the three files today, so latent, not live. Also unscanned: writers outside those three files (agents-md.ts,settings.ts,mcp-config.ts,templates.ts), and an aliased import (writeFile as w). Not widened here; see Open Question 2.\bwriteFile\(does not matchfsWriteFile((capital W). Fine here, but note it if a test file's helper name is ever scanned.Open Questions
-t "ownership policy covers"matches by full name, including the describeownership policy covers every destination sequant writes. Baseline isTests 2 passed(side a + side b). After deleting side (b) only side (a) remains:Tests 1 passed, and the[2-9][0-9]*grep doesn't match (the command also runstemplates.test.tsonly, not the new file). Recommendation: in place of a bare deletion, leave a thin side-(b)itin that describe that calls the new helper on the real writers (same describe name, so the AC-4 command counts it) and keep the heavy fixtures in the new file. This adds a few lines inside the deleted block's range rather than touching anything else in that file. Alternative: amend AC-4 to point atsrc/lib/ownership-gate.test.ts -t "ownership policy covers"and require the real-writer run there to be named so. Impact if unresolved:/qagets a false AC_NOT_MET or the exec agent silently games the count.appendFile/writeFileSync, but 0 occurrences today.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Tests are the deliverable, so
testgenstubs would duplicate whatexecwrites. Test-only change; no UI, no security surface. Runner context (comment above) applies: run only the named test files, no full suite in the worktree.Label Review
Current: enhancement
Recommended: enhancement, planned
Quality Loop: won't auto-enable (SCOPE_OK)
admarble commentedon Sep 20, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 0/7 met
Gaps:
chore(#1106): merge origin/main
chore(#1106): merge origin/main
test(#1106): ownership gate registers every writeFile site individual…