diff --git a/pi-extension-raspberrypi-wiki-local/index.ts b/pi-extension-raspberrypi-wiki-local/index.ts index 163d7c39..e900d167 100644 --- a/pi-extension-raspberrypi-wiki-local/index.ts +++ b/pi-extension-raspberrypi-wiki-local/index.ts @@ -4,12 +4,12 @@ import path from "node:path"; import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { createLocalWikiEngine, jsonToolResult, pathExists, runCommand } from "@firstpick/pi-utils"; import { Type } from "typebox"; +import { shouldRouteLocalWikiPrompt } from "./lib/prompt-routing.mjs"; const CONFIG = { extensionId: "raspberrypi", displayName: "Raspberry Pi Documentation", topicName: "Raspberry Pi", - skillName: "raspberrypi-local", docsPath: "~/.raspberrypiwiki".replace(/^~(?=\/|$)/, os.homedir()).replace(/^\$HOME(?=\/|$)/, os.homedir()), repoUrl: "https://github.com/raspberrypi/documentation", setupCommand: "/raspberrypi-wiki-local-setup", @@ -174,8 +174,7 @@ const smokeParams = Type.Object({ maxSearchResults: Type.Optional(Type.Number({ export default function localWikiExtension(pi: ExtensionAPI) { pi.on?.("before_agent_start", async (event, ctx) => { - const skillLoaded = event.systemPromptOptions.skills?.some((skill) => skill.name === CONFIG.skillName) ?? false; - if (!skillLoaded && !CONFIG.promptDetection.test(event.prompt ?? "")) return; + if (!shouldRouteLocalWikiPrompt(event.prompt ?? "", CONFIG.promptDetection)) return; if (!await wiki.available()) { const warning = `${MISSING_DOCS_MESSAGE} Aborting ${CONFIG.displayName}-local lookup until setup is complete.`; diff --git a/pi-extension-raspberrypi-wiki-local/lib/prompt-routing.mjs b/pi-extension-raspberrypi-wiki-local/lib/prompt-routing.mjs new file mode 100644 index 00000000..f4e60bf3 --- /dev/null +++ b/pi-extension-raspberrypi-wiki-local/lib/prompt-routing.mjs @@ -0,0 +1,6 @@ +const MISSING_DOCS_REPORT = /\blocal raspberry pi documentation docs are not available at\b|raspberrypi-wiki-local-missing-docs/i; + +export function shouldRouteLocalWikiPrompt(prompt, promptDetection) { + if (MISSING_DOCS_REPORT.test(prompt)) return false; + return promptDetection.test(prompt); +} diff --git a/pi-extension-raspberrypi-wiki-local/package.json b/pi-extension-raspberrypi-wiki-local/package.json index 970e9945..8bb5ba21 100644 --- a/pi-extension-raspberrypi-wiki-local/package.json +++ b/pi-extension-raspberrypi-wiki-local/package.json @@ -20,6 +20,9 @@ "raspberry-pi", "raspberrypi" ], + "scripts": { + "test": "node --test tests/*.test.mjs" + }, "pi": { "extensions": [ "./index.ts" @@ -37,6 +40,8 @@ }, "files": [ "index.ts", + "lib", + "tests", "skills", "references", "README.md", diff --git a/pi-extension-raspberrypi-wiki-local/tests/prompt-routing.test.mjs b/pi-extension-raspberrypi-wiki-local/tests/prompt-routing.test.mjs new file mode 100644 index 00000000..6d65e0c2 --- /dev/null +++ b/pi-extension-raspberrypi-wiki-local/tests/prompt-routing.test.mjs @@ -0,0 +1,22 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { shouldRouteLocalWikiPrompt } from "../lib/prompt-routing.mjs"; + +const raspberryPiPrompt = /\b(raspberry\s*pi|raspberrypi|raspi|rpi|pico|rp2040|rp2350)\b/i; + +test("does not route unrelated extension diagnostics", () => { + assert.equal(shouldRouteLocalWikiPrompt("[Extension issues]", raspberryPiPrompt), false); + assert.equal(shouldRouteLocalWikiPrompt("npm:@firstpick/pi-package-webui (user)", raspberryPiPrompt), false); +}); + +test("does not intercept its own missing-corpus diagnostic", () => { + assert.equal(shouldRouteLocalWikiPrompt( + "Local Raspberry Pi Documentation docs are not available at /tmp/docs. Run /raspberrypi-wiki-local-setup to set them up.", + raspberryPiPrompt, + ), false); +}); + +test("routes actual Raspberry Pi support prompts", () => { + assert.equal(shouldRouteLocalWikiPrompt("How do I enable SSH on Raspberry Pi OS?", raspberryPiPrompt), true); + assert.equal(shouldRouteLocalWikiPrompt("Configure Pico SDK for RP2350", raspberryPiPrompt), true); +});