From cb71623375df0d48f3f91d37d982c9902c8ddfb9 Mon Sep 17 00:00:00 2001 From: Promansis Date: Thu, 21 May 2026 09:47:53 +0800 Subject: [PATCH 1/2] debug mode console logging --- .../settings/components/SettingsPanel.tsx | 2 +- src/shared/api/llm-api.ts | 22 ++++++-- src/shared/api/llm-debug-logger.ts | 50 +++++++++++++++++++ updates/people/promansis.md | 35 +++++++++++++ 4 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/shared/api/llm-debug-logger.ts diff --git a/src/features/settings/components/SettingsPanel.tsx b/src/features/settings/components/SettingsPanel.tsx index 64ddcc2..1ad4d73 100644 --- a/src/features/settings/components/SettingsPanel.tsx +++ b/src/features/settings/components/SettingsPanel.tsx @@ -3131,7 +3131,7 @@ function AdvancedSettings() { label="Debug mode" checked={debugMode} onChange={setDebugMode} - help="Logs the prompt and response payloads sent to the local Tauri console for debugging." + help="Shows the in-app agent debug panel and logs LLM prompt/response payloads to the browser console." /> {/* ── Profile Export ── */} diff --git a/src/shared/api/llm-api.ts b/src/shared/api/llm-api.ts index 96ca9b3..26194ff 100644 --- a/src/shared/api/llm-api.ts +++ b/src/shared/api/llm-api.ts @@ -1,5 +1,6 @@ import type { LlmChunk, LlmGateway, LlmRequest } from "../../engine/capabilities/llm"; import { Channel } from "@tauri-apps/api/core"; +import { logLlmCompleteResponse, logLlmRequest, logLlmStreamResponse } from "./llm-debug-logger"; import { invokeTauri } from "./tauri-client"; function createStreamId(): string { @@ -8,13 +9,20 @@ function createStreamId(): string { } export const llmApi: LlmGateway = { - complete: (request: LlmRequest) => - invokeTauri("llm_complete", { + complete: async (request: LlmRequest) => { + logLlmRequest("complete", request); + const response = await invokeTauri("llm_complete", { request, - }), + }); + logLlmCompleteResponse(response); + return response; + }, stream: async function* (request: LlmRequest, signal?: AbortSignal): AsyncGenerator { + logLlmRequest("stream", request); const streamId = createStreamId(); const queue: LlmChunk[] = []; + const debugChunks: LlmChunk[] = []; + let debugContent = ""; let completed = false; let failure: unknown = null; let wake: (() => void) | null = null; @@ -60,11 +68,19 @@ export const llmApi: LlmGateway = { continue; } const event = queue.shift()!; + debugChunks.push(event); + if ((event.type === "token" || event.type === "thinking") && event.text) { + debugContent += event.text; + } if (event.type === "error") throw new Error(String(event.text ?? event.data ?? "LLM stream failed")); yield event; } await command; if (failure) throw failure; + logLlmStreamResponse(debugChunks, debugContent); + } catch (error) { + logLlmStreamResponse(debugChunks, debugContent, error); + throw error; } finally { signal?.removeEventListener("abort", abort); } diff --git a/src/shared/api/llm-debug-logger.ts b/src/shared/api/llm-debug-logger.ts new file mode 100644 index 0000000..2875845 --- /dev/null +++ b/src/shared/api/llm-debug-logger.ts @@ -0,0 +1,50 @@ +import type { LlmChunk, LlmRequest } from "../../engine/capabilities/llm"; +import { useUIStore } from "../stores/ui.store"; + +type LlmDebugKind = "complete" | "stream"; + +function isDebugModeEnabled(): boolean { + try { + return useUIStore.getState().debugMode === true; + } catch { + return false; + } +} + +function redactSensitiveValue(value: unknown): unknown { + if (Array.isArray(value)) return value.map(redactSensitiveValue); + if (!value || typeof value !== "object") return value; + + const redacted: Record = {}; + for (const [key, entry] of Object.entries(value)) { + if (/(token|secret|password|api[_-]?key|authorization|cookie|credential)/i.test(key)) { + redacted[key] = "[REDACTED]"; + continue; + } + redacted[key] = redactSensitiveValue(entry); + } + return redacted; +} + +function logDebugGroup(label: string, payload: Record) { + if (!isDebugModeEnabled()) return; + console.groupCollapsed(label); + console.log(redactSensitiveValue(payload)); + console.groupEnd(); +} + +export function logLlmRequest(kind: LlmDebugKind, request: LlmRequest) { + logDebugGroup(`[Marinara debug] LLM ${kind} request`, { request }); +} + +export function logLlmCompleteResponse(response: string) { + logDebugGroup("[Marinara debug] LLM complete response", { response }); +} + +export function logLlmStreamResponse(chunks: LlmChunk[], content: string, error?: unknown) { + logDebugGroup("[Marinara debug] LLM stream response", { + content, + chunks, + ...(error ? { error: error instanceof Error ? error.message : String(error) } : {}), + }); +} diff --git a/updates/people/promansis.md b/updates/people/promansis.md index 0e27dfa..e185909 100644 --- a/updates/people/promansis.md +++ b/updates/people/promansis.md @@ -2,6 +2,13 @@ ## Current Work +- GitHub issue #34: Debug Mode contract mismatch. + - Status: Locally verified + - Last updated: 2026-05-21 + - Current path: `src/shared/api/llm-api.ts` debug logging and Settings copy. + - Result: shared LLM complete/stream calls now emit redacted prompt and response payloads to the browser console when Debug mode is enabled, while the in-app agent debug panel remains tied to the same setting. + - Next step: smoke a real generation path with Debug mode enabled and confirm the console groups appear. + - Message translation failures leave no visible error - Status: Fixed locally on `fix/bug-19-translation-errors` - Impact area: UI, shared/api, Rust capability error surface @@ -10,6 +17,34 @@ ## Owned Bugs +## Debug Mode contract mismatch + +- Status: Locally verified +- Owner: Promansis +- Impact area: shared/api +- Reported: 2026-05-21 +- Last updated: 2026-05-21 + +### Steps + +1. Enable Debug mode in settings. +2. Run a generation path. +3. Compare the Settings help text against the runtime debug output. + +### Expected + +Debug mode should match its documented contract. + +### Actual + +The in-app agent debug panel is wired, but prompt/response console logging is not consistently owned by a shared LLM helper. + +### Notes + +- Upstream issue: https://github.com/Pasta-Devs/Marinara-Engine-Refactor/issues/34 +- Fix: centralized redacted LLM request/response console logging in `src/shared/api/llm-api.ts` while preserving the agent debug panel. +- Verification: `pnpm typecheck` and `pnpm check` passed. + ## Message translation failures leave no visible error - Status: Fixed locally on `fix/bug-19-translation-errors` From 564526b3c42efa9149c716ca606233f27bcaa320 Mon Sep 17 00:00:00 2001 From: Promansis Date: Thu, 21 May 2026 10:02:04 +0800 Subject: [PATCH 2/2] character library avatar crop scaling --- src/features/characters/components/CharacterLibraryView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/characters/components/CharacterLibraryView.tsx b/src/features/characters/components/CharacterLibraryView.tsx index bf9d721..aad5878 100644 --- a/src/features/characters/components/CharacterLibraryView.tsx +++ b/src/features/characters/components/CharacterLibraryView.tsx @@ -104,7 +104,7 @@ function CharacterLibraryDetailCard({ return (
-
+
{character.avatarPath ? ( -
+
{char.avatarPath ? (