@xzzpig/pi-subagents 0.12.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 +21 -0
- package/docs/configuration.md +1 -1
- package/docs/extension-api.md +35 -0
- 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/agents/runtime-discovery.ts +39 -0
- package/src/api/agents.ts +7 -0
- package/src/extension/index.ts +5 -20
- package/src/runs/background/async-execution.ts +6 -7
- package/src/runs/shared/child-launch.ts +23 -4
- package/src/runs/shared/extension-bindings.ts +25 -0
- package/src/shared/permission-profile.ts +12 -0
- 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,25 @@
|
|
|
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
|
+
|
|
13
|
+
## [0.13.0] - 2026-09-11
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **Sandbox profile env is pinned per child launch.** Every child launch now writes `PI_SUBAGENT_PERMISSION_PROFILE` explicitly (cleared when the child declares no profile) and drops launcher-owned `PI_SUBAGENT_*PROFILE*` keys from the runner's inherited environment, so a spawned child can neither inherit a host-session role selection nor override its own. The launch also sets `PI_SUBAGENT_PERMISSION_PROFILE_PINNED=1` to tell the permission system that this process owns a launched selection.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **Public agent discovery API.** `pi-subagents/agents` now exports `discoverAgentsWithRuntime(pi, cwd, scope, preferredModelProvider?)` alongside the existing registration surface, plus the `AgentConfig`, `AgentDiscoveryDiagnostic`, `AgentDiscoveryResult`, and `AgentScope` types. It returns the same merged view the subagent executor uses — builtin, package, user, and project agent files combined with agents registered at runtime — so an independent extension can offer the launcher's agent list instead of re-implementing discovery. The extension's own runtime discovery now calls the same function.
|
|
22
|
+
|
|
3
23
|
## [0.12.0] - 2026-09-11
|
|
4
24
|
|
|
5
25
|
### Added
|
|
@@ -687,6 +707,7 @@
|
|
|
687
707
|
- Keep `worktree: true` workflow children on the single-child path while preserving managed patch handoffs.
|
|
688
708
|
|
|
689
709
|
### Removed
|
|
710
|
+
|
|
690
711
|
- Remove unused foreground chain and parallel execution and durable chain management surfaces.
|
|
691
712
|
- Remove legacy subagent tool compatibility fields for append-step control, schedule aliases, async recovery metadata, and string mission goals.
|
|
692
713
|
- Remove chain approval checkpoint steps and the `approve-checkpoint` / `reject-checkpoint` controls.
|
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/extension-api.md
CHANGED
|
@@ -101,6 +101,41 @@ The installed owner applies the existing runtime-agent validation, collision che
|
|
|
101
101
|
|
|
102
102
|
This contract is process-local. It does not register agents in child sessions or other Pi processes, and it does not change package discovery or package resolution.
|
|
103
103
|
|
|
104
|
+
## Agent discovery from independent extensions
|
|
105
|
+
|
|
106
|
+
An extension that wants to offer the same agent list the subagent launcher uses
|
|
107
|
+
— a session role picker, for example — can call the exported discovery helper
|
|
108
|
+
instead of re-implementing agent loading:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { discoverAgentsWithRuntime } from "pi-subagents/agents";
|
|
112
|
+
|
|
113
|
+
const result = discoverAgentsWithRuntime(pi, cwd, "both");
|
|
114
|
+
for (const agent of result.agents) {
|
|
115
|
+
// agent.name, agent.description, agent.aliases, agent.source,
|
|
116
|
+
// agent.sandbox, agent.permissionProfile, agent.override?.scope, agent.disabled
|
|
117
|
+
}
|
|
118
|
+
result.agentDiagnostics; // loader problems, per source
|
|
119
|
+
result.projectAgentsDir; // where project agents came from
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The result is the merged view: builtin, package, user, and project agent files
|
|
123
|
+
plus anything registered at runtime through the contract above. With nothing
|
|
124
|
+
registered, it is exactly `discoverAgents(cwd, scope)`.
|
|
125
|
+
|
|
126
|
+
`scope` is `"user" | "project" | "both"`. Pass the caller's `cwd` so project
|
|
127
|
+
layering resolves against the right tree, and pass the caller's `ExtensionAPI`
|
|
128
|
+
because the runtime registry is keyed on it.
|
|
129
|
+
|
|
130
|
+
Two notes for consumers of an optional dependency:
|
|
131
|
+
|
|
132
|
+
- Treat the module as optional. A package that is not installed cannot be
|
|
133
|
+
imported, so load it dynamically and report the failure rather than failing
|
|
134
|
+
extension load.
|
|
135
|
+
- `agent.source === "project"` (or `agent.override?.scope === "project"`) means
|
|
136
|
+
the definition comes from the current project. Gate such an agent behind the
|
|
137
|
+
host's project-trust decision before adopting it for anything.
|
|
138
|
+
|
|
104
139
|
## External jobs in FleetView
|
|
105
140
|
|
|
106
141
|
Use `pi-subagents/external-runs` to publish display-only current-session jobs owned by another extension:
|
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",
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
discoverAgentSnapshot,
|
|
3
|
+
discoverAgents,
|
|
4
|
+
type AgentConfig,
|
|
5
|
+
type AgentDiscoveryResult,
|
|
6
|
+
type AgentScope,
|
|
7
|
+
} from "./agents.ts";
|
|
8
|
+
import { listRuntimeAgentConfigs, mergeRuntimeAgents, type RuntimeAgentOwner } from "./runtime-agent-registry.ts";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Discover agents exactly as the runtime sees them: file-based discovery
|
|
12
|
+
* (builtin, package, user, project) merged with agents registered in-process
|
|
13
|
+
* through the runtime agent registry.
|
|
14
|
+
*
|
|
15
|
+
* Callers outside this extension — for example an extension that lets the user
|
|
16
|
+
* pick a role for the interactive session — need the same merged view the
|
|
17
|
+
* subagent executor uses. When nothing is registered at runtime this is a thin
|
|
18
|
+
* wrapper around `discoverAgents`, so the registry stays a pure addition.
|
|
19
|
+
*/
|
|
20
|
+
export function discoverAgentsWithRuntime(
|
|
21
|
+
pi: RuntimeAgentOwner,
|
|
22
|
+
cwd: string,
|
|
23
|
+
scope: AgentScope,
|
|
24
|
+
preferredModelProvider?: string,
|
|
25
|
+
): AgentDiscoveryResult {
|
|
26
|
+
if (listRuntimeAgentConfigs(pi).length === 0) return discoverAgents(cwd, scope, preferredModelProvider);
|
|
27
|
+
const snapshot = discoverAgentSnapshot(cwd, scope, preferredModelProvider, { includeChains: false });
|
|
28
|
+
const discovered = snapshot.effective;
|
|
29
|
+
const all = snapshot.all;
|
|
30
|
+
const configuredAgents: AgentConfig[] = [...all.builtin, ...all.package, ...all.user, ...all.project];
|
|
31
|
+
const merged = mergeRuntimeAgents(pi, discovered, configuredAgents);
|
|
32
|
+
if (discovered.maxThinking === undefined) return merged;
|
|
33
|
+
return {
|
|
34
|
+
...merged,
|
|
35
|
+
agents: merged.agents.map((agent) =>
|
|
36
|
+
agent.maxThinking === discovered.maxThinking ? agent : { ...agent, maxThinking: discovered.maxThinking },
|
|
37
|
+
),
|
|
38
|
+
};
|
|
39
|
+
}
|
package/src/api/agents.ts
CHANGED
|
@@ -8,5 +8,12 @@ export {
|
|
|
8
8
|
type RuntimeAgentRegistrationRequest,
|
|
9
9
|
type RuntimeAgentRegistrationResult,
|
|
10
10
|
} from "../agents/runtime-agent-events.ts";
|
|
11
|
+
export { discoverAgentsWithRuntime } from "../agents/runtime-discovery.ts";
|
|
11
12
|
|
|
12
13
|
export type { RegisterRuntimeAgentInput, RuntimeAgentDefinition, RuntimeAgentRegistration };
|
|
14
|
+
export type {
|
|
15
|
+
AgentConfig,
|
|
16
|
+
AgentDiscoveryDiagnostic,
|
|
17
|
+
AgentDiscoveryResult,
|
|
18
|
+
AgentScope,
|
|
19
|
+
} from "../agents/agents.ts";
|
package/src/extension/index.ts
CHANGED
|
@@ -19,9 +19,10 @@ import * as path from "node:path";
|
|
|
19
19
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
20
20
|
import { keyText, type ExtensionAPI, type ExtensionContext, type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
21
21
|
import { Box, Container, Spacer, Text, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component } from "@earendil-works/pi-tui";
|
|
22
|
-
import {
|
|
22
|
+
import { discoverAgentsAll, type AgentScope } from "../agents/agents.ts";
|
|
23
23
|
import { mergeAgentsForScope } from "../agents/agent-selection.ts";
|
|
24
|
-
import { clearRuntimeAgentsForPi
|
|
24
|
+
import { clearRuntimeAgentsForPi } from "../agents/runtime-agent-registry.ts";
|
|
25
|
+
import { discoverAgentsWithRuntime } from "../agents/runtime-discovery.ts";
|
|
25
26
|
import { registerRuntimeAgentEventListener } from "../agents/runtime-agent-events.ts";
|
|
26
27
|
import { ensureAccessibleDir } from "../shared/accessible-dir.ts";
|
|
27
28
|
import { cleanupAllArtifactDirs, cleanupOldArtifacts, getArtifactsDir } from "../shared/artifacts.ts";
|
|
@@ -535,24 +536,8 @@ export default function registerSubagentExtension(pi: ExtensionAPI): void {
|
|
|
535
536
|
if (scheduledRunManager.observedCompletionRunIds().size > 0) return true;
|
|
536
537
|
return missionObserverResultCandidateFiles(DIRS.results).length > 0;
|
|
537
538
|
};
|
|
538
|
-
const discoverAgentsForRuntime = (cwd: string, scope: AgentScope, preferredModelProvider?: string) =>
|
|
539
|
-
|
|
540
|
-
const snapshot = discoverAgentSnapshot(cwd, scope, preferredModelProvider, { includeChains: false });
|
|
541
|
-
const discovered = snapshot.effective;
|
|
542
|
-
const all = snapshot.all;
|
|
543
|
-
const configuredAgents: AgentConfig[] = [
|
|
544
|
-
...all.builtin,
|
|
545
|
-
...all.package,
|
|
546
|
-
...all.user,
|
|
547
|
-
...all.project,
|
|
548
|
-
];
|
|
549
|
-
const merged = mergeRuntimeAgents(pi, discovered, configuredAgents);
|
|
550
|
-
if (discovered.maxThinking === undefined) return merged;
|
|
551
|
-
return {
|
|
552
|
-
...merged,
|
|
553
|
-
agents: merged.agents.map((agent) => agent.maxThinking === discovered.maxThinking ? agent : { ...agent, maxThinking: discovered.maxThinking }),
|
|
554
|
-
};
|
|
555
|
-
};
|
|
539
|
+
const discoverAgentsForRuntime = (cwd: string, scope: AgentScope, preferredModelProvider?: string) =>
|
|
540
|
+
discoverAgentsWithRuntime(pi, cwd, scope, preferredModelProvider);
|
|
556
541
|
const { ensurePoller, refreshWidget, handleStarted, handleComplete, resetJobs, restoreActiveJobs, dispose: disposeAsyncJobTracker } = createAsyncJobTracker(pi, state, DIRS.async, {
|
|
557
542
|
widgetEnabled: asyncWidgetEnabled,
|
|
558
543
|
onJobTerminal: () => refreshResultDelivery(),
|
|
@@ -28,7 +28,7 @@ import { backgroundProcessOptions } from "../shared/background-process-options.t
|
|
|
28
28
|
import { buildSkillInjection, normalizeSkillInput, resolveSkillsWithFallback } from "../../agents/skills.ts";
|
|
29
29
|
import { buildAgentMemoryInjection } from "../../agents/agent-memory.ts";
|
|
30
30
|
import { PI_CODING_AGENT_PACKAGE_ROOT_ENV, PROMPT_REDACTED, resolveChildCwd } from "../../shared/utils.ts";
|
|
31
|
-
import { buildModelCandidates,
|
|
31
|
+
import { buildModelCandidates, resolveEffectiveSubagentModel, resolveModelOrigin, resolveSubagentModelOverride, type AvailableModelInfo, type ModelOrigin, type ParentModel } from "../shared/model-fallback.ts";
|
|
32
32
|
import { resolveToolTimeoutMs, toolTimeoutFromEnv } from "../shared/tool-timeout.ts";
|
|
33
33
|
import { resolveModelScopesForAgent, type ModelScopeConfig } from "../shared/model-scope.ts";
|
|
34
34
|
import { findModelInfo, resolveEffectiveThinking } from "../../shared/model-info.ts";
|
|
@@ -82,7 +82,7 @@ import { SUBAGENT_PROCESS_TERMINAL_EVENT } from "../../shared/types.ts";
|
|
|
82
82
|
import { assertAgentAllowedByCapabilityCeiling, intersectSubagentCapabilityCeilings, resolveCurrentSubagentCapabilityCeiling, type ResolvedSubagentCapabilityCeiling } from "../shared/capability-ceiling.ts";
|
|
83
83
|
import { agentDefinitionDigest, launchBindingDigest } from "../../shared/launch-contract.ts";
|
|
84
84
|
import { resolvePermissionRules, type PermissionConfig } from "../shared/permissions.ts";
|
|
85
|
-
import { normalizeExtensionBindings, omitExtensionBindingsEnv, type ExtensionBindings } from "../shared/extension-bindings.ts";
|
|
85
|
+
import { normalizeExtensionBindings, omitExtensionBindingsEnv, omitInheritedProfileEnv, type ExtensionBindings } from "../shared/extension-bindings.ts";
|
|
86
86
|
import { assertWorkflowLaneKey, normalizeWorkflowLaneMetadata } from "../shared/lane-metadata.ts";
|
|
87
87
|
|
|
88
88
|
const require = createRequire(import.meta.url);
|
|
@@ -602,7 +602,7 @@ function spawnRunner(cfg: Record<string, unknown>, suffix: string, cwd: string,
|
|
|
602
602
|
...backgroundProcessOptions(),
|
|
603
603
|
stdio: ["ignore", stdoutFd ?? "ignore", stderrFd ?? "ignore"],
|
|
604
604
|
env: {
|
|
605
|
-
...omitExtensionBindingsEnv(process.env),
|
|
605
|
+
...omitInheritedProfileEnv(omitExtensionBindingsEnv(process.env)),
|
|
606
606
|
[PI_CODING_AGENT_PACKAGE_ROOT_ENV]: piPackageRoot,
|
|
607
607
|
[JITI_ALIAS_ENV]: JSON.stringify(hostPeerAliases.aliases),
|
|
608
608
|
},
|
|
@@ -770,7 +770,7 @@ function profileProjectTrustedForCwd(ctx: AsyncExecutionContext, cwd: string): b
|
|
|
770
770
|
&& path.resolve(ctx.trustedProjectCwd) === path.resolve(cwd);
|
|
771
771
|
}
|
|
772
772
|
|
|
773
|
-
function profileProjectTrustError(agent: AgentConfig, ctx: AsyncExecutionContext
|
|
773
|
+
function profileProjectTrustError(agent: AgentConfig, ctx: AsyncExecutionContext): string {
|
|
774
774
|
if (ctx.projectTrusted !== true) {
|
|
775
775
|
return `Agent '${agent.name}' selects sandbox profile '${agent.sandbox}' from project scope, but the project is not trusted. Trust the project and retry.`;
|
|
776
776
|
}
|
|
@@ -788,7 +788,6 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
788
788
|
maxSubagentDepth,
|
|
789
789
|
worktreeBaseDir,
|
|
790
790
|
worktreeProvider,
|
|
791
|
-
worktreeBranchPrefix,
|
|
792
791
|
asyncDir,
|
|
793
792
|
} = params;
|
|
794
793
|
const outputBaseDir = params.outputBaseDir;
|
|
@@ -905,7 +904,7 @@ export function buildAsyncRunnerSteps(id: string, params: AsyncRunnerStepBuildPa
|
|
|
905
904
|
const { stepCwd, instructionCwd, readExistenceCwd, behavior, namespaceOutputPath, outputPath, skillNames } = launchPlan;
|
|
906
905
|
const profileChildCwd = behaviorCwd ?? stepCwd;
|
|
907
906
|
if (a.sandbox && (a.source === "project" || a.override?.scope === "project") && !profileProjectTrustedForCwd(ctx, profileChildCwd)) {
|
|
908
|
-
throw new AsyncStartValidationError(profileProjectTrustError(a, ctx
|
|
907
|
+
throw new AsyncStartValidationError(profileProjectTrustError(a, ctx));
|
|
909
908
|
}
|
|
910
909
|
const { resolved: resolvedSkills, missing: missingSkills } = resolveSkillsWithFallback(
|
|
911
910
|
skillNames,
|
|
@@ -1656,7 +1655,7 @@ export function executeAsyncSingle(
|
|
|
1656
1655
|
? resolveExpectedWorktreeAgentCwd(runnerCwd, `${id}-s0`, 0, worktreeBaseDir)
|
|
1657
1656
|
: runnerCwd;
|
|
1658
1657
|
if (sandbox && (agentConfig.source === "project" || agentConfig.override?.scope === "project") && !profileProjectTrustedForCwd(ctx, instructionCwd)) {
|
|
1659
|
-
return formatAsyncStartError("single", profileProjectTrustError(agentConfig, ctx
|
|
1658
|
+
return formatAsyncStartError("single", profileProjectTrustError(agentConfig, ctx));
|
|
1660
1659
|
}
|
|
1661
1660
|
const readExistenceCwd = params.worktree === true ? runnerCwd : instructionCwd;
|
|
1662
1661
|
const skillNames = params.skills ?? agentConfig.skills ?? [];
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
type RunFanoutBudgetDescriptor,
|
|
19
19
|
} from "../../shared/types.ts";
|
|
20
20
|
import { SUBAGENT_SANDBOX_PROFILE_ENV, SUBAGENT_SANDBOX_PROJECT_TRUST_ENV } from "../../shared/sandbox-profile.ts";
|
|
21
|
-
import { SUBAGENT_PERMISSION_PROFILE_ENV } from "../../shared/permission-profile.ts";
|
|
21
|
+
import { SUBAGENT_PERMISSION_PROFILE_ENV, SUBAGENT_PERMISSION_PROFILE_PINNED_ENV } from "../../shared/permission-profile.ts";
|
|
22
22
|
import type { NestedPathEntry } from "./nested-path.ts";
|
|
23
23
|
import type { McpRuntimeSnapshotHost } from "./mcp-direct-tool-allowlist.ts";
|
|
24
24
|
import type { PermissionRules } from "./permissions.ts";
|
|
@@ -251,7 +251,24 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
251
251
|
sandboxEnv !== undefined || permissionProfileEnv !== undefined
|
|
252
252
|
? { ...(sandboxEnv ?? {}), ...(permissionProfileEnv ?? {}) }
|
|
253
253
|
: undefined;
|
|
254
|
-
|
|
254
|
+
// The profile key is pinned for every launch, `undefined` included: a child
|
|
255
|
+
// that declares no profile must not inherit the host session's role
|
|
256
|
+
// selection, and one that declares a profile must not be overridden by it
|
|
257
|
+
// (the launcher env wins inside pi-permission-system). It is kept out of
|
|
258
|
+
// `childEnv` so a plain in-process child does not also start receiving the
|
|
259
|
+
// binding and MCP values that only a runner-hosted child used to get.
|
|
260
|
+
const profilePin: Record<string, string | undefined> = {
|
|
261
|
+
[SUBAGENT_PERMISSION_PROFILE_ENV]: input.permissionProfile,
|
|
262
|
+
// Present for every child launch: it is what tells pi-permission-system
|
|
263
|
+
// this selection is authoritative for the child (see the constant).
|
|
264
|
+
[SUBAGENT_PERMISSION_PROFILE_PINNED_ENV]: "1",
|
|
265
|
+
};
|
|
266
|
+
const transientProcessEnv = [
|
|
267
|
+
...new Set([
|
|
268
|
+
...(childEnv ? Object.keys(childEnv) : []),
|
|
269
|
+
...Object.keys(profilePin),
|
|
270
|
+
]),
|
|
271
|
+
];
|
|
255
272
|
|
|
256
273
|
const inherited = input.inherited;
|
|
257
274
|
const fanout = toolPlan.fanoutAuthorized;
|
|
@@ -355,8 +372,10 @@ export function buildInProcessChildLaunch(input: BuildInProcessChildLaunchInput)
|
|
|
355
372
|
extensionPaths,
|
|
356
373
|
ambientExtensions,
|
|
357
374
|
hooks: createChildHooks(config),
|
|
358
|
-
...(input.host === "runner" || childEnv
|
|
359
|
-
|
|
375
|
+
...(input.host === "runner" || childEnv
|
|
376
|
+
? { processEnv: { ...childProcessEnv(input, toolPlan, childEnv), ...profilePin } }
|
|
377
|
+
: { processEnv: profilePin }),
|
|
378
|
+
transientProcessEnv,
|
|
360
379
|
runtime: config,
|
|
361
380
|
noSkills: !input.inheritSkills,
|
|
362
381
|
noContextFiles: !input.inheritProjectContext,
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { SUBAGENT_PERMISSION_PROFILE_ENV, SUBAGENT_PERMISSION_PROFILE_PINNED_ENV } from "../../shared/permission-profile.ts";
|
|
2
|
+
import {
|
|
3
|
+
SUBAGENT_SANDBOX_PROFILE_ENV,
|
|
4
|
+
SUBAGENT_SANDBOX_PROJECT_TRUST_ENV,
|
|
5
|
+
} from "../../shared/sandbox-profile.ts";
|
|
6
|
+
|
|
1
7
|
export const PI_SUBAGENT_EXTENSION_BINDINGS_ENV = "PI_SUBAGENT_EXTENSION_BINDINGS";
|
|
2
8
|
export const MAX_EXTENSION_BINDING_NAMESPACES = 16;
|
|
3
9
|
export const MAX_EXTENSION_BINDINGS_BYTES = 16 * 1024;
|
|
@@ -76,3 +82,22 @@ export function omitExtensionBindingsEnv(env: NodeJS.ProcessEnv): NodeJS.Process
|
|
|
76
82
|
const { [PI_SUBAGENT_EXTENSION_BINDINGS_ENV]: _extensionBindings, ...sanitized } = env;
|
|
77
83
|
return sanitized;
|
|
78
84
|
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Drop launcher-owned profile selections from an inherited environment.
|
|
88
|
+
*
|
|
89
|
+
* A runner process must not carry the host session's role selection into the
|
|
90
|
+
* children it launches: each child's own selection is pinned by the child
|
|
91
|
+
* launch, so anything inherited here would silently apply to every step that
|
|
92
|
+
* does not declare one.
|
|
93
|
+
*/
|
|
94
|
+
export function omitInheritedProfileEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
95
|
+
const {
|
|
96
|
+
[SUBAGENT_PERMISSION_PROFILE_ENV]: _permissionProfile,
|
|
97
|
+
[SUBAGENT_PERMISSION_PROFILE_PINNED_ENV]: _permissionProfilePinned,
|
|
98
|
+
[SUBAGENT_SANDBOX_PROFILE_ENV]: _sandboxProfile,
|
|
99
|
+
[SUBAGENT_SANDBOX_PROJECT_TRUST_ENV]: _sandboxTrust,
|
|
100
|
+
...sanitized
|
|
101
|
+
} = env;
|
|
102
|
+
return sanitized;
|
|
103
|
+
}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
/** Shared wire contract for selecting a pi-permission-system profile in a child Pi process. */
|
|
2
2
|
export const SUBAGENT_PERMISSION_PROFILE_ENV = "PI_SUBAGENT_PERMISSION_PROFILE";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Marks a child process whose profile selection was pinned by its launcher.
|
|
6
|
+
*
|
|
7
|
+
* The selection key alone cannot express "this child was launched with no
|
|
8
|
+
* profile": clearing it looks exactly like a host session that never selected
|
|
9
|
+
* one. pi-permission-system therefore freezes the launcher's selection only when
|
|
10
|
+
* this marker is present, which keeps a host session reading the value live so a
|
|
11
|
+
* mid-session role change still applies.
|
|
12
|
+
*/
|
|
13
|
+
export const SUBAGENT_PERMISSION_PROFILE_PINNED_ENV =
|
|
14
|
+
"PI_SUBAGENT_PERMISSION_PROFILE_PINNED";
|
|
15
|
+
|
|
4
16
|
const MAX_PERMISSION_PROFILE_NAME_LENGTH = 128;
|
|
5
17
|
const PERMISSION_PROFILE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
6
18
|
|
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));
|