import { fileURLToPath } from "node:url"; import { Type } from "@earendil-works/pi-ai"; import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { collectOfficeStatus } from "./status/probes.ts"; import { formatStatusSummary } from "./status/report.ts"; import { registerWordTools } from "./word/tools.ts"; import { registerPdfTools } from "./pdf/tools.ts"; const projectRoot = fileURLToPath(new URL("..", import.meta.url)); export default function piWordPdf(pi: ExtensionAPI): void { const collect = (cwd: string, signal?: AbortSignal) => collectOfficeStatus({ cwd, projectRoot, exec: (command, args, options) => { const effectiveSignal = signal ?? options?.signal; return pi.exec(command, args, { ...(options?.cwd ? { cwd: options.cwd } : {}), ...(options?.timeout !== undefined ? { timeout: options.timeout } : {}), ...(effectiveSignal ? { signal: effectiveSignal } : {}), }); }, }); pi.registerTool({ name: "office_status", label: "Office Status", description: "Read-only capability and dependency status for the staged pi-word-pdf package. It never installs or modifies documents.", promptSnippet: "Check whether Windows, Microsoft Word, Python, Bun, bun-docx, PDF modules, and Chinese fonts are available", promptGuidelines: [ "Use for Word/PDF readiness or dependency questions.", "Do not claim document editing features are implemented in stage 1.", "Never install dependencies as part of this status tool.", ], parameters: Type.Object({}, { additionalProperties: false }), async execute(_toolCallId, _params, signal, _onUpdate, ctx) { const report = await collect(ctx.cwd, signal); return { content: [{ type: "text", text: formatStatusSummary(report) }], details: report, }; }, }); pi.registerCommand("word-pdf-status", { description: "Show read-only pi-word-pdf capability and dependency status", handler: async (_args, ctx) => { try { const report = await collect(ctx.cwd); ctx.ui.notify(formatStatusSummary(report), "info"); } catch (error) { const message = error instanceof Error ? error.message : String(error); ctx.ui.notify(`pi-word-pdf 状态检测失败:${message}`, "error"); } }, }); registerWordTools(pi, projectRoot); registerPdfTools(pi, projectRoot); }