mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
fix: Auto-detect JSON Lines output format for Codex CLI
Problem: Codex CLI uses --json flag to output JSONL events, but executor was using plain text parser. This prevented proper parsing of structured events, breaking session creation. Root cause: buildCommand() added --json flag for Codex but never communicated this to the output parser. Result: JSONL events treated as raw text → session markers lost. Solution: - Extend buildCommand() to return outputFormat - Auto-detect 'json-lines' when tool is 'codex' - Use auto-detected format in executeCliTool() - Properly parse structured events and extract session data Files modified: - ccw/src/tools/cli-executor-utils.ts: Add output format auto-detection - ccw/src/tools/cli-executor-core.ts: Use auto-detected format for parser - ccw/src/commands/cli.ts: Add debug instrumentation Verified: - Codex outputs valid JSONL (confirmed via direct test) - CLI_EXECUTION_STARTED events broadcast correctly - Issue was downstream in output parsing, not event transmission
This commit is contained in:
@@ -77,6 +77,10 @@ function notifyDashboard(data: Record<string, unknown>): void {
|
||||
* Uses specific event types that match frontend handlers
|
||||
*/
|
||||
function broadcastStreamEvent(eventType: string, payload: Record<string, unknown>): void {
|
||||
if (process.env.DEBUG_CLI_EVENTS) {
|
||||
console.error(`[CLI-BROADCAST] START ${eventType} at ${Date.now()}`);
|
||||
}
|
||||
|
||||
const data = JSON.stringify({
|
||||
type: eventType,
|
||||
...payload,
|
||||
@@ -107,6 +111,10 @@ function broadcastStreamEvent(eventType: string, payload: Record<string, unknown
|
||||
});
|
||||
req.write(data);
|
||||
req.end();
|
||||
|
||||
if (process.env.DEBUG_CLI_EVENTS) {
|
||||
console.error(`[CLI-BROADCAST] END ${eventType} at ${Date.now()}`);
|
||||
}
|
||||
}
|
||||
|
||||
interface CliExecOptions {
|
||||
@@ -1093,15 +1101,27 @@ async function execAction(positionalPrompt: string | undefined, options: CliExec
|
||||
});
|
||||
|
||||
// Broadcast CLI_EXECUTION_COMPLETED for real-time streaming viewer
|
||||
if (process.env.DEBUG_CLI_EVENTS) {
|
||||
console.error(`[CLI-TIMING] Broadcasting CLI_EXECUTION_COMPLETED at ${Date.now()}`);
|
||||
}
|
||||
broadcastStreamEvent('CLI_EXECUTION_COMPLETED', {
|
||||
executionId, // Use the same executionId as started event
|
||||
success: true,
|
||||
duration: result.execution.duration_ms
|
||||
});
|
||||
if (process.env.DEBUG_CLI_EVENTS) {
|
||||
console.error(`[CLI-TIMING] Broadcast returned, setting timeout at ${Date.now()}`);
|
||||
}
|
||||
|
||||
// Ensure clean exit after successful execution
|
||||
// Delay to allow HTTP request to complete
|
||||
setTimeout(() => process.exit(0), 150);
|
||||
// FIX: Increased from 150ms to 500ms for long-running executions
|
||||
setTimeout(() => {
|
||||
if (process.env.DEBUG_CLI_EVENTS) {
|
||||
console.error(`[CLI-TIMING] process.exit(0) at ${Date.now()}`);
|
||||
}
|
||||
process.exit(0);
|
||||
}, 500);
|
||||
} else {
|
||||
if (!spinner) {
|
||||
console.log(chalk.red(` ✗ Failed (${result.execution.status})`));
|
||||
|
||||
Reference in New Issue
Block a user