@narumitw/pi-subagents 2.0.1 → 2.0.2

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 (148) hide show
  1. package/README.md +21 -8
  2. package/dist/chunks/auto-transport-SY2VHUFH.ts +109 -0
  3. package/dist/chunks/auto-transport-SY2VHUFH.ts.map +7 -0
  4. package/dist/chunks/capability-grant-CGEWOEKE.ts +19 -0
  5. package/dist/chunks/capability-grant-CGEWOEKE.ts.map +7 -0
  6. package/dist/chunks/chunk-434NII74.ts +282 -0
  7. package/dist/chunks/chunk-434NII74.ts.map +7 -0
  8. package/dist/chunks/chunk-47SK2QYC.ts +56 -0
  9. package/dist/chunks/chunk-47SK2QYC.ts.map +7 -0
  10. package/dist/chunks/chunk-6KJ34M6S.ts +159 -0
  11. package/dist/chunks/chunk-6KJ34M6S.ts.map +7 -0
  12. package/dist/chunks/chunk-7OBINKFM.ts +80 -0
  13. package/dist/chunks/chunk-7OBINKFM.ts.map +7 -0
  14. package/dist/chunks/chunk-7QPPBBXZ.ts +335 -0
  15. package/dist/chunks/chunk-7QPPBBXZ.ts.map +7 -0
  16. package/dist/chunks/chunk-AEUYS7JC.ts +73 -0
  17. package/dist/chunks/chunk-AEUYS7JC.ts.map +7 -0
  18. package/dist/chunks/chunk-BFK2Z4ZF.ts +189 -0
  19. package/dist/chunks/chunk-BFK2Z4ZF.ts.map +7 -0
  20. package/dist/chunks/chunk-BOAXY55Y.ts +153 -0
  21. package/dist/chunks/chunk-BOAXY55Y.ts.map +7 -0
  22. package/dist/chunks/chunk-C4L6P266.ts +22 -0
  23. package/dist/chunks/chunk-C4L6P266.ts.map +7 -0
  24. package/dist/chunks/chunk-DPPVEQAM.ts +29 -0
  25. package/dist/chunks/chunk-DPPVEQAM.ts.map +7 -0
  26. package/dist/chunks/chunk-DQMN4OYM.ts +913 -0
  27. package/dist/chunks/chunk-DQMN4OYM.ts.map +7 -0
  28. package/dist/chunks/chunk-DSOOH73Y.ts +238 -0
  29. package/dist/chunks/chunk-DSOOH73Y.ts.map +7 -0
  30. package/dist/chunks/chunk-EFBPISNT.ts +421 -0
  31. package/dist/chunks/chunk-EFBPISNT.ts.map +7 -0
  32. package/dist/chunks/chunk-EWWXFU7N.ts +150 -0
  33. package/dist/chunks/chunk-EWWXFU7N.ts.map +7 -0
  34. package/dist/chunks/chunk-F4L2UVSK.ts +380 -0
  35. package/dist/chunks/chunk-F4L2UVSK.ts.map +7 -0
  36. package/dist/chunks/chunk-F5YWVHQX.ts +1543 -0
  37. package/dist/chunks/chunk-F5YWVHQX.ts.map +7 -0
  38. package/dist/chunks/chunk-G3RSMSXJ.ts +63 -0
  39. package/dist/chunks/chunk-G3RSMSXJ.ts.map +7 -0
  40. package/dist/chunks/chunk-G6VZTCFH.ts +70 -0
  41. package/dist/chunks/chunk-G6VZTCFH.ts.map +7 -0
  42. package/dist/chunks/chunk-H3FP6DLR.ts +160 -0
  43. package/dist/chunks/chunk-H3FP6DLR.ts.map +7 -0
  44. package/dist/chunks/chunk-HA36LPCO.ts +130 -0
  45. package/dist/chunks/chunk-HA36LPCO.ts.map +7 -0
  46. package/dist/chunks/chunk-HKC4ES4B.ts +65 -0
  47. package/dist/chunks/chunk-HKC4ES4B.ts.map +7 -0
  48. package/dist/chunks/chunk-HOP5FXDT.ts +27 -0
  49. package/dist/chunks/chunk-HOP5FXDT.ts.map +7 -0
  50. package/dist/chunks/chunk-I2FAK44T.ts +324 -0
  51. package/dist/chunks/chunk-I2FAK44T.ts.map +7 -0
  52. package/dist/chunks/chunk-IGAMVWFN.ts +139 -0
  53. package/dist/chunks/chunk-IGAMVWFN.ts.map +7 -0
  54. package/dist/chunks/chunk-KMGKCEO4.ts +38 -0
  55. package/dist/chunks/chunk-KMGKCEO4.ts.map +7 -0
  56. package/dist/chunks/chunk-N7BLVXKK.ts +73 -0
  57. package/dist/chunks/chunk-N7BLVXKK.ts.map +7 -0
  58. package/dist/chunks/chunk-NIF42QMF.ts +297 -0
  59. package/dist/chunks/chunk-NIF42QMF.ts.map +7 -0
  60. package/dist/chunks/chunk-O4VO6JUJ.ts +52 -0
  61. package/dist/chunks/chunk-O4VO6JUJ.ts.map +7 -0
  62. package/dist/chunks/chunk-ONDTY4EL.ts +91 -0
  63. package/dist/chunks/chunk-ONDTY4EL.ts.map +7 -0
  64. package/dist/chunks/chunk-OVPHFGKO.ts +1769 -0
  65. package/dist/chunks/chunk-OVPHFGKO.ts.map +7 -0
  66. package/dist/chunks/chunk-P7OH4XMF.ts +60 -0
  67. package/dist/chunks/chunk-P7OH4XMF.ts.map +7 -0
  68. package/dist/chunks/chunk-PSK43Y6A.ts +339 -0
  69. package/dist/chunks/chunk-PSK43Y6A.ts.map +7 -0
  70. package/dist/chunks/chunk-QBORTI4W.ts +468 -0
  71. package/dist/chunks/chunk-QBORTI4W.ts.map +7 -0
  72. package/dist/chunks/chunk-QDVGH2X7.ts +171 -0
  73. package/dist/chunks/chunk-QDVGH2X7.ts.map +7 -0
  74. package/dist/chunks/chunk-RHRQMT7Q.ts +490 -0
  75. package/dist/chunks/chunk-RHRQMT7Q.ts.map +7 -0
  76. package/dist/chunks/chunk-RRR66UWR.ts +28 -0
  77. package/dist/chunks/chunk-RRR66UWR.ts.map +7 -0
  78. package/dist/chunks/chunk-RSUXZD6S.ts +275 -0
  79. package/dist/chunks/chunk-RSUXZD6S.ts.map +7 -0
  80. package/dist/chunks/chunk-RTCVYIZA.ts +221 -0
  81. package/dist/chunks/chunk-RTCVYIZA.ts.map +7 -0
  82. package/dist/chunks/chunk-S2IWVK3J.ts +44 -0
  83. package/dist/chunks/chunk-S2IWVK3J.ts.map +7 -0
  84. package/dist/chunks/chunk-SCZ33MYW.ts +52 -0
  85. package/dist/chunks/chunk-SCZ33MYW.ts.map +7 -0
  86. package/dist/chunks/chunk-SWGQLFSD.ts +60 -0
  87. package/dist/chunks/chunk-SWGQLFSD.ts.map +7 -0
  88. package/dist/chunks/chunk-UMBPMVJW.ts +22 -0
  89. package/dist/chunks/chunk-UMBPMVJW.ts.map +7 -0
  90. package/dist/chunks/chunk-UVFVHIOP.ts +735 -0
  91. package/dist/chunks/chunk-UVFVHIOP.ts.map +7 -0
  92. package/dist/chunks/completion-delivery-YPOWSSV3.ts +16 -0
  93. package/dist/chunks/completion-delivery-YPOWSSV3.ts.map +7 -0
  94. package/dist/chunks/config-status-J4GPWP46.ts +34 -0
  95. package/dist/chunks/config-status-J4GPWP46.ts.map +7 -0
  96. package/dist/chunks/config-ui-3IBMHTQB.ts +1146 -0
  97. package/dist/chunks/config-ui-3IBMHTQB.ts.map +7 -0
  98. package/dist/chunks/consult-NYXVDN5G.ts +518 -0
  99. package/dist/chunks/consult-NYXVDN5G.ts.map +7 -0
  100. package/dist/chunks/context-QDKLVQXE.ts +11 -0
  101. package/dist/chunks/context-QDKLVQXE.ts.map +7 -0
  102. package/dist/chunks/create-stateful-transport-4WKZHRSI.ts +130 -0
  103. package/dist/chunks/create-stateful-transport-4WKZHRSI.ts.map +7 -0
  104. package/dist/chunks/cwd-policy-NB6XZ5GF.ts +17 -0
  105. package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +7 -0
  106. package/dist/chunks/delegation-contract-WJPT4FVS.ts +24 -0
  107. package/dist/chunks/delegation-contract-WJPT4FVS.ts.map +7 -0
  108. package/dist/chunks/discovery-K25T3SH4.ts +12 -0
  109. package/dist/chunks/discovery-K25T3SH4.ts.map +7 -0
  110. package/dist/chunks/execution-DS2DEIQZ.ts +4034 -0
  111. package/dist/chunks/execution-DS2DEIQZ.ts.map +7 -0
  112. package/dist/chunks/in-process-transport-TEYAWSEC.ts +38 -0
  113. package/dist/chunks/in-process-transport-TEYAWSEC.ts.map +7 -0
  114. package/dist/chunks/inspect-UOQQ3KNL.ts +619 -0
  115. package/dist/chunks/inspect-UOQQ3KNL.ts.map +7 -0
  116. package/dist/chunks/peer-communication-KL36Z6CO.ts +294 -0
  117. package/dist/chunks/peer-communication-KL36Z6CO.ts.map +7 -0
  118. package/dist/chunks/persistence-VSGXAW4P.ts +344 -0
  119. package/dist/chunks/persistence-VSGXAW4P.ts.map +7 -0
  120. package/dist/chunks/registry-E6XPJB7L.ts +1324 -0
  121. package/dist/chunks/registry-E6XPJB7L.ts.map +7 -0
  122. package/dist/chunks/retained-semantic-state-7WXSGRJU.ts +81 -0
  123. package/dist/chunks/retained-semantic-state-7WXSGRJU.ts.map +7 -0
  124. package/dist/chunks/rpc-transport-Y6LA5BOP.ts +1154 -0
  125. package/dist/chunks/rpc-transport-Y6LA5BOP.ts.map +7 -0
  126. package/dist/chunks/runtime-policy-5YELCOVC.ts +15 -0
  127. package/dist/chunks/runtime-policy-5YELCOVC.ts.map +7 -0
  128. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +19 -0
  129. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +7 -0
  130. package/dist/chunks/spawn-idempotency-QGHO2WKC.ts +13 -0
  131. package/dist/chunks/spawn-idempotency-QGHO2WKC.ts.map +7 -0
  132. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +15 -0
  133. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +7 -0
  134. package/dist/chunks/subprocess-transport-C2XVR25R.ts +158 -0
  135. package/dist/chunks/subprocess-transport-C2XVR25R.ts.map +7 -0
  136. package/dist/chunks/workspace-WDKLN72J.ts +11 -0
  137. package/dist/chunks/workspace-WDKLN72J.ts.map +7 -0
  138. package/dist/index.ts +1057 -0
  139. package/dist/index.ts.map +7 -0
  140. package/package.json +7 -3
  141. package/src/index.ts +1 -1
  142. package/src/settings-reader.ts +208 -0
  143. package/src/settings.ts +22 -187
  144. package/src/stateful-registration.ts +1230 -0
  145. package/src/stateful-safety.ts +1 -1
  146. package/src/stateful.ts +2 -1234
  147. package/src/subagents-extension.ts +307 -0
  148. package/src/subagents.ts +1 -308
@@ -0,0 +1,38 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ InProcessTransport,
5
+ buildCurrentTurnPrompt,
6
+ copyRegisteredProviders,
7
+ createInProcessServices,
8
+ createSdkChildSession,
9
+ resolveChildModel,
10
+ seedChildSessionManager,
11
+ validateInProcessTools
12
+ } from "./chunk-UVFVHIOP.js";
13
+ import "./chunk-EWWXFU7N.js";
14
+ import "./chunk-G6VZTCFH.js";
15
+ import "./chunk-G3RSMSXJ.js";
16
+ import "./chunk-RTCVYIZA.js";
17
+ import "./chunk-ONDTY4EL.js";
18
+ import "./chunk-PSK43Y6A.js";
19
+ import "./chunk-RSUXZD6S.js";
20
+ import "./chunk-7QPPBBXZ.js";
21
+ import "./chunk-QBORTI4W.js";
22
+ import "./chunk-7OBINKFM.js";
23
+ import "./chunk-DPPVEQAM.js";
24
+ import "./chunk-SWGQLFSD.js";
25
+ import "./chunk-I2FAK44T.js";
26
+ import "./chunk-H3FP6DLR.js";
27
+ import "./chunk-RRR66UWR.js";
28
+ export {
29
+ InProcessTransport,
30
+ buildCurrentTurnPrompt,
31
+ copyRegisteredProviders,
32
+ createInProcessServices,
33
+ createSdkChildSession,
34
+ resolveChildModel,
35
+ seedChildSessionManager,
36
+ validateInProcessTools
37
+ };
38
+ //# sourceMappingURL=in-process-transport-TEYAWSEC.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,619 @@
1
+ // @generated by scripts/build-runtime.mjs; do not edit.
2
+ // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
3
+ import {
4
+ inspectSessionWorkflows
5
+ } from "./chunk-OVPHFGKO.js";
6
+ import {
7
+ resolveConsultTools
8
+ } from "./chunk-UMBPMVJW.js";
9
+ import {
10
+ resolvePiInvocation
11
+ } from "./chunk-IGAMVWFN.js";
12
+ import {
13
+ INSPECT_ACTIONS,
14
+ SubagentInspectParams,
15
+ registerSubagentInspect
16
+ } from "./chunk-F4L2UVSK.js";
17
+ import "./chunk-HOP5FXDT.js";
18
+ import {
19
+ discoverAgents,
20
+ projectCapabilityManifest
21
+ } from "./chunk-PSK43Y6A.js";
22
+ import "./chunk-RSUXZD6S.js";
23
+ import "./chunk-7QPPBBXZ.js";
24
+ import {
25
+ inspectBlockingParallelLimitSettings,
26
+ inspectCompletionDeliverySettings,
27
+ inspectConsultResourceSettings,
28
+ inspectCwdPolicySettings,
29
+ inspectDelegationWorkflowSettings,
30
+ inspectStatefulLimitSettings,
31
+ inspectStatefulTransportSettings,
32
+ inspectSubagentSettings,
33
+ resolveDelegationWorkflow
34
+ } from "./chunk-QBORTI4W.js";
35
+ import "./chunk-7OBINKFM.js";
36
+ import "./chunk-DPPVEQAM.js";
37
+ import "./chunk-BFK2Z4ZF.js";
38
+ import {
39
+ boundText,
40
+ boundedPrivateText,
41
+ safeDisplayPath,
42
+ safeTerminalLine
43
+ } from "./chunk-SWGQLFSD.js";
44
+ import {
45
+ DEFAULT_MAX_CONTEXT_BYTES,
46
+ buildContextSnapshot
47
+ } from "./chunk-H3FP6DLR.js";
48
+
49
+ // src/inspect.ts
50
+ import * as path from "node:path";
51
+ import { CONFIG_DIR_NAME } from "@earendil-works/pi-coding-agent";
52
+ var MAX_DETAILS_LIST_BYTES = 40 * 1024;
53
+ function validateInspectParams(params) {
54
+ const values = parameterRecord(params);
55
+ const rawAction = values.action;
56
+ if (typeof rawAction !== "string" || !INSPECT_ACTIONS.includes(rawAction)) {
57
+ throw new Error(`subagent_inspect action must be one of: ${INSPECT_ACTIONS.join(", ")}`);
58
+ }
59
+ const action = rawAction;
60
+ const allowed = {
61
+ list_agents: ["action", "agentScope", "limit"],
62
+ get_agent: ["action", "agent", "agentScope"],
63
+ list_runs: ["action", "includeClosed", "limit"],
64
+ get_run: ["action", "agentId"],
65
+ list_workflows: ["action", "limit"],
66
+ get_workflow: ["action", "workflowId"],
67
+ list_models: ["action", "limit"],
68
+ preview_context: ["action", "context", "contextEntryIds"],
69
+ status: ["action"],
70
+ diagnose: ["action"]
71
+ };
72
+ const unexpected = Object.keys(values).find(
73
+ (key) => values[key] !== void 0 && !allowed[action].includes(key)
74
+ );
75
+ if (unexpected)
76
+ throw new Error(`subagent_inspect action "${action}" does not accept ${unexpected}`);
77
+ if (action === "list_agents" || action === "get_agent") {
78
+ const agentScope = optionalAgentScope(values.agentScope);
79
+ if (action === "get_agent") {
80
+ return { action, agent: requiredString(values.agent, action, "agent"), agentScope };
81
+ }
82
+ return { action, agentScope, limit: optionalLimit(values.limit, 32) };
83
+ }
84
+ if (action === "list_runs") {
85
+ if (values.includeClosed !== void 0 && typeof values.includeClosed !== "boolean") {
86
+ throw new Error('subagent_inspect action "list_runs" requires includeClosed to be boolean');
87
+ }
88
+ return {
89
+ action,
90
+ includeClosed: values.includeClosed === true,
91
+ limit: optionalLimit(values.limit, 50)
92
+ };
93
+ }
94
+ if (action === "get_run") {
95
+ return { action, agentId: requiredString(values.agentId, action, "agentId") };
96
+ }
97
+ if (action === "list_workflows") {
98
+ return { action, limit: optionalLimit(values.limit, 50) };
99
+ }
100
+ if (action === "get_workflow") {
101
+ return { action, workflowId: requiredString(values.workflowId, action, "workflowId") };
102
+ }
103
+ if (action === "list_models") {
104
+ return { action, limit: optionalLimit(values.limit, 50) };
105
+ }
106
+ if (action === "preview_context") {
107
+ const context = optionalContextMode(values.context);
108
+ const contextEntryIds = optionalStringArray(values.contextEntryIds, "contextEntryIds");
109
+ return {
110
+ action,
111
+ context: values.context === void 0 && contextEntryIds ? "all" : context,
112
+ ...contextEntryIds ? { contextEntryIds } : {}
113
+ };
114
+ }
115
+ return { action };
116
+ }
117
+ async function executeSubagentInspect(params, ctx, runtime) {
118
+ const operation = validateInspectParams(params);
119
+ if (operation.action === "list_agents" || operation.action === "get_agent") {
120
+ assertTrustedScope(operation.agentScope, ctx);
121
+ const settings2 = inspectSubagentSettings().settings;
122
+ const discovery = discoverAgents(ctx.cwd, operation.agentScope, settings2);
123
+ const agents = [...discovery.agents].sort(
124
+ (left, right) => left.name === right.name ? left.source.localeCompare(right.source) : left.name.localeCompare(right.name)
125
+ );
126
+ if (operation.action === "list_agents") {
127
+ const selected = boundedProjection(
128
+ agents,
129
+ operation.limit,
130
+ (agent2) => projectAgent(agent2, ctx, false)
131
+ );
132
+ return inspectResult({
133
+ action: operation.action,
134
+ agents: selected.items,
135
+ returned: selected.items.length,
136
+ omitted: selected.omitted + (discovery.omittedAgentDefinitions ?? 0),
137
+ discoveryIncomplete: discovery.metadataDiscoveryIncomplete === true
138
+ });
139
+ }
140
+ const agent = agents.find((candidate) => candidate.name === operation.agent);
141
+ if (!agent) {
142
+ throw new Error(`Unknown subagent definition: ${boundedPrivateText(operation.agent, 256)}`);
143
+ }
144
+ return inspectResult({ action: operation.action, agent: projectAgent(agent, ctx) });
145
+ }
146
+ if (operation.action === "list_runs") {
147
+ const runs = runtime.listRunInspection(operation.includeClosed);
148
+ const selected = boundedProjection(runs, operation.limit, projectRunSummary);
149
+ return inspectResult({
150
+ action: operation.action,
151
+ runs: selected.items,
152
+ returned: selected.items.length,
153
+ omitted: selected.omitted
154
+ });
155
+ }
156
+ if (operation.action === "get_run") {
157
+ const run = runtime.getRunInspection(operation.agentId);
158
+ if (!run) {
159
+ throw new Error(`Unknown retained run: ${boundedPrivateText(operation.agentId, 256)}`);
160
+ }
161
+ return inspectResult({ action: operation.action, run: projectRun(run, ctx) });
162
+ }
163
+ if (operation.action === "list_workflows" || operation.action === "get_workflow") {
164
+ const owner = ctx.sessionManager.getSessionId?.() ?? ctx.sessionManager.getSessionFile?.() ?? `ephemeral:${ctx.cwd}`;
165
+ const inspected = inspectSessionWorkflows(owner, {
166
+ maxStoredWorkflows: operation.action === "list_workflows" ? operation.limit : 64
167
+ });
168
+ if (operation.action === "list_workflows") {
169
+ const selected = boundedProjection(
170
+ inspected.workflows,
171
+ operation.limit,
172
+ projectWorkflowSummary
173
+ );
174
+ return inspectResult({
175
+ action: operation.action,
176
+ workflows: selected.items,
177
+ returned: selected.items.length,
178
+ omitted: inspected.omitted + selected.omitted,
179
+ invalid: inspected.invalid
180
+ });
181
+ }
182
+ const workflow = inspected.workflows.find(
183
+ (candidate) => candidate.workflowId === operation.workflowId
184
+ );
185
+ if (!workflow) {
186
+ throw new Error(
187
+ `Unknown persisted workflow: ${boundedPrivateText(operation.workflowId, 256)}`
188
+ );
189
+ }
190
+ return inspectResult({ action: operation.action, workflow: projectWorkflow(workflow) });
191
+ }
192
+ if (operation.action === "list_models") {
193
+ return inspectResult({ action: operation.action, ...projectModels(ctx, operation.limit) });
194
+ }
195
+ if (operation.action === "preview_context") {
196
+ const snapshot = buildContextSnapshot(
197
+ ctx.sessionManager.getBranch(),
198
+ operation.context,
199
+ DEFAULT_MAX_CONTEXT_BYTES,
200
+ operation.contextEntryIds
201
+ );
202
+ return inspectResult({
203
+ action: operation.action,
204
+ preview: {
205
+ mode: operation.context,
206
+ turns: snapshot.turns,
207
+ sourceCount: snapshot.sourceIds.length,
208
+ bytes: Buffer.byteLength(snapshot.text, "utf8"),
209
+ truncated: snapshot.truncated
210
+ }
211
+ });
212
+ }
213
+ if (operation.action === "status") {
214
+ return inspectResult({ action: operation.action, status: projectStatus(runtime) });
215
+ }
216
+ const settings = inspectSubagentSettings();
217
+ const userDiscovery = discoverAgents(ctx.cwd, "user", settings.settings);
218
+ const modelCount = availableModelCount(ctx);
219
+ const runtimeStatus = runtime.getRuntimeStatus();
220
+ const rpcCapability = inspectRpcCapability();
221
+ const inProcessCapability = await inspectInProcessCapability();
222
+ const checks = [
223
+ {
224
+ name: "settings",
225
+ status: settings.error ? "fail" : "pass",
226
+ message: settings.error ? boundedPrivateText(settings.error, 2 * 1024) : "Settings are valid or absent."
227
+ },
228
+ {
229
+ name: "agent-discovery",
230
+ status: userDiscovery.metadataDiscoveryIncomplete || (userDiscovery.omittedAgentDefinitions ?? 0) > 0 ? "warning" : "pass",
231
+ message: `${userDiscovery.agents.length} user-scope definitions available.`
232
+ },
233
+ {
234
+ name: "models",
235
+ status: modelCount > 0 ? "pass" : "fail",
236
+ message: `${modelCount} session-usable models available.`
237
+ },
238
+ {
239
+ name: "runtime",
240
+ status: runtimeStatus.enabled && !runtimeStatus.initialized ? "warning" : "pass",
241
+ message: runtimeStatus.initialized ? "Stateful runtime initialized." : "Stateful runtime not initialized."
242
+ },
243
+ {
244
+ name: "in-process-sdk",
245
+ status: inProcessCapability.error ? "fail" : "pass",
246
+ message: inProcessCapability.error ? boundedPrivateText(inProcessCapability.error, 2 * 1024) : "Required public Pi in-process session APIs are available."
247
+ },
248
+ {
249
+ name: "rpc-cli",
250
+ status: rpcCapability.error ? "fail" : "pass",
251
+ message: rpcCapability.error ? boundedPrivateText(rpcCapability.error, 2 * 1024) : "The exact loaded Pi CLI is available for persistent RPC transport."
252
+ },
253
+ {
254
+ name: "consultation",
255
+ status: runtime.getBlockingEnabled() && modelCount > 0 ? "pass" : "fail",
256
+ message: runtime.getBlockingEnabled() ? modelCount > 0 ? "Read-only consultation is supported." : "Consultation has no available model." : "Blocking delegation is disabled, so consultation is not registered."
257
+ }
258
+ ];
259
+ return inspectResult({
260
+ action: operation.action,
261
+ checks,
262
+ ok: checks.every((check) => check.status !== "fail")
263
+ });
264
+ }
265
+ function projectAgent(agent, ctx, includeTools = true) {
266
+ const tools = agent.tools === void 0 ? void 0 : projectToolNames(agent.tools);
267
+ return {
268
+ name: boundedPrivateText(agent.name, 256),
269
+ description: boundedPrivateText(agent.description, 256),
270
+ source: agent.source,
271
+ scope: agent.source === "project" ? "project" : "user",
272
+ path: agent.source === "project" ? safeTerminalLine(
273
+ path.posix.join(CONFIG_DIR_NAME, "agents", path.basename(agent.filePath))
274
+ ) : safeDisplayPath(agent.filePath, ctx.cwd),
275
+ model: agent.model ? boundedPrivateText(agent.model, 256) : void 0,
276
+ thinkingLevel: agent.thinkingLevel,
277
+ capabilityManifest: projectCapabilityManifest(agent.capabilityManifest),
278
+ ...includeTools ? { tools, toolCount: agent.tools?.length } : { toolCount: agent.tools?.length },
279
+ consultTools: resolveConsultTools(agent.tools)
280
+ };
281
+ }
282
+ function projectRunSummary(run) {
283
+ return {
284
+ id: boundedPrivateText(run.id, 256),
285
+ agent: boundedPrivateText(run.agent, 256),
286
+ state: run.state,
287
+ createdAt: run.createdAt,
288
+ updatedAt: run.updatedAt,
289
+ historyCount: run.historyCount,
290
+ unreadMessages: run.unreadMessages,
291
+ turnGeneration: run.turnGeneration,
292
+ pendingCompletionCount: run.pendingCompletionCount
293
+ };
294
+ }
295
+ function projectRun(run, ctx) {
296
+ return {
297
+ ...projectRunSummary(run),
298
+ cwd: safeDisplayPath(run.cwd, ctx.cwd),
299
+ workspaceMode: run.workspaceMode ?? "shared",
300
+ thinkingLevel: run.thinkingLevel,
301
+ timeoutMs: run.timeoutMs,
302
+ currentTimeoutMs: run.currentTimeoutMs,
303
+ idleTimeoutMs: run.idleTimeoutMs,
304
+ currentIdleTimeoutMs: run.currentIdleTimeoutMs,
305
+ maxTurns: run.maxTurns,
306
+ currentMaxTurns: run.currentMaxTurns,
307
+ maxToolCalls: run.maxToolCalls,
308
+ currentMaxToolCalls: run.currentMaxToolCalls,
309
+ context: {
310
+ turns: run.contextTurns ?? 0,
311
+ sources: run.contextSources ?? 0,
312
+ bytes: run.contextBytes ?? 0,
313
+ truncated: run.contextTruncated === true
314
+ },
315
+ contract: run.contract ? {
316
+ version: run.contract.version,
317
+ level: run.contract.level,
318
+ taskId: boundedPrivateText(run.contract.taskId, 256),
319
+ enforcement: run.contract.enforcement,
320
+ dependencies: run.contract.dependencies.length,
321
+ acceptanceCriteria: run.contract.acceptanceCriteria.length,
322
+ requiredEvidence: run.contract.requiredEvidence.length
323
+ } : void 0,
324
+ resultFormat: run.resultFormat ?? "text",
325
+ structuredResult: run.structuredResult,
326
+ termination: run.termination,
327
+ outcome: run.outcome,
328
+ capabilityGrant: run.capabilityGrant ? {
329
+ version: run.capabilityGrant.version,
330
+ id: run.capabilityGrant.id,
331
+ executionPlanId: run.capabilityGrant.executionPlanId,
332
+ taskGeneration: run.capabilityGrant.taskGeneration,
333
+ issuedAt: run.capabilityGrant.issuedAt,
334
+ expiresAt: run.capabilityGrant.expiresAt,
335
+ state: run.capabilityGrant.state,
336
+ revokedAt: run.capabilityGrant.revokedAt,
337
+ revocationReason: run.capabilityGrant.revocationReason
338
+ } : void 0,
339
+ executionPlan: run.executionPlan ? {
340
+ ...run.executionPlan,
341
+ target: {
342
+ ...run.executionPlan.target,
343
+ cwd: safeDisplayPath(run.executionPlan.target.cwd, ctx.cwd),
344
+ trust: { ...run.executionPlan.target.trust, sourcePath: void 0 }
345
+ }
346
+ } : void 0,
347
+ semanticSnapshot: run.semanticSnapshot ? {
348
+ version: run.semanticSnapshot.version,
349
+ digest: run.semanticSnapshot.digest,
350
+ components: { ...run.semanticSnapshot.components }
351
+ } : void 0,
352
+ semanticCompatibility: run.semanticCompatibility,
353
+ telemetry: run.telemetry,
354
+ currentRunId: run.currentRunId,
355
+ currentTurnGeneration: run.currentTurnGeneration,
356
+ currentTask: run.currentTask ? boundedPrivateText(run.currentTask, 2 * 1024) : void 0,
357
+ error: run.error ? boundedPrivateText(run.error, 2 * 1024) : void 0,
358
+ target: run.target ? {
359
+ cwd: safeDisplayPath(run.target.cwd, ctx.cwd),
360
+ boundary: run.target.boundary,
361
+ trust: {
362
+ kind: run.target.trust.kind,
363
+ projectTrusted: run.target.trust.projectTrusted,
364
+ sourcePath: run.target.trust.sourcePath ? safeDisplayPath(run.target.trust.sourcePath, ctx.cwd) : void 0,
365
+ warning: run.target.trust.warning ? boundedPrivateText(run.target.trust.warning, 512) : void 0
366
+ }
367
+ } : void 0,
368
+ policy: run.policy ? {
369
+ inherited: projectToolNames(run.policy.inherited),
370
+ overridden: projectToolNames(run.policy.overridden),
371
+ unsupported: projectToolNames(run.policy.unsupported)
372
+ } : void 0
373
+ };
374
+ }
375
+ function projectWorkflowSummary(workflow) {
376
+ return {
377
+ workflowId: boundedPrivateText(workflow.workflowId, 256),
378
+ generation: workflow.generation,
379
+ itemCount: workflow.items.length,
380
+ states: Object.fromEntries(
381
+ [...new Set(workflow.items.map((item) => item.state))].sort().map((state) => [state, workflow.items.filter((item) => item.state === state).length])
382
+ )
383
+ };
384
+ }
385
+ function projectWorkflow(workflow) {
386
+ const projected = boundedProjection(workflow.items, 64, (item) => ({
387
+ id: boundedPrivateText(item.id, 256),
388
+ state: item.state,
389
+ generation: item.generation,
390
+ taskGeneration: item.taskGeneration,
391
+ dependencies: item.dependencies.map((value) => boundedPrivateText(value, 256)),
392
+ assignedAgentId: item.assignedAgentId ? boundedPrivateText(item.assignedAgentId, 256) : void 0,
393
+ acceptedExecutionPlanId: item.acceptedExecutionPlanId,
394
+ artifacts: item.artifacts.map((artifact) => ({
395
+ id: boundedPrivateText(artifact.id, 256),
396
+ kind: boundedPrivateText(artifact.kind, 256),
397
+ version: boundedPrivateText(artifact.version, 256),
398
+ producerTaskId: artifact.producerTaskId ? boundedPrivateText(artifact.producerTaskId, 256) : void 0,
399
+ generation: artifact.generation,
400
+ verified: artifact.verified
401
+ })),
402
+ verificationAccepted: item.verificationAccepted,
403
+ acceptanceStateVersion: item.acceptanceStateVersion,
404
+ acceptanceRequired: item.acceptanceRequired,
405
+ acceptanceState: item.acceptanceState,
406
+ reworkCount: item.reworkCount,
407
+ maxReworkCycles: item.maxReworkCycles,
408
+ acceptanceReceipt: item.acceptanceReceipt ? {
409
+ version: item.acceptanceReceipt.version,
410
+ decision: item.acceptanceReceipt.decision,
411
+ targetTaskId: boundedPrivateText(item.acceptanceReceipt.targetTaskId, 256),
412
+ targetTaskGeneration: item.acceptanceReceipt.targetTaskGeneration,
413
+ targetExecutionPlanId: item.acceptanceReceipt.targetExecutionPlanId,
414
+ verifierTaskId: boundedPrivateText(item.acceptanceReceipt.verifierTaskId, 256),
415
+ verifierTaskGeneration: item.acceptanceReceipt.verifierTaskGeneration,
416
+ verifierExecutionPlanId: item.acceptanceReceipt.verifierExecutionPlanId,
417
+ verifierAgent: boundedPrivateText(item.acceptanceReceipt.verifierAgent, 256),
418
+ beforeTreeIdentity: item.acceptanceReceipt.beforeTreeIdentity,
419
+ afterTreeIdentity: item.acceptanceReceipt.afterTreeIdentity,
420
+ patchDigest: item.acceptanceReceipt.patchDigest,
421
+ changedPathCount: item.acceptanceReceipt.changedPaths.length,
422
+ checkCount: item.acceptanceReceipt.checks.length,
423
+ requiredEvidenceCount: item.acceptanceReceipt.requiredEvidenceIds.length,
424
+ createdAt: item.acceptanceReceipt.createdAt,
425
+ sourceTruncated: item.acceptanceReceipt.sourceTruncated
426
+ } : void 0,
427
+ acceptanceReceiptHistoryCount: item.acceptanceReceiptHistory.length,
428
+ stagedTreeIdentity: item.stagedTreeIdentity ? {
429
+ version: item.stagedTreeIdentity.version,
430
+ kind: item.stagedTreeIdentity.kind,
431
+ digest: item.stagedTreeIdentity.digest
432
+ } : void 0,
433
+ verificationReceipt: item.verificationReceipt ? {
434
+ version: item.verificationReceipt.version,
435
+ decision: item.verificationReceipt.decision,
436
+ targetTaskId: boundedPrivateText(item.verificationReceipt.targetTaskId, 256),
437
+ targetTaskGeneration: item.verificationReceipt.targetTaskGeneration,
438
+ targetExecutionPlanId: item.verificationReceipt.targetExecutionPlanId,
439
+ verifierTaskId: boundedPrivateText(item.verificationReceipt.verifierTaskId, 256),
440
+ verifierTaskGeneration: item.verificationReceipt.verifierTaskGeneration,
441
+ verifierExecutionPlanId: item.verificationReceipt.verifierExecutionPlanId,
442
+ treeIdentity: item.verificationReceipt.treeIdentity,
443
+ summary: boundedPrivateText(item.verificationReceipt.summary, 8 * 1024),
444
+ evidenceCount: item.verificationReceipt.evidence.length,
445
+ limitationCount: item.verificationReceipt.limitations.length,
446
+ createdAt: item.verificationReceipt.createdAt,
447
+ truncated: item.verificationReceipt.truncated
448
+ } : void 0,
449
+ outcomeReason: item.outcomeReason ? boundedPrivateText(item.outcomeReason, 2 * 1024) : void 0
450
+ }));
451
+ return {
452
+ ...projectWorkflowSummary(workflow),
453
+ items: projected.items,
454
+ omittedItems: projected.omitted
455
+ };
456
+ }
457
+ function projectModels(ctx, limit) {
458
+ const scoped = ctx.scopedModels ?? [];
459
+ const candidates = scoped.length > 0 ? scoped : ctx.modelRegistry.getAvailable().map((model) => ({ model, thinkingLevel: void 0 }));
460
+ const selected = boundedProjection(candidates, limit, ({ model, thinkingLevel }) => ({
461
+ provider: boundedPrivateText(model.provider, 256),
462
+ id: boundedPrivateText(model.id, 256),
463
+ name: boundedPrivateText(model.name, 256),
464
+ reasoning: model.reasoning,
465
+ input: [...model.input],
466
+ contextWindow: model.contextWindow,
467
+ maxTokens: model.maxTokens,
468
+ thinkingLevel,
469
+ current: ctx.model?.provider === model.provider && ctx.model?.id === model.id
470
+ }));
471
+ return {
472
+ models: selected.items,
473
+ returned: selected.items.length,
474
+ omitted: selected.omitted,
475
+ source: scoped.length > 0 ? "session scope" : "available snapshot"
476
+ };
477
+ }
478
+ function projectStatus(runtime) {
479
+ const stateful = runtime.getRuntimeStatus();
480
+ const workflow = resolveDelegationWorkflow(runtime.getBlockingEnabled(), stateful.enabled);
481
+ const configured = inspectDelegationWorkflowSettings();
482
+ const resources = inspectConsultResourceSettings();
483
+ const cwdPolicy = inspectCwdPolicySettings();
484
+ const completion = inspectCompletionDeliverySettings();
485
+ const parallelLimit = inspectBlockingParallelLimitSettings();
486
+ const detachedLimits = inspectStatefulLimitSettings();
487
+ const transport = inspectStatefulTransportSettings();
488
+ const configuredDetachedLimits = detachedLimits.values ? Object.fromEntries(
489
+ Object.entries(detachedLimits.values).map(([field, snapshot]) => [field, snapshot.value])
490
+ ) : void 0;
491
+ const configuredDetachedLimitSources = detachedLimits.values ? Object.fromEntries(
492
+ Object.entries(detachedLimits.values).map(([field, snapshot]) => [field, snapshot.source])
493
+ ) : void 0;
494
+ return {
495
+ workflow,
496
+ configuredWorkflow: configured.value,
497
+ configuredWorkflowSource: configured.source,
498
+ stateful,
499
+ statefulLimits: stateful.limits,
500
+ configuredTransport: transport.value,
501
+ configuredTransportSource: transport.source,
502
+ configuredStatefulLimits: configuredDetachedLimits,
503
+ configuredStatefulLimitSources: configuredDetachedLimitSources,
504
+ configuredCompletionDelivery: completion.value,
505
+ configuredCompletionDeliverySource: completion.source,
506
+ maxParallelTasks: runtime.getMaxParallelTasks(),
507
+ configuredMaxParallelTasks: parallelLimit.value,
508
+ configuredMaxParallelTasksSource: parallelLimit.source,
509
+ consultResources: runtime.getConsultResourcePolicy(),
510
+ consultationCwdPolicy: runtime.getConsultationCwdPolicy(),
511
+ configuredConsultationCwdPolicy: cwdPolicy.consultation.value,
512
+ consultationCwdPolicySource: cwdPolicy.consultation.source,
513
+ delegationCwdPolicy: runtime.getDelegationCwdPolicy(),
514
+ configuredDelegationCwdPolicy: cwdPolicy.delegation.value,
515
+ delegationCwdPolicySource: cwdPolicy.delegation.source,
516
+ configuredConsultResources: resources.value,
517
+ consultResourcesSource: resources.source,
518
+ settingsPath: safeDisplayPath(resources.path, process.cwd()),
519
+ settingsError: configured.error || resources.error || cwdPolicy.error || completion.error || parallelLimit.error || detachedLimits.error || transport.error ? boundedPrivateText(
520
+ configured.error ?? resources.error ?? cwdPolicy.error ?? completion.error ?? parallelLimit.error ?? detachedLimits.error ?? transport.error ?? "",
521
+ 2 * 1024
522
+ ) : void 0
523
+ };
524
+ }
525
+ async function inspectInProcessCapability() {
526
+ try {
527
+ const moduleSpecifier = "@earendil-works/pi-coding-agent";
528
+ const core = await import(moduleSpecifier);
529
+ for (const name of [
530
+ "createAgentSessionServices",
531
+ "createAgentSessionFromServices",
532
+ "resolveCliModel"
533
+ ]) {
534
+ if (typeof core[name] !== "function") return { error: `Pi core does not export ${name}()` };
535
+ }
536
+ return {};
537
+ } catch (error) {
538
+ return { error: error instanceof Error ? error.message : String(error) };
539
+ }
540
+ }
541
+ function inspectRpcCapability() {
542
+ try {
543
+ resolvePiInvocation(["--mode", "rpc", "--no-session"]);
544
+ return {};
545
+ } catch (error) {
546
+ return { error: error instanceof Error ? error.message : String(error) };
547
+ }
548
+ }
549
+ function availableModelCount(ctx) {
550
+ return (ctx.scopedModels?.length ?? 0) > 0 ? ctx.scopedModels.length : ctx.modelRegistry.getAvailable().length;
551
+ }
552
+ function projectToolNames(tools) {
553
+ return tools.slice(0, 100).map((tool) => boundedPrivateText(tool, 256));
554
+ }
555
+ function boundedProjection(values, limit, project) {
556
+ const items = [];
557
+ for (const value of values.slice(0, limit)) {
558
+ const next = project(value);
559
+ if (Buffer.byteLength(JSON.stringify([...items, next]), "utf8") > MAX_DETAILS_LIST_BYTES) break;
560
+ items.push(next);
561
+ }
562
+ return { items, omitted: Math.max(0, values.length - items.length) };
563
+ }
564
+ function inspectResult(details) {
565
+ const rendered = boundText(JSON.stringify(details, null, 2));
566
+ return {
567
+ content: [{ type: "text", text: rendered.text }],
568
+ details: { ...details, ...rendered.truncated ? { truncated: true } : {} }
569
+ };
570
+ }
571
+ function assertTrustedScope(scope, ctx) {
572
+ if ((scope === "project" || scope === "both") && !ctx.isProjectTrusted()) {
573
+ throw new Error("Project-local subagent definitions require a trusted project");
574
+ }
575
+ }
576
+ function parameterRecord(params) {
577
+ if (!params || typeof params !== "object" || Array.isArray(params)) {
578
+ throw new Error("subagent_inspect parameters must be an object");
579
+ }
580
+ return params;
581
+ }
582
+ function optionalAgentScope(value) {
583
+ if (value === void 0) return "user";
584
+ if (value === "user" || value === "project" || value === "both") return value;
585
+ throw new Error("subagent_inspect agentScope must be user, project, or both");
586
+ }
587
+ function requiredString(value, action, field) {
588
+ if (typeof value !== "string" || value.length === 0) {
589
+ throw new Error(`subagent_inspect action "${action}" requires ${field}`);
590
+ }
591
+ return value;
592
+ }
593
+ function optionalContextMode(value) {
594
+ if (value === void 0) return "none";
595
+ if (value === "none" || value === "all" || value === "summary") return value;
596
+ if (typeof value === "number" && Number.isSafeInteger(value) && value >= 1) return value;
597
+ throw new Error("subagent_inspect context must be none, all, summary, or a positive integer");
598
+ }
599
+ function optionalStringArray(value, field) {
600
+ if (value === void 0) return void 0;
601
+ if (!Array.isArray(value) || !value.every((item) => typeof item === "string" && item.length > 0)) {
602
+ throw new Error(`subagent_inspect ${field} must be an array of non-empty strings`);
603
+ }
604
+ return [...value];
605
+ }
606
+ function optionalLimit(value, defaultValue) {
607
+ if (value === void 0) return defaultValue;
608
+ if (!Number.isSafeInteger(value) || value < 1 || value > 100) {
609
+ throw new Error("subagent_inspect limit must be an integer between 1 and 100");
610
+ }
611
+ return value;
612
+ }
613
+ export {
614
+ SubagentInspectParams,
615
+ executeSubagentInspect,
616
+ registerSubagentInspect,
617
+ validateInspectParams
618
+ };
619
+ //# sourceMappingURL=inspect-UOQQ3KNL.ts.map