[PR #4788] [GUI] Add a context gauge and conversation summaries to browser chat #5178

Open
opened 2026-11-07 16:33:16 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4788
Author: @orangeswim
Created: 10/31/2026
Status: 🔄 Open

Base: main ← Head: gui/gauge-and-compaction


📝 Commits (3)

  • fab52f3 Chat: conversation compaction
  • b907544 Chat: a context gauge by the input
  • d76e90f [Docs] explain chat context gauge and conversation summaries

📊 Changes

12 files changed (+747 additions, -26 deletions)

View changed files

📝 docs/DETAILS.md (+15 -3)
➕ serve/test_compaction.py (+30 -0)
📝 serve/web/app.css (+35 -0)
📝 serve/web/app.js (+201 -13)
📝 serve/web/chats-ui.js (+16 -8)
➕ serve/web/compact-prompt.js (+20 -0)
➕ serve/web/compaction.js (+42 -0)
📝 serve/web/history.js (+8 -2)
📝 serve/web/index.html (+8 -0)
➕ serve/web/test_compaction.mjs (+186 -0)
📝 tools/webtest/browser_test.mjs (+184 -0)
📝 tools/webtest/mock.mjs (+2 -0)

📄 Description

[GUI] Add a context gauge and conversation summaries to browser chat

Problem and result

The browser chat has no context-usage display or command to summarize older messages. This adds a gauge beside the message box and a manual compaction button.

The gauge updates from API-reported token usage after replies, independently of compaction. It warns at 70% and 90% of the context limit. After compaction, it displays an estimate until the next reply supplies a measured count. Local edits do not request a new count.

Compaction asks the model to summarize older messages. They remain visible, while subsequent requests use their summary. Recent messages kept outside the summary retain files, images and tool results. The latest summary card can undo that compaction. Repeated compaction uses the previous summary and newer messages. With Edit and rewind messages enabled, Edit summary changes the summary text without removing other messages or changing which earlier messages it replaces. The edit sends no request and supports Undo.

A long user message (over ten lines or 800 characters) is clamped to about ten lines with a fade; Show all N lines expands it in place, Show less collapses it again.

Split out of #1507 per the tracker reset for 0.2.0-beta: https://github.com/Niko1221/Strata/pull/1507#issuecomment-6444549518. This PR keeps the two related items together — the summary marker's context reading exists to feed the gauge, and the fold's effect is only visible through it. The third item, per-request timings, is filed separately.

Approach

The gauge reads usage.prompt_tokens + completion_tokens from the latest reply (or a fresh marker's post-fold estimate), formats with the existing kfmt/ctxfmt helpers, and sends nothing anywhere. Compaction is one hidden request: compact-prompt.js holds the summary prompt, and compaction.js owns the fold rules (pure, unit-tested) — the cut never crosses an earlier marker, so repeated compactions chain instead of orphaning older context, and the marker records its boundary. The kept window is budgeted on converted API messages, so attachments count, and an oversized paste cannot hijack it — it stays in the summarized part. Compaction, unfold and summary editing follow the existing history-lock rules, and messages queued during a compaction follow the normal settlePending rules. Editing a summary nulls the token counts that described the generated text rather than leaving them stale.

image

Validation

Windows, Python 3.12.1, Node.js 22.15.0, headless Chrome. Tested code revision: d76e90f2. Browser tests used an external puppeteer-core installation through WEBTEST_MODULES; Python tests used isolated Jinja2 and regex dependencies.

Passed:

  • node serve/web/test_compaction.mjs — 15 checks.
  • node tools/webtest/browser_test.mjs — 41 browser tests against the local mock server, including summary editing, Undo and reload.
  • python -B -m unittest discover -s serve -p 'test_web*.py' — 52 tests, 2 optional browser checks skipped.

Failed: none in these final runs.

Not run: real-model/GPU compaction and summary-recall validation.

Limits

The recent-message budget and context count after compaction are client estimates. Summaries can omit details.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4788 **Author:** [@orangeswim](https://github.com/orangeswim) **Created:** 10/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `gui/gauge-and-compaction` --- ### 📝 Commits (3) - [`fab52f3`](https://github.com/Niko1221/Strata/commit/fab52f342076b0c5d51af5f2a7d395589ac01d32) Chat: conversation compaction - [`b907544`](https://github.com/Niko1221/Strata/commit/b907544f41de78668cd1fd9c87e868a9b311b9b3) Chat: a context gauge by the input - [`d76e90f`](https://github.com/Niko1221/Strata/commit/d76e90f2bd006eafc7907591e34645b5b72c95d9) [Docs] explain chat context gauge and conversation summaries ### 📊 Changes **12 files changed** (+747 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+15 -3) ➕ `serve/test_compaction.py` (+30 -0) 📝 `serve/web/app.css` (+35 -0) 📝 `serve/web/app.js` (+201 -13) 📝 `serve/web/chats-ui.js` (+16 -8) ➕ `serve/web/compact-prompt.js` (+20 -0) ➕ `serve/web/compaction.js` (+42 -0) 📝 `serve/web/history.js` (+8 -2) 📝 `serve/web/index.html` (+8 -0) ➕ `serve/web/test_compaction.mjs` (+186 -0) 📝 `tools/webtest/browser_test.mjs` (+184 -0) 📝 `tools/webtest/mock.mjs` (+2 -0) </details> ### 📄 Description [GUI] Add a context gauge and conversation summaries to browser chat ## Problem and result The browser chat has no context-usage display or command to summarize older messages. This adds a gauge beside the message box and a manual compaction button. The gauge updates from API-reported token usage after replies, independently of compaction. It warns at 70% and 90% of the context limit. After compaction, it displays an estimate until the next reply supplies a measured count. Local edits do not request a new count. Compaction asks the model to summarize older messages. They remain visible, while subsequent requests use their summary. Recent messages kept outside the summary retain files, images and tool results. The latest summary card can undo that compaction. Repeated compaction uses the previous summary and newer messages. With **Edit and rewind messages** enabled, **Edit summary** changes the summary text without removing other messages or changing which earlier messages it replaces. The edit sends no request and supports Undo. A long user message (over ten lines or 800 characters) is clamped to about ten lines with a fade; **Show all N lines** expands it in place, **Show less** collapses it again. ## Related discussion Split out of #1507 per the tracker reset for 0.2.0-beta: https://github.com/Niko1221/Strata/pull/1507#issuecomment-6444549518. This PR keeps the two related items together — the summary marker's context reading exists to feed the gauge, and the fold's effect is only visible through it. The third item, per-request timings, is filed separately. ## Approach The gauge reads `usage.prompt_tokens + completion_tokens` from the latest reply (or a fresh marker's post-fold estimate), formats with the existing `kfmt`/`ctxfmt` helpers, and sends nothing anywhere. Compaction is one hidden request: `compact-prompt.js` holds the summary prompt, and `compaction.js` owns the fold rules (pure, unit-tested) — the cut never crosses an earlier marker, so repeated compactions chain instead of orphaning older context, and the marker records its boundary. The kept window is budgeted on converted API messages, so attachments count, and an oversized paste cannot hijack it — it stays in the summarized part. Compaction, unfold and summary editing follow the existing history-lock rules, and messages queued during a compaction follow the normal `settlePending` rules. Editing a summary nulls the token counts that described the generated text rather than leaving them stale. <img width="936" height="288" alt="image" src="https://github.com/user-attachments/assets/886fdff2-8cc1-49d1-83ae-84884f4ff280" /> ## Validation Windows, Python 3.12.1, Node.js 22.15.0, headless Chrome. Tested code revision: `d76e90f2`. Browser tests used an external `puppeteer-core` installation through `WEBTEST_MODULES`; Python tests used isolated Jinja2 and regex dependencies. **Passed:** - `node serve/web/test_compaction.mjs` — 15 checks. - `node tools/webtest/browser_test.mjs` — 41 browser tests against the local mock server, including summary editing, Undo and reload. - `python -B -m unittest discover -s serve -p 'test_web*.py'` — 52 tests, 2 optional browser checks skipped. **Failed:** none in these final runs. **Not run:** real-model/GPU compaction and summary-recall validation. ## Limits The recent-message budget and context count after compaction are client estimates. Summaries can omit details. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5178
No description provided.