Skip to content

fix(cli): accept -f/--format and --json on every command - #425

Open
ankitranjan7 wants to merge 1 commit into
mainfrom
fix/cli-universal-format-flags
Open

fix(cli): accept -f/--format and --json on every command#425
ankitranjan7 wants to merge 1 commit into
mainfrom
fix/cli-universal-format-flags

Conversation

@ankitranjan7

Copy link
Copy Markdown
Contributor

-f/--format and --json were registered on roughly half the CLI's commands. An agent that learns --json on webcmd plugin list hits error: unknown option '--json' on webcmd plugin install, and has no way to predict which side of the line a command falls on. In a recent eval this cost repeated wrong guesses in 4 of 12 scenarios.

What changed

  1. ensureOutputFormatOptions(program) walks the finished Commander tree and registers -f, --format <fmt> plus --json on every leaf that lacks them. Namespace commands (adapter, plugin, …) are skipped — they only print help — and external-CLI passthrough is skipped so its argv still reaches the wrapped binary.
  2. Action commands now render a structured result when a format is requested: plugin install/uninstall/update/create, profile create/rename/use, adapter path/override/reset, daemon stop/restart, external install/register, browser init, and the site write leaves (note add, endpoint set/stale, field-map add, fixture put, sample add). Shape is a small { ok, action, … } envelope, consistent across similar commands. Without a flag the human output is byte-identical.
  3. browser tabs/bind/close/snapshot/run route their result through the shared renderer with json as the default format, so -f yaml works and today's JSON bytes are unchanged. browser run gains -f/--format alongside the --json it already had.
  4. configureCompletionCommandSurface and the plugin install/uninstall/update surfaces gained the flag directly, so hosted mode inherits the same grammar as local — hosted help and structural-error parity tests cover this.
  5. webcmd skills add/update/remove keep their existing --json envelope and now also honour -f json.

Before / After

Before, on origin/main:

$ webcmd adapter path -f json hackernews/ask
error: unknown option '-f'

$ webcmd plugin install --json openfda
error: unknown option '--json'
help: valid flags for `webcmd plugin install`: --all

$ webcmd profile create demo --json
error: unknown option '--json'

After:

$ webcmd adapter path -f json hackernews/ask
{
  "ok": true,
  "command": "hackernews/ask",
  "path": "/Users/ankitranjan/.webcmd/plugins/hackernews/ask.js"
}

$ webcmd adapter path hackernews/ask
/Users/ankitranjan/.webcmd/plugins/hackernews/ask.js

$ webcmd plugin install --json openfda
Error: Invalid plugin source: "openfda"
Supported formats:
  github:user/repo

Tests

src/cli-format-contract.test.ts walks the whole Commander tree and asserts every non-namespace, non-passthrough command exposes -f, --format and --json, so a command added later cannot regress the contract. A second case asserts adapter path prints the bare path by default and the { ok, command, path } envelope under --json. src/site-memory/commands.test.ts adds equivalent default-silent / structured-under---json coverage for three write leaves.

npm run typecheck clean. npx vitest run --project unit: 2707 passed, 2 failed — both in src/browser/run/playwright-client-build.test.ts, which cannot read node_modules/playwright-core through this worktree's symlink; the same file passes in a normal checkout and is untouched by this change.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

🟠 Maintainer review suggested — low confidence

The automated review could not reach a fully supported conclusion.

Limitations

  • The automated review returned an invalid structured result.

This review is advisory and does not block merging.

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