[GH-ISSUE #4752] [Feature]: Add context budget indicator in Prof. Mari Workspace #2615

Closed
opened 2026-10-21 05:51:24 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @xDanteMD on GitHub (Aug 8, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4752

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

The Workspace assistant (Professor Mari's primary code path, via workspace-agent.service.ts) provides no persistent visibility into context consumption. Users see per-message token counts when the showTokenUsage toggle is enabled, but there's no aggregate readout — no running total that answers "how full is the context window right now?"

This is basic UX hygiene. Every AI chat interface that takes context management seriously provides this. It should exist regardless of whether the user is "hitting limits" — it removes an abstraction layer and lets users see what's actually happening with their context.

Practical value. Most users will likely stay under 100K tokens per conversation. But the feature earns its keep in the margins:

  • Complex lorebooks and alternate greetings benefit from living in context across generations — past turns inform the model's understanding and help it avoid generic overlap between items. When users know how much room remains, they can make informed decisions about whether to continue building context or start fresh.
  • Cost transparency. Cloud-hosted dense models have meaningful per-token costs. Local models via OAI-compatible endpoints (LM Studio, Ollama, llama.cpp) have finite VRAM. Opacity about context size makes it harder to plan usage.
  • 1M context windows are now commonplace. The UI should reflect this — showing "12.4k / 1M tokens" is more informative than hiding the denominator entirely. (Perhaps someone wishes to roleplay to the tune of The Rise and Fall of the Roman Empire)

The data already exists on both sides. The server calculates and returns promptTokens and completionTokens via LLMUsage on every generation. The client receives this and displays it per-message when the toggle is enabled. The maxContext field on each connection holds the model's configured maximum (default 128,000; configurable per-provider). The PeekPromptModal can show token estimates on demand. The gap is purely a persistent, at-a-glance display.

Proposed solution

Add a lightweight context budget indicator to the chat UI that shows:

  • Total tokens consumed in the current conversation (system prompt + messages + tool results + model responses)
  • The model's configured max context length
  • A visual bar or percentage

Minimal implementation:

  • A small indicator in the chat header or footer showing "12.4k / 1M tokens"
  • Updates after each generation
  • Optional (behind the existing showTokenUsage toggle or a new setting)

Alternatives considered

  • Per-message token display only — useful for debugging individual turns but doesn't help users manage context across a conversation.
  • PeekPromptModal only — partially exists there, but requires opening a modal. A persistent indicator is more practical.
  • Automatic context trimming — separate concern. This issue is about visibility, not management.

Additional context

  • Related: #289 proposed token-based context management (dynamic message selection by token count rather than message count). This issue is complementary — visibility first, management second.
  • The persona editor recently switched from character counts to approximate token counts (#3172), indicating the team values token-awareness in the UI.
  • The server already calculates token usage on every generation. The client already receives it. Implementation is primarily a new UI component and its data wiring.
  • Professor Mari's workspace uses the app_data tool and mari-db.service.ts — this issue targets that code path, not the legacy conversational assistant.

*Research: codebase analysis of generate.routes.ts (token usage flow), ChatMessage.tsx (per-message display), ChatSettingsDrawer.tsx (agent contextSize — message count, not token budget), PeekPromptModal (token estimates), seed-mari.ts (MARI_ASSISTANT_PROMPT — ~9K tokens), workspace-agent.service.ts (workspace assistant code path), connections.ts (OAI-compatible endpoint support, maxContext field). Token estimates verified with tiktoken (cl100k_base). GitHub issue search found no duplicates.

Originally created by @xDanteMD on GitHub (Aug 8, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4752 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? The Workspace assistant (Professor Mari's primary code path, via `workspace-agent.service.ts`) provides no persistent visibility into context consumption. Users see per-message token counts when the `showTokenUsage` toggle is enabled, but there's no aggregate readout — no running total that answers "how full is the context window right now?" This is basic UX hygiene. Every AI chat interface that takes context management seriously provides this. It should exist regardless of whether the user is "hitting limits" — it removes an abstraction layer and lets users see what's actually happening with their context. **Practical value.** Most users will likely stay under 100K tokens per conversation. But the feature earns its keep in the margins: - **Complex lorebooks and alternate greetings** benefit from living in context across generations — past turns inform the model's understanding and help it avoid generic overlap between items. When users know how much room remains, they can make informed decisions about whether to continue building context or start fresh. - **Cost transparency.** Cloud-hosted dense models have meaningful per-token costs. Local models via OAI-compatible endpoints (LM Studio, Ollama, llama.cpp) have finite VRAM. Opacity about context size makes it harder to plan usage. - **1M context windows are now commonplace.** The UI should reflect this — showing "12.4k / 1M tokens" is more informative than hiding the denominator entirely. (Perhaps someone wishes to roleplay to the tune of The Rise and Fall of the Roman Empire) The data already exists on both sides. The server calculates and returns `promptTokens` and `completionTokens` via `LLMUsage` on every generation. The client receives this and displays it per-message when the toggle is enabled. The `maxContext` field on each connection holds the model's configured maximum (default 128,000; configurable per-provider). The `PeekPromptModal` can show token estimates on demand. The gap is purely a persistent, at-a-glance display. ## Proposed solution Add a lightweight context budget indicator to the chat UI that shows: - Total tokens consumed in the current conversation (system prompt + messages + tool results + model responses) - The model's configured max context length - A visual bar or percentage Minimal implementation: - A small indicator in the chat header or footer showing "12.4k / 1M tokens" - Updates after each generation - Optional (behind the existing `showTokenUsage` toggle or a new setting) ## Alternatives considered - **Per-message token display only** — useful for debugging individual turns but doesn't help users manage context across a conversation. - **PeekPromptModal only** — partially exists there, but requires opening a modal. A persistent indicator is more practical. - **Automatic context trimming** — separate concern. This issue is about visibility, not management. ## Additional context - Related: #289 proposed token-based context management (dynamic message selection by token count rather than message count). This issue is complementary — visibility first, management second. - The persona editor recently switched from character counts to approximate token counts (#3172), indicating the team values token-awareness in the UI. - The server already calculates token usage on every generation. The client already receives it. Implementation is primarily a new UI component and its data wiring. - Professor Mari's workspace uses the `app_data` tool and `mari-db.service.ts` — this issue targets that code path, not the legacy conversational assistant. --- *Research: codebase analysis of `generate.routes.ts` (token usage flow), `ChatMessage.tsx` (per-message display), `ChatSettingsDrawer.tsx` (agent contextSize — message count, not token budget), `PeekPromptModal` (token estimates), `seed-mari.ts` (MARI_ASSISTANT_PROMPT — ~9K tokens), `workspace-agent.service.ts` (workspace assistant code path), `connections.ts` (OAI-compatible endpoint support, `maxContext` field). Token estimates verified with tiktoken (cl100k_base). GitHub issue search found no duplicates.
Author
Owner

@SpicyMarinara commented on GitHub (Aug 8, 2026):

SpicyMarinara is taking this in the current assigned-issue sweep. I am preparing a focused draft PR against staging and will link it here shortly.

<!-- gh-comment-id:5226819759 --> @SpicyMarinara commented on GitHub (Aug 8, 2026): SpicyMarinara is taking this in the current assigned-issue sweep. I am preparing a focused draft PR against `staging` and will link it here shortly.
Author
Owner

@SpicyMarinara commented on GitHub (Aug 8, 2026):

Implementation is now tracked in draft PR #4761: https://github.com/Pasta-Devs/Marinara-Engine/pull/4761

<!-- gh-comment-id:5226823670 --> @SpicyMarinara commented on GitHub (Aug 8, 2026): Implementation is now tracked in draft PR #4761: https://github.com/Pasta-Devs/Marinara-Engine/pull/4761
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
Pasta-Devs/Marinara-Engine#2615
No description provided.