Skip to content

refactor(vis): route native commands through a table - #246

Merged
prisis merged 8 commits into
nextfrom
refactor/vis-native-routing-table
Nov 25, 2026
Merged

prisis merged 8 commits into
nextfrom
refactor/vis-native-routing-table

Conversation

@prisis

@prisis prisis commented Nov 25, 2026

Copy link
Copy Markdown
Member

Pure refactor of the native vis front-end: no route, output or exit code changes.

Routing table

main() was one ~185-line match with the !asks_for_help guard written about thirty times. The routes are now rows of (command path, help policy, entry) in route.rs, looked up by longest path. The help policy is applied once. Explicit arms remain only for shapes that are not a path: __native-info, --version/-V, complete --, run <target> (exactly two arguments) and __pm-shim.

old arm new row help
hook run / list / validate (unix) same paths skipped to the manifest
advisories bloom status, ignore, clean, implode (unix) same skipped to the manifest
cache list/size, clean/prune (unix), hash, why one row each skipped to the manifest
list, replay, task-why, affected, sbom, secrets, sort-package-json, optimize, deps, self-update, add, dlx same skipped to the manifest
sync ci-workflow, security list/keys-refresh, shim status same skipped to the manifest
install / i, info / view two rows each skipped to the manifest
exec, pm, x, remove, dedupe, link, unlink, outdated, why one row each entry sees --help

How the routes are pinned

  • First commit (test(vis): pin which entry answers each native invocation) adds tests/fixtures/native-routes.snap (about 3100 invocations: every case of routing.json, every manifest command and alias, each routed word alone and with a subcommand, positional, --help/-h, --, leading global flags, version flags) and a test that checks it against a transcription of the old match, on the old main.rs.
  • Second commit swaps in the table. routes_match_the_snapshot now checks route() against the same, untouched snapshot, so a moved route fails with a was/now line.
  • Differential run of the old and new debug binaries over the 719 non-Windows cases of routing.json (stub Node, empty PATH): exit code, stdout and stderr identical, except the six sbom cases whose output carries a timestamp and a random UUID.

Finding (not changed here): --help is not the manifest's for eight commands

exec, pm, remove, dedupe, link, unlink, outdated and why skip the help guard. The launcher always sends them to the binary, and their entries pass --help on to the package manager (vis exec --help with no pnpm on PATH prints failed to run 'pnpm'). node dist/bin.js <cmd> --help prints vis's own help for each of them. x --help is the same in both engines (both treat it as a file name). This looks unintended; Help::Entry documents it and keeps it.

Other changes

  • Q107 node_contract::version() replaces the VIS_VERSION-else-crate-version rule in the version command, the help surface, the config cache and the HTTP user agent. self_update keeps its own check: it needs a missing or empty value to mean "not native".
  • Q108 drops the stale dead-code allowance and comment on mod targets.
  • Q110/Q111 surface::answer picks its output from an Intent enum; completion splits words with surface::Request.
  • Q112 term::ColourFlag::parse is the one reader of colour flags (detection and the "looks like a colour flag" hand-off). The surface's global-flag rule stays the two exact spellings --color/--no-color, now named ColourFlag::is_global_option; widening it would change routing.
  • Q113/Q72 term::Style is the one SGR painter for help, pail and the deps report. The deps copy re-opens a style after a nested close; to check the help text is unaffected I rendered vis --help, vis help <cmd> and vis <cmd> --help for every manifest command (1160 renders) with FORCE_COLOR=3, FORCE_COLOR=0, NO_COLOR=1 and a CI provider, old binary against new: byte-identical.
  • Q114 the "no group" help section is an Option key.
  • Q115 pail's module doc states the contract with its callers.
  • Q105 (partly) pail::printable, plain and plain_path replace the copies in cache hash, cache clean, clean, sbom and sort-package-json. Layout::block still returns a String: cache prune deliberately prints an em dash that a printable-ASCII check would refuse, so a checked block needs a per-caller rule first.

Ran locally

  • cargo fmt --check, cargo clippy -p vis-core -p vis-cli --all-targets -- -D warnings, cargo test --workspace: pass (including tests/{cli,golden,routing,hook,node_parity}.rs).
  • vitest run __tests__/native with FORCE_COLOR=3, with the task-runner, secret-scanner and vis addons built (pnpm build:native:debug) and the PR's binary copied to vis-native-cli: 5620 tests, 5615 passed, 0 failed, 5 skipped by the suites themselves.

