@wierdbytes/pi-facelift 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 +87 -0
- package/bash-rendering.test.ts +169 -0
- package/image-rendering.test.ts +153 -0
- package/index.ts +1560 -0
- package/media/demo.png +0 -0
- package/package.json +69 -0
- package/scripts/demo.ts +359 -0
package/media/demo.png
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wierdbytes/pi-facelift",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cosmetic facelift for built-in pi tool output — open-right rounded frames, syntax-highlighted reads, status-aware bash summaries, find/grep.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"*.ts",
|
|
8
|
+
"*.md",
|
|
9
|
+
"*.json",
|
|
10
|
+
"LICENSE",
|
|
11
|
+
"media/**",
|
|
12
|
+
"scripts/**"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"pi-package",
|
|
16
|
+
"pi",
|
|
17
|
+
"coding-agent",
|
|
18
|
+
"extension",
|
|
19
|
+
"tui",
|
|
20
|
+
"syntax-highlighting",
|
|
21
|
+
"shiki",
|
|
22
|
+
"pretty",
|
|
23
|
+
"facelift"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "wierdbytes",
|
|
27
|
+
"homepage": "https://github.com/wierdbytes/pi-wierd-stuff/tree/master/packages/facelift",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/wierdbytes/pi-wierd-stuff.git",
|
|
31
|
+
"directory": "packages/facelift"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/wierdbytes/pi-wierd-stuff/issues"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"main": "./index.ts",
|
|
40
|
+
"types": "./index.ts",
|
|
41
|
+
"exports": {
|
|
42
|
+
".": "./index.ts"
|
|
43
|
+
},
|
|
44
|
+
"pi": {
|
|
45
|
+
"extensions": [
|
|
46
|
+
"./index.ts"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"test:watch": "vitest",
|
|
52
|
+
"demo": "bun scripts/demo.ts"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@shikijs/cli": "^4.0.2"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@earendil-works/pi-ai": ">=0.74.0",
|
|
59
|
+
"@earendil-works/pi-coding-agent": ">=0.74.0",
|
|
60
|
+
"@earendil-works/pi-tui": ">=0.74.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@earendil-works/pi-ai": "^0.74.0",
|
|
64
|
+
"@earendil-works/pi-coding-agent": "^0.74.0",
|
|
65
|
+
"@earendil-works/pi-tui": "^0.74.0",
|
|
66
|
+
"shiki": "^4.0.2",
|
|
67
|
+
"vitest": "^4.0.18"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/scripts/demo.ts
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* scripts/demo.ts — visual smoke harness for @wierdbytes/pi-facelift.
|
|
4
|
+
*
|
|
5
|
+
* Renders every tool block (read with shiki highlighting, bash in
|
|
6
|
+
* success / non-zero / streaming / timeout states, ls tree, find groups,
|
|
7
|
+
* grep matches) directly to your terminal so you can eyeball the
|
|
8
|
+
* open-right rounded frame, the status-aware coloring, and the
|
|
9
|
+
* duration/exit summary in the bottom border.
|
|
10
|
+
*
|
|
11
|
+
* Run from the package root with:
|
|
12
|
+
*
|
|
13
|
+
* bun scripts/demo.ts
|
|
14
|
+
*
|
|
15
|
+
* or via the npm script:
|
|
16
|
+
*
|
|
17
|
+
* bun run demo
|
|
18
|
+
*/
|
|
19
|
+
/* eslint-disable no-console */
|
|
20
|
+
|
|
21
|
+
import piFaceliftExtension, { type PiFaceliftDeps } from "../index.ts";
|
|
22
|
+
|
|
23
|
+
// ── mock pi infrastructure ───────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
class MockText {
|
|
26
|
+
private text = "";
|
|
27
|
+
constructor(_text = "", _x = 0, _y = 0) {}
|
|
28
|
+
setText(value: string): void {
|
|
29
|
+
this.text = value;
|
|
30
|
+
}
|
|
31
|
+
getText(): string {
|
|
32
|
+
return this.text;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ANSI = {
|
|
37
|
+
reset: "\x1b[0m",
|
|
38
|
+
bold: "\x1b[1m",
|
|
39
|
+
unbold: "\x1b[22m",
|
|
40
|
+
toolTitle: "\x1b[1;37m",
|
|
41
|
+
accent: "\x1b[36m",
|
|
42
|
+
muted: "\x1b[90m",
|
|
43
|
+
dim: "\x1b[2m",
|
|
44
|
+
error: "\x1b[31m",
|
|
45
|
+
warning: "\x1b[33m",
|
|
46
|
+
success: "\x1b[32m",
|
|
47
|
+
toolOutput: "\x1b[37m",
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const theme = {
|
|
51
|
+
fg: (key: string, text: string): string => {
|
|
52
|
+
const c = (ANSI as Record<string, string>)[key] ?? "";
|
|
53
|
+
return `${c}${text}${ANSI.reset}`;
|
|
54
|
+
},
|
|
55
|
+
bold: (text: string): string => `${ANSI.bold}${text}${ANSI.unbold}`,
|
|
56
|
+
bg: (_key: string, text: string): string => text,
|
|
57
|
+
getBgAnsi: (): string | undefined => undefined,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type MockExec = (
|
|
61
|
+
tid: string,
|
|
62
|
+
params: unknown,
|
|
63
|
+
signal?: unknown,
|
|
64
|
+
upd?: unknown,
|
|
65
|
+
ctx?: unknown,
|
|
66
|
+
) => Promise<{
|
|
67
|
+
content: Array<{ type: string; text?: string }>;
|
|
68
|
+
isError?: boolean;
|
|
69
|
+
details?: unknown;
|
|
70
|
+
}>;
|
|
71
|
+
|
|
72
|
+
const noopExec: MockExec = async () => ({ content: [{ type: "text", text: "" }] });
|
|
73
|
+
|
|
74
|
+
function mockToolFactory(exec: MockExec) {
|
|
75
|
+
// `as any` because pi-coding-agent types `content[].type` as the literal
|
|
76
|
+
// `"text" | "image"`. We're feeding hand-built fixtures here, not real
|
|
77
|
+
// tool output, so we widen the cast at the boundary instead of carrying
|
|
78
|
+
// the typed literals everywhere.
|
|
79
|
+
return ((_cwd: string) => ({
|
|
80
|
+
name: "mock",
|
|
81
|
+
description: "mock",
|
|
82
|
+
parameters: { type: "object", properties: {} },
|
|
83
|
+
execute: exec,
|
|
84
|
+
})) as any;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function loadTools(execMap: Partial<Record<"read" | "bash" | "ls" | "find" | "grep", MockExec>> = {}) {
|
|
88
|
+
const tools = new Map<string, any>();
|
|
89
|
+
const pi = {
|
|
90
|
+
registerTool: (t: any) => tools.set(t.name, t),
|
|
91
|
+
registerCommand: () => {},
|
|
92
|
+
on: () => {},
|
|
93
|
+
};
|
|
94
|
+
const deps: PiFaceliftDeps = {
|
|
95
|
+
sdk: {
|
|
96
|
+
createReadToolDefinition: mockToolFactory(execMap.read ?? noopExec),
|
|
97
|
+
createBashToolDefinition: mockToolFactory(execMap.bash ?? noopExec),
|
|
98
|
+
createLsToolDefinition: mockToolFactory(execMap.ls ?? noopExec),
|
|
99
|
+
createFindToolDefinition: mockToolFactory(execMap.find ?? noopExec),
|
|
100
|
+
createGrepToolDefinition: mockToolFactory(execMap.grep ?? noopExec),
|
|
101
|
+
getAgentDir: () => "/tmp/pi-facelift-demo",
|
|
102
|
+
},
|
|
103
|
+
TextComponent: MockText as any,
|
|
104
|
+
};
|
|
105
|
+
piFaceliftExtension(pi, deps);
|
|
106
|
+
return tools;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── render context helpers ───────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
interface DemoRenderCtx {
|
|
112
|
+
lastComponent?: MockText;
|
|
113
|
+
state: Record<string, unknown>;
|
|
114
|
+
expanded: boolean;
|
|
115
|
+
isError: boolean;
|
|
116
|
+
isPartial?: boolean;
|
|
117
|
+
executionStarted?: boolean;
|
|
118
|
+
invalidate: () => void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function makeCtx(overrides: Partial<DemoRenderCtx> = {}): DemoRenderCtx {
|
|
122
|
+
return {
|
|
123
|
+
lastComponent: new MockText(),
|
|
124
|
+
state: {},
|
|
125
|
+
expanded: false,
|
|
126
|
+
isError: false,
|
|
127
|
+
isPartial: false,
|
|
128
|
+
executionStarted: true,
|
|
129
|
+
invalidate: () => {},
|
|
130
|
+
...overrides,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Wait until the renderer's async pipeline (e.g. shiki) calls
|
|
135
|
+
// ctx.invalidate(), then re-render to pick up the cached output.
|
|
136
|
+
async function renderAsync(
|
|
137
|
+
tool: any,
|
|
138
|
+
method: "renderResult",
|
|
139
|
+
args: unknown[],
|
|
140
|
+
ctx: DemoRenderCtx,
|
|
141
|
+
timeoutMs = 1500,
|
|
142
|
+
): Promise<MockText> {
|
|
143
|
+
let resolve!: () => void;
|
|
144
|
+
const inv = new Promise<void>((r) => {
|
|
145
|
+
resolve = r;
|
|
146
|
+
});
|
|
147
|
+
const renderCtx = { ...ctx, invalidate: () => resolve() };
|
|
148
|
+
(tool[method] as any)(...args, theme, renderCtx);
|
|
149
|
+
await Promise.race([inv, new Promise<void>((r) => setTimeout(r, timeoutMs))]);
|
|
150
|
+
const final = new MockText();
|
|
151
|
+
(tool[method] as any)(...args, theme, { ...renderCtx, lastComponent: final });
|
|
152
|
+
return final;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function header(title: string): void {
|
|
156
|
+
const w = Math.min(process.stdout.columns ?? 80, 100);
|
|
157
|
+
const bar = "═".repeat(Math.max(2, w - title.length - 4));
|
|
158
|
+
console.log(`\n${ANSI.bold}${ANSI.dim}══ ${title} ${bar}${ANSI.reset}\n`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ── individual demos ─────────────────────────────────────────────────────────
|
|
162
|
+
|
|
163
|
+
async function demoRead(): Promise<void> {
|
|
164
|
+
header("read — syntax-highlighted file with line numbers");
|
|
165
|
+
const sample = [
|
|
166
|
+
`import { foo } from "./bar.ts";`,
|
|
167
|
+
``,
|
|
168
|
+
`/** Greet someone. */`,
|
|
169
|
+
`export function greet(name: string): void {`,
|
|
170
|
+
" console.log(`Hello, ${name}!`);",
|
|
171
|
+
`}`,
|
|
172
|
+
``,
|
|
173
|
+
`greet("world");`,
|
|
174
|
+
].join("\n");
|
|
175
|
+
const tools = loadTools({
|
|
176
|
+
read: async () => ({ content: [{ type: "text", text: sample }] }),
|
|
177
|
+
});
|
|
178
|
+
const read = tools.get("read");
|
|
179
|
+
const callCtx = makeCtx();
|
|
180
|
+
console.log(read.renderCall({ path: "src/example.ts" }, theme, callCtx).getText());
|
|
181
|
+
|
|
182
|
+
const result = await read.execute("t1", { path: "src/example.ts" }, undefined, undefined, {});
|
|
183
|
+
const resCtx = makeCtx();
|
|
184
|
+
const out = await renderAsync(read, "renderResult", [result, { isPartial: false, expanded: false }], resCtx);
|
|
185
|
+
console.log(out.getText());
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function demoBashSuccess(): Promise<void> {
|
|
189
|
+
header("bash date — success (green, ✓ exit 0)");
|
|
190
|
+
const tools = loadTools({
|
|
191
|
+
bash: async () => ({
|
|
192
|
+
content: [{ type: "text", text: "Fri May 8 19:07:33 CEST 2026" }],
|
|
193
|
+
details: { _type: "bashResult", text: "Fri May 8 19:07:33 CEST 2026", exitCode: 0, command: "date" },
|
|
194
|
+
}),
|
|
195
|
+
});
|
|
196
|
+
const bash = tools.get("bash");
|
|
197
|
+
const state: { startedAt?: number; endedAt?: number } = { startedAt: Date.now() - 3300 };
|
|
198
|
+
const callCtx = makeCtx({ state });
|
|
199
|
+
console.log(bash.renderCall({ command: "date" }, theme, callCtx).getText());
|
|
200
|
+
const result = await bash.execute("t1", { command: "date" }, undefined, undefined, {});
|
|
201
|
+
state.endedAt = Date.now();
|
|
202
|
+
const resCtx = makeCtx({ state });
|
|
203
|
+
console.log(
|
|
204
|
+
bash.renderResult(result, { isPartial: false, expanded: false }, theme, resCtx).getText(),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function demoBashError(): Promise<void> {
|
|
209
|
+
header("bash false — non-zero exit (red, ✗ exit 1)");
|
|
210
|
+
const tools = loadTools();
|
|
211
|
+
const bash = tools.get("bash");
|
|
212
|
+
const state = { startedAt: Date.now() - 200, endedAt: Date.now() };
|
|
213
|
+
const result = {
|
|
214
|
+
isError: true,
|
|
215
|
+
content: [{ type: "text", text: "(no output)\n\nCommand exited with code 1" }],
|
|
216
|
+
details: undefined,
|
|
217
|
+
};
|
|
218
|
+
const callCtx = makeCtx({ state, isError: true });
|
|
219
|
+
console.log(bash.renderCall({ command: "false" }, theme, callCtx).getText());
|
|
220
|
+
const resCtx = makeCtx({ state, isError: true });
|
|
221
|
+
console.log(
|
|
222
|
+
bash.renderResult(result, { isPartial: false, expanded: false }, theme, resCtx).getText(),
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function demoBashStreaming(): Promise<void> {
|
|
227
|
+
header("bash sleep 5 — streaming (yellow, live counter)");
|
|
228
|
+
const tools = loadTools();
|
|
229
|
+
const bash = tools.get("bash");
|
|
230
|
+
const state = { startedAt: Date.now() - 3300 };
|
|
231
|
+
const callCtx = makeCtx({ state, isPartial: true });
|
|
232
|
+
console.log(bash.renderCall({ command: "sleep 5" }, theme, callCtx).getText());
|
|
233
|
+
const result = { content: [{ type: "text", text: "" }] };
|
|
234
|
+
const resCtx = makeCtx({ state, isPartial: true });
|
|
235
|
+
console.log(
|
|
236
|
+
bash.renderResult(result, { isPartial: true, expanded: false }, theme, resCtx).getText(),
|
|
237
|
+
);
|
|
238
|
+
// renderResult installs a setInterval(invalidate, 1000) while partial.
|
|
239
|
+
if ((state as any).interval) clearInterval((state as any).interval);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function demoBashTimeout(): Promise<void> {
|
|
243
|
+
header("bash sleep 60 (5s timeout) — ⚡ timed out");
|
|
244
|
+
const tools = loadTools();
|
|
245
|
+
const bash = tools.get("bash");
|
|
246
|
+
const state = { startedAt: Date.now() - 5400, endedAt: Date.now() };
|
|
247
|
+
const result = {
|
|
248
|
+
isError: true,
|
|
249
|
+
content: [
|
|
250
|
+
{ type: "text", text: "partial output line\n\nCommand timed out after 5 seconds" },
|
|
251
|
+
],
|
|
252
|
+
};
|
|
253
|
+
const callCtx = makeCtx({ state, isError: true });
|
|
254
|
+
console.log(
|
|
255
|
+
bash.renderCall({ command: "sleep 60", timeout: 5 }, theme, callCtx).getText(),
|
|
256
|
+
);
|
|
257
|
+
const resCtx = makeCtx({ state, isError: true });
|
|
258
|
+
console.log(
|
|
259
|
+
bash.renderResult(result, { isPartial: false, expanded: false }, theme, resCtx).getText(),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function demoLs(): Promise<void> {
|
|
264
|
+
header("ls — tree view with Nerd Font icons");
|
|
265
|
+
const tools = loadTools({
|
|
266
|
+
ls: async () => ({
|
|
267
|
+
content: [
|
|
268
|
+
{
|
|
269
|
+
type: "text",
|
|
270
|
+
text: [
|
|
271
|
+
"index.ts",
|
|
272
|
+
"package.json",
|
|
273
|
+
"README.md",
|
|
274
|
+
"media/",
|
|
275
|
+
"scripts/",
|
|
276
|
+
].join("\n"),
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
}),
|
|
280
|
+
});
|
|
281
|
+
const ls = tools.get("ls");
|
|
282
|
+
const callCtx = makeCtx();
|
|
283
|
+
console.log(ls.renderCall({ path: "." }, theme, callCtx).getText());
|
|
284
|
+
const result = await ls.execute("t1", { path: "." }, undefined, undefined, {});
|
|
285
|
+
const resCtx = makeCtx();
|
|
286
|
+
console.log(ls.renderResult(result, { isPartial: false, expanded: false }, theme, resCtx).getText());
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function demoFind(): Promise<void> {
|
|
290
|
+
header('find pattern="*.ts" — grouped with file-type icons');
|
|
291
|
+
const tools = loadTools({
|
|
292
|
+
find: async () => ({
|
|
293
|
+
content: [
|
|
294
|
+
{
|
|
295
|
+
type: "text",
|
|
296
|
+
text: [
|
|
297
|
+
"index.ts",
|
|
298
|
+
"bash-rendering.test.ts",
|
|
299
|
+
"image-rendering.test.ts",
|
|
300
|
+
"scripts/demo.ts",
|
|
301
|
+
].join("\n"),
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
}),
|
|
305
|
+
});
|
|
306
|
+
const find = tools.get("find");
|
|
307
|
+
const callCtx = makeCtx();
|
|
308
|
+
console.log(find.renderCall({ pattern: "*.ts" }, theme, callCtx).getText());
|
|
309
|
+
const result = await find.execute("t1", { pattern: "*.ts" }, undefined, undefined, {});
|
|
310
|
+
const resCtx = makeCtx();
|
|
311
|
+
console.log(find.renderResult(result, { isPartial: false, expanded: false }, theme, resCtx).getText());
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function demoGrep(): Promise<void> {
|
|
315
|
+
header('grep pattern="renderResult" — highlighted matches');
|
|
316
|
+
const grepText = [
|
|
317
|
+
"index.ts:1340: renderResult(result, opt, theme, ctx) {",
|
|
318
|
+
"index.ts:1410: renderResult(result, opt, theme, ctx) {",
|
|
319
|
+
"index.ts:1488: renderResult(",
|
|
320
|
+
"index.ts:1570: renderResult(",
|
|
321
|
+
].join("\n");
|
|
322
|
+
const tools = loadTools({
|
|
323
|
+
grep: async () => ({ content: [{ type: "text", text: grepText }] }),
|
|
324
|
+
});
|
|
325
|
+
const grep = tools.get("grep");
|
|
326
|
+
const callCtx = makeCtx();
|
|
327
|
+
console.log(grep.renderCall({ pattern: "renderResult" }, theme, callCtx).getText());
|
|
328
|
+
const result = await grep.execute("t1", { pattern: "renderResult" }, undefined, undefined, {});
|
|
329
|
+
const resCtx = makeCtx();
|
|
330
|
+
const out = await renderAsync(grep, "renderResult", [result, { isPartial: false, expanded: false }], resCtx);
|
|
331
|
+
console.log(out.getText());
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// ── main ─────────────────────────────────────────────────────────────────────
|
|
335
|
+
|
|
336
|
+
async function main(): Promise<void> {
|
|
337
|
+
const cols = process.stdout.columns ?? 80;
|
|
338
|
+
console.log(
|
|
339
|
+
`${ANSI.bold}@wierdbytes/pi-facelift${ANSI.reset} demo · terminal width ${cols} cols\n`,
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
await demoRead();
|
|
343
|
+
await demoBashSuccess();
|
|
344
|
+
await demoBashError();
|
|
345
|
+
await demoBashStreaming();
|
|
346
|
+
await demoBashTimeout();
|
|
347
|
+
await demoLs();
|
|
348
|
+
await demoFind();
|
|
349
|
+
await demoGrep();
|
|
350
|
+
|
|
351
|
+
console.log(`\n${ANSI.dim}Done. (Resize your terminal and re-run to verify wide / narrow layouts.)${ANSI.reset}`);
|
|
352
|
+
// Exit cleanly even if a stray timer is still pending.
|
|
353
|
+
process.exit(0);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
main().catch((err) => {
|
|
357
|
+
console.error(err);
|
|
358
|
+
process.exit(1);
|
|
359
|
+
});
|