@giladbarnea/pi-pretty-bash 1.0.3 → 1.0.4

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 (3) hide show
  1. package/README.md +7 -3
  2. package/index.ts +22 -12
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ ---
2
+ last_updated: 2026-10-25T20-28
3
+ ---
4
+
1
5
  <div align="center">
2
6
 
3
7
  # pi-pretty-bash
@@ -27,15 +31,15 @@ Start a new Pi session, or run `/reload` in the current session. Every later Bas
27
31
 
28
32
  ## Bash commands and JSON output get syntax colors
29
33
 
30
- The extension starts from Pi's complete built-in Bash definition. It highlights the visible command with Pi's Bash colors.
34
+ The extension registers Bash renderers through Pi's `registerToolRenderer()` API without replacing Bash parameters or execution. It highlights the visible command with Pi's Bash colors.
31
35
 
32
- After a command finishes, the extension checks its complete output with `JSON.parse()`. Valid JSON gets Pi's JSON colors without reformatting. All other output keeps Pi's built-in rendering.
36
+ After a command finishes, valid JSON up to 200 KiB gets Pi's JSON colors without reformatting. Larger output keeps Pi's native rendering without cutting its content. All other output keeps Pi's built-in rendering.
33
37
 
34
38
  Pi still owns command execution, streaming output, timing, truncation, expansion, and error display.
35
39
 
36
40
  ## Compatibility
37
41
 
38
- `pi-pretty-bash` requires Pi `0.99.2` or newer.
42
+ `pi-pretty-bash` targets Pi `1.4.*`. Other extensions can own the Bash tool and add parameters without changing this rendering.
39
43
 
40
44
  ## License
41
45
 
package/index.ts CHANGED
@@ -2,10 +2,13 @@ import {
2
2
  createBashToolDefinition,
3
3
  highlightCode,
4
4
  truncateToVisualLines,
5
+ type BashToolDetails,
5
6
  type ExtensionAPI,
7
+ type ToolRenderers,
6
8
  } from "@earendil-works/pi-coding-agent";
7
9
 
8
10
  const BASH_PREVIEW_LINES = 5;
11
+ const JSON_HIGHLIGHT_MAX_BYTES = 200 * 1024;
9
12
 
10
13
  interface RenderComponent {
11
14
  render(width: number): string[];
@@ -32,7 +35,7 @@ function isJson(output: string): boolean {
32
35
  }
33
36
 
34
37
  export default function prettyBash(pi: ExtensionAPI): void {
35
- const bashTool = createBashToolDefinition(process.cwd());
38
+ const bashTool = createBashToolDefinition(process.cwd()) as ToolRenderers;
36
39
  const renderBashCall = bashTool.renderCall;
37
40
  const renderBashResult = bashTool.renderResult;
38
41
 
@@ -43,22 +46,21 @@ export default function prettyBash(pi: ExtensionAPI): void {
43
46
  throw new Error("Pi's Bash tool has no result renderer");
44
47
  }
45
48
 
46
- pi.registerTool({
47
- ...bashTool,
48
-
49
+ const renderers: ToolRenderers = {
49
50
  renderCall(arguments_, theme, context) {
50
51
  const component = renderBashCall(arguments_, theme, context);
51
52
  if (!("setText" in component) || typeof component.setText !== "function") {
52
53
  throw new Error("Pi's Bash call renderer no longer returns mutable text");
53
54
  }
54
55
 
55
- const command = typeof arguments_.command === "string" ? arguments_.command : "";
56
+ const callArguments = arguments_ as Record<string, unknown>;
57
+ const command = typeof callArguments.command === "string" ? callArguments.command : "";
56
58
  const renderedCommand = command
57
59
  ? highlightCode(command, "bash").join("\n")
58
60
  : theme.fg("toolOutput", "...");
59
61
  const timeout =
60
- typeof arguments_.timeout === "number"
61
- ? theme.fg("muted", ` (timeout ${arguments_.timeout}s)`)
62
+ typeof callArguments.timeout === "number"
63
+ ? theme.fg("muted", ` (timeout ${callArguments.timeout}s)`)
62
64
  : "";
63
65
 
64
66
  component.setText(`${theme.fg("toolTitle", theme.bold("$"))} ${renderedCommand}${timeout}`);
@@ -69,10 +71,14 @@ export default function prettyBash(pi: ExtensionAPI): void {
69
71
  const component = renderBashResult(result, options, theme, context);
70
72
  const output = result.content
71
73
  .map((content) => (content.type === "text" ? content.text : ""))
72
- .join("\n")
73
- .trim();
74
+ .join("\n");
75
+ const details = result.details as BashToolDetails | undefined;
74
76
  const shouldHighlight =
75
- !options.isPartial && !result.details?.truncation?.truncated && isJson(output);
77
+ !options.isPartial &&
78
+ !details?.truncation?.truncated &&
79
+ output.length <= JSON_HIGHLIGHT_MAX_BYTES &&
80
+ Buffer.byteLength(output, "utf8") <= JSON_HIGHLIGHT_MAX_BYTES &&
81
+ isJson(output);
76
82
 
77
83
  if (!shouldHighlight) {
78
84
  return component;
@@ -85,7 +91,7 @@ export default function prettyBash(pi: ExtensionAPI): void {
85
91
 
86
92
  const outputComponent = component.children[outputIndex];
87
93
  const renderOutput = outputComponent.render.bind(outputComponent);
88
- const highlightedOutput = highlightCode(output, "json").join("\n");
94
+ const highlightedOutput = highlightCode(output.trim(), "json").join("\n");
89
95
  const maxVisualLines = options.expanded ? Number.POSITIVE_INFINITY : BASH_PREVIEW_LINES;
90
96
 
91
97
  outputComponent.render = (width) => {
@@ -106,5 +112,9 @@ export default function prettyBash(pi: ExtensionAPI): void {
106
112
 
107
113
  return component;
108
114
  },
109
- });
115
+ };
116
+
117
+ pi.registerToolRenderer((toolName, next) =>
118
+ toolName === "bash" ? { ...next(), ...renderers } : next(),
119
+ );
110
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-pretty-bash",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "Syntax-highlight Bash tool calls and JSON output in Pi's TUI.",
6
6
  "keywords": [
@@ -28,7 +28,7 @@
28
28
  "screenshots/1.png"
29
29
  ],
30
30
  "peerDependencies": {
31
- "@earendil-works/pi-coding-agent": ">=0.99.2"
31
+ "@earendil-works/pi-coding-agent": "1.4.*"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
@@ -39,7 +39,7 @@
39
39
  ]
40
40
  },
41
41
  "devDependencies": {
42
- "@earendil-works/pi-coding-agent": "1.1.0"
42
+ "@earendil-works/pi-coding-agent": "1.4.*"
43
43
  },
44
44
  "scripts": {
45
45
  "test": "node --test test/*.test.mjs"