Skip to content

fix(bootstrap): --force merges .ai/ instead of replacing it; add --reset-adf - #372

Merged
stackbilt-admin merged 3 commits into
mainfrom
fix/bootstrap-force-merge
Oct 17, 2026
Merged

stackbilt-admin merged 3 commits into
mainfrom
fix/bootstrap-force-merge

Conversation

@stackbilt-admin

@stackbilt-admin stackbilt-admin commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Closes #354
Closes #347

Summary

charter bootstrap --force replaced .ai/manifest.adf, core.adf, state.adf and the preset modules with the template. That silently dropped custom ON_DEMAND triggers, manifest RULES, the manifest METRICS section, custom constraints and core.adf METRICS ceilings (entry_loc: 120 / 150 became 0 / 500). The only copies were in an ungitignored .ai/.backup/.

This PR implements blueprint option D:

  • --force merges. A file gains only the whole template sections it lacks, and manifest.adf gains an entry, with the template's triggers, for each preset module it has no entry for. A section the file already has is never edited. Every write goes through a re-parse guard (the same contract as the adf migrate: new modules not registered in manifest or CLAUDE.md module index #239/feat(adf): register modules adf migrate creates in manifest.adf #348 writer, reusing sectionHeaders, lastSectionIndex and registerManifestModules). CRLF and the trailing-newline state are kept. A file that cannot be parsed, or that the guard refuses, is left as is, and the warning names --reset-adf.

  • New --reset-adf does the old replacement:

    • unique backups that never overwrite an earlier one (COPYFILE_EXCL plus a suffix);
    • a file whose backup fails is not replaced;
    • .ai/.backup/.gitignore containing *;
    • Replaced .ai/x (backup: …) followed by a loss report (lost sections, items, METRICS rows, reset entries), capped at 10 lines per file, with the full report in JSON.

    It needs --yes or an interactive y. Otherwise it exits 1 and writes nothing. It does not imply --force.

  • Phase 6 populate is scaffold-only. It passes an explicit mode: 'scaffold-only'; adf populate run directly keeps its own --force/--yes.

  • Housekeeping. "Created" is never printed for a file that existed: a rewritten lock prints Updated .ai/.adf.lock. bootstrap: warnings tell users to run 'charter adf register', which does not exist #347: both hints now name charter adf create <module> --load default|on-demand, and the orphan hint is printed only when the orphans were left unregistered.

New module packages/cli/src/commands/adf-scaffold-merge.ts (304 LOC). adf.ts is untouched (1027/1041).

Before → after (reproduction from the blueprint, built CLI, non-TTY)

S = the scaffold files (manifest, core, state, preset modules) when they hold custom content.

Flags S, existing custom .ai/.backup/ Exit
none / --yes skip → skip (unchanged) none 0
--force / --force --yes replace + backup → merge (append-only; a no-op on the repro) grew, tracked → none written 0
--reset-adf (flag ignored) → refuse, nothing written — 0 → 1
--reset-adf --yes (ignored) → replace + backup + loss report grows, gitignored 0
--reset-adf --force --yes replace + loss report, plus pointers and .mcp.json rewritten grows, gitignored 0

Phase 6 CONTEXT/STATE: always replaced → scaffold-only, under every flag combination.

Operator sign-offs

  • Gate 1: option D. --reset-adf requires --yes or an interactive y/N. The merge adds missing sections and missing template modules only. Phase 6 populate is scaffold-only. Housekeeping: gitignore backups, print "Replaced", fix bootstrap: warnings tell users to run 'charter adf register', which does not exist #347.
  • Gate 2:
    • CP-3: template triggers for a template-module file with no entry.
    • CP-7: plain bootstrap --yes stops replacing CONTEXT/STATE.
    • The --reset-adf refusal.
    • CP-1/2/4/5/6/8 as the contract recommends.
  • Ships in 2.1.0 as a data-loss fix, under CHANGELOG ### Changed (with a prominent lead paragraph and the migration) and ### Fixed.

Invariants and where they are tested

Unit tests are in bootstrap-force-merge.test.ts; the built-CLI tests are in integration/bootstrap-reset-cli.test.ts.

