Skip to content

Improve admin CLI per-method parameter help UX (MIR-746)#823

Merged
evanphx merged 2 commits into
mainfrom
mir-746-improve-admin-cli-per-method-parameter-help-ux
May 27, 2026
Merged

Improve admin CLI per-method parameter help UX (MIR-746)#823
evanphx merged 2 commits into
mainfrom
mir-746-improve-admin-cli-per-method-parameter-help-ux

Conversation

@evanphx
Copy link
Copy Markdown
Contributor

@evanphx evanphx commented May 26, 2026

Summary

Smooths out three rough edges in miren admin <method>:

  • --help / -h on a method now shows method help (same as --func-help) instead of erroring with unknown parameter(s): help.
  • Calling a method that declares params with no args now renders the help block instead of falling through to a raw -32602 Invalid params JSON-RPC error.
  • validateAdminCall missing-required and unknown-param errors now embed the full method definition (description, tree-formatted params with types and (required) markers), matching what --list / --func-help produce.

Also distinguishes two cases that previously looked identical on the wire:

  • (no parameters) — method explicitly declares an empty param list.
  • (parameters not advertised by this method) — method's $methods response omits the params key entirely.

servers/admin/admin.go fetchMethods now calls SetParams unconditionally when the source JSON includes a params key, even if empty. Combined with a tightened client guard (HasParams() instead of HasParams() && len > 0), declared-zero-params methods now also reject supplied params.

Test plan

  • go build ./...
  • go test ./cli/commands/ ./servers/admin/ — 208 passing
  • make lint — 0 issues
  • Live smoke against a real admin method:
    • m admin -a <app> <method> --help matches --func-help output
    • m admin -a <app> <method> (no params) renders method help, not -32602
    • m admin -a <app> <method> bogus=1 shows rich definition list after "unknown parameter(s)"
    • m admin -a <app> <method> (declared zero params) still calls server cleanly
    • m admin -a <app> <method> --no-validate still sends empty call
    • m admin -a <app> --list and m admin -a <app> <method> --func-help unchanged

Refs MIR-746.

Make per-method help discoverable and informative:

- Treat --help/-h as method help (same as --func-help) instead of
  erroring with "unknown parameter(s): help".
- Render method help when a method that declares params is invoked with
  none, instead of falling through to a raw -32602 JSON-RPC error.
- Embed the full method definition (term, description, tree-formatted
  params with types and (required) markers) in validateAdminCall error
  output for both missing-required and unknown-param branches.
- Distinguish "method takes no parameters" from "params not advertised
  by this method": fetchMethods now calls SetParams unconditionally
  when the wire payload includes a params key (even if empty), and
  renderMethodHelpString surfaces the distinction with a faint footer.
  validateAdminCall now rejects any supplied param on declared-empty-
  params methods (previously skipped because the guard required
  len(params) > 0).

Refs MIR-746.
@evanphx evanphx requested a review from a team as a code owner May 26, 2026 19:27
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c68777c2-5420-41f4-84a3-785d67719dd2

📥 Commits

Reviewing files that changed from the base of the PR and between 1715869 and cd1e628.

📒 Files selected for processing (2)
  • cli/commands/admin.go
  • cli/commands/admin_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cli/commands/admin.go

📝 Walkthrough

Walkthrough

This PR enhances the admin command's help handling and parameter validation semantics. The CLI now detects help tokens (--help, -h, help) alongside explicit --func-help requests and routes them consistently. Help rendering is refactored into reusable helpers (methodDefinition, paramShapeNote, renderMethodHelpString, renderMethodHelp) to reduce duplication. The command adds an early guard that renders help and returns when a method advertises parameters but the user supplies none. Parameter validation is updated to treat explicitly declared empty parameter lists as a distinct contract. Error messages for validation failures now embed the rendered help block. On the server side, fetchMethods now distinguishes between methods that declare params explicitly (including empty lists) versus those that omit params entirely, affecting the metadata sent to clients.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cli/commands/admin.go`:
- Around line 374-388: The function hasHelpFlag currently treats a bare "help"
token as a help request which falsely intercepts flag values (e.g., --topic
help); update hasHelpFlag in cli/commands/admin.go to stop treating the bare
"help" string as a help flag by removing the "help" case from the switch and
only matching "--help", "-h", and the "--help=" / "-h=" prefixes on the arg
variable so that values passed to flags are not mistaken for a help request.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e636e65-a37b-4599-b20a-cc36c2a75298

📥 Commits

Reviewing files that changed from the base of the PR and between 926db8a and 1715869.

📒 Files selected for processing (2)
  • cli/commands/admin.go
  • servers/admin/admin.go

Comment thread cli/commands/admin.go Outdated
Copy link
Copy Markdown
Contributor

@phinze phinze left a comment

Choose a reason for hiding this comment

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

Yer boy and yer bot here. We like this overall — good improvements. The (no parameters) vs (parameters not advertised) distinction in particular is a small clarity that punches above its weight (which presumes we're gonna be boxing with this API I guess?).

CodeRabbit caught a real one on hasHelpFlag — agree with the diagnosis, but we'd lean toward just dropping case "help" entirely rather than the preceding-flag heuristic. --help/-h are the conventions people know; bare help was the form that broke things.

One thing inline.

Seeing all this code shift around without any tests is a little itchy for Paul, and for Claude it kinda tickles:

brother may i have some TESTS

Comment thread cli/commands/admin.go
- hasHelpFlag no longer treats bare "help" as a help flag, so invocations
  like `m admin <method> --topic help` (or `topic=help`) pass through to
  parseUnknownFlags instead of being intercepted.
- The no-params-supplied branch now returns an error embedding the method
  help, mirroring missing-required-params. This keeps the exit code
  non-zero so shell chains like `m admin -a foo bar && echo ok` don't
  treat a help-rendered call as success. Explicit --help/--func-help
  still exits zero.
- Add tests for hasHelpFlag (including the --topic help edge case),
  paramShapeNote ("no parameters" vs "parameters not advertised"),
  methodDefinition, and renderMethodHelpString.

Refs MIR-746.
@evanphx evanphx merged commit b1642e6 into main May 27, 2026
19 checks passed
@evanphx evanphx deleted the mir-746-improve-admin-cli-per-method-parameter-help-ux branch May 27, 2026 22:40
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