Repository navigation
feat(adf): register modules adf migrate creates in manifest.adf - #348
Conversation
#239) adf migrate now registers every module it routes content into: core.adf and state.adf under DEFAULT_LOAD, others under ON_DEMAND with triggers inferred from the migrated headings (RoutingTrace.headingKeyword from @stackbilt/adf). The manifest is written after the module merge and before the pointer, so the hybrid CLAUDE.md module index includes the new entries; a later non-CLAUDE.md source refreshes that index. One shared append-only writer (adf-manifest-register.ts) replaces bootstrap's two orphan writers, including the non-idempotent line splice. This completes the migrate half of #241. Co-Authored-By: Claude Opus 5.5 <[email protected]>
stackbilt-admin
left a comment
There was a problem hiding this comment.
CHANGES_REQUESTED
Adversarial review of #348 against the approved blueprint (diagram.md plus issue-239.contract.ts, Q1–Q5). I built origin/auto/feature/issue-239 @ 5853a52 in a clean worktree. pnpm build passes. vitest run gives 1043 passed and 5 failed, the same 5 known Windows failures listed in the PR body. I also ran manifest round-trip harnesses and bootstrap --yes / doctor end to end.
Required changes
-
The shared writer destroys hand-edited manifest content. This is blocking, and bootstrap is now more destructive than on main.
packages/cli/src/commands/adf-manifest-register.ts:324(fs.writeFileSync(manifestPath, formatAdf(doc))) rewrites the whole manifest through parseAdf/formatAdf whenever one entry is appended. Migrate now does this automatically, and so does bootstrap's orphan pass, which was a byte-preserving line splice on main. These are the results of registering one module (infra.adf) on realistic manifests:- Preamble comment lines are deleted, and a stray duplicate
ADF: 0.1section is appended at the end of the file. Input:# Team manifest: keep RULES last, ping @platform before editingon line 1, thenADF: 0.1. The parser ignores lines before the first header, so the version line is parsed as a section namedADFand re-emitted afterformatAdfwrites its own version line. I reproduced this end to end withbootstrap --yesand a pre-existing orphan. Output:-# Team manifest: keep RULES last, ping @platform before editing ADF: 0.1 +📐 RULES: ...(moved up) ... + - backend.adf (Triggers on: backend) + - Observability.adf (Triggers on: observability) -📐 RULES: ... +ADF: 0.1 - HTML comments and markdown tables in text sections (e.g. CONTEXT) are deleted by
normalizeSectionin the formatter (stripHtmlComments/stripMarkdownTables).Routing notes <!-- TODO: revisit after Q3 -->plus a 3-row| module | owner |table becameRouting noteswith nothing else. - CRLF files are rewritten as LF, so the whole file churns. Blank lines inside list sections are dropped.
- - backend.adfis rewritten. Tab-indented text is reindented. A one-lineCUSTOM_THING [advisory]: hellowith body text has its inline value moved into the body. - Reordering sections into canonical order happens as well (on this repo's own
.ai/manifest.adf, SYNC moves above METRICS). That much is acceptable on its own.
On main, bootstrap's
registerOrphansInManifestinserted two lines and left everything else intact, so this PR turns a non-destructive path into a destructive one. Required fix: append at the text level. Find the target section's header line, insert- <entry>after its last list item, use the file's existing EOL, and leave every other byte alone. When the section is missing, append a new section block. As a guard, re-parse the result and check thatparseManifest(after)equalsparseManifest(before)plus the new entries, and skip with a warning otherwise. Add tests that assert byte-for-byte preservation for a preamble comment, a CONTEXT section with an HTML comment and a table, a CRLF file, and this repo's own manifest (before + inserted lines === after). The current test atadf-manifest-register.test.ts("creates missing sections in canonical order") locks in the reordering and should be relaxed. - Preamble comment lines are deleted, and a stray duplicate
-
An empty section header is reported as "not a list", so registration is skipped. At
adf-manifest-register.ts:309, a manifest containing📂 ON_DEMAND:with no items (left behind after a user deletes every entry) parses as{type:'text', value:''}. The result isskipped/section-not-listand the warning "ON_DEMAND … is not a list".DEFAULT_LOAD:with no items behaves the same way, which leavescore.adfunregistered and doctor failing. The old splice writer handled this case. Treat an empty text section as an empty list, and add a test. -
REGISTER/JSON output for
already-registeredmodules reports inferred triggers that are not in the manifest. Repro: manifest hasfrontend.adf (Triggers on: React, CSS, UI), and CLAUDE.md has## React components. Both text and JSON printfrontend.adf → ON_DEMAND: react, components [already registered], and thereasonsays "triggers inferred from 1 heading keyword(s)…". None of those triggers exist or will be written. The same problem affectscore.adfwhen it sits under ON_DEMAND: the line readscore.adf → DEFAULT_LOAD [already registered]while the module is actually under ON_DEMAND. Ruling on judgement call (c): printing a REGISTER line for already-registered modules is correct, because the contract defines the[already registered]suffix. The triggers shown must be the existing entry's, though. Atadf-manifest-register.ts:304, for already-registered entries, filltriggers(andtriggerSources) from the parsed manifest entry, or reporttriggers: []with no inference text inreason. Do not report a plan the writer refused to apply. The core.adf-under-ON_DEMAND case can keeploadPolicy: 'DEFAULT_LOAD'as the classification, since the warning already names the real placement. -
An unparseable manifest is skipped silently. This is judgement call (a), and the answer is no, it is not acceptable. At
adf-manifest-register.ts:290-291, the contract's ownRegistrationStatusdoc saysskippedmeans "Nothing written; a warning is emitted". The missing template is a gap in the warning envelope, and silence is the worse reading. As it stands, migrate creates modules, registers none of them, says nothing, anddoctorfails later. Emit a warning in the same style, e.g.{manifestPath} could not be parsed ({error}); {count} module(s) were written but not registered, and assert it in the existingskips with manifest-unparseabletest.
Non-blocking notes
- JSON vs text (orchestrator item 2): does not reproduce. I used a fresh tree, the scaffold manifest, and CLAUDE.md with
## Deployment/## React components/## Docker images. Text and JSON dry-runs both reportinfra.adf → ON_DEMAND: deployment, docker, images [planned]withtriggerSources: [heading-keyword, heading-keyword, heading-token]. The impl's earlier e2e must have run JSON on a different fixture. No change needed beyond item 3. - Trigger inference against §4 conforms: weight ×2 for the keyword only when the heading route chose this module, per-item counting, stopwords plus generic words, a 2-letter allowlist with a sync test, dropping other modules' triggers, cap 6, named seeds first, lowercase stem fallback, and deterministic output. On whether "images" surviving means the lists are too thin: yes.
images,components,workflow,release,appsandviaall survive as triggers.STOPWORDSlacksvia,use,how,when,all,not, and the generic list lackssetup,usage,guide,general,conventions,best,practices,tips,misc. Purely numeric tokens (2024) also pass. Consider a follow-up to widen the lists and drop all-digit tokens. A multi-word trigger owned by another module (dependency graph) does not block its single-word parts. Separately, a stem fallback shorter than 3 characters that is not in the allowlist (e.g.ux.adfgivesux) would violateTriggerSchema. That is an edge case. - Invariant tests: INV-2, -3, -4, -5 and -6 would each fail if their invariant broke. INV-1 is weak at the migrate level. The re-run test's sources are already pointers, so
migrateSourcereturns before the writer is called. Idempotency is really covered by the writer unit test and by INV-5's GEMINI.md re-run. Consider a migrate-level re-run with a fresh non-pointer source routing to the same new module. @stackbilt/adfcompatibility (item 6):headingToModuleis module-private and not exported frompackages/adf/src/index.ts, so its return-type change is not a public API break.RoutingTrace.headingKeywordis an additive optional field.classifyElementnow always setsroutingTrace, which is a behaviour change for anyone who usedroutingTrace !== undefinedto mean "content routing ran". The two in-repo consumers (adf-migrate.tsmisroute audit,adf-tidy.tsitemRoutes) behave the same becausecandidateScoresis{}. External consumers need a minor bump (feature), not a major one.phraseOverrideis now an explicitundefinedkey, sotoStrictEqualconsumers would notice.- Bootstrap (item 7): On a fresh repo,
bootstrap --yesregistersinfra.adf (Triggers on: deployment, docker, images)once. A re-run gives no orphan warning and a byte-identical manifest, anddoctorpasses the wiring checks. With pre-existing orphans, both are registered (lowercase stem) and doctor passes, apart from the destruction in item 1. Behaviour changes to note in CHANGELOG: orphan triggers are now lowercase, a non-list DEFAULT_LOAD now skips where it used to raw-append, and in--format jsonbootstrap swallows writer warnings entirely (bootstrap.ts:233). - Windows paths (item 8): entries are always written from
normalizeModulePathoutput, so forward slashes only. No backslashes reach the manifest. Thetargetfield in JSON is.ai\\manifest.adfon Windows, which matches the other actions. Matching is case-sensitive: if a user hasInfra.adfand migrate targetsinfra.adf, Windows gets two entries for the same file. This is an edge case. - Under
--dry-runwith no manifest, the warning says modules "were written". That is false in dry-run. Consider "would be written". - Judgement call (b), JSON-mode warnings on stderr, is fine.
adf_migrate_locis 748 / 792, under the 765 target. Good.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #239
Closes #241
Summary
charter adf migratenow registers every module it routes content into, in.ai/manifest.adfand in the hybridCLAUDE.mdmodule index. This follows the approved blueprint for #239 (Q1–Q5 resolved as recommended).@stackbilt/adf:headingToModulereturns{module, keyword}.RoutingTracegainsheadingKeyword, andclassifyElementnow sets the trace even without a trigger map (candidateScoresis{}in that case).packages/cli/src/commands/adf-manifest-register.ts: one shared writer,registerManifestModules. It round-trips through parseAdf/formatAdf, matches entries by normalized parsed path, appends only and never rewrites an entry, and creates a missing section in canonical order. Each module gets a status ofplanned,added,already-registeredorskipped(withskipReason). The file also holds the §4 trigger inference (inferTriggers), REGISTER formatting, and the dry-run dedupe across sources.STOPWORDSmoved here fromadf-suggest, which now imports it.adf-migrate.ts: registration happens afterapplyMigrationToModuleand beforewritePointerWithRetained. A source other thanCLAUDE.mdthat adds a module re-runsupdateModuleIndex('CLAUDE.md'). Each module gets aREGISTERaction, andsources[].registrations[]is added to the JSON. I removed the dead weight-promotion block and the empty Helpers banner;adf_migrate_locis 748 / 792.bootstrap.ts:registerOrphansInManifest(a line splice that was not idempotent) andregisterModulesInDefaultLoadare deleted, and orphans go through the shared writer. They get a lowercase stem trigger, soObservability.adfgetsobservability.adfCreate's upsert writer, and thecharter adf registerhint (bootstrap: warnings tell users to run 'charter adf register', which does not exist #347).Warning: …. In JSON mode they go to stderr so the JSON on stdout stays valid.Invariants and where they are tested
adf-migrate-register.test.ts, "a re-run writes nothing and adds no entries" compares a snapshot of the whole tree. Alsoadf-manifest-register.test.ts"appends entries and is idempotent on a second call", and the bootstrap orphan re-run test.CLAUDE.mdindex from the same source containsinfra.adf.AGENTS.mdcreatesinfra.adfand theCLAUDE.mdindex lists it.Every row of the behavior matrix (§3) has a test in
adf-migrate-register.test.tsoradf-manifest-register.test.ts: new module ON_DEMAND/DEFAULT_LOAD, scaffold-listed module, registered module, touched and untouched orphans, core.adf under ON_DEMAND, two sources routing to one module, late index refresh, re-run, new source routing to an existing module, dry-run, multi-source dry-run dedupe, JSON shape,--replace, missing manifest,bootstrap --yes, and--ai-dir.@stackbilt/adfhas its ownheadingKeywordtests incontent-classifier.test.ts, and theALLOWED_SHORT_TOKENSsync with the heading vocabulary is checked by a test.Notes
formatAdfapplies the canonical section order, so a manifest that hadRULESafterON_DEMANDgets it moved up on the first registration write. The old bootstrap DEFAULT_LOAD writer andadf createalready did this; entries are not changed.skippedwithmanifest-unparseable, but no warning, because the contract's warning envelope has no template for that case.docs/cli-reference.md.Test results:
pnpm build,pnpm typecheckandpnpm testall ran. 1043 tests pass and 5 fail, the same 5 that already fail on Windows on main (bootstrap #307 fixture, context-refresh git signals, serve-context snapshot, and two precommit-hook auto-tidy tests).Implemented via constellation-loop against a locked blueprint.
🤖 Generated with Claude Code
Contract amendments (approved during review, round 1):
already-registeredrows report the manifest's real placement and triggers as spelled there, withtriggerSources: []. The TriggerSchema and 1..6 refinements govern only the triggers migrate writes (planned/added).manifest-unparseable.adf registermessage).