Skip to content

feat(tui): surface compaction progress and context usage indicators - #32927

Closed
MoerAI wants to merge 4 commits into
anomalyco:devfrom
MoerAI:compaction-progress
Closed

MoerAI wants to merge 4 commits into
anomalyco:devfrom
MoerAI:compaction-progress

Conversation

@MoerAI

@MoerAI MoerAI commented Jun 19, 2026

Copy link
Copy Markdown

DRAFT: opening as DRAFT pending design approval for the linked feature request. Fixes #32926

Maintainer disclosure: I maintain oh-my-openagent, a community OpenCode plugin. This is a community contribution, not an OpenCode team change.

What and why

Compaction can make the TUI look frozen today, especially during /compact or auto-compaction. This PR adds two honest indicators: an always-on context countdown from existing token and model-window data, and a compaction operation indicator while compaction is running. When the threshold is computable, the countdown renders Context NN% · auto-compact ~MM%, mirroring overflow.ts usable() with the default reserved buffer. The operation indicator is gated behind experimentalEventSystem, so default UX is unchanged when the flag is off. It shows elapsed time and an indeterminate bar, not a fake operation percent or ETA.

What's in this PR

  1. feat(core): add compacting session status variant
    • Adds the compacting status variant in status.ts.
    • Updates consumers and regenerates the SDK type output.
  2. feat(opencode): emit compacting status across compaction lifecycle
    • Sets and restores status across manual and auto compaction.
    • Uses lifecycle-safe restore via Effect.ensuring.
    • Guards busy writes so compaction is not overwritten mid-stream.
    • Keeps emission behind experimentalEventSystem.
  3. feat(tui): add compaction progress and context countdown indicators
    • Adds two opentui components.
    • Wires both into the session bottom area.
    • Shows Context NN% · auto-compact ~MM% when the threshold can be computed.
  4. test(opencode): cover compaction status lifecycle and TUI indicators
    • Adds server lifecycle coverage.
    • Adds deterministic opentui buffer tests for both indicators.

How I verified it

  • cd packages/opencode && bun typecheck
    • Exit 0.
  • cd packages/tui && bun typecheck
    • Exit 0.
  • cd packages/opencode && bun test test/session/compaction.test.ts
    • Passes. The lifecycle suite covers manual compaction, auto compaction, failure restore with no stuck status, flag-off behavior, and the busy-overwrite guard.
    • I also verified the busy-overwrite guard with a negative control by temporarily removing the processor stream-start guard and confirming the new test failed before restoring the source.
  • cd packages/opencode && bun test test/session/
    • Passes: 368 pass, 7 skip, 0 fail.
  • cd packages/tui && bun test test/component/compaction-indicators.test.tsx
    • Passes: 7 pass.
    • Covers active and inactive states, animations-off fallback, narrow-width bar drop, Context 80%, the marker Context 90% · auto-compact ~90%, clamp to Context 100%, and hidden output when the model window is unknown.
  • cd packages/opencode && bun test
    • Full package run was executed. Compaction and status tests passed. The remaining httpapi PTY timeout is proven pre-existing on base 5d0f866 and sits outside this change.
  • cd packages/tui && bun test
    • Full package run was executed. The compaction indicator tests were not among failures. The sync failures are proven pre-existing on base 5d0f866; for example, sync.test.tsx reports 0 pass and 2 fail on base from unrelated SolidJS context-provider issues. This branch never touched those files, so it introduces zero new failures.
  • OPENCODE_EXPERIMENTAL_EVENT_SYSTEM=1 bun dev
    • Live TUI was driven through tmux.
    • Sent say hi, saw the model reply, token usage, spend, and the Context 5% · auto-compact ~97% countdown.
    • Ran /compact and captured both indicators in the same real TUI frame: the operation indicator counting Compacting conversation... 3s then 4s with the indeterminate bar, alongside the countdown.
    • After compaction, the completed Compaction, Claude Opus 4.8 (1M Max), 6.4s line appeared. The full sequence is in the recording under UI evidence.

Note: the live run and recording used bun dev, which CONTRIBUTING documents as the development equivalent of the CLI.

UI evidence

Live screen recording of the real TUI during /compact, captured with asciinema and agg from an OPENCODE_EXPERIMENTAL_EVENT_SYSTEM=1 bun dev session:

compaction progress and context countdown in the opencode TUI

The recording shows the operation indicator ticking Compacting conversation... 3s then 4s with the indeterminate bar, the completed Compaction, Claude Opus 4.8 (1M Max), 6.4s line, and the always-on Context 5% · auto-compact ~97% countdown throughout.

Branch and commit recap

  • Branch: compaction-progress, based on dev.
  • Commits: 4 focused commits on dev.
  • Target branch: dev, not master.
  • This is a draft PR linked to the feature request. I am not asking for merge before design approval.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 19, 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

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 Jun 19, 2026
@github-actions github-actions Bot closed this Jun 19, 2026
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.

[FEATURE]: Surface compaction progress and live context usage in the TUI

1 participant