From 1c912398b157adbbc18d473a1795b78589cbafba Mon Sep 17 00:00:00 2001 From: nrslib <38722970+nrslib@users.noreply.github.com> Date: Mon, 26 Jan 2026 21:31:13 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A4=E3=83=86=E3=83=AC=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=8C=E6=AD=A2=E3=81=BE=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=86=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/workflowExecution.ts | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/commands/workflowExecution.ts b/src/commands/workflowExecution.ts index 9b8c52d..cfae3fa 100644 --- a/src/commands/workflowExecution.ts +++ b/src/commands/workflowExecution.ts @@ -4,10 +4,12 @@ import { WorkflowEngine } from '../workflow/engine.js'; import type { WorkflowConfig } from '../models/types.js'; +import type { IterationLimitRequest } from '../workflow/types.js'; import { loadAgentSessions, updateAgentSession, clearAgentSessions } from '../config/paths.js'; import { header, info, + warn, error, success, status, @@ -22,6 +24,7 @@ import { } from '../utils/session.js'; import { createLogger } from '../utils/debug.js'; import { notifySuccess, notifyError } from '../utils/notification.js'; +import { selectOption, promptInput } from '../prompt/index.js'; const log = createLogger('workflow'); @@ -86,10 +89,54 @@ export async function executeWorkflow( updateAgentSession(cwd, agentName, agentSessionId); }; + const iterationLimitHandler = async ( + request: IterationLimitRequest + ): Promise => { + if (displayRef.current) { + displayRef.current.flush(); + displayRef.current = null; + } + + console.log(); + warn( + `最大イテレーションに到達しました (${request.currentIteration}/${request.maxIterations})` + ); + info(`現在のステップ: ${request.currentStep}`); + + const action = await selectOption('続行しますか?', [ + { + label: '続行する(追加イテレーション数を入力)', + value: 'continue', + description: '入力した回数だけ上限を増やします', + }, + { label: '終了する', value: 'stop' }, + ]); + + if (action !== 'continue') { + return null; + } + + while (true) { + const input = await promptInput('追加するイテレーション数を入力してください(1以上)'); + if (!input) { + return null; + } + + const additionalIterations = Number.parseInt(input, 10); + if (Number.isInteger(additionalIterations) && additionalIterations > 0) { + workflowConfig.maxIterations += additionalIterations; + return additionalIterations; + } + + warn('1以上の整数を入力してください。'); + } + }; + const engine = new WorkflowEngine(workflowConfig, cwd, task, { onStream: streamHandler, initialSessions: savedSessions, onSessionUpdate: sessionUpdateHandler, + onIterationLimit: iterationLimitHandler, }); let abortReason: string | undefined;