@xzzpig/pi-subagents 0.13.0 → 0.14.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 +10 -0
- package/docs/configuration.md +1 -1
- package/docs/observability.md +4 -0
- package/node_modules/@xzzpig/pi-components/CHANGELOG.md +19 -0
- package/node_modules/@xzzpig/pi-components/README.md +28 -0
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.d.ts +33 -1
- package/node_modules/@xzzpig/pi-components/dist/src/transcript.js +47 -11
- package/node_modules/@xzzpig/pi-components/package.json +1 -1
- package/node_modules/@xzzpig/pi-components/src/transcript.ts +81 -8
- package/package.json +5 -5
- package/src/shared/types.ts +1 -0
- package/src/tui/fleet-native-transcript.ts +50 -6
- package/src/tui/fleet.ts +23 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.14.0] - 2026-09-13
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **The fleet inspector no longer drops replayed thinking and assistant messages.** The structured transcript view upserted thinking and assistant text per turn (`upsertText`, whose contract is latest-wins), so a whole child turn collapsed into its last thinking block and last answer — measured on real transcripts, 38 thinking blocks became 1 entry, and it rendered at the very top of the panel while the view auto-followed the bottom. Replay now appends one entry per persisted assistant message, opens a new turn after a finished answer (so the reader's tail window no longer needs the original user record to separate turns), and reads a 600-record window instead of 240 (still capped by the 2 MiB byte limit).
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **Thinking expansion in the fleet inspector.** Replayed thinking blocks are collapsed by default to a `Thinking (t/T to expand)` label; the new `toggleThinking` Fleet binding (`t`/`T`) expands and collapses them. The plain-text view (`v`) carries no thinking entries, so the toggle stays inert there.
|
|
12
|
+
|
|
3
13
|
## [0.13.0] - 2026-09-11
|
|
4
14
|
|
|
5
15
|
### Changed
|
package/docs/configuration.md
CHANGED
|
@@ -183,7 +183,7 @@ Places the persistent FleetView either `"belowEditor"` or `"aboveEditor"`. The d
|
|
|
183
183
|
|
|
184
184
|
Customizes only the full Fleet inspector opened by `/subagents-fleet` or FleetView inspection. It does not change Pi's global keybindings or the compact persistent FleetView.
|
|
185
185
|
|
|
186
|
-
Each action accepts a non-empty array of key strings. Configured actions replace their defaults. Unset actions keep the defaults: `selectUp` is `up`/`k`, `selectDown` is `down`/`j`, `scrollUp` is `K`, `scrollDown` is `J`, `pageUp` is `pageUp`, `pageDown` is `pageDown`, `selectFirst` is `home`, `selectLast` is `end`, `toggleTools` is `x`/`X`/`ctrl+o`, `refresh` is `r`/`R`, `steer` is `s`, `stop` is `D`, `inspect` is `H`, and `close` is `escape`/`ctrl+c`/`q`.
|
|
186
|
+
Each action accepts a non-empty array of key strings. Configured actions replace their defaults. Unset actions keep the defaults: `selectUp` is `up`/`k`, `selectDown` is `down`/`j`, `scrollUp` is `K`, `scrollDown` is `J`, `pageUp` is `pageUp`, `pageDown` is `pageDown`, `selectFirst` is `home`, `selectLast` is `end`, `toggleTools` is `x`/`X`/`ctrl+o`, `toggleThinking` is `t`/`T`, `toggleRenderer` is `v`/`V`, `refresh` is `r`/`R`, `steer` is `s`, `stop` is `D`, `inspect` is `H`, and `close` is `escape`/`ctrl+c`/`q`.
|
|
187
187
|
|
|
188
188
|
Prompt modes keep their fixed keys. For example, `Esc` still cancels steer text or stop confirmation even when the Fleet-level close binding is changed.
|
|
189
189
|
|
package/docs/observability.md
CHANGED
|
@@ -72,6 +72,8 @@ Default keys:
|
|
|
72
72
|
- `Shift+K`/`Shift+J` — scroll one line
|
|
73
73
|
- `PgUp`/`PgDn` — scroll one page
|
|
74
74
|
- `x`/`Ctrl+O` — toggle tool details
|
|
75
|
+
- `t`/`T` — expand or collapse the replayed assistant thinking blocks
|
|
76
|
+
- `v` — switch between the structured transcript and the plain-text view
|
|
75
77
|
- `r` — refresh
|
|
76
78
|
- `Esc` — close
|
|
77
79
|
- `Enter` — open the selected inspectable async child in its child-specific Herdr inspector
|
|
@@ -81,6 +83,8 @@ Default keys:
|
|
|
81
83
|
|
|
82
84
|
Set `fleetKeybindings` in the extension config to replace inspector-level keys when a terminal intercepts keys such as `PgUp`, `PgDn`, `Home`, or `End`. Prompt modes keep fixed keys such as `Esc`, `Enter`, `Tab`, and stop-confirmation `Y`/`N`.
|
|
83
85
|
|
|
86
|
+
In the structured view every replayed assistant message keeps its own thinking block, collapsed by default to a `Thinking` label that names the expand key. The plain-text view (`v`) carries no thinking entries.
|
|
87
|
+
|
|
84
88
|
`Ctrl+Alt+F` opens the same inspector even while a foreground turn is active and slash input is queued.
|
|
85
89
|
|
|
86
90
|
Enter and `H` use the existing Herdr pane path. In a child-specific Herdr inspector, type ordinary guidance and press Enter to send it through the acknowledged steer channel; `steer <message>`, `status`, and `stop` remain available as explicit controls.
|
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to the internal `@xzzpig/pi-components` shared library are
|
|
4
4
|
documented here.
|
|
5
5
|
|
|
6
|
+
## 0.4.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **`appendText` and `appendAssistantMessage` builder helpers.** `upsertText`
|
|
11
|
+
is documented as latest-wins merging, which is right for repeated updates of
|
|
12
|
+
one message but collapses a replayed turn that contains several distinct
|
|
13
|
+
assistant messages into its final message. The new helpers append one entry
|
|
14
|
+
per message, so every thinking block and answer survives a replay of
|
|
15
|
+
persisted records.
|
|
16
|
+
- `TranscriptRenderOptions.hideThinkingBlock` renders assistant thinking blocks
|
|
17
|
+
collapsed to `thinkingLabel`, letting hosts that replay completed transcripts
|
|
18
|
+
own their expansion gesture (the collapsed label doubles as its hint).
|
|
19
|
+
Omitted keeps Pi's default: expanded.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- `upsertText` now documents when appending is required instead of merging.
|
|
24
|
+
|
|
6
25
|
## 0.3.0
|
|
7
26
|
|
|
8
27
|
### Added
|
|
@@ -51,6 +51,34 @@ scrolling. Hosts keep ownership of terminal mouse-reporting setup, dialog
|
|
|
51
51
|
chrome, focus behavior, input controls, session lifecycle, and cancellation
|
|
52
52
|
policy. `Esc` handling is intentionally delegated to the host overlay.
|
|
53
53
|
|
|
54
|
+
### History replay
|
|
55
|
+
|
|
56
|
+
Hosts that rebuild a transcript from persisted records write entries through
|
|
57
|
+
the public builder API (`appendEntry`, `ensureTurn`, `finishTurn`,
|
|
58
|
+
`removeTranscriptTurn`, `ensureToolCall`, `upsertToolResult`, `appendNotice`).
|
|
59
|
+
Text needs two different shapes:
|
|
60
|
+
|
|
61
|
+
- `upsertText` merges per turn (latest wins) — for one message observed
|
|
62
|
+
repeatedly, e.g. live `message_update` records.
|
|
63
|
+
- `appendText` / `appendAssistantMessage` never merge — for replaying several
|
|
64
|
+
finished assistant messages, so every thinking block and answer stays
|
|
65
|
+
visible instead of collapsing into the last one.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const turnId = ensureTurn(state);
|
|
69
|
+
appendAssistantMessage(state, turnId, {
|
|
70
|
+
thinking: "first pass",
|
|
71
|
+
text: "writing the patch",
|
|
72
|
+
});
|
|
73
|
+
// later messages in the same turn stay separate entries
|
|
74
|
+
appendAssistantMessage(state, turnId, { thinking: "verify", text: "done" });
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`renderTranscriptLines`/`TranscriptViewport` accept `hideThinkingBlock` (with
|
|
78
|
+
`thinkingLabel` as the collapsed label) so a host can present replayed thinking
|
|
79
|
+
collapsed and offer its own expansion gesture; omitted keeps Pi's default
|
|
80
|
+
(expanded).
|
|
81
|
+
|
|
54
82
|
The transcript normalizes user/assistant events, streaming thinking and text,
|
|
55
83
|
tool calls and results, and automatic retry notices. It bounds retained history
|
|
56
84
|
(entries and total chars — raw tool data is uncapped by design) and sanitizes
|
|
@@ -242,9 +242,34 @@ export declare function ensureToolCall(state: TranscriptState, turnId: number, t
|
|
|
242
242
|
/**
|
|
243
243
|
* Inserts or updates the thinking/assistant-text entry for `turnId`.
|
|
244
244
|
* Repeated records for the same turn merge into one entry (latest text wins).
|
|
245
|
-
* Public building block for hosts that replay completed message
|
|
245
|
+
* Public building block for hosts that replay the *same* completed message
|
|
246
|
+
* several times (live message updates persisted line by line).
|
|
247
|
+
*
|
|
248
|
+
* Hosts replaying *distinct* assistant messages inside one turn must use
|
|
249
|
+
* `appendText` / `appendAssistantMessage` instead: a turn that contains
|
|
250
|
+
* several persisted assistant messages would otherwise keep only the last one.
|
|
246
251
|
*/
|
|
247
252
|
export declare function upsertText(state: TranscriptState, turnId: number, type: "thinking" | "assistant-text", text: string, streaming: boolean): void;
|
|
253
|
+
/**
|
|
254
|
+
* Appends a thinking/assistant-text entry for `turnId` without merging into
|
|
255
|
+
* any previous entry of the same type. Public building block for hosts that
|
|
256
|
+
* replay finished transcripts, where every persisted assistant message is a
|
|
257
|
+
* distinct entry even when several of them share one turn.
|
|
258
|
+
*/
|
|
259
|
+
export declare function appendText(state: TranscriptState, turnId: number, type: "thinking" | "assistant-text", text: string, streaming?: boolean): TranscriptEntry | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Appends one completed assistant message as its own thinking and/or
|
|
262
|
+
* assistant-text entries, in the order Pi renders them inside a message.
|
|
263
|
+
* Unlike `upsertText` it never overwrites an earlier message of the same
|
|
264
|
+
* turn, so history replay keeps every assistant message and thinking block.
|
|
265
|
+
*/
|
|
266
|
+
export declare function appendAssistantMessage(state: TranscriptState, turnId: number, message: {
|
|
267
|
+
thinking?: string;
|
|
268
|
+
text?: string;
|
|
269
|
+
}, streaming?: boolean): {
|
|
270
|
+
thinkingEntryId?: number;
|
|
271
|
+
textEntryId?: number;
|
|
272
|
+
};
|
|
248
273
|
/**
|
|
249
274
|
* Inserts or updates the structured result of a tool call, creating the call
|
|
250
275
|
* placeholder first when the result arrives before its start event. Safe to
|
|
@@ -287,7 +312,14 @@ export interface TranscriptRenderOptions {
|
|
|
287
312
|
theme: Theme;
|
|
288
313
|
emptyText?: string;
|
|
289
314
|
assistantLabel?: string;
|
|
315
|
+
/** Collapsed-label text used when `hideThinkingBlock` is enabled. */
|
|
290
316
|
thinkingLabel?: string;
|
|
317
|
+
/**
|
|
318
|
+
* Render assistant thinking blocks collapsed to `thinkingLabel`. Defaults to
|
|
319
|
+
* `false` (expanded), so existing hosts keep Pi's default transcript
|
|
320
|
+
* behavior; hosts that own their own expansion gesture opt in.
|
|
321
|
+
*/
|
|
322
|
+
hideThinkingBlock?: boolean;
|
|
291
323
|
assistantBadgeBackground?: ThemeBackground;
|
|
292
324
|
assistantBadgeForeground?: ThemeColor;
|
|
293
325
|
/**
|
|
@@ -174,7 +174,8 @@ function isUnsafeTerminalCodePoint(codePoint) {
|
|
|
174
174
|
(codePoint & 0xffff) === 0xfffe ||
|
|
175
175
|
(codePoint & 0xffff) === 0xffff);
|
|
176
176
|
}
|
|
177
|
-
function consumeControlString(value,
|
|
177
|
+
function consumeControlString(value, start, osc) {
|
|
178
|
+
let index = start;
|
|
178
179
|
while (index < value.length) {
|
|
179
180
|
const codePoint = value.codePointAt(index);
|
|
180
181
|
if (codePoint === undefined)
|
|
@@ -190,7 +191,8 @@ function consumeControlString(value, index, osc) {
|
|
|
190
191
|
}
|
|
191
192
|
return value.length;
|
|
192
193
|
}
|
|
193
|
-
function consumeCsi(value,
|
|
194
|
+
function consumeCsi(value, start) {
|
|
195
|
+
let index = start;
|
|
194
196
|
while (index < value.length) {
|
|
195
197
|
const codePoint = value.codePointAt(index);
|
|
196
198
|
if (codePoint === undefined)
|
|
@@ -543,7 +545,12 @@ function finishActiveAssistantSegment(state) {
|
|
|
543
545
|
/**
|
|
544
546
|
* Inserts or updates the thinking/assistant-text entry for `turnId`.
|
|
545
547
|
* Repeated records for the same turn merge into one entry (latest text wins).
|
|
546
|
-
* Public building block for hosts that replay completed message
|
|
548
|
+
* Public building block for hosts that replay the *same* completed message
|
|
549
|
+
* several times (live message updates persisted line by line).
|
|
550
|
+
*
|
|
551
|
+
* Hosts replaying *distinct* assistant messages inside one turn must use
|
|
552
|
+
* `appendText` / `appendAssistantMessage` instead: a turn that contains
|
|
553
|
+
* several persisted assistant messages would otherwise keep only the last one.
|
|
547
554
|
*/
|
|
548
555
|
export function upsertText(state, turnId, type, text, streaming) {
|
|
549
556
|
if (!text)
|
|
@@ -556,6 +563,33 @@ export function upsertText(state, turnId, type, text, streaming) {
|
|
|
556
563
|
}
|
|
557
564
|
appendEntry(state, { type, turnId, text, streaming });
|
|
558
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Appends a thinking/assistant-text entry for `turnId` without merging into
|
|
568
|
+
* any previous entry of the same type. Public building block for hosts that
|
|
569
|
+
* replay finished transcripts, where every persisted assistant message is a
|
|
570
|
+
* distinct entry even when several of them share one turn.
|
|
571
|
+
*/
|
|
572
|
+
export function appendText(state, turnId, type, text, streaming = false) {
|
|
573
|
+
if (!text)
|
|
574
|
+
return undefined;
|
|
575
|
+
return appendEntry(state, { type, turnId, text, streaming });
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Appends one completed assistant message as its own thinking and/or
|
|
579
|
+
* assistant-text entries, in the order Pi renders them inside a message.
|
|
580
|
+
* Unlike `upsertText` it never overwrites an earlier message of the same
|
|
581
|
+
* turn, so history replay keeps every assistant message and thinking block.
|
|
582
|
+
*/
|
|
583
|
+
export function appendAssistantMessage(state, turnId, message, streaming = false) {
|
|
584
|
+
const result = {};
|
|
585
|
+
const thinking = appendText(state, turnId, "thinking", message.thinking ?? "", streaming);
|
|
586
|
+
if (thinking)
|
|
587
|
+
result.thinkingEntryId = thinking.id;
|
|
588
|
+
const text = appendText(state, turnId, "assistant-text", message.text ?? "", streaming);
|
|
589
|
+
if (text)
|
|
590
|
+
result.textEntryId = text.id;
|
|
591
|
+
return result;
|
|
592
|
+
}
|
|
559
593
|
/**
|
|
560
594
|
* Inserts or updates the structured result of a tool call, creating the call
|
|
561
595
|
* placeholder first when the result arrives before its start event. Safe to
|
|
@@ -928,7 +962,9 @@ function buildRenderBlocks(entries) {
|
|
|
928
962
|
flushAssistant();
|
|
929
963
|
return blocks;
|
|
930
964
|
}
|
|
931
|
-
const
|
|
965
|
+
const ESC_SEQUENCE = String.fromCharCode(27);
|
|
966
|
+
const BEL_SEQUENCE = String.fromCharCode(7);
|
|
967
|
+
const OSC_133_SEQUENCE = new RegExp(`${ESC_SEQUENCE}]133;[ABC]${BEL_SEQUENCE}`, "g");
|
|
932
968
|
function stripOsc133(lines) {
|
|
933
969
|
return lines.map((line) => line.replace(OSC_133_SEQUENCE, ""));
|
|
934
970
|
}
|
|
@@ -946,8 +982,8 @@ function createPresentationAssistantMessage(thinking, text) {
|
|
|
946
982
|
function renderNativeUserMessage(text, width) {
|
|
947
983
|
return stripOsc133(new UserMessageComponent(safeTerminalText(text), getMarkdownTheme(), 1).render(width));
|
|
948
984
|
}
|
|
949
|
-
function renderNativeAssistantMessage(thinking, text, width, thinkingLabel) {
|
|
950
|
-
return stripOsc133(new AssistantMessageComponent(createPresentationAssistantMessage(thinking, text),
|
|
985
|
+
function renderNativeAssistantMessage(thinking, text, width, thinkingLabel, hideThinkingBlock) {
|
|
986
|
+
return stripOsc133(new AssistantMessageComponent(createPresentationAssistantMessage(thinking, text), hideThinkingBlock, getMarkdownTheme(), thinkingLabel, 1).render(width));
|
|
951
987
|
}
|
|
952
988
|
function wrapRenderedLines(lines, width, verbatimLines) {
|
|
953
989
|
const wrapped = [];
|
|
@@ -958,10 +994,10 @@ function wrapRenderedLines(lines, width, verbatimLines) {
|
|
|
958
994
|
wrapped.push(line);
|
|
959
995
|
continue;
|
|
960
996
|
}
|
|
961
|
-
if (
|
|
962
|
-
wrapped.push("");
|
|
963
|
-
else
|
|
997
|
+
if (line)
|
|
964
998
|
wrapped.push(...wrapTextWithAnsi(line, Math.max(1, width)));
|
|
999
|
+
else
|
|
1000
|
+
wrapped.push("");
|
|
965
1001
|
}
|
|
966
1002
|
return wrapped;
|
|
967
1003
|
}
|
|
@@ -1029,7 +1065,7 @@ export function renderTranscriptLines(entries, options) {
|
|
|
1029
1065
|
case "assistant":
|
|
1030
1066
|
blankBefore();
|
|
1031
1067
|
lines.push(assistantBadge);
|
|
1032
|
-
lines.push(...renderNativeAssistantMessage(block.thinking, block.text, width, options.thinkingLabel ?? "Thinking"));
|
|
1068
|
+
lines.push(...renderNativeAssistantMessage(block.thinking, block.text, width, options.thinkingLabel ?? "Thinking", options.hideThinkingBlock === true));
|
|
1033
1069
|
break;
|
|
1034
1070
|
case "tool-native": {
|
|
1035
1071
|
blankBefore();
|
|
@@ -1062,7 +1098,7 @@ export function renderTranscriptLines(entries, options) {
|
|
|
1062
1098
|
* TUI mode does not already provide it.
|
|
1063
1099
|
*/
|
|
1064
1100
|
export function getTranscriptMouseScrollDelta(data) {
|
|
1065
|
-
const match = data.match(
|
|
1101
|
+
const match = data.match(new RegExp(`^${ESC_SEQUENCE}\\[<(\\d+);\\d+;\\d+[Mm]$`));
|
|
1066
1102
|
if (!match)
|
|
1067
1103
|
return null;
|
|
1068
1104
|
const button = Number(match[1]);
|
|
@@ -398,9 +398,10 @@ function isUnsafeTerminalCodePoint(codePoint: number): boolean {
|
|
|
398
398
|
|
|
399
399
|
function consumeControlString(
|
|
400
400
|
value: string,
|
|
401
|
-
|
|
401
|
+
start: number,
|
|
402
402
|
osc: boolean,
|
|
403
403
|
): number {
|
|
404
|
+
let index = start;
|
|
404
405
|
while (index < value.length) {
|
|
405
406
|
const codePoint = value.codePointAt(index);
|
|
406
407
|
if (codePoint === undefined) break;
|
|
@@ -414,7 +415,8 @@ function consumeControlString(
|
|
|
414
415
|
return value.length;
|
|
415
416
|
}
|
|
416
417
|
|
|
417
|
-
function consumeCsi(value: string,
|
|
418
|
+
function consumeCsi(value: string, start: number): number {
|
|
419
|
+
let index = start;
|
|
418
420
|
while (index < value.length) {
|
|
419
421
|
const codePoint = value.codePointAt(index);
|
|
420
422
|
if (codePoint === undefined) break;
|
|
@@ -843,7 +845,12 @@ function finishActiveAssistantSegment(state: TranscriptState): void {
|
|
|
843
845
|
/**
|
|
844
846
|
* Inserts or updates the thinking/assistant-text entry for `turnId`.
|
|
845
847
|
* Repeated records for the same turn merge into one entry (latest text wins).
|
|
846
|
-
* Public building block for hosts that replay completed message
|
|
848
|
+
* Public building block for hosts that replay the *same* completed message
|
|
849
|
+
* several times (live message updates persisted line by line).
|
|
850
|
+
*
|
|
851
|
+
* Hosts replaying *distinct* assistant messages inside one turn must use
|
|
852
|
+
* `appendText` / `appendAssistantMessage` instead: a turn that contains
|
|
853
|
+
* several persisted assistant messages would otherwise keep only the last one.
|
|
847
854
|
*/
|
|
848
855
|
export function upsertText(
|
|
849
856
|
state: TranscriptState,
|
|
@@ -862,6 +869,55 @@ export function upsertText(
|
|
|
862
869
|
appendEntry(state, { type, turnId, text, streaming });
|
|
863
870
|
}
|
|
864
871
|
|
|
872
|
+
/**
|
|
873
|
+
* Appends a thinking/assistant-text entry for `turnId` without merging into
|
|
874
|
+
* any previous entry of the same type. Public building block for hosts that
|
|
875
|
+
* replay finished transcripts, where every persisted assistant message is a
|
|
876
|
+
* distinct entry even when several of them share one turn.
|
|
877
|
+
*/
|
|
878
|
+
export function appendText(
|
|
879
|
+
state: TranscriptState,
|
|
880
|
+
turnId: number,
|
|
881
|
+
type: "thinking" | "assistant-text",
|
|
882
|
+
text: string,
|
|
883
|
+
streaming = false,
|
|
884
|
+
): TranscriptEntry | undefined {
|
|
885
|
+
if (!text) return undefined;
|
|
886
|
+
return appendEntry(state, { type, turnId, text, streaming });
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Appends one completed assistant message as its own thinking and/or
|
|
891
|
+
* assistant-text entries, in the order Pi renders them inside a message.
|
|
892
|
+
* Unlike `upsertText` it never overwrites an earlier message of the same
|
|
893
|
+
* turn, so history replay keeps every assistant message and thinking block.
|
|
894
|
+
*/
|
|
895
|
+
export function appendAssistantMessage(
|
|
896
|
+
state: TranscriptState,
|
|
897
|
+
turnId: number,
|
|
898
|
+
message: { thinking?: string; text?: string },
|
|
899
|
+
streaming = false,
|
|
900
|
+
): { thinkingEntryId?: number; textEntryId?: number } {
|
|
901
|
+
const result: { thinkingEntryId?: number; textEntryId?: number } = {};
|
|
902
|
+
const thinking = appendText(
|
|
903
|
+
state,
|
|
904
|
+
turnId,
|
|
905
|
+
"thinking",
|
|
906
|
+
message.thinking ?? "",
|
|
907
|
+
streaming,
|
|
908
|
+
);
|
|
909
|
+
if (thinking) result.thinkingEntryId = thinking.id;
|
|
910
|
+
const text = appendText(
|
|
911
|
+
state,
|
|
912
|
+
turnId,
|
|
913
|
+
"assistant-text",
|
|
914
|
+
message.text ?? "",
|
|
915
|
+
streaming,
|
|
916
|
+
);
|
|
917
|
+
if (text) result.textEntryId = text.id;
|
|
918
|
+
return result;
|
|
919
|
+
}
|
|
920
|
+
|
|
865
921
|
/**
|
|
866
922
|
* Inserts or updates the structured result of a tool call, creating the call
|
|
867
923
|
* placeholder first when the result arrives before its start event. Safe to
|
|
@@ -1430,7 +1486,13 @@ function buildRenderBlocks(
|
|
|
1430
1486
|
return blocks;
|
|
1431
1487
|
}
|
|
1432
1488
|
|
|
1433
|
-
const
|
|
1489
|
+
const ESC_SEQUENCE = String.fromCharCode(27);
|
|
1490
|
+
const BEL_SEQUENCE = String.fromCharCode(7);
|
|
1491
|
+
|
|
1492
|
+
const OSC_133_SEQUENCE = new RegExp(
|
|
1493
|
+
`${ESC_SEQUENCE}]133;[ABC]${BEL_SEQUENCE}`,
|
|
1494
|
+
"g",
|
|
1495
|
+
);
|
|
1434
1496
|
|
|
1435
1497
|
type PresentationAssistantMessage = NonNullable<
|
|
1436
1498
|
ConstructorParameters<typeof AssistantMessageComponent>[0]
|
|
@@ -1471,11 +1533,12 @@ function renderNativeAssistantMessage(
|
|
|
1471
1533
|
text: string,
|
|
1472
1534
|
width: number,
|
|
1473
1535
|
thinkingLabel: string,
|
|
1536
|
+
hideThinkingBlock: boolean,
|
|
1474
1537
|
): string[] {
|
|
1475
1538
|
return stripOsc133(
|
|
1476
1539
|
new AssistantMessageComponent(
|
|
1477
1540
|
createPresentationAssistantMessage(thinking, text),
|
|
1478
|
-
|
|
1541
|
+
hideThinkingBlock,
|
|
1479
1542
|
getMarkdownTheme(),
|
|
1480
1543
|
thinkingLabel,
|
|
1481
1544
|
1,
|
|
@@ -1496,8 +1559,8 @@ function wrapRenderedLines(
|
|
|
1496
1559
|
wrapped.push(line);
|
|
1497
1560
|
continue;
|
|
1498
1561
|
}
|
|
1499
|
-
if (
|
|
1500
|
-
else wrapped.push(
|
|
1562
|
+
if (line) wrapped.push(...wrapTextWithAnsi(line, Math.max(1, width)));
|
|
1563
|
+
else wrapped.push("");
|
|
1501
1564
|
}
|
|
1502
1565
|
return wrapped;
|
|
1503
1566
|
}
|
|
@@ -1518,7 +1581,14 @@ export interface TranscriptRenderOptions {
|
|
|
1518
1581
|
theme: Theme;
|
|
1519
1582
|
emptyText?: string;
|
|
1520
1583
|
assistantLabel?: string;
|
|
1584
|
+
/** Collapsed-label text used when `hideThinkingBlock` is enabled. */
|
|
1521
1585
|
thinkingLabel?: string;
|
|
1586
|
+
/**
|
|
1587
|
+
* Render assistant thinking blocks collapsed to `thinkingLabel`. Defaults to
|
|
1588
|
+
* `false` (expanded), so existing hosts keep Pi's default transcript
|
|
1589
|
+
* behavior; hosts that own their own expansion gesture opt in.
|
|
1590
|
+
*/
|
|
1591
|
+
hideThinkingBlock?: boolean;
|
|
1522
1592
|
assistantBadgeBackground?: ThemeBackground;
|
|
1523
1593
|
assistantBadgeForeground?: ThemeColor;
|
|
1524
1594
|
/**
|
|
@@ -1616,6 +1686,7 @@ export function renderTranscriptLines(
|
|
|
1616
1686
|
block.text,
|
|
1617
1687
|
width,
|
|
1618
1688
|
options.thinkingLabel ?? "Thinking",
|
|
1689
|
+
options.hideThinkingBlock === true,
|
|
1619
1690
|
),
|
|
1620
1691
|
);
|
|
1621
1692
|
break;
|
|
@@ -1669,7 +1740,9 @@ export interface TranscriptViewportRender {
|
|
|
1669
1740
|
* TUI mode does not already provide it.
|
|
1670
1741
|
*/
|
|
1671
1742
|
export function getTranscriptMouseScrollDelta(data: string): number | null {
|
|
1672
|
-
const match = data.match(
|
|
1743
|
+
const match = data.match(
|
|
1744
|
+
new RegExp(`^${ESC_SEQUENCE}\\[<(\\d+);\\d+;\\d+[Mm]$`),
|
|
1745
|
+
);
|
|
1673
1746
|
if (!match) return null;
|
|
1674
1747
|
|
|
1675
1748
|
const button = Number(match[1]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xzzpig/pi-subagents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Pi extension for single-agent delegation and scripted multi-agent workflows",
|
|
5
5
|
"author": "Nico Bailon",
|
|
6
6
|
"license": "MIT",
|
|
@@ -84,16 +84,16 @@
|
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@xzzpig/pi-components": "0.
|
|
87
|
+
"@xzzpig/pi-components": "0.4.0",
|
|
88
88
|
"acorn": "8.18.0",
|
|
89
89
|
"jiti": "2.7.0",
|
|
90
90
|
"typebox": "1.1.38",
|
|
91
91
|
"yaml": "2.8.3"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@earendil-works/pi-agent-core": "0.
|
|
95
|
-
"@earendil-works/pi-ai": "0.
|
|
96
|
-
"@earendil-works/pi-tui": "0.
|
|
94
|
+
"@earendil-works/pi-agent-core": "^0.85.1",
|
|
95
|
+
"@earendil-works/pi-ai": "^0.85.1",
|
|
96
|
+
"@earendil-works/pi-tui": "^0.85.1",
|
|
97
97
|
"@oxlint/plugins": "1.80.0",
|
|
98
98
|
"@types/node": "24.13.3",
|
|
99
99
|
"oxlint": "1.80.0",
|
package/src/shared/types.ts
CHANGED
|
@@ -28,6 +28,13 @@ const REQUIRED_NATIVE_EXPORTS = [
|
|
|
28
28
|
|
|
29
29
|
let nativeSupportPromise: Promise<NativeTranscriptModule | null> | undefined;
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Record window for the native transcript view. Larger than the legacy rail's
|
|
33
|
+
* 240-record tail so a replayed run still carries its user/turn boundaries and
|
|
34
|
+
* assistant messages; the shared reader keeps the 2 MiB byte cap on top.
|
|
35
|
+
*/
|
|
36
|
+
const NATIVE_MAX_RECORDS = 600;
|
|
37
|
+
|
|
31
38
|
/**
|
|
32
39
|
* Structural probe for a candidate transcript module: every export the native
|
|
33
40
|
* renderer calls must be present. Exported pure so hosts and tests can check
|
|
@@ -63,6 +70,10 @@ export interface NativeFleetBuildInput {
|
|
|
63
70
|
trustedFileRoot?: string;
|
|
64
71
|
width: number;
|
|
65
72
|
expandedTools: boolean;
|
|
73
|
+
/** Render replayed thinking blocks collapsed to `thinkingLabel`. */
|
|
74
|
+
hideThinkingBlock?: boolean;
|
|
75
|
+
/** Collapsed-label text shown while `hideThinkingBlock` is set. */
|
|
76
|
+
thinkingLabel?: string;
|
|
66
77
|
cwd?: string;
|
|
67
78
|
maxRecords?: number;
|
|
68
79
|
theme: {
|
|
@@ -121,6 +132,34 @@ function stringValue(record: Record<string, unknown>, key: string): string | und
|
|
|
121
132
|
return typeof value === "string" && value.trim() ? value : undefined;
|
|
122
133
|
}
|
|
123
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Writes one completed assistant message as its own entries. Prefers the
|
|
137
|
+
* append helper of newer shared-library builds and falls back to the
|
|
138
|
+
* always-required `appendEntry`, because `upsertText` would collapse a whole
|
|
139
|
+
* replayed turn into its last assistant message. */
|
|
140
|
+
function appendAssistantMessage(
|
|
141
|
+
mod: NativeTranscriptModule,
|
|
142
|
+
state: TranscriptState,
|
|
143
|
+
turnId: number,
|
|
144
|
+
thinking: string,
|
|
145
|
+
text: string,
|
|
146
|
+
): void {
|
|
147
|
+
const append = (mod as {
|
|
148
|
+
appendAssistantMessage?: (
|
|
149
|
+
state: TranscriptState,
|
|
150
|
+
turnId: number,
|
|
151
|
+
message: { thinking?: string; text?: string },
|
|
152
|
+
streaming?: boolean,
|
|
153
|
+
) => unknown;
|
|
154
|
+
}).appendAssistantMessage;
|
|
155
|
+
if (typeof append === "function") {
|
|
156
|
+
append(state, turnId, { thinking, text }, false);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (thinking) mod.appendEntry(state, { type: "thinking", turnId, text: thinking, streaming: false });
|
|
160
|
+
if (text) mod.appendEntry(state, { type: "assistant-text", turnId, text, streaming: false });
|
|
161
|
+
}
|
|
162
|
+
|
|
124
163
|
function nestedField(record: Record<string, unknown>, key: string): Record<string, unknown> | undefined {
|
|
125
164
|
const value = record[key];
|
|
126
165
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
@@ -199,15 +238,18 @@ function ingestRecords(
|
|
|
199
238
|
}
|
|
200
239
|
|
|
201
240
|
if (role === "assistant") {
|
|
241
|
+
// A recorded turn holds many finished assistant messages (one per tool
|
|
242
|
+
// cycle). Each is appended as its own entry: merging them would leave
|
|
243
|
+
// only the last thinking block and last answer of the whole turn.
|
|
244
|
+
if (state.currentTurnId !== null && currentTurnHasFinishedAssistant) {
|
|
245
|
+
mod.finishTurn(state);
|
|
246
|
+
}
|
|
202
247
|
const turnId = mod.ensureTurn(state);
|
|
203
248
|
const parts = contentParts(message?.content);
|
|
204
249
|
const thinking = partsToThinking(parts);
|
|
205
250
|
const text = partsToText(parts);
|
|
206
|
-
|
|
207
|
-
if (text)
|
|
208
|
-
mod.upsertText(state, turnId, "assistant-text", text, false);
|
|
209
|
-
currentTurnHasFinishedAssistant = true;
|
|
210
|
-
}
|
|
251
|
+
appendAssistantMessage(mod, state, turnId, thinking, text);
|
|
252
|
+
if (text) currentTurnHasFinishedAssistant = true;
|
|
211
253
|
continue;
|
|
212
254
|
}
|
|
213
255
|
|
|
@@ -318,7 +360,7 @@ export function buildNativeFleetTranscript(
|
|
|
318
360
|
trustedRoots: input.trustedRoots,
|
|
319
361
|
...(input.trustedFiles ? { trustedFiles: input.trustedFiles } : {}),
|
|
320
362
|
...(input.trustedFileRoot ? { trustedFileRoot: input.trustedFileRoot } : {}),
|
|
321
|
-
|
|
363
|
+
maxRecords: input.maxRecords ?? NATIVE_MAX_RECORDS,
|
|
322
364
|
};
|
|
323
365
|
const read = readTranscriptRecords(input.filePath, readOptions);
|
|
324
366
|
if (read.records.length === 0) {
|
|
@@ -356,6 +398,8 @@ export function buildNativeFleetTranscript(
|
|
|
356
398
|
width: input.width,
|
|
357
399
|
theme: input.theme,
|
|
358
400
|
toolComponents: registry,
|
|
401
|
+
...(input.hideThinkingBlock ? { hideThinkingBlock: true } : {}),
|
|
402
|
+
...(input.thinkingLabel ? { thinkingLabel: input.thinkingLabel } : {}),
|
|
359
403
|
});
|
|
360
404
|
|
|
361
405
|
const indicatorLines: string[] = [];
|
package/src/tui/fleet.ts
CHANGED
|
@@ -53,6 +53,7 @@ export const DEFAULT_FLEET_KEYBINDINGS: Record<FleetKeybindingAction, string[]>
|
|
|
53
53
|
inspect: ["return", "H"],
|
|
54
54
|
stop: ["D"],
|
|
55
55
|
toggleTools: ["x", "X", "ctrl+o"],
|
|
56
|
+
toggleThinking: ["t", "T"],
|
|
56
57
|
toggleRenderer: ["v", "V"],
|
|
57
58
|
};
|
|
58
59
|
|
|
@@ -780,6 +781,7 @@ interface FleetTranscriptCache {
|
|
|
780
781
|
fingerprint: string;
|
|
781
782
|
width: number;
|
|
782
783
|
expandedTools: boolean;
|
|
784
|
+
expandedThinking: boolean;
|
|
783
785
|
conversationState: string;
|
|
784
786
|
hasContent: boolean;
|
|
785
787
|
warning?: string;
|
|
@@ -806,6 +808,8 @@ export class SubagentFleetComponent implements Component {
|
|
|
806
808
|
private bodyHeight = 8;
|
|
807
809
|
private lastRosterWidth: number | undefined;
|
|
808
810
|
private expandedTools = false;
|
|
811
|
+
/** Structured-view thinking visibility; collapsed by default (see spec). */
|
|
812
|
+
private expandedThinking = false;
|
|
809
813
|
/** Structured-view renderer selection; legacy is the always-available fallback. */
|
|
810
814
|
private rendererMode: "native" | "legacy" = "native";
|
|
811
815
|
/** undefined = still loading, null = unavailable (permanent for this inspector session). */
|
|
@@ -865,6 +869,8 @@ export class SubagentFleetComponent implements Component {
|
|
|
865
869
|
...(target.trustedFileRoot ? { trustedFileRoot: target.trustedFileRoot } : {}),
|
|
866
870
|
width,
|
|
867
871
|
expandedTools: this.expandedTools,
|
|
872
|
+
hideThinkingBlock: !this.expandedThinking,
|
|
873
|
+
thinkingLabel: this.thinkingToggleLabel(),
|
|
868
874
|
cwd: this.state.baseCwd,
|
|
869
875
|
theme: this.theme,
|
|
870
876
|
});
|
|
@@ -1288,6 +1294,14 @@ export class SubagentFleetComponent implements Component {
|
|
|
1288
1294
|
this.tui.requestRender();
|
|
1289
1295
|
return;
|
|
1290
1296
|
}
|
|
1297
|
+
if (matchesFleetAction(data, this.keybindings, "toggleThinking")) {
|
|
1298
|
+
// Structured view only: the legacy rail renderer carries no thinking
|
|
1299
|
+
// entries, so the toggle stays inert there instead of erroring.
|
|
1300
|
+
this.expandedThinking = !this.expandedThinking;
|
|
1301
|
+
this.transcriptCache = undefined;
|
|
1302
|
+
this.tui.requestRender();
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1291
1305
|
if (matchesFleetAction(data, this.keybindings, "inspect")) {
|
|
1292
1306
|
this.inspectSelectedHerdr();
|
|
1293
1307
|
return;
|
|
@@ -1330,7 +1344,8 @@ export class SubagentFleetComponent implements Component {
|
|
|
1330
1344
|
&& this.transcriptCache.path === target.path
|
|
1331
1345
|
&& this.transcriptCache.fingerprint === fingerprint
|
|
1332
1346
|
&& this.transcriptCache.width === width
|
|
1333
|
-
&& this.transcriptCache.expandedTools === this.expandedTools
|
|
1347
|
+
&& this.transcriptCache.expandedTools === this.expandedTools
|
|
1348
|
+
&& this.transcriptCache.expandedThinking === this.expandedThinking) {
|
|
1334
1349
|
return {
|
|
1335
1350
|
body: [...this.transcriptCache.body],
|
|
1336
1351
|
conversationState: this.transcriptCache.conversationState,
|
|
@@ -1344,10 +1359,15 @@ export class SubagentFleetComponent implements Component {
|
|
|
1344
1359
|
const outcome = this.rendererMode === "native" && this.nativeModule
|
|
1345
1360
|
? this.nativeRenderedOutcome(this.nativeModule, target, width)
|
|
1346
1361
|
: this.legacyRenderedOutcome(target, width);
|
|
1347
|
-
this.transcriptCache = { mode: this.rendererMode, path: target.path, fingerprint, width, expandedTools: this.expandedTools, ...outcome, body: [...outcome.body] };
|
|
1362
|
+
this.transcriptCache = { mode: this.rendererMode, path: target.path, fingerprint, width, expandedTools: this.expandedTools, expandedThinking: this.expandedThinking, ...outcome, body: [...outcome.body] };
|
|
1348
1363
|
return outcome;
|
|
1349
1364
|
}
|
|
1350
1365
|
|
|
1366
|
+
/** Label of a collapsed thinking block, carrying its own expansion hint. */
|
|
1367
|
+
private thinkingToggleLabel(): string {
|
|
1368
|
+
return `Thinking (${bindingLabel(this.keybindings, "toggleThinking")} to expand)`;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1351
1371
|
private promptAuditDetail(width: number): FleetDetailSections {
|
|
1352
1372
|
const selected = this.snapshot.items[this.selected];
|
|
1353
1373
|
const prompt = this.selectedPromptAudit();
|
|
@@ -1457,7 +1477,7 @@ export class SubagentFleetComponent implements Component {
|
|
|
1457
1477
|
? ` j/k child · 1/2/3 view · g redo with guidance · c copy · wheel ↑↓ · Esc close Prompt Audit · ${position}`
|
|
1458
1478
|
: selected?.kind === "external"
|
|
1459
1479
|
? ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} job · display-only · ${bindingLabel(this.keybindings, "refresh")} refresh · wheel ↑↓ · ${bindingLabel(this.keybindings, "close")} close · ${position}`
|
|
1460
|
-
: ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} agent · p Prompt Audit · ${bindingLabel(this.keybindings, "inspect")} Herdr · ${bindingLabel(this.keybindings, "steer")} steer · ${bindingLabel(this.keybindings, "stop")} stop · ${bindingLabel(this.keybindings, "toggleTools")} tools · ${bindingLabel(this.keybindings, "toggleRenderer")} view · ${bindingLabel(this.keybindings, "refresh")} refresh · wheel ↑↓ · ${bindingLabel(this.keybindings, "close")} close · ${position}`;
|
|
1480
|
+
: ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} agent · p Prompt Audit · ${bindingLabel(this.keybindings, "inspect")} Herdr · ${bindingLabel(this.keybindings, "steer")} steer · ${bindingLabel(this.keybindings, "stop")} stop · ${bindingLabel(this.keybindings, "toggleTools")} tools · ${bindingLabel(this.keybindings, "toggleThinking")} thinking · ${bindingLabel(this.keybindings, "toggleRenderer")} view · ${bindingLabel(this.keybindings, "refresh")} refresh · wheel ↑↓ · ${bindingLabel(this.keybindings, "close")} close · ${position}`;
|
|
1461
1481
|
lines.push(this.theme.fg("border", "│") + fit(this.theme.fg("dim", footer), innerWidth) + this.theme.fg("border", "│"));
|
|
1462
1482
|
lines.push(this.theme.fg("border", `╰${"─".repeat(innerWidth)}╯`));
|
|
1463
1483
|
return lines.map((line) => truncateToWidth(line, width));
|