@lune_99/pi-core-theme 0.1.0 → 0.2.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/CHANGELOG.md +76 -0
- package/README.md +24 -20
- package/docs/reference.md +55 -18
- package/docs/theme-palettes.png +0 -0
- package/docs/theme-palettes.svg +27 -6
- package/package.json +10 -7
- package/src/extension.ts +3 -1
- package/src/feature/context.ts +101 -189
- package/src/header.ts +2 -1
- package/src/index.ts +13 -2
- package/src/palettes/index.ts +18 -0
- package/src/palettes/pi-core-claude-code.json +110 -0
- package/src/palettes/pi-core-codex.json +108 -0
- package/src/palettes/pi-core-cursor.json +111 -0
- package/src/renderer/activity-card.ts +1 -1
- package/src/renderer/cards.ts +24 -39
- package/src/renderer/index.ts +7 -1
- package/src/renderer/markdown-enhance.ts +29 -20
- package/src/renderer/tool/activity.ts +13 -5
- package/src/renderer/tool/diff/shiki-highlight.ts +4 -1
- package/src/renderer/tool/output.ts +5 -2
- package/src/renderer/tool/presentation.ts +5 -2
- package/src/renderer/tool/summary.ts +12 -0
- package/src/renderer/transcript.ts +4 -15
- package/src/settings.ts +1 -1
- package/src/startup-agents.ts +80 -0
- package/src/ui/call-list.ts +7 -2
- package/src/ui/context-browser.ts +214 -0
- package/src/ui/hover.ts +28 -14
- package/src/ui/link-hover.ts +226 -0
- package/src/ui/output-panel.ts +13 -178
- package/src/ui/text-panel.ts +357 -0
- package/src/utils/format-tokens.ts +5 -0
- package/src/utils/links.ts +67 -0
- package/src/ui/preview.ts +0 -195
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://pi.dev/schemas/theme.schema.json",
|
|
3
|
+
"name": "pi-core-codex",
|
|
4
|
+
"vars": {
|
|
5
|
+
"bg": "#0d0d0d",
|
|
6
|
+
"panel": "#171717",
|
|
7
|
+
"surface": "#212121",
|
|
8
|
+
"border": "#3a3a3a",
|
|
9
|
+
"borderMuted": "#262626",
|
|
10
|
+
"text": "#ececec",
|
|
11
|
+
"muted": "#b4b4b4",
|
|
12
|
+
"dim": "#808080",
|
|
13
|
+
"comment": "#6e6e6e",
|
|
14
|
+
"punctuation": "#9a9a9a",
|
|
15
|
+
"variable": "#e3e3e3",
|
|
16
|
+
"heading": "#ffffff",
|
|
17
|
+
"accent": "#4fc6d6",
|
|
18
|
+
"accentBright": "#8fe3ec",
|
|
19
|
+
"type": "#a5b4fc",
|
|
20
|
+
"moonDeep": "#2fa3b3",
|
|
21
|
+
"seaGlass": "#4ec27e",
|
|
22
|
+
"string": "#9fd3a4",
|
|
23
|
+
"rose": "#f26d6d",
|
|
24
|
+
"halo": "#e7b95a",
|
|
25
|
+
"magenta": "#d77ee0",
|
|
26
|
+
"phase1": "#6b6b6b",
|
|
27
|
+
"phase2": "#8f8f8f",
|
|
28
|
+
"phase3": "#b4b4b4",
|
|
29
|
+
"phase4": "#d9d9d9",
|
|
30
|
+
"phase5": "#ffffff",
|
|
31
|
+
"moon1": "#ffffff",
|
|
32
|
+
"moon2": "#d9d9d9",
|
|
33
|
+
"moon3": "#b4b4b4",
|
|
34
|
+
"moon4": "#8f8f8f",
|
|
35
|
+
"moon5": "#6b6b6b",
|
|
36
|
+
"selectedBg": "#1c2a2d",
|
|
37
|
+
"searchMatchBg": "#22414a",
|
|
38
|
+
"userMessageBg": "#1c1c1c",
|
|
39
|
+
"customMessageBg": "#221a24",
|
|
40
|
+
"toolPendingBg": "#141414",
|
|
41
|
+
"toolSuccessBg": "#112016",
|
|
42
|
+
"toolErrorBg": "#261414"
|
|
43
|
+
},
|
|
44
|
+
"colors": {
|
|
45
|
+
"accent": "accent",
|
|
46
|
+
"border": "border",
|
|
47
|
+
"borderAccent": "accent",
|
|
48
|
+
"borderMuted": "borderMuted",
|
|
49
|
+
"success": "seaGlass",
|
|
50
|
+
"error": "rose",
|
|
51
|
+
"warning": "halo",
|
|
52
|
+
"muted": "muted",
|
|
53
|
+
"dim": "dim",
|
|
54
|
+
"text": "text",
|
|
55
|
+
"thinkingText": "muted",
|
|
56
|
+
"selectedBg": "selectedBg",
|
|
57
|
+
"userMessageBg": "userMessageBg",
|
|
58
|
+
"userMessageText": "text",
|
|
59
|
+
"customMessageBg": "customMessageBg",
|
|
60
|
+
"customMessageText": "text",
|
|
61
|
+
"customMessageLabel": "magenta",
|
|
62
|
+
"toolPendingBg": "toolPendingBg",
|
|
63
|
+
"toolSuccessBg": "toolSuccessBg",
|
|
64
|
+
"toolErrorBg": "toolErrorBg",
|
|
65
|
+
"toolTitle": "text",
|
|
66
|
+
"toolOutput": "muted",
|
|
67
|
+
"mdHeading": "heading",
|
|
68
|
+
"mdLink": "accent",
|
|
69
|
+
"mdLinkUrl": "dim",
|
|
70
|
+
"mdCode": "accent",
|
|
71
|
+
"mdCodeBlock": "text",
|
|
72
|
+
"mdCodeBlockBorder": "borderMuted",
|
|
73
|
+
"mdQuote": "muted",
|
|
74
|
+
"mdQuoteBorder": "moonDeep",
|
|
75
|
+
"mdHr": "borderMuted",
|
|
76
|
+
"mdListBullet": "muted",
|
|
77
|
+
"toolDiffAdded": "seaGlass",
|
|
78
|
+
"toolDiffRemoved": "rose",
|
|
79
|
+
"toolDiffContext": "muted",
|
|
80
|
+
"syntaxComment": "comment",
|
|
81
|
+
"syntaxKeyword": "magenta",
|
|
82
|
+
"syntaxFunction": "accentBright",
|
|
83
|
+
"syntaxVariable": "variable",
|
|
84
|
+
"syntaxString": "string",
|
|
85
|
+
"syntaxNumber": "halo",
|
|
86
|
+
"syntaxType": "type",
|
|
87
|
+
"syntaxOperator": "muted",
|
|
88
|
+
"syntaxPunctuation": "punctuation",
|
|
89
|
+
"thinkingOff": "comment",
|
|
90
|
+
"thinkingMinimal": "dim",
|
|
91
|
+
"thinkingLow": "phase1",
|
|
92
|
+
"thinkingMedium": "phase2",
|
|
93
|
+
"thinkingHigh": "phase3",
|
|
94
|
+
"thinkingXhigh": "phase4",
|
|
95
|
+
"thinkingMax": "phase5",
|
|
96
|
+
"bashMode": "seaGlass",
|
|
97
|
+
"scrollbarThumb": "dim",
|
|
98
|
+
"scrollbarTrack": "borderMuted",
|
|
99
|
+
"searchMatchBg": "searchMatchBg",
|
|
100
|
+
"searchMatchText": "text"
|
|
101
|
+
},
|
|
102
|
+
"export": {
|
|
103
|
+
"pageBg": "bg",
|
|
104
|
+
"cardBg": "panel",
|
|
105
|
+
"infoBg": "surface"
|
|
106
|
+
},
|
|
107
|
+
"appearance": "dark"
|
|
108
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://pi.dev/schemas/theme.schema.json",
|
|
3
|
+
"name": "pi-core-cursor",
|
|
4
|
+
"vars": {
|
|
5
|
+
"bg": "#181818",
|
|
6
|
+
"panel": "#1e1e1e",
|
|
7
|
+
"surface": "#252525",
|
|
8
|
+
"border": "#3c3c3c",
|
|
9
|
+
"borderMuted": "#2b2b2b",
|
|
10
|
+
"text": "#d6d6dd",
|
|
11
|
+
"muted": "#a3a3aa",
|
|
12
|
+
"dim": "#84848b",
|
|
13
|
+
"comment": "#737373",
|
|
14
|
+
"punctuation": "#9d9da5",
|
|
15
|
+
"variable": "#d6d6dd",
|
|
16
|
+
"heading": "#87c3ff",
|
|
17
|
+
"accent": "#4c9df3",
|
|
18
|
+
"accentBright": "#87c3ff",
|
|
19
|
+
"type": "#87c3ff",
|
|
20
|
+
"moonDeep": "#228df2",
|
|
21
|
+
"seaGlass": "#3fb98a",
|
|
22
|
+
"string": "#e394dc",
|
|
23
|
+
"rose": "#f14c4c",
|
|
24
|
+
"halo": "#e5b95c",
|
|
25
|
+
"lavender": "#aa9bf5",
|
|
26
|
+
"keyword": "#83d6c5",
|
|
27
|
+
"function": "#efb080",
|
|
28
|
+
"number": "#ebc88d",
|
|
29
|
+
"phase1": "#3383dc",
|
|
30
|
+
"phase2": "#4c9df3",
|
|
31
|
+
"phase3": "#87c3ff",
|
|
32
|
+
"phase4": "#b9dcff",
|
|
33
|
+
"phase5": "#eef6ff",
|
|
34
|
+
"moon1": "#eef6ff",
|
|
35
|
+
"moon2": "#b9dcff",
|
|
36
|
+
"moon3": "#87c3ff",
|
|
37
|
+
"moon4": "#4c9df3",
|
|
38
|
+
"moon5": "#3383dc",
|
|
39
|
+
"selectedBg": "#22334a",
|
|
40
|
+
"searchMatchBg": "#2d4a6e",
|
|
41
|
+
"userMessageBg": "#232323",
|
|
42
|
+
"customMessageBg": "#24222f",
|
|
43
|
+
"toolPendingBg": "#1d1d1d",
|
|
44
|
+
"toolSuccessBg": "#18241f",
|
|
45
|
+
"toolErrorBg": "#2a1a1c"
|
|
46
|
+
},
|
|
47
|
+
"colors": {
|
|
48
|
+
"accent": "accent",
|
|
49
|
+
"border": "border",
|
|
50
|
+
"borderAccent": "accent",
|
|
51
|
+
"borderMuted": "borderMuted",
|
|
52
|
+
"success": "seaGlass",
|
|
53
|
+
"error": "rose",
|
|
54
|
+
"warning": "halo",
|
|
55
|
+
"muted": "muted",
|
|
56
|
+
"dim": "dim",
|
|
57
|
+
"text": "text",
|
|
58
|
+
"thinkingText": "muted",
|
|
59
|
+
"selectedBg": "selectedBg",
|
|
60
|
+
"userMessageBg": "userMessageBg",
|
|
61
|
+
"userMessageText": "text",
|
|
62
|
+
"customMessageBg": "customMessageBg",
|
|
63
|
+
"customMessageText": "text",
|
|
64
|
+
"customMessageLabel": "lavender",
|
|
65
|
+
"toolPendingBg": "toolPendingBg",
|
|
66
|
+
"toolSuccessBg": "toolSuccessBg",
|
|
67
|
+
"toolErrorBg": "toolErrorBg",
|
|
68
|
+
"toolTitle": "accentBright",
|
|
69
|
+
"toolOutput": "muted",
|
|
70
|
+
"mdHeading": "heading",
|
|
71
|
+
"mdLink": "accent",
|
|
72
|
+
"mdLinkUrl": "dim",
|
|
73
|
+
"mdCode": "accentBright",
|
|
74
|
+
"mdCodeBlock": "text",
|
|
75
|
+
"mdCodeBlockBorder": "borderMuted",
|
|
76
|
+
"mdQuote": "muted",
|
|
77
|
+
"mdQuoteBorder": "moonDeep",
|
|
78
|
+
"mdHr": "borderMuted",
|
|
79
|
+
"mdListBullet": "accent",
|
|
80
|
+
"toolDiffAdded": "seaGlass",
|
|
81
|
+
"toolDiffRemoved": "rose",
|
|
82
|
+
"toolDiffContext": "muted",
|
|
83
|
+
"syntaxComment": "comment",
|
|
84
|
+
"syntaxKeyword": "keyword",
|
|
85
|
+
"syntaxFunction": "function",
|
|
86
|
+
"syntaxVariable": "variable",
|
|
87
|
+
"syntaxString": "string",
|
|
88
|
+
"syntaxNumber": "number",
|
|
89
|
+
"syntaxType": "type",
|
|
90
|
+
"syntaxOperator": "muted",
|
|
91
|
+
"syntaxPunctuation": "punctuation",
|
|
92
|
+
"thinkingOff": "comment",
|
|
93
|
+
"thinkingMinimal": "dim",
|
|
94
|
+
"thinkingLow": "phase1",
|
|
95
|
+
"thinkingMedium": "phase2",
|
|
96
|
+
"thinkingHigh": "phase3",
|
|
97
|
+
"thinkingXhigh": "phase4",
|
|
98
|
+
"thinkingMax": "phase5",
|
|
99
|
+
"bashMode": "seaGlass",
|
|
100
|
+
"scrollbarThumb": "dim",
|
|
101
|
+
"scrollbarTrack": "borderMuted",
|
|
102
|
+
"searchMatchBg": "searchMatchBg",
|
|
103
|
+
"searchMatchText": "text"
|
|
104
|
+
},
|
|
105
|
+
"export": {
|
|
106
|
+
"pageBg": "bg",
|
|
107
|
+
"cardBg": "panel",
|
|
108
|
+
"infoBg": "surface"
|
|
109
|
+
},
|
|
110
|
+
"appearance": "dark"
|
|
111
|
+
}
|
|
@@ -133,7 +133,7 @@ export class ActivityCard implements Component {
|
|
|
133
133
|
!expanded &&
|
|
134
134
|
(this.header.contains(event) || this.hints.some((hint) => hint.contains(event)));
|
|
135
135
|
if (event.type === "move") {
|
|
136
|
-
let changed
|
|
136
|
+
let changed: boolean;
|
|
137
137
|
if (output) changed = hover.focus(output.target);
|
|
138
138
|
else if (hint) changed = hover.focus(this.state);
|
|
139
139
|
else {
|
package/src/renderer/cards.ts
CHANGED
|
@@ -19,12 +19,13 @@ import {
|
|
|
19
19
|
richDiffSummary,
|
|
20
20
|
type WriteExecutionMetadataStore,
|
|
21
21
|
} from "./tool/diff/index.ts";
|
|
22
|
-
import { toolSummary, singleLine } from "./tool/summary.ts";
|
|
22
|
+
import { toolHref, toolSummary, singleLine } from "./tool/summary.ts";
|
|
23
23
|
import { renderToolLine } from "./tool/presentation.ts";
|
|
24
24
|
import {
|
|
25
25
|
animationFrame,
|
|
26
26
|
callStatus,
|
|
27
27
|
nestedCalls,
|
|
28
|
+
nestedHref,
|
|
28
29
|
nestedSummary,
|
|
29
30
|
type CallStatus,
|
|
30
31
|
type NestedCall,
|
|
@@ -269,6 +270,7 @@ class ToolCard implements Component {
|
|
|
269
270
|
{
|
|
270
271
|
name: call.name,
|
|
271
272
|
summary: nestedSummary(call, this.context.cwd),
|
|
273
|
+
href: nestedHref(call, this.context.cwd),
|
|
272
274
|
status: call.status,
|
|
273
275
|
durationMs: call.durationMs,
|
|
274
276
|
detail: this.callDetail(call, open),
|
|
@@ -442,18 +444,9 @@ class ToolCard implements Component {
|
|
|
442
444
|
if (this.slot === "call") {
|
|
443
445
|
const status = callStatus(context.isPartial, context.isError);
|
|
444
446
|
const lines = [this.heading(width, open, grouped, status)];
|
|
447
|
+
// Collapsed codemode has no script preview: its first nested call would replace the
|
|
448
|
+
// streamed code, so the card would flash code and then jump to a call tree.
|
|
445
449
|
if (open) lines.push(...this.input(width));
|
|
446
|
-
else if (this.name === "codemode" && !this.calls().length) {
|
|
447
|
-
const script =
|
|
448
|
-
typeof context.args.code === "string" && context.args.code.trim()
|
|
449
|
-
? sanitizeToolResultText(context.args.code, 2000)
|
|
450
|
-
: "Preparing script…";
|
|
451
|
-
lines.push(
|
|
452
|
-
...wrapTextWithAnsi(script, Math.max(1, width - 3))
|
|
453
|
-
.slice(0, 5)
|
|
454
|
-
.map((row) => truncateToWidth(` ${theme.fg("dim", row)}`, width, "")),
|
|
455
|
-
);
|
|
456
|
-
}
|
|
457
450
|
if (!state(context).result) {
|
|
458
451
|
lines.push(
|
|
459
452
|
...this.callRows(Math.max(1, width - 3), open, lines.length).map((row) =>
|
|
@@ -496,33 +489,14 @@ class ToolCard implements Component {
|
|
|
496
489
|
const output = current.output ?? "";
|
|
497
490
|
if (!open) {
|
|
498
491
|
const rows = calls.map((row) => truncateToWidth(` ${row}`, width, ""));
|
|
492
|
+
// Live output stays in expanded cards: collapsed rows that grow while a tool runs and
|
|
493
|
+
// go when it settles move the bottom-pinned transcript twice.
|
|
499
494
|
if (rich)
|
|
500
495
|
rows.push(
|
|
501
496
|
...rich
|
|
502
497
|
.render(Math.max(1, width - 3))
|
|
503
498
|
.map((row) => truncateToWidth(` ${row}`, width, "")),
|
|
504
499
|
);
|
|
505
|
-
else if (context.isPartial && output.trim()) {
|
|
506
|
-
const preview = outputPreview(
|
|
507
|
-
output,
|
|
508
|
-
Math.max(1, width - 3),
|
|
509
|
-
config.previewLines,
|
|
510
|
-
true,
|
|
511
|
-
);
|
|
512
|
-
rows.push(
|
|
513
|
-
...preview.lines.map((row) =>
|
|
514
|
-
truncateToWidth(` ${theme.fg("toolOutput", row)}`, width, ""),
|
|
515
|
-
),
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
if (!rich && !this.composite && context.isError && output.trim())
|
|
519
|
-
rows.push(
|
|
520
|
-
truncateToWidth(
|
|
521
|
-
` ${theme.fg("error", singleLine(output.slice(0, 512)))}`,
|
|
522
|
-
width,
|
|
523
|
-
"…",
|
|
524
|
-
),
|
|
525
|
-
);
|
|
526
500
|
if (!grouped) this.addControls(rows, width, false);
|
|
527
501
|
return rows;
|
|
528
502
|
}
|
|
@@ -614,9 +588,8 @@ class ToolCard implements Component {
|
|
|
614
588
|
const context = this.context;
|
|
615
589
|
const inner = Math.max(1, width - 3);
|
|
616
590
|
if (this.composite) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
);
|
|
591
|
+
// Only nested calls count; the parent's own status still sets the heading mark.
|
|
592
|
+
const statuses = this.calls().map((call) => call.status);
|
|
620
593
|
return open
|
|
621
594
|
? framedRow(
|
|
622
595
|
theme,
|
|
@@ -648,9 +621,10 @@ class ToolCard implements Component {
|
|
|
648
621
|
const line = renderToolLine(theme, (open ? inner : width - 1) - reserve, {
|
|
649
622
|
name: this.name,
|
|
650
623
|
summary: toolSummary(this.name, context.args, context.cwd),
|
|
624
|
+
href: toolHref(this.name, context.args, context.cwd),
|
|
651
625
|
status,
|
|
652
626
|
durationMs: durationMs(context),
|
|
653
|
-
detail: this.detail(status),
|
|
627
|
+
detail: this.detail(status, open, width),
|
|
654
628
|
});
|
|
655
629
|
if (open) return framedRow(theme, line, width);
|
|
656
630
|
if (!hint) return truncateToWidth(` ${line}`, width, "");
|
|
@@ -670,8 +644,19 @@ class ToolCard implements Component {
|
|
|
670
644
|
);
|
|
671
645
|
}
|
|
672
646
|
/** Settled results summarize on the heading so collapsed cards stay one row. */
|
|
673
|
-
private detail(status: CallStatus): string | undefined {
|
|
647
|
+
private detail(status: CallStatus, open: boolean, width: number): string | undefined {
|
|
674
648
|
const current = state(this.context);
|
|
649
|
+
if (status === "failed") {
|
|
650
|
+
// Expanded cards show the whole output under the heading; a third of the row
|
|
651
|
+
// leaves room for the command.
|
|
652
|
+
const error = open ? "" : singleLine((current.output ?? "").slice(0, 512));
|
|
653
|
+
return error
|
|
654
|
+
? this.theme.fg(
|
|
655
|
+
"error",
|
|
656
|
+
truncateToWidth(error, Math.max(8, Math.floor(width / 3)), "…"),
|
|
657
|
+
)
|
|
658
|
+
: undefined;
|
|
659
|
+
}
|
|
675
660
|
if (status !== "done" || !current.result) return undefined;
|
|
676
661
|
const diff = richDiffSummary(
|
|
677
662
|
this.theme,
|
|
@@ -690,7 +675,7 @@ class ToolCard implements Component {
|
|
|
690
675
|
: this.disclosure.contains(event);
|
|
691
676
|
if (event.type === "move") {
|
|
692
677
|
if (!config.fullscreenMouse) return undefined;
|
|
693
|
-
let changed
|
|
678
|
+
let changed: boolean;
|
|
694
679
|
if (hidden) changed = this.hover.focus(hidden);
|
|
695
680
|
else if (hint) changed = this.hover.focus(this);
|
|
696
681
|
else {
|
package/src/renderer/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from "@earendil-works/pi-coding-agent";
|
|
14
14
|
import { config } from "../config/config.ts";
|
|
15
15
|
import { HoverState, installHoverTracking } from "../ui/hover.ts";
|
|
16
|
+
import { installLinkHover } from "../ui/link-hover.ts";
|
|
16
17
|
import { createOutputBrowser } from "../ui/output-panel.ts";
|
|
17
18
|
import { ExpansionState } from "../ui/expansion.ts";
|
|
18
19
|
import {
|
|
@@ -178,7 +179,12 @@ export function createThemeRendererHost(
|
|
|
178
179
|
if (tui !== next) {
|
|
179
180
|
stopHoverTracking();
|
|
180
181
|
tui = next;
|
|
181
|
-
|
|
182
|
+
const stopHover = installHoverTracking(host, hover, repaint);
|
|
183
|
+
const stopLinkHover = installLinkHover(host, repaint);
|
|
184
|
+
stopHoverTracking = () => {
|
|
185
|
+
stopLinkHover();
|
|
186
|
+
stopHover();
|
|
187
|
+
};
|
|
182
188
|
}
|
|
183
189
|
syncMouse();
|
|
184
190
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI, MarkdownTransformer } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { render as renderMermaid, sourceBox } from "grok-mermaid";
|
|
3
|
+
import { fileHref, hyperlinksEnabled, replaceLinks, webHref } from "../utils/links.ts";
|
|
3
4
|
|
|
4
5
|
const diagrams = new Map<string, ReturnType<typeof renderMermaid> | undefined>();
|
|
5
6
|
const MAX_DIAGRAMS = 48;
|
|
@@ -20,31 +21,37 @@ const admonitions: Record<string, string> = {
|
|
|
20
21
|
CAUTION: "!",
|
|
21
22
|
};
|
|
22
23
|
const protectedInline = /(`+).*?\1|!?\[[^\]]*\]\([^\n]*?\)|<https?:\/\/[^>]+>/g;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
const linkTarget = (text: string, href: string) => `[${text}](${href})`;
|
|
25
|
+
/**
|
|
26
|
+
* Code and existing links keep their text. With OSC 8 links, a code span that is one HTTP(S) URL
|
|
27
|
+
* or names an existing path becomes its link text, and a link to a local path gets a file URL that
|
|
28
|
+
* terminals can open.
|
|
29
|
+
*/
|
|
30
|
+
function linkProtected(segment: string, cwd: string | undefined): string {
|
|
31
|
+
if (cwd === undefined) return segment;
|
|
32
|
+
const code = /^(`+)(.*?)\1$/.exec(segment)?.[2]?.trim();
|
|
33
|
+
if (code !== undefined) {
|
|
34
|
+
// The whole span must be one URL or name an existing path; command arguments are never scanned.
|
|
35
|
+
const href =
|
|
36
|
+
webHref(code) ??
|
|
37
|
+
(/\/|\.[A-Za-z\d]+(?::[\d:-]+|#.*)?$/.test(code) && fileHref(code, cwd));
|
|
38
|
+
return href ? `[${segment}](<${href}>)` : segment;
|
|
32
39
|
}
|
|
33
|
-
|
|
40
|
+
const link = /^(\[[^\]]*\]\()<?([^\s<>()]+)>?((?:\s[^)]*)?\))$/.exec(segment);
|
|
41
|
+
// `name:<digits>` is a path location such as `README.md:12`, not a URL scheme.
|
|
42
|
+
if (!link || /^[a-z][a-z\d+.-]*:(?!\d)/i.test(link[2]!)) return segment;
|
|
43
|
+
const href = fileHref(link[2]!, cwd);
|
|
44
|
+
return href ? `${link[1]}<${href}>${link[3]}` : segment;
|
|
34
45
|
}
|
|
35
|
-
function prose(value: string): string {
|
|
46
|
+
function prose(value: string, cwd: string | undefined): string {
|
|
36
47
|
const convert = (text: string) => {
|
|
37
48
|
text = text.replace(/[①-⑳]/g, (character) => `(${character.codePointAt(0)! - 0x2460 + 1})`);
|
|
38
|
-
|
|
39
|
-
const url = trimUrl(value);
|
|
40
|
-
return url ? `[${url}](${url})${value.slice(url.length)}` : value;
|
|
41
|
-
});
|
|
42
|
-
return text;
|
|
49
|
+
return replaceLinks(text, linkTarget);
|
|
43
50
|
};
|
|
44
51
|
let start = 0;
|
|
45
52
|
const parts: string[] = [];
|
|
46
53
|
for (const match of value.matchAll(protectedInline)) {
|
|
47
|
-
parts.push(convert(value.slice(start, match.index)), match[0]);
|
|
54
|
+
parts.push(convert(value.slice(start, match.index)), linkProtected(match[0], cwd));
|
|
48
55
|
start = match.index + match[0].length;
|
|
49
56
|
}
|
|
50
57
|
parts.push(convert(value.slice(start)));
|
|
@@ -82,6 +89,8 @@ export function clearMarkdownCache() {
|
|
|
82
89
|
/** Code, existing links and streaming-incomplete structures must never be rewritten as prose. */
|
|
83
90
|
export const transformMarkdown: MarkdownTransformer = (markdown, context) => {
|
|
84
91
|
if (context.messageType === "assistant-thinking") return markdown;
|
|
92
|
+
// Paths resolve from Pi's working directory, like its native tools.
|
|
93
|
+
const cwd = hyperlinksEnabled() ? process.cwd() : undefined;
|
|
85
94
|
const lines = markdown.split("\n");
|
|
86
95
|
const output: string[] = [];
|
|
87
96
|
for (let index = 0; index < lines.length; index++) {
|
|
@@ -92,7 +101,7 @@ export const transformMarkdown: MarkdownTransformer = (markdown, context) => {
|
|
|
92
101
|
const marker = fence[2]!;
|
|
93
102
|
const label = fence[3]!;
|
|
94
103
|
const closing = new RegExp(
|
|
95
|
-
`^${prefix.replace(/[
|
|
104
|
+
`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}${marker[0]}{${marker.length},}\\s*$`,
|
|
96
105
|
);
|
|
97
106
|
let end = index + 1;
|
|
98
107
|
while (end < lines.length && !closing.test(lines[end]!)) end++;
|
|
@@ -118,9 +127,9 @@ export const transformMarkdown: MarkdownTransformer = (markdown, context) => {
|
|
|
118
127
|
if (alert) {
|
|
119
128
|
const name = alert[1]!.toUpperCase();
|
|
120
129
|
output.push(
|
|
121
|
-
`> **${admonitions[name]} ${name}**${alert[2] ? ` ${prose(alert[2])}` : ""}`,
|
|
130
|
+
`> **${admonitions[name]} ${name}**${alert[2] ? ` ${prose(alert[2], cwd)}` : ""}`,
|
|
122
131
|
);
|
|
123
|
-
} else output.push(prose(line));
|
|
132
|
+
} else output.push(prose(line, cwd));
|
|
124
133
|
}
|
|
125
134
|
return output.join("\n");
|
|
126
135
|
};
|
|
@@ -2,7 +2,7 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
2
2
|
import type { ToolRenderers } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { config } from "../../config/config.ts";
|
|
4
4
|
import { resultText } from "./output.ts";
|
|
5
|
-
import { singleLine, toolSummary } from "./summary.ts";
|
|
5
|
+
import { singleLine, toolHref, toolSummary } from "./summary.ts";
|
|
6
6
|
|
|
7
7
|
type ToolResult = Parameters<NonNullable<ToolRenderers["renderResult"]>>[0];
|
|
8
8
|
|
|
@@ -173,16 +173,24 @@ export function nestedCalls(
|
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
function nestedArgs(call: NestedCall): Record<string, unknown> | undefined {
|
|
177
177
|
let args = call.args;
|
|
178
178
|
if (typeof args === "string") {
|
|
179
179
|
try {
|
|
180
180
|
args = JSON.parse(args);
|
|
181
181
|
} catch {
|
|
182
|
-
return
|
|
182
|
+
return undefined;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
return args && typeof args === "object" && !Array.isArray(args)
|
|
186
|
-
?
|
|
187
|
-
:
|
|
186
|
+
? (args as Record<string, unknown>)
|
|
187
|
+
: undefined;
|
|
188
|
+
}
|
|
189
|
+
export function nestedSummary(call: NestedCall, cwd: string) {
|
|
190
|
+
const args = nestedArgs(call);
|
|
191
|
+
return args ? toolSummary(call.name, args, cwd) : singleLine(call.args);
|
|
192
|
+
}
|
|
193
|
+
export function nestedHref(call: NestedCall, cwd: string) {
|
|
194
|
+
const args = nestedArgs(call);
|
|
195
|
+
return args && toolHref(call.name, args, cwd);
|
|
188
196
|
}
|
|
@@ -78,7 +78,10 @@ export class ShikiHighlightCache {
|
|
|
78
78
|
if (!differs(lines, subscriber.fallback)) continue;
|
|
79
79
|
try {
|
|
80
80
|
subscriber.invalidate();
|
|
81
|
-
} catch {
|
|
81
|
+
} catch {
|
|
82
|
+
// Subscriber errors are dropped so the remaining invalidations still run;
|
|
83
|
+
// the fallback highlight stays on screen.
|
|
84
|
+
}
|
|
82
85
|
}
|
|
83
86
|
})
|
|
84
87
|
.catch(() => {})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
3
|
import { sanitizeToolResultText } from "../../utils/tool-result-sanitize.ts";
|
|
4
|
+
import { linkText } from "../../utils/links.ts";
|
|
4
5
|
import type { ToolRenderers } from "@earendil-works/pi-coding-agent";
|
|
5
6
|
|
|
6
7
|
type ToolResult = Parameters<NonNullable<ToolRenderers["renderResult"]>>[0];
|
|
@@ -10,10 +11,12 @@ export function resultText(result: ToolResult): string {
|
|
|
10
11
|
.map((block) => block.text)
|
|
11
12
|
.join("\n");
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
// Links are added after sanitizing, which strips every escape, and before wrapping, which
|
|
15
|
+
// carries an open link onto the next row.
|
|
16
|
+
export function outputPreview(text: string, width: number, limit: number, running: boolean) {
|
|
14
17
|
const budget = Math.min(64_000, Math.max(1024, Math.max(1, width) * limit * 4));
|
|
15
18
|
const source = running ? text.slice(-budget) : text.slice(0, budget);
|
|
16
|
-
const rows = wrapTextWithAnsi(sanitizeToolResultText(source), Math.max(1, width));
|
|
19
|
+
const rows = wrapTextWithAnsi(linkText(sanitizeToolResultText(source)), Math.max(1, width));
|
|
17
20
|
return {
|
|
18
21
|
lines: limit <= 0 ? [] : running ? rows.slice(-limit) : rows.slice(0, limit),
|
|
19
22
|
hidden: text.length > source.length || rows.length > limit,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { hyperlink, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { config } from "../../config/config.ts";
|
|
4
4
|
import { meta, SEPARATOR, statusLabel, statusMark } from "../../ui/style.ts";
|
|
5
5
|
import type { CallStatus } from "./activity.ts";
|
|
@@ -25,6 +25,8 @@ export function renderToolLine(
|
|
|
25
25
|
status: CallStatus;
|
|
26
26
|
durationMs?: number;
|
|
27
27
|
detail?: string;
|
|
28
|
+
/** Links the summary after clipping, which would otherwise cut the OSC 8 sequence. */
|
|
29
|
+
href?: string;
|
|
28
30
|
},
|
|
29
31
|
prefix = "",
|
|
30
32
|
): string {
|
|
@@ -37,7 +39,8 @@ export function renderToolLine(
|
|
|
37
39
|
const tailWidth = tail ? visibleWidth(SEPARATOR) + visibleWidth(tail) : 0;
|
|
38
40
|
const room = Math.max(0, width - visibleWidth(title) - tailWidth - 2);
|
|
39
41
|
const summary = fitSummary(call.summary, room, config.toolLabelClip || 80);
|
|
40
|
-
const
|
|
42
|
+
const text = theme.fg("muted", summary);
|
|
43
|
+
const head = summary ? `${title} ${call.href ? hyperlink(text, call.href) : text}` : title;
|
|
41
44
|
return tail ? `${head}${theme.fg("dim", SEPARATOR)}${tail}` : head;
|
|
42
45
|
}
|
|
43
46
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { posix, win32 } from "node:path";
|
|
2
2
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import { fileHref, hyperlinksEnabled } from "../../utils/links.ts";
|
|
3
4
|
|
|
4
5
|
export function singleLine(value: unknown): string {
|
|
5
6
|
return typeof value === "string"
|
|
@@ -221,6 +222,17 @@ export function toolSummary(name: string, args: Record<string, unknown>, cwd?: s
|
|
|
221
222
|
}
|
|
222
223
|
return "";
|
|
223
224
|
}
|
|
225
|
+
/** The file URL for a summary that shows only a path; a search pattern keeps the summary unlinked. */
|
|
226
|
+
export function toolHref(
|
|
227
|
+
name: string,
|
|
228
|
+
args: Record<string, unknown>,
|
|
229
|
+
cwd?: string,
|
|
230
|
+
): string | undefined {
|
|
231
|
+
if (name === "codemode" || typeof args.command === "string" || singleLine(args.pattern))
|
|
232
|
+
return undefined;
|
|
233
|
+
const path = singleLine(args.path ?? args.file_path);
|
|
234
|
+
return path && cwd && hyperlinksEnabled() ? fileHref(path, cwd) : undefined;
|
|
235
|
+
}
|
|
224
236
|
export function fitSummary(value: string, width: number, limit: number): string {
|
|
225
237
|
return clip(value, Math.max(0, limit > 0 ? Math.min(width, limit) : width));
|
|
226
238
|
}
|
|
@@ -18,9 +18,8 @@ import type { HoverState } from "../ui/hover.ts";
|
|
|
18
18
|
import type { ExpansionState } from "../ui/expansion.ts";
|
|
19
19
|
import { animationFrame, callStatus } from "./tool/activity.ts";
|
|
20
20
|
import { renderToolLine } from "./tool/presentation.ts";
|
|
21
|
-
import { toolSummary } from "./tool/summary.ts";
|
|
21
|
+
import { toolHref, toolSummary } from "./tool/summary.ts";
|
|
22
22
|
import { richDiffSummary } from "./tool/diff/index.ts";
|
|
23
|
-
import { outputPreview, resultText } from "./tool/output.ts";
|
|
24
23
|
import { branch } from "../ui/style.ts";
|
|
25
24
|
import { stripTerminalSequencesPreservingLayout } from "../utils/ansi-text.ts";
|
|
26
25
|
|
|
@@ -365,6 +364,8 @@ export function installTranscriptGroups(
|
|
|
365
364
|
);
|
|
366
365
|
continue;
|
|
367
366
|
}
|
|
367
|
+
// A collapsed call is one row without live output: rows that grow while a tool
|
|
368
|
+
// runs and go when it settles move the bottom-pinned transcript twice.
|
|
368
369
|
const diff =
|
|
369
370
|
!item.isPartial && !item.result?.isError
|
|
370
371
|
? richDiffSummary(palette, item.toolName, item.args, item.result?.details)
|
|
@@ -377,6 +378,7 @@ export function installTranscriptGroups(
|
|
|
377
378
|
{
|
|
378
379
|
name: item.toolName,
|
|
379
380
|
summary: toolSummary(item.toolName, item.args, context.cwd),
|
|
381
|
+
href: toolHref(item.toolName, item.args, context.cwd),
|
|
380
382
|
status: statuses[start + index]!,
|
|
381
383
|
durationMs: item.result?.durationMs,
|
|
382
384
|
detail: diff,
|
|
@@ -387,19 +389,6 @@ export function installTranscriptGroups(
|
|
|
387
389
|
"…",
|
|
388
390
|
),
|
|
389
391
|
);
|
|
390
|
-
if (item.isPartial && item.result) {
|
|
391
|
-
const preview = outputPreview(
|
|
392
|
-
resultText(item.result),
|
|
393
|
-
Math.max(1, width - 7),
|
|
394
|
-
config.previewLines,
|
|
395
|
-
true,
|
|
396
|
-
);
|
|
397
|
-
lines.push(
|
|
398
|
-
...preview.lines.map((row) =>
|
|
399
|
-
truncateToWidth(` ${palette.fg("toolOutput", row)}`, width, ""),
|
|
400
|
-
),
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
392
|
}
|
|
404
393
|
lines.push(
|
|
405
394
|
...this.callList.renderOverflow(
|
package/src/settings.ts
CHANGED
|
@@ -18,7 +18,7 @@ const integer = (initial: number, minimum: number, maximum: number) =>
|
|
|
18
18
|
const properties = {
|
|
19
19
|
mode: choice(["on", "compact", "off"] as const, "on"),
|
|
20
20
|
palette: choice(["inherit", ...paletteNames] as const, "inherit"),
|
|
21
|
-
paletteBackground: Type.Boolean({ default:
|
|
21
|
+
paletteBackground: Type.Boolean({ default: false }),
|
|
22
22
|
excludeRenderers: Type.Array(Type.String({ minLength: 1 }), { default: [], uniqueItems: true }),
|
|
23
23
|
diffViewMode: choice(["auto", "split", "unified"] as const, "auto"),
|
|
24
24
|
diffIndicatorMode: choice(["bars", "classic", "none"] as const, "bars"),
|