@casualjim/pi-pretty 0.7.0 → 0.7.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.
package/README.md CHANGED
@@ -1,39 +1,27 @@
1
1
  # @casualjim/pi-pretty
2
2
 
3
3
  Fork of [@heyhuynhgiabuu/pi-pretty](https://github.com/heyhuynhgiabuu/pi-pretty)
4
- (MIT) that composes with
5
- [@casualjim/pi-heimdall](https://github.com/casualjim/pi-mimir/tree/main/packages/pi-heimdall):
6
- pretty rendering AND the heimdall sandbox on the same `bash` tool.
4
+ (MIT) trimmed to the display tools it owns.
7
5
 
8
- ## How they compose
6
+ ## What it does
9
7
 
10
- Since pi 0.87.1, two extensions registering the same tool or flag is a hard
11
- load error, so exactly one extension may own `bash`:
12
-
13
- - **pi-heimdall** owns the `bash` tool (sandboxed execute via
14
- `@casualjim/heimdall-sandbox`) and the `--no-sandbox` flag.
15
- - **pi-pretty** never registers `bash` or any flag. It exports its bash
16
- renderers from the `@casualjim/pi-pretty/bash-renderers` subpath, and
17
- pi-heimdall attaches them to its tool — so `bash` output keeps pi-pretty
18
- styling while executing through the sandbox.
8
+ Shiki-highlighted `read` previews, `ls` tree views with file-type icons,
9
+ FFF-accelerated `find`/`grep`, a prompt editor, and activity indicators.
19
10
 
20
- Load order does not matter. All other pi-pretty features (shiki `read`
21
- previews, `ls` icons, FFF-powered `find`/`grep`, working indicator, thinking
22
- shimmer) are unchanged.
11
+ ## Bash
23
12
 
24
- Trade-offs of heimdall owning `bash`:
13
+ pi-pretty does not render, register, or substitute `bash`. That tool belongs to
14
+ pi-heimdall (sandboxed execute), and each host renders bash with its own
15
+ renderer: Pi's native bash definition carries `renderCall`/`renderResult`, and
16
+ Oh My Pi attaches its own from `@oh-my-pi/pi-tui/tools`.
25
17
 
26
- - bash rows show no elapsed-time line (the sandboxed execute does not record
27
- pretty's timing metadata)
28
- - pi-pretty's extra ripgrep prompt guidance for bash is gone; the tool keeps
29
- the host SDK's description and guidelines
30
- - mid-session `/sandbox on|off` works — the toggle and the tool live in the
31
- same extension now
18
+ Since pi 0.87.1, two extensions registering the same tool or flag is a hard
19
+ load error, so heimdall owns `bash` and the `--no-sandbox` flag, and pi-pretty
20
+ never touches either. Load order does not matter.
32
21
 
33
22
  ## Install
34
23
 
35
24
  ```bash
36
- pi install git:github.com/casualjim/pi-mimir#subdirectory=packages/pi-heimdall
37
25
  pi install git:github.com/casualjim/pi-mimir#subdirectory=packages/pi-pretty
38
26
  ```
39
27
 
package/package.json CHANGED
@@ -1,71 +1,65 @@
1
1
  {
2
- "name": "@casualjim/pi-pretty",
3
- "version": "0.7.0",
4
- "description": "Pretty terminal output for pi built-in tools, composed with pi-heimdall — the bash tool renders like pi-pretty and executes through the heimdall sandbox.",
5
- "keywords": [
6
- "pi",
7
- "pi-extension",
8
- "pi-package",
9
- "pretty-print",
10
- "shiki",
11
- "syntax-highlighting",
12
- "terminal",
13
- "heimdall",
14
- "sandbox"
15
- ],
16
- "homepage": "https://github.com/casualjim/pi-mimir/tree/main/packages/pi-pretty",
17
- "license": "MIT",
18
- "author": "casualjim",
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/casualjim/pi-mimir"
22
- },
23
- "files": [
24
- "src/",
25
- "README.md",
26
- "LICENSE"
27
- ],
28
- "type": "module",
29
- "exports": {
30
- ".": "./src/index.ts",
31
- "./bash-renderers": {
32
- "types": "./src/tools/bash.d.ts",
33
- "default": "./src/tools/bash.ts"
34
- }
35
- },
36
- "engines": {
37
- "node": ">=22.0.0"
38
- },
39
- "publishConfig": {
40
- "access": "public"
41
- },
42
- "scripts": {
43
- "typecheck": "tsc --noEmit",
44
- "check:pack": "pnpm pack --dry-run",
45
- "test": "vitest run"
46
- },
47
- "pi": {
48
- "extensions": [
49
- "./src/index.ts"
50
- ]
51
- },
52
- "peerDependencies": {
53
- "@earendil-works/pi-ai": "*",
54
- "@earendil-works/pi-coding-agent": "*",
55
- "@earendil-works/pi-tui": "*"
56
- },
57
- "devDependencies": {
58
- "@earendil-works/pi-ai": "^0.87.1",
59
- "@earendil-works/pi-coding-agent": "^0.87.1",
60
- "@earendil-works/pi-tui": "^0.87.0",
61
- "@types/node": "^24.13.4",
62
- "jiti": "^2.7.0",
63
- "typescript": "^7.0.2",
64
- "vitest": "^5.0.0"
65
- },
66
- "dependencies": {
67
- "@ff-labs/fff-node": "^0.10.0",
68
- "@shikijs/cli": "^4.0.2",
69
- "shiki": "4.0.2"
70
- }
71
- }
2
+ "name": "@casualjim/pi-pretty",
3
+ "version": "0.7.1",
4
+ "description": "Pretty terminal output for pi built-in tools: shiki-highlighted read previews, ls tree with icons, FFF-accelerated find/grep, prompt editor and activity indicators.",
5
+ "keywords": [
6
+ "pi",
7
+ "pi-extension",
8
+ "pi-package",
9
+ "pretty-print",
10
+ "shiki",
11
+ "syntax-highlighting",
12
+ "terminal"
13
+ ],
14
+ "homepage": "https://github.com/casualjim/pi-mimir/tree/main/packages/pi-pretty",
15
+ "license": "MIT",
16
+ "author": "casualjim",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/casualjim/pi-mimir"
20
+ },
21
+ "files": [
22
+ "src/",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "type": "module",
27
+ "exports": {
28
+ ".": "./src/index.ts"
29
+ },
30
+ "engines": {
31
+ "node": ">=22.0.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "pi": {
37
+ "extensions": [
38
+ "./src/index.ts"
39
+ ]
40
+ },
41
+ "peerDependencies": {
42
+ "@earendil-works/pi-ai": "*",
43
+ "@earendil-works/pi-coding-agent": "*",
44
+ "@earendil-works/pi-tui": "*"
45
+ },
46
+ "devDependencies": {
47
+ "@earendil-works/pi-ai": "^0.87.1",
48
+ "@earendil-works/pi-coding-agent": "^0.87.1",
49
+ "@earendil-works/pi-tui": "^0.87.0",
50
+ "@types/node": "^24.13.4",
51
+ "jiti": "^2.7.0",
52
+ "typescript": "^7.0.2",
53
+ "vitest": "^5.0.0"
54
+ },
55
+ "dependencies": {
56
+ "@ff-labs/fff-node": "^0.10.0",
57
+ "@shikijs/cli": "^4.0.2",
58
+ "shiki": "4.0.2"
59
+ },
60
+ "scripts": {
61
+ "typecheck": "tsc --noEmit",
62
+ "check:pack": "pnpm pack --dry-run",
63
+ "test": "vitest run"
64
+ }
65
+ }
package/src/helpers.ts CHANGED
@@ -9,21 +9,14 @@ import { relative } from "node:path";
9
9
  // ---------------------------------------------------------------------------
10
10
 
11
11
  export function normalizeLineEndings(text: string): string {
12
- return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
12
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
13
13
  }
14
14
 
15
15
  export function shortPath(cwd: string, home: string, p: string): string {
16
- if (!p) return "";
17
- const r = relative(cwd, p);
18
- if (!r.startsWith("..") && !r.startsWith("/")) return r;
19
- return p.replace(home, "~");
20
- }
21
-
22
- export function stripBashExitStatusLine(text: string): string {
23
- return normalizeLineEndings(text)
24
- .split("\n")
25
- .filter((line) => !/^Command exited with code \d+$/i.test(line.trim()))
26
- .join("\n");
16
+ if (!p) return "";
17
+ const r = relative(cwd, p);
18
+ if (!r.startsWith("..") && !r.startsWith("/")) return r;
19
+ return p.replace(home, "~");
27
20
  }
28
21
 
29
22
  // ---------------------------------------------------------------------------
@@ -31,45 +24,34 @@ export function stripBashExitStatusLine(text: string): string {
31
24
  // ---------------------------------------------------------------------------
32
25
 
33
26
  export function formatElapsedMs(ms: number | undefined): string {
34
- if (typeof ms !== "number" || !Number.isFinite(ms)) return "";
35
- if (ms < 1000) return `${Math.round(ms)}ms`;
36
- const s = ms / 1000;
37
- return s < 10 ? `${s.toFixed(1)}s` : `${Math.round(s)}s`;
27
+ if (typeof ms !== "number" || !Number.isFinite(ms)) return "";
28
+ if (ms < 1000) return `${Math.round(ms)}ms`;
29
+ const s = ms / 1000;
30
+ return s < 10 ? `${s.toFixed(1)}s` : `${Math.round(s)}s`;
38
31
  }
39
32
 
40
33
  export function formatCharCount(chars: number | undefined): string {
41
- if (typeof chars !== "number" || !Number.isFinite(chars) || chars <= 0) return "";
42
- if (chars < 1000) return `${chars} chars`;
43
- if (chars < 10_000) return `${(chars / 1000).toFixed(1)}k chars`;
44
- return `${Math.round(chars / 1000)}k chars`;
34
+ if (typeof chars !== "number" || !Number.isFinite(chars) || chars <= 0) return "";
35
+ if (chars < 1000) return `${chars} chars`;
36
+ if (chars < 10_000) return `${(chars / 1000).toFixed(1)}k chars`;
37
+ return `${Math.round(chars / 1000)}k chars`;
45
38
  }
46
39
 
47
40
  export const ELAPSED_KEY = "__prettyElapsedMs";
48
41
  export const CHARS_KEY = "__prettyOutputChars";
49
42
 
50
- // ---------------------------------------------------------------------------
51
- // Infer bash exit code
52
- // ---------------------------------------------------------------------------
53
-
54
- export function inferBashExitCode(text: string, fallback: number | null): number | null {
55
- const exitMatch = text.match(/(?:exit code|exited with(?: code)?|exit status)[:\s]*(\d+)/i);
56
- if (exitMatch) return Number(exitMatch[1]);
57
- if (text.includes("command not found") || text.includes("No such file")) return 1;
58
- return fallback;
59
- }
60
-
61
43
  // ---------------------------------------------------------------------------
62
44
  // Compact error lines
63
45
  // ---------------------------------------------------------------------------
64
46
 
65
47
  export function compactErrorLines(error: string): string[] {
66
- const compactedLines: string[] = [];
67
- let previousBlank = false;
68
- for (const line of normalizeLineEndings(error).trim().split("\n")) {
69
- const isBlank = line.trim() === "";
70
- if (isBlank && previousBlank) continue;
71
- compactedLines.push(line);
72
- previousBlank = isBlank;
73
- }
74
- return compactedLines;
48
+ const compactedLines: string[] = [];
49
+ let previousBlank = false;
50
+ for (const line of normalizeLineEndings(error).trim().split("\n")) {
51
+ const isBlank = line.trim() === "";
52
+ if (isBlank && previousBlank) continue;
53
+ compactedLines.push(line);
54
+ previousBlank = isBlank;
55
+ }
56
+ return compactedLines;
75
57
  }