@xzzpig/pi-subagents 0.13.0 → 0.15.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.
Files changed (202) hide show
  1. package/CHANGELOG.md +243 -0
  2. package/README.md +6 -5
  3. package/agents/evidence-auditor.md +34 -0
  4. package/agents/researcher.md +23 -13
  5. package/agents/reviewer.md +3 -2
  6. package/docs/agents.md +56 -15
  7. package/docs/configuration.md +93 -15
  8. package/docs/extension-api.md +132 -19
  9. package/docs/missions.md +10 -2
  10. package/docs/models.md +11 -22
  11. package/docs/observability.md +67 -11
  12. package/docs/standalone-background.md +59 -0
  13. package/docs/tool-reference.md +42 -23
  14. package/docs/watchdog.md +39 -10
  15. package/docs/workflows.md +58 -19
  16. package/index.ts +5 -2
  17. package/inspector-runner.mjs +2 -2
  18. package/node_modules/@xzzpig/pi-components/CHANGELOG.md +19 -0
  19. package/node_modules/@xzzpig/pi-components/README.md +28 -0
  20. package/node_modules/@xzzpig/pi-components/dist/src/transcript.d.ts +46 -4
  21. package/node_modules/@xzzpig/pi-components/dist/src/transcript.js +65 -17
  22. package/node_modules/@xzzpig/pi-components/package.json +1 -1
  23. package/node_modules/@xzzpig/pi-components/src/transcript.ts +107 -14
  24. package/package.json +10 -5
  25. package/prompts/parallel-review.md +1 -1
  26. package/runner-peer-loader.mjs +24 -0
  27. package/runner-peer-preload.mjs +36 -0
  28. package/skills/pi-subagents/SKILL.md +34 -22
  29. package/skills/pi-subagents/references/constraints-and-recipes.md +3 -2
  30. package/skills/pi-subagents/references/execution-controls.md +27 -8
  31. package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
  32. package/skills/pi-subagents/references/multi-lane-orchestration.md +3 -1
  33. package/skills/pi-subagents/references/prompting-and-roles.md +17 -13
  34. package/skills/pi-subagents/references/review-and-validation.md +3 -3
  35. package/src/agents/advertised-agent-prompt.ts +94 -0
  36. package/src/agents/agent-management.ts +71 -59
  37. package/src/agents/agent-serializer.ts +6 -3
  38. package/src/agents/agents.ts +198 -72
  39. package/src/agents/builtin-names.ts +1 -0
  40. package/src/agents/chain-serializer.ts +5 -0
  41. package/src/agents/runtime-agent-registry.ts +7 -6
  42. package/src/api/delegation.ts +4 -0
  43. package/src/api/preflight.ts +110 -71
  44. package/src/api/required-child-extensions.ts +6 -0
  45. package/src/api/shared-types.ts +3 -1
  46. package/src/api/workflow-resources.ts +6 -0
  47. package/src/extension/config.ts +14 -37
  48. package/src/extension/fanout-child.ts +68 -5
  49. package/src/extension/herdr-pi-bridge.ts +164 -0
  50. package/src/extension/index.ts +141 -51
  51. package/src/extension/public-execution.ts +7 -6
  52. package/src/extension/rpc.ts +8 -21
  53. package/src/extension/schemas.ts +86 -84
  54. package/src/extension/tool-description.ts +32 -79
  55. package/src/inspectors/actions.ts +148 -0
  56. package/src/inspectors/ghostty/actions.ts +74 -0
  57. package/src/inspectors/ghostty/plugin.ts +17 -0
  58. package/src/inspectors/herdr/actions.ts +99 -179
  59. package/src/inspectors/herdr/plugin.ts +20 -0
  60. package/src/inspectors/herdr/project-panes.ts +4 -1
  61. package/src/inspectors/{herdr/inspector-runner.ts → inspector-runner.ts} +12 -12
  62. package/src/inspectors/plugins.ts +8 -0
  63. package/src/inspectors/{herdr/session-roots-codec.ts → session-roots-codec.ts} +3 -14
  64. package/src/inspectors/types.ts +51 -0
  65. package/src/integrations/pi-web-session-liveness.ts +73 -0
  66. package/src/intercom/intercom-bridge.ts +50 -8
  67. package/src/intercom/native-supervisor-channel.ts +142 -115
  68. package/src/intercom/supervisor-ui.ts +3 -2
  69. package/src/missions/workflow-state.ts +37 -16
  70. package/src/policy/authority.ts +4 -0
  71. package/src/profiles/profiles.ts +12 -6
  72. package/src/runs/background/active-async-capacity.ts +22 -18
  73. package/src/runs/background/active-run-index.ts +17 -1
  74. package/src/runs/background/async-execution.ts +359 -176
  75. package/src/runs/background/async-job-tracker.ts +41 -7
  76. package/src/runs/background/async-resume.ts +19 -12
  77. package/src/runs/background/async-retention.ts +20 -0
  78. package/src/runs/background/async-status-snapshot.ts +10 -12
  79. package/src/runs/background/async-status.ts +32 -13
  80. package/src/runs/background/auto-drain.ts +59 -35
  81. package/src/runs/background/binary-bootstrap.ts +38 -0
  82. package/src/runs/background/chain-append.ts +1 -1
  83. package/src/runs/background/chain-root-attachment.ts +22 -33
  84. package/src/runs/background/control-channel.ts +78 -44
  85. package/src/runs/background/fleet-view.ts +30 -2
  86. package/src/runs/background/notify.ts +193 -19
  87. package/src/runs/background/owned-process-tree.ts +35 -8
  88. package/src/runs/background/process-terminal.ts +23 -23
  89. package/src/runs/background/result-files.ts +8 -4
  90. package/src/runs/background/result-watcher.ts +19 -2
  91. package/src/runs/background/retained-nested-route-tracker.ts +96 -0
  92. package/src/runs/background/run-child-session.ts +118 -41
  93. package/src/runs/background/run-status.ts +78 -5
  94. package/src/runs/background/runner-aliases.ts +22 -5
  95. package/src/runs/background/runner-child-launch.ts +93 -0
  96. package/src/runs/background/runner-child-sessions.ts +5 -4
  97. package/src/runs/background/runner-http-dispatcher.ts +119 -0
  98. package/src/runs/background/scheduled-runs.ts +51 -18
  99. package/src/runs/background/stale-run-reconciler.ts +38 -12
  100. package/src/runs/background/steering.ts +20 -2
  101. package/src/runs/background/subagent-runner.ts +766 -432
  102. package/src/runs/background/subagent-wait.ts +179 -28
  103. package/src/runs/background/wait-completions.ts +79 -27
  104. package/src/runs/background/wait-subscriptions.ts +9 -3
  105. package/src/runs/background/wait-tool.ts +5 -3
  106. package/src/runs/foreground/async-steering-action.ts +37 -7
  107. package/src/runs/foreground/async-stop-action.ts +93 -3
  108. package/src/runs/foreground/execution.ts +174 -194
  109. package/src/runs/foreground/foreground-history.ts +5 -2
  110. package/src/runs/foreground/prompt-audit.ts +12 -6
  111. package/src/runs/foreground/subagent-executor.ts +896 -397
  112. package/src/runs/foreground/workflow-detach-reconcile.ts +10 -5
  113. package/src/runs/foreground/workflow-foreground-steering.ts +57 -2
  114. package/src/runs/shared/acceptance.ts +54 -14
  115. package/src/runs/shared/agent-contract.ts +1 -1
  116. package/src/runs/shared/async-status-projection.ts +172 -78
  117. package/src/runs/shared/capability-ceiling.ts +2 -0
  118. package/src/runs/shared/child-hooks.ts +167 -3
  119. package/src/runs/shared/child-launch-plan.ts +15 -3
  120. package/src/runs/shared/child-launch.ts +44 -16
  121. package/src/runs/shared/child-lifecycle.ts +6 -3
  122. package/src/runs/shared/child-runtime-config.ts +8 -1
  123. package/src/runs/shared/child-session.ts +130 -24
  124. package/src/runs/shared/child-tool-plan.ts +145 -14
  125. package/src/runs/shared/completion-evidence.ts +2 -2
  126. package/src/runs/shared/completion-guard.ts +6 -3
  127. package/src/runs/shared/dynamic-fanout.ts +2 -2
  128. package/src/runs/shared/effective-system-prompt.ts +33 -0
  129. package/src/runs/shared/external-cli-contract.ts +11 -1
  130. package/src/runs/shared/external-cli-preflight.ts +6 -2
  131. package/src/runs/shared/external-cli-runner.ts +9 -7
  132. package/src/runs/shared/herdr-connection.ts +134 -0
  133. package/src/runs/shared/herdr-external-adapters.ts +169 -0
  134. package/src/runs/shared/herdr-machine.ts +279 -0
  135. package/src/runs/shared/herdr-pi-protocol.ts +59 -0
  136. package/src/runs/shared/herdr-placed-run.ts +263 -0
  137. package/src/runs/shared/host-step-status.ts +11 -11
  138. package/src/runs/shared/llm-intent-arbiter.ts +40 -21
  139. package/src/runs/shared/model-resolution-diagnostic.ts +76 -0
  140. package/src/runs/shared/{model-fallback.ts → model-resolution.ts} +34 -218
  141. package/src/runs/shared/model-scope.ts +1 -1
  142. package/src/runs/shared/nested-events.ts +19 -10
  143. package/src/runs/shared/orca-progress-tabs.ts +7 -1
  144. package/src/runs/shared/parallel-handoff.ts +57 -12
  145. package/src/runs/shared/parallel-utils.ts +10 -4
  146. package/src/runs/shared/pi-spawn.ts +10 -0
  147. package/src/runs/shared/readonly-drain-observation.ts +42 -0
  148. package/src/runs/shared/run-fanout-budget.ts +8 -8
  149. package/src/runs/shared/runtime-acknowledged-extensions.ts +3 -3
  150. package/src/runs/shared/subagent-prompt-runtime.ts +23 -5
  151. package/src/runs/shared/task-intent.ts +46 -13
  152. package/src/runs/shared/workflow-async-child-guidance.ts +18 -0
  153. package/src/runs/shared/worktree-cleanup-plan.ts +6 -3
  154. package/src/runs/shared/worktree-setup-command.ts +213 -0
  155. package/src/runs/shared/worktree.ts +437 -214
  156. package/src/shared/child-cache-retention.ts +43 -0
  157. package/src/shared/fork-context.ts +15 -72
  158. package/src/shared/launch-contract.ts +70 -8
  159. package/src/shared/model-response-aliases.ts +13 -0
  160. package/src/shared/opencode-session-headers.ts +30 -0
  161. package/src/shared/pruned-fork.ts +1 -1
  162. package/src/shared/required-child-extensions.ts +81 -0
  163. package/src/shared/settings.ts +5 -2
  164. package/src/shared/shortcuts.ts +0 -4
  165. package/src/shared/types.ts +164 -90
  166. package/src/shared/utils.ts +10 -2
  167. package/src/shared/watch-strategy.ts +2 -0
  168. package/src/shared/workflow-child-permit.ts +18 -13
  169. package/src/slash/delegation-adapters.ts +3 -1
  170. package/src/slash/delegation-request.ts +14 -0
  171. package/src/slash/slash-commands.ts +2 -7
  172. package/src/slash/subagents-admin.ts +31 -14
  173. package/src/tui/fleet-native-transcript.ts +50 -6
  174. package/src/tui/fleet-status.ts +165 -20
  175. package/src/tui/fleet.ts +52 -21
  176. package/src/tui/render.ts +210 -50
  177. package/src/watchdog/child-status.ts +28 -28
  178. package/src/watchdog/lsp-diagnostics.ts +1 -1
  179. package/src/watchdog/model-selection.ts +21 -1
  180. package/src/watchdog/permission-arbiter.ts +5 -2
  181. package/src/watchdog/register-child.ts +10 -2
  182. package/src/watchdog/register-main.ts +39 -35
  183. package/src/watchdog/render.ts +1 -1
  184. package/src/watchdog/review.ts +122 -74
  185. package/src/watchdog/rules.ts +1 -1
  186. package/src/watchdog/runtime.ts +100 -27
  187. package/src/watchdog/scope.ts +1 -1
  188. package/src/watchdog/settings.ts +3 -0
  189. package/src/watchdog/tool-actions.ts +13 -12
  190. package/src/watchdog/turn-delta.ts +23 -0
  191. package/src/watchdog/types.ts +5 -3
  192. package/src/watchdog/warning-format.ts +1 -1
  193. package/src/workflows/chat-progress.ts +3 -3
  194. package/src/workflows/scripted-workflow.ts +349 -26
  195. package/src/workflows/workflow-checklist.ts +17 -20
  196. package/src/workflows/workflow-child-summary.ts +57 -8
  197. package/src/workflows/workflow-preflight.ts +19 -19
  198. package/src/workflows/workflow-receipt.ts +24 -6
  199. package/src/workflows/workflow-resources.ts +108 -22
  200. package/src/workflows/workflow-settlement.ts +3 -0
  201. package/src/runs/shared/model-exclusions.ts +0 -373
  202. /package/src/inspectors/{herdr/shell-command.ts → shell-command.ts} +0 -0
