import { StringEnum } from "@earendil-works/pi-ai"; import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { Type } from "typebox"; import { truncateUtf8 } from "./output.js"; import { REPORT_MAX_BYTES } from "./types.js"; export const ReportParams = Type.Object({ kind: StringEnum(["progress", "help_request"] as const), message: Type.String({ minLength: 1, maxLength: REPORT_MAX_BYTES }), }, { additionalProperties: false }); export default function registerChildExtension(pi: ExtensionAPI): void { pi.registerTool({ name: "subagent_report", label: "Subagent Report", description: "Use subagent_report with kind=progress only at meaningful milestones, not routine chatter; when blocked, call kind=help_request alone, then stop/settle; do not combine help with other tool calls.", parameters: ReportParams, execute: async (_id, input) => { const message = truncateUtf8(input.message, REPORT_MAX_BYTES).text; return { content: [{ type: "text", text: message }], details: { kind: input.kind, message }, ...(input.kind === "help_request" ? { terminate: true } : {}), }; }, }); pi.registerCommand("simple-subagent-shutdown", { description: "Internal child shutdown command.", handler: async (_args, ctx) => { ctx.shutdown(); }, }); }