@ai-agent-forge/agent-forge 0.87.0 → 0.88.1

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 (451) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +2 -2
  3. package/bundled-plugins/agent-loop-policy/agent-forge.json +19 -0
  4. package/bundled-plugins/agent-loop-policy/dist/entry.d.ts +28 -0
  5. package/bundled-plugins/agent-loop-policy/dist/entry.d.ts.map +1 -0
  6. package/bundled-plugins/agent-loop-policy/dist/entry.js +69 -0
  7. package/bundled-plugins/agent-loop-policy/dist/entry.js.map +1 -0
  8. package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts +199 -0
  9. package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts.map +1 -0
  10. package/bundled-plugins/agent-loop-policy/dist/loop-guard.js +208 -0
  11. package/bundled-plugins/agent-loop-policy/dist/loop-guard.js.map +1 -0
  12. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts +17 -0
  13. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts.map +1 -0
  14. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js +18 -0
  15. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js.map +1 -0
  16. package/bundled-plugins/agent-loop-policy/plugin.json +7 -0
  17. package/bundled-plugins/coding-tools/agent-forge.json +19 -0
  18. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.d.ts +5 -44
  19. package/bundled-plugins/coding-tools/dist/bash.d.ts.map +1 -0
  20. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.js +15 -119
  21. package/bundled-plugins/coding-tools/dist/bash.js.map +1 -0
  22. package/bundled-plugins/coding-tools/dist/capability.d.ts +25 -0
  23. package/bundled-plugins/coding-tools/dist/capability.d.ts.map +1 -0
  24. package/bundled-plugins/coding-tools/dist/capability.js +98 -0
  25. package/bundled-plugins/coding-tools/dist/capability.js.map +1 -0
  26. package/bundled-plugins/coding-tools/dist/config.d.ts +8 -0
  27. package/bundled-plugins/coding-tools/dist/config.d.ts.map +1 -0
  28. package/bundled-plugins/coding-tools/dist/config.js +8 -0
  29. package/bundled-plugins/coding-tools/dist/config.js.map +1 -0
  30. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.d.ts +3 -3
  31. package/bundled-plugins/coding-tools/dist/edit.d.ts.map +1 -0
  32. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.js +12 -10
  33. package/bundled-plugins/coding-tools/dist/edit.js.map +1 -0
  34. package/bundled-plugins/coding-tools/dist/entry.d.ts +14 -0
  35. package/bundled-plugins/coding-tools/dist/entry.d.ts.map +1 -0
  36. package/bundled-plugins/coding-tools/dist/entry.js +23 -0
  37. package/bundled-plugins/coding-tools/dist/entry.js.map +1 -0
  38. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.d.ts +4 -4
  39. package/bundled-plugins/coding-tools/dist/find.d.ts.map +1 -0
  40. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.js +10 -8
  41. package/bundled-plugins/coding-tools/dist/find.js.map +1 -0
  42. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.d.ts +3 -3
  43. package/bundled-plugins/coding-tools/dist/grep.d.ts.map +1 -0
  44. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.js +10 -8
  45. package/bundled-plugins/coding-tools/dist/grep.js.map +1 -0
  46. package/bundled-plugins/coding-tools/dist/index.d.ts +17 -0
  47. package/bundled-plugins/coding-tools/dist/index.d.ts.map +1 -0
  48. package/bundled-plugins/coding-tools/dist/index.js +17 -0
  49. package/bundled-plugins/coding-tools/dist/index.js.map +1 -0
  50. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.d.ts +3 -3
  51. package/bundled-plugins/coding-tools/dist/ls.d.ts.map +1 -0
  52. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js +8 -6
  53. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js.map +1 -1
  54. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.d.ts +2 -1
  55. package/bundled-plugins/coding-tools/dist/powershell.d.ts.map +1 -0
  56. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.js +6 -3
  57. package/bundled-plugins/coding-tools/dist/powershell.js.map +1 -0
  58. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.d.ts +3 -3
  59. package/bundled-plugins/coding-tools/dist/read.d.ts.map +1 -0
  60. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.js +15 -13
  61. package/bundled-plugins/coding-tools/dist/read.js.map +1 -0
  62. package/bundled-plugins/coding-tools/dist/types.d.ts +74 -0
  63. package/bundled-plugins/coding-tools/dist/types.d.ts.map +1 -0
  64. package/bundled-plugins/coding-tools/dist/types.js +28 -0
  65. package/bundled-plugins/coding-tools/dist/types.js.map +1 -0
  66. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.d.ts +2 -2
  67. package/bundled-plugins/coding-tools/dist/write.d.ts.map +1 -0
  68. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.js +11 -9
  69. package/bundled-plugins/coding-tools/dist/write.js.map +1 -0
  70. package/bundled-plugins/coding-tools/plugin.json +10 -0
  71. package/bundled-plugins/compaction-policy/agent-forge.json +19 -0
  72. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts +6 -0
  73. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts.map +1 -0
  74. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js +19 -0
  75. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js.map +1 -0
  76. package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts +6 -0
  77. package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts.map +1 -0
  78. package/bundled-plugins/compaction-policy/dist/compaction-policy.js +38 -0
  79. package/bundled-plugins/compaction-policy/dist/compaction-policy.js.map +1 -0
  80. package/bundled-plugins/compaction-policy/dist/entry.d.ts +13 -0
  81. package/bundled-plugins/compaction-policy/dist/entry.d.ts.map +1 -0
  82. package/bundled-plugins/compaction-policy/dist/entry.js +23 -0
  83. package/bundled-plugins/compaction-policy/dist/entry.js.map +1 -0
  84. package/bundled-plugins/compaction-policy/plugin.json +10 -0
  85. package/bundled-plugins/mcp-http/dist/index.d.ts +8 -0
  86. package/bundled-plugins/mcp-http/dist/index.d.ts.map +1 -0
  87. package/bundled-plugins/mcp-http/dist/index.js +8 -0
  88. package/bundled-plugins/mcp-http/dist/index.js.map +1 -0
  89. package/bundled-plugins/mcp-http/dist/mcp-http.d.ts.map +1 -0
  90. package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.js +1 -1
  91. package/bundled-plugins/mcp-http/dist/mcp-http.js.map +1 -0
  92. package/bundled-plugins/overflow-policy/agent-forge.json +19 -0
  93. package/bundled-plugins/overflow-policy/dist/entry.d.ts +16 -0
  94. package/bundled-plugins/overflow-policy/dist/entry.d.ts.map +1 -0
  95. package/bundled-plugins/overflow-policy/dist/entry.js +35 -0
  96. package/bundled-plugins/overflow-policy/dist/entry.js.map +1 -0
  97. package/bundled-plugins/overflow-policy/plugin.json +10 -0
  98. package/bundled-plugins/provider-failover/agent-forge.json +19 -0
  99. package/bundled-plugins/provider-failover/dist/entry.d.ts +8 -0
  100. package/bundled-plugins/provider-failover/dist/entry.d.ts.map +1 -0
  101. package/bundled-plugins/provider-failover/dist/entry.js +8 -0
  102. package/bundled-plugins/provider-failover/dist/entry.js.map +1 -0
  103. package/bundled-plugins/provider-failover/dist/provider-failover.d.ts +122 -0
  104. package/bundled-plugins/provider-failover/dist/provider-failover.d.ts.map +1 -0
  105. package/{dist/core/extensions → bundled-plugins/provider-failover/dist}/provider-failover.js +149 -61
  106. package/bundled-plugins/provider-failover/dist/provider-failover.js.map +1 -0
  107. package/bundled-plugins/provider-failover/plugin.json +7 -0
  108. package/bundled-plugins/retry-policy/agent-forge.json +19 -0
  109. package/bundled-plugins/retry-policy/dist/entry.d.ts +16 -0
  110. package/bundled-plugins/retry-policy/dist/entry.d.ts.map +1 -0
  111. package/bundled-plugins/retry-policy/dist/entry.js +34 -0
  112. package/bundled-plugins/retry-policy/dist/entry.js.map +1 -0
  113. package/bundled-plugins/retry-policy/plugin.json +10 -0
  114. package/dist/bundle/.build-manifest.json +105 -183
  115. package/dist/bundle/chunks/{anthropic-messages-ALDZBUKI.js → anthropic-messages-PLAKXR73.js} +1 -1
  116. package/dist/bundle/chunks/{azure-openai-responses-A2WJWZFB.js → azure-openai-responses-OUWQ2AZD.js} +1 -1
  117. package/dist/bundle/chunks/{chunk-CIX3FSBK.js → chunk-A3JYRWB6.js} +1 -1
  118. package/dist/bundle/chunks/{chunk-SQFG22WN.js → chunk-AC2FIS4G.js} +1 -1
  119. package/dist/bundle/chunks/chunk-AQLNTW2B.js +664 -0
  120. package/dist/bundle/chunks/chunk-D3ARGZFR.js +13 -0
  121. package/dist/bundle/chunks/{chunk-YJCQVXW5.js → chunk-HTEVUY7F.js} +1 -1
  122. package/dist/bundle/chunks/{chunk-Y7HXTASS.js → chunk-HV64ASMT.js} +1 -1
  123. package/dist/bundle/chunks/chunk-LZOEQITZ.js +855 -0
  124. package/dist/bundle/chunks/{chunk-7ZY7IXZD.js → chunk-TRDNDS6A.js} +1 -1
  125. package/dist/bundle/chunks/chunk-Z72JWUZ4.js +4 -0
  126. package/dist/bundle/chunks/{google-generative-ai-NIB4WONV.js → google-generative-ai-DLII6DAT.js} +1 -1
  127. package/dist/bundle/chunks/{google-vertex-DCPYUEUO.js → google-vertex-G7BZL7GM.js} +1 -1
  128. package/dist/bundle/chunks/image-resize-worker.js +3 -3
  129. package/dist/bundle/chunks/{mistral-conversations-OC6LA5XL.js → mistral-conversations-JXUK24ID.js} +1 -1
  130. package/dist/bundle/chunks/{openai-codex-responses-IO2X4Y7L.js → openai-codex-responses-5GSGFIPG.js} +1 -1
  131. package/dist/bundle/chunks/{openai-completions-XYQQHETU.js → openai-completions-EI2I6DTG.js} +1 -1
  132. package/dist/bundle/chunks/{openai-responses-DLIRN3CI.js → openai-responses-AUJQ3NWT.js} +1 -1
  133. package/dist/bundle/chunks/{pi-messages-E6RRYBO7.js → pi-messages-PWU2VJMR.js} +1 -1
  134. package/dist/bundle/chunks/virtual-modules-WF6WRHP7.js +5 -0
  135. package/dist/bundle/cli.js +1 -1
  136. package/dist/bundle/client.js +1 -1
  137. package/dist/bundle/index.js +3 -3
  138. package/dist/bundle/rpc-entry.js +1 -1
  139. package/dist/capabilities/builtin.d.ts +1 -1
  140. package/dist/capabilities/builtin.d.ts.map +1 -1
  141. package/dist/capabilities/builtin.js +5 -0
  142. package/dist/capabilities/builtin.js.map +1 -1
  143. package/dist/cli/auth-check.d.ts.map +1 -1
  144. package/dist/cli/auth-check.js +14 -2
  145. package/dist/cli/auth-check.js.map +1 -1
  146. package/dist/cli/auth-command.d.ts.map +1 -1
  147. package/dist/cli/auth-command.js +1 -1
  148. package/dist/cli/auth-command.js.map +1 -1
  149. package/dist/cli/plugin-command.d.ts.map +1 -1
  150. package/dist/cli/plugin-command.js +17 -1
  151. package/dist/cli/plugin-command.js.map +1 -1
  152. package/dist/config.d.ts +2 -3
  153. package/dist/config.d.ts.map +1 -1
  154. package/dist/config.js +5 -6
  155. package/dist/config.js.map +1 -1
  156. package/dist/core/agent-session-bash.d.ts +1 -1
  157. package/dist/core/agent-session-bash.d.ts.map +1 -1
  158. package/dist/core/agent-session-bash.js +1 -1
  159. package/dist/core/agent-session-bash.js.map +1 -1
  160. package/dist/core/agent-session-compaction.d.ts +6 -10
  161. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  162. package/dist/core/agent-session-compaction.js +21 -112
  163. package/dist/core/agent-session-compaction.js.map +1 -1
  164. package/dist/core/agent-session-internal.d.ts +1 -7
  165. package/dist/core/agent-session-internal.d.ts.map +1 -1
  166. package/dist/core/agent-session-internal.js.map +1 -1
  167. package/dist/core/agent-session-loop.d.ts +4 -3
  168. package/dist/core/agent-session-loop.d.ts.map +1 -1
  169. package/dist/core/agent-session-loop.js +9 -6
  170. package/dist/core/agent-session-loop.js.map +1 -1
  171. package/dist/core/agent-session-retry.d.ts +1 -1
  172. package/dist/core/agent-session-retry.d.ts.map +1 -1
  173. package/dist/core/agent-session-retry.js +32 -4
  174. package/dist/core/agent-session-retry.js.map +1 -1
  175. package/dist/core/agent-session-services.d.ts.map +1 -1
  176. package/dist/core/agent-session-services.js +30 -9
  177. package/dist/core/agent-session-services.js.map +1 -1
  178. package/dist/core/agent-session-tools.d.ts.map +1 -1
  179. package/dist/core/agent-session-tools.js +5 -1
  180. package/dist/core/agent-session-tools.js.map +1 -1
  181. package/dist/core/agent-session.d.ts +12 -33
  182. package/dist/core/agent-session.d.ts.map +1 -1
  183. package/dist/core/agent-session.js +61 -67
  184. package/dist/core/agent-session.js.map +1 -1
  185. package/dist/core/bash-executor.d.ts +1 -1
  186. package/dist/core/bash-executor.d.ts.map +1 -1
  187. package/dist/core/bash-executor.js.map +1 -1
  188. package/dist/core/extensions/bootstrap-agent-loop.d.ts +23 -151
  189. package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
  190. package/dist/core/extensions/bootstrap-agent-loop.js +28 -290
  191. package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
  192. package/dist/core/extensions/capability-runtime-types.d.ts +5 -3
  193. package/dist/core/extensions/capability-runtime-types.d.ts.map +1 -1
  194. package/dist/core/extensions/capability-runtime-types.js.map +1 -1
  195. package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
  196. package/dist/core/extensions/capability-runtime.js +42 -6
  197. package/dist/core/extensions/capability-runtime.js.map +1 -1
  198. package/dist/core/extensions/index.d.ts +12 -5
  199. package/dist/core/extensions/index.d.ts.map +1 -1
  200. package/dist/core/extensions/index.js +12 -5
  201. package/dist/core/extensions/index.js.map +1 -1
  202. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  203. package/dist/core/extensions/virtual-modules.js +65 -0
  204. package/dist/core/extensions/virtual-modules.js.map +1 -1
  205. package/dist/core/facade/coding-agent-facade.d.ts +1 -7
  206. package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
  207. package/dist/core/facade/coding-agent-facade.js +0 -3
  208. package/dist/core/facade/coding-agent-facade.js.map +1 -1
  209. package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -1
  210. package/dist/core/i18n/locales/zh-cn/cli.js +3 -1
  211. package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -1
  212. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +1 -1
  213. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -1
  214. package/dist/core/i18n/locales/zh-cn/core-contract-core.js +1 -1
  215. package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -1
  216. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -1
  217. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +2 -4
  218. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -1
  219. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -1
  220. package/dist/core/i18n/locales/zh-cn/core-errors.js +3 -1
  221. package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -1
  222. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -1
  223. package/dist/core/i18n/locales/zh-cn/interactive-mode.js +2 -0
  224. package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -1
  225. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts.map +1 -1
  226. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js +0 -2
  227. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js.map +1 -1
  228. package/dist/core/model-config.d.ts +0 -1
  229. package/dist/core/model-config.d.ts.map +1 -1
  230. package/dist/core/model-config.js +9 -1
  231. package/dist/core/model-config.js.map +1 -1
  232. package/dist/core/model-runtime.d.ts.map +1 -1
  233. package/dist/core/model-runtime.js +3 -3
  234. package/dist/core/model-runtime.js.map +1 -1
  235. package/dist/core/provider-composer.d.ts +2 -2
  236. package/dist/core/provider-composer.d.ts.map +1 -1
  237. package/dist/core/provider-composer.js +7 -8
  238. package/dist/core/provider-composer.js.map +1 -1
  239. package/dist/core/sdk.d.ts +18 -3
  240. package/dist/core/sdk.d.ts.map +1 -1
  241. package/dist/core/sdk.js +267 -76
  242. package/dist/core/sdk.js.map +1 -1
  243. package/dist/core/settings-manager.d.ts +9 -20
  244. package/dist/core/settings-manager.d.ts.map +1 -1
  245. package/dist/core/settings-manager.js +20 -54
  246. package/dist/core/settings-manager.js.map +1 -1
  247. package/dist/core/tools/bash-operations.d.ts +41 -0
  248. package/dist/core/tools/bash-operations.d.ts.map +1 -0
  249. package/dist/core/tools/bash-operations.js +113 -0
  250. package/dist/core/tools/bash-operations.js.map +1 -0
  251. package/dist/core/tools/index.d.ts +12 -36
  252. package/dist/core/tools/index.d.ts.map +1 -1
  253. package/dist/core/tools/index.js +1 -117
  254. package/dist/core/tools/index.js.map +1 -1
  255. package/dist/core/tools/readme-path.d.ts +3 -0
  256. package/dist/core/tools/readme-path.d.ts.map +1 -0
  257. package/dist/core/tools/readme-path.js +15 -0
  258. package/dist/core/tools/readme-path.js.map +1 -0
  259. package/dist/index.d.ts +3 -19
  260. package/dist/index.d.ts.map +1 -1
  261. package/dist/index.js +6 -39
  262. package/dist/index.js.map +1 -1
  263. package/dist/main.d.ts.map +1 -1
  264. package/dist/main.js +3 -2
  265. package/dist/main.js.map +1 -1
  266. package/dist/modes/interactive/components/footer.d.ts +0 -2
  267. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  268. package/dist/modes/interactive/components/footer.js +2 -7
  269. package/dist/modes/interactive/components/footer.js.map +1 -1
  270. package/dist/modes/interactive/components/settings-selector.d.ts +2 -6
  271. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  272. package/dist/modes/interactive/components/settings-selector.js +6 -28
  273. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  274. package/dist/modes/interactive/components/tool-execution.d.ts +0 -1
  275. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  276. package/dist/modes/interactive/components/tool-execution.js +9 -25
  277. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  278. package/dist/modes/interactive/interactive-mode.d.ts +0 -1
  279. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  280. package/dist/modes/interactive/interactive-mode.js +23 -36
  281. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  282. package/dist/modes/rpc/rpc-client.d.ts +0 -8
  283. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  284. package/dist/modes/rpc/rpc-client.js +0 -12
  285. package/dist/modes/rpc/rpc-client.js.map +1 -1
  286. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  287. package/dist/modes/rpc/rpc-mode.js +0 -9
  288. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  289. package/dist/modes/rpc/rpc-types.d.ts +0 -19
  290. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  291. package/dist/modes/rpc/rpc-types.js.map +1 -1
  292. package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
  293. package/dist/plugins/ecosystem/cli.js +14 -2
  294. package/dist/plugins/ecosystem/cli.js.map +1 -1
  295. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts +7 -2
  296. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
  297. package/dist/plugins/ecosystem/node-npm-registry-source.js +64 -9
  298. package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
  299. package/dist/plugins/ecosystem/node-plugin-acquisition-host.d.ts.map +1 -1
  300. package/dist/plugins/ecosystem/node-plugin-acquisition-host.js +6 -0
  301. package/dist/plugins/ecosystem/node-plugin-acquisition-host.js.map +1 -1
  302. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +9 -2
  303. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  304. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +23 -0
  305. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  306. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +9 -1
  307. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
  308. package/dist/plugins/ecosystem/plugin-bootstrap.js +5 -0
  309. package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
  310. package/dist/profiles/builtin-suites.d.ts +5 -1
  311. package/dist/profiles/builtin-suites.d.ts.map +1 -1
  312. package/dist/profiles/builtin-suites.js +6 -1
  313. package/dist/profiles/builtin-suites.js.map +1 -1
  314. package/dist/utils/photon.d.ts +2 -2
  315. package/dist/utils/photon.d.ts.map +1 -1
  316. package/dist/utils/photon.js +2 -2
  317. package/dist/utils/photon.js.map +1 -1
  318. package/docs/compaction.md +1 -3
  319. package/docs/docs.json +4 -0
  320. package/docs/index.md +1 -0
  321. package/docs/mcp.md +103 -0
  322. package/docs/models.md +14 -22
  323. package/docs/providers.md +0 -1
  324. package/docs/rpc.md +1 -26
  325. package/docs/sdk.md +4 -6
  326. package/docs/settings.md +9 -12
  327. package/docs/skills.md +1 -9
  328. package/docs/usage.md +1 -1
  329. package/examples/extensions/bash-spawn-hook/index.ts +7 -2
  330. package/examples/extensions/built-in-tool-renderer/index.ts +4 -2
  331. package/examples/extensions/minimal-mode/index.ts +2 -2
  332. package/examples/extensions/truncated-tool/index.ts +1 -1
  333. package/examples/extensions/with-deps/package-lock.json +2 -2
  334. package/examples/extensions/with-deps/package.json +1 -1
  335. package/examples/extensions/with-deps/plugin.json +1 -1
  336. package/examples/sdk/10-settings.ts +2 -4
  337. package/examples/sdk/12-full-control.ts +1 -2
  338. package/package.json +3 -4
  339. package/dist/bundle/chunks/chunk-6ZKDNZHA.js +0 -145
  340. package/dist/bundle/chunks/chunk-BFC2BDVJ.js +0 -13
  341. package/dist/bundle/chunks/chunk-MOHOLL3F.js +0 -1456
  342. package/dist/bundle/chunks/virtual-modules-KZ5DRH7Q.js +0 -2
  343. package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts +0 -7
  344. package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts.map +0 -1
  345. package/dist/core/extensions/bootstrap-branch-summary-policy.js +0 -28
  346. package/dist/core/extensions/bootstrap-branch-summary-policy.js.map +0 -1
  347. package/dist/core/extensions/bootstrap-compaction-policy.d.ts +0 -7
  348. package/dist/core/extensions/bootstrap-compaction-policy.d.ts.map +0 -1
  349. package/dist/core/extensions/bootstrap-compaction-policy.js +0 -82
  350. package/dist/core/extensions/bootstrap-compaction-policy.js.map +0 -1
  351. package/dist/core/extensions/bootstrap-overflow-policy.d.ts +0 -7
  352. package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +0 -1
  353. package/dist/core/extensions/bootstrap-overflow-policy.js +0 -30
  354. package/dist/core/extensions/bootstrap-overflow-policy.js.map +0 -1
  355. package/dist/core/extensions/bootstrap-retry-policy.d.ts +0 -7
  356. package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +0 -1
  357. package/dist/core/extensions/bootstrap-retry-policy.js +0 -29
  358. package/dist/core/extensions/bootstrap-retry-policy.js.map +0 -1
  359. package/dist/core/extensions/bootstrap-tools.d.ts +0 -20
  360. package/dist/core/extensions/bootstrap-tools.d.ts.map +0 -1
  361. package/dist/core/extensions/bootstrap-tools.js +0 -36
  362. package/dist/core/extensions/bootstrap-tools.js.map +0 -1
  363. package/dist/core/extensions/microcompact.d.ts +0 -80
  364. package/dist/core/extensions/microcompact.d.ts.map +0 -1
  365. package/dist/core/extensions/microcompact.js +0 -134
  366. package/dist/core/extensions/microcompact.js.map +0 -1
  367. package/dist/core/extensions/provider-failover.d.ts +0 -106
  368. package/dist/core/extensions/provider-failover.d.ts.map +0 -1
  369. package/dist/core/extensions/provider-failover.js.map +0 -1
  370. package/dist/core/tools/bash.d.ts.map +0 -1
  371. package/dist/core/tools/bash.js.map +0 -1
  372. package/dist/core/tools/edit.d.ts.map +0 -1
  373. package/dist/core/tools/edit.js.map +0 -1
  374. package/dist/core/tools/find.d.ts.map +0 -1
  375. package/dist/core/tools/find.js.map +0 -1
  376. package/dist/core/tools/grep.d.ts.map +0 -1
  377. package/dist/core/tools/grep.js.map +0 -1
  378. package/dist/core/tools/ls.d.ts.map +0 -1
  379. package/dist/core/tools/powershell.d.ts.map +0 -1
  380. package/dist/core/tools/powershell.js.map +0 -1
  381. package/dist/core/tools/read.d.ts.map +0 -1
  382. package/dist/core/tools/read.js.map +0 -1
  383. package/dist/core/tools/write.d.ts.map +0 -1
  384. package/dist/core/tools/write.js.map +0 -1
  385. package/dist/plugins/mcp-http.d.ts.map +0 -1
  386. package/dist/plugins/mcp-http.js.map +0 -1
  387. package/dist/profile/child-facade.d.ts +0 -44
  388. package/dist/profile/child-facade.d.ts.map +0 -1
  389. package/dist/profile/child-facade.js +0 -56
  390. package/dist/profile/child-facade.js.map +0 -1
  391. package/dist/profile/dependency-wiring.d.ts +0 -48
  392. package/dist/profile/dependency-wiring.d.ts.map +0 -1
  393. package/dist/profile/dependency-wiring.js +0 -56
  394. package/dist/profile/dependency-wiring.js.map +0 -1
  395. package/dist/profile/domain-recovery.d.ts +0 -60
  396. package/dist/profile/domain-recovery.d.ts.map +0 -1
  397. package/dist/profile/domain-recovery.js +0 -94
  398. package/dist/profile/domain-recovery.js.map +0 -1
  399. package/dist/profile/first-roles.d.ts +0 -30
  400. package/dist/profile/first-roles.d.ts.map +0 -1
  401. package/dist/profile/first-roles.js +0 -83
  402. package/dist/profile/first-roles.js.map +0 -1
  403. package/dist/profile/goal-plugin.d.ts +0 -38
  404. package/dist/profile/goal-plugin.d.ts.map +0 -1
  405. package/dist/profile/goal-plugin.js +0 -132
  406. package/dist/profile/goal-plugin.js.map +0 -1
  407. package/dist/profile/plan-plugin.d.ts +0 -44
  408. package/dist/profile/plan-plugin.d.ts.map +0 -1
  409. package/dist/profile/plan-plugin.js +0 -157
  410. package/dist/profile/plan-plugin.js.map +0 -1
  411. package/dist/profile/policy-manifest.d.ts +0 -53
  412. package/dist/profile/policy-manifest.d.ts.map +0 -1
  413. package/dist/profile/policy-manifest.js +0 -53
  414. package/dist/profile/policy-manifest.js.map +0 -1
  415. package/dist/profile/role-assembly.d.ts +0 -47
  416. package/dist/profile/role-assembly.d.ts.map +0 -1
  417. package/dist/profile/role-assembly.js +0 -31
  418. package/dist/profile/role-assembly.js.map +0 -1
  419. package/dist/profile/role-catalog.d.ts +0 -43
  420. package/dist/profile/role-catalog.d.ts.map +0 -1
  421. package/dist/profile/role-catalog.js +0 -132
  422. package/dist/profile/role-catalog.js.map +0 -1
  423. package/dist/profile/role-orchestrator.d.ts +0 -123
  424. package/dist/profile/role-orchestrator.d.ts.map +0 -1
  425. package/dist/profile/role-orchestrator.js +0 -195
  426. package/dist/profile/role-orchestrator.js.map +0 -1
  427. package/dist/profile/role-runner.d.ts +0 -99
  428. package/dist/profile/role-runner.d.ts.map +0 -1
  429. package/dist/profile/role-runner.js +0 -79
  430. package/dist/profile/role-runner.js.map +0 -1
  431. package/dist/profile/root-facade.d.ts +0 -36
  432. package/dist/profile/root-facade.d.ts.map +0 -1
  433. package/dist/profile/root-facade.js +0 -49
  434. package/dist/profile/root-facade.js.map +0 -1
  435. package/dist/profile/skill-discovery-wiring.d.ts +0 -58
  436. package/dist/profile/skill-discovery-wiring.d.ts.map +0 -1
  437. package/dist/profile/skill-discovery-wiring.js +0 -80
  438. package/dist/profile/skill-discovery-wiring.js.map +0 -1
  439. package/dist/profile/state-store.d.ts +0 -62
  440. package/dist/profile/state-store.d.ts.map +0 -1
  441. package/dist/profile/state-store.js +0 -144
  442. package/dist/profile/state-store.js.map +0 -1
  443. package/dist/profile/todo-plugin.d.ts +0 -37
  444. package/dist/profile/todo-plugin.d.ts.map +0 -1
  445. package/dist/profile/todo-plugin.js +0 -137
  446. package/dist/profile/todo-plugin.js.map +0 -1
  447. package/dist/server/create-harness.d.ts +0 -26
  448. package/dist/server/create-harness.d.ts.map +0 -1
  449. package/dist/server/create-harness.js +0 -106
  450. package/dist/server/create-harness.js.map +0 -1
  451. /package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.d.ts +0 -0
