Skip to content

feat(quickstart): add statusline live preview section - #438

Merged
anshss merged 2 commits into
ticket-120from
statusline-preview
Jul 9, 2026
Merged

anshss merged 2 commits into
ticket-120from
statusline-preview

Conversation

@anshss

@anshss anshss commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

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 exact tj statusline line that would have appeared at the turn cumulative re-read share first crossed the nudge threshold, then ties it to tj onboard.

  • Reuses the real statusline rendering code, not a re-derivation: cmd_statusline.render_line is refactored into a shared format_status_line(model_name, total, reread_pct), so the preview and the live statusline can never render different text for the same figures.
  • Added core/usage.iter_assistant_turns (usage + raw model per record) and core/usage.iter_cumulative_usage (running last-wins cumulative totals per turn), both built on a new shared _iter_assistant_records filter. iter_assistant_usage's existing 2-tuple contract and its tests are untouched.
  • Session selection: most-recent session with >= 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.
  • Forward-looking framing only — this previews the live product; it does not imply the (ended) session shown is actionable now.
  • Zero new dependencies; matches the existing Rich-rendering style in cmd_quickstart.py.

Rendered output (real run against my own ~/.claude/projects)

╭─ Where your quota goes ──────────────────────────────────────────────────────╮
│                                                                              │
│  Quota composition  ·  61 sessions, 8880 turns (most-recent 300)             │
│  ...                                                                        │
╰──────────────────────────────────────────────────────────────────────────────╯

With the statusline installed, session 4794cf75-4bd would have shown this at 
turn 5:

  ◆ Fable 5  906.9k tok  ⚠ re-read 70%  → consider /compact

That's live, every turn, for zero model tokens — tj onboard sets it up.

Session timeline (most recent)
...

Merge order

Another concurrent branch is concurrently editing the SAME _render function in cmd_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 failed
  • ruff check tokenjam/ — clean
  • mypy tokenjam/cli/cmd_quickstart.py tokenjam/cli/cmd_statusline.py tokenjam/core/usage.py — clean
  • New unit tests:
    • tests/unit/test_usage.py: iter_assistant_turns (model surfaced, same filter as iter_assistant_usage), iter_cumulative_usage (accumulates across turns, growing snapshot doesn't advance turn count, final cumulative total matches session_usage)
    • tests/unit/test_statusline.py: format_status_line degrades to model-only with no figures; byte-identical output to render_line for 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 to format_status_line's own output for the crossing turn's figures
  • Eyeballed real output via CliRunner against my own ~/.claude/projects (pasted above)

🤖 Generated with Claude Code

`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]>
@anshss
anshss requested a review from anilmurty as a code owner July 9, 2026 13:22
@greptile-apps

greptile-apps Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a "what you'd see live" statusline preview section to tj quickstart, showing users the exact statusline output their most-recent substantial session would have displayed at the turn it first crossed the re-read nudge threshold. It also refactors render_line into a shared format_status_line helper so the preview and the live statusline always render identical text for the same inputs.

  • tokenjam/core/usage.py: Introduces _iter_assistant_records (shared billable-record filter), iter_assistant_turns (adds raw model id to each yield), and iter_cumulative_usage (running last-wins deduped totals per turn).
  • tokenjam/cli/cmd_statusline.py: Extracts format_status_line(model_name, total, reread_pct) from render_line; behaviour-preserving with a byte-identical output test.
  • tokenjam/cli/cmd_quickstart.py: Adds _select_preview_session, _walk_for_preview, and _render_statusline_preview; the early-return-on-substantial-candidate optimisation is already present in _select_preview_session.

Confidence Score: 5/5

Safe to merge — the preview section is self-contained and fails silently, the formatter refactor is behaviour-preserving, and the new usage iterators are well-tested.

All new code paths degrade gracefully (no crossing omits the section, unreadable transcripts are treated as no candidate, unknown model ids fall back to a display string). The render_line refactor is guarded by a byte-identical output test. The two findings are non-blocking suggestions that do not affect correctness or data integrity.

tokenjam/cli/cmd_quickstart.py — specifically _display_model_name's fallback branch and the _walk_for_preview loop exit condition.

Important Files Changed

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
Loading
%%{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
Loading

Reviews (2): Last reviewed commit: "fix(quickstart): stop early on substanti..." | Re-trigger Greptile

Comment thread tokenjam/cli/cmd_quickstart.py Resolved
Comment thread tokenjam/cli/cmd_quickstart.py Resolved
…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]>
@anshss
anshss changed the base branch from main to ticket-120 July 9, 2026 18:42
@anshss
anshss merged commit 6c87111 into ticket-120 Jul 9, 2026
4 checks passed
anshss added a commit that referenced this pull request Jul 9, 2026
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]>
@anilmurty
anilmurty deleted the statusline-preview branch July 29, 2026 23:07
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