@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,23 +1,27 @@
1
1
  /**
2
- * Default agent-loop bootstrap executor (W3).
2
+ * Default agent-loop bootstrap executor (W3; D-082 批 3 拆分登记).
3
3
  *
4
- /**
5
- * Registers the default main-loop capabilities through the public extension
6
- * face so the default loop stays a replaceable first-party plugin:
7
- * - the five default loop-hook links (capability lifecycle dispatch, image
8
- * normalization, context strategy, compaction + next-turn refresh, and the
9
- * repeated-tool-call guard: shouldStopAfterTurn decision + transformContext
10
- * warn-reminder injection), and
11
- * - the default post-run continuation strategy (the host's own candidate
12
- * decision).
4
+ * Registers the default main-loop event-dispatch links through the public
5
+ * extension face so the default loop stays a replaceable first-party plugin:
6
+ * the four default loop-hook links (capability lifecycle dispatch, image
7
+ * normalization, context strategy, compaction + next-turn refresh).
8
+ *
9
+ * D-082 批 3 拆分事实:默认重复工具调用护栏(createRepeatedToolCallStopPolicy
10
+ * 的 shouldStopAfterTurn 决策链 + transformContext 提醒注入链)与默认
11
+ * run-loop strategy(decideNextCycle 直通)不消费 {@link AgentLoopWiringV1},
12
+ * 已迁出为 `plugins/agent-loop-policy`(插件 id
13
+ * `agent-forge.plugin.agent-loop-policy`),经 sdk 的 bundled 分发通道装配;
14
+ * 禁用面为会话装配的 `disabledPluginIds`。本模块保留的四条链是宿主事件分发
15
+ * 装配(与 bootstrap-lifecycle 同类的内核事件机制接线):它们消费 wiring 的
16
+ * 会话闭包成员,无法经插件通道获得,故留宿主内嵌。
13
17
  *
14
18
  * The default links need session-bound host state (session id, revision,
15
19
  * correlation id, error observation, settings). That state is injected as
16
20
  * {@link AgentLoopWiringV1} — host wiring, not a plugin capability. Third-party
17
21
  * plugins register additional links through `api.registerLoopHook`; they run
18
- * after the default links in registration order.
22
+ * after the default links in registration order (the bundled agent-loop-policy
23
+ * plugin's guard/strategy links land in that same trailing region).
19
24
  */
20
- import { createHash } from "node:crypto";
21
25
  import { normalizeToolResultImages } from "../../utils/tool-result-images.js";
22
26
  import { t } from "../i18n/index.js";
23
27
  import { loadCapabilityPluginSync } from "./capability-plugin.js";
@@ -25,236 +29,14 @@ import { applyCapabilityContextStrategy } from "./context-strategy-binding.js";
25
29
  import { TOOL_CALL_EVENT_ID, TOOL_CALL_EVENT_VERSION, TOOL_EXECUTE_EVENT_ID, TOOL_EXECUTE_EVENT_VERSION, TOOL_RESULT_RAW_EVENT_ID, TOOL_RESULT_RAW_EVENT_VERSION, TOOL_RESULT_TRANSFORM_EVENT_ID, TOOL_RESULT_TRANSFORM_EVENT_VERSION, } from "./lifecycle-catalog.js";
26
30
  import { detachedSessionSnapshot, EXPERIMENTAL_PUBLIC_API_VERSION, } from "./public-api.js";
27
31
  export const BOOTSTRAP_AGENT_LOOP_PLUGIN_ID = "agent-forge.bootstrap-agent-loop";
28
- export const DEFAULT_RUN_LOOP_STRATEGY_NAME = "default";
29
- /** 滑动窗口大小:护栏只回看最近 N 个工具调用签名(跨回合累计)。 */
30
- export const REPEATED_TOOL_CALL_WINDOW_SIZE = 6;
31
- /** 提醒阈值:窗口尾部连续相同签名达到该次数时提醒模型(不停机,两级响应第一级)。 */
32
- export const REPEATED_TOOL_CALL_WARN_THRESHOLD = 3;
33
- /** 停机阈值:提醒后仍连续相同达到该次数才请求停机(两级响应第二级兜底)。 */
34
- export const REPEATED_TOOL_CALL_STOP_THRESHOLD = 5;
35
- /** 停机提示消息的 customType(用户可见面,随 agent_end 的 messages 带出)。 */
36
- export const REPEATED_TOOL_CALL_STOP_CUSTOM_TYPE = "loop_guard_stop";
37
- /** 提醒消息的 customType(用户可见面经 sendMessage 持久化+渲染;模型面注入复用同一标记)。 */
38
- export const REPEATED_TOOL_CALL_WARN_CUSTOM_TYPE = "loop_guard_warn";
39
- /** 提示消息中参数串的最大长度,超出截断(只影响提示文本,不影响检测签名)。 */
40
- export const REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS = 200;
41
- /**
42
- * 参数稳定字符串化:对象键递归排序后逐层拼接(数组保持顺序),循环引用输出
43
- * 固定占位。只用于签名比较与提示文本,不是通用 JSON 序列化器。
44
- */
45
- export function stableSerializeValue(value, seen = new WeakSet()) {
46
- if (value === null)
47
- return "null";
48
- switch (typeof value) {
49
- case "string":
50
- return JSON.stringify(value);
51
- case "number":
52
- return String(value);
53
- case "boolean":
54
- return String(value);
55
- case "undefined":
56
- return "undefined";
57
- case "bigint":
58
- return `bigint:${String(value)}`;
59
- case "function":
60
- return "function";
61
- case "symbol":
62
- return "symbol";
63
- case "object":
64
- break;
65
- default:
66
- return "unknown";
67
- }
68
- if (seen.has(value))
69
- return '"[cycle]"';
70
- seen.add(value);
71
- const serialized = Array.isArray(value)
72
- ? `[${value.map((item) => stableSerializeValue(item, seen)).join(",")}]`
73
- : (() => {
74
- const record = value;
75
- const keys = Object.keys(record).sort();
76
- return `{${keys.map((key) => `${JSON.stringify(key)}:${stableSerializeValue(record[key], seen)}`).join(",")}}`;
77
- })();
78
- seen.delete(value);
79
- return serialized;
80
- }
81
32
  /**
82
- * 工具结果哈希(签名第三要素):拼接结果的 text 内容后做全量 SHA-256(十六进制),
83
- * isError 一并纳入(同参同果且同错误状态才计重复)。任何字节差异都产生不同哈希,
84
- * 因此长结果(前缀稳定、尾部变化)的合法轮询不会被误判成"同果"——签名不受任何
85
- * 截断影响。无文本结果(纯图像等)与结果缺席都返回空串占位:签名退化为两要素
86
- * (工具名 + 参数),这是已知局限——无文本的同参结果彼此不可区分。
87
- * 调用与结果按 toolCallId 对应,正常流程中每个调用都有结果;无结果返回空串。
33
+ * 默认 run-loop strategy 名(宿主会话配置缺省名,D-082 批 3)。策略实现本体已
34
+ * 迁出为 `plugins/agent-loop-policy`(其 `DEFAULT_RUN_LOOP_STRATEGY_NAME` 与本
35
+ * 值逐字相同,两侧测试各自钉值);宿主保留该名字用于 `runLoopStrategyName`
36
+ * 缺省解析——策略缺席时宿主回退自身的延续候选(行为不变),存在时经
37
+ * `runtime.decideRunLoop` 咨询。
88
38
  */
