repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

refactor(shame): rename review extension

ac6a84cd381482c839fd5b7d3ab0225438f847c5

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (11)

CHANGELOG.md

Modified
4 4 # Changelog
6 6 ## Unreleased
8 8 - Add the `btw` extension with a `/btw` side-chat overlay, persisted side-thread history, summary injection back into the main chat, limited `read`/`bash` side-agent tools, README, package metadata, and harness coverage
9 9 - Add the `uv` extension to route Python package/tooling commands through `uv`, with harness coverage
10 -- Add the `review` extension with `/review` smart defaults and targets for uncommitted changes, branch diffs, commits, folders, and GitHub PRs, plus project `REVIEW_GUIDELINES.md` support and harness coverage
10 +- Add the `shame` extension with `/shame` smart defaults, inferred targets, `@` paths, argument completion, project `REVIEW_GUIDELINES.md` support, and harness coverage
11 11 - Add the `split-fork` extension with `/split-fork [prompt]` to fork the current session branch into a new Pi process in a Ghostty split on macOS, with `osascript` checks and harness coverage
12 12 - Bump the project Node toolchain from 22 to 26.5.0
13 13 - Add a `cmprss` Pi extension design spec adapted from Headroom concepts, keeping deterministic content-aware tool-result compression, Pi-native retrieval markers, session-persisted originals for restart-stable retrieval, compact savings UI, commands, settings, tests, and acceptance checks while rejecting proxy/server, SDK dependency, Python/Rust/ML/MCP, telemetry, dashboards, provider wrappers, and legacy compatibility
30 30 thinking suffixes such as `openai/gpt-5-mini:low`
31 31 - Add ultra aggregate token/cost accounting in workflow results from reported
32 32 sub-agent usage
33 +- Add ultra incomplete-run resume journals, reusing completed matching steps
34 + after an aborted run while completed runs start fresh
33 35 - Ship the ultra `feature` workflow (research → plan → adversarial critique →
34 36 implement → security/quality review), and make `/ultra` positional args soak
35 37 the trailing free text into the last declared param so `/ultra feature <task>`

README.md

Modified
90 90 | `pulse` | Living documentation sync for Pi. | [README](extensions/pulse/README.md) |
91 91 | `q` | Follow-up question fork helper for Pi. | [README](extensions/q/README.md) |
92 92 | `quota` | Subscription quota dashboard for Pi providers. | [README](extensions/quota/README.md) |
93 -| `review` | Agent code-review command for Pi. | [README](extensions/review/README.md) |
93 +| `shame` | Hostile agent code review for Pi. | [README](extensions/shame/README.md) |
94 94 | `runtime` | Runtime detection telemetry for Pi footer/status. | [README](extensions/runtime/README.md) |
95 95 | `rtk` | RTK bash command rewrite hook for Pi. | [README](extensions/rtk/README.md) |
96 96 | `session-rename` | Automatic short session names for Pi. | [README](extensions/session-rename/README.md) |

extensions/review/README.md

Deleted
deleted file mode 100644
1 -# review
3 -Agent code-review command for Pi.
5 -## Install / load
7 -Loaded through the root `pi-ext` package.
8 -See [root README](../../README.md).
10 -## Commands / tools / settings
12 -- Commands:
13 - - `/review [target] [--extra <focus>]`
14 -- Tools:
15 - none
16 -- Hooks:
17 - none
18 -- Settings:
19 - none
21 -Targets:
23 -- `/review` picks a smart default:
24 - uncommitted changes, current branch against default branch, then `HEAD`.
25 -- `/review uncommitted` reviews staged, unstaged, and untracked changes.
26 -- `/review branch <base>` reviews the diff against a base branch.
27 -- `/review commit <sha>` reviews one commit.
28 -- `/review folder <path> [path...]` reviews paths as a snapshot.
29 -- `/review pr <number-or-url>` reviews a GitHub PR through `gh pr view` and `gh pr diff`.
31 -## Behavior
33 -`/review` sends a review prompt as the next user message.
34 -It does not checkout PRs or mutate branches.
36 -The prompt asks for prioritized findings, a verdict, and non-blocking human reviewer callouts.
37 -If `REVIEW_GUIDELINES.md` exists beside a project `.pi/` directory, its content is appended.

