From b4e5f20cd78da2601243d31b93d0f39e1434346d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 25 Nov 2025 01:36:52 +0100 Subject: [PATCH] Add claudeOutputFormat support and provider banners --- src/index.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/index.ts b/src/index.ts index 59af4ec88..9bab689a9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -483,6 +483,8 @@ const CONFIG_PATH = path.join(os.homedir(), ".warelay", "warelay.json"); type ReplyMode = "text" | "command"; +type ClaudeOutputFormat = "text" | "json" | "stream-json"; + type WarelayConfig = { inbound?: { allowFrom?: string[]; // E.164 numbers allowed to trigger auto-reply (without whatsapp:) @@ -494,6 +496,7 @@ type WarelayConfig = { timeoutSeconds?: number; // optional command timeout; defaults to 600s bodyPrefix?: string; // optional string prepended to Body before templating session?: SessionConfig; + claudeOutputFormat?: ClaudeOutputFormat; // when command starts with `claude`, force an output format }; }; }; @@ -713,6 +716,35 @@ async function getReplyFromConfig( argv = [argv[0], templatePrefix, ...argv.slice(1)]; } + // Ensure Claude commands can emit plain text by forcing --output-format when configured. + if ( + reply.claudeOutputFormat && + argv.length > 0 && + path.basename(argv[0]) === "claude" + ) { + const hasOutputFormat = argv.some( + (part) => + part === "--output-format" || part.startsWith("--output-format="), + ); + // Keep the final argument as the prompt/body; insert options just before it. + const insertBeforeBody = Math.max(argv.length - 1, 0); + if (!hasOutputFormat) { + argv = [ + ...argv.slice(0, insertBeforeBody), + "--output-format", + reply.claudeOutputFormat, + ...argv.slice(insertBeforeBody), + ]; + } + const hasPrintFlag = argv.some( + (part) => part === "-p" || part === "--print", + ); + if (!hasPrintFlag) { + const insertIdx = Math.max(argv.length - 1, 0); + argv = [...argv.slice(0, insertIdx), "-p", ...argv.slice(insertIdx)]; + } + } + // Inject session args if configured (use resume for existing, session-id for new) if (reply.session) { const sessionArgList = (