@xzzpig/pi-subagents 0.8.0 → 0.9.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 (218) hide show
  1. package/CHANGELOG.md +443 -0
  2. package/README.md +2 -2
  3. package/agents/claude-code-writer.md +15 -0
  4. package/agents/claude-code.md +15 -0
  5. package/agents/codex-exec-writer.md +15 -0
  6. package/agents/codex-exec.md +15 -0
  7. package/agents/cursor-agent-writer.md +14 -0
  8. package/agents/cursor-agent.md +14 -0
  9. package/agents/reviewer.md +1 -1
  10. package/agents/scout.md +1 -1
  11. package/docs/agents.md +151 -39
  12. package/docs/configuration.md +81 -22
  13. package/docs/extension-api.md +69 -14
  14. package/docs/missions.md +2 -0
  15. package/docs/models.md +32 -9
  16. package/docs/observability.md +22 -20
  17. package/docs/tool-reference.md +123 -14
  18. package/docs/watchdog.md +92 -114
  19. package/docs/workflows.md +142 -4
  20. package/install.mjs +1 -1
  21. package/package.json +5 -4
  22. package/prompts/review-loop.md +2 -2
  23. package/skills/council-mode/SKILL.md +48 -243
  24. package/skills/council-mode/references/pass-contracts.md +150 -0
  25. package/skills/pi-subagents/SKILL.md +89 -35
  26. package/skills/pi-subagents/references/constraints-and-recipes.md +30 -234
  27. package/skills/pi-subagents/references/execution-controls.md +91 -15
  28. package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
  29. package/skills/pi-subagents/references/multi-lane-orchestration.md +13 -1
  30. package/skills/pi-subagents/references/prompting-and-roles.md +59 -31
  31. package/skills/pi-subagents/references/review-and-validation.md +73 -0
  32. package/src/agents/agent-management.ts +370 -114
  33. package/src/agents/agent-refinements.ts +4 -4
  34. package/src/agents/agent-serializer.ts +12 -2
  35. package/src/agents/agents.ts +919 -372
  36. package/src/agents/builtin-names.ts +6 -0
  37. package/src/agents/runtime-agent-events.ts +70 -0
  38. package/src/agents/runtime-agent-registry.ts +31 -20
  39. package/src/api/agents.ts +10 -5
  40. package/src/api/background-work.ts +12 -3
  41. package/src/api/capability-ceiling.ts +0 -1
  42. package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
  43. package/src/api/delegation.ts +0 -7
  44. package/src/api/external-runs.ts +67 -4
  45. package/src/api/preflight.ts +48 -18
  46. package/src/api/shared-types.ts +6 -0
  47. package/src/extension/config.ts +90 -0
  48. package/src/extension/doctor.ts +5 -13
  49. package/src/extension/fanout-child.ts +14 -14
  50. package/src/extension/index.ts +115 -37
  51. package/src/extension/public-execution.ts +103 -15
  52. package/src/extension/rpc.ts +120 -25
  53. package/src/extension/schemas.ts +57 -21
  54. package/src/extension/tool-description.ts +48 -26
  55. package/src/inspectors/herdr/actions.ts +2 -1
  56. package/src/inspectors/herdr/inspector-runner.ts +21 -23
  57. package/src/inspectors/herdr/session-roots-codec.ts +42 -0
  58. package/src/integrations/herdr-status.ts +51 -3
  59. package/src/intercom/native-supervisor-channel.ts +138 -60
  60. package/src/intercom/result-intercom.ts +2 -0
  61. package/src/intercom/supervisor-ui.ts +243 -0
  62. package/src/profiles/profiles.ts +5 -6
  63. package/src/runs/background/active-async-capacity.ts +103 -18
  64. package/src/runs/background/async-execution.ts +366 -128
  65. package/src/runs/background/async-job-tracker.ts +95 -15
  66. package/src/runs/background/async-resume.ts +45 -28
  67. package/src/runs/background/async-retention.ts +20 -3
  68. package/src/runs/background/async-status-snapshot.ts +23 -261
  69. package/src/runs/background/async-status.ts +189 -14
  70. package/src/runs/background/auto-drain.ts +1 -1
  71. package/src/runs/background/chain-append.ts +8 -3
  72. package/src/runs/background/chain-root-attachment.ts +74 -8
  73. package/src/runs/background/control-channel.ts +4 -205
  74. package/src/runs/background/fleet-view.ts +38 -22
  75. package/src/runs/background/inspect-rpc.ts +8 -8
  76. package/src/runs/background/notify.ts +238 -12
  77. package/src/runs/background/process-terminal.ts +16 -0
  78. package/src/runs/background/result-delivery-ownership.ts +45 -0
  79. package/src/runs/background/result-files.ts +28 -14
  80. package/src/runs/background/result-watcher.ts +39 -16
  81. package/src/runs/background/resume-guidance.ts +2 -2
  82. package/src/runs/background/retained-children.ts +1 -1
  83. package/src/runs/background/run-child-session.ts +613 -0
  84. package/src/runs/background/run-status.ts +84 -17
  85. package/src/runs/background/runner-aliases.ts +125 -0
  86. package/src/runs/background/runner-child-sessions.ts +31 -0
  87. package/src/runs/background/scheduled-runs.ts +174 -18
  88. package/src/runs/background/stale-run-reconciler.ts +10 -4
  89. package/src/runs/background/steering.ts +8 -15
  90. package/src/runs/background/subagent-runner.ts +676 -1161
  91. package/src/runs/background/subagent-wait.ts +86 -31
  92. package/src/runs/background/terminal-run-index.ts +1 -1
  93. package/src/runs/background/wait-completions.ts +43 -2
  94. package/src/runs/background/wait-config.ts +23 -9
  95. package/src/runs/background/wait-tool.ts +26 -19
  96. package/src/runs/foreground/async-steering-action.ts +3 -19
  97. package/src/runs/foreground/execution.ts +468 -499
  98. package/src/runs/foreground/foreground-control.ts +13 -0
  99. package/src/runs/foreground/foreground-history.ts +23 -1
  100. package/src/runs/foreground/subagent-executor.ts +1172 -400
  101. package/src/runs/foreground/workflow-detach-reconcile.ts +140 -115
  102. package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
  103. package/src/runs/shared/abort-recovery.ts +119 -0
  104. package/src/runs/shared/acceptance.ts +138 -36
  105. package/src/runs/shared/async-status-projection.ts +565 -0
  106. package/src/runs/shared/background-process-options.ts +9 -0
  107. package/src/runs/shared/capability-ceiling.ts +2 -2
  108. package/src/runs/shared/child-hooks.ts +25 -0
  109. package/src/runs/shared/child-identity.ts +32 -6
  110. package/src/runs/shared/child-launch-plan.ts +151 -0
  111. package/src/runs/shared/child-launch.ts +314 -0
  112. package/src/runs/shared/child-lifecycle.ts +25 -0
  113. package/src/runs/shared/child-runtime-config.ts +126 -0
  114. package/src/runs/shared/child-session.ts +342 -0
  115. package/src/runs/shared/child-tool-plan.ts +540 -0
  116. package/src/runs/shared/claude-code-adapter.ts +133 -0
  117. package/src/runs/shared/codex-exec-adapter.ts +129 -0
  118. package/src/runs/shared/completion-evidence.ts +89 -0
  119. package/src/runs/shared/completion-guard.ts +6 -5
  120. package/src/runs/shared/cursor-agent-adapter.ts +114 -0
  121. package/src/runs/shared/dynamic-fanout.ts +3 -3
  122. package/src/runs/shared/external-cli-contract.ts +167 -0
  123. package/src/runs/shared/external-cli-preflight.ts +138 -0
  124. package/src/runs/shared/external-cli-runner.ts +348 -55
  125. package/src/runs/shared/fast-mode-extension.ts +5 -5
  126. package/src/runs/shared/host-step-status.ts +231 -0
  127. package/src/runs/shared/lane-metadata.ts +126 -0
  128. package/src/runs/shared/launch-cwd.ts +16 -0
  129. package/src/runs/shared/long-running-guard.ts +2 -1
  130. package/src/runs/shared/mcp-config-sources.ts +422 -0
  131. package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
  132. package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
  133. package/src/runs/shared/model-exclusions.ts +139 -9
  134. package/src/runs/shared/model-fallback.ts +142 -14
  135. package/src/runs/shared/mutation-evidence.ts +57 -3
  136. package/src/runs/shared/nested-events.ts +38 -48
  137. package/src/runs/shared/nested-path.ts +0 -14
  138. package/src/runs/shared/nested-render.ts +9 -5
  139. package/src/runs/shared/orca-progress-tabs.ts +12 -7
  140. package/src/runs/shared/parallel-handoff.ts +423 -7
  141. package/src/runs/shared/parallel-utils.ts +15 -7
  142. package/src/runs/shared/permissions.ts +1 -14
  143. package/src/runs/shared/pi-spawn.ts +69 -35
  144. package/src/runs/shared/process-signal.ts +16 -0
  145. package/src/runs/shared/run-fanout-budget.ts +0 -13
  146. package/src/runs/shared/run-history.ts +21 -1
  147. package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
  148. package/src/runs/shared/single-output.ts +89 -22
  149. package/src/runs/shared/structured-output.ts +49 -9
  150. package/src/runs/shared/subagent-control.ts +6 -2
  151. package/src/runs/shared/subagent-prompt-runtime.ts +188 -365
  152. package/src/runs/shared/task-intent.ts +21 -7
  153. package/src/runs/shared/tool-availability.ts +18 -62
  154. package/src/runs/shared/tool-budget.ts +0 -14
  155. package/src/runs/shared/tool-timeout.ts +1 -1
  156. package/src/runs/shared/workflow-graph.ts +16 -0
  157. package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
  158. package/src/runs/shared/worktree.ts +571 -62
  159. package/src/shared/atomic-json.ts +3 -1
  160. package/src/shared/child-session-name.ts +46 -0
  161. package/src/shared/extension-context.ts +24 -0
  162. package/src/shared/fork-context.ts +21 -12
  163. package/src/shared/fork-session-cwd.ts +27 -0
  164. package/src/shared/formatters.ts +18 -3
  165. package/src/shared/jsonl-writer.ts +11 -0
  166. package/src/shared/launch-contract.ts +8 -1
  167. package/src/shared/pruned-fork.ts +450 -0
  168. package/src/shared/session-file-trust.ts +19 -0
  169. package/src/shared/session-tokens.ts +14 -3
  170. package/src/shared/settings.ts +19 -105
  171. package/src/shared/shortcuts.ts +17 -0
  172. package/src/shared/thinking-ceiling.ts +0 -6
  173. package/src/shared/types.ts +524 -70
  174. package/src/shared/utils.ts +60 -93
  175. package/src/shared/workflow-child-permit.ts +207 -0
  176. package/src/slash/delegation-adapters.ts +1 -9
  177. package/src/slash/delegation-request.ts +0 -4
  178. package/src/slash/prompt-template-bridge.ts +37 -1
  179. package/src/slash/slash-bridge.ts +1 -2
  180. package/src/slash/slash-commands.ts +383 -116
  181. package/src/slash/slash-live-state.ts +22 -11
  182. package/src/slash/subagents-admin.ts +29 -12
  183. package/src/tui/fleet-native-transcript.ts +4 -0
  184. package/src/tui/fleet-status.ts +217 -82
  185. package/src/tui/fleet-transcript.ts +11 -5
  186. package/src/tui/fleet.ts +54 -28
  187. package/src/tui/render-helpers.ts +31 -0
  188. package/src/tui/render.ts +1429 -163
  189. package/src/watchdog/change-signature.ts +40 -1
  190. package/src/watchdog/child-status.ts +54 -34
  191. package/src/watchdog/diff-tool.ts +77 -0
  192. package/src/watchdog/emission-guard.ts +5 -3
  193. package/src/watchdog/guidance.ts +20 -0
  194. package/src/watchdog/register-child.ts +28 -25
  195. package/src/watchdog/register-main.ts +10 -9
  196. package/src/watchdog/render.ts +4 -5
  197. package/src/watchdog/review.ts +15 -4
  198. package/src/watchdog/rules.ts +70 -0
  199. package/src/watchdog/runtime.ts +75 -92
  200. package/src/watchdog/scope.ts +0 -11
  201. package/src/watchdog/settings.ts +48 -104
  202. package/src/watchdog/turn-delta.ts +1 -1
  203. package/src/watchdog/types.ts +18 -32
  204. package/src/watchdog/warning-format.ts +0 -1
  205. package/src/workflows/chat-progress.ts +7 -3
  206. package/src/workflows/host-command.ts +235 -0
  207. package/src/workflows/scripted-workflow.ts +988 -59
  208. package/src/workflows/workflow-checklist.ts +439 -0
  209. package/src/workflows/workflow-child-summary.ts +121 -0
  210. package/src/workflows/workflow-preflight.ts +297 -0
  211. package/src/workflows/workflow-receipt.ts +232 -6
  212. package/src/workflows/workflow-resources.ts +150 -0
  213. package/src/workflows/workflow-settlement.ts +246 -0
  214. package/src/runs/shared/child-protocol.ts +0 -401
  215. package/src/runs/shared/pi-args.ts +0 -935
  216. package/src/runs/shared/subagent-startup-retry.ts +0 -116
  217. package/src/runs/shared/turn-budget.ts +0 -98
  218. package/src/shared/post-exit-stdio-guard.ts +0 -85
