feat: reduce debug logging with conditional output based on streamDebugEnabled

This commit is contained in:
Bohdan Triapitsyn
2025-12-25 03:33:24 +02:00
parent 6fbdf90cd3
commit eb8355b37e
5 changed files with 27 additions and 22 deletions
+15 -12
View File
@@ -3,6 +3,7 @@ import { useSessionStore } from '@/stores/useSessionStore';
import { useDirectoryStore } from '@/stores/useDirectoryStore';
import { opencodeClient } from '@/lib/opencode/client';
import { checkIsGitRepository } from '@/lib/gitApi';
import { streamDebugEnabled } from '@/stores/utils/streamDebug';
export interface DebugMessageInfo {
messageId: string;
@@ -631,18 +632,20 @@ export const debugUtils = {
if (typeof window !== 'undefined') {
(window as any).__opencodeDebug = debugUtils;
console.log('[DEBUG] OpenCode Debug Utils loaded! Use window.__opencodeDebug in console');
console.log('Available commands:');
console.log(' __opencodeDebug.getLastAssistantMessage() - Get last assistant message details');
console.log(' __opencodeDebug.getAllMessages(truncate?) - List all messages (truncate=true for short preview)');
console.log(' __opencodeDebug.truncateMessages(messages) - Truncate long fields in messages array');
console.log(' __opencodeDebug.getAppStatus() - Show app status snapshot');
console.log(' __opencodeDebug.checkLastMessage() - Check if last message is problematic');
console.log(' __opencodeDebug.findEmptyMessages() - Find all empty assistant messages');
console.log(' __opencodeDebug.showRetryHelp() - Show instructions for handling empty responses');
console.log(' __opencodeDebug.getStreamingState() - Get streaming state info');
console.log(' __opencodeDebug.analyzeMessageCompletionConsistency(opts?) - Compare time.completed vs part timings');
console.log(' __opencodeDebug.checkCompletionStatus() - Check completion status of last message');
if (streamDebugEnabled()) {
console.log('[DEBUG] OpenCode Debug Utils loaded! Use window.__opencodeDebug in console');
console.log('Available commands:');
console.log(' __opencodeDebug.getLastAssistantMessage() - Get last assistant message details');
console.log(' __opencodeDebug.getAllMessages(truncate?) - List all messages (truncate=true for short preview)');
console.log(' __opencodeDebug.truncateMessages(messages) - Truncate long fields in messages array');
console.log(' __opencodeDebug.getAppStatus() - Show app status snapshot');
console.log(' __opencodeDebug.checkLastMessage() - Check if last message is problematic');
console.log(' __opencodeDebug.findEmptyMessages() - Find all empty assistant messages');
console.log(' __opencodeDebug.showRetryHelp() - Show instructions for handling empty responses');
console.log(' __opencodeDebug.getStreamingState() - Get streaming state info');
console.log(' __opencodeDebug.analyzeMessageCompletionConsistency(opts?) - Compare time.completed vs part timings');
console.log(' __opencodeDebug.checkCompletionStatus() - Check completion status of last message');
}
window.addEventListener('error', (event) => {
try {
+7 -2
View File
@@ -10,6 +10,7 @@ import { refreshAfterOpenCodeRestart } from '@/stores/useAgentsStore';
import { useCommandsStore } from '@/stores/useCommandsStore';
import { useFileSearchStore } from '@/stores/useFileSearchStore';
import { emitConfigChange } from '@/lib/configSync';
import { streamDebugEnabled } from '@/stores/utils/streamDebug';
import { getSafeStorage } from './utils/safeStorage';
interface DirectoryStore {
@@ -296,13 +297,17 @@ export const useDirectoryStore = create<DirectoryStore>()(
setDirectory: (path: string, options?: { showOverlay?: boolean }) => {
const homeDir = cachedHomeDirectory || get().homeDirectory || safeStorage.getItem('homeDirectory');
const resolvedPath = resolveDirectoryPath(path, homeDir);
console.log('[DirectoryStore] setDirectory called with path:', resolvedPath);
if (streamDebugEnabled()) {
console.log('[DirectoryStore] setDirectory called with path:', resolvedPath);
}
const showOverlay = options?.showOverlay ?? true;
opencodeClient.setDirectory(resolvedPath);
invalidateFileSearchCache();
const restartPromise = notifyOpenCodeWorkingDirectory(resolvedPath, { showOverlay });
console.log('[DirectoryStore] notifyOpenCodeWorkingDirectory initiated');
if (streamDebugEnabled()) {
console.log('[DirectoryStore] notifyOpenCodeWorkingDirectory initiated');
}
set((state) => {