@ai-agent-forge/agent-forge 0.86.7 → 0.88.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 (717) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +10 -11
  3. package/dist/artifacts/artifact-store.d.ts.map +1 -1
  4. package/dist/artifacts/artifact-store.js +9 -5
  5. package/dist/artifacts/artifact-store.js.map +1 -1
  6. package/dist/bundle/.build-manifest.json +430 -413
  7. package/dist/bundle/chunks/{chunk-A7GUOX2H.js → chunk-6ZKDNZHA.js} +5 -1
  8. package/dist/bundle/chunks/chunk-HLJEVRWP.js +13 -0
  9. package/dist/bundle/chunks/chunk-YGHQME4V.js +1456 -0
  10. package/dist/bundle/chunks/image-resize-worker.js +12 -1
  11. package/dist/bundle/chunks/{virtual-modules-3IZ4MYSQ.js → virtual-modules-KZ5DRH7Q.js} +1 -1
  12. package/dist/bundle/cli.js +1 -1
  13. package/dist/bundle/client.js +1 -1
  14. package/dist/bundle/index.js +2 -2
  15. package/dist/bundle/rpc-entry.js +1 -1
  16. package/dist/cli/args.d.ts.map +1 -1
  17. package/dist/cli/args.js +231 -185
  18. package/dist/cli/args.js.map +1 -1
  19. package/dist/cli/auth-check.d.ts.map +1 -1
  20. package/dist/cli/auth-check.js +17 -4
  21. package/dist/cli/auth-check.js.map +1 -1
  22. package/dist/cli/auth-command.d.ts.map +1 -1
  23. package/dist/cli/auth-command.js +15 -9
  24. package/dist/cli/auth-command.js.map +1 -1
  25. package/dist/cli/credential-print.d.ts.map +1 -1
  26. package/dist/cli/credential-print.js +14 -7
  27. package/dist/cli/credential-print.js.map +1 -1
  28. package/dist/cli/experimental/command.d.ts.map +1 -1
  29. package/dist/cli/experimental/command.js +6 -5
  30. package/dist/cli/experimental/command.js.map +1 -1
  31. package/dist/cli/list-models.d.ts.map +1 -1
  32. package/dist/cli/list-models.js +9 -8
  33. package/dist/cli/list-models.js.map +1 -1
  34. package/dist/cli/plugin-manager-controller.d.ts.map +1 -1
  35. package/dist/cli/plugin-manager-controller.js +2 -1
  36. package/dist/cli/plugin-manager-controller.js.map +1 -1
  37. package/dist/cli/serve.d.ts.map +1 -1
  38. package/dist/cli/serve.js +8 -5
  39. package/dist/cli/serve.js.map +1 -1
  40. package/dist/client/remote-session.d.ts.map +1 -1
  41. package/dist/client/remote-session.js +16 -9
  42. package/dist/client/remote-session.js.map +1 -1
  43. package/dist/config.d.ts.map +1 -1
  44. package/dist/config.js +5 -3
  45. package/dist/config.js.map +1 -1
  46. package/dist/core/agent-capability-contract.d.ts +0 -7
  47. package/dist/core/agent-capability-contract.d.ts.map +1 -1
  48. package/dist/core/agent-capability-contract.js +72 -68
  49. package/dist/core/agent-capability-contract.js.map +1 -1
  50. package/dist/core/agent-session-bash.d.ts.map +1 -1
  51. package/dist/core/agent-session-bash.js +5 -4
  52. package/dist/core/agent-session-bash.js.map +1 -1
  53. package/dist/core/agent-session-compaction.d.ts +6 -10
  54. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  55. package/dist/core/agent-session-compaction.js +35 -133
  56. package/dist/core/agent-session-compaction.js.map +1 -1
  57. package/dist/core/agent-session-context.d.ts.map +1 -1
  58. package/dist/core/agent-session-context.js +18 -13
  59. package/dist/core/agent-session-context.js.map +1 -1
  60. package/dist/core/agent-session-internal.d.ts +0 -6
  61. package/dist/core/agent-session-internal.d.ts.map +1 -1
  62. package/dist/core/agent-session-internal.js.map +1 -1
  63. package/dist/core/agent-session-model.d.ts.map +1 -1
  64. package/dist/core/agent-session-model.js +2 -1
  65. package/dist/core/agent-session-model.js.map +1 -1
  66. package/dist/core/agent-session-retry.d.ts.map +1 -1
  67. package/dist/core/agent-session-retry.js +3 -3
  68. package/dist/core/agent-session-retry.js.map +1 -1
  69. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  70. package/dist/core/agent-session-runtime.js +7 -6
  71. package/dist/core/agent-session-runtime.js.map +1 -1
  72. package/dist/core/agent-session-services.d.ts +1 -1
  73. package/dist/core/agent-session-services.d.ts.map +1 -1
  74. package/dist/core/agent-session-services.js.map +1 -1
  75. package/dist/core/agent-session-tools.d.ts.map +1 -1
  76. package/dist/core/agent-session-tools.js +3 -2
  77. package/dist/core/agent-session-tools.js.map +1 -1
  78. package/dist/core/agent-session.d.ts +40 -22
  79. package/dist/core/agent-session.d.ts.map +1 -1
  80. package/dist/core/agent-session.js +147 -67
  81. package/dist/core/agent-session.js.map +1 -1
  82. package/dist/core/auth-guidance.d.ts.map +1 -1
  83. package/dist/core/auth-guidance.js +11 -5
  84. package/dist/core/auth-guidance.js.map +1 -1
  85. package/dist/core/auth-storage.d.ts.map +1 -1
  86. package/dist/core/auth-storage.js +9 -6
  87. package/dist/core/auth-storage.js.map +1 -1
  88. package/dist/core/compaction/compaction.d.ts.map +1 -1
  89. package/dist/core/compaction/compaction.js +2 -1
  90. package/dist/core/compaction/compaction.js.map +1 -1
  91. package/dist/core/embedded-sdk.d.ts.map +1 -1
  92. package/dist/core/embedded-sdk.js +10 -6
  93. package/dist/core/embedded-sdk.js.map +1 -1
  94. package/dist/core/export-html/index.d.ts.map +1 -1
  95. package/dist/core/export-html/index.js +9 -4
  96. package/dist/core/export-html/index.js.map +1 -1
  97. package/dist/core/extensions/agent-composition.d.ts.map +1 -1
  98. package/dist/core/extensions/agent-composition.js +26 -19
  99. package/dist/core/extensions/agent-composition.js.map +1 -1
  100. package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
  101. package/dist/core/extensions/bootstrap-agent-loop.js +3 -2
  102. package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
  103. package/dist/core/extensions/bootstrap-compaction-policy.d.ts.map +1 -1
  104. package/dist/core/extensions/bootstrap-compaction-policy.js +0 -34
  105. package/dist/core/extensions/bootstrap-compaction-policy.js.map +1 -1
  106. package/dist/core/extensions/bootstrap-lifecycle.d.ts.map +1 -1
  107. package/dist/core/extensions/bootstrap-lifecycle.js +20 -17
  108. package/dist/core/extensions/bootstrap-lifecycle.js.map +1 -1
  109. package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +1 -1
  110. package/dist/core/extensions/bootstrap-overflow-policy.js +2 -1
  111. package/dist/core/extensions/bootstrap-overflow-policy.js.map +1 -1
  112. package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +1 -1
  113. package/dist/core/extensions/bootstrap-retry-policy.js +4 -3
  114. package/dist/core/extensions/bootstrap-retry-policy.js.map +1 -1
  115. package/dist/core/extensions/bootstrap-skills.d.ts.map +1 -1
  116. package/dist/core/extensions/bootstrap-skills.js +7 -6
  117. package/dist/core/extensions/bootstrap-skills.js.map +1 -1
  118. package/dist/core/extensions/bootstrap-tools.d.ts.map +1 -1
  119. package/dist/core/extensions/bootstrap-tools.js +2 -1
  120. package/dist/core/extensions/bootstrap-tools.js.map +1 -1
  121. package/dist/core/extensions/capability-plugin.d.ts.map +1 -1
  122. package/dist/core/extensions/capability-plugin.js +37 -13
  123. package/dist/core/extensions/capability-plugin.js.map +1 -1
  124. package/dist/core/extensions/capability-runtime-events.d.ts.map +1 -1
  125. package/dist/core/extensions/capability-runtime-events.js +17 -13
  126. package/dist/core/extensions/capability-runtime-events.js.map +1 -1
  127. package/dist/core/extensions/capability-runtime-guards.d.ts.map +1 -1
  128. package/dist/core/extensions/capability-runtime-guards.js +16 -15
  129. package/dist/core/extensions/capability-runtime-guards.js.map +1 -1
  130. package/dist/core/extensions/capability-runtime-manifest.d.ts.map +1 -1
  131. package/dist/core/extensions/capability-runtime-manifest.js +52 -30
  132. package/dist/core/extensions/capability-runtime-manifest.js.map +1 -1
  133. package/dist/core/extensions/capability-runtime-validation.d.ts.map +1 -1
  134. package/dist/core/extensions/capability-runtime-validation.js +66 -65
  135. package/dist/core/extensions/capability-runtime-validation.js.map +1 -1
  136. package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
  137. package/dist/core/extensions/capability-runtime.js +147 -127
  138. package/dist/core/extensions/capability-runtime.js.map +1 -1
  139. package/dist/core/extensions/compaction-memory-failure-mode.d.ts.map +1 -1
  140. package/dist/core/extensions/compaction-memory-failure-mode.js +3 -2
  141. package/dist/core/extensions/compaction-memory-failure-mode.js.map +1 -1
  142. package/dist/core/extensions/context-strategy-binding.d.ts.map +1 -1
  143. package/dist/core/extensions/context-strategy-binding.js +7 -4
  144. package/dist/core/extensions/context-strategy-binding.js.map +1 -1
  145. package/dist/core/extensions/lifecycle-catalog.d.ts.map +1 -1
  146. package/dist/core/extensions/lifecycle-catalog.js +290 -279
  147. package/dist/core/extensions/lifecycle-catalog.js.map +1 -1
  148. package/dist/core/extensions/lifecycle-delivery-queue.d.ts.map +1 -1
  149. package/dist/core/extensions/lifecycle-delivery-queue.js +3 -2
  150. package/dist/core/extensions/lifecycle-delivery-queue.js.map +1 -1
  151. package/dist/core/extensions/provider-failover.d.ts +7 -3
  152. package/dist/core/extensions/provider-failover.d.ts.map +1 -1
  153. package/dist/core/extensions/provider-failover.js +9 -8
  154. package/dist/core/extensions/provider-failover.js.map +1 -1
  155. package/dist/core/facade/coding-agent-facade.d.ts +6 -6
  156. package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
  157. package/dist/core/facade/coding-agent-facade.js +2 -3
  158. package/dist/core/facade/coding-agent-facade.js.map +1 -1
  159. package/dist/core/http-dispatcher.d.ts.map +1 -1
  160. package/dist/core/http-dispatcher.js +2 -1
  161. package/dist/core/http-dispatcher.js.map +1 -1
  162. package/dist/core/i18n/index.d.ts +14 -0
  163. package/dist/core/i18n/index.d.ts.map +1 -0
  164. package/dist/core/i18n/index.js +67 -0
  165. package/dist/core/i18n/index.js.map +1 -0
  166. package/dist/core/i18n/locales/en/example.d.ts +7 -0
  167. package/dist/core/i18n/locales/en/example.d.ts.map +1 -0
  168. package/dist/core/i18n/locales/en/example.js +7 -0
  169. package/dist/core/i18n/locales/en/example.js.map +1 -0
  170. package/dist/core/i18n/locales/zh-cn/cli.d.ts +8 -0
  171. package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -0
  172. package/dist/core/i18n/locales/zh-cn/cli.js +229 -0
  173. package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -0
  174. package/dist/core/i18n/locales/zh-cn/common.d.ts +6 -0
  175. package/dist/core/i18n/locales/zh-cn/common.d.ts.map +1 -0
  176. package/dist/core/i18n/locales/zh-cn/common.js +6 -0
  177. package/dist/core/i18n/locales/zh-cn/common.js.map +1 -0
  178. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +13 -0
  179. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -0
  180. package/dist/core/i18n/locales/zh-cn/core-contract-core.js +173 -0
  181. package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -0
  182. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts +12 -0
  183. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -0
  184. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +582 -0
  185. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -0
  186. package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts +9 -0
  187. package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts.map +1 -0
  188. package/dist/core/i18n/locales/zh-cn/core-contract-final.js +55 -0
  189. package/dist/core/i18n/locales/zh-cn/core-contract-final.js.map +1 -0
  190. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.d.ts +11 -0
  191. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.d.ts.map +1 -0
  192. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js +455 -0
  193. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js.map +1 -0
  194. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts +9 -0
  195. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -0
  196. package/dist/core/i18n/locales/zh-cn/core-errors.js +191 -0
  197. package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -0
  198. package/dist/core/i18n/locales/zh-cn/example.d.ts +7 -0
  199. package/dist/core/i18n/locales/zh-cn/example.d.ts.map +1 -0
  200. package/dist/core/i18n/locales/zh-cn/example.js +10 -0
  201. package/dist/core/i18n/locales/zh-cn/example.js.map +1 -0
  202. package/dist/core/i18n/locales/zh-cn/index.d.ts +2 -0
  203. package/dist/core/i18n/locales/zh-cn/index.d.ts.map +1 -0
  204. package/dist/core/i18n/locales/zh-cn/index.js +41 -0
  205. package/dist/core/i18n/locales/zh-cn/index.js.map +1 -0
  206. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts +10 -0
  207. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -0
  208. package/dist/core/i18n/locales/zh-cn/interactive-mode.js +267 -0
  209. package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -0
  210. package/dist/core/i18n/locales/zh-cn/keybindings.d.ts +11 -0
  211. package/dist/core/i18n/locales/zh-cn/keybindings.d.ts.map +1 -0
  212. package/dist/core/i18n/locales/zh-cn/keybindings.js +67 -0
  213. package/dist/core/i18n/locales/zh-cn/keybindings.js.map +1 -0
  214. package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts +7 -0
  215. package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts.map +1 -0
  216. package/dist/core/i18n/locales/zh-cn/slash-commands.js +39 -0
  217. package/dist/core/i18n/locales/zh-cn/slash-commands.js.map +1 -0
  218. package/dist/core/i18n/locales/zh-cn/tui-builtin.d.ts +10 -0
  219. package/dist/core/i18n/locales/zh-cn/tui-builtin.d.ts.map +1 -0
  220. package/dist/core/i18n/locales/zh-cn/tui-builtin.js +15 -0
  221. package/dist/core/i18n/locales/zh-cn/tui-builtin.js.map +1 -0
  222. package/dist/core/i18n/locales/zh-cn/tui-components-misc.d.ts +13 -0
  223. package/dist/core/i18n/locales/zh-cn/tui-components-misc.d.ts.map +1 -0
  224. package/dist/core/i18n/locales/zh-cn/tui-components-misc.js +102 -0
  225. package/dist/core/i18n/locales/zh-cn/tui-components-misc.js.map +1 -0
  226. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts +12 -0
  227. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts.map +1 -0
  228. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js +286 -0
  229. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js.map +1 -0
  230. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.d.ts +9 -0
  231. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.d.ts.map +1 -0
  232. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.js +79 -0
  233. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.js.map +1 -0
  234. package/dist/core/i18n/locales/zh-cn/tui-self-owned.d.ts +8 -0
  235. package/dist/core/i18n/locales/zh-cn/tui-self-owned.d.ts.map +1 -0
  236. package/dist/core/i18n/locales/zh-cn/tui-self-owned.js +72 -0
  237. package/dist/core/i18n/locales/zh-cn/tui-self-owned.js.map +1 -0
  238. package/dist/core/keybindings.d.ts +15 -0
  239. package/dist/core/keybindings.d.ts.map +1 -1
  240. package/dist/core/keybindings.js +18 -0
  241. package/dist/core/keybindings.js.map +1 -1
  242. package/dist/core/logger.d.ts.map +1 -1
  243. package/dist/core/logger.js +5 -1
  244. package/dist/core/logger.js.map +1 -1
  245. package/dist/core/model-config.d.ts +0 -1
  246. package/dist/core/model-config.d.ts.map +1 -1
  247. package/dist/core/model-config.js +9 -1
  248. package/dist/core/model-config.js.map +1 -1
  249. package/dist/core/model-registry.d.ts.map +1 -1
  250. package/dist/core/model-registry.js +2 -1
  251. package/dist/core/model-registry.js.map +1 -1
  252. package/dist/core/model-runtime.d.ts.map +1 -1
  253. package/dist/core/model-runtime.js +11 -7
  254. package/dist/core/model-runtime.js.map +1 -1
  255. package/dist/core/package-install-host.d.ts.map +1 -1
  256. package/dist/core/package-install-host.js +4 -3
  257. package/dist/core/package-install-host.js.map +1 -1
  258. package/dist/core/package-manager.d.ts.map +1 -1
  259. package/dist/core/package-manager.js +15 -10
  260. package/dist/core/package-manager.js.map +1 -1
  261. package/dist/core/package-resource-collection.d.ts.map +1 -1
  262. package/dist/core/package-resource-collection.js +2 -1
  263. package/dist/core/package-resource-collection.js.map +1 -1
  264. package/dist/core/package-source.d.ts.map +1 -1
  265. package/dist/core/package-source.js +3 -2
  266. package/dist/core/package-source.js.map +1 -1
  267. package/dist/core/provider-composer.d.ts +2 -2
  268. package/dist/core/provider-composer.d.ts.map +1 -1
  269. package/dist/core/provider-composer.js +29 -21
  270. package/dist/core/provider-composer.js.map +1 -1
  271. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  272. package/dist/core/remote-catalog-provider.js +6 -2
  273. package/dist/core/remote-catalog-provider.js.map +1 -1
  274. package/dist/core/resolve-config-value.d.ts.map +1 -1
  275. package/dist/core/resolve-config-value.js +15 -5
  276. package/dist/core/resolve-config-value.js.map +1 -1
  277. package/dist/core/sdk.d.ts +27 -5
  278. package/dist/core/sdk.d.ts.map +1 -1
  279. package/dist/core/sdk.js +80 -55
  280. package/dist/core/sdk.js.map +1 -1
  281. package/dist/core/session-cwd.d.ts.map +1 -1
  282. package/dist/core/session-cwd.js +5 -2
  283. package/dist/core/session-cwd.js.map +1 -1
  284. package/dist/core/session-export.d.ts.map +1 -1
  285. package/dist/core/session-export.js +2 -1
  286. package/dist/core/session-export.js.map +1 -1
  287. package/dist/core/session-manager.d.ts.map +1 -1
  288. package/dist/core/session-manager.js +39 -29
  289. package/dist/core/session-manager.js.map +1 -1
  290. package/dist/core/session-storage.d.ts.map +1 -1
  291. package/dist/core/session-storage.js +3 -3
  292. package/dist/core/session-storage.js.map +1 -1
  293. package/dist/core/settings-manager.d.ts +20 -20
  294. package/dist/core/settings-manager.d.ts.map +1 -1
  295. package/dist/core/settings-manager.js +47 -59
  296. package/dist/core/settings-manager.js.map +1 -1
  297. package/dist/core/slash-commands.d.ts.map +1 -1
  298. package/dist/core/slash-commands.js +53 -32
  299. package/dist/core/slash-commands.js.map +1 -1
  300. package/dist/core/system-prompt.d.ts.map +1 -1
  301. package/dist/core/system-prompt.js +25 -2
  302. package/dist/core/system-prompt.js.map +1 -1
  303. package/dist/core/tools/bash.d.ts.map +1 -1
  304. package/dist/core/tools/bash.js +11 -7
  305. package/dist/core/tools/bash.js.map +1 -1
  306. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  307. package/dist/core/tools/edit-diff.js +9 -4
  308. package/dist/core/tools/edit-diff.js.map +1 -1
  309. package/dist/core/tools/edit.d.ts.map +1 -1
  310. package/dist/core/tools/edit.js +4 -3
  311. package/dist/core/tools/edit.js.map +1 -1
  312. package/dist/core/tools/index.d.ts.map +1 -1
  313. package/dist/core/tools/index.js +3 -2
  314. package/dist/core/tools/index.js.map +1 -1
  315. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  316. package/dist/core/tools/output-accumulator.js +2 -1
  317. package/dist/core/tools/output-accumulator.js.map +1 -1
  318. package/dist/core/tools/read.d.ts.map +1 -1
  319. package/dist/core/tools/read.js +6 -2
  320. package/dist/core/tools/read.js.map +1 -1
  321. package/dist/core/tools/write.d.ts.map +1 -1
  322. package/dist/core/tools/write.js +2 -1
  323. package/dist/core/tools/write.js.map +1 -1
  324. package/dist/durable/durable-service.d.ts.map +1 -1
  325. package/dist/durable/durable-service.js +25 -18
  326. package/dist/durable/durable-service.js.map +1 -1
  327. package/dist/host/checkpoint-commit.d.ts.map +1 -1
  328. package/dist/host/checkpoint-commit.js +2 -1
  329. package/dist/host/checkpoint-commit.js.map +1 -1
  330. package/dist/host/manual-compaction.d.ts.map +1 -1
  331. package/dist/host/manual-compaction.js +2 -1
  332. package/dist/host/manual-compaction.js.map +1 -1
  333. package/dist/host/output-projection.d.ts +0 -13
  334. package/dist/host/output-projection.d.ts.map +1 -1
  335. package/dist/host/output-projection.js +16 -2
  336. package/dist/host/output-projection.js.map +1 -1
  337. package/dist/host/summary-retry.d.ts.map +1 -1
  338. package/dist/host/summary-retry.js +3 -2
  339. package/dist/host/summary-retry.js.map +1 -1
  340. package/dist/main.d.ts.map +1 -1
  341. package/dist/main.js +97 -60
  342. package/dist/main.js.map +1 -1
  343. package/dist/modes/interactive/components/agents-view.d.ts.map +1 -1
  344. package/dist/modes/interactive/components/agents-view.js +18 -15
  345. package/dist/modes/interactive/components/agents-view.js.map +1 -1
  346. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  347. package/dist/modes/interactive/components/assistant-message.js +6 -5
  348. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  349. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  350. package/dist/modes/interactive/components/bash-execution.js +12 -7
  351. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  352. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  353. package/dist/modes/interactive/components/bordered-loader.js +2 -1
  354. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  355. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  356. package/dist/modes/interactive/components/branch-summary-message.js +6 -5
  357. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  358. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  359. package/dist/modes/interactive/components/compaction-summary-message.js +9 -5
  360. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  361. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  362. package/dist/modes/interactive/components/config-selector.js +18 -15
  363. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  364. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  365. package/dist/modes/interactive/components/custom-entry.js +2 -1
  366. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  367. package/dist/modes/interactive/components/dialog-editor.d.ts.map +1 -1
  368. package/dist/modes/interactive/components/dialog-editor.js +5 -4
  369. package/dist/modes/interactive/components/dialog-editor.js.map +1 -1
  370. package/dist/modes/interactive/components/dialog-input.d.ts.map +1 -1
  371. package/dist/modes/interactive/components/dialog-input.js +2 -1
  372. package/dist/modes/interactive/components/dialog-input.js.map +1 -1
  373. package/dist/modes/interactive/components/dialog-selector.d.ts.map +1 -1
  374. package/dist/modes/interactive/components/dialog-selector.js +4 -3
  375. package/dist/modes/interactive/components/dialog-selector.js.map +1 -1
  376. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  377. package/dist/modes/interactive/components/first-time-setup.js +11 -10
  378. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  379. package/dist/modes/interactive/components/footer.d.ts +0 -2
  380. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  381. package/dist/modes/interactive/components/footer.js +8 -10
  382. package/dist/modes/interactive/components/footer.js.map +1 -1
  383. package/dist/modes/interactive/components/index.d.ts +1 -0
  384. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  385. package/dist/modes/interactive/components/index.js +1 -0
  386. package/dist/modes/interactive/components/index.js.map +1 -1
  387. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  388. package/dist/modes/interactive/components/keybinding-hints.js +3 -2
  389. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  390. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  391. package/dist/modes/interactive/components/login-dialog.js +12 -11
  392. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  393. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  394. package/dist/modes/interactive/components/mermaid.js +6 -2
  395. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  396. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  397. package/dist/modes/interactive/components/model-selector.js +28 -16
  398. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  399. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  400. package/dist/modes/interactive/components/oauth-selector.js +10 -9
  401. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  402. package/dist/modes/interactive/components/plugin-manager-entry.d.ts.map +1 -1
  403. package/dist/modes/interactive/components/plugin-manager-entry.js +22 -13
  404. package/dist/modes/interactive/components/plugin-manager-entry.js.map +1 -1
  405. package/dist/modes/interactive/components/plugin-selection-entry.d.ts.map +1 -1
  406. package/dist/modes/interactive/components/plugin-selection-entry.js +27 -12
  407. package/dist/modes/interactive/components/plugin-selection-entry.js.map +1 -1
  408. package/dist/modes/interactive/components/queue-manager-selector.d.ts +60 -0
  409. package/dist/modes/interactive/components/queue-manager-selector.d.ts.map +1 -0
  410. package/dist/modes/interactive/components/queue-manager-selector.js +166 -0
  411. package/dist/modes/interactive/components/queue-manager-selector.js.map +1 -0
  412. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  413. package/dist/modes/interactive/components/scoped-models-selector.js +16 -14
  414. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  415. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  416. package/dist/modes/interactive/components/session-selector.js +43 -31
  417. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  418. package/dist/modes/interactive/components/settings-selector.d.ts +4 -6
  419. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  420. package/dist/modes/interactive/components/settings-selector.js +115 -120
  421. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  422. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  423. package/dist/modes/interactive/components/settings-submenu.js +5 -4
  424. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  425. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  426. package/dist/modes/interactive/components/show-images-selector.js +3 -2
  427. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  428. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  429. package/dist/modes/interactive/components/skill-invocation-message.js +4 -3
  430. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  431. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  432. package/dist/modes/interactive/components/status-indicator.js +14 -5
  433. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  434. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  435. package/dist/modes/interactive/components/theme-selector.js +2 -1
  436. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  437. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  438. package/dist/modes/interactive/components/thinking-selector.js +11 -4
  439. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  440. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  441. package/dist/modes/interactive/components/tool-execution.js +8 -3
  442. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  443. package/dist/modes/interactive/components/tree-list.d.ts.map +1 -1
  444. package/dist/modes/interactive/components/tree-list.js +7 -6
  445. package/dist/modes/interactive/components/tree-list.js.map +1 -1
  446. package/dist/modes/interactive/components/tree-render.d.ts.map +1 -1
  447. package/dist/modes/interactive/components/tree-render.js +28 -23
  448. package/dist/modes/interactive/components/tree-render.js.map +1 -1
  449. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  450. package/dist/modes/interactive/components/tree-selector.js +9 -7
  451. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  452. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  453. package/dist/modes/interactive/components/user-message-selector.js +5 -4
  454. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  455. package/dist/modes/interactive/components/workflow-view.d.ts.map +1 -1
  456. package/dist/modes/interactive/components/workflow-view.js +36 -21
  457. package/dist/modes/interactive/components/workflow-view.js.map +1 -1
  458. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  459. package/dist/modes/interactive/external-editor.js +2 -1
  460. package/dist/modes/interactive/external-editor.js.map +1 -1
  461. package/dist/modes/interactive/interactive-auth.d.ts.map +1 -1
  462. package/dist/modes/interactive/interactive-auth.js +71 -40
  463. package/dist/modes/interactive/interactive-auth.js.map +1 -1
  464. package/dist/modes/interactive/interactive-commands.d.ts +1 -0
  465. package/dist/modes/interactive/interactive-commands.d.ts.map +1 -1
  466. package/dist/modes/interactive/interactive-commands.js +3 -0
  467. package/dist/modes/interactive/interactive-commands.js.map +1 -1
  468. package/dist/modes/interactive/interactive-dialog-ui.d.ts.map +1 -1
  469. package/dist/modes/interactive/interactive-dialog-ui.js +5 -5
  470. package/dist/modes/interactive/interactive-dialog-ui.js.map +1 -1
  471. package/dist/modes/interactive/interactive-format.d.ts.map +1 -1
  472. package/dist/modes/interactive/interactive-format.js +34 -18
  473. package/dist/modes/interactive/interactive-format.js.map +1 -1
  474. package/dist/modes/interactive/interactive-helpers.d.ts.map +1 -1
  475. package/dist/modes/interactive/interactive-helpers.js +7 -2
  476. package/dist/modes/interactive/interactive-helpers.js.map +1 -1
  477. package/dist/modes/interactive/interactive-mode.d.ts +4 -2
  478. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  479. package/dist/modes/interactive/interactive-mode.js +350 -279
  480. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  481. package/dist/modes/interactive/interactive-selectors.d.ts +9 -0
  482. package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
  483. package/dist/modes/interactive/interactive-selectors.js +79 -25
  484. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  485. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  486. package/dist/modes/interactive/theme/theme-controller.js +5 -1
  487. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  488. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  489. package/dist/modes/interactive/theme/theme.js +26 -23
  490. package/dist/modes/interactive/theme/theme.js.map +1 -1
  491. package/dist/modes/json-event.d.ts.map +1 -1
  492. package/dist/modes/json-event.js +3 -2
  493. package/dist/modes/json-event.js.map +1 -1
  494. package/dist/modes/print-mode.d.ts.map +1 -1
  495. package/dist/modes/print-mode.js +3 -2
  496. package/dist/modes/print-mode.js.map +1 -1
  497. package/dist/modes/rpc/rpc-client.d.ts +0 -8
  498. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  499. package/dist/modes/rpc/rpc-client.js +3 -14
  500. package/dist/modes/rpc/rpc-client.js.map +1 -1
  501. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  502. package/dist/modes/rpc/rpc-mode.js +0 -9
  503. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  504. package/dist/modes/rpc/rpc-types.d.ts +0 -19
  505. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  506. package/dist/modes/rpc/rpc-types.js.map +1 -1
  507. package/dist/package-manager-cli.d.ts.map +1 -1
  508. package/dist/package-manager-cli.js +28 -13
  509. package/dist/package-manager-cli.js.map +1 -1
  510. package/dist/plugins/ecosystem/catalog.d.ts.map +1 -1
  511. package/dist/plugins/ecosystem/catalog.js +3 -2
  512. package/dist/plugins/ecosystem/catalog.js.map +1 -1
  513. package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
  514. package/dist/plugins/ecosystem/cli.js +2 -1
  515. package/dist/plugins/ecosystem/cli.js.map +1 -1
  516. package/dist/plugins/ecosystem/default-plugin-market.d.ts.map +1 -1
  517. package/dist/plugins/ecosystem/default-plugin-market.js +3 -2
  518. package/dist/plugins/ecosystem/default-plugin-market.js.map +1 -1
  519. package/dist/plugins/ecosystem/distribution.d.ts.map +1 -1
  520. package/dist/plugins/ecosystem/distribution.js +2 -1
  521. package/dist/plugins/ecosystem/distribution.js.map +1 -1
  522. package/dist/plugins/ecosystem/installer.d.ts.map +1 -1
  523. package/dist/plugins/ecosystem/installer.js +3 -2
  524. package/dist/plugins/ecosystem/installer.js.map +1 -1
  525. package/dist/plugins/ecosystem/node-disk-registry-source.d.ts.map +1 -1
  526. package/dist/plugins/ecosystem/node-disk-registry-source.js +20 -17
  527. package/dist/plugins/ecosystem/node-disk-registry-source.js.map +1 -1
  528. package/dist/plugins/ecosystem/node-distribution-host.d.ts.map +1 -1
  529. package/dist/plugins/ecosystem/node-distribution-host.js +35 -34
  530. package/dist/plugins/ecosystem/node-distribution-host.js.map +1 -1
  531. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
  532. package/dist/plugins/ecosystem/node-npm-registry-source.js +35 -34
  533. package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
  534. package/dist/plugins/ecosystem/node-package-install-host.d.ts.map +1 -1
  535. package/dist/plugins/ecosystem/node-package-install-host.js +9 -8
  536. package/dist/plugins/ecosystem/node-package-install-host.js.map +1 -1
  537. package/dist/plugins/ecosystem/node-package-install-persistence.d.ts.map +1 -1
  538. package/dist/plugins/ecosystem/node-package-install-persistence.js +4 -3
  539. package/dist/plugins/ecosystem/node-package-install-persistence.js.map +1 -1
  540. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +9 -2
  541. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  542. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +44 -5
  543. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  544. package/dist/plugins/ecosystem/node-plugin-trust-root.d.ts.map +1 -1
  545. package/dist/plugins/ecosystem/node-plugin-trust-root.js +10 -9
  546. package/dist/plugins/ecosystem/node-plugin-trust-root.js.map +1 -1
  547. package/dist/plugins/ecosystem/node-registry-source.d.ts.map +1 -1
  548. package/dist/plugins/ecosystem/node-registry-source.js +31 -30
  549. package/dist/plugins/ecosystem/node-registry-source.js.map +1 -1
  550. package/dist/plugins/ecosystem/node-release-package-source.d.ts.map +1 -1
  551. package/dist/plugins/ecosystem/node-release-package-source.js +30 -29
  552. package/dist/plugins/ecosystem/node-release-package-source.js.map +1 -1
  553. package/dist/plugins/ecosystem/node-tar-writer.d.ts.map +1 -1
  554. package/dist/plugins/ecosystem/node-tar-writer.js +11 -10
  555. package/dist/plugins/ecosystem/node-tar-writer.js.map +1 -1
  556. package/dist/plugins/ecosystem/node-url-package-source.d.ts.map +1 -1
  557. package/dist/plugins/ecosystem/node-url-package-source.js +21 -20
  558. package/dist/plugins/ecosystem/node-url-package-source.js.map +1 -1
  559. package/dist/plugins/ecosystem/plugin-acquisition.d.ts.map +1 -1
  560. package/dist/plugins/ecosystem/plugin-acquisition.js +3 -2
  561. package/dist/plugins/ecosystem/plugin-acquisition.js.map +1 -1
  562. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +9 -1
  563. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
  564. package/dist/plugins/ecosystem/plugin-bootstrap.js +5 -0
  565. package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
  566. package/dist/plugins/ecosystem/registry-cli-adapter.d.ts.map +1 -1
  567. package/dist/plugins/ecosystem/registry-cli-adapter.js +2 -1
  568. package/dist/plugins/ecosystem/registry-cli-adapter.js.map +1 -1
  569. package/dist/plugins/ecosystem/registry.d.ts.map +1 -1
  570. package/dist/plugins/ecosystem/registry.js +35 -32
  571. package/dist/plugins/ecosystem/registry.js.map +1 -1
  572. package/dist/plugins/ecosystem/resolver.d.ts.map +1 -1
  573. package/dist/plugins/ecosystem/resolver.js +3 -2
  574. package/dist/plugins/ecosystem/resolver.js.map +1 -1
  575. package/dist/plugins/ecosystem/selection-store.d.ts.map +1 -1
  576. package/dist/plugins/ecosystem/selection-store.js +11 -10
  577. package/dist/plugins/ecosystem/selection-store.js.map +1 -1
  578. package/dist/plugins/ecosystem/selection.d.ts.map +1 -1
  579. package/dist/plugins/ecosystem/selection.js +8 -7
  580. package/dist/plugins/ecosystem/selection.js.map +1 -1
  581. package/dist/plugins/ecosystem/state.d.ts.map +1 -1
  582. package/dist/plugins/ecosystem/state.js +24 -23
  583. package/dist/plugins/ecosystem/state.js.map +1 -1
  584. package/dist/plugins/ecosystem/updates.d.ts.map +1 -1
  585. package/dist/plugins/ecosystem/updates.js +5 -4
  586. package/dist/plugins/ecosystem/updates.js.map +1 -1
  587. package/dist/plugins/mcp-http.d.ts +0 -17
  588. package/dist/plugins/mcp-http.d.ts.map +1 -1
  589. package/dist/plugins/mcp-http.js +30 -7
  590. package/dist/plugins/mcp-http.js.map +1 -1
  591. package/dist/plugins/plugin-supervisor.d.ts.map +1 -1
  592. package/dist/plugins/plugin-supervisor.js +19 -1
  593. package/dist/plugins/plugin-supervisor.js.map +1 -1
  594. package/dist/profile/first-roles.d.ts.map +1 -1
  595. package/dist/profile/first-roles.js +10 -1
  596. package/dist/profile/first-roles.js.map +1 -1
  597. package/dist/profile/goal-plugin.d.ts.map +1 -1
  598. package/dist/profile/goal-plugin.js +24 -5
  599. package/dist/profile/goal-plugin.js.map +1 -1
  600. package/dist/profile/identity.d.ts.map +1 -1
  601. package/dist/profile/identity.js +7 -6
  602. package/dist/profile/identity.js.map +1 -1
  603. package/dist/profile/lock.d.ts.map +1 -1
  604. package/dist/profile/lock.js +15 -1
  605. package/dist/profile/lock.js.map +1 -1
  606. package/dist/profile/plan-plugin.d.ts.map +1 -1
  607. package/dist/profile/plan-plugin.js +26 -13
  608. package/dist/profile/plan-plugin.js.map +1 -1
  609. package/dist/profile/plugin-profiles.d.ts.map +1 -1
  610. package/dist/profile/plugin-profiles.js +2 -1
  611. package/dist/profile/plugin-profiles.js.map +1 -1
  612. package/dist/profile/policy-manifest.d.ts.map +1 -1
  613. package/dist/profile/policy-manifest.js +5 -4
  614. package/dist/profile/policy-manifest.js.map +1 -1
  615. package/dist/profile/profile-registry.d.ts +0 -12
  616. package/dist/profile/profile-registry.d.ts.map +1 -1
  617. package/dist/profile/profile-registry.js +14 -1
  618. package/dist/profile/profile-registry.js.map +1 -1
  619. package/dist/profile/role-catalog.d.ts +0 -1
  620. package/dist/profile/role-catalog.d.ts.map +1 -1
  621. package/dist/profile/role-catalog.js +17 -15
  622. package/dist/profile/role-catalog.js.map +1 -1
  623. package/dist/profile/role-orchestrator.d.ts.map +1 -1
  624. package/dist/profile/role-orchestrator.js +8 -7
  625. package/dist/profile/role-orchestrator.js.map +1 -1
  626. package/dist/profile/role-runner.d.ts.map +1 -1
  627. package/dist/profile/role-runner.js +3 -2
  628. package/dist/profile/role-runner.js.map +1 -1
  629. package/dist/profile/root-facade.d.ts.map +1 -1
  630. package/dist/profile/root-facade.js +2 -1
  631. package/dist/profile/root-facade.js.map +1 -1
  632. package/dist/profile/skill-discovery-wiring.d.ts.map +1 -1
  633. package/dist/profile/skill-discovery-wiring.js +7 -2
  634. package/dist/profile/skill-discovery-wiring.js.map +1 -1
  635. package/dist/profile/state-store.d.ts.map +1 -1
  636. package/dist/profile/state-store.js +13 -9
  637. package/dist/profile/state-store.js.map +1 -1
  638. package/dist/profile/todo-plugin.d.ts.map +1 -1
  639. package/dist/profile/todo-plugin.js +9 -4
  640. package/dist/profile/todo-plugin.js.map +1 -1
  641. package/dist/profiles/builtin-suites.d.ts +13 -6
  642. package/dist/profiles/builtin-suites.d.ts.map +1 -1
  643. package/dist/profiles/builtin-suites.js +15 -6
  644. package/dist/profiles/builtin-suites.js.map +1 -1
  645. package/dist/profiles/suite-loader.d.ts +25 -1
  646. package/dist/profiles/suite-loader.d.ts.map +1 -1
  647. package/dist/profiles/suite-loader.js +34 -9
  648. package/dist/profiles/suite-loader.js.map +1 -1
  649. package/dist/remote/server-entry.d.ts.map +1 -1
  650. package/dist/remote/server-entry.js +3 -2
  651. package/dist/remote/server-entry.js.map +1 -1
  652. package/dist/remote/session-source.d.ts.map +1 -1
  653. package/dist/remote/session-source.js +8 -4
  654. package/dist/remote/session-source.js.map +1 -1
  655. package/dist/share/session-share.d.ts.map +1 -1
  656. package/dist/share/session-share.js +14 -2
  657. package/dist/share/session-share.js.map +1 -1
  658. package/dist/testing/plugin-testkit.d.ts.map +1 -1
  659. package/dist/testing/plugin-testkit.js +4 -3
  660. package/dist/testing/plugin-testkit.js.map +1 -1
  661. package/dist/testing/runtime-delivery-queue.d.ts.map +1 -1
  662. package/dist/testing/runtime-delivery-queue.js +2 -1
  663. package/dist/testing/runtime-delivery-queue.js.map +1 -1
  664. package/dist/testing/session-plugin-testkit.d.ts.map +1 -1
  665. package/dist/testing/session-plugin-testkit.js +10 -7
  666. package/dist/testing/session-plugin-testkit.js.map +1 -1
  667. package/dist/utils/ansi.d.ts.map +1 -1
  668. package/dist/utils/ansi.js +2 -1
  669. package/dist/utils/ansi.js.map +1 -1
  670. package/dist/utils/clipboard.d.ts.map +1 -1
  671. package/dist/utils/clipboard.js +7 -6
  672. package/dist/utils/clipboard.js.map +1 -1
  673. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  674. package/dist/utils/image-resize-worker.js +3 -2
  675. package/dist/utils/image-resize-worker.js.map +1 -1
  676. package/dist/utils/photon.d.ts +2 -2
  677. package/dist/utils/photon.d.ts.map +1 -1
  678. package/dist/utils/photon.js +2 -2
  679. package/dist/utils/photon.js.map +1 -1
  680. package/dist/utils/shell.d.ts.map +1 -1
  681. package/dist/utils/shell.js +9 -8
  682. package/dist/utils/shell.js.map +1 -1
  683. package/dist/utils/tools-manager.d.ts.map +1 -1
  684. package/dist/utils/tools-manager.js +23 -13
  685. package/dist/utils/tools-manager.js.map +1 -1
  686. package/dist/utils/version-check.d.ts.map +1 -1
  687. package/dist/utils/version-check.js +5 -1
  688. package/dist/utils/version-check.js.map +1 -1
  689. package/docs/compaction.md +1 -3
  690. package/docs/docs.json +4 -0
  691. package/docs/index.md +1 -0
  692. package/docs/keybindings.md +3 -0
  693. package/docs/mcp.md +103 -0
  694. package/docs/models.md +14 -22
  695. package/docs/providers.md +0 -1
  696. package/docs/quickstart.md +1 -1
  697. package/docs/rpc.md +1 -26
  698. package/docs/sdk.md +4 -6
  699. package/docs/settings.md +10 -12
  700. package/docs/skills.md +1 -9
  701. package/docs/terminal-setup.md +2 -3
  702. package/docs/usage.md +7 -6
  703. package/examples/extensions/with-deps/package-lock.json +2 -2
  704. package/examples/extensions/with-deps/package.json +1 -1
  705. package/examples/extensions/with-deps/plugin.json +1 -1
  706. package/examples/sdk/10-settings.ts +2 -4
  707. package/examples/sdk/12-full-control.ts +1 -2
  708. package/package.json +1 -3
  709. package/dist/bundle/chunks/chunk-EALJ5DDX.js +0 -1452
  710. package/dist/core/extensions/microcompact.d.ts +0 -80
  711. package/dist/core/extensions/microcompact.d.ts.map +0 -1
  712. package/dist/core/extensions/microcompact.js +0 -134
  713. package/dist/core/extensions/microcompact.js.map +0 -1
  714. package/dist/server/create-harness.d.ts +0 -26
  715. package/dist/server/create-harness.d.ts.map +0 -1
  716. package/dist/server/create-harness.js +0 -106
  717. package/dist/server/create-harness.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import { VERSION } from "../../config.js";
