/ index.ts
index.ts
1 import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; 2 3 const STYLEGUIDE_PATH = "~/.claude/references/org-styleguide-full.org"; 4 5 const REMINDER = [ 6 `You are about to edit or create an org-mode file.`, 7 `Authoritative style guide: ${STYLEGUIDE_PATH} — Read it before substantive edits.`, 8 ``, 9 `Quick reminders:`, 10 `- Single-asterisk *bold*, NOT markdown-style **bold** (renders as literal asterisks in org).`, 11 `- Inline code: ~code~. Paths/commands/values: =verbatim=. Never markdown backticks.`, 12 `- Lowercase #+keywords (#+title:, #+begin_src — not #+TITLE:).`, 13 `- Heading depth <= 4 (* through ****).`, 14 `- Bullet lists use '-' only (not '+' or '*').`, 15 `- #+begin_src requires a language identifier.`, 16 `- One blank line before each headline; no blank line between headline and first content.`, 17 `- Links: [[url][description]], not bare URLs.`, 18 ].join("\n"); 19 20 export function isOrgFile(path: string | undefined): boolean { 21 return !!path && /\.(org|org_archive|org\.gpg)$/.test(path); 22 } 23 24 export default function orgStyleguideReminder(pi: ExtensionAPI) { 25 let notified = false; 26 27 pi.on("session_start", async () => { 28 notified = false; 29 }); 30 31 pi.on("tool_call", async (event, ctx) => { 32 if (event.toolName !== "edit" && event.toolName !== "write") return; 33 34 const path = (event.input as { path?: string }).path; 35 if (!isOrgFile(path)) return; 36 37 if (notified) return; 38 notified = true; 39 40 if (ctx.hasUI) { 41 ctx.ui.notify( 42 `Org-mode file detected — reminding agent of style guide.`, 43 "info", 44 ); 45 } 46 47 try { 48 pi.sendUserMessage(REMINDER, { deliverAs: "steer" }); 49 } catch { 50 // Best-effort: the notify above already surfaced the signal to the user. 51 } 52 }); 53 }