pi-extensions 0.1.9

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.
Files changed (135) hide show
  1. package/.ralph/import-cc-codex.md +31 -0
  2. package/.ralph/import-cc-codex.state.json +14 -0
  3. package/.ralph/mario-not-impl.md +69 -0
  4. package/.ralph/mario-not-impl.state.json +14 -0
  5. package/.ralph/mario-not-spec.md +163 -0
  6. package/.ralph/mario-not-spec.state.json +14 -0
  7. package/LICENSE +21 -0
  8. package/README.md +65 -0
  9. package/RELEASING.md +34 -0
  10. package/agent-guidance/CHANGELOG.md +4 -0
  11. package/agent-guidance/README.md +102 -0
  12. package/agent-guidance/agent-guidance.ts +147 -0
  13. package/agent-guidance/package.json +22 -0
  14. package/agent-guidance/setup.sh +75 -0
  15. package/agent-guidance/templates/CLAUDE.md +5 -0
  16. package/agent-guidance/templates/CODEX.md +92 -0
  17. package/agent-guidance/templates/GEMINI.md +5 -0
  18. package/arcade/CHANGELOG.md +4 -0
  19. package/arcade/README.md +85 -0
  20. package/arcade/assets/picman.png +0 -0
  21. package/arcade/assets/ping.png +0 -0
  22. package/arcade/assets/spice-invaders.png +0 -0
  23. package/arcade/assets/tetris.png +0 -0
  24. package/arcade/mario-not/README.md +30 -0
  25. package/arcade/mario-not/boss.js +103 -0
  26. package/arcade/mario-not/camera.js +59 -0
  27. package/arcade/mario-not/collision.js +91 -0
  28. package/arcade/mario-not/colors.js +36 -0
  29. package/arcade/mario-not/constants.js +97 -0
  30. package/arcade/mario-not/core.js +39 -0
  31. package/arcade/mario-not/death.js +77 -0
  32. package/arcade/mario-not/effects.js +84 -0
  33. package/arcade/mario-not/enemies.js +31 -0
  34. package/arcade/mario-not/engine.js +171 -0
  35. package/arcade/mario-not/fireballs.js +98 -0
  36. package/arcade/mario-not/items.js +24 -0
  37. package/arcade/mario-not/levels.js +403 -0
  38. package/arcade/mario-not/logic.js +104 -0
  39. package/arcade/mario-not/mario-not.ts +297 -0
  40. package/arcade/mario-not/player.js +244 -0
  41. package/arcade/mario-not/render.js +257 -0
  42. package/arcade/mario-not/spec.md +548 -0
  43. package/arcade/mario-not/state.js +246 -0
  44. package/arcade/mario-not/tests/e2e.test.js +855 -0
  45. package/arcade/mario-not/tests/engine.test.js +888 -0
  46. package/arcade/mario-not/tests/fixtures/story0-frame.txt +4 -0
  47. package/arcade/mario-not/tests/fixtures/story1-camera.txt +4 -0
  48. package/arcade/mario-not/tests/fixtures/story1-glyphs.txt +4 -0
  49. package/arcade/mario-not/tests/fixtures/story10-item.txt +4 -0
  50. package/arcade/mario-not/tests/fixtures/story11-hazards.txt +4 -0
  51. package/arcade/mario-not/tests/fixtures/story12-used-block.txt +4 -0
  52. package/arcade/mario-not/tests/fixtures/story13-pipes.txt +4 -0
  53. package/arcade/mario-not/tests/fixtures/story14-goal.txt +4 -0
  54. package/arcade/mario-not/tests/fixtures/story15-hud-narrow.txt +2 -0
  55. package/arcade/mario-not/tests/fixtures/story16-unknown-tile.txt +4 -0
  56. package/arcade/mario-not/tests/fixtures/story17-mix.txt +4 -0
  57. package/arcade/mario-not/tests/fixtures/story18-hud-score.txt +2 -0
  58. package/arcade/mario-not/tests/fixtures/story19-cue.txt +4 -0
  59. package/arcade/mario-not/tests/fixtures/story2-enemy.txt +4 -0
  60. package/arcade/mario-not/tests/fixtures/story20-camera-offset.txt +4 -0
  61. package/arcade/mario-not/tests/fixtures/story21-hud-zero.txt +2 -0
  62. package/arcade/mario-not/tests/fixtures/story22-big-viewport.txt +4 -0
  63. package/arcade/mario-not/tests/fixtures/story23-camera-negative.txt +4 -0
  64. package/arcade/mario-not/tests/fixtures/story24-camera-width.txt +4 -0
  65. package/arcade/mario-not/tests/fixtures/story25-camera-positive.txt +4 -0
  66. package/arcade/mario-not/tests/fixtures/story26-hud-lives.txt +2 -0
  67. package/arcade/mario-not/tests/fixtures/story27-hud-coins.txt +2 -0
  68. package/arcade/mario-not/tests/fixtures/story28-item-viewport.txt +4 -0
  69. package/arcade/mario-not/tests/fixtures/story29-enemy-viewport.txt +4 -0
  70. package/arcade/mario-not/tests/fixtures/story3-hud.txt +2 -0
  71. package/arcade/mario-not/tests/fixtures/story30-hud-score.txt +2 -0
  72. package/arcade/mario-not/tests/fixtures/story31-particles-viewport.txt +4 -0
  73. package/arcade/mario-not/tests/fixtures/story32-paused-frame.txt +4 -0
  74. package/arcade/mario-not/tests/fixtures/story4-big.txt +4 -0
  75. package/arcade/mario-not/tests/fixtures/story5-resume-hud.txt +2 -0
  76. package/arcade/mario-not/tests/fixtures/story6-particles.txt +4 -0
  77. package/arcade/mario-not/tests/fixtures/story6-paused.txt +4 -0
  78. package/arcade/mario-not/tests/fixtures/story7-powerup.txt +4 -0
  79. package/arcade/mario-not/tests/fixtures/story8-hud-time.txt +2 -0
  80. package/arcade/mario-not/tests/fixtures/story9-hud-level.txt +2 -0
  81. package/arcade/mario-not/tiles.js +79 -0
  82. package/arcade/mario-not/tsconfig.json +14 -0
  83. package/arcade/mario-not/types.js +225 -0
  84. package/arcade/package.json +26 -0
  85. package/arcade/picman.ts +328 -0
  86. package/arcade/ping.ts +594 -0
  87. package/arcade/spice-invaders.ts +1104 -0
  88. package/arcade/tetris.ts +662 -0
  89. package/code-actions/CHANGELOG.md +4 -0
  90. package/code-actions/README.md +65 -0
  91. package/code-actions/actions.ts +107 -0
  92. package/code-actions/index.ts +148 -0
  93. package/code-actions/package.json +22 -0
  94. package/code-actions/search.ts +79 -0
  95. package/code-actions/snippets.ts +179 -0
  96. package/code-actions/ui.ts +120 -0
  97. package/files-widget/CHANGELOG.md +90 -0
  98. package/files-widget/DESIGN.md +452 -0
  99. package/files-widget/README.md +122 -0
  100. package/files-widget/TODO.md +141 -0
  101. package/files-widget/browser.ts +922 -0
  102. package/files-widget/comment.ts +5 -0
  103. package/files-widget/constants.ts +18 -0
  104. package/files-widget/demo.svg +1 -0
  105. package/files-widget/file-tree.ts +224 -0
  106. package/files-widget/file-viewer.ts +93 -0
  107. package/files-widget/git.ts +107 -0
  108. package/files-widget/index.ts +140 -0
  109. package/files-widget/input-utils.ts +3 -0
  110. package/files-widget/package.json +22 -0
  111. package/files-widget/types.ts +28 -0
  112. package/files-widget/utils.ts +26 -0
  113. package/files-widget/viewer.ts +424 -0
  114. package/import-cc-codex/research/import-chats-from-other-agents.md +135 -0
  115. package/import-cc-codex/spec.md +79 -0
  116. package/package.json +29 -0
  117. package/ralph-wiggum/CHANGELOG.md +7 -0
  118. package/ralph-wiggum/README.md +96 -0
  119. package/ralph-wiggum/SKILL.md +73 -0
  120. package/ralph-wiggum/index.ts +792 -0
  121. package/ralph-wiggum/package.json +25 -0
  122. package/raw-paste/CHANGELOG.md +7 -0
  123. package/raw-paste/README.md +52 -0
  124. package/raw-paste/index.ts +112 -0
  125. package/raw-paste/package.json +22 -0
  126. package/tab-status/CHANGELOG.md +4 -0
  127. package/tab-status/README.md +61 -0
  128. package/tab-status/assets/tab-status.png +0 -0
  129. package/tab-status/package.json +22 -0
  130. package/tab-status/tab-status.ts +179 -0
  131. package/usage-extension/CHANGELOG.md +17 -0
  132. package/usage-extension/README.md +120 -0
  133. package/usage-extension/index.ts +628 -0
  134. package/usage-extension/package.json +22 -0
  135. package/usage-extension/screenshot.png +0 -0