2
+ import { t } from "../../core/i18n/index.js";
2
3
  import { stableJsonDigest } from "../../profile/identity.js";
3
4
  import { resolvePluginCompatibilityV1 } from "./resolver.js";
4
5
  function manifestPayload(manifest) {
@@ -48,7 +49,7 @@ function snapshotManifest(manifest) {
48
49
  /** Create an immutable staged update; activation is a separate explicit transition. */
49
50
  export function stagePluginUpdateV1(input) {
50
51
  if (input.source.trim().length === 0)
51
- throw new Error("update source must be a non-empty string");
52
+ throw new Error(t("update source must be a non-empty string"));
52
53
  return Object.freeze({
53
54
  pluginId: input.manifest.id,
54
55
  pluginVersion: input.manifest.pluginVersion,
@@ -133,16 +134,16 @@ export function verifyPluginUpdateV1(input) {
133
134
  }
134
135
  export function activatePluginUpdateV1(record) {
135
136
  if (record.state !== "verified")
136
- throw new Error(`Only a verified update can become active: ${record.pluginId}`);
137
+ throw new Error(t("Only a verified update can become active: {pluginId}", { pluginId: record.pluginId }));
137
138
  return Object.freeze({ ...record, state: "active" });
138
139
  }
139
140
  /** Preserve the old record and return it as active after a failed update. */
140
141
  export function rollbackPluginUpdateV1(input) {
141
142
  if (input.previous.pluginId !== input.failed.pluginId) {
142
- throw new Error("Cannot rollback updates for different plugins");
143
+ throw new Error(t("Cannot rollback updates for different plugins"));
143
144
  }
144
145
  if (input.previous.state !== "active")
145
- throw new Error("Rollback target must be active");
146
+ throw new Error(t("Rollback target must be active"));
146
147
  return Object.freeze({ ...input.previous, state: "active" });
147
148
  }
148
149
  //# sourceMappingURL=updates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"updates.js","sourceRoot":"","sources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.ts\";\nimport { stableJsonDigest } from \"../../profile/identity.ts\";\nimport { resolvePluginCompatibilityV1 } from \"./resolver.ts\";\nimport type {\n\tCapabilityRefV1,\n\tHostFactsV1,\n\tPluginManifestV1,\n\tPluginSourceVerifierV1,\n\tPluginUpdateRecordV1,\n} from \"./types.ts\";\n\nfunction manifestPayload(manifest: PluginManifestV1): Record<string, unknown> {\n\treturn {\n\t\tid: manifest.id,\n\t\tpluginVersion: manifest.pluginVersion,\n\t\tapiVersion: manifest.apiVersion,\n\t\t...(manifest.capabilityRefs === undefined ? {} : { capabilityRefs: manifest.capabilityRefs }),\n\t\t...(manifest.requires === undefined ? {} : { requires: manifest.requires }),\n\t\t...(manifest.platform === undefined ? {} : { platform: manifest.platform }),\n\t\ttestOnly: manifest.testOnly ?? false,\n\t};\n}\n\nexport function pluginManifestDigestV1(manifest: PluginManifestV1): string {\n\treturn stableJsonDigest(manifestPayload(manifest) as Parameters<typeof stableJsonDigest>[0]);\n}\n\nfunction snapshotManifest(manifest: PluginManifestV1): PluginManifestV1 {\n\tconst capabilityRefs = manifest.capabilityRefs?.map((ref) => Object.freeze({ ...ref }));\n\tconst requires = manifest.requires?.map((requirement) => Object.freeze({ ...requirement }));\n\tconst platform = manifest.platform;\n\tconst runtime = platform?.runtime?.map((constraint) => Object.freeze({ ...constraint }));\n\tconst adapters = platform?.adapters?.map((adapter) =>\n\t\tObject.freeze({\n\t\t\t...adapter,\n\t\t\tos: Object.freeze([...adapter.os]),\n\t\t\t...(adapter.arch === undefined ? {} : { arch: Object.freeze([...adapter.arch]) }),\n\t\t\t...(adapter.hostFeatures === undefined ? {} : { hostFeatures: Object.freeze([...adapter.hostFeatures]) }),\n\t\t}),\n\t);\n\tconst platformSnapshot =\n\t\tplatform === undefined\n\t\t\t? undefined\n\t\t\t: Object.freeze({\n\t\t\t\t\t...platform,\n\t\t\t\t\tos: Object.freeze([...platform.os]),\n\t\t\t\t\t...(platform.arch === undefined ? {} : { arch: Object.freeze([...platform.arch]) }),\n\t\t\t\t\t...(runtime === undefined ? {} : { runtime: Object.freeze(runtime) }),\n\t\t\t\t\t...(platform.hostFeatures === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { hostFeatures: Object.freeze([...platform.hostFeatures]) }),\n\t\t\t\t\t...(adapters === undefined ? {} : { adapters: Object.freeze(adapters) }),\n\t\t\t\t});\n\treturn Object.freeze({\n\t\t...manifest,\n\t\t...(capabilityRefs === undefined ? {} : { capabilityRefs: Object.freeze(capabilityRefs) }),\n\t\t...(requires === undefined ? {} : { requires: Object.freeze(requires) }),\n\t\t...(platformSnapshot === undefined ? {} : { platform: platformSnapshot }),\n\t});\n}\n\n/** Create an immutable staged update; activation is a separate explicit transition. */\nexport function stagePluginUpdateV1(input: {\n\treadonly manifest: PluginManifestV1;\n\treadonly source: string;\n}): PluginUpdateRecordV1 {\n\tif (input.source.trim().length === 0) throw new Error(\"update source must be a non-empty string\");\n\treturn Object.freeze({\n\t\tpluginId: input.manifest.id,\n\t\tpluginVersion: input.manifest.pluginVersion,\n\t\tsource: input.source,\n\t\tmanifest: snapshotManifest(input.manifest),\n\t\tmanifestDigest: pluginManifestDigestV1(input.manifest),\n\t\tstate: \"staged\",\n\t});\n}\n\nexport type UpdateVerificationV1 =\n\t| { readonly status: \"verified\"; readonly record: PluginUpdateRecordV1 }\n\t| { readonly status: \"rejected\"; readonly record: PluginUpdateRecordV1; readonly reason: string };\n\n/** Verify digest and host compatibility without applying any policy or side effect. */\nexport function verifyPluginUpdateV1(input: {\n\treadonly record: PluginUpdateRecordV1;\n\treadonly host: HostFactsV1;\n\treadonly expectedDigest?: string;\n\treadonly availableCapabilities?: readonly CapabilityRefV1[];\n\treadonly verifier?: PluginSourceVerifierV1;\n}): UpdateVerificationV1 {\n\tconst actualDigest = pluginManifestDigestV1(input.record.manifest);\n\tif (input.record.state !== \"staged\") {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: `Update must be staged before verification: ${input.record.state}`,\n\t\t};\n\t}\n\tif (input.record.pluginId !== input.record.manifest.id) {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: \"Update record plugin ID does not match embedded manifest\",\n\t\t};\n\t}\n\tif (input.record.pluginVersion !== input.record.manifest.pluginVersion) {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: \"Update record plugin version does not match embedded manifest\",\n\t\t};\n\t}\n\tif (input.record.manifestDigest !== actualDigest) {\n\t\treturn { status: \"rejected\", record: input.record, reason: \"Staged manifest digest drifted\" };\n\t}\n\tif (input.expectedDigest !== undefined && input.expectedDigest !== actualDigest) {\n\t\treturn { status: \"rejected\", record: input.record, reason: \"Manifest digest does not match expectation\" };\n\t}\n\tconst resolution = resolvePluginCompatibilityV1({\n\t\tmanifest: input.record.manifest,\n\t\thost: input.host,\n\t\trequired: true,\n\t\tavailableCapabilities: input.availableCapabilities,\n\t\t// D-073: update verification enforces the declared host version range;\n\t\t// previously this path skipped the check entirely.\n\t\thostVersion: VERSION,\n\t});\n\tif (resolution.status !== \"installed-ready\") {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: `Plugin is not ready on host: ${resolution.status}`,\n\t\t};\n\t}\n\tif (input.verifier !== undefined) {\n\t\ttry {\n\t\t\tconst sourceVerification = input.verifier({\n\t\t\t\tpluginId: input.record.pluginId,\n\t\t\t\tpluginVersion: input.record.pluginVersion,\n\t\t\t\tsource: input.record.source,\n\t\t\t\tmanifestDigest: actualDigest,\n\t\t\t});\n\t\t\tif (sourceVerification.status !== \"accepted\") {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"rejected\",\n\t\t\t\t\trecord: input.record,\n\t\t\t\t\treason: \"Plugin source was rejected by the configured verifier\",\n\t\t\t\t};\n\t\t\t}\n\t\t} catch {\n\t\t\treturn {\n\t\t\t\tstatus: \"rejected\",\n\t\t\t\trecord: input.record,\n\t\t\t\treason: \"Plugin source verifier failed\",\n\t\t\t};\n\t\t}\n\t}\n\tconst record = Object.freeze({ ...input.record, state: \"verified\" as const });\n\treturn { status: \"verified\", record };\n}\n\nexport function activatePluginUpdateV1(record: PluginUpdateRecordV1): PluginUpdateRecordV1 {\n\tif (record.state !== \"verified\") throw new Error(`Only a verified update can become active: ${record.pluginId}`);\n\treturn Object.freeze({ ...record, state: \"active\" as const });\n}\n\n/** Preserve the old record and return it as active after a failed update. */\nexport function rollbackPluginUpdateV1(input: {\n\treadonly failed: PluginUpdateRecordV1;\n\treadonly previous: PluginUpdateRecordV1;\n}): PluginUpdateRecordV1 {\n\tif (input.previous.pluginId !== input.failed.pluginId) {\n\t\tthrow new Error(\"Cannot rollback updates for different plugins\");\n\t}\n\tif (input.previous.state !== \"active\") throw new Error(\"Rollback target must be active\");\n\treturn Object.freeze({ ...input.previous, state: \"active\" as const });\n}\n"]}
1
+ {"version":3,"file":"updates.js","sourceRoot":"","sources":["../../../src/plugins/ecosystem/updates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,0BAA0B,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAS7D,SAAS,eAAe,CAAC,QAA0B,EAA2B;IAC7E,OAAO;QACN,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,GAAG,CAAC,QAAQ,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,CAAC,cAAc,EAAE,CAAC;QAC7F,GAAG,CAAC,QAAQ,CAAC,QAAQ,KAAK,SAAS,CAAC,CA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AAM,CAAC,KAAK,KAAK,UAAU;QAC9B,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,sDAAsD,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC3G,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,QAAiB,EAAE,CAAC,CAAC;AAAA,CAC9D;AAED,6EAA6E;AAC7E,MAAM,UAAU,sBAAsB,CAAC,KAGtC,EAAwB;IACxB,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC;IAC5F,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAiB,EAAE,CAAC,CAAC;AAAA,CACtE","sourcesContent":["import { VERSION } from \"../../config.ts\";\nimport { t } from \"../../core/i18n/index.ts\";\nimport { stableJsonDigest } from \"../../profile/identity.ts\";\nimport { resolvePluginCompatibilityV1 } from \"./resolver.ts\";\nimport type {\n\tCapabilityRefV1,\n\tHostFactsV1,\n\tPluginManifestV1,\n\tPluginSourceVerifierV1,\n\tPluginUpdateRecordV1,\n} from \"./types.ts\";\n\nfunction manifestPayload(manifest: PluginManifestV1): Record<string, unknown> {\n\treturn {\n\t\tid: manifest.id,\n\t\tpluginVersion: manifest.pluginVersion,\n\t\tapiVersion: manifest.apiVersion,\n\t\t...(manifest.capabilityRefs === undefined ? {} : { capabilityRefs: manifest.capabilityRefs }),\n\t\t...(manifest.requires === undefined ? {} : { requires: manifest.requires }),\n\t\t...(manifest.platform === undefined ? {} : { platform: manifest.platform }),\n\t\ttestOnly: manifest.testOnly ?? false,\n\t};\n}\n\nexport function pluginManifestDigestV1(manifest: PluginManifestV1): string {\n\treturn stableJsonDigest(manifestPayload(manifest) as Parameters<typeof stableJsonDigest>[0]);\n}\n\nfunction snapshotManifest(manifest: PluginManifestV1): PluginManifestV1 {\n\tconst capabilityRefs = manifest.capabilityRefs?.map((ref) => Object.freeze({ ...ref }));\n\tconst requires = manifest.requires?.map((requirement) => Object.freeze({ ...requirement }));\n\tconst platform = manifest.platform;\n\tconst runtime = platform?.runtime?.map((constraint) => Object.freeze({ ...constraint }));\n\tconst adapters = platform?.adapters?.map((adapter) =>\n\t\tObject.freeze({\n\t\t\t...adapter,\n\t\t\tos: Object.freeze([...adapter.os]),\n\t\t\t...(adapter.arch === undefined ? {} : { arch: Object.freeze([...adapter.arch]) }),\n\t\t\t...(adapter.hostFeatures === undefined ? {} : { hostFeatures: Object.freeze([...adapter.hostFeatures]) }),\n\t\t}),\n\t);\n\tconst platformSnapshot =\n\t\tplatform === undefined\n\t\t\t? undefined\n\t\t\t: Object.freeze({\n\t\t\t\t\t...platform,\n\t\t\t\t\tos: Object.freeze([...platform.os]),\n\t\t\t\t\t...(platform.arch === undefined ? {} : { arch: Object.freeze([...platform.arch]) }),\n\t\t\t\t\t...(runtime === undefined ? {} : { runtime: Object.freeze(runtime) }),\n\t\t\t\t\t...(platform.hostFeatures === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { hostFeatures: Object.freeze([...platform.hostFeatures]) }),\n\t\t\t\t\t...(adapters === undefined ? {} : { adapters: Object.freeze(adapters) }),\n\t\t\t\t});\n\treturn Object.freeze({\n\t\t...manifest,\n\t\t...(capabilityRefs === undefined ? {} : { capabilityRefs: Object.freeze(capabilityRefs) }),\n\t\t...(requires === undefined ? {} : { requires: Object.freeze(requires) }),\n\t\t...(platformSnapshot === undefined ? {} : { platform: platformSnapshot }),\n\t});\n}\n\n/** Create an immutable staged update; activation is a separate explicit transition. */\nexport function stagePluginUpdateV1(input: {\n\treadonly manifest: PluginManifestV1;\n\treadonly source: string;\n}): PluginUpdateRecordV1 {\n\tif (input.source.trim().length === 0) throw new Error(t(\"update source must be a non-empty string\"));\n\treturn Object.freeze({\n\t\tpluginId: input.manifest.id,\n\t\tpluginVersion: input.manifest.pluginVersion,\n\t\tsource: input.source,\n\t\tmanifest: snapshotManifest(input.manifest),\n\t\tmanifestDigest: pluginManifestDigestV1(input.manifest),\n\t\tstate: \"staged\",\n\t});\n}\n\nexport type UpdateVerificationV1 =\n\t| { readonly status: \"verified\"; readonly record: PluginUpdateRecordV1 }\n\t| { readonly status: \"rejected\"; readonly record: PluginUpdateRecordV1; readonly reason: string };\n\n/** Verify digest and host compatibility without applying any policy or side effect. */\nexport function verifyPluginUpdateV1(input: {\n\treadonly record: PluginUpdateRecordV1;\n\treadonly host: HostFactsV1;\n\treadonly expectedDigest?: string;\n\treadonly availableCapabilities?: readonly CapabilityRefV1[];\n\treadonly verifier?: PluginSourceVerifierV1;\n}): UpdateVerificationV1 {\n\tconst actualDigest = pluginManifestDigestV1(input.record.manifest);\n\tif (input.record.state !== \"staged\") {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: `Update must be staged before verification: ${input.record.state}`,\n\t\t};\n\t}\n\tif (input.record.pluginId !== input.record.manifest.id) {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: \"Update record plugin ID does not match embedded manifest\",\n\t\t};\n\t}\n\tif (input.record.pluginVersion !== input.record.manifest.pluginVersion) {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: \"Update record plugin version does not match embedded manifest\",\n\t\t};\n\t}\n\tif (input.record.manifestDigest !== actualDigest) {\n\t\treturn { status: \"rejected\", record: input.record, reason: \"Staged manifest digest drifted\" };\n\t}\n\tif (input.expectedDigest !== undefined && input.expectedDigest !== actualDigest) {\n\t\treturn { status: \"rejected\", record: input.record, reason: \"Manifest digest does not match expectation\" };\n\t}\n\tconst resolution = resolvePluginCompatibilityV1({\n\t\tmanifest: input.record.manifest,\n\t\thost: input.host,\n\t\trequired: true,\n\t\tavailableCapabilities: input.availableCapabilities,\n\t\t// D-073: update verification enforces the declared host version range;\n\t\t// previously this path skipped the check entirely.\n\t\thostVersion: VERSION,\n\t});\n\tif (resolution.status !== \"installed-ready\") {\n\t\treturn {\n\t\t\tstatus: \"rejected\",\n\t\t\trecord: input.record,\n\t\t\treason: `Plugin is not ready on host: ${resolution.status}`,\n\t\t};\n\t}\n\tif (input.verifier !== undefined) {\n\t\ttry {\n\t\t\tconst sourceVerification = input.verifier({\n\t\t\t\tpluginId: input.record.pluginId,\n\t\t\t\tpluginVersion: input.record.pluginVersion,\n\t\t\t\tsource: input.record.source,\n\t\t\t\tmanifestDigest: actualDigest,\n\t\t\t});\n\t\t\tif (sourceVerification.status !== \"accepted\") {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"rejected\",\n\t\t\t\t\trecord: input.record,\n\t\t\t\t\treason: \"Plugin source was rejected by the configured verifier\",\n\t\t\t\t};\n\t\t\t}\n\t\t} catch {\n\t\t\treturn {\n\t\t\t\tstatus: \"rejected\",\n\t\t\t\trecord: input.record,\n\t\t\t\treason: \"Plugin source verifier failed\",\n\t\t\t};\n\t\t}\n\t}\n\tconst record = Object.freeze({ ...input.record, state: \"verified\" as const });\n\treturn { status: \"verified\", record };\n}\n\nexport function activatePluginUpdateV1(record: PluginUpdateRecordV1): PluginUpdateRecordV1 {\n\tif (record.state !== \"verified\")\n\t\tthrow new Error(t(\"Only a verified update can become active: {pluginId}\", { pluginId: record.pluginId }));\n\treturn Object.freeze({ ...record, state: \"active\" as const });\n}\n\n/** Preserve the old record and return it as active after a failed update. */\nexport function rollbackPluginUpdateV1(input: {\n\treadonly failed: PluginUpdateRecordV1;\n\treadonly previous: PluginUpdateRecordV1;\n}): PluginUpdateRecordV1 {\n\tif (input.previous.pluginId !== input.failed.pluginId) {\n\t\tthrow new Error(t(\"Cannot rollback updates for different plugins\"));\n\t}\n\tif (input.previous.state !== \"active\") throw new Error(t(\"Rollback target must be active\"));\n\treturn Object.freeze({ ...input.previous, state: \"active\" as const });\n}\n"]}
@@ -1,20 +1,3 @@
1
- /**
2
- * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the
3
- * same transport interface as the stdio plugin, plus observable retry.
4
- *
5
- * Retries apply ONLY to requests the server could not have started (connect
6
- * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never
7
- * re-sent, keeping calls idempotent from the caller's perspective. Every
8
- * transport error, retry attempt, and reconnect is reported through the
9
- * `onEvent` callback so callers can observe what happened. CLI
10
- * productization is out of scope.
11
- */
12
- /**
13
- * Per-request options for MCP transports. Defined here rather than imported
14
- * from the mcp-stdio example so production src never depends on examples/
15
- * (统一修复轮 C reverse-dependency fix); structurally identical to the
16
- * example's own declaration, which stays self-contained.
17
- */
18
1
  export interface McpRequestOptions {
19
2
  signal?: AbortSignal;
20
3
  timeoutMs?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-http.d.ts","sourceRoot":"","sources":["../../src/plugins/mcp-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,CAAC;IAClF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,GAAG,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;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,0GAA0G;IAC1G,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C,GAAG,CAAC,GAAG,EAAE,wBAAwB,KAAK,OAAO,CAAC;IAAE,OAAO,IAAI,IAAI,CAAA;CAAE,CAAC,CAqDlE","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. Every\n * transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? (() => undefined);\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t): Promise<{ status: number; text: string } | { status: \"connect_error\"; reason: string }> => {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst text = await response.text();\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\t\t\treturn { status: \"connect_error\", reason };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\tconst response = await postOnce(body, requestOptions);\n\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\tif (attempt > retryLimit) {\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tthrow new Error(`MCP HTTP transport error: ${reason}`);\n\t\t\t}\n\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\trecord({\n\t\t\t\tkind: \"retry\",\n\t\t\t\tat: now(),\n\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\tattempt,\n\t\t\t});\n\t\t\tawait sleep(waitedMs);\n\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t}\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw new Error(\"MCP HTTP transport is closed\");\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(`MCP HTTP transport returned HTTP ${response.status}`);\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\t`MCP HTTP transport returned non-JSON body: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(`MCP error ${parsed.error.code ?? \"\"}: ${parsed.error.message ?? \"unknown error\"}`);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(\"MCP tools/list result must contain tools[]\");\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(\"MCP tool requires a non-empty name\");\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
1
+ {"version":3,"file":"mcp-http.d.ts","sourceRoot":"","sources":["../../src/plugins/mcp-http.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,CAAC;IAClF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CA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C3C,GAAG,CAAC,GAAG,EAAE,wBAAwB,KAAK,OAAO,CAAC;IAAE,OAAO,IAAI,IAAI,CAAA;CAAE,CAAC,CAqDlE","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. Every\n * transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nimport { t } from \"../core/i18n/index.ts\";\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? (() => undefined);\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t): Promise<{ status: number; text: string } | { status: \"connect_error\"; reason: string }> => {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst text = await response.text();\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\t\t\treturn { status: \"connect_error\", reason };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\tconst response = await postOnce(body, requestOptions);\n\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\tif (attempt > retryLimit) {\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason }));\n\t\t\t}\n\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\trecord({\n\t\t\t\tkind: \"retry\",\n\t\t\t\tat: now(),\n\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\tattempt,\n\t\t\t});\n\t\t\tawait sleep(waitedMs);\n\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t}\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw new Error(t(\"MCP HTTP transport is closed\"));\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(t(\"MCP HTTP transport returned HTTP {status}\", { status: response.status }));\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\tt(\"MCP HTTP transport returned non-JSON body: {reason}\", {\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"MCP error {code}: {message}\", {\n\t\t\t\t\tcode: parsed.error.code ?? \"\",\n\t\t\t\t\tmessage: parsed.error.message ?? t(\"unknown error\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(t(\"MCP tools/list result must contain tools[]\"));\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(t(\"MCP tool requires a non-empty name\"));\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
@@ -1,3 +1,21 @@
1
+ /**
2
+ * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the
3
+ * same transport interface as the stdio plugin, plus observable retry.
4
+ *
5
+ * Retries apply ONLY to requests the server could not have started (connect
6
+ * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never
7
+ * re-sent, keeping calls idempotent from the caller's perspective. Every
8
+ * transport error, retry attempt, and reconnect is reported through the
9
+ * `onEvent` callback so callers can observe what happened. CLI
10
+ * productization is out of scope.
11
+ */
12
+ /**
13
+ * Per-request options for MCP transports. Defined here rather than imported
14
+ * from the mcp-stdio example so production src never depends on examples/
15
+ * (统一修复轮 C reverse-dependency fix); structurally identical to the
16
+ * example's own declaration, which stays self-contained.
17
+ */
18
+ import { t } from "../core/i18n/index.js";
1
19
  export function createMcpHttpTransport(options) {
2
20
  const timeoutMs = options.timeoutMs ?? 10_000;
3
21
  const retryLimit = options.retryLimit ?? 2;
@@ -52,7 +70,7 @@ export function createMcpHttpTransport(options) {
52
70
  detail: `giving up after ${attempt - 1} retries: ${reason}`,
53
71
  attempt,
54
72
  });
55
- throw new Error(`MCP HTTP transport error: ${reason}`);
73
+ throw new Error(t("MCP HTTP transport error: {reason}", { reason }));
56
74
  }
57
75
  const waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);
58
76
  record({
@@ -69,13 +87,13 @@ export function createMcpHttpTransport(options) {
69
87
  };
70
88
  const rpc = async (method, params, requestOptions) => {
71
89
  if (closed)
72
- throw new Error("MCP HTTP transport is closed");
90
+ throw new Error(t("MCP HTTP transport is closed"));
73
91
  const id = nextId;
74
92
  nextId += 1;
75
93
  const body = JSON.stringify({ jsonrpc: "2.0", id, method, ...(params === undefined ? {} : { params }) });
76
94
  const response = await postWithRetry(body, requestOptions);
77
95
  if (response.status !== 200) {
78
- throw new Error(`MCP HTTP transport returned HTTP ${response.status}`);
96
+ throw new Error(t("MCP HTTP transport returned HTTP {status}", { status: response.status }));
79
97
  }
80
98
  let parsed;
81
99
  try {
@@ -84,10 +102,15 @@ export function createMcpHttpTransport(options) {
84
102
  catch (error) {
85
103
  throw new Error(
86
104
  // v8 ignore next -- JSON.parse 只会抛出 Error 对象
87
- `MCP HTTP transport returned non-JSON body: ${error instanceof Error ? error.message : String(error)}`);
105
+ t("MCP HTTP transport returned non-JSON body: {reason}", {
106
+ reason: error instanceof Error ? error.message : String(error),
107
+ }));
88
108
  }
89
109
  if (parsed.error !== undefined) {
90
- throw new Error(`MCP error ${parsed.error.code ?? ""}: ${parsed.error.message ?? "unknown error"}`);
110
+ throw new Error(t("MCP error {code}: {message}", {
111
+ code: parsed.error.code ?? "",
112
+ message: parsed.error.message ?? t("unknown error"),
113
+ }));
91
114
  }
92
115
  return parsed.result;
93
116
  };
@@ -136,12 +159,12 @@ export function createMcpHttpServerPlugin(config) {
136
159
  await transport.notify("notifications/initialized");
137
160
  const listing = (await transport.request("tools/list"));
138
161
  if (!listing || !Array.isArray(listing.tools)) {
139
- throw new Error("MCP tools/list result must contain tools[]");
162
+ throw new Error(t("MCP tools/list result must contain tools[]"));
140
163
  }
141
164
  for (const tool of listing.tools) {
142
165
  const candidate = tool;
143
166
  if (!candidate || typeof candidate.name !== "string" || !candidate.name) {
144
- throw new Error("MCP tool requires a non-empty name");
167
+ throw new Error(t("MCP tool requires a non-empty name"));
145
168
  }
146
169
  api.registerTool({
147
170
  name: candidate.name,
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-http.js","sourceRoot":"","sources":["../../src/plugins/mcp-http.ts"],"names":[],"mappings":"AAkEA,MAAM,UAAU,sBAAsB,CAAC,OAAkC,EAAsB;IAC9F,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC;IAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC;IAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,MAAM,GAAG,CAAC,KAA8B,EAAQ,EAAE,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAAA,CACzB,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,EACrB,IAAY,EACZ,cAA6C,EAC6C,EAAE,CAAC;QAC7F,MA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AAO,SAAS,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,SAAS,CAAC,IAAI,EAAE;oBAClG,UAAU,EACT,SAAS,CAAC,WAAW,IAAI,OAAO,SAAS,CAAC,WAAW,KAAK,QAAQ;wBACjE,CAAC,CAAC,SAAS,CAAC,WAAW;wBACvB,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;oBACtC,OAAO,EAAE,KAAK,EAAE,UAAkB,EAAE,MAAe,EAAE,MAAoB,EAAE,EAAE,CAAC;wBAC7E,gEAAgE;wBAChE,4DAA4D;wBAC5D,yBAAyB;wBACzB,MAAM,aAAa,GAAG,MAAM,KAAK,SAAS,IAAI,OAAO,UAAU,KAAK,QAAQ,CAAC;wBAC7E,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;wBAClD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CACrC,YAAY,EACZ,EAAE,IAAI,EAAE,SAAS,CAAC,IAAc,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,EAAE,EAC1D,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CACtC,CAAC;wBACF,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;oBAAA,CACnC;iBACD,CAAC,CAAC;YACJ,CAAC;YACD,OAAO;gBACN,OAAO,GAAG;oBACT,SAAS,CAAC,KAAK,EAAE,CAAC;gBAAA,CAClB;aACD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,KAAK,CAAC;QACb,CAAC;IAAA,CACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. Every\n * transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? (() => undefined);\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t): Promise<{ status: number; text: string } | { status: \"connect_error\"; reason: string }> => {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst text = await response.text();\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\t\t\treturn { status: \"connect_error\", reason };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\tconst response = await postOnce(body, requestOptions);\n\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\tif (attempt > retryLimit) {\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tthrow new Error(`MCP HTTP transport error: ${reason}`);\n\t\t\t}\n\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\trecord({\n\t\t\t\tkind: \"retry\",\n\t\t\t\tat: now(),\n\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\tattempt,\n\t\t\t});\n\t\t\tawait sleep(waitedMs);\n\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t}\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw new Error(\"MCP HTTP transport is closed\");\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(`MCP HTTP transport returned HTTP ${response.status}`);\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\t`MCP HTTP transport returned non-JSON body: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(`MCP error ${parsed.error.code ?? \"\"}: ${parsed.error.message ?? \"unknown error\"}`);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(\"MCP tools/list result must contain tools[]\");\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(\"MCP tool requires a non-empty name\");\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
1
+ {"version":3,"file":"mcp-http.js","sourceRoot":"","sources":["../../src/plugins/mcp-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAmD1C,MAAM,UAAU,sBAAsB,CAAC,OAAkC,EAAsB;IAC9F,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC;IAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC;IAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,MAAM,GAAG,CAAC,KAA8B,EAAQ,EAAE,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAAA,CACzB,CAAC;I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D,CAAC,CAAC;YACJ,CAAC;YACD,OAAO;gBACN,OAAO,GAAG;oBACT,SAAS,CAAC,KAAK,EAAE,CAAC;gBAAA,CAClB;aACD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,KAAK,CAAC;QACb,CAAC;IAAA,CACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. Every\n * transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nimport { t } from \"../core/i18n/index.ts\";\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? (() => undefined);\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t): Promise<{ status: number; text: string } | { status: \"connect_error\"; reason: string }> => {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst text = await response.text();\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\t\t\treturn { status: \"connect_error\", reason };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\tconst response = await postOnce(body, requestOptions);\n\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\tif (attempt > retryLimit) {\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason }));\n\t\t\t}\n\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\trecord({\n\t\t\t\tkind: \"retry\",\n\t\t\t\tat: now(),\n\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\tattempt,\n\t\t\t});\n\t\t\tawait sleep(waitedMs);\n\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t}\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw new Error(t(\"MCP HTTP transport is closed\"));\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(t(\"MCP HTTP transport returned HTTP {status}\", { status: response.status }));\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\tt(\"MCP HTTP transport returned non-JSON body: {reason}\", {\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"MCP error {code}: {message}\", {\n\t\t\t\t\tcode: parsed.error.code ?? \"\",\n\t\t\t\t\tmessage: parsed.error.message ?? t(\"unknown error\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(t(\"MCP tools/list result must contain tools[]\"));\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(t(\"MCP tool requires a non-empty name\"));\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-supervisor.d.ts","sourceRoot":"","sources":["../../src/plugins/plugin-supervisor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,cAAc,GAAG,SAAS,GAA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IAC7B,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9F,KAAK,IAAI,SAAS,MAAM,EAAE,CAAC;IAC3B,MAAM,IAAI,SAAS,iBAAiB,EAAE,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC/C,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAC;IAC5C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACrF,GAAG,kBAAkB,CAuFrB","sourcesContent":["/**\n * Plugin supervisor (7.2) — heartbeat, restart, and backpressure over the\n * 7.1 plugin host, all deterministic (clock and sleep are injected; there\n * are no hidden timers).\n *\n * Heartbeat: every supervised plugin must report a beat before\n * `heartbeatIntervalMs` elapses since its last beat, checked only by an\n * explicit `tick()`. A missed beat marks the plugin unhealthy and triggers\n * a restart policy (bounded attempts with exponential backoff). Restart:\n * the supervisor re-invokes the plugin's start with the recorded attempt\n * number; a plugin exceeding `restartLimit` ends in a terminal\n * `exhausted` health. Backpressure: an internal event queue with a hard\n * cap — enqueueing beyond the cap fails closed with `queue_full` instead of\n * growing unbounded. Fault injection is trivially the caller's job: the\n * tests simulate missed beats and crashes directly. Supply-chain signing is\n * 7.3.\n */\nimport type { HostedPluginV1 } from \"./plugin-host.ts\";\n\nexport interface SupervisorPolicyV1 {\n\treadonly heartbeatIntervalMs: number;\n\treadonly restartLimit: number;\n\treadonly baseRestartMs: number;\n\treadonly queueCap: number;\n}\n\nexport type PluginHealthV1 = \"healthy\" | \"unhealthy\" | \"exhausted\" | \"stopped\";\n\nexport interface SupervisorEntryV1 {\n\treadonly pluginId: string;\n\treadonly health: PluginHealthV1;\n\treadonly restarts: number;\n\treadonly lastBeatAt: number;\n\treadonly nextRestartAllowedAt?: number;\n}\n\nexport type SupervisorEventV1 =\n\t| { readonly kind: \"beat\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"unhealthy\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"restart\"; readonly pluginId: string; readonly at: number; readonly attempt: number }\n\t| { readonly kind: \"exhausted\"; readonly pluginId: string; readonly at: number; readonly attempts: number }\n\t| { readonly kind: \"queue_full\"; readonly at: number };\n\nexport interface PluginSupervisorV1 {\n\tsupervise(plugin: HostedPluginV1): void;\n\tbeat(pluginId: string): void;\n\ttick(at: number): void;\n\trestart(pluginId: string): { readonly status: \"restarted\" | \"exhausted\" | \"unknown\"; readonly attempt?: number };\n\tenqueue(event: string): { readonly status: \"enqueued\" | \"queue_full\"; readonly size: number };\n\tdrain(): readonly string[];\n\thealth(): readonly SupervisorEntryV1[];\n\treadonly queueSize: number;\n}\n\nexport function createPluginSupervisor(options: {\n\treadonly policy: SupervisorPolicyV1;\n\treadonly plugins: readonly HostedPluginV1[];\n\treadonly now?: () => number;\n\treadonly restartPlugin?: (pluginId: string, attempt: number) => Promise<void> | void;\n}): PluginSupervisorV1 {\n\tconst policy = options.policy;\n\tconst now = options.now ?? (() => 0);\n\n\tinterface Entry {\n\t\tpluginId: string;\n\t\thealth: PluginHealthV1;\n\t\trestarts: number;\n\t\tlastBeatAt: number;\n\t\tnextRestartAllowedAt?: number;\n\t}\n\tconst entries = new Map<string, Entry>();\n\tconst events: SupervisorEventV1[] = [];\n\tconst queue: string[] = [];\n\n\tfor (const plugin of options.plugins) {\n\t\tentries.set(plugin.pluginId, {\n\t\t\tpluginId: plugin.pluginId,\n\t\t\thealth: \"healthy\",\n\t\t\trestarts: 0,\n\t\t\tlastBeatAt: now(),\n\t\t});\n\t}\n\n\treturn {\n\t\tsupervise(plugin) {\n\t\t\tentries.set(plugin.pluginId, {\n\t\t\t\tpluginId: plugin.pluginId,\n\t\t\t\thealth: \"healthy\",\n\t\t\t\trestarts: 0,\n\t\t\t\tlastBeatAt: now(),\n\t\t\t});\n\t\t},\n\t\tbeat(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) throw new Error(`Unknown supervised plugin: ${pluginId}`);\n\t\t\tentry.lastBeatAt = now();\n\t\t\tentry.health = \"healthy\";\n\t\t\tevents.push({ kind: \"beat\", pluginId, at: entry.lastBeatAt });\n\t\t},\n\t\ttick(at) {\n\t\t\tfor (const entry of entries.values()) {\n\t\t\t\tif (entry.health !== \"unhealthy\" && at - entry.lastBeatAt > policy.heartbeatIntervalMs) {\n\t\t\t\t\tentry.health = \"unhealthy\";\n\t\t\t\t\tevents.push({ kind: \"unhealthy\", pluginId: entry.pluginId, at });\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\trestart(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) return { status: \"unknown\" as const };\n\t\t\tif (entry.health === \"exhausted\") return { status: \"exhausted\" as const, attempts: entry.restarts };\n\t\t\tif (entry.nextRestartAllowedAt !== undefined && now() < entry.nextRestartAllowedAt) {\n\t\t\t\treturn { status: \"restarted\" as const, attempt: entry.restarts };\n\t\t\t}\n\t\t\tentry.restarts += 1;\n\t\t\tif (entry.restarts > policy.restartLimit) {\n\t\t\t\tentry.health = \"exhausted\";\n\t\t\t\tevents.push({ kind: \"exhausted\", pluginId, at: now(), attempts: entry.restarts - 1 });\n\t\t\t\treturn { status: \"exhausted\" as const, attempts: entry.restarts - 1 };\n\t\t\t}\n\t\t\tvoid options.restartPlugin?.(pluginId, entry.restarts);\n\t\t\tentry.health = \"healthy\";\n\t\t\tentry.lastBeatAt = now();\n\t\t\tconst backoff = Math.min(policy.baseRestartMs * 2 ** (entry.restarts - 1), Number.MAX_SAFE_INTEGER);\n\t\t\tentry.nextRestartAllowedAt = now() + backoff;\n\t\t\tevents.push({ kind: \"restart\", pluginId, at: now(), attempt: entry.restarts });\n\t\t\treturn { status: \"restarted\", attempt: entry.restarts };\n\t\t},\n\t\tenqueue(event) {\n\t\t\tif (queue.length >= policy.queueCap) {\n\t\t\t\tevents.push({ kind: \"queue_full\", at: now() });\n\t\t\t\treturn { status: \"queue_full\", size: queue.length };\n\t\t\t}\n\t\t\tqueue.push(event);\n\t\t\treturn { status: \"enqueued\", size: queue.length };\n\t\t},\n\t\tdrain() {\n\t\t\treturn Object.freeze(queue.splice(0, queue.length));\n\t\t},\n\t\thealth() {\n\t\t\treturn Object.freeze([...entries.values()].map((entry) => ({ ...entry })));\n\t\t},\n\t\tget queueSize() {\n\t\t\treturn queue.length;\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"plugin-supervisor.d.ts","sourceRoot":"","sources":["../../src/plugins/plugin-supervisor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAA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,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9F,KAAK,IAAI,SAAS,MAAM,EAAE,CAAC;IAC3B,MAAM,IAAI,SAAS,iBAAiB,EAAE,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC/C,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAC;IAC5C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACrF,GAAG,kBAAkB,CAuFrB","sourcesContent":["/**\n * Plugin supervisor (7.2) — heartbeat, restart, and backpressure over the\n * 7.1 plugin host, all deterministic (clock and sleep are injected; there\n * are no hidden timers).\n *\n * Heartbeat: every supervised plugin must report a beat before\n * `heartbeatIntervalMs` elapses since its last beat, checked only by an\n * explicit `tick()`. A missed beat marks the plugin unhealthy and triggers\n * a restart policy (bounded attempts with exponential backoff). Restart:\n * the supervisor re-invokes the plugin's start with the recorded attempt\n * number; a plugin exceeding `restartLimit` ends in a terminal\n * `exhausted` health. Backpressure: an internal event queue with a hard\n * cap — enqueueing beyond the cap fails closed with `queue_full` instead of\n * growing unbounded. Fault injection is trivially the caller's job: the\n * tests simulate missed beats and crashes directly. Supply-chain signing is\n * 7.3.\n */\n\nimport { t } from \"../core/i18n/index.ts\";\nimport type { HostedPluginV1 } from \"./plugin-host.ts\";\n\nexport interface SupervisorPolicyV1 {\n\treadonly heartbeatIntervalMs: number;\n\treadonly restartLimit: number;\n\treadonly baseRestartMs: number;\n\treadonly queueCap: number;\n}\n\nexport type PluginHealthV1 = \"healthy\" | \"unhealthy\" | \"exhausted\" | \"stopped\";\n\nexport interface SupervisorEntryV1 {\n\treadonly pluginId: string;\n\treadonly health: PluginHealthV1;\n\treadonly restarts: number;\n\treadonly lastBeatAt: number;\n\treadonly nextRestartAllowedAt?: number;\n}\n\nexport type SupervisorEventV1 =\n\t| { readonly kind: \"beat\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"unhealthy\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"restart\"; readonly pluginId: string; readonly at: number; readonly attempt: number }\n\t| { readonly kind: \"exhausted\"; readonly pluginId: string; readonly at: number; readonly attempts: number }\n\t| { readonly kind: \"queue_full\"; readonly at: number };\n\nexport interface PluginSupervisorV1 {\n\tsupervise(plugin: HostedPluginV1): void;\n\tbeat(pluginId: string): void;\n\ttick(at: number): void;\n\trestart(pluginId: string): { readonly status: \"restarted\" | \"exhausted\" | \"unknown\"; readonly attempt?: number };\n\tenqueue(event: string): { readonly status: \"enqueued\" | \"queue_full\"; readonly size: number };\n\tdrain(): readonly string[];\n\thealth(): readonly SupervisorEntryV1[];\n\treadonly queueSize: number;\n}\n\nexport function createPluginSupervisor(options: {\n\treadonly policy: SupervisorPolicyV1;\n\treadonly plugins: readonly HostedPluginV1[];\n\treadonly now?: () => number;\n\treadonly restartPlugin?: (pluginId: string, attempt: number) => Promise<void> | void;\n}): PluginSupervisorV1 {\n\tconst policy = options.policy;\n\tconst now = options.now ?? (() => 0);\n\n\tinterface Entry {\n\t\tpluginId: string;\n\t\thealth: PluginHealthV1;\n\t\trestarts: number;\n\t\tlastBeatAt: number;\n\t\tnextRestartAllowedAt?: number;\n\t}\n\tconst entries = new Map<string, Entry>();\n\tconst events: SupervisorEventV1[] = [];\n\tconst queue: string[] = [];\n\n\tfor (const plugin of options.plugins) {\n\t\tentries.set(plugin.pluginId, {\n\t\t\tpluginId: plugin.pluginId,\n\t\t\thealth: \"healthy\",\n\t\t\trestarts: 0,\n\t\t\tlastBeatAt: now(),\n\t\t});\n\t}\n\n\treturn {\n\t\tsupervise(plugin) {\n\t\t\tentries.set(plugin.pluginId, {\n\t\t\t\tpluginId: plugin.pluginId,\n\t\t\t\thealth: \"healthy\",\n\t\t\t\trestarts: 0,\n\t\t\t\tlastBeatAt: now(),\n\t\t\t});\n\t\t},\n\t\tbeat(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) throw new Error(t(\"Unknown supervised plugin: {pluginId}\", { pluginId }));\n\t\t\tentry.lastBeatAt = now();\n\t\t\tentry.health = \"healthy\";\n\t\t\tevents.push({ kind: \"beat\", pluginId, at: entry.lastBeatAt });\n\t\t},\n\t\ttick(at) {\n\t\t\tfor (const entry of entries.values()) {\n\t\t\t\tif (entry.health !== \"unhealthy\" && at - entry.lastBeatAt > policy.heartbeatIntervalMs) {\n\t\t\t\t\tentry.health = \"unhealthy\";\n\t\t\t\t\tevents.push({ kind: \"unhealthy\", pluginId: entry.pluginId, at });\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\trestart(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) return { status: \"unknown\" as const };\n\t\t\tif (entry.health === \"exhausted\") return { status: \"exhausted\" as const, attempts: entry.restarts };\n\t\t\tif (entry.nextRestartAllowedAt !== undefined && now() < entry.nextRestartAllowedAt) {\n\t\t\t\treturn { status: \"restarted\" as const, attempt: entry.restarts };\n\t\t\t}\n\t\t\tentry.restarts += 1;\n\t\t\tif (entry.restarts > policy.restartLimit) {\n\t\t\t\tentry.health = \"exhausted\";\n\t\t\t\tevents.push({ kind: \"exhausted\", pluginId, at: now(), attempts: entry.restarts - 1 });\n\t\t\t\treturn { status: \"exhausted\" as const, attempts: entry.restarts - 1 };\n\t\t\t}\n\t\t\tvoid options.restartPlugin?.(pluginId, entry.restarts);\n\t\t\tentry.health = \"healthy\";\n\t\t\tentry.lastBeatAt = now();\n\t\t\tconst backoff = Math.min(policy.baseRestartMs * 2 ** (entry.restarts - 1), Number.MAX_SAFE_INTEGER);\n\t\t\tentry.nextRestartAllowedAt = now() + backoff;\n\t\t\tevents.push({ kind: \"restart\", pluginId, at: now(), attempt: entry.restarts });\n\t\t\treturn { status: \"restarted\", attempt: entry.restarts };\n\t\t},\n\t\tenqueue(event) {\n\t\t\tif (queue.length >= policy.queueCap) {\n\t\t\t\tevents.push({ kind: \"queue_full\", at: now() });\n\t\t\t\treturn { status: \"queue_full\", size: queue.length };\n\t\t\t}\n\t\t\tqueue.push(event);\n\t\t\treturn { status: \"enqueued\", size: queue.length };\n\t\t},\n\t\tdrain() {\n\t\t\treturn Object.freeze(queue.splice(0, queue.length));\n\t\t},\n\t\thealth() {\n\t\t\treturn Object.freeze([...entries.values()].map((entry) => ({ ...entry })));\n\t\t},\n\t\tget queueSize() {\n\t\t\treturn queue.length;\n\t\t},\n\t};\n}\n"]}
@@ -1,3 +1,21 @@
1
+ /**
2
+ * Plugin supervisor (7.2) — heartbeat, restart, and backpressure over the
3
+ * 7.1 plugin host, all deterministic (clock and sleep are injected; there
4
+ * are no hidden timers).
5
+ *
6
+ * Heartbeat: every supervised plugin must report a beat before
7
+ * `heartbeatIntervalMs` elapses since its last beat, checked only by an
8
+ * explicit `tick()`. A missed beat marks the plugin unhealthy and triggers
9
+ * a restart policy (bounded attempts with exponential backoff). Restart:
10
+ * the supervisor re-invokes the plugin's start with the recorded attempt
11
+ * number; a plugin exceeding `restartLimit` ends in a terminal
12
+ * `exhausted` health. Backpressure: an internal event queue with a hard
13
+ * cap — enqueueing beyond the cap fails closed with `queue_full` instead of
14
+ * growing unbounded. Fault injection is trivially the caller's job: the
15
+ * tests simulate missed beats and crashes directly. Supply-chain signing is
16
+ * 7.3.
17
+ */
18
+ import { t } from "../core/i18n/index.js";
1
19
  export function createPluginSupervisor(options) {
2
20
  const policy = options.policy;
3
21
  const now = options.now ?? (() => 0);
@@ -24,7 +42,7 @@ export function createPluginSupervisor(options) {
24
42
  beat(pluginId) {
25
43
  const entry = entries.get(pluginId);
26
44
  if (!entry)
27
- throw new Error(`Unknown supervised plugin: ${pluginId}`);
45
+ throw new Error(t("Unknown supervised plugin: {pluginId}", { pluginId }));
28
46
  entry.lastBeatAt = now();
29
47
  entry.health = "healthy";
30
48
  events.push({ kind: "beat", pluginId, at: entry.lastBeatAt });
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-supervisor.js","sourceRoot":"","sources":["../../src/plugins/plugin-supervisor.ts"],"names":[],"mappings":"AAsDA,MAAM,UAAU,sBAAsB,CAAC,OAKtC,EAAsB;IACtB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IASrC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACzC,MAAM,MAAM,GAAwB,EAAE,CAAC;IACvC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,SAAS;YACjB,QAAQ,EAAE,CAAC;YACX,UAAU,EAAE,GAAG,EAAE;SACjB,CAAC,CAAC;IACJ,CAAC;IAED,OAAO;QACN,SAAS,CAAC,MAAM,EAAE;YACjB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ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,EAAE,CAAC,CAAC;YAC/E,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;QAAA,CACxD;QACD,OAAO,CAAC,KAAK,EAAE;YACd,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACrC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC/C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;YACrD,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAAA,CAClD;QACD,KAAK,GAAG;YACP,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAAA,CACpD;QACD,MAAM,GAAG;YACR,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAAA,CAC3E;QACD,IAAI,SAAS,GAAG;YACf,OAAO,KAAK,CAAC,MAAM,CAAC;QAAA,CACpB;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Plugin supervisor (7.2) — heartbeat, restart, and backpressure over the\n * 7.1 plugin host, all deterministic (clock and sleep are injected; there\n * are no hidden timers).\n *\n * Heartbeat: every supervised plugin must report a beat before\n * `heartbeatIntervalMs` elapses since its last beat, checked only by an\n * explicit `tick()`. A missed beat marks the plugin unhealthy and triggers\n * a restart policy (bounded attempts with exponential backoff). Restart:\n * the supervisor re-invokes the plugin's start with the recorded attempt\n * number; a plugin exceeding `restartLimit` ends in a terminal\n * `exhausted` health. Backpressure: an internal event queue with a hard\n * cap — enqueueing beyond the cap fails closed with `queue_full` instead of\n * growing unbounded. Fault injection is trivially the caller's job: the\n * tests simulate missed beats and crashes directly. Supply-chain signing is\n * 7.3.\n */\nimport type { HostedPluginV1 } from \"./plugin-host.ts\";\n\nexport interface SupervisorPolicyV1 {\n\treadonly heartbeatIntervalMs: number;\n\treadonly restartLimit: number;\n\treadonly baseRestartMs: number;\n\treadonly queueCap: number;\n}\n\nexport type PluginHealthV1 = \"healthy\" | \"unhealthy\" | \"exhausted\" | \"stopped\";\n\nexport interface SupervisorEntryV1 {\n\treadonly pluginId: string;\n\treadonly health: PluginHealthV1;\n\treadonly restarts: number;\n\treadonly lastBeatAt: number;\n\treadonly nextRestartAllowedAt?: number;\n}\n\nexport type SupervisorEventV1 =\n\t| { readonly kind: \"beat\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"unhealthy\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"restart\"; readonly pluginId: string; readonly at: number; readonly attempt: number }\n\t| { readonly kind: \"exhausted\"; readonly pluginId: string; readonly at: number; readonly attempts: number }\n\t| { readonly kind: \"queue_full\"; readonly at: number };\n\nexport interface PluginSupervisorV1 {\n\tsupervise(plugin: HostedPluginV1): void;\n\tbeat(pluginId: string): void;\n\ttick(at: number): void;\n\trestart(pluginId: string): { readonly status: \"restarted\" | \"exhausted\" | \"unknown\"; readonly attempt?: number };\n\tenqueue(event: string): { readonly status: \"enqueued\" | \"queue_full\"; readonly size: number };\n\tdrain(): readonly string[];\n\thealth(): readonly SupervisorEntryV1[];\n\treadonly queueSize: number;\n}\n\nexport function createPluginSupervisor(options: {\n\treadonly policy: SupervisorPolicyV1;\n\treadonly plugins: readonly HostedPluginV1[];\n\treadonly now?: () => number;\n\treadonly restartPlugin?: (pluginId: string, attempt: number) => Promise<void> | void;\n}): PluginSupervisorV1 {\n\tconst policy = options.policy;\n\tconst now = options.now ?? (() => 0);\n\n\tinterface Entry {\n\t\tpluginId: string;\n\t\thealth: PluginHealthV1;\n\t\trestarts: number;\n\t\tlastBeatAt: number;\n\t\tnextRestartAllowedAt?: number;\n\t}\n\tconst entries = new Map<string, Entry>();\n\tconst events: SupervisorEventV1[] = [];\n\tconst queue: string[] = [];\n\n\tfor (const plugin of options.plugins) {\n\t\tentries.set(plugin.pluginId, {\n\t\t\tpluginId: plugin.pluginId,\n\t\t\thealth: \"healthy\",\n\t\t\trestarts: 0,\n\t\t\tlastBeatAt: now(),\n\t\t});\n\t}\n\n\treturn {\n\t\tsupervise(plugin) {\n\t\t\tentries.set(plugin.pluginId, {\n\t\t\t\tpluginId: plugin.pluginId,\n\t\t\t\thealth: \"healthy\",\n\t\t\t\trestarts: 0,\n\t\t\t\tlastBeatAt: now(),\n\t\t\t});\n\t\t},\n\t\tbeat(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) throw new Error(`Unknown supervised plugin: ${pluginId}`);\n\t\t\tentry.lastBeatAt = now();\n\t\t\tentry.health = \"healthy\";\n\t\t\tevents.push({ kind: \"beat\", pluginId, at: entry.lastBeatAt });\n\t\t},\n\t\ttick(at) {\n\t\t\tfor (const entry of entries.values()) {\n\t\t\t\tif (entry.health !== \"unhealthy\" && at - entry.lastBeatAt > policy.heartbeatIntervalMs) {\n\t\t\t\t\tentry.health = \"unhealthy\";\n\t\t\t\t\tevents.push({ kind: \"unhealthy\", pluginId: entry.pluginId, at });\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\trestart(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) return { status: \"unknown\" as const };\n\t\t\tif (entry.health === \"exhausted\") return { status: \"exhausted\" as const, attempts: entry.restarts };\n\t\t\tif (entry.nextRestartAllowedAt !== undefined && now() < entry.nextRestartAllowedAt) {\n\t\t\t\treturn { status: \"restarted\" as const, attempt: entry.restarts };\n\t\t\t}\n\t\t\tentry.restarts += 1;\n\t\t\tif (entry.restarts > policy.restartLimit) {\n\t\t\t\tentry.health = \"exhausted\";\n\t\t\t\tevents.push({ kind: \"exhausted\", pluginId, at: now(), attempts: entry.restarts - 1 });\n\t\t\t\treturn { status: \"exhausted\" as const, attempts: entry.restarts - 1 };\n\t\t\t}\n\t\t\tvoid options.restartPlugin?.(pluginId, entry.restarts);\n\t\t\tentry.health = \"healthy\";\n\t\t\tentry.lastBeatAt = now();\n\t\t\tconst backoff = Math.min(policy.baseRestartMs * 2 ** (entry.restarts - 1), Number.MAX_SAFE_INTEGER);\n\t\t\tentry.nextRestartAllowedAt = now() + backoff;\n\t\t\tevents.push({ kind: \"restart\", pluginId, at: now(), attempt: entry.restarts });\n\t\t\treturn { status: \"restarted\", attempt: entry.restarts };\n\t\t},\n\t\tenqueue(event) {\n\t\t\tif (queue.length >= policy.queueCap) {\n\t\t\t\tevents.push({ kind: \"queue_full\", at: now() });\n\t\t\t\treturn { status: \"queue_full\", size: queue.length };\n\t\t\t}\n\t\t\tqueue.push(event);\n\t\t\treturn { status: \"enqueued\", size: queue.length };\n\t\t},\n\t\tdrain() {\n\t\t\treturn Object.freeze(queue.splice(0, queue.length));\n\t\t},\n\t\thealth() {\n\t\t\treturn Object.freeze([...entries.values()].map((entry) => ({ ...entry })));\n\t\t},\n\t\tget queueSize() {\n\t\t\treturn queue.length;\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"plugin-supervisor.js","sourceRoot":"","sources":["../../src/plugins/plugin-supervisor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAsC1C,MAAM,UAAU,sBAAsB,CAAC,OAKtC,EAAsB;IACtB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAA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AM,GAAG;YACR,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAAA,CAC3E;QACD,IAAI,SAAS,GAAG;YACf,OAAO,KAAK,CAAC,MAAM,CAAC;QAAA,CACpB;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Plugin supervisor (7.2) — heartbeat, restart, and backpressure over the\n * 7.1 plugin host, all deterministic (clock and sleep are injected; there\n * are no hidden timers).\n *\n * Heartbeat: every supervised plugin must report a beat before\n * `heartbeatIntervalMs` elapses since its last beat, checked only by an\n * explicit `tick()`. A missed beat marks the plugin unhealthy and triggers\n * a restart policy (bounded attempts with exponential backoff). Restart:\n * the supervisor re-invokes the plugin's start with the recorded attempt\n * number; a plugin exceeding `restartLimit` ends in a terminal\n * `exhausted` health. Backpressure: an internal event queue with a hard\n * cap — enqueueing beyond the cap fails closed with `queue_full` instead of\n * growing unbounded. Fault injection is trivially the caller's job: the\n * tests simulate missed beats and crashes directly. Supply-chain signing is\n * 7.3.\n */\n\nimport { t } from \"../core/i18n/index.ts\";\nimport type { HostedPluginV1 } from \"./plugin-host.ts\";\n\nexport interface SupervisorPolicyV1 {\n\treadonly heartbeatIntervalMs: number;\n\treadonly restartLimit: number;\n\treadonly baseRestartMs: number;\n\treadonly queueCap: number;\n}\n\nexport type PluginHealthV1 = \"healthy\" | \"unhealthy\" | \"exhausted\" | \"stopped\";\n\nexport interface SupervisorEntryV1 {\n\treadonly pluginId: string;\n\treadonly health: PluginHealthV1;\n\treadonly restarts: number;\n\treadonly lastBeatAt: number;\n\treadonly nextRestartAllowedAt?: number;\n}\n\nexport type SupervisorEventV1 =\n\t| { readonly kind: \"beat\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"unhealthy\"; readonly pluginId: string; readonly at: number }\n\t| { readonly kind: \"restart\"; readonly pluginId: string; readonly at: number; readonly attempt: number }\n\t| { readonly kind: \"exhausted\"; readonly pluginId: string; readonly at: number; readonly attempts: number }\n\t| { readonly kind: \"queue_full\"; readonly at: number };\n\nexport interface PluginSupervisorV1 {\n\tsupervise(plugin: HostedPluginV1): void;\n\tbeat(pluginId: string): void;\n\ttick(at: number): void;\n\trestart(pluginId: string): { readonly status: \"restarted\" | \"exhausted\" | \"unknown\"; readonly attempt?: number };\n\tenqueue(event: string): { readonly status: \"enqueued\" | \"queue_full\"; readonly size: number };\n\tdrain(): readonly string[];\n\thealth(): readonly SupervisorEntryV1[];\n\treadonly queueSize: number;\n}\n\nexport function createPluginSupervisor(options: {\n\treadonly policy: SupervisorPolicyV1;\n\treadonly plugins: readonly HostedPluginV1[];\n\treadonly now?: () => number;\n\treadonly restartPlugin?: (pluginId: string, attempt: number) => Promise<void> | void;\n}): PluginSupervisorV1 {\n\tconst policy = options.policy;\n\tconst now = options.now ?? (() => 0);\n\n\tinterface Entry {\n\t\tpluginId: string;\n\t\thealth: PluginHealthV1;\n\t\trestarts: number;\n\t\tlastBeatAt: number;\n\t\tnextRestartAllowedAt?: number;\n\t}\n\tconst entries = new Map<string, Entry>();\n\tconst events: SupervisorEventV1[] = [];\n\tconst queue: string[] = [];\n\n\tfor (const plugin of options.plugins) {\n\t\tentries.set(plugin.pluginId, {\n\t\t\tpluginId: plugin.pluginId,\n\t\t\thealth: \"healthy\",\n\t\t\trestarts: 0,\n\t\t\tlastBeatAt: now(),\n\t\t});\n\t}\n\n\treturn {\n\t\tsupervise(plugin) {\n\t\t\tentries.set(plugin.pluginId, {\n\t\t\t\tpluginId: plugin.pluginId,\n\t\t\t\thealth: \"healthy\",\n\t\t\t\trestarts: 0,\n\t\t\t\tlastBeatAt: now(),\n\t\t\t});\n\t\t},\n\t\tbeat(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) throw new Error(t(\"Unknown supervised plugin: {pluginId}\", { pluginId }));\n\t\t\tentry.lastBeatAt = now();\n\t\t\tentry.health = \"healthy\";\n\t\t\tevents.push({ kind: \"beat\", pluginId, at: entry.lastBeatAt });\n\t\t},\n\t\ttick(at) {\n\t\t\tfor (const entry of entries.values()) {\n\t\t\t\tif (entry.health !== \"unhealthy\" && at - entry.lastBeatAt > policy.heartbeatIntervalMs) {\n\t\t\t\t\tentry.health = \"unhealthy\";\n\t\t\t\t\tevents.push({ kind: \"unhealthy\", pluginId: entry.pluginId, at });\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\trestart(pluginId) {\n\t\t\tconst entry = entries.get(pluginId);\n\t\t\tif (!entry) return { status: \"unknown\" as const };\n\t\t\tif (entry.health === \"exhausted\") return { status: \"exhausted\" as const, attempts: entry.restarts };\n\t\t\tif (entry.nextRestartAllowedAt !== undefined && now() < entry.nextRestartAllowedAt) {\n\t\t\t\treturn { status: \"restarted\" as const, attempt: entry.restarts };\n\t\t\t}\n\t\t\tentry.restarts += 1;\n\t\t\tif (entry.restarts > policy.restartLimit) {\n\t\t\t\tentry.health = \"exhausted\";\n\t\t\t\tevents.push({ kind: \"exhausted\", pluginId, at: now(), attempts: entry.restarts - 1 });\n\t\t\t\treturn { status: \"exhausted\" as const, attempts: entry.restarts - 1 };\n\t\t\t}\n\t\t\tvoid options.restartPlugin?.(pluginId, entry.restarts);\n\t\t\tentry.health = \"healthy\";\n\t\t\tentry.lastBeatAt = now();\n\t\t\tconst backoff = Math.min(policy.baseRestartMs * 2 ** (entry.restarts - 1), Number.MAX_SAFE_INTEGER);\n\t\t\tentry.nextRestartAllowedAt = now() + backoff;\n\t\t\tevents.push({ kind: \"restart\", pluginId, at: now(), attempt: entry.restarts });\n\t\t\treturn { status: \"restarted\", attempt: entry.restarts };\n\t\t},\n\t\tenqueue(event) {\n\t\t\tif (queue.length >= policy.queueCap) {\n\t\t\t\tevents.push({ kind: \"queue_full\", at: now() });\n\t\t\t\treturn { status: \"queue_full\", size: queue.length };\n\t\t\t}\n\t\t\tqueue.push(event);\n\t\t\treturn { status: \"enqueued\", size: queue.length };\n\t\t},\n\t\tdrain() {\n\t\t\treturn Object.freeze(queue.splice(0, queue.length));\n\t\t},\n\t\thealth() {\n\t\t\treturn Object.freeze([...entries.values()].map((entry) => ({ ...entry })));\n\t\t},\n\t\tget queueSize() {\n\t\t\treturn queue.length;\n\t\t},\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"first-roles.d.ts","sourceRoot":"","sources":["../../src/profile/first-roles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGvE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzF;AAsCD,eAAO,MAAM,iBAAiB,EAAE,SAAS;IACxC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;CACtC,EAmBA,CAAC;AAEF,kEAAkE;AAClE,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,aAAa,GAAG;IACnE,QAAQ,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC5C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjG,CAeA","sourcesContent":["/**\n * First-batch role vertical slices (2.2c): 架构/实现/测试.\n *\n * Each role is a `RoleMetadataV1` registered in the role catalog plus a\n * deterministic runner that only consumes the public facade — no private\n * session access. These are the first vertical slices proving that a role can\n * be declared, discovered, and executed end to end.\n */\nimport type { RoleCatalogV1, RoleMetadataV1 } from \"./role-catalog.ts\";\nimport { validateRoleMetadataV1 } from \"./role-catalog.ts\";\n\nexport interface FirstBatchRoleV1 {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: (input: { readonly spec: string }) => Promise<{ readonly result: string }>;\n}\n\nconst ARCHITECTURE_ROLE: RoleMetadataV1 = {\n\troleId: \"architecture-analyst\",\n\ttitle: \"Architecture Analyst\",\n\tinput: { schemaId: \"role/architecture-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/architecture-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"module structure findings recorded\",\n};\n\nconst IMPLEMENTER_ROLE: RoleMetadataV1 = {\n\troleId: \"implementer\",\n\ttitle: \"Implementer\",\n\tinput: { schemaId: \"role/implement-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/implement-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [\n\t\t{ capabilityId: \"tool.edit\", capabilityVersion: 1, required: true },\n\t\t{ capabilityId: \"tool.write\", capabilityVersion: 1, required: false },\n\t],\n\twritableScopes: [\"session\", \"cycle\"],\n\tconcurrency: \"single\",\n\tcompletionCriteria: \"patch produced for the requested spec\",\n};\n\nconst TEST_DESIGNER_ROLE: RoleMetadataV1 = {\n\troleId: \"test-designer\",\n\ttitle: \"Test Designer\",\n\tinput: { schemaId: \"role/test-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/test-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"test cases derived from the spec\",\n};\n\nexport const FIRST_BATCH_ROLES: readonly {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: FirstBatchRoleV1[\"run\"];\n}[] = [\n\t{\n\t\tmetadata: ARCHITECTURE_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `architecture findings for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: IMPLEMENTER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `patch for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: TEST_DESIGNER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `test cases for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n];\n\n/** Registers and returns the first-batch role vertical slices. */\nexport function createFirstBatchRoleSlices(catalog: RoleCatalogV1): {\n\treadonly roles: readonly FirstBatchRoleV1[];\n\trun(roleId: string, spec: string): Promise<{ readonly roleId: string; readonly result: string }>;\n} {\n\tconst roles = FIRST_BATCH_ROLES.map((role) => ({\n\t\tmetadata: validateRoleMetadataV1(role.metadata),\n\t\trun: role.run,\n\t}));\n\tfor (const role of roles) catalog.register(role.metadata);\n\tconst runners = new Map(roles.map((role) => [role.metadata.roleId, role.run]));\n\treturn {\n\t\troles,\n\t\tasync run(roleId, spec) {\n\t\t\tconst run = runners.get(roleId);\n\t\t\tif (!run) throw new Error(`Unknown first-batch role: ${roleId}`);\n\t\t\treturn { roleId, result: (await run({ spec })).result };\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"first-roles.d.ts","sourceRoot":"","sources":["../../src/profile/first-roles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGvE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzF;AAsCD,eAAO,MAAM,iBAAiB,EAAE,SAAS;IACxC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;CACtC,EAmBA,CAAC;AAEF,kEAAkE;AAClE,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,aAAa,GAAG;IACnE,QAAQ,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC5C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjG,CAeA","sourcesContent":["/**\n * First-batch role vertical slices (2.2c): 架构/实现/测试.\n *\n * Each role is a `RoleMetadataV1` registered in the role catalog plus a\n * deterministic runner that only consumes the public facade — no private\n * session access. These are the first vertical slices proving that a role can\n * be declared, discovered, and executed end to end.\n */\n\nimport { t } from \"../core/i18n/index.ts\";\nimport type { RoleCatalogV1, RoleMetadataV1 } from \"./role-catalog.ts\";\nimport { validateRoleMetadataV1 } from \"./role-catalog.ts\";\n\nexport interface FirstBatchRoleV1 {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: (input: { readonly spec: string }) => Promise<{ readonly result: string }>;\n}\n\nconst ARCHITECTURE_ROLE: RoleMetadataV1 = {\n\troleId: \"architecture-analyst\",\n\ttitle: \"Architecture Analyst\",\n\tinput: { schemaId: \"role/architecture-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/architecture-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"module structure findings recorded\",\n};\n\nconst IMPLEMENTER_ROLE: RoleMetadataV1 = {\n\troleId: \"implementer\",\n\ttitle: \"Implementer\",\n\tinput: { schemaId: \"role/implement-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/implement-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [\n\t\t{ capabilityId: \"tool.edit\", capabilityVersion: 1, required: true },\n\t\t{ capabilityId: \"tool.write\", capabilityVersion: 1, required: false },\n\t],\n\twritableScopes: [\"session\", \"cycle\"],\n\tconcurrency: \"single\",\n\tcompletionCriteria: \"patch produced for the requested spec\",\n};\n\nconst TEST_DESIGNER_ROLE: RoleMetadataV1 = {\n\troleId: \"test-designer\",\n\ttitle: \"Test Designer\",\n\tinput: { schemaId: \"role/test-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/test-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"test cases derived from the spec\",\n};\n\nexport const FIRST_BATCH_ROLES: readonly {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: FirstBatchRoleV1[\"run\"];\n}[] = [\n\t{\n\t\tmetadata: ARCHITECTURE_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `architecture findings for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: IMPLEMENTER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `patch for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: TEST_DESIGNER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `test cases for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n];\n\n/** Registers and returns the first-batch role vertical slices. */\nexport function createFirstBatchRoleSlices(catalog: RoleCatalogV1): {\n\treadonly roles: readonly FirstBatchRoleV1[];\n\trun(roleId: string, spec: string): Promise<{ readonly roleId: string; readonly result: string }>;\n} {\n\tconst roles = FIRST_BATCH_ROLES.map((role) => ({\n\t\tmetadata: validateRoleMetadataV1(role.metadata),\n\t\trun: role.run,\n\t}));\n\tfor (const role of roles) catalog.register(role.metadata);\n\tconst runners = new Map(roles.map((role) => [role.metadata.roleId, role.run]));\n\treturn {\n\t\troles,\n\t\tasync run(roleId, spec) {\n\t\t\tconst run = runners.get(roleId);\n\t\t\tif (!run) throw new Error(t(\"Unknown first-batch role: {roleId}\", { roleId }));\n\t\t\treturn { roleId, result: (await run({ spec })).result };\n\t\t},\n\t};\n}\n"]}
@@ -1,3 +1,12 @@
1
+ /**
2
+ * First-batch role vertical slices (2.2c): 架构/实现/测试.
3
+ *
4
+ * Each role is a `RoleMetadataV1` registered in the role catalog plus a
5
+ * deterministic runner that only consumes the public facade — no private
6
+ * session access. These are the first vertical slices proving that a role can
7
+ * be declared, discovered, and executed end to end.
8
+ */
9
+ import { t } from "../core/i18n/index.js";
1
10
  import { validateRoleMetadataV1 } from "./role-catalog.js";
2
11
  const ARCHITECTURE_ROLE = {
3
12
  roleId: "architecture-analyst",
@@ -66,7 +75,7 @@ export function createFirstBatchRoleSlices(catalog) {
66
75
  async run(roleId, spec) {
67
76
  const run = runners.get(roleId);
68
77
  if (!run)
69
- throw new Error(`Unknown first-batch role: ${roleId}`);
78
+ throw new Error(t("Unknown first-batch role: {roleId}", { roleId }));
70
79
  return { roleId, result: (await run({ spec })).result };
71
80
  },
72
81
  };
@@ -1 +1 @@
1
- {"version":3,"file":"first-roles.js","sourceRoot":"","sources":["../../src/profile/first-roles.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAO3D,MAAM,iBAAiB,GAAmB;IACzC,MAAM,EAAE,sBAAsB;IAC9B,KAAK,EAAE,sBAAsB;IAC7B,KAAK,EA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AAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO;QACN,KAAK;QACL,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE;YACvB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAC;YACjE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAAA,CACxD;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * First-batch role vertical slices (2.2c): 架构/实现/测试.\n *\n * Each role is a `RoleMetadataV1` registered in the role catalog plus a\n * deterministic runner that only consumes the public facade — no private\n * session access. These are the first vertical slices proving that a role can\n * be declared, discovered, and executed end to end.\n */\nimport type { RoleCatalogV1, RoleMetadataV1 } from \"./role-catalog.ts\";\nimport { validateRoleMetadataV1 } from \"./role-catalog.ts\";\n\nexport interface FirstBatchRoleV1 {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: (input: { readonly spec: string }) => Promise<{ readonly result: string }>;\n}\n\nconst ARCHITECTURE_ROLE: RoleMetadataV1 = {\n\troleId: \"architecture-analyst\",\n\ttitle: \"Architecture Analyst\",\n\tinput: { schemaId: \"role/architecture-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/architecture-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"module structure findings recorded\",\n};\n\nconst IMPLEMENTER_ROLE: RoleMetadataV1 = {\n\troleId: \"implementer\",\n\ttitle: \"Implementer\",\n\tinput: { schemaId: \"role/implement-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/implement-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [\n\t\t{ capabilityId: \"tool.edit\", capabilityVersion: 1, required: true },\n\t\t{ capabilityId: \"tool.write\", capabilityVersion: 1, required: false },\n\t],\n\twritableScopes: [\"session\", \"cycle\"],\n\tconcurrency: \"single\",\n\tcompletionCriteria: \"patch produced for the requested spec\",\n};\n\nconst TEST_DESIGNER_ROLE: RoleMetadataV1 = {\n\troleId: \"test-designer\",\n\ttitle: \"Test Designer\",\n\tinput: { schemaId: \"role/test-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/test-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"test cases derived from the spec\",\n};\n\nexport const FIRST_BATCH_ROLES: readonly {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: FirstBatchRoleV1[\"run\"];\n}[] = [\n\t{\n\t\tmetadata: ARCHITECTURE_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `architecture findings for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: IMPLEMENTER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `patch for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: TEST_DESIGNER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `test cases for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n];\n\n/** Registers and returns the first-batch role vertical slices. */\nexport function createFirstBatchRoleSlices(catalog: RoleCatalogV1): {\n\treadonly roles: readonly FirstBatchRoleV1[];\n\trun(roleId: string, spec: string): Promise<{ readonly roleId: string; readonly result: string }>;\n} {\n\tconst roles = FIRST_BATCH_ROLES.map((role) => ({\n\t\tmetadata: validateRoleMetadataV1(role.metadata),\n\t\trun: role.run,\n\t}));\n\tfor (const role of roles) catalog.register(role.metadata);\n\tconst runners = new Map(roles.map((role) => [role.metadata.roleId, role.run]));\n\treturn {\n\t\troles,\n\t\tasync run(roleId, spec) {\n\t\t\tconst run = runners.get(roleId);\n\t\t\tif (!run) throw new Error(`Unknown first-batch role: ${roleId}`);\n\t\t\treturn { roleId, result: (await run({ spec })).result };\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"first-roles.js","sourceRoot":"","sources":["../../src/profile/first-roles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAE1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAO3D,MAAM,iBAAiB,GAAmB;IACzC,MAAM,EAAE,sBAAsB;IAC9B,KAAK,EAAE,sBAAsB;IAC7B,KAAK,EAAE,EAAE,QAAQ,EAAE,2BAA2B,EAAE,aAAa,EAAE,CAAC,EAAE;IAClE,MAAM,EAAE,EAAE,QAAQ,EAAE,4BAA4B,EAAE,aAAa,EAAE,CAAC,EAAE;IACpE,sBAAsB,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC7F,cAAc,EAAE,CAAC,SAAS,CAAC;IAC3B,WAAW,EAAE,UAAU;IACvB,kBAAkB,EAAE,oCAAoC;CACxD,CAAC;AAEF,MAAM,gBAAgB,GAAmB;IACxC,MAAM,EAAE,aAAa;IACrB,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,EAAE,QAAQ,EAAE,wBAAwB,EAAE,aAAa,EAAE,CAAC,EAAE;IAC/D,MAAM,EAAE,EAAE,QAAQ,EAAE,yBAAyB,EAAE,aAAa,EAAE,CAAC,EAAE;IACjE,sBAAsB,EAAE;QACvB,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC,EAAE,QAAQ,EA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mB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE;SACpD,CAAC;KACF;CACD,CAAC;AAEF,kEAAkE;AAClE,MAAM,UAAU,0BAA0B,CAAC,OAAsB,EAG/D;IACD,MAAM,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9C,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC/C,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC,CAAC,CAAC;IACJ,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO;QACN,KAAK;QACL,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE;YACvB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,oCAAoC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAAA,CACxD;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * First-batch role vertical slices (2.2c): 架构/实现/测试.\n *\n * Each role is a `RoleMetadataV1` registered in the role catalog plus a\n * deterministic runner that only consumes the public facade — no private\n * session access. These are the first vertical slices proving that a role can\n * be declared, discovered, and executed end to end.\n */\n\nimport { t } from \"../core/i18n/index.ts\";\nimport type { RoleCatalogV1, RoleMetadataV1 } from \"./role-catalog.ts\";\nimport { validateRoleMetadataV1 } from \"./role-catalog.ts\";\n\nexport interface FirstBatchRoleV1 {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: (input: { readonly spec: string }) => Promise<{ readonly result: string }>;\n}\n\nconst ARCHITECTURE_ROLE: RoleMetadataV1 = {\n\troleId: \"architecture-analyst\",\n\ttitle: \"Architecture Analyst\",\n\tinput: { schemaId: \"role/architecture-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/architecture-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"module structure findings recorded\",\n};\n\nconst IMPLEMENTER_ROLE: RoleMetadataV1 = {\n\troleId: \"implementer\",\n\ttitle: \"Implementer\",\n\tinput: { schemaId: \"role/implement-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/implement-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [\n\t\t{ capabilityId: \"tool.edit\", capabilityVersion: 1, required: true },\n\t\t{ capabilityId: \"tool.write\", capabilityVersion: 1, required: false },\n\t],\n\twritableScopes: [\"session\", \"cycle\"],\n\tconcurrency: \"single\",\n\tcompletionCriteria: \"patch produced for the requested spec\",\n};\n\nconst TEST_DESIGNER_ROLE: RoleMetadataV1 = {\n\troleId: \"test-designer\",\n\ttitle: \"Test Designer\",\n\tinput: { schemaId: \"role/test-input@1\", schemaVersion: 1 },\n\toutput: { schemaId: \"role/test-output@1\", schemaVersion: 1 },\n\tcapabilityDependencies: [{ capabilityId: \"tool.read\", capabilityVersion: 1, required: true }],\n\twritableScopes: [\"session\"],\n\tconcurrency: \"parallel\",\n\tcompletionCriteria: \"test cases derived from the spec\",\n};\n\nexport const FIRST_BATCH_ROLES: readonly {\n\treadonly metadata: RoleMetadataV1;\n\treadonly run: FirstBatchRoleV1[\"run\"];\n}[] = [\n\t{\n\t\tmetadata: ARCHITECTURE_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `architecture findings for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: IMPLEMENTER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `patch for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n\t{\n\t\tmetadata: TEST_DESIGNER_ROLE,\n\t\trun: async (input) => ({\n\t\t\tresult: `test cases for: ${input.spec.slice(0, 64)}`,\n\t\t}),\n\t},\n];\n\n/** Registers and returns the first-batch role vertical slices. */\nexport function createFirstBatchRoleSlices(catalog: RoleCatalogV1): {\n\treadonly roles: readonly FirstBatchRoleV1[];\n\trun(roleId: string, spec: string): Promise<{ readonly roleId: string; readonly result: string }>;\n} {\n\tconst roles = FIRST_BATCH_ROLES.map((role) => ({\n\t\tmetadata: validateRoleMetadataV1(role.metadata),\n\t\trun: role.run,\n\t}));\n\tfor (const role of roles) catalog.register(role.metadata);\n\tconst runners = new Map(roles.map((role) => [role.metadata.roleId, role.run]));\n\treturn {\n\t\troles,\n\t\tasync run(roleId, spec) {\n\t\t\tconst run = runners.get(roleId);\n\t\t\tif (!run) throw new Error(t(\"Unknown first-batch role: {roleId}\", { roleId }));\n\t\t\treturn { roleId, result: (await run({ spec })).result };\n\t\t},\n\t};\n}\n"]}