@@ -0,0 +1,565 @@
1
+ import { sanitizeDisplayText, truncateDisplayText } from "../../shared/display-text.ts";
2
+ import { formatModelThinking } from "../../shared/formatters.ts";
3
+ import type { AsyncJobState, AsyncJobStep, HostStepFreshnessV1, HostStepMonitorKind, HostStepNodeV1, HostStepState, HostStepVerdict, NestedRunSummary, NestedStepSummary, SubagentRunMode, WorkflowGraphSnapshot, WorkflowPreflightLaneV1, WorkflowPreflightV1 } from "../../shared/types.ts";
4
+ import { HOST_STEP_MAX_COUNT, HOST_STEP_MAX_DETAIL_CHARS, HOST_STEP_MAX_LABEL_CHARS, HOST_STEP_MAX_PROVIDER_CHARS, HOST_STEP_MAX_REASON_CHARS, HOST_STEP_MAX_REF_CHARS, HOST_STEP_MAX_ROLE_CHARS, HOST_STEP_MAX_TARGET_CHARS, hostStepReportName, parseHostStepNode, validHostStepNodes } from "./host-step-status.ts";
5
+ import { workflowPreflightLaneForRuntimeKey } from "../../workflows/workflow-preflight.ts";
6
+ import { workflowGraphStageNodes } from "./workflow-graph.ts";
7
+
8
+ export const ASYNC_STATUS_SNAPSHOT_KIND = "pi-subagents.async-status-snapshot";
9
+ export const ASYNC_STATUS_SNAPSHOT_VERSION = 1;
10
+
11
+ const DEFAULT_MAX_RUNS = 20;
12
+ const DEFAULT_MAX_CHILDREN_PER_NODE = 8;
13
+ const DEFAULT_MAX_DEPTH = 3;
14
+ const DEFAULT_MAX_STRING_LENGTH = 160;
15
+ const DEFAULT_MAX_SERIALIZED_BYTES = 32 * 1024;
16
+
17
+ export type AsyncStatusSnapshotState = "queued" | "running" | "complete" | "failed" | "partial" | "paused" | "stopped" | "rejected";
18
+ export type AsyncStatusSnapshotKind = "subagent" | "workflow" | "step";
19
+
20
+ const ASYNC_STATUS_SNAPSHOT_STATES: Record<AsyncStatusSnapshotState, true> = {
21
+ queued: true,
22
+ running: true,
23
+ complete: true,
24
+ failed: true,
25
+ partial: true,
26
+ paused: true,
27
+ stopped: true,
28
+ rejected: true,
29
+ };
30
+
31
+ function isAsyncStatusSnapshotState(value: string): value is AsyncStatusSnapshotState {
32
+ return Object.hasOwn(ASYNC_STATUS_SNAPSHOT_STATES, value);
33
+ }
34
+
35
+ export interface AsyncStatusSnapshotActivityV1 {
36
+ state?: string;
37
+ currentTool?: string;
38
+ lastActivityAt?: number;
39
+ currentToolStartedAt?: number;
40
+ turnCount?: number;
41
+ toolCount?: number;
42
+ }
43
+
44
+ export interface AsyncStatusSnapshotHostStepV1 {
45
+ kind: HostStepMonitorKind;
46
+ provider?: string;
47
+ role?: string;
48
+ state: HostStepState;
49
+ verdict?: HostStepVerdict;
50
+ reasonCode?: string;
51
+ detail?: string;
52
+ target?: string;
53
+ stale?: boolean;
54
+ report?: string;
55
+ }
56
+
57
+ export interface AsyncStatusSnapshotNodeV1 {
58
+ id: string;
59
+ kind: AsyncStatusSnapshotKind | "host-step";
60
+ label: string;
61
+ state: AsyncStatusSnapshotState;
62
+ startedAt?: number;
63
+ updatedAt?: number;
64
+ endedAt?: number;
65
+ activity?: AsyncStatusSnapshotActivityV1;
66
+ hostStep?: AsyncStatusSnapshotHostStepV1;
67
+ children?: AsyncStatusSnapshotNodeV1[];
68
+ }
69
+
70
+ export interface AsyncStatusSnapshotCapsV1 {
71
+ maxRuns: number;
72
+ maxChildrenPerNode: number;
73
+ maxDepth: number;
74
+ maxStringLength: number;
75
+ maxSerializedBytes: number;
76
+ }
77
+
78
+ export interface AsyncStatusSnapshotOmittedV1 {
79
+ runs: number;
80
+ children: number;
81
+ byteLimitExceeded: boolean;
82
+ }
83
+
84
+ export interface AsyncStatusSnapshotV1 {
85
+ kind: typeof ASYNC_STATUS_SNAPSHOT_KIND;
86
+ version: typeof ASYNC_STATUS_SNAPSHOT_VERSION;
87
+ generatedAt: number;
88
+ caps: AsyncStatusSnapshotCapsV1;
89
+ omitted: AsyncStatusSnapshotOmittedV1;
90
+ runs: AsyncStatusSnapshotNodeV1[];
91
+ }
92
+
93
+ export interface AsyncStatusSnapshotOptions {
94
+ generatedAt?: number;
95
+ maxRuns?: number;
96
+ maxChildrenPerNode?: number;
97
+ maxDepth?: number;
98
+ maxStringLength?: number;
99
+ maxSerializedBytes?: number;
100
+ }
101
+
102
+ export interface AsyncStatusWorkflowRow {
103
+ name: string;
104
+ state: AsyncJobStep["status"] | HostStepState | "planned";
105
+ /** Present only for typed host-owned monitor rows; legacy child rows omit it. */
106
+ kind?: HostStepMonitorKind;
107
+ context?: AsyncJobStep["context"];
108
+ modelThinking?: string;
109
+ activity?: string;
110
+ startedAt?: number;
111
+ tokens?: number;
112
+ window?: number;
113
+ overflow?: number;
114
+ provider?: string;
115
+ role?: string;
116
+ verdict?: HostStepVerdict;
117
+ reasonCode?: string;
118
+ detail?: string;
119
+ target?: string;
120
+ freshness?: HostStepFreshnessV1;
121
+ reportPath?: string;
122
+ preflight?: WorkflowPreflightLaneV1;
123
+ }
124
+
125
+ interface ProjectionContext {
126
+ caps: AsyncStatusSnapshotCapsV1;
127
+ omitted: AsyncStatusSnapshotOmittedV1;
128
+ }
129
+
130
+ function validHostStepList(source: readonly HostStepNodeV1[] | WorkflowGraphSnapshot | undefined): HostStepNodeV1[] {
131
+ if (source && "nodes" in source) return validHostStepNodes(source);
132
+ const hostSteps: HostStepNodeV1[] = [];
133
+ for (const [index, value] of (source ?? []).slice(0, HOST_STEP_MAX_COUNT).entries()) {
134
+ try {
135
+ hostSteps.push(parseHostStepNode(value, `hostSteps[${index}]`));
136
+ } catch {
137
+ // Renderers must not turn malformed host data into a fake child row.
138
+ }
139
+ }
140
+ return hostSteps;
141
+ }
142
+
143
+ function resolveCaps(options: AsyncStatusSnapshotOptions): AsyncStatusSnapshotCapsV1 {
144
+ return {
145
+ maxRuns: Math.max(0, Math.floor(options.maxRuns ?? DEFAULT_MAX_RUNS)),
146
+ maxChildrenPerNode: Math.max(0, Math.floor(options.maxChildrenPerNode ?? DEFAULT_MAX_CHILDREN_PER_NODE)),
147
+ maxDepth: Math.max(0, Math.floor(options.maxDepth ?? DEFAULT_MAX_DEPTH)),
148
+ maxStringLength: Math.max(0, Math.floor(options.maxStringLength ?? DEFAULT_MAX_STRING_LENGTH)),
149
+ maxSerializedBytes: Math.max(256, Math.floor(options.maxSerializedBytes ?? DEFAULT_MAX_SERIALIZED_BYTES)),
150
+ };
151
+ }
152
+
153
+ function publicText(value: unknown, fallback: string, maxLength: number): string {
154
+ if (typeof value !== "string") return fallback;
155
+ const normalized = sanitizeDisplayText(value.slice(0, Math.max(0, maxLength * 4)));
156
+ return truncateDisplayText(normalized || fallback, maxLength);
157
+ }
158
+
159
+ function publicOptionalText(value: unknown, maxLength: number): string | undefined {
160
+ if (typeof value !== "string") return undefined;
161
+ const normalized = sanitizeDisplayText(value.slice(0, Math.max(0, maxLength * 4)));
162
+ return normalized ? truncateDisplayText(normalized, maxLength) : undefined;
163
+ }
164
+
165
+ function publicTime(value: unknown): number | undefined {
166
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
167
+ }
168
+
169
+ function publicCount(value: unknown): number | undefined {
170
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
171
+ }
172
+
173
+ function normalizeState(value: string): AsyncStatusSnapshotState {
174
+ if (value === "completed") return "complete";
175
+ if (value === "pending") return "queued";
176
+ if (isAsyncStatusSnapshotState(value)) return value;
177
+ return "partial";
178
+ }
179
+
180
+ function terminalState(state: AsyncStatusSnapshotState): boolean {
181
+ return state === "complete" || state === "failed" || state === "partial" || state === "paused" || state === "stopped" || state === "rejected";
182
+ }
183
+
184
+ function kindForMode(mode: SubagentRunMode | undefined): AsyncStatusSnapshotKind {
185
+ return mode === "workflow" ? "workflow" : "subagent";
186
+ }
187
+
188
+ function labelForAgents(agents: readonly string[] | undefined, fallback: string, maxLength: number): string {
189
+ if (!agents?.length) return publicText(fallback, fallback, maxLength);
190
+ const visible = agents.slice(0, 3).map((agent) => publicText(agent, "agent", maxLength)).join(", ");
191
+ const suffix = agents.length > 3 ? `, +${agents.length - 3} more` : "";
192
+ return truncateDisplayText(`${visible}${suffix}`, maxLength);
193
+ }
194
+
195
+ function activityFor(source: {
196
+ activityState?: unknown;
197
+ currentTool?: unknown;
198
+ lastActivityAt?: unknown;
199
+ currentToolStartedAt?: unknown;
200
+ turnCount?: unknown;
201
+ toolCount?: unknown;
202
+ }, ctx: ProjectionContext): AsyncStatusSnapshotActivityV1 | undefined {
203
+ const currentTool = publicOptionalText(source.currentTool, ctx.caps.maxStringLength);
204
+ const lastActivityAt = publicTime(source.lastActivityAt);
205
+ const currentToolStartedAt = publicTime(source.currentToolStartedAt);
206
+ const turnCount = publicCount(source.turnCount);
207
+ const toolCount = publicCount(source.toolCount);
208
+ const activity: AsyncStatusSnapshotActivityV1 = {
209
+ ...(typeof source.activityState === "string" ? { state: publicText(source.activityState, "unknown", ctx.caps.maxStringLength) } : {}),
210
+ ...(currentTool ? { currentTool } : {}),
211
+ ...(lastActivityAt !== undefined ? { lastActivityAt } : {}),
212
+ ...(currentToolStartedAt !== undefined ? { currentToolStartedAt } : {}),
213
+ ...(turnCount !== undefined ? { turnCount } : {}),
214
+ ...(toolCount !== undefined ? { toolCount } : {}),
215
+ };
216
+ return Object.keys(activity).length ? activity : undefined;
217
+ }
218
+
219
+ function appendBoundedChildren(children: AsyncStatusSnapshotNodeV1[], source: readonly AsyncStatusSnapshotNodeV1[], ctx: ProjectionContext): void {
220
+ const remaining = Math.max(0, ctx.caps.maxChildrenPerNode - children.length);
221
+ children.push(...source.slice(0, remaining));
222
+ ctx.omitted.children += Math.max(0, source.length - remaining);
223
+ }
224
+
225
+ function projectStep(step: AsyncJobStep | NestedStepSummary, index: number, depth: number, ctx: ProjectionContext): AsyncStatusSnapshotNodeV1 {
226
+ const state = normalizeState(step.status);
227
+ const startedAt = publicTime(step.startedAt);
228
+ const endedAt = publicTime(step.endedAt);
229
+ const updatedAt = endedAt ?? publicTime(step.lastActivityAt) ?? startedAt;
230
+ const activity = activityFor(step, ctx);
231
+ const node: AsyncStatusSnapshotNodeV1 = {
232
+ id: publicText("workflowKey" in step && step.workflowKey ? step.workflowKey : "runId" in step && step.runId ? step.runId : `step:${index}`, `step:${index}`, ctx.caps.maxStringLength),
233
+ kind: "step",
234
+ label: publicText("label" in step && step.label ? step.label : step.agent, "step", ctx.caps.maxStringLength),
235
+ state,
236
+ ...(startedAt !== undefined ? { startedAt } : {}),
237
+ ...(updatedAt !== undefined ? { updatedAt } : {}),
238
+ ...(terminalState(state) && endedAt !== undefined ? { endedAt } : {}),
239
+ ...(activity ? { activity } : {}),
240
+ };
241
+ if (depth < ctx.caps.maxDepth && step.children?.length) {
242
+ const nested = step.children.map((child, childIndex) => projectNestedRun(child, childIndex, depth + 1, ctx));
243
+ const bounded: AsyncStatusSnapshotNodeV1[] = [];
244
+ appendBoundedChildren(bounded, nested, ctx);
245
+ if (bounded.length) node.children = bounded;
246
+ } else if (step.children?.length) {
247
+ ctx.omitted.children += step.children.length;
248
+ }
249
+ return node;
250
+ }
251
+
252
+ function projectWorkflowGraphNode(node: WorkflowGraphSnapshot["nodes"][number], index: number, depth: number, ctx: ProjectionContext): AsyncStatusSnapshotNodeV1 {
253
+ const step: AsyncJobStep = {
254
+ agent: node.agent ?? node.label,
255
+ status: workflowGraphStepStatus(node.status),
256
+ workflowKey: node.id,
257
+ label: node.label,
258
+ };
259
+ return projectStep(step, node.flatIndex ?? index, depth, ctx);
260
+ }
261
+
262
+ function projectNestedRun(child: NestedRunSummary, index: number, depth: number, ctx: ProjectionContext): AsyncStatusSnapshotNodeV1 {
263
+ const state = normalizeState(child.state);
264
+ const startedAt = publicTime(child.startedAt);
265
+ const endedAt = publicTime(child.endedAt);
266
+ const updatedAt = publicTime(child.lastUpdate) ?? endedAt ?? publicTime(child.lastActivityAt) ?? startedAt;
267
+ const activity = activityFor(child, ctx);
268
+ const node: AsyncStatusSnapshotNodeV1 = {
269
+ id: publicText(child.id, `nested:${index}`, ctx.caps.maxStringLength),
270
+ kind: kindForMode(child.mode),
271
+ label: child.agent ? publicText(child.agent, "subagent", ctx.caps.maxStringLength) : labelForAgents(child.agents, child.mode ?? "subagent", ctx.caps.maxStringLength),
272
+ state,
273
+ ...(startedAt !== undefined ? { startedAt } : {}),
274
+ ...(updatedAt !== undefined ? { updatedAt } : {}),
275
+ ...(terminalState(state) && endedAt !== undefined ? { endedAt } : {}),
276
+ ...(activity ? { activity } : {}),
277
+ };
278
+ if (depth < ctx.caps.maxDepth) {
279
+ const nestedSteps = child.steps?.map((step, stepIndex) => projectStep(step, stepIndex, depth + 1, ctx)) ?? [];
280
+ const nestedChildren = child.children?.map((nested, childIndex) => projectNestedRun(nested, childIndex, depth + 1, ctx)) ?? [];
281
+ const bounded: AsyncStatusSnapshotNodeV1[] = [];
282
+ appendBoundedChildren(bounded, [...nestedSteps, ...nestedChildren], ctx);
283
+ if (bounded.length) node.children = bounded;
284
+ } else {
285
+ ctx.omitted.children += (child.steps?.length ?? 0) + (child.children?.length ?? 0);
286
+ }
287
+ return node;
288
+ }
289
+
290
+ function hostStepSnapshotState(state: HostStepState, verdict: HostStepVerdict | undefined): AsyncStatusSnapshotState {
291
+ if (state === "pending") return "queued";
292
+ if (state === "running") return "running";
293
+ if (state === "cancelled") return "stopped";
294
+ if (state === "error" || verdict === "fail") return "failed";
295
+ return verdict === undefined || verdict === "inconclusive" ? "partial" : "complete";
296
+ }
297
+
298
+ function projectHostStep(hostStep: HostStepNodeV1, ctx: ProjectionContext): AsyncStatusSnapshotNodeV1 {
299
+ const state = hostStepSnapshotState(hostStep.state, hostStep.verdict);
300
+ const detail = publicOptionalText(hostStep.detail, ctx.caps.maxStringLength);
301
+ const report = publicOptionalText(hostStepReportName(hostStep.reportPath), ctx.caps.maxStringLength);
302
+ const hostMetadata: AsyncStatusSnapshotHostStepV1 = {
303
+ kind: hostStep.monitorKind,
304
+ state: hostStep.state,
305
+ ...(hostStep.provider ? { provider: publicText(hostStep.provider, "provider", ctx.caps.maxStringLength) } : {}),
306
+ ...(hostStep.role ? { role: publicText(hostStep.role, "role", ctx.caps.maxStringLength) } : {}),
307
+ ...(hostStep.verdict ? { verdict: hostStep.verdict } : {}),
308
+ ...(hostStep.reasonCode ? { reasonCode: publicText(hostStep.reasonCode, "reason", ctx.caps.maxStringLength) } : {}),
309
+ ...(detail ? { detail } : {}),
310
+ ...(hostStep.target ? { target: publicText(hostStep.target, "target", ctx.caps.maxStringLength) } : {}),
311
+ ...(hostStep.freshness?.stale !== undefined ? { stale: hostStep.freshness.stale } : {}),
312
+ ...(report ? { report } : {}),
313
+ };
314
+ return {
315
+ id: publicText(hostStep.id, "host-step", ctx.caps.maxStringLength),
316
+ kind: "host-step",
317
+ label: publicText(hostStep.label, "host step", ctx.caps.maxStringLength),
318
+ state,
319
+ updatedAt: hostStep.updatedAt,
320
+ ...(terminalState(state) ? { endedAt: hostStep.updatedAt } : {}),
321
+ hostStep: hostMetadata,
322
+ };
323
+ }
324
+
325
+ function projectRun(job: AsyncJobState, ctx: ProjectionContext): AsyncStatusSnapshotNodeV1 {
326
+ const state = normalizeState(job.status);
327
+ const startedAt = publicTime(job.startedAt);
328
+ const updatedAt = publicTime(job.updatedAt) ?? startedAt;
329
+ const activity = activityFor(job, ctx);
330
+ const node: AsyncStatusSnapshotNodeV1 = {
331
+ id: publicText(job.asyncId, "async", ctx.caps.maxStringLength),
332
+ kind: kindForMode(job.mode),
333
+ label: labelForAgents(job.agents, job.mode ?? "subagent", ctx.caps.maxStringLength),
334
+ state,
335
+ ...(startedAt !== undefined ? { startedAt } : {}),
336
+ ...(updatedAt !== undefined ? { updatedAt } : {}),
337
+ ...(terminalState(state) && updatedAt !== undefined ? { endedAt: updatedAt } : {}),
338
+ ...(activity ? { activity } : {}),
339
+ };
340
+ if (ctx.caps.maxDepth > 0) {
341
+ const stepChildren = job.steps?.map((step, index) => projectStep(step, step.index ?? index, 1, ctx)) ?? [];
342
+ const loadedKeys = new Set(job.steps?.flatMap((step) => step.workflowKey ? [step.workflowKey] : []) ?? []);
343
+ const graphStages = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : [];
344
+ const graphChildren = graphStages
345
+ .filter((graphNode) => !loadedKeys.has(graphNode.id))
346
+ .map((graphNode, index) => projectWorkflowGraphNode(graphNode, index, 1, ctx));
347
+ const nestedChildren = job.nestedChildren?.map((child, index) => projectNestedRun(child, index, 1, ctx)) ?? [];
348
+ const hostStepChildren = validHostStepList(job.hostSteps).map((hostStep) => projectHostStep(hostStep, ctx));
349
+ const ordinaryChildren = [...stepChildren, ...graphChildren, ...nestedChildren];
350
+ const retainedHostSteps = hostStepChildren.slice(0, ctx.caps.maxChildrenPerNode);
351
+ const retainedOrdinaryChildren = ordinaryChildren.slice(0, ctx.caps.maxChildrenPerNode - retainedHostSteps.length);
352
+ const bounded: AsyncStatusSnapshotNodeV1[] = [];
353
+ bounded.push(...retainedOrdinaryChildren, ...retainedHostSteps);
354
+ ctx.omitted.children += ordinaryChildren.length - retainedOrdinaryChildren.length + hostStepChildren.length - retainedHostSteps.length;
355
+ if (bounded.length) node.children = bounded;
356
+ } else {
357
+ const loadedKeys = new Set(job.steps?.flatMap((step) => step.workflowKey ? [step.workflowKey] : []) ?? []);
358
+ const graphStages = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : [];
359
+ const graphCount = graphStages.filter((graphNode) => !loadedKeys.has(graphNode.id)).length;
360
+ ctx.omitted.children += (job.steps?.length ?? 0) + graphCount + (job.nestedChildren?.length ?? 0) + validHostStepList(job.hostSteps).length;
361
+ }
362
+ return node;
363
+ }
364
+
365
+ function snapshotBytes(snapshot: AsyncStatusSnapshotV1): number {
366
+ return Buffer.byteLength(JSON.stringify(snapshot), "utf8");
367
+ }
368
+
369
+ function enforceByteLimit(snapshot: AsyncStatusSnapshotV1): void {
370
+ if (snapshotBytes(snapshot) <= snapshot.caps.maxSerializedBytes) return;
371
+ snapshot.omitted.byteLimitExceeded = true;
372
+ const runs = snapshot.runs;
373
+ const initialOmittedRuns = snapshot.omitted.runs;
374
+ let lower = 0;
375
+ let upper = Math.max(0, runs.length - 1);
376
+ while (lower < upper) {
377
+ const retained = Math.ceil((lower + upper) / 2);
378
+ snapshot.runs = runs.slice(0, retained);
379
+ snapshot.omitted.runs = initialOmittedRuns + runs.length - retained;
380
+ if (snapshotBytes(snapshot) <= snapshot.caps.maxSerializedBytes) lower = retained;
381
+ else upper = retained - 1;
382
+ }
383
+ snapshot.runs = runs.slice(0, lower);
384
+ snapshot.omitted.runs = initialOmittedRuns + runs.length - lower;
385
+ }
386
+
387
+ function workflowStepActivity(step: AsyncJobStep): string | undefined {
388
+ if (step.currentTool) return `tool ${step.currentTool}`;
389
+ if (step.currentPath) return step.currentPath.split(/[\\/]/).at(-1);
390
+ if (step.activityState === "needs_attention") return "needs attention";
391
+ if (step.activityState === "active_long_running") return "long-running";
392
+ if (step.turnCount !== undefined) return `${step.turnCount} turns`;
393
+ if (step.toolCount !== undefined) return `${step.toolCount} tools`;
394
+ return undefined;
395
+ }
396
+
397
+ function workflowStepName(step: AsyncJobStep, index: number): string {
398
+ const key = step.workflowKey ?? `step ${index + 1}`;
399
+ const label = step.label && step.label !== key ? ` · ${step.label}` : "";
400
+ const phase = step.phase ? `${step.phase}: ` : "";
401
+ return `${phase}${key}${label} (${step.agent})`;
402
+ }
403
+
404
+ function hostStepRow(hostStep: HostStepNodeV1): AsyncStatusWorkflowRow {
405
+ const freshness = hostStep.freshness
406
+ ? {
407
+ expectedRef: publicText(hostStep.freshness.expectedRef, "ref", HOST_STEP_MAX_REF_CHARS),
408
+ ...(hostStep.freshness.observedRef ? { observedRef: publicText(hostStep.freshness.observedRef, "ref", HOST_STEP_MAX_REF_CHARS) } : {}),
409
+ ...(hostStep.freshness.stale !== undefined ? { stale: hostStep.freshness.stale } : {}),
410
+ }
411
+ : undefined;
412
+ return {
413
+ name: publicText(hostStep.label, "host step", HOST_STEP_MAX_LABEL_CHARS),
414
+ kind: hostStep.monitorKind,
415
+ state: hostStep.state,
416
+ ...(hostStep.role ? { role: publicText(hostStep.role, "role", HOST_STEP_MAX_ROLE_CHARS) } : {}),
417
+ ...(hostStep.provider ? { provider: publicText(hostStep.provider, "provider", HOST_STEP_MAX_PROVIDER_CHARS) } : {}),
418
+ ...(hostStep.verdict ? { verdict: hostStep.verdict } : {}),
419
+ ...(hostStep.reasonCode ? { reasonCode: publicText(hostStep.reasonCode, "reason", HOST_STEP_MAX_REASON_CHARS) } : {}),
420
+ ...(hostStep.detail ? { detail: publicText(hostStep.detail, "detail", HOST_STEP_MAX_DETAIL_CHARS) } : {}),
421
+ ...(hostStep.target ? { target: publicText(hostStep.target, "target", HOST_STEP_MAX_TARGET_CHARS) } : {}),
422
+ ...(freshness ? { freshness } : {}),
423
+ ...(hostStep.reportPath ? { reportPath: hostStepReportName(hostStep.reportPath) } : {}),
424
+ };
425
+ }
426
+
427
+
428
+ function isWorkflowPreflight(value: readonly HostStepNodeV1[] | WorkflowGraphSnapshot | WorkflowPreflightV1 | undefined): value is WorkflowPreflightV1 {
429
+ return value !== undefined && !Array.isArray(value) && "lanes" in value;
430
+ }
431
+
432
+ function isWorkflowGraph(value: readonly HostStepNodeV1[] | WorkflowGraphSnapshot | WorkflowPreflightV1 | undefined): value is WorkflowGraphSnapshot {
433
+ return value !== undefined && !Array.isArray(value) && "nodes" in value;
434
+ }
435
+
436
+ function workflowGraphRowState(status: WorkflowGraphSnapshot["nodes"][number]["status"]): AsyncStatusWorkflowRow["state"] {
437
+ switch (status) {
438
+ case "pending":
439
+ return "planned";
440
+ case "completed":
441
+ return "complete";
442
+ case "detached":
443
+ return "paused";
444
+ default:
445
+ return status;
446
+ }
447
+ }
448
+
449
+ function workflowGraphStepStatus(status: WorkflowGraphSnapshot["nodes"][number]["status"]): AsyncJobStep["status"] {
450
+ switch (status) {
451
+ case "completed":
452
+ return "complete";
453
+ case "detached":
454
+ return "paused";
455
+ default:
456
+ return status;
457
+ }
458
+ }
459
+
460
+ function workflowGraphRowName(node: WorkflowGraphSnapshot["nodes"][number]): string {
461
+ const key = publicText(node.id, "stage", HOST_STEP_MAX_LABEL_CHARS);
462
+ const label = publicOptionalText(node.label, HOST_STEP_MAX_LABEL_CHARS);
463
+ const phase = publicOptionalText(node.phase, HOST_STEP_MAX_LABEL_CHARS);
464
+ const agent = publicOptionalText(node.agent, HOST_STEP_MAX_LABEL_CHARS);
465
+ return `${phase ? `${phase}: ` : ""}${key}${label && label !== node.id ? ` · ${label}` : ""}${agent ? ` (${agent})` : ""}`;
466
+ }
467
+
468
+ function projectWorkflowGraphRow(node: WorkflowGraphSnapshot["nodes"][number], preflight?: WorkflowPreflightLaneV1): AsyncStatusWorkflowRow {
469
+ return {
470
+ name: workflowGraphRowName(node),
471
+ state: workflowGraphRowState(node.status),
472
+ ...(preflight ? { preflight } : {}),
473
+ };
474
+ }
475
+
476
+ /** Project authoritative workflow facts into compact rows, annotated by preflight hints. */
477
+ export function projectAsyncWorkflowRows(
478
+ steps: readonly AsyncJobStep[] | undefined,
479
+ hostStepsOrPreflight?: readonly HostStepNodeV1[] | WorkflowGraphSnapshot | WorkflowPreflightV1,
480
+ preflightOverride?: WorkflowPreflightV1,
481
+ ): AsyncStatusWorkflowRow[] {
482
+ const preflight = preflightOverride ?? (isWorkflowPreflight(hostStepsOrPreflight) ? hostStepsOrPreflight : undefined);
483
+ const graph = isWorkflowGraph(hostStepsOrPreflight) ? hostStepsOrPreflight : undefined;
484
+ const hostSteps = isWorkflowPreflight(hostStepsOrPreflight) || graph ? undefined : hostStepsOrPreflight;
485
+ const loaded = steps ?? [];
486
+ const preflightForKey = (key: string, groupKeys: readonly (string | undefined)[] = []): WorkflowPreflightLaneV1 | undefined =>
487
+ workflowPreflightLaneForRuntimeKey(preflight, key, groupKeys);
488
+ if (graph) {
489
+ const loadedIndexesByKey = new Map<string, number[]>();
490
+ for (const [index, step] of loaded.entries()) {
491
+ if (!step.workflowKey) continue;
492
+ const indexes = loadedIndexesByKey.get(step.workflowKey) ?? [];
493
+ indexes.push(index);
494
+ loadedIndexesByKey.set(step.workflowKey, indexes);
495
+ }
496
+ const consumed = new Set<number>();
497
+ const childRows: AsyncStatusWorkflowRow[] = [];
498
+ const graphStages = workflowGraphStageNodes(graph);
499
+ const graphKeys = new Set(graphStages.map((node) => node.id));
500
+ const graphPhaseByNodeId = new Map<string, string>();
501
+ for (const phase of graph.phases) {
502
+ for (const nodeId of phase.nodeIds) {
503
+ if (graphKeys.has(nodeId) && !graphPhaseByNodeId.has(nodeId)) graphPhaseByNodeId.set(nodeId, phase.title);
504
+ }
505
+ }
506
+ for (const node of graphStages) {
507
+ const lane = preflightForKey(node.id, [node.phase, graphPhaseByNodeId.get(node.id)]);
508
+ const indexes = (loadedIndexesByKey.get(node.id) ?? []).filter((index) => !consumed.has(index));
509
+ if (indexes.length > 0) {
510
+ for (const index of indexes) {
511
+ consumed.add(index);
512
+ childRows.push(projectLoadedWorkflowRow(loaded[index]!, index, lane));
513
+ }
514
+ } else {
515
+ childRows.push(projectWorkflowGraphRow(node, lane));
516
+ }
517
+ }
518
+ for (const [index, step] of loaded.entries()) {
519
+ if (!consumed.has(index)) childRows.push(projectLoadedWorkflowRow(step, index, step.workflowKey ? preflightForKey(step.workflowKey, [step.phase]) : undefined));
520
+ }
521
+ return [...childRows, ...validHostStepList(graph).map(hostStepRow)];
522
+ }
523
+ return [
524
+ ...loaded.map((step, index) => projectLoadedWorkflowRow(step, index, step.workflowKey ? preflightForKey(step.workflowKey, [step.phase]) : undefined)),
525
+ ...validHostStepList(hostSteps).map(hostStepRow),
526
+ ];
527
+ }
528
+
529
+ function projectLoadedWorkflowRow(step: AsyncJobStep, index: number, preflight?: WorkflowPreflightLaneV1): AsyncStatusWorkflowRow {
530
+ const modelThinking = formatModelThinking(step.model, step.thinking) || undefined;
531
+ const activity = workflowStepActivity(step);
532
+ return {
533
+ name: workflowStepName(step, index),
534
+ state: step.status,
535
+ ...(step.context ? { context: step.context } : {}),
536
+ ...(modelThinking ? { modelThinking } : {}),
537
+ ...(activity ? { activity } : {}),
538
+ ...(step.startedAt !== undefined ? { startedAt: step.startedAt } : {}),
539
+ ...(step.tokens?.total !== undefined ? { tokens: step.tokens.total } : {}),
540
+ ...(step.tokens?.window !== undefined ? { window: step.tokens.window } : {}),
541
+ ...(preflight ? { preflight } : {}),
542
+ };
543
+ }
544
+
545
+ /** Project already-loaded async status facts into the bounded public snapshot shape. */
546
+ export function projectAsyncStatusSnapshot(jobs: Iterable<AsyncJobState>, options: AsyncStatusSnapshotOptions = {}): AsyncStatusSnapshotV1 {
547
+ const caps = resolveCaps(options);
548
+ const ctx: ProjectionContext = { caps, omitted: { runs: 0, children: 0, byteLimitExceeded: false } };
549
+ const sorted = [...jobs].sort((left, right) => {
550
+ const leftUpdated = left.updatedAt ?? left.startedAt ?? 0;
551
+ const rightUpdated = right.updatedAt ?? right.startedAt ?? 0;
552
+ return rightUpdated - leftUpdated || left.asyncId.localeCompare(right.asyncId);
553
+ });
554
+ ctx.omitted.runs += Math.max(0, sorted.length - caps.maxRuns);
555
+ const snapshot: AsyncStatusSnapshotV1 = {
556
+ kind: ASYNC_STATUS_SNAPSHOT_KIND,
557
+ version: ASYNC_STATUS_SNAPSHOT_VERSION,
558
+ generatedAt: options.generatedAt ?? Date.now(),
559
+ caps,
560
+ omitted: ctx.omitted,
561
+ runs: sorted.slice(0, caps.maxRuns).map((job) => projectRun(job, ctx)),
562
+ };
563
+ enforceByteLimit(snapshot);
564
+ return snapshot;
565
+ }
@@ -0,0 +1,9 @@
1
+ export function backgroundProcessOptions(platform: NodeJS.Platform = process.platform): {
2
+ detached: boolean;
3
+ windowsHide: true;
4
+ } {
5
+ return {
6
+ detached: platform !== "win32",
7
+ windowsHide: true,
8
+ };
9
+ }
@@ -2,7 +2,6 @@ import { Buffer } from "node:buffer";
2
2
 
