Skip to content

Commit 1ada08f

Browse files
author
catlog22
committed
refactor: 移除调试日志相关代码,简化历史保存逻辑
1 parent 65ff5f5 commit 1ada08f

4 files changed

Lines changed: 12 additions & 96 deletions

File tree

ccw/src/commands/install.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,17 @@ export async function installCommand(options: InstallOptions): Promise<void> {
306306
info(` Files in manifest: ${existingManifest.files?.length || 0}`);
307307
info(` Installed: ${new Date(existingManifest.installation_date).toLocaleDateString()}`);
308308

309-
const { backup } = await inquirer.prompt([{
310-
type: 'confirm',
311-
name: 'backup',
312-
message: 'Create backup before reinstalling?',
313-
default: true
314-
}]);
315-
316-
if (backup) {
317-
await createBackup(existingManifest);
309+
if (!options.force) {
310+
const { backup } = await inquirer.prompt([{
311+
type: 'confirm',
312+
name: 'backup',
313+
message: 'Create backup before reinstalling?',
314+
default: true
315+
}]);
316+
317+
if (backup) {
318+
await createBackup(existingManifest);
319+
}
318320
}
319321

320322
// Clean based on manifest records
@@ -495,7 +497,7 @@ export async function installCommand(options: InstallOptions): Promise<void> {
495497
});
496498

497499
// Install Git Bash fix on Windows
498-
if (platform() === 'win32') {
500+
if (platform() === 'win32' && !options.force) {
499501
console.log('');
500502
const { installFix } = await inquirer.prompt([{
501503
type: 'confirm',

ccw/src/tools/cli-executor-core.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,6 @@ import {
3535
saveConversation
3636
} from './cli-executor-state.js';
3737

38-
// Debug logging for history save investigation (Iteration 4)
39-
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
40-
const DEBUG_LOG_PATH = path.join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
41-
42-
// Ensure debug log directory exists
43-
try {
44-
const debugDir = path.dirname(DEBUG_LOG_PATH);
45-
if (!fs.existsSync(debugDir)) {
46-
fs.mkdirSync(debugDir, { recursive: true });
47-
}
48-
} catch (err) {
49-
// Ignore directory creation errors
50-
}
51-
52-
function writeDebugLog(event: string, data: Record<string, any>): void {
53-
try {
54-
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
55-
fs.appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
56-
} catch (err) {
57-
// Silently ignore logging errors
58-
}
59-
}
60-
6138
// Track all running child processes for cleanup on interruption (multi-process support)
6239
const runningChildProcesses = new Set<ChildProcess>();
6340

@@ -1296,11 +1273,8 @@ async function executeCliTool(
12961273
};
12971274
// Try to save conversation to history
12981275
try {
1299-
writeDebugLog('BEFORE_SAVE_CONV', { conversationId: conversation.id, workingDir, tool });
13001276
saveConversation(workingDir, conversation);
1301-
writeDebugLog('AFTER_SAVE_CONV', { conversationId: conversation.id, workingDir, tool });
13021277
} catch (err) {
1303-
writeDebugLog('SAVE_CONV_OUTER_ERROR', { conversationId: conversation.id, workingDir, tool, error: (err as Error).message, stack: (err as Error).stack });
13041278
// Non-fatal: continue even if history save fails
13051279
console.error('[CLI Executor] Failed to save history:', (err as Error).message);
13061280
}

ccw/src/tools/cli-executor-state.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,15 @@ import type { CliOutputUnit } from './cli-output-converter.js';
99
import * as fs from 'fs';
1010
import * as path from 'path';
1111

12-
// Debug logging for history save investigation (Iteration 4)
13-
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
14-
const DEBUG_LOG_PATH = path.join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
15-
16-
// Ensure debug log directory exists
17-
try {
18-
const debugDir = path.dirname(DEBUG_LOG_PATH);
19-
if (!fs.existsSync(debugDir)) {
20-
fs.mkdirSync(debugDir, { recursive: true });
21-
}
22-
} catch (err) {
23-
// Ignore directory creation errors
24-
}
25-
26-
function writeDebugLog(event: string, data: Record<string, any>): void {
27-
try {
28-
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
29-
fs.appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
30-
} catch (err) {
31-
// Silently ignore logging errors
32-
}
33-
}
34-
3512
// Lazy-loaded SQLite store module
3613
let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null;
3714

3815
/**
3916
* Get or initialize SQLite store (async)
4017
*/
4118
export async function getSqliteStore(baseDir: string) {
42-
writeDebugLog('GET_STORE', { baseDir, baseDirType: typeof baseDir, moduleInitialized: sqliteStoreModule !== null });
4319
if (!sqliteStoreModule) {
4420
sqliteStoreModule = await import('./cli-history-store.js');
45-
writeDebugLog('MODULE_LOADED', { baseDir });
4621
}
4722
return sqliteStoreModule.getHistoryStore(baseDir);
4823
}
@@ -163,20 +138,15 @@ async function saveConversationAsync(baseDir: string, conversation: Conversation
163138
* @param baseDir - Project base directory (NOT historyDir)
164139
*/
165140
export function saveConversation(baseDir: string, conversation: ConversationRecord): void {
166-
writeDebugLog('SAVE_CONV_START', { baseDir, conversationId: conversation.id, moduleInitialized: sqliteStoreModule !== null });
167141
try {
168142
const store = getSqliteStoreSync(baseDir);
169-
writeDebugLog('SAVE_CONV_SYNC', { baseDir, conversationId: conversation.id });
170143
// Fire and forget - don't block on async save in sync context
171144
store.saveConversation(conversation).catch(err => {
172-
writeDebugLog('SAVE_CONV_ERROR', { baseDir, conversationId: conversation.id, error: err.message, stack: err.stack });
173145
console.error('[CLI Executor] Failed to save conversation:', err.message);
174146
});
175147
} catch (err) {
176-
writeDebugLog('SAVE_CONV_FALLBACK_ASYNC', { baseDir, conversationId: conversation.id, error: (err as Error).message });
177148
// If sync not available, queue for async save
178149
saveConversationAsync(baseDir, conversation).catch(err => {
179-
writeDebugLog('SAVE_CONV_ASYNC_ERROR', { baseDir, conversationId: conversation.id, error: err.message, stack: err.stack });
180150
console.error('[CLI Executor] Failed to save conversation:', err.message);
181151
});
182152
}

ccw/src/tools/cli-history-store.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@ import { getDiscoverer, getNativeSessions } from './native-session-discovery.js'
1111
import { StoragePaths, ensureStorageDir, getProjectId, getCCWHome } from '../config/storage-paths.js';
1212
import { createOutputParser, flattenOutputUnits, type CliOutputUnit } from './cli-output-converter.js';
1313

14-
// Debug logging for history save investigation (Iteration 4)
15-
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
16-
const DEBUG_LOG_PATH = join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
17-
18-
// Ensure debug log directory exists
19-
try {
20-
const debugDir = dirname(DEBUG_LOG_PATH);
21-
if (!existsSync(debugDir)) {
22-
mkdirSync(debugDir, { recursive: true });
23-
}
24-
} catch (err) {
25-
// Ignore directory creation errors
26-
}
27-
28-
function writeDebugLog(event: string, data: Record<string, any>): void {
29-
try {
30-
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
31-
appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
32-
} catch (err) {
33-
// Silently ignore logging errors
34-
}
35-
}
36-
3714
function reconstructFinalOutputFromStdout(rawStdout: string, canTrustStdout: boolean): string | undefined {
3815
if (!canTrustStdout || !rawStdout.trim()) {
3916
return undefined;
@@ -154,29 +131,22 @@ export class CliHistoryStore {
154131
private projectPath: string;
155132

156133
constructor(baseDir: string) {
157-
writeDebugLog('STORE_CONSTRUCT_START', { baseDir });
158134
this.projectPath = baseDir;
159135

160136
// Use centralized storage path
161137
const paths = StoragePaths.project(baseDir);
162138
const historyDir = paths.cliHistory;
163-
writeDebugLog('STORAGE_PATHS', { baseDir, historyDir, historyDb: paths.historyDb });
164139
ensureStorageDir(historyDir);
165140

166141
this.dbPath = paths.historyDb;
167-
writeDebugLog('DB_INSTANCE_CREATE', { dbPath: this.dbPath });
168142
this.db = new Database(this.dbPath);
169-
writeDebugLog('DB_INSTANCE_CREATED', { dbPath: this.dbPath });
170143
this.db.pragma('journal_mode = WAL');
171144
this.db.pragma('synchronous = NORMAL');
172145
this.db.pragma('busy_timeout = 10000'); // Wait up to 10 seconds for locks (increased for write-heavy scenarios)
173146
this.db.pragma('wal_autocheckpoint = 1000'); // Optimize WAL checkpointing
174147

175-
writeDebugLog('INIT_SCHEMA_START', { dbPath: this.dbPath });
176148
this.initSchema();
177-
writeDebugLog('INIT_SCHEMA_COMPLETE', { dbPath: this.dbPath });
178149
this.migrateFromJson(historyDir);
179-
writeDebugLog('STORE_CONSTRUCT_COMPLETE', { baseDir, dbPath: this.dbPath });
180150
}
181151

182152
/**

0 commit comments

Comments
 (0)