Skip to content

fix: no silent overwrite in bootstrap/init (.charter/, .mcp.json) and adf init --force (#369, #370) - #373

Merged
stackbilt-admin merged 4 commits into
mainfrom
fix/369-370-no-silent-overwrite
Oct 17, 2026
Merged

stackbilt-admin merged 4 commits into
mainfrom
fix/369-370-no-silent-overwrite

Conversation

@stackbilt-admin

Copy link
Copy Markdown
Member

Closes #369
Closes #370

#369: --yes never overwrites .charter/ or .mcp.json

  • bootstrap (no flag, --yes, --force or --reset-adf) never overwrites an existing .charter/* file or SECURITY.md. It creates each missing file on its own: before, initializeCharter returned early when config.json existed, so a deleted blessed-stack.json was never recreated. No JSON key-merge: loadConfig already fills defaults.
  • Phase 2 prints Created only for files it actually wrote, and one Kept existing … line for files it left as is. setup.details.kept is added to JSON.
  • .mcp.json mcpServers.charter is replaced only under bootstrap --force (not --yes). Before it replaces an existing, differing entry, bootstrap copies .mcp.json to .charter/.backup/mcp.json.<timestamp>, using bootstrap --force replaces a hand-edited manifest.adf with the template (custom triggers, RULES, METRICS lost) #354's timestamp style. If the backup fails, the entry is not replaced and a warning is printed. Output: Updated .mcp.json (backup: …), plus setup.details.mcpBackup in JSON. The skip warning now says --yes alone never does and mentions the backup.
  • charter init --yes no longer overwrites. charter init --force, and setup --force for consistency, is the explicit replace path:
    • Each existing file that differs from the template is first backed up to .charter/.backup/<name-with-slashes-flattened>.<timestamp>, for example patterns-blessed-stack.json.<ts>.
    • A file whose backup fails is not replaced. If no file could be replaced, init exits 1.
    • Text output prints Replaced <file> (backup: <path>).
    • JSON gains createdFiles, kept, replaced, notReplaced. setup's JSON gains replaced and notReplaced when they are non-empty.
    • .charter/.backup/ is gitignored by the existing ensureBackupGitignore, which now takes a parent dir. GITIGNORE_CONTENT is unchanged.
  • init --guided appends its auth policy only to a governance.md that this run wrote.

#370: adf init --force merges; new adf init --reset-adf

  • The scaffold create/merge/reset loop, template-module registration, .adf.lock handling, the VENDORS carry-over and the reset confirmation/refusal moved out of bootstrap.ts into commands/adf-scaffold-write.ts. The new module is parameterized by scaffold list, manifest template, command name used in hints, and lock mode. bootstrap and adfInit both call it. Bootstrap's phase-3 behavior and output are unchanged, and all existing bootstrap tests pass unmodified.
  • adf init --force uses exactly bootstrap's merge semantics:
    • creates missing files
    • appends missing whole sections (the manifest excludes MANIFEST_EXCLUDED_KEYS)
    • registers missing template modules with the template's triggers
    • never rewrites existing bytes; CRLF is kept and a second run changes nothing
    • when the re-parse guard refuses, the file is left as is and the warning names charter adf init --reset-adf --yes
  • adf init --reset-adf needs --yes or a y at the TTY prompt. Otherwise it exits 1 and writes nothing.
    • Each file is backed up to a gitignored .ai/.backup/ first. A failed backup means that file is not replaced, and exit 1 if none could be.
    • Text output prints Replaced .ai/x (backup: …) followed by the formatLossLines report.
    • JSON gains mode, scaffolds, replaced, warnings, and under reset also notReset, backupGitignore, resetAdf.
  • adf init keeps its own scaffold set and {} lock, so rust-wasm still gets frontend+backend. Fresh-dir output is byte-identical: I snapshotted stdout plus every file for 19 preset/format/flag combinations before and after the change, and they match apart from telemetry timestamps. A test also pins the exact output. --emit-pointers and --module are unchanged. The no-op hint names --force (merge) and --reset-adf (replace).
  • adf.ts is 1029/1041 measured lines (base 1027). No ceiling was changed.

Docs

Tests

New no-silent-overwrite.test.ts, 30 tests:

  • bootstrap --yes / --force keeps hand-edited .charter/ files byte-for-byte, recreates a deleted blessed-stack.json, and keeps SECURITY.md.
  • MCP: --yes leaves the entry unchanged and warns. --force replaces it with a gitignored backup and keeps other keys. A failed backup leaves it unchanged. --reset-adf --yes alone does not replace it.
  • init --yes does not overwrite. init --force writes backups, prints Replaced and fills the JSON field. A backup failure leaves files unchanged with exit 1; this is simulated with a regular file at .charter/.backup.
  • setup --force backs up before replacing.
  • adf init merge: byte-preserving with custom triggers, RULES and METRICS; idempotent; CRLF; a missing module is created and registered; the guard refusal works.
  • --reset-adf: non-TTY and JSON refusals, TTY n/y, --yes with backups and the loss report, JSON fields, and a total backup failure exits 1.
  • Fresh dir: byte-identical files and stdout.

adf-init.test.ts: the old "overwrites with --force" test now covers --force (keeps the file) and --reset-adf --yes (replaces it with a backup).

Full suite: 1560 pass, 3 fail. The 3 failures are Windows-host-only path assertions in bootstrap.test.ts (#307 premise path.isAbsolute), context-refresh.test.ts and serve-context.test.ts, all expecting / separators. They are unrelated to this change.

🤖 Generated with Claude Code

… adf init --force (#369, #370)

#369: bootstrap never overwrites an existing .charter/ file (or SECURITY.md),
whatever --yes/--force/--reset-adf say, and creates each missing file
individually (a missing blessed-stack.json is recreated). .mcp.json's
mcpServers.charter is replaced only under bootstrap --force, after backing
.mcp.json up to .charter/.backup/mcp.json.<timestamp>; a failed backup leaves
it as is with a warning. charter init --yes no longer overwrites;
init --force (and setup --force) back each replaced file up to a gitignored
.charter/.backup/ first, print "Replaced <file> (backup: <path>)", and add
createdFiles/kept/replaced/notReplaced to JSON.

#370: adf init --force merges the preset template exactly like
bootstrap --force; new adf init --reset-adf replaces with confirmation,
backups to .ai/.backup/ and a loss report. The scaffold write engine moved
from bootstrap.ts to commands/adf-scaffold-write.ts, shared by both
commands. adf init's fresh-directory output is byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread packages/cli/src/commands/init.ts Fixed
kovermier and others added 2 commits October 17, 2026 16:00
…ed exits)

- adf init --force / --reset-adf --yes on an empty .ai/ print exactly what
  plain adf init prints (text and JSON with nextActions); --emit-pointers
  lines follow the merge/reset report.
- Replace the three /\/+$/ trailing-slash regexes (CodeQL
  js/polynomial-redos) with one loop-based dirLabel helper.
- setup --force and init --guided --force exit 1 when every backup failed,
  like init --force; setup text names created/kept files.
- A .backup/.gitignore that cannot be written is a warning everywhere
  (tryEnsureBackupGitignore), never a failed step.
- init JSON: files stays [] for an existing .charter/ without --force.
- Bootstrap phase 2 keeps platform separators in Created/kept paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…set-adf)

- blessed-stack.json is compared as JSON with generatedAt ignored, so an
  untouched copy is never reported kept or backed up and replaced.
- setup JSON includes init warnings; init text on an existing .charter/
  always prints warnings; a fresh adf init --force/--reset-adf prints
  engine warnings (stderr under JSON) instead of dropping them.
- --reset-adf with nothing to replace (empty or absent .ai/) needs no
  confirmation in adf init and bootstrap alike (resetAdf kind
  nothing-to-replace).
- init / init --guided print the "Created .charter/ directory" banner
  only on success.
- dirLabel keeps "/" for a root dir; tests for dirLabel, phase-3
  gitignore failure, phase-2 separators and setup JSON warnings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When every backup fails and init / init --guided exit 1 without the
success banner, the files the run did create are now still listed as
Created. Docs: the nothing-to-replace rule also covers an .ai/ whose
files all still match the template. Tests: exit-1 Created lines (plain
and guided), whitespace-only differences count as nothing to replace,
and bootstrap --reset-adf without --yes and no .ai/ keeps a hand-edited
.charter/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stackbilt-admin
stackbilt-admin merged commit 327697e into main Oct 17, 2026
7 checks passed
@stackbilt-admin
stackbilt-admin deleted the fix/369-370-no-silent-overwrite branch October 17, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants