@lebronj/pi-suite 0.1.0
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/LICENSE +21 -0
- package/README.md +86 -0
- package/extensions/pet.ts +1033 -0
- package/extensions/prompt-url-widget.ts +158 -0
- package/extensions/redraws.ts +24 -0
- package/extensions/snake.ts +343 -0
- package/extensions/tps.ts +47 -0
- package/package.json +69 -0
- package/prompts/cl.md +54 -0
- package/prompts/is.md +25 -0
- package/prompts/pr.md +37 -0
- package/prompts/wr.md +35 -0
- package/scripts/bootstrap.sh +95 -0
- package/skills/add-llm-provider.md +57 -0
- package/skills/image-to-editable-ppt-slide/SKILL.md +113 -0
- package/skills/image-to-editable-ppt-slide/scripts/generate_spec_template.py +91 -0
- package/skills/image-to-editable-ppt-slide/scripts/pptx_rebuilder.py +181 -0
- package/skills/leetcode-array/SKILL.md +40 -0
- package/skills/leetcode-array/problems/best_time_to_buy_and_sell_stock.py +19 -0
- package/skills/leetcode-array/problems/product_of_array_except_self.py +22 -0
- package/skills/leetcode-array/problems/two_sum.py +19 -0
- package/skills/pi-skill/SKILL.md +154 -0
- package/skills/weather.md +49 -0
- package/vendor/pi-memory/LICENSE +21 -0
- package/vendor/pi-memory/README.md +223 -0
- package/vendor/pi-memory/index.ts +2367 -0
- package/vendor/pi-memory/package.json +68 -0
- package/vendor/pi-memory/scripts/postinstall.cjs +44 -0
- package/vendor/pi-memory/src/cli.ts +79 -0
- package/vendor/pi-memory/src/curator-core/audit.ts +45 -0
- package/vendor/pi-memory/src/curator-core/curate.ts +90 -0
- package/vendor/pi-memory/src/curator-core/metadata.ts +55 -0
- package/vendor/pi-memory/src/curator-core/patch.ts +24 -0
- package/vendor/pi-memory/src/curator-core/policy.ts +77 -0
- package/vendor/pi-memory/src/curator-store/file-store.ts +51 -0
- package/vendor/pi-memory/src/curator-store/types.ts +21 -0
- package/vendor/pi-memory/src/index.ts +35 -0
- package/vendor/pi-memory/src/learning/candidates.ts +205 -0
- package/vendor/pi-memory/src/learning/memory.ts +144 -0
- package/vendor/pi-memory/src/learning/skills.ts +200 -0
- package/vendor/pi-memory/src/service-controller.ts +248 -0
- package/vendor/pi-memory/test/curate.test.ts +68 -0
- package/vendor/pi-memory/test/learning-candidates.test.ts +107 -0
- package/vendor/pi-memory/test/memory-promotions.test.ts +44 -0
- package/vendor/pi-memory/test/metadata.test.ts +17 -0
- package/vendor/pi-memory/test/skill-drafts.test.ts +57 -0
- package/vendor/pi-memory/test/transition-handoff.test.ts +86 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { DynamicBorder, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Container, Text } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
const PR_PROMPT_PATTERN = /^\s*You are given one or more GitHub PR URLs:\s*(\S+)/im;
|
|
5
|
+
const ISSUE_PROMPT_PATTERN = /^\s*Analyze GitHub issue\(s\):\s*(\S+)/im;
|
|
6
|
+
|
|
7
|
+
type PromptMatch = {
|
|
8
|
+
kind: "pr" | "issue";
|
|
9
|
+
url: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type GhMetadata = {
|
|
13
|
+
title?: string;
|
|
14
|
+
author?: {
|
|
15
|
+
login?: string;
|
|
16
|
+
name?: string | null;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function extractPromptMatch(prompt: string): PromptMatch | undefined {
|
|
21
|
+
const prMatch = prompt.match(PR_PROMPT_PATTERN);
|
|
22
|
+
if (prMatch?.[1]) {
|
|
23
|
+
return { kind: "pr", url: prMatch[1].trim() };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const issueMatch = prompt.match(ISSUE_PROMPT_PATTERN);
|
|
27
|
+
if (issueMatch?.[1]) {
|
|
28
|
+
return { kind: "issue", url: issueMatch[1].trim() };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function fetchGhMetadata(
|
|
35
|
+
pi: ExtensionAPI,
|
|
36
|
+
kind: PromptMatch["kind"],
|
|
37
|
+
url: string,
|
|
38
|
+
): Promise<GhMetadata | undefined> {
|
|
39
|
+
const args =
|
|
40
|
+
kind === "pr" ? ["pr", "view", url, "--json", "title,author"] : ["issue", "view", url, "--json", "title,author"];
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const result = await pi.exec("gh", args);
|
|
44
|
+
if (result.code !== 0 || !result.stdout) return undefined;
|
|
45
|
+
return JSON.parse(result.stdout) as GhMetadata;
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatAuthor(author?: GhMetadata["author"]): string | undefined {
|
|
52
|
+
if (!author) return undefined;
|
|
53
|
+
const name = author.name?.trim();
|
|
54
|
+
const login = author.login?.trim();
|
|
55
|
+
if (name && login) return `${name} (@${login})`;
|
|
56
|
+
if (login) return `@${login}`;
|
|
57
|
+
if (name) return name;
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default function promptUrlWidgetExtension(pi: ExtensionAPI) {
|
|
62
|
+
const setWidget = (ctx: ExtensionContext, match: PromptMatch, title?: string, authorText?: string) => {
|
|
63
|
+
ctx.ui.setWidget("prompt-url", (_tui, thm) => {
|
|
64
|
+
const titleText = title ? thm.fg("accent", title) : thm.fg("accent", match.url);
|
|
65
|
+
const authorLine = authorText ? thm.fg("muted", authorText) : undefined;
|
|
66
|
+
const urlLine = thm.fg("dim", match.url);
|
|
67
|
+
|
|
68
|
+
const lines = [titleText];
|
|
69
|
+
if (authorLine) lines.push(authorLine);
|
|
70
|
+
lines.push(urlLine);
|
|
71
|
+
|
|
72
|
+
const container = new Container();
|
|
73
|
+
container.addChild(new DynamicBorder((s: string) => thm.fg("muted", s)));
|
|
74
|
+
container.addChild(new Text(lines.join("\n"), 1, 0));
|
|
75
|
+
return container;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const applySessionName = (ctx: ExtensionContext, match: PromptMatch, title?: string) => {
|
|
80
|
+
const label = match.kind === "pr" ? "PR" : "Issue";
|
|
81
|
+
const trimmedTitle = title?.trim();
|
|
82
|
+
const fallbackName = `${label}: ${match.url}`;
|
|
83
|
+
const desiredName = trimmedTitle ? `${label}: ${trimmedTitle} (${match.url})` : fallbackName;
|
|
84
|
+
const currentName = pi.getSessionName()?.trim();
|
|
85
|
+
if (!currentName) {
|
|
86
|
+
pi.setSessionName(desiredName);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (currentName === match.url || currentName === fallbackName) {
|
|
90
|
+
pi.setSessionName(desiredName);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
95
|
+
if (!ctx.hasUI) return;
|
|
96
|
+
const match = extractPromptMatch(event.prompt);
|
|
97
|
+
if (!match) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setWidget(ctx, match);
|
|
102
|
+
applySessionName(ctx, match);
|
|
103
|
+
void fetchGhMetadata(pi, match.kind, match.url).then((meta) => {
|
|
104
|
+
const title = meta?.title?.trim();
|
|
105
|
+
const authorText = formatAuthor(meta?.author);
|
|
106
|
+
setWidget(ctx, match, title, authorText);
|
|
107
|
+
applySessionName(ctx, match, title);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
pi.on("session_switch", async (_event, ctx) => {
|
|
112
|
+
rebuildFromSession(ctx);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const getUserText = (content: string | { type: string; text?: string }[] | undefined): string => {
|
|
116
|
+
if (!content) return "";
|
|
117
|
+
if (typeof content === "string") return content;
|
|
118
|
+
return (
|
|
119
|
+
content
|
|
120
|
+
.filter((block): block is { type: "text"; text: string } => block.type === "text")
|
|
121
|
+
.map((block) => block.text)
|
|
122
|
+
.join("\n") ?? ""
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const rebuildFromSession = (ctx: ExtensionContext) => {
|
|
127
|
+
if (!ctx.hasUI) return;
|
|
128
|
+
|
|
129
|
+
const entries = ctx.sessionManager.getEntries();
|
|
130
|
+
const lastMatch = [...entries].reverse().find((entry) => {
|
|
131
|
+
if (entry.type !== "message" || entry.message.role !== "user") return false;
|
|
132
|
+
const text = getUserText(entry.message.content);
|
|
133
|
+
return !!extractPromptMatch(text);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const content =
|
|
137
|
+
lastMatch?.type === "message" && lastMatch.message.role === "user" ? lastMatch.message.content : undefined;
|
|
138
|
+
const text = getUserText(content);
|
|
139
|
+
const match = text ? extractPromptMatch(text) : undefined;
|
|
140
|
+
if (!match) {
|
|
141
|
+
ctx.ui.setWidget("prompt-url", undefined);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setWidget(ctx, match);
|
|
146
|
+
applySessionName(ctx, match);
|
|
147
|
+
void fetchGhMetadata(pi, match.kind, match.url).then((meta) => {
|
|
148
|
+
const title = meta?.title?.trim();
|
|
149
|
+
const authorText = formatAuthor(meta?.author);
|
|
150
|
+
setWidget(ctx, match, title, authorText);
|
|
151
|
+
applySessionName(ctx, match, title);
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
156
|
+
rebuildFromSession(ctx);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redraws Extension
|
|
3
|
+
*
|
|
4
|
+
* Exposes /tui to show TUI redraw stats.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
9
|
+
|
|
10
|
+
export default function (pi: ExtensionAPI) {
|
|
11
|
+
pi.registerCommand("tui", {
|
|
12
|
+
description: "Show TUI stats",
|
|
13
|
+
handler: async (_args, ctx) => {
|
|
14
|
+
if (!ctx.hasUI) return;
|
|
15
|
+
let redraws = 0;
|
|
16
|
+
await ctx.ui.custom<void>((tui, _theme, _keybindings, done) => {
|
|
17
|
+
redraws = tui.fullRedraws;
|
|
18
|
+
done(undefined);
|
|
19
|
+
return new Text("", 0, 0);
|
|
20
|
+
});
|
|
21
|
+
ctx.ui.notify(`TUI full redraws: ${redraws}`, "info");
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snake game extension - play snake with /snake command
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { matchesKey, visibleWidth } from "@earendil-works/pi-tui";
|
|
7
|
+
|
|
8
|
+
const GAME_WIDTH = 40;
|
|
9
|
+
const GAME_HEIGHT = 15;
|
|
10
|
+
const TICK_MS = 100;
|
|
11
|
+
|
|
12
|
+
type Direction = "up" | "down" | "left" | "right";
|
|
13
|
+
type Point = { x: number; y: number };
|
|
14
|
+
|
|
15
|
+
interface GameState {
|
|
16
|
+
snake: Point[];
|
|
17
|
+
food: Point;
|
|
18
|
+
direction: Direction;
|
|
19
|
+
nextDirection: Direction;
|
|
20
|
+
score: number;
|
|
21
|
+
gameOver: boolean;
|
|
22
|
+
highScore: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createInitialState(): GameState {
|
|
26
|
+
const startX = Math.floor(GAME_WIDTH / 2);
|
|
27
|
+
const startY = Math.floor(GAME_HEIGHT / 2);
|
|
28
|
+
return {
|
|
29
|
+
snake: [
|
|
30
|
+
{ x: startX, y: startY },
|
|
31
|
+
{ x: startX - 1, y: startY },
|
|
32
|
+
{ x: startX - 2, y: startY },
|
|
33
|
+
],
|
|
34
|
+
food: spawnFood([{ x: startX, y: startY }]),
|
|
35
|
+
direction: "right",
|
|
36
|
+
nextDirection: "right",
|
|
37
|
+
score: 0,
|
|
38
|
+
gameOver: false,
|
|
39
|
+
highScore: 0,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function spawnFood(snake: Point[]): Point {
|
|
44
|
+
let food: Point;
|
|
45
|
+
do {
|
|
46
|
+
food = {
|
|
47
|
+
x: Math.floor(Math.random() * GAME_WIDTH),
|
|
48
|
+
y: Math.floor(Math.random() * GAME_HEIGHT),
|
|
49
|
+
};
|
|
50
|
+
} while (snake.some((s) => s.x === food.x && s.y === food.y));
|
|
51
|
+
return food;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class SnakeComponent {
|
|
55
|
+
private state: GameState;
|
|
56
|
+
private interval: ReturnType<typeof setInterval> | null = null;
|
|
57
|
+
private onClose: () => void;
|
|
58
|
+
private onSave: (state: GameState | null) => void;
|
|
59
|
+
private tui: { requestRender: () => void };
|
|
60
|
+
private cachedLines: string[] = [];
|
|
61
|
+
private cachedWidth = 0;
|
|
62
|
+
private version = 0;
|
|
63
|
+
private cachedVersion = -1;
|
|
64
|
+
private paused: boolean;
|
|
65
|
+
|
|
66
|
+
constructor(
|
|
67
|
+
tui: { requestRender: () => void },
|
|
68
|
+
onClose: () => void,
|
|
69
|
+
onSave: (state: GameState | null) => void,
|
|
70
|
+
savedState?: GameState,
|
|
71
|
+
) {
|
|
72
|
+
this.tui = tui;
|
|
73
|
+
if (savedState && !savedState.gameOver) {
|
|
74
|
+
// Resume from saved state, start paused
|
|
75
|
+
this.state = savedState;
|
|
76
|
+
this.paused = true;
|
|
77
|
+
} else {
|
|
78
|
+
// New game or saved game was over
|
|
79
|
+
this.state = createInitialState();
|
|
80
|
+
if (savedState) {
|
|
81
|
+
this.state.highScore = savedState.highScore;
|
|
82
|
+
}
|
|
83
|
+
this.paused = false;
|
|
84
|
+
this.startGame();
|
|
85
|
+
}
|
|
86
|
+
this.onClose = onClose;
|
|
87
|
+
this.onSave = onSave;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private startGame(): void {
|
|
91
|
+
this.interval = setInterval(() => {
|
|
92
|
+
if (!this.state.gameOver) {
|
|
93
|
+
this.tick();
|
|
94
|
+
this.version++;
|
|
95
|
+
this.tui.requestRender();
|
|
96
|
+
}
|
|
97
|
+
}, TICK_MS);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private tick(): void {
|
|
101
|
+
// Apply queued direction change
|
|
102
|
+
this.state.direction = this.state.nextDirection;
|
|
103
|
+
|
|
104
|
+
// Calculate new head position
|
|
105
|
+
const head = this.state.snake[0];
|
|
106
|
+
let newHead: Point;
|
|
107
|
+
|
|
108
|
+
switch (this.state.direction) {
|
|
109
|
+
case "up":
|
|
110
|
+
newHead = { x: head.x, y: head.y - 1 };
|
|
111
|
+
break;
|
|
112
|
+
case "down":
|
|
113
|
+
newHead = { x: head.x, y: head.y + 1 };
|
|
114
|
+
break;
|
|
115
|
+
case "left":
|
|
116
|
+
newHead = { x: head.x - 1, y: head.y };
|
|
117
|
+
break;
|
|
118
|
+
case "right":
|
|
119
|
+
newHead = { x: head.x + 1, y: head.y };
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Check wall collision
|
|
124
|
+
if (newHead.x < 0 || newHead.x >= GAME_WIDTH || newHead.y < 0 || newHead.y >= GAME_HEIGHT) {
|
|
125
|
+
this.state.gameOver = true;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Check self collision
|
|
130
|
+
if (this.state.snake.some((s) => s.x === newHead.x && s.y === newHead.y)) {
|
|
131
|
+
this.state.gameOver = true;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Move snake
|
|
136
|
+
this.state.snake.unshift(newHead);
|
|
137
|
+
|
|
138
|
+
// Check food collision
|
|
139
|
+
if (newHead.x === this.state.food.x && newHead.y === this.state.food.y) {
|
|
140
|
+
this.state.score += 10;
|
|
141
|
+
if (this.state.score > this.state.highScore) {
|
|
142
|
+
this.state.highScore = this.state.score;
|
|
143
|
+
}
|
|
144
|
+
this.state.food = spawnFood(this.state.snake);
|
|
145
|
+
} else {
|
|
146
|
+
this.state.snake.pop();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
handleInput(data: string): void {
|
|
151
|
+
// If paused (resuming), wait for any key
|
|
152
|
+
if (this.paused) {
|
|
153
|
+
if (matchesKey(data, "escape") || data === "q" || data === "Q") {
|
|
154
|
+
// Quit without clearing save
|
|
155
|
+
this.dispose();
|
|
156
|
+
this.onClose();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// Any other key resumes
|
|
160
|
+
this.paused = false;
|
|
161
|
+
this.startGame();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ESC to pause and save
|
|
166
|
+
if (matchesKey(data, "escape")) {
|
|
167
|
+
this.dispose();
|
|
168
|
+
this.onSave(this.state);
|
|
169
|
+
this.onClose();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Q to quit without saving (clears saved state)
|
|
174
|
+
if (data === "q" || data === "Q") {
|
|
175
|
+
this.dispose();
|
|
176
|
+
this.onSave(null); // Clear saved state
|
|
177
|
+
this.onClose();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Arrow keys or WASD
|
|
182
|
+
if (matchesKey(data, "up") || data === "w" || data === "W") {
|
|
183
|
+
if (this.state.direction !== "down") this.state.nextDirection = "up";
|
|
184
|
+
} else if (matchesKey(data, "down") || data === "s" || data === "S") {
|
|
185
|
+
if (this.state.direction !== "up") this.state.nextDirection = "down";
|
|
186
|
+
} else if (matchesKey(data, "right") || data === "d" || data === "D") {
|
|
187
|
+
if (this.state.direction !== "left") this.state.nextDirection = "right";
|
|
188
|
+
} else if (matchesKey(data, "left") || data === "a" || data === "A") {
|
|
189
|
+
if (this.state.direction !== "right") this.state.nextDirection = "left";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Restart on game over
|
|
193
|
+
if (this.state.gameOver && (data === "r" || data === "R" || data === " ")) {
|
|
194
|
+
const highScore = this.state.highScore;
|
|
195
|
+
this.state = createInitialState();
|
|
196
|
+
this.state.highScore = highScore;
|
|
197
|
+
this.onSave(null); // Clear saved state on restart
|
|
198
|
+
this.version++;
|
|
199
|
+
this.tui.requestRender();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
invalidate(): void {
|
|
204
|
+
this.cachedWidth = 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
render(width: number): string[] {
|
|
208
|
+
if (width === this.cachedWidth && this.cachedVersion === this.version) {
|
|
209
|
+
return this.cachedLines;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const lines: string[] = [];
|
|
213
|
+
|
|
214
|
+
// Each game cell is 2 chars wide to appear square (terminal cells are ~2:1 aspect)
|
|
215
|
+
const cellWidth = 2;
|
|
216
|
+
const effectiveWidth = Math.min(GAME_WIDTH, Math.floor((width - 4) / cellWidth));
|
|
217
|
+
const effectiveHeight = GAME_HEIGHT;
|
|
218
|
+
|
|
219
|
+
// Colors
|
|
220
|
+
const dim = (s: string) => `\x1b[2m${s}\x1b[22m`;
|
|
221
|
+
const green = (s: string) => `\x1b[32m${s}\x1b[0m`;
|
|
222
|
+
const red = (s: string) => `\x1b[31m${s}\x1b[0m`;
|
|
223
|
+
const yellow = (s: string) => `\x1b[33m${s}\x1b[0m`;
|
|
224
|
+
const bold = (s: string) => `\x1b[1m${s}\x1b[22m`;
|
|
225
|
+
|
|
226
|
+
const boxWidth = effectiveWidth * cellWidth;
|
|
227
|
+
|
|
228
|
+
// Helper to pad content inside box
|
|
229
|
+
const boxLine = (content: string) => {
|
|
230
|
+
const contentLen = visibleWidth(content);
|
|
231
|
+
const padding = Math.max(0, boxWidth - contentLen);
|
|
232
|
+
return dim(" │") + content + " ".repeat(padding) + dim("│");
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// Top border
|
|
236
|
+
lines.push(this.padLine(dim(` ╭${"─".repeat(boxWidth)}╮`), width));
|
|
237
|
+
|
|
238
|
+
// Header with score
|
|
239
|
+
const scoreText = `Score: ${bold(yellow(String(this.state.score)))}`;
|
|
240
|
+
const highText = `High: ${bold(yellow(String(this.state.highScore)))}`;
|
|
241
|
+
const title = `${bold(green("SNAKE"))} │ ${scoreText} │ ${highText}`;
|
|
242
|
+
lines.push(this.padLine(boxLine(title), width));
|
|
243
|
+
|
|
244
|
+
// Separator
|
|
245
|
+
lines.push(this.padLine(dim(` ├${"─".repeat(boxWidth)}┤`), width));
|
|
246
|
+
|
|
247
|
+
// Game grid
|
|
248
|
+
for (let y = 0; y < effectiveHeight; y++) {
|
|
249
|
+
let row = "";
|
|
250
|
+
for (let x = 0; x < effectiveWidth; x++) {
|
|
251
|
+
const isHead = this.state.snake[0].x === x && this.state.snake[0].y === y;
|
|
252
|
+
const isBody = this.state.snake.slice(1).some((s) => s.x === x && s.y === y);
|
|
253
|
+
const isFood = this.state.food.x === x && this.state.food.y === y;
|
|
254
|
+
|
|
255
|
+
if (isHead) {
|
|
256
|
+
row += green("██"); // Snake head (2 chars)
|
|
257
|
+
} else if (isBody) {
|
|
258
|
+
row += green("▓▓"); // Snake body (2 chars)
|
|
259
|
+
} else if (isFood) {
|
|
260
|
+
row += red("◆ "); // Food (2 chars)
|
|
261
|
+
} else {
|
|
262
|
+
row += " "; // Empty cell (2 spaces)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
lines.push(this.padLine(dim(" │") + row + dim("│"), width));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Separator
|
|
269
|
+
lines.push(this.padLine(dim(` ├${"─".repeat(boxWidth)}┤`), width));
|
|
270
|
+
|
|
271
|
+
// Footer
|
|
272
|
+
let footer: string;
|
|
273
|
+
if (this.paused) {
|
|
274
|
+
footer = `${yellow(bold("PAUSED"))} Press any key to continue, ${bold("Q")} to quit`;
|
|
275
|
+
} else if (this.state.gameOver) {
|
|
276
|
+
footer = `${red(bold("GAME OVER!"))} Press ${bold("R")} to restart, ${bold("Q")} to quit`;
|
|
277
|
+
} else {
|
|
278
|
+
footer = `↑↓←→ or WASD to move, ${bold("ESC")} pause, ${bold("Q")} quit`;
|
|
279
|
+
}
|
|
280
|
+
lines.push(this.padLine(boxLine(footer), width));
|
|
281
|
+
|
|
282
|
+
// Bottom border
|
|
283
|
+
lines.push(this.padLine(dim(` ╰${"─".repeat(boxWidth)}╯`), width));
|
|
284
|
+
|
|
285
|
+
this.cachedLines = lines;
|
|
286
|
+
this.cachedWidth = width;
|
|
287
|
+
this.cachedVersion = this.version;
|
|
288
|
+
|
|
289
|
+
return lines;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private padLine(line: string, width: number): string {
|
|
293
|
+
// Calculate visible length (strip ANSI codes)
|
|
294
|
+
const visibleLen = line.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
295
|
+
const padding = Math.max(0, width - visibleLen);
|
|
296
|
+
return line + " ".repeat(padding);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
dispose(): void {
|
|
300
|
+
if (this.interval) {
|
|
301
|
+
clearInterval(this.interval);
|
|
302
|
+
this.interval = null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const SNAKE_SAVE_TYPE = "snake-save";
|
|
308
|
+
|
|
309
|
+
export default function (pi: ExtensionAPI) {
|
|
310
|
+
pi.registerCommand("snake", {
|
|
311
|
+
description: "Play Snake!",
|
|
312
|
+
|
|
313
|
+
handler: async (_args, ctx) => {
|
|
314
|
+
if (ctx.mode !== "tui") {
|
|
315
|
+
ctx.ui.notify("Snake requires interactive mode", "error");
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Load saved state from session
|
|
320
|
+
const entries = ctx.sessionManager.getEntries();
|
|
321
|
+
let savedState: GameState | undefined;
|
|
322
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
323
|
+
const entry = entries[i];
|
|
324
|
+
if (entry.type === "custom" && entry.customType === SNAKE_SAVE_TYPE) {
|
|
325
|
+
savedState = entry.data as GameState;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
await ctx.ui.custom((tui, _theme, _kb, done) => {
|
|
331
|
+
return new SnakeComponent(
|
|
332
|
+
tui,
|
|
333
|
+
() => done(undefined),
|
|
334
|
+
(state) => {
|
|
335
|
+
// Save or clear state
|
|
336
|
+
pi.appendEntry(SNAKE_SAVE_TYPE, state);
|
|
337
|
+
},
|
|
338
|
+
savedState,
|
|
339
|
+
);
|
|
340
|
+
});
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
function isAssistantMessage(message: unknown): message is AssistantMessage {
|
|
5
|
+
if (!message || typeof message !== "object") return false;
|
|
6
|
+
const role = (message as { role?: unknown }).role;
|
|
7
|
+
return role === "assistant";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function (pi: ExtensionAPI) {
|
|
11
|
+
let agentStartMs: number | null = null;
|
|
12
|
+
|
|
13
|
+
pi.on("agent_start", () => {
|
|
14
|
+
agentStartMs = Date.now();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
pi.on("agent_end", (event, ctx) => {
|
|
18
|
+
if (!ctx.hasUI) return;
|
|
19
|
+
if (agentStartMs === null) return;
|
|
20
|
+
|
|
21
|
+
const elapsedMs = Date.now() - agentStartMs;
|
|
22
|
+
agentStartMs = null;
|
|
23
|
+
if (elapsedMs <= 0) return;
|
|
24
|
+
|
|
25
|
+
let input = 0;
|
|
26
|
+
let output = 0;
|
|
27
|
+
let cacheRead = 0;
|
|
28
|
+
let cacheWrite = 0;
|
|
29
|
+
let totalTokens = 0;
|
|
30
|
+
|
|
31
|
+
for (const message of event.messages) {
|
|
32
|
+
if (!isAssistantMessage(message)) continue;
|
|
33
|
+
input += message.usage.input || 0;
|
|
34
|
+
output += message.usage.output || 0;
|
|
35
|
+
cacheRead += message.usage.cacheRead || 0;
|
|
36
|
+
cacheWrite += message.usage.cacheWrite || 0;
|
|
37
|
+
totalTokens += message.usage.totalTokens || 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (output <= 0) return;
|
|
41
|
+
|
|
42
|
+
const elapsedSeconds = elapsedMs / 1000;
|
|
43
|
+
const tokensPerSecond = output / elapsedSeconds;
|
|
44
|
+
const message = `TPS ${tokensPerSecond.toFixed(1)} tok/s. out ${output.toLocaleString()}, in ${input.toLocaleString()}, cache r/w ${cacheRead.toLocaleString()}/${cacheWrite.toLocaleString()}, total ${totalTokens.toLocaleString()}, ${elapsedSeconds.toFixed(1)}s`;
|
|
45
|
+
ctx.ui.notify(message, "info");
|
|
46
|
+
});
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lebronj/pi-suite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JHP's Pi extension suite for team coding workflows",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"pi-package",
|
|
8
|
+
"pi",
|
|
9
|
+
"pi-coding-agent",
|
|
10
|
+
"extensions",
|
|
11
|
+
"skills",
|
|
12
|
+
"prompts"
|
|
13
|
+
],
|
|
14
|
+
"author": "JHP",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"files": [
|
|
17
|
+
"extensions",
|
|
18
|
+
"prompts",
|
|
19
|
+
"skills",
|
|
20
|
+
"scripts",
|
|
21
|
+
"vendor",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"pi-mcp-adapter": "2.9.0",
|
|
27
|
+
"pi-subagents": "0.28.0",
|
|
28
|
+
"pi-web-access": "0.10.7"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@earendil-works/pi-agent-core": "*",
|
|
32
|
+
"@earendil-works/pi-ai": "*",
|
|
33
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
34
|
+
"@earendil-works/pi-tui": "*",
|
|
35
|
+
"typebox": "*"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"@earendil-works/pi-agent-core": { "optional": true },
|
|
39
|
+
"@earendil-works/pi-ai": { "optional": true },
|
|
40
|
+
"@earendil-works/pi-coding-agent": { "optional": true },
|
|
41
|
+
"@earendil-works/pi-tui": { "optional": true },
|
|
42
|
+
"typebox": { "optional": true }
|
|
43
|
+
},
|
|
44
|
+
"pi": {
|
|
45
|
+
"extensions": [
|
|
46
|
+
"./extensions",
|
|
47
|
+
"./vendor/pi-memory/index.ts",
|
|
48
|
+
"node_modules/pi-mcp-adapter/index.ts",
|
|
49
|
+
"node_modules/pi-subagents/src/extension/index.ts",
|
|
50
|
+
"node_modules/pi-web-access/index.ts"
|
|
51
|
+
],
|
|
52
|
+
"prompts": [
|
|
53
|
+
"./prompts",
|
|
54
|
+
"node_modules/pi-subagents/prompts"
|
|
55
|
+
],
|
|
56
|
+
"skills": [
|
|
57
|
+
"./skills",
|
|
58
|
+
"node_modules/pi-subagents/skills",
|
|
59
|
+
"node_modules/pi-web-access/skills"
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"pack:check": "npm pack --dry-run",
|
|
67
|
+
"bootstrap": "bash scripts/bootstrap.sh"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/prompts/cl.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Audit changelog entries before release
|
|
3
|
+
---
|
|
4
|
+
Audit changelog entries for all commits since the last release.
|
|
5
|
+
|
|
6
|
+
## Process
|
|
7
|
+
|
|
8
|
+
1. **Find the last release tag:**
|
|
9
|
+
```bash
|
|
10
|
+
git tag --sort=-version:refname | head -1
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
2. **List all commits since that tag:**
|
|
14
|
+
```bash
|
|
15
|
+
git log <tag>..HEAD --oneline
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
3. **Read each package's [Unreleased] section:**
|
|
19
|
+
- packages/ai/CHANGELOG.md
|
|
20
|
+
- packages/tui/CHANGELOG.md
|
|
21
|
+
- packages/coding-agent/CHANGELOG.md
|
|
22
|
+
|
|
23
|
+
4. **For each commit, check:**
|
|
24
|
+
- Skip: changelog updates, doc-only changes, release housekeeping
|
|
25
|
+
- Skip: changes to generated model catalogs (for example `packages/ai/src/models.generated.ts`) unless accompanied by an intentional product-facing change in non-generated source/docs.
|
|
26
|
+
- Determine which package(s) the commit affects (use `git show <hash> --stat`)
|
|
27
|
+
- Verify a changelog entry exists in the affected package(s)
|
|
28
|
+
- For external contributions (PRs), verify format: `Description ([#N](url) by [@user](url))`
|
|
29
|
+
|
|
30
|
+
5. **Cross-package duplication rule:**
|
|
31
|
+
Changes in `ai`, `agent` or `tui` that affect end users should be duplicated to `coding-agent` changelog, since coding-agent is the user-facing package that depends on them.
|
|
32
|
+
|
|
33
|
+
6. **Add New Features section after changelog fixes:**
|
|
34
|
+
- Insert a `### New Features` section at the start of `## [Unreleased]` in `packages/coding-agent/CHANGELOG.md`.
|
|
35
|
+
- Propose the top new features to the user for confirmation before writing them.
|
|
36
|
+
- Link to relevant docs and sections whenever possible.
|
|
37
|
+
|
|
38
|
+
7. **Report:**
|
|
39
|
+
- List commits with missing entries
|
|
40
|
+
- List entries that need cross-package duplication
|
|
41
|
+
- Add any missing entries directly
|
|
42
|
+
|
|
43
|
+
## Changelog Format Reference
|
|
44
|
+
|
|
45
|
+
Sections (in order):
|
|
46
|
+
- `### Breaking Changes` - API changes requiring migration
|
|
47
|
+
- `### Added` - New features
|
|
48
|
+
- `### Changed` - Changes to existing functionality
|
|
49
|
+
- `### Fixed` - Bug fixes
|
|
50
|
+
- `### Removed` - Removed features
|
|
51
|
+
|
|
52
|
+
Attribution:
|
|
53
|
+
- Internal: `Fixed foo ([#123](https://github.com/earendil-works/pi-mono/issues/123))`
|
|
54
|
+
- External: `Added bar ([#456](https://github.com/earendil-works/pi-mono/pull/456) by [@user](https://github.com/user))`
|