@@ -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
@@ -54,11 +54,19 @@ type Theme = TranscriptTheme;
54
54
  type ThemeColor = string;
55
55
  type ThemeBackground = string;
56
56
  export type TranscriptNoticeTone = "info" | "warning" | "error";
57
+ /**
58
+ * How a turn ended. A host that distinguishes a completed exchange from one the
59
+ * user aborted or that failed records it on the turn's end boundary; rendering
60
+ * treats every finished turn the same, so this stays metadata for hosts/tests.
61
+ */
62
+ export type TranscriptTurnOutcome = "completed" | "aborted" | "failed";
57
63
  export type TranscriptEntry = {
58
64
  id: number;
59
65
  turnId: number;
60
66
  type: "turn-boundary";
61
67
  phase: "start" | "end";
68
+ /** Present on `end` boundaries when the host reported how the turn ended. */
69
+ outcome?: TranscriptTurnOutcome;
62
70
  } | {
63
71
  id: number;
64
72
  turnId: number;
@@ -206,10 +214,12 @@ export declare function findLatestEntry<TType extends TranscriptEntry["type"]>(s
206
214
  * Closes `turnId` (defaulting to the current turn): appends the end boundary
207
215
  * unless one already exists, clears streaming flags on the turn's entries,
208
216
  * and updates bookkeeping. Idempotent — finishing an already-finished turn is
209
- * a no-op for boundary creation. Public building block for hosts that know
210
- * when a replayed exchange is complete.
217
+ * a no-op for boundary creation. An optional `outcome` is recorded on the end
218
+ * boundary, letting hosts distinguish completed, aborted, and failed turns.
219
+ * Public building block for hosts that know when a replayed exchange is
220
+ * complete.
211
221
  */
212
- export declare function finishTurn(state: TranscriptState, turnId?: number | null): void;
222
+ export declare function finishTurn(state: TranscriptState, turnId?: number | null, outcome?: TranscriptTurnOutcome): void;
213
223
  export declare function removeTranscriptTurn(state: TranscriptState, turnId: number | null): void;
214
224
  /**
215
225
  * Degraded stand-in stored on a tool-call entry when the original arguments
@@ -242,9 +252,34 @@ export declare function ensureToolCall(state: TranscriptState, turnId: number, t
242
252
  /**
243
253
  * Inserts or updates the thinking/assistant-text entry for `turnId`.
244
254
  * Repeated records for the same turn merge into one entry (latest text wins).
245
- * Public building block for hosts that replay completed message records.
255
+ * Public building block for hosts that replay the *same* completed message
256
+ * several times (live message updates persisted line by line).
257
+ *
258
+ * Hosts replaying *distinct* assistant messages inside one turn must use
259
+ * `appendText` / `appendAssistantMessage` instead: a turn that contains
260
+ * several persisted assistant messages would otherwise keep only the last one.
246
261
  */
247
262
  export declare function upsertText(state: TranscriptState, turnId: number, type: "thinking" | "assistant-text", text: string, streaming: boolean): void;
263
+ /**
264
+ * Appends a thinking/assistant-text entry for `turnId` without merging into
265
+ * any previous entry of the same type. Public building block for hosts that
266
+ * replay finished transcripts, where every persisted assistant message is a
267
+ * distinct entry even when several of them share one turn.
268
+ */
269
+ export declare function appendText(state: TranscriptState, turnId: number, type: "thinking" | "assistant-text", text: string, streaming?: boolean): TranscriptEntry | undefined;
270
+ /**
271
+ * Appends one completed assistant message as its own thinking and/or
272
+ * assistant-text entries, in the order Pi renders them inside a message.
273
+ * Unlike `upsertText` it never overwrites an earlier message of the same
274
+ * turn, so history replay keeps every assistant message and thinking block.
275
+ */
276
+ export declare function appendAssistantMessage(state: TranscriptState, turnId: number, message: {
277
+ thinking?: string;
278
+ text?: string;
279
+ }, streaming?: boolean): {
280
+ thinkingEntryId?: number;
281
+ textEntryId?: number;
282
+ };
248
283
  /**
249
284
  * Inserts or updates the structured result of a tool call, creating the call
250
285
  * placeholder first when the result arrives before its start event. Safe to
@@ -287,7 +322,14 @@ export interface TranscriptRenderOptions {
287
322
  theme: Theme;
288
323
  emptyText?: string;
289
324
  assistantLabel?: string;
325
+ /** Collapsed-label text used when `hideThinkingBlock` is enabled. */
290
326
  thinkingLabel?: string;
327
+ /**
328
+ * Render assistant thinking blocks collapsed to `thinkingLabel`. Defaults to
329
+ * `false` (expanded), so existing hosts keep Pi's default transcript
330
+ * behavior; hosts that own their own expansion gesture opt in.
331
+ */
332
+ hideThinkingBlock?: boolean;
291
333
  assistantBadgeBackground?: ThemeBackground;
292
334
  assistantBadgeForeground?: ThemeColor;
293
335
  /**
@@ -174,7 +174,8 @@ function isUnsafeTerminalCodePoint(codePoint) {
174
174
  (codePoint & 0xffff) === 0xfffe ||
175
175
  (codePoint & 0xffff) === 0xffff);
176
176
  }
177
- function consumeControlString(value, index, osc) {
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, index) {
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)
@@ -312,17 +314,29 @@ export function findLatestEntry(state, turnId, type) {
312
314
  * Closes `turnId` (defaulting to the current turn): appends the end boundary
313
315
  * unless one already exists, clears streaming flags on the turn's entries,
314
316
  * and updates bookkeeping. Idempotent — finishing an already-finished turn is
315
- * a no-op for boundary creation. Public building block for hosts that know
316
- * when a replayed exchange is complete.
317
+ * a no-op for boundary creation. An optional `outcome` is recorded on the end
318
+ * boundary, letting hosts distinguish completed, aborted, and failed turns.
319
+ * Public building block for hosts that know when a replayed exchange is
320
+ * complete.
317
321
  */
318
- export function finishTurn(state, turnId = state.currentTurnId) {
322
+ export function finishTurn(state, turnId = state.currentTurnId, outcome) {
319
323
  if (turnId === null)
320
324
  return;
321
- const alreadyFinished = state.entries.some((entry) => entry.turnId === turnId &&
325
+ const endBoundary = state.entries.find((entry) => entry.turnId === turnId &&
322
326
  entry.type === "turn-boundary" &&
323
327
  entry.phase === "end");
324
- if (!alreadyFinished)
325
- appendEntry(state, { type: "turn-boundary", turnId, phase: "end" });
328
+ if (endBoundary) {
329
+ if (outcome !== undefined)
330
+ endBoundary.outcome = outcome;
331
+ }
332
+ else {
333
+ appendEntry(state, {
334
+ type: "turn-boundary",
335
+ turnId,
336
+ phase: "end",
337
+ ...(outcome === undefined ? {} : { outcome }),
338
+ });
339
+ }
326
340
  for (const entry of state.entries) {
327
341
  if (entry.turnId !== turnId)
328
342
  continue;
@@ -543,7 +557,12 @@ function finishActiveAssistantSegment(state) {
543
557
  /**
544
558
  * Inserts or updates the thinking/assistant-text entry for `turnId`.
545
559
  * Repeated records for the same turn merge into one entry (latest text wins).
546
- * Public building block for hosts that replay completed message records.
560
+ * Public building block for hosts that replay the *same* completed message
561
+ * several times (live message updates persisted line by line).
562
+ *
563
+ * Hosts replaying *distinct* assistant messages inside one turn must use
564
+ * `appendText` / `appendAssistantMessage` instead: a turn that contains
565
+ * several persisted assistant messages would otherwise keep only the last one.
547
566
  */
548
567
  export function upsertText(state, turnId, type, text, streaming) {
549
568
  if (!text)
@@ -556,6 +575,33 @@ export function upsertText(state, turnId, type, text, streaming) {
556
575
  }
557
576
  appendEntry(state, { type, turnId, text, streaming });
558
577
  }
578
+ /**
579
+ * Appends a thinking/assistant-text entry for `turnId` without merging into
580
+ * any previous entry of the same type. Public building block for hosts that
581
+ * replay finished transcripts, where every persisted assistant message is a
582
+ * distinct entry even when several of them share one turn.
583
+ */
584
+ export function appendText(state, turnId, type, text, streaming = false) {
585
+ if (!text)
586
+ return undefined;
587
+ return appendEntry(state, { type, turnId, text, streaming });
588
+ }
589
+ /**
590
+ * Appends one completed assistant message as its own thinking and/or
591
+ * assistant-text entries, in the order Pi renders them inside a message.
592
+ * Unlike `upsertText` it never overwrites an earlier message of the same
593
+ * turn, so history replay keeps every assistant message and thinking block.
594
+ */
595
+ export function appendAssistantMessage(state, turnId, message, streaming = false) {
596
+ const result = {};
597
+ const thinking = appendText(state, turnId, "thinking", message.thinking ?? "", streaming);
598
+ if (thinking)
599
+ result.thinkingEntryId = thinking.id;
600
+ const text = appendText(state, turnId, "assistant-text", message.text ?? "", streaming);
601
+ if (text)
602
+ result.textEntryId = text.id;
603
+ return result;
604
+ }
559
605
  /**
560
606
  * Inserts or updates the structured result of a tool call, creating the call
561
607
  * placeholder first when the result arrives before its start event. Safe to
@@ -928,7 +974,9 @@ function buildRenderBlocks(entries) {
928
974
  flushAssistant();
929
975
  return blocks;
930
976
  }
931
- const OSC_133_SEQUENCE = /\x1b]133;[ABC]\x07/g;
977
+ const ESC_SEQUENCE = String.fromCharCode(27);
978
+ const BEL_SEQUENCE = String.fromCharCode(7);
979
+ const OSC_133_SEQUENCE = new RegExp(`${ESC_SEQUENCE}]133;[ABC]${BEL_SEQUENCE}`, "g");
932
980
  function stripOsc133(lines) {
933
981
  return lines.map((line) => line.replace(OSC_133_SEQUENCE, ""));
934
982
  }
@@ -946,8 +994,8 @@ function createPresentationAssistantMessage(thinking, text) {
946
994
  function renderNativeUserMessage(text, width) {
947
995
  return stripOsc133(new UserMessageComponent(safeTerminalText(text), getMarkdownTheme(), 1).render(width));
948
996
  }
949
- function renderNativeAssistantMessage(thinking, text, width, thinkingLabel) {
950
- return stripOsc133(new AssistantMessageComponent(createPresentationAssistantMessage(thinking, text), false, getMarkdownTheme(), thinkingLabel, 1).render(width));
997
+ function renderNativeAssistantMessage(thinking, text, width, thinkingLabel, hideThinkingBlock) {
998
+ return stripOsc133(new AssistantMessageComponent(createPresentationAssistantMessage(thinking, text), hideThinkingBlock, getMarkdownTheme(), thinkingLabel, 1).render(width));
951
999
  }
952
1000
  function wrapRenderedLines(lines, width, verbatimLines) {
953
1001
  const wrapped = [];
@@ -958,10 +1006,10 @@ function wrapRenderedLines(lines, width, verbatimLines) {
958
1006
  wrapped.push(line);
959
1007
  continue;
960
1008
  }
961
- if (!line)
962
- wrapped.push("");
963
- else
1009
+ if (line)
964
1010
  wrapped.push(...wrapTextWithAnsi(line, Math.max(1, width)));
1011
+ else
1012
+ wrapped.push("");
965
1013
  }
966
1014
  return wrapped;
967
1015
  }
@@ -1029,7 +1077,7 @@ export function renderTranscriptLines(entries, options) {
1029
1077
  case "assistant":
1030
1078
  blankBefore();
1031
1079
  lines.push(assistantBadge);
1032
- lines.push(...renderNativeAssistantMessage(block.thinking, block.text, width, options.thinkingLabel ?? "Thinking"));
1080
+ lines.push(...renderNativeAssistantMessage(block.thinking, block.text, width, options.thinkingLabel ?? "Thinking", options.hideThinkingBlock === true));
1033
1081
  break;
1034
1082
  case "tool-native": {
1035
1083
  blankBefore();
@@ -1062,7 +1110,7 @@ export function renderTranscriptLines(entries, options) {
1062
1110
  * TUI mode does not already provide it.
1063
1111
  */
1064
1112
  export function getTranscriptMouseScrollDelta(data) {
1065
- const match = data.match(/^\x1b\[<(\d+);\d+;\d+[Mm]$/);
1113
+ const match = data.match(new RegExp(`^${ESC_SEQUENCE}\\[<(\\d+);\\d+;\\d+[Mm]$`));
1066
1114
  if (!match)
1067
1115
  return null;
1068
1116
  const button = Number(match[1]);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xzzpig/pi-components",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": true,
5
5
  "description": "Reusable transcript components for Pi extensions.",
6
6
  "license": "MIT",
@@ -79,12 +79,21 @@ type ThemeBackground = string;
79
79
 
80
80
  export type TranscriptNoticeTone = "info" | "warning" | "error";
81
81
 
82
+ /**
83
+ * How a turn ended. A host that distinguishes a completed exchange from one the
84
+ * user aborted or that failed records it on the turn's end boundary; rendering
85
+ * treats every finished turn the same, so this stays metadata for hosts/tests.
86
+ */
87
+ export type TranscriptTurnOutcome = "completed" | "aborted" | "failed";
88
+
82
89
  export type TranscriptEntry =
83
90
  | {
84
91
  id: number;
85
92
  turnId: number;
86
93
  type: "turn-boundary";
87
94
  phase: "start" | "end";
95
+ /** Present on `end` boundaries when the host reported how the turn ended. */
96
+ outcome?: TranscriptTurnOutcome;
88
97
  }
89
98
  | { id: number; turnId: number; type: "user-message"; text: string }
90
99
  | {
@@ -398,9 +407,10 @@ function isUnsafeTerminalCodePoint(codePoint: number): boolean {
398
407
 
399
408
  function consumeControlString(
400
409
  value: string,
401
- index: number,
410
+ start: number,
402
411
  osc: boolean,
403
412
  ): number {
413
+ let index = start;
404
414
  while (index < value.length) {
405
415
  const codePoint = value.codePointAt(index);
406
416
  if (codePoint === undefined) break;
@@ -414,7 +424,8 @@ function consumeControlString(
414
424
  return value.length;
415
425
  }
416
426
 
417
- function consumeCsi(value: string, index: number): number {
427
+ function consumeCsi(value: string, start: number): number {
428
+ let index = start;
418
429
  while (index < value.length) {
419
430
  const codePoint = value.codePointAt(index);
420
431
  if (codePoint === undefined) break;
@@ -553,22 +564,33 @@ export function findLatestEntry<TType extends TranscriptEntry["type"]>(
553
564
  * Closes `turnId` (defaulting to the current turn): appends the end boundary
554
565
  * unless one already exists, clears streaming flags on the turn's entries,
555
566
  * and updates bookkeeping. Idempotent — finishing an already-finished turn is
556
- * a no-op for boundary creation. Public building block for hosts that know
557
- * when a replayed exchange is complete.
567
+ * a no-op for boundary creation. An optional `outcome` is recorded on the end
568
+ * boundary, letting hosts distinguish completed, aborted, and failed turns.
569
+ * Public building block for hosts that know when a replayed exchange is
570
+ * complete.
558
571
  */
559
572
  export function finishTurn(
560
573
  state: TranscriptState,
561
574
  turnId: number | null = state.currentTurnId,
575
+ outcome?: TranscriptTurnOutcome,
562
576
  ): void {
563
577
  if (turnId === null) return;
564
- const alreadyFinished = state.entries.some(
565
- (entry) =>
578
+ const endBoundary = state.entries.find(
579
+ (entry): entry is Extract<TranscriptEntry, { type: "turn-boundary" }> =>
566
580
  entry.turnId === turnId &&
567
581
  entry.type === "turn-boundary" &&
568
582
  entry.phase === "end",
569
583
  );
570
- if (!alreadyFinished)
571
- appendEntry(state, { type: "turn-boundary", turnId, phase: "end" });
584
+ if (endBoundary) {
585
+ if (outcome !== undefined) endBoundary.outcome = outcome;
586
+ } else {
587
+ appendEntry(state, {
588
+ type: "turn-boundary",
589
+ turnId,
590
+ phase: "end",
591
+ ...(outcome === undefined ? {} : { outcome }),
592
+ });
593
+ }
572
594
  for (const entry of state.entries) {
573
595
  if (entry.turnId !== turnId) continue;
574
596
  if (
@@ -843,7 +865,12 @@ function finishActiveAssistantSegment(state: TranscriptState): void {
843
865
  /**
844
866
  * Inserts or updates the thinking/assistant-text entry for `turnId`.
845
867
  * Repeated records for the same turn merge into one entry (latest text wins).
846
- * Public building block for hosts that replay completed message records.
868
+ * Public building block for hosts that replay the *same* completed message
869
+ * several times (live message updates persisted line by line).
870
+ *
871
+ * Hosts replaying *distinct* assistant messages inside one turn must use
872
+ * `appendText` / `appendAssistantMessage` instead: a turn that contains
873
+ * several persisted assistant messages would otherwise keep only the last one.
847
874
  */
848
875
  export function upsertText(
849
876
  state: TranscriptState,
@@ -862,6 +889,55 @@ export function upsertText(
862
889
  appendEntry(state, { type, turnId, text, streaming });
863
890
  }
864
891
 
892
+ /**
893
+ * Appends a thinking/assistant-text entry for `turnId` without merging into
894
+ * any previous entry of the same type. Public building block for hosts that
895
+ * replay finished transcripts, where every persisted assistant message is a
896
+ * distinct entry even when several of them share one turn.
897
+ */
898
+ export function appendText(
899
+ state: TranscriptState,
900
+ turnId: number,
901
+ type: "thinking" | "assistant-text",
902
+ text: string,
903
+ streaming = false,
904
+ ): TranscriptEntry | undefined {
905
+ if (!text) return undefined;
906
+ return appendEntry(state, { type, turnId, text, streaming });
907
+ }
908
+
909
+ /**
910
+ * Appends one completed assistant message as its own thinking and/or
911
+ * assistant-text entries, in the order Pi renders them inside a message.
912
+ * Unlike `upsertText` it never overwrites an earlier message of the same
913
+ * turn, so history replay keeps every assistant message and thinking block.
914
+ */
915
+ export function appendAssistantMessage(
916
+ state: TranscriptState,
917
+ turnId: number,
918
+ message: { thinking?: string; text?: string },
919
+ streaming = false,
920
+ ): { thinkingEntryId?: number; textEntryId?: number } {
921
+ const result: { thinkingEntryId?: number; textEntryId?: number } = {};
922
+ const thinking = appendText(
923
+ state,
924
+ turnId,
925
+ "thinking",
926
+ message.thinking ?? "",
927
+ streaming,
928
+ );
929
+ if (thinking) result.thinkingEntryId = thinking.id;
930
+ const text = appendText(
931
+ state,
932
+ turnId,
933
+ "assistant-text",
934
+ message.text ?? "",
935
+ streaming,
936
+ );
937
+ if (text) result.textEntryId = text.id;
938
+ return result;
939
+ }
940
+
865
941
  /**
866
942
  * Inserts or updates the structured result of a tool call, creating the call
867
943
  * placeholder first when the result arrives before its start event. Safe to
@@ -1430,7 +1506,13 @@ function buildRenderBlocks(
1430
1506
  return blocks;
1431
1507
  }
1432
1508
 
1433
- const OSC_133_SEQUENCE = /\x1b]133;[ABC]\x07/g;
1509
+ const ESC_SEQUENCE = String.fromCharCode(27);
1510
+ const BEL_SEQUENCE = String.fromCharCode(7);
1511
+
1512
+ const OSC_133_SEQUENCE = new RegExp(
1513
+ `${ESC_SEQUENCE}]133;[ABC]${BEL_SEQUENCE}`,
1514
+ "g",
1515
+ );
1434
1516
 
1435
1517
  type PresentationAssistantMessage = NonNullable<
1436
1518
  ConstructorParameters<typeof AssistantMessageComponent>[0]
@@ -1471,11 +1553,12 @@ function renderNativeAssistantMessage(
1471
1553
  text: string,
1472
1554
  width: number,
1473
1555
  thinkingLabel: string,
1556
+ hideThinkingBlock: boolean,
1474
1557
  ): string[] {
1475
1558
  return stripOsc133(
1476
1559
  new AssistantMessageComponent(
1477
1560
  createPresentationAssistantMessage(thinking, text),
1478
- false,
1561
+ hideThinkingBlock,
1479
1562
  getMarkdownTheme(),
1480
1563
  thinkingLabel,
1481
1564
  1,
@@ -1496,8 +1579,8 @@ function wrapRenderedLines(
1496
1579
  wrapped.push(line);
1497
1580
  continue;
1498
1581
  }
1499
- if (!line) wrapped.push("");
1500
- else wrapped.push(...wrapTextWithAnsi(line, Math.max(1, width)));
1582
+ if (line) wrapped.push(...wrapTextWithAnsi(line, Math.max(1, width)));
1583
+ else wrapped.push("");
1501
1584
  }
1502
1585
  return wrapped;
1503
1586
  }
@@ -1518,7 +1601,14 @@ export interface TranscriptRenderOptions {
1518
1601
  theme: Theme;
1519
1602
  emptyText?: string;
1520
1603
  assistantLabel?: string;
1604
+ /** Collapsed-label text used when `hideThinkingBlock` is enabled. */
1521
1605
  thinkingLabel?: string;
1606
+ /**
1607
+ * Render assistant thinking blocks collapsed to `thinkingLabel`. Defaults to
1608
+ * `false` (expanded), so existing hosts keep Pi's default transcript
1609
+ * behavior; hosts that own their own expansion gesture opt in.
1610
+ */
1611
+ hideThinkingBlock?: boolean;
1522
1612
  assistantBadgeBackground?: ThemeBackground;
1523
1613
  assistantBadgeForeground?: ThemeColor;
1524
1614
  /**
@@ -1616,6 +1706,7 @@ export function renderTranscriptLines(
1616
1706
  block.text,
1617
1707
  width,
1618
1708
  options.thinkingLabel ?? "Thinking",
1709
+ options.hideThinkingBlock === true,
1619
1710
  ),
1620
1711
  );
1621
1712
  break;
@@ -1669,7 +1760,9 @@ export interface TranscriptViewportRender {
1669
1760
  * TUI mode does not already provide it.
1670
1761
  */
1671
1762
  export function getTranscriptMouseScrollDelta(data: string): number | null {
1672
- const match = data.match(/^\x1b\[<(\d+);\d+;\d+[Mm]$/);
1763
+ const match = data.match(
1764
+ new RegExp(`^${ESC_SEQUENCE}\\[<(\\d+);\\d+;\\d+[Mm]$`),
1765
+ );
1673
1766
  if (!match) return null;
1674
1767
 
1675
1768
  const button = Number(match[1]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xzzpig/pi-subagents",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Pi extension for single-agent delegation and scripted multi-agent workflows",
5
5
  "author": "Nico Bailon",
6
6
  "license": "MIT",
@@ -13,6 +13,8 @@
13
13
  "./agents": "./src/api/agents.ts",
14
14
  "./delegation": "./src/api/delegation.ts",
15
15
  "./capability-ceiling": "./src/api/capability-ceiling.ts",
16
+ "./workflow-resources": "./src/api/workflow-resources.ts",
17
+ "./required-child-extensions": "./src/api/required-child-extensions.ts",
16
18
  "./preflight": "./src/api/preflight.ts",
17
19
  "./agent-management": "./src/api/agent-management.ts",
18
20
  "./control-channel": "./src/api/control-channel.ts",
@@ -84,16 +86,17 @@
84
86
  }
85
87
  },
86
88
  "dependencies": {
87
- "@xzzpig/pi-components": "0.3.0",
89
+ "@xzzpig/pi-components": "0.4.0",
88
90
  "acorn": "8.18.0",
89
91
  "jiti": "2.7.0",
90
92
  "typebox": "1.1.38",
93
+ "undici": "8.10.0",
91
94
  "yaml": "2.8.3"
92
95
  },
93
96
  "devDependencies": {
94
- "@earendil-works/pi-agent-core": "0.84.2",
95
- "@earendil-works/pi-ai": "0.84.2",
96
- "@earendil-works/pi-tui": "0.84.2",
97
+ "@earendil-works/pi-agent-core": "0.85.1",
98
+ "@earendil-works/pi-ai": "0.85.1",
99
+ "@earendil-works/pi-tui": "0.85.1",
97
100
  "@oxlint/plugins": "1.80.0",
98
101
  "@types/node": "24.13.3",
99
102
  "oxlint": "1.80.0",
@@ -107,6 +110,8 @@
107
110
  "@xzzpig/pi-components"
108
111
  ],
109
112
  "scripts": {
113
+ "build:pkg": "node scripts/build-package.mjs",
114
+ "pack:pkg": "npm run build:pkg && npm pack ./dist-pkg",
110
115
  "typecheck": "tsc --noEmit",
111
116
  "test": "npm run test:unit",
112
117
  "test:unit": "env -u PI_SUBAGENT_PARENT_SESSION -u PI_SESSION_ID -u PI_SESSION_FILE -u PI_CODING_AGENT -u PI_PROVIDER -u PI_MODEL -u PI_REASONING_LEVEL -u PI_SUBAGENT_EXTRA_AGENT_DIRS node --experimental-strip-types --import ./test/support/isolated-temp-root.mjs --test test/unit/*.test.ts",
@@ -28,7 +28,7 @@ Choose or adapt angles when the work calls for it:
28
28
 
29
29
  Prefer three strong reviewers over many vague reviewers.
30
30
 
31
- Give every reviewer a specific task prompt naming its angle. Ask reviewers to return concise, evidence-backed findings with file/line references and suggested fixes. Filter on evidence, not severity: a finding must be concrete, current, caused or made reachable by the target diff, and supported by source proof, a test or repro, or a contract contradiction. Label findings P0/P1/P2. P0 blocks merge. P1 should be fixed before release. P2 is report-only. End each review with `Merge verdict: BLOCK`, `Merge verdict: OK`, or `Merge verdict: OK with notes`. If nothing qualifies, ask the reviewer to say exactly `No issues found.` The response should be review feedback, not a context summary. Reviewers must not edit files unless I explicitly ask for a writer pass.
31
+ Give every reviewer a specific task prompt naming its angle. Ask reviewers to return concise, evidence-backed findings with file/line references and suggested fixes. Filter on evidence, not severity: a finding must be concrete and current within the named review target, and supported by source proof, a test or repro, or a contract contradiction. For a diff review, require that the issue is caused or made reachable by that diff. Label findings P0/P1/P2. P0 blocks merge. P1 should be fixed before release. P2 is report-only. End each review with `Merge verdict: BLOCK`, `Merge verdict: OK`, or `Merge verdict: OK with notes`. If nothing qualifies, ask the reviewer to say exactly `No issues found.` The response should be review feedback, not a context summary. Reviewers must not edit files unless I explicitly ask for a writer pass.
32
32
 
33
33
  Do not default first-pass reviews to `blockers only`. That phrase is valid only for final pre-merge re-checks after P1/P2 findings are already inventoried, or for explicit emergency hotfix lanes where non-blocking findings are intentionally deferred.
34
34
 
@@ -0,0 +1,24 @@
1
+ import { pathToFileURL } from "node:url";
2
+
3
+ let aliases = {};
4
+ let nativeRunner = false;
5
+ let compiledRunner = false;
6
+ let packageRootUrl;
7
+ const redirected = new Set([
8
+ "@earendil-works/pi-tui",
9
+ ]);
10
+
11
+ export function initialize(data) {
12
+ aliases = data?.aliases ?? {};
13
+ nativeRunner = data?.nativeRunner === true;
14
+ compiledRunner = data?.compiledRunner === true;
15
+ packageRootUrl = data?.packageRootUrl;
16
+ }
17
+
18
+ export function resolve(specifier, context, nextResolve) {
19
+ const packageImport = typeof packageRootUrl === "string" && context.parentURL?.startsWith(packageRootUrl) === true;
20
+ if (nativeRunner && (!compiledRunner || packageImport) ? aliases[specifier] : redirected.has(specifier) && aliases[specifier]) {
21
+ return nextResolve(pathToFileURL(aliases[specifier]).href, context);
22
+ }
23
+ return nextResolve(specifier, context);
24
+ }
@@ -0,0 +1,36 @@
1
+ import * as nodeModule from "node:module";
2
+ import { pathToFileURL } from "node:url";
3
+
4
+ // Upstream-original preload: JITI_ALIAS is written by the runner launcher, so a malformed value must fail loudly.
5
+ // pi-lens-ignore: unchecked-throwing-call-js
6
+ const aliases = JSON.parse(process.env.JITI_ALIAS ?? "{}");
7
+ const nativeRunner = process.env.PI_ASYNC_NATIVE_RUNNER === "1";
8
+ const compiledRunner = process.env.PI_ASYNC_COMPILED_RUNNER === "1";
9
+ // Pi's jiti loader owns aliases for external extensions; these hooks only supply peers to our compiled package.
10
+ const packageRootUrl = new URL("./", import.meta.url).href;
11
+ const redirected = new Set([
12
+ "@earendil-works/pi-tui",
13
+ ]);
14
+
15
+ // Upstream-original: Node version feature detection for registerHooks (Node 22.12+ vs register()).
16
+ // pi-lens-ignore: no-runtime-typeof
17
+ if (typeof nodeModule.registerHooks === "function") {
18
+ nodeModule.registerHooks({
19
+ resolve(specifier, context, nextResolve) {
20
+ const packageImport = context.parentURL?.startsWith(packageRootUrl) === true;
21
+ if ((nativeRunner && (!compiledRunner || packageImport) ? aliases[specifier] : redirected.has(specifier) && aliases[specifier])) {
22
+ return nextResolve(pathToFileURL(aliases[specifier]).href, context);
23
+ }
24
+ try {
25
+ return nextResolve(specifier, context);
26
+ } catch (error) {
27
+ if (nativeRunner && specifier.endsWith(".js")) return nextResolve(`${specifier.slice(0, -3)}.ts`, context);
28
+ throw error;
29
+ }
30
+ },
31
+ });
32
+ } else {
33
+ nodeModule.register(new URL("./runner-peer-loader.mjs", import.meta.url), {
34
+ data: { aliases, nativeRunner, compiledRunner, packageRootUrl },
35
+ });
36
+ }