import { Type } from "@sinclair/typebox"; import type { ExtensionAPI } from "../_shared/pi-api.js"; import { errorResult, getCommandText, setTextWidget } from "../_shared/pi-api.js"; import { validateParams } from "../_shared/validation.js"; const GoalSetParams = Type.Object({ objective: Type.String({ description: "Goal text", minLength: 1, maxLength: 2000 }), constraints: Type.Optional(Type.Array(Type.String({ maxLength: 500 }), { maxItems: 20 })), doneCriteria: Type.Optional(Type.Array(Type.String({ maxLength: 200 }), { maxItems: 10 })), }); const GoalParams = Type.Object({ op: Type.Union([ Type.Literal("create"), Type.Literal("get"), Type.Literal("complete"), Type.Literal("resume"), Type.Literal("drop"), ], { description: "OMP goal operation" }), objective: Type.Optional(Type.String({ description: "Goal objective for op=create", minLength: 1, maxLength: 8000 })), token_budget: Type.Optional(Type.Integer({ description: "Positive token budget for op=create", minimum: 1 })), }); export default function goal(pi: ExtensionAPI): void { pi.registerTool({ name: "goal", description: "OMP-shaped goal contract. Fails closed until OMP GoalRuntime is ported.", parameters: GoalParams, async execute(_toolCallId, params) { const valid = validateParams(GoalParams, params); if (!valid.ok) return valid.result; return goalNotPorted(valid.value.op); }, }); pi.registerTool({ name: "goalSet", description: "Legacy alias for the old local goal state. Fails closed until OMP GoalRuntime is ported.", parameters: GoalSetParams, async execute(_toolCallId, params) { const valid = validateParams(GoalSetParams, params); if (!valid.ok) return valid.result; return goalNotPorted("create", "goalSet"); }, }); pi.registerCommand("goal", { description: "Show fail-closed OMP goal status until GoalRuntime is ported.", handler: async (args, ctx) => { const [action = "show"] = getCommandText(args).trim().split(/\s+/); const op = commandActionToGoalOp(action); const result = goalNotPorted(op, "goal-command"); ctx.ui.setStatus("goal", "disabled until OMP GoalRuntime port"); setTextWidget(ctx, "goal", result.content[0]?.type === "text" ? result.content[0].text : "goal runtime is not available"); }, }); } function commandActionToGoalOp(action: string): "create" | "get" | "complete" | "resume" | "drop" { if (action === "set" || action === "create") return "create"; if (action === "done" || action === "complete") return "complete"; if (action === "resume") return "resume"; if (action === "clear" || action === "drop") return "drop"; return "get"; } function goalNotPorted(op: "create" | "get" | "complete" | "resume" | "drop", requestedSurface: "goal" | "goalSet" | "goal-command" = "goal") { return errorResult( [ "Goal runtime is disabled in miloc-pi.", "OMP `goal` is the source truth for create/get/resume/drop/complete, token budgets, status transitions, continuation prompts, and completion audit.", "This extension does not inject hidden goal context until OMP GoalRuntime is ported here.", ].join("\n"), { owner: "omp-goal", ported: false, requestedSurface, op, ompSources: [ "packages/coding-agent/src/goals/tools/goal-tool.ts", "packages/coding-agent/src/goals/runtime.ts", "packages/coding-agent/src/goals/state.ts", "packages/coding-agent/src/prompts/tools/goal.md", "packages/coding-agent/src/prompts/goals/goal-mode-active.md", "packages/coding-agent/src/prompts/goals/goal-continuation.md", "packages/coding-agent/src/session/agent-session.ts", ], }, ); }