From a8a21045dd19c34954fe30fa81efa3c9ff0ca752 Mon Sep 17 00:00:00 2001 From: Eyejoker Date: Sun, 29 Mar 2026 19:12:20 +0900 Subject: [PATCH] fix: use claude-agent-sdk query() API in container runner --- container/agent-runner/package.json | 2 +- container/agent-runner/src/index.ts | 38 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/container/agent-runner/package.json b/container/agent-runner/package.json index 1e5a841..ac7ca31 100644 --- a/container/agent-runner/package.json +++ b/container/agent-runner/package.json @@ -9,7 +9,7 @@ "dev": "tsc --watch" }, "dependencies": { - "@anthropic-ai/claude-code": "^1.0.0" + "@anthropic-ai/claude-agent-sdk": "^0.1.0" }, "devDependencies": { "@types/node": "^22.0.0", diff --git a/container/agent-runner/src/index.ts b/container/agent-runner/src/index.ts index c8d6894..9f435c2 100644 --- a/container/agent-runner/src/index.ts +++ b/container/agent-runner/src/index.ts @@ -8,7 +8,7 @@ * The project directory is mounted read-only — the reviewer * can read/test code but cannot modify it. */ -import { claude } from '@anthropic-ai/claude-code'; +import { query } from '@anthropic-ai/claude-agent-sdk'; import fs from 'fs'; import path from 'path'; @@ -79,10 +79,12 @@ async function main(): Promise { const systemPrompt = systemPromptParts.join('\n\n'); try { - const result = await claude({ + let lastAssistantText = ''; + + for await (const message of query({ prompt: input.prompt, - systemPrompt, options: { + systemPrompt, allowedTools: [ 'Read', 'Bash', @@ -95,25 +97,25 @@ async function main(): Promise { ], maxTurns: 30, cwd: '/workspace/project', + permissionMode: 'bypassPermissions', + allowDangerouslySkipPermissions: true, }, - }); - - // Extract text from result - const text = - typeof result === 'string' - ? result - : Array.isArray(result) - ? result - .filter( - (b: { type: string; text?: string }) => b.type === 'text', - ) - .map((b: { text?: string }) => b.text || '') - .join('\n') - : String(result); + })) { + if (message.type === 'assistant') { + const content = (message as { message?: { content?: Array<{ type: string; text?: string }> } }).message?.content; + if (content) { + for (const block of content) { + if (block.type === 'text' && block.text) { + lastAssistantText = block.text; + } + } + } + } + } emitOutput({ status: 'success', - result: text, + result: lastAssistantText || null, phase: 'final', }); } catch (err) {