mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
feat: 增加 CLI 通知的超时设置,优化执行工具的会话跟踪逻辑
This commit is contained in:
@@ -43,6 +43,7 @@ function notifyDashboard(data: Record<string, unknown>): void {
|
|||||||
port: Number(DASHBOARD_PORT),
|
port: Number(DASHBOARD_PORT),
|
||||||
path: '/api/hook',
|
path: '/api/hook',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
timeout: 2000, // 2 second timeout to prevent hanging
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Content-Length': Buffer.byteLength(payload)
|
'Content-Length': Buffer.byteLength(payload)
|
||||||
@@ -53,6 +54,10 @@ function notifyDashboard(data: Record<string, unknown>): void {
|
|||||||
req.on('error', (err) => {
|
req.on('error', (err) => {
|
||||||
if (process.env.DEBUG) console.error('[Dashboard] CLI notification failed:', err.message);
|
if (process.env.DEBUG) console.error('[Dashboard] CLI notification failed:', err.message);
|
||||||
});
|
});
|
||||||
|
req.on('timeout', () => {
|
||||||
|
req.destroy();
|
||||||
|
if (process.env.DEBUG) console.error('[Dashboard] CLI notification timed out');
|
||||||
|
});
|
||||||
req.write(payload);
|
req.write(payload);
|
||||||
req.end();
|
req.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -796,7 +796,7 @@ async function executeCliTool(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle completion
|
// Handle completion
|
||||||
child.on('close', (code) => {
|
child.on('close', async (code) => {
|
||||||
const endTime = Date.now();
|
const endTime = Date.now();
|
||||||
const duration = endTime - startTime;
|
const duration = endTime - startTime;
|
||||||
|
|
||||||
@@ -942,29 +942,28 @@ async function executeCliTool(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track native session after execution (async, non-blocking)
|
// Track native session after execution (awaited to prevent process hang)
|
||||||
// Pass prompt for precise matching in parallel execution scenarios
|
// Pass prompt for precise matching in parallel execution scenarios
|
||||||
trackNewSession(tool, new Date(startTime), workingDir, prompt)
|
try {
|
||||||
.then((nativeSession) => {
|
const nativeSession = await trackNewSession(tool, new Date(startTime), workingDir, prompt);
|
||||||
if (nativeSession) {
|
if (nativeSession) {
|
||||||
// Save native session mapping
|
// Save native session mapping
|
||||||
try {
|
try {
|
||||||
store.saveNativeSessionMapping({
|
store.saveNativeSessionMapping({
|
||||||
ccw_id: conversationId,
|
ccw_id: conversationId,
|
||||||
tool,
|
tool,
|
||||||
native_session_id: nativeSession.sessionId,
|
native_session_id: nativeSession.sessionId,
|
||||||
native_session_path: nativeSession.filePath,
|
native_session_path: nativeSession.filePath,
|
||||||
project_hash: nativeSession.projectHash,
|
project_hash: nativeSession.projectHash,
|
||||||
created_at: new Date().toISOString()
|
created_at: new Date().toISOString()
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[CLI Executor] Failed to save native session mapping:', (err as Error).message);
|
console.error('[CLI Executor] Failed to save native session mapping:', (err as Error).message);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error('[CLI Executor] Failed to track native session:', (err as Error).message);
|
console.error('[CLI Executor] Failed to track native session:', (err as Error).message);
|
||||||
});
|
}
|
||||||
|
|
||||||
// Create legacy execution record for backward compatibility
|
// Create legacy execution record for backward compatibility
|
||||||
const execution: ExecutionRecord = {
|
const execution: ExecutionRecord = {
|
||||||
|
|||||||
Reference in New Issue
Block a user