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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (451) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +2 -2
  3. package/bundled-plugins/agent-loop-policy/agent-forge.json +19 -0
  4. package/bundled-plugins/agent-loop-policy/dist/entry.d.ts +28 -0
  5. package/bundled-plugins/agent-loop-policy/dist/entry.d.ts.map +1 -0
  6. package/bundled-plugins/agent-loop-policy/dist/entry.js +69 -0
  7. package/bundled-plugins/agent-loop-policy/dist/entry.js.map +1 -0
  8. package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts +199 -0
  9. package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts.map +1 -0
  10. package/bundled-plugins/agent-loop-policy/dist/loop-guard.js +208 -0
  11. package/bundled-plugins/agent-loop-policy/dist/loop-guard.js.map +1 -0
  12. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts +17 -0
  13. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts.map +1 -0
  14. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js +18 -0
  15. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js.map +1 -0
  16. package/bundled-plugins/agent-loop-policy/plugin.json +7 -0
  17. package/bundled-plugins/coding-tools/agent-forge.json +19 -0
  18. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.d.ts +5 -44
  19. package/bundled-plugins/coding-tools/dist/bash.d.ts.map +1 -0
  20. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.js +15 -119
  21. package/bundled-plugins/coding-tools/dist/bash.js.map +1 -0
  22. package/bundled-plugins/coding-tools/dist/capability.d.ts +25 -0
  23. package/bundled-plugins/coding-tools/dist/capability.d.ts.map +1 -0
  24. package/bundled-plugins/coding-tools/dist/capability.js +98 -0
  25. package/bundled-plugins/coding-tools/dist/capability.js.map +1 -0
  26. package/bundled-plugins/coding-tools/dist/config.d.ts +8 -0
  27. package/bundled-plugins/coding-tools/dist/config.d.ts.map +1 -0
  28. package/bundled-plugins/coding-tools/dist/config.js +8 -0
  29. package/bundled-plugins/coding-tools/dist/config.js.map +1 -0
  30. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.d.ts +3 -3
  31. package/bundled-plugins/coding-tools/dist/edit.d.ts.map +1 -0
  32. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.js +12 -10
  33. package/bundled-plugins/coding-tools/dist/edit.js.map +1 -0
  34. package/bundled-plugins/coding-tools/dist/entry.d.ts +14 -0
  35. package/bundled-plugins/coding-tools/dist/entry.d.ts.map +1 -0
  36. package/bundled-plugins/coding-tools/dist/entry.js +23 -0
  37. package/bundled-plugins/coding-tools/dist/entry.js.map +1 -0
  38. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.d.ts +4 -4
  39. package/bundled-plugins/coding-tools/dist/find.d.ts.map +1 -0
  40. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.js +10 -8
  41. package/bundled-plugins/coding-tools/dist/find.js.map +1 -0
  42. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.d.ts +3 -3
  43. package/bundled-plugins/coding-tools/dist/grep.d.ts.map +1 -0
  44. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.js +10 -8
  45. package/bundled-plugins/coding-tools/dist/grep.js.map +1 -0
  46. package/bundled-plugins/coding-tools/dist/index.d.ts +17 -0
  47. package/bundled-plugins/coding-tools/dist/index.d.ts.map +1 -0
  48. package/bundled-plugins/coding-tools/dist/index.js +17 -0
  49. package/bundled-plugins/coding-tools/dist/index.js.map +1 -0
  50. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.d.ts +3 -3
  51. package/bundled-plugins/coding-tools/dist/ls.d.ts.map +1 -0
  52. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js +8 -6
  53. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js.map +1 -1
  54. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.d.ts +2 -1
  55. package/bundled-plugins/coding-tools/dist/powershell.d.ts.map +1 -0
  56. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.js +6 -3
  57. package/bundled-plugins/coding-tools/dist/powershell.js.map +1 -0
  58. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.d.ts +3 -3
  59. package/bundled-plugins/coding-tools/dist/read.d.ts.map +1 -0
  60. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.js +15 -13
  61. package/bundled-plugins/coding-tools/dist/read.js.map +1 -0
  62. package/bundled-plugins/coding-tools/dist/types.d.ts +74 -0
  63. package/bundled-plugins/coding-tools/dist/types.d.ts.map +1 -0
  64. package/bundled-plugins/coding-tools/dist/types.js +28 -0
  65. package/bundled-plugins/coding-tools/dist/types.js.map +1 -0
  66. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.d.ts +2 -2
  67. package/bundled-plugins/coding-tools/dist/write.d.ts.map +1 -0
  68. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.js +11 -9
  69. package/bundled-plugins/coding-tools/dist/write.js.map +1 -0
  70. package/bundled-plugins/coding-tools/plugin.json +10 -0
  71. package/bundled-plugins/compaction-policy/agent-forge.json +19 -0
  72. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts +6 -0
  73. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts.map +1 -0
  74. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js +19 -0
  75. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js.map +1 -0
  76. package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts +6 -0
  77. package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts.map +1 -0
  78. package/bundled-plugins/compaction-policy/dist/compaction-policy.js +38 -0
  79. package/bundled-plugins/compaction-policy/dist/compaction-policy.js.map +1 -0
  80. package/bundled-plugins/compaction-policy/dist/entry.d.ts +13 -0
  81. package/bundled-plugins/compaction-policy/dist/entry.d.ts.map +1 -0
  82. package/bundled-plugins/compaction-policy/dist/entry.js +23 -0
  83. package/bundled-plugins/compaction-policy/dist/entry.js.map +1 -0
  84. package/bundled-plugins/compaction-policy/plugin.json +10 -0
  85. package/bundled-plugins/mcp-http/dist/index.d.ts +8 -0
  86. package/bundled-plugins/mcp-http/dist/index.d.ts.map +1 -0
  87. package/bundled-plugins/mcp-http/dist/index.js +8 -0
  88. package/bundled-plugins/mcp-http/dist/index.js.map +1 -0
  89. package/bundled-plugins/mcp-http/dist/mcp-http.d.ts.map +1 -0
  90. package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.js +1 -1
  91. package/bundled-plugins/mcp-http/dist/mcp-http.js.map +1 -0
  92. package/bundled-plugins/overflow-policy/agent-forge.json +19 -0
  93. package/bundled-plugins/overflow-policy/dist/entry.d.ts +16 -0
  94. package/bundled-plugins/overflow-policy/dist/entry.d.ts.map +1 -0
  95. package/bundled-plugins/overflow-policy/dist/entry.js +35 -0
  96. package/bundled-plugins/overflow-policy/dist/entry.js.map +1 -0
  97. package/bundled-plugins/overflow-policy/plugin.json +10 -0
  98. package/bundled-plugins/provider-failover/agent-forge.json +19 -0
  99. package/bundled-plugins/provider-failover/dist/entry.d.ts +8 -0
  100. package/bundled-plugins/provider-failover/dist/entry.d.ts.map +1 -0
  101. package/bundled-plugins/provider-failover/dist/entry.js +8 -0
  102. package/bundled-plugins/provider-failover/dist/entry.js.map +1 -0
  103. package/bundled-plugins/provider-failover/dist/provider-failover.d.ts +122 -0
  104. package/bundled-plugins/provider-failover/dist/provider-failover.d.ts.map +1 -0
  105. package/{dist/core/extensions → bundled-plugins/provider-failover/dist}/provider-failover.js +149 -61
  106. package/bundled-plugins/provider-failover/dist/provider-failover.js.map +1 -0
  107. package/bundled-plugins/provider-failover/plugin.json +7 -0
  108. package/bundled-plugins/retry-policy/agent-forge.json +19 -0
  109. package/bundled-plugins/retry-policy/dist/entry.d.ts +16 -0
  110. package/bundled-plugins/retry-policy/dist/entry.d.ts.map +1 -0
  111. package/bundled-plugins/retry-policy/dist/entry.js +34 -0
  112. package/bundled-plugins/retry-policy/dist/entry.js.map +1 -0
  113. package/bundled-plugins/retry-policy/plugin.json +10 -0
  114. package/dist/bundle/.build-manifest.json +105 -183
  115. package/dist/bundle/chunks/{anthropic-messages-ALDZBUKI.js → anthropic-messages-PLAKXR73.js} +1 -1
  116. package/dist/bundle/chunks/{azure-openai-responses-A2WJWZFB.js → azure-openai-responses-OUWQ2AZD.js} +1 -1
  117. package/dist/bundle/chunks/{chunk-CIX3FSBK.js → chunk-A3JYRWB6.js} +1 -1
  118. package/dist/bundle/chunks/{chunk-SQFG22WN.js → chunk-AC2FIS4G.js} +1 -1
  119. package/dist/bundle/chunks/chunk-AQLNTW2B.js +664 -0
  120. package/dist/bundle/chunks/chunk-D3ARGZFR.js +13 -0
  121. package/dist/bundle/chunks/{chunk-YJCQVXW5.js → chunk-HTEVUY7F.js} +1 -1
  122. package/dist/bundle/chunks/{chunk-Y7HXTASS.js → chunk-HV64ASMT.js} +1 -1
  123. package/dist/bundle/chunks/chunk-LZOEQITZ.js +855 -0
  124. package/dist/bundle/chunks/{chunk-7ZY7IXZD.js → chunk-TRDNDS6A.js} +1 -1
  125. package/dist/bundle/chunks/chunk-Z72JWUZ4.js +4 -0
  126. package/dist/bundle/chunks/{google-generative-ai-NIB4WONV.js → google-generative-ai-DLII6DAT.js} +1 -1
  127. package/dist/bundle/chunks/{google-vertex-DCPYUEUO.js → google-vertex-G7BZL7GM.js} +1 -1
  128. package/dist/bundle/chunks/image-resize-worker.js +3 -3
  129. package/dist/bundle/chunks/{mistral-conversations-OC6LA5XL.js → mistral-conversations-JXUK24ID.js} +1 -1
  130. package/dist/bundle/chunks/{openai-codex-responses-IO2X4Y7L.js → openai-codex-responses-5GSGFIPG.js} +1 -1
  131. package/dist/bundle/chunks/{openai-completions-XYQQHETU.js → openai-completions-EI2I6DTG.js} +1 -1
  132. package/dist/bundle/chunks/{openai-responses-DLIRN3CI.js → openai-responses-AUJQ3NWT.js} +1 -1
  133. package/dist/bundle/chunks/{pi-messages-E6RRYBO7.js → pi-messages-PWU2VJMR.js} +1 -1
  134. package/dist/bundle/chunks/virtual-modules-WF6WRHP7.js +5 -0
  135. package/dist/bundle/cli.js +1 -1
  136. package/dist/bundle/client.js +1 -1
  137. package/dist/bundle/index.js +3 -3
  138. package/dist/bundle/rpc-entry.js +1 -1
  139. package/dist/capabilities/builtin.d.ts +1 -1
  140. package/dist/capabilities/builtin.d.ts.map +1 -1
  141. package/dist/capabilities/builtin.js +5 -0
  142. package/dist/capabilities/builtin.js.map +1 -1
  143. package/dist/cli/auth-check.d.ts.map +1 -1
  144. package/dist/cli/auth-check.js +14 -2
  145. package/dist/cli/auth-check.js.map +1 -1
  146. package/dist/cli/auth-command.d.ts.map +1 -1
  147. package/dist/cli/auth-command.js +1 -1
  148. package/dist/cli/auth-command.js.map +1 -1
  149. package/dist/cli/plugin-command.d.ts.map +1 -1
  150. package/dist/cli/plugin-command.js +17 -1
  151. package/dist/cli/plugin-command.js.map +1 -1
  152. package/dist/config.d.ts +2 -3
  153. package/dist/config.d.ts.map +1 -1
  154. package/dist/config.js +5 -6
  155. package/dist/config.js.map +1 -1
  156. package/dist/core/agent-session-bash.d.ts +1 -1
  157. package/dist/core/agent-session-bash.d.ts.map +1 -1
  158. package/dist/core/agent-session-bash.js +1 -1
  159. package/dist/core/agent-session-bash.js.map +1 -1
  160. package/dist/core/agent-session-compaction.d.ts +6 -10
  161. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  162. package/dist/core/agent-session-compaction.js +21 -112
  163. package/dist/core/agent-session-compaction.js.map +1 -1
  164. package/dist/core/agent-session-internal.d.ts +1 -7
  165. package/dist/core/agent-session-internal.d.ts.map +1 -1
  166. package/dist/core/agent-session-internal.js.map +1 -1
  167. package/dist/core/agent-session-loop.d.ts +4 -3
  168. package/dist/core/agent-session-loop.d.ts.map +1 -1
  169. package/dist/core/agent-session-loop.js +9 -6
  170. package/dist/core/agent-session-loop.js.map +1 -1
  171. package/dist/core/agent-session-retry.d.ts +1 -1
  172. package/dist/core/agent-session-retry.d.ts.map +1 -1
  173. package/dist/core/agent-session-retry.js +32 -4
  174. package/dist/core/agent-session-retry.js.map +1 -1
  175. package/dist/core/agent-session-services.d.ts.map +1 -1
  176. package/dist/core/agent-session-services.js +30 -9
  177. package/dist/core/agent-session-services.js.map +1 -1
  178. package/dist/core/agent-session-tools.d.ts.map +1 -1
  179. package/dist/core/agent-session-tools.js +5 -1
  180. package/dist/core/agent-session-tools.js.map +1 -1
  181. package/dist/core/agent-session.d.ts +12 -33
  182. package/dist/core/agent-session.d.ts.map +1 -1
  183. package/dist/core/agent-session.js +61 -67
  184. package/dist/core/agent-session.js.map +1 -1
  185. package/dist/core/bash-executor.d.ts +1 -1
  186. package/dist/core/bash-executor.d.ts.map +1 -1
  187. package/dist/core/bash-executor.js.map +1 -1
  188. package/dist/core/extensions/bootstrap-agent-loop.d.ts +23 -151
  189. package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
  190. package/dist/core/extensions/bootstrap-agent-loop.js +28 -290
  191. package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
  192. package/dist/core/extensions/capability-runtime-types.d.ts +5 -3
  193. package/dist/core/extensions/capability-runtime-types.d.ts.map +1 -1
  194. package/dist/core/extensions/capability-runtime-types.js.map +1 -1
  195. package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
  196. package/dist/core/extensions/capability-runtime.js +42 -6
  197. package/dist/core/extensions/capability-runtime.js.map +1 -1
  198. package/dist/core/extensions/index.d.ts +12 -5
  199. package/dist/core/extensions/index.d.ts.map +1 -1
  200. package/dist/core/extensions/index.js +12 -5
  201. package/dist/core/extensions/index.js.map +1 -1
  202. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  203. package/dist/core/extensions/virtual-modules.js +65 -0
  204. package/dist/core/extensions/virtual-modules.js.map +1 -1
  205. package/dist/core/facade/coding-agent-facade.d.ts +1 -7
  206. package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
  207. package/dist/core/facade/coding-agent-facade.js +0 -3
  208. package/dist/core/facade/coding-agent-facade.js.map +1 -1
  209. package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -1
  210. package/dist/core/i18n/locales/zh-cn/cli.js +3 -1
  211. package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -1
  212. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +1 -1
  213. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -1
  214. package/dist/core/i18n/locales/zh-cn/core-contract-core.js +1 -1
  215. package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -1
  216. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -1
  217. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +2 -4
  218. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -1
  219. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -1
  220. package/dist/core/i18n/locales/zh-cn/core-errors.js +3 -1
  221. package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -1
  222. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -1
  223. package/dist/core/i18n/locales/zh-cn/interactive-mode.js +2 -0
  224. package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -1
  225. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts.map +1 -1
  226. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js +0 -2
  227. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js.map +1 -1
  228. package/dist/core/model-config.d.ts +0 -1
  229. package/dist/core/model-config.d.ts.map +1 -1
  230. package/dist/core/model-config.js +9 -1
  231. package/dist/core/model-config.js.map +1 -1
  232. package/dist/core/model-runtime.d.ts.map +1 -1
  233. package/dist/core/model-runtime.js +3 -3
  234. package/dist/core/model-runtime.js.map +1 -1
  235. package/dist/core/provider-composer.d.ts +2 -2
  236. package/dist/core/provider-composer.d.ts.map +1 -1
  237. package/dist/core/provider-composer.js +7 -8
  238. package/dist/core/provider-composer.js.map +1 -1
  239. package/dist/core/sdk.d.ts +18 -3
  240. package/dist/core/sdk.d.ts.map +1 -1
  241. package/dist/core/sdk.js +267 -76
  242. package/dist/core/sdk.js.map +1 -1
  243. package/dist/core/settings-manager.d.ts +9 -20
  244. package/dist/core/settings-manager.d.ts.map +1 -1
  245. package/dist/core/settings-manager.js +20 -54
  246. package/dist/core/settings-manager.js.map +1 -1
  247. package/dist/core/tools/bash-operations.d.ts +41 -0
  248. package/dist/core/tools/bash-operations.d.ts.map +1 -0
  249. package/dist/core/tools/bash-operations.js +113 -0
  250. package/dist/core/tools/bash-operations.js.map +1 -0
  251. package/dist/core/tools/index.d.ts +12 -36
  252. package/dist/core/tools/index.d.ts.map +1 -1
  253. package/dist/core/tools/index.js +1 -117
  254. package/dist/core/tools/index.js.map +1 -1
  255. package/dist/core/tools/readme-path.d.ts +3 -0
  256. package/dist/core/tools/readme-path.d.ts.map +1 -0
  257. package/dist/core/tools/readme-path.js +15 -0
  258. package/dist/core/tools/readme-path.js.map +1 -0
  259. package/dist/index.d.ts +3 -19
  260. package/dist/index.d.ts.map +1 -1
  261. package/dist/index.js +6 -39
  262. package/dist/index.js.map +1 -1
  263. package/dist/main.d.ts.map +1 -1
  264. package/dist/main.js +3 -2
  265. package/dist/main.js.map +1 -1
  266. package/dist/modes/interactive/components/footer.d.ts +0 -2
  267. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  268. package/dist/modes/interactive/components/footer.js +2 -7
  269. package/dist/modes/interactive/components/footer.js.map +1 -1
  270. package/dist/modes/interactive/components/settings-selector.d.ts +2 -6
  271. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  272. package/dist/modes/interactive/components/settings-selector.js +6 -28
  273. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  274. package/dist/modes/interactive/components/tool-execution.d.ts +0 -1
  275. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  276. package/dist/modes/interactive/components/tool-execution.js +9 -25
  277. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  278. package/dist/modes/interactive/interactive-mode.d.ts +0 -1
  279. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  280. package/dist/modes/interactive/interactive-mode.js +23 -36
  281. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  282. package/dist/modes/rpc/rpc-client.d.ts +0 -8
  283. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  284. package/dist/modes/rpc/rpc-client.js +0 -12
  285. package/dist/modes/rpc/rpc-client.js.map +1 -1
  286. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  287. package/dist/modes/rpc/rpc-mode.js +0 -9
  288. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  289. package/dist/modes/rpc/rpc-types.d.ts +0 -19
  290. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  291. package/dist/modes/rpc/rpc-types.js.map +1 -1
  292. package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
  293. package/dist/plugins/ecosystem/cli.js +14 -2
  294. package/dist/plugins/ecosystem/cli.js.map +1 -1
  295. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts +7 -2
  296. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
  297. package/dist/plugins/ecosystem/node-npm-registry-source.js +64 -9
  298. package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
  299. package/dist/plugins/ecosystem/node-plugin-acquisition-host.d.ts.map +1 -1
  300. package/dist/plugins/ecosystem/node-plugin-acquisition-host.js +6 -0
  301. package/dist/plugins/ecosystem/node-plugin-acquisition-host.js.map +1 -1
  302. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +9 -2
  303. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  304. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +23 -0
  305. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  306. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +9 -1
  307. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
  308. package/dist/plugins/ecosystem/plugin-bootstrap.js +5 -0
  309. package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
  310. package/dist/profiles/builtin-suites.d.ts +5 -1
  311. package/dist/profiles/builtin-suites.d.ts.map +1 -1
  312. package/dist/profiles/builtin-suites.js +6 -1
  313. package/dist/profiles/builtin-suites.js.map +1 -1
  314. package/dist/utils/photon.d.ts +2 -2
  315. package/dist/utils/photon.d.ts.map +1 -1
  316. package/dist/utils/photon.js +2 -2
  317. package/dist/utils/photon.js.map +1 -1
  318. package/docs/compaction.md +1 -3
  319. package/docs/docs.json +4 -0
  320. package/docs/index.md +1 -0
  321. package/docs/mcp.md +103 -0
  322. package/docs/models.md +14 -22
  323. package/docs/providers.md +0 -1
  324. package/docs/rpc.md +1 -26
  325. package/docs/sdk.md +4 -6
  326. package/docs/settings.md +9 -12
  327. package/docs/skills.md +1 -9
  328. package/docs/usage.md +1 -1
  329. package/examples/extensions/bash-spawn-hook/index.ts +7 -2
  330. package/examples/extensions/built-in-tool-renderer/index.ts +4 -2
  331. package/examples/extensions/minimal-mode/index.ts +2 -2
  332. package/examples/extensions/truncated-tool/index.ts +1 -1
  333. package/examples/extensions/with-deps/package-lock.json +2 -2
  334. package/examples/extensions/with-deps/package.json +1 -1
  335. package/examples/extensions/with-deps/plugin.json +1 -1
  336. package/examples/sdk/10-settings.ts +2 -4
  337. package/examples/sdk/12-full-control.ts +1 -2
  338. package/package.json +3 -4
  339. package/dist/bundle/chunks/chunk-6ZKDNZHA.js +0 -145
  340. package/dist/bundle/chunks/chunk-BFC2BDVJ.js +0 -13
  341. package/dist/bundle/chunks/chunk-MOHOLL3F.js +0 -1456
  342. package/dist/bundle/chunks/virtual-modules-KZ5DRH7Q.js +0 -2
  343. package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts +0 -7
  344. package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts.map +0 -1
  345. package/dist/core/extensions/bootstrap-branch-summary-policy.js +0 -28
  346. package/dist/core/extensions/bootstrap-branch-summary-policy.js.map +0 -1
  347. package/dist/core/extensions/bootstrap-compaction-policy.d.ts +0 -7
  348. package/dist/core/extensions/bootstrap-compaction-policy.d.ts.map +0 -1
  349. package/dist/core/extensions/bootstrap-compaction-policy.js +0 -82
  350. package/dist/core/extensions/bootstrap-compaction-policy.js.map +0 -1
  351. package/dist/core/extensions/bootstrap-overflow-policy.d.ts +0 -7
  352. package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +0 -1
  353. package/dist/core/extensions/bootstrap-overflow-policy.js +0 -30
  354. package/dist/core/extensions/bootstrap-overflow-policy.js.map +0 -1
  355. package/dist/core/extensions/bootstrap-retry-policy.d.ts +0 -7
  356. package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +0 -1
  357. package/dist/core/extensions/bootstrap-retry-policy.js +0 -29
  358. package/dist/core/extensions/bootstrap-retry-policy.js.map +0 -1
  359. package/dist/core/extensions/bootstrap-tools.d.ts +0 -20
  360. package/dist/core/extensions/bootstrap-tools.d.ts.map +0 -1
  361. package/dist/core/extensions/bootstrap-tools.js +0 -36
  362. package/dist/core/extensions/bootstrap-tools.js.map +0 -1
  363. package/dist/core/extensions/microcompact.d.ts +0 -80
  364. package/dist/core/extensions/microcompact.d.ts.map +0 -1
  365. package/dist/core/extensions/microcompact.js +0 -134
  366. package/dist/core/extensions/microcompact.js.map +0 -1
  367. package/dist/core/extensions/provider-failover.d.ts +0 -106
  368. package/dist/core/extensions/provider-failover.d.ts.map +0 -1
  369. package/dist/core/extensions/provider-failover.js.map +0 -1
  370. package/dist/core/tools/bash.d.ts.map +0 -1
  371. package/dist/core/tools/bash.js.map +0 -1
  372. package/dist/core/tools/edit.d.ts.map +0 -1
  373. package/dist/core/tools/edit.js.map +0 -1
  374. package/dist/core/tools/find.d.ts.map +0 -1
  375. package/dist/core/tools/find.js.map +0 -1
  376. package/dist/core/tools/grep.d.ts.map +0 -1
  377. package/dist/core/tools/grep.js.map +0 -1
  378. package/dist/core/tools/ls.d.ts.map +0 -1
  379. package/dist/core/tools/powershell.d.ts.map +0 -1
  380. package/dist/core/tools/powershell.js.map +0 -1
  381. package/dist/core/tools/read.d.ts.map +0 -1
  382. package/dist/core/tools/read.js.map +0 -1
  383. package/dist/core/tools/write.d.ts.map +0 -1
  384. package/dist/core/tools/write.js.map +0 -1
  385. package/dist/plugins/mcp-http.d.ts.map +0 -1
  386. package/dist/plugins/mcp-http.js.map +0 -1
  387. package/dist/profile/child-facade.d.ts +0 -44
  388. package/dist/profile/child-facade.d.ts.map +0 -1
  389. package/dist/profile/child-facade.js +0 -56
  390. package/dist/profile/child-facade.js.map +0 -1
  391. package/dist/profile/dependency-wiring.d.ts +0 -48
  392. package/dist/profile/dependency-wiring.d.ts.map +0 -1
  393. package/dist/profile/dependency-wiring.js +0 -56
  394. package/dist/profile/dependency-wiring.js.map +0 -1
  395. package/dist/profile/domain-recovery.d.ts +0 -60
  396. package/dist/profile/domain-recovery.d.ts.map +0 -1
  397. package/dist/profile/domain-recovery.js +0 -94
  398. package/dist/profile/domain-recovery.js.map +0 -1
  399. package/dist/profile/first-roles.d.ts +0 -30
  400. package/dist/profile/first-roles.d.ts.map +0 -1
  401. package/dist/profile/first-roles.js +0 -83
  402. package/dist/profile/first-roles.js.map +0 -1
  403. package/dist/profile/goal-plugin.d.ts +0 -38
  404. package/dist/profile/goal-plugin.d.ts.map +0 -1
  405. package/dist/profile/goal-plugin.js +0 -132
  406. package/dist/profile/goal-plugin.js.map +0 -1
  407. package/dist/profile/plan-plugin.d.ts +0 -44
  408. package/dist/profile/plan-plugin.d.ts.map +0 -1
  409. package/dist/profile/plan-plugin.js +0 -157
  410. package/dist/profile/plan-plugin.js.map +0 -1
  411. package/dist/profile/policy-manifest.d.ts +0 -53
  412. package/dist/profile/policy-manifest.d.ts.map +0 -1
  413. package/dist/profile/policy-manifest.js +0 -53
  414. package/dist/profile/policy-manifest.js.map +0 -1
  415. package/dist/profile/role-assembly.d.ts +0 -47
  416. package/dist/profile/role-assembly.d.ts.map +0 -1
  417. package/dist/profile/role-assembly.js +0 -31
  418. package/dist/profile/role-assembly.js.map +0 -1
  419. package/dist/profile/role-catalog.d.ts +0 -43
  420. package/dist/profile/role-catalog.d.ts.map +0 -1
  421. package/dist/profile/role-catalog.js +0 -132
  422. package/dist/profile/role-catalog.js.map +0 -1
  423. package/dist/profile/role-orchestrator.d.ts +0 -123
  424. package/dist/profile/role-orchestrator.d.ts.map +0 -1
  425. package/dist/profile/role-orchestrator.js +0 -195
  426. package/dist/profile/role-orchestrator.js.map +0 -1
  427. package/dist/profile/role-runner.d.ts +0 -99
  428. package/dist/profile/role-runner.d.ts.map +0 -1
  429. package/dist/profile/role-runner.js +0 -79
  430. package/dist/profile/role-runner.js.map +0 -1
  431. package/dist/profile/root-facade.d.ts +0 -36
  432. package/dist/profile/root-facade.d.ts.map +0 -1
  433. package/dist/profile/root-facade.js +0 -49
  434. package/dist/profile/root-facade.js.map +0 -1
  435. package/dist/profile/skill-discovery-wiring.d.ts +0 -58
  436. package/dist/profile/skill-discovery-wiring.d.ts.map +0 -1
  437. package/dist/profile/skill-discovery-wiring.js +0 -80
  438. package/dist/profile/skill-discovery-wiring.js.map +0 -1
  439. package/dist/profile/state-store.d.ts +0 -62
  440. package/dist/profile/state-store.d.ts.map +0 -1
  441. package/dist/profile/state-store.js +0 -144
  442. package/dist/profile/state-store.js.map +0 -1
  443. package/dist/profile/todo-plugin.d.ts +0 -37
  444. package/dist/profile/todo-plugin.d.ts.map +0 -1
  445. package/dist/profile/todo-plugin.js +0 -137
  446. package/dist/profile/todo-plugin.js.map +0 -1
  447. package/dist/server/create-harness.d.ts +0 -26
  448. package/dist/server/create-harness.d.ts.map +0 -1
  449. package/dist/server/create-harness.js +0 -106
  450. package/dist/server/create-harness.js.map +0 -1
  451. /package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.d.ts +0 -0
