Skip to content

[feature] tj optimize: scoreboard by default, full cards behind -v - #691

Merged
anshss merged 8 commits into
mainfrom
optimize-output
Aug 4, 2026
Merged

anshss merged 8 commits into
mainfrom
optimize-output

Conversation

@anshss

@anshss anshss commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

tj optimize printed every finding card in full on every run: candidate lists, verbatim caveats, multi-hundred-word methodology paragraphs, coverage notes. Nothing in that output was wrong, but the screen asserted no hierarchy over it, so the headline numbers, the per-area findings and the next command all landed at equal weight across several pages of justified prose.

Summary

Three views over the existing renderer set. No analyzer changes.

Command Output
tj optimize Scoreboard: header, findings table, Next block. Never calls a card renderer.
tj optimize <area> That one analyzer's card, full detail, renderer unchanged.
tj optimize -v Byte for byte what a bare tj optimize printed before.

--json is unchanged.

Neither <area> nor -v is new surface area; both were unreachable defaults. Analyzer names are already positional args to tj optimize, and the global -v/--verbose was defined but never read by this command.

Before / after

Bare tj optimize, same window, same data:

  100 sessions · 38.6M tokens · Max 20x plan ($200/mo)
  Implied API value $674, about 3.4× your plan cost.
  5 analyzers · 2 findings

  ANALYZERS   FINDING                        RECOVERABLE
 ────────────────────────────────────────────────────────
  downsize    60 downsize candidates         $97.69
  resend      92% of prompt tokens re-sent   —

  Estimates carry method notes and caveats. See tj optimize <analyzer>.

  Next:  tj relearn cost-proposals   3 copy-paste fixes
         tj optimize downsize        which sessions
         tj optimize -v              every finding in full

That same run previously emitted ~120 lines. It is now reachable, unchanged, as tj optimize -v.

Where the rows come from

A _FINDING_SUMMARIES dict beside _FINDING_RENDERERS in cmd_optimize.py, one summarizer per analyzer returning the finding line plus a short hint for the Next block. They live in the CLI layer rather than as a new summary field across fifteen analyzer modules: the one-liner is a presentation concern of this one screen, and the analyzers stay the single source of the prose that has to render verbatim.

Honesty rails

This is a summary, not a rewrite, and the difference is enforced:

  • A caveat, estimate_basis or coverage_note is never paraphrased onto the scoreboard. It carries one pointer line at the card that prints them verbatim; the card path (<area> and -v) is untouched.
  • A finding with no priced figure shows the — null marker, never 0 and never an empty cell. Zero reads as "no waste", which is the opposite claim. This goes through render_savings, which already returns that marker for a missing figure, so an absent estimate cannot surface as a number.
  • stream-usage is forced unpriced. Its figure is spend that already happened and was never recorded, not a saving. A data-quality number sitting in a savings column is read as a saving.
  • An analyzer that ran and found nothing gets no row, but is still counted in the N analyzers · M findings header, so silence is never ambiguous. The analyzer notes and the "deadweight, relearn and summarize did not run" line still print.

Formatting

Colour goes on typeable commands only, through the existing accent role. The recoverable figure is weight (label), not colour: the accent role means "a string the user can type" and nothing else. No raw colour literals; the table is the shared make_table, so --no-color, NO_COLOR and non-TTY all degrade to plain aligned text through the shared console. The — in the RECOVERABLE column is a null marker, not prose punctuation, and a test asserts nothing else on the screen uses one.

Tests / Verification

Existing pins on the full rendering are migrated by adding -v to their invocation, not by deleting assertions — -v reproduces that output exactly, which is what makes the migration honest. Five tests in tests/integration/test_cli.py.

New tests/unit/test_optimize_scoreboard.py (12 tests) covers: header counts, one row per finding, the Next block; that the caveat and estimate basis are absent from the scoreboard while the pointer at them is present; that the candidate detail the card carries is omitted; the — marker for an unpriced finding and the "never $0" half; stream-usage never borrowing the savings column; a clean analyzer producing no row while still being counted; the subscription / unknown-plan framings; no em-dash prose; and that the columns stay aligned with colour off.