3
3
  export const SUBAGENT_CAPABILITY_CEILING_VERSION = 1 as const;
4
4
  export const SUBAGENT_CAPABILITY_CEILING_REGISTRY_KEY = "pi-subagents.capability-ceiling.v1";
5
- export const SUBAGENT_CAPABILITY_CEILING_ENV = "PI_SUBAGENT_CAPABILITY_CEILING_V1";
6
5
 
7
6
  export type SubagentCapabilityCeiling =
8
7
  | { allowedTools: readonly string[]; allowedAgents?: readonly string[]; denyExtensions?: boolean }
@@ -22,6 +21,7 @@ export interface SubagentCapabilityAudit {
22
21
  requestedTools?: string[];
23
22
  effectiveTools: string[];
24
23
  removedTools: string[];
24
+ excludeTools?: string[];
25
25
  internalTools: string[];
26
26
  extensionsDenied: boolean;
27
27
  removedExtensionCount: number;
@@ -166,7 +166,7 @@ export function resolveSubagentCapabilityCeiling(sessionId: string | undefined,
166
166
  }
167
167
 
168
168
  export function resolveCurrentSubagentCapabilityCeiling(sessionId: string | undefined): ResolvedSubagentCapabilityCeiling | undefined {
169
- return resolveSubagentCapabilityCeiling(sessionId, decodeSubagentCapabilityCeiling(process.env[SUBAGENT_CAPABILITY_CEILING_ENV]));
169
+ return resolveSubagentCapabilityCeiling(sessionId, undefined);
170
170
  }
171
171
 
172
172
  export function isAgentAllowedByCapabilityCeiling(agentName: string, ceiling: ResolvedSubagentCapabilityCeiling | undefined): boolean {
@@ -0,0 +1,25 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import registerFanoutChildSubagentExtension from "../../extension/fanout-child.ts";
3
+ import registerSubagentFastModeExtension from "./fast-mode-extension.ts";
4
+ import registerSubagentPromptRuntime from "./subagent-prompt-runtime.ts";
5
+ import type { ChildRuntimeConfig } from "./child-runtime-config.ts";
6
+
7
+ /** Inline extension shape accepted by pi's resource loader (`extensionFactories`). */
8
+ export interface ChildHookExtension {
9
+ name: string;
10
+ factory: (pi: ExtensionAPI) => void;
11
+ }
12
+
13
+ /**
14
+ * The child-side hooks pi-subagents installs in every child, keyed off the
15
+ * launch config. The registrations live in `subagent-prompt-runtime.ts`,
16
+ * `fast-mode-extension.ts`, and `fanout-child.ts`.
17
+ */
18
+ export function createChildHooks(config: ChildRuntimeConfig): ChildHookExtension[] {
19
+ const hooks: ChildHookExtension[] = [
20
+ { name: "pi-subagents:prompt-runtime", factory: (pi) => registerSubagentPromptRuntime(pi, config) },
21
+ ];
22
+ if (config.fast) hooks.push({ name: "pi-subagents:fast-mode", factory: (pi) => registerSubagentFastModeExtension(pi) });
23
+ if (config.fanoutChild) hooks.push({ name: "pi-subagents:fanout-child", factory: (pi) => registerFanoutChildSubagentExtension(pi, config) });
24
+ return hooks;
25
+ }