Repository navigation
feat(quickstart): add statusline live preview section - #438
Conversation
`tj quickstart` now renders a self-contained "what you'd see live" section between the quota-composition panel and the session timeline: the exact `tj statusline` line the user's own most-recent substantial session would have shown at the turn its cumulative re-read share first crossed the nudge threshold. Selection favors the most-recent session with at least PREVIEW_MIN_TURNS turns, falling back to the largest recent crossing session, and omits the section silently if none ever crosses. Reuses the real statusline formatter end-to-end instead of duplicating it: cmd_statusline.render_line is refactored to build on a new format_status_line(model_name, total, reread_pct) so the preview can never render text the live product wouldn't. core/usage.py gains iter_assistant_turns (usage + raw model per record) and iter_cumulative_usage (running last-wins totals per turn), extracted behind a shared _iter_assistant_records filter so iter_assistant_usage's existing 2-tuple contract and tests are untouched. Co-Authored-By: Claude <[email protected]>
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_quickstart.py | Adds the statusline live-preview section. The early-return-on-substantial-candidate logic in _select_preview_session is correct. Two minor findings: _display_model_name's final fallback returns raw (with build-date stamp) instead of stripped, and _walk_for_preview could break early once crossing+turns threshold are both met. |
| tokenjam/cli/cmd_statusline.py | Refactors render_line to call the new shared format_status_line helper; behaviour-preserving with a byte-identical output test. |
| tokenjam/core/usage.py | Introduces _iter_assistant_records, iter_assistant_turns, and iter_cumulative_usage. Dedup arithmetic is correct; existing iter_assistant_usage contract untouched. |
| tests/unit/test_quickstart.py | Five focused preview tests covering all selection branches and byte-identical formatter reuse. |
| tests/unit/test_statusline.py | Adds format_status_line unit tests including byte-identical match against render_line. |
| tests/unit/test_usage.py | Covers iter_assistant_turns and iter_cumulative_usage including growing-snapshot dedup and final-total invariant. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant QS as cmd_quickstart
participant SP as _select_preview_session
participant WP as _walk_for_preview
participant CU as iter_cumulative_usage
participant RP as _render_statusline_preview
participant FS as format_status_line
QS->>SP: timeline, root
loop sessions (most-recent-first)
SP->>WP: transcript path
WP->>CU: file handle
CU-->>WP: (turn_index, model, cumulative_usage)
WP-->>SP: "(turns, first_crossing | None)"
alt "turns >= PREVIEW_MIN_TURNS AND crossing found"
SP-->>QS: _PreviewCandidate (early return)
else crossing found but not substantial
SP->>SP: append to fallback candidates
end
end
SP-->>QS: "largest-by-turns candidate (fallback) | None"
QS->>RP: picked candidate
RP->>FS: model_name, total, reread_pct
FS-->>RP: statusline string
RP->>RP: console.print preview block
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant QS as cmd_quickstart
participant SP as _select_preview_session
participant WP as _walk_for_preview
participant CU as iter_cumulative_usage
participant RP as _render_statusline_preview
participant FS as format_status_line
QS->>SP: timeline, root
loop sessions (most-recent-first)
SP->>WP: transcript path
WP->>CU: file handle
CU-->>WP: (turn_index, model, cumulative_usage)
WP-->>SP: "(turns, first_crossing | None)"
alt "turns >= PREVIEW_MIN_TURNS AND crossing found"
SP-->>QS: _PreviewCandidate (early return)
else crossing found but not substantial
SP->>SP: append to fallback candidates
end
end
SP-->>QS: "largest-by-turns candidate (fallback) | None"
QS->>RP: picked candidate
RP->>FS: model_name, total, reread_pct
FS-->>RP: statusline string
RP->>RP: console.print preview block
Reviews (2): Last reviewed commit: "fix(quickstart): stop early on substanti..." | Re-trigger Greptile
…nal unpack Two Greptile findings on PR #438: - _select_preview_session walked every candidate's full transcript even though sessions are most-recent-first and the first substantial crossing candidate always wins. Return as soon as one is found instead of building the full candidate list — the largest-by-turns fallback only runs when no substantial candidate exists, so nothing is skipped. Added a test that stubs _walk_for_preview to count calls and asserts older sessions are never walked once the newest already qualifies. - picked.crossing is typed Optional; guard the unpack with an assert documenting the invariant (only crossing candidates are ever selected) instead of unpacking directly. Co-Authored-By: Claude <[email protected]>
Combining #437 (ticket-119: aggregate reclaim line, never names a past session) with #438 (statusline live preview: shows the exact statusline line one concrete named session would have triggered, by design) broke CI: test_quickstart_reclaim_section_is_aggregate_not_named_sessions asserted "sess-heavy" absent from the ENTIRE quickstart output, which was true when #437 was authored (quickstart never named a session anywhere) but stopped being true once #438 added a later section that intentionally names its preview session as a concrete "what you'd have seen live" example — itself covered by dedicated #438 tests (`test_quickstart.py` asserts "session sess-recent would have shown this at turn 3" / "session sess-old ... turn 5"). Both invariants are correct and neither feature should be reverted: the quota-composition PANEL must never name a session (#119's actual intent — see the "(#119)" comment at cmd_quickstart.py's aggregate line), while the separate, later statusline-preview section legitimately does. Scoped the assertion to the panel's own text (everything before the preview section's fixed intro, "With the statusline installed") instead of the whole rendered output. Co-Authored-By: Claude <[email protected]>
Summary
Adds a "what you'd see live" statusline preview section to
tj quickstart— the zero-install first touch that reads~/.claude/projects/*.jsonl. For the user's own most-recent substantial session, it renders the exacttj statuslineline that would have appeared at the turn cumulative re-read share first crossed the nudge threshold, then ties it totj onboard.cmd_statusline.render_lineis refactored into a sharedformat_status_line(model_name, total, reread_pct), so the preview and the live statusline can never render different text for the same figures.core/usage.iter_assistant_turns(usage + raw model per record) andcore/usage.iter_cumulative_usage(running last-wins cumulative totals per turn), both built on a new shared_iter_assistant_recordsfilter.iter_assistant_usage's existing 2-tuple contract and its tests are untouched.>= PREVIEW_MIN_TURNS(20) turns that crosses the re-read nudge threshold; if none is "substantial" enough, falls back to the largest (by turns) session that still crosses it; if no session ever crosses, the section is omitted silently.cmd_quickstart.py.Rendered output (real run against my own
~/.claude/projects)Merge order
Another concurrent branch is concurrently editing the SAME
_renderfunction incmd_quickstart.py— fixing the quota-composition headline math and deleting the "Biggest reclaim opportunities" section. This PR does not touch that code (composition box / compact-candidates section); the new preview is a self-contained addition placed between the composition panel and the session timeline. that branch's PR is expected to merge first — this branch will need a rebase afterward.Test plan
make test(full suite: unit + synthetic + agents + integration) — 2175 passed, 1 skipped, 0 failedruff check tokenjam/— cleanmypy tokenjam/cli/cmd_quickstart.py tokenjam/cli/cmd_statusline.py tokenjam/core/usage.py— cleantests/unit/test_usage.py:iter_assistant_turns(model surfaced, same filter asiter_assistant_usage),iter_cumulative_usage(accumulates across turns, growing snapshot doesn't advance turn count, final cumulative total matchessession_usage)tests/unit/test_statusline.py:format_status_linedegrades to model-only with no figures; byte-identical output torender_linefor the same inputs (formatter-reuse guarantee)tests/unit/test_quickstart.py: preview picks the most-recent substantial crossing session over an older-but-bigger one; falls back to the largest crossing session when none is substantial; omits the section when no session ever crosses the threshold; omits when there are no sessions at all; asserts the rendered line is byte-identical toformat_status_line's own output for the crossing turn's figuresCliRunneragainst my own~/.claude/projects(pasted above)🤖 Generated with Claude Code