Skip to content

fix(main): surface invalid-subcommand hint in agent --help - #735

Draft
amaskara-dd wants to merge 1 commit into
mainfrom
fix/agent-help-invalid-subcommand
Draft

fix(main): surface invalid-subcommand hint in agent --help#735
amaskara-dd wants to merge 1 commit into
mainfrom
fix/agent-help-invalid-subcommand

Conversation

@amaskara-dd

@amaskara-dd amaskara-dd commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Use clap help text in agent mode for invalid subcommands

Motivation

Evals were showing that a lot of tokens are wasted in --agent mode when the agent uses the wrong command name (i.e pup monitors vs pup monitor). In such cases, the clap output is far more useful than the root level agent schema

Additional Notes

Checklist

  • The code change follows the project conventions (see CONTRIBUTING.md)
  • Tests have been added/updated (if applicable)
  • Documentation has been updated (if applicable)
  • All CI checks pass
  • Code coverage is maintained or improved

Related Issues

In agent mode, `--help` is intercepted before clap to emit a JSON
schema. The intercept resolved the requested subcommand and fell
through a catch-all to the generic root schema (exit 0) whenever it
didn't resolve — swallowing clap's "did you mean" suggestion. So
`pup monitor list --help --agent` was less helpful than the same
command without `--help`.

Only emit a schema when the request resolves to a real command (or
no subcommand was given); for an unknown subcommand, fall through to
clap so it reports the typo with a suggestion.

- Make `find_subcommand` alias-aware so valid aliases (e.g. `audit`)
  still return the scoped JSON schema instead of clap text help.
- Extract `top_level_subcommand` to skip values of value-taking global
  flags (`--org`, `-o/--output`, `--jq`), so `--org x monitors --help`
  scopes to `monitors`, not the flag value.
- Add unit tests for subcommand resolution, alias handling, and
  top-level extraction.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

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.

1 participant