@@ -0,0 +1,328 @@
1
+ /**
2
+ * Picman - Pi eats tokens, avoids bugs! Play with /picman
3
+ */
4
+
5
+ import type { ExtensionAPI, ExtensionCommandContext } from "@mariozechner/pi-coding-agent";
6
+ import { matchesKey, truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
7
+
8
+ const TICK_MS = 100;
9
+ const POWER_DURATION = 50;
10
+ const BUG_RESPAWN_TICKS = 30;
11
+ const INITIAL_LIVES = 3;
12
+ const BUG_MOVE_INTERVAL = 2;
13
+ const SAVE_TYPE = "picman-save";
14
+
15
+ type Direction = "up" | "down" | "left" | "right";
16
+
17
+ // The codebase - navigate and collect tokens!
18
+ const MAZE_TEMPLATE = [
19
+ "#####################",
20
+ "#.........#.........#",
21
+ "#O###.###.#.###.###O#",
22
+ "#.###.###.#.###.###.#",
23
+ "#...................#",
24
+ "#.###.#.#####.#.###.#",
25
+ "#.....#...#...#.....#",
26
+ "#####.### # ###.#####",
27
+ " #.# B B #.# ",
28
+ "#####.# BBB B#.#####",
29
+ " . BBB B . ",
30
+ "#####.# BBBBB #.#####",
31
+ " #.# #.# ",
32
+ "#####.# ##### #.#####",
33
+ "#.........#.........#",
34
+ "#.###.###.#.###.###.#",
35
+ "#O..#.....P.....#..O#",
36
+ "###.#.#.#####.#.#.###",
37
+ "#.....#...#...#.....#",
38
+ "#.#######.#.#######.#",
39
+ "#####################",
40
+ ];
41
+
42
+ const DIRECTIONS: Record<Direction, { x: number; y: number }> = {
43
+ up: { x: 0, y: -1 }, down: { x: 0, y: 1 }, left: { x: -1, y: 0 }, right: { x: 1, y: 0 },
44
+ };
45
+ const OPPOSITE: Record<Direction, Direction> = { up: "down", down: "up", left: "right", right: "left" };
46
+
47
+ // ANSI colors
48
+ const [RESET, CYAN, BLUE, WHITE, DIM, RED] = ["\x1b[0m", "\x1b[1;96m", "\x1b[1;34m", "\x1b[1;97m", "\x1b[2m", "\x1b[1;91m"];
49
+ const GREEN = "\x1b[1;32m";
50
+ const BUG_COLORS = ["\x1b[1;91m", "\x1b[1;95m", "\x1b[1;93m", "\x1b[1;31m"]; // Red, Magenta, Yellow, Dark Red
51
+ const BUG_NAMES = ["Bug", "Error", "Crash", "Glitch"];
52
+
53
+ interface Bug {
54
+ x: number; y: number; homeX: number; homeY: number;
55
+ direction: Direction; color: string; name: string;
56
+ squashed: boolean; respawnTimer: number;
57
+ }
58
+
59
+ interface GameState {
60
+ pi: { x: number; y: number };
61
+ piDir: Direction;
62
+ nextDir: Direction | null;
63
+ bugs: Bug[];
64
+ maze: string[][];
65
+ tokens: number; highScore: number; lives: number; level: number;
66
+ tokensRemaining: number; caffeine: number; tickCount: number;
67
+ gameOver: boolean; paused: boolean; mouthOpen: boolean;
68
+ deathAnimation: number; levelCompleteTimer: number;
69
+ }
70
+
71
+ const findInMaze = (char: string): { x: number; y: number }[] => {
72
+ const results: { x: number; y: number }[] = [];
73
+ MAZE_TEMPLATE.forEach((row, y) => {
74
+ for (let x = 0; x < row.length; x++) if (row[x] === char) results.push({ x, y });
75
+ });
76
+ return results;
77
+ };
78
+
79
+ const createMaze = (): string[][] => {
80
+ const maze = MAZE_TEMPLATE.map(row => row.split(""));
81
+ for (let y = 0; y < maze.length; y++)
82
+ for (let x = 0; x < maze[y].length; x++)
83
+ if (maze[y][x] === "P" || maze[y][x] === "B") maze[y][x] = " ";
84
+ return maze;
85
+ };
86
+
87
+ const countTokens = (maze: string[][]): number =>
88
+ maze.flat().filter(c => c === "." || c === "O").length;
89
+
90
+ const createBugs = (): Bug[] =>
91
+ findInMaze("B").slice(0, 4).map((pos, i) => ({
92
+ x: pos.x, y: pos.y, homeX: pos.x, homeY: pos.y,
93
+ direction: "up" as Direction, color: BUG_COLORS[i], name: BUG_NAMES[i],
94
+ squashed: false, respawnTimer: 0,
95
+ }));
96
+
97
+ const createState = (highScore = 0): GameState => {
98
+ const maze = createMaze();
99
+ const piStart = findInMaze("P")[0] || { x: 10, y: 16 };
100
+ return {
101
+ pi: piStart, piDir: "right", nextDir: null,
102
+ bugs: createBugs(), maze,
103
+ tokens: 0, highScore, lives: INITIAL_LIVES, level: 1,
104
+ tokensRemaining: countTokens(maze), caffeine: 0, tickCount: 0,
105
+ gameOver: false, paused: false, mouthOpen: true,
106
+ deathAnimation: 0, levelCompleteTimer: 0,
107
+ };
108
+ };
109
+
110
+ const resetLevel = (s: GameState): void => {
111
+ s.maze = createMaze();
112
+ s.pi = findInMaze("P")[0] || { x: 10, y: 16 };
113
+ s.piDir = "right"; s.nextDir = null;
114
+ s.bugs = createBugs();
115
+ s.tokensRemaining = countTokens(s.maze);
116
+ s.caffeine = s.deathAnimation = s.levelCompleteTimer = 0;
117
+ };
118
+
119
+ const resetPositions = (s: GameState): void => {
120
+ s.pi = findInMaze("P")[0] || { x: 10, y: 16 };
121
+ s.piDir = "right"; s.nextDir = null;
122
+ s.caffeine = s.deathAnimation = 0;
123
+ s.bugs.forEach(b => { b.x = b.homeX; b.y = b.homeY; b.squashed = false; b.respawnTimer = 0; });
124
+ };
125
+
126
+ const isWalkable = (maze: string[][], x: number, y: number): boolean =>
127
+ y >= 0 && y < maze.length && (x < 0 || x >= maze[0].length || maze[y][x] !== "#");
128
+
129
+ const wrap = (x: number, w: number): number => x < 0 ? w - 1 : x >= w ? 0 : x;
130
+
131
+ const dist = (a: { x: number; y: number }, b: { x: number; y: number }): number =>
132
+ Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
133
+
134
+ const getValidDirs = (maze: string[][], x: number, y: number, exclude?: Direction): Direction[] =>
135
+ (Object.keys(DIRECTIONS) as Direction[]).filter(dir => {
136
+ if (dir === exclude) return false;
137
+ const d = DIRECTIONS[dir];
138
+ return isWalkable(maze, x + d.x, y + d.y);
139
+ });
140
+
141
+ const moveBug = (b: Bug, s: GameState): void => {
142
+ if (b.squashed) {
143
+ if (--b.respawnTimer <= 0) { b.squashed = false; b.x = b.homeX; b.y = b.homeY; }
144
+ return;
145
+ }
146
+
147
+ const { maze, pi, caffeine } = s;
148
+ const validDirs = getValidDirs(maze, b.x, b.y, OPPOSITE[b.direction]);
149
+
150
+ if (validDirs.length === 0) {
151
+ const rev = OPPOSITE[b.direction], d = DIRECTIONS[rev];
152
+ if (isWalkable(maze, b.x + d.x, b.y + d.y)) {
153
+ b.direction = rev; b.x = wrap(b.x + d.x, maze[0].length); b.y += d.y;
154
+ }
155
+ return;
156
+ }
157
+
158
+ // Target: flee if Pi is caffeinated, else chase with personality
159
+ let target = pi;
160
+ if (caffeine <= 0) {
161
+ if (b.name === "Error") {
162
+ const d = DIRECTIONS[s.piDir];
163
+ target = { x: pi.x + d.x * 4, y: pi.y + d.y * 4 };
164
+ } else if (b.name === "Glitch" && dist(b, pi) < 8) {
165
+ target = { x: 0, y: maze.length - 1 };
166
+ }
167
+ }
168
+
169
+ // Pick best direction
170
+ const bestDir = validDirs.reduce((best, dir) => {
171
+ const d = DIRECTIONS[dir];
172
+ const nx = wrap(b.x + d.x, maze[0].length), ny = b.y + d.y;
173
+ const score = dist({ x: nx, y: ny }, target);
174
+ const bestScore = dist({ x: wrap(b.x + DIRECTIONS[best].x, maze[0].length), y: b.y + DIRECTIONS[best].y }, target);
175
+ return caffeine > 0 ? (score > bestScore ? dir : best) : (score < bestScore ? dir : best);
176
+ }, validDirs[0]);
177
+
178
+ b.direction = bestDir;
179
+ const d = DIRECTIONS[bestDir];
180
+ b.x = wrap(b.x + d.x, maze[0].length); b.y += d.y;
181
+ };
182
+
183
+ const movePi = (s: GameState): void => {
184
+ const { maze, pi } = s;
185
+
186
+ // Try queued direction
187
+ if (s.nextDir) {
188
+ const d = DIRECTIONS[s.nextDir];
189
+ if (isWalkable(maze, pi.x + d.x, pi.y + d.y)) { s.piDir = s.nextDir; s.nextDir = null; }
190
+ }
191
+
192
+ const d = DIRECTIONS[s.piDir];
193
+ if (isWalkable(maze, pi.x + d.x, pi.y + d.y)) {
194
+ pi.x = wrap(pi.x + d.x, maze[0].length); pi.y += d.y;
195
+ const cell = maze[pi.y][pi.x];
196
+ if (cell === ".") { maze[pi.y][pi.x] = " "; s.tokens += 10; s.tokensRemaining--; }
197
+ else if (cell === "O") { maze[pi.y][pi.x] = " "; s.tokens += 50; s.tokensRemaining--; s.caffeine = POWER_DURATION; }
198
+ }
199
+
200
+ if (s.tickCount % 3 === 0) s.mouthOpen = !s.mouthOpen;
201
+ };
202
+
203
+ const checkCollisions = (s: GameState): void => {
204
+ for (const b of s.bugs) {
205
+ if (b.squashed || b.x !== s.pi.x || b.y !== s.pi.y) continue;
206
+ if (s.caffeine > 0) { b.squashed = true; b.respawnTimer = BUG_RESPAWN_TICKS; s.tokens += 200; }
207
+ else if (--s.lives <= 0) s.gameOver = true;
208
+ else s.deathAnimation = 10;
209
+ }
210
+ };
211
+
212
+ class PicmanComponent {
213
+ private state: GameState;
214
+ private interval: ReturnType<typeof setInterval> | null = null;
215
+ private onClose: () => void;
216
+ private onSave: (state: GameState) => void;
217
+ private tui: { requestRender: () => void };
218
+ private cache = { lines: [] as string[], width: 0, version: -1 };
219
+ private version = 0;
220
+
221
+ constructor(tui: { requestRender: () => void }, onClose: () => void, onSave: (s: GameState) => void, saved?: GameState) {
222
+ this.tui = tui; this.onClose = onClose; this.onSave = onSave;
223
+ this.state = saved ? { ...saved, paused: true } : createState();
224
+ this.interval = setInterval(() => this.tick(), TICK_MS);
225
+ }
226
+
227
+ private tick(): void {
228
+ const s = this.state;
229
+ if (s.paused || s.gameOver) return;
230
+ s.tickCount++;
231
+
232
+ if (s.deathAnimation > 0) { if (--s.deathAnimation === 0) resetPositions(s); }
233
+ else if (s.levelCompleteTimer > 0) { if (--s.levelCompleteTimer === 0) { s.level++; resetLevel(s); } }
234
+ else if (s.tokensRemaining === 0) s.levelCompleteTimer = 20;
235
+ else {
236
+ if (s.caffeine > 0) s.caffeine--;
237
+ movePi(s);
238
+ const bugInterval = Math.max(1, BUG_MOVE_INTERVAL - Math.floor(s.level / 3));
239
+ if (s.tickCount % bugInterval === 0) s.bugs.forEach(b => moveBug(b, s));
240
+ checkCollisions(s);
241
+ if (s.tokens > s.highScore) s.highScore = s.tokens;
242
+ }
243
+
244
+ this.version++;
245
+ this.tui.requestRender();
246
+ }
247
+
248
+ handleInput(key: string): boolean {
249
+ const s = this.state;
250
+ if (matchesKey(key, "escape") || key === "q" || key === "Q") { this.onSave(s); this.onClose(); return true; }
251
+ if (key === "n" || key === "N") { Object.assign(this.state, createState(Math.max(s.highScore, s.tokens))); this.version++; this.tui.requestRender(); return true; }
252
+ if (key === " " || key === "p" || key === "P") { s.paused = !s.paused; this.version++; this.tui.requestRender(); return true; }
253
+ if (s.gameOver || s.paused) return true;
254
+
255
+ const dirMap: Record<string, Direction> = { k: "up", w: "up", j: "down", s: "down", h: "left", a: "left", l: "right", d: "right" };
256
+ if (matchesKey(key, "up")) s.nextDir = "up";
257
+ else if (matchesKey(key, "down")) s.nextDir = "down";
258
+ else if (matchesKey(key, "left")) s.nextDir = "left";
259
+ else if (matchesKey(key, "right")) s.nextDir = "right";
260
+ else if (dirMap[key]) s.nextDir = dirMap[key];
261
+ return true;
262
+ }
263
+
264
+ render(width: number, _height: number): string[] {
265
+ const pad = (line: string) => truncateToWidth(line, width) + " ".repeat(Math.max(0, width - visibleWidth(truncateToWidth(line, width))));
266
+ const minWidth = MAZE_TEMPLATE[0].length * 2 + 4;
267
+
268
+ if (width < minWidth) {
269
+ return ["", pad(`${CYAN}PICMAN${RESET}`), "", pad("Terminal too narrow"), pad(`Need ${minWidth} cols`), "", pad("[Q] Quit")];
270
+ }
271
+
272
+ if (this.cache.version === this.version && this.cache.width === width) return this.cache.lines;
273
+
274
+ const s = this.state, lines: string[] = [""];
275
+ const lives = Array(Math.max(0, s.lives)).fill(`${CYAN}Pi${RESET}`).join(" ");
276
+ lines.push(pad(`${CYAN}PICMAN${RESET} Tokens: ${WHITE}${s.tokens}${RESET} Hi: ${s.highScore} Lv: ${s.level} ${lives}`));
277
+ lines.push("");
278
+
279
+ if (s.gameOver) {
280
+ lines.push(pad(`${RED}SEGFAULT${RESET}`), pad(`Final Tokens: ${s.tokens}`), "", pad("[N] New Game [Q] Quit"), "");
281
+ } else {
282
+ if (s.paused) lines.push(pad(`${DIM}PAUSED${RESET}`), pad("[SPACE] Resume [N] New [Q] Quit"), "");
283
+ if (s.levelCompleteTimer > 0) lines.push(pad(`${GREEN}LEVEL ${s.level} SHIPPED!${RESET}`), "");
284
+ if (s.deathAnimation > 0) lines.push(pad(`${RED}BUG FOUND!${RESET}`), "");
285
+
286
+ for (let y = 0; y < s.maze.length; y++) {
287
+ let row = "";
288
+ for (let x = 0; x < s.maze[y].length; x++) {
289
+ const cell = s.maze[y][x];
290
+ if (s.pi.x === x && s.pi.y === y && s.deathAnimation === 0) {
291
+ const glyph = s.mouthOpen ? ({ right: "Pi", left: "iP", up: "Pi", down: "Pi" })[s.piDir] : "PI";
292
+ row += `${CYAN}${glyph}${RESET}`;
293
+ } else {
294
+ const bug = s.bugs.find(b => b.x === x && b.y === y && !b.squashed);
295
+ if (bug) {
296
+ const scared = s.caffeine > 0, blink = scared && s.caffeine < 15 && s.tickCount % 4 < 2;
297
+ row += `${blink ? WHITE : scared ? GREEN : bug.color}${scared ? "><" : "<>"}${RESET}`;
298
+ } else {
299
+ row += cell === "#" ? `${BLUE}██${RESET}` : cell === "." ? ` ${DIM};${RESET}` : cell === "O" ? `${GREEN}()${RESET}` : " ";
300
+ }
301
+ }
302
+ }
303
+ lines.push(pad(row));
304
+ }
305
+
306
+ lines.push("", pad(s.caffeine > 0 ? `${GREEN}CAFFEINATED!${RESET} [Arrows/HJKL] Move [SPACE] Pause [Q] Quit` : "[Arrows/HJKL] Move [SPACE] Pause [N] New [Q] Quit"), "");
307
+ }
308
+
309
+ this.cache = { lines, width, version: this.version };
310
+ return lines;
311
+ }
312
+
313
+ dispose(): void { if (this.interval) clearInterval(this.interval); }
314
+ }
315
+
316
+ export default function (api: ExtensionAPI) {
317
+ api.registerCommand("picman", {
318
+ description: "Play Picman! Collect tokens, squash bugs, drink coffee!",
319
+ handler: async (_args, ctx: ExtensionCommandContext) => {
320
+ if (!ctx.hasUI) { ctx.ui.notify("Picman requires interactive mode", "error"); return; }
321
+
322
+ const entries = ctx.sessionManager.getEntries();
323
+ const saved = entries.reverse().find(e => e.type === "custom" && e.customType === SAVE_TYPE)?.data as GameState | undefined;
324
+
325
+ await ctx.ui.custom((tui, _theme, _kb, done) => new PicmanComponent(tui, () => done(undefined), s => api.appendEntry(SAVE_TYPE, s), saved));
326
+ },
327
+ });
328
+ }