@@ -1,144 +0,0 @@
1
- import { t } from "../core/i18n/index.js";
2
- function assertNonEmptyString(value, label) {
3
- if (typeof value !== "string" || value.trim().length === 0)
4
- throw new Error(t("{label} must be a non-empty string", { label }));
5
- }
6
- function validateEvidence(value, label) {
7
- if (value === undefined)
8
- return [];
9
- if (!Array.isArray(value))
10
- throw new Error(t("{label} must be an array", { label }));
11
- return value.map((item, index) => {
12
- const depLabel = `${label}[${index}]`;
13
- if (item === null || typeof item !== "object" || Array.isArray(item)) {
14
- throw new Error(t("{label} must be a plain object", { label: depLabel }));
15
- }
16
- const record = item;
17
- assertNonEmptyString(record.kind, `${depLabel}.kind`);
18
- assertNonEmptyString(record.ref, `${depLabel}.ref`);
19
- if (record.digest !== undefined)
20
- assertNonEmptyString(record.digest, `${depLabel}.digest`);
21
- return Object.freeze({
22
- kind: record.kind,
23
- ref: record.ref,
24
- ...(record.digest === undefined ? {} : { digest: record.digest }),
25
- });
26
- });
27
- }
28
- function validatePayload(value, label) {
29
- if (value === undefined)
30
- return undefined;
31
- const seen = new Set();
32
- const check = (node) => {
33
- if (node === null || typeof node === "string" || typeof node === "boolean")
34
- return;
35
- if (typeof node === "number") {
36
- if (!Number.isFinite(node))
37
- throw new Error(t("{label} must be JSON-safe: {node} is not a finite number", { label, node: String(node) }));
38
- return;
39
- }
40
- if (typeof node === "object") {
41
- if (seen.has(node))
42
- throw new Error(t("{label} must be JSON-safe: circular reference", { label }));
43
- seen.add(node);
44
- if (Array.isArray(node)) {
45
- for (const item of node)
46
- check(item);
47
- }
48
- else {
49
- const proto = Object.getPrototypeOf(node);
50
- if (proto !== Object.prototype && proto !== null)
51
- throw new Error(t("{label} must be a plain object", { label }));
52
- for (const entry of Object.entries(node)) {
53
- if (entry[1] === undefined)
54
- throw new Error(t("{label} must be JSON-safe: {key} is undefined", { label, key: entry[0] }));
55
- check(entry[1]);
56
- }
57
- }
58
- seen.delete(node);
59
- return;
60
- }
61
- throw new Error(t("{label} must be JSON-safe: unsupported value of type {type}", { label, type: typeof node }));
62
- };
63
- check(value);
64
- return JSON.parse(JSON.stringify(value));
65
- }
66
- export function createTransitionStore(options = {}) {
67
- const now = options.now ?? (() => Date.now());
68
- const recordsByEntity = new Map();
69
- const idempotency = new Map();
70
- const currentStatus = new Map();
71
- const revisions = new Map();
72
- const entityKey = (domain, entityId) => `${domain}\u0000${entityId}`;
73
- return {
74
- transition(input) {
75
- assertNonEmptyString(input.domain, "Transition domain");
76
- assertNonEmptyString(input.entityId, "Transition entityId");
77
- assertNonEmptyString(input.owner, "Transition owner");
78
- assertNonEmptyString(input.operationId, "Transition operationId");
79
- assertNonEmptyString(input.toStatus, "Transition toStatus");
80
- const evidence = validateEvidence(input.evidence, "Transition evidence");
81
- const payload = validatePayload(input.payload, "Transition payload");
82
- const key = `${entityKey(input.domain, input.entityId)}\u0000${input.operationId}\u0000${input.toStatus}`;
83
- const existing = idempotency.get(key);
84
- if (existing)
85
- return { record: existing, deduped: true };
86
- const entityKeyId = entityKey(input.domain, input.entityId);
87
- const current = currentStatus.get(entityKeyId);
88
- const fromStatus = input.fromStatus;
89
- if ((current?.status ?? null) !== fromStatus) {
90
- throw new Error(t("Transition conflict: expected fromStatus {from}, got {to}", {
91
- from: JSON.stringify(current?.status ?? null),
92
- to: JSON.stringify(fromStatus),
93
- }));
94
- }
95
- const revision = (revisions.get(entityKeyId) ?? 0) + 1;
96
- revisions.set(entityKeyId, revision);
97
- const record = Object.freeze({
98
- domain: input.domain,
99
- entityId: input.entityId,
100
- owner: input.owner,
101
- fromStatus,
102
- toStatus: input.toStatus,
103
- operationId: input.operationId,
104
- evidence: Object.freeze(evidence),
105
- ...(payload === undefined ? {} : { payload }),
106
- revision,
107
- at: input.at ?? now(),
108
- });
109
- const log = recordsByEntity.get(entityKeyId) ?? [];
110
- log.push(record);
111
- recordsByEntity.set(entityKeyId, log);
112
- currentStatus.set(entityKeyId, { status: input.toStatus, revision });
113
- idempotency.set(key, record);
114
- return { record, deduped: false };
115
- },
116
- currentStatus(domain, entityId) {
117
- return currentStatus.get(entityKey(domain, entityId));
118
- },
119
- history(entityId) {
120
- return Object.freeze([...recordsByEntity.entries()]
121
- .filter(([entityKeyId]) => entityKeyId.endsWith(`\u0000${entityId}`))
122
- .flatMap(([, log]) => log));
123
- },
124
- replay(history) {
125
- for (const record of history) {
126
- this.transition({
127
- domain: record.domain,
128
- entityId: record.entityId,
129
- owner: record.owner,
130
- fromStatus: record.fromStatus,
131
- toStatus: record.toStatus,
132
- operationId: record.operationId,
133
- evidence: record.evidence,
134
- payload: record.payload,
135
- at: record.at,
136
- });
137
- }
138
- },
139
- entities() {
140
- return Object.freeze([...new Set([...currentStatus.keys()].map((key) => key.split("\u0000")[1]))]);
141
- },
142
- };
143
- }
144
- //# sourceMappingURL=state-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state-store.js","sourceRoot":"","sources":["../../src/profile/state-store.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAsC1C,SAAS,oBAAoB,CAAC,KAAc,EAAE,KAAa,EAA2B;IACrF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,oCAAoC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAAA,CACrE;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,KAAa,EAA6B;IACnF,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,0BAA0B,EAAE,EAAE,KAA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QAAQ,CAAC,SAAS,QAAQ,EAAE,CAAC,CAAC;iBACpE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAC3B,CAAC;QAAA,CACF;QACD,MAAM,CAAC,OAAO,EAAE;YACf,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC9B,IAAI,CAAC,UAAU,CAAC;oBACf,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,WAAW,EAAE,MAAM,CAAC,WAAW;oBAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,EAAE,EAAE,MAAM,CAAC,EAAE;iBACb,CAAC,CAAC;YACJ,CAAC;QAAA,CACD;QACD,QAAQ,GAAG;YACV,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAAA,CACpG;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Generic transition/evidence/revision store (2.3a) — the domain-agnostic\n * contract base for Goal/Plan/Todo plugins.\n *\n * The store knows NOTHING about goal/plan/todo semantics. It only enforces:\n * - causality: a transition's `fromStatus` must equal the entity's current\n * status (null = initial transition), otherwise an explicit conflict;\n * - idempotency: replaying the same (domain, entityId, operationId, toStatus)\n * returns the existing record and never advances the revision;\n * - evidence: every transition carries structured evidence references;\n * - payload: transitions may carry an optional domain payload (e.g. a goal\n * title) that is validated JSON and part of the replayable record;\n * - replay: the full history rebuilds the identical current state.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\n\nexport interface TransitionEvidenceRefV1 {\n\treadonly kind: string;\n\treadonly ref: string;\n\treadonly digest?: string;\n}\n\nexport interface TransitionRecordV1 {\n\treadonly domain: string;\n\treadonly entityId: string;\n\treadonly owner: string;\n\treadonly fromStatus: string | null;\n\treadonly toStatus: string;\n\treadonly operationId: string;\n\treadonly evidence: readonly TransitionEvidenceRefV1[];\n\treadonly payload?: JsonValue;\n\treadonly revision: number;\n\treadonly at: number;\n}\n\nexport interface TransitionInputV1 {\n\treadonly domain: string;\n\treadonly entityId: string;\n\treadonly owner: string;\n\treadonly fromStatus: string | null;\n\treadonly toStatus: string;\n\treadonly operationId: string;\n\treadonly evidence?: readonly TransitionEvidenceRefV1[];\n\treadonly payload?: JsonValue;\n\treadonly at?: number;\n}\n\nexport interface TransitionResultV1 {\n\treadonly record: TransitionRecordV1;\n\treadonly deduped: boolean;\n}\n\nfunction assertNonEmptyString(value: unknown, label: string): asserts value is string {\n\tif (typeof value !== \"string\" || value.trim().length === 0)\n\t\tthrow new Error(t(\"{label} must be a non-empty string\", { label }));\n}\n\nfunction validateEvidence(value: unknown, label: string): TransitionEvidenceRefV1[] {\n\tif (value === undefined) return [];\n\tif (!Array.isArray(value)) throw new Error(t(\"{label} must be an array\", { label }));\n\treturn value.map((item, index) => {\n\t\tconst depLabel = `${label}[${index}]`;\n\t\tif (item === null || typeof item !== \"object\" || Array.isArray(item)) {\n\t\t\tthrow new Error(t(\"{label} must be a plain object\", { label: depLabel }));\n\t\t}\n\t\tconst record = item as Record<string, unknown>;\n\t\tassertNonEmptyString(record.kind, `${depLabel}.kind`);\n\t\tassertNonEmptyString(record.ref, `${depLabel}.ref`);\n\t\tif (record.digest !== undefined) assertNonEmptyString(record.digest, `${depLabel}.digest`);\n\t\treturn Object.freeze({\n\t\t\tkind: record.kind,\n\t\t\tref: record.ref,\n\t\t\t...(record.digest === undefined ? {} : { digest: record.digest }),\n\t\t});\n\t});\n}\n\nfunction validatePayload(value: unknown, label: string): JsonValue | undefined {\n\tif (value === undefined) return undefined;\n\tconst seen = new Set<object>();\n\tconst check = (node: unknown): void => {\n\t\tif (node === null || typeof node === \"string\" || typeof node === \"boolean\") return;\n\t\tif (typeof node === \"number\") {\n\t\t\tif (!Number.isFinite(node))\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"{label} must be JSON-safe: {node} is not a finite number\", { label, node: String(node) }),\n\t\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tif (typeof node === \"object\") {\n\t\t\tif (seen.has(node)) throw new Error(t(\"{label} must be JSON-safe: circular reference\", { label }));\n\t\t\tseen.add(node);\n\t\t\tif (Array.isArray(node)) {\n\t\t\t\tfor (const item of node) check(item);\n\t\t\t} else {\n\t\t\t\tconst proto = Object.getPrototypeOf(node) as unknown;\n\t\t\t\tif (proto !== Object.prototype && proto !== null)\n\t\t\t\t\tthrow new Error(t(\"{label} must be a plain object\", { label }));\n\t\t\t\tfor (const entry of Object.entries(node)) {\n\t\t\t\t\tif (entry[1] === undefined)\n\t\t\t\t\t\tthrow new Error(t(\"{label} must be JSON-safe: {key} is undefined\", { label, key: entry[0] }));\n\t\t\t\t\tcheck(entry[1]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tseen.delete(node);\n\t\t\treturn;\n\t\t}\n\t\tthrow new Error(t(\"{label} must be JSON-safe: unsupported value of type {type}\", { label, type: typeof node }));\n\t};\n\tcheck(value);\n\treturn JSON.parse(JSON.stringify(value)) as JsonValue;\n}\n\nexport interface TransitionStoreV1 {\n\ttransition(input: TransitionInputV1): TransitionResultV1;\n\tcurrentStatus(domain: string, entityId: string): { readonly status: string; readonly revision: number } | undefined;\n\thistory(entityId: string): readonly TransitionRecordV1[];\n\t/** Replays a history into a fresh store; the rebuilt state must be identical. */\n\treplay(history: readonly TransitionRecordV1[]): void;\n\tentities(): readonly string[];\n}\n\nexport function createTransitionStore(options: { readonly now?: () => number } = {}): TransitionStoreV1 {\n\tconst now = options.now ?? (() => Date.now());\n\tconst recordsByEntity = new Map<string, TransitionRecordV1[]>();\n\tconst idempotency = new Map<string, TransitionRecordV1>();\n\tconst currentStatus = new Map<string, { status: string; revision: number }>();\n\tconst revisions = new Map<string, number>();\n\n\tconst entityKey = (domain: string, entityId: string): string => `${domain}\\u0000${entityId}`;\n\n\treturn {\n\t\ttransition(input) {\n\t\t\tassertNonEmptyString(input.domain, \"Transition domain\");\n\t\t\tassertNonEmptyString(input.entityId, \"Transition entityId\");\n\t\t\tassertNonEmptyString(input.owner, \"Transition owner\");\n\t\t\tassertNonEmptyString(input.operationId, \"Transition operationId\");\n\t\t\tassertNonEmptyString(input.toStatus, \"Transition toStatus\");\n\t\t\tconst evidence = validateEvidence(input.evidence, \"Transition evidence\");\n\t\t\tconst payload = validatePayload(input.payload, \"Transition payload\");\n\t\t\tconst key = `${entityKey(input.domain, input.entityId)}\\u0000${input.operationId}\\u0000${input.toStatus}`;\n\n\t\t\tconst existing = idempotency.get(key);\n\t\t\tif (existing) return { record: existing, deduped: true };\n\n\t\t\tconst entityKeyId = entityKey(input.domain, input.entityId);\n\t\t\tconst current = currentStatus.get(entityKeyId);\n\t\t\tconst fromStatus = input.fromStatus;\n\t\t\tif ((current?.status ?? null) !== fromStatus) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Transition conflict: expected fromStatus {from}, got {to}\", {\n\t\t\t\t\t\tfrom: JSON.stringify(current?.status ?? null),\n\t\t\t\t\t\tto: JSON.stringify(fromStatus),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst revision = (revisions.get(entityKeyId) ?? 0) + 1;\n\t\t\trevisions.set(entityKeyId, revision);\n\t\t\tconst record: TransitionRecordV1 = Object.freeze({\n\t\t\t\tdomain: input.domain,\n\t\t\t\tentityId: input.entityId,\n\t\t\t\towner: input.owner,\n\t\t\t\tfromStatus,\n\t\t\t\ttoStatus: input.toStatus,\n\t\t\t\toperationId: input.operationId,\n\t\t\t\tevidence: Object.freeze(evidence),\n\t\t\t\t...(payload === undefined ? {} : { payload }),\n\t\t\t\trevision,\n\t\t\t\tat: input.at ?? now(),\n\t\t\t});\n\t\t\tconst log = recordsByEntity.get(entityKeyId) ?? [];\n\t\t\tlog.push(record);\n\t\t\trecordsByEntity.set(entityKeyId, log);\n\t\t\tcurrentStatus.set(entityKeyId, { status: input.toStatus, revision });\n\t\t\tidempotency.set(key, record);\n\t\t\treturn { record, deduped: false };\n\t\t},\n\t\tcurrentStatus(domain: string, entityId: string) {\n\t\t\treturn currentStatus.get(entityKey(domain, entityId));\n\t\t},\n\t\thistory(entityId: string) {\n\t\t\treturn Object.freeze(\n\t\t\t\t[...recordsByEntity.entries()]\n\t\t\t\t\t.filter(([entityKeyId]) => entityKeyId.endsWith(`\\u0000${entityId}`))\n\t\t\t\t\t.flatMap(([, log]) => log),\n\t\t\t);\n\t\t},\n\t\treplay(history) {\n\t\t\tfor (const record of history) {\n\t\t\t\tthis.transition({\n\t\t\t\t\tdomain: record.domain,\n\t\t\t\t\tentityId: record.entityId,\n\t\t\t\t\towner: record.owner,\n\t\t\t\t\tfromStatus: record.fromStatus,\n\t\t\t\t\ttoStatus: record.toStatus,\n\t\t\t\t\toperationId: record.operationId,\n\t\t\t\t\tevidence: record.evidence,\n\t\t\t\t\tpayload: record.payload,\n\t\t\t\t\tat: record.at,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tentities() {\n\t\t\treturn Object.freeze([...new Set([...currentStatus.keys()].map((key) => key.split(\"\\u0000\")[1]!))]);\n\t\t},\n\t};\n}\n"]}
@@ -1,37 +0,0 @@
1
- import type { TransitionEvidenceRefV1, TransitionStoreV1 } from "./state-store.ts";
2
- export type TodoStatusV1 = "open" | "in_progress" | "completed" | "cancelled";
3
- export interface TodoV1 {
4
- readonly todoId: string;
5
- readonly owner: string;
6
- readonly content: string;
7
- readonly status: TodoStatusV1;
8
- readonly evidence: readonly TransitionEvidenceRefV1[];
9
- readonly revision: number;
10
- }
11
- export interface TodoPluginV1 {
12
- createTodo(input: {
13
- readonly todoId: string;
14
- readonly owner: string;
15
- readonly content: string;
16
- }): TodoV1;
17
- start(todoId: string, owner: string, options?: {
18
- readonly operationId?: string;
19
- }): TodoV1;
20
- /** Rewrites the content while open/in_progress; the ledger keeps every version replayable. */
21
- update(todoId: string, owner: string, content: string, options?: {
22
- readonly operationId?: string;
23
- }): TodoV1;
24
- complete(todoId: string, owner: string, evidence?: readonly TransitionEvidenceRefV1[], options?: {
25
- readonly operationId?: string;
26
- }): TodoV1;
27
- cancel(todoId: string, owner: string, reason?: string): TodoV1;
28
- /** Restarts a cancelled todo back into open. */
29
- reopen(todoId: string, owner: string, options?: {
30
- readonly operationId?: string;
31
- }): TodoV1;
32
- get(todoId: string, owner: string): TodoV1 | undefined;
33
- }
34
- export declare function createTodoPlugin(options: {
35
- readonly transitions: TransitionStoreV1;
36
- }): TodoPluginV1;
37
- //# sourceMappingURL=todo-plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"todo-plugin.d.ts","sourceRoot":"","sources":["../../src/profile/todo-plugin.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEnF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,aAAa,GAAG,WAAW,GAAG,WAAW,CAAC;AAE9E,MAAM,WAAW,MAAM;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1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AA;CAAE,GAAG,YAAY,CA6InG","sourcesContent":["/**\n * Todo plugin (2.3d) — Todo content lifecycle with cancellation and restart\n * over the 2.3a transition store.\n *\n * Status graph: null → open → in_progress → completed; open/in_progress →\n * cancelled; cancelled → open (restart). Content updates rewrite the payload\n * in place while the todo is open/in_progress, and every terminal transition\n * stays replayable from the ledger. The plugin holds NO shadow state —\n * content and status are always derived from the transition history.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { TransitionEvidenceRefV1, TransitionStoreV1 } from \"./state-store.ts\";\n\nexport type TodoStatusV1 = \"open\" | \"in_progress\" | \"completed\" | \"cancelled\";\n\nexport interface TodoV1 {\n\treadonly todoId: string;\n\treadonly owner: string;\n\treadonly content: string;\n\treadonly status: TodoStatusV1;\n\treadonly evidence: readonly TransitionEvidenceRefV1[];\n\treadonly revision: number;\n}\n\nexport interface TodoPluginV1 {\n\tcreateTodo(input: { readonly todoId: string; readonly owner: string; readonly content: string }): TodoV1;\n\tstart(todoId: string, owner: string, options?: { readonly operationId?: string }): TodoV1;\n\t/** Rewrites the content while open/in_progress; the ledger keeps every version replayable. */\n\tupdate(todoId: string, owner: string, content: string, options?: { readonly operationId?: string }): TodoV1;\n\tcomplete(\n\t\ttodoId: string,\n\t\towner: string,\n\t\tevidence?: readonly TransitionEvidenceRefV1[],\n\t\toptions?: { readonly operationId?: string },\n\t): TodoV1;\n\tcancel(todoId: string, owner: string, reason?: string): TodoV1;\n\t/** Restarts a cancelled todo back into open. */\n\treopen(todoId: string, owner: string, options?: { readonly operationId?: string }): TodoV1;\n\tget(todoId: string, owner: string): TodoV1 | undefined;\n}\n\ninterface TodoPayloadV1 {\n\treadonly content: string;\n\treadonly cancelReason?: string;\n}\n\n/** FNV-1a 32-bit — a short deterministic operationId suffix for content updates. */\nfunction contentHash(content: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < content.length; index += 1) {\n\t\thash ^= content.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(36);\n}\n\nfunction todoPayloadOf(record: { readonly payload?: unknown }): Partial<TodoPayloadV1> | undefined {\n\tconst payload = record.payload;\n\tif (payload !== null && typeof payload === \"object\" && !Array.isArray(payload)) {\n\t\treturn payload as Partial<TodoPayloadV1>;\n\t}\n\treturn undefined;\n}\n\nexport function createTodoPlugin(options: { readonly transitions: TransitionStoreV1 }): TodoPluginV1 {\n\tconst transitions = options.transitions;\n\n\tconst todoHistory = (todoId: string, owner: string) =>\n\t\ttransitions.history(todoId).filter((record) => record.domain === \"todo\" && record.owner === owner);\n\n\tconst current = (todoId: string, owner: string): { status: TodoStatusV1; revision: number } | undefined => {\n\t\tconst state = transitions.currentStatus(\"todo\", todoId);\n\t\tif (state === undefined || todoHistory(todoId, owner).length === 0) return undefined;\n\t\treturn { status: state.status as TodoStatusV1, revision: state.revision };\n\t};\n\n\tconst todoGet = (todoId: string, owner: string): TodoV1 | undefined => {\n\t\tconst state = current(todoId, owner);\n\t\tif (!state) return undefined;\n\t\tconst history = todoHistory(todoId, owner);\n\t\tconst content = [...history]\n\t\t\t.reverse()\n\t\t\t.map((record) => todoPayloadOf(record)?.content)\n\t\t\t.find((value): value is string => typeof value === \"string\");\n\t\tconst lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];\n\t\treturn {\n\t\t\ttodoId,\n\t\t\towner,\n\t\t\t// v8 ignore next -- createTodo 恒写入 content payload,标题扫描必命中\n\t\t\tcontent: content ?? \"\",\n\t\t\tstatus: state.status,\n\t\t\tevidence: lastEvidence,\n\t\t\trevision: state.revision,\n\t\t};\n\t};\n\n\t/** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */\n\tconst replayedTodo = (\n\t\ttodoId: string,\n\t\towner: string,\n\t\ttoStatus: TodoStatusV1,\n\t\toperationId?: string,\n\t): TodoV1 | undefined => {\n\t\tif (!operationId) return undefined;\n\t\tconst applied = todoHistory(todoId, owner).some(\n\t\t\t(record) => record.toStatus === toStatus && record.operationId === operationId,\n\t\t);\n\t\treturn applied ? todoGet(todoId, owner) : undefined;\n\t};\n\n\tconst transitionTodo = (\n\t\ttodoId: string,\n\t\towner: string,\n\t\tfromStatus: TodoStatusV1 | null,\n\t\ttoStatus: TodoStatusV1,\n\t\ttodoOptions: {\n\t\t\treadonly evidence?: readonly TransitionEvidenceRefV1[];\n\t\t\treadonly payload?: TodoPayloadV1;\n\t\t\treadonly operationId?: string;\n\t\t},\n\t): TodoV1 => {\n\t\ttransitions.transition({\n\t\t\tdomain: \"todo\",\n\t\t\tentityId: todoId,\n\t\t\towner,\n\t\t\tfromStatus,\n\t\t\ttoStatus,\n\t\t\toperationId: todoOptions.operationId ?? `${toStatus}:${todoId}`,\n\t\t\tevidence: todoOptions.evidence,\n\t\t\tpayload: todoOptions.payload as JsonValue | undefined,\n\t\t});\n\t\treturn todoGet(todoId, owner)!;\n\t};\n\n\tconst requireStatus = (todoId: string, owner: string, allowed: readonly TodoStatusV1[]): TodoV1 => {\n\t\tconst todo = todoGet(todoId, owner);\n\t\tif (!todo || !allowed.includes(todo.status)) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Todo {todoId} must be {allowed} (current: {status})\", {\n\t\t\t\t\ttodoId,\n\t\t\t\t\tallowed: allowed.join(\"/\"),\n\t\t\t\t\tstatus: todo?.status ?? \"missing\",\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn todo;\n\t};\n\n\treturn {\n\t\tcreateTodo({ todoId, owner, content }) {\n\t\t\tif (content.trim().length === 0) throw new Error(t(\"Todo content must be a non-empty string\"));\n\t\t\treturn transitionTodo(todoId, owner, null, \"open\", {\n\t\t\t\tpayload: { content },\n\t\t\t\toperationId: `create:${todoId}`,\n\t\t\t});\n\t\t},\n\t\tstart(todoId, owner, startOptions) {\n\t\t\tconst replayed = replayedTodo(todoId, owner, \"in_progress\", startOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\trequireStatus(todoId, owner, [\"open\"]);\n\t\t\treturn transitionTodo(todoId, owner, \"open\", \"in_progress\", { operationId: startOptions?.operationId });\n\t\t},\n\t\tupdate(todoId, owner, content, updateOptions) {\n\t\t\tif (content.trim().length === 0) throw new Error(t(\"Todo content must be a non-empty string\"));\n\t\t\tconst replayed = replayedTodo(\n\t\t\t\ttodoId,\n\t\t\t\towner,\n\t\t\t\ttodoGet(todoId, owner)?.status ?? \"open\",\n\t\t\t\tupdateOptions?.operationId,\n\t\t\t);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst todo = requireStatus(todoId, owner, [\"open\", \"in_progress\"]);\n\t\t\treturn transitionTodo(todoId, owner, todo.status, todo.status, {\n\t\t\t\tpayload: { content },\n\t\t\t\toperationId: updateOptions?.operationId ?? `update:${todoId}:${contentHash(content)}`,\n\t\t\t});\n\t\t},\n\t\tcomplete(todoId, owner, evidence, completeOptions) {\n\t\t\tconst replayed = replayedTodo(todoId, owner, \"completed\", completeOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\trequireStatus(todoId, owner, [\"in_progress\"]);\n\t\t\treturn transitionTodo(todoId, owner, \"in_progress\", \"completed\", {\n\t\t\t\tevidence: evidence ?? [],\n\t\t\t\toperationId: completeOptions?.operationId,\n\t\t\t});\n\t\t},\n\t\tcancel(todoId, owner, reason) {\n\t\t\tconst todo = requireStatus(todoId, owner, [\"open\", \"in_progress\"]);\n\t\t\tif (reason !== undefined && reason.trim().length === 0) {\n\t\t\t\tthrow new Error(t(\"Todo cancel reason must be a non-empty string when provided\"));\n\t\t\t}\n\t\t\treturn transitionTodo(todoId, owner, todo.status, \"cancelled\", {\n\t\t\t\t...(reason === undefined ? {} : { payload: { content: todo.content, cancelReason: reason } }),\n\t\t\t});\n\t\t},\n\t\treopen(todoId, owner, reopenOptions) {\n\t\t\tconst replayed = replayedTodo(todoId, owner, \"open\", reopenOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\trequireStatus(todoId, owner, [\"cancelled\"]);\n\t\t\treturn transitionTodo(todoId, owner, \"cancelled\", \"open\", { operationId: reopenOptions?.operationId });\n\t\t},\n\t\tget(todoId, owner) {\n\t\t\treturn todoGet(todoId, owner);\n\t\t},\n\t};\n}\n"]}
@@ -1,137 +0,0 @@
1
- import { t } from "../core/i18n/index.js";
2
- /** FNV-1a 32-bit — a short deterministic operationId suffix for content updates. */
3
- function contentHash(content) {
4
- let hash = 0x811c9dc5;
5
- for (let index = 0; index < content.length; index += 1) {
6
- hash ^= content.charCodeAt(index);
7
- hash = Math.imul(hash, 0x01000193);
8
- }
9
- return (hash >>> 0).toString(36);
10
- }
11
- function todoPayloadOf(record) {
12
- const payload = record.payload;
13
- if (payload !== null && typeof payload === "object" && !Array.isArray(payload)) {
14
- return payload;
15
- }
16
- return undefined;
17
- }
18
- export function createTodoPlugin(options) {
19
- const transitions = options.transitions;
20
- const todoHistory = (todoId, owner) => transitions.history(todoId).filter((record) => record.domain === "todo" && record.owner === owner);
21
- const current = (todoId, owner) => {
22
- const state = transitions.currentStatus("todo", todoId);
23
- if (state === undefined || todoHistory(todoId, owner).length === 0)
24
- return undefined;
25
- return { status: state.status, revision: state.revision };
26
- };
27
- const todoGet = (todoId, owner) => {
28
- const state = current(todoId, owner);
29
- if (!state)
30
- return undefined;
31
- const history = todoHistory(todoId, owner);
32
- const content = [...history]
33
- .reverse()
34
- .map((record) => todoPayloadOf(record)?.content)
35
- .find((value) => typeof value === "string");
36
- const lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];
37
- return {
38
- todoId,
39
- owner,
40
- // v8 ignore next -- createTodo 恒写入 content payload,标题扫描必命中
41
- content: content ?? "",
42
- status: state.status,
43
- evidence: lastEvidence,
44
- revision: state.revision,
45
- };
46
- };
47
- /** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */
48
- const replayedTodo = (todoId, owner, toStatus, operationId) => {
49
- if (!operationId)
50
- return undefined;
51
- const applied = todoHistory(todoId, owner).some((record) => record.toStatus === toStatus && record.operationId === operationId);
52
- return applied ? todoGet(todoId, owner) : undefined;
53
- };
54
- const transitionTodo = (todoId, owner, fromStatus, toStatus, todoOptions) => {
55
- transitions.transition({
56
- domain: "todo",
57
- entityId: todoId,
58
- owner,
59
- fromStatus,
60
- toStatus,
61
- operationId: todoOptions.operationId ?? `${toStatus}:${todoId}`,
62
- evidence: todoOptions.evidence,
63
- payload: todoOptions.payload,
64
- });
65
- return todoGet(todoId, owner);
66
- };
67
- const requireStatus = (todoId, owner, allowed) => {
68
- const todo = todoGet(todoId, owner);
69
- if (!todo || !allowed.includes(todo.status)) {
70
- throw new Error(t("Todo {todoId} must be {allowed} (current: {status})", {
71
- todoId,
72
- allowed: allowed.join("/"),
73
- status: todo?.status ?? "missing",
74
- }));
75
- }
76
- return todo;
77
- };
78
- return {
79
- createTodo({ todoId, owner, content }) {
80
- if (content.trim().length === 0)
81
- throw new Error(t("Todo content must be a non-empty string"));
82
- return transitionTodo(todoId, owner, null, "open", {
83
- payload: { content },
84
- operationId: `create:${todoId}`,
85
- });
86
- },
87
- start(todoId, owner, startOptions) {
88
- const replayed = replayedTodo(todoId, owner, "in_progress", startOptions?.operationId);
89
- if (replayed)
90
- return replayed;
91
- requireStatus(todoId, owner, ["open"]);
92
- return transitionTodo(todoId, owner, "open", "in_progress", { operationId: startOptions?.operationId });
93
- },
94
- update(todoId, owner, content, updateOptions) {
95
- if (content.trim().length === 0)
96
- throw new Error(t("Todo content must be a non-empty string"));
97
- const replayed = replayedTodo(todoId, owner, todoGet(todoId, owner)?.status ?? "open", updateOptions?.operationId);
98
- if (replayed)
99
- return replayed;
100
- const todo = requireStatus(todoId, owner, ["open", "in_progress"]);
101
- return transitionTodo(todoId, owner, todo.status, todo.status, {
102
- payload: { content },
103
- operationId: updateOptions?.operationId ?? `update:${todoId}:${contentHash(content)}`,
104
- });
105
- },
106
- complete(todoId, owner, evidence, completeOptions) {
107
- const replayed = replayedTodo(todoId, owner, "completed", completeOptions?.operationId);
108
- if (replayed)
109
- return replayed;
110
- requireStatus(todoId, owner, ["in_progress"]);
111
- return transitionTodo(todoId, owner, "in_progress", "completed", {
112
- evidence: evidence ?? [],
113
- operationId: completeOptions?.operationId,
114
- });
115
- },
116
- cancel(todoId, owner, reason) {
117
- const todo = requireStatus(todoId, owner, ["open", "in_progress"]);
118
- if (reason !== undefined && reason.trim().length === 0) {
119
- throw new Error(t("Todo cancel reason must be a non-empty string when provided"));
120
- }
121
- return transitionTodo(todoId, owner, todo.status, "cancelled", {
122
- ...(reason === undefined ? {} : { payload: { content: todo.content, cancelReason: reason } }),
123
- });
124
- },
125
- reopen(todoId, owner, reopenOptions) {
126
- const replayed = replayedTodo(todoId, owner, "open", reopenOptions?.operationId);
127
- if (replayed)
128
- return replayed;
129
- requireStatus(todoId, owner, ["cancelled"]);
130
- return transitionTodo(todoId, owner, "cancelled", "open", { operationId: reopenOptions?.operationId });
131
- },
132
- get(todoId, owner) {
133
- return todoGet(todoId, owner);
134
- },
135
- };
136
- }
137
- //# sourceMappingURL=todo-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"todo-plugin.js","sourceRoot":"","sources":["../../src/profile/todo-plugin.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAoC1C,sFAAoF;AACpF,SAAS,WAAW,CAAC,OAAe,EAAU;IAC7C,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACxD,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAAA,C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AC;YAC9B,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;YAC5C,OAAO,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,CAAC;QAAA,CACvG;QACD,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE;YAClB,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAAA,CAC9B;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Todo plugin (2.3d) — Todo content lifecycle with cancellation and restart\n * over the 2.3a transition store.\n *\n * Status graph: null → open → in_progress → completed; open/in_progress →\n * cancelled; cancelled → open (restart). Content updates rewrite the payload\n * in place while the todo is open/in_progress, and every terminal transition\n * stays replayable from the ledger. The plugin holds NO shadow state —\n * content and status are always derived from the transition history.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { TransitionEvidenceRefV1, TransitionStoreV1 } from \"./state-store.ts\";\n\nexport type TodoStatusV1 = \"open\" | \"in_progress\" | \"completed\" | \"cancelled\";\n\nexport interface TodoV1 {\n\treadonly todoId: string;\n\treadonly owner: string;\n\treadonly content: string;\n\treadonly status: TodoStatusV1;\n\treadonly evidence: readonly TransitionEvidenceRefV1[];\n\treadonly revision: number;\n}\n\nexport interface TodoPluginV1 {\n\tcreateTodo(input: { readonly todoId: string; readonly owner: string; readonly content: string }): TodoV1;\n\tstart(todoId: string, owner: string, options?: { readonly operationId?: string }): TodoV1;\n\t/** Rewrites the content while open/in_progress; the ledger keeps every version replayable. */\n\tupdate(todoId: string, owner: string, content: string, options?: { readonly operationId?: string }): TodoV1;\n\tcomplete(\n\t\ttodoId: string,\n\t\towner: string,\n\t\tevidence?: readonly TransitionEvidenceRefV1[],\n\t\toptions?: { readonly operationId?: string },\n\t): TodoV1;\n\tcancel(todoId: string, owner: string, reason?: string): TodoV1;\n\t/** Restarts a cancelled todo back into open. */\n\treopen(todoId: string, owner: string, options?: { readonly operationId?: string }): TodoV1;\n\tget(todoId: string, owner: string): TodoV1 | undefined;\n}\n\ninterface TodoPayloadV1 {\n\treadonly content: string;\n\treadonly cancelReason?: string;\n}\n\n/** FNV-1a 32-bit — a short deterministic operationId suffix for content updates. */\nfunction contentHash(content: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < content.length; index += 1) {\n\t\thash ^= content.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(36);\n}\n\nfunction todoPayloadOf(record: { readonly payload?: unknown }): Partial<TodoPayloadV1> | undefined {\n\tconst payload = record.payload;\n\tif (payload !== null && typeof payload === \"object\" && !Array.isArray(payload)) {\n\t\treturn payload as Partial<TodoPayloadV1>;\n\t}\n\treturn undefined;\n}\n\nexport function createTodoPlugin(options: { readonly transitions: TransitionStoreV1 }): TodoPluginV1 {\n\tconst transitions = options.transitions;\n\n\tconst todoHistory = (todoId: string, owner: string) =>\n\t\ttransitions.history(todoId).filter((record) => record.domain === \"todo\" && record.owner === owner);\n\n\tconst current = (todoId: string, owner: string): { status: TodoStatusV1; revision: number } | undefined => {\n\t\tconst state = transitions.currentStatus(\"todo\", todoId);\n\t\tif (state === undefined || todoHistory(todoId, owner).length === 0) return undefined;\n\t\treturn { status: state.status as TodoStatusV1, revision: state.revision };\n\t};\n\n\tconst todoGet = (todoId: string, owner: string): TodoV1 | undefined => {\n\t\tconst state = current(todoId, owner);\n\t\tif (!state) return undefined;\n\t\tconst history = todoHistory(todoId, owner);\n\t\tconst content = [...history]\n\t\t\t.reverse()\n\t\t\t.map((record) => todoPayloadOf(record)?.content)\n\t\t\t.find((value): value is string => typeof value === \"string\");\n\t\tconst lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];\n\t\treturn {\n\t\t\ttodoId,\n\t\t\towner,\n\t\t\t// v8 ignore next -- createTodo 恒写入 content payload,标题扫描必命中\n\t\t\tcontent: content ?? \"\",\n\t\t\tstatus: state.status,\n\t\t\tevidence: lastEvidence,\n\t\t\trevision: state.revision,\n\t\t};\n\t};\n\n\t/** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */\n\tconst replayedTodo = (\n\t\ttodoId: string,\n\t\towner: string,\n\t\ttoStatus: TodoStatusV1,\n\t\toperationId?: string,\n\t): TodoV1 | undefined => {\n\t\tif (!operationId) return undefined;\n\t\tconst applied = todoHistory(todoId, owner).some(\n\t\t\t(record) => record.toStatus === toStatus && record.operationId === operationId,\n\t\t);\n\t\treturn applied ? todoGet(todoId, owner) : undefined;\n\t};\n\n\tconst transitionTodo = (\n\t\ttodoId: string,\n\t\towner: string,\n\t\tfromStatus: TodoStatusV1 | null,\n\t\ttoStatus: TodoStatusV1,\n\t\ttodoOptions: {\n\t\t\treadonly evidence?: readonly TransitionEvidenceRefV1[];\n\t\t\treadonly payload?: TodoPayloadV1;\n\t\t\treadonly operationId?: string;\n\t\t},\n\t): TodoV1 => {\n\t\ttransitions.transition({\n\t\t\tdomain: \"todo\",\n\t\t\tentityId: todoId,\n\t\t\towner,\n\t\t\tfromStatus,\n\t\t\ttoStatus,\n\t\t\toperationId: todoOptions.operationId ?? `${toStatus}:${todoId}`,\n\t\t\tevidence: todoOptions.evidence,\n\t\t\tpayload: todoOptions.payload as JsonValue | undefined,\n\t\t});\n\t\treturn todoGet(todoId, owner)!;\n\t};\n\n\tconst requireStatus = (todoId: string, owner: string, allowed: readonly TodoStatusV1[]): TodoV1 => {\n\t\tconst todo = todoGet(todoId, owner);\n\t\tif (!todo || !allowed.includes(todo.status)) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Todo {todoId} must be {allowed} (current: {status})\", {\n\t\t\t\t\ttodoId,\n\t\t\t\t\tallowed: allowed.join(\"/\"),\n\t\t\t\t\tstatus: todo?.status ?? \"missing\",\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn todo;\n\t};\n\n\treturn {\n\t\tcreateTodo({ todoId, owner, content }) {\n\t\t\tif (content.trim().length === 0) throw new Error(t(\"Todo content must be a non-empty string\"));\n\t\t\treturn transitionTodo(todoId, owner, null, \"open\", {\n\t\t\t\tpayload: { content },\n\t\t\t\toperationId: `create:${todoId}`,\n\t\t\t});\n\t\t},\n\t\tstart(todoId, owner, startOptions) {\n\t\t\tconst replayed = replayedTodo(todoId, owner, \"in_progress\", startOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\trequireStatus(todoId, owner, [\"open\"]);\n\t\t\treturn transitionTodo(todoId, owner, \"open\", \"in_progress\", { operationId: startOptions?.operationId });\n\t\t},\n\t\tupdate(todoId, owner, content, updateOptions) {\n\t\t\tif (content.trim().length === 0) throw new Error(t(\"Todo content must be a non-empty string\"));\n\t\t\tconst replayed = replayedTodo(\n\t\t\t\ttodoId,\n\t\t\t\towner,\n\t\t\t\ttodoGet(todoId, owner)?.status ?? \"open\",\n\t\t\t\tupdateOptions?.operationId,\n\t\t\t);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst todo = requireStatus(todoId, owner, [\"open\", \"in_progress\"]);\n\t\t\treturn transitionTodo(todoId, owner, todo.status, todo.status, {\n\t\t\t\tpayload: { content },\n\t\t\t\toperationId: updateOptions?.operationId ?? `update:${todoId}:${contentHash(content)}`,\n\t\t\t});\n\t\t},\n\t\tcomplete(todoId, owner, evidence, completeOptions) {\n\t\t\tconst replayed = replayedTodo(todoId, owner, \"completed\", completeOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\trequireStatus(todoId, owner, [\"in_progress\"]);\n\t\t\treturn transitionTodo(todoId, owner, \"in_progress\", \"completed\", {\n\t\t\t\tevidence: evidence ?? [],\n\t\t\t\toperationId: completeOptions?.operationId,\n\t\t\t});\n\t\t},\n\t\tcancel(todoId, owner, reason) {\n\t\t\tconst todo = requireStatus(todoId, owner, [\"open\", \"in_progress\"]);\n\t\t\tif (reason !== undefined && reason.trim().length === 0) {\n\t\t\t\tthrow new Error(t(\"Todo cancel reason must be a non-empty string when provided\"));\n\t\t\t}\n\t\t\treturn transitionTodo(todoId, owner, todo.status, \"cancelled\", {\n\t\t\t\t...(reason === undefined ? {} : { payload: { content: todo.content, cancelReason: reason } }),\n\t\t\t});\n\t\t},\n\t\treopen(todoId, owner, reopenOptions) {\n\t\t\tconst replayed = replayedTodo(todoId, owner, \"open\", reopenOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\trequireStatus(todoId, owner, [\"cancelled\"]);\n\t\t\treturn transitionTodo(todoId, owner, \"cancelled\", \"open\", { operationId: reopenOptions?.operationId });\n\t\t},\n\t\tget(todoId, owner) {\n\t\t\treturn todoGet(todoId, owner);\n\t\t},\n\t};\n}\n"]}
@@ -1,26 +0,0 @@
1
- import { AgentHarness, type AgentHarnessOptions, type ExecutionEnv, type HarnessTool } from "@agent-forge/agent-core";
2
- import { type BuildSystemPromptOptions } from "../core/system-prompt.ts";
3
- export interface CodingAgentHarnessTool extends HarnessTool {
4
- promptSnippet?: string;
5
- promptGuidelines?: readonly string[];
6
- }
7
- export interface CreateCodingAgentHarnessOptions extends Omit<AgentHarnessOptions, "toolContext" | "tools"> {
8
- env: ExecutionEnv;
9
- bashCommandPrefix?: string;
10
- /** Path to the JSONL session file exposed to default bash commands as AGENT_FORGE_SESSION_FILE. */
11
- sessionFile?: string;
12
- tools?: CodingAgentHarnessTool[];
13
- systemPromptOptions?: Omit<BuildSystemPromptOptions, "cwd" | "promptGuidelines" | "selectedTools" | "toolSnippets">;
14
- }
15
- export interface BuildCodingAgentHarnessSystemPromptOptions {
16
- cwd: string;
17
- tools: readonly CodingAgentHarnessTool[];
18
- activeToolNames: readonly string[];
19
- systemPromptOptions?: CreateCodingAgentHarnessOptions["systemPromptOptions"];
20
- }
21
- export declare function buildCodingAgentHarnessSystemPrompt(options: BuildCodingAgentHarnessSystemPromptOptions): string;
22
- export declare function createCodingAgentHarness(options: CreateCodingAgentHarnessOptions): Promise<{
23
- harness: AgentHarness;
24
- suspended: import("@agent-forge/agent-core").SuspendedOperation[];
25
- }>;
26
- //# sourceMappingURL=create-harness.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-harness.d.ts","sourceRoot":"","sources":["../../src/server/create-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EACZ,KAAK,mBAAmB,EAMxB,KAAK,YAAY,EAEjB,KAAK,WAAW,EAChB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,KAAK,wBAAwB,EAAqB,MAAM,0BAA0B,CAAC;AAM5F,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IAC1D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAgBD,MAAM,WAAW,+BAAgC,SAAQ,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,OAAO,CAAC;IAC1G,GAAG,EAAE,YAAY,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mGAAmG;IACnG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACjC,mBAAmB,CAAC,EAAE,IAAI,CAAC,wBAAwB,EAAE,KAAK,GAAG,kBAAkB,GAAG,eAAe,GAAG,cAAc,CAAC,CAAC;CACpH;AAED,MAAM,WAAW,0CAA0C;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACzC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,mBAAmB,CAAC,EAAE,+BAA+B,CAAC,qBAAqB,CAAC,CAAC;CAC7E;AAED,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,0CAA0C,GAAG,MAAM,CAsB/G;AAED,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,+BAA+B;;;GAkFtF","sourcesContent":["import {\n\tAgentHarness,\n\ttype AgentHarnessOptions,\n\ttype AgentHarnessTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\tcreateReadTool,\n\tcreateWriteTool,\n\ttype ExecutionEnv,\n\ttype ExecutionToolContext,\n\ttype HarnessTool,\n} from \"@agent-forge/agent-core\";\nimport type { Static, TSchema } from \"typebox\";\nimport { type BuildSystemPromptOptions, buildSystemPrompt } from \"../core/system-prompt.ts\";\nimport { bashToolSystemPromptContribution } from \"../core/tools/bash.ts\";\nimport { editToolSystemPromptContribution } from \"../core/tools/edit.ts\";\nimport { readToolSystemPromptContribution } from \"../core/tools/read.ts\";\nimport { writeToolSystemPromptContribution } from \"../core/tools/write.ts\";\n\nexport interface CodingAgentHarnessTool extends HarnessTool {\n\tpromptSnippet?: string;\n\tpromptGuidelines?: readonly string[];\n}\n\nfunction createCodingAgentHarnessTool<TParameters extends TSchema, TDetails>(\n\ttool: AgentHarnessTool<ExecutionToolContext, TParameters, TDetails>,\n\tcontext: ExecutionToolContext,\n\tprompt: Required<Pick<CodingAgentHarnessTool, \"promptSnippet\" | \"promptGuidelines\">>,\n): CodingAgentHarnessTool {\n\treturn {\n\t\t...tool,\n\t\t...prompt,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\texecute: (toolCallId, params, signal, onUpdate) =>\n\t\t\ttool.execute(toolCallId, params as Static<TParameters>, signal, onUpdate, context),\n\t};\n}\n\nexport interface CreateCodingAgentHarnessOptions extends Omit<AgentHarnessOptions, \"toolContext\" | \"tools\"> {\n\tenv: ExecutionEnv;\n\tbashCommandPrefix?: string;\n\t/** Path to the JSONL session file exposed to default bash commands as AGENT_FORGE_SESSION_FILE. */\n\tsessionFile?: string;\n\ttools?: CodingAgentHarnessTool[];\n\tsystemPromptOptions?: Omit<BuildSystemPromptOptions, \"cwd\" | \"promptGuidelines\" | \"selectedTools\" | \"toolSnippets\">;\n}\n\nexport interface BuildCodingAgentHarnessSystemPromptOptions {\n\tcwd: string;\n\ttools: readonly CodingAgentHarnessTool[];\n\tactiveToolNames: readonly string[];\n\tsystemPromptOptions?: CreateCodingAgentHarnessOptions[\"systemPromptOptions\"];\n}\n\nexport function buildCodingAgentHarnessSystemPrompt(options: BuildCodingAgentHarnessSystemPromptOptions): string {\n\tconst activeTools = options.activeToolNames.flatMap((name) => {\n\t\tconst tool = options.tools.find((candidate) => candidate.name === name);\n\t\treturn tool ? [tool] : [];\n\t});\n\tconst toolSnippets = Object.fromEntries(\n\t\tactiveTools.flatMap((tool) => {\n\t\t\tconst promptSnippet = tool.promptSnippet\n\t\t\t\t?.replace(/[\\r\\n]+/g, \" \")\n\t\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t\t.trim();\n\t\t\treturn promptSnippet ? [[tool.name, promptSnippet]] : [];\n\t\t}),\n\t);\n\tconst promptGuidelines = activeTools.flatMap((tool) => tool.promptGuidelines ?? []);\n\treturn buildSystemPrompt({\n\t\t...options.systemPromptOptions,\n\t\tcwd: options.cwd,\n\t\tselectedTools: activeTools.map((tool) => tool.name),\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t});\n}\n\nexport async function createCodingAgentHarness(options: CreateCodingAgentHarnessOptions) {\n\tconst {\n\t\tenv,\n\t\tbashCommandPrefix,\n\t\tsessionFile,\n\t\tsystemPromptOptions,\n\t\ttools: providedTools,\n\t\tactiveToolNames: providedActiveToolNames,\n\t\tsystemPrompt: providedSystemPrompt,\n\t\t...harnessOptions\n\t} = options;\n\tlet harness: AgentHarness | undefined;\n\tconst getHarness = (): AgentHarness => {\n\t\t// v8 ignore next -- harness 在 create 返回后同步赋值,回调只会在其后执行\n\t\tif (!harness) throw new Error(\"Coding-agent Harness callback ran before Harness initialization\");\n\t\treturn harness;\n\t};\n\tlet tools = providedTools;\n\tif (tools === undefined) {\n\t\tconst metadata = await options.session.getMetadata();\n\t\tconst toolContext = { env } satisfies ExecutionToolContext;\n\t\ttools = [\n\t\t\tcreateCodingAgentHarnessTool(createReadTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: readToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: readToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(\n\t\t\t\tcreateBashTool<ExecutionToolContext>({\n\t\t\t\t\tcommandPrefix: bashCommandPrefix,\n\t\t\t\t\tprepare: async (execution) => {\n\t\t\t\t\t\tconst currentHarness = getHarness();\n\t\t\t\t\t\tconst [model, thinkingLevel] = await Promise.all([\n\t\t\t\t\t\t\tcurrentHarness.getModel(),\n\t\t\t\t\t\t\tcurrentHarness.getThinkingLevel(),\n\t\t\t\t\t\t]);\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_ID = metadata.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_FILE = sessionFile ?? \"\";\n\t\t\t\t\t\texecution.env.AGENT_FORGE_PROVIDER = model.provider;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_MODEL = model.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_REASONING_LEVEL = thinkingLevel;\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\ttoolContext,\n\t\t\t\t{\n\t\t\t\t\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\t\t\t\t\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\t\t\t\t},\n\t\t\t),\n\t\t\tcreateCodingAgentHarnessTool(createEditTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: editToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(createWriteTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: writeToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t];\n\t}\n\tconst activeToolNames = [...(providedActiveToolNames ?? tools.map((tool) => tool.name))];\n\tconst systemPrompt =\n\t\tprovidedSystemPrompt ??\n\t\t(async () => {\n\t\t\tconst currentHarness = getHarness();\n\t\t\tconst [currentTools, currentActiveToolNames] = await Promise.all([\n\t\t\t\tcurrentHarness.getTools(),\n\t\t\t\tcurrentHarness.getActiveTools(),\n\t\t\t]);\n\t\t\treturn buildCodingAgentHarnessSystemPrompt({\n\t\t\t\tcwd: env.cwd,\n\t\t\t\ttools: currentTools,\n\t\t\t\tactiveToolNames: currentActiveToolNames,\n\t\t\t\tsystemPromptOptions,\n\t\t\t});\n\t\t});\n\tconst created = await AgentHarness.create({\n\t\t...harnessOptions,\n\t\ttools,\n\t\tactiveToolNames,\n\t\tsystemPrompt,\n\t});\n\tharness = created.harness;\n\treturn created;\n}\n"]}
@@ -1,106 +0,0 @@
1
- import { AgentHarness, createBashTool, createEditTool, createReadTool, createWriteTool, } from "@agent-forge/agent-core";
2
- import { buildSystemPrompt } from "../core/system-prompt.js";
3
- import { bashToolSystemPromptContribution } from "../core/tools/bash.js";
4
- import { editToolSystemPromptContribution } from "../core/tools/edit.js";
5
- import { readToolSystemPromptContribution } from "../core/tools/read.js";
6
- import { writeToolSystemPromptContribution } from "../core/tools/write.js";
7
- function createCodingAgentHarnessTool(tool, context, prompt) {
8
- return {
9
- ...tool,
10
- ...prompt,
11
- constrainedSampling: { type: "json_schema", strict: "prefer" },
12
- execute: (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate, context),
13
- };
14
- }
15
- export function buildCodingAgentHarnessSystemPrompt(options) {
16
- const activeTools = options.activeToolNames.flatMap((name) => {
17
- const tool = options.tools.find((candidate) => candidate.name === name);
18
- return tool ? [tool] : [];
19
- });
20
- const toolSnippets = Object.fromEntries(activeTools.flatMap((tool) => {
21
- const promptSnippet = tool.promptSnippet
22
- ?.replace(/[\r\n]+/g, " ")
23
- .replace(/\s+/g, " ")
24
- .trim();
25
- return promptSnippet ? [[tool.name, promptSnippet]] : [];
26
- }));
27
- const promptGuidelines = activeTools.flatMap((tool) => tool.promptGuidelines ?? []);
28
- return buildSystemPrompt({
29
- ...options.systemPromptOptions,
30
- cwd: options.cwd,
31
- selectedTools: activeTools.map((tool) => tool.name),
32
- toolSnippets,
33
- promptGuidelines,
34
- });
35
- }
36
- export async function createCodingAgentHarness(options) {
37
- const { env, bashCommandPrefix, sessionFile, systemPromptOptions, tools: providedTools, activeToolNames: providedActiveToolNames, systemPrompt: providedSystemPrompt, ...harnessOptions } = options;
38
- let harness;
39
- const getHarness = () => {
40
- // v8 ignore next -- harness 在 create 返回后同步赋值,回调只会在其后执行
41
- if (!harness)
42
- throw new Error("Coding-agent Harness callback ran before Harness initialization");
43
- return harness;
44
- };
45
- let tools = providedTools;
46
- if (tools === undefined) {
47
- const metadata = await options.session.getMetadata();
48
- const toolContext = { env };
49
- tools = [
50
- createCodingAgentHarnessTool(createReadTool(), toolContext, {
51
- promptSnippet: readToolSystemPromptContribution.snippet,
52
- promptGuidelines: readToolSystemPromptContribution.guidelines,
53
- }),
54
- createCodingAgentHarnessTool(createBashTool({
55
- commandPrefix: bashCommandPrefix,
56
- prepare: async (execution) => {
57
- const currentHarness = getHarness();
58
- const [model, thinkingLevel] = await Promise.all([
59
- currentHarness.getModel(),
60
- currentHarness.getThinkingLevel(),
61
- ]);
62
- execution.env.AGENT_FORGE_SESSION_ID = metadata.id;
63
- execution.env.AGENT_FORGE_SESSION_FILE = sessionFile ?? "";
64
- execution.env.AGENT_FORGE_PROVIDER = model.provider;
65
- execution.env.AGENT_FORGE_MODEL = model.id;
66
- execution.env.AGENT_FORGE_REASONING_LEVEL = thinkingLevel;
67
- },
68
- }), toolContext, {
69
- promptSnippet: bashToolSystemPromptContribution.snippet,
70
- promptGuidelines: bashToolSystemPromptContribution.guidelines,
71
- }),
72
- createCodingAgentHarnessTool(createEditTool(), toolContext, {
73
- promptSnippet: editToolSystemPromptContribution.snippet,
74
- promptGuidelines: editToolSystemPromptContribution.guidelines,
75
- }),
76
- createCodingAgentHarnessTool(createWriteTool(), toolContext, {
77
- promptSnippet: writeToolSystemPromptContribution.snippet,
78
- promptGuidelines: writeToolSystemPromptContribution.guidelines,
79
- }),
80
- ];
81
- }
82
- const activeToolNames = [...(providedActiveToolNames ?? tools.map((tool) => tool.name))];
83
- const systemPrompt = providedSystemPrompt ??
84
- (async () => {
85
- const currentHarness = getHarness();
86
- const [currentTools, currentActiveToolNames] = await Promise.all([
87
- currentHarness.getTools(),
88
- currentHarness.getActiveTools(),
89
- ]);
90
- return buildCodingAgentHarnessSystemPrompt({
91
- cwd: env.cwd,
92
- tools: currentTools,
93
- activeToolNames: currentActiveToolNames,
94
- systemPromptOptions,
95
- });
96
- });
97
- const created = await AgentHarness.create({
98
- ...harnessOptions,
99
- tools,
100
- activeToolNames,
101
- systemPrompt,
102
- });
103
- harness = created.harness;
104
- return created;
105
- }
106
- //# sourceMappingURL=create-harness.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-harness.js","sourceRoot":"","sources":["../../src/server/create-harness.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,EAGZ,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,GAIf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAiC,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAC;AAO3E,SAAS,4BAA4B,CACpC,IAAmE,EACnE,OAA6B,EAC7B,MAAoF,EAC3D;IACzB,OAAO;QACN,GAAG,IAAI;QACP,GAAG,MAAM;QACT,mBAAmB,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE;QAC9D,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MA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AAC,GAAG;gBACZ,KAAK,EAAE,YAAY;gBACnB,eAAe,EAAE,sBAAsB;gBACvC,mBAAmB;aACnB,CAAC,CAAC;QAAA,CACH,CAAC,CAAC;IACJ,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC;QACzC,GAAG,cAAc;QACjB,KAAK;QACL,eAAe;QACf,YAAY;KACZ,CAAC,CAAC;IACH,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAC1B,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import {\n\tAgentHarness,\n\ttype AgentHarnessOptions,\n\ttype AgentHarnessTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\tcreateReadTool,\n\tcreateWriteTool,\n\ttype ExecutionEnv,\n\ttype ExecutionToolContext,\n\ttype HarnessTool,\n} from \"@agent-forge/agent-core\";\nimport type { Static, TSchema } from \"typebox\";\nimport { type BuildSystemPromptOptions, buildSystemPrompt } from \"../core/system-prompt.ts\";\nimport { bashToolSystemPromptContribution } from \"../core/tools/bash.ts\";\nimport { editToolSystemPromptContribution } from \"../core/tools/edit.ts\";\nimport { readToolSystemPromptContribution } from \"../core/tools/read.ts\";\nimport { writeToolSystemPromptContribution } from \"../core/tools/write.ts\";\n\nexport interface CodingAgentHarnessTool extends HarnessTool {\n\tpromptSnippet?: string;\n\tpromptGuidelines?: readonly string[];\n}\n\nfunction createCodingAgentHarnessTool<TParameters extends TSchema, TDetails>(\n\ttool: AgentHarnessTool<ExecutionToolContext, TParameters, TDetails>,\n\tcontext: ExecutionToolContext,\n\tprompt: Required<Pick<CodingAgentHarnessTool, \"promptSnippet\" | \"promptGuidelines\">>,\n): CodingAgentHarnessTool {\n\treturn {\n\t\t...tool,\n\t\t...prompt,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\texecute: (toolCallId, params, signal, onUpdate) =>\n\t\t\ttool.execute(toolCallId, params as Static<TParameters>, signal, onUpdate, context),\n\t};\n}\n\nexport interface CreateCodingAgentHarnessOptions extends Omit<AgentHarnessOptions, \"toolContext\" | \"tools\"> {\n\tenv: ExecutionEnv;\n\tbashCommandPrefix?: string;\n\t/** Path to the JSONL session file exposed to default bash commands as AGENT_FORGE_SESSION_FILE. */\n\tsessionFile?: string;\n\ttools?: CodingAgentHarnessTool[];\n\tsystemPromptOptions?: Omit<BuildSystemPromptOptions, \"cwd\" | \"promptGuidelines\" | \"selectedTools\" | \"toolSnippets\">;\n}\n\nexport interface BuildCodingAgentHarnessSystemPromptOptions {\n\tcwd: string;\n\ttools: readonly CodingAgentHarnessTool[];\n\tactiveToolNames: readonly string[];\n\tsystemPromptOptions?: CreateCodingAgentHarnessOptions[\"systemPromptOptions\"];\n}\n\nexport function buildCodingAgentHarnessSystemPrompt(options: BuildCodingAgentHarnessSystemPromptOptions): string {\n\tconst activeTools = options.activeToolNames.flatMap((name) => {\n\t\tconst tool = options.tools.find((candidate) => candidate.name === name);\n\t\treturn tool ? [tool] : [];\n\t});\n\tconst toolSnippets = Object.fromEntries(\n\t\tactiveTools.flatMap((tool) => {\n\t\t\tconst promptSnippet = tool.promptSnippet\n\t\t\t\t?.replace(/[\\r\\n]+/g, \" \")\n\t\t\t\t.replace(/\\s+/g, \" \")\n\t\t\t\t.trim();\n\t\t\treturn promptSnippet ? [[tool.name, promptSnippet]] : [];\n\t\t}),\n\t);\n\tconst promptGuidelines = activeTools.flatMap((tool) => tool.promptGuidelines ?? []);\n\treturn buildSystemPrompt({\n\t\t...options.systemPromptOptions,\n\t\tcwd: options.cwd,\n\t\tselectedTools: activeTools.map((tool) => tool.name),\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t});\n}\n\nexport async function createCodingAgentHarness(options: CreateCodingAgentHarnessOptions) {\n\tconst {\n\t\tenv,\n\t\tbashCommandPrefix,\n\t\tsessionFile,\n\t\tsystemPromptOptions,\n\t\ttools: providedTools,\n\t\tactiveToolNames: providedActiveToolNames,\n\t\tsystemPrompt: providedSystemPrompt,\n\t\t...harnessOptions\n\t} = options;\n\tlet harness: AgentHarness | undefined;\n\tconst getHarness = (): AgentHarness => {\n\t\t// v8 ignore next -- harness 在 create 返回后同步赋值,回调只会在其后执行\n\t\tif (!harness) throw new Error(\"Coding-agent Harness callback ran before Harness initialization\");\n\t\treturn harness;\n\t};\n\tlet tools = providedTools;\n\tif (tools === undefined) {\n\t\tconst metadata = await options.session.getMetadata();\n\t\tconst toolContext = { env } satisfies ExecutionToolContext;\n\t\ttools = [\n\t\t\tcreateCodingAgentHarnessTool(createReadTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: readToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: readToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(\n\t\t\t\tcreateBashTool<ExecutionToolContext>({\n\t\t\t\t\tcommandPrefix: bashCommandPrefix,\n\t\t\t\t\tprepare: async (execution) => {\n\t\t\t\t\t\tconst currentHarness = getHarness();\n\t\t\t\t\t\tconst [model, thinkingLevel] = await Promise.all([\n\t\t\t\t\t\t\tcurrentHarness.getModel(),\n\t\t\t\t\t\t\tcurrentHarness.getThinkingLevel(),\n\t\t\t\t\t\t]);\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_ID = metadata.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_SESSION_FILE = sessionFile ?? \"\";\n\t\t\t\t\t\texecution.env.AGENT_FORGE_PROVIDER = model.provider;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_MODEL = model.id;\n\t\t\t\t\t\texecution.env.AGENT_FORGE_REASONING_LEVEL = thinkingLevel;\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\ttoolContext,\n\t\t\t\t{\n\t\t\t\t\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\t\t\t\t\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\t\t\t\t},\n\t\t\t),\n\t\t\tcreateCodingAgentHarnessTool(createEditTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: editToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t\tcreateCodingAgentHarnessTool(createWriteTool<ExecutionToolContext>(), toolContext, {\n\t\t\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\t\t\tpromptGuidelines: writeToolSystemPromptContribution.guidelines,\n\t\t\t}),\n\t\t];\n\t}\n\tconst activeToolNames = [...(providedActiveToolNames ?? tools.map((tool) => tool.name))];\n\tconst systemPrompt =\n\t\tprovidedSystemPrompt ??\n\t\t(async () => {\n\t\t\tconst currentHarness = getHarness();\n\t\t\tconst [currentTools, currentActiveToolNames] = await Promise.all([\n\t\t\t\tcurrentHarness.getTools(),\n\t\t\t\tcurrentHarness.getActiveTools(),\n\t\t\t]);\n\t\t\treturn buildCodingAgentHarnessSystemPrompt({\n\t\t\t\tcwd: env.cwd,\n\t\t\t\ttools: currentTools,\n\t\t\t\tactiveToolNames: currentActiveToolNames,\n\t\t\t\tsystemPromptOptions,\n\t\t\t});\n\t\t});\n\tconst created = await AgentHarness.create({\n\t\t...harnessOptions,\n\t\ttools,\n\t\tactiveToolNames,\n\t\tsystemPrompt,\n\t});\n\tharness = created.harness;\n\treturn created;\n}\n"]}