feat: reduce AI-agent flag/command errors#13
Open
weiminglong wants to merge 1 commit into
Open
Conversation
Analysis of 194 recent agent errors showed four CLI-side improvements that
would materially reduce guesswork. Implements all four:
1. Fix the broken README example. `surf market-futures --symbol BTC` was
shown in both README.md and the root command's Example, but
market-futures has no --symbol flag. Replaced with `surf market-price
--symbol BTC`, which is a real endpoint.
2. Surface [required] + example in --help. `Param.Required` and
`Param.Example` were captured from the OpenAPI spec but never shown in
--help output, so agents couldn't tell which flags were mandatory. A
new helpDescription() helper prepends "[required] " and appends
"(example: BTC)" when those fields are set. No other code path touches
the raw Description string.
3. Did-you-mean for unknown flags. Previously Cobra's default error was
just "unknown flag: --query". Added a FlagErrorFunc on every API
subcommand that computes Levenshtein distance against the command's
own flags and suggests the closest (≤ 3 edits or substring match).
`--query` → `--q`, `--timerange` → `--time-range`, etc. Sort order
prefers shorter names on ties so `--query` actually surfaces `--q`.
4. Machine-readable catalog via `surf list-operations --json`. Emits a
structured array of {name, method, group, required_flags[],
optional_flags[], path_flags[], body_required} with each flag
including type, description, default, and example. Agents can now
introspect the full command surface before calling instead of trial-
and-error. Human output paths unchanged.
Tests added in cli/suggest_test.go cover the new helpers. Full test suite
passes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Analysis of 194 recent agent errors collected from Claude Code / Codex usage showed ~40% traced to hermod doc strings (fixed in https://github.com/cyberconnecthq/hermod/pull/711) and a further group that the CLI can fix directly. This PR lands the four highest-ROI CLI improvements.
Changes
Fix the broken root example.
surf market-futures --symbol BTCin bothREADME.mdandcmd/surf/main.goRoot.Example —market-futureshas no--symbolflag. Replaced withsurf market-price --symbol BTC, which is a real endpoint.Surface `[required]` + `example:` in `--help`.
Param.RequiredandParam.Examplewere captured from the OpenAPI spec but never shown, so agents had to guess which flags were mandatory. NewhelpDescription()helper (cli/param.go) prepends[required]and appends(example: BTC)when those fields are set. No other code path changed."Did you mean?" for unknown flags. Every API subcommand now has a
FlagErrorFunc(cli/operation.go) that computes Levenshtein distance against its own flags and suggests the closest match (≤ 3 edits or substring match). Sort order prefers shorter names on ties so--queryactually surfaces--qinstead of only--quiet. Net effect: agents that guess--query,--timerange,--usernameget pointed at the real flag immediately.`surf list-operations --json`. Emits a machine-readable command catalog for agents — array of
{name, method, group, required_flags[], optional_flags[], path_flags[], body_required}with each flag including type, description, default, example. Agents can now introspect the full command surface before calling, instead of trial-and-error.Examples
`--help` now shows required + example:
```
--market-slug string [required] REQUIRED. Polymarket market slug (identifies a single Yes/No outcome)...
--symbol string Single token ticker symbol like `BTC`, `ETH`, or `SOL` (example: BTC)
```
Unknown flag → suggestion:
```
$ surf search-project --query bitcoin
Error: unknown flag: --query
Did you mean one of these?
--q
--quiet
```
JSON catalog (first entry):
```json
{
"name": "polymarket-markets",
"method": "GET",
"group": "Prediction Market",
"required_flags": [{"name": "market-slug", "type": "string", "required": true, "description": "..."}],
"optional_flags": [{"name": "limit", "type": "integer", "default": 20}, ...]
}
```
Test plan
Out of scope (follow-ups)
🤖 Generated with Claude Code