(panelId: string)
| 390 | }; |
| 391 | |
| 392 | const finalizeAutoContextRun = async (panelId: string): Promise<void> => { |
| 393 | console.log(`[auto-context-debug] finalizeAutoContextRun called for panel ${panelId}`); |
| 394 | try { |
| 395 | const bufferedOutputs = sessionManager.consumeAutoContextCapture(panelId); |
| 396 | const outputs = bufferedOutputs.length > 0 |
| 397 | ? bufferedOutputs |
| 398 | : (typeof sessionManager.getPanelOutputs === 'function' |
| 399 | ? sessionManager.getPanelOutputs(panelId, 200) |
| 400 | : []); |
| 401 | console.log(`[auto-context-debug] Extracted ${outputs.length} outputs for context usage analysis`); |
| 402 | |
| 403 | const contextUsage = extractContextUsageFromOutputs(outputs); |
| 404 | console.log(`[auto-context-debug] Context usage extracted: ${contextUsage || 'none found'}`); |
| 405 | |
| 406 | const timestamp = new Date().toISOString(); |
| 407 | |
| 408 | console.log(`[auto-context-debug] Setting autoContextRunState back to 'idle'`); |
| 409 | await updateClaudePanelCustomState(panelId, (state) => ({ |
| 410 | ...state, |
| 411 | autoContextRunState: 'idle', |
| 412 | lastAutoContextAt: timestamp, |
| 413 | contextUsage: contextUsage ?? state.contextUsage ?? null |
| 414 | })); |
| 415 | console.log(`[auto-context-debug] finalizeAutoContextRun completed successfully`); |
| 416 | } catch (error) { |
| 417 | console.error(`[Main] Failed to finalize automatic context run for panel ${panelId}:`, error); |
| 418 | console.log(`[auto-context-debug] Error in finalizeAutoContextRun: ${error instanceof Error ? error.message : String(error)}`); |
| 419 | sessionManager.clearAutoContextCapture(panelId); |
| 420 | await updateClaudePanelCustomState(panelId, (state) => ({ |
| 421 | ...state, |
| 422 | autoContextRunState: 'idle' |
| 423 | })); |
| 424 | } |
| 425 | }; |
| 426 | |
| 427 | const startAutoContextRun = async (panelId: string, sessionId: string): Promise<void> => { |
| 428 | console.log(`[auto-context-debug] startAutoContextRun called - panelId: ${panelId}, sessionId: ${sessionId}`); |
no test coverage detected