extensions/review/__tests__/harness.test.ts

Deleted
deleted file mode 100644
1 -import { afterEach, describe, expect, it } from "vitest";
2 -import { createTestSession, type TestSession } from "../../../test/harness";
3 -import reviewExtension, { __test } from "../index";
5 -let t: TestSession | undefined;
7 -afterEach(() => {
8 - t?.dispose();
9 - t = undefined;
10 -});
12 -describe("review extension", () => {
13 - it("loads in real Pi extension runtime", async () => {
14 - t = await createTestSession({ extensionFactories: [reviewExtension] });
16 - expect(t.session.extensionRunner.extensions).toHaveLength(1);
17 - });
19 - it("parses quoted extra review focus", () => {
20 - expect(
21 - __test.parseReviewArgs('branch trunk --extra "focus auth regressions"'),
22 - ).toMatchObject({
23 - target: { type: "branch", branch: "trunk" },
24 - extra: "focus auth regressions",
25 - });
26 - });
28 - it("parses direct review targets", () => {
29 - expect(__test.parseReviewArgs("uncommitted").target).toEqual({
30 - type: "uncommitted",
31 - });
32 - expect(__test.parseReviewArgs("folder src docs").target).toEqual({
33 - type: "folder",
34 - paths: ["src", "docs"],
35 - });
36 - expect(__test.parseReviewArgs("pr 123").target).toEqual({
37 - type: "pr",
38 - ref: "123",
39 - });
40 - });
41 -});

extensions/review/index.ts