INV Tests
INV-1 (phase 3 only appends) "the hand-edited reproduction survives --force --yes byte for byte"; "missing sections and template modules are appended; every original byte stays" (CRLF, no trailing newline)
INV-2 (entries keep their exact bytes) same two tests; "entry-only … leaves the entry untouched"
INV-3 (no bullet added to an existing section) "a section the user has keeps its bullets"; unit test "never inserts into a section the file has"
INV-4 (backup before replace) "backs up before replacing …"; "a file whose backup fails is not replaced"
INV-5 (backups never collide) "backups of later runs never overwrite earlier ones"; unit test "same stamp twice gets a suffix"
INV-6 (backups gitignored) .ai/.backup/.gitignore describe block, including a backup dir left by 2.0.0 under a merge
INV-7 (refusal writes nothing) non-TTY, --format json, and N at the prompt (unit tests); built CLI with stdin ignore and with a closed pipe
INV-8 (required wiring) "adds missing core/state … doctor passes"; "core.adf under ON_DEMAND is not moved"
INV-9 (idempotent) "a second --force run changes nothing" (.ai/ and vendor files)
INV-10 (populate scaffold-only) the populate scaffold-only block (unit) and the built-CLI --yes test
INV-11 (never "Created" for an existing file) the INV-11 block
INV-12 (JSON superset) three flag combinations against a hard-coded 2.0.0 shape

Other scope tests: guard refusal → skipped{guard}; unsupported ADF: version → skipped{unparseable}; non-list DEFAULT_LOAD → skipped{not-a-list}; template module file-only / entry-only / neither; loss report text and JSON, including the cap; #347 hint text. The existing bootstrap.test.ts:98-119 pin is re-pinned to --reset-adf --yes.

Mutation checks: each of the following was made by hand and caught by at least one test.

  • removed the re-parse guard
  • dropped COPYFILE_EXCL
  • let populate force under --yes
  • replaced a file despite a failed backup
  • skipped the reset preflight
  • used stem triggers for template modules

2.0.0 vs this PR (twin scratch repos, npx @stackbilt/[email protected] vs dist/bin.js)

Fresh bootstrap --yes (first commit; see Review round 1 for the populate changes). Text output is identical. The trees are identical apart from the blessed-stack generatedAt timestamp and telemetry. In JSON, 2.0.0 printed two JSON documents on stdout (populate's report, then bootstrap's); this PR prints one. In bootstrap's own document no key was removed or retyped. The only additions are adf-init.details.{scaffolds,replaced,mode,backupGitignore}; all other values are equal.

Re-run bootstrap --yes (each item is sanctioned):

  1. Created .ai/.adf.lock becomes Updated .ai/.adf.lock (INV-11).
  2. The managed-pointer warning now names --force as safe instead of "Do not use --force … re-scaffolds .ai/*.adf". That sentence is no longer true after this change.
  3. Populate prints [skip] … (already customized) instead of [ok] … 1 op applied (CP-7). The trees are identical.

Re-run bootstrap --force --yes:

  1. Created .ai/{manifest,core,state,backend}.adf becomes Unchanged … (the merge; INV-11).
  2. The Backed up 4 files line and the 4 per-file Backed up … warnings are gone (no .ai/.backup/ is written). The warning count drops from 5 to 1.
  3. Populate is skipped (CP-7).
  4. .ai/.adf.lock now hashes the current core/state. In 2.0.0 it hashed the template that populate then overwrote.

Reproduction under --force --yes. git diff --no-index of .ai/ before and after shows only the .adf.lock hash. With missing RULES/GUIDE plus a CRLF manifest with no trailing newline, the diff is pure insertions: + backend.adf (Triggers on: API, Node, DB), + RULES block, + GUIDE block. A second --force run changes nothing, and doctor required wiring passes.

--reset-adf --yes prints:

Replaced .ai/manifest.adf (backup: .ai/.backup/manifest.adf.<ts>)
  lost section METRICS (1 row)
  lost RULES item: CUSTOM RULE: always load billing.adf for payments.
  dropped entry: billing.adf (Triggers on: payments, stripe, invoice) (...)
  reset entry: backend.adf (Triggers on: API, Node, DB, worker, wrangler) -> (Triggers on: API, Node, DB)
Replaced .ai/core.adf (backup: ...)
  changed METRICS entry_loc: 120 / 150 [lines] -> 0 / 500 [lines]
  lost CONSTRAINTS item: CUSTOM: all money math uses integer cents

The backups match the old files and .ai/.backup/.gitignore is *.

Non-TTY --reset-adf exits 1 and writes nothing (the git status is clean).

