/** * dispatch-loop — 调度循环状态机(v8.3.225+) * * 方式 Y(宿主会话内闭环):CLI 每轮处理一个步骤,宿主 AI 在同一会话内连续调用: * * CLI 首次调用 → 推进状态机 → 找到第一个「未完成」步骤 → 输出自包含 prompt(exitCode 10) * → 宿主 AI 落盘 → 宿主 AI 再次调用 CLI → CLI 校验产物 → 通过则标记 done 并推进下一步 * → …… → 全部完成 → 输出汇总报告(exitCode 0) * * 错误隔离:步骤间相互独立,某一步失败(重试超限)只标记该步 failed 并继续后续步骤, * 不影响其他步骤。状态文件支持 Ctrl-C 中断后恢复。 * * 状态文件:/.speccore/local/dispatch-loop.json(按 scope 分节,一个文件多租户) */ export type LoopStepStatus = 'done' | 'failed'; export interface LoopStepState { status?: LoopStepStatus; /** 已完成的尝试次数(1-based)。首试 attempt=1,一次重试 attempt=2 */ attempt: number; lastError?: string; updatedAt: string; } export interface LoopStateFile { version: 1; scopes: Record>; } export interface LoopStep { /** 步骤唯一 ID(建议带前缀,如 `unit:PRD-会议室管理`) */ id: string; /** 步骤展示名 */ name: string; /** 产出校验:返回 null = 通过;返回字符串 = 失败原因 */ validate: () => Promise; /** 生成该步骤的 prompt(attempt 为第几次尝试,lastError 为上次失败原因,仅重试时有值) */ buildPrompt: (ctx: { attempt: number; lastError?: string; }) => Promise; } export interface LoopSummary { done: string[]; failed: string[]; failedErrors: Record; } export interface LoopRoundResult { finished: boolean; /** finished=true 时的汇总 */ summary?: LoopSummary; /** finished=false 时的当前步骤 */ step?: LoopStep; /** 本次输出的尝试序号(1-based) */ attempt?: number; /** 当前步骤的 prompt(finished=false 时必有) */ prompt?: string; } export interface DispatchLoopOptions { projectRoot: string; /** 状态文件命名空间(如 `analyze-units:meeting-system`) */ scope: string; /** 重试次数(默认 1,即最多 2 次尝试) */ maxRetries?: number; /** 已完成步骤的产物被删除时是否重置为 pending(默认 true) */ resetStaleDone?: boolean; } /** * 推进一轮调度循环。 * * 行为: * 1. 已标记 failed 的步骤直接跳过(错误隔离,不阻塞后续) * 2. 从前往后逐个校验步骤产出:通过 → 标记 done 并继续(宿主可能一次落盘多个步骤) * 3. 遇到「产出未就绪」的步骤: * - 尝试次数已达上限(maxRetries+1)→ 标记 failed,继续后续步骤 * - 否则 → 记录本次尝试、生成 prompt 并返回(调用方输出 prompt 后以 exitCode 10 退出) * 4. 所有步骤均为 done/failed → 返回 finished=true + 汇总报告 */ export declare function runDispatchLoopRound(steps: LoopStep[], options: DispatchLoopOptions): Promise; /** * 重置指定 scope 的状态(如用户手动删除产物后重跑)。 */ export declare function resetDispatchLoopState(projectRoot: string, scope: string): Promise; //# sourceMappingURL=dispatch-loop.d.ts.map