🤖 Generated with Claude Code

prisis and others added 5 commits November 25, 2026 00:35
Records, for about three thousand invocations, where the dispatch in main()
sends them: every case of the shared routing fixture, every manifest command
and alias, each routed command word on its own and with a subcommand, a
positional, help flags, a `--` separator and a leading global flag, and the
version flags. The expected answer is written out from the dispatch as it
stands, so the next change to it can show that no route moved.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
main() was one match with the same help guard written about thirty times.
The routes are now rows of (command path, help policy, entry) in route.rs,
looked up by longest path; the odd shapes (`complete --`, `run <target>`,
`__pm-shim`, the version flags) stay explicit arms. Routing is a pure
function, pinned by a snapshot of every row of the shared routing fixture,
every manifest command and alias, and each table word with subcommands, help
flags and leading global flags.

Also drops the stale dead-code allowance on `mod targets`, which three
commands use.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The VIS_VERSION-else-crate-version rule was written out in the help surface,
the config cache and the HTTP user agent as well as the version command.
Self-update keeps its own check, which wants an empty or missing value to
mean "not native".

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… help surface

- term::ColourFlag::parse is the one reader of colour flags; the detection,
  the "looks like a colour flag" hand-off and the surface's global-flag rule
  use it instead of three separate matchers.
- term::Style is the one SGR painter for the help text and the deps report
  (the deps copy re-opened a style after a nested close; the help text is
  byte-identical with that rule, checked over every help page with colour on
  and off).
- surface::answer picks its output from an Intent enum instead of four
  booleans, and completion splits its words with the surface's Request.
- The "no group" help section is an Option key, not a magic string.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The "printable ASCII" and "printable ASCII without a space" checks that gate
a pail block were written out in cache hash, cache clean, clean, sbom and
sort-package-json, with two spellings of the same rule. They now live in
pail next to the layout, whose module documentation states the contract
between the layout and its callers; pail's colour painter uses the shared
Style.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1260697a-3b3a-4be9-a937-444623480a29

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

qodo-code-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Refactor native vis dispatch into a command routing table

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Replace repeated dispatch guards with a longest-path routing table and explicit help policies.
• Pin native dispatch against 3,105 recorded invocations to protect existing routing behavior.
• Centralize version, terminal styling, and output-validation helpers across native commands.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 4 capabilities

  • 4 affected capabilities span independent functional scopes: native CLI command execution, native CLI completion integration, native CLI output and delegation compatibility, native CLI version and cache/network contract.
  • The route table and main dispatch jointly determine which end-to-end CLI command behavior receives an invocation.
  • The route rows are command entry points within one bounded native frontend integration, not separate deployment or storage capabilities.
  • The changed style and pail predicates are shared output-contract infrastructure for the native command integration.
  • The affected end-to-end behavior is the command's rendered output or fallback decision, not each helper or command as an independent technical capability.
  • The changed accessor provides one bounded package-version contract consumed by help/version, HTTP, and config-cache lookup.
  • These callers share the same native CLI version contract; the changed code does not alter their independent business operations.
  • The changed parser feeds one end-to-end completion behavior.
  • Surface parsing is a shared input boundary for that behavior, not a separate capability.
Behavioral complexity 🟡 Medium 🧩 Interacting branches

  • Before, dispatch was expressed as a large ordered match in main.
  • After, special cases, longest-prefix route selection, help filtering, and main's Dispatch match interact through a routing table.
  • New correctness condition: the selected row must preserve precedence between overlapping command paths and must agree with help/surface ownership before any handler runs.
  • The follow-up only adds cfg(unix) to routing tests; it does not change this production condition.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If a route decision regresses, an invocation can be sent to the wrong native handler, incorrectly answered by the surface, or delegated when the native command should answer.
  • The supported consequence is loss or misexecution of the affected CLI operation, conditional on the invocation; the routing code itself does not establish persistent state corruption or an external side effect.
  • Reverting or correcting the binary restores the prior dispatch logic.
  • A failed command can normally be retried after correction; any command-specific side effect would require that command's own recovery, which is not established by this routing change.
