Skip to content

feat(cli): top-level --format / CBM_CLI_FORMAT default for tools (follow-up from #1867) #2102

Description

@Lowpower

Split out of #1867 per @DeusData's request

Split out from #1867 (secondary finding there: search_graph / trace_path / detect_changes emit the compact tree by default when stdout is not a TTY), per the maintainer's invitation to give it its own discussion.

Current state (verified on v0.10.8) — better than my original report assumed

  • Tools that accept a format argument (notably search_graph / trace_path / detect_changes) already support --format json, and <tool> --help documents it (e.g. search_graph --help: "Response encoding. tree (default) … json: the SAME tree model as structured JSON")
  • The README CLI section documents both layers: tool-level --format json (payload JSON) vs outer --json (full MCP envelope)
  • The tree default is deliberate, and I understand why: the primary non-TTY consumers of this CLI are AI agents and bridges, and the compact tree is token-optimized for exactly that audience

So this is not a bug report — it is a small UX/discoverability suggestion.

Remaining friction

  1. --format json is per-tool-call only. A script or bridge invoking several tools must pass it on every single invocation; there is no way to set it once for a session.
  2. The top-level cli --help doesn't mention it. You have to run <tool> --help for each tool to discover the flag. The README covers it, but --help is where habitual CLI users look first.

Suggestion — pick whichever direction you prefer; happy to submit a PR

  • (a) Top-level flag: cli [--format tree|json] <tool> ... acting as a default for tools that accept format; an explicit per-tool --format still wins.
  • (b) Env var: CBM_CLI_FORMAT=tree|json, useful for bridges that spawn the binary from generated glue code without full control over argv on every call.
  • (c) Docs-only: add one line to the top-level cli usage string pointing at tool-level --format json.

I'd lean towards (a) + (b): both are fully backward compatible, and they deliberately do not flip the default on non-TTY stdout — auto-switching would silently change the output that model-facing bridges and agents see, which I assume is the audience the tree default was designed for.

I can implement this myself if you agree on a direction. From reading the source, the change looks localized:

  • run_cli() in src/main.c — merge a top-level/env-provided format into args_json before tool dispatch (per-tool explicit value still takes precedence)
  • tests/test_cli.c — precedence tests (top-level vs per-tool vs unset)
  • CLI_USAGE string + README CLI section
  • Per CONTRIBUTING (pre-commit hooks, scripts/lint.sh, DCO Signed-off-by trailer)

Activity

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

    editor/integrationEditor compatibility and CLI integrationenhancementNew feature or requestpriority/normalStandard review queue; useful PR with ordinary maintainer urgency.ux/behaviorDisplay bugs, docs, adoption UX

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions