Skip to content

fix(cli): format opencode models --verbose as a table - #50522

Open
fede-kamel wants to merge 3 commits into
anomalyco:devfrom
fede-kamel:fix/models-formatting
Open

fede-kamel wants to merge 3 commits into
anomalyco:devfrom
fede-kamel:fix/models-formatting

Conversation

@fede-kamel

@fede-kamel fede-kamel commented Sep 22, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #50513

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

opencode models --verbose printed JSON.stringify(model, null, 2) for every model. With three providers and 80+ models that is several thousand lines of JSON, and the fields you actually want are buried in it.

This prints one aligned table per provider instead, using fields the catalog already carries: model id, name, base cost per 1M tokens, context and output limits, and capabilities.

Spark (the house's GB10)
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Model                       Name                                                         Cost ($/1M in/out)  Context  Output  Capabilities
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
kamelhar-spark/qwen3.6-35b  qwen3.6-35b (GB10 first, cheap cloud pool behind it)         free                131K     8K      tools
kamelhar-spark/spark-only   qwen3.6-35b, Spark ONLY — fails rather than leaving the box  free                131K     8K      tools

Three things I deliberately did not do:

  • Default output is untouched. opencode models still writes the same plain provider/model lines to stdout, byte for byte, because that is the form scripts pipe into grep and fzf. Only --verbose changed.
  • Everything stays on stdout. No ANSI colour is emitted, so the table survives a pipe and a redirect without escape-code noise.
  • Column widths are computed per provider, not globally, so one provider with very long OpenRouter-style model IDs does not pad out every other provider's table. Widths come from the data, so nothing is truncated; the last column is left unpadded so no line carries trailing whitespace.

This follows the table already built by session list in packages/opencode/src/cli/cmd/session.ts — data-derived widths, a rule under the header, no colour.

packages/web/src/content/docs/cli.mdx gains a short --verbose example. English only — recent docs PRs (#38395, #33279) touch only the English file and the translated copies are regenerated separately.

Two points where I took a narrower line than #50513's bullets, both raised as open questions on the issue for a maintainer to settle: the table is behind --verbose rather than replacing the default output, and it emits no colour. Happy to change either.

How did you verify your code works?

  • bun run --cwd packages/opencode src/index.ts models > after.txt against the same binary built from dev — output is byte-identical, so the scriptable path is unchanged.
  • bun run --cwd packages/opencode src/index.ts models --verbose and … models <provider> --verbose against a config with three providers and 80+ models; checked alignment, and cat -A to confirm no trailing whitespace.
  • opencode models nope --verbose still exits 1 with Provider not found.
  • bun test test/cli/ — the whole CLI suite: 372 pass, 5 skip, 0 fail.
  • bun test test/cli/cmd/models.test.ts — a new unit test covers the formatter: column alignment, no trailing whitespace, the provider-prefixed model id, cost/limit/capability rendering, and a provider with no models. I checked the alignment assertion by dropping the padEnd and confirming it fails.
  • bun turbo typecheck --filter=opencode passes; oxlint on the file reports the same single pre-existing warning as on dev; prettier --check is clean.

Screenshots / recordings

Output is plain text. The table above is a verbatim paste of a real run, and the one in cli.mdx was generated by calling the formatter rather than drawn by hand.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Previous revision of this PR also changed the TUI /models dialog. CONTRIBUTING requires a design review for UI changes, so that half is dropped from here; it is already tracked in #47600.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 22, 2026
opencode models --verbose printed JSON.stringify(model, null, 2) for
every model, which is unreadable once several providers are configured.

It now prints one aligned table per provider, with the columns the model
catalog already carries: model id, name, base cost per 1M tokens, context
and output limits, and capabilities.

Default output is unchanged: the same plain provider/model lines on
stdout, so existing pipelines keep working.
@fede-kamel
fede-kamel force-pushed the fix/models-formatting branch from 5fe0ea0 to 04717dc Compare September 22, 2026 04:57
@fede-kamel fede-kamel changed the title fix(opencode): format /models CLI and TUI dialog maximize fix(cli): format opencode models --verbose as a table Sep 22, 2026
@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Sep 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Asserts column alignment, the absence of trailing whitespace, the
provider-prefixed model id, cost/limit/capability rendering, and the
empty-provider case.
Documents what --verbose prints now, and states that the default output
is still one plain provider/model per line so it can be piped.
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.

cli: opencode models output is unreadable — no grouping, no names, --verbose dumps raw JSON

1 participant