@gonrocca/zero-pi 0.1.27 → 0.1.29

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/README.md CHANGED
@@ -64,7 +64,7 @@ into `/forge` for you.
64
64
  | **`/zero-sync`** | Folds each run's spec delta into a canonical, project-wide spec store. |
65
65
  | **Run memory** | Every run recalls and saves traces to Cortex, so runs learn from each other. |
66
66
  | **Provider guard** | Warns when the `anthropic` provider runs on a metered API key instead of your subscription. |
67
- | **Startup banner** | The animated `ZERO` wordmark Tetris-cell assembly + a sparkle pass. |
67
+ | **Startup banner** | The violet ANSI-Shadow `ZERO` wordmark, drawn once at pi startup `ZERO_HEADER=off` to disable. |
68
68
  | **Working-phrase ticker** | Swaps pi's `Working...` for a context-aware Spanish phrase + spinner. |
69
69
  | **Conversation resume** | Writes `.pi/zero-resume.md` on exit — the restore command + a conversation tail. |
70
70
  | **Windows tree-kill** | Aborting a turn kills the whole process tree — no orphaned `claude`. |
@@ -84,8 +84,7 @@ into `/forge` for you.
84
84
 
85
85
  zero-pi keeps its state in `~/.pi/zero.json` (per-phase models + autotune mode)
86
86
  and `~/.pi/zero-runs.jsonl` (the run-metrics log); per-project artifacts live
87
- under `.sdd/`. Environment variables: `ZERO_BANNER` (`shimmer` / `static` /
88
- `off`) and `ZERO_RESUME` (`off` disables the resume note).
87
+ under `.sdd/`. Set `ZERO_RESUME=off` to disable the conversation-resume note.
89
88
 
90
89
  ## 🔗 Relationship to `zero`
91
90
 
@@ -15,8 +15,8 @@
15
15
  //
16
16
  // All decisions live in `autotune.ts`; this file only reads files, calls those
17
17
  // functions, and applies/notifies. The whole handler is wrapped in a swallowing
18
- // `try/catch` — exactly like `startup-banner.ts`, a failure must never break a
19
- // pi session. The package stays dependency-free: `node:fs`/`node:os`/`node:path`
18
+ // `try/catch` — a failure must never break a pi session. The package stays
19
+ // dependency-free: `node:fs`/`node:os`/`node:path`
20
20
  // only, plus minimal local interfaces for the pi API.
21
21
 
22
22
  import { readFileSync, writeFileSync } from "node:fs";
