From c4b0155cc289e272d814dc6f2d4f00d4914b4a49 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 3 Dec 2025 01:02:10 +0000 Subject: [PATCH] Format: align thinking helpers --- src/auto-reply/command-reply.ts | 45 +++++++++++++++++++++++++++++++-- src/auto-reply/reply.ts | 20 +++++---------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/auto-reply/command-reply.ts b/src/auto-reply/command-reply.ts index 4b82608de..c89d5f4d6 100644 --- a/src/auto-reply/command-reply.ts +++ b/src/auto-reply/command-reply.ts @@ -20,6 +20,8 @@ type CommandReplyConfig = NonNullable["reply"] & { type EnqueueRunner = typeof enqueueCommand; +type ThinkLevel = "off" | "minimal" | "low" | "medium" | "high"; + type CommandReplyParams = { reply: CommandReplyConfig; templatingCtx: TemplateContext; @@ -31,6 +33,7 @@ type CommandReplyParams = { timeoutSeconds: number; commandRunner: typeof runCommandWithTimeout; enqueue?: EnqueueRunner; + thinkLevel?: ThinkLevel; }; export type CommandReplyMeta = { @@ -98,6 +101,25 @@ export function summarizeClaudeMetadata(payload: unknown): string | undefined { return parts.length ? parts.join(", ") : undefined; } +function appendThinkingCue(body: string, level?: ThinkLevel): string { + if (!level || level === "off") return body; + const cue = (() => { + switch (level) { + case "high": + return "ultrathink"; + case "medium": + return "think harder"; + case "low": + return "think hard"; + case "minimal": + return "think"; + default: + return ""; + } + })(); + return [body.trim(), cue].filter(Boolean).join(" "); +} + export async function runCommandReply( params: CommandReplyParams, ): Promise { @@ -118,6 +140,7 @@ export async function runCommandReply( timeoutSeconds, commandRunner, enqueue = enqueueCommand, + thinkLevel, } = params; if (!reply.command?.length) { @@ -178,6 +201,23 @@ export async function runCommandReply( } } + if (thinkLevel && thinkLevel !== "off") { + if (agentKind === "pi") { + const hasThinkingFlag = argv.some( + (p, i) => + p === "--thinking" || + (i > 0 && argv[i - 1] === "--thinking") || + p.startsWith("--thinking="), + ); + if (!hasThinkingFlag) { + argv.splice(bodyIndex, 0, "--thinking", thinkLevel); + bodyIndex += 2; + } + } else if (argv[bodyIndex]) { + argv[bodyIndex] = appendThinkingCue(argv[bodyIndex] ?? "", thinkLevel); + } + } + const shouldApplyAgent = agent.isInvocation(argv); const finalArgv = shouldApplyAgent ? agent.buildArgs({ @@ -213,11 +253,12 @@ export async function runCommandReply( const run = async () => { // Prefer long-lived tau RPC for pi agent to avoid cold starts. if (agentKind === "pi") { - const body = finalArgv[bodyIndex] ?? ""; + const promptIndex = finalArgv.length - 1; + const body = finalArgv[promptIndex] ?? ""; // Build rpc args without the prompt body; force --mode rpc. const rpcArgv = (() => { const copy = [...finalArgv]; - copy.splice(bodyIndex, 1); + copy.splice(promptIndex, 1); const modeIdx = copy.indexOf("--mode"); if (modeIdx >= 0 && copy[modeIdx + 1]) { copy.splice(modeIdx, 2, "--mode", "rpc"); diff --git a/src/auto-reply/reply.ts b/src/auto-reply/reply.ts index f2fe5b707..b1f6235bf 100644 --- a/src/auto-reply/reply.ts +++ b/src/auto-reply/reply.ts @@ -40,10 +40,13 @@ function normalizeThinkLevel(raw?: string | null): ThinkLevel | undefined { const key = raw.toLowerCase(); if (["off"].includes(key)) return "off"; if (["min", "minimal"].includes(key)) return "minimal"; - if (["low"].includes(key)) return "low"; - if (["med", "medium", "thinkhard", "think-harder", "thinkharder"].includes(key)) + if (["low", "thinkhard", "think-hard", "think_hard"].includes(key)) + return "low"; + if (["med", "medium", "thinkharder", "think-harder", "harder"].includes(key)) return "medium"; - if (["high", "ultra", "ultrathink", "think-hard", "thinkhardest"].includes(key)) + if ( + ["high", "ultra", "ultrathink", "think-hard", "thinkhardest"].includes(key) + ) return "high"; if (["think"].includes(key)) return "minimal"; return undefined; @@ -61,17 +64,6 @@ function extractThinkDirective(body?: string): { return { cleaned, thinkLevel }; } -function appendThinkingCue(body: string, level?: ThinkLevel): string { - if (!level || level === "off") return body; - const cue = - level === "high" - ? "ultrathink" - : level === "medium" - ? "think harder" - : "think"; - return [body.trim(), cue].filter(Boolean).join(" "); -} - function isAbortTrigger(text?: string): boolean { if (!text) return false; const normalized = text.trim().toLowerCase();