Structured positional-arg metadata in help system#240
Merged
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/cli/args.go">
<violation number="1" location="internal/cli/args.go:120">
P2: `strings.Contains(lower, "id")` matches substrings within larger words (e.g., "video" → "identifier", "update" → "date"). Split the name into tokens on `|`/`-`/`_` delimiters and match whole tokens instead.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
In TTY mode, missing required args show cmd.Help() (exit 0) preserving David's human UX. In non-TTY/agent mode, return structured JSON errors naming the specific missing arg with usage hints for elicitation. Three new helpers in helpers.go: - missingArg(cmd, "<arg>") — dispatches based on isMachineOutput - noChanges(cmd) — same for update commands with no fields - isMachineOutput(cmd) — detects agent/json/piped output Nine unit tests covering both modes, multi-line examples, and flag detection fallbacks.
There was a problem hiding this comment.
Pull request overview
Adds structured positional-argument metadata to the CLI help system by parsing Cobra Use: strings into ArgInfo, exposing that structure in both human help output and --help --agent JSON, and introducing doc/contract tests to keep help/docs aligned with the live command tree.
Changes:
- Parse positional args from
Use:into structuredArgInfo(with optional annotation override) and render an ARGUMENTS section in styled help. - Extend
--help --agentJSON output with anargsfield and update the CLI surface snapshot script to emitARGrecords. - Add contract tests for key positional-arg declarations and for SKILL.md Quick Reference command paths.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/check-cli-surface.sh | Emits ARG lines (with padded positional index) from agent-help JSON. |
| internal/commands/doc_contract_test.go | Adds doc/CLI contract tests for positional args and SKILL.md command references. |
| internal/cli/root.go | Extends agent-help JSON schema with args. |
| internal/cli/help_test.go | Adds coverage for agent args JSON + human ARGUMENTS section rendering behavior. |
| internal/cli/help.go | Renders an ARGUMENTS section for runnable commands with parsed positional args. |
| internal/cli/args_test.go | Adds unit tests for parsing, display, humanization, and kind inference. |
| internal/cli/args.go | Implements ArgInfo, ParseArgs, ArgDisplay, and arg humanization/kind inference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ParseArgs extracts ArgInfo metadata from cobra command Use: strings. Strips [flags] and [action] conventions, skips non-runnable commands, and supports annotation overrides via arg_schema. Includes mechanical humanization (id→ID, url→URL, dash→space, title case) and kind inference (identifier/date/text) with no hand-maintained lookup table.
Agent help (--help --agent) now includes an "args" field with structured positional arg metadata (name, required, variadic, description, kind). Field is omitted when empty, consistent with subcommands/flags. Human help renders an ARGUMENTS section between ALIASES and COMMANDS when a command declares positional args, with aligned display and (optional)/(one or more) suffixes.
TestDocContractArgs validates that key commands declare expected positional args in their Use: string via cli.ParseArgs. TestSkillMDQuickReferenceCommands validates that every command path in the SKILL.md Quick Reference table exists in the live command tree.
Zero-padded positional index preserves declaration order under LC_ALL=C sort. Format: ARG <path> <index> <bracket-notation>
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
Use:strings into structuredArgInfometadata (name, required, variadic, description, kind) with mechanical humanization and no hand-maintained lookup table--help --agent) now includes anargsJSON field; human help renders an ARGUMENTS sectionARGlines with zero-padded positional indexTest plan
make test— all Go tests pass (0 failures)make test-e2e— all e2e tests pass (0 failures)./bin/basecamp todo --help --agent | jq '.args'— shows structured content arg./bin/basecamp projects --help --agent | jq 'has("args")'— false (no args)./bin/basecamp show --help— ARGUMENTS section with[type]and<id|url>./bin/basecamp people --help— no ARGUMENTS (not runnable)./bin/basecamp webhooks create --help --agent | jq '.args[].name'— "url" only ([flags]stripped)./bin/basecamp schedule --help --agent | jq '.args // empty'— absent ([action]stripped)Summary by cubic
Add structured parsing of positional args and surface them in both agent (
--help --agent) and human help. Also add clear missing-arg behavior: friendly help in TTY, structured JSON errors in agent/machine mode.New Features
ArgInfo(name, required, variadic, description, kind) with humanization and kind inference; supportsAnnotations["arg_schema"]; skips non-runnable commands; strips[flags]and[action].argsJSON field; omitted when empty.missingArg,noChanges, andisMachineOutputhelpers showcmd.Help()(exit 0) in TTY, or return structured JSON errors naming the specific arg in agent/machine mode.scripts/check-cli-surface.shnow emits zero-paddedARGlines to preserve positional order in the CLI surface snapshot.Bug Fixes
Written for commit 0f52333. Summary will update on new commits.