[GH-ISSUE #2442] 12. Prompt assembly #1196

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

Originally created by @Promansis on GitHub (Jun 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2442

Originally assigned to: @Promansis on GitHub.

Target 12: Prompt Assembly

target: 12
name: Prompt assembly
scan_status: reported
parity_verdict: gaps_open
proof_level: static_trace
scan_refactor: refactor@d7d733ce
legacy_ref: legacy-checkout@7c6190aa (hotfix/1.6.1-tracker-alias-avatar-hud-temp)
report: 2026-06-07 focused closure rescan in this issue
last_refreshed: 2026-06-07

Scope

Included:

  • Static inventory of prompt construction before provider transport for conversation, roleplay, and game generation.
  • Prompt preset selection, parameter merge, section and marker expansion, macro/variable resolution, chat history, summaries, lorebooks, agent data, memory recall, connected-chat context, role formatting, regex prompt transforms, prompt preview, generation replay, and saved prompt snapshots.
  • Mode-specific prompt assembly entrypoints where they feed the shared generation path.

Not checked:

  • Full prompt assembly on-par proof after the 2026-06-07 blocker; the rescan stopped at the current negative-control gap, so no on-par claim is made.
  • Native Tauri app behavior or live provider calls.
  • Prompt preset CRUD/import/export details; Target 8 owns those surfaces.
  • Chat/message storage shape and prompt snapshot materialization; Target 9 owns storage/UI compatibility, while this target owns prompt construction semantics.
  • Provider transport and provider-specific request mapping after messages are assembled; Target 11 owns transport.
  • Agent/tool/regex catalog management; Target 13 owns those authoring/runtime details, while this target owns prompt injection points.
  • Mode-specific end-to-end generation behavior; Targets 15, 16, and 17 own conversation, roleplay, and game mode scans.

Inventory note:

  • Legacy trace used the local legacy checkout at 7c6190aa on hotfix/1.6.1-tracker-alias-avatar-hud-temp.
  • Source labels are static inventory leads, not parity verdicts.

Current Rescan - 2026-06-07

Result: not on par. All seven linked Target 12 follow-up issues are closed, but current refactor@d7d733ce still has a blocker in 12-PROMPT-ERROR-invalid-empty-fallbacks.

Static trace findings:

  • Fixed/covered leads: creator notes marker fields, group scenario override consumption, deferred character macros, chat summary fallback insertion, prompt/injection regex pass ordering, random-pool connection ids, and user-message regeneration source/rewrite helpers have current refactor evidence.
  • Remaining blocker: when neither the request nor chat supplies a connection id, src/engine/generation/context.ts:78 lists stored connections and :80-:83 still returns the default/first stored connection before erroring. Legacy packages/server/src/routes/generate.routes.ts:1855 returned No API connection configured for this chat for that negative-control path.
  • Closed issue mismatch: #2451/#2461 are closed and claim this negative-control acceptance criterion, but the current branch evidence above still fails it. Random-pool handling from #2451 is present at src/engine/generation/context.ts:62-:75.

Classification: Current refactor defect; Target 12 remains gaps_open and should not be marked on_par until the missing request/chat connection path is fixed or explicitly documented as an intentional divergence.

Surface Inventory

Surface ID Surface Bucket Source Legacy owner Refactor owner In scope Notes
12-PROMPT-CONTRACT-assembler-input-output Prompt assembler contract accepts chat, messages, connection/request, latest user input, agent data, embedding source, and returns assembled messages, preview messages, selected preset, parameters, character/persona context, lorebook state, and summary fingerprints. CONTRACT both packages/server/src/services/prompt/assembler.ts; packages/server/src/routes/generate.routes.ts src/engine/generation/prompt-assembly.ts; src/engine/generation/start-generation.ts yes Baseline contract for every prompt parity row.
12-PROMPT-RUNTIME-preset-selection-parameter-merge Prompt preset and parameter precedence merge connection defaults, chat metadata, request overrides, selected prompt preset, wrap format, and generation options. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/routes/generate/prompt-preset-selection.ts; legacy prompt assembler src/engine/generation/prompt-preset-selection.ts; src/engine/generation/prompt-assembly.ts; src/engine/generation/context.ts yes Target 8 owns saved preset fields; Target 12 owns runtime consumption.
12-PROMPT-RUNTIME-section-marker-expansion Prompt sections and marker sections expand into ordered messages for character, persona, lorebook/world info, chat history, summary, dialogue examples, and agent data while preserving enabled state, grouping, order, roles, and wrapping. RUNTIME both packages/server/src/services/prompt/assembler.ts; packages/server/src/services/prompt/marker-expander.ts src/engine/generation/prompt-assembly.ts; src/engine/generation-core/prompt/format-engine.ts yes Inventory should compare static text and dynamic marker behavior.
12-PROMPT-RUNTIME-macro-variable-resolution Macro and prompt variable resolution covers user/character/persona fields, input/date/time, random/choice variables, conditional blocks, agent data macros, character-scoped macros, and variable side effects. RUNTIME both packages/shared/src/utils/macro-engine.ts; packages/server/src/services/prompt/macro-context.ts; packages/server/src/services/prompt/assembler.ts src/engine/shared/macros/macro-engine.ts; src/engine/generation/prompt-assembly.ts yes Include deferred character macro behavior for multi-character/group turns.
12-PROMPT-RUNTIME-character-persona-context Character and persona prompt context includes card fields, system prompt, post-history instructions, creator notes, depth prompts, group scenario overrides, persona fallback, and active persona fields. RUNTIME both packages/server/src/services/prompt/macro-context.ts; packages/server/src/services/prompt/marker-expander.ts; legacy character/persona storage src/engine/generation/prompt-assembly.ts; src/engine/contracts/types/character.ts; src/engine/contracts/types/persona.ts yes Coordinates with Targets 5 and 6 for card field storage/import parity.
12-PROMPT-RUNTIME-history-window-hidden-reasoning Prompt history selection respects conversation-start markers, context message limits, hidden-from-AI flags, role mapping, last user message context, and optional replay of stored provider reasoning/thinking. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/routes/chats.routes.ts; packages/shared/src/types/chat.ts src/engine/generation/context.ts; src/engine/generation/start-generation.ts; src/engine/generation/prompt-assembly.ts yes Target 9 owns message extra storage; this row owns whether those flags affect prompt inclusion.
12-PROMPT-RUNTIME-lorebook-scan-activation Active lorebook scope, manual/global/character/persona/game filters, keyword and semantic matching, trigger labels, timing state, ephemeral state, and content macro resolution feed prompt assembly. RUNTIME both packages/server/src/services/prompt/marker-expander.ts; packages/server/src/services/lorebook/index.ts; packages/server/src/routes/generate.routes.ts src/engine/generation/active-lorebook-scanner.ts; src/engine/generation/prompt-assembly.ts; src/engine/generation-core/lorebooks/active-lorebook-scope.ts yes Coordinates with Target 7 for lorebook editor/storage contract.
12-PROMPT-RUNTIME-lorebook-injection-budget-depth Activated lorebook entries inject as world info before/after blocks or depth messages, enforce token budgets, preserve skipped-entry diagnostics, and anchor depth entries inside history bounds. RUNTIME both packages/server/src/services/lorebook/prompt-injector.ts; packages/server/src/services/prompt/assembler.ts src/engine/generation-core/lorebooks/prompt-injector.ts; src/engine/generation/prompt-assembly.ts yes Include constant entries, fresh-user-message priority, order, role, and depth semantics.
12-PROMPT-RUNTIME-chat-summary-injection Compiled chat summary is included through explicit summary markers or fallback insertion, fingerprinted, and surfaced for saved prompt/debug compatibility. RUNTIME both packages/server/src/services/prompt/assembler.ts; packages/server/src/routes/generate.routes.ts; packages/shared/src/utils/chat-summary-entries.ts src/engine/generation/prompt-assembly.ts; src/engine/shared/text/chat-summary-entries.ts; src/engine/shared/text/chat-summary-fingerprint.ts yes Target 9 owns summary edit/generation workflow; this row owns summary prompt consumption.
12-PROMPT-RUNTIME-agent-data-two-pass Generation runs an initial assembly, executes pre-generation agents, optionally pauses for injection review, then reassembles with fresh agent data and context injections before model call. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/services/prompt/assembler.ts; legacy agent executor src/engine/generation/start-generation.ts; src/engine/generation/agent-runner.ts; src/engine/generation/prompt-assembly.ts yes Target 13 owns agent execution details; this row owns prompt data handoff and second-pass assembly.
12-PROMPT-RUNTIME-memory-connected-context Memory recall chunks, connected conversation summaries, OOC influences, durable connected notes, and command capability reminders are injected or consumed in the correct mode and prompt position. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/routes/chats.routes.ts; packages/server/src/services/memory-recall.ts; legacy connected note storage src/engine/generation/prompt-assembly.ts; src/engine/generation/connected-commands.ts; src/engine/contracts/types/chat.ts yes Target 9 owns storage/UI; Target 12 owns prompt inclusion and consumption semantics.
12-PROMPT-RUNTIME-roleplay-scene-directives Roleplay prompt assembly adds narrator style, scene prompt, scene continuity, direct-message command reminders, author notes, and character depth prompts without changing conversation/game owners. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/services/prompt/assembler.ts; legacy roleplay chat prompt code src/engine/generation/prompt-assembly.ts; src/engine/modes/roleplay/scene/scene-service.ts; src/engine/modes/chat/commands/character-commands.ts yes Mode separation check: roleplay owns roleplay scene semantics.
12-PROMPT-RUNTIME-game-system-prompt Game prompt assembly applies segment edits, game tracker baseline, GM system prompt, party prompt/reminder, player notes, world/game state, lorebook scope exclusions, and game-specific generation guidance. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/services/game/gm-prompts.ts; packages/server/src/services/game/party-prompts.ts src/engine/generation/prompt-assembly.ts; src/engine/modes/game/prompts/gm-prompts.ts; src/engine/modes/game/prompts/party-prompts.ts; src/engine/modes/game/turn/game-turn.service.ts yes Target 17 owns end-to-end game mode behavior.
12-PROMPT-RUNTIME-regenerate-continue-impersonate Regenerate, continue, guided/narrator/amend instruction, assistant prefill, direct messages, and impersonation flows slice history and directive messages without saving duplicate user turns. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/services/conversation/impersonate-prompt.ts; packages/shared/src/utils/generation-guide.ts src/engine/generation/start-generation.ts; src/engine/generation/generation-replay.ts; src/engine/modes/chat/commands/impersonate-prompt.ts; src/engine/shared/text/generation-guide.ts yes Coordinates with Target 15/16 for user-facing mode outcomes.
12-PROMPT-RUNTIME-group-turn-scoping Group and multi-character generation resolves target speakers, group scenario overrides, individual/sequential turns, speaker-scoped macros, strict role shaping, and response order. RUNTIME both packages/server/src/routes/generate.routes.ts; packages/server/src/services/prompt/assembler.ts; legacy group chat paths src/engine/generation/start-generation.ts; src/engine/generation/prompt-assembly.ts; src/features/modes/conversation/components/ConversationInput.tsx yes Include both conversation group chats and roleplay multi-character scenes.
12-PROMPT-RUNTIME-regex-prompt-transforms User input and outgoing prompt regex scripts transform prompt messages with macro-aware replacements at the same stage as legacy generation. RUNTIME both packages/client/src/hooks/use-apply-regex.ts; packages/server/src/services/regex/regex-application.ts; packages/server/src/routes/generate.routes.ts src/engine/generation/regex-runtime.ts; src/engine/generation-core/regex/regex-application.ts; src/engine/generation/prompt-assembly.ts; src/features/catalog/agents/regex-application.ts yes Target 13 owns regex authoring/storage; this row owns prompt transformation timing.
12-PROMPT-CONTRACT-message-shaping-provider-ready Final prompt messages merge adjacent roles, optionally squash system messages, enforce strict role alternation for roleplay, collapse to single-user-message mode, attach images, and remain provider-ready. CONTRACT both packages/server/src/services/prompt/merger.ts; packages/server/src/services/prompt/assembler.ts; packages/server/src/routes/generate.routes.ts src/engine/generation-core/prompt/merger.ts; src/engine/generation/prompt-assembly.ts; src/engine/generation/start-generation.ts yes Target 11 starts after this provider-neutral message shape exists.
12-PROMPT-PERF-context-window-fit Prompt assembly and final provider send trim history/messages to context limits while preserving non-history prompt sections and enough recent history to generate. PERF both packages/server/src/routes/generate.routes.ts; legacy provider send path src/engine/generation/context-window.ts; src/engine/generation/start-generation.ts; src/engine/generation/prompt-assembly.ts yes Needs measured or harness proof in parityscan, not just static row.
12-PROMPT-STORAGE-saved-prompt-snapshot-replay Exact prompts used for generation are stored and replayed for prompt inspection/regeneration, with legacy cachedPrompt compatibility and current prompt snapshot fields. STORAGE both packages/server/src/routes/generate.routes.ts; packages/server/src/routes/chats.routes.ts; packages/client/src/components/chat/PeekPromptModal.tsx src/engine/generation/start-generation.ts; src/features/modes/shared/chat-ui/lib/prompt-snapshot.ts; src/features/modes/shared/chat-ui/hooks/use-chat-timeline-actions.ts; src-tauri/src/commands/storage/shared.rs yes Target 9 owns physical storage/display compatibility; Target 12 owns prompt replay semantics.
12-PROMPT-API-preview-peek-assembly Prompt preview and Peek Prompt assemble or load prompt data without unintended runtime side effects, return visible parameters/model info, and support before-message/preset/choice overrides. API both packages/server/src/routes/prompts.routes.ts; packages/server/src/routes/chats.routes.ts; packages/server/src/routes/prompt-reviewer.routes.ts src/engine/generation/prompt-preview.ts; src/engine/generation/prompt-reviewer.ts; src/features/modes/shared/chat-ui/components/PeekPromptModal.tsx yes Include preview-only lorebook timing/ephemeral behavior in focused proof.
12-PROMPT-REMOTE-hostable-assembly-path Refactor hostable runtime uses the same shared API wrappers, storage reads, and LLM capability ports for prompt assembly as embedded Tauri, without embedded-only prompt behavior. REMOTE refactor_only legacy server REST route by design src/features/runtime/generation/hooks/use-generate.ts; src/engine/generation/start-generation.ts; src/shared/api/storage-api.ts; src/shared/api/llm-api.ts; src/shared/api/remote-runtime.ts; src-tauri/src/http_dispatch.rs yes Refactor-specific risk because generation assembly runs against embedded or hostable capabilities.
12-PROMPT-ERROR-invalid-empty-fallbacks Missing chat/connection/preset, invalid marker config, empty prompt sections, no active characters, offline/delayed characters, malformed metadata, and model-call-aborted states surface as explicit errors or intentional fallbacks. ERROR both packages/server/src/routes/generate.routes.ts; packages/server/src/services/prompt/assembler.ts; legacy chat UI src/engine/generation/start-generation.ts; src/engine/generation/prompt-assembly.ts; src/features/runtime/generation/hooks/use-generate.ts; src/features/modes/shared/chat-ui yes Parityscan should include negative-control rows for should-not-send and fallback prompt paths.

Coverage Matrix

Surface ID Status Proof Follow-up
12-PROMPT-CONTRACT-assembler-input-output unscanned static inventory only
12-PROMPT-RUNTIME-preset-selection-parameter-merge refactor_better Batch 2 static trace Refactor adds request-level preset/parameter override consumption; no issue filed.
12-PROMPT-RUNTIME-section-marker-expansion blocked Batch 2 static trace Runtime marker expansion mostly matches; order parity proof requires Target 8 preset CRUD/import/export tracing, so no issue filed.
12-PROMPT-RUNTIME-macro-variable-resolution covered_static 2026-06-07 closure rescan #2446 closed; current deferred character macro paths are present.
12-PROMPT-RUNTIME-character-persona-context covered_static 2026-06-07 closure rescan #2444 and #2445 closed; current creator-notes marker and group scenario override paths are present.
12-PROMPT-RUNTIME-history-window-hidden-reasoning refactor_better Batch 4 static trace Refactor preserves conversation-start, context limit, hidden-from-AI, role mapping, and opt-in stored reasoning behavior; no issue filed.
12-PROMPT-RUNTIME-lorebook-scan-activation no gap Batch 5 static trace Active scope, keyword/semantic matching, timing, ephemeral state, trigger filters, and macro-resolved content match legacy; no issue filed.
12-PROMPT-RUNTIME-lorebook-injection-budget-depth gap Batch 5 static trace #2448
12-PROMPT-RUNTIME-chat-summary-injection covered_static 2026-06-07 closure rescan #2447 closed; current prompt assembly includes explicit marker handling and fallback insertion when no marker inserted the summary.
12-PROMPT-RUNTIME-agent-data-two-pass no gap Batch 7 static trace
12-PROMPT-RUNTIME-memory-connected-context no gap Batch 6 static trace
12-PROMPT-RUNTIME-roleplay-scene-directives refactor_better Batch 9 static trace Refactor preserves legacy scene directives and adds explicit narrator style plus previous scene continuity; no issue filed.
12-PROMPT-RUNTIME-game-system-prompt no gap Batch 9 static trace Refactor preserves legacy GM prompt assembly, segment edits, game state/player notes, lore merge, and format reminder; no issue filed.
12-PROMPT-RUNTIME-regenerate-continue-impersonate covered_static 2026-06-07 closure rescan #2450 closed; user-message regeneration source/rewrite helpers and focused generation tests are present.
12-PROMPT-RUNTIME-group-turn-scoping no gap Batch 10 static trace
12-PROMPT-RUNTIME-regex-prompt-transforms covered_static 2026-06-07 closure rescan #2449 closed; current prompt regex runs after prompt/injection and group-turn messages are assembled.
12-PROMPT-CONTRACT-message-shaping-provider-ready unscanned static inventory only
12-PROMPT-PERF-context-window-fit refactor_better Batch 4 static trace + pnpm exec vitest run src/engine/generation/context-window.test.ts Refactor trims final provider messages to effective context by dropping oldest history while preserving non-history prompt sections; no issue filed.
12-PROMPT-STORAGE-saved-prompt-snapshot-replay refactor_better Batch 11 static trace Refactor stores structured prompt snapshots, preserves per-swipe replay, synthesizes legacy cachedPrompt for inspector compatibility, and keeps bounded snapshot retention; no issue filed.
12-PROMPT-API-preview-peek-assembly refactor_better Batch 11 static trace Refactor keeps saved-snapshot-first Peek Prompt behavior and adds before-message, preset, choice, character, parameter, and visible model-info preview support without persisting lorebook timing/ephemeral state; no issue filed.
12-PROMPT-REMOTE-hostable-assembly-path no gap Batch 12 static trace Refactor hostable path uses shared storageApi/llmApi capability ports for prompt assembly and routes remote storage/LLM calls through /api/invoke or /api/llm/stream; no issue filed.
12-PROMPT-ERROR-invalid-empty-fallbacks gap 2026-06-07 static closure rescan #2451 is closed, but current refactor@d7d733ce still falls back to the default/first stored connection when no request/chat connection id is set. Random-pool handling is present.

Follow-Ups

Issue State Why it matters
Batch 2 section marker order proof blocked, not filed Refactor runtime consumes child sortOrder while legacy consumes preset.sectionOrder; proving whether this is a gap requires preset CRUD/import/export proof owned by Target 8.
#2444 closed 12-PROMPT-RUNTIME-character-persona-context: creator notes marker field was fixed; current static trace shows creator_notes/creatorNotes return GenerationCharacterContext.creatorNotes.
#2445 closed 12-PROMPT-RUNTIME-character-persona-context: group scenario override consumption is present in current prompt assembly macro and marker paths.
#2446 closed 12-PROMPT-RUNTIME-macro-variable-resolution: deferred character macro support is present in current macro/prompt assembly paths.
#2447 closed 12-PROMPT-RUNTIME-chat-summary-injection: current prompt assembly has explicit marker handling and fallback summary insertion when no marker inserted it.
#2448 closed 12-PROMPT-RUNTIME-lorebook-injection-budget-depth: refactor treated the first over-budget lorebook entry as exhausting the lorebook/chat budget, dropping later smaller entries legacy would still consider.
#2449 closed 12-PROMPT-RUNTIME-regex-prompt-transforms: current prompt assembly runs prompt regex after prompt/injection and group-turn messages are assembled.
#2450 closed 12-PROMPT-RUNTIME-regenerate-continue-impersonate: user-message regeneration source/rewrite helpers and focused generation tests are present in current refactor.
#2451 closed, still blocking current rescan 12-PROMPT-ERROR-invalid-empty-fallbacks: random connection ids now select from the random pool, but missing request/chat connections still fall back to the default/first stored connection on current refactor@d7d733ce. Needs reopen or follow-up fix before Target 12 can be on_par.

Refactor-Better Or Intentional Divergence

  • Batch 2: 12-PROMPT-RUNTIME-preset-selection-parameter-merge is refactor-better because refactor consumes request-level prompt preset and request parameter overrides in the runtime merge; no issue filed.
  • Batch 4: 12-PROMPT-RUNTIME-history-window-hidden-reasoning is refactor-better because refactor preserves legacy history filtering and opt-in reasoning replay behavior; no issue filed.
  • Batch 4: 12-PROMPT-PERF-context-window-fit is refactor-better because refactor adds final provider-send context fitting that trims oldest history while preserving prompt sections; no issue filed.
  • Batch 9: 12-PROMPT-RUNTIME-roleplay-scene-directives is refactor-better because refactor preserves legacy roleplay scene directives and adds explicit narrator style plus previous scene continuity; no issue filed.
  • Batch 11: 12-PROMPT-STORAGE-saved-prompt-snapshot-replay is refactor-better because refactor stores structured prompt snapshots, preserves per-swipe replay, synthesizes legacy cachedPrompt for inspector compatibility, and keeps bounded snapshot retention; no issue filed.
  • Batch 11: 12-PROMPT-API-preview-peek-assembly is refactor-better because refactor keeps saved-snapshot-first Peek Prompt behavior and adds before-message, preset, choice, character, parameter, and visible model-info preview support without persisting lorebook timing/ephemeral state; no issue filed.

Rescan Criteria

  • Run a prompt assembly parityscan on current refactor.
  • Include assembler contract, preset/parameter precedence, markers, macros, character/persona context, history filtering, lorebook scan/injection/budget, summaries, pre-generation agent reassembly, memory/connected context, roleplay directives, game prompts, regenerate/continue/impersonate, group turns, regex prompt transforms, role/message shaping, context fitting, saved prompt snapshots, preview/peek APIs, hostable runtime parity, and negative-control fallback paths.
  • Coordinate stored prompt snapshot proof with Target 9, preset authoring/import proof with Target 8, provider request transport with Target 11, agent/tool details with Target 13, and mode end-to-end proof with Targets 15, 16, and 17.
Originally created by @Promansis on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2442 Originally assigned to: @Promansis on GitHub. # Target 12: Prompt Assembly ```yaml target: 12 name: Prompt assembly scan_status: reported parity_verdict: gaps_open proof_level: static_trace scan_refactor: refactor@d7d733ce legacy_ref: legacy-checkout@7c6190aa (hotfix/1.6.1-tracker-alias-avatar-hud-temp) report: 2026-06-07 focused closure rescan in this issue last_refreshed: 2026-06-07 ``` ## Scope Included: - Static inventory of prompt construction before provider transport for conversation, roleplay, and game generation. - Prompt preset selection, parameter merge, section and marker expansion, macro/variable resolution, chat history, summaries, lorebooks, agent data, memory recall, connected-chat context, role formatting, regex prompt transforms, prompt preview, generation replay, and saved prompt snapshots. - Mode-specific prompt assembly entrypoints where they feed the shared generation path. Not checked: - Full prompt assembly on-par proof after the 2026-06-07 blocker; the rescan stopped at the current negative-control gap, so no on-par claim is made. - Native Tauri app behavior or live provider calls. - Prompt preset CRUD/import/export details; Target 8 owns those surfaces. - Chat/message storage shape and prompt snapshot materialization; Target 9 owns storage/UI compatibility, while this target owns prompt construction semantics. - Provider transport and provider-specific request mapping after messages are assembled; Target 11 owns transport. - Agent/tool/regex catalog management; Target 13 owns those authoring/runtime details, while this target owns prompt injection points. - Mode-specific end-to-end generation behavior; Targets 15, 16, and 17 own conversation, roleplay, and game mode scans. Inventory note: - Legacy trace used the local legacy checkout at `7c6190aa` on `hotfix/1.6.1-tracker-alias-avatar-hud-temp`. - Source labels are static inventory leads, not parity verdicts. ## Current Rescan - 2026-06-07 Result: **not on par**. All seven linked Target 12 follow-up issues are closed, but current `refactor@d7d733ce` still has a blocker in `12-PROMPT-ERROR-invalid-empty-fallbacks`. Static trace findings: - Fixed/covered leads: creator notes marker fields, group scenario override consumption, deferred character macros, chat summary fallback insertion, prompt/injection regex pass ordering, random-pool connection ids, and user-message regeneration source/rewrite helpers have current refactor evidence. - Remaining blocker: when neither the request nor chat supplies a connection id, `src/engine/generation/context.ts:78` lists stored connections and `:80`-`:83` still returns the default/first stored connection before erroring. Legacy `packages/server/src/routes/generate.routes.ts:1855` returned `No API connection configured for this chat` for that negative-control path. - Closed issue mismatch: #2451/#2461 are closed and claim this negative-control acceptance criterion, but the current branch evidence above still fails it. Random-pool handling from #2451 is present at `src/engine/generation/context.ts:62`-`:75`. Classification: `Current refactor defect`; Target 12 remains `gaps_open` and should not be marked `on_par` until the missing request/chat connection path is fixed or explicitly documented as an intentional divergence. ## Surface Inventory | Surface ID | Surface | Bucket | Source | Legacy owner | Refactor owner | In scope | Notes | | --- | --- | --- | --- | --- | --- | --- | --- | | 12-PROMPT-CONTRACT-assembler-input-output | Prompt assembler contract accepts chat, messages, connection/request, latest user input, agent data, embedding source, and returns assembled messages, preview messages, selected preset, parameters, character/persona context, lorebook state, and summary fingerprints. | CONTRACT | both | `packages/server/src/services/prompt/assembler.ts`; `packages/server/src/routes/generate.routes.ts` | `src/engine/generation/prompt-assembly.ts`; `src/engine/generation/start-generation.ts` | yes | Baseline contract for every prompt parity row. | | 12-PROMPT-RUNTIME-preset-selection-parameter-merge | Prompt preset and parameter precedence merge connection defaults, chat metadata, request overrides, selected prompt preset, wrap format, and generation options. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/routes/generate/prompt-preset-selection.ts`; legacy prompt assembler | `src/engine/generation/prompt-preset-selection.ts`; `src/engine/generation/prompt-assembly.ts`; `src/engine/generation/context.ts` | yes | Target 8 owns saved preset fields; Target 12 owns runtime consumption. | | 12-PROMPT-RUNTIME-section-marker-expansion | Prompt sections and marker sections expand into ordered messages for character, persona, lorebook/world info, chat history, summary, dialogue examples, and agent data while preserving enabled state, grouping, order, roles, and wrapping. | RUNTIME | both | `packages/server/src/services/prompt/assembler.ts`; `packages/server/src/services/prompt/marker-expander.ts` | `src/engine/generation/prompt-assembly.ts`; `src/engine/generation-core/prompt/format-engine.ts` | yes | Inventory should compare static text and dynamic marker behavior. | | 12-PROMPT-RUNTIME-macro-variable-resolution | Macro and prompt variable resolution covers user/character/persona fields, input/date/time, random/choice variables, conditional blocks, agent data macros, character-scoped macros, and variable side effects. | RUNTIME | both | `packages/shared/src/utils/macro-engine.ts`; `packages/server/src/services/prompt/macro-context.ts`; `packages/server/src/services/prompt/assembler.ts` | `src/engine/shared/macros/macro-engine.ts`; `src/engine/generation/prompt-assembly.ts` | yes | Include deferred character macro behavior for multi-character/group turns. | | 12-PROMPT-RUNTIME-character-persona-context | Character and persona prompt context includes card fields, system prompt, post-history instructions, creator notes, depth prompts, group scenario overrides, persona fallback, and active persona fields. | RUNTIME | both | `packages/server/src/services/prompt/macro-context.ts`; `packages/server/src/services/prompt/marker-expander.ts`; legacy character/persona storage | `src/engine/generation/prompt-assembly.ts`; `src/engine/contracts/types/character.ts`; `src/engine/contracts/types/persona.ts` | yes | Coordinates with Targets 5 and 6 for card field storage/import parity. | | 12-PROMPT-RUNTIME-history-window-hidden-reasoning | Prompt history selection respects conversation-start markers, context message limits, hidden-from-AI flags, role mapping, last user message context, and optional replay of stored provider reasoning/thinking. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/routes/chats.routes.ts`; `packages/shared/src/types/chat.ts` | `src/engine/generation/context.ts`; `src/engine/generation/start-generation.ts`; `src/engine/generation/prompt-assembly.ts` | yes | Target 9 owns message extra storage; this row owns whether those flags affect prompt inclusion. | | 12-PROMPT-RUNTIME-lorebook-scan-activation | Active lorebook scope, manual/global/character/persona/game filters, keyword and semantic matching, trigger labels, timing state, ephemeral state, and content macro resolution feed prompt assembly. | RUNTIME | both | `packages/server/src/services/prompt/marker-expander.ts`; `packages/server/src/services/lorebook/index.ts`; `packages/server/src/routes/generate.routes.ts` | `src/engine/generation/active-lorebook-scanner.ts`; `src/engine/generation/prompt-assembly.ts`; `src/engine/generation-core/lorebooks/active-lorebook-scope.ts` | yes | Coordinates with Target 7 for lorebook editor/storage contract. | | 12-PROMPT-RUNTIME-lorebook-injection-budget-depth | Activated lorebook entries inject as world info before/after blocks or depth messages, enforce token budgets, preserve skipped-entry diagnostics, and anchor depth entries inside history bounds. | RUNTIME | both | `packages/server/src/services/lorebook/prompt-injector.ts`; `packages/server/src/services/prompt/assembler.ts` | `src/engine/generation-core/lorebooks/prompt-injector.ts`; `src/engine/generation/prompt-assembly.ts` | yes | Include constant entries, fresh-user-message priority, order, role, and depth semantics. | | 12-PROMPT-RUNTIME-chat-summary-injection | Compiled chat summary is included through explicit summary markers or fallback insertion, fingerprinted, and surfaced for saved prompt/debug compatibility. | RUNTIME | both | `packages/server/src/services/prompt/assembler.ts`; `packages/server/src/routes/generate.routes.ts`; `packages/shared/src/utils/chat-summary-entries.ts` | `src/engine/generation/prompt-assembly.ts`; `src/engine/shared/text/chat-summary-entries.ts`; `src/engine/shared/text/chat-summary-fingerprint.ts` | yes | Target 9 owns summary edit/generation workflow; this row owns summary prompt consumption. | | 12-PROMPT-RUNTIME-agent-data-two-pass | Generation runs an initial assembly, executes pre-generation agents, optionally pauses for injection review, then reassembles with fresh agent data and context injections before model call. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/services/prompt/assembler.ts`; legacy agent executor | `src/engine/generation/start-generation.ts`; `src/engine/generation/agent-runner.ts`; `src/engine/generation/prompt-assembly.ts` | yes | Target 13 owns agent execution details; this row owns prompt data handoff and second-pass assembly. | | 12-PROMPT-RUNTIME-memory-connected-context | Memory recall chunks, connected conversation summaries, OOC influences, durable connected notes, and command capability reminders are injected or consumed in the correct mode and prompt position. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/routes/chats.routes.ts`; `packages/server/src/services/memory-recall.ts`; legacy connected note storage | `src/engine/generation/prompt-assembly.ts`; `src/engine/generation/connected-commands.ts`; `src/engine/contracts/types/chat.ts` | yes | Target 9 owns storage/UI; Target 12 owns prompt inclusion and consumption semantics. | | 12-PROMPT-RUNTIME-roleplay-scene-directives | Roleplay prompt assembly adds narrator style, scene prompt, scene continuity, direct-message command reminders, author notes, and character depth prompts without changing conversation/game owners. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/services/prompt/assembler.ts`; legacy roleplay chat prompt code | `src/engine/generation/prompt-assembly.ts`; `src/engine/modes/roleplay/scene/scene-service.ts`; `src/engine/modes/chat/commands/character-commands.ts` | yes | Mode separation check: roleplay owns roleplay scene semantics. | | 12-PROMPT-RUNTIME-game-system-prompt | Game prompt assembly applies segment edits, game tracker baseline, GM system prompt, party prompt/reminder, player notes, world/game state, lorebook scope exclusions, and game-specific generation guidance. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/services/game/gm-prompts.ts`; `packages/server/src/services/game/party-prompts.ts` | `src/engine/generation/prompt-assembly.ts`; `src/engine/modes/game/prompts/gm-prompts.ts`; `src/engine/modes/game/prompts/party-prompts.ts`; `src/engine/modes/game/turn/game-turn.service.ts` | yes | Target 17 owns end-to-end game mode behavior. | | 12-PROMPT-RUNTIME-regenerate-continue-impersonate | Regenerate, continue, guided/narrator/amend instruction, assistant prefill, direct messages, and impersonation flows slice history and directive messages without saving duplicate user turns. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/services/conversation/impersonate-prompt.ts`; `packages/shared/src/utils/generation-guide.ts` | `src/engine/generation/start-generation.ts`; `src/engine/generation/generation-replay.ts`; `src/engine/modes/chat/commands/impersonate-prompt.ts`; `src/engine/shared/text/generation-guide.ts` | yes | Coordinates with Target 15/16 for user-facing mode outcomes. | | 12-PROMPT-RUNTIME-group-turn-scoping | Group and multi-character generation resolves target speakers, group scenario overrides, individual/sequential turns, speaker-scoped macros, strict role shaping, and response order. | RUNTIME | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/services/prompt/assembler.ts`; legacy group chat paths | `src/engine/generation/start-generation.ts`; `src/engine/generation/prompt-assembly.ts`; `src/features/modes/conversation/components/ConversationInput.tsx` | yes | Include both conversation group chats and roleplay multi-character scenes. | | 12-PROMPT-RUNTIME-regex-prompt-transforms | User input and outgoing prompt regex scripts transform prompt messages with macro-aware replacements at the same stage as legacy generation. | RUNTIME | both | `packages/client/src/hooks/use-apply-regex.ts`; `packages/server/src/services/regex/regex-application.ts`; `packages/server/src/routes/generate.routes.ts` | `src/engine/generation/regex-runtime.ts`; `src/engine/generation-core/regex/regex-application.ts`; `src/engine/generation/prompt-assembly.ts`; `src/features/catalog/agents/regex-application.ts` | yes | Target 13 owns regex authoring/storage; this row owns prompt transformation timing. | | 12-PROMPT-CONTRACT-message-shaping-provider-ready | Final prompt messages merge adjacent roles, optionally squash system messages, enforce strict role alternation for roleplay, collapse to single-user-message mode, attach images, and remain provider-ready. | CONTRACT | both | `packages/server/src/services/prompt/merger.ts`; `packages/server/src/services/prompt/assembler.ts`; `packages/server/src/routes/generate.routes.ts` | `src/engine/generation-core/prompt/merger.ts`; `src/engine/generation/prompt-assembly.ts`; `src/engine/generation/start-generation.ts` | yes | Target 11 starts after this provider-neutral message shape exists. | | 12-PROMPT-PERF-context-window-fit | Prompt assembly and final provider send trim history/messages to context limits while preserving non-history prompt sections and enough recent history to generate. | PERF | both | `packages/server/src/routes/generate.routes.ts`; legacy provider send path | `src/engine/generation/context-window.ts`; `src/engine/generation/start-generation.ts`; `src/engine/generation/prompt-assembly.ts` | yes | Needs measured or harness proof in parityscan, not just static row. | | 12-PROMPT-STORAGE-saved-prompt-snapshot-replay | Exact prompts used for generation are stored and replayed for prompt inspection/regeneration, with legacy `cachedPrompt` compatibility and current prompt snapshot fields. | STORAGE | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/routes/chats.routes.ts`; `packages/client/src/components/chat/PeekPromptModal.tsx` | `src/engine/generation/start-generation.ts`; `src/features/modes/shared/chat-ui/lib/prompt-snapshot.ts`; `src/features/modes/shared/chat-ui/hooks/use-chat-timeline-actions.ts`; `src-tauri/src/commands/storage/shared.rs` | yes | Target 9 owns physical storage/display compatibility; Target 12 owns prompt replay semantics. | | 12-PROMPT-API-preview-peek-assembly | Prompt preview and Peek Prompt assemble or load prompt data without unintended runtime side effects, return visible parameters/model info, and support before-message/preset/choice overrides. | API | both | `packages/server/src/routes/prompts.routes.ts`; `packages/server/src/routes/chats.routes.ts`; `packages/server/src/routes/prompt-reviewer.routes.ts` | `src/engine/generation/prompt-preview.ts`; `src/engine/generation/prompt-reviewer.ts`; `src/features/modes/shared/chat-ui/components/PeekPromptModal.tsx` | yes | Include preview-only lorebook timing/ephemeral behavior in focused proof. | | 12-PROMPT-REMOTE-hostable-assembly-path | Refactor hostable runtime uses the same shared API wrappers, storage reads, and LLM capability ports for prompt assembly as embedded Tauri, without embedded-only prompt behavior. | REMOTE | refactor_only | legacy server REST route by design | `src/features/runtime/generation/hooks/use-generate.ts`; `src/engine/generation/start-generation.ts`; `src/shared/api/storage-api.ts`; `src/shared/api/llm-api.ts`; `src/shared/api/remote-runtime.ts`; `src-tauri/src/http_dispatch.rs` | yes | Refactor-specific risk because generation assembly runs against embedded or hostable capabilities. | | 12-PROMPT-ERROR-invalid-empty-fallbacks | Missing chat/connection/preset, invalid marker config, empty prompt sections, no active characters, offline/delayed characters, malformed metadata, and model-call-aborted states surface as explicit errors or intentional fallbacks. | ERROR | both | `packages/server/src/routes/generate.routes.ts`; `packages/server/src/services/prompt/assembler.ts`; legacy chat UI | `src/engine/generation/start-generation.ts`; `src/engine/generation/prompt-assembly.ts`; `src/features/runtime/generation/hooks/use-generate.ts`; `src/features/modes/shared/chat-ui` | yes | Parityscan should include negative-control rows for should-not-send and fallback prompt paths. | ## Coverage Matrix | Surface ID | Status | Proof | Follow-up | | --- | --- | --- | --- | | 12-PROMPT-CONTRACT-assembler-input-output | unscanned | static inventory only | | | 12-PROMPT-RUNTIME-preset-selection-parameter-merge | refactor_better | Batch 2 static trace | Refactor adds request-level preset/parameter override consumption; no issue filed. | | 12-PROMPT-RUNTIME-section-marker-expansion | blocked | Batch 2 static trace | Runtime marker expansion mostly matches; order parity proof requires Target 8 preset CRUD/import/export tracing, so no issue filed. | | 12-PROMPT-RUNTIME-macro-variable-resolution | covered_static | 2026-06-07 closure rescan | #2446 closed; current deferred character macro paths are present. | | 12-PROMPT-RUNTIME-character-persona-context | covered_static | 2026-06-07 closure rescan | #2444 and #2445 closed; current creator-notes marker and group scenario override paths are present. | | 12-PROMPT-RUNTIME-history-window-hidden-reasoning | refactor_better | Batch 4 static trace | Refactor preserves conversation-start, context limit, hidden-from-AI, role mapping, and opt-in stored reasoning behavior; no issue filed. | | 12-PROMPT-RUNTIME-lorebook-scan-activation | no gap | Batch 5 static trace | Active scope, keyword/semantic matching, timing, ephemeral state, trigger filters, and macro-resolved content match legacy; no issue filed. | | 12-PROMPT-RUNTIME-lorebook-injection-budget-depth | gap | Batch 5 static trace | #2448 | | 12-PROMPT-RUNTIME-chat-summary-injection | covered_static | 2026-06-07 closure rescan | #2447 closed; current prompt assembly includes explicit marker handling and fallback insertion when no marker inserted the summary. | | 12-PROMPT-RUNTIME-agent-data-two-pass | no gap | Batch 7 static trace | | | 12-PROMPT-RUNTIME-memory-connected-context | no gap | Batch 6 static trace | | | 12-PROMPT-RUNTIME-roleplay-scene-directives | refactor_better | Batch 9 static trace | Refactor preserves legacy scene directives and adds explicit narrator style plus previous scene continuity; no issue filed. | | 12-PROMPT-RUNTIME-game-system-prompt | no gap | Batch 9 static trace | Refactor preserves legacy GM prompt assembly, segment edits, game state/player notes, lore merge, and format reminder; no issue filed. | | 12-PROMPT-RUNTIME-regenerate-continue-impersonate | covered_static | 2026-06-07 closure rescan | #2450 closed; user-message regeneration source/rewrite helpers and focused generation tests are present. | | 12-PROMPT-RUNTIME-group-turn-scoping | no gap | Batch 10 static trace | | | 12-PROMPT-RUNTIME-regex-prompt-transforms | covered_static | 2026-06-07 closure rescan | #2449 closed; current prompt regex runs after prompt/injection and group-turn messages are assembled. | | 12-PROMPT-CONTRACT-message-shaping-provider-ready | unscanned | static inventory only | | | 12-PROMPT-PERF-context-window-fit | refactor_better | Batch 4 static trace + `pnpm exec vitest run src/engine/generation/context-window.test.ts` | Refactor trims final provider messages to effective context by dropping oldest history while preserving non-history prompt sections; no issue filed. | | 12-PROMPT-STORAGE-saved-prompt-snapshot-replay | refactor_better | Batch 11 static trace | Refactor stores structured prompt snapshots, preserves per-swipe replay, synthesizes legacy `cachedPrompt` for inspector compatibility, and keeps bounded snapshot retention; no issue filed. | | 12-PROMPT-API-preview-peek-assembly | refactor_better | Batch 11 static trace | Refactor keeps saved-snapshot-first Peek Prompt behavior and adds before-message, preset, choice, character, parameter, and visible model-info preview support without persisting lorebook timing/ephemeral state; no issue filed. | | 12-PROMPT-REMOTE-hostable-assembly-path | no gap | Batch 12 static trace | Refactor hostable path uses shared `storageApi`/`llmApi` capability ports for prompt assembly and routes remote storage/LLM calls through `/api/invoke` or `/api/llm/stream`; no issue filed. | | 12-PROMPT-ERROR-invalid-empty-fallbacks | gap | 2026-06-07 static closure rescan | #2451 is closed, but current `refactor@d7d733ce` still falls back to the default/first stored connection when no request/chat connection id is set. Random-pool handling is present. | ## Follow-Ups | Issue | State | Why it matters | | --- | --- | --- | | Batch 2 section marker order proof | blocked, not filed | Refactor runtime consumes child `sortOrder` while legacy consumes `preset.sectionOrder`; proving whether this is a gap requires preset CRUD/import/export proof owned by Target 8. | | #2444 | closed | `12-PROMPT-RUNTIME-character-persona-context`: creator notes marker field was fixed; current static trace shows `creator_notes`/`creatorNotes` return `GenerationCharacterContext.creatorNotes`. | | #2445 | closed | `12-PROMPT-RUNTIME-character-persona-context`: group scenario override consumption is present in current prompt assembly macro and marker paths. | | #2446 | closed | `12-PROMPT-RUNTIME-macro-variable-resolution`: deferred character macro support is present in current macro/prompt assembly paths. | | #2447 | closed | `12-PROMPT-RUNTIME-chat-summary-injection`: current prompt assembly has explicit marker handling and fallback summary insertion when no marker inserted it. | | #2448 | closed | `12-PROMPT-RUNTIME-lorebook-injection-budget-depth`: refactor treated the first over-budget lorebook entry as exhausting the lorebook/chat budget, dropping later smaller entries legacy would still consider. | | #2449 | closed | `12-PROMPT-RUNTIME-regex-prompt-transforms`: current prompt assembly runs prompt regex after prompt/injection and group-turn messages are assembled. | | #2450 | closed | `12-PROMPT-RUNTIME-regenerate-continue-impersonate`: user-message regeneration source/rewrite helpers and focused generation tests are present in current refactor. | | #2451 | closed, still blocking current rescan | `12-PROMPT-ERROR-invalid-empty-fallbacks`: random connection ids now select from the random pool, but missing request/chat connections still fall back to the default/first stored connection on current `refactor@d7d733ce`. Needs reopen or follow-up fix before Target 12 can be `on_par`. | ## Refactor-Better Or Intentional Divergence - Batch 2: `12-PROMPT-RUNTIME-preset-selection-parameter-merge` is refactor-better because refactor consumes request-level prompt preset and request parameter overrides in the runtime merge; no issue filed. - Batch 4: `12-PROMPT-RUNTIME-history-window-hidden-reasoning` is refactor-better because refactor preserves legacy history filtering and opt-in reasoning replay behavior; no issue filed. - Batch 4: `12-PROMPT-PERF-context-window-fit` is refactor-better because refactor adds final provider-send context fitting that trims oldest history while preserving prompt sections; no issue filed. - Batch 9: `12-PROMPT-RUNTIME-roleplay-scene-directives` is refactor-better because refactor preserves legacy roleplay scene directives and adds explicit narrator style plus previous scene continuity; no issue filed. - Batch 11: `12-PROMPT-STORAGE-saved-prompt-snapshot-replay` is refactor-better because refactor stores structured prompt snapshots, preserves per-swipe replay, synthesizes legacy `cachedPrompt` for inspector compatibility, and keeps bounded snapshot retention; no issue filed. - Batch 11: `12-PROMPT-API-preview-peek-assembly` is refactor-better because refactor keeps saved-snapshot-first Peek Prompt behavior and adds before-message, preset, choice, character, parameter, and visible model-info preview support without persisting lorebook timing/ephemeral state; no issue filed. ## Rescan Criteria - Run a prompt assembly parityscan on current `refactor`. - Include assembler contract, preset/parameter precedence, markers, macros, character/persona context, history filtering, lorebook scan/injection/budget, summaries, pre-generation agent reassembly, memory/connected context, roleplay directives, game prompts, regenerate/continue/impersonate, group turns, regex prompt transforms, role/message shaping, context fitting, saved prompt snapshots, preview/peek APIs, hostable runtime parity, and negative-control fallback paths. - Coordinate stored prompt snapshot proof with Target 9, preset authoring/import proof with Target 8, provider request transport with Target 11, agent/tool details with Target 13, and mode end-to-end proof with Targets 15, 16, and 17.
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#1196
No description provided.