Deleted
deleted file mode 100644
1 -import { promises as fs } from "node:fs";
2 -import path from "node:path";
3 -import type {
4 - ExtensionAPI,
5 - ExtensionCommandContext,
6 -} from "@earendil-works/pi-coding-agent";
8 -type ReviewTarget =
9 - | { type: "uncommitted" }
10 - | { type: "branch"; branch: string }
11 - | { type: "commit"; sha: string }
12 - | { type: "folder"; paths: string[] }
13 - | { type: "pr"; ref: string };
15 -type ParsedReviewArgs = {
16 - target: ReviewTarget | null;
17 - extra?: string;
18 - error?: string;
19 -};
21 -const REVIEW_RUBRIC = `# Review Guidelines
23 -You are acting as a code reviewer for a proposed code change.
25 -Flag only issues that are:
27 -1. introduced by the reviewed change
28 -2. concrete and actionable
29 -3. likely worth fixing if the author knew
30 -4. backed by code paths, not speculation
32 -Priority tags:
34 -- [P0] release blocker
35 -- [P1] urgent
36 -- [P2] normal defect
37 -- [P3] low-value cleanup
39 -Rules:
41 -- Findings must reference changed lines or reviewed paths.
42 -- Keep each finding to one short paragraph.
43 -- Ignore trivia unless it hides behavior.
44 -- Prefer fail-fast error handling over silent fallback.
45 -- Flag unparameterized SQL, unsafe redirects, local-network URL fetches, auth regressions, and destructive operations.
47 -Output:
49 -1. Findings with priority, path, line, and rationale.
50 -2. Overall verdict: "correct" or "needs attention".
51 -3. Human Reviewer Callouts (Non-Blocking): migrations, dependency/lockfile changes, auth/permission changes, public API/schema breaks, destructive operations; or "- (none)".`;
53 -function tokenizeArgs(input: string): string[] {
54 - const tokens: string[] = [];
55 - let current = "";
56 - let quote: "'" | '"' | undefined;
58 - for (let i = 0; i < input.length; i++) {
59 - const char = input[i];
60 - if (quote) {
61 - if (char === "\\" && i + 1 < input.length) {
62 - current += input[++i];
63 - continue;
64 - }
65 - if (char === quote) {
66 - quote = undefined;
67 - continue;
68 - }
69 - current += char;
70 - continue;
71 - }
72 - if (char === "'" || char === '"') {
73 - quote = char;
74 - continue;
75 - }
76 - if (/\s/.test(char)) {
77 - if (current) tokens.push(current);
78 - current = "";
79 - continue;
80 - }
81 - current += char;
82 - }
83 - if (current) tokens.push(current);
84 - return tokens;
87 -function parseReviewArgs(args: string): ParsedReviewArgs {
88 - const raw = tokenizeArgs(args.trim());
89 - const parts: string[] = [];
90 - let extra: string | undefined;
92 - for (let i = 0; i < raw.length; i++) {
93 - const token = raw[i];
94 - if (token === "--extra" || token === "-e") {
95 - extra = raw[++i];
96 - if (!extra)
97 - return { target: null, error: `Expected text after ${token}` };
98 - continue;
99 - }
100 - parts.push(token);
101 - }
103 - if (parts.length === 0) return { target: null, extra };
104 - const [kind, ...rest] = parts;
106 - if (kind === "uncommitted") return { target: { type: "uncommitted" }, extra };
107 - if (kind === "branch") {
108 - const branch = rest[0];
109 - return branch
110 - ? { target: { type: "branch", branch }, extra }
111 - : { target: null, error: "Usage: /review branch <base>" };
112 - }
113 - if (kind === "commit") {
114 - const sha = rest[0];
115 - return sha
116 - ? { target: { type: "commit", sha }, extra }
117 - : { target: null, error: "Usage: /review commit <sha>" };
118 - }
119 - if (kind === "folder") {
120 - return rest.length > 0
121 - ? { target: { type: "folder", paths: rest }, extra }
122 - : { target: null, error: "Usage: /review folder <path> [path...]" };
123 - }
124 - if (kind === "pr") {
125 - const ref = rest[0];
126 - return ref
127 - ? { target: { type: "pr", ref }, extra }
128 - : { target: null, error: "Usage: /review pr <number-or-url>" };
129 - }
131 - return { target: null, error: `Unknown review target: ${kind}` };
134 -async function execText(pi: ExtensionAPI, command: string, args: string[]) {
135 - const result = await pi.exec(command, args);
136 - return result.code === 0 ? result.stdout.trim() : "";
139 -async function currentBranch(pi: ExtensionAPI): Promise<string> {
140 - return await execText(pi, "git", ["branch", "--show-current"]);
143 -async function defaultBranch(pi: ExtensionAPI): Promise<string> {
144 - const remote = await execText(pi, "git", [
145 - "symbolic-ref",
146 - "refs/remotes/origin/HEAD",
147 - "--short",
148 - ]);
149 - if (remote) return remote.replace(/^origin\//, "");
150 - const branches = await execText(pi, "git", [
151 - "branch",
152 - "--format=%(refname:short)",
153 - ]);
154 - if (branches.split(/\r?\n/).includes("main")) return "main";
155 - if (branches.split(/\r?\n/).includes("master")) return "master";
156 - return "main";
159 -async function hasChanges(pi: ExtensionAPI): Promise<boolean> {
160 - return (await execText(pi, "git", ["status", "--porcelain"])).length > 0;
163 -async function mergeBase(pi: ExtensionAPI, branch: string): Promise<string> {
164 - const upstream = await execText(pi, "git", [
165 - "rev-parse",
166 - "--abbrev-ref",
167 - `${branch}@{upstream}`,
168 - ]);
169 - if (upstream) {
170 - const base = await execText(pi, "git", ["merge-base", "HEAD", upstream]);
171 - if (base) return base;
172 - }
173 - return await execText(pi, "git", ["merge-base", "HEAD", branch]);
176 -async function smartTarget(pi: ExtensionAPI): Promise<ReviewTarget> {
177 - if (await hasChanges(pi)) return { type: "uncommitted" };
178 - const current = await currentBranch(pi);
179 - const base = await defaultBranch(pi);
180 - if (current && current !== base) return { type: "branch", branch: base };
181 - return { type: "commit", sha: "HEAD" };
184 -async function loadProjectReviewGuidelines(cwd: string): Promise<string> {
185 - let dir = path.resolve(cwd);
186 - while (true) {
187 - const marker = path.join(dir, ".pi");
188 - const guidelines = path.join(dir, "REVIEW_GUIDELINES.md");
189 - const markerStat = await fs.stat(marker).catch(() => null);
190 - if (markerStat?.isDirectory()) {
191 - const text = await fs.readFile(guidelines, "utf8").catch(() => "");
192 - return text.trim();
193 - }
194 - const parent = path.dirname(dir);
195 - if (parent === dir) return "";
196 - dir = parent;
197 - }
200 -async function targetPrompt(
201 - pi: ExtensionAPI,
202 - target: ReviewTarget,
203 -): Promise<string> {
204 - switch (target.type) {
205 - case "uncommitted":
206 - return "Review staged, unstaged, and untracked working-tree changes. Use git status --porcelain, git diff, git diff --staged, and git ls-files --others --exclude-standard.";
207 - case "branch": {
208 - const base = await mergeBase(pi, target.branch);
209 - return base
210 - ? `Review changes against ${target.branch}. Use git diff ${base}.`
211 - : `Review changes against ${target.branch}. Find the merge base first, then inspect the diff.`;
212 - }
213 - case "commit":
214 - return `Review changes introduced by commit ${target.sha}. Use git show --stat --patch ${target.sha}.`;
215 - case "folder":
216 - return `Review this snapshot, not a diff: ${target.paths.join(", ")}. Read files directly under these paths.`;
217 - case "pr":
218 - return `Review GitHub PR ${target.ref}. Use gh pr view and gh pr diff. Do not checkout or mutate branches unless the user explicitly asks.`;
219 - }
222 -async function buildPrompt(
223 - pi: ExtensionAPI,
224 - ctx: ExtensionCommandContext,
225 - target: ReviewTarget,
226 - extra?: string,
227 -): Promise<string> {
228 - const guidelines = await loadProjectReviewGuidelines(ctx.cwd);
229 - return [
230 - REVIEW_RUBRIC,
231 - "---",
232 - await targetPrompt(pi, target),
233 - extra?.trim() ? `Extra review focus:\n${extra.trim()}` : "",
234 - guidelines ? `Project review guidelines:\n${guidelines}` : "",
235 - ]
236 - .filter(Boolean)
237 - .join("\n\n");
240 -function targetLabel(target: ReviewTarget): string {
241 - switch (target.type) {
242 - case "uncommitted":
243 - return "uncommitted changes";
244 - case "branch":
245 - return `branch diff against ${target.branch}`;
246 - case "commit":
247 - return `commit ${target.sha}`;
248 - case "folder":
249 - return `paths ${target.paths.join(", ")}`;
250 - case "pr":
251 - return `PR ${target.ref}`;
252 - }
255 -export const __test = { parseReviewArgs, tokenizeArgs, targetLabel };
257 -export default function reviewExtension(pi: ExtensionAPI) {
258 - pi.registerCommand("review", {
259 - description:
260 - "Ask the agent to review code. Usage: /review [uncommitted|branch <base>|commit <sha>|folder <path...>|pr <ref>] [--extra <focus>]",
261 - handler: async (args, ctx) => {
262 - await ctx.waitForIdle();
263 - const parsed = parseReviewArgs(args);
264 - if (parsed.error) {
265 - ctx.ui.notify(parsed.error, "error");
266 - return;
267 - }
268 - const target = parsed.target ?? (await smartTarget(pi));
269 - ctx.ui.notify(`Starting review: ${targetLabel(target)}`, "info");
270 - pi.sendUserMessage(await buildPrompt(pi, ctx, target, parsed.extra));
271 - },
272 - });

extensions/review/package.json

Deleted
deleted file mode 100644
1 -{
2 - "name": "@bugabinga/pi-ext-review",
3 - "private": true,
4 - "type": "module",
5 - "main": "index.ts",
6 - "license": "MIT",
7 - "description": "Agent code-review command for Pi.",
8 - "keywords": [
9 - "pi",
10 - "pi-extension"
11 - ],
12 - "peerDependencies": {
13 - "@earendil-works/pi-coding-agent": "*"
14 - },
15 - "devDependencies": {
16 - "@marcfargas/pi-test-harness": "^0.6.1",
17 - "vitest": "^4.1.9"
18 - },
19 - "scripts": {}
20 -}

extensions/shame/README.md

Added
new file mode 100644
1 +# shame
3 +Hostile agent code review for Pi.
5 +## Install / load
7 +Loaded through the root `pi-ext` package.
8 +See [root README](../../README.md).
10 +## Command
12 +```text
13 +/shame
14 +/shame @extensions/super
15 +/shame @src @test
16 +/shame #123
17 +/shame https://github.com/owner/repo/pull/123
18 +/shame trunk
19 +/shame a1b2c3d
20 +/shame --extra "focus on auth"
21 +```
23 +`/shame` infers paths, GitHub PRs, branches, and commits.
24 +With no target, it reviews uncommitted changes, the current branch against its default branch, or `HEAD`.
26 +The command sends a review prompt as the next user message.
27 +It does not checkout PRs or mutate branches.
29 +If `REVIEW_GUIDELINES.md` exists beside a project `.pi/` directory, its content is appended.

extensions/shame/__tests__/harness.test.ts

Added
new file mode 100644
1 +import { afterEach, describe, expect, it } from "vitest";
2 +import { createTestSession, type TestSession } from "../../../test/harness";
3 +import shameExtension, { __test } from "../index";
5 +let t: TestSession | undefined;
7 +afterEach(() => {
8 + t?.dispose();
9 + t = undefined;
10 +});
12 +describe("shame extension", () => {
13 + it("loads in real Pi extension runtime", async () => {
14 + t = await createTestSession({ extensionFactories: [shameExtension] });
16 + expect(t.session.extensionRunner.extensions).toHaveLength(1);
17 + });
19 + it("parses quoted extra review focus", () => {
20 + expect(
21 + __test.parseReviewArgs('branch trunk --extra "focus auth regressions"'),
22 + ).toMatchObject({
23 + target: { type: "branch", branch: "trunk" },
24 + extra: "focus auth regressions",
25 + });
26 + });
28 + it("parses direct review targets", () => {
29 + expect(__test.parseReviewArgs("uncommitted").target).toEqual({
30 + type: "uncommitted",
31 + });
32 + expect(__test.parseReviewArgs("folder src docs").target).toEqual({
33 + type: "folder",
34 + paths: ["src", "docs"],
35 + });
36 + expect(__test.parseReviewArgs("pr 123").target).toEqual({
37 + type: "pr",
38 + ref: "123",
39 + });
40 + });
41 +});

extensions/shame/index.ts

Added
new file mode 100644
1 +import { promises as fs } from "node:fs";
2 +import path from "node:path";
3 +import type {
4 + ExtensionAPI,
5 + ExtensionCommandContext,
6 +} from "@earendil-works/pi-coding-agent";
8 +type ReviewTarget =
9 + | { type: "uncommitted" }
10 + | { type: "branch"; branch: string }
11 + | { type: "commit"; sha: string }
12 + | { type: "folder"; paths: string[] }
13 + | { type: "pr"; ref: string };
15 +type ParsedReviewArgs = {
16 + target: ReviewTarget | null;
17 + extra?: string;
18 + error?: string;
19 +};
21 +const REVIEW_RUBRIC = `# Review Guidelines
23 +You are acting as a code reviewer for a proposed code change.
25 +Flag only issues that are:
27 +1. introduced by the reviewed change
28 +2. concrete and actionable
29 +3. likely worth fixing if the author knew
30 +4. backed by code paths, not speculation
32 +Priority tags:
34 +- [P0] release blocker
35 +- [P1] urgent
36 +- [P2] normal defect
37 +- [P3] low-value cleanup
39 +Rules:
41 +- Findings must reference changed lines or reviewed paths.
42 +- Keep each finding to one short paragraph.
43 +- Ignore trivia unless it hides behavior.
44 +- Prefer fail-fast error handling over silent fallback.
45 +- Flag unparameterized SQL, unsafe redirects, local-network URL fetches, auth regressions, and destructive operations.
47 +Output:
49 +1. Findings with priority, path, line, and rationale.
50 +2. Overall verdict: "correct" or "needs attention".
51 +3. Human Reviewer Callouts (Non-Blocking): migrations, dependency/lockfile changes, auth/permission changes, public API/schema breaks, destructive operations; or "- (none)".`;
53 +function tokenizeArgs(input: string): string[] {
54 + const tokens: string[] = [];
55 + let current = "";
56 + let quote: "'" | '"' | undefined;
58 + for (let i = 0; i < input.length; i++) {
59 + const char = input[i];
60 + if (quote) {
61 + if (char === "\\" && i + 1 < input.length) {
62 + current += input[++i];
63 + continue;
64 + }
65 + if (char === quote) {
66 + quote = undefined;
67 + continue;
68 + }
69 + current += char;
70 + continue;
71 + }
72 + if (char === "'" || char === '"') {
73 + quote = char;
74 + continue;
75 + }
76 + if (/\s/.test(char)) {
77 + if (current) tokens.push(current);
78 + current = "";
79 + continue;
80 + }
81 + current += char;
82 + }
83 + if (current) tokens.push(current);
84 + return tokens;
87 +function parseReviewArgs(args: string): ParsedReviewArgs {
88 + const raw = tokenizeArgs(args.trim());
89 + const parts: string[] = [];
90 + let extra: string | undefined;
92 + for (let i = 0; i < raw.length; i++) {
93 + const token = raw[i];
94 + if (token === "--extra" || token === "-e") {
95 + extra = raw[++i];
96 + if (!extra)
97 + return { target: null, error: `Expected text after ${token}` };
98 + continue;
99 + }
100 + parts.push(token);
103 + if (parts.length === 0) return { target: null, extra };
104 + const [kind, ...rest] = parts;
106 + if (kind === "uncommitted") return { target: { type: "uncommitted" }, extra };
107 + if (kind === "branch") {
108 + const branch = rest[0];
109 + return branch
110 + ? { target: { type: "branch", branch }, extra }
111 + : { target: null, error: "Usage: /review branch <base>" };
113 + if (kind === "commit") {
114 + const sha = rest[0];
115 + return sha
116 + ? { target: { type: "commit", sha }, extra }
117 + : { target: null, error: "Usage: /review commit <sha>" };
119 + if (kind === "folder") {
120 + return rest.length > 0
121 + ? { target: { type: "folder", paths: rest }, extra }
122 + : { target: null, error: "Usage: /review folder <path> [path...]" };
124 + if (kind === "pr") {
125 + const ref = rest[0];
126 + return ref
127 + ? { target: { type: "pr", ref }, extra }
128 + : { target: null, error: "Usage: /review pr <number-or-url>" };
131 + return { target: null, error: `Unknown review target: ${kind}` };
134 +async function execText(pi: ExtensionAPI, command: string, args: string[]) {
135 + const result = await pi.exec(command, args);
136 + return result.code === 0 ? result.stdout.trim() : "";
139 +async function currentBranch(pi: ExtensionAPI): Promise<string> {
140 + return await execText(pi, "git", ["branch", "--show-current"]);
143 +async function defaultBranch(pi: ExtensionAPI): Promise<string> {
144 + const remote = await execText(pi, "git", [
145 + "symbolic-ref",
146 + "refs/remotes/origin/HEAD",
147 + "--short",
148 + ]);
149 + if (remote) return remote.replace(/^origin\//, "");
150 + const branches = await execText(pi, "git", [
151 + "branch",
152 + "--format=%(refname:short)",
153 + ]);
154 + if (branches.split(/\r?\n/).includes("main")) return "main";
155 + if (branches.split(/\r?\n/).includes("master")) return "master";
156 + return "main";
159 +async function hasChanges(pi: ExtensionAPI): Promise<boolean> {
160 + return (await execText(pi, "git", ["status", "--porcelain"])).length > 0;
163 +async function mergeBase(pi: ExtensionAPI, branch: string): Promise<string> {
164 + const upstream = await execText(pi, "git", [
165 + "rev-parse",
166 + "--abbrev-ref",
167 + `${branch}@{upstream}`,
168 + ]);
169 + if (upstream) {
170 + const base = await execText(pi, "git", ["merge-base", "HEAD", upstream]);
171 + if (base) return base;
173 + return await execText(pi, "git", ["merge-base", "HEAD", branch]);
176 +async function smartTarget(pi: ExtensionAPI): Promise<ReviewTarget> {
177 + if (await hasChanges(pi)) return { type: "uncommitted" };
178 + const current = await currentBranch(pi);
179 + const base = await defaultBranch(pi);
180 + if (current && current !== base) return { type: "branch", branch: base };
181 + return { type: "commit", sha: "HEAD" };
184 +async function loadProjectReviewGuidelines(cwd: string): Promise<string> {
185 + let dir = path.resolve(cwd);
186 + while (true) {
187 + const marker = path.join(dir, ".pi");
188 + const guidelines = path.join(dir, "REVIEW_GUIDELINES.md");
189 + const markerStat = await fs.stat(marker).catch(() => null);
190 + if (markerStat?.isDirectory()) {
191 + const text = await fs.readFile(guidelines, "utf8").catch(() => "");
192 + return text.trim();
194 + const parent = path.dirname(dir);
195 + if (parent === dir) return "";
196 + dir = parent;
200 +async function targetPrompt(
201 + pi: ExtensionAPI,
202 + target: ReviewTarget,
203 +): Promise<string> {
204 + switch (target.type) {
205 + case "uncommitted":
206 + return "Review staged, unstaged, and untracked working-tree changes. Use git status --porcelain, git diff, git diff --staged, and git ls-files --others --exclude-standard.";
207 + case "branch": {
208 + const base = await mergeBase(pi, target.branch);
209 + return base
210 + ? `Review changes against ${target.branch}. Use git diff ${base}.`
211 + : `Review changes against ${target.branch}. Find the merge base first, then inspect the diff.`;
213 + case "commit":
214 + return `Review changes introduced by commit ${target.sha}. Use git show --stat --patch ${target.sha}.`;
215 + case "folder":
216 + return `Review this snapshot, not a diff: ${target.paths.join(", ")}. Read files directly under these paths.`;
217 + case "pr":
218 + return `Review GitHub PR ${target.ref}. Use gh pr view and gh pr diff. Do not checkout or mutate branches unless the user explicitly asks.`;
222 +async function buildPrompt(
223 + pi: ExtensionAPI,
224 + ctx: ExtensionCommandContext,
225 + target: ReviewTarget,
226 + extra?: string,
227 +): Promise<string> {
228 + const guidelines = await loadProjectReviewGuidelines(ctx.cwd);
229 + return [
230 + REVIEW_RUBRIC,
231 + "---",
232 + await targetPrompt(pi, target),
233 + extra?.trim() ? `Extra review focus:\n${extra.trim()}` : "",
234 + guidelines ? `Project review guidelines:\n${guidelines}` : "",
236 + .filter(Boolean)
237 + .join("\n\n");
240 +function targetLabel(target: ReviewTarget): string {
241 + switch (target.type) {
242 + case "uncommitted":
243 + return "uncommitted changes";
244 + case "branch":
245 + return `branch diff against ${target.branch}`;
246 + case "commit":
247 + return `commit ${target.sha}`;
248 + case "folder":
249 + return `paths ${target.paths.join(", ")}`;
250 + case "pr":
251 + return `PR ${target.ref}`;
255 +export const __test = { parseReviewArgs, tokenizeArgs, targetLabel };
257 +export default function shameExtension(pi: ExtensionAPI) {
258 + pi.registerCommand("shame", {
259 + description:
260 + "Shame code. Usage: /shame [@path ...|#pr|pr-url|git-ref] [--extra <focus>]",
261 + handler: async (args, ctx) => {
262 + await ctx.waitForIdle();
263 + const parsed = parseReviewArgs(args);
264 + if (parsed.error) {
265 + ctx.ui.notify(parsed.error, "error");
266 + return;
268 + const target = parsed.target ?? (await smartTarget(pi));
269 + ctx.ui.notify(`Starting review: ${targetLabel(target)}`, "info");
270 + pi.sendUserMessage(await buildPrompt(pi, ctx, target, parsed.extra));
271 + },
272 + });

extensions/shame/package.json

Added
new file mode 100644
1 +{
2 + "name": "@bugabinga/pi-ext-shame",
3 + "private": true,
4 + "type": "module",
5 + "main": "index.ts",
6 + "license": "MIT",
7 + "description": "Hostile agent code review for Pi.",
8 + "keywords": [
9 + "pi",
10 + "pi-extension"
11 + ],
12 + "peerDependencies": {
13 + "@earendil-works/pi-coding-agent": "*"
14 + },
15 + "devDependencies": {
16 + "@marcfargas/pi-test-harness": "^0.6.1",
17 + "vitest": "^4.1.9"
18 + },
19 + "scripts": {}

package-lock.json

Modified
31 31 "typebox": "*"
34 + "extensions/btw": {
35 + "name": "@bugabinga/pi-ext-btw",
36 + "license": "MIT",
37 + "devDependencies": {
38 + "@marcfargas/pi-test-harness": "^0.6.1",
39 + "vitest": "^4.1.9"
40 + },
41 + "peerDependencies": {
42 + "@earendil-works/pi-ai": "*",
43 + "@earendil-works/pi-coding-agent": "*",
44 + "@earendil-works/pi-tui": "*"
45 + }
46 + },
34 47 "extensions/builtin-tools": {
35 48 "name": "@bugabinga/pi-ext-builtin-tools",
36 49 "license": "MIT",
336 349 "@earendil-works/pi-coding-agent": "*"
339 - "extensions/review": {
340 - "name": "@bugabinga/pi-ext-review",
341 - "license": "MIT",
342 - "devDependencies": {
343 - "@marcfargas/pi-test-harness": "^0.6.1",
344 - "vitest": "^4.1.9"
345 - },
346 - "peerDependencies": {
347 - "@earendil-works/pi-coding-agent": "*"
349 - },
350 352 "extensions/rtk": {
351 353 "name": "@bugabinga/pi-ext-rtk",
352 354 "license": "MIT",
381 383 "@earendil-works/pi-coding-agent": "*"
386 + "extensions/shame": {
387 + "name": "@bugabinga/pi-ext-shame",
388 + "license": "MIT",
389 + "devDependencies": {
390 + "@marcfargas/pi-test-harness": "^0.6.1",
391 + "vitest": "^4.1.9"
392 + },
393 + "peerDependencies": {
394 + "@earendil-works/pi-coding-agent": "*"
396 + },
384 397 "extensions/split-fork": {
385 398 "name": "@bugabinga/pi-ext-split-fork",
386 399 "license": "MIT",
1233 1246 "resolved": "extensions/angel",
1234 1247 "link": true
1249 + "node_modules/@bugabinga/pi-ext-btw": {
1250 + "resolved": "extensions/btw",
1251 + "link": true
1252 + },
1236 1253 "node_modules/@bugabinga/pi-ext-builtin-tools": {
1237 1254 "resolved": "extensions/builtin-tools",
1238 1255 "link": true
1333 1350 "resolved": "extensions/quota",
1334 1351 "link": true
1336 - "node_modules/@bugabinga/pi-ext-review": {
1337 - "resolved": "extensions/review",
1338 - "link": true
1339 - },
1340 1353 "node_modules/@bugabinga/pi-ext-rtk": {
1341 1354 "resolved": "extensions/rtk",
1342 1355 "link": true
1349 1362 "resolved": "extensions/session-rename",
1350 1363 "link": true
1365 + "node_modules/@bugabinga/pi-ext-shame": {
1366 + "resolved": "extensions/shame",
1367 + "link": true
1368 + },
1352 1369 "node_modules/@bugabinga/pi-ext-split-fork": {
1353 1370 "resolved": "extensions/split-fork",
1354 1371 "link": true