Notes for review

  • Beyond the listed lines, kept minimal:
    • The bootstrap runtime warnings that said --force "re-scaffolds .ai/*.adf" (pointer custom/managed, both .mcp.json messages) were reworded, because that is no longer true.
    • Embedded populate no longer prints its own JSON inside bootstrap --format json. In 2.0.0 that output made stdout two JSON documents.
  • Contract interpretation:
    • Template-module registration (CP-3) runs in every mode, as in the scope table's "none"/"--yes" columns. In skip mode the manifest outcome is then merged, with addedSections: [].
    • In --reset-adf, VENDORS is excluded from the loss report because it is carried over.
  • Telemetry: the CLI wrapper's passive telemetry (.charter/telemetry/events.ndjson, gitignored, index.ts) is still appended after a refused --reset-adf. That write predates this change and is not bootstrap's. The integration test excludes it explicitly.
  • Scope-table discrepancy, not changed: under --yes alone, .mcp.json's charter entry is replaced in both 2.0.0 and this PR (setupOverwrite = yes || force). The scope table says "warn"; this belongs with bootstrap --yes overwrites .charter/config.json, .mcp.json's charter entry and related files without --force or a backup #369.

NOT in scope (filed separately)

Review round 1 (commit 2c0a725): all 7 findings fixed

  1. [CRITICAL] Populate no longer re-renders the file.
    • The new adf-text-patch.ts applies populate's ops as in-place text edits: ADD_BULLET, REPLACE_SECTION (list or map), and ADD_SECTION.
    • Line endings, section order, whitespace and the final-newline state are all kept.
    • A re-parse guard checks that the result equals applyPatches(old, ops). If it does not, the file is skipped with a reason.
    • This applies to bootstrap and to the adf populate CLI.
    • Reviewer repro (CRLF, non-canonical order, no scaffold text, CF constraint deleted) under --force --yes: the core.adf diff is now 1 +, the adf populate re-adds deleted default CONSTRAINTS bullets on every bootstrap #371 constraint re-add inserted in place with CRLF. A second run shows No scaffold content to replace.
  2. [CRITICAL] A section is filled only while it is absent, empty, or exactly the template's text. Lines are trimmed and blank lines ignored. One user line means hands off.
    • The partial CONTEXT and partial STATE repros keep CUSTOM and BLOCKED under none, --yes and --force --yes.
    • The same shared rule now decides what plain charter adf populate (no --force) fills. Before, it was a substring match on scaffold phrases.
    • The CLI's --force/--yes still force. This is stated in the CHANGELOG.
  3. Refusal wording. It now says nothing is written to the project. The CLI's gitignored .charter/telemetry/events.ndjson is still appended. Updated in the CHANGELOG and cli-reference.md.
  4. Loss report is now computed after phase 6 against the final file and printed as a "Reset report" block.
    • It reads every DEFAULT_LOAD/ON_DEMAND section, not just the last.
    • It reports decoration and weight changes (headerChanges) and VENDORS entries that were not carried over (vendorsDropped).
    • Content refilled by populate or orphan registration is no longer reported as lost. In the repro, state.adf and backend.adf show nothing lost, and billing shows -> (Triggers on: billing).
  5. --reset-adf --yes backup failures.
    • When every backup fails, the adf-init step fails, the status is partial and the exit code is 1.
    • A partial failure keeps exit 0 and prints N of M file(s) not reset: …. adf-init.details.notReset (reset mode only) carries the same list.
  6. Managed-pointer warning. It now names delete-and-re-run, then says what --force also does: rewrites every managed pointer, replaces .mcp.json's mcpServers.charter, and merges .ai/*.adf without rewriting existing content. The generic .mcp.json warning says the same.
  7. Truthful output.
    • Phase 3 prints Unchanged by merge: .ai/<f> (and Already the template: under reset).
    • Phase 6 prints each change: Filled CONTEXT in .ai/core.adf, Added CONSTRAINTS item in .ai/core.adf: ….
    • Populate's own text block is no longer printed inside bootstrap.
    • The populate step's JSON gains changes. populated/skipped now count files; 2.0.0 always reported 1/0.

New tests:

  • Unit tests in bootstrap-force-merge.test.ts:
    • applyOpsAsText: CRLF, no final newline, map replace, append, guard, version.
    • isUntouchedScaffold, including CLI default vs --force.
    • Loss report: duplicate ON_DEMAND, header change, VENDORS dropped, refilled content.
    • All-backups-failed (exit 1) and partial failure, with a mocked copyFileSync.
  • Built-CLI tests in integration/bootstrap-reset-cli.test.ts:
    • The reviewer's CRLF repro.
    • Partial CONTEXT/STATE under 3 flag combinations.
    • "Unchanged by merge" plus "Filled CONTEXT".
    • The reset report not listing refilled STATE.

