@narumitw/pi-subagents 2.1.4 → 3.0.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 (312) hide show
  1. package/README.md +187 -1228
  2. package/dist/child-communication-bridge.ts +136 -0
  3. package/dist/child-communication-bridge.ts.map +7 -0
  4. package/dist/chunks/chunk-UKTWUQRM.js +667 -0
  5. package/dist/chunks/chunk-UKTWUQRM.js.map +7 -0
  6. package/dist/index.ts +1448 -1614
  7. package/dist/index.ts.map +4 -4
  8. package/docs/design-principles.md +31 -0
  9. package/docs/ipc-transport-idea.md +103 -0
  10. package/docs/tools.md +109 -0
  11. package/package.json +11 -19
  12. package/src/broker-credentials.ts +71 -0
  13. package/src/child-communication-bridge.ts +153 -0
  14. package/src/child-communication-tools.ts +147 -0
  15. package/src/completion-renderer.ts +60 -0
  16. package/src/index.ts +1 -1
  17. package/src/message-broker.ts +628 -0
  18. package/src/model-output.ts +42 -0
  19. package/src/process.ts +688 -0
  20. package/src/runtime.ts +538 -0
  21. package/src/subagents.ts +33 -34
  22. package/src/tools.ts +416 -0
  23. package/src/types.ts +85 -0
  24. package/src/widget.ts +130 -0
  25. package/dist/chunks/auto-transport-FUUKFDIG.ts +0 -109
  26. package/dist/chunks/auto-transport-FUUKFDIG.ts.map +0 -7
  27. package/dist/chunks/capability-grant-PR72SWWS.ts +0 -19
  28. package/dist/chunks/capability-grant-PR72SWWS.ts.map +0 -7
  29. package/dist/chunks/child-peer-bridge.ts +0 -108
  30. package/dist/chunks/child-peer-bridge.ts.map +0 -7
  31. package/dist/chunks/chunk-2LMJU25E.ts +0 -1641
  32. package/dist/chunks/chunk-2LMJU25E.ts.map +0 -7
  33. package/dist/chunks/chunk-47SK2QYC.ts +0 -56
  34. package/dist/chunks/chunk-47SK2QYC.ts.map +0 -7
  35. package/dist/chunks/chunk-4AQSF7AS.ts +0 -29
  36. package/dist/chunks/chunk-4AQSF7AS.ts.map +0 -7
  37. package/dist/chunks/chunk-5DGRMKNV.ts +0 -126
  38. package/dist/chunks/chunk-5DGRMKNV.ts.map +0 -7
  39. package/dist/chunks/chunk-6H6TBBED.ts +0 -108
  40. package/dist/chunks/chunk-6H6TBBED.ts.map +0 -7
  41. package/dist/chunks/chunk-6KJ34M6S.ts +0 -159
  42. package/dist/chunks/chunk-6KJ34M6S.ts.map +0 -7
  43. package/dist/chunks/chunk-6NSJVPXX.ts +0 -480
  44. package/dist/chunks/chunk-6NSJVPXX.ts.map +0 -7
  45. package/dist/chunks/chunk-7AAJEUSL.ts +0 -238
  46. package/dist/chunks/chunk-7AAJEUSL.ts.map +0 -7
  47. package/dist/chunks/chunk-BFK2Z4ZF.ts +0 -189
  48. package/dist/chunks/chunk-BFK2Z4ZF.ts.map +0 -7
  49. package/dist/chunks/chunk-BOAXY55Y.ts +0 -153
  50. package/dist/chunks/chunk-BOAXY55Y.ts.map +0 -7
  51. package/dist/chunks/chunk-D4CR7T73.ts +0 -353
  52. package/dist/chunks/chunk-D4CR7T73.ts.map +0 -7
  53. package/dist/chunks/chunk-FEVPWRMU.ts +0 -300
  54. package/dist/chunks/chunk-FEVPWRMU.ts.map +0 -7
  55. package/dist/chunks/chunk-G6VZTCFH.ts +0 -70
  56. package/dist/chunks/chunk-G6VZTCFH.ts.map +0 -7
  57. package/dist/chunks/chunk-H3FP6DLR.ts +0 -160
  58. package/dist/chunks/chunk-H3FP6DLR.ts.map +0 -7
  59. package/dist/chunks/chunk-HA36LPCO.ts +0 -130
  60. package/dist/chunks/chunk-HA36LPCO.ts.map +0 -7
  61. package/dist/chunks/chunk-HOP5FXDT.ts +0 -27
  62. package/dist/chunks/chunk-HOP5FXDT.ts.map +0 -7
  63. package/dist/chunks/chunk-IGAMVWFN.ts +0 -139
  64. package/dist/chunks/chunk-IGAMVWFN.ts.map +0 -7
  65. package/dist/chunks/chunk-ILEQ27AL.ts +0 -45
  66. package/dist/chunks/chunk-ILEQ27AL.ts.map +0 -7
  67. package/dist/chunks/chunk-ITVWPNU4.ts +0 -819
  68. package/dist/chunks/chunk-ITVWPNU4.ts.map +0 -7
  69. package/dist/chunks/chunk-IWC32VPY.ts +0 -172
  70. package/dist/chunks/chunk-IWC32VPY.ts.map +0 -7
  71. package/dist/chunks/chunk-JSZIP73U.ts +0 -362
  72. package/dist/chunks/chunk-JSZIP73U.ts.map +0 -7
  73. package/dist/chunks/chunk-JU6LUNLP.ts +0 -380
  74. package/dist/chunks/chunk-JU6LUNLP.ts.map +0 -7
  75. package/dist/chunks/chunk-KMGKCEO4.ts +0 -38
  76. package/dist/chunks/chunk-KMGKCEO4.ts.map +0 -7
  77. package/dist/chunks/chunk-LASD73CM.ts +0 -339
  78. package/dist/chunks/chunk-LASD73CM.ts.map +0 -7
  79. package/dist/chunks/chunk-LEOYDZI3.ts +0 -22
  80. package/dist/chunks/chunk-LEOYDZI3.ts.map +0 -7
  81. package/dist/chunks/chunk-LL4LP2T7.ts +0 -737
  82. package/dist/chunks/chunk-LL4LP2T7.ts.map +0 -7
  83. package/dist/chunks/chunk-N2T5IN4X.ts +0 -18
  84. package/dist/chunks/chunk-N2T5IN4X.ts.map +0 -7
  85. package/dist/chunks/chunk-N7BLVXKK.ts +0 -73
  86. package/dist/chunks/chunk-N7BLVXKK.ts.map +0 -7
  87. package/dist/chunks/chunk-NLT67IZS.ts +0 -322
  88. package/dist/chunks/chunk-NLT67IZS.ts.map +0 -7
  89. package/dist/chunks/chunk-NTRPLF46.ts +0 -63
  90. package/dist/chunks/chunk-NTRPLF46.ts.map +0 -7
  91. package/dist/chunks/chunk-ONDTY4EL.ts +0 -91
  92. package/dist/chunks/chunk-ONDTY4EL.ts.map +0 -7
  93. package/dist/chunks/chunk-OVPHFGKO.ts +0 -1769
  94. package/dist/chunks/chunk-OVPHFGKO.ts.map +0 -7
  95. package/dist/chunks/chunk-P7OH4XMF.ts +0 -60
  96. package/dist/chunks/chunk-P7OH4XMF.ts.map +0 -7
  97. package/dist/chunks/chunk-PBZMBTNJ.ts +0 -422
  98. package/dist/chunks/chunk-PBZMBTNJ.ts.map +0 -7
  99. package/dist/chunks/chunk-PGLSFLYW.ts +0 -52
  100. package/dist/chunks/chunk-PGLSFLYW.ts.map +0 -7
  101. package/dist/chunks/chunk-RRR66UWR.ts +0 -28
  102. package/dist/chunks/chunk-RRR66UWR.ts.map +0 -7
  103. package/dist/chunks/chunk-RSUXZD6S.ts +0 -275
  104. package/dist/chunks/chunk-RSUXZD6S.ts.map +0 -7
  105. package/dist/chunks/chunk-RTCVYIZA.ts +0 -221
  106. package/dist/chunks/chunk-RTCVYIZA.ts.map +0 -7
  107. package/dist/chunks/chunk-RY2AEGMZ.ts +0 -34
  108. package/dist/chunks/chunk-RY2AEGMZ.ts.map +0 -7
  109. package/dist/chunks/chunk-SWGQLFSD.ts +0 -60
  110. package/dist/chunks/chunk-SWGQLFSD.ts.map +0 -7
  111. package/dist/chunks/chunk-TM2R67J3.ts +0 -52
  112. package/dist/chunks/chunk-TM2R67J3.ts.map +0 -7
  113. package/dist/chunks/chunk-TMZRHIIK.ts +0 -497
  114. package/dist/chunks/chunk-TMZRHIIK.ts.map +0 -7
  115. package/dist/chunks/chunk-TZ34IQ3M.ts +0 -59
  116. package/dist/chunks/chunk-TZ34IQ3M.ts.map +0 -7
  117. package/dist/chunks/chunk-UMBPMVJW.ts +0 -22
  118. package/dist/chunks/chunk-UMBPMVJW.ts.map +0 -7
  119. package/dist/chunks/chunk-VDG7LTYE.ts +0 -80
  120. package/dist/chunks/chunk-VDG7LTYE.ts.map +0 -7
  121. package/dist/chunks/chunk-X4NMONPE.ts +0 -73
  122. package/dist/chunks/chunk-X4NMONPE.ts.map +0 -7
  123. package/dist/chunks/chunk-YPJEN6NU.ts +0 -65
  124. package/dist/chunks/chunk-YPJEN6NU.ts.map +0 -7
  125. package/dist/chunks/chunk-YU53SHA7.ts +0 -328
  126. package/dist/chunks/chunk-YU53SHA7.ts.map +0 -7
  127. package/dist/chunks/completion-delivery-RSJU6BXL.ts +0 -17
  128. package/dist/chunks/completion-delivery-RSJU6BXL.ts.map +0 -7
  129. package/dist/chunks/config-status-FKGDECZ3.ts +0 -35
  130. package/dist/chunks/config-status-FKGDECZ3.ts.map +0 -7
  131. package/dist/chunks/config-ui-ABHYNGQ7.ts +0 -1212
  132. package/dist/chunks/config-ui-ABHYNGQ7.ts.map +0 -7
  133. package/dist/chunks/consult-LJU3IQY5.ts +0 -519
  134. package/dist/chunks/consult-LJU3IQY5.ts.map +0 -7
  135. package/dist/chunks/context-QDKLVQXE.ts +0 -11
  136. package/dist/chunks/context-QDKLVQXE.ts.map +0 -7
  137. package/dist/chunks/create-stateful-transport-JWC2EFYL.ts +0 -130
  138. package/dist/chunks/create-stateful-transport-JWC2EFYL.ts.map +0 -7
  139. package/dist/chunks/cwd-policy-NB6XZ5GF.ts +0 -17
  140. package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +0 -7
  141. package/dist/chunks/delegation-contract-LA56I5DT.ts +0 -24
  142. package/dist/chunks/delegation-contract-LA56I5DT.ts.map +0 -7
  143. package/dist/chunks/discovery-MIFB2U4Y.ts +0 -12
  144. package/dist/chunks/discovery-MIFB2U4Y.ts.map +0 -7
  145. package/dist/chunks/execution-Q2JZLKJA.ts +0 -4037
  146. package/dist/chunks/execution-Q2JZLKJA.ts.map +0 -7
  147. package/dist/chunks/in-process-transport-HJ6TZXC3.ts +0 -39
  148. package/dist/chunks/in-process-transport-HJ6TZXC3.ts.map +0 -7
  149. package/dist/chunks/inspect-UH2TKH6E.ts +0 -634
  150. package/dist/chunks/inspect-UH2TKH6E.ts.map +0 -7
  151. package/dist/chunks/peer-communication-KL36Z6CO.ts +0 -294
  152. package/dist/chunks/peer-communication-KL36Z6CO.ts.map +0 -7
  153. package/dist/chunks/persistence-UY3PY6E5.ts +0 -348
  154. package/dist/chunks/persistence-UY3PY6E5.ts.map +0 -7
  155. package/dist/chunks/registry-BT54L6CY.ts +0 -1445
  156. package/dist/chunks/registry-BT54L6CY.ts.map +0 -7
  157. package/dist/chunks/retained-semantic-state-GM75FZGE.ts +0 -81
  158. package/dist/chunks/retained-semantic-state-GM75FZGE.ts.map +0 -7
  159. package/dist/chunks/rpc-transport-7R7DVCEB.ts +0 -1222
  160. package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +0 -7
  161. package/dist/chunks/runtime-policy-5YELCOVC.ts +0 -15
  162. package/dist/chunks/runtime-policy-5YELCOVC.ts.map +0 -7
  163. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +0 -19
  164. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +0 -7
  165. package/dist/chunks/spawn-idempotency-BNHOSMZW.ts +0 -13
  166. package/dist/chunks/spawn-idempotency-BNHOSMZW.ts.map +0 -7
  167. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +0 -15
  168. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +0 -7
  169. package/dist/chunks/subprocess-transport-VHZJRBTW.ts +0 -160
  170. package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +0 -7
  171. package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +0 -164
  172. package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +0 -7
  173. package/dist/chunks/workspace-WDKLN72J.ts +0 -11
  174. package/dist/chunks/workspace-WDKLN72J.ts.map +0 -7
  175. package/docs/async-runtime-protocol.md +0 -84
  176. package/docs/implementation-notes/pi-subagents-capability-matrix.md +0 -62
  177. package/docs/implementation-notes/pi-subagents-current-direction.md +0 -99
  178. package/docs/implementation-notes/pi-subagents-rpc-v1.md +0 -139
  179. package/docs/pi-subagents-diagrams.md +0 -183
  180. package/src/adaptive-scheduler.ts +0 -224
  181. package/src/admission-policy.ts +0 -78
  182. package/src/agent-projection.ts +0 -53
  183. package/src/agents/built-ins.ts +0 -71
  184. package/src/agents/catalog.ts +0 -241
  185. package/src/agents/discovery.ts +0 -265
  186. package/src/agents/types.ts +0 -100
  187. package/src/agents.ts +0 -51
  188. package/src/auto-transport.ts +0 -121
  189. package/src/blocking-status.ts +0 -63
  190. package/src/cached-module-loader.ts +0 -18
  191. package/src/capabilities.ts +0 -145
  192. package/src/capability-grant.ts +0 -115
  193. package/src/capability-router.ts +0 -107
  194. package/src/child-peer-bridge.ts +0 -124
  195. package/src/child-peer-tools.ts +0 -132
  196. package/src/completion-delivery.ts +0 -409
  197. package/src/completion-render.ts +0 -190
  198. package/src/completion-requirement.ts +0 -479
  199. package/src/completion-routing.ts +0 -24
  200. package/src/config-registration.ts +0 -114
  201. package/src/config-status.ts +0 -217
  202. package/src/config-ui.ts +0 -983
  203. package/src/consult-policy.ts +0 -15
  204. package/src/consult-registration.ts +0 -125
  205. package/src/consult-render.ts +0 -194
  206. package/src/consult-resources.ts +0 -51
  207. package/src/consult-tool.ts +0 -95
  208. package/src/consult.ts +0 -566
  209. package/src/context.ts +0 -126
  210. package/src/create-stateful-transport.ts +0 -157
  211. package/src/cwd-policy.ts +0 -183
  212. package/src/delegation-contract.ts +0 -463
  213. package/src/execution/budget.ts +0 -56
  214. package/src/execution/runtime-policy.ts +0 -19
  215. package/src/execution-plan.ts +0 -322
  216. package/src/execution-ui.ts +0 -259
  217. package/src/execution.ts +0 -1679
  218. package/src/in-process-transport.ts +0 -941
  219. package/src/inspect-registration.ts +0 -64
  220. package/src/inspect-render.ts +0 -334
  221. package/src/inspect-tool.ts +0 -45
  222. package/src/inspect.ts +0 -769
  223. package/src/integration-controller.ts +0 -98
  224. package/src/limits.ts +0 -75
  225. package/src/orchestration-metrics.ts +0 -116
  226. package/src/outcome.ts +0 -61
  227. package/src/panel-child-group.ts +0 -35
  228. package/src/panel-contract.ts +0 -343
  229. package/src/panel-evidence.ts +0 -59
  230. package/src/panel-execution.ts +0 -769
  231. package/src/panel-failure.ts +0 -56
  232. package/src/panel-planning.ts +0 -175
  233. package/src/panel-presets.ts +0 -3
  234. package/src/panel-prompts.ts +0 -132
  235. package/src/panel-reconciliation.ts +0 -57
  236. package/src/panel-render.ts +0 -103
  237. package/src/parallel-limit-ui.ts +0 -113
  238. package/src/params.ts +0 -278
  239. package/src/peer-communication.ts +0 -352
  240. package/src/peer-transport.ts +0 -49
  241. package/src/persistence.ts +0 -522
  242. package/src/pi-args.ts +0 -43
  243. package/src/pi-invocation.ts +0 -168
  244. package/src/process-control.ts +0 -43
  245. package/src/prompt-resources.ts +0 -38
  246. package/src/prompt-source-safety.ts +0 -48
  247. package/src/protocol.ts +0 -76
  248. package/src/registry-types.ts +0 -204
  249. package/src/registry.ts +0 -1698
  250. package/src/render-common.ts +0 -252
  251. package/src/render.ts +0 -704
  252. package/src/result-contract.ts +0 -431
  253. package/src/retained-semantic-state.ts +0 -100
  254. package/src/rpc-timeout-finalization.ts +0 -207
  255. package/src/rpc-transport-metadata.ts +0 -65
  256. package/src/rpc-transport.ts +0 -1035
  257. package/src/rpc-turn-capture.ts +0 -217
  258. package/src/runner-outcome.ts +0 -31
  259. package/src/runner-result.ts +0 -55
  260. package/src/runner-types.ts +0 -102
  261. package/src/runner-usage.ts +0 -48
  262. package/src/runner.ts +0 -866
  263. package/src/safe-text.ts +0 -67
  264. package/src/semantic-snapshot.ts +0 -214
  265. package/src/session-guidance-contract.ts +0 -399
  266. package/src/settings/inspection.ts +0 -302
  267. package/src/settings/schema.ts +0 -195
  268. package/src/settings-reader.ts +0 -215
  269. package/src/settings.ts +0 -452
  270. package/src/spawn-idempotency.ts +0 -68
  271. package/src/stateful-agent-view.ts +0 -85
  272. package/src/stateful-config.ts +0 -13
  273. package/src/stateful-guidance.ts +0 -29
  274. package/src/stateful-lifecycle.ts +0 -74
  275. package/src/stateful-limit-ui.ts +0 -249
  276. package/src/stateful-limits.ts +0 -96
  277. package/src/stateful-prompt.ts +0 -49
  278. package/src/stateful-registration.ts +0 -1320
  279. package/src/stateful-render.ts +0 -318
  280. package/src/stateful-safety.ts +0 -47
  281. package/src/stateful-tool-params.ts +0 -215
  282. package/src/stateful.ts +0 -12
  283. package/src/subagent-details.ts +0 -43
  284. package/src/subagents-extension.ts +0 -372
  285. package/src/subprocess-transport.ts +0 -145
  286. package/src/supervision.ts +0 -104
  287. package/src/task-path.ts +0 -65
  288. package/src/timeout-checkpoint.ts +0 -305
  289. package/src/timeout-finalization.ts +0 -75
  290. package/src/tool-schema-compatibility.ts +0 -73
  291. package/src/transport-types.ts +0 -74
  292. package/src/transport-ui.ts +0 -135
  293. package/src/transport.ts +0 -43
  294. package/src/turn-budget.ts +0 -109
  295. package/src/usage-format.ts +0 -42
  296. package/src/usage-recording-config.ts +0 -13
  297. package/src/usage-recording-store.ts +0 -183
  298. package/src/usage-recording.ts +0 -478
  299. package/src/verification-harness.ts +0 -516
  300. package/src/verification-policy.ts +0 -67
  301. package/src/verification-receipt.ts +0 -275
  302. package/src/verified-execution-benchmark.ts +0 -86
  303. package/src/verified-execution-contract.ts +0 -191
  304. package/src/verified-execution-schema.ts +0 -32
  305. package/src/work-item-ledger.ts +0 -1404
  306. package/src/work-item-persistence.ts +0 -254
  307. package/src/workflow-completion-controller.ts +0 -397
  308. package/src/workflow-planning.ts +0 -172
  309. package/src/workflow-tree-identity.ts +0 -289
  310. package/src/workflow-ui.ts +0 -69
  311. package/src/workflow-verification.ts +0 -296
  312. package/src/workspace.ts +0 -174
