repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix prompt autopsy and system docs

1ddec6dd1c0d1e59ac74aa0a4d04e7c6cd0c6f61

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (6)

.system/MISSION.md

Modified
1 -# MISSION
1 +# Why this exists
3 -Maintain a personal Pi extension pack that adapts Pi to the maintainer's workflows through small tools, integrations, interface components, and automation.
3 +I maintain `pi-ext` to make Pi fit the way I work.

.system/SYSTEM.md

Modified
1 -# SYSTEM
1 +# pi-ext
3 -## Identity
3 +This is my personal TypeScript and ES-module monorepo for Pi extensions.
4 +I use it to shape Pi around my workflows through small tools, integrations, interface components, and automation.
5 -`pi-ext` is a personal TypeScript and ES-module monorepo of Pi extensions.
6 -Extension workspaces live under `extensions/*`.
6 +The root package is the supported Pi installation and distribution unit.
7 +Extensions live under `extensions/*`.
8 +They are not independent release units.
9 +Sibling extensions stay isolated.
10 +Dependencies are installed centrally.
8 -## Runtime package
10 -The repository root is the supported Pi installation and distribution unit.
11 -Its manifest exports `extensions/pfui/index.ts` first, `extensions/footer/index.ts` second, then `extensions/*/index.ts`, and no root skills, prompts, or themes.
12 -Package filters may select a subset of those exported resources.
13 -Pi loads the TypeScript extension entrypoints directly through its extension loader.
15 -Extension manifests define private npm workspaces and development boundaries, not independent release units.
16 -Static validation forbids dependencies and imports between sibling extensions.
17 -Workspace dependencies are installed centrally and resolved from the shared installation.
19 -## Automation and verification
21 -Mise exposes the public repository automation interface.
22 -npm owns the workspace dependency graph and lockfile.
23 -Vitest runs source tests, and Playwright runs browser acceptance tests.
24 -Luci runs the repository CI task after pushes.
26 -## Release
28 -The root package owns one repository version and releases use `vX.Y.Z` tags.
29 -Per-extension versions are absent.
30 -Release automation updates documentation, commits, tags, and pushes the source package.
31 -The current release path does not build standalone extension packages or publish to npm.
12 +Mise is the repository's public automation interface.
13 +The repository has one version.
14 +Releases use `vX.Y.Z` tags.

CHANGELOG.md

Modified
9 9 - Move The System, Ultra, Mockup, and Tune prompt contributions into named sections and prohibit flat prompt overrides
10 10 - Register Mockup and Ultra authoring guidance as skills instead of tool rules
11 11 - Correct tool metadata with self-identifying guidelines, UV and IntelliJ routing guidance, Tune VCS semantics, and richer provider descriptions
12 -- Update Prompt Autopsy to group Pi 0.86 prompt sections and refuse to show the pre-hook base prompt when no provider-effective prompt has been captured
12 +- Update Prompt Autopsy to group Pi 0.86 prompt sections, handle nested sections, and write captured prompts to private temporary files
13 13 - Improve Decay’s compaction display with stationary retained context, left-growing summaries, chunk-position progress, live memory selection, and recency markers
14 14 - Make Decay retry classification and summarization with the current session model when an explicit model is unavailable or fails, including quota and rate-limit errors
15 15 - Remove working-label updates from the Web fetch and search tools

extensions/prompt-autopsy/README.md

Modified
23 23 ## Behavior
25 -Writes the current generated system prompt to `/tmp/sysprompt-autopsy.md`.
25 +Writes the current generated system prompt to a private temporary file.
26 26 Opens it with `$VISUAL`, else `$EDITOR`, else `vi`.
28 28 `before_agent_start` captures Pi's rendered system prompt.

extensions/prompt-autopsy/__tests__/harness.test.ts

