Skip to content

feat(vg-helper): canonical command registry with split exit codes#104

Open
majiayu000 wants to merge 2 commits intomainfrom
feat/command-registry-102
Open

feat(vg-helper): canonical command registry with split exit codes#104
majiayu000 wants to merge 2 commits intomainfrom
feat/command-registry-102

Conversation

@majiayu000
Copy link
Copy Markdown
Owner

Summary

  • Replace duplicated help text + dispatch match in main.rs with a static COMMANDS table (name, usage, handler fn-ptr); help is generated from the registry, eliminating drift between help text and dispatch logic
  • Split exit codes at the CLI boundary: unknown/missing command → exit 2 (user-input error), handler Err → exit 1 (execution error)
  • Add vg-helper/tests/cli.rs with 5 integration tests; the help_lists_all_8_commands test acts as a registry-completeness assertion

Test plan

  • cargo check — clean (verified locally)
  • cargo test — 28/28 pass: 23 unit tests + 5 new integration tests (verified locally)
  • Integration tests exercise: no-args exits 2, unknown command exits 2, help lists all 8 commands, known command exits 0, bad sub-args exits 1
  • Pre-existing flaky test test_run_produces_learn_suggested_and_appends_metrics fixed (parse last JSONL line, not whole file)

Closes #102

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hook Latency (P95)

Details
Benchmark suite Current: 796eec9 Previous: 075c3ed Ratio
pre-edit-guard (P95) 196 ms 188 ms 1.04
pre-write-guard (P95) 229 ms 213 ms 1.08
pre-bash-guard (P95) 277 ms 255 ms 1.09
post-edit-guard (100) (P95) 324 ms 298 ms 1.09
post-write-guard (100) (P95) 223 ms 208 ms 1.07
post-edit-guard (5000) (P95) 333 ms 314 ms 1.06
post-write-guard (5000) (P95) 238 ms 209 ms 1.14
stop-guard (5000) (P95) 140 ms 132 ms 1.06
learn-evaluator (5000) (P95) 141 ms 132 ms 1.07

This comment was automatically generated by workflow using github-action-benchmark.

Replace the duplicated help-text + dispatch match in main.rs with a
static COMMANDS table (name, usage, handler fn-ptr). Help is now
generated from the registry, so adding a command cannot silently drift
the help text. Exit codes are split at the CLI boundary: unknown/missing
command → 2 (user-input error), handler Err → 1 (execution error).

Also fix a pre-existing test flakiness in session_metrics: parse the
last JSONL line rather than the whole file content, which failed on
repeated test runs due to file appending in a persistent temp dir.

Integration tests in tests/cli.rs cover all five contract cases and
double as a registry-completeness assertion (all 8 command names in help).

Signed-off-by: majiayu000 <1835304752@qq.com>
The command registry split exit codes at the main entrypoint, but json-field and
json-two-fields still treated malformed stdin JSON as a blank result. Return
parse errors instead so invalid input exits 1 while missing fields remain blank.

Signed-off-by: majiayu000 <1835304752@qq.com>
@majiayu000 majiayu000 force-pushed the feat/command-registry-102 branch from 8077f63 to 796eec9 Compare April 21, 2026 21:18
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.

Refactor vg-helper main into a canonical command registry

1 participant