Skip to content

feat(cli): tool commands pass unknown arguments to the tool #5223

Open
3 of 6 issues completed
Open

Description

@dan-petty

Update 2026-11-26 (infra move): gh comes from the devtools image, and tools.lock is gone.

The devcontainer and the Service image take gh from the same devtools image, so step 9 needs no pin and no feature option. src/devops_cli/tools_lock/ and its runbook no longer exist: keep the recorded flag files next to the registry code.


Problem or Motivation

The owner asked on 2026-11-12: "I'd prefer if devops subcommands that run other cli tools match the command names and parameters and pass them through when possible, api based tools should use the api route naming for consistency. This should reduce agent confusion."

Today each wrapper builds a fixed argv from its own Typer options. So each new tool flag needs code, and an agent that types a real tool flag gets a usage error. Loki holds 159 cli_usage_error records in the 7 days to 2026-11-12, and agents made all of them. 149 of them (94 %) are gh flags on view and list commands: --json 127, --comments 10, --search 9, --head 2, --jq 1. Only four commands pass arguments through today: devops gh api, devops uv run, devops valkey cli and devops k8s run-job.

Examples:

  • devops gh run list uses -n for gh's -L, and -f/--format table|json for gh's --json <fields>.
  • devops gh run view has no --json, --jq, --attempt or --exit-status.
  • In devops, gh api --cache is a boolean flag. In gh, --cache takes a duration. So with devops gh api <route> --cache 1h, gh gets 1h as a second endpoint.
  • devops gh api changes each byte that is not UTF-8 to U+FFFD, and devops gh has no run download. So an agent cannot read a run artifact (fix(gh): devops gh api breaks a binary response #5015).
  • The devcontainer installs gh with the feature github-cli:1 and no version (.devcontainer/image/devcontainer.json:27). The Service image pins gh 2.103.3 (Dockerfile:40-43). So the gh of an agent can differ from the gh of the Service, and no recorded flag list can match both.

Proposed Solution & Architectural Design

  1. Documents. Write ADR docs/adr/0026-a-command-that-runs-a-tool-takes-its-names-and-passes-its-arguments-through.md, the naming rows of CONTRIBUTING.md, a 'Tool pass-through' bullet in section 7.3 of ARCHITECTURE.md, and the MCP and egress rules in SECURITY.md. The spec tool-command-names replaces gh-command-names.
    Follow the ADR rules of the ADR modernization tracker (MADR front matter, 1,000 words or fewer) if its first item has merged; else write the record in the current form.
  2. Registry. Add src/devops_cli/core/passthrough.py. The key of an entry is the tool path (gh run list). An entry holds:
    • the devops paths (a gh pr entry names devops gh pr <verb> and devops pr <verb>)
    • the runner (run_gh, or run_subprocess with the isolated environment of the tool)
    • read or write
    • the owned options and the refused options, with the tool's names
    • the MCP allowlist: each option that an MCP caller can give, with its arity and its caps
    • the cost of one run, and the page rule of -L/--limit
    • the timeout
      The registry also lists the gh verbs that devops never wraps: pr merge, auth, secret set, repo delete and release.
  3. Command shape. One Typer argument args with click.UNPROCESSED, the context settings ignore_unknown_options and help_option_names=[], the option --dry-run, and the owned and refused options of the entry as Typer options with the tool's names. Click parses each form of a declared option (--opt=value, -Ovalue, -dO value), so the command reads or refuses the parsed value, not a token. The runner gives each owned value to the tool unchanged, and args in the typed order.
  4. Options that each gh entry owns or refuses:
    • -R/--repo: a value that is not OWNER/REPO (a host or a URL) exits 2. The child gets GH_HOST=github.com. So no gh entry sends a request to another host.
    • -L/--limit on a list entry: the runner charges one unit for each 100 items.
    • gh api owns --paginate and --cache <duration>, and refuses --hostname. --cache-ttl goes.
  5. Runner.
    • A read keeps backoff and retry. A write runs once (max_retries=0). gh can send two mutations in one run, and run_gh runs the whole argv again after rate-limit text today (github/rate_limiter.py:1824-1869), so a second run can write twice.
    • On a rate-limit refusal, the command prints gh's error, then one line with the reset time and the note that REST reads go through devops gh api (ADR 0026). The line holds no filled route, because the runner does not read the number.
    • Output: the runner decodes stdout and stderr with surrogateescape, masks them with mask_secrets and writes the same bytes back. The command exits with the exit code of the tool. When the timeout of the entry stops the tool, it exits 124 and prints the masked partial output.
  6. Help. When args holds -h or --help before a --, the runner runs the tool as a local command: no token, no pin and no rate-limit read (is_local_gh_command checks only args[0] today, core/process.py:407). First it prints one devops line from the entry: the devops paths, the owned and refused options, the forced options and the devops meaning of --dry-run. main._delegate returns the exit code of a help query on a pass-through path (src/devops_cli/main.py:105-130 drops it today).
  7. Dry run. --dry-run, devops --dry-run and DEVOPS_CLI_DRY_RUN print the masked tool argv and its rate-limit resource (detect_resource), and send 0 requests. The tool never gets --dry-run.
  8. MCP.
    • The generator publishes args: list[str] for a pass-through row and puts the devops options before args (ai/mcp/generator.py:466-484 puts them after today).
    • The MCP layer parses args with a strict Click parser built from the MCP allowlist of the entry. It refuses an option that is not on the list, in any form, and a bare --, before a request.
    • No allowlist holds -F/--body-file, --input, --recover, -w/--web or -e/--editor. -L/--limit is at most 100.
    • A row can be read-only only for a read entry.
    • Each MCP tool description starts with its exact CLI path. A test checks each row (ai_cost_report is devops ai cost report, feat(cli): usage errors show a hint for known wrong commands #4860).
  9. Recorded flags. The devcontainer and the Service image take gh from the devtools image. Record the flags of each registry path from the cobra completion command of the pinned gh (gh __complete <path> -, with the values of enum flags), and the help of the pinned openspec (tests/support/openspec_recording.py). Keep the files next to the registry code.
  10. Resolver. core/command_resolver.py accepts a token after a pass-through path only when its option name is in the recorded flags of the tool, and only with a listed value where the flag has an enum. So devops docs check still finds a stale flag. A hint of feat(cli): usage errors show a hint for known wrong commands #4860 never covers a token after a pass-through path.
  11. Commands. Change devops gh run list, gh run view and gh api, and add devops gh run download. run view and run download get the timeout DEFAULT_GH_RUN_LOG_TIMEOUT_SECONDS (120 s). run download writes local files, so it is not an MCP tool.
  12. Premise check, recorded in the proposal:
  • Run each changed verb with GH_DEBUG=api and record its API. A GraphQL verb goes into CONST_GH_GRAPHQL_PORCELAIN_COMMANDS (config/constants.py:2855).
  • Typer 0.28 gives -h to args when help_option_names is empty.
  • gh __complete lists the flags and the enum values with no request and no token.
  • Which identity runs each path: the CLI runs as the login of the person; the MCP rows and the Service tools run as the GitHub App installation.

Target Subsystem

CLI core (core/passthrough.py, core/command_resolver.py, core/process.py, ai/mcp/generator.py, main.py), devops gh api, devops gh run and the devcontainer gh pin.

Existing Tool Considered

  • The Click pattern that forwards unknown options (ignore_unknown_options, nargs=-1, click.UNPROCESSED), and Click's own parser for the MCP allowlist. No new parser.
  • The cobra completion command of gh for the recorded flags. gh parses and documents its own flags, --json fields, --jq and --template, so devops keeps no full flag table.
  • The surrogateescape error handler of Python.
    Built: the registry and one runner of about 200 lines. Estimate: about 0.80 USD on the DeepSeek implement path and 2 days elapsed.

Acceptance Criteria

  • devops gh run list -L 5 --json databaseId,status --jq '.[0].status' prints what gh prints and exits with the exit code of gh.
  • devops gh run view 1 --log-failed --dry-run and devops --dry-run gh run view 1 --log-failed print gh run view 1 --log-failed and send 0 requests (process-stub test).
  • devops gh run download 43191263934 -n coverage-shard-1 -D <dir> writes a zip of 2,420,029 bytes. devops gh api <artifact zip route> > f.zip writes the same bytes (fix(gh): devops gh api breaks a binary response #5015).
  • A second devops gh api <route> --cache 1h in the same hour sends 0 requests.
  • devops gh run list -R evil.example.com/o/r and -R https://evil.example.com/o/r exit 2 before a request. devops gh api --hostname example.com user exits 2.
  • Process-stub tests: a write entry whose gh run fails with secondary rate limit runs gh once. A read entry that times out exits 124 and prints the partial output.
  • With sockets blocked and no token, devops gh run view --help prints the devops line and the help of gh, and exits with the exit code of gh.
  • MCP: on a read entry, args ["--json", "databaseId"] runs. On a test write entry, ["5", "-F/etc/hostname"], ["5", "--body-file=/etc/hostname"], ["5", "-dF", "/etc/hostname"] and ["5", "--", "--dry-run"] are refused before a request. ["-L", "500"] is refused.
  • A test: each MCP tool description starts with its CLI path.
  • uv run devops gh --version in the devcontainer prints the gh version of the Service image.
  • tests/commands/test_tool_command_names.py fails when a registry path differs from the tool prefix, when a pass-through command declares an option that the entry does not own or refuse, and when a project verb in a tool group is a verb of the tool.
  • A fixture document with devops gh run list --no-such-flag fails devops docs check. devops docs check passes on the repository.

Dependencies

Merge first: a private security fix (owner) and #4860. Do not open its pull request while a pull request of #4862 is open, because both change core/command_resolver.py. #5015 is closed as superseded by this item.

Source: #4833

Alternatives check of 2026-11-29: in-use.
The repository already uses this tool.
Tool: pallets/click (https://github.com/pallets/click), BSD-3-Clause, last activity 2026-11-16, maintained.
Reason: Searches surfaced only Click, the parser the project already builds on: it gives unknown-option forwarding, ordered UNPROCESSED tokens and a strict parser, but no registry, rate-limit cost, timeout, dry-run, help delegation or MCP schema.

Covers:

  • Forwards unknown options through ignore_unknown_options with nargs=-1
  • Keeps typed order and option forms via click.UNPROCESSED
  • Strict parser refuses undeclared options for the MCP allowlist
  • Parses each declared form such as --opt=value and -Ovalue

Lacks:

  • No registry of tool paths, owned or refused options
  • No rate-limit cost, retry, timeout or dry-run rules
  • No help delegation or MCP tool description generation
  • No recorded per-tool flags for resolver validation

Sub-issues

Sub-issues

3 of 6 Issues completed
Loading 6 sub-issues

Activity

  1. added
    source/agent
    on Nov 12, 2026
  2. added
    type/feature
    scope/cli
    status/new
    value/high
    effort/high
    on Nov 12, 2026
  3. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  4. added
    priority/p2-medium
    on Nov 12, 2026
  5. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Order 9 of tracker #5311 (#5323) builds on the registry of this item. #5323 adds devops gh repo, gh ruleset, gh variable and gh org list as registry entries with no new logic, so it starts after this item merges. With the registry it costs about 250k tokens and 0.5 day; without it, about 400k tokens. The owner approved the plan in #5311 on 2026-11-13.

  6. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    New evidence of 2026-11-13 (review of failing CLI calls). This item is the largest single cause of devops usage errors.

    Counts

    • Claude Code transcripts, 2026-10-22 to 2026-11-13: gh flags that the mirror commands do not take gave 449 usage errors. --json 299 (23 sessions, 256 agents), --comments 51, --search 48, --body-file 42, --head 9.
    • Local usage-error ledger, 28 hours to 2026-11-13: 294 of 341 rows (86%) are these flags. gh issue view --json 173, gh issue list --search 47, gh pr view --json 43, gh issue view --comments 11, gh pr list --json 5, pr view --json 3. The --json share stays between 71% and 87% on every release from 0.118.0 to 0.129.1.
    • Loki, 3 days: 251 of 307 cli_usage_error records.
    • 84% of these errors get a retry within 3 calls, mostly through devops gh api: issues/{n} 6,133 calls, issues/{n}/comments about 3,000, search/issues 2,022.

    Two points for the scope

    1. An interim hint. Until this item merges, No such option: --json gives no next step, so each agent finds the devops gh api fallback again. I ask feat(cli): usage errors show a hint for known wrong commands #4860 to add hint rows for --json, --jq, --comments and --search on the mirror paths, each with the exact fallback (for example devops gh api repos/{owner}/{repo}/issues/<n> --jq .title). A hint is output, not an alias. This item deletes those rows when the pass-through merges, as feat(cli): usage errors show a hint for known wrong commands #4860 already plans ("no hint covers a token after a pass-through path").
    2. Two meanings of --json in one group. devops gh status, gh metrics, gh project workflows list and gh branch-protection audit have a true/false --json (src/devops_cli/commands/gh.py, lines 738, 1635, 1856 and 2199). After the pass-through, --json <fields> on the mirror commands and a bare --json on these commands mean different things in the devops gh group. feat(gh): gh status, label list and secret list run gh #5228 makes gh status a pass-through. For the other 3, I propose --format json in the pull request that changes them, and a test that walks the gh and pr groups and fails on a true/false --json. This changes the feat(cli): track gh-parity names and usage-error capture #4833 decision ("the boolean --json of the other 118 commands does not change") for the gh group only.

    Measure: cli_usage_error records with the names --json, --jq, --comments, --search, --head or --body-file go to 0 in the 7 days after the release. devops gh api calls to issues/{n} and search/issues per session go down.

  7. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (10)

    Tools considered:

    Searches run:

    • Click forwarding unknown options ignore_unknown_options UNPROCESSED, results: 5
    • python CLI wrapper pass through unknown arguments to external command, results: 5
    • typer click UNPROCESSED arguments pass through to subprocess, results: 5
    • click.palletsprojects.com advanced forwarding unknown options, results: 5
    • "ignore_unknown_options" click python, results: 5
    • Click documentation ignore_unknown_options, results: 5
    • typer python CLI framework pass through arguments, results: 5
    • click python package command line library, results: 5
    • pallets click github repository, results: 5
    • gh cli wrapper pass through flags github, results: 5

    Sources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/clisource/agentstatus/newtype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions