import { Type } from "@sinclair/typebox"; import type { ExtensionAPI, ToolResult } from "../_shared/pi-api.js"; import { errorResult, getCommandText, setTextWidget, textResult } from "../_shared/pi-api.js"; import { validateParams } from "../_shared/validation.js"; const LoopParams = Type.Object({ action: Type.Union([ Type.Literal("start"), Type.Literal("stop"), Type.Literal("status"), Type.Literal("once"), Type.Literal("until"), ], { description: "Loop action" }), condition: Type.Optional(Type.String({ description: "Stop condition regex for until", maxLength: 500 })), maxTurns: Type.Optional(Type.Integer({ minimum: 1, maximum: 50, default: 5, description: "Maximum turns" })), }); const DETAILS = { owner: "omp-loop-mode", ported: false, requestedSurface: "loop", redesignRequired: true, } as const; const REPORT = [ "Loop is disabled in miloc-pi.", "OMP loop mode, loop-limit parsing, interactive auto-submit, compaction guards and post-prompt background delivery are the source truth for this capability.", "Port or thin-wrap that OMP behavior before enabling automatic continuation.", ].join(" "); export default function loop(pi: ExtensionAPI): void { pi.registerTool({ name: "loopControl", description: "Disabled loop controller until OMP loop mode and async delivery are ported.", parameters: LoopParams, execute(_toolCallId, params) { const valid = validateParams(LoopParams, params); if (!valid.ok) return valid.result; if (valid.value.action === "status") return loopStatus(); return loopBlocked(valid.value.action); }, }); pi.registerCommand("loop", { description: "Report disabled loop status; automatic continuation waits for the OMP loop mode port.", handler: async (args, ctx) => { const action = getCommandText(args).trim().split(/\s+/)[0] || "status"; const result = action === "status" ? loopStatus() : loopBlocked(action); const text = result.content[0]?.type === "text" ? result.content[0].text : REPORT; setTextWidget(ctx, "loop", text); }, }); } function loopStatus(): ToolResult { return textResult(REPORT, { ...DETAILS, requestedAction: "status" }); } function loopBlocked(action: string): ToolResult { return errorResult(REPORT, { ...DETAILS, requestedAction: action }); }