@@ -0,0 +1,151 @@
1
+ // zero-pi — static ZERO SDD startup banner.
2
+ //
3
+ // Renders the ZERO wordmark ONCE, at extension load, as an "ANSI Shadow" 3D
4
+ // block in ceroclawd.com violet — deep-violet faces, a lit top edge, dark
5
+ // shadow strokes and a cast shadow for depth.
6
+ //
7
+ // It writes a single block to stdout before pi's UI takes over. There is
8
+ // deliberately NO setHeader and NO animation timer: an animated header that
9
+ // re-renders on a timer spammed the terminal on pi 0.75.x and could crash the
10
+ // session. A one-time stdout write cannot re-render, so it cannot spam.
11
+ //
12
+ // Disable with the ZERO_HEADER=off environment variable.
13
+
14
+ type RGB = [number, number, number];
15
+
16
+ const WORD = "ZERO";
17
+ const ROWS = 6;
18
+
19
+ // Cast-shadow offset — light from the top-left, shadow falls bottom-right.
20
+ const SHADOW_DX = 2;
21
+ const SHADOW_DY = 1;
22
+
23
+ // ANSI Shadow glyphs — six rows each, glued edge to edge like figlet output.
24
+ const FONT: Record<string, string[]> = {
25
+ Z: ["███████╗", "╚══███╔╝", " ███╔╝ ", " ███╔╝ ", "███████╗", "╚══════╝"],
26
+ E: ["███████╗", "██╔════╝", "█████╗ ", "██╔══╝ ", "███████╗", "╚══════╝"],
27
+ R: ["██████╗ ", "██╔══██╗", "██████╔╝", "██╔══██╗", "██║ ██║", "╚═╝ ╚═╝"],
28
+ O: [" ██████╗ ", "██╔═══██╗", "██║ ██║", "██║ ██║", "╚██████╔╝", " ╚═════╝ "],
29
+ " ": [" ", " ", " ", " ", " ", " "],
30
+ };
31
+
32
+ // ceroclawd.com palette — violet, glow and darkness.
33
+ const VIOLET_DEEP: RGB = [124, 58, 237];
34
+ const LAVENDER: RGB = [205, 188, 255];
35
+ const PEAK: RGB = [248, 244, 255];
36
+ const SHADOW: RGB = [38, 24, 66];
37
+ const INK: RGB = [20, 13, 34];
38
+ const VIOLET: RGB = [167, 139, 250];
39
+ const MUTED: RGB = [120, 110, 150];
40
+
41
+ const ANSI_RE = /\x1b\[[0-9;]*m/g;
42
+
43
+ function fg([r, g, b]: RGB, text: string): string {
44
+ return `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
45
+ }
46
+
47
+ function lerp(a: number, b: number, t: number): number {
48
+ return a + (b - a) * t;
49
+ }
50
+
51
+ function mix(a: RGB, b: RGB, t: number): RGB {
52
+ const k = Math.max(0, Math.min(1, t));
53
+ return [
54
+ Math.round(lerp(a[0], b[0], k)),
55
+ Math.round(lerp(a[1], b[1], k)),
56
+ Math.round(lerp(a[2], b[2], k)),
57
+ ];
58
+ }
59
+
60
+ /** Printable width of a string, ignoring ANSI colour escapes. */
61
+ export function visibleWidth(text: string): number {
62
+ return text.replace(ANSI_RE, "").length;
63
+ }
64
+
65
+ function center(text: string, width: number): string {
66
+ const pad = Math.max(0, Math.floor((width - visibleWidth(text)) / 2));
67
+ return " ".repeat(pad) + text;
68
+ }
69
+
70
+ function matrixFor(text: string): { rows: string[]; width: number } {
71
+ const rows = Array.from({ length: ROWS }, () => "");
72
+ for (const raw of Array.from(text)) {
73
+ const glyph = FONT[raw.toUpperCase()] ?? FONT[" "];
74
+ for (let row = 0; row < ROWS; row++) rows[row] += glyph[row];
75
+ }
76
+ return { rows, width: rows[0]?.length ?? 0 };
77
+ }
78
+
79
+ /** Front-face colour: violet vertical gradient with a lit top edge. */
80
+ function faceColor(row: number, topEdge: boolean): RGB {
81
+ const vt = Math.pow(row / (ROWS - 1), 0.85);
82
+ const base = mix(LAVENDER, VIOLET_DEEP, vt);
83
+ return topEdge ? mix(base, PEAK, 0.5) : base;
84
+ }
85
+
86
+ /** Extrusion side: a darker, shaded version of the face it belongs to. */
87
+ function sideColor(row: number): RGB {
88
+ const vt = Math.pow(row / (ROWS - 1), 0.85);
89
+ return mix(mix(LAVENDER, VIOLET_DEEP, vt), SHADOW, 0.66);
90
+ }
91
+
92
+ function renderLogo(width: number): string[] {
93
+ const matrix = matrixFor(WORD);
94
+ const W = matrix.width;
95
+ const cellAt = (r: number, c: number): string =>
96
+ r >= 0 && r < ROWS && c >= 0 && c < W ? matrix.rows[r][c] ?? " " : " ";
97
+ const isFill = (r: number, c: number): boolean => cellAt(r, c) !== " ";
98
+
99
+ const lines: string[] = [];
100
+ for (let gr = 0; gr < ROWS + SHADOW_DY; gr++) {
101
+ let out = "";
102
+ for (let gc = 0; gc < W + SHADOW_DX; gc++) {
103
+ const ch = cellAt(gr, gc);
104
+ if (ch !== " ") {
105
+ out += ch === "█" ? fg(faceColor(gr, !isFill(gr - 1, gc)), ch) : fg(sideColor(gr), ch);
106
+ } else if ((gr >= ROWS || gc >= W) && isFill(gr - SHADOW_DY, gc - SHADOW_DX)) {
107
+ out += fg(INK, "█");
108
+ } else {
109
+ out += " ";
110
+ }
111
+ }
112
+ lines.push(center(out, width));
113
+ }
114
+ return lines;
115
+ }
116
+
117
+ /** A thin violet rule, brightest in the middle. */
118
+ function ornament(width: number): string {
119
+ const length = Math.min(46, Math.max(22, Math.floor(width * 0.5)));
120
+ let line = "";
121
+ for (let i = 0; i < length; i++) {
122
+ const t = i / Math.max(1, length - 1);
123
+ line += fg(mix(VIOLET_DEEP, VIOLET, Math.sin(t * Math.PI)), "─");
124
+ }
125
+ return center(line, width);
126
+ }
127
+
128
+ /** The full banner block, centered to the given width. */
129
+ export function bannerBlock(width: number): string[] {
130
+ if (width < 64) {
131
+ return [center(fg(VIOLET, "ZERO SDD"), width), center(fg(MUTED, "pi.dev · spec-driven work"), width)];
132
+ }
133
+ const tag = fg(VIOLET, "ZERO SDD") + fg(MUTED, " explore → plan → build → veredicto");
134
+ return [ornament(width), "", ...renderLogo(width), "", center(tag, width), ornament(width)];
135
+ }
136
+
137
+ /**
138
+ * The pi extension entry point. Renders the banner exactly once, synchronously,
139
+ * at load time. Any failure is swallowed — a banner must never break a session.
140
+ */
141
+ export default function register(_pi?: unknown): void {
142
+ try {
143
+ if ((process.env.ZERO_HEADER ?? "").trim().toLowerCase() === "off") return;
144
+ const stream = process.stdout;
145
+ if (!stream || !stream.isTTY || process.env.NO_COLOR) return;
146
+ const width = stream.columns && stream.columns > 0 ? stream.columns : 80;
147
+ stream.write("\n" + bannerBlock(width).join("\n") + "\n\n");
148
+ } catch {
149
+ // A banner failure must never break a pi session.
150
+ }
151
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gonrocca/zero-pi",
3
- "version": "0.1.27",
4
- "description": "zero-pi — an installable layer for pi (pi.dev): the zero spec-driven development workflow, skill auto-learning, and an animated ZERO startup banner. Adds capability to pi without modifying pi.",
3
+ "version": "0.1.29",
4
+ "description": "zero-pi — an installable layer for pi (pi.dev): the zero spec-driven development workflow, per-phase model autotune, and skill auto-learning. Adds capability to pi without modifying pi.",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "pi",
@@ -23,7 +23,7 @@
23
23
  "./themes"
24
24
  ],
25
25
  "extensions": [
26
- "./extensions/startup-banner.ts",
26
+ "./extensions/zero-banner.ts",
27
27
  "./extensions/working-phrases.ts",
28
28
  "./extensions/win-tree-kill.ts",
29
29
  "./extensions/sdd-agents.ts",
@@ -38,7 +38,7 @@
38
38
  "prompts",
39
39
  "skills",
40
40
  "themes",
41
- "extensions/startup-banner.ts",
41
+ "extensions/zero-banner.ts",
42
42
  "extensions/working-phrases.ts",
43
43
  "extensions/win-tree-kill.ts",
44
44
  "extensions/sdd-agents.ts",
@@ -1,280 +0,0 @@
1
- // zero-pi - animated startup banner.
2
- //
3
- // A pi extension that renders the ZERO wordmark as ASCII-safe Tetris cells.
4
- // The animated mode progressively assembles the wordmark from the bottom up,
5
- // then settles into the complete banner. The extension stays dependency-free
6
- // and keeps the historical ZERO_BANNER controls.
7
-
8
- type RGB = [number, number, number];
9
-
10
- const COLORS: Record<string, RGB> = {
11
- cyan: [80, 210, 255],
12
- blue: [116, 151, 255],
13
- mint: [79, 221, 171],
14
- amber: [238, 190, 92],
15
- rose: [255, 106, 122],
16
- violet: [175, 138, 255],
17
- peak: [255, 245, 218],
18
- };
19
-
20
- /** Number of rows in every glyph. */
21
- const ROWS = 6;
22
-
23
- // Five-cell-wide glyphs. Non-space characters become visible Tetris cells.
24
- const FONT: Record<string, string[]> = {
25
- Z: ["ZZZZZ", " ZZ", " ZZ ", " ZZ ", "ZZ ", "ZZZZZ"],
26
- E: ["EEEEE", "EE ", "EEEE ", "EE ", "EE ", "EEEEE"],
27
- R: ["RRRR ", "RR RR", "RRRR ", "RR RR", "RR R", "RR R"],
28
- O: [" OOO ", "OO OO", "OO OO", "OO OO", "OO OO", " OOO "],
29
- P: ["PPPP ", "PP PP", "PP PP", "PPPP ", "PP ", "PP "],
30
- I: ["IIIII", " II ", " II ", " II ", " II ", "IIIII"],
31
- "-": [" ", " ", "-----", " ", " ", " "],
32
- " ": [" ", " ", " ", " ", " ", " "],
33
- };
34
-
35
- const PIECE_COLORS: Record<string, RGB> = {
36
- Z: COLORS.cyan,
37
- E: COLORS.amber,
38
- R: COLORS.mint,
39
- O: COLORS.rose,
40
- P: COLORS.violet,
41
- I: COLORS.blue,
42
- "-": COLORS.amber,
43
- };
44
-
45
- interface Matrix {
46
- rows: string[];
47
- width: number;
48
- totalCells: number;
49
- ranks: Map<string, number>;
50
- }
51
-
52
- function glyphFor(ch: string): string[] {
53
- return FONT[ch.toUpperCase()] ?? FONT[" "];
54
- }
55
-
56
- function matrixForText(text: string): Matrix {
57
- const rows = Array.from({ length: ROWS }, () => "");
58
- for (const [index, raw] of Array.from(text).entries()) {
59
- const glyph = glyphFor(raw);
60
- for (let r = 0; r < ROWS; r++) {
61
- rows[r] += (index === 0 ? "" : " ") + glyph[r];
62
- }
63
- }
64
-
65
- const cells: Array<{ row: number; col: number }> = [];
66
- for (let row = 0; row < ROWS; row++) {
67
- for (let col = 0; col < rows[row].length; col++) {
68
- if (rows[row][col] !== " ") cells.push({ row, col });
69
- }
70
- }
71
-
72
- // Tetris reads as a pile building upward: bottom rows settle first.
73
- cells.sort((a, b) => b.row - a.row || a.col - b.col);
74
-
75
- const ranks = new Map<string, number>();
76
- for (const [rank, cell] of cells.entries()) {
77
- ranks.set(`${cell.row}:${cell.col}`, rank);
78
- }
79
-
80
- return {
81
- rows,
82
- width: rows[0]?.length ?? 0,
83
- totalCells: cells.length,
84
- ranks,
85
- };
86
- }
87
-
88
- /** Lay a word out as six rows of ASCII-safe Tetris cells. */
89
- export function bannerLines(text = "ZERO"): string[] {
90
- return matrixForText(text).rows.map((row) =>
91
- Array.from(row)
92
- .map((cell) => (cell === " " ? " " : "[]"))
93
- .join(""),
94
- );
95
- }
96
-
97
- function lerp(a: number, b: number, t: number): number {
98
- return a + (b - a) * t;
99
- }
100
-
101
- function lerpColor(c1: RGB, c2: RGB, t: number): RGB {
102
- const k = Math.max(0, Math.min(1, t));
103
- return [
104
- Math.round(lerp(c1[0], c2[0], k)),
105
- Math.round(lerp(c1[1], c2[1], k)),
106
- Math.round(lerp(c1[2], c2[2], k)),
107
- ];
108
- }
109
-
110
- function ansiFg([r, g, b]: RGB, text: string): string {
111
- return `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
112
- }
113
-
114
- function colorForPiece(piece: string, row: number, rank: number, active: boolean): RGB {
115
- if (active) return COLORS.peak;
116
- const base = PIECE_COLORS[piece] ?? COLORS.blue;
117
- const heightWarmth = (ROWS - 1 - row) / Math.max(1, ROWS - 1);
118
- const rankPulse = (rank % 7) / 18;
119
- return lerpColor(base, COLORS.peak, heightWarmth * 0.18 + rankPulse);
120
- }
121
-
122
- function paintMatrixLine(
123
- matrix: Matrix,
124
- row: number,
125
- visibleCells: number,
126
- sparkles?: ReadonlySet<string>,
127
- ): string {
128
- let out = "";
129
- const line = matrix.rows[row] ?? "";
130
- for (let col = 0; col < matrix.width; col++) {
131
- const piece = line[col] ?? " ";
132
- if (piece === " ") {
133
- out += " ";
134
- continue;
135
- }
136
- const key = `${row}:${col}`;
137
- const rank = matrix.ranks.get(key) ?? Number.POSITIVE_INFINITY;
138
- if (rank >= visibleCells) {
139
- out += " ";
140
- continue;
141
- }
142
- // A cell glints when it is the assembly's leading cell or when this
143
- // sparkle frame picked it.
144
- const glint = rank === visibleCells - 1 || (sparkles?.has(key) ?? false);
145
- out += ansiFg(colorForPiece(piece, row, rank, glint), "[]");
146
- }
147
- return out;
148
- }
149
-
150
- /** Pick a handful of distinct settled cells to glint for one sparkle frame. */
151
- function pickSparkles(matrix: Matrix, count: number, rand: () => number): Set<string> {
152
- const keys = Array.from(matrix.ranks.keys());
153
- const chosen = new Set<string>();
154
- const target = Math.min(Math.max(0, count), keys.length);
155
- for (let guard = 0; chosen.size < target && guard < target * 8; guard++) {
156
- chosen.add(keys[Math.floor(rand() * keys.length)]);
157
- }
158
- return chosen;
159
- }
160
-
161
- interface OutStream {
162
- write(chunk: string): unknown;
163
- isTTY?: boolean;
164
- }
165
-
166
- /** Whether colour output is appropriate for the given stream. */
167
- function shouldColor(stream: OutStream): boolean {
168
- if (process.env.NO_COLOR) return false;
169
- if (process.env.FORCE_COLOR) return true;
170
- return Boolean(stream && stream.isTTY);
171
- }
172
-
173
- /** The three banner modes, resolved from the ZERO_BANNER environment variable. */
174
- export type BannerMode = "off" | "static" | "shimmer";
175
-
176
- /** Resolve the banner mode from an environment-variable value. */
177
- export function resolveBannerMode(raw: string | undefined): BannerMode {
178
- const value = (raw ?? "").trim().toLowerCase();
179
- if (value === "off" || value === "0" || value === "false" || value === "none") return "off";
180
- if (value === "static" || value === "plain" || value === "no-animate") return "static";
181
- return "shimmer";
182
- }
183
-
184
- // Atomics.wait gives us a synchronous sleep without adding a dependency. The
185
- // banner renders before Pi's TUI takes over, so blocking briefly is intentional.
186
- const SLEEP_SLOT = new Int32Array(new SharedArrayBuffer(4));
187
- function sleepSync(ms: number): void {
188
- if (ms > 0) Atomics.wait(SLEEP_SLOT, 0, 0, ms);
189
- }
190
-
191
- function easeOutCubic(t: number): number {
192
- return 1 - Math.pow(1 - t, 3);
193
- }
194
-
195
- /** Options for {@link renderBanner}. */
196
- export interface RenderOptions {
197
- mode?: BannerMode;
198
- text?: string;
199
- frames?: number;
200
- frameMs?: number;
201
- /** Number of post-settle sparkle frames (shimmer mode). `0` disables it. */
202
- sparkleFrames?: number;
203
- /** Delay between sparkle frames, in milliseconds. */
204
- sparkleMs?: number;
205
- stream?: OutStream;
206
- }
207
-
208
- /**
209
- * Render the ZERO banner synchronously.
210
- *
211
- * On a non-colour stream the banner is printed plain. Otherwise the animated
212
- * mode assembles cells frame by frame, then settles on the completed wordmark.
213
- */
214
- export function renderBanner(options: RenderOptions = {}): void {
215
- const mode = options.mode ?? resolveBannerMode(process.env.ZERO_BANNER);
216
- if (mode === "off") return;
217
-
218
- const stream: OutStream = options.stream ?? process.stdout;
219
- const matrix = matrixForText(options.text ?? "ZERO");
220
-
221
- if (!shouldColor(stream)) {
222
- stream.write("\n" + bannerLines(options.text ?? "ZERO").join("\n") + "\n\n");
223
- return;
224
- }
225
-
226
- stream.write("\n" + Array.from({ length: ROWS }, () => "").join("\n") + "\n");
227
-
228
- // Repaint the six rows in place; optionally with this frame's sparkle set.
229
- const paintRows = (sparkles?: ReadonlySet<string>): void => {
230
- stream.write(`\x1b[${ROWS}A\r`);
231
- for (let r = 0; r < ROWS; r++) {
232
- stream.write("\x1b[2K" + paintMatrixLine(matrix, r, matrix.totalCells, sparkles) + "\n");
233
- }
234
- };
235
-
236
- if (mode === "shimmer") {
237
- const frames = Math.max(2, options.frames ?? 42);
238
- const frameMs = Math.max(1, options.frameMs ?? 18);
239
- for (let f = 0; f < frames; f++) {
240
- const t = easeOutCubic(f / (frames - 1));
241
- const visibleCells = Math.max(1, Math.ceil(matrix.totalCells * t));
242
- stream.write(`\x1b[${ROWS}A\r`);
243
- for (let r = 0; r < ROWS; r++) {
244
- stream.write("\x1b[2K" + paintMatrixLine(matrix, r, visibleCells) + "\n");
245
- }
246
- sleepSync(frameMs);
247
- }
248
- }
249
-
250
- // Settle on the completed wordmark.
251
- paintRows();
252
-
253
- // Sparkle pass — a few settled cells glint bright each frame, then a clean
254
- // final settle. Shimmer only; `sparkleFrames: 0` disables it.
255
- if (mode === "shimmer") {
256
- const sparkleFrames = Math.max(0, options.sparkleFrames ?? 22);
257
- const sparkleMs = Math.max(1, options.sparkleMs ?? 36);
258
- for (let f = 0; f < sparkleFrames; f++) {
259
- paintRows(pickSparkles(matrix, 3 + (f % 4), Math.random));
260
- sleepSync(sparkleMs);
261
- }
262
- if (sparkleFrames > 0) paintRows();
263
- }
264
-
265
- stream.write("\n");
266
- }
267
-
268
- /**
269
- * The pi extension entry point.
270
- *
271
- * The pi argument is accepted for API compatibility. The banner is rendered
272
- * defensively: visual sugar should never break an interactive session.
273
- */
274
- export default function register(_pi?: unknown): void {
275
- try {
276
- renderBanner();
277
- } catch {
278
- // A banner failure must never break a pi session.
279
- }
280
- }