Assessed commit 3b0a544
Diagram

graph TD
  A["CLI arguments"] --> B{"Route selection"} --> C["Special cases"] --> E["Native entries"]
  B --> D["Command table"] --> E
  B --> F["Manifest surface"] --> G["Node CLI"]
  E -.->|"unsupported shape"| G
Loading
High-Level Assessment

Keep the table with explicit exceptional cases and the pre-refactor routing snapshot. Retaining the large match would preserve behavior but also preserve duplicated help guards; this approach makes routing policy reviewable without changing the native handlers' delegation decisions.

Files changed (19) +3725 / -408

Refactor (18) +620 / -408
cache_clean.rsReuse the shared plain-text check +2/-7

Reuse the shared plain-text check

• Replaces a local printable-path predicate with the equivalent shared pail helper for cache-clean output gating.

packages/tooling/vis/native/cli/src/cache_clean.rs

cache_hash.rsMove ASCII output predicates to pail +1/-11

Move ASCII output predicates to pail

• Imports shared plain and printable predicates instead of defining them in the cache-hash module.

packages/tooling/vis/native/cli/src/cache_hash.rs

cache_why.rsRead output predicates from pail +2/-3

Read output predicates from pail

• Switches plain and printable imports from cache-hash to their shared pail home.

packages/tooling/vis/native/cli/src/cache_why.rs

clean.rsShare plain-path validation +2/-7

Share plain-path validation

• Uses the shared pail path check when deciding whether native clean output can be reproduced exactly.

packages/tooling/vis/native/cli/src/clean.rs

complete.rsReuse surface argument parsing for completion +2/-3

Reuse surface argument parsing for completion

• Obtains typed command words through the surface Request parser rather than separately stripping leading global flags.

packages/tooling/vis/native/cli/src/complete.rs

config_cache.rsUse the shared package-version rule +1/-5

Use the shared package-version rule

• Replaces a local VIS_VERSION fallback function with node_contract::version when resolving configuration-cache entries.

packages/tooling/vis/native/cli/src/config_cache.rs

print.rsReuse terminal styling for dependency reports +1/-43

Reuse terminal styling for dependency reports

• Removes the dependency printer's duplicate ANSI Style implementation in favor of the shared terminal style.

packages/tooling/vis/native/cli/src/deps/print.rs

help.rsShare help styling and simplify command grouping +11/-40

Share help styling and simplify command grouping

• Uses terminal Style for help rendering and represents ungrouped commands without a sentinel string. Introduces a row alias for command listings.

packages/tooling/vis/native/cli/src/help.rs

mod.rsShare the version used by HTTP configuration +1/-1

Share the version used by HTTP configuration

• Uses node_contract::version instead of repeating the environment-variable fallback for the HTTP client's package version.

packages/tooling/vis/native/cli/src/http/mod.rs

main.rsDispatch through the new router +13/-196

Dispatch through the new router

• Replaces the long native-command match with Dispatch handling while retaining the manifest surface and Node delegation path. Removes the redundant local version function and stale dead-code allowance.

packages/tooling/vis/native/cli/src/main.rs

node_contract.rsCentralize vis version resolution +6/-0

Centralize vis version resolution

• Adds a shared accessor that reads VIS_VERSION and falls back to the crate version for direct binary runs.

packages/tooling/vis/native/cli/src/node_contract.rs

pail.rsCentralize native pail output checks +32/-11

Centralize native pail output checks

• Adds shared printable-text, plain-word, and plain-path predicates used to gate exact native output. Uses terminal Style for pail's ANSI paint helper and documents the callers' delegation contract.

packages/tooling/vis/native/cli/src/pail.rs

replay.rsUse shared replay output predicates +2/-2

Use shared replay output predicates

• Imports plain and printable checks from pail rather than cache-hash.

packages/tooling/vis/native/cli/src/replay.rs

route.rsDefine and test pure native command routing +359/-0

Define and test pure native command routing

• Adds a longest-prefix command table with explicit manifest-versus-entry help policy and separate dispatch cases for non-path argument shapes. Tests routing against the recorded snapshot, checks table coverage, and verifies representative prefix and help decisions.

packages/tooling/vis/native/cli/src/route.rs

