From 355c83a8c1b78dcf1aecbec59af1829cf91ce90a Mon Sep 17 00:00:00 2001 From: Yashvardhan Jagnani Date: Tue, 5 Aug 2025 13:42:38 +0530 Subject: [PATCH] feat: non interactive spawn compatible --- src/utils/codeCommand.ts | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/utils/codeCommand.ts b/src/utils/codeCommand.ts index b1b2afd6..6035e7fb 100644 --- a/src/utils/codeCommand.ts +++ b/src/utils/codeCommand.ts @@ -1,21 +1,29 @@ -import { spawn } from "child_process"; -import { - incrementReferenceCount, - decrementReferenceCount, -} from "./processCheck"; -import { closeService } from "./close"; +import { spawn, type StdioOptions } from "child_process"; import { readConfigFile } from "."; +import { closeService } from "./close"; +import { + decrementReferenceCount, + incrementReferenceCount, +} from "./processCheck"; export async function executeCodeCommand(args: string[] = []) { // Set environment variables const config = await readConfigFile(); - const env = { + const env: Record = { ...process.env, ANTHROPIC_AUTH_TOKEN: "test", ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.PORT || 3456}`, API_TIMEOUT_MS: String(config.API_TIMEOUT_MS ?? 600000), // Default to 10 minutes if not set }; + // Non-interactive mode for automation environments + if (config.NON_INTERACTIVE_MODE) { + env.CI = "true"; + env.FORCE_COLOR = "0"; + env.NODE_NO_READLINE = "1"; + env.TERM = "dumb"; + } + // Set ANTHROPIC_SMALL_FAST_MODEL if it exists in config if (config?.ANTHROPIC_SMALL_FAST_MODEL) { env.ANTHROPIC_SMALL_FAST_MODEL = config.ANTHROPIC_SMALL_FAST_MODEL; @@ -31,12 +39,23 @@ export async function executeCodeCommand(args: string[] = []) { // Execute claude command const claudePath = process.env.CLAUDE_PATH || "claude"; + + // 🔥 CONFIG-DRIVEN: stdio configuration based on environment + const stdioConfig: StdioOptions = config.NON_INTERACTIVE_MODE + ? ["pipe", "inherit", "inherit"] // Pipe stdin for non-interactive + : "inherit"; // Default inherited behavior + const claudeProcess = spawn(claudePath, args, { env, - stdio: "inherit", + stdio: stdioConfig, shell: true, }); + // Close stdin for non-interactive mode + if (config.NON_INTERACTIVE_MODE) { + claudeProcess.stdin?.end(); + } + claudeProcess.on("error", (error) => { console.error("Failed to start claude command:", error.message); console.log(