Files
maestro/src/model/status.ts
T
wangjia f18db021c3 feat: Phase2 完整管线——score 调度 + 自动复审 + 模型分级 + 归档与详情
调度:
- model/scoring.ts: score = 自身分(P0=3/P1=2/P2=1) + 已完成依赖分(链条惯性)
  + 等待解锁的 blocked 任务分(解锁加权),编排器与 nextExecutable 同一打分
- createTask 校验 deps 存在且同项目(依赖图天然无环)
- daemon 重启中断自愈: executing 任务标 failed run 后重新入队(reconcileInterrupted)

执行管线:
- executor/cc.ts: 公共 headless CC 执行器(转录/超时/模型回退重试)
- executor/reviewer.ts: 执行后自动复审(只读 CC 审 diff),固定模板 summary
  (做了什么/怎么做/测试/CodeReview/安全Review/结论) + VERDICT 解析
- executor/models.ts: 按复杂度选模型(easy→sonnet/medium→opus/hard→fable5),
  env 可覆盖、project.model 最优先、不可用自动回退链
- runner: 测试/构建命令白名单(npm/go/shellcheck/make/pytest),prompt 要求实跑测试
- TaskResult 加 summary/verdict; RunKind 加 reviewer
- 容器收口: 已拆解 Hard 子任务全 done → 容器自动 done(afterDone 逐级向上)

看板:
- 五徽章组(待审批/待执行/执行中/被阻塞/总量,hover 展开,均不含已完成)
- 归档区: 深度1整树完成沉底,时间倒序分页(10/20/50/100 chip 选择)
- 归档详情对话框: 全属性/执行历史与时长/审批记录/状态流转时间线(含相关人或事)
- Agent 面板显示调度模式 + 各复杂度实际模型
- 结果闸展示复审 summary + 建议通过/拒绝徽章
- 筛选修复(组选与单选分离、已拆解移出进行中)、同步按钮收进配置面板、
  保存配置自动收起、预览全宽、被依赖阻塞→被阻塞
- API: GET /api/tasks/:id/events(任务级事件时间线)、/api/agents 带 scheduling/models

测试: 49/49(新增 scoring/复审/模型/容器收口/deps 校验/中断恢复)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 02:46:37 +08:00

96 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Complexity } from './complexity.js';
/** 任务执行状态机(设计见 DESIGN.md §5 */
export type TaskStatus =
| 'init' // 新建,未分析 / 未定方案
| 'analyzing' // Hardplan 分析 + 拆解中
| 'plan_review' // Hard)拆解完成,待 accept
| 'decomposed' // (Hard)已拆解,作为容器,进度由子任务汇总
| 'speccing' // Medium)写方案中
| 'spec_review' // Medium)方案完成,待 accept
| 'ready' // 可执行叶子
| 'blocked' // 依赖未满足
| 'queued' // 编排器已领取,等 worker 槽位
| 'executing' // agent 在 worktree 跑 headless Claude Code
| 'exec_review' // 执行完成,改动在分支,待审 / 合
| 'failed' // 执行失败
| 'needs_attention' // 失败超阈值 / 冲突 / 歧义,需人工
| 'done' // 已合并 / 已接受
| 'paused'
| 'cancelled';
export const STATUS_LABEL: Record<TaskStatus, string> = {
init: '新建',
analyzing: '分析拆解中',
plan_review: '待确认拆解',
decomposed: '已拆解',
speccing: '写方案中',
spec_review: '待确认方案',
ready: '可执行',
blocked: '被阻塞',
queued: '排队中',
executing: '执行中',
exec_review: '待审/合',
failed: '失败',
needs_attention: '需人工',
done: '完成',
paused: '暂停',
cancelled: '取消',
};
/** 审批闸类型 */
export type GateKind = 'plan' | 'spec' | 'exec';
/** 哪些状态在等待用户审批,以及对应的闸类型 */
export const GATE_STATUS: Partial<Record<TaskStatus, GateKind>> = {
plan_review: 'plan',
spec_review: 'spec',
exec_review: 'exec',
};
export function gateOf(s: TaskStatus): GateKind | null {
return GATE_STATUS[s] ?? null;
}
export const TERMINAL_STATUS: ReadonlySet<TaskStatus> = new Set<TaskStatus>(['done', 'cancelled']);
/** 合法状态流转表:from → 允许的 to[] */
export const TRANSITIONS: Record<TaskStatus, TaskStatus[]> = {
init: ['analyzing', 'speccing', 'ready', 'cancelled'], // 按复杂度分流
analyzing: ['plan_review', 'cancelled', 'paused'],
plan_review: ['decomposed', 'analyzing', 'cancelled'], // accept / reject(+意见)
decomposed: ['done', 'analyzing', 'cancelled', 'paused'], // 子全 done / 重拆
speccing: ['spec_review', 'cancelled', 'paused'],
spec_review: ['ready', 'speccing', 'cancelled'], // accept / reject(+意见)
ready: ['blocked', 'queued', 'speccing', 'analyzing', 'cancelled', 'paused'],
blocked: ['ready', 'cancelled', 'paused'],
queued: ['executing', 'ready', 'cancelled', 'paused'],
executing: ['exec_review', 'failed', 'cancelled'],
exec_review: ['done', 'ready', 'failed', 'cancelled'], // accept(合并) / reject(返工)
failed: ['queued', 'needs_attention', 'cancelled'], // 重试 / 升级
needs_attention: ['ready', 'queued', 'analyzing', 'speccing', 'cancelled', 'paused'],
done: [],
paused: ['ready', 'analyzing', 'speccing', 'queued', 'cancelled'],
cancelled: [],
};
export function canTransition(from: TaskStatus, to: TaskStatus): boolean {
return TRANSITIONS[from]?.includes(to) ?? false;
}
/** 新建任务按复杂度决定从 init 进入的下一个状态 */
export function initialNextStatus(c: Complexity): TaskStatus {
if (c === 'hard') return 'analyzing'; // 强制分析 + 拆解
if (c === 'medium') return 'speccing'; // 写方案
return 'ready'; // Easy:写完 operations 即可执行
}
/** 可被执行器领取的状态(叶子 + 依赖满足由调用方另判) */
export function isExecutable(s: TaskStatus): boolean {
return s === 'ready';
}
export function isGate(s: TaskStatus): boolean {
return s in GATE_STATUS;
}