Mutation-checked: restoring the substring check fails 5 tests; restoring the whole-file reformat fails the CRLF test.

New 2.0.0-vs-PR differences (twin repos):

  • Fresh bootstrap --yes:
    • Phase 6 prints Filled …/Added … lines instead of populate's embedded block and the Populated 1 module(s) line.
    • core/state/backend.adf keep the template layout: CONSTRAINTS stays after GUIDE, the blank line after ADF: 0.1 stays, and the decoration stays ⚠️. 2.0.0 had formatAdf's canonical order and ⚠.
  • Re-run --yes: the custom-content byte counts differ by 1 because of that layout, the lock hashes differ for the same reason, and the output says No scaffold content to replace.
  • --force --yes: prints Unchanged by merge: (was Created), and the backup lines are gone, as before.

All are consequences of findings 1, 2 and 7.

Review round 2 (commit f1fccb2): all 5 findings fixed

  1. [MEDIUM] Generated values are normalized.
    • Populate now normalizes every generated value before building its ops: control characters are stripped, whitespace and newlines collapse to single spaces, and the result is trimmed. This covers the package.json description, the README summary, and every list item and map value.
    • Reviewer repro, bootstrap --yes with descriptions "Demo app ", "Demo second line" and "Demo app": CONTEXT is filled (project: demo — Demo second line, and so on) and the CF constraint is added. refused is [] and there are no warnings.
    • A guard refusal now says what failed, for example could not be edited in place: after the edit, section RULES would not re-parse as the intended content.
  2. [LOW] Refused files are reported on their own.
    • Populate rows gain status: "refused" with a reason.
    • Bootstrap's populate.details gains refused: [{file, reason}]. A refused file is counted in neither populated nor skipped.
    • The CHANGELOG now describes the populated/skipped change exactly. In 2.0.0 they meant 1/0 when populate succeeded and 0 when it failed; they now count files.
  3. [LOW] Line endings are per line. An inserted line takes the ending of the line it follows. Replaced body lines take the ending of the body's first line. Appended sections use the file's dominant ending. No existing line's ending changes. The reviewer's mixed-ending probe gives `… - project: x

… - NEW
. 4. **[LOW] Reset report header changes.** They are now checked for every key, VENDORS and the module lists included (🔌 VENDORS -> 🏷 VENDORS). Headers are printed as the file has them, keeping U+FE0F (⚠️ CONSTRAINTS [load-bearing]). 5. **[LOW] Docs say what phase 6 fills.** CONTEXT is filled when it is absent, empty or exactly the template. STATE is filled only when it is empty or exactly the template; an absent STATE is not added. Fixed in docs/cli-reference.md` and the CHANGELOG.

New tests:

  • Unit tests: normalizeValue; populate with the three descriptions; a refused row in populate JSON; the guard detail; mixed endings; VENDORS header changes with U+FE0F.
  • Built-CLI tests: bootstrap --yes with the three descriptions fills CONTEXT and adds the stack constraint, with refused: [].

Mutation checks: removing the normalization fails 3 tests. Using the dominant ending for an inserted bullet fails the mixed-ending test.

Reviewer scripts s4.sh (all three descriptions) and s5.sh (the reset report) were re-run against this build, along with probe.cjs (mixed endings). The 2.0.0 twin comparison shows no new differences beyond those listed for round 1.

Tests: build, typecheck and verify:adf all pass. Vitest: 1530 pass. The 3 known Windows-only failures remain.

Implemented via constellation-loop against a locked blueprint.

🤖 Generated with Claude Code

