Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pi-extension-raspberrypi-wiki-local/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.`;
Expand Down
6 changes: 6 additions & 0 deletions pi-extension-raspberrypi-wiki-local/lib/prompt-routing.mjs
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions pi-extension-raspberrypi-wiki-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"raspberry-pi",
"raspberrypi"
],
"scripts": {
"test": "node --test tests/*.test.mjs"
},
"pi": {
"extensions": [
"./index.ts"
Expand All @@ -37,6 +40,8 @@
},
"files": [
"index.ts",
"lib",
"tests",
"skills",
"references",
"README.md",
Expand Down
22 changes: 22 additions & 0 deletions pi-extension-raspberrypi-wiki-local/tests/prompt-routing.test.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
Loading