Repository navigation
[feature] tj optimize: scoreboard by default, full cards behind -v - #691
Merged
Merged
Conversation
`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]>
Contributor
|
| 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]
Reviews (7): Last reviewed commit: "Merge branch 'main' into optimize-output" | Re-trigger Greptile
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tj optimizeprinted 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.
tj optimizetj optimize <area>tj optimize -vtj optimizeprinted before.--jsonis unchanged.Neither
<area>nor-vis new surface area; both were unreachable defaults. Analyzer names are already positional args totj optimize, and the global-v/--verbosewas defined but never read by this command.Before / after
Bare
tj optimize, same window, same data:That same run previously emitted ~120 lines. It is now reachable, unchanged, as
tj optimize -v.Where the rows come from
A
_FINDING_SUMMARIESdict beside_FINDING_RENDERERSincmd_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 newsummaryfield 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:
estimate_basisorcoverage_noteis 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.—null marker, never0and never an empty cell. Zero reads as "no waste", which is the opposite claim. This goes throughrender_savings, which already returns that marker for a missing figure, so an absent estimate cannot surface as a number.stream-usageis 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.N analyzers · M findingsheader, 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
accentrole. 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 sharedmake_table, so--no-color,NO_COLORand 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
-vto their invocation, not by deleting assertions —-vreproduces that output exactly, which is what makes the migration honest. Five tests intests/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-usagenever 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.pyadds the three-view test (scoreboard vs-vvs<area>, including that the verbatim caveat renders in both card paths) and a pin that--jsonis unchanged by the flag and leaks no scoreboard string.All three views were run against a seeded throwaway DuckDB under an isolated
HOME, never the real~/.tj.What's NOT in this PR
estimate_basis,coverage_noteandcaveatis produced and worded exactly as before; only which screen prints them moved.--json,--compare,--export-config,--validateor the daemon/API-shim path. The verbosity flag is read after the JSON early return, so it cannot reach the payload.<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