@@ -1,463 +0,0 @@
1
- import { StringEnum } from "@earendil-works/pi-ai";
2
- import { Type } from "typebox";
3
- import { redactPrivateText } from "./context.js";
4
- import { DEFAULT_MAX_CONTEXT_BYTES, MAX_SUBAGENT_TIMEOUT_MS, truncateUtf8 } from "./limits.js";
5
-
6
- export const DELEGATION_CONTRACT_VERSION = "pi-subagents:delegation:v2" as const;
7
- export const DELEGATION_CONTRACT_LEVELS = ["minimal", "full"] as const;
8
- export const DELEGATION_ENFORCEMENT_MODES = ["audit", "enforce"] as const;
9
- export const AUTHORITY_REQUIREMENTS = ["unspecified", "denied", "required"] as const;
10
- export const DELEGATION_SIDE_EFFECT_POLICIES = ["read-only", "idempotent", "mutating"] as const;
11
-
12
- const MAX_IDENTIFIER_BYTES = 256;
13
- const MAX_TEXT_BYTES = 16 * 1024;
14
- const MAX_ITEM_BYTES = 4 * 1024;
15
- const MAX_ITEMS = 50;
16
- const MAX_TURNS_OR_TOOLS = 1_000_000;
17
-
18
- const BoundedString = Type.String({ maxLength: MAX_TEXT_BYTES });
19
- const BoundedItem = Type.String({ maxLength: MAX_ITEM_BYTES });
20
- const BoundedItems = Type.Array(BoundedItem, { maxItems: MAX_ITEMS });
21
- const DependencySchema = Type.Object(
22
- {
23
- taskId: Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES }),
24
- artifactId: Type.Optional(Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES })),
25
- version: Type.Optional(Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES })),
26
- },
27
- { additionalProperties: false },
28
- );
29
-
30
- export const DelegationContractSchema = Type.Object(
31
- {
32
- version: Type.Literal(DELEGATION_CONTRACT_VERSION),
33
- level: StringEnum(DELEGATION_CONTRACT_LEVELS),
34
- taskId: Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES }),
35
- objective: BoundedString,
36
- nonGoals: Type.Optional(BoundedItems),
37
- dependencies: Type.Optional(Type.Array(DependencySchema, { maxItems: MAX_ITEMS })),
38
- requiredInputs: Type.Optional(BoundedItems),
39
- requestedAuthority: Type.Optional(
40
- Type.Object(
41
- {
42
- capabilities: Type.Optional(
43
- Type.Array(BoundedItem, {
44
- maxItems: MAX_ITEMS,
45
- description: "Capabilities requested from the selected agent manifest.",
46
- }),
47
- ),
48
- tools: Type.Optional(
49
- Type.Array(BoundedItem, {
50
- maxItems: MAX_ITEMS,
51
- description:
52
- "Tools that enforcement may narrow to the selected agent's available set.",
53
- }),
54
- ),
55
- readPaths: Type.Optional(
56
- Type.Array(BoundedItem, {
57
- maxItems: MAX_ITEMS,
58
- description:
59
- 'Audit metadata only; enforcement "enforce" rejects non-empty readPaths because path scope is unsupported.',
60
- }),
61
- ),
62
- writePaths: Type.Optional(
63
- Type.Array(BoundedItem, {
64
- maxItems: MAX_ITEMS,
65
- description:
66
- 'Audit metadata only; enforcement "enforce" rejects non-empty writePaths because path scope is unsupported.',
67
- }),
68
- ),
69
- network: Type.Optional(
70
- StringEnum(AUTHORITY_REQUIREMENTS, {
71
- description:
72
- 'Audit metadata only; enforcement "enforce" rejects denied or required network guarantees as unsupported.',
73
- }),
74
- ),
75
- secrets: Type.Optional(
76
- StringEnum(AUTHORITY_REQUIREMENTS, {
77
- description:
78
- 'Audit metadata only; enforcement "enforce" rejects denied or required secret guarantees as unsupported.',
79
- }),
80
- ),
81
- },
82
- {
83
- additionalProperties: false,
84
- description:
85
- "Only capabilities and tools have executor enforcement; readPaths, writePaths, network, and secrets are unsupported guarantees.",
86
- },
87
- ),
88
- ),
89
- acceptanceCriteria: Type.Optional(BoundedItems),
90
- requiredEvidence: Type.Optional(BoundedItems),
91
- budget: Type.Optional(
92
- Type.Object(
93
- {
94
- timeoutMs: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_SUBAGENT_TIMEOUT_MS })),
95
- maxTurns: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_TURNS_OR_TOOLS })),
96
- maxToolCalls: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_TURNS_OR_TOOLS })),
97
- },
98
- { additionalProperties: false },
99
- ),
100
- ),
101
- admission: Type.Optional(
102
- Type.Object(
103
- {
104
- contextPressure: StringEnum(["low", "medium", "high"] as const),
105
- independentWorkItems: Type.Integer({ minimum: 1, maximum: 2 }),
106
- coupling: StringEnum(["dense", "sparse"] as const),
107
- verificationRequired: Type.Boolean(),
108
- verificationAvailable: Type.Boolean(),
109
- budgetAllowsChildren: Type.Boolean(),
110
- requirementsComplete: Type.Boolean(),
111
- },
112
- { additionalProperties: false },
113
- ),
114
- ),
115
- sideEffectPolicy: Type.Optional(StringEnum(DELEGATION_SIDE_EFFECT_POLICIES)),
116
- enforcement: Type.Optional(
117
- StringEnum(DELEGATION_ENFORCEMENT_MODES, {
118
- description:
119
- "Defaults to audit; enforce rejects unsupported requestedAuthority guarantees before child launch.",
120
- }),
121
- ),
122
- },
123
- {
124
- additionalProperties: false,
125
- description:
126
- "Advanced delegation contract. For ordinary delegation omit this object; use it only for explicit acceptance, authority, evidence, or admission semantics.",
127
- },
128
- );
129
-
130
- export interface DelegationDependency {
131
- taskId: string;
132
- artifactId?: string;
133
- version?: string;
134
- }
135
-
136
- export interface DelegationAuthorityRequest {
137
- capabilities?: string[];
138
- tools?: string[];
139
- readPaths?: string[];
140
- writePaths?: string[];
141
- network?: (typeof AUTHORITY_REQUIREMENTS)[number];
142
- secrets?: (typeof AUTHORITY_REQUIREMENTS)[number];
143
- }
144
-
145
- export interface DelegationBudgetRequest {
146
- timeoutMs?: number;
147
- maxTurns?: number;
148
- maxToolCalls?: number;
149
- }
150
-
151
- export interface DelegationAdmissionRequest {
152
- contextPressure: "low" | "medium" | "high";
153
- independentWorkItems: number;
154
- coupling: "dense" | "sparse";
155
- verificationRequired: boolean;
156
- verificationAvailable: boolean;
157
- budgetAllowsChildren: boolean;
158
- requirementsComplete: boolean;
159
- }
160
-
161
- export interface DelegationContract {
162
- version: typeof DELEGATION_CONTRACT_VERSION;
163
- level: (typeof DELEGATION_CONTRACT_LEVELS)[number];
164
- taskId: string;
165
- objective: string;
166
- nonGoals: string[];
167
- dependencies: DelegationDependency[];
168
- requiredInputs: string[];
169
- requestedAuthority?: DelegationAuthorityRequest;
170
- acceptanceCriteria: string[];
171
- requiredEvidence: string[];
172
- budget?: DelegationBudgetRequest;
173
- admission?: DelegationAdmissionRequest;
174
- sideEffectPolicy: (typeof DELEGATION_SIDE_EFFECT_POLICIES)[number];
175
- enforcement: (typeof DELEGATION_ENFORCEMENT_MODES)[number];
176
- }
177
-
178
- export interface AppendedDelegationContract {
179
- text: string;
180
- contract?: DelegationContract;
181
- truncated: boolean;
182
- }
183
-
184
- export function normalizeDelegationContract(value: unknown): DelegationContract | undefined {
185
- if (!isPlainObject(value)) return undefined;
186
- if (
187
- !hasOnlyKeys(value, [
188
- "version",
189
- "level",
190
- "taskId",
191
- "objective",
192
- "nonGoals",
193
- "dependencies",
194
- "requiredInputs",
195
- "requestedAuthority",
196
- "acceptanceCriteria",
197
- "requiredEvidence",
198
- "budget",
199
- "admission",
200
- "sideEffectPolicy",
201
- "enforcement",
202
- ])
203
- ) {
204
- return undefined;
205
- }
206
- if (
207
- value.version !== DELEGATION_CONTRACT_VERSION ||
208
- typeof value.level !== "string" ||
209
- !DELEGATION_CONTRACT_LEVELS.includes(
210
- value.level as (typeof DELEGATION_CONTRACT_LEVELS)[number],
211
- ) ||
212
- typeof value.taskId !== "string" ||
213
- !value.taskId.trim() ||
214
- typeof value.objective !== "string"
215
- ) {
216
- return undefined;
217
- }
218
- const taskId = bounded(value.taskId, MAX_IDENTIFIER_BYTES);
219
- const objective = bounded(value.objective, MAX_TEXT_BYTES);
220
- if (!taskId || !objective) return undefined;
221
- const nonGoals = normalizeStrings(value.nonGoals);
222
- const requiredInputs = normalizeStrings(value.requiredInputs);
223
- const acceptanceCriteria = normalizeStrings(value.acceptanceCriteria);
224
- const requiredEvidence = normalizeStrings(value.requiredEvidence);
225
- if (!nonGoals || !requiredInputs || !acceptanceCriteria || !requiredEvidence) return undefined;
226
- const dependencies = normalizeDependencies(value.dependencies);
227
- if (!dependencies) return undefined;
228
- const authority = normalizeAuthority(value.requestedAuthority);
229
- if (authority === false) return undefined;
230
- const budget = normalizeBudget(value.budget);
231
- if (budget === false) return undefined;
232
- const admission = normalizeAdmission(value.admission);
233
- if (admission === false) return undefined;
234
- const sideEffectPolicy = value.sideEffectPolicy ?? "mutating";
235
- if (
236
- typeof sideEffectPolicy !== "string" ||
237
- !DELEGATION_SIDE_EFFECT_POLICIES.includes(
238
- sideEffectPolicy as (typeof DELEGATION_SIDE_EFFECT_POLICIES)[number],
239
- )
240
- ) {
241
- return undefined;
242
- }
243
- const enforcement = value.enforcement ?? "audit";
244
- if (
245
- typeof enforcement !== "string" ||
246
- !DELEGATION_ENFORCEMENT_MODES.includes(
247
- enforcement as (typeof DELEGATION_ENFORCEMENT_MODES)[number],
248
- )
249
- ) {
250
- return undefined;
251
- }
252
- return {
253
- version: DELEGATION_CONTRACT_VERSION,
254
- level: value.level as DelegationContract["level"],
255
- taskId,
256
- objective,
257
- nonGoals,
258
- dependencies,
259
- requiredInputs,
260
- ...(authority === undefined ? {} : { requestedAuthority: authority }),
261
- acceptanceCriteria,
262
- requiredEvidence,
263
- ...(budget === undefined ? {} : { budget }),
264
- ...(admission === undefined ? {} : { admission }),
265
- sideEffectPolicy: sideEffectPolicy as DelegationContract["sideEffectPolicy"],
266
- enforcement: enforcement as DelegationContract["enforcement"],
267
- };
268
- }
269
-
270
- export function appendDelegationContract(
271
- prompt: string,
272
- value: unknown,
273
- maxBytes = DEFAULT_MAX_CONTEXT_BYTES,
274
- ): AppendedDelegationContract {
275
- const contract = normalizeDelegationContract(value);
276
- if (!contract) return { text: prompt, truncated: false };
277
- const suffix = [
278
- "",
279
- "Delegation contract:",
280
- JSON.stringify(contract),
281
- "The requested authority is advisory until an executor-owned ExecutionPlan confirms which controls are enforceable and effective.",
282
- "Acknowledge missing inputs, authority, capabilities, or verification instead of guessing.",
283
- ].join("\n");
284
- const suffixBytes = Buffer.byteLength(suffix, "utf8");
285
- const boundedPrompt = truncateUtf8(
286
- redactPrivateText(prompt),
287
- Math.max(0, maxBytes - suffixBytes),
288
- );
289
- const text = truncateUtf8(`${boundedPrompt.text}${suffix}`, maxBytes);
290
- return {
291
- text: text.text,
292
- contract,
293
- truncated: boundedPrompt.truncated || text.truncated,
294
- };
295
- }
296
-
297
- function normalizeAdmission(value: unknown): DelegationAdmissionRequest | undefined | false {
298
- if (value === undefined) return undefined;
299
- if (!isPlainObject(value)) return false;
300
- if (
301
- !hasOnlyKeys(value, [
302
- "contextPressure",
303
- "independentWorkItems",
304
- "coupling",
305
- "verificationRequired",
306
- "verificationAvailable",
307
- "budgetAllowsChildren",
308
- "requirementsComplete",
309
- ]) ||
310
- !["low", "medium", "high"].includes(String(value.contextPressure)) ||
311
- !Number.isSafeInteger(value.independentWorkItems) ||
312
- Number(value.independentWorkItems) < 1 ||
313
- Number(value.independentWorkItems) > 2 ||
314
- !["dense", "sparse"].includes(String(value.coupling)) ||
315
- typeof value.verificationRequired !== "boolean" ||
316
- typeof value.verificationAvailable !== "boolean" ||
317
- typeof value.budgetAllowsChildren !== "boolean" ||
318
- typeof value.requirementsComplete !== "boolean"
319
- ) {
320
- return false;
321
- }
322
- return {
323
- contextPressure: value.contextPressure as DelegationAdmissionRequest["contextPressure"],
324
- independentWorkItems: Number(value.independentWorkItems),
325
- coupling: value.coupling as DelegationAdmissionRequest["coupling"],
326
- verificationRequired: value.verificationRequired,
327
- verificationAvailable: value.verificationAvailable,
328
- budgetAllowsChildren: value.budgetAllowsChildren,
329
- requirementsComplete: value.requirementsComplete,
330
- };
331
- }
332
-
333
- function normalizeDependencies(value: unknown): DelegationDependency[] | undefined {
334
- if (value === undefined) return [];
335
- if (!Array.isArray(value) || value.length > MAX_ITEMS) return undefined;
336
- const result: DelegationDependency[] = [];
337
- const seen = new Set<string>();
338
- for (const item of value) {
339
- if (
340
- !isPlainObject(item) ||
341
- !hasOnlyKeys(item, ["taskId", "artifactId", "version"]) ||
342
- typeof item.taskId !== "string"
343
- ) {
344
- return undefined;
345
- }
346
- const taskId = bounded(item.taskId, MAX_IDENTIFIER_BYTES);
347
- if (!taskId || seen.has(taskId)) return undefined;
348
- seen.add(taskId);
349
- const artifactId = optionalString(item.artifactId, MAX_IDENTIFIER_BYTES);
350
- const version = optionalString(item.version, MAX_IDENTIFIER_BYTES);
351
- if (artifactId === false || version === false) return undefined;
352
- result.push({
353
- taskId,
354
- ...(artifactId === undefined ? {} : { artifactId }),
355
- ...(version === undefined ? {} : { version }),
356
- });
357
- }
358
- return result;
359
- }
360
-
361
- function normalizeAuthority(value: unknown): DelegationAuthorityRequest | undefined | false {
362
- if (value === undefined) return undefined;
363
- if (!isPlainObject(value)) return false;
364
- if (
365
- !hasOnlyKeys(value, ["capabilities", "tools", "readPaths", "writePaths", "network", "secrets"])
366
- ) {
367
- return false;
368
- }
369
- const capabilities = normalizeOptionalStrings(value.capabilities);
370
- const tools = normalizeOptionalStrings(value.tools);
371
- const readPaths = normalizeOptionalStrings(value.readPaths);
372
- const writePaths = normalizeOptionalStrings(value.writePaths);
373
- if (capabilities === false || tools === false || readPaths === false || writePaths === false) {
374
- return false;
375
- }
376
- const network = normalizeAuthorityRequirement(value.network);
377
- const secrets = normalizeAuthorityRequirement(value.secrets);
378
- if (network === false || secrets === false) return false;
379
- return {
380
- ...(capabilities === undefined ? {} : { capabilities }),
381
- ...(tools === undefined ? {} : { tools }),
382
- ...(readPaths === undefined ? {} : { readPaths }),
383
- ...(writePaths === undefined ? {} : { writePaths }),
384
- ...(network === undefined ? {} : { network }),
385
- ...(secrets === undefined ? {} : { secrets }),
386
- };
387
- }
388
-
389
- function normalizeBudget(value: unknown): DelegationBudgetRequest | undefined | false {
390
- if (value === undefined) return undefined;
391
- if (!isPlainObject(value) || !hasOnlyKeys(value, ["timeoutMs", "maxTurns", "maxToolCalls"])) {
392
- return false;
393
- }
394
- const timeoutMs = optionalInteger(value.timeoutMs, MAX_SUBAGENT_TIMEOUT_MS);
395
- const maxTurns = optionalInteger(value.maxTurns, MAX_TURNS_OR_TOOLS);
396
- const maxToolCalls = optionalInteger(value.maxToolCalls, MAX_TURNS_OR_TOOLS);
397
- if (timeoutMs === false || maxTurns === false || maxToolCalls === false) return false;
398
- return {
399
- ...(timeoutMs === undefined ? {} : { timeoutMs }),
400
- ...(maxTurns === undefined ? {} : { maxTurns }),
401
- ...(maxToolCalls === undefined ? {} : { maxToolCalls }),
402
- };
403
- }
404
-
405
- function normalizeStrings(value: unknown): string[] | undefined {
406
- if (value === undefined) return [];
407
- const normalized = normalizeOptionalStrings(value);
408
- return normalized === false ? undefined : normalized;
409
- }
410
-
411
- function normalizeOptionalStrings(value: unknown): string[] | undefined | false {
412
- if (value === undefined) return undefined;
413
- if (!Array.isArray(value) || value.length > MAX_ITEMS) return false;
414
- const result: string[] = [];
415
- const seen = new Set<string>();
416
- for (const item of value) {
417
- if (typeof item !== "string") return false;
418
- const normalized = bounded(item, MAX_ITEM_BYTES);
419
- if (!normalized || seen.has(normalized)) continue;
420
- seen.add(normalized);
421
- result.push(normalized);
422
- }
423
- return result;
424
- }
425
-
426
- function normalizeAuthorityRequirement(
427
- value: unknown,
428
- ): (typeof AUTHORITY_REQUIREMENTS)[number] | undefined | false {
429
- if (value === undefined) return undefined;
430
- if (
431
- typeof value !== "string" ||
432
- !AUTHORITY_REQUIREMENTS.includes(value as (typeof AUTHORITY_REQUIREMENTS)[number])
433
- ) {
434
- return false;
435
- }
436
- return value as (typeof AUTHORITY_REQUIREMENTS)[number];
437
- }
438
-
439
- function optionalString(value: unknown, maxBytes: number): string | undefined | false {
440
- if (value === undefined) return undefined;
441
- if (typeof value !== "string") return false;
442
- const normalized = bounded(value, maxBytes);
443
- return normalized || false;
444
- }
445
-
446
- function optionalInteger(value: unknown, max: number): number | undefined | false {
447
- if (value === undefined) return undefined;
448
- if (!Number.isSafeInteger(value) || (value as number) < 1 || (value as number) > max)
449
- return false;
450
- return value as number;
451
- }
452
-
453
- function bounded(value: string, maxBytes: number): string {
454
- return truncateUtf8(redactPrivateText(value), maxBytes).text.trim();
455
- }
456
-
457
- function hasOnlyKeys(value: Record<string, unknown>, allowed: readonly string[]): boolean {
458
- return Object.keys(value).every((key) => allowed.includes(key));
459
- }
460
-
461
- function isPlainObject(value: unknown): value is Record<string, unknown> {
462
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
463
- }
@@ -1,56 +0,0 @@
1
- import type { AgentConfig } from "../agents/types.js";
2
- import type { TurnLimits } from "../turn-budget.js";
3
-
4
- export interface ExecutionBudget {
5
- timeoutMs: number;
6
- workTimeoutReason: "work_timeout" | "orchestration_timeout";
7
- workTimeoutReportLimit: number;
8
- }
9
-
10
- export function resolveConfiguredTimeout(
11
- agents: readonly AgentConfig[],
12
- agentName: string,
13
- localTimeoutMs: number | undefined,
14
- topLevelTimeoutMs: number | undefined,
15
- defaultTimeoutMs: number,
16
- ): number {
17
- return (
18
- localTimeoutMs ??
19
- topLevelTimeoutMs ??
20
- agents.find((agent) => agent.name === agentName)?.timeoutMs ??
21
- defaultTimeoutMs
22
- );
23
- }
24
-
25
- export function mergeTurnLimits(local: TurnLimits | undefined, fallback: TurnLimits): TurnLimits {
26
- return {
27
- idleTimeoutMs: local?.idleTimeoutMs ?? fallback.idleTimeoutMs,
28
- maxTurns: local?.maxTurns ?? fallback.maxTurns,
29
- maxToolCalls: local?.maxToolCalls ?? fallback.maxToolCalls,
30
- };
31
- }
32
-
33
- export function calculateExecutionBudget(input: {
34
- requestedTimeoutMs: number;
35
- orchestrationDeadline?: number;
36
- totalTimeoutMs?: number;
37
- now: number;
38
- }): ExecutionBudget | undefined {
39
- if (input.orchestrationDeadline === undefined) {
40
- return {
41
- timeoutMs: input.requestedTimeoutMs,
42
- workTimeoutReason: "work_timeout",
43
- workTimeoutReportLimit: input.requestedTimeoutMs,
44
- };
45
- }
46
- const remaining = Math.floor(input.orchestrationDeadline - input.now);
47
- if (remaining < 1) return undefined;
48
- const orchestrationLimited = remaining < input.requestedTimeoutMs;
49
- return {
50
- timeoutMs: Math.min(input.requestedTimeoutMs, remaining),
51
- workTimeoutReason: orchestrationLimited ? "orchestration_timeout" : "work_timeout",
52
- workTimeoutReportLimit: orchestrationLimited
53
- ? Math.floor(input.totalTimeoutMs as number)
54
- : input.requestedTimeoutMs,
55
- };
56
- }
@@ -1,19 +0,0 @@
1
- export const FALLBACK_TIMEOUT_MS = 10 * 60 * 1000;
2
-
3
- export function parsePositiveInteger(value: string | undefined): number | undefined {
4
- if (!value) return undefined;
5
- const parsed = Number.parseInt(value, 10);
6
- return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
7
- }
8
-
9
- export function resolveDefaultSubagentTimeoutMs(): number {
10
- return parsePositiveInteger(process.env.PI_SUBAGENT_TIMEOUT_MS) ?? FALLBACK_TIMEOUT_MS;
11
- }
12
-
13
- export function assertSubagentDepthAllowed(): void {
14
- const depth = Number.parseInt(process.env.PI_SUBAGENT_DEPTH ?? "0", 10) || 0;
15
- const maxDepth = parsePositiveInteger(process.env.PI_SUBAGENT_MAX_DEPTH) ?? 1;
16
- if (depth >= maxDepth) {
17
- throw new Error(`Subagent recursion depth limit reached (${maxDepth})`);
18
- }
19
- }