fix: use claude-agent-sdk query() API in container runner

This commit is contained in:
Eyejoker
2026-03-29 19:12:20 +09:00
parent 9a365854c5
commit a8a21045dd
2 changed files with 21 additions and 19 deletions

View File

@@ -9,7 +9,7 @@
"dev": "tsc --watch" "dev": "tsc --watch"
}, },
"dependencies": { "dependencies": {
"@anthropic-ai/claude-code": "^1.0.0" "@anthropic-ai/claude-agent-sdk": "^0.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.0.0", "@types/node": "^22.0.0",

View File

@@ -8,7 +8,7 @@
* The project directory is mounted read-only — the reviewer * The project directory is mounted read-only — the reviewer
* can read/test code but cannot modify it. * 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 fs from 'fs';
import path from 'path'; import path from 'path';
@@ -79,10 +79,12 @@ async function main(): Promise<void> {
const systemPrompt = systemPromptParts.join('\n\n'); const systemPrompt = systemPromptParts.join('\n\n');
try { try {
const result = await claude({ let lastAssistantText = '';
for await (const message of query({
prompt: input.prompt, prompt: input.prompt,
systemPrompt,
options: { options: {
systemPrompt,
allowedTools: [ allowedTools: [
'Read', 'Read',
'Bash', 'Bash',
@@ -95,25 +97,25 @@ async function main(): Promise<void> {
], ],
maxTurns: 30, maxTurns: 30,
cwd: '/workspace/project', cwd: '/workspace/project',
permissionMode: 'bypassPermissions',
allowDangerouslySkipPermissions: true,
}, },
}); })) {
if (message.type === 'assistant') {
// Extract text from result const content = (message as { message?: { content?: Array<{ type: string; text?: string }> } }).message?.content;
const text = if (content) {
typeof result === 'string' for (const block of content) {
? result if (block.type === 'text' && block.text) {
: Array.isArray(result) lastAssistantText = block.text;
? result }
.filter( }
(b: { type: string; text?: string }) => b.type === 'text', }
) }
.map((b: { text?: string }) => b.text || '') }
.join('\n')
: String(result);
emitOutput({ emitOutput({
status: 'success', status: 'success',
result: text, result: lastAssistantText || null,
phase: 'final', phase: 'final',
}); });
} catch (err) { } catch (err) {