Skip to content

fix(populate): leave an edited CONSTRAINTS section alone (#371) - #378

Merged
stackbilt-admin merged 5 commits into
mainfrom
fix/371-populate-constraints
Oct 18, 2026
Merged

stackbilt-admin merged 5 commits into
mainfrom
fix/371-populate-constraints

Conversation

@stackbilt-admin

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

Copy link
Copy Markdown
Member

Closes #371

Problem

charter adf populate (bootstrap phase 6) appended every detected stack constraint it did not find to core.adf CONSTRAINTS, so a bullet the user deleted came back on every bootstrap.

Fix (three commits)

71d050b: stack constraints go only into a CONSTRAINTS that is missing or still exactly the template's; any edit leaves it alone, with a reason.

e2e860e (review round 2): populate now remembers what it did, in .ai/.populate.json:
{ "version": 1, "constraints": { "core.adf": { "added": [...], "offered": [...] } } }. The text is normalized, lists are sorted and de-duplicated, the JSON uses a two-space indent and a trailing newline, and the file is written only when it changes (not on a no-op run, not on --dry-run). It is meant to be committed: bootstrap lists it under "Created", and its git add .charter .ai ... next step already covers it.

  • Never re-add a recorded constraint, whether it is still in the section or was deleted. This fixes the plain-Worker case where populate adds a single rule (deleting it used to leave the exact template, so the rule was re-added). Once a file has a record, a deleted CONSTRAINTS section is not recreated.
  • Untouched means the template's bullets in order, followed only by recorded-added bullets, each at most once. Only an untouched section gets newly detected constraints, and each one is recorded as added.
  • Edited or non-list section plus a new constraint: it is not added. It is reported once, as text and as a structured notAdded (section, why: edited | not-a-list | removed, constraints) on the adf populate --format json row and in bootstrap --format json steps[populate].details.notAdded. It is then recorded as offered, so later runs stay quiet.
  • No hint recommends --force. The new text: "CONSTRAINTS has been edited, so populate did not add the stack constraint: X. Add it by hand if you want it." The not-a-list branch has the same wording.
  • Repos without a record behave like a record with nothing in it, and start one on the first add or offer. A record that cannot be read is left as is and reported as status: "refused", and nothing is recorded that run.
  • --force (and populate's own --yes) keeps its semantics: it appends any detected constraint not present, and now records it too. It also fills an emptied section, which was skipped silently before. Bootstrap never runs populate in force mode.
  • Placement: a created CONSTRAINTS goes after CONTEXT, else after GUIDE, else before METRICS (where the scaffold puts it). This goes through an anchored ADD_SECTION in adf-text-patch.ts. The re-parse guard is kept: the expected document is built one op at a time with the section moved to the same anchor, and the comparison is still exact. The header is written as ⚠️ CONSTRAINTS [load-bearing]:; the parser drops U+FE0F, so the text edit restores it.

aa6241d (review round 3):

  • Invalid record fails closed. A UTF-8 BOM is stripped first. Bad JSON, version other than 1, or the wrong shape (an array constraints, a non-object entry, a non-list or non-string added/offered) means no stack constraints are added for any file that run. CONTEXT/STATE filling is unaffected. The record is never rewritten, and its row reports status: "refused" once per run.
  • Parsing moves to adf-populate-record.ts. Entries are kept in a Map, so a __proto__ key stays an ordinary key. Keys are normalized to the bare module name (.ai/core.adf is read as core.adf).
  • --reset-adf (both adf init and bootstrap, via writeAdfScaffolds): the record is backed up to .ai/.backup/.populate.json.<stamp>, the entry of each replaced module is dropped, and a line in the run's warnings says so. I chose a backup plus a warning line over adding entries to the loss report. A reset Worker repo gets its rule again. bootstrap.ts is not changed in this round.
  • Placement: a created CONSTRAINTS goes right after whichever of GUIDE and CONTEXT comes later, which is the scaffold's own position. A CONTEXT that populate appends in the same run is followed by CONSTRAINTS. Tested through populate.
  • A skipped core.adf row says CONTEXT already customized; no stack constraints to add and never suggests --force.
  • The record row has status: "recorded", so it is not counted in details.populated.
  • "left as is" is no longer doubled.
  • The "Edits are in place" docs paragraph is back under adf populate.

Checked that a dotfile in .ai/ is ignored: tidy, serve, bootstrap and vendor all filter *.adf. doctor's LOC and security walks skip .ai. bundle and migrate read manifest and vendor files only. .adf.lock (itself a dotfile there) hashes only core/state. A scratch bootstrap followed by doctor, adf evidence --auto-measure, adf tidy --dry-run, adf bundle, adf sync --check, adf migrate --dry-run and score printed nothing about it, and the evidence gate passed.

Known, left as is (review finding 7): only bullets are compared. Changing just the CONSTRAINTS header's weight ([advisory]) or removing its decoration does not count as an edit.

bootstrap.ts: one added line in runPopulatePhase (details.notAdded).

Tests

  • adf-populate.test.ts:
    • template-only section gets the rule once, then a no-op
    • deleted default stays deleted
    • user bullet, reworded default, emptied section and not-a-list section are left alone; no hint mentions --force
    • duplicate CONSTRAINTS headers: the first one is judged
    • a deleted populate bullet, and the single-rule plain-Worker delete, both stick across runs
    • missing section is created once, then not recreated once recorded
    • CRLF is kept
    • --force pinned, including the recorded-but-deleted case
    • record: created, deterministic bytes, mtime unchanged on re-run, not written on --dry-run, unreadable record refused
    • an offered constraint is warned about once, then quiet
    • an untouched template plus recorded bullets still gets a new constraint
    • placement: after CONTEXT; at end of file with no trailing newline; CRLF; before METRICS (direct text-patch test)
  • integration/bootstrap-reset-cli.test.ts (built CLI):
    • a pre-record repo is warned once and then quiet; the hint has no --force; Created .ai/.populate.json is printed
    • structured details.notAdded appears once, then is empty
    • idempotent re-runs, including the record bytes
    • single-rule delete sticks under no flags, --yes, and --force --yes
  • Round 3 adds tests for: each invalid-record shape (core.adf CONSTRAINTS byte-identical), BOM, path keys, __proto__, reset through adf init and bootstrap, placement through populate, the skip text, the record status and count, and the single "left as is".
  • Full suite: 1677 pass. The only 3 failures are the known Windows path-separator ones (bootstrap bootstrap: phases 6/7 collect warnings without printing them; absoluteAiDirArg misses Windows paths on POSIX #307, context-refresh, serve-context).

Docs: CHANGELOG Unreleased/Fixed (2.1.0 history untouched); docs/cli-reference.md sections for adf populate (including what .ai/.populate.json is and that it should be committed) and bootstrap phase 6.

🤖 Generated with Claude Code

kovermier and others added 5 commits October 17, 2026 18:45
adf populate (and so every bootstrap) appended detected stack constraints
to CONSTRAINTS whenever it did not find them, so a default the user had
deleted kept coming back. Stack constraints are now added only when
CONSTRAINTS is missing (created [load-bearing]) or still exactly the
template's bullets. Any edit, including deleting a default or one of
populate's own earlier bullets, leaves the section alone, and the core.adf
result carries a reason naming what was not added (bootstrap warns with
it). --force keeps the additive behaviour and now also fills an emptied
section. ADD_SECTION text edits write a text-style decoration back with
U+FE0F, as the scaffolds do, so the re-parse guard accepts it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e.json (#371)

Review round 2 on #378. A section holding the template plus the one bullet
populate added is, once that bullet is deleted, the template again, so the
plain-Worker rule kept coming back. Populate now keeps .ai/.populate.json
(version 1; per file, sorted `added` and `offered` lists, written only when
it changes) and never re-adds a recorded constraint. A section is untouched
while it is the template's bullets followed only by recorded-added ones; a
recorded file whose CONSTRAINTS was deleted is not recreated. A new
constraint for an edited section is reported once, as text and as a
structured `notAdded` field (populate JSON row, bootstrap
details.notAdded), and recorded as offered. Hints no longer suggest
--force. A created CONSTRAINTS goes after CONTEXT (else GUIDE, else before
METRICS) via an anchored ADD_SECTION whose position the re-parse guard
checks. --force semantics unchanged, now recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ies (#371)

Review round 3 on #378.
- An invalid .ai/.populate.json (bad JSON, version != 1, wrong shape,
  including an array `constraints` or a string `added`) blocks every stack
  constraint for the run; CONTEXT/STATE still fill. It is reported once per
  run and never rewritten. A UTF-8 BOM is stripped first.
- Record parsing moves to adf-populate-record.ts: entries in a Map (no
  prototype keys), keys normalized to the bare module name.
- adf init / bootstrap --reset-adf back the record up to .ai/.backup/ and
  drop each replaced module's entry, so its stack rules are filled again.
- A created CONSTRAINTS goes after the later of GUIDE and CONTEXT.
- No core.adf row suggests --force; the record row is status "recorded"
  and not counted as populated; no doubled "left as is"; docs paragraph
  moved back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review round 4 on #378.
- dropRecordEntries catches backup and write failures and returns a
  warning: the reset still registers modules, writes .adf.lock, carries
  the VENDORS record over and reports losses; the exit code is unchanged.
- A read-only record is probed up front: populate adds no stack
  constraints that run (it could not record them), warns on the record
  row and never throws. The final write is caught too.
- A reset drops the entry of every module it leaves at the template:
  replaced, created, or already the template.
- While the record is invalid or unwritable, the core.adf row carries
  constraintsSkipped instead of "CONTEXT already customized" alone.
- A reset with an invalid record leaves it untouched and warns.
- Record keys with no file name are invalid; empty-list entries count as
  not recorded; parse errors are reported on one line; unknown fields
  are documented as dropped on rewrite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stackbilt-admin
stackbilt-admin merged commit dfcaacc into main Oct 18, 2026
7 checks passed
@stackbilt-admin
stackbilt-admin deleted the fix/371-populate-constraints branch October 18, 2026 00:50
stackbilt-admin pushed a commit that referenced this pull request Oct 18, 2026
Keeps both the #366 and #371 CHANGELOG entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stackbilt-admin added a commit that referenced this pull request Oct 18, 2026
parseAdf drops the U+FE0F variation selector from section decorations, and
formatAdf emitted the parsed form. As a result, adf fmt --write rewrote the
standard decorations (CONSTRAINTS, FILES, TOOLS) to their text-style
glyphs, and adf fmt --check flagged correctly decorated files.

- New canonicalDecoration(key, decoration) in @stackbilt/adf returns
  STANDARD_DECORATIONS[key] when the parsed decoration equals it apart from
  U+FE0F, and otherwise returns the decoration unchanged. formatAdf applies
  it to every explicit decoration.
- The text patcher's U+FE0F workaround (#378) uses the same helper, so
  headers that populate adds are byte-identical to adf fmt output. Other
  decorations no longer gain a U+FE0F that fmt would strip.
- This repo's .ai/*.adf CONSTRAINTS headers are rewritten to canonical
  form, and .adf.lock is refreshed (adf sync hashes raw bytes).

adf fmt --write output changes for affected files.

Closes #351

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

adf populate re-adds deleted default CONSTRAINTS bullets on every bootstrap

2 participants