@xynogen/pix-pretty 1.30.0 → 1.31.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/package.json +1 -1
- package/src/chips.ts +6 -3
- package/src/highlight.ts +41 -0
- package/src/shell-tool.ts +2 -1
- package/src/types.ts +2 -0
- package/src/utils.ts +14 -2
package/package.json
CHANGED
package/src/chips.ts
CHANGED
|
@@ -51,7 +51,9 @@ type PiEditor = {
|
|
|
51
51
|
/** A text paste becomes a chip only above this many characters (Pi's own limit is 1000). */
|
|
52
52
|
const PASTE_MAX_CHARS = 100;
|
|
53
53
|
const MARKER = /\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]/g;
|
|
54
|
-
|
|
54
|
+
// Zero-width codes the editor may put inside a marker: SGR, the cursor marker, and
|
|
55
|
+
// pi-tui 1.4's fake-cursor APC pair (`\x1b_pi:fc\x07` … `\x1b_pi:/fc\x07`).
|
|
56
|
+
const SGR = "(?:\\x1b\\[[0-9;]*m|\\x1b_pi:(?:c|/?fc)\\x07)*";
|
|
55
57
|
const PASTE_SPAN = new RegExp(`${SGR}\\[${SGR}paste #(?:[^\\]]|${SGR})*\\]`, "g");
|
|
56
58
|
const PATH_TAG = /<path>([^<]+)<\/path>/g;
|
|
57
59
|
/** Matches `chipTag.skill` output. Group 1 is the ref. */
|
|
@@ -60,7 +62,7 @@ const PASTE_TAG = /<paste>([\s\S]*?)<\/paste>/g;
|
|
|
60
62
|
// Injected prompt from another extension (e.g. /plan). Kept as a tag for the model.
|
|
61
63
|
const PROMPT_TAG = /<prompt name="([\w-]+)">([\s\S]*?)<\/prompt>/g;
|
|
62
64
|
const PROMPT_ONLY = /^<prompt name="[\w-]+">[\s\S]*<\/prompt>\s*$/;
|
|
63
|
-
const CODES = /\x1b\[[0-9;]*m|\x1b_pi:c\x07/g;
|
|
65
|
+
const CODES = /\x1b\[[0-9;]*m|\x1b_pi:(?:c|\/?fc)\x07/g;
|
|
64
66
|
const IMAGE_PATH =
|
|
65
67
|
/(^|[^\w/@])((?:~|[a-zA-Z]:[/\\]|\/|\\\\)[^\s,;'"(){}[\]]+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif))(?=$|[\s,;'"(){}[\]])/gi;
|
|
66
68
|
|
|
@@ -79,7 +81,8 @@ export function expandChips(text: string, registry: Registry): string {
|
|
|
79
81
|
/** Re-emit the cursor (inverse video + TUI marker) that a chip swallowed. */
|
|
80
82
|
function keepCursor(span: string, label: string): string {
|
|
81
83
|
const marker = span.includes(CURSOR_MARKER) ? CURSOR_MARKER : "";
|
|
82
|
-
|
|
84
|
+
// pi-tui <1.4 drew the cursor as inverse video; 1.4 wraps it in fake-cursor APC markers.
|
|
85
|
+
return span.includes("\x1b[7m") || span.includes("\x1b_pi:fc\x07")
|
|
83
86
|
? `${marker}\x1b[7m${label.replaceAll(RST, `${RST}\x1b[7m`)}\x1b[27m`
|
|
84
87
|
: marker + label;
|
|
85
88
|
}
|
package/src/highlight.ts
CHANGED
|
@@ -35,11 +35,52 @@ function forceChalkColor(): void {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// highlight.js bash only colors shell builtins, so `sleep`, `df`, `tail` stay plain.
|
|
39
|
+
// Add the standard external commands to its built_in list.
|
|
40
|
+
export const BASH_COMMANDS =
|
|
41
|
+
"awk basename cat chgrp chmod chown cp curl cut date dd df diff dirname du env file find " +
|
|
42
|
+
"free git grep gzip head hostname id kill ln ls mkdir mktemp mv nohup pgrep pkill ps rm " +
|
|
43
|
+
"rmdir sed seq sleep sort ssh scp tail tar tee touch tr uname uniq wc which whoami xargs";
|
|
44
|
+
|
|
45
|
+
// Windows native executables plus common cross-platform CLIs. highlight.js powershell
|
|
46
|
+
// only knows cmdlets and aliases, so `ipconfig` or `git` would stay plain.
|
|
47
|
+
export const POWERSHELL_COMMANDS =
|
|
48
|
+
"arp assoc attrib bcdedit certutil chkdsk choco cipher clip cmd cmdkey cscript curl diskpart " +
|
|
49
|
+
"docker driverquery fc find findstr format fsutil ftp getmac git gpresult gpupdate hostname " +
|
|
50
|
+
"icacls ipconfig klist logoff make msiexec nbtstat net netsh netstat nltest node npm npx " +
|
|
51
|
+
"nslookup pathping pip ping pnpm powercfg powershell pwsh python reg regsvr32 robocopy route " +
|
|
52
|
+
"scoop sfc shutdown ssh scp systeminfo takeown taskkill tasklist tar tracert tree uv " +
|
|
53
|
+
"w32tm wevtutil where whoami winget wmic xcopy bun cargo go yarn";
|
|
54
|
+
|
|
55
|
+
// ponytail: reach the highlight.js instance cli-highlight already loaded instead of
|
|
56
|
+
// declaring a second dependency. Pin highlight.js directly if cli-highlight drops it.
|
|
57
|
+
function extendBuiltIns(): void {
|
|
58
|
+
try {
|
|
59
|
+
const { createRequire } = require("node:module") as typeof import("node:module");
|
|
60
|
+
const sub = createRequire(require.resolve("cli-highlight"));
|
|
61
|
+
const hljs = sub("highlight.js");
|
|
62
|
+
for (const [name, commands] of [
|
|
63
|
+
["bash", BASH_COMMANDS],
|
|
64
|
+
["powershell", POWERSHELL_COMMANDS],
|
|
65
|
+
] as const) {
|
|
66
|
+
const grammar = sub(`highlight.js/lib/languages/${name}`);
|
|
67
|
+
hljs.registerLanguage(name, (h: unknown) => {
|
|
68
|
+
const def = grammar(h);
|
|
69
|
+
def.keywords.built_in += ` ${commands}`;
|
|
70
|
+
return def;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
/* keep the stock grammars */
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
38
78
|
function cliHighlight(): CliHighlight | null {
|
|
39
79
|
if (_hl) return _hl;
|
|
40
80
|
try {
|
|
41
81
|
forceChalkColor();
|
|
42
82
|
_hl = require("cli-highlight") as CliHighlight;
|
|
83
|
+
extendBuiltIns();
|
|
43
84
|
} catch {
|
|
44
85
|
_hl = null;
|
|
45
86
|
}
|
package/src/shell-tool.ts
CHANGED
|
@@ -189,7 +189,8 @@ export function registerShellTool(
|
|
|
189
189
|
if (d?._type === "bashResult") {
|
|
190
190
|
const normalizedText = normalizeShellText(d.text as string);
|
|
191
191
|
const lc = normalizedText ? normalizedText.split("\n").length : 0;
|
|
192
|
-
|
|
192
|
+
// Host time (monotonic, persisted) wins; details keep old hosts and sessions working.
|
|
193
|
+
const durationMs = Number(renderCtx.durationMs ?? d.durationMs ?? 0);
|
|
193
194
|
const exitCode = d.exitCode as number | null;
|
|
194
195
|
const status = exitCode === null ? "warning" : exitCode === 0 ? "success" : "error";
|
|
195
196
|
const meta = dotJoin([
|
package/src/types.ts
CHANGED
|
@@ -72,6 +72,8 @@ export type RenderContextLike<
|
|
|
72
72
|
invalidate: () => void;
|
|
73
73
|
/** Stable id for this tool execution — used to key resize invalidators. */
|
|
74
74
|
toolCallId?: string;
|
|
75
|
+
/** Host-recorded execution time of the final result (Pi >= 1.1). Undefined while partial. */
|
|
76
|
+
durationMs?: number;
|
|
75
77
|
};
|
|
76
78
|
|
|
77
79
|
type SessionContextLike = ExtensionContext;
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { isAbsolute, relative } from "node:path";
|
|
2
|
-
import {
|
|
1
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { getCapabilities, hyperlink, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
ANSI_CAPTURE_RE,
|
|
@@ -546,6 +547,17 @@ export function shortPath(cwd: string, home: string, p: string): string {
|
|
|
546
547
|
return home && p.startsWith(home) ? `~${p.slice(home.length)}` : p;
|
|
547
548
|
}
|
|
548
549
|
|
|
550
|
+
/**
|
|
551
|
+
* shortPath() wrapped in an OSC 8 `file://` link when the terminal supports it
|
|
552
|
+
* (pi-tui detects support, including tmux/screen). Width math and truncation in
|
|
553
|
+
* pi-tui skip OSC 8, and terminals without it get plain text.
|
|
554
|
+
*/
|
|
555
|
+
export function linkedShortPath(cwd: string, home: string, p: string): string {
|
|
556
|
+
const text = shortPath(cwd, home, p);
|
|
557
|
+
if (!text || !getCapabilities().hyperlinks) return text;
|
|
558
|
+
return hyperlink(text, pathToFileURL(resolve(cwd, p)).href);
|
|
559
|
+
}
|
|
560
|
+
|
|
549
561
|
/** Paints a rule line. Callers pass `(s) => theme.fg(status, s)` so the frame
|
|
550
562
|
* tint follows the active theme (success/error/warning). Default = neutral FG_RULE. */
|
|
551
563
|
export type RulePaint = (glyphs: string) => string;
|