Skip to content

feat(tui): add response tokens/sec, paste expand command, and context usage dialog - #37052

Closed
SakshamKapoor2911 wants to merge 3 commits into
anomalyco:devfrom
SakshamKapoor2911:tui-enhancements
Closed

SakshamKapoor2911 wants to merge 3 commits into
anomalyco:devfrom
SakshamKapoor2911:tui-enhancements

Conversation

@SakshamKapoor2911

Copy link
Copy Markdown

Closes #6096, closes #8501, closes #6152

Type of change

  • New feature

What does this PR do?

Three TUI improvements:

  1. Tokens/sec in response footer — calculates total tokens across all categories divided by wall-clock duration, displayed after the duration in assistant message footers.

  2. Paste expand command — prompt.toggle_paste_expand expands all [Pasted ~X lines] placeholders inline using the existing expandTrackedPastedText helper. Available from command palette.

  3. Session context dialog — new dialog accessible via /context showing context window bar, token breakdown (input/output/reasoning/cache), cost, and per-message usage.

How did you verify your code works?

  • Typecheck in packages/tui passes with no new errors
  • All changes scoped to packages/tui/ — no server/protocol/SDK changes
  • Uses existing APIs: expandTrackedPastedText for paste expansion, sync store data for context dialog

Screenshots / recordings

UI changes — no screenshots yet, pending local verification.

Checklist

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

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on the search results, I found one potentially related PR that overlaps with this PR's features:

Related PR:

However, the current PR (#37052) is the most recent and comprehensive implementation that combines three improvements. The older PR #12721 appears to address only one of the three features being added in the current PR.

Also found:

The current PR (#37052) appears to be the main implementation PR. You may want to check if PR #12721 was superseded or merged, and whether #33700 should be referenced alongside this new PR.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 15, 2026
@github-actions github-actions Bot closed this Jul 15, 2026
hunterchristian added a commit to chipp-ai/opencode that referenced this pull request Sep 23, 2026
Shows generation speed while an assistant response streams
(refreshing every 500ms) and a final rate once the turn completes.

Ported from upstream anomalyco#5374 (111 reactions): the
footer placement/refresh approach and the ~4-chars/token live
estimate come from PR anomalyco#46882 (closed by the 2-hour PR-template bot,
same day, never reviewed); the "show a rate after completion too"
idea comes from PR anomalyco#37052 (a bundled PR with an unrelated paste-
expand feature -- only the tokens/sec piece used). anomalyco#37052's own
final-rate formula was rewritten here because it counted input and
cache tokens, badly inflating the number -- this counts only output
and reasoning tokens. New: the measurement window starts at the first
streamed token rather than message creation, and stops at the last
finished text/reasoning part, so time-to-first-token and tool
execution time don't distort the rate.

New packages/tui/src/util/throughput.ts (~40 lines). Known gaps: the
live number is a character-count estimate, not exact (providers only
report real token counts at step-finish); each tool step gets its own
footer so the rate shown is per-step, not averaged across a turn; an
interrupted response shows no rate.

New packages/tui/test/util/throughput.test.ts (9 tests). Full
packages/tui suite: 208 pass. bun typecheck clean.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
hunterchristian added a commit to chipp-ai/opencode that referenced this pull request Sep 23, 2026
A pasted [Pasted ~N lines] placeholder in the prompt can now be
expanded to its full content and collapsed back -- click it, or run
"Expand/collapse pasted text" (prompt.paste.toggle) from the palette
or a keybind.

Ported from upstream anomalyco#8501 (325 reactions -- the
highest of any issue found across a full survey of this repo's open
issues). A trivial 1-file fix already merged upstream as anomalyco#39920 isn't
even on this fork's history and is a one-way, no-collapse expand
anyway, not the real ask. Richer attempts were all closed by the
automated PR-cleanup bot and never reviewed:

- PR anomalyco#41813 "paste expand toggle" is the primary source: a pasted-
  text part remembers its original placeholder so it can collapse
  again, the chip is swapped by deleting its extmark, replacing the
  selected text, and recreating the extmark over the new text.
- PR anomalyco#33700 fixed a real, separate bug reused as-is:
  expandPastedTextPlaceholders substituted text back in via
  String.replace(str, str2), which treats $&/$$/etc. in the pasted
  text as special replacement patterns and silently corrupts it --
  fixed by passing a replacer function instead of a literal string.
- PR anomalyco#37052 contributed only the idea of a palette command to expand
  chips (its own version was one-way, expand-all); this fork's
  version is a proper per-chip toggle.

New: older saved prompts with no stored placeholder can still be
expanded (anomalyco#41813's version would lock them collapsed-only). Two pure
functions (togglePastedText, replaceVirtualExtmarkText) were extracted
into packages/tui/src/prompt/part.ts so anomalyco#41813's logic is unit-
testable outside the full Prompt component.

Known gaps: the full Prompt component's mouse-click path has no
automated test (no existing fixture mounts it with SDK/sync/route
providers -- checked manually against a bare textarea instead);
clicking a chip's very last character can miss the same way it does
in anomalyco#41813; an expanded chip is viewable but not editable in place.

New tests in packages/tui/test/prompt/part.test.ts and a new
packages/tui/test/prompt/paste-toggle.test.tsx (using this repo's
existing testRender/mockMouse helpers). Verified against this fork's
current dev (not just the agent's own stale worktree base): bun
typecheck clean; full packages/tui suite 215 pass.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant