[PR #8625] [MERGED] feat(presets): show each section's estimated tokens, and the static preset's total (#8583) #8711

Closed
opened 2026-11-07 17:39:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8625
Author: @SpicyMarinara
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/preset-tokens-8583


📝 Commits (1)

  • 082bda3 feat(presets): show each section's estimated tokens, and the static preset's total

📊 Changes

5 files changed (+184 additions, -0 deletions)

View changed files

📝 packages/client/src/components/presets/PresetEditor.tsx (+46 -0)
➕ packages/client/src/lib/preset-section-tokens.ts (+45 -0)
📝 packages/client/src/localization/locales/en.json (+4 -0)
➕ scripts/regressions/preset-section-tokens.regression.ts (+88 -0)
📝 scripts/regressions/tsconfig.client-lanes.json (+1 -0)

📄 Description

Closes #8583

Why this change

The Preset Editor showed a token estimate only inside an expanded section's text editor. The collapsed rows had no count and the Sections panel had no total, so the static cost of a modular preset could only be understood by opening every section and adding estimates up by hand. This shows the cost where the sections are: one number per row, one always-visible total.

What changed

One estimator for everything (packages/client/src/lib/preset-section-tokens.ts)

  • Rows and the footer both go through the app's shared light estimator (estimateTextTokens), so a collapsed row and its expanded editor can never disagree, and no model call or tokenizer is involved.
  • Estimated values are deliberately rough: only a section's own text is counted, not the XML/Markdown wrapper the assembler adds around it.

The total is the enabled static preset (header chip next to Add Section and Groups)

  • Marker sections — character info, persona, World Info/lorebook, chat examples, chat history, summaries, agent data — are filled in from the current chat at prompt assembly, so the preset alone cannot size them. They show "Dynamic" with an explanation rather than a false zero, and never count toward the total.
  • A disabled section keeps its own estimate, struck through, and stays out of the total, so re-enabling it shows what it would cost.
  • The total is a pure sum recomputed from the current section list, so editing, toggling, duplicating, deleting and reordering all update together.

Localization: four new keys in the canonical English catalog (dynamic, dynamicSectionDescription, enabledStaticPresetValue1Tokens, enabledStaticPresetValue1TokensDescription). No other locale is touched; they fall back to English.

Validation

  • scripts/regressions/preset-section-tokens.regression.ts (added to tsconfig.client-lanes.json): pins the marker rule for every marker kind, both storage spellings of enabled/isMarker (a string "false" is not truthy), the empty and not-yet-fetched cases, and that the total is a pure sum — duplicating adds exactly its own estimate, editing recalculates without a cached total, reordering cannot change it, disabling drops exactly that section's share.
  • prettier --check passes on all changed files.

Test plan

  • Open a preset with many sections; confirm every row shows ~N tokens without expanding it.
  • Confirm the header total equals the sum of the enabled static rows and updates on edit, toggle, duplicate, delete and reorder.
  • Confirm marker rows read "Dynamic" with the explanation tooltip and are excluded from the total.
  • Disable a section; confirm its own count stays visible, struck through, and the total drops by exactly its share.
  • Check light and dark mode and the mobile viewport (the chip wraps under the header on small screens).

🤖 Generated with Claude Code


🔄 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/Pasta-Devs/Marinara-Engine/pull/8625 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/preset-tokens-8583` --- ### 📝 Commits (1) - [`082bda3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/082bda36732af44c44909f8e3b5b68deaf494e01) feat(presets): show each section's estimated tokens, and the static preset's total ### 📊 Changes **5 files changed** (+184 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/presets/PresetEditor.tsx` (+46 -0) ➕ `packages/client/src/lib/preset-section-tokens.ts` (+45 -0) 📝 `packages/client/src/localization/locales/en.json` (+4 -0) ➕ `scripts/regressions/preset-section-tokens.regression.ts` (+88 -0) 📝 `scripts/regressions/tsconfig.client-lanes.json` (+1 -0) </details> ### 📄 Description Closes #8583 ## Why this change The Preset Editor showed a token estimate only *inside* an expanded section's text editor. The collapsed rows had no count and the Sections panel had no total, so the static cost of a modular preset could only be understood by opening every section and adding estimates up by hand. This shows the cost where the sections are: one number per row, one always-visible total. ## What changed **One estimator for everything** (`packages/client/src/lib/preset-section-tokens.ts`) - Rows and the footer both go through the app's shared light estimator (`estimateTextTokens`), so a collapsed row and its expanded editor can never disagree, and no model call or tokenizer is involved. - Estimated values are deliberately rough: only a section's own text is counted, not the XML/Markdown wrapper the assembler adds around it. **The total is the enabled *static* preset** (header chip next to Add Section and Groups) - Marker sections — character info, persona, World Info/lorebook, chat examples, chat history, summaries, agent data — are filled in from the current chat at prompt assembly, so the preset alone cannot size them. They show **"Dynamic"** with an explanation rather than a false zero, and never count toward the total. - A disabled section keeps its own estimate, struck through, and stays out of the total, so re-enabling it shows what it would cost. - The total is a pure sum recomputed from the current section list, so editing, toggling, duplicating, deleting and reordering all update together. **Localization:** four new keys in the canonical English catalog (`dynamic`, `dynamicSectionDescription`, `enabledStaticPresetValue1Tokens`, `enabledStaticPresetValue1TokensDescription`). No other locale is touched; they fall back to English. ## Validation - `scripts/regressions/preset-section-tokens.regression.ts` (added to `tsconfig.client-lanes.json`): pins the marker rule for every marker kind, both storage spellings of `enabled`/`isMarker` (a string `"false"` is not truthy), the empty and not-yet-fetched cases, and that the total is a pure sum — duplicating adds exactly its own estimate, editing recalculates without a cached total, reordering cannot change it, disabling drops exactly that section's share. - `prettier --check` passes on all changed files. ## Test plan - [ ] Open a preset with many sections; confirm every row shows `~N tokens` without expanding it. - [ ] Confirm the header total equals the sum of the enabled static rows and updates on edit, toggle, duplicate, delete and reorder. - [ ] Confirm marker rows read "Dynamic" with the explanation tooltip and are excluded from the total. - [ ] Disable a section; confirm its own count stays visible, struck through, and the total drops by exactly its share. - [ ] Check light and dark mode and the mobile viewport (the chip wraps under the header on small screens). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:08 +07:00
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#8711
No description provided.