@@ -1,132 +0,0 @@
1
- /**
2
- * Role metadata catalog (2.2a).
3
- *
4
- * Role metadata is DISCOVERY data, not a security policy: roleId, input/output
5
- * schema references, capability dependencies, writable memory scopes,
6
- * concurrency, and completion criteria are all discoverable through the
7
- * catalog. Registered roles are validated and served as detached, frozen
8
- * snapshots.
9
- */
10
- /** Memory scopes a role may write to (aligned with the 1C.1b store scopes). */
11
- import { t } from "../core/i18n/index.js";
12
- const WRITABLE_SCOPES = ["session", "cycle", "long-term"];
13
- function assertNonEmptyString(value, label) {
14
- if (typeof value !== "string" || value.trim().length === 0)
15
- throw new Error(t("{label} must be a non-empty string", { label }));
16
- }
17
- function assertIOSchemaRef(value, label) {
18
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
19
- throw new Error(t("{label} must be a plain object", { label }));
20
- }
21
- const record = value;
22
- assertNonEmptyString(record.schemaId, `${label}.schemaId`);
23
- if (typeof record.schemaVersion !== "number" ||
24
- !Number.isSafeInteger(record.schemaVersion) ||
25
- record.schemaVersion < 1) {
26
- throw new Error(t("{label}.schemaVersion must be a positive safe integer", { label }));
27
- }
28
- return Object.freeze({ schemaId: record.schemaId, schemaVersion: record.schemaVersion });
29
- }
30
- /** Validates role metadata and returns a detached, frozen snapshot. */
31
- export function validateRoleMetadataV1(value) {
32
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
33
- throw new Error(t("Role metadata must be a plain object"));
34
- }
35
- const record = value;
36
- const required = [
37
- "roleId",
38
- "title",
39
- "input",
40
- "output",
41
- "capabilityDependencies",
42
- "writableScopes",
43
- "concurrency",
44
- "completionCriteria",
45
- ];
46
- for (const key of required) {
47
- if (!(key in record))
48
- throw new Error(t("Role metadata is missing required field: {key}", { key }));
49
- }
50
- const unsupported = Object.keys(record)
51
- .filter((key) => !required.includes(key))
52
- .sort();
53
- if (unsupported.length > 0)
54
- throw new Error(t("Role metadata has unsupported fields: {fields}", { fields: unsupported.join(", ") }));
55
- assertNonEmptyString(record.roleId, "Role metadata.roleId");
56
- assertNonEmptyString(record.title, "Role metadata.title");
57
- const input = assertIOSchemaRef(record.input, "Role metadata.input");
58
- const output = assertIOSchemaRef(record.output, "Role metadata.output");
59
- if (!Array.isArray(record.capabilityDependencies)) {
60
- throw new Error(t("Role metadata.capabilityDependencies must be an array"));
61
- }
62
- const capabilityDependencies = record.capabilityDependencies.map((item, index) => {
63
- const depLabel = `Role metadata.capabilityDependencies[${index}]`;
64
- if (item === null || typeof item !== "object" || Array.isArray(item)) {
65
- throw new Error(t("{label} must be a plain object", { label: depLabel }));
66
- }
67
- const dep = item;
68
- assertNonEmptyString(dep.capabilityId, `${depLabel}.capabilityId`);
69
- if (typeof dep.capabilityVersion !== "number" ||
70
- !Number.isSafeInteger(dep.capabilityVersion) ||
71
- dep.capabilityVersion < 1) {
72
- throw new Error(t("{label}.capabilityVersion must be a positive safe integer", { label: depLabel }));
73
- }
74
- if (typeof dep.required !== "boolean")
75
- throw new Error(t("{label}.required must be boolean", { label: depLabel }));
76
- return Object.freeze({
77
- capabilityId: dep.capabilityId,
78
- capabilityVersion: dep.capabilityVersion,
79
- required: dep.required,
80
- });
81
- });
82
- if (!Array.isArray(record.writableScopes))
83
- throw new Error(t("Role metadata.writableScopes must be an array"));
84
- for (const [index, scope] of record.writableScopes.entries()) {
85
- if (!WRITABLE_SCOPES.includes(scope)) {
86
- throw new Error(t("Role metadata.writableScopes[{index}] is invalid", { index }));
87
- }
88
- }
89
- assertNonEmptyString(record.completionCriteria, "Role metadata.completionCriteria");
90
- if (record.concurrency !== "single" && record.concurrency !== "parallel") {
91
- throw new Error(t("Role metadata.concurrency is invalid"));
92
- }
93
- return Object.freeze({
94
- roleId: record.roleId,
95
- title: record.title,
96
- input,
97
- output,
98
- capabilityDependencies: Object.freeze(capabilityDependencies),
99
- writableScopes: Object.freeze([...record.writableScopes]),
100
- concurrency: record.concurrency,
101
- completionCriteria: record.completionCriteria,
102
- });
103
- }
104
- /** Discoverable role catalog: register, get, list (sorted), find by capability. */
105
- export function createRoleCatalog(initial = []) {
106
- const roles = new Map();
107
- for (const metadata of initial) {
108
- const validated = validateRoleMetadataV1(metadata);
109
- if (roles.has(validated.roleId))
110
- throw new Error(t("Role already registered: {roleId}", { roleId: validated.roleId }));
111
- roles.set(validated.roleId, validated);
112
- }
113
- return {
114
- register(metadata) {
115
- const validated = validateRoleMetadataV1(metadata);
116
- if (roles.has(validated.roleId))
117
- throw new Error(t("Role already registered: {roleId}", { roleId: validated.roleId }));
118
- roles.set(validated.roleId, validated);
119
- return validated;
120
- },
121
- get(roleId) {
122
- return roles.get(roleId);
123
- },
124
- list() {
125
- return Object.freeze([...roles.values()].sort((left, right) => left.roleId.localeCompare(right.roleId)));
126
- },
127
- findByCapability(capabilityId) {
128
- return Object.freeze([...roles.values()].filter((role) => role.capabilityDependencies.some((dependency) => dependency.capabilityId === capabilityId)));
129
- },
130
- };
131
- }
132
- //# sourceMappingURL=role-catalog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"role-catalog.js","sourceRoot":"","sources":["../../src/profile/role-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,+EAA+E;AAC/E,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAoC1C,MAAM,eAAe,GAAmC,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AAE1F,SAAS,oBAAoB,CAAC,KAAc,EAAE,KAAa,EAA2B;IACrF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,oCAAoC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAAA,CACrE;AAED,SAAS,iBAAiB,CAA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AE;YAClB,MAAM,SAAS,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;YACnD,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,mCAAmC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACvF,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACvC,OAAO,SAAS,CAAC;QAAA,CACjB;QACD,GAAG,CAAC,MAAM,EAAE;YACX,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAAA,CACzB;QACD,IAAI,GAAG;YACN,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAAA,CACzG;QACD,gBAAgB,CAAC,YAAY,EAAE;YAC9B,OAAO,MAAM,CAAC,MAAM,CACnB,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CACnC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,YAAY,KAAK,YAAY,CAAC,CAC1F,CACD,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Role metadata catalog (2.2a).\n *\n * Role metadata is DISCOVERY data, not a security policy: roleId, input/output\n * schema references, capability dependencies, writable memory scopes,\n * concurrency, and completion criteria are all discoverable through the\n * catalog. Registered roles are validated and served as detached, frozen\n * snapshots.\n */\n\n/** Memory scopes a role may write to (aligned with the 1C.1b store scopes). */\nimport { t } from \"../core/i18n/index.ts\";\n\nexport type RoleWritableScopeV1 = \"session\" | \"cycle\" | \"long-term\";\n\nexport interface RoleCapabilityDependencyV1 {\n\treadonly capabilityId: string;\n\treadonly capabilityVersion: number;\n\t/** Required dependencies fail role activation when missing. */\n\treadonly required: boolean;\n}\n\n/** Versioned input/output schema reference (schema bodies live with the domain plugin). */\nexport interface RoleIOSchemaRefV1 {\n\treadonly schemaId: string;\n\treadonly schemaVersion: number;\n}\n\nexport interface RoleMetadataV1 {\n\treadonly roleId: string;\n\treadonly title: string;\n\treadonly input: RoleIOSchemaRefV1;\n\treadonly output: RoleIOSchemaRefV1;\n\treadonly capabilityDependencies: readonly RoleCapabilityDependencyV1[];\n\treadonly writableScopes: readonly RoleWritableScopeV1[];\n\treadonly concurrency: \"single\" | \"parallel\";\n\treadonly completionCriteria: string;\n}\n\nexport interface RoleCatalogV1 {\n\tregister(metadata: RoleMetadataV1): RoleMetadataV1;\n\tget(roleId: string): RoleMetadataV1 | undefined;\n\tlist(): readonly RoleMetadataV1[];\n\t/** Roles declaring the given capability as a dependency (required or optional). */\n\tfindByCapability(capabilityId: string): readonly RoleMetadataV1[];\n}\n\nconst WRITABLE_SCOPES: readonly RoleWritableScopeV1[] = [\"session\", \"cycle\", \"long-term\"];\n\nfunction assertNonEmptyString(value: unknown, label: string): asserts value is string {\n\tif (typeof value !== \"string\" || value.trim().length === 0)\n\t\tthrow new Error(t(\"{label} must be a non-empty string\", { label }));\n}\n\nfunction assertIOSchemaRef(value: unknown, label: string): RoleIOSchemaRefV1 {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(t(\"{label} must be a plain object\", { label }));\n\t}\n\tconst record = value as Record<string, unknown>;\n\tassertNonEmptyString(record.schemaId, `${label}.schemaId`);\n\tif (\n\t\ttypeof record.schemaVersion !== \"number\" ||\n\t\t!Number.isSafeInteger(record.schemaVersion) ||\n\t\trecord.schemaVersion < 1\n\t) {\n\t\tthrow new Error(t(\"{label}.schemaVersion must be a positive safe integer\", { label }));\n\t}\n\treturn Object.freeze({ schemaId: record.schemaId, schemaVersion: record.schemaVersion });\n}\n\n/** Validates role metadata and returns a detached, frozen snapshot. */\nexport function validateRoleMetadataV1(value: unknown): RoleMetadataV1 {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(t(\"Role metadata must be a plain object\"));\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst required = [\n\t\t\"roleId\",\n\t\t\"title\",\n\t\t\"input\",\n\t\t\"output\",\n\t\t\"capabilityDependencies\",\n\t\t\"writableScopes\",\n\t\t\"concurrency\",\n\t\t\"completionCriteria\",\n\t];\n\tfor (const key of required) {\n\t\tif (!(key in record)) throw new Error(t(\"Role metadata is missing required field: {key}\", { key }));\n\t}\n\tconst unsupported = Object.keys(record)\n\t\t.filter((key) => !required.includes(key))\n\t\t.sort();\n\tif (unsupported.length > 0)\n\t\tthrow new Error(t(\"Role metadata has unsupported fields: {fields}\", { fields: unsupported.join(\", \") }));\n\n\tassertNonEmptyString(record.roleId, \"Role metadata.roleId\");\n\tassertNonEmptyString(record.title, \"Role metadata.title\");\n\tconst input = assertIOSchemaRef(record.input, \"Role metadata.input\");\n\tconst output = assertIOSchemaRef(record.output, \"Role metadata.output\");\n\n\tif (!Array.isArray(record.capabilityDependencies)) {\n\t\tthrow new Error(t(\"Role metadata.capabilityDependencies must be an array\"));\n\t}\n\tconst capabilityDependencies = record.capabilityDependencies.map((item, index) => {\n\t\tconst depLabel = `Role metadata.capabilityDependencies[${index}]`;\n\t\tif (item === null || typeof item !== \"object\" || Array.isArray(item)) {\n\t\t\tthrow new Error(t(\"{label} must be a plain object\", { label: depLabel }));\n\t\t}\n\t\tconst dep = item as Record<string, unknown>;\n\t\tassertNonEmptyString(dep.capabilityId, `${depLabel}.capabilityId`);\n\t\tif (\n\t\t\ttypeof dep.capabilityVersion !== \"number\" ||\n\t\t\t!Number.isSafeInteger(dep.capabilityVersion) ||\n\t\t\tdep.capabilityVersion < 1\n\t\t) {\n\t\t\tthrow new Error(t(\"{label}.capabilityVersion must be a positive safe integer\", { label: depLabel }));\n\t\t}\n\t\tif (typeof dep.required !== \"boolean\")\n\t\t\tthrow new Error(t(\"{label}.required must be boolean\", { label: depLabel }));\n\t\treturn Object.freeze({\n\t\t\tcapabilityId: dep.capabilityId,\n\t\t\tcapabilityVersion: dep.capabilityVersion,\n\t\t\trequired: dep.required,\n\t\t});\n\t});\n\n\tif (!Array.isArray(record.writableScopes)) throw new Error(t(\"Role metadata.writableScopes must be an array\"));\n\tfor (const [index, scope] of record.writableScopes.entries()) {\n\t\tif (!WRITABLE_SCOPES.includes(scope as RoleWritableScopeV1)) {\n\t\t\tthrow new Error(t(\"Role metadata.writableScopes[{index}] is invalid\", { index }));\n\t\t}\n\t}\n\tassertNonEmptyString(record.completionCriteria, \"Role metadata.completionCriteria\");\n\tif (record.concurrency !== \"single\" && record.concurrency !== \"parallel\") {\n\t\tthrow new Error(t(\"Role metadata.concurrency is invalid\"));\n\t}\n\n\treturn Object.freeze({\n\t\troleId: record.roleId,\n\t\ttitle: record.title,\n\t\tinput,\n\t\toutput,\n\t\tcapabilityDependencies: Object.freeze(capabilityDependencies),\n\t\twritableScopes: Object.freeze([...(record.writableScopes as readonly RoleWritableScopeV1[])]),\n\t\tconcurrency: record.concurrency as RoleMetadataV1[\"concurrency\"],\n\t\tcompletionCriteria: record.completionCriteria,\n\t});\n}\n\n/** Discoverable role catalog: register, get, list (sorted), find by capability. */\nexport function createRoleCatalog(initial: readonly RoleMetadataV1[] = []): RoleCatalogV1 {\n\tconst roles = new Map<string, RoleMetadataV1>();\n\tfor (const metadata of initial) {\n\t\tconst validated = validateRoleMetadataV1(metadata);\n\t\tif (roles.has(validated.roleId))\n\t\t\tthrow new Error(t(\"Role already registered: {roleId}\", { roleId: validated.roleId }));\n\t\troles.set(validated.roleId, validated);\n\t}\n\treturn {\n\t\tregister(metadata) {\n\t\t\tconst validated = validateRoleMetadataV1(metadata);\n\t\t\tif (roles.has(validated.roleId))\n\t\t\t\tthrow new Error(t(\"Role already registered: {roleId}\", { roleId: validated.roleId }));\n\t\t\troles.set(validated.roleId, validated);\n\t\t\treturn validated;\n\t\t},\n\t\tget(roleId) {\n\t\t\treturn roles.get(roleId);\n\t\t},\n\t\tlist() {\n\t\t\treturn Object.freeze([...roles.values()].sort((left, right) => left.roleId.localeCompare(right.roleId)));\n\t\t},\n\t\tfindByCapability(capabilityId) {\n\t\t\treturn Object.freeze(\n\t\t\t\t[...roles.values()].filter((role) =>\n\t\t\t\t\trole.capabilityDependencies.some((dependency) => dependency.capabilityId === capabilityId),\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n"]}
@@ -1,123 +0,0 @@
1
- /**
2
- * Role orchestrator (2.2e) — root-side concurrent orchestration of registered
3
- * roles with bounded aggregation.
4
- *
5
- * Spawns one child per requested roleId through the public
6
- * `AgentCompositionAPI` (create/lease/run/wait bound to the root via
7
- * `parentInstanceId`), honoring the role's `RoleMetadataV1.concurrency`
8
- * metadata: `parallel` roles run concurrently, `single` roles execute one at
9
- * a time in stable roleId order. Aggregation reuses the multi-agent-tasks 6.3
10
- * semantics — entries sorted by roleId (never completion order), a per-entry
11
- * byte budget over the JSON-serialized output (`limitBytes`; over-budget
12
- * entries are dropped whole with an explicit `truncated` flag, outputs that
13
- * are absent carry `missing`), and `completionCriteria` metadata checked per
14
- * role into a structured satisfied/unmet/unchecked list (never thrown).
15
- * Child failures are collected, never swallowed: a failed child lands in its
16
- * structured entry while the orchestration still resolves (fail-collect at
17
- * the orchestration level, not fail-fast).
18
- *
19
- * Limit constants: multi-agent-tasks itself has no built-in numeric caps —
20
- * its `limitBytes`/`maxResultBytes` are caller-injected and default to
21
- * unbounded. This contract therefore defaults `limitBytes` to 16 KiB, the
22
- * magnitude of the repo's existing `DEFAULT_MAX_RESULT_BYTES_V1` (office
23
- * writer). No separate entry cap is added: the multi-agent-tasks aggregate
24
- * has none either, and the entry count here is already bounded by the
25
- * explicit `roleIds` list.
26
- *
27
- * Honest state-namespace boundary: state namespaces are partitioned per
28
- * plugin owner, not per child instance. Concurrent children therefore do NOT
29
- * get per-instance state isolation under this contract. The deterministic
30
- * injected run callbacks of this milestone never write state, so the boundary
31
- * is not exercised here; concurrent child state writes remain outside this
32
- * contract.
33
- */
34
- import type { AgentCompositionAPI } from "../core/extensions/public-api.ts";
35
- import type { RoleRunCallbackV1, RoleRunnerResultV1, RoleRunnerV1 } from "./role-runner.ts";
36
- /**
37
- * Default aggregation byte budget. The multi-agent-tasks aggregate defaults
38
- * to unbounded (caller-injected limits); this default anchors the contract to
39
- * the repo's existing 16 KiB result-cap magnitude.
40
- */
41
- export declare const DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES: number;
42
- /** Terminal instance states an orchestrated child can settle into. */
43
- export type RoleOrchestrationStatusV1 = "succeeded" | "failed" | "cancelled" | "disposed";
44
- /** One orchestrated child's aggregation entry (sorted by roleId, never completion order). */
45
- export interface RoleOrchestrationEntryV1 {
46
- readonly roleId: string;
47
- readonly definitionId: string;
48
- readonly childInstanceId: string;
49
- /** Terminal revision of the child instance (result reference half, see 2.2b). */
50
- readonly revision: number;
51
- readonly status: RoleOrchestrationStatusV1;
52
- /** The entry's output exceeded the remaining byte budget and was dropped whole. */
53
- readonly truncated: boolean;
54
- /** No output was available (failure, cancellation, disposal, or truncation). */
55
- readonly missing: boolean;
56
- /** Present only for succeeded entries that fit the byte budget. */
57
- readonly result?: RoleRunnerResultV1;
58
- /** Structured failure text; present when the instance settled with an error. */
59
- readonly error?: string;
60
- }
61
- /** Per-role completion-criteria verdict produced at aggregation time (never thrown). */
62
- export interface RoleCompletionCheckV1 {
63
- readonly roleId: string;
64
- readonly criteria: string;
65
- /**
66
- * `satisfied`/`unmet` come from an injected evaluator; `unchecked` means no
67
- * evaluator was available or the entry had no in-budget output to judge.
68
- */
69
- readonly status: "satisfied" | "unmet" | "unchecked";
70
- }
71
- /**
72
- * Deterministic completion evaluator. Returns `true`/`false` for a verdict or
73
- * `undefined` when the criteria cannot be judged from the result.
74
- */
75
- export type RoleCompletionEvaluatorV1 = (input: {
76
- readonly roleId: string;
77
- readonly criteria: string;
78
- readonly result: RoleRunnerResultV1;
79
- }) => boolean | undefined;
80
- /** One orchestration request: explicit roleIds plus one shared spec string. */
81
- export interface RoleOrchestratorRunRequestV1 {
82
- readonly roleIds: readonly string[];
83
- readonly spec: string;
84
- /** Per-role run overrides taking precedence for this request only. */
85
- readonly runs?: readonly {
86
- readonly roleId: string;
87
- readonly run: RoleRunCallbackV1;
88
- }[];
89
- /** Aggregation byte budget for this request (defaults to the orchestrator option). */
90
- readonly limitBytes?: number;
91
- /** Completion evaluator for this request (defaults to the orchestrator option). */
92
- readonly evaluateCompletion?: RoleCompletionEvaluatorV1;
93
- }
94
- export interface RoleOrchestratorOptionsV1 {
95
- readonly composition: AgentCompositionAPI;
96
- readonly runner: RoleRunnerV1;
97
- /** Root instance the children are parented to via `parentInstanceId`. */
98
- readonly parentInstanceId: string;
99
- /** Controller-lease owner for the orchestrated children. */
100
- readonly owner?: string;
101
- /** Default aggregation byte budget (see {@link DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES}). */
102
- readonly limitBytes?: number;
103
- /** Default completion evaluator. Without one every check reports `unchecked`. */
104
- readonly evaluateCompletion?: RoleCompletionEvaluatorV1;
105
- }
106
- /** Orchestration result: bounded aggregation plus completion verdicts. */
107
- export interface RoleOrchestrationResultV1 {
108
- /** One entry per requested role, sorted by roleId (stable, never completion order). */
109
- readonly entries: readonly RoleOrchestrationEntryV1[];
110
- /** True when at least one entry was dropped for exceeding the byte budget. */
111
- readonly truncated: boolean;
112
- /** Completion verdicts per requested role, sorted by roleId. */
113
- readonly completionChecks: readonly RoleCompletionCheckV1[];
114
- }
115
- export interface RoleOrchestratorV1 {
116
- readonly composition: AgentCompositionAPI;
117
- readonly runner: RoleRunnerV1;
118
- readonly parentInstanceId: string;
119
- runRoles(request: RoleOrchestratorRunRequestV1): Promise<RoleOrchestrationResultV1>;
120
- }
121
- /** Creates the root-side concurrent role orchestrator (2.2e). */
122
- export declare function createRoleOrchestrator(options: RoleOrchestratorOptionsV1): RoleOrchestratorV1;
123
- //# sourceMappingURL=role-orchestrator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"role-orchestrator.d.ts","sourceRoot":"","sources":["../../src/profile/role-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAmB,MAAM,kCAAkC,CAAC;AAG7F,OAAO,KAAK,EAAE,iBAAiB,EAAqB,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE/G;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,QAAY,CAAC;AAE9D,sEAAsE;AACtE,MAAM,MAAM,yBAAyB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAC;AAE1F,6FAA6F;AAC7F,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAC3C,mFAAmF;IACnF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IACrC,gFAAgF;IAChF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wFAAwF;AACxF,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,Q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ACzC,uFAAuF;IACvF,QAAQ,CAAC,OAAO,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACtD,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,gBAAgB,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC5D;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,4BAA4B,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;CACpF;AAcD,iEAAiE;AACjE,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB,CA6L7F","sourcesContent":["/**\n * Role orchestrator (2.2e) — root-side concurrent orchestration of registered\n * roles with bounded aggregation.\n *\n * Spawns one child per requested roleId through the public\n * `AgentCompositionAPI` (create/lease/run/wait bound to the root via\n * `parentInstanceId`), honoring the role's `RoleMetadataV1.concurrency`\n * metadata: `parallel` roles run concurrently, `single` roles execute one at\n * a time in stable roleId order. Aggregation reuses the multi-agent-tasks 6.3\n * semantics — entries sorted by roleId (never completion order), a per-entry\n * byte budget over the JSON-serialized output (`limitBytes`; over-budget\n * entries are dropped whole with an explicit `truncated` flag, outputs that\n * are absent carry `missing`), and `completionCriteria` metadata checked per\n * role into a structured satisfied/unmet/unchecked list (never thrown).\n * Child failures are collected, never swallowed: a failed child lands in its\n * structured entry while the orchestration still resolves (fail-collect at\n * the orchestration level, not fail-fast).\n *\n * Limit constants: multi-agent-tasks itself has no built-in numeric caps —\n * its `limitBytes`/`maxResultBytes` are caller-injected and default to\n * unbounded. This contract therefore defaults `limitBytes` to 16 KiB, the\n * magnitude of the repo's existing `DEFAULT_MAX_RESULT_BYTES_V1` (office\n * writer). No separate entry cap is added: the multi-agent-tasks aggregate\n * has none either, and the entry count here is already bounded by the\n * explicit `roleIds` list.\n *\n * Honest state-namespace boundary: state namespaces are partitioned per\n * plugin owner, not per child instance. Concurrent children therefore do NOT\n * get per-instance state isolation under this contract. The deterministic\n * injected run callbacks of this milestone never write state, so the boundary\n * is not exercised here; concurrent child state writes remain outside this\n * contract.\n */\nimport type { AgentCompositionAPI, AgentDefinition } from \"../core/extensions/public-api.ts\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { RoleMetadataV1 } from \"./role-catalog.ts\";\nimport type { RoleRunCallbackV1, RoleRunnerInputV1, RoleRunnerResultV1, RoleRunnerV1 } from \"./role-runner.ts\";\n\n/**\n * Default aggregation byte budget. The multi-agent-tasks aggregate defaults\n * to unbounded (caller-injected limits); this default anchors the contract to\n * the repo's existing 16 KiB result-cap magnitude.\n */\nexport const DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES = 16 * 1024;\n\n/** Terminal instance states an orchestrated child can settle into. */\nexport type RoleOrchestrationStatusV1 = \"succeeded\" | \"failed\" | \"cancelled\" | \"disposed\";\n\n/** One orchestrated child's aggregation entry (sorted by roleId, never completion order). */\nexport interface RoleOrchestrationEntryV1 {\n\treadonly roleId: string;\n\treadonly definitionId: string;\n\treadonly childInstanceId: string;\n\t/** Terminal revision of the child instance (result reference half, see 2.2b). */\n\treadonly revision: number;\n\treadonly status: RoleOrchestrationStatusV1;\n\t/** The entry's output exceeded the remaining byte budget and was dropped whole. */\n\treadonly truncated: boolean;\n\t/** No output was available (failure, cancellation, disposal, or truncation). */\n\treadonly missing: boolean;\n\t/** Present only for succeeded entries that fit the byte budget. */\n\treadonly result?: RoleRunnerResultV1;\n\t/** Structured failure text; present when the instance settled with an error. */\n\treadonly error?: string;\n}\n\n/** Per-role completion-criteria verdict produced at aggregation time (never thrown). */\nexport interface RoleCompletionCheckV1 {\n\treadonly roleId: string;\n\treadonly criteria: string;\n\t/**\n\t * `satisfied`/`unmet` come from an injected evaluator; `unchecked` means no\n\t * evaluator was available or the entry had no in-budget output to judge.\n\t */\n\treadonly status: \"satisfied\" | \"unmet\" | \"unchecked\";\n}\n\n/**\n * Deterministic completion evaluator. Returns `true`/`false` for a verdict or\n * `undefined` when the criteria cannot be judged from the result.\n */\nexport type RoleCompletionEvaluatorV1 = (input: {\n\treadonly roleId: string;\n\treadonly criteria: string;\n\treadonly result: RoleRunnerResultV1;\n}) => boolean | undefined;\n\n/** One orchestration request: explicit roleIds plus one shared spec string. */\nexport interface RoleOrchestratorRunRequestV1 {\n\treadonly roleIds: readonly string[];\n\treadonly spec: string;\n\t/** Per-role run overrides taking precedence for this request only. */\n\treadonly runs?: readonly { readonly roleId: string; readonly run: RoleRunCallbackV1 }[];\n\t/** Aggregation byte budget for this request (defaults to the orchestrator option). */\n\treadonly limitBytes?: number;\n\t/** Completion evaluator for this request (defaults to the orchestrator option). */\n\treadonly evaluateCompletion?: RoleCompletionEvaluatorV1;\n}\n\nexport interface RoleOrchestratorOptionsV1 {\n\treadonly composition: AgentCompositionAPI;\n\treadonly runner: RoleRunnerV1;\n\t/** Root instance the children are parented to via `parentInstanceId`. */\n\treadonly parentInstanceId: string;\n\t/** Controller-lease owner for the orchestrated children. */\n\treadonly owner?: string;\n\t/** Default aggregation byte budget (see {@link DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES}). */\n\treadonly limitBytes?: number;\n\t/** Default completion evaluator. Without one every check reports `unchecked`. */\n\treadonly evaluateCompletion?: RoleCompletionEvaluatorV1;\n}\n\n/** Orchestration result: bounded aggregation plus completion verdicts. */\nexport interface RoleOrchestrationResultV1 {\n\t/** One entry per requested role, sorted by roleId (stable, never completion order). */\n\treadonly entries: readonly RoleOrchestrationEntryV1[];\n\t/** True when at least one entry was dropped for exceeding the byte budget. */\n\treadonly truncated: boolean;\n\t/** Completion verdicts per requested role, sorted by roleId. */\n\treadonly completionChecks: readonly RoleCompletionCheckV1[];\n}\n\nexport interface RoleOrchestratorV1 {\n\treadonly composition: AgentCompositionAPI;\n\treadonly runner: RoleRunnerV1;\n\treadonly parentInstanceId: string;\n\trunRoles(request: RoleOrchestratorRunRequestV1): Promise<RoleOrchestrationResultV1>;\n}\n\nconst DEFAULT_ORCHESTRATION_OWNER = \"role-orchestrator\";\n\ninterface SettledChildV1 {\n\treadonly roleId: string;\n\treadonly definitionId: string;\n\treadonly childInstanceId: string;\n\treadonly revision: number;\n\treadonly status: RoleOrchestrationStatusV1;\n\treadonly output?: RoleRunnerResultV1;\n\treadonly error?: string;\n}\n\n/** Creates the root-side concurrent role orchestrator (2.2e). */\nexport function createRoleOrchestrator(options: RoleOrchestratorOptionsV1): RoleOrchestratorV1 {\n\tconst owner = options.owner ?? DEFAULT_ORCHESTRATION_OWNER;\n\t// Definitions are registered once per roleId and reused across runs: a\n\t// composition instance is single-run, so every orchestration creates fresh\n\t// child instances from the same definitions.\n\tconst definitions = new Map<string, AgentDefinition<RoleRunnerInputV1, RoleRunnerResultV1>>();\n\tlet activeOverrides: ReadonlyMap<string, RoleRunCallbackV1> = new Map();\n\tlet runInFlight = false;\n\n\tfunction requireMetadata(roleId: string): RoleMetadataV1 {\n\t\tconst metadata = options.runner.catalog.get(roleId);\n\t\tif (!metadata) throw new Error(t(\"Unknown role: {roleId}\", { roleId }));\n\t\treturn metadata;\n\t}\n\n\tfunction definitionFor(roleId: string): AgentDefinition<RoleRunnerInputV1, RoleRunnerResultV1> {\n\t\tconst cached = definitions.get(roleId);\n\t\tif (cached) return cached;\n\t\tconst base = options.runner.createDefinition(roleId);\n\t\tconst definition: AgentDefinition<RoleRunnerInputV1, RoleRunnerResultV1> = {\n\t\t\t...base,\n\t\t\trun: (input, context) => {\n\t\t\t\tconst override = activeOverrides.get(roleId);\n\t\t\t\treturn override ? override(input, context) : options.runner.run(roleId, input, context);\n\t\t\t},\n\t\t};\n\t\tconst registered = options.composition.define(definition);\n\t\tdefinitions.set(roleId, registered);\n\t\treturn registered;\n\t}\n\n\tasync function runOne(roleId: string, spec: string, settled: Map<string, SettledChildV1>): Promise<void> {\n\t\tconst definition = definitionFor(roleId);\n\t\tconst instance = options.composition.create<RoleRunnerInputV1, RoleRunnerResultV1>(\n\t\t\t{ id: definition.id, version: definition.version },\n\t\t\t{ parentInstanceId: options.parentInstanceId },\n\t\t);\n\t\tconst childInstanceId = instance.id;\n\t\tconst lease = await instance.acquireControllerLease(owner);\n\t\ttry {\n\t\t\tconst operation = instance.run({ spec }, { lease });\n\t\t\ttry {\n\t\t\t\tawait operation.result;\n\t\t\t} catch {\n\t\t\t\t// run() rejects on failure/cancellation mid-flight; instance.wait()\n\t\t\t\t// below yields the terminal status and error.\n\t\t\t}\n\t\t\tconst terminal = await instance.wait();\n\t\t\tconst error =\n\t\t\t\tterminal.error === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: terminal.error instanceof Error\n\t\t\t\t\t\t? terminal.error.message\n\t\t\t\t\t\t: String(terminal.error);\n\t\t\tsettled.set(roleId, {\n\t\t\t\troleId,\n\t\t\t\tdefinitionId: definition.id,\n\t\t\t\tchildInstanceId,\n\t\t\t\trevision: terminal.revision,\n\t\t\t\tstatus: terminal.status,\n\t\t\t\t...(terminal.output !== undefined ? { output: terminal.output } : {}),\n\t\t\t\t...(error !== undefined ? { error } : {}),\n\t\t\t});\n\t\t} finally {\n\t\t\tif (lease.isActive()) await lease.release();\n\t\t}\n\t}\n\n\tasync function runRoles(request: RoleOrchestratorRunRequestV1): Promise<RoleOrchestrationResultV1> {\n\t\tif (runInFlight) throw new Error(t(\"Role orchestrator is already running an orchestration\"));\n\t\t// Input validation fails explicitly before any child is spawned.\n\t\tconst seen = new Set<string>();\n\t\tfor (const roleId of request.roleIds) {\n\t\t\tif (typeof roleId !== \"string\" || roleId.trim().length === 0) {\n\t\t\t\tthrow new Error(t(\"Role id must be a non-empty string\"));\n\t\t\t}\n\t\t\tif (seen.has(roleId)) throw new Error(t(\"Duplicate roleId in orchestration request: {roleId}\", { roleId }));\n\t\t\tseen.add(roleId);\n\t\t}\n\t\tconst overrides = new Map<string, RoleRunCallbackV1>();\n\t\tfor (const override of request.runs ?? []) {\n\t\t\tif (overrides.has(override.roleId))\n\t\t\t\tthrow new Error(t(\"Duplicate run override for role: {roleId}\", { roleId: override.roleId }));\n\t\t\toverrides.set(override.roleId, override.run);\n\t\t}\n\t\tfor (const roleId of overrides.keys()) {\n\t\t\tif (!seen.has(roleId)) throw new Error(t(\"Run override for unrequested role: {roleId}\", { roleId }));\n\t\t}\n\t\t// Stable execution order: roleId-sorted, `parallel` roles concurrent,\n\t\t// `single` roles strictly sequential. Aggregation order is independent\n\t\t// of this execution order.\n\t\tconst sorted = [...request.roleIds].sort((left, right) => left.localeCompare(right));\n\t\tfor (const roleId of sorted) {\n\t\t\trequireMetadata(roleId);\n\t\t\tdefinitionFor(roleId);\n\t\t}\n\n\t\trunInFlight = true;\n\t\ttry {\n\t\t\tactiveOverrides = overrides;\n\t\t\tconst settled = new Map<string, SettledChildV1>();\n\t\t\tif (sorted.length > 0) {\n\t\t\t\tconst parallelIds = sorted.filter((roleId) => requireMetadata(roleId).concurrency === \"parallel\");\n\t\t\t\tconst singleIds = sorted.filter((roleId) => requireMetadata(roleId).concurrency === \"single\");\n\t\t\t\tawait Promise.all(parallelIds.map((roleId) => runOne(roleId, request.spec, settled)));\n\t\t\t\tfor (const roleId of singleIds) await runOne(roleId, request.spec, settled);\n\t\t\t}\n\t\t\treturn aggregate(sorted, settled, request);\n\t\t} finally {\n\t\t\tactiveOverrides = new Map();\n\t\t\trunInFlight = false;\n\t\t}\n\t}\n\n\tfunction aggregate(\n\t\tsorted: readonly string[],\n\t\tsettled: ReadonlyMap<string, SettledChildV1>,\n\t\trequest: RoleOrchestratorRunRequestV1,\n\t): RoleOrchestrationResultV1 {\n\t\tconst limitBytes = request.limitBytes ?? options.limitBytes ?? DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES;\n\t\t// 6.3 budget semantics: a running byte total over roleId-sorted entries;\n\t\t// an entry that would exceed the budget is dropped whole (truncated),\n\t\t// never partially sliced — mirroring multi-agent-tasks aggregate().\n\t\tlet used = 0;\n\t\tlet truncated = false;\n\t\tconst frozenEntries = sorted.map((roleId): RoleOrchestrationEntryV1 => {\n\t\t\tconst outcome = settled.get(roleId);\n\t\t\tif (!outcome) throw new Error(t(\"Orchestration outcome missing for role: {roleId}\", { roleId }));\n\t\t\tconst base = {\n\t\t\t\troleId: outcome.roleId,\n\t\t\t\tdefinitionId: outcome.definitionId,\n\t\t\t\tchildInstanceId: outcome.childInstanceId,\n\t\t\t\trevision: outcome.revision,\n\t\t\t\tstatus: outcome.status,\n\t\t\t};\n\t\t\tif (outcome.status !== \"succeeded\" || outcome.output === undefined) {\n\t\t\t\treturn Object.freeze({\n\t\t\t\t\t...base,\n\t\t\t\t\ttruncated: false,\n\t\t\t\t\tmissing: true,\n\t\t\t\t\t...(outcome.error !== undefined ? { error: outcome.error } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst size = JSON.stringify(outcome.output).length;\n\t\t\tif (used + size > limitBytes) {\n\t\t\t\ttruncated = true;\n\t\t\t\treturn Object.freeze({ ...base, truncated: true, missing: false });\n\t\t\t}\n\t\t\tused += size;\n\t\t\treturn Object.freeze({ ...base, truncated: false, missing: false, result: outcome.output });\n\t\t});\n\t\tconst entryByRole = new Map(frozenEntries.map((entry) => [entry.roleId, entry]));\n\t\tconst evaluate = request.evaluateCompletion ?? options.evaluateCompletion;\n\t\tconst frozenChecks = sorted.map((roleId): RoleCompletionCheckV1 => {\n\t\t\tconst criteria = requireMetadata(roleId).completionCriteria;\n\t\t\tconst outcome = settled.get(roleId);\n\t\t\tconst entry = entryByRole.get(roleId);\n\t\t\tconst output = outcome?.output;\n\t\t\t// No evaluator, no output, or an output dropped by the byte budget:\n\t\t\t// the criteria cannot be judged, which is reported as unchecked\n\t\t\t// instead of being silently treated as satisfied or unmet.\n\t\t\tif (!evaluate || !output || entry?.truncated === true) {\n\t\t\t\treturn Object.freeze({ roleId, criteria, status: \"unchecked\" as const });\n\t\t\t}\n\t\t\tconst verdict = evaluate({ roleId, criteria, result: output });\n\t\t\treturn Object.freeze({\n\t\t\t\troleId,\n\t\t\t\tcriteria,\n\t\t\t\tstatus:\n\t\t\t\t\tverdict === true\n\t\t\t\t\t\t? (\"satisfied\" as const)\n\t\t\t\t\t\t: verdict === false\n\t\t\t\t\t\t\t? (\"unmet\" as const)\n\t\t\t\t\t\t\t: (\"unchecked\" as const),\n\t\t\t});\n\t\t});\n\t\treturn Object.freeze({\n\t\t\tentries: Object.freeze(frozenEntries),\n\t\t\ttruncated,\n\t\t\tcompletionChecks: Object.freeze(frozenChecks),\n\t\t});\n\t}\n\n\treturn {\n\t\tcomposition: options.composition,\n\t\trunner: options.runner,\n\t\tparentInstanceId: options.parentInstanceId,\n\t\trunRoles,\n\t};\n}\n"]}
@@ -1,195 +0,0 @@
1
- import { t } from "../core/i18n/index.js";
2
- /**
3
- * Default aggregation byte budget. The multi-agent-tasks aggregate defaults
4
- * to unbounded (caller-injected limits); this default anchors the contract to
5
- * the repo's existing 16 KiB result-cap magnitude.
6
- */
7
- export const DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES = 16 * 1024;
8
- const DEFAULT_ORCHESTRATION_OWNER = "role-orchestrator";
9
- /** Creates the root-side concurrent role orchestrator (2.2e). */
10
- export function createRoleOrchestrator(options) {
11
- const owner = options.owner ?? DEFAULT_ORCHESTRATION_OWNER;
12
- // Definitions are registered once per roleId and reused across runs: a
13
- // composition instance is single-run, so every orchestration creates fresh
14
- // child instances from the same definitions.
15
- const definitions = new Map();
16
- let activeOverrides = new Map();
17
- let runInFlight = false;
18
- function requireMetadata(roleId) {
19
- const metadata = options.runner.catalog.get(roleId);
20
- if (!metadata)
21
- throw new Error(t("Unknown role: {roleId}", { roleId }));
22
- return metadata;
23
- }
24
- function definitionFor(roleId) {
25
- const cached = definitions.get(roleId);
26
- if (cached)
27
- return cached;
28
- const base = options.runner.createDefinition(roleId);
29
- const definition = {
30
- ...base,
31
- run: (input, context) => {
32
- const override = activeOverrides.get(roleId);
33
- return override ? override(input, context) : options.runner.run(roleId, input, context);
34
- },
35
- };
36
- const registered = options.composition.define(definition);
37
- definitions.set(roleId, registered);
38
- return registered;
39
- }
40
- async function runOne(roleId, spec, settled) {
41
- const definition = definitionFor(roleId);
42
- const instance = options.composition.create({ id: definition.id, version: definition.version }, { parentInstanceId: options.parentInstanceId });
43
- const childInstanceId = instance.id;
44
- const lease = await instance.acquireControllerLease(owner);
45
- try {
46
- const operation = instance.run({ spec }, { lease });
47
- try {
48
- await operation.result;
49
- }
50
- catch {
51
- // run() rejects on failure/cancellation mid-flight; instance.wait()
52
- // below yields the terminal status and error.
53
- }
54
- const terminal = await instance.wait();
55
- const error = terminal.error === undefined
56
- ? undefined
57
- : terminal.error instanceof Error
58
- ? terminal.error.message
59
- : String(terminal.error);
60
- settled.set(roleId, {
61
- roleId,
62
- definitionId: definition.id,
63
- childInstanceId,
64
- revision: terminal.revision,
65
- status: terminal.status,
66
- ...(terminal.output !== undefined ? { output: terminal.output } : {}),
67
- ...(error !== undefined ? { error } : {}),
68
- });
69
- }
70
- finally {
71
- if (lease.isActive())
72
- await lease.release();
73
- }
74
- }
75
- async function runRoles(request) {
76
- if (runInFlight)
77
- throw new Error(t("Role orchestrator is already running an orchestration"));
78
- // Input validation fails explicitly before any child is spawned.
79
- const seen = new Set();
80
- for (const roleId of request.roleIds) {
81
- if (typeof roleId !== "string" || roleId.trim().length === 0) {
82
- throw new Error(t("Role id must be a non-empty string"));
83
- }
84
- if (seen.has(roleId))
85
- throw new Error(t("Duplicate roleId in orchestration request: {roleId}", { roleId }));
86
- seen.add(roleId);
87
- }
88
- const overrides = new Map();
89
- for (const override of request.runs ?? []) {
90
- if (overrides.has(override.roleId))
91
- throw new Error(t("Duplicate run override for role: {roleId}", { roleId: override.roleId }));
92
- overrides.set(override.roleId, override.run);
93
- }
94
- for (const roleId of overrides.keys()) {
95
- if (!seen.has(roleId))
96
- throw new Error(t("Run override for unrequested role: {roleId}", { roleId }));
97
- }
98
- // Stable execution order: roleId-sorted, `parallel` roles concurrent,
99
- // `single` roles strictly sequential. Aggregation order is independent
100
- // of this execution order.
101
- const sorted = [...request.roleIds].sort((left, right) => left.localeCompare(right));
102
- for (const roleId of sorted) {
103
- requireMetadata(roleId);
104
- definitionFor(roleId);
105
- }
106
- runInFlight = true;
107
- try {
108
- activeOverrides = overrides;
109
- const settled = new Map();
110
- if (sorted.length > 0) {
111
- const parallelIds = sorted.filter((roleId) => requireMetadata(roleId).concurrency === "parallel");
112
- const singleIds = sorted.filter((roleId) => requireMetadata(roleId).concurrency === "single");
113
- await Promise.all(parallelIds.map((roleId) => runOne(roleId, request.spec, settled)));
114
- for (const roleId of singleIds)
115
- await runOne(roleId, request.spec, settled);
116
- }
117
- return aggregate(sorted, settled, request);
118
- }
119
- finally {
120
- activeOverrides = new Map();
121
- runInFlight = false;
122
- }
123
- }
124
- function aggregate(sorted, settled, request) {
125
- const limitBytes = request.limitBytes ?? options.limitBytes ?? DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES;
126
- // 6.3 budget semantics: a running byte total over roleId-sorted entries;
127
- // an entry that would exceed the budget is dropped whole (truncated),
128
- // never partially sliced — mirroring multi-agent-tasks aggregate().
129
- let used = 0;
130
- let truncated = false;
131
- const frozenEntries = sorted.map((roleId) => {
132
- const outcome = settled.get(roleId);
133
- if (!outcome)
134
- throw new Error(t("Orchestration outcome missing for role: {roleId}", { roleId }));
135
- const base = {
136
- roleId: outcome.roleId,
137
- definitionId: outcome.definitionId,
138
- childInstanceId: outcome.childInstanceId,
139
- revision: outcome.revision,
140
- status: outcome.status,
141
- };
142
- if (outcome.status !== "succeeded" || outcome.output === undefined) {
143
- return Object.freeze({
144
- ...base,
145
- truncated: false,
146
- missing: true,
147
- ...(outcome.error !== undefined ? { error: outcome.error } : {}),
148
- });
149
- }
150
- const size = JSON.stringify(outcome.output).length;
151
- if (used + size > limitBytes) {
152
- truncated = true;
153
- return Object.freeze({ ...base, truncated: true, missing: false });
154
- }
155
- used += size;
156
- return Object.freeze({ ...base, truncated: false, missing: false, result: outcome.output });
157
- });
158
- const entryByRole = new Map(frozenEntries.map((entry) => [entry.roleId, entry]));
159
- const evaluate = request.evaluateCompletion ?? options.evaluateCompletion;
160
- const frozenChecks = sorted.map((roleId) => {
161
- const criteria = requireMetadata(roleId).completionCriteria;
162
- const outcome = settled.get(roleId);
163
- const entry = entryByRole.get(roleId);
164
- const output = outcome?.output;
165
- // No evaluator, no output, or an output dropped by the byte budget:
166
- // the criteria cannot be judged, which is reported as unchecked
167
- // instead of being silently treated as satisfied or unmet.
168
- if (!evaluate || !output || entry?.truncated === true) {
169
- return Object.freeze({ roleId, criteria, status: "unchecked" });
170
- }
171
- const verdict = evaluate({ roleId, criteria, result: output });
172
- return Object.freeze({
173
- roleId,
174
- criteria,
175
- status: verdict === true
176
- ? "satisfied"
177
- : verdict === false
178
- ? "unmet"
179
- : "unchecked",
180
- });
181
- });
182
- return Object.freeze({
183
- entries: Object.freeze(frozenEntries),
184
- truncated,
185
- completionChecks: Object.freeze(frozenChecks),
186
- });
187
- }
188
- return {
189
- composition: options.composition,
190
- runner: options.runner,
191
- parentInstanceId: options.parentInstanceId,
192
- runRoles,
193
- };
194
- }
195
- //# sourceMappingURL=role-orchestrator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"role-orchestrator.js","sourceRoot":"","sources":["../../src/profile/role-orchestrator.ts"],"names":[],"mappings":"AAkCA,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAI1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,EAAE,GAAG,IAAI,CAAC;AAsF9D,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AAYxD,iEAAiE;AACjE,MAAM,UAAU,sBAAsB,CAAC,OAAkC,EAAsB;IAC9F,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,2BAA2B,CAAC;IAC3D,uEAAuE;IACvE,2EAA2E;I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AAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACtC,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;YAC/B,oEAAoE;YACpE,gEAAgE;YAChE,2DAA2D;YAC3D,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,IAAI,KAAK,EAAE,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAoB,EAAE,CAAC,CAAC;YAC1E,CAAC;YACD,MAAM,OAAO,GAAG,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/D,OAAO,MAAM,CAAC,MAAM,CAAC;gBACpB,MAAM;gBACN,QAAQ;gBACR,MAAM,EACL,OAAO,KAAK,IAAI;oBACf,CAAC,CAAE,WAAqB;oBACxB,CAAC,CAAC,OAAO,KAAK,KAAK;wBAClB,CAAC,CAAE,OAAiB;wBACpB,CAAC,CAAE,WAAqB;aAC3B,CAAC,CAAC;QAAA,CACH,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,CAAC;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;YACrC,SAAS;YACT,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;SAC7C,CAAC,CAAC;IAAA,CACH;IAED,OAAO;QACN,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,QAAQ;KACR,CAAC;AAAA,CACF","sourcesContent":["/**\n * Role orchestrator (2.2e) — root-side concurrent orchestration of registered\n * roles with bounded aggregation.\n *\n * Spawns one child per requested roleId through the public\n * `AgentCompositionAPI` (create/lease/run/wait bound to the root via\n * `parentInstanceId`), honoring the role's `RoleMetadataV1.concurrency`\n * metadata: `parallel` roles run concurrently, `single` roles execute one at\n * a time in stable roleId order. Aggregation reuses the multi-agent-tasks 6.3\n * semantics — entries sorted by roleId (never completion order), a per-entry\n * byte budget over the JSON-serialized output (`limitBytes`; over-budget\n * entries are dropped whole with an explicit `truncated` flag, outputs that\n * are absent carry `missing`), and `completionCriteria` metadata checked per\n * role into a structured satisfied/unmet/unchecked list (never thrown).\n * Child failures are collected, never swallowed: a failed child lands in its\n * structured entry while the orchestration still resolves (fail-collect at\n * the orchestration level, not fail-fast).\n *\n * Limit constants: multi-agent-tasks itself has no built-in numeric caps —\n * its `limitBytes`/`maxResultBytes` are caller-injected and default to\n * unbounded. This contract therefore defaults `limitBytes` to 16 KiB, the\n * magnitude of the repo's existing `DEFAULT_MAX_RESULT_BYTES_V1` (office\n * writer). No separate entry cap is added: the multi-agent-tasks aggregate\n * has none either, and the entry count here is already bounded by the\n * explicit `roleIds` list.\n *\n * Honest state-namespace boundary: state namespaces are partitioned per\n * plugin owner, not per child instance. Concurrent children therefore do NOT\n * get per-instance state isolation under this contract. The deterministic\n * injected run callbacks of this milestone never write state, so the boundary\n * is not exercised here; concurrent child state writes remain outside this\n * contract.\n */\nimport type { AgentCompositionAPI, AgentDefinition } from \"../core/extensions/public-api.ts\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { RoleMetadataV1 } from \"./role-catalog.ts\";\nimport type { RoleRunCallbackV1, RoleRunnerInputV1, RoleRunnerResultV1, RoleRunnerV1 } from \"./role-runner.ts\";\n\n/**\n * Default aggregation byte budget. The multi-agent-tasks aggregate defaults\n * to unbounded (caller-injected limits); this default anchors the contract to\n * the repo's existing 16 KiB result-cap magnitude.\n */\nexport const DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES = 16 * 1024;\n\n/** Terminal instance states an orchestrated child can settle into. */\nexport type RoleOrchestrationStatusV1 = \"succeeded\" | \"failed\" | \"cancelled\" | \"disposed\";\n\n/** One orchestrated child's aggregation entry (sorted by roleId, never completion order). */\nexport interface RoleOrchestrationEntryV1 {\n\treadonly roleId: string;\n\treadonly definitionId: string;\n\treadonly childInstanceId: string;\n\t/** Terminal revision of the child instance (result reference half, see 2.2b). */\n\treadonly revision: number;\n\treadonly status: RoleOrchestrationStatusV1;\n\t/** The entry's output exceeded the remaining byte budget and was dropped whole. */\n\treadonly truncated: boolean;\n\t/** No output was available (failure, cancellation, disposal, or truncation). */\n\treadonly missing: boolean;\n\t/** Present only for succeeded entries that fit the byte budget. */\n\treadonly result?: RoleRunnerResultV1;\n\t/** Structured failure text; present when the instance settled with an error. */\n\treadonly error?: string;\n}\n\n/** Per-role completion-criteria verdict produced at aggregation time (never thrown). */\nexport interface RoleCompletionCheckV1 {\n\treadonly roleId: string;\n\treadonly criteria: string;\n\t/**\n\t * `satisfied`/`unmet` come from an injected evaluator; `unchecked` means no\n\t * evaluator was available or the entry had no in-budget output to judge.\n\t */\n\treadonly status: \"satisfied\" | \"unmet\" | \"unchecked\";\n}\n\n/**\n * Deterministic completion evaluator. Returns `true`/`false` for a verdict or\n * `undefined` when the criteria cannot be judged from the result.\n */\nexport type RoleCompletionEvaluatorV1 = (input: {\n\treadonly roleId: string;\n\treadonly criteria: string;\n\treadonly result: RoleRunnerResultV1;\n}) => boolean | undefined;\n\n/** One orchestration request: explicit roleIds plus one shared spec string. */\nexport interface RoleOrchestratorRunRequestV1 {\n\treadonly roleIds: readonly string[];\n\treadonly spec: string;\n\t/** Per-role run overrides taking precedence for this request only. */\n\treadonly runs?: readonly { readonly roleId: string; readonly run: RoleRunCallbackV1 }[];\n\t/** Aggregation byte budget for this request (defaults to the orchestrator option). */\n\treadonly limitBytes?: number;\n\t/** Completion evaluator for this request (defaults to the orchestrator option). */\n\treadonly evaluateCompletion?: RoleCompletionEvaluatorV1;\n}\n\nexport interface RoleOrchestratorOptionsV1 {\n\treadonly composition: AgentCompositionAPI;\n\treadonly runner: RoleRunnerV1;\n\t/** Root instance the children are parented to via `parentInstanceId`. */\n\treadonly parentInstanceId: string;\n\t/** Controller-lease owner for the orchestrated children. */\n\treadonly owner?: string;\n\t/** Default aggregation byte budget (see {@link DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES}). */\n\treadonly limitBytes?: number;\n\t/** Default completion evaluator. Without one every check reports `unchecked`. */\n\treadonly evaluateCompletion?: RoleCompletionEvaluatorV1;\n}\n\n/** Orchestration result: bounded aggregation plus completion verdicts. */\nexport interface RoleOrchestrationResultV1 {\n\t/** One entry per requested role, sorted by roleId (stable, never completion order). */\n\treadonly entries: readonly RoleOrchestrationEntryV1[];\n\t/** True when at least one entry was dropped for exceeding the byte budget. */\n\treadonly truncated: boolean;\n\t/** Completion verdicts per requested role, sorted by roleId. */\n\treadonly completionChecks: readonly RoleCompletionCheckV1[];\n}\n\nexport interface RoleOrchestratorV1 {\n\treadonly composition: AgentCompositionAPI;\n\treadonly runner: RoleRunnerV1;\n\treadonly parentInstanceId: string;\n\trunRoles(request: RoleOrchestratorRunRequestV1): Promise<RoleOrchestrationResultV1>;\n}\n\nconst DEFAULT_ORCHESTRATION_OWNER = \"role-orchestrator\";\n\ninterface SettledChildV1 {\n\treadonly roleId: string;\n\treadonly definitionId: string;\n\treadonly childInstanceId: string;\n\treadonly revision: number;\n\treadonly status: RoleOrchestrationStatusV1;\n\treadonly output?: RoleRunnerResultV1;\n\treadonly error?: string;\n}\n\n/** Creates the root-side concurrent role orchestrator (2.2e). */\nexport function createRoleOrchestrator(options: RoleOrchestratorOptionsV1): RoleOrchestratorV1 {\n\tconst owner = options.owner ?? DEFAULT_ORCHESTRATION_OWNER;\n\t// Definitions are registered once per roleId and reused across runs: a\n\t// composition instance is single-run, so every orchestration creates fresh\n\t// child instances from the same definitions.\n\tconst definitions = new Map<string, AgentDefinition<RoleRunnerInputV1, RoleRunnerResultV1>>();\n\tlet activeOverrides: ReadonlyMap<string, RoleRunCallbackV1> = new Map();\n\tlet runInFlight = false;\n\n\tfunction requireMetadata(roleId: string): RoleMetadataV1 {\n\t\tconst metadata = options.runner.catalog.get(roleId);\n\t\tif (!metadata) throw new Error(t(\"Unknown role: {roleId}\", { roleId }));\n\t\treturn metadata;\n\t}\n\n\tfunction definitionFor(roleId: string): AgentDefinition<RoleRunnerInputV1, RoleRunnerResultV1> {\n\t\tconst cached = definitions.get(roleId);\n\t\tif (cached) return cached;\n\t\tconst base = options.runner.createDefinition(roleId);\n\t\tconst definition: AgentDefinition<RoleRunnerInputV1, RoleRunnerResultV1> = {\n\t\t\t...base,\n\t\t\trun: (input, context) => {\n\t\t\t\tconst override = activeOverrides.get(roleId);\n\t\t\t\treturn override ? override(input, context) : options.runner.run(roleId, input, context);\n\t\t\t},\n\t\t};\n\t\tconst registered = options.composition.define(definition);\n\t\tdefinitions.set(roleId, registered);\n\t\treturn registered;\n\t}\n\n\tasync function runOne(roleId: string, spec: string, settled: Map<string, SettledChildV1>): Promise<void> {\n\t\tconst definition = definitionFor(roleId);\n\t\tconst instance = options.composition.create<RoleRunnerInputV1, RoleRunnerResultV1>(\n\t\t\t{ id: definition.id, version: definition.version },\n\t\t\t{ parentInstanceId: options.parentInstanceId },\n\t\t);\n\t\tconst childInstanceId = instance.id;\n\t\tconst lease = await instance.acquireControllerLease(owner);\n\t\ttry {\n\t\t\tconst operation = instance.run({ spec }, { lease });\n\t\t\ttry {\n\t\t\t\tawait operation.result;\n\t\t\t} catch {\n\t\t\t\t// run() rejects on failure/cancellation mid-flight; instance.wait()\n\t\t\t\t// below yields the terminal status and error.\n\t\t\t}\n\t\t\tconst terminal = await instance.wait();\n\t\t\tconst error =\n\t\t\t\tterminal.error === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: terminal.error instanceof Error\n\t\t\t\t\t\t? terminal.error.message\n\t\t\t\t\t\t: String(terminal.error);\n\t\t\tsettled.set(roleId, {\n\t\t\t\troleId,\n\t\t\t\tdefinitionId: definition.id,\n\t\t\t\tchildInstanceId,\n\t\t\t\trevision: terminal.revision,\n\t\t\t\tstatus: terminal.status,\n\t\t\t\t...(terminal.output !== undefined ? { output: terminal.output } : {}),\n\t\t\t\t...(error !== undefined ? { error } : {}),\n\t\t\t});\n\t\t} finally {\n\t\t\tif (lease.isActive()) await lease.release();\n\t\t}\n\t}\n\n\tasync function runRoles(request: RoleOrchestratorRunRequestV1): Promise<RoleOrchestrationResultV1> {\n\t\tif (runInFlight) throw new Error(t(\"Role orchestrator is already running an orchestration\"));\n\t\t// Input validation fails explicitly before any child is spawned.\n\t\tconst seen = new Set<string>();\n\t\tfor (const roleId of request.roleIds) {\n\t\t\tif (typeof roleId !== \"string\" || roleId.trim().length === 0) {\n\t\t\t\tthrow new Error(t(\"Role id must be a non-empty string\"));\n\t\t\t}\n\t\t\tif (seen.has(roleId)) throw new Error(t(\"Duplicate roleId in orchestration request: {roleId}\", { roleId }));\n\t\t\tseen.add(roleId);\n\t\t}\n\t\tconst overrides = new Map<string, RoleRunCallbackV1>();\n\t\tfor (const override of request.runs ?? []) {\n\t\t\tif (overrides.has(override.roleId))\n\t\t\t\tthrow new Error(t(\"Duplicate run override for role: {roleId}\", { roleId: override.roleId }));\n\t\t\toverrides.set(override.roleId, override.run);\n\t\t}\n\t\tfor (const roleId of overrides.keys()) {\n\t\t\tif (!seen.has(roleId)) throw new Error(t(\"Run override for unrequested role: {roleId}\", { roleId }));\n\t\t}\n\t\t// Stable execution order: roleId-sorted, `parallel` roles concurrent,\n\t\t// `single` roles strictly sequential. Aggregation order is independent\n\t\t// of this execution order.\n\t\tconst sorted = [...request.roleIds].sort((left, right) => left.localeCompare(right));\n\t\tfor (const roleId of sorted) {\n\t\t\trequireMetadata(roleId);\n\t\t\tdefinitionFor(roleId);\n\t\t}\n\n\t\trunInFlight = true;\n\t\ttry {\n\t\t\tactiveOverrides = overrides;\n\t\t\tconst settled = new Map<string, SettledChildV1>();\n\t\t\tif (sorted.length > 0) {\n\t\t\t\tconst parallelIds = sorted.filter((roleId) => requireMetadata(roleId).concurrency === \"parallel\");\n\t\t\t\tconst singleIds = sorted.filter((roleId) => requireMetadata(roleId).concurrency === \"single\");\n\t\t\t\tawait Promise.all(parallelIds.map((roleId) => runOne(roleId, request.spec, settled)));\n\t\t\t\tfor (const roleId of singleIds) await runOne(roleId, request.spec, settled);\n\t\t\t}\n\t\t\treturn aggregate(sorted, settled, request);\n\t\t} finally {\n\t\t\tactiveOverrides = new Map();\n\t\t\trunInFlight = false;\n\t\t}\n\t}\n\n\tfunction aggregate(\n\t\tsorted: readonly string[],\n\t\tsettled: ReadonlyMap<string, SettledChildV1>,\n\t\trequest: RoleOrchestratorRunRequestV1,\n\t): RoleOrchestrationResultV1 {\n\t\tconst limitBytes = request.limitBytes ?? options.limitBytes ?? DEFAULT_ROLE_AGGREGATION_LIMIT_BYTES;\n\t\t// 6.3 budget semantics: a running byte total over roleId-sorted entries;\n\t\t// an entry that would exceed the budget is dropped whole (truncated),\n\t\t// never partially sliced — mirroring multi-agent-tasks aggregate().\n\t\tlet used = 0;\n\t\tlet truncated = false;\n\t\tconst frozenEntries = sorted.map((roleId): RoleOrchestrationEntryV1 => {\n\t\t\tconst outcome = settled.get(roleId);\n\t\t\tif (!outcome) throw new Error(t(\"Orchestration outcome missing for role: {roleId}\", { roleId }));\n\t\t\tconst base = {\n\t\t\t\troleId: outcome.roleId,\n\t\t\t\tdefinitionId: outcome.definitionId,\n\t\t\t\tchildInstanceId: outcome.childInstanceId,\n\t\t\t\trevision: outcome.revision,\n\t\t\t\tstatus: outcome.status,\n\t\t\t};\n\t\t\tif (outcome.status !== \"succeeded\" || outcome.output === undefined) {\n\t\t\t\treturn Object.freeze({\n\t\t\t\t\t...base,\n\t\t\t\t\ttruncated: false,\n\t\t\t\t\tmissing: true,\n\t\t\t\t\t...(outcome.error !== undefined ? { error: outcome.error } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst size = JSON.stringify(outcome.output).length;\n\t\t\tif (used + size > limitBytes) {\n\t\t\t\ttruncated = true;\n\t\t\t\treturn Object.freeze({ ...base, truncated: true, missing: false });\n\t\t\t}\n\t\t\tused += size;\n\t\t\treturn Object.freeze({ ...base, truncated: false, missing: false, result: outcome.output });\n\t\t});\n\t\tconst entryByRole = new Map(frozenEntries.map((entry) => [entry.roleId, entry]));\n\t\tconst evaluate = request.evaluateCompletion ?? options.evaluateCompletion;\n\t\tconst frozenChecks = sorted.map((roleId): RoleCompletionCheckV1 => {\n\t\t\tconst criteria = requireMetadata(roleId).completionCriteria;\n\t\t\tconst outcome = settled.get(roleId);\n\t\t\tconst entry = entryByRole.get(roleId);\n\t\t\tconst output = outcome?.output;\n\t\t\t// No evaluator, no output, or an output dropped by the byte budget:\n\t\t\t// the criteria cannot be judged, which is reported as unchecked\n\t\t\t// instead of being silently treated as satisfied or unmet.\n\t\t\tif (!evaluate || !output || entry?.truncated === true) {\n\t\t\t\treturn Object.freeze({ roleId, criteria, status: \"unchecked\" as const });\n\t\t\t}\n\t\t\tconst verdict = evaluate({ roleId, criteria, result: output });\n\t\t\treturn Object.freeze({\n\t\t\t\troleId,\n\t\t\t\tcriteria,\n\t\t\t\tstatus:\n\t\t\t\t\tverdict === true\n\t\t\t\t\t\t? (\"satisfied\" as const)\n\t\t\t\t\t\t: verdict === false\n\t\t\t\t\t\t\t? (\"unmet\" as const)\n\t\t\t\t\t\t\t: (\"unchecked\" as const),\n\t\t\t});\n\t\t});\n\t\treturn Object.freeze({\n\t\t\tentries: Object.freeze(frozenEntries),\n\t\t\ttruncated,\n\t\t\tcompletionChecks: Object.freeze(frozenChecks),\n\t\t});\n\t}\n\n\treturn {\n\t\tcomposition: options.composition,\n\t\trunner: options.runner,\n\t\tparentInstanceId: options.parentInstanceId,\n\t\trunRoles,\n\t};\n}\n"]}