mod.rsShare SBOM output-path validation +2/-7

Share SBOM output-path validation

• Replaces the local ASCII path predicate with pail::plain_path before native SBOM output is written.

packages/tooling/vis/native/cli/src/sbom/mod.rs

mod.rsShare package-JSON output-path validation +2/-7

Share package-JSON output-path validation

• Uses pail::plain_path in place of a local predicate when checking whether file paths permit exact native output.

packages/tooling/vis/native/cli/src/sort_package_json/mod.rs

surface.rsMake help intent and argument parsing explicit +69/-42

Make help intent and argument parsing explicit

• Introduces ordered help intents and exposes Request parsing to completion. Uses shared version and styling helpers while retaining manifest help, group-listing, and fallback behavior.

packages/tooling/vis/native/cli/src/surface.rs

term.rsCentralize ANSI styling and colour-flag parsing +112/-23

Centralize ANSI styling and colour-flag parsing

• Adds shared Style and ColourFlag types, then uses the parser for colour detection and native-output gating. Adds tests for flag spellings and the narrower set of valid leading global options.

packages/tooling/vis/native/cli/src/term.rs

Tests (1) +3105 / -0
native-routes.snapPin native dispatch for 3,105 invocations +3105/-0

Pin native dispatch for 3,105 invocations

• Records the expected dispatch destination for fixture cases, manifest commands and aliases, help flags, positionals, separators, and leading global flags. The routing tests compare current decisions with this pre-refactor baseline.

packages/tooling/vis/native/cli/tests/fixtures/native-routes.snap

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@qodo-code-review

qodo-code-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

Resolved findings
1. Route tests fail on Windows ✓ Resolved Low

Resolving commit: 3b0a544

Resolution reason
The commit adds #[cfg(unix)] to both routes_match_the_snapshot and
the_rows_are_the_paths_the_snapshot_covers tests, exactly the recommended fix of gating the
row-coverage and snapshot tests to Unix, with a comment explaining that the snapshot was written for
Unix routes. This prevents these tests from running on Windows where the failures occurred.
Description
Four ROUTES rows (hook validate, implode, cache clean, and cache prune) are compiled only
with #[cfg(unix)], while COMMAND_PATHS and the committed native-routes.snap include them
unconditionally. On Windows, the_rows_are_the_paths_the_snapshot_covers fails its row-count
assertion and routes_match_the_snapshot sees those invocations reach surface instead of their
recorded entries, breaking cargo test -p vis-cli.

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Four routes (`hook validate`, `implode`, `cache clean`, `cache prune`) are
compiled only on Unix, but the committed snapshot and the list of command
paths name them unconditionally. On Windows the row-count test and the
snapshot comparison therefore fail, because those invocations reach the
surface there. Gate both tests with cfg(unix) and say why in a comment.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added package: vis size:XXL Size of the change, tests and generated files excluded. vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list. labels Nov 25, 2026
@prisis
prisis deployed to benchmarks November 25, 2026 01:45 — with GitHub Actions Active
@codspeed

codspeed Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

🆕 3 new benchmarks
⏩ 113 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 transform/transform_ts[470] N/A 355.4 µs N/A
🆕 transform/transform_ts[47000] N/A 16 ms N/A
🆕 transform/transform_ts[9400] N/A 3.3 ms N/A

Comparing refactor/vis-native-routing-table (ea48f73) with next (1078fa9)2

Open in CodSpeed

Footnotes

  1. 113 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on next (a65ddee) during the generation of this report, so 65c051d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo did not review this PR because this workspace reached its daily trial limit of 100 reviews. Reviews start again at 00:00 UTC. Choose a plan to continue now.

@prisis
prisis deployed to benchmarks November 25, 2026 08:02 — with GitHub Actions Active
@github-actions github-actions Bot added size:XL Size of the change, tests and generated files excluded. and removed size:XXL Size of the change, tests and generated files excluded. labels Nov 25, 2026
@prisis
prisis merged commit 949ed28 into next Nov 25, 2026
33 of 34 checks passed

This branch was successfully deployed

1 active deployment
benchmarks — ea48f730 Deployed Nov 25, 2026 by prisis via Bench native (vis) #417
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: vis size:XL Size of the change, tests and generated files excluded. vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant