From b69e669638b19fccfe93c37215ae6cae09d66e79 Mon Sep 17 00:00:00 2001 From: tanmay11k Date: Sun, 22 Feb 2026 00:56:18 -0500 Subject: [PATCH] Initial commit: Discord-Claude Gateway with event-driven agent runtime --- src/agent-runtime.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/agent-runtime.ts b/src/agent-runtime.ts index 717decd..c70a866 100644 --- a/src/agent-runtime.ts +++ b/src/agent-runtime.ts @@ -171,6 +171,8 @@ export class AgentRuntime { // Max turns to prevent runaway loops args.push("--max-turns", "25"); + console.log(`[DEBUG] Spawning Claude CLI: ${this.config.claudeCliPath} ${args.slice(0, 4).join(" ")} ... (${args.length} args total)`); + const child = execFile( this.config.claudeCliPath, args, @@ -181,6 +183,7 @@ export class AgentRuntime { }, (error, stdout, stderr) => { if (error) { + console.error(`[DEBUG] Claude CLI error: code=${error.code}, killed=${error.killed}, stderr=${stderr?.slice(0, 500)}`); if (error.killed || error.code === "ETIMEDOUT") { reject(new Error("Query timed out")); return; @@ -189,9 +192,12 @@ export class AgentRuntime { return; } + console.log(`[DEBUG] Claude CLI stdout (${stdout.length} chars): ${stdout.slice(0, 300)}...`); + if (stderr) { + console.log(`[DEBUG] Claude CLI stderr: ${stderr.slice(0, 300)}`); + } + try { - // The JSON output may contain multiple JSON objects (one per line for stream-json) - // With --output-format json, the last line is the final result const lines = stdout.trim().split("\n"); const lastLine = lines[lines.length - 1]; const parsed = JSON.parse(lastLine) as ClaudeJsonResponse; @@ -203,7 +209,6 @@ export class AgentRuntime { resolve(parsed); } catch (parseError) { - // If JSON parsing fails, treat stdout as plain text result resolve({ type: "result", result: stdout.trim(), @@ -212,8 +217,8 @@ export class AgentRuntime { }, ); - // Handle child process errors child.on("error", (err) => { + console.error(`[DEBUG] Failed to spawn Claude CLI: ${err.message}`); reject(new Error(`Failed to spawn Claude CLI: ${err.message}`)); }); });