@geminixiang/pi-simplify 0.0.1

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.
@@ -0,0 +1,53 @@
1
+ name: CI / Publish to npm
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ push:
7
+ branches: [main]
8
+ workflow_dispatch:
9
+
10
+ permissions:
11
+ id-token: write
12
+ contents: read
13
+
14
+ jobs:
15
+ ci:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - uses: actions/setup-node@v4
21
+ with:
22
+ node-version: "20"
23
+ registry-url: "https://registry.npmjs.org"
24
+
25
+ - name: Install dependencies
26
+ run: npm ci
27
+
28
+ - name: Type check
29
+ run: npx tsc --noEmit --skipLibCheck || echo "No TypeScript, skipping type check"
30
+
31
+ publish:
32
+ needs: ci
33
+ runs-on: ubuntu-latest
34
+ if: github.event_name == 'release'
35
+ steps:
36
+ - uses: actions/checkout@v4
37
+
38
+ - uses: actions/setup-node@v4
39
+ with:
40
+ node-version: "20"
41
+ registry-url: "https://registry.npmjs.org"
42
+
43
+ - name: Install dependencies
44
+ run: npm ci
45
+
46
+ - name: Publish to npm
47
+ run: |
48
+ VERSION=$(node -p "require('./package.json').version")
49
+ if [[ "$VERSION" == *-* ]]; then
50
+ npm publish --provenance --access public --tag beta
51
+ else
52
+ npm publish --provenance --access public
53
+ fi
package/index.ts ADDED
@@ -0,0 +1,89 @@
1
+ import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
2
+
3
+ const CUSTOM_TYPE = "simplify-context";
4
+ const DELIVERY_FOLLOW_UP = "followUp";
5
+ const NOTIFY_REVIEW_STARTED = "Simplify review started";
6
+ const NOTIFY_REVIEW_QUEUED = "Simplify review queued as a follow-up";
7
+
8
+ const SIMPLIFY_PROMPT = `# Simplify: Code Review and Cleanup
9
+
10
+ Review all changed files for reuse, quality, and efficiency. Fix any issues found.
11
+
12
+ ## Phase 1: Identify Changes
13
+
14
+ Run \`git diff\` (or \`git diff HEAD\` if there are staged changes) to see what changed. If there are no git changes, review the most recently modified files that the user mentioned or that you edited earlier in this conversation.
15
+
16
+ ## Phase 2: Launch Three Review SubAgents in Parallel
17
+
18
+ Use the Agent tool to launch all three agents concurrently in a single message. Pass each agent the full diff so it has the complete context.
19
+
20
+ ### SubAgent 1: Code Reuse Review
21
+
22
+ For each change:
23
+
24
+ 1. **Search for existing utilities and helpers** that could replace newly written code. Look for similar patterns elsewhere in the codebase — common locations are utility directories, shared modules, and files adjacent to the changed ones.
25
+ 2. **Flag any new function that duplicates existing functionality.** Suggest the existing function to use instead.
26
+ 3. **Flag any inline logic that could use an existing utility** — hand-rolled string manipulation, manual path handling, custom environment checks, ad-hoc type guards, and similar patterns are common candidates.
27
+
28
+ ### SubAgent 2: Code Quality Review
29
+
30
+ Review the same changes for hacky patterns:
31
+
32
+ 1. **Redundant state**: state that duplicates existing state, cached values that could be derived, observers/effects that could be direct calls
33
+ 2. **Parameter sprawl**: adding new parameters to a function instead of generalizing or restructuring existing ones
34
+ 3. **Copy-paste with slight variation**: near-duplicate code blocks that should be unified with a shared abstraction
35
+ 4. **Leaky abstractions**: exposing internal details that should be encapsulated, or breaking existing abstraction boundaries
36
+ 5. **Stringly-typed code**: using raw strings where constants, enums (string unions), or branded types already exist in the codebase
37
+ 6. **Unnecessary JSX nesting**: wrapper Boxes/elements that add no layout value — check if inner component props (flexShrink, alignItems, etc.) already provide the needed behavior
38
+ 7. **Unnecessary comments**: comments explaining WHAT the code does (well-named identifiers already do that), narrating the change, or referencing the task/caller — delete; keep only non-obvious WHY (hidden constraints, subtle invariants, workarounds)
39
+
40
+ ### SubAgent 3: Efficiency Review
41
+
42
+ Review the same changes for efficiency:
43
+
44
+ 1. **Unnecessary work**: redundant computations, repeated file reads, duplicate network/API calls, N+1 patterns
45
+ 2. **Missed concurrency**: independent operations run sequentially when they could run in parallel
46
+ 3. **Hot-path bloat**: new blocking work added to startup or per-request/per-render hot paths
47
+ 4. **Recurring no-op updates**: state/store updates inside polling loops, intervals, or event handlers that fire unconditionally — add a change-detection guard so downstream consumers aren't notified when nothing changed. Also: if a wrapper function takes an updater/reducer callback, verify it honors same-reference returns (or whatever the "no change" signal is) — otherwise callers' early-return no-ops are silently defeated
48
+ 5. **Unnecessary existence checks**: pre-checking file/resource existence before operating (TOCTOU anti-pattern) — operate directly and handle the error
49
+ 6. **Memory**: unbounded data structures, missing cleanup, event listener leaks
50
+ 7. **Overly broad operations**: reading entire files when only a portion is needed, loading all items when filtering for one
51
+
52
+ ## Phase 3: Fix Issues
53
+
54
+ Wait for all three agents to complete. Aggregate their findings and fix each issue directly. If a finding is a false positive or not worth addressing, note it and move on — do not argue with the finding, just skip it.
55
+
56
+ When done, briefly summarize what was fixed (or confirm the code was already clean).
57
+ `;
58
+
59
+ function buildPrompt(args: string): string {
60
+ const focus = args.trim();
61
+ if (!focus) return SIMPLIFY_PROMPT;
62
+ return `${SIMPLIFY_PROMPT}\n\n## Additional Focus\n\n${focus}`;
63
+ }
64
+
65
+ function runSimplify(pi: ExtensionAPI, ctx: ExtensionCommandContext, args: string): void {
66
+ const message = {
67
+ customType: CUSTOM_TYPE,
68
+ content: buildPrompt(args),
69
+ display: false,
70
+ };
71
+
72
+ if (ctx.isIdle()) {
73
+ pi.sendMessage(message, { triggerTurn: true });
74
+ ctx.ui.notify(NOTIFY_REVIEW_STARTED, "info");
75
+ return;
76
+ }
77
+
78
+ pi.sendMessage(message, { deliverAs: DELIVERY_FOLLOW_UP, triggerTurn: true });
79
+ ctx.ui.notify(NOTIFY_REVIEW_QUEUED, "info");
80
+ }
81
+
82
+ export default function simplifyExtension(pi: ExtensionAPI): void {
83
+ pi.registerCommand("simplify", {
84
+ description: "Review changed code for reuse, quality, and efficiency, then fix issues",
85
+ handler: async (args: string, ctx: ExtensionCommandContext) => {
86
+ runSimplify(pi, ctx, args);
87
+ },
88
+ });
89
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@geminixiang/pi-simplify",
3
+ "version": "0.0.1",
4
+ "description": "Simplify: code reuse, quality, and efficiency review for pi coding agent",
5
+ "main": "index.ts",
6
+ "keywords": [
7
+ "pi-package"
8
+ ],
9
+ "author": "",
10
+ "license": "MIT",
11
+ "pi": {
12
+ "extensions": [
13
+ "./index.ts"
14
+ ]
15
+ },
16
+ "dependencies": {
17
+ "@mariozechner/pi-coding-agent": "^0.65.2"
18
+ }
19
+ }