Skip to content

feat(cli): route adf context --files modules from path tokens - #452

Merged
stackbilt-admin merged 4 commits into
mainfrom
feat/issue-442-path-token-routing
Nov 28, 2026
Merged

stackbilt-admin merged 4 commits into
mainfrom
feat/issue-442-path-token-routing

Conversation

@stackbilt-admin

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

Copy link
Copy Markdown
Member

Summary

  • New module packages/cli/src/commands/adf-path-tokens.ts holds all --files keyword derivation:
    • filePathToTokens() splits each path into its own name tokens (kebab, snake, dot, camelCase, / and \), drops a small stop-list of generic segments (packages, src, lib, dist, build, index, main, test dirs, extensions, node_modules, pure numbers), and returns lowercase tokens.
    • filePathToKeywords() (the existing extension and directory signals) moved here unchanged and is re-exported from adf-context.ts for existing importers.
    • filePathRoutingKeywords() combines both. It makes each path repo-relative once and runs both signals on that relative path.
  • Repo-relative paths (relativizeFilePath):
    • The root is git rev-parse --show-toplevel run from the --ai-dir's parent, or that parent itself outside git. It is memoized per .ai/ location, so git runs at most once per process (including a long-running serve).
    • It handles absolute POSIX and Windows paths (drive letters, either separator, case-insensitive), ./ and ../.
    • Symlinks and junctions are resolved with fs.realpathSync on both sides. A path that doesn't exist yet resolves through its deepest existing parent.
    • A relative path that is missing under the cwd but exists under the repo root is read as repo-relative. So --files packages/adf/src/manifest.ts run from packages/cli gives adf, manifest, not cli, adf, manifest.
    • The directories above the checkout (Users, home, or api/, test/, session/ folders) never become keywords. A path outside the repo adds no path tokens and no directory signals; only its extension signals count.
  • The non-bundle --format json output gains an additive triggerMatches key, the same buildTriggerReport shape --bundle already emits, so agents can see which token matched which trigger. Existing keys (keywords, resolvedModules, and ceilings from feat(cli): report live ceiling headroom in adf context --files #454) and exit codes are unchanged.
  • origin/main (fix(cli): MCP/CLI task tokenizer parity and adf context --bundle paths #453 and feat(cli): report live ceiling headroom in adf context --files #454) is merged in. --bundle now works together with path routing: adf context --files packages/adf/src/manifest.ts --bundle --format json exits 0 and resolves core.adf, state.adf, adf-dev.adf.

Routing (fixture that mirrors this repo's manifest, typed-data-access.adf included)

File Routed module
packages/adf/src/manifest.ts adf-dev.adf (token adf matched trigger ADF)
packages/cli/src/commands/adf-migrate.ts adf-dev.adf
packages/cli/src/commands/validate.ts governance.adf
packages/blast/src/index.ts analysis.adf
packages/cli/src/commands/tenant-quota.ts typed-data-access.adf
serve.ts, context-refresh.ts, ci.yml defaults only

Tests

  • adf-path-tokens.test.ts: the tokenizer, the routing table, the JSON trigger report, and these guards:
    • generic-word triggers never match;
    • checkout-root triggers never match from absolute paths;
    • a repo under api/test/session/ gives docs, readme and defaults only for <abs>/docs/readme.txt, the same as the repo-relative spelling;
    • an outside path keeps only its extension signals.
  • The same file also covers:
    • junction/symlink relativizing, both directions plus a file that doesn't exist yet (skipped if the OS refuses to create the link; it ran on Windows);
    • running from a packages/cli cwd;
    • relativizeFilePath for POSIX and Windows paths.
  • adf-path-root.test.ts: git runs once across repeated lookups and repeated adf context runs with several --files.
  • adf-ceilings.test.ts (from main): the key-order assertion now expects triggerMatches between resolvedModules and ceilings.
  • Targeted files (adf-path-tokens, adf-path-root, adf-context, adf-ceilings, context-parity): 60/60 pass. tsc --build and tsc --noEmit are clean.
  • Full suite on Windows: 2138 passed, 2 skipped, 4 failed. All 4 are known Windows-only failures on main: 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 the github-commit-range timeout.

Not in this PR

MCP (serve.ts) does not use path tokens yet; #455 covers that. #455 needs a rebase onto this so that it calls filePathRoutingKeywords with resolvePathTokenRoot, which keeps the CLI and MCP in agreement.

Closes #442
Part of #437

🤖 Generated with Claude Code

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]>
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]>
@stackbilt-admin

Copy link
Copy Markdown
Member Author

Review follow-up (eb3c0a1):

  • [major] path-root leakage: each --files path is now made relative to the repo root before tokenizing (git rev-parse --show-toplevel from the --ai-dir's parent, falling back to that parent). Handles Windows drive letters (case-insensitive), backslashes, ./ and ../; relative paths resolve against cwd. A path outside the repo adds no path tokens. New relativizeFilePath / resolvePathTokenRoot live in adf-path-tokens.ts; adf-context.ts changes by one line.
  • Tests: absolute POSIX and Windows paths (C:\Users\x\repo\packages\adf\src\manifest.ts), .//../, a mixed file set, and an end-to-end guard where the repo sits under home/users/projects/documents/user/ (inside the OS temp dir) with triggers user, users, home, projects, documents, appdata, local, temp, .... Nothing matches, and the repo-relative part still routes. 35/35 pass across adf-path-tokens and adf-context; tsc --build and --noEmit are clean.
  • Stop-list: added home, documents, desktop, repo, repos as a backstop. I left out users, projects, workspace, code, commands, cli on purpose, because inside a repo they are real domain signals (src/users/). Relativizing is the actual fix.
  • Docs: docs/cli-reference.md adf context now covers path tokens, relativizing, the stop-list and the additive triggerMatches key. CHANGELOG is untouched.
  • Not changed here: the MCP file-seed gap is feat(cli): preflight answer, first slice (#447) #455. --bundle still exits 2 on this branch, the same as main (fixed by fix(cli): MCP/CLI task tokenizer parity and adf context --bundle paths #453), so --bundle with token routing is still not exercised end to end. The older filePathToKeywords directory regexes still read the full dirname, which is pre-existing behaviour I left as is.

Committed with a plain Conventional Commit, since smart-commit.sh can't set a message or trailers.

kovermier and others added 2 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]>
@stackbilt-admin

Copy link
Copy Markdown
Member Author

Round 3 changes (merge 2648897, fix 55b605f):

  • Merged origin/main (fix(cli): MCP/CLI task tokenizer parity and adf context --bundle paths #453, feat(cli): report live ceiling headroom in adf context --files #454). --bundle with path routing now exits 0 and resolves adf-dev.adf for packages/adf/src/manifest.ts.
  • Directory signals now read the repo-relative path as well. A repo under api/test/session/ gives docs, readme and defaults only for an absolute docs/readme.txt; there is a guard test for this. Outside paths keep only their extension signals. The docs now match.
  • Symlinks and junctions are resolved with realpath, with a fallback for paths that don't exist yet. The junction test ran on Windows.
  • From a subdirectory cwd, a path that exists only under the repo root is read as repo-relative. Test added for packages/cli.
  • The test manifest mirror now includes typed-data-access.adf with its real triggers, plus a routing row for it.
  • The git toplevel is memoized per .ai location; a test confirms one spawn across repeated runs.
  • PR description updated. Targeted tests 60/60; the full suite has only the 4 known Windows failures.

stackbilt-admin pushed a commit that referenced this pull request Nov 28, 2026
…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]>
@stackbilt-admin
stackbilt-admin merged commit d9a933c into main Nov 28, 2026
7 checks passed
@stackbilt-admin
stackbilt-admin deleted the feat/issue-442-path-token-routing branch November 28, 2026 03:01
stackbilt-admin pushed a commit that referenced this pull request Nov 28, 2026
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
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.

adf context --files: route modules from the file's own path tokens

2 participants