tests/integration/test_cli.py adds the three-view test (scoreboard vs -v vs <area>, including that the verbatim caveat renders in both card paths) and a pin that --json is unchanged by the flag and leaks no scoreboard string.

tests/unit -k optimize          246 passed
tests/integration/test_cli.py   105 passed (with test_cmd_route, test_cli_api_framing_parity)
tests/unit/test_cli_palette.py  320 passed (with the printed-string guards)
ruff + mypy on tokenjam/        clean

All three views were run against a seeded throwaway DuckDB under an isolated HOME, never the real ~/.tj.

What's NOT in this PR

  • No analyzer changes. Every estimate_basis, coverage_note and caveat is produced and worded exactly as before; only which screen prints them moved.
  • No change to --json, --compare, --export-config, --validate or the daemon/API-shim path. The verbosity flag is read after the JSON early return, so it cannot reach the payload.
  • The <area> card keeps its existing header ("Analyzing N sessions, …"). The scoreboard's more compact header is scoped to the scoreboard; unifying them would change output the migrated tests pin.

🤖 Generated with Claude Code

`tj optimize` printed every finding card in full on every run: candidate
lists, verbatim caveats, multi-hundred-word methodology paragraphs. Nothing
in that output was wrong, but the screen asserted no hierarchy over it, so
the headline numbers, the per-area findings and the next command all landed
at equal weight across several pages of justified prose.

Three views over the existing renderer set, no analyzer changes:

  tj optimize          the scoreboard: header, findings table, Next block
  tj optimize <area>   that one card, in full, renderer untouched
  tj optimize -v       byte for byte what a bare run printed before

Both `<area>` and `-v` already existed and were simply unreachable defaults:
analyzer names are already positional args, and the global -v was never read
by this command. `--json` is untouched.

The one-line summaries live in the CLI layer (a `_FINDING_SUMMARIES` dict
beside `_FINDING_RENDERERS`) rather than as a new `summary` field on fifteen
analyzer findings, because they are a presentation concern of this one screen
and the analyzers must stay the single source of the prose that renders
verbatim.

Honesty rails, which are why this is a summary and not a rewrite:

* a caveat, estimate basis or coverage note is never paraphrased onto the
  scoreboard. It carries a pointer at the card that prints them verbatim;
* a finding with no priced figure shows the null marker, never 0 and never
  an empty cell, since zero reads as "no waste";
* `stream-usage` is forced unpriced: its figure is spend that already
  happened and was never recorded, and a data-quality number sitting in a
  savings column is read as a saving;
* an analyzer that ran and found nothing gets no row, and the
  "N analyzers, M findings" header line carries the did-it-run signal so
  silence is never ambiguous.

Colour stays on the typeable commands only. The recoverable figure is weight,
not colour, because the accent role means "a string you can type" and nothing
else.

Tests: the existing pins on the full rendering are migrated by adding -v to
their invocation, not by dropping assertions. New coverage for the scoreboard
itself, both honesty rails, the plan-tier framings, no-colour alignment, and
that --json is unchanged by the flag.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@anshss
anshss requested a review from anilmurty as a code owner August 4, 2026 14:05
@greptile-apps

greptile-apps Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the default verbose tj optimize and tj status output with concise scoreboard views while preserving detailed cards behind drill-down commands and -v.

  • Adds finding summaries, recoverable-value ordering, caveat pointers, and next-step commands to the optimize scoreboard.
  • Adds a capped agent overview to tj status, with individual and verbose card paths.
  • Extends shared table formatting and migrates integration and unit coverage across all output modes.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
