From 62f5a45de0db023a96e1bdb380c405550b075526 Mon Sep 17 00:00:00 2001 From: KrasimirKralev <263465593+KrasimirKralev@users.noreply.github.com> Date: Sun, 5 Jul 2026 12:40:33 +0300 Subject: [PATCH] fix(ci): lazy-load the Anthropic SDK so the OAuth path needs no SDK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OAuth transport (shipped in #248) installs only the Claude Code CLI, not @anthropic-ai/sdk, but both bot scripts had a static top-level 'import Anthropic from @anthropic-ai/sdk' evaluated at module load regardless of transport — so the live bots on main crash with ERR_MODULE_NOT_FOUND before running. Moved the import into a dynamic import() inside reviewViaSdk/classifyViaSdk, reached only on the API-key fallback. Verified by running the OAuth path with node_modules removed. Same fix rides to beta in #250. --- scripts/issue-triage.mjs | 7 +++++-- scripts/pr-review.mjs | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/issue-triage.mjs b/scripts/issue-triage.mjs index ae06bbfa..8868f551 100644 --- a/scripts/issue-triage.mjs +++ b/scripts/issue-triage.mjs @@ -4,7 +4,9 @@ // Needs: ANTHROPIC_API_KEY (repo secret) and GH_TOKEN (the workflow's GITHUB_TOKEN). import fs from "node:fs"; import { execFileSync } from "node:child_process"; -import Anthropic from "@anthropic-ai/sdk"; +// NB: @anthropic-ai/sdk is imported lazily inside classifyViaSdk() — the OAuth +// transport installs only the Claude Code CLI, not the SDK, so a static +// top-level import would ERR_MODULE_NOT_FOUND before any code runs. // Haiku 4.5 — fast and cheap, ideal for a high-volume issue classifier. // Switch to "claude-opus-4-8" for maximum classification accuracy. @@ -75,7 +77,8 @@ function classifyViaClaudeCli(userContent) { } async function classifyViaSdk(userContent) { - const client = new Anthropic(); // reads ANTHROPIC_API_KEY from env + const { default: Anthropic } = await import("@anthropic-ai/sdk"); // reads ANTHROPIC_API_KEY from env + const client = new Anthropic(); const resp = await client.messages.create({ model: MODEL, max_tokens: 1024, diff --git a/scripts/pr-review.mjs b/scripts/pr-review.mjs index 3613a3e8..3a762114 100644 --- a/scripts/pr-review.mjs +++ b/scripts/pr-review.mjs @@ -8,7 +8,9 @@ // logs and exits 0 — a broken bot must never block a PR. import fs from "node:fs"; import { execFileSync } from "node:child_process"; -import Anthropic from "@anthropic-ai/sdk"; +// NB: @anthropic-ai/sdk is imported lazily inside reviewViaSdk() — the OAuth +// transport installs only the Claude Code CLI, not the SDK, so a static +// top-level import would ERR_MODULE_NOT_FOUND before any code runs. // Sonnet: PR review needs real reasoning; still cents per run at PR-diff sizes. const MODEL = "claude-sonnet-4-6"; @@ -243,6 +245,7 @@ function reviewViaClaudeCli(userPrompt) { } async function reviewViaSdk(userPrompt) { + const { default: Anthropic } = await import("@anthropic-ai/sdk"); const client = new Anthropic(); const resp = await client.messages.create({ model: MODEL,