mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-03-12 17:21:19 +08:00
refactor: 移除调试日志相关代码,简化历史保存逻辑
This commit is contained in:
@@ -306,15 +306,17 @@ export async function installCommand(options: InstallOptions): Promise<void> {
|
|||||||
info(` Files in manifest: ${existingManifest.files?.length || 0}`);
|
info(` Files in manifest: ${existingManifest.files?.length || 0}`);
|
||||||
info(` Installed: ${new Date(existingManifest.installation_date).toLocaleDateString()}`);
|
info(` Installed: ${new Date(existingManifest.installation_date).toLocaleDateString()}`);
|
||||||
|
|
||||||
const { backup } = await inquirer.prompt([{
|
if (!options.force) {
|
||||||
type: 'confirm',
|
const { backup } = await inquirer.prompt([{
|
||||||
name: 'backup',
|
type: 'confirm',
|
||||||
message: 'Create backup before reinstalling?',
|
name: 'backup',
|
||||||
default: true
|
message: 'Create backup before reinstalling?',
|
||||||
}]);
|
default: true
|
||||||
|
}]);
|
||||||
|
|
||||||
if (backup) {
|
if (backup) {
|
||||||
await createBackup(existingManifest);
|
await createBackup(existingManifest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean based on manifest records
|
// Clean based on manifest records
|
||||||
@@ -495,7 +497,7 @@ export async function installCommand(options: InstallOptions): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Install Git Bash fix on Windows
|
// Install Git Bash fix on Windows
|
||||||
if (platform() === 'win32') {
|
if (platform() === 'win32' && !options.force) {
|
||||||
console.log('');
|
console.log('');
|
||||||
const { installFix } = await inquirer.prompt([{
|
const { installFix } = await inquirer.prompt([{
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
|
|||||||
@@ -35,29 +35,6 @@ import {
|
|||||||
saveConversation
|
saveConversation
|
||||||
} from './cli-executor-state.js';
|
} from './cli-executor-state.js';
|
||||||
|
|
||||||
// Debug logging for history save investigation (Iteration 4)
|
|
||||||
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
|
|
||||||
const DEBUG_LOG_PATH = path.join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
|
|
||||||
|
|
||||||
// Ensure debug log directory exists
|
|
||||||
try {
|
|
||||||
const debugDir = path.dirname(DEBUG_LOG_PATH);
|
|
||||||
if (!fs.existsSync(debugDir)) {
|
|
||||||
fs.mkdirSync(debugDir, { recursive: true });
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// Ignore directory creation errors
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeDebugLog(event: string, data: Record<string, any>): void {
|
|
||||||
try {
|
|
||||||
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
|
|
||||||
fs.appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
|
|
||||||
} catch (err) {
|
|
||||||
// Silently ignore logging errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track all running child processes for cleanup on interruption (multi-process support)
|
// Track all running child processes for cleanup on interruption (multi-process support)
|
||||||
const runningChildProcesses = new Set<ChildProcess>();
|
const runningChildProcesses = new Set<ChildProcess>();
|
||||||
|
|
||||||
@@ -1296,11 +1273,8 @@ async function executeCliTool(
|
|||||||
};
|
};
|
||||||
// Try to save conversation to history
|
// Try to save conversation to history
|
||||||
try {
|
try {
|
||||||
writeDebugLog('BEFORE_SAVE_CONV', { conversationId: conversation.id, workingDir, tool });
|
|
||||||
saveConversation(workingDir, conversation);
|
saveConversation(workingDir, conversation);
|
||||||
writeDebugLog('AFTER_SAVE_CONV', { conversationId: conversation.id, workingDir, tool });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
writeDebugLog('SAVE_CONV_OUTER_ERROR', { conversationId: conversation.id, workingDir, tool, error: (err as Error).message, stack: (err as Error).stack });
|
|
||||||
// Non-fatal: continue even if history save fails
|
// Non-fatal: continue even if history save fails
|
||||||
console.error('[CLI Executor] Failed to save history:', (err as Error).message);
|
console.error('[CLI Executor] Failed to save history:', (err as Error).message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,29 +9,6 @@ import type { CliOutputUnit } from './cli-output-converter.js';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
// Debug logging for history save investigation (Iteration 4)
|
|
||||||
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
|
|
||||||
const DEBUG_LOG_PATH = path.join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
|
|
||||||
|
|
||||||
// Ensure debug log directory exists
|
|
||||||
try {
|
|
||||||
const debugDir = path.dirname(DEBUG_LOG_PATH);
|
|
||||||
if (!fs.existsSync(debugDir)) {
|
|
||||||
fs.mkdirSync(debugDir, { recursive: true });
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// Ignore directory creation errors
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeDebugLog(event: string, data: Record<string, any>): void {
|
|
||||||
try {
|
|
||||||
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
|
|
||||||
fs.appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
|
|
||||||
} catch (err) {
|
|
||||||
// Silently ignore logging errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lazy-loaded SQLite store module
|
// Lazy-loaded SQLite store module
|
||||||
let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null;
|
let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null;
|
||||||
|
|
||||||
@@ -39,10 +16,8 @@ let sqliteStoreModule: typeof import('./cli-history-store.js') | null = null;
|
|||||||
* Get or initialize SQLite store (async)
|
* Get or initialize SQLite store (async)
|
||||||
*/
|
*/
|
||||||
export async function getSqliteStore(baseDir: string) {
|
export async function getSqliteStore(baseDir: string) {
|
||||||
writeDebugLog('GET_STORE', { baseDir, baseDirType: typeof baseDir, moduleInitialized: sqliteStoreModule !== null });
|
|
||||||
if (!sqliteStoreModule) {
|
if (!sqliteStoreModule) {
|
||||||
sqliteStoreModule = await import('./cli-history-store.js');
|
sqliteStoreModule = await import('./cli-history-store.js');
|
||||||
writeDebugLog('MODULE_LOADED', { baseDir });
|
|
||||||
}
|
}
|
||||||
return sqliteStoreModule.getHistoryStore(baseDir);
|
return sqliteStoreModule.getHistoryStore(baseDir);
|
||||||
}
|
}
|
||||||
@@ -163,20 +138,15 @@ async function saveConversationAsync(baseDir: string, conversation: Conversation
|
|||||||
* @param baseDir - Project base directory (NOT historyDir)
|
* @param baseDir - Project base directory (NOT historyDir)
|
||||||
*/
|
*/
|
||||||
export function saveConversation(baseDir: string, conversation: ConversationRecord): void {
|
export function saveConversation(baseDir: string, conversation: ConversationRecord): void {
|
||||||
writeDebugLog('SAVE_CONV_START', { baseDir, conversationId: conversation.id, moduleInitialized: sqliteStoreModule !== null });
|
|
||||||
try {
|
try {
|
||||||
const store = getSqliteStoreSync(baseDir);
|
const store = getSqliteStoreSync(baseDir);
|
||||||
writeDebugLog('SAVE_CONV_SYNC', { baseDir, conversationId: conversation.id });
|
|
||||||
// Fire and forget - don't block on async save in sync context
|
// Fire and forget - don't block on async save in sync context
|
||||||
store.saveConversation(conversation).catch(err => {
|
store.saveConversation(conversation).catch(err => {
|
||||||
writeDebugLog('SAVE_CONV_ERROR', { baseDir, conversationId: conversation.id, error: err.message, stack: err.stack });
|
|
||||||
console.error('[CLI Executor] Failed to save conversation:', err.message);
|
console.error('[CLI Executor] Failed to save conversation:', err.message);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
writeDebugLog('SAVE_CONV_FALLBACK_ASYNC', { baseDir, conversationId: conversation.id, error: (err as Error).message });
|
|
||||||
// If sync not available, queue for async save
|
// If sync not available, queue for async save
|
||||||
saveConversationAsync(baseDir, conversation).catch(err => {
|
saveConversationAsync(baseDir, conversation).catch(err => {
|
||||||
writeDebugLog('SAVE_CONV_ASYNC_ERROR', { baseDir, conversationId: conversation.id, error: err.message, stack: err.stack });
|
|
||||||
console.error('[CLI Executor] Failed to save conversation:', err.message);
|
console.error('[CLI Executor] Failed to save conversation:', err.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,29 +11,6 @@ import { getDiscoverer, getNativeSessions } from './native-session-discovery.js'
|
|||||||
import { StoragePaths, ensureStorageDir, getProjectId, getCCWHome } from '../config/storage-paths.js';
|
import { StoragePaths, ensureStorageDir, getProjectId, getCCWHome } from '../config/storage-paths.js';
|
||||||
import { createOutputParser, flattenOutputUnits, type CliOutputUnit } from './cli-output-converter.js';
|
import { createOutputParser, flattenOutputUnits, type CliOutputUnit } from './cli-output-converter.js';
|
||||||
|
|
||||||
// Debug logging for history save investigation (Iteration 4)
|
|
||||||
const DEBUG_SESSION_ID = 'DBG-parallel-ccw-cli-test-2026-03-07';
|
|
||||||
const DEBUG_LOG_PATH = join(process.cwd(), '.workflow', '.debug', DEBUG_SESSION_ID, 'debug-save.log');
|
|
||||||
|
|
||||||
// Ensure debug log directory exists
|
|
||||||
try {
|
|
||||||
const debugDir = dirname(DEBUG_LOG_PATH);
|
|
||||||
if (!existsSync(debugDir)) {
|
|
||||||
mkdirSync(debugDir, { recursive: true });
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// Ignore directory creation errors
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeDebugLog(event: string, data: Record<string, any>): void {
|
|
||||||
try {
|
|
||||||
const logEntry = JSON.stringify({ event, ...data, timestamp: new Date().toISOString() }) + '\n';
|
|
||||||
appendFileSync(DEBUG_LOG_PATH, logEntry, 'utf8');
|
|
||||||
} catch (err) {
|
|
||||||
// Silently ignore logging errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function reconstructFinalOutputFromStdout(rawStdout: string, canTrustStdout: boolean): string | undefined {
|
function reconstructFinalOutputFromStdout(rawStdout: string, canTrustStdout: boolean): string | undefined {
|
||||||
if (!canTrustStdout || !rawStdout.trim()) {
|
if (!canTrustStdout || !rawStdout.trim()) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -154,29 +131,22 @@ export class CliHistoryStore {
|
|||||||
private projectPath: string;
|
private projectPath: string;
|
||||||
|
|
||||||
constructor(baseDir: string) {
|
constructor(baseDir: string) {
|
||||||
writeDebugLog('STORE_CONSTRUCT_START', { baseDir });
|
|
||||||
this.projectPath = baseDir;
|
this.projectPath = baseDir;
|
||||||
|
|
||||||
// Use centralized storage path
|
// Use centralized storage path
|
||||||
const paths = StoragePaths.project(baseDir);
|
const paths = StoragePaths.project(baseDir);
|
||||||
const historyDir = paths.cliHistory;
|
const historyDir = paths.cliHistory;
|
||||||
writeDebugLog('STORAGE_PATHS', { baseDir, historyDir, historyDb: paths.historyDb });
|
|
||||||
ensureStorageDir(historyDir);
|
ensureStorageDir(historyDir);
|
||||||
|
|
||||||
this.dbPath = paths.historyDb;
|
this.dbPath = paths.historyDb;
|
||||||
writeDebugLog('DB_INSTANCE_CREATE', { dbPath: this.dbPath });
|
|
||||||
this.db = new Database(this.dbPath);
|
this.db = new Database(this.dbPath);
|
||||||
writeDebugLog('DB_INSTANCE_CREATED', { dbPath: this.dbPath });
|
|
||||||
this.db.pragma('journal_mode = WAL');
|
this.db.pragma('journal_mode = WAL');
|
||||||
this.db.pragma('synchronous = NORMAL');
|
this.db.pragma('synchronous = NORMAL');
|
||||||
this.db.pragma('busy_timeout = 10000'); // Wait up to 10 seconds for locks (increased for write-heavy scenarios)
|
this.db.pragma('busy_timeout = 10000'); // Wait up to 10 seconds for locks (increased for write-heavy scenarios)
|
||||||
this.db.pragma('wal_autocheckpoint = 1000'); // Optimize WAL checkpointing
|
this.db.pragma('wal_autocheckpoint = 1000'); // Optimize WAL checkpointing
|
||||||
|
|
||||||
writeDebugLog('INIT_SCHEMA_START', { dbPath: this.dbPath });
|
|
||||||
this.initSchema();
|
this.initSchema();
|
||||||
writeDebugLog('INIT_SCHEMA_COMPLETE', { dbPath: this.dbPath });
|
|
||||||
this.migrateFromJson(historyDir);
|
this.migrateFromJson(historyDir);
|
||||||
writeDebugLog('STORE_CONSTRUCT_COMPLETE', { baseDir, dbPath: this.dbPath });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user