tokenjam/cli/cmd_optimize.py Adds the default optimize scoreboard, per-analyzer summaries, recoverable-value sorting, and explicit verbose/card routing while retaining existing JSON behavior.
tokenjam/cli/cmd_status.py Adds a capped default agent overview while preserving individual-agent and verbose card rendering.
tokenjam/utils/formatting.py Updates shared table formatting used by the new compact CLI views.
tests/unit/test_optimize_scoreboard.py Covers scoreboard counts, summaries, pricing markers, caveat omission, next commands, and plain-text alignment.
tests/integration/test_cli.py Migrates detailed-output assertions to verbose mode and verifies default, drill-down, verbose, and JSON behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[tj optimize] --> B{Output mode}
  B -->|--json| C[Existing JSON payload]
  B -->|Named analyzer| D[One full finding card]
  B -->|-v / --verbose| E[All full finding cards]
  B -->|Default| F[Scoreboard]
  F --> G[Header and analyzer counts]
  F --> H[Ranked findings table]
  F --> I[Next commands]
Loading

Reviews (7): Last reviewed commit: "Merge branch 'main' into optimize-output" | Re-trigger Greptile

Comment thread tokenjam/cli/cmd_optimize.py Resolved
anshss and others added 7 commits August 4, 2026 19:51
…ind -v

`tj status` printed one ~9-line card per tracked agent_id with no cap, no
pointer at what it left out, and no cross-agent totals until the very last
line, after the reader had already scrolled past everything those totals
summarise. On a real corpus that is 3044 lines for 304 agents. The agent_id
set grows monotonically (roughly one per project directory tj has ever seen),
so the screen gets longer the longer you use tj, and is worst for the heaviest
user, who is exactly the one with something to find in it.

Two views over the same data, mirroring what `tj optimize` just became:

  tj status              the overview: totals, capped table, trailer
  tj status --agent <id> that one agent's card, in full, renderer untouched
  tj status -v           byte for byte what a bare run printed before

Both were already reachable and simply unreachable defaults: `--agent` is an
existing option on this command, and the global `-v` was never read by it.
`--json` is untouched, and so is the exit code (1 while unacknowledged alerts
exist).

Rows rank by RECENCY, live sessions above everything, not by cost. Cost today
is $0.00 for nearly every tracked agent on a normal day, so a cost ranking
would order the handful of agents the user actually worked in today
arbitrarily below a tie of hundreds of zeroes. Recency is defined for every
agent that has ever run and matches how the user thinks about the list.

Honesty rails on the cells, since a table asserts more per character than a
card does:

* an agent with no alerts shows the null marker, never `0` and never an empty
  cell, on the same reasoning a `$0` savings figure reads as "no waste";
* an agent with no recorded session shows the marker rather than being handed
  an invented timestamp, and sorts last on that basis;
* the per-session token counts and the daily-budget suffix stay on the card:
  a per-session figure sitting beside a today-scoped dollar column is two
  figures over two populations published as one row;
* the agent_id column elides from the LEFT, keeping the distinguishing tail,
  because these ids share a long leading run and right-truncation renders a
  screen of identical rows.

The cap itself is a shared helper (`print_capped_table` in
utils/formatting.py) rather than logic private to this command: pricing,
tools, summarize, backfill, session-story, loop, relearn and report all print
unbounded per-entity listings and can adopt it. `more_command` is required
rather than optional, because a caller that cannot name the drill-down has no
business capping its output.

Colour on the lines touched goes through the named theme roles (Critical Rule
35): the active-agent glyph is weight, not green.

Tests: the existing pins on the card rendering are migrated by adding -v to
their invocation, not by dropping assertions. New coverage for the cap and its
trailer, totals-before-rows, the recency ranking, both null-marker rails, the
drill-down command actually resolving, and the shared helper on its own.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The scoreboard's rows came straight out of `_rank_findings`, which orders by
reclaimable TOKEN share. That is the right order for the card path it was
written for (it also drives the de-minimis pointer collapsing there) and the
wrong one for a table whose visible column is dollars: on a real corpus it
rendered

  summarize   54 summarizable prompt files   $48.55
  downsize    110 downsize candidates        $296.74

so a $48 row sat above a $296 one. A table sorted by a quantity it does not
show reads as unsorted, and the Next block names `rows[0]`, so the same defect
also mis-aimed the one command the screen tells the user to run.

The rows are now re-sorted on the figure the RECOVERABLE column actually
prints, with the token-share rank kept only as a deterministic tie-break.
`_rank_findings` itself is untouched, since the card path still wants its
ordering.