89
- export function toolResultHash(result) {
90
- if (!result)
91
- return "";
92
- const text = result.content
93
- .filter((block) => block.type === "text")
94
- .map((block) => block.text)
95
- .join("\n");
96
- if (text === "")
97
- return "";
98
- return `${result.isError ? "error" : "ok"}:${createHash("sha256").update(text).digest("hex")}`;
99
- }
100
- /** 工具调用签名:工具名 + 参数稳定字符串化 + 结果哈希。 */
101
- export function repeatedToolCallSignature(toolName, args, resultHash) {
102
- return `${JSON.stringify(toolName)}:${stableSerializeValue(args)}:${resultHash}`;
103
- }
104
- /** 参数摘要截断:超出 {@link REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS} 打截断标记(用户可见消息与日志通道共用)。 */
105
- function truncateNoticeArgs(argsText) {
106
- return argsText.length > REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS
107
- ? `${argsText.slice(0, REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS)}...(truncated)`
108
- : argsText;
109
- }
110
- /** 停机提示消息:随停机回合的 newMessages 带出(agent_end 可见),并经 deliverNotice 投递到宿主公共面。 */
111
- export function createRepeatedToolCallStopNotice(toolName, argsText, stopThreshold) {
112
- const truncated = truncateNoticeArgs(argsText);
113
- return {
114
- role: "custom",
115
- customType: REPEATED_TOOL_CALL_STOP_CUSTOM_TYPE,
116
- content: `Loop guard: stopped after the same tool call (${toolName}) was repeated ${stopThreshold} times in a row. Args: ${truncated}`,
117
- display: true,
118
- timestamp: Date.now(),
119
- };
120
- }
121
- /**
122
- * 提醒通知消息(用户可见面,loop_guard_warn):经 deliverWarn 投递(默认安装接
123
- * `SessionAPI.sendMessage`,持久化 + 实时渲染),与停机通知(loop_guard_stop)
124
- * 的 customType 区分。提醒不进入 newMessages——模型面提醒由 transformContext
125
- * 注入承担,用户面提醒由本消息的持久化+渲染承担。
126
- */
127
- export function createRepeatedToolCallWarnNotice(toolName, argsText, warnThreshold) {
128
- const truncated = truncateNoticeArgs(argsText);
129
- return {
130
- role: "custom",
131
- customType: REPEATED_TOOL_CALL_WARN_CUSTOM_TYPE,
132
- content: `Loop guard: the same tool call (${toolName}) was repeated ${warnThreshold} times in a row with the same result. Args: ${truncated}`,
133
- display: true,
134
- timestamp: Date.now(),
135
- };
136
- }
137
- /**
138
- * 模型面提醒消息(transformContext 注入用):display:false 的 custom 消息,
139
- * 经 convertToLlm 转为 user 文本进入下一次模型请求。只存在于该次请求视图
140
- * (不写 context.messages、不进 newMessages,故不持久化);customType 复用
141
- * loop_guard_warn 标记来源。
142
- */
143
- export function createRepeatedToolCallWarnReminder(warnThreshold) {
144
- return {
145
- role: "custom",
146
- customType: REPEATED_TOOL_CALL_WARN_CUSTOM_TYPE,
147
- content: `You have repeated the identical tool call with an identical result ${warnThreshold} times. If you are waiting for external state to change, change your approach instead of retrying the same call.`,
148
- display: false,
149
- timestamp: Date.now(),
150
- };
151
- }
152
- /**
153
- * 默认重复工具调用护栏(主对话循环护栏切片A,两级响应)。
154
- *
155
- * 每个完成的回合从 assistant 消息中按序取出工具调用,签名(工具名 + 键序参数
156
- * + 本轮结果哈希,结果按 toolCallId 对应)追加进滑动窗口并裁剪到 windowSize;
157
- * 然后按窗口尾部连续相同签名段(含同一回合内多次相同调用)做两级响应:
158
- *
159
- * - 第一级(达到 warnThreshold,缺省 3):返回 false 不停机,改为提醒——内部
160
- * 标记 pendingWarn,由本工厂返回的 transformContext 链路在下一轮请求前把提醒
161
- * 消息追加到请求视图尾部(agent-loop 的 runLoop 在每次 shouldStopAfterTurn
162
- * 之后、下一次 streamAssistantResponse 之前消费 transformContext,故提醒必然
163
- * 进入下一次请求);同时把用户可见提醒经 deliverWarn 投递、事实经 onWarn 记
164
- * 日志。同一连续重复段只提醒一次(warnedForRun 闩);连续段断开(模型改变
165
- * 行为)即复位,后续新的连续段可再次提醒。
166
- * - 第二级(达到 stopThreshold,缺省 5):返回 true 请求停机——先向
167
- * {@link ShouldStopAfterTurnContext} 的 newMessages 追加一条用户可见的停机消
168
- * 息并交给 deliverNotice(禁止静默停机),再经 onStop 记日志。判据不可能完
169
- * 美,因此不可逆停机不是第一响应。
170
- *
171
- * 同参不同果(合法轮询,如等待外部状态就绪)不计重复:结果要素是全量哈希,
172
- * 任何字节差异(包括 >200 字符长结果仅尾部变化)都产生不同签名;无文本结果
173
- * 退化为两要素(见 {@link toolResultHash} 局限声明)。无工具调用或结果缺席的
174
- * 轮次不进窗口。
175
- *
176
- * 挂载点说明:两条链路都由 {@link installBootstrapAgentLoop} 经公共扩展面
177
- * `api.registerLoopHook` 注册为默认链路(transformContext 注入链注册在默认上
178
- * 下文策略链之后,提醒落到最终请求视图尾部);disabledBootstrapPlugins 跳过本
179
- * 插件时均不注册,护栏随之关闭。wireDefaultLoop 只消费链,不直接安装本策略。
180
- */
181
- export function createRepeatedToolCallStopPolicy(options = {}) {
182
- const windowSize = options.windowSize ?? REPEATED_TOOL_CALL_WINDOW_SIZE;
183
- const warnThreshold = options.warnThreshold ?? REPEATED_TOOL_CALL_WARN_THRESHOLD;
184
- const stopThreshold = options.stopThreshold ?? REPEATED_TOOL_CALL_STOP_THRESHOLD;
185
- const window = [];
186
- let lastToolName = "";
187
- let lastArgsText = "";
188
- /** 待注入的提醒事实:warn 时置位,transformContext 消费即清除(只注入一次)。 */
189
- let pendingWarn;
190
- /** 当前连续重复段已提醒闩:同段不重复提醒;段断开(尾部连续段短于提醒阈值)时复位。 */
191
- let warnedForRun = false;
192
- /** 窗口尾部连续相同签名的段长。 */
193
- const trailingRunLength = () => {
194
- const last = window[window.length - 1];
195
- if (last === undefined)
196
- return 0;
197
- let run = 0;
198
- for (let i = window.length - 1; i >= 0 && window[i] === last; i -= 1)
199
- run += 1;
200
- return run;
201
- };
202
- const shouldStopAfterTurn = (context) => {
203
- const toolCalls = context.message.content.filter((block) => block.type === "toolCall");
204
- // 三要素签名需要本轮工具结果:结果缺席时无法判定"同果",该轮不进窗口,
205
- // 避免把合法轮询误判成重复。
206
- if (toolCalls.length > 0 && context.toolResults.length > 0) {
207
- const resultById = new Map(context.toolResults.map((result) => [result.toolCallId, result]));
208
- for (const call of toolCalls) {
209
- window.push(repeatedToolCallSignature(call.name, call.arguments, toolResultHash(resultById.get(call.id))));
210
- lastToolName = call.name;
211
- lastArgsText = stableSerializeValue(call.arguments);
212
- }
213
- }
214
- if (window.length > windowSize) {
215
- window.splice(0, window.length - windowSize);
216
- }
217
- const run = trailingRunLength();
218
- if (run >= stopThreshold) {
219
- // 第二级兜底:硬停,走停机全通道(newMessages + deliverNotice + onStop)。
220
- // 先于提醒判定:stopThreshold 被显式覆盖到不大于 warnThreshold 时停机优先。
221
- pendingWarn = undefined;
222
- const notice = createRepeatedToolCallStopNotice(lastToolName, lastArgsText, stopThreshold);
223
- context.newMessages.push(notice);
224
- options.deliverNotice?.(notice);
225
- // 日志可见通道(D-072 6(a)):与用户可见提示成对发出;onStop 属宿主接线,
226
- // 策略本身不知道任何具体日志实现。
227
- options.onStop?.({ toolName: lastToolName, argsSummary: truncateNoticeArgs(lastArgsText), stopThreshold });
228
- return true;
229
- }
230
- if (run < warnThreshold) {
231
- // 连续段断开:模型改变行为。复位已提醒闩并丢弃未消费的待注入提醒
232
- // (正常流程中它已在下一轮请求前被消费;此处只兜底运行中断的残留)。
233
- warnedForRun = false;
234
- pendingWarn = undefined;
235
- return false;
236
- }
237
- // 第一级:提醒不停机。标记待注入(transformContext 链路消费),经
238
- // deliverWarn/onWarn 双通道可见;同一连续段只提醒一次。
239
- if (!warnedForRun) {
240
- warnedForRun = true;
241
- pendingWarn = { toolName: lastToolName, argsSummary: truncateNoticeArgs(lastArgsText), warnThreshold };
242
- options.deliverWarn?.(createRepeatedToolCallWarnNotice(lastToolName, lastArgsText, warnThreshold));
243
- options.onWarn?.(pendingWarn);
244
- }
245
- return false;
246
- };
247
- const transformContext = async (messages, _signal) => {
248
- const info = pendingWarn;
249
- if (!info)
250
- return undefined;
251
- // 消费即清除:提醒只注入一次;重复继续发生不重复注入。非变异地追加到
252
- // 请求视图尾部(不写 context.messages,故不持久化、不进 newMessages)。
253
- pendingWarn = undefined;
254
- return [...messages, createRepeatedToolCallWarnReminder(info.warnThreshold)];
255
- };
256
- return { shouldStopAfterTurn, transformContext };
257
- }
39
+ export const DEFAULT_RUN_LOOP_STRATEGY_NAME = "default";
258
40
  /**
259
41
  * Default beforeToolCall link: the `tool.call@1` candidate dispatch with
260
42
  * identity/revision checks. Moved from the AgentSession tool-hook wiring.
@@ -511,56 +293,12 @@ export function installBootstrapAgentLoop(runtime, wiring) {
511
293
  api.registerLoopHook("afterToolCall", createDefaultAfterToolCallLink(runtime, wiring));
512
294
  api.registerLoopHook("transformContext", createDefaultTransformContextLink(runtime, wiring));
513
295
  api.registerLoopHook("prepareNextTurn", createDefaultPrepareNextTurnLink(wiring));
514
- // The default repeated-tool-call guard rides the public loop-hook
515
- // chains like any other first-party link; disabling this plugin
516
- // removes both of its links. It answers with two levels (judgments
517
- // can be wrong, so an irreversible stop is never the first response):
518
- // - warn (third identical call): the shouldStopAfterTurn link votes
519
- // false and the transformContext link below injects a reminder into
520
- // the next request view (runLoop consumes transformContext after
521
- // shouldStopAfterTurn and before the next model call); the user-
522
- // facing warn notice is delivered through the public SessionAPI
523
- // sendMessage face (persisted custom_message entry with live
524
- // message_start/message_end rendering), plus a warn log through
525
- // the public LoggerAPI.
526
- // - stop (fifth identical call): the shouldStopAfterTurn link votes
527
- // true; the stop notice rides agent_end newMessages, sendMessage
528
- // persistence + rendering, and a warn log — all channels on.
529
- // Absent host features (session/logger) degrade to the remaining
530
- // channels instead of blocking the guard.
531
- const loopGuard = createRepeatedToolCallStopPolicy({
532
- deliverWarn: (notice) => {
533
- void api.session?.sendMessage?.(notice, { triggerTurn: false });
534
- },
535
- onWarn: (info) => {
536
- api.logger?.warn("Loop guard warned the model", {
537
- tool: info.toolName,
538
- repeats: info.warnThreshold,
539
- argsSummary: info.argsSummary,
540
- });
541
- },
542
- deliverNotice: (notice) => {
543
- void api.session?.sendMessage?.(notice, { triggerTurn: false });
544
- },
545
- onStop: (info) => {
546
- api.logger?.warn("Loop guard stopped the turn", {
547
- tool: info.toolName,
548
- repeats: info.stopThreshold,
549
- argsSummary: info.argsSummary,
550
- });
551
- },
552
- });
553
- api.registerLoopHook("shouldStopAfterTurn", loopGuard.shouldStopAfterTurn);
554
- // Registered after the default context-strategy link, so the reminder
555
- // is appended to the final post-strategy request view (survives any
556
- // strategy pruning) at its tail.
557
- api.registerLoopHook("transformContext", loopGuard.transformContext);
558
- // The default continuation strategy reproduces the host's own
559
- // post-run decision byte for byte; a replacement strategy overrides
560
- // the continue/stop call through registerRunLoopStrategy.
561
- api.registerRunLoopStrategy(DEFAULT_RUN_LOOP_STRATEGY_NAME, {
562
- decideNextCycle: (request) => ({ continueLoop: request.hostWillContinue }),
563
- });
296
+ // D-082 批 3:默认重复工具调用护栏(shouldStopAfterTurn 决策链 +
297
+ // transformContext 提醒注入链)与默认 run-loop strategy 不再在此注册——
298
+ // 它们不消费 wiring,已迁出为 plugins/agent-loop-policy
299
+ // (agent-forge.plugin.agent-loop-policy),经 sdk bundled 分发通道装配;
300
+ // 其链接在本执行器之后注册,落链顺序与内嵌时代一致(护栏注入链仍在
301
+ // 默认上下文策略链之后、第三方链接之前)。
564
302
  });
565
303
  }
566
304
  //# sourceMappingURL=bootstrap-agent-loop.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap-agent-loop.js","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-agent-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC,OAAO,EAA+B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,E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,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC;SAC1E,CAAC,CAAC;IAAA,CACH,CACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Default agent-loop bootstrap executor (W3).\n *\n/**\n * Registers the default main-loop capabilities through the public extension\n * face so the default loop stays a replaceable first-party plugin:\n * - the five default loop-hook links (capability lifecycle dispatch, image\n * normalization, context strategy, compaction + next-turn refresh, and the\n * repeated-tool-call guard: shouldStopAfterTurn decision + transformContext\n * warn-reminder injection), and\n * - the default post-run continuation strategy (the host's own candidate\n * decision).\n *\n * The default links need session-bound host state (session id, revision,\n * correlation id, error observation, settings). That state is injected as\n * {@link AgentLoopWiringV1} — host wiring, not a plugin capability. Third-party\n * plugins register additional links through `api.registerLoopHook`; they run\n * after the default links in registration order.\n */\n\nimport { createHash } from \"node:crypto\";\nimport type {\n\tAgentContext,\n\tAgentLoopTurnUpdate,\n\tAgentMessage,\n\tAgentTool,\n\tPrepareNextTurnContext,\n\tShouldStopAfterTurnContext,\n\tThinkingLevel,\n} from \"@agent-forge/agent-core\";\nimport type { ToolCall, ToolResultMessage } from \"@agent-forge/ai\";\nimport type { Api, ImageContent, Model, TextContent, Usage } from \"@agent-forge/ai/compat\";\nimport { normalizeToolResultImages } from \"../../utils/tool-result-images.ts\";\nimport { t } from \"../i18n/index.ts\";\nimport type { CustomMessage } from \"../messages.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { applyCapabilityContextStrategy } from \"./context-strategy-binding.ts\";\nimport {\n\tTOOL_CALL_EVENT_ID,\n\tTOOL_CALL_EVENT_VERSION,\n\tTOOL_EXECUTE_EVENT_ID,\n\tTOOL_EXECUTE_EVENT_VERSION,\n\tTOOL_RESULT_RAW_EVENT_ID,\n\tTOOL_RESULT_RAW_EVENT_VERSION,\n\tTOOL_RESULT_TRANSFORM_EVENT_ID,\n\tTOOL_RESULT_TRANSFORM_EVENT_VERSION,\n\ttype ToolCallEventDataV1,\n\ttype ToolExecuteEventDataV1,\n\ttype ToolResultRawEventDataV1,\n\ttype ToolResultTransformEventDataV1,\n} from \"./lifecycle-catalog.ts\";\nimport {\n\ttype AgentLoopAfterToolCallHookV1,\n\ttype AgentLoopBeforeToolCallHookV1,\n\ttype AgentLoopPrepareNextTurnHookV1,\n\ttype AgentLoopTransformContextHookV1,\n\tdetachedSessionSnapshot,\n\tEXPERIMENTAL_PUBLIC_API_VERSION,\n\ttype SessionRevisionV1,\n} from \"./public-api.ts\";\n\nexport const BOOTSTRAP_AGENT_LOOP_PLUGIN_ID = \"agent-forge.bootstrap-agent-loop\";\nexport const DEFAULT_RUN_LOOP_STRATEGY_NAME = \"default\";\n\n/** 滑动窗口大小:护栏只回看最近 N 个工具调用签名(跨回合累计)。 */\nexport const REPEATED_TOOL_CALL_WINDOW_SIZE = 6;\n/** 提醒阈值:窗口尾部连续相同签名达到该次数时提醒模型(不停机,两级响应第一级)。 */\nexport const REPEATED_TOOL_CALL_WARN_THRESHOLD = 3;\n/** 停机阈值:提醒后仍连续相同达到该次数才请求停机(两级响应第二级兜底)。 */\nexport const REPEATED_TOOL_CALL_STOP_THRESHOLD = 5;\n/** 停机提示消息的 customType(用户可见面,随 agent_end 的 messages 带出)。 */\nexport const REPEATED_TOOL_CALL_STOP_CUSTOM_TYPE = \"loop_guard_stop\";\n/** 提醒消息的 customType(用户可见面经 sendMessage 持久化+渲染;模型面注入复用同一标记)。 */\nexport const REPEATED_TOOL_CALL_WARN_CUSTOM_TYPE = \"loop_guard_warn\";\n/** 提示消息中参数串的最大长度,超出截断(只影响提示文本,不影响检测签名)。 */\nexport const REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS = 200;\n\n/** {@link createRepeatedToolCallStopPolicy} 的窗口与两级阈值参数(缺省用上方命名常量)。 */\nexport interface RepeatedToolCallStopPolicyOptions {\n\t/** 滑动窗口大小,缺省 {@link REPEATED_TOOL_CALL_WINDOW_SIZE}。 */\n\twindowSize?: number;\n\t/** 提醒阈值(第一级,不停机),缺省 {@link REPEATED_TOOL_CALL_WARN_THRESHOLD}。 */\n\twarnThreshold?: number;\n\t/** 停机阈值(第二级兜底),缺省 {@link REPEATED_TOOL_CALL_STOP_THRESHOLD}。显式设为不大于提醒阈值时停机优先。 */\n\tstopThreshold?: number;\n\t/**\n\t * 提醒时的日志面回调(与 {@link onStop} 同纪律:info 只携带脱敏后的事实——\n\t * 工具名、截断参数摘要、提醒阈值,不含完整工具参数)。只在第一级实际提醒的\n\t * 回合调用一次;缺省不接 = 行为不变。\n\t */\n\tonWarn?: (info: RepeatedToolCallWarnInfo) => void;\n\t/**\n\t * 停机时的日志面回调(D-072 治理纪律 6(a):用户可见 + 日志可见双通道)。\n\t * 只在策略实际请求停机的回合调用一次;缺省不接 = 行为不变。info 只携带\n\t * 脱敏后的事实(工具名、截断参数摘要、阈值),不含完整工具参数。\n\t */\n\tonStop?: (info: RepeatedToolCallStopInfo) => void;\n\t/**\n\t * 提醒通知投递缝:策略把提醒消息交给宿主选定的公共面。默认安装把它接到\n\t * `SessionAPI.sendMessage`(持久化 + message_start 实时渲染);缺席时提醒\n\t * 仍经 transformContext 注入模型请求(模型面不依赖该缝)。\n\t */\n\tdeliverWarn?: (notice: CustomMessage) => void;\n\t/**\n\t * 停机通知投递缝:策略把停机提示消息交给宿主选定的公共面。默认安装把它接到\n\t * `SessionAPI.sendMessage`(运行中排队、run 收尾 flush 落为 custom_message\n\t * 条目——持久化 + message_start 实时渲染);缺席时停机事实仅随 agent_end 的\n\t * newMessages 带出(行为不变)。\n\t */\n\tdeliverNotice?: (notice: CustomMessage) => void;\n}\n\n/** 提醒事实(脱敏):{@link RepeatedToolCallStopPolicyOptions.onWarn} 的载荷。 */\nexport interface RepeatedToolCallWarnInfo {\n\t/** 触发提醒的最后一个工具名。 */\n\ttoolName: string;\n\t/** 截断后的参数稳定序列化摘要(复用 {@link REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS})。 */\n\targsSummary: string;\n\t/** 达到的连续重复提醒阈值。 */\n\twarnThreshold: number;\n}\n\n/** 停机事实(脱敏):{@link RepeatedToolCallStopPolicyOptions.onStop} 的载荷。 */\nexport interface RepeatedToolCallStopInfo {\n\t/** 触发停机的最后一个工具名。 */\n\ttoolName: string;\n\t/** 截断后的参数稳定序列化摘要(复用 {@link REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS})。 */\n\targsSummary: string;\n\t/** 达到的连续重复停机阈值。 */\n\tstopThreshold: number;\n}\n\n/**\n * 参数稳定字符串化:对象键递归排序后逐层拼接(数组保持顺序),循环引用输出\n * 固定占位。只用于签名比较与提示文本,不是通用 JSON 序列化器。\n */\nexport function stableSerializeValue(value: unknown, seen: WeakSet<object> = new WeakSet()): string {\n\tif (value === null) return \"null\";\n\tswitch (typeof value) {\n\t\tcase \"string\":\n\t\t\treturn JSON.stringify(value);\n\t\tcase \"number\":\n\t\t\treturn String(value);\n\t\tcase \"boolean\":\n\t\t\treturn String(value);\n\t\tcase \"undefined\":\n\t\t\treturn \"undefined\";\n\t\tcase \"bigint\":\n\t\t\treturn `bigint:${String(value)}`;\n\t\tcase \"function\":\n\t\t\treturn \"function\";\n\t\tcase \"symbol\":\n\t\t\treturn \"symbol\";\n\t\tcase \"object\":\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn \"unknown\";\n\t}\n\tif (seen.has(value)) return '\"[cycle]\"';\n\tseen.add(value);\n\tconst serialized = Array.isArray(value)\n\t\t? `[${value.map((item) => stableSerializeValue(item, seen)).join(\",\")}]`\n\t\t: (() => {\n\t\t\t\tconst record = value as Record<string, unknown>;\n\t\t\t\tconst keys = Object.keys(record).sort();\n\t\t\t\treturn `{${keys.map((key) => `${JSON.stringify(key)}:${stableSerializeValue(record[key], seen)}`).join(\",\")}}`;\n\t\t\t})();\n\tseen.delete(value);\n\treturn serialized;\n}\n\n/**\n * 工具结果哈希(签名第三要素):拼接结果的 text 内容后做全量 SHA-256(十六进制),\n * isError 一并纳入(同参同果且同错误状态才计重复)。任何字节差异都产生不同哈希,\n * 因此长结果(前缀稳定、尾部变化)的合法轮询不会被误判成\"同果\"——签名不受任何\n * 截断影响。无文本结果(纯图像等)与结果缺席都返回空串占位:签名退化为两要素\n * (工具名 + 参数),这是已知局限——无文本的同参结果彼此不可区分。\n * 调用与结果按 toolCallId 对应,正常流程中每个调用都有结果;无结果返回空串。\n */\nexport function toolResultHash(result: ToolResultMessage | undefined): string {\n\tif (!result) return \"\";\n\tconst text = result.content\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n\tif (text === \"\") return \"\";\n\treturn `${result.isError ? \"error\" : \"ok\"}:${createHash(\"sha256\").update(text).digest(\"hex\")}`;\n}\n\n/** 工具调用签名:工具名 + 参数稳定字符串化 + 结果哈希。 */\nexport function repeatedToolCallSignature(toolName: string, args: unknown, resultHash: string): string {\n\treturn `${JSON.stringify(toolName)}:${stableSerializeValue(args)}:${resultHash}`;\n}\n\n/** 参数摘要截断:超出 {@link REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS} 打截断标记(用户可见消息与日志通道共用)。 */\nfunction truncateNoticeArgs(argsText: string): string {\n\treturn argsText.length > REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS\n\t\t? `${argsText.slice(0, REPEATED_TOOL_CALL_NOTICE_MAX_ARGS_CHARS)}...(truncated)`\n\t\t: argsText;\n}\n\n/** 停机提示消息:随停机回合的 newMessages 带出(agent_end 可见),并经 deliverNotice 投递到宿主公共面。 */\nexport function createRepeatedToolCallStopNotice(\n\ttoolName: string,\n\targsText: string,\n\tstopThreshold: number,\n): CustomMessage {\n\tconst truncated = truncateNoticeArgs(argsText);\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType: REPEATED_TOOL_CALL_STOP_CUSTOM_TYPE,\n\t\tcontent: `Loop guard: stopped after the same tool call (${toolName}) was repeated ${stopThreshold} times in a row. Args: ${truncated}`,\n\t\tdisplay: true,\n\t\ttimestamp: Date.now(),\n\t};\n}\n\n/**\n * 提醒通知消息(用户可见面,loop_guard_warn):经 deliverWarn 投递(默认安装接\n * `SessionAPI.sendMessage`,持久化 + 实时渲染),与停机通知(loop_guard_stop)\n * 的 customType 区分。提醒不进入 newMessages——模型面提醒由 transformContext\n * 注入承担,用户面提醒由本消息的持久化+渲染承担。\n */\nexport function createRepeatedToolCallWarnNotice(\n\ttoolName: string,\n\targsText: string,\n\twarnThreshold: number,\n): CustomMessage {\n\tconst truncated = truncateNoticeArgs(argsText);\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType: REPEATED_TOOL_CALL_WARN_CUSTOM_TYPE,\n\t\tcontent: `Loop guard: the same tool call (${toolName}) was repeated ${warnThreshold} times in a row with the same result. Args: ${truncated}`,\n\t\tdisplay: true,\n\t\ttimestamp: Date.now(),\n\t};\n}\n\n/**\n * 模型面提醒消息(transformContext 注入用):display:false 的 custom 消息,\n * 经 convertToLlm 转为 user 文本进入下一次模型请求。只存在于该次请求视图\n * (不写 context.messages、不进 newMessages,故不持久化);customType 复用\n * loop_guard_warn 标记来源。\n */\nexport function createRepeatedToolCallWarnReminder(warnThreshold: number): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType: REPEATED_TOOL_CALL_WARN_CUSTOM_TYPE,\n\t\tcontent: `You have repeated the identical tool call with an identical result ${warnThreshold} times. If you are waiting for external state to change, change your approach instead of retrying the same call.`,\n\t\tdisplay: false,\n\t\ttimestamp: Date.now(),\n\t};\n}\n\n/** {@link createRepeatedToolCallStopPolicy} 返回的两条链路(共享同一滑动窗口与两级状态)。 */\nexport interface RepeatedToolCallGuard {\n\t/**\n\t * \"shouldStopAfterTurn\" 链路:两级判定的决策面(返回 true 即请求停机)。\n\t */\n\tshouldStopAfterTurn: (context: ShouldStopAfterTurnContext) => boolean;\n\t/**\n\t * \"transformContext\" 链路:提醒注入面。有待注入提醒时返回追加了提醒消息的\n\t * 新数组(进入下一次模型请求视图),否则返回 undefined(保留输入)。\n\t */\n\ttransformContext: (messages: readonly unknown[], signal?: AbortSignal) => Promise<readonly unknown[] | undefined>;\n}\n\n/**\n * 默认重复工具调用护栏(主对话循环护栏切片A,两级响应)。\n *\n * 每个完成的回合从 assistant 消息中按序取出工具调用,签名(工具名 + 键序参数\n * + 本轮结果哈希,结果按 toolCallId 对应)追加进滑动窗口并裁剪到 windowSize;\n * 然后按窗口尾部连续相同签名段(含同一回合内多次相同调用)做两级响应:\n *\n * - 第一级(达到 warnThreshold,缺省 3):返回 false 不停机,改为提醒——内部\n * 标记 pendingWarn,由本工厂返回的 transformContext 链路在下一轮请求前把提醒\n * 消息追加到请求视图尾部(agent-loop 的 runLoop 在每次 shouldStopAfterTurn\n * 之后、下一次 streamAssistantResponse 之前消费 transformContext,故提醒必然\n * 进入下一次请求);同时把用户可见提醒经 deliverWarn 投递、事实经 onWarn 记\n * 日志。同一连续重复段只提醒一次(warnedForRun 闩);连续段断开(模型改变\n * 行为)即复位,后续新的连续段可再次提醒。\n * - 第二级(达到 stopThreshold,缺省 5):返回 true 请求停机——先向\n * {@link ShouldStopAfterTurnContext} 的 newMessages 追加一条用户可见的停机消\n * 息并交给 deliverNotice(禁止静默停机),再经 onStop 记日志。判据不可能完\n * 美,因此不可逆停机不是第一响应。\n *\n * 同参不同果(合法轮询,如等待外部状态就绪)不计重复:结果要素是全量哈希,\n * 任何字节差异(包括 >200 字符长结果仅尾部变化)都产生不同签名;无文本结果\n * 退化为两要素(见 {@link toolResultHash} 局限声明)。无工具调用或结果缺席的\n * 轮次不进窗口。\n *\n * 挂载点说明:两条链路都由 {@link installBootstrapAgentLoop} 经公共扩展面\n * `api.registerLoopHook` 注册为默认链路(transformContext 注入链注册在默认上\n * 下文策略链之后,提醒落到最终请求视图尾部);disabledBootstrapPlugins 跳过本\n * 插件时均不注册,护栏随之关闭。wireDefaultLoop 只消费链,不直接安装本策略。\n */\nexport function createRepeatedToolCallStopPolicy(\n\toptions: RepeatedToolCallStopPolicyOptions = {},\n): RepeatedToolCallGuard {\n\tconst windowSize = options.windowSize ?? REPEATED_TOOL_CALL_WINDOW_SIZE;\n\tconst warnThreshold = options.warnThreshold ?? REPEATED_TOOL_CALL_WARN_THRESHOLD;\n\tconst stopThreshold = options.stopThreshold ?? REPEATED_TOOL_CALL_STOP_THRESHOLD;\n\tconst window: string[] = [];\n\tlet lastToolName = \"\";\n\tlet lastArgsText = \"\";\n\t/** 待注入的提醒事实:warn 时置位,transformContext 消费即清除(只注入一次)。 */\n\tlet pendingWarn: RepeatedToolCallWarnInfo | undefined;\n\t/** 当前连续重复段已提醒闩:同段不重复提醒;段断开(尾部连续段短于提醒阈值)时复位。 */\n\tlet warnedForRun = false;\n\n\t/** 窗口尾部连续相同签名的段长。 */\n\tconst trailingRunLength = (): number => {\n\t\tconst last = window[window.length - 1];\n\t\tif (last === undefined) return 0;\n\t\tlet run = 0;\n\t\tfor (let i = window.length - 1; i >= 0 && window[i] === last; i -= 1) run += 1;\n\t\treturn run;\n\t};\n\n\tconst shouldStopAfterTurn = (context: ShouldStopAfterTurnContext): boolean => {\n\t\tconst toolCalls = context.message.content.filter((block): block is ToolCall => block.type === \"toolCall\");\n\t\t// 三要素签名需要本轮工具结果:结果缺席时无法判定\"同果\",该轮不进窗口,\n\t\t// 避免把合法轮询误判成重复。\n\t\tif (toolCalls.length > 0 && context.toolResults.length > 0) {\n\t\t\tconst resultById = new Map(context.toolResults.map((result) => [result.toolCallId, result]));\n\t\t\tfor (const call of toolCalls) {\n\t\t\t\twindow.push(repeatedToolCallSignature(call.name, call.arguments, toolResultHash(resultById.get(call.id))));\n\t\t\t\tlastToolName = call.name;\n\t\t\t\tlastArgsText = stableSerializeValue(call.arguments);\n\t\t\t}\n\t\t}\n\t\tif (window.length > windowSize) {\n\t\t\twindow.splice(0, window.length - windowSize);\n\t\t}\n\t\tconst run = trailingRunLength();\n\t\tif (run >= stopThreshold) {\n\t\t\t// 第二级兜底:硬停,走停机全通道(newMessages + deliverNotice + onStop)。\n\t\t\t// 先于提醒判定:stopThreshold 被显式覆盖到不大于 warnThreshold 时停机优先。\n\t\t\tpendingWarn = undefined;\n\t\t\tconst notice = createRepeatedToolCallStopNotice(lastToolName, lastArgsText, stopThreshold);\n\t\t\tcontext.newMessages.push(notice);\n\t\t\toptions.deliverNotice?.(notice);\n\t\t\t// 日志可见通道(D-072 6(a)):与用户可见提示成对发出;onStop 属宿主接线,\n\t\t\t// 策略本身不知道任何具体日志实现。\n\t\t\toptions.onStop?.({ toolName: lastToolName, argsSummary: truncateNoticeArgs(lastArgsText), stopThreshold });\n\t\t\treturn true;\n\t\t}\n\t\tif (run < warnThreshold) {\n\t\t\t// 连续段断开:模型改变行为。复位已提醒闩并丢弃未消费的待注入提醒\n\t\t\t// (正常流程中它已在下一轮请求前被消费;此处只兜底运行中断的残留)。\n\t\t\twarnedForRun = false;\n\t\t\tpendingWarn = undefined;\n\t\t\treturn false;\n\t\t}\n\t\t// 第一级:提醒不停机。标记待注入(transformContext 链路消费),经\n\t\t// deliverWarn/onWarn 双通道可见;同一连续段只提醒一次。\n\t\tif (!warnedForRun) {\n\t\t\twarnedForRun = true;\n\t\t\tpendingWarn = { toolName: lastToolName, argsSummary: truncateNoticeArgs(lastArgsText), warnThreshold };\n\t\t\toptions.deliverWarn?.(createRepeatedToolCallWarnNotice(lastToolName, lastArgsText, warnThreshold));\n\t\t\toptions.onWarn?.(pendingWarn);\n\t\t}\n\t\treturn false;\n\t};\n\n\tconst transformContext = async (\n\t\tmessages: readonly unknown[],\n\t\t_signal?: AbortSignal,\n\t): Promise<readonly unknown[] | undefined> => {\n\t\tconst info = pendingWarn;\n\t\tif (!info) return undefined;\n\t\t// 消费即清除:提醒只注入一次;重复继续发生不重复注入。非变异地追加到\n\t\t// 请求视图尾部(不写 context.messages,故不持久化、不进 newMessages)。\n\t\tpendingWarn = undefined;\n\t\treturn [...messages, createRepeatedToolCallWarnReminder(info.warnThreshold)];\n\t};\n\n\treturn { shouldStopAfterTurn, transformContext };\n}\n\n/**\n * Session-bound host state the default loop links read at execution time.\n * Host wiring injected into the bootstrap executor; not part of the plugin\n * capability surface.\n */\nexport interface AgentLoopWiringV1 {\n\t/** Canonical session id for lifecycle payloads. */\n\tgetSessionId(): string;\n\t/** Detached revision snapshot captured at payload build time. */\n\tgetRevision(): SessionRevisionV1;\n\t/** Correlation id of the current prompt run, if any. */\n\tgetTurnCorrelationId(): string | undefined;\n\t/** Non-fatal delivery error sink (same surface as session-level observation). */\n\tobserveError(error: unknown, extensionPath: string, event: string): void;\n\t/** Image auto-resize setting for tool-result normalization. */\n\tgetImageAutoResize(): boolean;\n\t/** Compaction hook chained first inside the default prepareNextTurn link. */\n\tcompactBeforeNextAssistantResponse(context: AgentContext, signal?: AbortSignal): Promise<AgentContext>;\n\t/** Next-turn refresh snapshot applied last inside the default prepareNextTurn link. */\n\tgetTurnRefresh(): {\n\t\tsystemPrompt: string;\n\t\ttools: AgentTool[];\n\t\tmodel: Model<Api>;\n\t\tthinkingLevel: ThinkingLevel;\n\t};\n\t/** The agent's construction-time prepare adapter, chained after compaction. */\n\tgetInitialPrepareNextTurn():\n\t\t| ((\n\t\t\t\tcontext: PrepareNextTurnContext,\n\t\t\t\tsignal?: AbortSignal,\n\t\t ) => Promise<AgentLoopTurnUpdate | undefined> | AgentLoopTurnUpdate | undefined)\n\t\t| undefined;\n\t/** Configured external context strategy name, if any. */\n\tgetContextStrategyName(): string | undefined;\n}\n\ninterface LifecycleFailureReport {\n\treport?: { failures?: readonly { error: unknown; pluginId: string; kind: string }[] };\n}\n\n/**\n * Default beforeToolCall link: the `tool.call@1` candidate dispatch with\n * identity/revision checks. Moved from the AgentSession tool-hook wiring.\n */\nfunction createDefaultBeforeToolCallLink(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): AgentLoopBeforeToolCallHookV1 {\n\treturn async ({ toolCallId, toolName, args, signal }) => {\n\t\t// v8 ignore next -- bootstrap lifecycle 恒定义全部生命周期事件,其 token 在 dispose 前恒活跃,提前返回不可达\n\t\tif (!runtime.hasLifecycleEvent(TOOL_CALL_EVENT_ID, TOOL_CALL_EVENT_VERSION)) return undefined;\n\t\tconst data: ToolCallEventDataV1 = {\n\t\t\tversion: 1,\n\t\t\tsessionId: wiring.getSessionId(),\n\t\t\trevision: wiring.getRevision(),\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tinput: detachedSessionSnapshot(args),\n\t\t};\n\t\ttry {\n\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\ttype: TOOL_CALL_EVENT_ID,\n\t\t\t\tversion: TOOL_CALL_EVENT_VERSION,\n\t\t\t\tphase: \"candidate\",\n\t\t\t\tdata,\n\t\t\t\tsource: \"agent-session\",\n\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\twiring.observeError(\n\t\t\t\t\tfailure.error,\n\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t`${TOOL_CALL_EVENT_ID}@${TOOL_CALL_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst transformed = delivery.data;\n\t\t\tconst revision = transformed.revision;\n\t\t\tif (\n\t\t\t\ttransformed.sessionId !== data.sessionId ||\n\t\t\t\ttransformed.toolCallId !== data.toolCallId ||\n\t\t\t\ttransformed.toolName !== data.toolName ||\n\t\t\t\trevision.version !== data.revision.version ||\n\t\t\t\trevision.sessionId !== data.revision.sessionId ||\n\t\t\t\trevision.sequence !== data.revision.sequence ||\n\t\t\t\trevision.leafId !== data.revision.leafId\n\t\t\t) {\n\t\t\t\tthrow new Error(t(\"tool.call transform cannot change call identity or revision\"));\n\t\t\t}\n\t\t\treturn { args: transformed.input };\n\t\t} catch (error) {\n\t\t\tconst report = (error as LifecycleFailureReport).report;\n\t\t\tif (report?.failures) {\n\t\t\t\tfor (const failure of report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_CALL_EVENT_ID}@${TOOL_CALL_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n\n/**\n * Default afterToolCall link: `tool.execute@1` committed, `tool.result.raw@1`\n * raw, the legacy `tool_result` extension hook (via wiring), image\n * normalization, and the `tool.result.transform@1` candidate dispatch — in the\n * exact order the previous single AgentSession hook used. Moved from the\n * AgentSession tool-hook wiring.\n */\nfunction createDefaultAfterToolCallLink(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): AgentLoopAfterToolCallHookV1 {\n\treturn async ({ toolCallId, toolName, args, result, isError, signal }) => {\n\t\tconst toolResult = result as {\n\t\t\tcontent?: (TextContent | ImageContent)[];\n\t\t\tdetails?: unknown;\n\t\t\tisError?: boolean;\n\t\t\tusage?: Usage;\n\t\t};\n\t\tif (runtime.hasLifecycleEvent(TOOL_EXECUTE_EVENT_ID, TOOL_EXECUTE_EVENT_VERSION)) {\n\t\t\ttry {\n\t\t\t\tconst data: ToolExecuteEventDataV1 = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tsessionId: wiring.getSessionId(),\n\t\t\t\t\trevision: wiring.getRevision(),\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\ttoolName,\n\t\t\t\t\tinput: detachedSessionSnapshot(args),\n\t\t\t\t\tisError,\n\t\t\t\t\tcontent: detachedSessionSnapshot(toolResult.content ?? []),\n\t\t\t\t};\n\t\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\t\ttype: TOOL_EXECUTE_EVENT_ID,\n\t\t\t\t\tversion: TOOL_EXECUTE_EVENT_VERSION,\n\t\t\t\t\tphase: \"committed\",\n\t\t\t\t\tdata,\n\t\t\t\t\tsource: \"agent-session\",\n\t\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\t});\n\t\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_EXECUTE_EVENT_ID}@${TOOL_EXECUTE_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst report = (error as LifecycleFailureReport).report;\n\t\t\t\tif (report?.failures) {\n\t\t\t\t\tfor (const failure of report.failures) {\n\t\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t\t`${TOOL_EXECUTE_EVENT_ID}@${TOOL_EXECUTE_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\terror,\n\t\t\t\t\t\t\"<capability-lifecycle>\",\n\t\t\t\t\t\t`${TOOL_EXECUTE_EVENT_ID}@${TOOL_EXECUTE_EVENT_VERSION}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (runtime.hasLifecycleEvent(TOOL_RESULT_RAW_EVENT_ID, TOOL_RESULT_RAW_EVENT_VERSION) && !signal?.aborted) {\n\t\t\ttry {\n\t\t\t\tconst data: ToolResultRawEventDataV1 = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tsessionId: wiring.getSessionId(),\n\t\t\t\t\trevision: wiring.getRevision(),\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\ttoolName,\n\t\t\t\t\tisError,\n\t\t\t\t\tcontent: detachedSessionSnapshot(toolResult.content ?? []),\n\t\t\t\t};\n\t\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\t\ttype: TOOL_RESULT_RAW_EVENT_ID,\n\t\t\t\t\tversion: TOOL_RESULT_RAW_EVENT_VERSION,\n\t\t\t\t\tphase: \"raw\",\n\t\t\t\t\tdata,\n\t\t\t\t\tsource: \"agent-session\",\n\t\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_RESULT_RAW_EVENT_ID}@${TOOL_RESULT_RAW_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (!signal?.aborted) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\terror,\n\t\t\t\t\t\t\"host\",\n\t\t\t\t\t\t`${TOOL_RESULT_RAW_EVENT_ID}@${TOOL_RESULT_RAW_EVENT_VERSION}/dispatch`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst content = toolResult.content ?? [];\n\t\t// Images are normalized before the transform dispatch so injected or\n\t\t// replaced images are normalized too.\n\t\tconst normalizedContent = await normalizeToolResultImages(content, {\n\t\t\tautoResizeImages: wiring.getImageAutoResize(),\n\t\t});\n\t\tconst legacyIsError = isError;\n\n\t\t// Standard tool.result.transform@1 candidate dispatch runs on the\n\t\t// normalized result candidate, after the legacy tool_result hook and\n\t\t// before the result is returned for session commit. Transform output is\n\t\t// schema-validated and identity-checked; failures propagate to the\n\t\t// agent loop's existing afterToolCall error isolation.\n\t\tlet finalContent: (typeof normalizedContent)[number][] = normalizedContent;\n\t\tlet finalIsError = legacyIsError;\n\t\tif (\n\t\t\truntime.hasLifecycleEvent(TOOL_RESULT_TRANSFORM_EVENT_ID, TOOL_RESULT_TRANSFORM_EVENT_VERSION) &&\n\t\t\t!signal?.aborted\n\t\t) {\n\t\t\tconst data: ToolResultTransformEventDataV1 = {\n\t\t\t\tversion: 1,\n\t\t\t\tsessionId: wiring.getSessionId(),\n\t\t\t\trevision: wiring.getRevision(),\n\t\t\t\ttoolCallId,\n\t\t\t\ttoolName,\n\t\t\t\tisError: legacyIsError,\n\t\t\t\tcontent: detachedSessionSnapshot(normalizedContent),\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\t\ttype: TOOL_RESULT_TRANSFORM_EVENT_ID,\n\t\t\t\t\tversion: TOOL_RESULT_TRANSFORM_EVENT_VERSION,\n\t\t\t\t\tphase: \"candidate\",\n\t\t\t\t\tdata,\n\t\t\t\t\tsource: \"agent-session\",\n\t\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_RESULT_TRANSFORM_EVENT_ID}@${TOOL_RESULT_TRANSFORM_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst transformed = delivery.data;\n\t\t\t\tconst revision = transformed.revision;\n\t\t\t\tif (\n\t\t\t\t\ttransformed.sessionId !== data.sessionId ||\n\t\t\t\t\ttransformed.toolCallId !== data.toolCallId ||\n\t\t\t\t\ttransformed.toolName !== data.toolName ||\n\t\t\t\t\trevision.version !== data.revision.version ||\n\t\t\t\t\trevision.sessionId !== data.revision.sessionId ||\n\t\t\t\t\trevision.sequence !== data.revision.sequence ||\n\t\t\t\t\trevision.leafId !== data.revision.leafId\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(t(\"tool.result.transform transform cannot change result identity or revision\"));\n\t\t\t\t}\n\t\t\t\tfinalContent = transformed.content as (typeof normalizedContent)[number][];\n\t\t\t\tfinalIsError = transformed.isError;\n\t\t\t} catch (error) {\n\t\t\t\tconst report = (error as LifecycleFailureReport).report;\n\t\t\t\tif (report?.failures) {\n\t\t\t\t\tfor (const failure of report.failures) {\n\t\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t\t`${TOOL_RESULT_TRANSFORM_EVENT_ID}@${TOOL_RESULT_TRANSFORM_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tif (finalContent === content && finalIsError === isError) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: finalContent,\n\t\t\tdetails: toolResult.details,\n\t\t\tisError: finalIsError,\n\t\t\tusage: toolResult.usage,\n\t\t};\n\t};\n}\n\n/**\n * Default transformContext link: the explicitly selected capability context\n * strategy. Moved from the AgentSession context-transform wiring (the legacy\n * chaining wrapper keeps composing it for the pre-chain path).\n */\nfunction createDefaultTransformContextLink(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): AgentLoopTransformContextHookV1 {\n\treturn async (messages, signal) => {\n\t\tconst strategyName = wiring.getContextStrategyName();\n\t\tif (!strategyName) return undefined;\n\t\treturn applyCapabilityContextStrategy(\n\t\t\tmessages as AgentMessage[],\n\t\t\truntime,\n\t\t\tstrategyName,\n\t\t\twiring.getSessionId(),\n\t\t\tsignal,\n\t\t);\n\t};\n}\n\n/**\n * Default prepareNextTurn link: compaction first, then the agent's\n * construction-time prepare adapter, then the system-prompt/tools/model/\n * thinking-level refresh. Moved from the AgentSession next-turn wiring.\n */\nfunction createDefaultPrepareNextTurnLink(wiring: AgentLoopWiringV1): AgentLoopPrepareNextTurnHookV1 {\n\treturn async (turn, signal) => {\n\t\tconst turnContext = turn as PrepareNextTurnContext;\n\t\tconst context = await wiring.compactBeforeNextAssistantResponse(turnContext.context, signal);\n\t\tconst previousSnapshot = await wiring.getInitialPrepareNextTurn()?.({ ...turnContext, context }, signal);\n\t\tconst nextContext = previousSnapshot?.context ?? context;\n\t\tconst refresh = wiring.getTurnRefresh();\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...nextContext,\n\t\t\t\tsystemPrompt: refresh.systemPrompt,\n\t\t\t\ttools: refresh.tools,\n\t\t\t},\n\t\t\tmodel: refresh.model,\n\t\t\tthinkingLevel: refresh.thinkingLevel,\n\t\t};\n\t};\n}\n\n/**\n * Install the default agent-loop executor as a first-party plugin. Default\n * links register first, so third-party links registered later chain after\n * them in registration order.\n */\nexport function installBootstrapAgentLoop(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_AGENT_LOOP_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-agent-loop>\",\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerLoopHook(\"beforeToolCall\", createDefaultBeforeToolCallLink(runtime, wiring));\n\t\t\tapi.registerLoopHook(\"afterToolCall\", createDefaultAfterToolCallLink(runtime, wiring));\n\t\t\tapi.registerLoopHook(\"transformContext\", createDefaultTransformContextLink(runtime, wiring));\n\t\t\tapi.registerLoopHook(\"prepareNextTurn\", createDefaultPrepareNextTurnLink(wiring));\n\t\t\t// The default repeated-tool-call guard rides the public loop-hook\n\t\t\t// chains like any other first-party link; disabling this plugin\n\t\t\t// removes both of its links. It answers with two levels (judgments\n\t\t\t// can be wrong, so an irreversible stop is never the first response):\n\t\t\t// - warn (third identical call): the shouldStopAfterTurn link votes\n\t\t\t// false and the transformContext link below injects a reminder into\n\t\t\t// the next request view (runLoop consumes transformContext after\n\t\t\t// shouldStopAfterTurn and before the next model call); the user-\n\t\t\t// facing warn notice is delivered through the public SessionAPI\n\t\t\t// sendMessage face (persisted custom_message entry with live\n\t\t\t// message_start/message_end rendering), plus a warn log through\n\t\t\t// the public LoggerAPI.\n\t\t\t// - stop (fifth identical call): the shouldStopAfterTurn link votes\n\t\t\t// true; the stop notice rides agent_end newMessages, sendMessage\n\t\t\t// persistence + rendering, and a warn log — all channels on.\n\t\t\t// Absent host features (session/logger) degrade to the remaining\n\t\t\t// channels instead of blocking the guard.\n\t\t\tconst loopGuard = createRepeatedToolCallStopPolicy({\n\t\t\t\tdeliverWarn: (notice) => {\n\t\t\t\t\tvoid api.session?.sendMessage?.(notice, { triggerTurn: false });\n\t\t\t\t},\n\t\t\t\tonWarn: (info) => {\n\t\t\t\t\tapi.logger?.warn(\"Loop guard warned the model\", {\n\t\t\t\t\t\ttool: info.toolName,\n\t\t\t\t\t\trepeats: info.warnThreshold,\n\t\t\t\t\t\targsSummary: info.argsSummary,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tdeliverNotice: (notice) => {\n\t\t\t\t\tvoid api.session?.sendMessage?.(notice, { triggerTurn: false });\n\t\t\t\t},\n\t\t\t\tonStop: (info) => {\n\t\t\t\t\tapi.logger?.warn(\"Loop guard stopped the turn\", {\n\t\t\t\t\t\ttool: info.toolName,\n\t\t\t\t\t\trepeats: info.stopThreshold,\n\t\t\t\t\t\targsSummary: info.argsSummary,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t});\n\t\t\tapi.registerLoopHook(\"shouldStopAfterTurn\", loopGuard.shouldStopAfterTurn);\n\t\t\t// Registered after the default context-strategy link, so the reminder\n\t\t\t// is appended to the final post-strategy request view (survives any\n\t\t\t// strategy pruning) at its tail.\n\t\t\tapi.registerLoopHook(\"transformContext\", loopGuard.transformContext);\n\t\t\t// The default continuation strategy reproduces the host's own\n\t\t\t// post-run decision byte for byte; a replacement strategy overrides\n\t\t\t// the continue/stop call through registerRunLoopStrategy.\n\t\t\tapi.registerRunLoopStrategy(DEFAULT_RUN_LOOP_STRATEGY_NAME, {\n\t\t\t\tdecideNextCycle: (request) => ({ continueLoop: request.hostWillContinue }),\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
