/** * 9plan_queue_add tool * * Adds a new plan to the queue with front/back positioning. */ import { z } from "zod"; import type { SessionStoreInterface } from "../types.js"; import { formatResponse, NinePlanError } from "../types.js"; // Input schema export const queueAddInputSchema = { context: z .string() .min(1, "Context is required") .describe("Where this plan fits in the overall task"), goal: z .string() .min(1, "Goal is required") .describe("What this plan accomplishes"), approach: z .string() .min(1, "Approach is required") .describe( "How to accomplish the goal. Include enough detail (steps, code samples, " + "structure, edge cases) that the plan is executable without additional context.", ), success_criteria: z .string() .min(1, "Success criteria is required") .describe("Observable conditions that indicate completion"), testing: z .string() .min(1, "Testing is required") .describe( "How to verify the implementation works. Include specific commands, " + "expected outputs, and edge cases to validate.", ), inputs: z .string() .optional() .describe( 'Dependencies from other plans (format: "- description: source")', ), outputs: z .string() .optional() .describe( 'What this plan produces that others may consume (format: "- description: details")', ), position: z .enum(["front", "back"]) .optional() .default("back") .describe( 'Queue position: "front" for blocking work, "back" for eventual work', ), }; // Input type export interface QueueAddInput { context: string; goal: string; approach: string; success_criteria: string; testing: string; inputs?: string; outputs?: string; position?: "front" | "back"; } /** * Handle queue add tool call */ export function handleQueueAdd( store: SessionStoreInterface, sessionName: string, args: QueueAddInput, ): { content: { type: "text"; text: string }[] } { try { const planInput = { context: args.context, goal: args.goal, approach: args.approach, successCriteria: args.success_criteria, testing: args.testing, ...(args.inputs !== undefined && { inputs: args.inputs }), ...(args.outputs !== undefined && { outputs: args.outputs }), }; const plan = store.addPlan(planInput, args.position ?? "back"); const planPath = store.getSessionPath() + `/plans/${plan.id}.txt`; const positionNote = args.position === "front" ? " (front)" : ""; const response = formatResponse( sessionName, `Plan added: ${plan.id} Path: ${planPath} Queue position: ${String(plan.queuePosition)}${positionNote} The plan file has been created. Use 9plan_queue_pull when ready to execute.`, ); return { content: [{ type: "text", text: response }], }; } catch (error) { if (error instanceof NinePlanError) { return { content: [{ type: "text", text: error.format(sessionName) }], }; } throw error; } } // Tool configuration for registration export const queueAddToolConfig = { title: "Add Plan to Queue", description: "Adds a new plan to the queue. Required fields: context, goal, approach, testing, success_criteria. Optional: inputs, outputs, position (front/back, default: back). Front = blocking work, back = eventual work.", inputSchema: queueAddInputSchema, };