feat(models/protocol/types): 模型档位优化+协议扩展
- models.ts: 回退链加 fable-5 首位;planner 按复杂度分化(sonnet/opus/fable);reviewer 全升 fable-5;加 conflict 角色,reviewer/conflict 不受 project.model 覆盖 - protocol.ts: RunKind 加 conflict;DecomposeResult.subtasks 扩展 priority/deps 字段;OutboxRecord decompose-result 同步对齐 - types.ts: Project 加 autoApprovePlan / autoApproveExec / checks 可选字段 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+23
-13
@@ -1,11 +1,11 @@
|
||||
import type { Project, Task } from '../model/types.js';
|
||||
import type { Complexity } from '../model/complexity.js';
|
||||
|
||||
/** 角色:executor(执行改动)/ reviewer(执行后复审)/ planner(拆解 Hard / 写方案 Medium) */
|
||||
export type ModelRole = 'executor' | 'reviewer' | 'planner';
|
||||
/** 角色:executor(执行改动)/ reviewer(执行后复审)/ planner(拆解 Hard / 写方案 Medium)/ conflict(冲突裁决) */
|
||||
export type ModelRole = 'executor' | 'reviewer' | 'planner' | 'conflict';
|
||||
|
||||
/** 模型不可用时的回退链(按序取第一个 ≠ 失败模型的,同一 run 内只重试一次) */
|
||||
export const MODEL_FALLBACK_CHAIN = ['claude-opus-4-8', 'claude-sonnet-4-6'] as const;
|
||||
export const MODEL_FALLBACK_CHAIN = ['claude-fable-5', 'claude-opus-4-8', 'claude-sonnet-4-6'] as const;
|
||||
|
||||
/** 复杂度 → [env 覆盖变量名, 默认模型] */
|
||||
const MODEL_TABLE: Record<ModelRole, Record<Complexity, [env: string, fallback: string]>> = {
|
||||
@@ -15,26 +15,36 @@ const MODEL_TABLE: Record<ModelRole, Record<Complexity, [env: string, fallback:
|
||||
hard: ['MAESTRO_MODEL_HARD', 'claude-fable-5'],
|
||||
},
|
||||
reviewer: {
|
||||
easy: ['MAESTRO_MODEL_REVIEW_EASY', 'claude-sonnet-4-6'],
|
||||
medium: ['MAESTRO_MODEL_REVIEW_MEDIUM', 'claude-opus-4-8'],
|
||||
hard: ['MAESTRO_MODEL_REVIEW_HARD', 'claude-opus-4-8'],
|
||||
easy: ['MAESTRO_MODEL_REVIEW_EASY', 'claude-fable-5'],
|
||||
medium: ['MAESTRO_MODEL_REVIEW_MEDIUM', 'claude-fable-5'],
|
||||
hard: ['MAESTRO_MODEL_REVIEW_HARD', 'claude-fable-5'],
|
||||
},
|
||||
// planner:拆解/写方案要质量,统一用 opus 档(project.model 设了仍最优先)
|
||||
// planner:拆解/写方案按复杂度分化(不受 project.model 覆盖)
|
||||
planner: {
|
||||
easy: ['MAESTRO_MODEL_PLAN_EASY', 'claude-opus-4-8'],
|
||||
easy: ['MAESTRO_MODEL_PLAN_EASY', 'claude-sonnet-4-6'],
|
||||
medium: ['MAESTRO_MODEL_PLAN_MEDIUM', 'claude-opus-4-8'],
|
||||
hard: ['MAESTRO_MODEL_PLAN_HARD', 'claude-opus-4-8'],
|
||||
hard: ['MAESTRO_MODEL_PLAN_HARD', 'claude-fable-5'],
|
||||
},
|
||||
// conflict:固定 fable-5,TABLE 条目仅占位(pickModel 对此角色直接 return 不走此处)
|
||||
conflict: {
|
||||
easy: ['', 'claude-fable-5'],
|
||||
medium: ['', 'claude-fable-5'],
|
||||
hard: ['', 'claude-fable-5'],
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 按角色 + 复杂度选模型:
|
||||
* 1. project.model 设了就最优先(executor/reviewer 都用它)
|
||||
* 2. 否则查 env 覆盖(MAESTRO_MODEL_* / MAESTRO_MODEL_REVIEW_*)
|
||||
* 3. 否则按复杂度取默认
|
||||
* 1. reviewer/conflict 不受 project.model 覆盖(保复审独立性)
|
||||
* 2. conflict 固定返回 claude-fable-5
|
||||
* 3. 其他角色 project.model 设了就最优先
|
||||
* 4. 否则查 env 覆盖(MAESTRO_MODEL_* / MAESTRO_MODEL_REVIEW_*)
|
||||
* 5. 否则按复杂度取默认
|
||||
*/
|
||||
export function pickModel(task: Task, project: Project, role: ModelRole): string {
|
||||
if (project.model) return project.model;
|
||||
// reviewer/conflict 用最强档,不受 project.model 覆盖(保自审独立性)
|
||||
if (role !== 'reviewer' && role !== 'conflict' && project.model) return project.model;
|
||||
if (role === 'conflict') return 'claude-fable-5';
|
||||
const [env, fallback] = MODEL_TABLE[role][task.complexity];
|
||||
const override = process.env[env]?.trim();
|
||||
return override || fallback;
|
||||
|
||||
@@ -54,8 +54,8 @@ export function isPlainRunId(runId: string): boolean {
|
||||
* worker 的唯一输入。daemon 在 spawn 前写 runs/<runId>/job.json,worker 读它即可执行,
|
||||
* 【无需访问 DB】。携带完整 Task / Project(均 JSON 可序列化),worker 自行 pickModel/buildPrompt。
|
||||
*/
|
||||
/** run 类型:executor(在 worktree 执行改动)/ planner-spec(写 Medium 方案)/ planner-decompose(拆解 Hard) */
|
||||
export type RunKind = 'executor' | 'planner-spec' | 'planner-decompose';
|
||||
/** run 类型:executor(在 worktree 执行改动)/ planner-spec(写 Medium 方案)/ planner-decompose(拆解 Hard)/ conflict(冲突裁决) */
|
||||
export type RunKind = 'executor' | 'planner-spec' | 'planner-decompose' | 'conflict';
|
||||
|
||||
export interface JobSpec {
|
||||
runId: string;
|
||||
@@ -71,7 +71,12 @@ export interface JobSpec {
|
||||
/** planner-decompose 的拆解产出:plan 文本 + 子任务列表 */
|
||||
export interface DecomposeResult {
|
||||
plan: string;
|
||||
subtasks: Array<{ title: string; complexity: 'easy' | 'medium' | 'hard' }>;
|
||||
subtasks: Array<{
|
||||
title: string;
|
||||
complexity: 'easy' | 'medium' | 'hard';
|
||||
priority?: number; // 0=P0最高/1=P1中/2=P2最低,缺省=1
|
||||
deps?: number[]; // 引用同列表其他子任务的 0-based 序号,缺省=[]
|
||||
}>;
|
||||
}
|
||||
|
||||
export function writeJobSpec(job: JobSpec): void {
|
||||
@@ -115,7 +120,12 @@ export type OutboxRecord =
|
||||
| { seq: number; at: string; type: 'spec-result'; spec: string; transcriptRef: string | null; sessionId: string | null }
|
||||
| {
|
||||
seq: number; at: string; type: 'decompose-result';
|
||||
plan: string; subtasks: Array<{ title: string; complexity: 'easy' | 'medium' | 'hard' }>;
|
||||
plan: string; subtasks: Array<{
|
||||
title: string;
|
||||
complexity: 'easy' | 'medium' | 'hard';
|
||||
priority?: number;
|
||||
deps?: number[];
|
||||
}>;
|
||||
transcriptRef: string | null; sessionId: string | null;
|
||||
}
|
||||
| { seq: number; at: string; type: 'done' };
|
||||
|
||||
@@ -26,6 +26,11 @@ export interface Project {
|
||||
sortOrder: number; // 侧栏排序(小在前)
|
||||
createdAt: string;
|
||||
lastSyncAt: string | null; // 最近一次 todo.json 同步完成时间
|
||||
/** 项目级自动放行开关(auto-approved autonomy 下才生效)*/
|
||||
autoApprovePlan?: boolean; // decompose 全 easy 时跳过 plan_review(默认 false)
|
||||
autoApproveExec?: boolean; // 双复审 approve 后跳过 exec_review 自动合并(默认 false)
|
||||
/** 分项检查命令(JSON,如 {"lint":"npm run lint","typecheck":"npm run typecheck"})*/
|
||||
checks?: string | null;
|
||||
}
|
||||
|
||||
export interface ApprovalRecord {
|
||||
|
||||
Reference in New Issue
Block a user