Skip to content

feat(cli): preflight answer, first slice (#447) - #455

Merged
stackbilt-admin merged 16 commits into
mainfrom
feat/issue-447-preflight-slice
Nov 28, 2026
Merged

stackbilt-admin merged 16 commits into
mainfrom
feat/issue-447-preflight-slice

Conversation

@stackbilt-admin

@stackbilt-admin stackbilt-admin commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Refs #447
Part of #437

Stacks on (merge that first)

#453 and #454 are now squash-merged on main. This branch has main in it, through #452's round-3 merge (2648897). The only prerequisite left is:

Merge this after #452. The diff against main includes #452's commits until #452 lands.

Merge 2a84423 brought in #452 (and main with it). The conflicts were where the same #453/#454 changes came in as different commits. They were resolved toward this branch's code, which already contains #454's ceilings work and builds on it:

What this slice adds

The new module is packages/cli/src/commands/adf-preflight.ts, used by both the CLI and MCP.

Round 3: review fixes (c112971, tests and docs in 83f4fd3)

  1. One path resolver for rules and ceilings (major):
    • computeFileCeilings now matches requested files to METRICS sources through relativizeFilePath. That is feat(cli): route adf context --files modules from path tokens #452's resolver, the same one path tokens and rule locations use.
    • The answer no longer depends on cwd. A repo-relative path passed from a subdirectory, or over MCP from any cwd, still finds its ceiling.
    • Tested on this repo with adf-migrate.ts:
      • From packages/cli with the repo-relative, cwd-relative and absolute paths, the rules, ceilings and full text output match the root run.
      • MCP resolveProjectContext with an absolute aiDir gives the same rules, ceilings and text from the repo root, from packages/ and from a temp dir. The reviewer's probe case, which gave ceilings: [] before this fix, is covered here.
  2. locate() and column-0 list items:
    • A section now ends at the next section header, read the way the parser's SECTION_HEADER_RE reads one. Before, it ended at the first unindented line.
    • So - rule written at column 0 gets its own line, not the header's.
    • Tested by a unit test and end to end through --format json.
  3. MCP with task and files, nothing binds:
    • The response is now [task bundle, nothing-binds line, JSON].
    • With files only (or a blank task), it is still the short [line, JSON].
    • The tool description and docs/cli-reference.md say so. Tested.
  4. Memoized git root reused:
  5. Multi-file Binds attribution (done, text only):
    • With several files, each Binds line ends with for <file> when only some of the files trigger that module.
    • It ends with for the task keywords when the module came only from --keywords or the MCP task.
    • It has no suffix when every file triggers the module.
    • The JSON rules[] shape is unchanged. A per-rule files key would be additive, and is left as a follow-up.

Earlier rounds, still in place: absolute and Windows paths, the parse guard (unreadable[], exit code 0), exact section-header matching, the import-cycle fix, repo-root display paths, the short MCP answer, and --bundle text on stderr.

Real output from this run (rebuilt dist, Windows, PowerShell)

From the repo root:

> node packages/cli/dist/bin.js adf context --files "packages/cli/src/commands/adf-migrate.ts,.github/workflows/ci.yml"
Binds:     adf-dev.adf → "ADF package has zero runtime dependencies"  (.ai/adf-dev.adf:18) for packages/cli/src/commands/adf-migrate.ts
           adf-dev.adf → "Parser is tolerant (handles messy LLM output); formatter is strict (canonical emission)"  (.ai/adf-dev.adf:19) for packages/cli/src/commands/adf-migrate.ts
           adf-dev.adf → "Patcher is immutable (deep clone via JSON.parse/stringify; original never mutated)"  (.ai/adf-dev.adf:20) for packages/cli/src/commands/adf-migrate.ts
           adf-dev.adf → "All new content types must support: parse, format, roundtrip idempotency, merge, token estimation"  (.ai/adf-dev.adf:21) for packages/cli/src/commands/adf-migrate.ts
           adf-dev.adf → "Metric entries use lowercase_key; map entries use UPPERCASE_KEY — this is the disambiguation"  (.ai/adf-dev.adf:22) for packages/cli/src/commands/adf-migrate.ts
Headroom:  adf_migrate_loc 792/792 → 0 lines left [warn] (core.adf) for packages/cli/src/commands/adf-migrate.ts
Contract:  unknown
Run first: unknown
Fresh:     unknown

  Keywords: cli, commands, adf, migrate, github, workflows, ci
  Resolved modules:
    core.adf (DEFAULT)
    state.adf (DEFAULT)
    adf-dev.adf (ON_DEMAND)

From packages/cli, with a cwd-relative path and an absolute Windows path, the output is identical, line for line:

> cd packages\cli
> node dist/bin.js adf context --ai-dir ../../.ai --files "src/commands/adf-migrate.ts,<repo>\.github\workflows\ci.yml"
Binds:     adf-dev.adf → "ADF package has zero runtime dependencies"  (.ai/adf-dev.adf:18) for packages/cli/src/commands/adf-migrate.ts
           ... (same 4 further rule lines as above)
Headroom:  adf_migrate_loc 792/792 → 0 lines left [warn] (core.adf) for packages/cli/src/commands/adf-migrate.ts
Contract:  unknown
Run first: unknown
Fresh:     unknown

  Keywords: cli, commands, adf, migrate, github, workflows, ci
  ...

From packages/cli with the repo-relative path, the case the major finding was about. Headroom is present:

> node dist/bin.js adf context --ai-dir ../../.ai --files packages/cli/src/commands/adf-migrate.ts
Binds:     adf-dev.adf → "ADF package has zero runtime dependencies"  (.ai/adf-dev.adf:18)
           ... (4 more adf-dev.adf rules, lines 19-22)
Headroom:  adf_migrate_loc 792/792 → 0 lines left [warn] (core.adf)
Contract:  unknown
Run first: unknown
Fresh:     unknown

> node dist/bin.js adf context --ai-dir ../../.ai --format json --files packages/cli/src/commands/adf-migrate.ts
  ... "ceilings": [ { "file": "packages/cli/src/commands/adf-migrate.ts", "metric": "adf_migrate_loc", ..., "headroom": 0, ... } ],
  ... "binds": true

(Git Bash rewrites a C:/... argument into C;C:/Program Files/Git/..., so I ran the absolute-path examples in PowerShell.)

Tests

  • New adf-preflight-cwd.test.ts (10 tests):
    • this repo from the root vs packages/cli, with repo-relative, cwd-relative and absolute paths
    • MCP from three different cwds
    • locate() with column-0 items, unit and end to end
    • MCP task+files when nothing binds, and files only / blank task
    • multi-file attribution: a subset of files, the task keywords, every file, and a single file
  • adf-preflight.test.ts (9) and adf-preflight-guards.test.ts (14): unchanged and passing.
  • Focused set: 8 files, 92 tests passed. The set was preflight, preflight-guards, preflight-cwd, ceilings, adf-context, path-tokens, path-root and context-parity. The 10th preflight-cwd test was added after that run, and that file was re-run (10/10).
  • Full suite on Windows (Git Bash): 2170 passed, 5 failed, 2 skipped. All 5 failures are the known Windows-only ones: bootstrap bootstrap: phases 6/7 collect warnings without printing them; absoluteAiDirArg misses Windows paths on POSIX #307 POSIX case, context-refresh and serve-context path separators, and two github-commit-range timeouts.
  • tsc --build and tsc --noEmit are clean. The pre-commit hook passed (tsc and adf evidence). No ceilings were changed or recalibrated, and adf_migrate_loc is untouched at 792/792.
  • I used normal Conventional Commits, because smart-commit.sh can't set a message or trailers.

Not in this slice / follow-ups

🤖 Generated with Claude Code

kovermier and others added 7 commits November 27, 2026 19:08
Split each --files path into its own name tokens (kebab, snake, dot,
camelCase), drop generic layout segments (packages, src, lib, dist,
index, test dirs, extensions, node_modules), and feed them to the
existing trigger matcher alongside the extension and directory signals.
`adf context --files packages/adf/src/manifest.ts` now resolves
adf-dev.adf. The non-bundle JSON output gains an additive
triggerMatches key (same shape as --bundle) so agents can see which
token matched which trigger.

Closes #442

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

MCP getProjectContext split the task on whitespace only, so "ADF." failed
to match the ADF trigger and on-demand modules were silently dropped. It
now resolves through a shared resolveProjectContext helper that uses the
CLI's tokenizeTask. getProjectContext is the only MCP tool taking a task.

adf context --bundle joined aiDir onto paths bundleModules had already
resolved, exiting 2 with "Module not found: core.adf". The reader now
reads the path as given.

Closes #438
Closes #439
Part of #437

Co-Authored-By: Claude Opus 5.5 <[email protected]>
For each --files entry that maps to a manifest METRICS source, adf context
now adds an additive `ceilings` array ({ file, metric, value, ceiling,
headroom, status, module }) to its JSON output, plus a Ceilings block in
text mode. Measurement moves into a shared adf-ceilings module that adf
evidence --auto-measure now also uses, so the value an agent sees before
editing is exactly what the gate enforces (trailing newline included).

Closes #443
Part of #437

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… into feat/issue-447-preflight-slice

# Conflicts:
#	packages/cli/src/commands/adf-context.ts
Text mode for `charter adf context --files <path>` now leads with a
preflight block: Binds (load-bearing rules of resolved on-demand modules,
with .ai/<module>:<line> locations), Headroom (live ceilings from #443),
and Contract/Run first/Fresh as `unknown` until #445/#444/#440 land.
A file nothing binds prints one short line.

JSON gains an additive `rules[]` key next to `ceilings[]` (only with
--files); unbuilt fields are not emitted. MCP getProjectContext accepts
an optional `files` array and appends the same preflight text and
rules/ceilings JSON; without `files` its response is unchanged.

New logic lives in packages/cli/src/commands/adf-preflight.ts.

Refs #447
Part of #437

Co-Authored-By: Claude Opus 5.5 <[email protected]>
filePathToTokens tokenized every segment of an absolute path, so the
directories a checkout sits in (C:\Users\..., /home/...) became routing
keywords. Paths are now made relative to the repo root (git toplevel from
the --ai-dir's parent, else that parent) before tokenizing, handling
Windows drive letters, backslashes, ./ and ../. A path outside the repo
contributes no path tokens.

- Add a small checkout-root backstop to the stop-list (home, documents,
  desktop, repo, repos); domain-ish words like users/projects stay routable.
- Tests: absolute POSIX and Windows paths, ./ and ../, mixed file sets,
  and a guard manifest with user/users/home/projects/documents triggers
  for a repo nested under those directories.
- docs/cli-reference.md: document path tokens, the stop-list and the
  triggerMatches JSON key for adf context.

Refs #442

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kovermier and others added 3 commits November 27, 2026 20:00
…g' into feat/issue-447-preflight-slice

Brings in eb3c0a1 (relativize --files paths before deriving path tokens).
Conflict in adf-context.ts imports resolved by keeping both sides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Parse guard: a resolved on-demand module the ADF parser rejects is
  reported in a new additive `unreadable[]` ({ module, file, reason }) and
  as "(unreadable: <reason>)" in Binds; the exit code stays 0.
- locate() matches the real section header (escaped key, optional emoji
  and [load-bearing]/[advisory], then ':'), and the n-th occurrence for
  repeated sections, so TASK text that mentions the key no longer wins.
- Rule and ceiling paths are shown relative to the repo root, not cwd.
  Ceilings measure METRICS paths from the .ai dir's parent, so
  --ai-dir ../.ai from a subdirectory gives the same answer.
- CLI and MCP share fileRoutingKeywords(), which feeds both the
  extension/directory signals and path tokens repo-relative paths, so an
  absolute C:/Users/... path routes like the relative one.
- filePathToKeywords moves to the leaf module adf-path-tokens.ts
  (re-exported from adf-context.ts) to break the
  index -> serve -> project-context -> adf-context -> index cycle.
- MCP getProjectContext with files: when nothing binds, return only the
  short answer and { rules, ceilings, unreadable, binds } JSON, not the
  default bundle. Content building moves to projectContextContent().
- Additive `binds` boolean in --files JSON output.
- --bundle text prints the preflight block on stderr (stdout stays ADF).
- Multi-file Headroom lines name the file they measure; the text answer
  labels files repo-relative.

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

adf-preflight-guards.test.ts: absolute, forward-slash, lower-case drive
and backslash --files paths (fixture under Users/... and this repo's
ci.yml / adf-migrate.ts), an unparseable module (exit 0, unreadable),
header-mismatch line location, subdirectory display paths, --bundle text
stderr block, multi-file Headroom, the filePathToKeywords re-export, and
the serve.ts getProjectContext content-array shapes via a stub server.

docs/cli-reference.md: preflight text block, JSON keys, MCP files arg.

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

Copy link
Copy Markdown
Member Author

Review response, pushed as e1a41c5 (fixes) and 07b4cfa (tests and docs), after merging eb3c0a1 from #452. No force-push.

  • [major] Absolute paths and false Binds: fixed by the merged feat(cli): route adf context --files modules from path tokens #452 relativizing, plus a shared fileRoutingKeywords() so CLI and MCP route the same. Tests cover absolute, forward-slash, lower-case-drive and backslash paths. ci.yml given absolutely still says "Nothing binds".
  • [major] Exit-code regression: an unparseable module is now reported in unreadable[] (module, file, reason) and as (unreadable: …) in Binds. Exit code stays 0. Tested.
  • [minor] locate(): the key is escaped and matched against the exact header form, and repeated sections are counted. Tested with TASK text that mentions the key.
  • [minor] MCP "nothing binds": returns only the one-line answer and {rules, ceilings, unreadable, binds}, with no default bundle. A test drives the real serve.ts handler through a stub server and covers all three content-array shapes. CLI JSON keeps triggerMatches, since it's an existing key, and adds binds.
  • [minor] --bundle text: the preflight block now goes to stderr, so stdout stays pure ADF.
  • [minor] Missing tests: added adf-preflight-guards.test.ts (14 tests).
  • [nit] displayPath: rule and ceiling paths are relative to the repo root. Ceilings measure from the .ai parent, so running from a subdirectory with --ai-dir ../.ai gives the same answer. The adf evidence gate is unchanged.
  • [nit] Multi-file output: Headroom names each file. Per-file attribution of rules is recorded as a follow-up, because it needs per-file resolution.
  • [nit] Import cycle: filePathToKeywords moved to adf-path-tokens.ts and is re-exported from adf-context.ts.

Full suite: 2144 passed and 9 failed. Six are the known Windows-only failures. Three are 5 s timeouts in bootstrap-reset-cli #371, which this PR doesn't touch and which I didn't check against main. tsc is clean and no ceilings were changed. The PR is still a draft, and the description is updated with fresh output.

kovermier and others added 5 commits November 27, 2026 20:27
Brings in #453 (task tokenizer parity, --bundle path fix) and #454
(ceiling headroom). Resolves the adf-context.ts conflict by keeping both
the path-token import and triggerMatches (this branch) and the ceilings
field (main). The adf-ceilings key-order test now expects triggerMatches
between resolvedModules and ceilings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Directory signals (api, test, session, ...) now read the repo-relative
path, like path tokens do, so folders above the checkout never route a
module. A path outside the repo keeps only its extension signals.

- Resolve symlinks and junctions on both sides when relativizing, with
  a fallback for paths that do not exist yet.
- A relative path that is missing under the cwd but exists under the
  repo root is read as repo-relative (running from packages/cli).
- Memoize the git toplevel lookup per .ai location.
- filePathToKeywords moves to adf-path-tokens.ts (re-exported from
  adf-context.ts) next to a shared filePathRoutingKeywords helper.
- Test manifest mirror now includes typed-data-access.adf.

Refs #442

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o feat/issue-447-preflight-slice

Brings in #453 and #454 (squash-merged on main) through #452's round-3
merge, plus #452's memoized resolvePathTokenRoot and filePathRoutingKeywords.
Conflicts resolved toward this branch's preflight code (which already
contains the #443/#454 ceilings work); fileRoutingKeywords is kept as a thin
wrapper over #452's filePathRoutingKeywords.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round-2 review fixes for PR #455:
- computeFileCeilings matches requested files through relativizeFilePath,
  the same resolver path tokens and rule locations use, so Headroom is the
  same from the repo root, a subdirectory, and MCP with any cwd.
- locate() ends a section at the next section header, so column-0 list
  items (`- rule`) get their own line instead of the header's.
- MCP getProjectContext keeps the task's bundle when task and files are
  given and nothing binds the files.
- The CLI and MCP look the memoized git root up once per call and pass it
  to routing, rules, ceilings and labels (new preflightAnswer helper).
- Multi-file Binds names the files that trigger each module, or "the task
  keywords" when none does; no suffix when every file triggers it.

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

- This repo: adf-migrate.ts from the root and from packages/cli
  (repo-relative, cwd-relative and absolute) gives the same rules,
  ceilings and text; MCP with an absolute aiDir gives the same answer
  from the repo root, packages/ and a temp dir.
- locate() with column-0 list items, end to end and unit.
- MCP task+files with nothing binding keeps the bundle; files-only and a
  blank task keep the short answer.
- Multi-file Binds attribution.
- docs/cli-reference.md: attribution, ceiling matching, MCP task+files.

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

Copy link
Copy Markdown
Member Author

Round 3 is pushed as three new commits: merge 2a84423 (#452, which includes main), fix c112971, and tests/docs 83f4fd3. Nothing was force-pushed.

  • Major (fixed): ceilings now match files through feat(cli): route adf context --files modules from path tokens #452's relativizeFilePath, so Binds and Headroom match from the root, from packages/cli (repo-relative, cwd-relative and absolute paths) and over MCP from any cwd. Tests cover all of these.
  • locate() now handles column-0 - rule items.
  • MCP with task and files where nothing binds now returns the task's bundle, then the nothing-binds line.
  • The memoized git root is looked up once and passed through.
  • Multi-file Binds now names its files in the text output. JSON rules[].files is left as a follow-up.

Full suite: the 5 known Windows-only failures, nothing else. The description has fresh output from the root and from packages/cli. The PR is still a draft.

@stackbilt-admin
stackbilt-admin marked this pull request as ready for review November 28, 2026 03:04
@stackbilt-admin
stackbilt-admin merged commit 99c2397 into main Nov 28, 2026
7 checks passed
@stackbilt-admin
stackbilt-admin deleted the feat/issue-447-preflight-slice branch November 28, 2026 03:04
stackbilt-admin pushed a commit that referenced this pull request Nov 28, 2026
Review fixes for #458:
- #454 entry: ceilings print as the preflight Headroom line, not a
  Ceilings: block; drop the stale "--keywords-only output unchanged".
- #455 entry: parse errors are tolerated only without --bundle; the
  preflight block goes to stderr with --bundle; MCP returns the full
  preflight fields.
- Changed: #452 signals now read the repo-relative path; nothing-binds
  shortens CLI text and the MCP response.
- Breaking: scope "MCP argument shapes unchanged" to the Zod migration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stackbilt-admin pushed a commit that referenced this pull request Nov 28, 2026
Second review round for #458:
- Changed: --files text output changes on every run (preflight block
  first); the nothing-binds one-liner applies without --bundle only.
- Move the MCP files response shape into the #455 Added entry; calls
  without files are unchanged.
- Parse errors under --bundle/MCP produce no preflight fields; rule
  locations are repo-root relative; note the non-git root fallback and
  checkout-root words.
- cli-reference: scope the unreadable and one-line claims to non-bundle.
- Zod 4 migration guide: scope "argument shapes remain stable" to the
  migration and point at the new optional files argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stackbilt-admin pushed a commit that referenced this pull request Nov 28, 2026
Round-3 review notes for #458:
- #452 Changed: a relative path from a subdirectory now gains that
  subdirectory's signals, not only loses checkout-root ones.
- #455 Added: over MCP, unreadable is always empty because a parse
  error fails the call; drop it from "same as the CLI".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stackbilt-admin added a commit that referenced this pull request Nov 28, 2026
* docs(changelog): add 3.0.0 entries for #452 and #455

Both merged after #457, so 3.0.0 would have shipped them without notes.

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

* docs(changelog): correct 3.0.0 entries for #452, #454 and #455

Review fixes for #458:
- #454 entry: ceilings print as the preflight Headroom line, not a
  Ceilings: block; drop the stale "--keywords-only output unchanged".
- #455 entry: parse errors are tolerated only without --bundle; the
  preflight block goes to stderr with --bundle; MCP returns the full
  preflight fields.
- Changed: #452 signals now read the repo-relative path; nothing-binds
  shortens CLI text and the MCP response.
- Breaking: scope "MCP argument shapes unchanged" to the Zod migration.

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

* docs: scope 3.0.0 preflight notes to --bundle and MCP behavior

Second review round for #458:
- Changed: --files text output changes on every run (preflight block
  first); the nothing-binds one-liner applies without --bundle only.
- Move the MCP files response shape into the #455 Added entry; calls
  without files are unchanged.
- Parse errors under --bundle/MCP produce no preflight fields; rule
  locations are repo-root relative; note the non-git root fallback and
  checkout-root words.
- cli-reference: scope the unreadable and one-line claims to non-bundle.
- Zod 4 migration guide: scope "argument shapes remain stable" to the
  migration and point at the new optional files argument.

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

* docs(changelog): note subdirectory signals and MCP unreadable scope

Round-3 review notes for #458:
- #452 Changed: a relative path from a subdirectory now gains that
  subdirectory's signals, not only loses checkout-root ones.
- #455 Added: over MCP, unreadable is always empty because a parse
  error fails the call; drop it from "same as the CLI".

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

---------

Co-authored-by: Kurt Overmier <[email protected]>
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