@pi-kaush/pi-tool-call-markers 0.3.23 → 0.3.25
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 +18 -16
- package/package.json +1 -1
- package/src/bash-block.ts +20 -14
- package/src/index.ts +99 -77
- package/src/muted.ts +3 -7
- package/src/question-block.ts +8 -2
- package/src/thinking-block-merger.ts +122 -91
package/README.md
CHANGED
|
@@ -15,14 +15,14 @@ Restart Pi or run `/reload`.
|
|
|
15
15
|
Collapsed tool rows use semantic theme colors with no gear, background fill, box padding, or filled blank rows:
|
|
16
16
|
|
|
17
17
|
```text
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
▏§ writing-prose/SKILL.md 42 lines
|
|
19
|
+
▏≡ .pi/prompts/review.md 18 lines
|
|
20
|
+
▏● src/a.ts 42 lines
|
|
21
|
+
▏$ npm test → done
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
- **Two-column outer inset.** Tool markers and image output align with an inset conversation surface. Very narrow terminals reduce the decoration before useful content.
|
|
25
|
-
- **`▏` tool-call rail.** Collapsed calls use a bold glyph instead of repeating the tool name. The thin rail lines up with the
|
|
25
|
+
- **`▏` tool-call rail.** Collapsed calls use a bold glyph instead of repeating the tool name. The thin rail lines up with the left edge of the submitted prompt bar, and the call text lines up with the first character of the prompt. A single space separates the glyph from the call text. Grouped rows flow directly across tool types. See [Tool-call glyphs](#tool-call-glyphs) for the full list.
|
|
26
26
|
- **Semantic, low-contrast status.** The anchor and the call content share the collapsed mute, pending state is warning-colored, and failures remain error-colored. Ordinary tool states have no background.
|
|
27
27
|
- **Width-safe outcome tails.** Long summaries truncate before useful tails such as `→ done`, `→ 42 lines`, `→ +2/-1`, or a `bash` duration.
|
|
28
28
|
- **Stable running groups.** Adjacent calls group as they appear, including settled failures, which stay error-colored inside the group. Pending state and elapsed `bash` time settle into the final outcome without changing the row count.
|
|
@@ -57,8 +57,8 @@ Subagent calls use the `▏` rail without a glyph. Recognized question calls use
|
|
|
57
57
|
Collapsed codemode rows include bash command previews instead of only tool names:
|
|
58
58
|
|
|
59
59
|
```text
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
▏¢ bash ×1 npm test
|
|
61
|
+
▏¢ bash ×2 git status --short, bash npm test
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
The first preview for each tool shows its total call count, including ×1.
|
|
@@ -76,16 +76,18 @@ native script, nested call status, and result details.
|
|
|
76
76
|
A recognized `subagent` call renders as an unboxed plan in the shared tool aesthetic, using the same `▏` tool-call rail:
|
|
77
77
|
|
|
78
78
|
```text
|
|
79
|
-
|
|
79
|
+
▏ subagent chain (3 steps) [repo-review]
|
|
80
80
|
1. 🐝 bee [workhorse] Challenge the compatibility conclusion…
|
|
81
81
|
2. 🐝 bee …
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
Single calls stay on one `▏
|
|
84
|
+
Single calls stay on one `▏ [<emoji>] [<profile>][<agent>] <task preview>` row — no tool label. Chain calls get a heading with the kind, count, and scope followed by numbered steps (parallel tasks list without numbers), with each step ordered emoji, profile badge, name badge. Agent display names (emoji + name) are scraped from the native plan component — including the single-call heading — with an args fallback, and render in `accent`; everything else stays muted, and failed subagents go full red. Subagents never join ordinary tool groups.
|
|
85
|
+
|
|
86
|
+
Assigned agent emojis take priority. Without one, calls use 👾 for non-interactive runs or 🤖 for interactive launches and worker controls (`list`, `status`, `send`, `wait`, `stop`, and `resume`). Tasks using the `coder` profile default to 🧑💻 in either mode. An explicit model override disables that profile default, just as it hides the profile badge. These defaults also cover generic fallback rows such as `subagent 🤖 ... [user]`.
|
|
85
87
|
|
|
86
88
|
While a subagent runs, the plan headline's tail shows live progress from the streamed result details — `→ 1 turn · provider/model` in the warning tone — and a settled call keeps the same `→ N turns · provider/model` summary in muted (turns aggregate across tasks; the model shows only when every task used the same one).
|
|
87
89
|
|
|
88
|
-
Malformed, ambiguous, future, or too-narrow shapes fall back to the generic `▏
|
|
90
|
+
Malformed, ambiguous, future, or too-narrow shapes fall back to the generic `▏ subagent …` collapsed row rather than dropping information, and `Ctrl+O` still exposes the native subagent renderer.
|
|
89
91
|
|
|
90
92
|
## Asked questions
|
|
91
93
|
|
|
@@ -94,10 +96,10 @@ A call that asks the user something is a user-input moment, not an execution row
|
|
|
94
96
|
```text
|
|
95
97
|
▎
|
|
96
98
|
▎ > Which call-site shape should `notifications:` use?
|
|
97
|
-
▎
|
|
99
|
+
▎ User: Nested within subagent (Recommended)
|
|
98
100
|
▎
|
|
99
101
|
▎ > Which tier should the flag read at runtime?
|
|
100
|
-
▎
|
|
102
|
+
▎ User: Client only, Client and server
|
|
101
103
|
▎
|
|
102
104
|
```
|
|
103
105
|
|
|
@@ -137,11 +139,11 @@ The second package entrypoint, `src/thinking-block-merger.ts`, combines only dir
|
|
|
137
139
|
When Pi exposes its per-row hidden-thinking and streaming fields, hidden reasoning uses these native-themed labels:
|
|
138
140
|
|
|
139
141
|
```text
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
▏⠋ Thinking… → ▏⠙ Thinking… → …
|
|
143
|
+
▏* Thought · 2.5s
|
|
142
144
|
```
|
|
143
145
|
|
|
144
|
-
The live label samples Pi's native braille spinner sequence from the clock each time the TUI draws it, so it steps with the redraws Pi's working indicator already drives instead of freezing between bursty thinking deltas. It does not add a timer; with the working indicator hidden, the spinner advances on each content update. The adapter stores the first local streaming timestamp per assistant row in a `WeakMap`. A restored message or an older runtime with no streaming argument uses
|
|
146
|
+
The live label samples Pi's native braille spinner sequence from the clock each time the TUI draws it, so it steps with the redraws Pi's working indicator already drives instead of freezing between bursty thinking deltas. It does not add a timer; with the working indicator hidden, the spinner advances on each content update. The adapter stores the first local streaming timestamp per assistant row in a `WeakMap`. A restored message or an older runtime with no streaming argument uses `▏* Thought`. Both labels keep a faint `▏` rail and a bold glyph. The spinner holds the glyph slot and settles into `*` in place: the rail and the label text keep their columns, and the rail keeps the settled tone throughout. There is no interval, timeout, render request, model call, or network work.
|
|
145
147
|
|
|
146
148
|
Pi renders thinking labels and traces italic. This package drops those italics: both labels read as plain collapsed rows (the live spinner keeps its thinking-level tint, the settled row the muted tone, and a theme that resolves no color still loses the italics), and a visible trace stays italic only while it streams, then settles into ordinary transcript text. `PI_TOOL_CALL_MARKERS_THOUGHT_COLOR=inherit` is the opt-out that keeps Pi's native italic `thinkingText` styling.
|
|
147
149
|
|
|
@@ -175,7 +177,7 @@ Names are comma-separated and matched exactly. Listed rows never join a group, a
|
|
|
175
177
|
|
|
176
178
|
### Collapsed-row colors
|
|
177
179
|
|
|
178
|
-
Collapsed rows (tool calls,
|
|
180
|
+
Collapsed rows (tool calls, `▏* Thought`, subagents) default to the theme's `dim` color — it ships with every Pi theme and sits below `muted`, including in the generated `system` theme — with the row's anchor and the call content sharing it. Failures stay error-colored and live spinners keep their existing tints.
|
|
179
181
|
|
|
180
182
|
A theme can override each collapsed kind independently with optional color tokens:
|
|
181
183
|
|
package/package.json
CHANGED
package/src/bash-block.ts
CHANGED
|
@@ -59,20 +59,25 @@ function renderBashBlockLines(
|
|
|
59
59
|
theme: ThemeLike,
|
|
60
60
|
status: string | undefined,
|
|
61
61
|
inset = promptBlockInset(width),
|
|
62
|
-
): string[] {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
): string[] | undefined {
|
|
63
|
+
try {
|
|
64
|
+
const [spacer, ...rest] = lines;
|
|
65
|
+
const topRule = isRuleLine(rest[0]) ? rest[0] : undefined;
|
|
66
|
+
const inner = topRule !== undefined ? rest.slice(1) : rest.slice();
|
|
67
|
+
if (isRuleLine(inner[inner.length - 1])) inner.pop();
|
|
68
|
+
const railColor = bashBlockRailColor(status, topRule, theme);
|
|
69
|
+
const block = renderRailedBlockLines(
|
|
70
|
+
["", ...inner, ""],
|
|
71
|
+
width,
|
|
72
|
+
theme,
|
|
73
|
+
inset,
|
|
74
|
+
railColor,
|
|
75
|
+
);
|
|
76
|
+
return [fitLine(spacer ?? "", width), ...block];
|
|
77
|
+
} catch {
|
|
78
|
+
// Decoration is optional; the caller retries Pi's native full-width render.
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
type BashRow = { status?: unknown };
|
|
@@ -154,6 +159,7 @@ function installBashBlockPatch(): BashBlockPatchState | undefined {
|
|
|
154
159
|
typeof status === "string" ? status : undefined,
|
|
155
160
|
inset,
|
|
156
161
|
);
|
|
162
|
+
if (!decorated) return state.originalRender.call(this, width);
|
|
157
163
|
state.cache.set(this, { width, src: lines, lines: decorated, palette });
|
|
158
164
|
return decorated;
|
|
159
165
|
};
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
uninstallInfoVisibility,
|
|
23
23
|
} from "./info-visibility.ts";
|
|
24
24
|
import {
|
|
25
|
-
|
|
25
|
+
COLLAPSED_RAIL,
|
|
26
26
|
fgCollapsed,
|
|
27
27
|
paletteSample,
|
|
28
28
|
withFaintCollapsedRail,
|
|
@@ -31,12 +31,13 @@ import { isQuestionToolCall, renderQuestionBlock } from "./question-block.ts";
|
|
|
31
31
|
import { sanitizeInline } from "./sanitize.ts";
|
|
32
32
|
|
|
33
33
|
const OUTER_INSET = 2;
|
|
34
|
+
// Glyphless rows leave room for the glyph and its trailing space.
|
|
35
|
+
const SUBAGENT_LABEL_GAP = " ";
|
|
34
36
|
// Collapsed rows anchor with a glyph instead of repeating the tool name;
|
|
35
37
|
// tools that read as one family share a glyph, and unmapped tools fall back
|
|
36
38
|
// to `*`. A single space separates the glyph from the call content: the
|
|
37
39
|
// anchor is punctuation enough without a joining colon.
|
|
38
40
|
const TOOL_CALL_GLYPHS: ReadonlyMap<string, string> = new Map([
|
|
39
|
-
["read", "●"],
|
|
40
41
|
["write", "+"],
|
|
41
42
|
["edit", "±"],
|
|
42
43
|
["grep", "○"],
|
|
@@ -127,12 +128,16 @@ type GroupingPatchState = {
|
|
|
127
128
|
disabled?: boolean;
|
|
128
129
|
};
|
|
129
130
|
|
|
131
|
+
type GroupMemberSnapshot = {
|
|
132
|
+
readonly row: ToolExecutionRow;
|
|
133
|
+
readonly version: number;
|
|
134
|
+
};
|
|
135
|
+
|
|
130
136
|
type GroupRenderCache = {
|
|
131
137
|
lines: string[];
|
|
132
138
|
// The first member absorbs the leading blank; each member owns its line.
|
|
133
139
|
heights: Array<{ component: ToolExecutionRow; height: number }>;
|
|
134
|
-
|
|
135
|
-
memberVersions: number[];
|
|
140
|
+
memberSnapshots: readonly GroupMemberSnapshot[];
|
|
136
141
|
themeSample: string;
|
|
137
142
|
width: number;
|
|
138
143
|
};
|
|
@@ -181,14 +186,6 @@ function rowSignatureOf(row: ToolExecutionRow): string {
|
|
|
181
186
|
return `${row.isPartial}|${row.expanded}|${row.result ? 1 : 0}|${row.result?.isError ? 1 : 0}`;
|
|
182
187
|
}
|
|
183
188
|
|
|
184
|
-
// Render caches hold lines with resolved colors baked in, so they key on the
|
|
185
|
-
// palette's values rather than the theme object: Pi swaps the colors behind a
|
|
186
|
-
// stable Proxy, which made an identity key survive a theme switch. Probing is
|
|
187
|
-
// a handful of map lookups per row per frame.
|
|
188
|
-
function themeSampleFor(theme: ThemeLike): string {
|
|
189
|
-
return paletteSample(theme);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
189
|
type InsetLayout = {
|
|
193
190
|
contentWidth: number;
|
|
194
191
|
left: number;
|
|
@@ -506,36 +503,29 @@ function liveElapsedText(row: ToolExecutionRow): string | undefined {
|
|
|
506
503
|
return formatDuration(Math.max(0, Date.now() - startedAt));
|
|
507
504
|
}
|
|
508
505
|
|
|
509
|
-
function
|
|
510
|
-
return
|
|
511
|
-
row.expanded === false &&
|
|
512
|
-
(row.isPartial !== false || !row.result) &&
|
|
513
|
-
!hasImageResult(row)
|
|
514
|
-
);
|
|
506
|
+
function isPendingRow(row: ToolExecutionRow): boolean {
|
|
507
|
+
return row.isPartial !== false || !row.result;
|
|
515
508
|
}
|
|
516
509
|
|
|
517
|
-
function
|
|
518
|
-
return (
|
|
519
|
-
row.expanded === false &&
|
|
520
|
-
row.isPartial === false &&
|
|
521
|
-
!!row.result &&
|
|
522
|
-
!rowHasFailed(row) &&
|
|
523
|
-
!hasImageResult(row)
|
|
524
|
-
);
|
|
510
|
+
function isLiveRow(row: ToolExecutionRow): boolean {
|
|
511
|
+
return row.expanded === false && isPendingRow(row) && !hasImageResult(row);
|
|
525
512
|
}
|
|
526
513
|
|
|
527
514
|
// Settled failures join groups like settled successes; the row's error
|
|
528
515
|
// color carries the failure, so the group stays visually unbroken.
|
|
529
|
-
function
|
|
516
|
+
function isCollapsibleRow(row: ToolExecutionRow): boolean {
|
|
530
517
|
return (
|
|
531
518
|
row.expanded === false &&
|
|
532
519
|
row.isPartial === false &&
|
|
533
520
|
!!row.result &&
|
|
534
|
-
rowHasFailed(row) &&
|
|
535
521
|
!hasImageResult(row)
|
|
536
522
|
);
|
|
537
523
|
}
|
|
538
524
|
|
|
525
|
+
function isCollapsibleSuccess(row: ToolExecutionRow): boolean {
|
|
526
|
+
return isCollapsibleRow(row) && !rowHasFailed(row);
|
|
527
|
+
}
|
|
528
|
+
|
|
539
529
|
function hasToolSiblingInAssistantBatch(
|
|
540
530
|
children: unknown[],
|
|
541
531
|
index: number,
|
|
@@ -576,12 +566,7 @@ function isGroupableToolRow(
|
|
|
576
566
|
if (row.toolName === "subagent") return false;
|
|
577
567
|
if (isQuestionToolCall(row)) return false;
|
|
578
568
|
if (drawsNoRowLines(row, renderAt(index))) return false;
|
|
579
|
-
if (
|
|
580
|
-
!isLiveRow(row) &&
|
|
581
|
-
!isCollapsibleSuccess(row) &&
|
|
582
|
-
!isCollapsibleFailure(row)
|
|
583
|
-
)
|
|
584
|
-
return false;
|
|
569
|
+
if (!isLiveRow(row) && !isCollapsibleRow(row)) return false;
|
|
585
570
|
return (
|
|
586
571
|
state.collapseParallel ||
|
|
587
572
|
!hasToolSiblingInAssistantBatch(children, index, renderAt)
|
|
@@ -966,7 +951,7 @@ function collapsedAnchor(
|
|
|
966
951
|
fgCollapsed(theme, "muted", marker),
|
|
967
952
|
);
|
|
968
953
|
return glyph === undefined
|
|
969
|
-
? rail
|
|
954
|
+
? `${rail}${SUBAGENT_LABEL_GAP}`
|
|
970
955
|
: `${rail}${fgCollapsed(theme, color, glyph, true)} `;
|
|
971
956
|
}
|
|
972
957
|
|
|
@@ -1028,7 +1013,7 @@ function collapsedSeam(
|
|
|
1028
1013
|
// labels still carry it; a subagent fallback keeps `subagent` as its own
|
|
1029
1014
|
// heading, which the scrape dropped.
|
|
1030
1015
|
const text = isSubagent
|
|
1031
|
-
?
|
|
1016
|
+
? subagentFallbackLabel(row.args, plain)
|
|
1032
1017
|
: selfRendered
|
|
1033
1018
|
? dropCallToken(plain, row.toolName ?? "tool")
|
|
1034
1019
|
: plain;
|
|
@@ -1059,7 +1044,7 @@ function collapsedOutcome(
|
|
|
1059
1044
|
theme,
|
|
1060
1045
|
);
|
|
1061
1046
|
}
|
|
1062
|
-
if (
|
|
1047
|
+
if (isPendingRow(row)) {
|
|
1063
1048
|
const elapsed = liveElapsedText(row);
|
|
1064
1049
|
return theme.fg("warning", elapsed ? `… · ${elapsed}` : "…");
|
|
1065
1050
|
}
|
|
@@ -1101,6 +1086,35 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
1101
1086
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1102
1087
|
}
|
|
1103
1088
|
|
|
1089
|
+
function defaultSubagentEmoji(args: unknown): string {
|
|
1090
|
+
if (!isRecord(args)) return "👾";
|
|
1091
|
+
if (
|
|
1092
|
+
typeof args.profile === "string" &&
|
|
1093
|
+
args.profile.trim() === "coder" &&
|
|
1094
|
+
args.model === undefined
|
|
1095
|
+
)
|
|
1096
|
+
return "🧑💻";
|
|
1097
|
+
return typeof args.action === "string" &&
|
|
1098
|
+
[
|
|
1099
|
+
"interactive",
|
|
1100
|
+
"list",
|
|
1101
|
+
"status",
|
|
1102
|
+
"send",
|
|
1103
|
+
"wait",
|
|
1104
|
+
"stop",
|
|
1105
|
+
"resume",
|
|
1106
|
+
].includes(args.action)
|
|
1107
|
+
? "🤖"
|
|
1108
|
+
: "👾";
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
function subagentFallbackLabel(args: unknown, summary: string): string {
|
|
1112
|
+
const { displayName, bareName } = parseStepContent(summary);
|
|
1113
|
+
const prefix =
|
|
1114
|
+
displayName === bareName ? `${defaultSubagentEmoji(args)} ` : "";
|
|
1115
|
+
return `subagent ${prefix}${summary}`.trimEnd();
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1104
1118
|
type SubagentStep = {
|
|
1105
1119
|
agent: string;
|
|
1106
1120
|
profile: string | undefined;
|
|
@@ -1110,7 +1124,7 @@ type SubagentStep = {
|
|
|
1110
1124
|
type SubagentPlan = {
|
|
1111
1125
|
kind: "single" | "parallel" | "chain";
|
|
1112
1126
|
scope: string;
|
|
1113
|
-
steps: SubagentStep[];
|
|
1127
|
+
steps: readonly [SubagentStep, ...SubagentStep[]];
|
|
1114
1128
|
};
|
|
1115
1129
|
|
|
1116
1130
|
function parseSubagentArgs(args: unknown): SubagentPlan | undefined {
|
|
@@ -1146,30 +1160,40 @@ function parseSubagentArgs(args: unknown): SubagentPlan | undefined {
|
|
|
1146
1160
|
};
|
|
1147
1161
|
};
|
|
1148
1162
|
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1163
|
+
const multiStepMode = hasParallel
|
|
1164
|
+
? { kind: "parallel" as const, input: args.tasks as unknown[] }
|
|
1165
|
+
: hasChain
|
|
1166
|
+
? { kind: "chain" as const, input: args.chain as unknown[] }
|
|
1167
|
+
: undefined;
|
|
1168
|
+
|
|
1169
|
+
if (multiStepMode) {
|
|
1170
|
+
const parsedSteps = multiStepMode.input.map(parseStep);
|
|
1171
|
+
const steps: SubagentStep[] = [];
|
|
1172
|
+
for (const step of parsedSteps) {
|
|
1173
|
+
if (step === undefined) return undefined;
|
|
1174
|
+
steps.push(step);
|
|
1175
|
+
}
|
|
1176
|
+
const firstStep = steps[0];
|
|
1177
|
+
if (firstStep === undefined) return undefined;
|
|
1178
|
+
const nonEmptySteps: readonly [SubagentStep, ...SubagentStep[]] = [
|
|
1179
|
+
firstStep,
|
|
1180
|
+
...steps.slice(1),
|
|
1181
|
+
];
|
|
1182
|
+
return { kind: multiStepMode.kind, scope, steps: nonEmptySteps };
|
|
1158
1183
|
}
|
|
1184
|
+
|
|
1159
1185
|
const single = parseStep(args);
|
|
1160
1186
|
if (!single) return undefined;
|
|
1161
1187
|
return { kind: "single", scope, steps: [single] };
|
|
1162
1188
|
}
|
|
1163
1189
|
|
|
1164
|
-
// Splits
|
|
1165
|
-
// carry a leading emoji) and the remaining badge/preview text.
|
|
1190
|
+
// Splits scraped plan content into the emoji-capable display name and its bare lookup name.
|
|
1166
1191
|
function parseStepContent(content: string): {
|
|
1167
1192
|
displayName: string;
|
|
1168
1193
|
bareName: string;
|
|
1169
|
-
rest: string;
|
|
1170
1194
|
} {
|
|
1171
1195
|
const tokens = content.trim().split(/\s+/).filter(Boolean);
|
|
1172
|
-
if (tokens.length === 0) return { displayName: "", bareName: ""
|
|
1196
|
+
if (tokens.length === 0) return { displayName: "", bareName: "" };
|
|
1173
1197
|
const first = tokens[0]!;
|
|
1174
1198
|
const hasEmoji = [...first].some((char) => (char.codePointAt(0) ?? 0) > 0x7f);
|
|
1175
1199
|
const nameTokens = hasEmoji && tokens.length > 1 ? 2 : 1;
|
|
@@ -1177,7 +1201,6 @@ function parseStepContent(content: string): {
|
|
|
1177
1201
|
return {
|
|
1178
1202
|
displayName,
|
|
1179
1203
|
bareName: tokens[nameTokens - 1] ?? displayName,
|
|
1180
|
-
rest: tokens.slice(nameTokens).join(" "),
|
|
1181
1204
|
};
|
|
1182
1205
|
}
|
|
1183
1206
|
|
|
@@ -1271,7 +1294,7 @@ function subagentPlanOutcome(
|
|
|
1271
1294
|
theme: ThemeLike,
|
|
1272
1295
|
): string | undefined {
|
|
1273
1296
|
if (failed) return collapsedOutcome(row, budget, theme);
|
|
1274
|
-
if (
|
|
1297
|
+
if (isPendingRow(row))
|
|
1275
1298
|
return theme.fg("warning", progress ? `→ ${progress}` : "…");
|
|
1276
1299
|
if (row.result)
|
|
1277
1300
|
return fgCollapsed(
|
|
@@ -1306,7 +1329,11 @@ function renderSubagentPlan(
|
|
|
1306
1329
|
displayNames.get(step.agent) ?? sanitizeInline(step.agent);
|
|
1307
1330
|
const { emoji, name } = splitEmojiName(displayName, step.agent);
|
|
1308
1331
|
const accentPart = (text: string) => fgCollapsed(theme, nameColor, text);
|
|
1309
|
-
const
|
|
1332
|
+
const fallbackEmoji = defaultSubagentEmoji({
|
|
1333
|
+
action: isRecord(row.args) ? row.args.action : undefined,
|
|
1334
|
+
profile: step.profile,
|
|
1335
|
+
});
|
|
1336
|
+
const emojiPart = `${accentPart(emoji || fallbackEmoji)} `;
|
|
1310
1337
|
const profilePart = step.profile
|
|
1311
1338
|
? accentPart(`[${sanitizeInline(step.profile)}]`)
|
|
1312
1339
|
: "";
|
|
@@ -1327,7 +1354,7 @@ function renderSubagentPlan(
|
|
|
1327
1354
|
: fitSummary(label, budget, suffix));
|
|
1328
1355
|
|
|
1329
1356
|
if (plan.kind === "single") {
|
|
1330
|
-
const step = plan.steps[0]
|
|
1357
|
+
const step = plan.steps[0];
|
|
1331
1358
|
return [headline(identityOf(step) + previewOf(step))];
|
|
1332
1359
|
}
|
|
1333
1360
|
|
|
@@ -1343,7 +1370,9 @@ function renderSubagentPlan(
|
|
|
1343
1370
|
fgCollapsed(theme, failed ? "error" : "toolOutput", ` [${plan.scope}]`),
|
|
1344
1371
|
),
|
|
1345
1372
|
];
|
|
1346
|
-
const stepIndent = " ".repeat(
|
|
1373
|
+
const stepIndent = " ".repeat(
|
|
1374
|
+
visibleWidth(COLLAPSED_RAIL + SUBAGENT_LABEL_GAP),
|
|
1375
|
+
);
|
|
1347
1376
|
const shown = plan.steps.slice(0, 3);
|
|
1348
1377
|
for (let index = 0; index < shown.length; index++) {
|
|
1349
1378
|
const step = shown[index]!;
|
|
@@ -1427,25 +1456,17 @@ function renderGroupedCallLines(
|
|
|
1427
1456
|
return segments;
|
|
1428
1457
|
}
|
|
1429
1458
|
|
|
1430
|
-
function
|
|
1431
|
-
|
|
1432
|
-
right: ToolExecutionRow[],
|
|
1433
|
-
): boolean {
|
|
1434
|
-
return (
|
|
1435
|
-
left.length === right.length &&
|
|
1436
|
-
left.every((member, index) => member === right[index])
|
|
1437
|
-
);
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
function sameMemberVersions(
|
|
1459
|
+
function sameMemberSnapshots(
|
|
1460
|
+
snapshots: readonly GroupMemberSnapshot[],
|
|
1441
1461
|
rows: ToolExecutionRow[],
|
|
1442
|
-
versions: number[],
|
|
1443
1462
|
state: PresentationPatchState,
|
|
1444
1463
|
): boolean {
|
|
1445
1464
|
return (
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
(
|
|
1465
|
+
snapshots.length === rows.length &&
|
|
1466
|
+
snapshots.every(
|
|
1467
|
+
(snapshot, index) =>
|
|
1468
|
+
snapshot.row === rows[index] &&
|
|
1469
|
+
snapshot.version === (state.rowVersions.get(snapshot.row) ?? 0),
|
|
1449
1470
|
)
|
|
1450
1471
|
);
|
|
1451
1472
|
}
|
|
@@ -1468,7 +1489,7 @@ function renderGroupedToolRows(
|
|
|
1468
1489
|
const lines = state.originalRender.call(row, width);
|
|
1469
1490
|
return { lines, heights: [{ component: row, height: lines.length }] };
|
|
1470
1491
|
}
|
|
1471
|
-
const themeSample =
|
|
1492
|
+
const themeSample = paletteSample(theme);
|
|
1472
1493
|
const cached = state.groupCache.get(row);
|
|
1473
1494
|
const hasLiveMembers = rows.some(isLiveRow);
|
|
1474
1495
|
if (
|
|
@@ -1476,8 +1497,7 @@ function renderGroupedToolRows(
|
|
|
1476
1497
|
cached &&
|
|
1477
1498
|
cached.width === width &&
|
|
1478
1499
|
cached.themeSample === themeSample &&
|
|
1479
|
-
|
|
1480
|
-
sameMemberVersions(rows, cached.memberVersions, state)
|
|
1500
|
+
sameMemberSnapshots(cached.memberSnapshots, rows, state)
|
|
1481
1501
|
) {
|
|
1482
1502
|
return { lines: cached.lines, heights: cached.heights };
|
|
1483
1503
|
}
|
|
@@ -1507,8 +1527,10 @@ function renderGroupedToolRows(
|
|
|
1507
1527
|
state.groupCache.set(row, {
|
|
1508
1528
|
lines,
|
|
1509
1529
|
heights,
|
|
1510
|
-
|
|
1511
|
-
|
|
1530
|
+
memberSnapshots: rows.map((member) => ({
|
|
1531
|
+
row: member,
|
|
1532
|
+
version: state.rowVersions.get(member) ?? 0,
|
|
1533
|
+
})),
|
|
1512
1534
|
themeSample,
|
|
1513
1535
|
width,
|
|
1514
1536
|
});
|
|
@@ -1827,7 +1849,7 @@ function installPresentationPatch(): PresentationPatchState | undefined {
|
|
|
1827
1849
|
if (!this.isPartial) {
|
|
1828
1850
|
const signature = rowSignatureOf(this);
|
|
1829
1851
|
const version = state.rowVersions.get(this) ?? 0;
|
|
1830
|
-
const themeSample =
|
|
1852
|
+
const themeSample = paletteSample(theme);
|
|
1831
1853
|
const cached = state.collapsedCache.get(this);
|
|
1832
1854
|
if (
|
|
1833
1855
|
cached &&
|
package/src/muted.ts
CHANGED
|
@@ -10,18 +10,14 @@
|
|
|
10
10
|
//
|
|
11
11
|
// Failures always fall back to the historical tokens.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const COLLAPSED_RAIL_PREFIX = ` ${COLLAPSED_RAIL} `;
|
|
13
|
+
// The thin rail shares the submitted prompt bar's left edge.
|
|
14
|
+
export const COLLAPSED_RAIL = "▏";
|
|
16
15
|
|
|
17
16
|
// Faint keeps the rail quieter than the label, even on failed rows.
|
|
18
17
|
export function withFaintCollapsedRail(
|
|
19
18
|
style: (rail: string) => string,
|
|
20
19
|
): string {
|
|
21
|
-
return
|
|
22
|
-
COLLAPSED_RAIL,
|
|
23
|
-
() => `\x1b[2m${style(COLLAPSED_RAIL)}\x1b[22m`,
|
|
24
|
-
);
|
|
20
|
+
return `\x1b[2m${style(COLLAPSED_RAIL)}\x1b[22m`;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
const TOOL_OVERRIDE_TOKEN = "collapsedToolCall";
|
package/src/question-block.ts
CHANGED
|
@@ -51,7 +51,8 @@ const DECLINE_TEXT = "User declined to answer questions";
|
|
|
51
51
|
const AWAITING_TEXT = "awaiting your answer…";
|
|
52
52
|
const NO_ANSWER_TEXT = "(no answer)";
|
|
53
53
|
const QUESTION_PREFIX = "> ";
|
|
54
|
-
|
|
54
|
+
// Start the answer label under the question text, not its quote marker.
|
|
55
|
+
const ANSWER_PREFIX = `${" ".repeat(visibleWidth(QUESTION_PREFIX))}User: `;
|
|
55
56
|
|
|
56
57
|
// Question tools keep the ask-tool vocabulary in their name even when they
|
|
57
58
|
// invent their own result shape. The result-shape check is the primary signal;
|
|
@@ -244,7 +245,11 @@ function italics(theme: QuestionTheme, text: string): string {
|
|
|
244
245
|
// width math exact and lets the shell's own fit pass stay a no-op.
|
|
245
246
|
function wrapPlain(text: string, width: number): string[] {
|
|
246
247
|
const max = Math.max(1, width);
|
|
247
|
-
const words = text
|
|
248
|
+
const words = sanitizeInline(text)
|
|
249
|
+
.replace(/\s+/g, " ")
|
|
250
|
+
.trim()
|
|
251
|
+
.split(" ")
|
|
252
|
+
.filter(Boolean);
|
|
248
253
|
if (words.length === 0) return [""];
|
|
249
254
|
|
|
250
255
|
const lines: string[] = [];
|
|
@@ -325,6 +330,7 @@ export function renderQuestionBlock(
|
|
|
325
330
|
): string[] | undefined {
|
|
326
331
|
const details = row.result?.details;
|
|
327
332
|
if (!isQuestionToolCall(row)) return undefined;
|
|
333
|
+
if (row.result?.isError) return undefined;
|
|
328
334
|
if (isRecord(details) && typeof details.error === "string") return undefined;
|
|
329
335
|
|
|
330
336
|
const lines = questionLines(row, details);
|
|
@@ -2,12 +2,13 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { AssistantMessageComponent } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { infoVisibilityHidden } from "./info-visibility-state.ts";
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
COLLAPSED_RAIL,
|
|
6
6
|
collapsedThinkingAnsi,
|
|
7
7
|
withFaintCollapsedRail,
|
|
8
8
|
} from "./muted.ts";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// v2 wrappers close over module-local providers and cannot adopt shared contexts.
|
|
11
|
+
const THINKING_GROUPING_PATCHED = Symbol.for("kg.pi.thinkingGrouping.v3");
|
|
11
12
|
const PI_SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
12
13
|
const SPINNER_INTERVAL_MS = 80;
|
|
13
14
|
|
|
@@ -49,10 +50,18 @@ type ThemeDetail = {
|
|
|
49
50
|
getColorMode?(): "truecolor" | "256color" | string;
|
|
50
51
|
};
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
type ThinkingStylingContext = {
|
|
54
|
+
theme(): ThemeDetail | undefined;
|
|
55
|
+
level(): string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Entrypoints load uncached. A buried wrapper and every new owner must read
|
|
59
|
+
// the same contexts; the last session to start supplies live theme/level getters.
|
|
60
|
+
let stylingContexts = new Map<object, ThinkingStylingContext>();
|
|
61
|
+
|
|
62
|
+
function currentStylingContext(): ThinkingStylingContext | undefined {
|
|
63
|
+
return [...stylingContexts.values()].at(-1);
|
|
64
|
+
}
|
|
56
65
|
// Pi builds both thinking labels italic. The default treatment replaces that
|
|
57
66
|
// with a plain row: italic-off always leads — the TUI diff renderer can skip
|
|
58
67
|
// bytes shared with the previous italic frame, which would leave the terminal
|
|
@@ -65,7 +74,10 @@ type LabelStyle = { prefix: string; suffix: string };
|
|
|
65
74
|
// The package styles labels only inside a session it can read the theme from.
|
|
66
75
|
// `inherit` is the other native case: it keeps Pi's italic labels.
|
|
67
76
|
function stylesThinkingLabels(): boolean {
|
|
68
|
-
return
|
|
77
|
+
return (
|
|
78
|
+
currentStylingContext() !== undefined &&
|
|
79
|
+
thoughtLabelColorChoice() !== "inherit"
|
|
80
|
+
);
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
function styledWith(
|
|
@@ -105,7 +117,8 @@ function labelStyle(
|
|
|
105
117
|
const token =
|
|
106
118
|
choice === "mdheading"
|
|
107
119
|
? "mdHeading"
|
|
108
|
-
: (LEVEL_TOKEN[
|
|
120
|
+
: (LEVEL_TOKEN[currentStylingContext()?.level() ?? "off"] ??
|
|
121
|
+
"thinkingOff");
|
|
109
122
|
return styledWith(token, theme);
|
|
110
123
|
}
|
|
111
124
|
|
|
@@ -114,9 +127,9 @@ function labelStyle(
|
|
|
114
127
|
// the glyph slot and settles into `*` in place: the rail and the label text
|
|
115
128
|
// keep their columns, and only the glyph, the words, and the tint change.
|
|
116
129
|
const THOUGHT_GLYPH = "*";
|
|
117
|
-
const SETTLED_THOUGHT = `${
|
|
130
|
+
const SETTLED_THOUGHT = `${COLLAPSED_RAIL}${THOUGHT_GLYPH} Thought`;
|
|
118
131
|
const ANCHORED_LABEL_RE = new RegExp(
|
|
119
|
-
String.raw`^${
|
|
132
|
+
String.raw`^${COLLAPSED_RAIL}(\S) (.*)$`,
|
|
120
133
|
"su",
|
|
121
134
|
);
|
|
122
135
|
|
|
@@ -143,8 +156,8 @@ function styledAnchoredLabel(
|
|
|
143
156
|
|
|
144
157
|
export function visibleThoughtLabel(label: string): string {
|
|
145
158
|
if (!stylesThinkingLabels()) return label;
|
|
146
|
-
const raw = label
|
|
147
|
-
const theme =
|
|
159
|
+
const raw = plainText(label);
|
|
160
|
+
const theme = currentStylingContext()?.theme();
|
|
148
161
|
const settled = isSettledThoughtLabel(raw);
|
|
149
162
|
const style = theme ? labelStyle(settled, theme) : undefined;
|
|
150
163
|
// A theme that cannot resolve a color still drops Pi's italics.
|
|
@@ -321,13 +334,20 @@ function restyleHiddenThinkingLabel(
|
|
|
321
334
|
});
|
|
322
335
|
}
|
|
323
336
|
|
|
324
|
-
type ThinkingTiming =
|
|
325
|
-
|
|
326
|
-
startedAt: number
|
|
327
|
-
|
|
337
|
+
type ThinkingTiming =
|
|
338
|
+
| { readonly kind: "untimed" }
|
|
339
|
+
| { readonly kind: "live"; readonly startedAt: number }
|
|
340
|
+
| {
|
|
341
|
+
readonly kind: "settled";
|
|
342
|
+
readonly startedAt: number;
|
|
343
|
+
readonly finishedAt: number;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const UNTIMED_THINKING_TIMING: ThinkingTiming = { kind: "untimed" };
|
|
328
347
|
|
|
329
348
|
type ThinkingGroupingPatchState = {
|
|
330
349
|
owners: number;
|
|
350
|
+
stylingContexts: Map<object, ThinkingStylingContext>;
|
|
331
351
|
// Set at the final owner's shutdown. A wrapper another extension has buried
|
|
332
352
|
// cannot be uninstalled, so it delegates instead of outliving its owner; a
|
|
333
353
|
// later install re-enables it.
|
|
@@ -430,7 +450,7 @@ function formatThoughtDuration(startedAt: number, finishedAt: number): string {
|
|
|
430
450
|
}
|
|
431
451
|
|
|
432
452
|
function liveThinkingLabel(startedAt: number, now: number): string {
|
|
433
|
-
return `${
|
|
453
|
+
return `${COLLAPSED_RAIL}${thinkingSpinner(startedAt, now)} Thinking…`;
|
|
434
454
|
}
|
|
435
455
|
|
|
436
456
|
function thinkingSpinner(startedAt: number, now: number): string {
|
|
@@ -438,22 +458,6 @@ function thinkingSpinner(startedAt: number, now: number): string {
|
|
|
438
458
|
return PI_SPINNER_FRAMES[frame % PI_SPINNER_FRAMES.length]!;
|
|
439
459
|
}
|
|
440
460
|
|
|
441
|
-
// A row is live while it streams, and stays live through un-flagged rebuilds
|
|
442
|
-
// (resize, theme switch, /reload) until an explicit final update arrives.
|
|
443
|
-
// Rows that never carry the flag — restored history, older runtimes — count
|
|
444
|
-
// as settled.
|
|
445
|
-
function thinkingStillLive(
|
|
446
|
-
streaming: boolean | undefined,
|
|
447
|
-
timing: ThinkingTiming | undefined,
|
|
448
|
-
): boolean {
|
|
449
|
-
if (streaming === true) return true;
|
|
450
|
-
return (
|
|
451
|
-
streaming === undefined &&
|
|
452
|
-
timing !== undefined &&
|
|
453
|
-
timing.finishedAt === undefined
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
461
|
// Thinking ends when the answer starts: visible text or a tool call after
|
|
458
462
|
// the last thinking block. Settling there keeps the duration honest and
|
|
459
463
|
// keeps a live label as the transcript's last line, so its spinner never
|
|
@@ -473,15 +477,41 @@ function answerStarted(message: AssistantMessageLike): boolean {
|
|
|
473
477
|
});
|
|
474
478
|
}
|
|
475
479
|
|
|
476
|
-
|
|
480
|
+
type ThinkingTimingUpdate =
|
|
481
|
+
| { readonly kind: "begin"; readonly now: number }
|
|
482
|
+
| { readonly kind: "rebuild" }
|
|
483
|
+
| { readonly kind: "finish"; readonly now: number };
|
|
484
|
+
|
|
485
|
+
function classifyThinkingUpdate(
|
|
477
486
|
streaming: boolean | undefined,
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
487
|
+
answering: boolean,
|
|
488
|
+
now: number,
|
|
489
|
+
): ThinkingTimingUpdate {
|
|
490
|
+
if (answering || streaming === false) return { kind: "finish", now };
|
|
491
|
+
if (streaming === true) return { kind: "begin", now };
|
|
492
|
+
return { kind: "rebuild" };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function transitionThinkingTiming(
|
|
496
|
+
previous: ThinkingTiming,
|
|
497
|
+
update: ThinkingTimingUpdate,
|
|
498
|
+
): ThinkingTiming {
|
|
499
|
+
switch (update.kind) {
|
|
500
|
+
case "begin":
|
|
501
|
+
return previous.kind === "live"
|
|
502
|
+
? previous
|
|
503
|
+
: { kind: "live", startedAt: update.now };
|
|
504
|
+
case "rebuild":
|
|
505
|
+
return previous;
|
|
506
|
+
case "finish":
|
|
507
|
+
return previous.kind === "live"
|
|
508
|
+
? {
|
|
509
|
+
kind: "settled",
|
|
510
|
+
startedAt: previous.startedAt,
|
|
511
|
+
finishedAt: update.now,
|
|
512
|
+
}
|
|
513
|
+
: previous;
|
|
514
|
+
}
|
|
485
515
|
}
|
|
486
516
|
|
|
487
517
|
function lifecycleLabel(
|
|
@@ -489,32 +519,25 @@ function lifecycleLabel(
|
|
|
489
519
|
message: AssistantMessageLike,
|
|
490
520
|
streaming: boolean | undefined,
|
|
491
521
|
timings: WeakMap<AssistantMessageRow, ThinkingTiming>,
|
|
492
|
-
): string {
|
|
522
|
+
): { label: string; timing: ThinkingTiming } {
|
|
493
523
|
const now = Date.now();
|
|
494
|
-
const
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
) {
|
|
510
|
-
previous.finishedAt = now;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
const settled = timings.get(row);
|
|
514
|
-
if (settled?.finishedAt !== undefined) {
|
|
515
|
-
return `${SETTLED_THOUGHT} · ${formatThoughtDuration(settled.startedAt, settled.finishedAt)}`;
|
|
524
|
+
const update = classifyThinkingUpdate(streaming, answerStarted(message), now);
|
|
525
|
+
const timing = transitionThinkingTiming(
|
|
526
|
+
timings.get(row) ?? UNTIMED_THINKING_TIMING,
|
|
527
|
+
update,
|
|
528
|
+
);
|
|
529
|
+
timings.set(row, timing);
|
|
530
|
+
|
|
531
|
+
let label = SETTLED_THOUGHT;
|
|
532
|
+
if (timing.kind === "live") {
|
|
533
|
+
label = liveThinkingLabel(timing.startedAt, now);
|
|
534
|
+
} else if (timing.kind === "settled") {
|
|
535
|
+
label = `${SETTLED_THOUGHT} · ${formatThoughtDuration(
|
|
536
|
+
timing.startedAt,
|
|
537
|
+
timing.finishedAt,
|
|
538
|
+
)}`;
|
|
516
539
|
}
|
|
517
|
-
return
|
|
540
|
+
return { label, timing };
|
|
518
541
|
}
|
|
519
542
|
|
|
520
543
|
function stripThinkingBlocks(
|
|
@@ -556,20 +579,21 @@ function applyHiddenThinkingLabel(
|
|
|
556
579
|
message: AssistantMessageLike,
|
|
557
580
|
streaming: boolean | undefined,
|
|
558
581
|
timings: WeakMap<AssistantMessageRow, ThinkingTiming>,
|
|
559
|
-
):
|
|
582
|
+
): ThinkingTiming {
|
|
560
583
|
// Record the component's first streaming update even when the provider has
|
|
561
584
|
// not emitted a non-empty thinking block yet.
|
|
562
|
-
const
|
|
563
|
-
if (!hasThinkingContent(message)) return;
|
|
585
|
+
const lifecycle = lifecycleLabel(row, message, streaming, timings);
|
|
586
|
+
if (!hasThinkingContent(message)) return lifecycle.timing;
|
|
564
587
|
if (
|
|
565
588
|
row.hideThinkingBlock !== true ||
|
|
566
589
|
typeof row.hiddenThinkingLabel !== "string"
|
|
567
590
|
) {
|
|
568
|
-
return;
|
|
591
|
+
return lifecycle.timing;
|
|
569
592
|
}
|
|
570
593
|
// Assign the row-local field directly. The public UI setter relabels every
|
|
571
594
|
// historical assistant row and would make earlier durations change.
|
|
572
|
-
row.hiddenThinkingLabel = label;
|
|
595
|
+
row.hiddenThinkingLabel = lifecycle.label;
|
|
596
|
+
return lifecycle.timing;
|
|
573
597
|
}
|
|
574
598
|
|
|
575
599
|
// TODO: Replace prototype patching with a public assistant-message rendering API.
|
|
@@ -591,12 +615,14 @@ function installThinkingGroupingPatch():
|
|
|
591
615
|
if (existing) {
|
|
592
616
|
existing.owners++;
|
|
593
617
|
existing.rows ??= new Map();
|
|
618
|
+
stylingContexts = existing.stylingContexts;
|
|
594
619
|
existing.disabled = false;
|
|
595
620
|
return existing;
|
|
596
621
|
}
|
|
597
622
|
|
|
598
623
|
const state: ThinkingGroupingPatchState = {
|
|
599
624
|
owners: 1,
|
|
625
|
+
stylingContexts,
|
|
600
626
|
originalUpdateContent: proto.updateContent,
|
|
601
627
|
timings: new WeakMap(),
|
|
602
628
|
rows: new Map(),
|
|
@@ -624,29 +650,31 @@ function installThinkingGroupingPatch():
|
|
|
624
650
|
} catch {
|
|
625
651
|
// Preserve the original message intact.
|
|
626
652
|
}
|
|
653
|
+
let timing = state.timings.get(this) ?? UNTIMED_THINKING_TIMING;
|
|
627
654
|
try {
|
|
628
|
-
|
|
655
|
+
// Visibility changes the display copy, not the thinking lifecycle.
|
|
656
|
+
timing = applyHiddenThinkingLabel(
|
|
657
|
+
this,
|
|
658
|
+
message,
|
|
659
|
+
streaming,
|
|
660
|
+
state.timings,
|
|
661
|
+
);
|
|
629
662
|
} catch {
|
|
630
663
|
// Preserve Pi's native label if its private row shape changes.
|
|
664
|
+
timing = state.timings.get(this) ?? timing;
|
|
631
665
|
}
|
|
632
666
|
Reflect.apply(state.originalUpdateContent, this, [combined, ...args]);
|
|
633
667
|
try {
|
|
634
668
|
if (hasThinkingContent(combined)) {
|
|
635
|
-
const timing = state.timings.get(this);
|
|
636
669
|
const liveSince =
|
|
637
|
-
timing
|
|
638
|
-
? timing.startedAt
|
|
639
|
-
: undefined;
|
|
670
|
+
timing.kind === "live" ? timing.startedAt : undefined;
|
|
640
671
|
restyleHiddenThinkingLabel(this, combined, liveSince);
|
|
641
672
|
}
|
|
642
673
|
} catch {
|
|
643
674
|
// Keep Pi's native label styling if the row shape changes.
|
|
644
675
|
}
|
|
645
676
|
try {
|
|
646
|
-
if (
|
|
647
|
-
hasThinkingContent(combined) &&
|
|
648
|
-
!timingLive(streaming, state.timings.get(this))
|
|
649
|
-
) {
|
|
677
|
+
if (hasThinkingContent(combined) && timing.kind !== "live") {
|
|
650
678
|
unitalicizeSettledThinking(this);
|
|
651
679
|
}
|
|
652
680
|
} catch {
|
|
@@ -694,9 +722,10 @@ function uninstallThinkingGroupingPatch(
|
|
|
694
722
|
|
|
695
723
|
export default function (pi: ExtensionAPI) {
|
|
696
724
|
const patch = installThinkingGroupingPatch();
|
|
725
|
+
const owner = {};
|
|
697
726
|
let released = false;
|
|
698
727
|
pi.on("session_start", (_event, ctx) => {
|
|
699
|
-
if (ctx.mode !== "tui") return;
|
|
728
|
+
if (released || ctx.mode !== "tui") return;
|
|
700
729
|
try {
|
|
701
730
|
const proto = AssistantMessageComponent?.prototype as unknown as {
|
|
702
731
|
[THINKING_GROUPING_PATCHED]?: ThinkingGroupingPatchState;
|
|
@@ -706,20 +735,22 @@ export default function (pi: ExtensionAPI) {
|
|
|
706
735
|
// Best effort; stale rows would only linger until the process exits.
|
|
707
736
|
}
|
|
708
737
|
const uiCtx = ctx;
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
738
|
+
stylingContexts.delete(owner);
|
|
739
|
+
stylingContexts.set(owner, {
|
|
740
|
+
theme: () => uiCtx.ui?.theme as unknown as ThemeDetail,
|
|
741
|
+
level: () => {
|
|
742
|
+
try {
|
|
743
|
+
return pi.getThinkingLevel();
|
|
744
|
+
} catch {
|
|
745
|
+
return "off";
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
});
|
|
717
749
|
});
|
|
718
750
|
pi.on("session_shutdown", () => {
|
|
719
751
|
if (released) return;
|
|
720
752
|
released = true;
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
activeLevel = undefined;
|
|
753
|
+
stylingContexts.delete(owner);
|
|
754
|
+
uninstallThinkingGroupingPatch(patch);
|
|
724
755
|
});
|
|
725
756
|
}
|