[GH-ISSUE #3840] [Issue]: Improve Peek Prompt modal #2073

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

Originally created by @BobEckman0348 on GitHub (Jul 19, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3840

Originally assigned to: @SpicyMarinara on GitHub.

Feature: Surface lorebook activation provenance in Peek Prompt modal and unify Roleplay active context view

Summary

The backend already tracks per-entry activation provenance (activation sources, matched keys, vector scores, budget-skipped reasons) but two key UI surfaces don't expose it:

  1. The Peek Prompt modal (PeekPromptModal.tsx) has no lorebook awareness at all — lorebook content appears as opaque text in the assembled prompt with no mapping to entries or activation reasons.
  2. The Roleplay mode Active Context popover renders a simplified view (status dot, name, badge, order, hover-tooltip) that omits the provenance detail already rendered by the Conversation/Game mode equivalent.

This data is critical for users fine-tuning lorebook entries, keyword selection, vector settings, and budget allocation.

Current state

Data pipeline — ✅ Already exists

The backend /lorebooks/scan/:chatId endpoint returns ActiveLorebookScan with full provenance per entry:

// packages/client/src/hooks/use-lorebooks.ts:531-545
export interface ActiveLorebookEntry {
  id: string;
  name: string;
  content: string;
  keys: string[];
  lorebookId: string;
  lorebookName: string;
  activationSources: Array<"current_location" | "keyword" | "semantic" | "constant" | "sticky" | "recursive">;
  order: number;
  constant: boolean;
  selective: boolean;
  matchedKeys?: string[];
  matchType?: "keyword" | "semantic" | "constant" | "sticky";
  semanticScore?: number;
}

Conversation/Game mode active context — ✅ Rich provenance

ActiveLorebookEntriesButton (packages/client/src/components/chat/ActiveLorebookEntriesButton.tsx) lazy-loads ActiveLorebookEntriesPanel from ChatRoleplayPanels.tsx, which renders per entry:

  • Activation sources as comma-separated subtitle
  • Matched keys (first 5)
  • Vector score badges with semantic score
  • Location badges
  • Budget-skipped entries with blocking reasons
  • Click-to-expand full entry content

Used in:

  • ConversationView.tsx:450
  • GameSurface.tsx:10867, 11125

Roleplay mode active context — ❌ Simplified, no provenance

ChatRoleplaySurface.tsx (lines 578–674) renders its own inline active context popover. Per entry (lines 622–645):

  • Status dot (green/yellow/red)
  • Entry name (truncated)
  • Status badge (NOR/CONST/SEL)
  • Location badge (if current_location triggered)
  • Order number (#1, #2, etc.)
  • title={entry.content || entry.name} — native browser tooltip on hover

Missing: activation sources, matched keys, vector scores, click-to-expand.

The data is available — triggeredEntries (line 524) contains full ActiveLorebookEntry[] — but the render code ignores the provenance fields.

Peek Prompt modal — ❌ No lorebook awareness

PeekPromptData (packages/client/src/components/chat/chat-area.types.ts:45-69):

export type PeekPromptData = {
  messages: Array<{ role: string; content: string }>;
  chatMode?: string;
  parameters: unknown;
  source?: "cached" | "live_preview" | "raw_messages";
  exact?: boolean;
  generationInfo?: { ... } | null;
  agentNote?: string;
};

No lorebookScan or equivalent. The modal parses the assembled prompt into sections by XML tags and estimates tokens per section, but cannot map lorebook text chunks back to individual entries or show why each entry was injected.

Proposed changes

1. Unify Roleplay active context with the existing rich panel

Quick win. Replace the inline active context render in ChatRoleplaySurface.tsx (lines 620–646) with the existing ActiveLorebookEntriesPanel component from ChatRoleplayPanels.tsx, or at minimum render the same provenance fields (activation sources subtitle, matched keys, vector score badges) in the existing row layout.

The data is already in scope (triggeredEntries at line 524). No backend changes needed.

2. Wire lorebook scan into Peek Prompt modal

Larger but high-value. Two parts:

a) Pass scan data to the peek endpoint response:

  • The generate route already builds a LorebookScanSnapshot. Include the scan snapshot (or a lightweight version with entry IDs, names, activation sources, matched keys, semantic scores, token counts) in the PeekPromptData response.
  • Add a lorebookScan?: ActiveLorebookScan field to PeekPromptData.

b) Render provenance in PeekPromptModal:

  • Add a "Lorebook Provenance" section/tab in the modal that lists activated entries with their activation source, matched keys, vector score, and token count.
  • Optionally annotate the raw prompt text with per-entry markers to correlate injected text chunks with their source entries. A simpler MVP: just list the scan results alongside the prompt, without inline annotation.

3. (Bonus) Surface recursion depth

The scan tracks "recursive" as an activation source but doesn't surface how deep the recursion went or which entry triggered the recursive scan. Adding a recursionDepth field and the parent entry ID would help debug recursive lorebook chains.

Why this matters

Without per-entry activation provenance in the prompt inspector, users tuning lorebooks are flying blind:

  • Can't see which keyword actually triggered an entry
  • Can't see vector similarity scores to adjust thresholds
  • Can't see if recursion fired unexpectedly
  • Can't correlate injected text in the prompt back to its source entry
  • In Roleplay mode specifically, can't see ANY of this without switching to Conversation mode

The data pipeline is already built. This is a presentation-layer gap, not an engine gap.

File references

File Relevant lines Role
packages/client/src/hooks/use-lorebooks.ts 531–545, 564–578 ActiveLorebookEntry type, useActiveLorebookEntries hook
packages/client/src/components/chat/ChatRoleplayPanels.tsx 57–150, 249+ Rich ActiveLorebookEntryRow + ActiveLorebookEntriesPanel (Conversation/Game)
packages/client/src/components/chat/ActiveLorebookEntriesButton.tsx 16–18, 111+ Button that lazy-loads the rich panel
packages/client/src/components/chat/ChatRoleplaySurface.tsx 524–525, 578–674 Simplified inline active context (Roleplay mode)
packages/client/src/components/chat/chat-area.types.ts 45–69 PeekPromptData type (no lorebook scan field)
packages/client/src/components/chat/ChatArea.tsx 2205–2226, 3197, 3274, 3411 Peek prompt state + modal mounting
packages/client/src/components/chat/ConversationView.tsx 450 Rich panel used in Conversation mode
packages/client/src/components/game/GameSurface.tsx 10867, 11125 Rich panel used in Game mode

Thanks to Mari for creating this for me!

Originally created by @BobEckman0348 on GitHub (Jul 19, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3840 Originally assigned to: @SpicyMarinara on GitHub. # Feature: Surface lorebook activation provenance in Peek Prompt modal and unify Roleplay active context view ## Summary The backend already tracks per-entry activation provenance (activation sources, matched keys, vector scores, budget-skipped reasons) but two key UI surfaces don't expose it: 1. **The Peek Prompt modal** (`PeekPromptModal.tsx`) has no lorebook awareness at all — lorebook content appears as opaque text in the assembled prompt with no mapping to entries or activation reasons. 2. **The Roleplay mode Active Context popover** renders a simplified view (status dot, name, badge, order, hover-tooltip) that omits the provenance detail already rendered by the Conversation/Game mode equivalent. This data is critical for users fine-tuning lorebook entries, keyword selection, vector settings, and budget allocation. ## Current state ### Data pipeline — ✅ Already exists The backend `/lorebooks/scan/:chatId` endpoint returns `ActiveLorebookScan` with full provenance per entry: ```ts // packages/client/src/hooks/use-lorebooks.ts:531-545 export interface ActiveLorebookEntry { id: string; name: string; content: string; keys: string[]; lorebookId: string; lorebookName: string; activationSources: Array<"current_location" | "keyword" | "semantic" | "constant" | "sticky" | "recursive">; order: number; constant: boolean; selective: boolean; matchedKeys?: string[]; matchType?: "keyword" | "semantic" | "constant" | "sticky"; semanticScore?: number; } ``` ### Conversation/Game mode active context — ✅ Rich provenance `ActiveLorebookEntriesButton` (`packages/client/src/components/chat/ActiveLorebookEntriesButton.tsx`) lazy-loads `ActiveLorebookEntriesPanel` from `ChatRoleplayPanels.tsx`, which renders per entry: - Activation sources as comma-separated subtitle - Matched keys (first 5) - Vector score badges with semantic score - Location badges - Budget-skipped entries with blocking reasons - Click-to-expand full entry content Used in: - `ConversationView.tsx:450` - `GameSurface.tsx:10867, 11125` ### Roleplay mode active context — ❌ Simplified, no provenance `ChatRoleplaySurface.tsx` (lines 578–674) renders its own inline active context popover. Per entry (lines 622–645): - Status dot (green/yellow/red) - Entry name (truncated) - Status badge (NOR/CONST/SEL) - Location badge (if current_location triggered) - Order number (#1, #2, etc.) - `title={entry.content || entry.name}` — native browser tooltip on hover **Missing:** activation sources, matched keys, vector scores, click-to-expand. The data is available — `triggeredEntries` (line 524) contains full `ActiveLorebookEntry[]` — but the render code ignores the provenance fields. ### Peek Prompt modal — ❌ No lorebook awareness `PeekPromptData` (`packages/client/src/components/chat/chat-area.types.ts:45-69`): ```ts export type PeekPromptData = { messages: Array<{ role: string; content: string }>; chatMode?: string; parameters: unknown; source?: "cached" | "live_preview" | "raw_messages"; exact?: boolean; generationInfo?: { ... } | null; agentNote?: string; }; ``` No `lorebookScan` or equivalent. The modal parses the assembled prompt into sections by XML tags and estimates tokens per section, but cannot map lorebook text chunks back to individual entries or show why each entry was injected. ## Proposed changes ### 1. Unify Roleplay active context with the existing rich panel **Quick win.** Replace the inline active context render in `ChatRoleplaySurface.tsx` (lines 620–646) with the existing `ActiveLorebookEntriesPanel` component from `ChatRoleplayPanels.tsx`, or at minimum render the same provenance fields (activation sources subtitle, matched keys, vector score badges) in the existing row layout. The data is already in scope (`triggeredEntries` at line 524). No backend changes needed. ### 2. Wire lorebook scan into Peek Prompt modal **Larger but high-value.** Two parts: **a) Pass scan data to the peek endpoint response:** - The generate route already builds a `LorebookScanSnapshot`. Include the scan snapshot (or a lightweight version with entry IDs, names, activation sources, matched keys, semantic scores, token counts) in the `PeekPromptData` response. - Add a `lorebookScan?: ActiveLorebookScan` field to `PeekPromptData`. **b) Render provenance in `PeekPromptModal`:** - Add a "Lorebook Provenance" section/tab in the modal that lists activated entries with their activation source, matched keys, vector score, and token count. - Optionally annotate the raw prompt text with per-entry markers to correlate injected text chunks with their source entries. A simpler MVP: just list the scan results alongside the prompt, without inline annotation. ### 3. (Bonus) Surface recursion depth The scan tracks `"recursive"` as an activation source but doesn't surface *how deep* the recursion went or *which entry* triggered the recursive scan. Adding a `recursionDepth` field and the parent entry ID would help debug recursive lorebook chains. ## Why this matters Without per-entry activation provenance in the prompt inspector, users tuning lorebooks are flying blind: - Can't see which keyword actually triggered an entry - Can't see vector similarity scores to adjust thresholds - Can't see if recursion fired unexpectedly - Can't correlate injected text in the prompt back to its source entry - In Roleplay mode specifically, can't see ANY of this without switching to Conversation mode The data pipeline is already built. This is a presentation-layer gap, not an engine gap. ## File references | File | Relevant lines | Role | |---|---|---| | `packages/client/src/hooks/use-lorebooks.ts` | 531–545, 564–578 | `ActiveLorebookEntry` type, `useActiveLorebookEntries` hook | | `packages/client/src/components/chat/ChatRoleplayPanels.tsx` | 57–150, 249+ | Rich `ActiveLorebookEntryRow` + `ActiveLorebookEntriesPanel` (Conversation/Game) | | `packages/client/src/components/chat/ActiveLorebookEntriesButton.tsx` | 16–18, 111+ | Button that lazy-loads the rich panel | | `packages/client/src/components/chat/ChatRoleplaySurface.tsx` | 524–525, 578–674 | Simplified inline active context (Roleplay mode) | | `packages/client/src/components/chat/chat-area.types.ts` | 45–69 | `PeekPromptData` type (no lorebook scan field) | | `packages/client/src/components/chat/ChatArea.tsx` | 2205–2226, 3197, 3274, 3411 | Peek prompt state + modal mounting | | `packages/client/src/components/chat/ConversationView.tsx` | 450 | Rich panel used in Conversation mode | | `packages/client/src/components/game/GameSurface.tsx` | 10867, 11125 | Rich panel used in Game mode | Thanks to Mari for creating this for me!
bsakaguchi 2026-10-21 05:45:08 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jul 19, 2026):

  1. Pookie, Peek Prompt literally just shows what was sent to the model. If a lorebook entry is there, it means it was sent. What you mention would do better as a separate tool but is otherwise not needed, given the existence of Active Context.
  2. I can make it so Active Context works the same way in Roleplay mode as in the others.
<!-- gh-comment-id:5017819835 --> @SpicyMarinara commented on GitHub (Jul 19, 2026): 1. Pookie, Peek Prompt literally just shows what was sent to the model. If a lorebook entry is there, it means it was sent. What you mention would do better as a separate tool but is otherwise not needed, given the existence of Active Context. 2. I can make it so Active Context works the same way in Roleplay mode as in the others.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 19, 2026):

I am taking the focused Roleplay Active Context parity slice. This will reuse the existing rich lorebook activation panel so Roleplay displays activation sources, matched keys, semantic scores, budget-skipped reasons, and expandable content. Peek Prompt provenance, scan payload changes, and recursion metadata are explicitly out of scope for this PR.

<!-- gh-comment-id:5017829862 --> @SpicyMarinara commented on GitHub (Jul 19, 2026): I am taking the focused Roleplay Active Context parity slice. This will reuse the existing rich lorebook activation panel so Roleplay displays activation sources, matched keys, semantic scores, budget-skipped reasons, and expandable content. Peek Prompt provenance, scan payload changes, and recursion metadata are explicitly out of scope for this PR.
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#2073
No description provided.