fix(desktop): console.log 清理 — 替换为结构化 logger

将 desktop/src 中 23 处 console.log 替换为 createLogger() 结构化日志:
- 生产构建自动静默 debug/info 级别
- 保留 console.error 用于关键错误可见性
- 新增 dompurify 依赖修复 XSS 防护引入缺失

涉及文件: App.tsx, offlineStore.ts, autonomy-manager.ts,
gateway-auth.ts, llm-service.ts, request-helper.ts,
security-index.ts, skill-discovery.ts, use-onboarding.ts 等 16 个文件
This commit is contained in:
iven
2026-03-30 16:22:16 +08:00
parent 544358764e
commit ecd7f2e928
16 changed files with 140 additions and 68 deletions

View File

@@ -28,6 +28,9 @@ import { invoke } from '@tauri-apps/api/core';
import { useProposalNotifications, ProposalNotificationHandler } from './lib/useProposalNotifications';
import { useToast } from './components/ui/Toast';
import type { Clone } from './store/agentStore';
import { createLogger } from './lib/logger';
const log = createLogger('App');
type View = 'main' | 'settings';
@@ -149,18 +152,18 @@ function App() {
if (!isRunning && status.cliAvailable) {
setBootstrapStatus('Starting ZCLAW Gateway...');
console.log('[App] Local gateway not running, auto-starting...');
log.debug('Local gateway not running, auto-starting...');
await startLocalGateway();
// Wait for gateway to be ready
await new Promise(resolve => setTimeout(resolve, 2000));
console.log('[App] Local gateway started');
log.debug('Local gateway started');
} else if (isRunning) {
console.log('[App] Local gateway already running');
log.debug('Local gateway already running');
}
} catch (err) {
console.warn('[App] Failed to check/start local gateway:', err);
log.warn('Failed to check/start local gateway:', err);
}
}
@@ -204,13 +207,13 @@ function App() {
stats.totalEntries,
stats.storageSizeBytes
);
console.log('[App] Memory stats synced to heartbeat engine');
log.debug('Memory stats synced to heartbeat engine');
} catch (statsErr) {
console.warn('[App] Failed to sync memory stats:', statsErr);
log.warn('Failed to sync memory stats:', statsErr);
}
await intelligenceClient.heartbeat.start(defaultAgentId);
console.log('[App] Heartbeat engine started for self-evolution');
log.debug('Heartbeat engine started for self-evolution');
// Set up periodic memory stats sync (every 5 minutes)
const MEMORY_STATS_SYNC_INTERVAL = 5 * 60 * 1000;
@@ -224,9 +227,9 @@ function App() {
stats.totalEntries,
stats.storageSizeBytes
);
console.log('[App] Memory stats synced (periodic)');
log.debug('Memory stats synced (periodic)');
} catch (err) {
console.warn('[App] Periodic memory stats sync failed:', err);
log.warn('Periodic memory stats sync failed:', err);
}
}, MEMORY_STATS_SYNC_INTERVAL);
@@ -234,7 +237,7 @@ function App() {
// @ts-expect-error - Global cleanup reference
window.__ZCLAW_STATS_SYNC_INTERVAL__ = statsSyncInterval;
} catch (err) {
console.warn('[App] Failed to start heartbeat engine:', err);
log.warn('Failed to start heartbeat engine:', err);
// Non-critical, continue without heartbeat
}
@@ -270,10 +273,10 @@ function App() {
model: embConfig.model || undefined,
endpoint: embConfig.endpoint || undefined,
});
console.log('[App] Embedding configuration restored to backend');
log.debug('Embedding configuration restored to backend');
}
} catch (embErr) {
console.warn('[App] Failed to restore embedding config:', embErr);
log.warn('Failed to restore embedding config:', embErr);
// Non-critical, semantic search will fall back to TF-IDF
}
@@ -290,17 +293,17 @@ function App() {
apiKey: modelConfig.apiKey,
model: modelConfig.model || undefined,
});
console.log('[App] Summary driver configured with active LLM');
log.debug('Summary driver configured with active LLM');
}
} catch (sumErr) {
console.warn('[App] Failed to configure summary driver:', sumErr);
log.warn('Failed to configure summary driver:', sumErr);
// Non-critical, summaries won't be auto-generated
}
// Step 6: Bootstrap complete
setBootstrapping(false);
} catch (err) {
console.error('[App] Bootstrap failed:', err);
log.error('Bootstrap failed:', err);
// Still allow app to load, connection status will show error
setBootstrapping(false);
}
@@ -391,7 +394,7 @@ function App() {
}
}
} catch (err) {
console.warn('[App] Failed to create default agent on skip:', err);
log.warn('Failed to create default agent on skip:', err);
}
// Mark onboarding as completed