[PR #312] [MERGED] feat(client): Knowledge Router UX polish + theme-aware Knowledge Sources #4557

Closed
opened 2026-10-22 04:08:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/312
Author: @cha1latte
Created: 4/29/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @SpicyMarinara

Base: main ← Head: feat/knowledge-router-ux-polish


📝 Commits (5)

  • 47868fe feat(client): Knowledge Router UX polish + theme-aware Knowledge Sources
  • 0308a75 fix(client): tighten "both agents" warning + dedupe lorebook IDs
  • 31f386a fix(client): handle zero-entry and fetch-error states in coverage badge
  • 541b02c fix(client): gate warning on enabled rows + tighten hook API on error
  • 9f9c9d0 Merge branch 'main' into feat/knowledge-router-ux-polish

📊 Changes

2 files changed (+150 additions, -8 deletions)

View changed files

📝 packages/client/src/components/agents/AgentEditor.tsx (+111 -7)
📝 packages/client/src/hooks/use-lorebooks.ts (+39 -1)

📄 Description

Part 3 of #226 — the UX layer for the Knowledge Router agent merged in #228.

Summary

Adds three small UX improvements to make the Knowledge Router agent (#228) easier to configure and harder to misuse:

  1. Description-coverage badge in the agent editor — tells the user how well-described their selected source lorebooks are, since router precision scales with description quality
  2. "Both agents enabled" warning banner — surfaces the redundancy when both Knowledge Retrieval and Knowledge Router are configured
  3. Tip text about the description fallback — explains the previously-invisible content-snippet fallback behavior

Plus an earned scope-creep fix: the wider Knowledge Sources section was using hard-coded white-on-X colors that washed out completely in light mode, making the lorebook picker invisible to half the user base. Now uses theme-aware CSS variables.

Why

PR #228 shipped the Knowledge Router agent itself, but left the UX surface bare:

  • No way to know whether your lorebooks are well-described enough for routing
  • No warning if you accidentally enable both KR and Router on the same chat
  • No documentation of the hybrid description/content-snippet fallback

This PR fills those gaps so users can actually use the agent confidently.

Architecture

Commit Layer
47868fe Client-only — useEntriesAcrossLorebooks hook + 3 UX pieces in AgentEditor + theme-aware Knowledge Sources

How each piece works

Description-coverage badge:

  • Renders only for the Knowledge Router agent, only when at least one source lorebook is selected
  • Uses useEntriesAcrossLorebooks (new hook) to batch-fetch entries via TanStack Query's useQueries — each per-lorebook query is cached independently
  • Computes (entries with non-empty description) / (total entries), displays as colored dot + "X% described (Y/Z)" text
  • Thresholds: 🟢 ≥75% / 🟡 25-75% / 🔴 <25%

"Both agents enabled" warning banner:

  • Renders at the top of the agent editor for both KR and Router
  • Fires when agentConfigs contains a row for the other knowledge agent
  • Soft amber styling matching the existing "Unsaved changes" banner pattern
  • Names correctly flipped depending on which editor you're viewing — opens KR's editor and it says "Knowledge Router is also configured…", opens Router's and it says "Knowledge Retrieval is also configured…"

Tip text:

  • Small italic explainer below the lorebook picker, router-only, only when lorebooks are selected
  • "Tip: entries without a description fall back to a short content snippet. Adding tight one-line descriptions to your most important entries improves routing precision."

Theme-aware Knowledge Sources fix:

  • Replaced text-white/X and bg-white/[0.02] throughout the section with text-[var(--muted-foreground)], bg-[var(--secondary)], and similar theme-adaptive CSS variables
  • The selected-state amber styling stays the same — that already worked in both themes
  • Affects both Knowledge Retrieval and Knowledge Router since they share this UI surface

Known limitations

  • Threshold tier choices are best-guess. I picked 75% / 25% / <25% for green/amber/red. Real router behavior would tell us if those cutoffs are right; for now they're conservative.
  • Coverage calc treats "any non-empty description" as covered. A 5-character description and a 200-character one count the same. A future enhancement could weight by description quality, but that's much more complex.
  • The warning banner can't be dismissed. Each open of the editor re-shows it. That's intentional for this PR — if it becomes annoying we can add a dismiss state, but a persistent reminder is the safer default.

Test plan

Manual smoke tests on the dual-install dev environment (port 7820), Roleplay chat, with Ghostface and Apollo test lorebooks (10 + 11 entries, 0% description coverage):

  • pnpm check passes locally
  • Empty state — Router with no source lorebooks selected → no badge, no tip
  • Single-lorebook selection — badge appears with "0% described (0/10)" and red dot
  • Multi-lorebook selection — badge aggregates: "0% described (0/21)" across both books
  • Both agents configured — warning banner shows on both editors with names correctly flipped (verified by adding both KR and Router to the agents list, then opening each editor)
  • Light mode — badge, tip, picker rows, and all section text now visible (verified BEFORE and AFTER the theme fix; before, the entire section was washed out)
  • Dark mode — visual hasn't regressed
  • Mobile viewport (~400px) — badge fits inline with "Lorebooks" header, warning banner wraps to multiple lines but stays inside the viewport, tip text wraps gracefully

Screenshots

  1. Dark mode — Router editor with Ghostface selected (badge + tip visible)
    image

  2. Light mode — Router editor with Ghostface selected (badge + tip visible after theme fix)
    image

  3. Warning banner at top of either KR or Router editor when both are configured
    image

  4. Mobile viewport (~400px) — Knowledge Sources section + warning banner wrapping cleanly
    image

Summary by CodeRabbit

  • New Features

    • Added a coverage badge displaying description coverage across selected lorebooks
    • Added a warning banner when both knowledge agents are enabled, indicating parallel execution and potential overlapping context injection
    • Added explanatory tips about description fallback behavior
  • Style

    • Updated UI styling to align with theme variables for improved visual consistency

🔄 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/312 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 4/29/2026 **Status:** ✅ Merged **Merged:** 5/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `feat/knowledge-router-ux-polish` --- ### 📝 Commits (5) - [`47868fe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/47868fe9661b6ff7a8e883d0e8c559af817869d2) feat(client): Knowledge Router UX polish + theme-aware Knowledge Sources - [`0308a75`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0308a757e282f0c6ba91bd5bbe5c62b4d68781c4) fix(client): tighten "both agents" warning + dedupe lorebook IDs - [`31f386a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/31f386a06e5755dea50087c0f9ae8b13ddceed33) fix(client): handle zero-entry and fetch-error states in coverage badge - [`541b02c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/541b02cf551d2a123f748463209247edba469cd6) fix(client): gate warning on enabled rows + tighten hook API on error - [`9f9c9d0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9f9c9d092763f1110b74113b217c852cc3fd672c) Merge branch 'main' into feat/knowledge-router-ux-polish ### 📊 Changes **2 files changed** (+150 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/agents/AgentEditor.tsx` (+111 -7) 📝 `packages/client/src/hooks/use-lorebooks.ts` (+39 -1) </details> ### 📄 Description Part 3 of #226 — the UX layer for the Knowledge Router agent merged in #228. ## Summary Adds three small UX improvements to make the Knowledge Router agent (#228) easier to configure and harder to misuse: 1. **Description-coverage badge** in the agent editor — tells the user how well-described their selected source lorebooks are, since router precision scales with description quality 2. **"Both agents enabled" warning banner** — surfaces the redundancy when both Knowledge Retrieval and Knowledge Router are configured 3. **Tip text about the description fallback** — explains the previously-invisible content-snippet fallback behavior Plus an earned scope-creep fix: the wider **Knowledge Sources section** was using hard-coded white-on-X colors that washed out completely in light mode, making the lorebook picker invisible to half the user base. Now uses theme-aware CSS variables. ## Why PR #228 shipped the Knowledge Router agent itself, but left the UX surface bare: - No way to know whether your lorebooks are well-described enough for routing - No warning if you accidentally enable both KR and Router on the same chat - No documentation of the hybrid description/content-snippet fallback This PR fills those gaps so users can actually use the agent confidently. ## Architecture | Commit | Layer | |---|---| | `47868fe` | Client-only — `useEntriesAcrossLorebooks` hook + 3 UX pieces in AgentEditor + theme-aware Knowledge Sources | ## How each piece works **Description-coverage badge:** - Renders only for the Knowledge Router agent, only when at least one source lorebook is selected - Uses `useEntriesAcrossLorebooks` (new hook) to batch-fetch entries via TanStack Query's `useQueries` — each per-lorebook query is cached independently - Computes `(entries with non-empty description) / (total entries)`, displays as colored dot + "X% described (Y/Z)" text - Thresholds: 🟢 ≥75% / 🟡 25-75% / 🔴 <25% **"Both agents enabled" warning banner:** - Renders at the top of the agent editor for both KR and Router - Fires when `agentConfigs` contains a row for the *other* knowledge agent - Soft amber styling matching the existing "Unsaved changes" banner pattern - Names correctly flipped depending on which editor you're viewing — opens KR's editor and it says "Knowledge Router is also configured…", opens Router's and it says "Knowledge Retrieval is also configured…" **Tip text:** - Small italic explainer below the lorebook picker, router-only, only when lorebooks are selected - *"Tip: entries without a description fall back to a short content snippet. Adding tight one-line descriptions to your most important entries improves routing precision."* **Theme-aware Knowledge Sources fix:** - Replaced `text-white/X` and `bg-white/[0.02]` throughout the section with `text-[var(--muted-foreground)]`, `bg-[var(--secondary)]`, and similar theme-adaptive CSS variables - The selected-state amber styling stays the same — that already worked in both themes - Affects both Knowledge Retrieval and Knowledge Router since they share this UI surface ## Known limitations - **Threshold tier choices are best-guess.** I picked 75% / 25% / <25% for green/amber/red. Real router behavior would tell us if those cutoffs are right; for now they're conservative. - **Coverage calc treats "any non-empty description" as covered.** A 5-character description and a 200-character one count the same. A future enhancement could weight by description quality, but that's much more complex. - **The warning banner can't be dismissed.** Each open of the editor re-shows it. That's intentional for this PR — if it becomes annoying we can add a dismiss state, but a persistent reminder is the safer default. ## Test plan Manual smoke tests on the dual-install dev environment (port 7820), Roleplay chat, with `Ghostface` and `Apollo` test lorebooks (10 + 11 entries, 0% description coverage): - [x] `pnpm check` passes locally - [x] **Empty state** — Router with no source lorebooks selected → no badge, no tip - [x] **Single-lorebook selection** — badge appears with "0% described (0/10)" and red dot - [x] **Multi-lorebook selection** — badge aggregates: "0% described (0/21)" across both books - [x] **Both agents configured** — warning banner shows on both editors with names correctly flipped (verified by adding both KR and Router to the agents list, then opening each editor) - [x] **Light mode** — badge, tip, picker rows, and all section text now visible (verified BEFORE and AFTER the theme fix; before, the entire section was washed out) - [x] **Dark mode** — visual hasn't regressed - [x] **Mobile viewport (~400px)** — badge fits inline with "Lorebooks" header, warning banner wraps to multiple lines but stays inside the viewport, tip text wraps gracefully ## Screenshots 1. **Dark mode — Router editor with Ghostface selected** (badge + tip visible) <img width="1015" height="279" alt="image" src="https://github.com/user-attachments/assets/3887eaa4-f16d-4fcb-bbe1-d0847188588e" /> 2. **Light mode — Router editor with Ghostface selected** (badge + tip visible after theme fix) <img width="936" height="255" alt="image" src="https://github.com/user-attachments/assets/fe4674cc-27c5-4f95-9bef-a55c3e2cb739" /> 3. **Warning banner** at top of either KR or Router editor when both are configured <img width="1063" height="131" alt="image" src="https://github.com/user-attachments/assets/62653b21-d28e-4268-a821-05a7c36399cc" /> 5. **Mobile viewport (~400px)** — Knowledge Sources section + warning banner wrapping cleanly <img width="417" height="845" alt="image" src="https://github.com/user-attachments/assets/59c46de6-1c36-4736-89d6-d31f6aebe930" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a coverage badge displaying description coverage across selected lorebooks * Added a warning banner when both knowledge agents are enabled, indicating parallel execution and potential overlapping context injection * Added explanatory tips about description fallback behavior * **Style** * Updated UI styling to align with theme variables for improved visual consistency <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:42 +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#4557
No description provided.