1
+ {"version":3,"file":"bootstrap-agent-loop.js","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-agent-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAWH,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AACrC,OAAO,EAA+B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EACN,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,6BAA6B,EAC7B,8BAA8B,EAC9B,mCAAmC,GAKnC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAKN,uBAAuB,EACvB,+BAA+B,GAE/B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,8BAA8B,GAAG,kCAAkC,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,SAAS,CAAC;AA0CxD;;;GAGG;AACH,SAAS,+BAA+B,CACvC,OAA0B,EAC1B,MAAyB,EACO;IAChC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;QACxD,uIAAmF;QACnF,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,uBAAuB,CAAC;YAAE,OAAO,SAAS,CAAC;QAC9F,MAAM,IAAI,GAAwB;YACjC,OAAO,EAAE,CAAC;YACV,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE;YAChC,QAAQ,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,CAAC,eAAe,EAAE,8BAA8B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACvF,GAAG,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,iCAAiC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QAC7F,GAAG,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,gCAAgC,CAAC,MAAM,CAAC,CAAC,CAAC;QAClF,iFAAiD;QACjD,0FAAwD;QACxD,kEAA8C;QAC9C,qFAA+D;QAC/D,mGAAmC;QACnC,+DAAuB;IAN2D,CAOlF,CACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Default agent-loop bootstrap executor (W3; D-082 批 3 拆分登记).\n *\n * Registers the default main-loop event-dispatch links through the public\n * extension face so the default loop stays a replaceable first-party plugin:\n * the four default loop-hook links (capability lifecycle dispatch, image\n * normalization, context strategy, compaction + next-turn refresh).\n *\n * D-082 批 3 拆分事实:默认重复工具调用护栏(createRepeatedToolCallStopPolicy\n * 的 shouldStopAfterTurn 决策链 + transformContext 提醒注入链)与默认\n * run-loop strategy(decideNextCycle 直通)不消费 {@link AgentLoopWiringV1},\n * 已迁出为 `plugins/agent-loop-policy`(插件 id\n * `agent-forge.plugin.agent-loop-policy`),经 sdk 的 bundled 分发通道装配;\n * 禁用面为会话装配的 `disabledPluginIds`。本模块保留的四条链是宿主事件分发\n * 装配(与 bootstrap-lifecycle 同类的内核事件机制接线):它们消费 wiring 的\n * 会话闭包成员,无法经插件通道获得,故留宿主内嵌。\n *\n * The default links need session-bound host state (session id, revision,\n * correlation id, error observation, settings). That state is injected as\n * {@link AgentLoopWiringV1} — host wiring, not a plugin capability. Third-party\n * plugins register additional links through `api.registerLoopHook`; they run\n * after the default links in registration order (the bundled agent-loop-policy\n * plugin's guard/strategy links land in that same trailing region).\n */\n\nimport type {\n\tAgentContext,\n\tAgentLoopTurnUpdate,\n\tAgentMessage,\n\tAgentTool,\n\tPrepareNextTurnContext,\n\tThinkingLevel,\n} from \"@agent-forge/agent-core\";\nimport type { Api, ImageContent, Model, TextContent, Usage } from \"@agent-forge/ai/compat\";\nimport { normalizeToolResultImages } from \"../../utils/tool-result-images.ts\";\nimport { t } from \"../i18n/index.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { applyCapabilityContextStrategy } from \"./context-strategy-binding.ts\";\nimport {\n\tTOOL_CALL_EVENT_ID,\n\tTOOL_CALL_EVENT_VERSION,\n\tTOOL_EXECUTE_EVENT_ID,\n\tTOOL_EXECUTE_EVENT_VERSION,\n\tTOOL_RESULT_RAW_EVENT_ID,\n\tTOOL_RESULT_RAW_EVENT_VERSION,\n\tTOOL_RESULT_TRANSFORM_EVENT_ID,\n\tTOOL_RESULT_TRANSFORM_EVENT_VERSION,\n\ttype ToolCallEventDataV1,\n\ttype ToolExecuteEventDataV1,\n\ttype ToolResultRawEventDataV1,\n\ttype ToolResultTransformEventDataV1,\n} from \"./lifecycle-catalog.ts\";\nimport {\n\ttype AgentLoopAfterToolCallHookV1,\n\ttype AgentLoopBeforeToolCallHookV1,\n\ttype AgentLoopPrepareNextTurnHookV1,\n\ttype AgentLoopTransformContextHookV1,\n\tdetachedSessionSnapshot,\n\tEXPERIMENTAL_PUBLIC_API_VERSION,\n\ttype SessionRevisionV1,\n} from \"./public-api.ts\";\n\nexport const BOOTSTRAP_AGENT_LOOP_PLUGIN_ID = \"agent-forge.bootstrap-agent-loop\";\n\n/**\n * 默认 run-loop strategy 名(宿主会话配置缺省名,D-082 批 3)。策略实现本体已\n * 迁出为 `plugins/agent-loop-policy`(其 `DEFAULT_RUN_LOOP_STRATEGY_NAME` 与本\n * 值逐字相同,两侧测试各自钉值);宿主保留该名字用于 `runLoopStrategyName`\n * 缺省解析——策略缺席时宿主回退自身的延续候选(行为不变),存在时经\n * `runtime.decideRunLoop` 咨询。\n */\nexport const DEFAULT_RUN_LOOP_STRATEGY_NAME = \"default\";\n\n/**\n * Session-bound host state the default loop links read at execution time.\n * Host wiring injected into the bootstrap executor; not part of the plugin\n * capability surface.\n */\nexport interface AgentLoopWiringV1 {\n\t/** Canonical session id for lifecycle payloads. */\n\tgetSessionId(): string;\n\t/** Detached revision snapshot captured at payload build time. */\n\tgetRevision(): SessionRevisionV1;\n\t/** Correlation id of the current prompt run, if any. */\n\tgetTurnCorrelationId(): string | undefined;\n\t/** Non-fatal delivery error sink (same surface as session-level observation). */\n\tobserveError(error: unknown, extensionPath: string, event: string): void;\n\t/** Image auto-resize setting for tool-result normalization. */\n\tgetImageAutoResize(): boolean;\n\t/** Compaction hook chained first inside the default prepareNextTurn link. */\n\tcompactBeforeNextAssistantResponse(context: AgentContext, signal?: AbortSignal): Promise<AgentContext>;\n\t/** Next-turn refresh snapshot applied last inside the default prepareNextTurn link. */\n\tgetTurnRefresh(): {\n\t\tsystemPrompt: string;\n\t\ttools: AgentTool[];\n\t\tmodel: Model<Api>;\n\t\tthinkingLevel: ThinkingLevel;\n\t};\n\t/** The agent's construction-time prepare adapter, chained after compaction. */\n\tgetInitialPrepareNextTurn():\n\t\t| ((\n\t\t\t\tcontext: PrepareNextTurnContext,\n\t\t\t\tsignal?: AbortSignal,\n\t\t ) => Promise<AgentLoopTurnUpdate | undefined> | AgentLoopTurnUpdate | undefined)\n\t\t| undefined;\n\t/** Configured external context strategy name, if any. */\n\tgetContextStrategyName(): string | undefined;\n}\n\ninterface LifecycleFailureReport {\n\treport?: { failures?: readonly { error: unknown; pluginId: string; kind: string }[] };\n}\n\n/**\n * Default beforeToolCall link: the `tool.call@1` candidate dispatch with\n * identity/revision checks. Moved from the AgentSession tool-hook wiring.\n */\nfunction createDefaultBeforeToolCallLink(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): AgentLoopBeforeToolCallHookV1 {\n\treturn async ({ toolCallId, toolName, args, signal }) => {\n\t\t// v8 ignore next -- bootstrap lifecycle 恒定义全部生命周期事件,其 token 在 dispose 前恒活跃,提前返回不可达\n\t\tif (!runtime.hasLifecycleEvent(TOOL_CALL_EVENT_ID, TOOL_CALL_EVENT_VERSION)) return undefined;\n\t\tconst data: ToolCallEventDataV1 = {\n\t\t\tversion: 1,\n\t\t\tsessionId: wiring.getSessionId(),\n\t\t\trevision: wiring.getRevision(),\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tinput: detachedSessionSnapshot(args),\n\t\t};\n\t\ttry {\n\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\ttype: TOOL_CALL_EVENT_ID,\n\t\t\t\tversion: TOOL_CALL_EVENT_VERSION,\n\t\t\t\tphase: \"candidate\",\n\t\t\t\tdata,\n\t\t\t\tsource: \"agent-session\",\n\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\twiring.observeError(\n\t\t\t\t\tfailure.error,\n\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t`${TOOL_CALL_EVENT_ID}@${TOOL_CALL_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst transformed = delivery.data;\n\t\t\tconst revision = transformed.revision;\n\t\t\tif (\n\t\t\t\ttransformed.sessionId !== data.sessionId ||\n\t\t\t\ttransformed.toolCallId !== data.toolCallId ||\n\t\t\t\ttransformed.toolName !== data.toolName ||\n\t\t\t\trevision.version !== data.revision.version ||\n\t\t\t\trevision.sessionId !== data.revision.sessionId ||\n\t\t\t\trevision.sequence !== data.revision.sequence ||\n\t\t\t\trevision.leafId !== data.revision.leafId\n\t\t\t) {\n\t\t\t\tthrow new Error(t(\"tool.call transform cannot change call identity or revision\"));\n\t\t\t}\n\t\t\treturn { args: transformed.input };\n\t\t} catch (error) {\n\t\t\tconst report = (error as LifecycleFailureReport).report;\n\t\t\tif (report?.failures) {\n\t\t\t\tfor (const failure of report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_CALL_EVENT_ID}@${TOOL_CALL_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n\n/**\n * Default afterToolCall link: `tool.execute@1` committed, `tool.result.raw@1`\n * raw, the legacy `tool_result` extension hook (via wiring), image\n * normalization, and the `tool.result.transform@1` candidate dispatch — in the\n * exact order the previous single AgentSession hook used. Moved from the\n * AgentSession tool-hook wiring.\n */\nfunction createDefaultAfterToolCallLink(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): AgentLoopAfterToolCallHookV1 {\n\treturn async ({ toolCallId, toolName, args, result, isError, signal }) => {\n\t\tconst toolResult = result as {\n\t\t\tcontent?: (TextContent | ImageContent)[];\n\t\t\tdetails?: unknown;\n\t\t\tisError?: boolean;\n\t\t\tusage?: Usage;\n\t\t};\n\t\tif (runtime.hasLifecycleEvent(TOOL_EXECUTE_EVENT_ID, TOOL_EXECUTE_EVENT_VERSION)) {\n\t\t\ttry {\n\t\t\t\tconst data: ToolExecuteEventDataV1 = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tsessionId: wiring.getSessionId(),\n\t\t\t\t\trevision: wiring.getRevision(),\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\ttoolName,\n\t\t\t\t\tinput: detachedSessionSnapshot(args),\n\t\t\t\t\tisError,\n\t\t\t\t\tcontent: detachedSessionSnapshot(toolResult.content ?? []),\n\t\t\t\t};\n\t\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\t\ttype: TOOL_EXECUTE_EVENT_ID,\n\t\t\t\t\tversion: TOOL_EXECUTE_EVENT_VERSION,\n\t\t\t\t\tphase: \"committed\",\n\t\t\t\t\tdata,\n\t\t\t\t\tsource: \"agent-session\",\n\t\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\t});\n\t\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_EXECUTE_EVENT_ID}@${TOOL_EXECUTE_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconst report = (error as LifecycleFailureReport).report;\n\t\t\t\tif (report?.failures) {\n\t\t\t\t\tfor (const failure of report.failures) {\n\t\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t\t`${TOOL_EXECUTE_EVENT_ID}@${TOOL_EXECUTE_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\terror,\n\t\t\t\t\t\t\"<capability-lifecycle>\",\n\t\t\t\t\t\t`${TOOL_EXECUTE_EVENT_ID}@${TOOL_EXECUTE_EVENT_VERSION}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (runtime.hasLifecycleEvent(TOOL_RESULT_RAW_EVENT_ID, TOOL_RESULT_RAW_EVENT_VERSION) && !signal?.aborted) {\n\t\t\ttry {\n\t\t\t\tconst data: ToolResultRawEventDataV1 = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tsessionId: wiring.getSessionId(),\n\t\t\t\t\trevision: wiring.getRevision(),\n\t\t\t\t\ttoolCallId,\n\t\t\t\t\ttoolName,\n\t\t\t\t\tisError,\n\t\t\t\t\tcontent: detachedSessionSnapshot(toolResult.content ?? []),\n\t\t\t\t};\n\t\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\t\ttype: TOOL_RESULT_RAW_EVENT_ID,\n\t\t\t\t\tversion: TOOL_RESULT_RAW_EVENT_VERSION,\n\t\t\t\t\tphase: \"raw\",\n\t\t\t\t\tdata,\n\t\t\t\t\tsource: \"agent-session\",\n\t\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_RESULT_RAW_EVENT_ID}@${TOOL_RESULT_RAW_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (!signal?.aborted) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\terror,\n\t\t\t\t\t\t\"host\",\n\t\t\t\t\t\t`${TOOL_RESULT_RAW_EVENT_ID}@${TOOL_RESULT_RAW_EVENT_VERSION}/dispatch`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst content = toolResult.content ?? [];\n\t\t// Images are normalized before the transform dispatch so injected or\n\t\t// replaced images are normalized too.\n\t\tconst normalizedContent = await normalizeToolResultImages(content, {\n\t\t\tautoResizeImages: wiring.getImageAutoResize(),\n\t\t});\n\t\tconst legacyIsError = isError;\n\n\t\t// Standard tool.result.transform@1 candidate dispatch runs on the\n\t\t// normalized result candidate, after the legacy tool_result hook and\n\t\t// before the result is returned for session commit. Transform output is\n\t\t// schema-validated and identity-checked; failures propagate to the\n\t\t// agent loop's existing afterToolCall error isolation.\n\t\tlet finalContent: (typeof normalizedContent)[number][] = normalizedContent;\n\t\tlet finalIsError = legacyIsError;\n\t\tif (\n\t\t\truntime.hasLifecycleEvent(TOOL_RESULT_TRANSFORM_EVENT_ID, TOOL_RESULT_TRANSFORM_EVENT_VERSION) &&\n\t\t\t!signal?.aborted\n\t\t) {\n\t\t\tconst data: ToolResultTransformEventDataV1 = {\n\t\t\t\tversion: 1,\n\t\t\t\tsessionId: wiring.getSessionId(),\n\t\t\t\trevision: wiring.getRevision(),\n\t\t\t\ttoolCallId,\n\t\t\t\ttoolName,\n\t\t\t\tisError: legacyIsError,\n\t\t\t\tcontent: detachedSessionSnapshot(normalizedContent),\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tconst delivery = await runtime.dispatchLifecycle({\n\t\t\t\t\ttype: TOOL_RESULT_TRANSFORM_EVENT_ID,\n\t\t\t\t\tversion: TOOL_RESULT_TRANSFORM_EVENT_VERSION,\n\t\t\t\t\tphase: \"candidate\",\n\t\t\t\t\tdata,\n\t\t\t\t\tsource: \"agent-session\",\n\t\t\t\t\tcorrelationId: wiring.getTurnCorrelationId(),\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\tfor (const failure of delivery.report.failures) {\n\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t`${TOOL_RESULT_TRANSFORM_EVENT_ID}@${TOOL_RESULT_TRANSFORM_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst transformed = delivery.data;\n\t\t\t\tconst revision = transformed.revision;\n\t\t\t\tif (\n\t\t\t\t\ttransformed.sessionId !== data.sessionId ||\n\t\t\t\t\ttransformed.toolCallId !== data.toolCallId ||\n\t\t\t\t\ttransformed.toolName !== data.toolName ||\n\t\t\t\t\trevision.version !== data.revision.version ||\n\t\t\t\t\trevision.sessionId !== data.revision.sessionId ||\n\t\t\t\t\trevision.sequence !== data.revision.sequence ||\n\t\t\t\t\trevision.leafId !== data.revision.leafId\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(t(\"tool.result.transform transform cannot change result identity or revision\"));\n\t\t\t\t}\n\t\t\t\tfinalContent = transformed.content as (typeof normalizedContent)[number][];\n\t\t\t\tfinalIsError = transformed.isError;\n\t\t\t} catch (error) {\n\t\t\t\tconst report = (error as LifecycleFailureReport).report;\n\t\t\t\tif (report?.failures) {\n\t\t\t\t\tfor (const failure of report.failures) {\n\t\t\t\t\t\twiring.observeError(\n\t\t\t\t\t\t\tfailure.error,\n\t\t\t\t\t\t\tfailure.pluginId,\n\t\t\t\t\t\t\t`${TOOL_RESULT_TRANSFORM_EVENT_ID}@${TOOL_RESULT_TRANSFORM_EVENT_VERSION}/${failure.kind}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tif (finalContent === content && finalIsError === isError) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: finalContent,\n\t\t\tdetails: toolResult.details,\n\t\t\tisError: finalIsError,\n\t\t\tusage: toolResult.usage,\n\t\t};\n\t};\n}\n\n/**\n * Default transformContext link: the explicitly selected capability context\n * strategy. Moved from the AgentSession context-transform wiring (the legacy\n * chaining wrapper keeps composing it for the pre-chain path).\n */\nfunction createDefaultTransformContextLink(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): AgentLoopTransformContextHookV1 {\n\treturn async (messages, signal) => {\n\t\tconst strategyName = wiring.getContextStrategyName();\n\t\tif (!strategyName) return undefined;\n\t\treturn applyCapabilityContextStrategy(\n\t\t\tmessages as AgentMessage[],\n\t\t\truntime,\n\t\t\tstrategyName,\n\t\t\twiring.getSessionId(),\n\t\t\tsignal,\n\t\t);\n\t};\n}\n\n/**\n * Default prepareNextTurn link: compaction first, then the agent's\n * construction-time prepare adapter, then the system-prompt/tools/model/\n * thinking-level refresh. Moved from the AgentSession next-turn wiring.\n */\nfunction createDefaultPrepareNextTurnLink(wiring: AgentLoopWiringV1): AgentLoopPrepareNextTurnHookV1 {\n\treturn async (turn, signal) => {\n\t\tconst turnContext = turn as PrepareNextTurnContext;\n\t\tconst context = await wiring.compactBeforeNextAssistantResponse(turnContext.context, signal);\n\t\tconst previousSnapshot = await wiring.getInitialPrepareNextTurn()?.({ ...turnContext, context }, signal);\n\t\tconst nextContext = previousSnapshot?.context ?? context;\n\t\tconst refresh = wiring.getTurnRefresh();\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...nextContext,\n\t\t\t\tsystemPrompt: refresh.systemPrompt,\n\t\t\t\ttools: refresh.tools,\n\t\t\t},\n\t\t\tmodel: refresh.model,\n\t\t\tthinkingLevel: refresh.thinkingLevel,\n\t\t};\n\t};\n}\n\n/**\n * Install the default agent-loop executor as a first-party plugin. Default\n * links register first, so third-party links registered later chain after\n * them in registration order.\n */\nexport function installBootstrapAgentLoop(\n\truntime: CapabilityRuntime,\n\twiring: AgentLoopWiringV1,\n): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_AGENT_LOOP_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-agent-loop>\",\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerLoopHook(\"beforeToolCall\", createDefaultBeforeToolCallLink(runtime, wiring));\n\t\t\tapi.registerLoopHook(\"afterToolCall\", createDefaultAfterToolCallLink(runtime, wiring));\n\t\t\tapi.registerLoopHook(\"transformContext\", createDefaultTransformContextLink(runtime, wiring));\n\t\t\tapi.registerLoopHook(\"prepareNextTurn\", createDefaultPrepareNextTurnLink(wiring));\n\t\t\t// D-082 批 3:默认重复工具调用护栏(shouldStopAfterTurn 决策链 +\n\t\t\t// transformContext 提醒注入链)与默认 run-loop strategy 不再在此注册——\n\t\t\t// 它们不消费 wiring,已迁出为 plugins/agent-loop-policy\n\t\t\t// (agent-forge.plugin.agent-loop-policy),经 sdk bundled 分发通道装配;\n\t\t\t// 其链接在本执行器之后注册,落链顺序与内嵌时代一致(护栏注入链仍在\n\t\t\t// 默认上下文策略链之后、第三方链接之前)。\n\t\t},\n\t);\n}\n"]}
@@ -260,9 +260,11 @@ export interface CapabilityRuntime {
260
260
  /**
261
261
  * Ordered stream-function wrappers registered through the public
262
262
  * `registerStreamFnWrapper` face (provider-failover family), filtered by
263
- * active owners, in registration order (first registered = outermost).
264
- * The host's default stream assembly composes them around its own stream
265
- * call at request time.
263
+ * active owners, sorted by (priority ascending, registration order
264
+ * ascending) — lower priority wraps outermost; equal priorities keep
265
+ * registration order (first registered = outermost), the pre-priority
266
+ * semantics (contract A, D-082 批 3b). The host's default stream assembly
267
+ * composes them around its own stream call at request time.
266
268
  */
267
269
  getStreamFnWrappers(): readonly StreamFnWrapper[];
268
270
  getOperationStatus(id: string): OperationStatus | undefined;