…set-adf (closes #354)

bootstrap --force replaced manifest.adf, core.adf, state.adf and the preset
modules with the template, dropping custom triggers, RULES, METRICS ceilings
and constraints (copies survived only in an ungitignored .ai/.backup/).

- --force now merges: a file gains only the whole template sections it lacks,
  and manifest.adf gains entries (with template triggers) for preset modules
  it has no entry for. Existing sections are never edited. Every write goes
  through a re-parse guard; CRLF and trailing-newline state are kept. A
  file the guard refuses or cannot parse is left as is, naming --reset-adf.
- New --reset-adf does the old replacement: unique non-overwriting backups,
  .ai/.backup/.gitignore (*), "Replaced ... (backup: ...)" and a loss report
  (sections, items, METRICS rows, reset entries). It needs --yes or an
  interactive y; otherwise exit 1 with nothing written. It does not imply
  --force.
- Phase 6 populate is scaffold-only (CONTEXT/STATE replaced only while they
  hold scaffold text), so plain bootstrap --yes stops clobbering them; its
  embedded JSON no longer precedes bootstrap's own report on stdout.
- Text output never prints "Created" for an existing file; JSON gains
  scaffolds/replaced/mode/backupGitignore and top-level resetAdf only.
- Hints name `charter adf create <module> --load default|on-demand`
  instead of the nonexistent `adf register`.

Closes #347

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@stackbilt-admin stackbilt-admin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review: #372 (bootstrap --force merges, --reset-adf)

Verdict: CHANGES_REQUESTED. Phase 3 does what it claims. The merge is append-only and byte-preserving, it is idempotent, the guard holds, the refusal works, and the JSON changes are only additions. But phase 6 (populate) still rewrites and drops user bytes in core.adf and state.adf under bare --force, --yes and no flags. That contradicts what this PR's docs promise.

Verification: I checked out head 68e0c2e. pnpm build && pnpm test gives 1500 passed and 3 failed (the 3 known Windows failures). CI is green. Every scenario ran against built dist/bin.js in fresh scratch git repos, and 2.0.0 ran via npx @stackbilt/[email protected] in twin repos.

Findings

  1. [CRITICAL] packages/cli/src/commands/adf-populate.ts:129: phase 6 rewrites the whole file through formatAdf whenever any op applies, after phase 3 printed Unchanged.
    • Repro: in a wrangler and hono repo, bootstrap, then hand-write core.adf. Make it CRLF, with sections in the order METRICS, CONTEXT, CONSTRAINTS, GUIDE, no scaffold markers, and the user has deleted the CF constraint. Run bootstrap --force --yes.
    • Output: Unchanged .ai/core.adf, then [ok] .ai\core.adf (1 op applied). git diff --stat shows core.adf | 29 +++---. CRLF became LF, METRICS moved to the end, and whitespace was normalized.
    • This contradicts docs/cli-reference.md:103: "custom triggers, RULES lines, METRICS ceilings and constraints survive byte for byte, as do line endings". It also contradicts the CHANGELOG's "A section the file already has is never edited".
    • #371 covers which bullet gets re-added. It does not cover the whole-file reformat, which happens for any op, including a legitimate CONTEXT fill.
    • Fix options: make populate's writes byte-preserving the way phase 3's are (text insert or replace plus a re-parse guard), or narrow the docs to phase 3 and say that phase 6 reformats.
  2. [CRITICAL] adf-populate.ts:43-46: the "still template text" check is a substring test, so a lightly edited section is classified as scaffold and replaced wholesale.
    • Repro, CONTEXT: the list holds the placeholder bullet Project context (run 'charter adf populate' …) plus CUSTOM: billing team owns src/pay. Run plain bootstrap --yes, bootstrap with no flags, or --force --yes. The custom bullet is gone.
    • Repro, STATE: the map holds CURRENT: Repository initialized with ADF context system plus BLOCKED: waiting on legal sign-off for EU. The BLOCKED row is gone, under every flag combination.
    • The letter of INV-10 is met, but the CHANGELOG line "no longer replaces hand-written CONTEXT and STATE" is not true for partially edited sections. This is the same class of silent loss as #354.
    • Suggested fix: treat a section as scaffold only when its items are a subset of the template's scaffold items, or replace just the placeholder items.
  3. [NON-CRITICAL] CHANGELOG.md:14: a refused --reset-adf "writes nothing, including under .charter/" is false.
    • Repro: run bootstrap --reset-adf </dev/null and then --reset-adf --format json. Both exit 1, and each run changes .charter/telemetry/events.ndjson. Nothing else changes, confirmed by md5 of every file outside .git.
    • Either suppress telemetry for that path or drop "including under .charter/". The same applies to "writes nothing" in docs/cli-reference.md:104.
  4. [NON-CRITICAL] The loss report (adf-scaffold-merge.ts:192-255) is incomplete in places and overstated in others.
    • Entries in a non-last duplicate ON_DEMAND/DEFAULT_LOAD section are dropped silently, because entryBullets reads only lastSectionIndex and those keys are skipped. Repro: a first ON_DEMAND holding old.adf (Triggers on: legacy) is not reported.
    • A change to a section's weight or decoration ([advisory] to [load-bearing]) is not reported.
    • VENDORS entries that are invalid, and so are not carried over, are not reported.
    • It reports CONTEXT and STATE items as lost when phase 6 refills them in the same run. The repro reported 2 STATE items and 1 backend CONTEXT item as lost, yet git status showed state.adf and backend.adf unchanged.
  5. [NON-CRITICAL] bootstrap.ts:1050-1060: --reset-adf --yes exits 0 when every backup fails.
    • Repro: make .ai/.backup a file. All 4 files print Could not back up …; not replaced, and the exit code is 0.
    • Not replacing the files is correct. But exit 0 means a scripted reset fails silently. Consider partial with a non-zero exit.
  6. [NON-CRITICAL] bootstrap.ts:1228: the managed-pointer warning recommends --force "which merges .ai/*.adf and never replaces it" as the way to regenerate one file.
    • --force also rewrites every managed pointer and replaces .mcp.json's mcpServers.charter entry, and finding 1 still applies under it.
    • "Delete the file and re-run" is the narrow remedy. Either keep it alone or name the side effects.
  7. [NON-CRITICAL] Text output: phase 3 prints Unchanged .ai/core.adf, and phase 6 then modifies that file in the same run (finding 1).
    • A user reads Unchanged as "not touched".
    • The [ok] .ai\core.adf line in phase 6 uses \, and it prints before the [6/7] header because the header is printed after the phase body runs. That ordering predates this PR and is cosmetic.

Verified as claimed

  • Phase 3 merge. Tested with CRLF, no trailing newline, non-canonical order, duplicate ON_DEMAND and RULES, an undecorated ROLE [advisory], custom triggers and METRICS. The diff was insertions only: the backend.adf template-trigger bullet plus RULES appended. A second --force --yes changed nothing under .ai/.
  • Doctor. adf required wiring passes after the merge, including for a manifest that had neither DEFAULT_LOAD nor ON_DEMAND.
  • CP-3. It never duplicated an entry and did not fight orphan registration (billing.adf was registered once with its stem).
  • Unparseable or unsupported manifest. ADF: 9.9 is left as is in both skip and merge, and the warning names --reset-adf. CP-3 is not attempted.
  • Refusal. Non-TTY, closed stdin and --format json exit 1 with no .ai/, hook, package.json or config write. Telemetry is the exception (finding 3). The JSON refusal is a single document.
  • --reset-adf --yes. Backups match the old files, .ai/.backup/.gitignore contains *, and the files are untracked in git status. The METRICS, RULES and dropped-entry lines are accurate. A failed backup means the file is not replaced.
  • JSON vs 2.0.0. Compared on fresh --yes, re-run --yes and --force --yes: 2.0.0 does print two JSON documents. This PR prints one. No key was removed or retyped. The only additions are adf-init.details.{scaffolds,replaced,mode,backupGitignore}.

Rulings

I mapped (a)–(d) to the PR's "Notes for review", since the PR does not label them.

  • (a) Reworded --force warnings: accept. Keep the .mcp.json and pointer wording honest (finding 6).
  • (b) Embedded populate JSON suppressed: accept. It fixes the two-document stdout I reproduced. Note that the populate per-file results are now absent from bootstrap JSON.
  • (c) CP-3 in every mode, with skip mode reported as merged and addedSections: []: accept. It matches the scope table. Be aware that plain bootstrap with no flags now writes manifest.adf without a prompt.
  • (d) VENDORS excluded from the loss report: accept. Entries that are carried over are not losses. Invalid entries that are dropped should still be reported (finding 4).
  • Caveat, telemetry after refusal: the behavior is acceptable, but the doc claim is not (finding 3).
  • Caveat, .mcp.json replaced under --yes alone: acceptable to defer. It predates this PR (setupOverwrite = yes || force, bootstrap.ts:152). Make sure #369 covers .mcp.json explicitly, since its title only names .charter/config.json.

Not verified

  • The interactive TTY y/N prompt, since no TTY was available.
  • Timing with a non-TTY stdin held open: the exit code was 1, but the shell pipeline wait masked how long node itself ran.
  • Backup-name collisions in a real run (covered by unit tests only).
  • Non-Windows platforms.

@stackbilt-admin stackbilt-admin left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial re-review: #372 at 2c0a725

Verdict: CHANGES_REQUESTED. All 7 findings from the previous review are fixed, and I verified each against real runs. The one change I'm asking for is small: the new re-parse guard makes populate refuse benign input that 2.0.0 handled (finding 1 below), and on a fresh bootstrap that leaves core.adf unpopulated. The other findings are non-blocking.

How I checked

  • Detached checkout of 2c0a725. pnpm install && pnpm build && pnpm test gives 1519 passed, 3 failed. The 3 failures are the known Windows ones: bootstrap #307 fixture, context-refresh "captures git signals", serve-context "returns existing snapshot".
  • CI: all checks pass (Governance Scorecard skipped).
  • Every scenario ran against the built dist/bin.js in fresh scratch git repos (hono, wrangler and typescript). Comparison runs used npx @stackbilt/[email protected] and @2.0.0.

The 7 previous findings

  1. Fixed: populate rewrote the whole file via formatAdf. I re-ran the previous repro:
    • Setup: a CRLF core.adf with sections reordered as METRICS, CONTEXT, CONSTRAINTS, GUIDE, no markers, and the CF constraint deleted.
    • Under --yes, no flags, and --force --yes, git diff is a single inserted CRLF line in CONSTRAINTS. That line is the #371 re-add, which is a known, separate issue. Order, CRLF and whitespace are untouched.
  2. Fixed: partial edits to CONTEXT/STATE were replaced. A backend.adf CONTEXT holding the placeholder plus CUSTOM: billing team owns src/pay, and a state.adf holding the placeholder CURRENT plus BLOCKED: …, are byte-identical after all three flag sets.
  3. Fixed: refused-reset docs claimed nothing under .charter/ was written. The CHANGELOG and cli-reference now say the telemetry log is still appended. A refused --reset-adf, with stdin from /dev/null and with --format json, exits 1, and git status shows no project change. The JSON refusal is one document.
  4. Fixed: loss report gaps. Against a hand-built manifest, core and state:
    • These are now reported: entries in a non-last ON_DEMAND section (old.adf (Triggers on: legacy) -> (Triggers on: old)), RULES [load-bearing] -> RULES, CONSTRAINTS [advisory] -> ⚠ CONSTRAINTS [load-bearing], dropped VENDORS entry: NOPE.md: banana, the METRICS rows, and the lost items.
    • Content refilled by populate is no longer reported: backend.adf … nothing lost.
    • I checked every line against diff backup final. It is accurate apart from the gap in finding 4 below.
  5. Fixed: exit 0 when every backup fails. With .ai/.backup as a regular file:
    • Text output prints 4 of 4 file(s) not reset and exits 1.
    • --format json exits 1 with adf-init: fail, notReset holding 4 entries and replaced: [].
    • A normal reset still exits 0.
  6. Fixed: the managed-pointer warning oversold --force. It now leads with "delete and re-run" and lists what --force also does: pointers, .mcp.json, and the .ai/ merge.
  7. Fixed: phase 3 printed Unchanged for files phase 6 then modified. Phase 3 now prints Unchanged by merge: .ai/core.adf. Phase 6 then prints Added CONSTRAINTS item in .ai/core.adf: …, with forward slashes and after the [6/7] header. The embedded [ok] .ai\core.adf line is gone.

New findings

  1. [MEDIUM] adf-populate.ts:233 and adf-text-patch.ts:105-112: populate builds values that do not round-trip through the parser, so the guard refuses the whole file. This regresses from 2.0.0.
    • Cause: contextItems embeds package.json description verbatim. The parser trim()s list items and splits on newlines, so a description with trailing whitespace, or one containing \n, can never equal applyPatches(parse(old), ops). The guard then refuses every op for core.adf, including the stack CONSTRAINTS bullet.
    • Repro: a fresh repo with "description": "Demo app ", or "Demo\nsecond line", then bootstrap --yes.
    • Result: core.adf keeps the placeholder Project context (run 'charter adf populate' …) and gets no No Node.js-specific APIs… constraint. Output: Warning: .ai/core.adf could not be edited in place without changing other content (guard); left as is. JSON: populate: pass, populated 0.
    • 2.0.0 on the same repo fills CONTEXT with project: demo — Demo app.
    • The warning blames "other content", but the only problem is populate's own value. Every later bootstrap repeats it.
    • Suggested fix: normalize generated values before building ops (trim, collapse internal newlines). Add a test with a whitespace-padded or multi-line description.
  2. [LOW] populate.details.skipped mixes two outcomes. It counts both "nothing to do" files and files the guard refused, so JSON consumers cannot tell them apart. Example: in the repro above, a re-run reports skipped: 3, and one of those 3 was refused. The refusal appears only as a free-text warning.
    • populated/skipped also change meaning compared with 2.0.0, where they meant "populate ran (1/0)". The CHANGELOG discloses this, but it is a semantic change of existing keys, not an addition. Its wording "always reported 1/0" is slightly off, since 2.0.0 reported 0 on failure.
    • Consider a refused count or a per-file status: 'refused'.
  3. [LOW] adf-text-patch.ts:55: in a mixed-ending file, edited lines become CRLF. crlf = text.includes('\r\n'), so a mostly LF file with one CRLF line gets its inserted or replaced lines written as CRLF.
    • Probe: 'ADF: 0.1\nCONTEXT:\n - old\r\n\nCONSTRAINTS:\n - a\n' gives … - project: x\r\n… - NEW\r\n.
    • The guard passes, because the parser ignores endings. "Line endings are kept" holds only for uniform files. Cosmetic.
  4. [LOW] adf-scaffold-merge.ts:165: a VENDORS header change is not reported. VENDORS sits in MANIFEST_EXCLUDED_KEYS, so the header check skips it. In my reset run, 🔌 VENDORS: became 🏷 VENDORS: with no changed header line, although the docs promise "changed section decorations or weights".
    • Also cosmetic: headerChanges.after shows ⚠ without U+FE0F, because the parser drops it, so the reported header differs from the bytes in the file.
  5. [LOW] docs/cli-reference.md:107 and the CHANGELOG: "absent" is true for CONTEXT only. Both say phase 6 fills CONTEXT/STATE "while the section is absent, empty, or exactly the template's text". For STATE, buildStateOps returns null when the section is absent, so an absent STATE is never filled.

Probes of the new code that held up

  • applyOpsAsText handles the following correctly:
    • CRLF, no trailing newline, an empty section at EOF (CRLF, no final newline), tabs, nested-indent bullets, a header with trailing spaces and a weight, a BOM, and an inline header value plus body.
    • Text-type bodies replaced under force, and trailing blank lines kept.
    • ADD_SECTION with no final newline, and the guard refusing a body that is part list, part text.
    • Lone-CR files and a same-key ADD_SECTION are refused. The refused ADD_SECTION is labeled unparseable because applyPatches throws, which is a mislabel but safe.
  • Duplicate sections: sectionHeaders(...).own[0] and applyPatches' doc.sections.find both target the FIRST section with a key, so the guard checks the right section.
  • Bytes the parser does not model: the REPLACE range is the section body from the header to the next header. The scaffold-only path enters it only when the normalized body equals the template, so the most it can lose is trailing whitespace or blank lines inside a placeholder section.
  • isUntouchedScaffold:
    • Ignores whitespace-only edits (true).
    • Treats reordered template bullets and * bullets as hand-written (false, the conservative direction).
    • Also treats the inline or undashed text form, and STATE written as a list, as untouched (harmless).
  • 1.9.3 templates still count as scaffold, so the template-version risk is zero in practice.
    • The constants are textually identical to 1.9.3's.
    • A 1.9.3 bootstrap --yes repo, upgraded with bootstrap --yes, gets no .ai/*.adf change. Only the lock changes, because 1.9.3 had already populated it.
    • A 1.9.3 adf init repo: plain adf populate and bootstrap --yes fill all four files, as 2.0.0 does, but without the re-render.
  • Plain charter adf populate: without flags it fills only exact-template sections, and --force still overwrites customized CONTEXT/STATE. JSON rows gain changes, and reason when one applies. --dry-run leaves the file unchanged (md5 identical). The INV-10 tests cover plain, --yes and --force.
  • JSON vs 2.0.0: notReset appears only in reset mode, and populate.details.changes is added. No key is removed or retyped (see finding 2 for the semantic change).

Not verified

  • The interactive TTY y/N prompt, since no TTY was available.
  • Non-Windows platforms.
  • Reset where only some backups fail (I covered all-fail and none-fail; the unit tests cover partial).

@stackbilt-admin
stackbilt-admin merged commit 630b34e into main Oct 17, 2026
7 checks passed
@stackbilt-admin
stackbilt-admin deleted the fix/bootstrap-force-merge branch October 17, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants