Skip to content

feat(adf): record vendor file modes in manifest.adf (#318 1/6) - #350

Merged
stackbilt-admin merged 2 commits into
mainfrom
auto/feature/issue-318-vendor-record
Oct 16, 2026
Merged

stackbilt-admin merged 2 commits into
mainfrom
auto/feature/issue-318-vendor-record

Conversation

@stackbilt-admin

Copy link
Copy Markdown
Member

Refs #318

PR 1 of 6 from the #318 blueprint. It adds a record of each vendor file's mode, the API to read it, and charter adf vendor status|set|init. No command acts on the record yet.

What it adds

  • The record. .ai/manifest.adf can carry a 🏷️ VENDORS: list of <file>: <pointer|compiled|unmanaged> items. parseManifest gains a permissive vendors: {raw, file, mode}[] field that never throws. VENDORS gets a decoration, sorts after SYNC in CANONICAL_KEY_ORDER, and is added to MANIFEST_PLUMBING_KEYS.
  • Read API (packages/cli/src/commands/adf-vendor.ts):
    • inferVendorMode works the way adf tidy classifies files: banner first, then POINTER_MARKERS, else unmanaged. A pointer-only name is never compiled.
    • resolveVendorMode(s) returns {mode, source: recorded|inferred, evidence, disagrees}.
    • Entry problems are malformed, unknown-file, mode-not-allowed and duplicate. For duplicates, the last valid entry wins.
  • Writer. recordVendorModes(manifestPath, entries, 'add-if-absent'|'upsert') uses the adf migrate: new modules not registered in manifest or CLAUDE.md module index #239 text-level helpers in adf-manifest-register.ts:
    • insertManifestBullet now takes the section key and decoration.
    • A new replaceManifestBullet does the one-line upsert.
    • The re-parse guard is kept.
    • ALLOWED_MODES is checked on every path.
  • Commands. charter adf vendor status [--all], set <file> <mode> [--dry-run] and init [--dry-run], all with --ai-dir and --format json. Exit codes follow the contract:
    • status always exits 0.
    • set exits 1 for a mode that is not allowed or a skipped write. It exits 2 for usage errors, an unknown file or mode, or a missing manifest.
    • init exits 2 for a missing manifest, and 1 for any skip other than already-recorded or file-absent.
  • Implicit writers. These record add-if-absent, only after a real write and never under --dry-run:
    • bootstrap's pointer phase records pointer. Under CP-7, its warnings go into the phase-3 step's warnings.
    • adf init --emit-pointers records pointer.
    • adf migrate records pointer after the pointer is written.
    • adf compile --write records compiled.
    • A record failure is only a warning. It goes to stderr where the command has no JSON warnings channel, and it never changes the exit code or JSON.

What is NOT changed yet (later PRs in the series)

Because implicit writers are add-if-absent, compile --write over a file bootstrap recorded as pointer keeps the record and warns. vendor status then shows (recorded; file looks compiled). PR2 makes that flip need --mode compiled.

Invariants and where they are tested

  • INV-1, no consumer behaviour change: adf-vendor.test.ts › "consumers ignore the record". It covers compile --check/--write/stdout, tidy and doctor. Each runs in two repos that differ only by a VENDORS section, and the stdout, filtered stderr, exit codes and resulting vendor bytes must be identical. The precommit-hook and hook parity tests are unchanged.
  • INV-2, a byte-preserving writer with a re-parse guard: recordVendorModes tests. They cover insert, a new section at EOF, CRLF, no trailing newline, the one-line upsert, this repo's own manifest fixture, the lone-CR guard refusal, and re-parse equality.
  • INV-3, read-only commands never write: status leaves bytes and mtime unchanged, and compile --check and stdout leave the manifest unchanged.
  • INV-4, never compiled: packages/adf vendors.test.ts checks every target, including a module that declares VENDORS. There is also a CLI stdout check.
  • INV-5, inference matches tidy: one test per case compares against adf tidy --dry-run --format json as the oracle. The cases are banner, each pointer template, banner plus a quoted marker, hand-written, and absent.
  • INV-6, init is idempotent: three runs, and existing entries are never overwritten.
  • INV-7, ALLOWED_MODES on every path: writer tests for both policies and with the manifest missing, plus vendor set copilot-instructions.md compiled exiting 1.
  • INV-8, implicit writers record only after a real write and keep existing entries: init --emit-pointers, compile, migrate (--dry-run versus real) and bootstrap.
  • INV-9, a failed record write changes no exit code or JSON: compile --write JSON is identical with a broken VENDORS section, and the bootstrap warning lands in the step's warnings.
  • INV-10, --ai-dir: tested for both set and status.
  • INV-11, the register writer is unchanged: adf-manifest-register.test.ts is untouched and passes, and insertManifestBullet still gives DEFAULT_LOAD and ON_DEMAND their default decorations.
  • INV-12, a permissive parser: malformed, non-list and duplicate VENDORS never throw (vendors.test.ts).

adf-migrate-register.test.ts had byte-equality assertions on the manifest after migrate or bootstrap. They now compare with the VENDORS block removed, which is the exception INV-1 allows. The missing-manifest case now expects the extra vendor modes cannot be recorded warning.

LOC: adf.ts is at 1026 of 1041 and adf-migrate.ts at 750 of 792. No ceilings were raised.

Implemented via constellation-loop against a locked blueprint.

🤖 Generated with Claude Code

@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.

CHANGES_REQUESTED

Adversarial review of #350 (#318 PR 1 of 6). I built origin/auto/feature/issue-318-vendor-record and origin/main side by side and ran the same command sequences in temp repos on both builds. I also ran each consumer against the same repo with and without the VENDORS block. Most of the PR holds up. Two consumers change behaviour because of the VENDORS block, which INV-1 does not allow, and one case-insensitive filesystem path writes a contradictory record.

Required changes

  1. charter score changes because of VENDORS (INV-1 lists score). packages/cli/src/commands/score.ts:415-422.

    • Cause. The grounding check runs extractPathCandidates over the whole text of manifest.adf. Each - CLAUDE.md: pointer item becomes a path reference that resolves relative to .ai/ (for example .ai/CLAUDE.md).
    • Plain bootstrap repo. The summary changes from 37/47 referenced paths resolve to 41/51.
    • Repo where a vendor basename is not unique. I used adf init --emit-pointers plus packages/a/CLAUDE.md and packages/a/AGENTS.md, which is any monorepo with per-package agent files. The score total drops from 61 to 60, grounding drops from 9 to 8, and recommendations gains Fix or remove 4 broken path reference(s): ..., .ai/CLAUDE.md, .ai/AGENTS.md. Score is telling users to delete the record.
    • Recorded but absent file. The same thing happens to a file that is recorded but not on disk, for example after vendor set GEMINI.md compiled ahead of the file, which the contract explicitly endorses.
    • Fix. Leave the VENDORS section out of the grounding scan for the manifest. Add score to the "consumers ignore the record (INV-1)" suite (adf-vendor.test.ts:694), which today covers compile, tidy and doctor only.
  2. Any writer-created VENDORS block makes adf fmt --check fail. packages/adf/src/formatter.ts:22, together with the parser dropping U+FE0F.

    • Cause. The writer emits 🏷️ (U+1F3F7 U+FE0F). parseAdf stores only U+1F3F7, and formatAdf emits section.decoration. So the canonical form is 🏷 VENDORS:, which differs from the bytes the writer wrote.
    • Repro. Take a manifest where fmt --check prints [ok] ... is canonical. Run vendor set CLAUDE.md pointer, or any implicit writer. fmt --check then prints [warn] .ai/manifest.adf is not in canonical format and exits 1. The VENDORS block is in a canonical position (last, after DEFAULT_LOAD).
    • Second effect. fmt --write then rewrites the header to the text-presentation 🏷.
    • Fix. Keep the contract's locked header. Have the formatter emit STANDARD_DECORATIONS[key] when the parsed decoration equals it minus VS16, or have the parser keep the FE0F.
    • Test. A canonical manifest plus recordVendorModes should satisfy formatAdf(parseAdf(text)) === text.
  3. Case-insensitive filesystems: one physical file gets two contradictory records. packages/cli/src/commands/adf-vendor.ts:570-571 (vendorSet), :251 (readVendorFile), :261 (vendorFilesOnDisk).

    • Repro (Windows). Start with only a legacy agents.md, then:
      • vendor init records AGENTS.md: unmanaged. The inode dedupe works.
      • vendor set agents.md pointer prints agents.md does not exist yet (false), and appends agents.md: pointer.
      • vendor status now shows AGENTS.md unmanaged (recorded) and agents.md pointer (recorded; file absent) for the same file.
      • adf migrate --source agents.md goes through recordWrittenVendorModes and splits the record the same way.
    • Fix. When <file> has the same file identity as another vendor name on disk, refuse it or map it to the spelling the record already uses, and name that spelling in the message. Check existence in vendor set with the real path, not the deduped set, so fileAbsentSet is only printed when it is true. Scope test 5 owns this dedupe, so it belongs in PR1.

Verified, no change needed

  • P1, no other hidden consumer changes. I ran bootstrap, adf sync --write, adf compile --target all --write (text and json), adf sync --check and adf compile --check on both builds. Outputs are identical apart from the VENDORS edit and the record kept warning lines.
    • adf sync hashes only SYNC sources, and bootstrap's lock covers only core and state, so there is no stale lock.
    • adf evidence, adf bundle --format json, doctor --format json and context-refresh are identical with and without VENDORS, on both the main and PR builds.
    • Compile output never contains VENDORS. It renders only DEFAULT_LOAD modules, MANIFEST_PLUMBING_KEYS also covers it, and vendors.test.ts checks every target.
  • P2, writer edge cases (run directly against dist):
    • Handled and byte-exact: LF, CRLF, no trailing newline, BOM, empty file, an empty VENDORS header at EOF and mid-file, duplicate VENDORS sections (inserts into the last), duplicate sections where the last one is empty, and a header without decoration.
    • Upsert: with odd spacing, CRLF, or duplicate entries, upsert changes exactly one line (the winning last entry).
    • Refused with the right skip reason, nothing written: a lone CR (reparse-guard), a malformed entry for the file (entry-malformed), a non-list or map body (section-not-list), and a multi-line item or comment line (section-not-list).
  • INV-11. adf-manifest-register.test.ts is untouched and passes. The new default decoration = SECTION_DECORATION[key] produces exactly the old header for DEFAULT_LOAD and ON_DEMAND.
  • P3, the stripping regex is exact. It removes \n🏷️ VENDORS:\n plus the two-space - lines that follow, once, which is exactly what the writer appends at EOF.
  • P4, contract conformance.
    • Inference matches analyzeVendorFile: banner, then POINTER_MARKERS, else unmanaged. A banner on a pointer-only name gives unmanaged.
    • ALLOWED_MODES is checked before any manifest state.
    • Exit codes, checked by hand:
      • status exits 0, including with the manifest missing.
      • set copilot-instructions.md compiled exits 1.
      • set with an unknown file, bad usage or a missing manifest exits 2.
      • init exits 2 with the manifest missing, and a second init is a no-op.
    • --dry-run and --ai-dir work. status has no write path.
    • The extra messages are acceptable additions, not drift. The contract templates would be false in those cases:
      • manifestUnparseableStatus and sectionNotListStatus: a read-only command cannot say "were not recorded".
      • entryProblemNoFile: an unknown file has no {file} to fall back.
      • entryDuplicate: last-wins, so "falls back to inferred" would be wrong.
      • initDisagrees: fine.
    • Init reporting file-absent only for recorded-but-absent files matches the contract.
  • P5, CP-7. Bootstrap JSON is identical to main except that the phase-3 step's warnings array gains the record kept line, with nothing on stderr. compile and migrate send warnings to stderr in JSON mode, and stdout stays valid JSON. Bootstrap --format json printing two JSON documents is pre-existing on main.
  • P7, path separators. Entries come only from the VENDOR_FILES constants, and recordWrittenVendorModes normalizes to / and filters through isVendorFile. No backslash can be written. Backslashes appear only in the displayed manifestPath.
  • P8, LOC ceilings. adf_commands_loc is 1026 of 1041 and adf_migrate_loc is 750 of 792. Evidence passes and no ceilings were raised.
  • Tests. The full suite on the PR has 5 failures, and the same 5 fail on main on this Windows host. They are bootstrap #307, context-refresh, serve-context and two precommit-hook tests, so they are environmental and pre-existing. adf-vendor, adf-migrate-register, adf-manifest-register and vendors all pass (122 tests).

Non-blocking

  • P3, test strength. The strip deletes whatever two-space - lines follow the VENDORS header. In the INV-5 and "already registered" tests, run 1 creates VENDORS as the last section before run 2 registers. A #348 regression that misroutes a module bullet into the trailing section would therefore be stripped away and pass. Assert the VENDORS block's exact content instead, for example toBe(MANIFEST + '\n🏷️ VENDORS:\n - CLAUDE.md: pointer\n').
  • P6, noise. After bootstrap, every adf compile --target all --write warns four lines (CLAUDE.md is recorded as pointer but adf compile --write wrote it as compiled; record kept. To change it: charter adf vendor set CLAUDE.md compiled, and the same for AGENTS.md, .cursorrules and GEMINI.md). It repeats on every run until vendor set. The wording gives the exact per-file fix, and PR2 removes the cause. If it stays for a release, consider collapsing it into one line that lists the files.
  • Text-mode warning channel. compile sends warnings to stderr, but init --emit-pointers and migrate use console.log (stdout). INV-9 says stderr in text mode. Using each command's existing warn convention is defensible, but say so in the PR body.
  • Duplicate VENDORS sections whose last one is empty. @stackbilt/adf parseManifest().vendors returns the earlier section's entries, while the CLI's readVendorRecord treats the record as empty. Align them before PR2 consumes the library field.
  • Comment lines. A comment line inside VENDORS makes the parser treat the section as text, so the is not a list message is misleading there.
  • Placement. Writers append VENDORS at EOF regardless of canonical order. This follows the #348 precedent, but it can also trip fmt --check, for example when the manifest ends with a key that sorts after VENDORS.
  • Headroom. adf.ts has 15 lines left under its ceiling for five more PRs.
  • Cosmetic. In bootstrap's VENDORS block, CLAUDE.md comes last (the migrate phase records it).

@stackbilt-admin

Copy link
Copy Markdown
Member Author

Round 1 review addressed in 5f58ef3:

  • score: withoutVendorsSection takes VENDORS out of the manifest text before the grounding scan. It finds sections with the parser's header grammar and re-parses the result to check it. score is now in the INV-1 suite, including a non-unique packages/a/CLAUDE.md and a recorded-but-absent file.
  • fmt: VENDORS now uses bare U+1F3F7 in both STANDARD_DECORATIONS and the writer. The writer's output stays formatAdf canonical. This is tested for each writer path, and adf fmt --check passes after vendor set. Hand-written headers with U+FE0F still parse.
  • File identity: vendor names are grouped by dev/ino. Every writer, including set, init and the implicit writers, records one physical file under the spelling already recorded for it. set reports the mapping and checks existence against the real path. status shows one row per file and warns when both spellings are recorded. Tested with a hard link, which also works on case-sensitive filesystems.
  • Non-blocking items:
    • The migrate-register assertions now check the exact VENDORS block.
    • The last VENDORS section wins in parseManifest, and an empty one means no entries.
    • The 'not a list' message now explains why the section is not read as a list. ADF has no comment lines.

🤖 Generated with Claude Code

@stackbilt-admin
stackbilt-admin merged commit 555711a into main Oct 16, 2026
5 checks passed
@stackbilt-admin
stackbilt-admin deleted the auto/feature/issue-318-vendor-record branch October 16, 2026 01:50
stackbilt-admin added a commit that referenced this pull request Oct 16, 2026
…352)

adf compile --check reported every deliberate thin pointer as stale forever, and the remedy it printed (compile --write) silently turned the pointer into compiled output; tidy guarded compiled files only by the presence of the banner (#318). Both now read the vendor mode record from #350, falling back to the same marker inference when a file has no entry. --check gains pointer-ok, pointer-bloated, mode-drift and skipped-unmanaged and never suggests --write for a pointer; tidy only ever processes pointers and walks each physical file once. compile --write converts a pointer or unmanaged file only under the new --mode compiled, recording the switch first and reverting it if the write fails, and remedies that could discard content now list the content-preserving path first. Also fixes NTFS file identity (bigint inodes) so two vendor files can no longer collide.

BREAKING CHANGE: adf compile --write no longer converts pointer files without --mode compiled. Use `charter adf compile --target all --write --mode compiled`, or `charter adf vendor set <file> compiled`.

Closes #318

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.

2 participants