Skip to content

fix(sync): never rewrite a user-owned AGENTS.md or write a machine-specific scripts/dev symlink (#990) - #1036

Merged
admarble merged 6 commits into
mainfrom
feature/990-fix-sync-never-rewrite-a-user-owned-agents-md-or-w
Sep 10, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/990-fix-sync-never-rewrite-a-user-owned-agents-md-or-w

Conversation

@admarble

@admarble admarble commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • generateAgentsMd now prepends a self-verifying marker line (<!-- sequant:agents-md v=<version> h=<sha1> -->); sync only regenerates AGENTS.md when the marker is present and its hash matches the body — otherwise the file is left byte-identical and reported preserved. --force still overrides; --no-agents-md skips generation entirely.
  • scripts/dev/*.sh symlink targeting now prefers a local node_modules/sequant/templates/scripts (survives git clone && npm install regardless of which sequant binary ran the command), and falls back to copies (not symlinks) plus a one-line explanation when the resolved templates dir is under an npx cache or outside the project tree.
  • sync --dry-run previews both the AGENTS.md decision and any scripts/dev target changes before writing anything; doctor warns on dead/foreign-target scripts/dev links and reports a user-owned AGENTS.md without ever recommending sync --force for that case (the bug this issue's "Found in Phase 0" note called out).

Closes #990 (absorbs #991).

Pre-PR AC Verification

AC Description Status Evidence
AC-1 Marker line + hash on generated AGENTS.md ✅ Implemented src/lib/agents-md.ts (buildAgentsMdMarker, hashAgentsMdBody); agents-md.test.ts "begins with a self-verifying marker... (AC-1)"
AC-2 sync preserves unmarked/mismatched AGENTS.md, regenerates matched, --force overrides ✅ Implemented src/commands/sync.ts:530-566; sync.test.ts "AGENTS.md ownership (AC-2, AC-3)" — 3 cases
AC-3 sync --no-agents-md skips entirely ✅ Implemented bin/cli.ts:229; sync.test.ts "--no-agents-md skips generation... (AC-3)"
AC-4 node_modules/sequant/templates/scripts always wins as symlink target ✅ Implemented src/lib/templates.ts resolveScriptsSymlinkTarget; templates.test.ts "prefers a local node_modules/sequant... (AC-4)"
AC-5 npx-cache/outside-tree dirs fall back to copies + one --no-symlinks line ✅ Implemented same function; templates.test.ts two AC-5 cases (npx cache, outside tree)
AC-6 sync --dry-run previews both decisions, writes nothing ✅ Implemented sync.ts dry-run branch; sync.test.ts "previews both the AGENTS.md decision and scripts/dev link changes... (AC-6)"
AC-7 doctor warns on dead/foreign scripts/dev links; reports user-owned AGENTS.md with no --force hint ✅ Implemented src/commands/doctor.ts checkScriptsDevLinks + AGENTS.md check; doctor.test.ts "990 AC-7: scripts/dev links and AGENTS.md ownership" (added this pass — the checkpointed commit only had mock renames, no real assertions)
AC-8 Behavior documented in CHANGELOG + README ✅ Implemented README.md sync section, CHANGELOG.md [Unreleased]; grep -c "sequant:agents-md" README.md CHANGELOG.md → 1, 1
AC-9 Suite green ⚠️ Partial npm run build && npm test — build/lint clean; full suite has 3 pre-existing failures in unrelated files (batch-executor.test.ts, relay-hook.integration.test.ts, prompt-wait.test.ts) that reproduce identically in isolation and touch none of this PR's files. All 194 targeted tests across the 5 changed test files pass.

Mutation verification (gate ACs)

Mutation-verified: AC-2 — set isAgentsMdSequantOwned to always return true; sync.test.ts > ... leaves an unmarked AGENTS.md byte-identical and reports it preserved failed; restored.

Mutation-verified: AC-4 — removed the node_modules/sequant/templates/scripts preference block from resolveScriptsSymlinkTarget; templates.test.ts > ... prefers a local node_modules/sequant/templates/scripts target... (AC-4) failed; restored.

Mutation-verified: AC-5 — removed the isUnderNpxCache/isOutsideProjectTree detection block; both templates.test.ts > ... falls back to copies... npx cache... (AC-5) and ...outside the project tree... (AC-5) failed; restored.

Mutation-verified: AC-7 — restored the old --force hint on the user-owned AGENTS.md message; doctor.test.ts > 990 AC-7 ... reports an unmarked/hash-mismatched AGENTS.md as user-owned, with no --force hint failed; restored. (This test did not exist before this PR — added it since the checkpointed commit only renamed mocks with no assertions on the actual AC-7 behavior.)

Post-QA follow-ups (first pass AC_NOT_MET, ee1e54d)

QA's findings and what was done, by the graph runner:

Mutation-verified: AC-7 — restored the old sequant sync --force hint on the dead-link warning in doctor.ts; src/commands/doctor.test.ts > warns on a dead scripts/dev symlink and names the fix command failed; restored.

Mutation-verified: AC-6 — made previewScriptsSymlinkTargets return [] unconditionally; src/lib/templates.test.ts > previewScriptsSymlinkTargets reports old → new for each link, against the real filesystem (AC-6) failed; restored.

Full suite: QA's first pass ran it at 7f7eaef (3 pre-existing failures, reproduced on origin/main in the same worktree by QA). The follow-up commit touches doctor.ts, agents-md.ts and three test files; those four suites were re-run (50 + 49 + 21 + 37 passed) plus npm run build and npm run lint.

Notes

Test plan

  • npm run build — pass
  • npm run lint — pass
  • npx vitest run src/lib/agents-md.test.ts src/lib/templates.test.ts src/commands/sync.test.ts src/commands/doctor.test.ts src/commands/init.test.ts — 194/194 pass
  • npm test (full suite) — 6212 passed, 3 pre-existing failures unrelated to this change (verified reproducible in isolation, touch none of this PR's files)
  • Mutation verification recorded above for AC-2, AC-4, AC-5, AC-7

Second-pass QA (AC_MET_BUT_NOT_A_PLUS at ee1e54d) — notes left for the owner

Broke to PR per the A+ rule; none of these is an AC gap:

  • Two sync.ts hints still say run \sync --force` to replacefor a preservedAGENTS.md. That is the documented one-time escape hatch (AC-8: unmarked files are user-owned *until sync --forceonce*), so the wording is intentional; QA would prefer it to matchdoctor`'s ownership phrasing. Your call.
  • The AGENTS.md: decision line prints after the report-only short-circuit, so a --dry-run with no template changes does not answer the ownership question. Small hoist if wanted.
  • previewScriptsSymlinkTargets repeats symlinkDir's relative-target arithmetic; QA verified they agree today. A shared helper would keep them from drifting.

admarble and others added 6 commits September 10, 2026 10:21
… runner, 2026-09-10)

Two exec attempts ended without a commit: the first was killed by the MCP
30-minute per-phase wall, the second parked on a backgrounded npm test whose
notification never arrived (#1032). Checkpointing the 12 files so the next
exec dispatch resumes from git rather than from a loose worktree.

Entire-Checkpoint: 8faa8322b0b3
…+ AGENTS.md ownership)

The prior checkpoint's doctor.test.ts only renamed mocks (checkAgentsMdConsistency
-> isAgentsMdSequantOwned); no test actually exercised checkScriptsDevLinks' dead/
foreign-target warnings or the "user-owned (preserved by sync)" AGENTS.md message.
Mutation-verified both: reintroducing the old --force hint, or removing the
symlink-target checks, now fails these tests.

Entire-Checkpoint: 48af3dc3dee8
…awareness

update.ts has zero AGENTS.md/scripts-dev references (spec Open Question 1
flagged this as a risk if left unclarified) — its --dry-run reuses the
generic computeTemplateChanges() apply-set, not the sync-only preview this
issue adds. Narrowed the README and CHANGELOG claims to sync --dry-run only.

Entire-Checkpoint: 263cd716257d
… link; real-fs preview test; drop dead helper

QA (AC_NOT_MET) findings addressed:
- F4: doctor's dead-link and foreign-link warnings recommended
  `sequant sync --force` — the command that overwrites a user-owned
  AGENTS.md, this issue's own motivating incident. Plain `sync` already
  replaces an existing symlink, so the hint is now `run: sequant sync`
  with the ownership note; the missing-AGENTS.md hint drops its wrong
  `sync --force` alternative (sync never creates one). Tests assert the
  hint and the absence of `--force`.
- F2: previewScriptsSymlinkTargets gains a real-filesystem test covering
  no link, a stale npx-cache link (old -> new), and a matching link.
- F3: checkAgentsMdConsistency was dead code; removed with its tests.
- F1 (AC-6's `update --dry-run` clause) is scoped out on the issue (W2
  D16) and handed to #1030, which owns update's dry-run/apply parity.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_0147heJNRw8wBBujPGMqxDpR
Entire-Checkpoint: d6119ff14c39
@admarble
admarble merged commit 6783356 into main Sep 10, 2026
8 checks passed
@admarble
admarble deleted the feature/990-fix-sync-never-rewrite-a-user-owned-agents-md-or-w branch September 10, 2026 23:00
admarble added a commit that referenced this pull request Sep 20, 2026
…s outside the diff need an issue number (#1101)

* chore(hooks): allow anchored env|grep in the env-dump guard; red tests outside the diff need an issue number

pre-tool.sh (all three copies): a bare env/printenv piped into a grep whose pattern starts with ^ is a prefix-scoped listing, not a dump. It is how a phase checks for the orchestrator's own SEQUANT_* vars leaking into the suite (#1086). Bare env, printenv, export and an unanchored env | grep TOKEN still block. 8 new cases per hook copy in the integration test.

exec and qa skills (all three copies): a failing test in a file the diff never touched must be re-run with the SEQUANT_* vars unset, settled against base in the same worktree, and named in the PR body with an issue number. PRs #1036, #1042 and #1048 wrote 'pre-existing, unrelated' for the same three failures; none filed, and the same failures stopped the #1060 gate a week later.

Entire-Checkpoint: 2ebe233c071c

* chore(skills): unset every SEQUANT_* var generically so the exec skill passes the relay isolation guard (AC-16)

Entire-Checkpoint: 02360586d1fc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sync): never rewrite a user-owned AGENTS.md or write a machine-specific scripts/dev symlink (absorbs #991)

1 participant