`_scoreboard_sort_value` mirrors `_scoreboard_recoverable` field for field,
including which figure each pricing mode renders (`local` shows tokens,
everything else dollars) — a sort key read from a different field than the
column displays is the same defect wearing a different hat. It returns None
for anything the column renders as the null marker, so an unpriced row sorts
to the bottom and keeps its marker: a finding with no figure is not a finding
worth nothing.

Tests: the ordering under both pricing modes, unpriced rows landing last with
their marker intact, and the Next block pointing at the largest recoverable
finding.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The scoreboard publishes a column of dollar figures and no total. That was
the right call and the screen never said why, which leaves the reader to do
the sum in their head instead.

The analyzers price overlapping angles on the SAME sessions. `downsize`
deliberately excludes `sub_agent_id IS NOT NULL` spans because `subagent`
already prices the identical model swap over them, and `summarize` keeps a
figure out of its own `past_overspend_usd` on the same grounds. Adding the
column therefore sums waste that was measured twice.

This is already solved once, at `api/routes/cost.py`: that route labels its
sum a gross ceiling, ships `recoverable_additive: False` beside it, and
publishes `largest_recoverable_usd` as the one entry that "isn't a sum of
anything". The terminal now carries the substance of that route's
`_recoverable_overlap_note`, condensed to fit a screen, rather than a second
hand-written version of the same idea.

No total is printed, and none should be. Sorting the column descending
already puts the largest single lever on top, and that row is the honest
standalone number: acting on it alone recovers at least that much.

The note renders through `Padding` rather than a two-space prefix, since it
is the one line here long enough to wrap and a literal prefix indents only
the first line. It appears only with two or more PRICED rows, mirroring
`_recoverable_overlap_note` returning empty below two entries: one figure and
one null marker is not two overlapping estimates.

Tests: no summed figure anywhere in the output, the disclosure present with
two priced rows, and absent when the second row is unpriced.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… advertise

`tj status`'s trailer prints "All of them: tj status -v" and the optimize
scoreboard's Next block prints "tj optimize -v". Both exited 2:

  $ tj status -v
  Error: No such option '-v'.

`--verbose` is declared on the top-level group (main.py) and stored in
`ctx.obj`, so `tj -v status` worked and the advertised form did not. Reading
`ctx.obj["verbose"]` is not the same as accepting the flag, and nothing caught
it because a renderer will print any string it is given.

This is worse than the uncapped output these screens replaced. The escape
hatch is the entire justification for capping a view, so a next-step command
that does not run makes the cap a claim the product cannot honour.

Both commands now declare `-v/--verbose` themselves and OR it with the
group's copy, so `tj status -v` and `tj -v status` are the same command and
neither shadows the other. Two booleans meaning the same thing have no
precedence question to resolve.

Verified by running every command string this branch prints:

  tj status -v                       3043 lines (cards)
  tj -v status                       3043 lines (cards)
  tj status --agent <id>             13 lines (that agent's card)
  tj optimize -v                     271 lines (cards)
  tj -v optimize                     271 lines (cards)
  tj optimize subagent               exit 0, the subagent card
  tj relearn cost-proposals          exit 0, 21 proposals

The standing guard parses command strings out of the RENDERED screens rather
than from a hand-kept list, so new copy is covered the moment it is printed,
and checks each against the real Click command tree. It carries its own
negative controls: an undeclared option and a non-existent subcommand must
both fail it, which is what pins that the eager `--help` used to reach the
parser does not mask a bad option and leave every assertion vacuous.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…st be pinned invocable

Promotes the durable half of the -v defect: both capped screens printed a
next-step command that exited 2, because the flag was declared on the group
and only read from ctx.obj by the subcommand. The rule states the general
form (a cap makes its escape hatch load-bearing) and names the guard that
enforces it, so the rule points at its own test.

Appended as the next free number. 43 was taken by the plugin-residency rule
that landed in the meantime, which is why this is 44; nothing was renumbered
or reordered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@anshss
anshss merged commit 966712d into main Aug 4, 2026
6 checks passed
@anilmurty
anilmurty deleted the optimize-output branch September 18, 2026 21:03
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