// ============================================================ // Dispatch Tasks tool - workspace-level task batch dispatch // ============================================================ // 设计合同见根目录 docs/specs/workspace-task-dispatch.md。 // 关键约束: // - 子会话不继承本对话历史,prompt 必须自包含;schema description 里显式告知模型。 // - execute 可被用户在统一确认窗改写(仅创建 / 创建并执行),host 端以确认结果为准。 // - 失败隔离:单项失败不阻塞其余,输出为逐项结果的有界列表,不回灌子会话正文。 import { z } from "zod"; import { toToolJsonSchema } from "./json-schema.js"; const nonEmptyString = z.string().trim().min(1); export const DISPATCH_TASKS_MAX_TASKS = 50; export const DISPATCH_TASKS_TITLE_MAX_CHARS = 120; export const DispatchTaskItemSchema = z .object({ id: nonEmptyString .max(64) .describe( "Short stable slug for this task, unique within this dispatch (for example 'fix-login-crash'). Used by dependsOn references and the result summary.", ), title: nonEmptyString .max(DISPATCH_TASKS_TITLE_MAX_CHARS) .describe( "Concise task title shown in the workspace task list, for example '修复登录页崩溃'. No file paths.", ), prompt: nonEmptyString.describe( "Self-contained instructions for this task. The new session does NOT inherit this conversation's history, so restate all needed context (files, symptoms, acceptance criteria) inside the prompt.", ), dependsOn: z .array(nonEmptyString.max(64)) .max(DISPATCH_TASKS_MAX_TASKS) .optional() .describe( "Ids of tasks this one logically depends on. Display-only in v1 (all tasks run concurrently); kept for future ordered execution.", ), parallelGroup: z .number() .int() .min(0) .max(99) .optional() .describe( "Execution plan group (M-spec): tasks with the same parallelGroup run concurrently; groups run in ascending order. Omit for a single default group.", ), }) .strict(); export type DispatchTaskItem = z.infer; export const DispatchTasksInputSchema = z .object({ tasks: z.array(DispatchTaskItemSchema).min(1).max(DISPATCH_TASKS_MAX_TASKS).describe( "The organized task list to create under the current workspace. Deduplicate overlapping items first; each item must be independently actionable.", ), execute: z .boolean() .default(true) .describe( "Whether to also start executing each task after creation. The user can override this in the confirmation dialog (create-only mode leaves tasks as drafts).", ), }) .strict(); export type DispatchTasksInput = z.infer; export const DispatchTasksInputJsonSchema = toToolJsonSchema(DispatchTasksInputSchema); /** 单项终态;failure 仅在 status 为 failed 时出现一行摘要,不带堆栈。 */ export const DispatchTaskResultSchema = z .object({ id: nonEmptyString.max(64), title: z.string(), status: z.enum(["created", "started", "failed"]), sessionId: nonEmptyString.optional(), failure: z.string().max(400).optional(), }) .strict(); export type DispatchTaskResult = z.infer; export const DispatchTasksOutputSchema = z .object({ executed: z.boolean(), createdCount: z.number().int().nonnegative(), failedCount: z.number().int().nonnegative(), results: z.array(DispatchTaskResultSchema).max(DISPATCH_TASKS_MAX_TASKS), message: nonEmptyString, }) .strict(); export type DispatchTasksOutput = z.infer; export const DispatchTasksOutputJsonSchema = toToolJsonSchema(DispatchTasksOutputSchema);