Modified
1 +import { lstatSync, readFileSync, rmSync } from "node:fs";
1 2 import path from "node:path";
2 3 import { afterEach, describe, expect, it } from "vitest";
3 4 import { createTestSession, type TestSession } from "../../../test/harness";
65 66 expect(grouped).not.toContain("[SECTION project_instructions]");
69 + it("keeps nested same-name sections intact", () => {
70 + const grouped = groupSystemPrompt(`<addendum>
71 +outer
72 +<addendum>
73 +inner
74 +</addendum>
75 +outer tail
76 +</addendum>
78 +<cwd>
79 +/repo
80 +</cwd>`);
82 + expect(grouped).toBe(`[APPEND]
83 +<addendum>
84 +outer
85 +<addendum>
86 +inner
87 +</addendum>
88 +outer tail
89 +</addendum>
91 +[CWD]
92 +<cwd>
93 +/repo
94 +</cwd>`);
95 + });
97 + it("writes a private output file and opens it", async () => {
98 + const extensionPath = path.resolve(import.meta.dirname, "../index.ts");
99 + t = await createTestSession({
100 + extensions: [extensionPath],
101 + env: { VISUAL: `${process.execPath} -e "process.exit(0)"` },
102 + });
104 + await t.session.extensionRunner.emitBeforeAgentStart("prompt", undefined, {
105 + cwd: t.cwd,
106 + forceSystemPrompt: "<tools>\n- read\n</tools>",
107 + });
108 + await t.session.extensionRunner.emit({ type: "agent_start" } as never);
110 + const command =
111 + t.session.extensionRunner.extensions[0].commands.get("prompt-autopsy");
112 + await command.handler("", t.session.extensionRunner.createCommandContext());
114 + const notification = t.events.uiCallsFor("notify").at(-1)?.args;
115 + expect(notification?.[1]).toBe("info");
116 + const outputPath = String(notification?.[0]).replace(/^wrote /, "");
117 + expect(outputPath).not.toBe("/tmp/sysprompt-autopsy.md");
118 + expect(lstatSync(path.dirname(outputPath)).mode & 0o777).toBe(0o700);
119 + expect(lstatSync(outputPath).mode & 0o777).toBe(0o600);
120 + expect(readFileSync(outputPath, "utf8")).toContain("[TOOLS]");
121 + rmSync(path.dirname(outputPath), { recursive: true, force: true });
122 + });
68 124 it("loads in real Pi extension runtime", async () => {
69 125 const extensionPath = path.resolve(import.meta.dirname, "../index.ts");
70 126 t = await createTestSession({ extensions: [extensionPath] });

extensions/prompt-autopsy/index.ts

Modified
1 1 import { spawnSync } from "node:child_process";
2 -import { writeFileSync } from "node:fs";
2 +import { mkdtempSync, writeFileSync } from "node:fs";
3 +import { tmpdir } from "node:os";
4 +import { join } from "node:path";
3 5 import type {
4 6 ExtensionAPI,
5 7 ExtensionContext,
6 8 } from "@earendil-works/pi-coding-agent";
7 9 import { Key } from "@earendil-works/pi-tui";
9 -const OUT = "/tmp/sysprompt-autopsy.md";
11 +const OUTPUT_PREFIX = "pi-prompt-autopsy-";
12 +const OUTPUT_FILENAME = "system-prompt.md";
10 13 const LABEL = {
11 14 preamble: "[PREAMBLE]",
12 15 core: "[CORE]",
62 65 const start = match.index + (match[0].startsWith("\n") ? 1 : 0);
63 66 if (start < consumed) continue;
64 67 const name = match[1];
65 - const close = `\n</${name}>`;
66 - const closeStart = prompt.indexOf(close, pattern.lastIndex);
67 - if (closeStart < 0) continue;
68 - const end = closeStart + close.length;
68 + const end = findSectionEnd(prompt, name, pattern.lastIndex);
69 + if (end === undefined) continue;
69 70 ranges.push({
70 71 start,
77 78 return ranges;
81 +function findSectionEnd(
82 + prompt: string,
83 + name: string,
84 + contentStart: number,
85 +): number | undefined {
86 + const opening = `<${name}>\n`;
87 + const closing = `\n</${name}>`;
88 + let depth = 1;
89 + let cursor = contentStart;
91 + while (depth > 0) {
92 + const nextOpening = findLineOpening(prompt, opening, cursor);
93 + const closeStart = prompt.indexOf(closing, cursor);
94 + if (closeStart < 0) return undefined;
96 + if (nextOpening >= 0 && nextOpening < closeStart) {
97 + depth++;
98 + cursor = nextOpening + opening.length;
99 + continue;
102 + depth--;
103 + cursor = closeStart + closing.length;
104 + if (depth === 0) return cursor;
107 + return undefined;
110 +function findLineOpening(
111 + prompt: string,
112 + opening: string,
113 + from: number,
114 +): number {
115 + for (
116 + let index = prompt.indexOf(opening, from);
117 + index >= 0;
118 + index = prompt.indexOf(opening, index + opening.length)
119 + ) {
120 + if (index === 0 || prompt[index - 1] === "\n") return index;
122 + return -1;
80 125 function appendSection(out: string[], label: string, text: string): void {
81 126 const body = text.trim();
82 127 if (body) out.push(`${label}\n${body}`);
130 +function writePromptFile(prompt: string): string {
131 + const directory = mkdtempSync(join(tmpdir(), OUTPUT_PREFIX));
132 + const outputPath = join(directory, OUTPUT_FILENAME);
133 + writeFileSync(outputPath, prompt, {
134 + encoding: "utf8",
135 + mode: 0o600,
136 + flag: "wx",
137 + });
138 + return outputPath;
85 141 function openEditor(path: string): boolean {
86 142 const editor = process.env.VISUAL || process.env.EDITOR || "vi";
87 143 const result = spawnSync(`${editor} ${JSON.stringify(path)}`, {
118 174 return;
120 - writeFileSync(OUT, groupSystemPrompt(captured.prompt));
121 - const ok = openEditor(OUT);
176 + const outputPath = writePromptFile(groupSystemPrompt(captured.prompt));
177 + const ok = openEditor(outputPath);
122 178 ctx.ui.notify(
123 - ok ? `wrote ${OUT}` : `wrote ${OUT}; editor failed`,
179 + ok ? `wrote ${outputPath}` : `wrote ${outputPath}; editor failed`,
124 180 ok ? "info" : "warning",