/** * claude-sdk-sessionstore #9 (Part 2) — claude-SDK-vs-PTY routing predicate. * * Sibling to `shouldUseWarmBackend` (warm-acp-routing.ts). The warm Claude-SDK * backend keys its persistent `query()` on (chat_id, agent) — exactly like the * warm-ACP / opencode-server backends — so a task only routes to it when it carries * BOTH a `session_id` and a `chat_id` (a real chat tab). * * CRUCIALLY this is ALSO gated behind the `CLAUDE_SDK_BACKEND` env flag (default * OFF). While off — the production default — claude always falls through to the * existing one-shot PTY `runExternalAgent` path, UNCHANGED. The live SDK streaming * pump + cross-turn resume need a host smoke against the real `claude` binary, so * we keep the working PTY path as the default until that lands. Flip the env var * on a host (any truthy value) to opt a deployment into the SDK backend. * * Pure (env read injected) so it's unit-testable; the dispatcher consumes it. */ /** True iff the `CLAUDE_SDK_BACKEND` env flag is set to a truthy value. */ export function claudeSdkBackendEnabled(env: NodeJS.ProcessEnv = process.env): boolean { const v = env.CLAUDE_SDK_BACKEND; if (v == null) return false; const s = v.trim().toLowerCase(); return s !== '' && s !== '0' && s !== 'false' && s !== 'off' && s !== 'no'; } export function shouldUseClaudeSdk( task: { agent: string | null; session_id: string | null; chat_id: string | null; }, env: NodeJS.ProcessEnv = process.env, ): boolean { if (!claudeSdkBackendEnabled(env)) return false; if (task.agent !== 'claude') return false; return task.session_id != null && task.chat_id != null; }