import type { ExtensionFactory } from "@oh-my-pi/pi-coding-agent"; export function createFieldNotesExtension(notebookName: string): ExtensionFactory { return pi => { let selected: string | null = null; const { Type } = pi.typebox; pi.registerTool({ name: "inline_notebook", label: "Inline notebook", description: "Discover the inline notebook, inspect its contract, query selection, or act to select reed or fern. Binding-local memory survives /new and session switches; a fresh factory binding resets it.", parameters: Type.Object({ op: Type.Union([Type.Literal("discover"), Type.Literal("inspect"), Type.Literal("query"), Type.Literal("act")]), id: Type.Optional(Type.Union([Type.Literal("reed"), Type.Literal("fern")])), }), async execute(_callId, params) { if (params.op === "act") { if (!params.id) throw new Error("act requires id; nothing changed."); selected = params.id; } const details = { notebookName, selected, ids: ["reed", "fern"], operations: ["discover", "inspect", "query", "act"], persistence: "factory-local" }; return { content: [{ type: "text", text: JSON.stringify(details) }], details }; }, }); pi.registerCommand("inline-notebook", { description: "Show the inline notebook selection", async handler(_args, ctx) { ctx.ui.notify(`${notebookName}: ${selected ?? "no note selected"}.`, "info"); }, }); }; }