diff --git a/src/components/monitor/SettingsPanel.tsx b/src/components/monitor/SettingsPanel.tsx index 733de3c..c4630a9 100644 --- a/src/components/monitor/SettingsPanel.tsx +++ b/src/components/monitor/SettingsPanel.tsx @@ -1,11 +1,13 @@ import { useState } from 'react' import { motion, AnimatePresence } from 'framer-motion' -import { Settings, X, History, Wifi, WifiOff, RefreshCw } from 'lucide-react' +import { Settings, X, History, Wifi, WifiOff, RefreshCw, Terminal } from 'lucide-react' interface SettingsPanelProps { connected: boolean historicalMode: boolean + debugMode: boolean onHistoricalModeChange: (enabled: boolean) => void + onDebugModeChange: (enabled: boolean) => void onConnect: () => void onDisconnect: () => void onRefresh: () => void @@ -14,7 +16,9 @@ interface SettingsPanelProps { export function SettingsPanel({ connected, historicalMode, + debugMode, onHistoricalModeChange, + onDebugModeChange, onConnect, onDisconnect, onRefresh, @@ -132,6 +136,31 @@ export function SettingsPanel({ + {/* Debug mode toggle */} +
+
+ + + Debug Logging + +
+ +

+ > log raw events to terminal +

+ + +
+ {/* Info panel */}

diff --git a/src/integrations/trpc/router.ts b/src/integrations/trpc/router.ts index 23100e0..f08d9b4 100644 --- a/src/integrations/trpc/router.ts +++ b/src/integrations/trpc/router.ts @@ -10,6 +10,9 @@ import { type MonitorAction, } from '~/integrations/clawdbot' +// Server-side debug mode state +let debugMode = false + const t = initTRPC.create({ transformer: superjson, }) @@ -51,6 +54,18 @@ const clawdbotRouter = router({ return { connected: client.connected } }), + setDebugMode: publicProcedure + .input(z.object({ enabled: z.boolean() })) + .mutation(({ input }) => { + debugMode = input.enabled + console.log(`[clawdbot] debug mode ${debugMode ? 'enabled' : 'disabled'}`) + return { debugMode } + }), + + getDebugMode: publicProcedure.query(() => { + return { debugMode } + }), + sessions: publicProcedure .input( z @@ -88,8 +103,16 @@ const clawdbotRouter = router({ const client = getClawdbotClient() const unsubscribe = client.onEvent((event) => { + // Log raw event when debug mode is enabled + if (debugMode) { + console.log('\n[DEBUG] Raw event:', JSON.stringify(event, null, 2)) + } + const parsed = parseEventFrame(event) if (parsed) { + if (debugMode && parsed.action) { + console.log('[DEBUG] Parsed action:', parsed.action.type, parsed.action.eventType, 'sessionKey:', parsed.action.sessionKey) + } if (parsed.session) { emit.next({ type: 'session', session: parsed.session }) } diff --git a/src/routes/monitor/index.tsx b/src/routes/monitor/index.tsx index a91af9c..7f0d2ad 100644 --- a/src/routes/monitor/index.tsx +++ b/src/routes/monitor/index.tsx @@ -62,6 +62,7 @@ function MonitorPage() { const [connecting, setConnecting] = useState(false) const [error, setError] = useState(null) const [historicalMode, setHistoricalMode] = useState(false) + const [debugMode, setDebugMode] = useState(false) const [selectedSession, setSelectedSession] = useState(null) // Sidebar collapse state - default to collapsed on mobile @@ -158,6 +159,15 @@ function MonitorPage() { } } + const handleDebugModeChange = async (enabled: boolean) => { + setDebugMode(enabled) + try { + await trpc.clawdbot.setDebugMode.mutate({ enabled }) + } catch (e) { + console.error('Failed to set debug mode:', e) + } + } + const handleToggleSidebar = useCallback(() => { setSidebarCollapsed((prev) => !prev) }, []) @@ -264,7 +274,9 @@ function MonitorPage() {