Repository navigation
Description
What happens
sequant init --agent <name> on an already-initialized repo overwrites .sequant/settings.json with defaults, discarding every tuned value.
initCommand notices the existing install and warns:
! Sequant appears to be already initialized (.claude/settings.json exists)
Use --force to reinitialize
but with --yes (or after confirming the prompt) it continues, and further down calls createDefaultSettings(options.agent) unconditionally — src/commands/init.ts, the "Create default settings + reference doc" block. createDefaultSettings writes generateSettingsJsonc(DEFAULT_SETTINGS) straight over SETTINGS_PATH.
Impact
Anything the user tuned is lost without a diff, a backup or a mention: run.phases model policy, run.timeout, agents.*, scopeAssessment.*. In this repo that means the per-phase routing (spec: sonnet, exec: sonnet/medium, qa: opus, timeout: 5400) would silently revert to defaults.
Found while provisioning this repo for the #1060 Codex gate — the documented setup step is sequant init --agent codex on an existing checkout, i.e. exactly the path that eats the settings. The provisioning was done by hand instead (symlink + .codex/config.toml copied from templates/codex/config.toml).
Expected
An init over an existing install should preserve .sequant/settings.json, merging in only what the flags actually change (here: run.agent). The precedent already exists — #990 gave AGENTS.md a marker-and-hash check so sync only regenerates what it wrote, preserves user-owned files, and reports the decision, with --force as the explicit override.
Note
The run.agent persistence itself is correct and wanted (#1059): init --agent codex must record the driver or doctor runs none of that driver's checks. The bug is the blast radius around it.
Prior art — this class has been fixed three times, never as a rule
| Issue | What got clobbered | Fix shape |
|---|---|---|
| #708 | in-place customizations on update |
diff/write variable sets unified so a customized file stops reading as "modified" |
| #814 | .claude/memory/constitution.md on a plain sync |
CUSTOMIZABLE_FILES + isCustomizableFile() (src/lib/templates.ts:239), honored by sync/update, overridden only by --force |
| #990 | a user-owned AGENTS.md on sync |
<!-- sequant:agents-md v= h= --> marker + body hash; regenerate only if sequant wrote it, else preserve and report |
Each fix protected one file for one command. .sequant/settings.json is on none of those lists, and init never reaches the mechanism at all — it calls createDefaultSettings() directly rather than going through copyTemplates, so isCustomizableFile is never consulted.
The guard even exists already and is dead: settingsExist() is exported from src/lib/settings.ts:1225 and nothing calls it — doctor checks .claude/settings.json via fileExists instead. A three-line guard in createDefaultSettings (skip when the file exists unless force, or merge only the keys the flags set) would close this, and it is the same contract #814 and #990 already established.
Worth considering whether the real fix is a single preservation rule that every writer consults, rather than a fourth per-file patch.
Release-graph plan — pre-2.16.0 blockers (2026-09-17)
Graph: pre-2.16.0 release blockers, node 2 of 4 Tier: judgment Wave: 1
May touch: src/commands/init.ts, src/lib/settings.ts, src/commands/init.test.ts, CHANGELOG.md
Reproduced end-to-end 2026-09-17 — and it is worse than filed
Scratch repo, .claude/settings.json present, .sequant/settings.json tuned
(timeout: 5400, per-phase spec/exec/qa policy), then
sequant init --agent codex --yes:
timeout: 5400→1800- the entire
run.phasesblock — deleted - only
agent: "codex"survived (what the flag set) - init printed its success banner; the overwrite was never mentioned
Not in the original report: the "already initialized" guard checks
.claude/settings.json (init.ts:689), but the file destroyed is
.sequant/settings.json. A repo with tuned sequant settings and no
.claude/settings.json is clobbered with no warning at all.
Pre-dates v2.15.1 — not a regression from the codex batch. It blocks 2.16.0 because
2.16.0 is the release whose README tells people to run sequant init --agent codex on
an existing checkout.
Fix shape (graph D-3; open to challenge in spec)
Guard inside createDefaultSettings (src/lib/settings.ts:1238): when SETTINGS_PATH
exists and force is not set, read it, apply only the keys the flags set (today:
run.agent), write that back, and report the decision on stdout. --force keeps
today's overwrite. This is the contract #814 and #990 already established. It is
deliberately NOT the unified preservation rule — that is a follow-up, out of scope.
Acceptance Criteria
- AC-1:
initon a repo with an existing.sequant/settings.jsonpreserves every key the flags did not set (run.timeout,run.phasessurvive) — Evidence:npx vitest run src/commands/init.test.ts -t "1071" 2>&1 | grep -E "Tests +([5-9]|[1-9][0-9]+) passed"prints a passed line (AC-1..AC-5 are five distinct cases named with1071; zero matches or any failure prints nothing) - AC-2:
init --agent codexon that same repo still recordsrun.agent: "codex"while preserving the rest (feat(#497): sequant init --agent codex — .agents/skills symlink, .codex hooks wrapper, doctor, README #1059 behavior kept) — Evidence: covered by the AC-1 command, as its own case - AC-3:
init --forcestill overwrites with defaults — the documented escape hatch — Evidence: covered by the AC-1 command, as its own case - AC-4: init reports what it preserved instead of succeeding silently — Evidence: covered by the AC-1 command, as a case asserting captured stdout names
.sequant/settings.jsonas preserved - AC-5: the clobber is impossible with no
.claude/settings.jsonpresent either (the guard keys off the file it actually writes) — Evidence: covered by the AC-1 command, as a case whose fixture has .sequant/settings.json but no .claude/settings.json - AC-6:
settingsExist()is either used by the new guard or deleted — no exported dead code left — Evidence:bash -c 'grep -q settingsExist src/commands/init.ts || ! grep -q "export async function settingsExist" src/lib/settings.ts' && echo PASSprints PASS - AC-7: the manual end-to-end repro below, run against the worktree's own build, prints PRESERVED — Evidence:
gh pr view --json body -q .body | grep -c "RESULT: PRESERVED"prints 1
AC-1 and AC-5 are gate tests: mutation-verify (remove the exists-guard → AC-1 fails;
key the guard off .claude/settings.json → AC-5 fails) and record the markers.
Manual end-to-end repro (run from the worktree root — the global sequant points at main's dist, not yours)
npm run build >/dev/null 2>&1 && CLI="$PWD/dist/bin/cli.js"
SC=$(mktemp -d); mkdir -p "$SC/.claude" "$SC/.sequant"; cd "$SC"; git init -q .
echo '{}' > .claude/settings.json
printf '%s\n' '{' ' "version": 1,' ' "run": { "agent": "claude-code", "timeout": 5400, "phases": { "spec": "sonnet", "exec": "sonnet", "qa": "opus" } }' '}' > .sequant/settings.json
B=$(shasum .sequant/settings.json | cut -d' ' -f1)
node "$CLI" init --agent codex --yes >/dev/null 2>&1
grep -q '"agent": "codex"' .sequant/settings.json && grep -q '"timeout": 5400' .sequant/settings.json && grep -q '"qa": "opus"' .sequant/settings.json \
&& echo "RESULT: PRESERVED (agent recorded, tuned keys intact)" || echo "RESULT: CLOBBERED"Note the check is not a byte-for-byte hash — run.agent is supposed to change. It
asserts the flag's key landed and the tuned keys survived.
Out of scope
The "single preservation rule every writer consults" this issue speculates about. File
it as a follow-up after this merges.
Activity
chore(#497): commit codex provisioning so worktree phases inherit ski…
admarble commentedon Sep 18, 2026
Runner context (2026-09-18, wave 1 of the pre-2.16.0 graph)
mainatf776158f. The files in May touch are unchanged since this plan was written, so the line references above still hold.timeout. Never background it.Mutation-verified: AC-N — <mutation>; <test> failed; restored.marker in the PR body (CLAUDE.md format, machine-anchored as<!-- SEQUANT_MUTATION: ... -->)./qa§6i enforces it.CHANGELOG.mdUnreleased entry; add yours alongside.settingsExist()now sits atsrc/lib/settings.ts:1242(the issue says 1225). Still zero callers;doctor.ts:496uses a local variable of the same name, not the export.src/lib/templates.test.ts. Prefer not to touchtemplates.ts/templates.test.tshere unless the fix requires it, so the two PRs merge cleanly.admarble commentedon Sep 18, 2026
Plan — #1071 (preserve
.sequant/settings.jsonon re-init)Complexity: Standard (7 ACs, 2 directories)
AC Quality Check
7 ACs parsed, all single-line, all carrying
Evidence:. Declared evidence resolves AC-1 → unit_test, AC-4/AC-6/AC-7 → integration_test. No vague/unmeasurable/open-ended patterns. Two notes, neither blocking:grep -q settingsExist src/commands/init.ts || ! grep -q "export async function settingsExist" src/lib/settings.tspasses only if (a)init.tsnamessettingsExist, or (b) theexportis gone fromsettings.ts. A guard that lives insidecreateDefaultSettingsand callssettingsExist()satisfies the AC's text but fails its command. Compliant shape recommended below.grep -c "RESULT: PRESERVED"must print exactly1. The repro script in the issue body contains that literal string inside its ownecho. Pasting the script into the PR body makes the count2and the gate fails. Paste the captured output line only.Scope Assessment
Non-Goals: present as "### Out of scope" — the unified preservation rule every writer consults. Parser reports the
Non-Goalssection as empty (heading name mismatch); the boundary is stated and honoured here.src/commands,src/lib)Verdict:⚠️ SCOPE_WARNING — driven entirely by AC count; the real change is ~2 source files. Quality loop enabled per the SCOPE_WARNING rule.
Acceptance Criteria
AC-1: existing
.sequant/settings.jsonsurvives init;run.timeout/run.phasesintactVerification: Unit Test (
src/commands/init.test.ts, describe1071 …)Scenario: Given
.sequant/settings.jsonwithtimeout: 5400and arun.phasesblock → WhencreateDefaultSettingsruns withoutforce→ Then the file is not rewritten with defaults and both keys survive.Assumptions: the real
createDefaultSettingsis exercised, not the file-level mock (see Risk R3).AC-2:
--agent codexstill recordsrun.agentwhile preserving the rest (#1059 kept)Verification: Unit Test — same describe, own case.
Scenario: Given the same tuned file → When init runs with
agent: "codex"→ Then written content hasagent: "codex"andtimeout: 5400and thephasesblock.AC-3:
--forcestill overwrites with defaultsVerification: Unit Test — same describe, own case.
Scenario: Given the same tuned file → When
forceis set → Then the file is the freshly generated default JSONC (timeout back to1800).AC-4: init reports what it preserved
Verification: Integration Test (init-level,
consoleLogSpy).Scenario: Given an existing settings file → When
initCommandruns → Then captured stdout contains.sequant/settings.jsonand says it was preserved.Assumptions: the line goes through
console.log, notspinner.succeed—cli-ui's spinner is mocked in that suite and its text never reachesconsoleLogSpy(Risk R5).AC-5: no
.claude/settings.jsonpresent → still preservedVerification: Unit Test — same describe, own case.
Scenario: Given
fileExists(".claude/settings.json") === falseand.sequant/settings.jsontuned → When init runs → Then the tuned keys survive. This is the guard keying off the file it writes, not the one it checks.AC-6:
settingsExist()used by the guard or deletedVerification: Integration Test (the grep, run in CI/QA).
Scenario: see AC Quality Check — recommended shape: drop
export, call it from the guard.AC-7: manual end-to-end repro prints PRESERVED
Verification: Manual Test, output pasted once into the PR body.
Scenario: build the worktree, run the issue's script against
dist/bin/cli.js, paste the singleRESULT:line.Implementation Plan
Phase 1 — the guard (
src/lib/settings.ts)createDefaultSettings(agent?: string, force = false). Whenforceis false andsettingsExist()(now module-local, noexport— AC-6), take the preserve path; otherwise today's behaviour verbatim (AC-3).JSON.parse(stripJsoncComments(content))on the raw object. If no flag key needs changing, do not write at all — the file stays byte-identical, JSONC comments included. Ifagentmust change, setrun.agenton the raw object and writeJSON.stringify(merged, null, 2).generateSettingsJsonc. It emits neitherrun.phasesnorscopeAssessmentnorrun.modelRoles(settings.ts:1272+) — round-tripping through it reproduces the exact data loss this issue reports and fails AC-1. Merge on the raw parsed object; nested Zod schemas strip unknown keys too, so don't route the write throughvalidateSettingseither.--force(derived AC below).{ action: "created" | "preserved" | "updated", path }) so the caller can report.Phase 2 — the report (
src/commands/init.ts)6. Pass
options.forcethrough; render the result.console.loga line naming.sequant/settings.jsonand what was preserved (AC-4), alongside the existing spinner.7. Update the #1059 test at
init.test.ts:868—toHaveBeenCalledWith("codex")breaks once the signature gains a second argument.Phase 3 — tests + evidence
8.
describe("1071: …")insrc/commands/init.test.tswith ≥5 cases (AC-1's grep needsTests 5 passed; format confirmed asTests N passed | M skipped (T)under-t).9. Drive the real implementation via
await vi.importActual("../lib/settings.js")inside that describe —../lib/fs.jsstays mocked, so the assertions are onreadFile/writeFilecalls. No temp cwd, noprocess.cwdspy (#870).10. Mutation-verify AC-1 (remove the exists-guard → the AC-1 case fails) and AC-5 (key the guard off
.claude/settings.json→ the AC-5 case fails); record both<!-- SEQUANT_MUTATION: … -->markers in the PR body.11. CHANGELOG entry alongside the existing Unreleased ones.
Design Review
createDefaultSettings— the only writer ofSETTINGS_PATHon this path, andinitnever reachescopyTemplates/isCustomizableFile. Confirms graph D-3.--agentsets a key. Rejected: a surgical JSONC line patch that would also keep comments on the merge path — two code paths and a regex against user-formatted JSONC, for a comment-fidelity gain on one branch. Rejected: the unified preservation rule — explicitly out of scope here.--forceas the single override. Writing plain JSON over JSONC on the merge branch already has precedent insaveSettings.run.phasesanyway" (step 3 exists to prevent exactly that), and "the new tests mockcreateDefaultSettingsand assert nothing" — which the mutation record is there to disprove.Feature Quality Planning
writeCodexConfig(init.ts:579) overwrites.codex/config.tomlunconditionally, andsaveConfigoverwrites.claude/.sequant/config.json. Recommend a follow-up issue rather than widening scope, since the unified rule is declared out of scope.Open Questions
--agent claude-codeclear a recordedrun.agent: "codex"? TodaycreateDefaultSettingsskips writingagentwhen it equalsclaude-code, so under the guard a user switching back would silently stay on codex. Recommendation: treat an explicitly-passed--agentas a key the flag set and write it, per the AC's own "only the keys the flags actually set". Impact if wrong: a switch-back is a silent no-op.Conflict Risk
No overlap. #1075 (in flight) touches
templates.ts/templates.test.ts— untouched here, per the runner note. PR #1085 touches MCP/doctor/serve, no shared files. Both worktrees sit atf776158f.Recommended Workflow
Phases: exec → qa
Quality Loop: enabled (SCOPE_WARNING)
Reasoning:
buglabel, one localized fix with the test design already pinned by AC-1's evidence command.testgenskipped despite declared unit/integration evidence — the evidence names one existing test file and an exact case count, so generated stubs would be replaced immediately; overriding the declared-evidence default deliberately.admarble commentedon Sep 19, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 0/2 met
Gaps:
Suggestions:
settings.ts:1318,if (!content.trim())) is new production code with no automated test. I exercised it manually (empty file → 1836-byte default JSONC written, no "Preserved" line) and it is correct, but it has no regression guard.expect(onDisk.run.timeout).toBe(5400)on a re-parse of theTUNEDtest constant — those two lines cannot fail regardless of implementation. The discriminating assertions (result.action === "preserved",writtenSettings()isnull) are present and mutation-verified, so this is cosmetic, but it reads as coverage it is not.fix(#1071): preserve .sequant/settings.json on re-init (#1092)
test(#1097): writer state-matrix — init/sync/update × every destinati…