@nielpattin/pi-simplify 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## [0.2.1](https://github.com/MattDevy/pi-extensions/compare/pi-simplify-v0.2.0...pi-simplify-v0.2.1) (2026-05-14)
4
+
5
+ ### Bug Fixes
6
+
7
+ - **deps:** Migrate to [@earendil-works](https://github.com/earendil-works) namespace ([7124e84](https://github.com/MattDevy/pi-extensions/commit/7124e846c29d92f605ceaed1c5581910a91d8d3d))
8
+
9
+ ## [0.2.0](https://github.com/MattDevy/pi-extensions/compare/pi-simplify-v0.1.0...pi-simplify-v0.2.0) (2026-04-10)
10
+
11
+ ### Features
12
+
13
+ - Add pi-simplify code review extension ([#94](https://github.com/MattDevy/pi-extensions/issues/94)) ([aded3cd](https://github.com/MattDevy/pi-extensions/commit/aded3cd6ea928e93b50e787b4c6443bc2d3f8684))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nielpattin/pi-simplify",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "A Pi extension that reviews recently changed code for clarity, consistency, and maintainability.",
5
5
  "keywords": [
6
6
  "ai",
@@ -31,9 +31,8 @@
31
31
  },
32
32
  "files": [
33
33
  "dist",
34
- "src",
35
- "!src/**/*.test.ts",
36
- "README.md"
34
+ "README.md",
35
+ "CHANGELOG.md"
37
36
  ],
38
37
  "type": "module",
39
38
  "main": "./dist/index.js",
@@ -49,6 +48,10 @@
49
48
  "prepack": "node -e \"const fs=require('node:fs');if(!fs.existsSync('dist')){console.error('Error: dist/ missing. Run npm run build first.');process.exit(1);}\""
50
49
  },
51
50
  "devDependencies": {
51
+ "@earendil-works/pi-ai": "^0.74.1",
52
+ "@earendil-works/pi-coding-agent": "^0.74.1",
53
+ "@earendil-works/pi-tui": "^0.74.1",
54
+ "@sinclair/typebox": "^0.34.49",
52
55
  "@types/node": "^25.7.0",
53
56
  "@typescript-eslint/eslint-plugin": "^8.0.0",
54
57
  "@typescript-eslint/parser": "^8.0.0",
@@ -67,7 +70,7 @@
67
70
  },
68
71
  "pi": {
69
72
  "extensions": [
70
- "src/index.ts"
73
+ "./dist/index.js"
71
74
  ]
72
75
  }
73
76
  }
package/src/git-diff.ts DELETED
@@ -1,59 +0,0 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import type { ChangedFile, SimplifyOptions } from "./types.js";
3
-
4
- const STATUS_MAP: Record<string, ChangedFile["status"]> = {
5
- M: "modified",
6
- A: "added",
7
- R: "renamed",
8
- C: "copied",
9
- };
10
-
11
- function parseDiffOutput(stdout: string): ChangedFile[] {
12
- const files: ChangedFile[] = [];
13
-
14
- for (const line of stdout.split("\n")) {
15
- if (!line.trim()) continue;
16
-
17
- const parts = line.split("\t");
18
- const statusCode = parts[0]?.[0];
19
- if (!statusCode) continue;
20
-
21
- const status = STATUS_MAP[statusCode];
22
- if (!status) continue;
23
-
24
- // Renamed (R100\told\tnew) and copied (C100\told\tnew) have two paths; use the new one.
25
- const path = status === "renamed" || status === "copied" ? parts[2] : parts[1];
26
- if (path) {
27
- files.push({ path, status });
28
- }
29
- }
30
-
31
- return files;
32
- }
33
-
34
- export async function getChangedFiles(pi: ExtensionAPI, cwd: string, options: SimplifyOptions): Promise<ChangedFile[]> {
35
- if (options.files.length > 0) {
36
- return options.files.map((path) => ({ path, status: "modified" as const }));
37
- }
38
-
39
- const args = ["diff", "--name-status"];
40
- if (options.staged) {
41
- args.push("--cached");
42
- } else {
43
- args.push(options.ref);
44
- }
45
-
46
- const result = await pi.exec("git", args, { cwd });
47
- if (result.code === 0) {
48
- const files = parseDiffOutput(result.stdout);
49
- if (files.length > 0) return files;
50
- }
51
-
52
- // Fallback: diff against previous commit
53
- const fallback = await pi.exec("git", ["diff", "--name-status", "HEAD~1"], { cwd });
54
- if (fallback.code === 0) {
55
- return parseDiffOutput(fallback.stdout);
56
- }
57
-
58
- return [];
59
- }
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
- import { handleSimplifyCommand, COMMAND_NAME } from "./simplify-command.js";
3
-
4
- export default function (pi: ExtensionAPI): void {
5
- pi.registerCommand(COMMAND_NAME, {
6
- description: "Review recently changed files for clarity, consistency, and maintainability improvements",
7
- handler: (args: string, ctx: ExtensionCommandContext) => handleSimplifyCommand(args, ctx, pi),
8
- });
9
- }
@@ -1,29 +0,0 @@
1
- import type { ChangedFile } from "./types.js";
2
-
3
- export function buildSimplifyPrompt(files: readonly ChangedFile[]): string {
4
- const fileList = files.map((f) => `- ${f.path} (${f.status})`).join("\n");
5
-
6
- return `Review the following recently changed files and apply simplification improvements.
7
-
8
- ## Principles
9
-
10
- - **Preserve functionality**: Never change what the code does. All existing tests must continue to pass.
11
- - **Apply project standards**: Follow any conventions from CLAUDE.md or AGENTS.md in this project.
12
- - **Enhance clarity**: Reduce unnecessary complexity and nesting, eliminate redundant code and abstractions, improve variable and function names, consolidate related logic, remove unnecessary comments that describe obvious code. Avoid nested ternary operators: prefer switch statements or if/else chains for multiple conditions.
13
- - **Maintain balance**: Do not over-simplify. Avoid overly clever solutions that are hard to understand. Do not combine too many concerns into single functions. Do not remove helpful abstractions. Prioritize readability over fewer lines.
14
-
15
- ## Scope
16
-
17
- Only review and modify these files:
18
- ${fileList}
19
-
20
- ## Process
21
-
22
- 1. Read each file listed above
23
- 2. Identify concrete improvements (dead code, unclear names, redundant logic, inconsistent patterns)
24
- 3. Apply changes one file at a time
25
- 4. After all changes, run existing tests to verify nothing is broken
26
- 5. Summarize what you changed and why
27
-
28
- Do NOT add new features, change public APIs, or refactor code outside the listed files.`;
29
- }
@@ -1,42 +0,0 @@
1
- import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
- import { getChangedFiles } from "./git-diff.js";
3
- import { buildSimplifyPrompt } from "./prompt-builder.js";
4
- import type { SimplifyOptions } from "./types.js";
5
-
6
- export const COMMAND_NAME = "simplify";
7
-
8
- export function parseArgs(args: string): SimplifyOptions {
9
- const tokens = args.trim().split(/\s+/).filter(Boolean);
10
- const files: string[] = [];
11
- let ref = "HEAD";
12
- let staged = false;
13
-
14
- for (const token of tokens) {
15
- if (token === "--staged") {
16
- staged = true;
17
- } else if (token.startsWith("--ref=")) {
18
- ref = token.slice("--ref=".length);
19
- } else {
20
- files.push(token);
21
- }
22
- }
23
-
24
- return { files, ref, staged };
25
- }
26
-
27
- export async function handleSimplifyCommand(
28
- args: string,
29
- ctx: ExtensionCommandContext,
30
- pi: ExtensionAPI,
31
- ): Promise<void> {
32
- const options = parseArgs(args);
33
- const files = await getChangedFiles(pi, ctx.cwd, options);
34
-
35
- if (files.length === 0) {
36
- ctx.ui.notify("No changed files found. Specify file paths or make some changes first.", "info");
37
- return;
38
- }
39
-
40
- const prompt = buildSimplifyPrompt(files);
41
- pi.sendUserMessage(prompt, { deliverAs: "followUp" });
42
- }
package/src/types.ts DELETED
@@ -1,10 +0,0 @@
1
- export interface ChangedFile {
2
- readonly path: string;
3
- readonly status: "modified" | "added" | "renamed" | "copied";
4
- }
5
-
6
- export interface SimplifyOptions {
7
- readonly files: readonly string[];
8
- readonly ref: string;
9
- readonly staged: boolean;
10
- }