qlogicagent 2.13.4 → 2.13.5

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 (1261) hide show
  1. package/dist/agent/agent.d.ts +48 -0
  2. package/dist/agent/agent.js +197 -0
  3. package/dist/agent/memory-recall-context.d.ts +18 -0
  4. package/dist/agent/memory-recall-context.js +139 -0
  5. package/dist/agent/memory-recall-context.test.d.ts +1 -0
  6. package/dist/agent/memory-recall-context.test.js +58 -0
  7. package/dist/agent/memory-recall-injection.d.ts +34 -0
  8. package/dist/agent/memory-recall-injection.js +66 -0
  9. package/dist/agent/runtime-vars.d.ts +48 -0
  10. package/dist/agent/runtime-vars.js +54 -0
  11. package/dist/agent/tool-access.d.ts +1 -0
  12. package/dist/agent/tool-access.js +1 -0
  13. package/dist/agent/tool-loop/artifact-events.d.ts +17 -0
  14. package/dist/agent/tool-loop/artifact-events.js +75 -0
  15. package/dist/agent/tool-loop/budget-continuation-policy.d.ts +22 -0
  16. package/dist/agent/tool-loop/budget-continuation-policy.js +44 -0
  17. package/dist/agent/tool-loop/completion-action-policy.d.ts +19 -0
  18. package/dist/agent/tool-loop/completion-action-policy.js +68 -0
  19. package/dist/agent/tool-loop/completion-action-policy.test.d.ts +1 -0
  20. package/dist/agent/tool-loop/completion-action-policy.test.js +77 -0
  21. package/dist/agent/tool-loop/completion-stop-policy.d.ts +19 -0
  22. package/dist/agent/tool-loop/completion-stop-policy.js +31 -0
  23. package/dist/agent/tool-loop/compression-pipeline.d.ts +44 -0
  24. package/dist/agent/tool-loop/compression-pipeline.js +68 -0
  25. package/dist/agent/tool-loop/loop-helpers.d.ts +15 -0
  26. package/dist/agent/tool-loop/loop-helpers.js +86 -0
  27. package/dist/agent/tool-loop/recovery-helpers.d.ts +18 -0
  28. package/dist/agent/tool-loop/recovery-helpers.js +42 -0
  29. package/dist/agent/tool-loop/single-round.d.ts +2 -0
  30. package/dist/agent/tool-loop/single-round.js +43 -0
  31. package/dist/agent/tool-loop/skill-instruction-policy.d.ts +7 -0
  32. package/dist/agent/tool-loop/skill-instruction-policy.js +18 -0
  33. package/dist/agent/tool-loop/stream-error-recovery.d.ts +59 -0
  34. package/dist/agent/tool-loop/stream-error-recovery.js +93 -0
  35. package/dist/agent/tool-loop/tool-failure-policy.d.ts +22 -0
  36. package/dist/agent/tool-loop/tool-failure-policy.js +46 -0
  37. package/dist/agent/tool-loop/tool-result-events.d.ts +11 -0
  38. package/dist/agent/tool-loop/tool-result-events.js +59 -0
  39. package/dist/agent/tool-loop/tool-result-events.test.d.ts +1 -0
  40. package/dist/agent/tool-loop/tool-result-events.test.js +30 -0
  41. package/dist/agent/tool-loop.contract.test.d.ts +1 -0
  42. package/dist/agent/tool-loop.contract.test.js +254 -0
  43. package/dist/agent/tool-loop.d.ts +121 -0
  44. package/dist/agent/tool-loop.js +1017 -0
  45. package/dist/agent/tool-loop.policy-architecture.test.d.ts +1 -0
  46. package/dist/agent/tool-loop.policy-architecture.test.js +21 -0
  47. package/dist/agent/tool-loop.states.test.d.ts +1 -0
  48. package/dist/agent/tool-loop.states.test.js +211 -0
  49. package/dist/agent/tunable-defaults.d.ts +1 -0
  50. package/dist/agent/tunable-defaults.js +1 -0
  51. package/dist/agent/types.d.ts +311 -0
  52. package/dist/agent/types.js +8 -0
  53. package/dist/cli/acp-commands.d.ts +32 -0
  54. package/dist/cli/acp-commands.js +145 -0
  55. package/dist/cli/acp-commands.test.d.ts +1 -0
  56. package/dist/cli/acp-commands.test.js +89 -0
  57. package/dist/cli/acp-extended-handlers.d.ts +69 -0
  58. package/dist/cli/acp-extended-handlers.js +484 -0
  59. package/dist/cli/acp-extended-handlers.product-confirm.test.d.ts +1 -0
  60. package/dist/cli/acp-extended-handlers.product-confirm.test.js +56 -0
  61. package/dist/cli/acp-extended-handlers.product-project.test.d.ts +1 -0
  62. package/dist/cli/acp-extended-handlers.product-project.test.js +66 -0
  63. package/dist/cli/acp-extended-handlers.solo-project.test.d.ts +1 -0
  64. package/dist/cli/acp-extended-handlers.solo-project.test.js +51 -0
  65. package/dist/cli/acp-extended-handlers.specchat.test.d.ts +1 -0
  66. package/dist/cli/acp-extended-handlers.specchat.test.js +62 -0
  67. package/dist/cli/acp-extended-handlers.workflowchat.test.d.ts +1 -0
  68. package/dist/cli/acp-extended-handlers.workflowchat.test.js +49 -0
  69. package/dist/cli/acp-extended-host-adapter.d.ts +29 -0
  70. package/dist/cli/acp-extended-host-adapter.js +40 -0
  71. package/dist/cli/acp-extended-host-adapter.test.d.ts +1 -0
  72. package/dist/cli/acp-extended-host-adapter.test.js +63 -0
  73. package/dist/cli/acp-message-router.d.ts +8 -0
  74. package/dist/cli/acp-message-router.js +40 -0
  75. package/dist/cli/acp-message-router.test.d.ts +1 -0
  76. package/dist/cli/acp-message-router.test.js +30 -0
  77. package/dist/cli/acp-session-handlers.d.ts +41 -0
  78. package/dist/cli/acp-session-handlers.js +304 -0
  79. package/dist/cli/acp-session-handlers.test.d.ts +1 -0
  80. package/dist/cli/acp-session-handlers.test.js +346 -0
  81. package/dist/cli/acp-session-host.d.ts +48 -0
  82. package/dist/cli/acp-session-host.js +1 -0
  83. package/dist/cli/agent-config-coordinator.d.ts +16 -0
  84. package/dist/cli/agent-config-coordinator.js +56 -0
  85. package/dist/cli/agent-config-coordinator.test.d.ts +1 -0
  86. package/dist/cli/agent-config-coordinator.test.js +51 -0
  87. package/dist/cli/agent-config-runtime.d.ts +11 -0
  88. package/dist/cli/agent-config-runtime.js +4 -0
  89. package/dist/cli/agent-runner-factory.d.ts +2 -0
  90. package/dist/cli/agent-runner-factory.js +11 -0
  91. package/dist/cli/agent-runtime-bootstrap.d.ts +67 -0
  92. package/dist/cli/agent-runtime-bootstrap.js +104 -0
  93. package/dist/cli/agent-runtime-ports-adapter.d.ts +2 -0
  94. package/dist/cli/agent-runtime-ports-adapter.js +22 -0
  95. package/dist/cli/agent-runtime-session-state.d.ts +24 -0
  96. package/dist/cli/agent-runtime-session-state.js +51 -0
  97. package/dist/cli/agent-status-notifier.d.ts +11 -0
  98. package/dist/cli/agent-status-notifier.js +26 -0
  99. package/dist/cli/agent-status-notifier.test.d.ts +1 -0
  100. package/dist/cli/agent-status-notifier.test.js +33 -0
  101. package/dist/cli/base-tool-bootstrap.d.ts +16 -0
  102. package/dist/cli/base-tool-bootstrap.js +20 -0
  103. package/dist/cli/cli-acp-request-handler.d.ts +11 -0
  104. package/dist/cli/cli-acp-request-handler.js +61 -0
  105. package/dist/cli/cli-acp-request-handler.test.d.ts +1 -0
  106. package/dist/cli/cli-acp-request-handler.test.js +58 -0
  107. package/dist/cli/cli-agent-builder.d.ts +35 -0
  108. package/dist/cli/cli-agent-builder.js +33 -0
  109. package/dist/cli/community-resource-installer.d.ts +30 -0
  110. package/dist/cli/community-resource-installer.js +66 -0
  111. package/dist/cli/community-resource-installer.test.d.ts +1 -0
  112. package/dist/cli/community-resource-installer.test.js +175 -0
  113. package/dist/cli/community-skill-installer.d.ts +12 -0
  114. package/dist/cli/community-skill-installer.js +220 -0
  115. package/dist/cli/community-skill-installer.test.d.ts +1 -0
  116. package/dist/cli/community-skill-installer.test.js +179 -0
  117. package/dist/cli/community-workflow-installer.d.ts +29 -0
  118. package/dist/cli/community-workflow-installer.js +69 -0
  119. package/dist/cli/conversation-context.d.ts +30 -0
  120. package/dist/cli/conversation-context.js +69 -0
  121. package/dist/cli/conversation-context.test.d.ts +1 -0
  122. package/dist/cli/conversation-context.test.js +61 -0
  123. package/dist/cli/core-tool-coordinator.d.ts +41 -0
  124. package/dist/cli/core-tool-coordinator.js +55 -0
  125. package/dist/cli/core-tools/agent-tool-bootstrap.d.ts +12 -0
  126. package/dist/cli/core-tools/agent-tool-bootstrap.js +5 -0
  127. package/dist/cli/core-tools/agent-tool-service.background.test.d.ts +1 -0
  128. package/dist/cli/core-tools/agent-tool-service.background.test.js +212 -0
  129. package/dist/cli/core-tools/agent-tool-service.d.ts +36 -0
  130. package/dist/cli/core-tools/agent-tool-service.js +152 -0
  131. package/dist/cli/core-tools/checkpoint-tool-bootstrap.d.ts +9 -0
  132. package/dist/cli/core-tools/checkpoint-tool-bootstrap.js +8 -0
  133. package/dist/cli/core-tools/checkpoint-tool-service.d.ts +7 -0
  134. package/dist/cli/core-tools/checkpoint-tool-service.js +5 -0
  135. package/dist/cli/core-tools/config-tool-bootstrap.d.ts +5 -0
  136. package/dist/cli/core-tools/config-tool-bootstrap.js +5 -0
  137. package/dist/cli/core-tools/config-tool-service.d.ts +11 -0
  138. package/dist/cli/core-tools/config-tool-service.js +86 -0
  139. package/dist/cli/core-tools/config-tool-service.test.d.ts +1 -0
  140. package/dist/cli/core-tools/config-tool-service.test.js +69 -0
  141. package/dist/cli/core-tools/cron-tool-bootstrap.d.ts +8 -0
  142. package/dist/cli/core-tools/cron-tool-bootstrap.js +8 -0
  143. package/dist/cli/core-tools/cron-workflow-service.d.ts +7 -0
  144. package/dist/cli/core-tools/cron-workflow-service.js +206 -0
  145. package/dist/cli/core-tools/cron-workflow-service.test.d.ts +1 -0
  146. package/dist/cli/core-tools/cron-workflow-service.test.js +78 -0
  147. package/dist/cli/core-tools/fork-system-prompt.d.ts +45 -0
  148. package/dist/cli/core-tools/fork-system-prompt.js +66 -0
  149. package/dist/cli/core-tools/fork-system-prompt.test.d.ts +1 -0
  150. package/dist/cli/core-tools/fork-system-prompt.test.js +77 -0
  151. package/dist/cli/core-tools/monitor-tool-bootstrap.d.ts +7 -0
  152. package/dist/cli/core-tools/monitor-tool-bootstrap.js +8 -0
  153. package/dist/cli/core-tools/monitor-tool-service.d.ts +6 -0
  154. package/dist/cli/core-tools/monitor-tool-service.js +74 -0
  155. package/dist/cli/core-tools/registry.d.ts +8 -0
  156. package/dist/cli/core-tools/registry.js +60 -0
  157. package/dist/cli/core-tools/session-tool-manifest.d.ts +12 -0
  158. package/dist/cli/core-tools/session-tool-manifest.js +19 -0
  159. package/dist/cli/core-tools/team-registry.d.ts +62 -0
  160. package/dist/cli/core-tools/team-registry.js +85 -0
  161. package/dist/cli/core-tools/team-registry.test.d.ts +1 -0
  162. package/dist/cli/core-tools/team-registry.test.js +79 -0
  163. package/dist/cli/core-tools/team-tool-bootstrap.d.ts +11 -0
  164. package/dist/cli/core-tools/team-tool-bootstrap.js +8 -0
  165. package/dist/cli/core-tools/team-tool-service.d.ts +43 -0
  166. package/dist/cli/core-tools/team-tool-service.js +326 -0
  167. package/dist/cli/core-tools/team-tool-service.test.d.ts +1 -0
  168. package/dist/cli/core-tools/team-tool-service.test.js +48 -0
  169. package/dist/cli/credential-vault.d.ts +62 -0
  170. package/dist/cli/credential-vault.js +190 -0
  171. package/dist/cli/credential-vault.test.d.ts +6 -0
  172. package/dist/cli/credential-vault.test.js +130 -0
  173. package/dist/cli/default-project-bootstrap.d.ts +8 -0
  174. package/dist/cli/default-project-bootstrap.js +39 -0
  175. package/dist/cli/dev-tool-bootstrap.d.ts +8 -0
  176. package/dist/cli/dev-tool-bootstrap.js +19 -0
  177. package/dist/cli/dev-tools/dev-tool-bootstrap-service.d.ts +6 -0
  178. package/dist/cli/dev-tools/dev-tool-bootstrap-service.js +6 -0
  179. package/dist/cli/dev-tools/dev-tool-registry.d.ts +6 -0
  180. package/dist/cli/dev-tools/dev-tool-registry.js +7 -0
  181. package/dist/cli/dev-tools/lsp-tool-service.d.ts +5 -0
  182. package/dist/cli/dev-tools/lsp-tool-service.js +30 -0
  183. package/dist/cli/dev-tools/lsp-tool-service.test.d.ts +1 -0
  184. package/dist/cli/dev-tools/lsp-tool-service.test.js +14 -0
  185. package/dist/cli/dream-host-adapter.d.ts +23 -0
  186. package/dist/cli/dream-host-adapter.js +33 -0
  187. package/dist/cli/gateway-rpc-connection.d.ts +50 -0
  188. package/dist/cli/gateway-rpc-connection.js +133 -0
  189. package/dist/cli/handlers/agents-handler.d.ts +51 -0
  190. package/dist/cli/handlers/agents-handler.js +769 -0
  191. package/dist/cli/handlers/community-handler.d.ts +39 -0
  192. package/dist/cli/handlers/community-handler.js +671 -0
  193. package/dist/cli/handlers/community-handler.test.d.ts +1 -0
  194. package/dist/cli/handlers/community-handler.test.js +1602 -0
  195. package/dist/cli/handlers/config-handler.d.ts +28 -0
  196. package/dist/cli/handlers/config-handler.js +438 -0
  197. package/dist/cli/handlers/config-handler.test.d.ts +1 -0
  198. package/dist/cli/handlers/config-handler.test.js +140 -0
  199. package/dist/cli/handlers/config-handler.tools-list.test.d.ts +1 -0
  200. package/dist/cli/handlers/config-handler.tools-list.test.js +93 -0
  201. package/dist/cli/handlers/control-handler.d.ts +23 -0
  202. package/dist/cli/handlers/control-handler.js +88 -0
  203. package/dist/cli/handlers/dream-handler.d.ts +31 -0
  204. package/dist/cli/handlers/dream-handler.js +235 -0
  205. package/dist/cli/handlers/files-handler.d.ts +22 -0
  206. package/dist/cli/handlers/files-handler.instructions.test.d.ts +1 -0
  207. package/dist/cli/handlers/files-handler.instructions.test.js +127 -0
  208. package/dist/cli/handlers/files-handler.js +593 -0
  209. package/dist/cli/handlers/media-handler.d.ts +19 -0
  210. package/dist/cli/handlers/media-handler.js +212 -0
  211. package/dist/cli/handlers/media-handler.test.d.ts +1 -0
  212. package/dist/cli/handlers/media-handler.test.js +107 -0
  213. package/dist/cli/handlers/memory-handler.d.ts +61 -0
  214. package/dist/cli/handlers/memory-handler.js +792 -0
  215. package/dist/cli/handlers/pet-confirm-handler.d.ts +7 -0
  216. package/dist/cli/handlers/pet-confirm-handler.js +6 -0
  217. package/dist/cli/handlers/pet-handler.d.ts +47 -0
  218. package/dist/cli/handlers/pet-handler.js +455 -0
  219. package/dist/cli/handlers/pet-handler.test.d.ts +1 -0
  220. package/dist/cli/handlers/pet-handler.test.js +620 -0
  221. package/dist/cli/handlers/product-handler.d.ts +37 -0
  222. package/dist/cli/handlers/product-handler.js +393 -0
  223. package/dist/cli/handlers/project-handler.d.ts +28 -0
  224. package/dist/cli/handlers/project-handler.js +421 -0
  225. package/dist/cli/handlers/session-handler.channel.test.d.ts +1 -0
  226. package/dist/cli/handlers/session-handler.channel.test.js +157 -0
  227. package/dist/cli/handlers/session-handler.d.ts +58 -0
  228. package/dist/cli/handlers/session-handler.delete.test.d.ts +1 -0
  229. package/dist/cli/handlers/session-handler.delete.test.js +38 -0
  230. package/dist/cli/handlers/session-handler.js +833 -0
  231. package/dist/cli/handlers/session-handler.resume.test.d.ts +1 -0
  232. package/dist/cli/handlers/session-handler.resume.test.js +66 -0
  233. package/dist/cli/handlers/settings-handler.d.ts +19 -0
  234. package/dist/cli/handlers/settings-handler.js +710 -0
  235. package/dist/cli/handlers/settings-handler.remote-catalog.test.d.ts +1 -0
  236. package/dist/cli/handlers/settings-handler.remote-catalog.test.js +1247 -0
  237. package/dist/cli/handlers/skills-handler.d.ts +29 -0
  238. package/dist/cli/handlers/skills-handler.js +368 -0
  239. package/dist/cli/handlers/skills-handler.profile.test.d.ts +1 -0
  240. package/dist/cli/handlers/skills-handler.profile.test.js +70 -0
  241. package/dist/cli/handlers/solo-handler.d.ts +38 -0
  242. package/dist/cli/handlers/solo-handler.js +351 -0
  243. package/dist/cli/handlers/turn-handler.d.ts +52 -0
  244. package/dist/cli/handlers/turn-handler.js +574 -0
  245. package/dist/cli/handlers/turn-handler.test.d.ts +1 -0
  246. package/dist/cli/handlers/turn-handler.test.js +22 -0
  247. package/dist/cli/handlers/workflow-handler.d.ts +181 -0
  248. package/dist/cli/handlers/workflow-handler.events.test.d.ts +1 -0
  249. package/dist/cli/handlers/workflow-handler.events.test.js +113 -0
  250. package/dist/cli/handlers/workflow-handler.js +1449 -0
  251. package/dist/cli/handlers/workflow-handler.multiroot.test.d.ts +12 -0
  252. package/dist/cli/handlers/workflow-handler.multiroot.test.js +745 -0
  253. package/dist/cli/idle-dream-coordinator.d.ts +47 -0
  254. package/dist/cli/idle-dream-coordinator.js +126 -0
  255. package/dist/cli/idle-dream-coordinator.test.d.ts +1 -0
  256. package/dist/cli/idle-dream-coordinator.test.js +125 -0
  257. package/dist/cli/main.d.ts +15 -0
  258. package/dist/cli/main.js +112 -0
  259. package/dist/cli/mcp-bootstrap.d.ts +20 -0
  260. package/dist/cli/mcp-bootstrap.js +66 -0
  261. package/dist/cli/mcp-plugin-bootstrap.d.ts +2 -0
  262. package/dist/cli/mcp-plugin-bootstrap.js +2 -0
  263. package/dist/cli/mcp-plugin-bootstrap.test.d.ts +1 -0
  264. package/dist/cli/mcp-plugin-bootstrap.test.js +38 -0
  265. package/dist/cli/mcp-tool-proxy.d.ts +7 -0
  266. package/dist/cli/mcp-tool-proxy.js +15 -0
  267. package/dist/cli/media-capability-schema.d.ts +49 -0
  268. package/dist/cli/media-capability-schema.js +384 -0
  269. package/dist/cli/media-capability-schema.test.d.ts +1 -0
  270. package/dist/cli/media-capability-schema.test.js +103 -0
  271. package/dist/cli/media-file-api-service.d.ts +73 -0
  272. package/dist/cli/media-file-api-service.js +143 -0
  273. package/dist/cli/media-file-api-service.test.d.ts +1 -0
  274. package/dist/cli/media-file-api-service.test.js +119 -0
  275. package/dist/cli/media-file-tool-service.d.ts +13 -0
  276. package/dist/cli/media-file-tool-service.js +63 -0
  277. package/dist/cli/media-runtime-capability.test.d.ts +1 -0
  278. package/dist/cli/media-runtime-capability.test.js +106 -0
  279. package/dist/cli/media-runtime-facade.d.ts +51 -0
  280. package/dist/cli/media-runtime-facade.js +389 -0
  281. package/dist/cli/media-runtime-facade.test.d.ts +1 -0
  282. package/dist/cli/media-runtime-facade.test.js +42 -0
  283. package/dist/cli/memory-candidate-service.d.ts +83 -0
  284. package/dist/cli/memory-candidate-service.js +341 -0
  285. package/dist/cli/memory-coordinator.d.ts +37 -0
  286. package/dist/cli/memory-coordinator.js +85 -0
  287. package/dist/cli/memory-coordinator.test.d.ts +1 -0
  288. package/dist/cli/memory-coordinator.test.js +78 -0
  289. package/dist/cli/memory-multimodal.test.d.ts +1 -0
  290. package/dist/cli/memory-multimodal.test.js +137 -0
  291. package/dist/cli/model-client-resolver.d.ts +31 -0
  292. package/dist/cli/model-client-resolver.js +173 -0
  293. package/dist/cli/model-client-resolver.test.d.ts +1 -0
  294. package/dist/cli/model-client-resolver.test.js +105 -0
  295. package/dist/cli/multi-agent-handler-host.d.ts +27 -0
  296. package/dist/cli/multi-agent-handler-host.js +55 -0
  297. package/dist/cli/multi-agent-handler-host.test.d.ts +1 -0
  298. package/dist/cli/multi-agent-handler-host.test.js +63 -0
  299. package/dist/cli/multi-agent-state-coordinator.d.ts +11 -0
  300. package/dist/cli/multi-agent-state-coordinator.js +7 -0
  301. package/dist/cli/permission-approval-bridge.d.ts +15 -0
  302. package/dist/cli/permission-approval-bridge.js +66 -0
  303. package/dist/cli/permission-approval-bridge.test.d.ts +1 -0
  304. package/dist/cli/permission-approval-bridge.test.js +100 -0
  305. package/dist/cli/permission-bootstrap.d.ts +40 -0
  306. package/dist/cli/permission-bootstrap.js +58 -0
  307. package/dist/cli/permission-bootstrap.test.d.ts +1 -0
  308. package/dist/cli/permission-bootstrap.test.js +129 -0
  309. package/dist/cli/permission-runtime-service.d.ts +9 -0
  310. package/dist/cli/permission-runtime-service.js +11 -0
  311. package/dist/cli/permission-settings-store.d.ts +1 -0
  312. package/dist/cli/permission-settings-store.js +3 -0
  313. package/dist/cli/permission-settings-store.test.d.ts +1 -0
  314. package/dist/cli/permission-settings-store.test.js +65 -0
  315. package/dist/cli/pet-confirm-coordinator.d.ts +20 -0
  316. package/dist/cli/pet-confirm-coordinator.js +32 -0
  317. package/dist/cli/pet-confirm-coordinator.test.d.ts +1 -0
  318. package/dist/cli/pet-confirm-coordinator.test.js +34 -0
  319. package/dist/cli/pet-runtime.d.ts +55 -0
  320. package/dist/cli/pet-runtime.js +220 -0
  321. package/dist/cli/pet-runtime.test.d.ts +1 -0
  322. package/dist/cli/pet-runtime.test.js +46 -0
  323. package/dist/cli/plugin-bootstrap.d.ts +15 -0
  324. package/dist/cli/plugin-bootstrap.js +63 -0
  325. package/dist/cli/product-coordinator.d.ts +34 -0
  326. package/dist/cli/product-coordinator.js +124 -0
  327. package/dist/cli/product-coordinator.test.d.ts +1 -0
  328. package/dist/cli/product-coordinator.test.js +51 -0
  329. package/dist/cli/project-command-service.d.ts +28 -0
  330. package/dist/cli/project-command-service.js +99 -0
  331. package/dist/cli/project-context.d.ts +1 -0
  332. package/dist/cli/project-context.js +4 -0
  333. package/dist/cli/project-memory-store-factory.d.ts +2 -0
  334. package/dist/cli/project-memory-store-factory.js +11 -0
  335. package/dist/cli/project-template-seeder.d.ts +5 -0
  336. package/dist/cli/project-template-seeder.js +43 -0
  337. package/dist/cli/provider-core-facade.d.ts +31 -0
  338. package/dist/cli/provider-core-facade.js +51 -0
  339. package/dist/cli/provider-core-facade.test.d.ts +1 -0
  340. package/dist/cli/provider-core-facade.test.js +9 -0
  341. package/dist/cli/resolved-agent-cache.d.ts +47 -0
  342. package/dist/cli/resolved-agent-cache.js +38 -0
  343. package/dist/cli/rpc-registry.community.test.d.ts +1 -0
  344. package/dist/cli/rpc-registry.community.test.js +45 -0
  345. package/dist/cli/rpc-registry.d.ts +62 -0
  346. package/dist/cli/rpc-registry.js +243 -0
  347. package/dist/cli/runtime-dependency-catalog.d.ts +56 -0
  348. package/dist/cli/runtime-dependency-catalog.js +110 -0
  349. package/dist/cli/runtime-hook-bootstrap.d.ts +38 -0
  350. package/dist/cli/runtime-hook-bootstrap.js +71 -0
  351. package/dist/cli/runtime-watcher-bootstrap.d.ts +15 -0
  352. package/dist/cli/runtime-watcher-bootstrap.js +30 -0
  353. package/dist/cli/session-context.d.ts +32 -0
  354. package/dist/cli/session-context.js +15 -0
  355. package/dist/cli/session-coordinator.d.ts +22 -0
  356. package/dist/cli/session-coordinator.js +47 -0
  357. package/dist/cli/session-coordinator.test.d.ts +1 -0
  358. package/dist/cli/session-coordinator.test.js +61 -0
  359. package/dist/cli/session-history-coordinator.d.ts +8 -0
  360. package/dist/cli/session-history-coordinator.js +57 -0
  361. package/dist/cli/session-history-coordinator.test.d.ts +1 -0
  362. package/dist/cli/session-history-coordinator.test.js +39 -0
  363. package/dist/cli/session-query-service.d.ts +24 -0
  364. package/dist/cli/session-query-service.js +57 -0
  365. package/dist/cli/skill-meta-subturn-service.d.ts +26 -0
  366. package/dist/cli/skill-meta-subturn-service.js +93 -0
  367. package/dist/cli/skill-meta-tool-bootstrap.d.ts +34 -0
  368. package/dist/cli/skill-meta-tool-bootstrap.js +295 -0
  369. package/dist/cli/skill-meta-tool-bootstrap.test.d.ts +1 -0
  370. package/dist/cli/skill-meta-tool-bootstrap.test.js +42 -0
  371. package/dist/cli/skill-supporting-file.test.d.ts +1 -0
  372. package/dist/cli/skill-supporting-file.test.js +97 -0
  373. package/dist/cli/skills-query-service.d.ts +29 -0
  374. package/dist/cli/skills-query-service.js +38 -0
  375. package/dist/cli/stdio-acp-protocol-coordinator.d.ts +18 -0
  376. package/dist/cli/stdio-acp-protocol-coordinator.js +33 -0
  377. package/dist/cli/stdio-acp-request-host.d.ts +28 -0
  378. package/dist/cli/stdio-acp-request-host.js +82 -0
  379. package/dist/cli/stdio-acp-request-host.test.d.ts +1 -0
  380. package/dist/cli/stdio-acp-request-host.test.js +61 -0
  381. package/dist/cli/stdio-agent-session-bootstrap.d.ts +80 -0
  382. package/dist/cli/stdio-agent-session-bootstrap.js +74 -0
  383. package/dist/cli/stdio-rpc-handler-hosts.d.ts +50 -0
  384. package/dist/cli/stdio-rpc-handler-hosts.js +135 -0
  385. package/dist/cli/stdio-rpc-handler-hosts.test.d.ts +1 -0
  386. package/dist/cli/stdio-rpc-handler-hosts.test.js +10 -0
  387. package/dist/cli/stdio-runtime-bootstrap.d.ts +16 -0
  388. package/dist/cli/stdio-runtime-bootstrap.js +17 -0
  389. package/dist/cli/stdio-runtime-services.d.ts +36 -0
  390. package/dist/cli/stdio-runtime-services.js +53 -0
  391. package/dist/cli/stdio-server.architecture.test.d.ts +1 -0
  392. package/dist/cli/stdio-server.architecture.test.js +18 -0
  393. package/dist/cli/stdio-server.contract.test.d.ts +1 -0
  394. package/dist/cli/stdio-server.contract.test.js +96 -0
  395. package/dist/cli/stdio-server.d.ts +211 -0
  396. package/dist/cli/stdio-server.js +731 -0
  397. package/dist/cli/stdio-session-runtime-coordinator.d.ts +19 -0
  398. package/dist/cli/stdio-session-runtime-coordinator.js +21 -0
  399. package/dist/cli/test-support/tool-catalog-fixture.d.ts +3 -0
  400. package/dist/cli/test-support/tool-catalog-fixture.js +98 -0
  401. package/dist/cli/tool-bootstrap-core-registration.d.ts +30 -0
  402. package/dist/cli/tool-bootstrap-core-registration.js +555 -0
  403. package/dist/cli/tool-bootstrap-media-registration.d.ts +8 -0
  404. package/dist/cli/tool-bootstrap-media-registration.js +348 -0
  405. package/dist/cli/tool-bootstrap-paths.d.ts +7 -0
  406. package/dist/cli/tool-bootstrap-paths.js +17 -0
  407. package/dist/cli/tool-bootstrap-providers.d.ts +3 -0
  408. package/dist/cli/tool-bootstrap-providers.js +10 -0
  409. package/dist/cli/tool-bootstrap-web-registration.d.ts +13 -0
  410. package/dist/cli/tool-bootstrap-web-registration.js +144 -0
  411. package/dist/cli/tool-bootstrap-workflow-registration.d.ts +7 -0
  412. package/dist/cli/tool-bootstrap-workflow-registration.js +65 -0
  413. package/dist/cli/tool-bootstrap.background-exec.test.d.ts +1 -0
  414. package/dist/cli/tool-bootstrap.background-exec.test.js +83 -0
  415. package/dist/cli/tool-bootstrap.cwd.test.d.ts +1 -0
  416. package/dist/cli/tool-bootstrap.cwd.test.js +37 -0
  417. package/dist/cli/tool-bootstrap.d.ts +63 -0
  418. package/dist/cli/tool-bootstrap.instructions.test.d.ts +1 -0
  419. package/dist/cli/tool-bootstrap.instructions.test.js +37 -0
  420. package/dist/cli/tool-bootstrap.js +255 -0
  421. package/dist/cli/tool-bootstrap.media-provider-alias.test.d.ts +1 -0
  422. package/dist/cli/tool-bootstrap.media-provider-alias.test.js +90 -0
  423. package/dist/cli/tool-bootstrap.test.d.ts +1 -0
  424. package/dist/cli/tool-bootstrap.test.js +94 -0
  425. package/dist/cli/tool-catalog.d.ts +4 -0
  426. package/dist/cli/tool-catalog.js +14 -0
  427. package/dist/cli/tool-invoker-factory.d.ts +12 -0
  428. package/dist/cli/tool-invoker-factory.js +45 -0
  429. package/dist/cli/tool-registration-modules.contract.test.d.ts +1 -0
  430. package/dist/cli/tool-registration-modules.contract.test.js +75 -0
  431. package/dist/cli/tool-registry-adapter.d.ts +5 -0
  432. package/dist/cli/tool-registry-adapter.js +27 -0
  433. package/dist/cli/tool-result-processor.d.ts +14 -0
  434. package/dist/cli/tool-result-processor.js +83 -0
  435. package/dist/cli/tool-result-processor.test.d.ts +1 -0
  436. package/dist/cli/tool-result-processor.test.js +69 -0
  437. package/dist/cli/transport.d.ts +30 -0
  438. package/dist/cli/transport.js +68 -0
  439. package/dist/cli/tunable-store.d.ts +26 -0
  440. package/dist/cli/tunable-store.js +105 -0
  441. package/dist/cli/turn-ask-user-setup.d.ts +24 -0
  442. package/dist/cli/turn-ask-user-setup.js +46 -0
  443. package/dist/cli/turn-ask-user-setup.test.d.ts +1 -0
  444. package/dist/cli/turn-ask-user-setup.test.js +39 -0
  445. package/dist/cli/turn-core.d.ts +57 -0
  446. package/dist/cli/turn-core.js +58 -0
  447. package/dist/cli/turn-event-forwarder.d.ts +10 -0
  448. package/dist/cli/turn-event-forwarder.js +136 -0
  449. package/dist/cli/turn-lifecycle.d.ts +19 -0
  450. package/dist/cli/turn-lifecycle.js +53 -0
  451. package/dist/cli/turn-lifecycle.test.d.ts +1 -0
  452. package/dist/cli/turn-lifecycle.test.js +32 -0
  453. package/dist/cli/turn-media-setup.d.ts +19 -0
  454. package/dist/cli/turn-media-setup.js +71 -0
  455. package/dist/cli/turn-media-setup.test.d.ts +1 -0
  456. package/dist/cli/turn-media-setup.test.js +280 -0
  457. package/dist/cli/turn-permission-sync.d.ts +6 -0
  458. package/dist/cli/turn-permission-sync.js +7 -0
  459. package/dist/cli/turn-permission-sync.test.d.ts +1 -0
  460. package/dist/cli/turn-permission-sync.test.js +20 -0
  461. package/dist/cli/turn-project-router.d.ts +22 -0
  462. package/dist/cli/turn-project-router.js +141 -0
  463. package/dist/cli/turn-project-router.test.d.ts +1 -0
  464. package/dist/cli/turn-project-router.test.js +79 -0
  465. package/dist/cli/turn-skill-autopersist.d.ts +47 -0
  466. package/dist/cli/turn-skill-autopersist.js +262 -0
  467. package/dist/cli/turn-skill-autopersist.test.d.ts +1 -0
  468. package/dist/cli/turn-skill-autopersist.test.js +222 -0
  469. package/dist/cli/turn-suggestion-generator.d.ts +15 -0
  470. package/dist/cli/turn-suggestion-generator.js +34 -0
  471. package/dist/cli/workflow-host-adapter.d.ts +29 -0
  472. package/dist/cli/workflow-host-adapter.js +15 -0
  473. package/dist/cli/workflow-host-adapter.test.d.ts +1 -0
  474. package/dist/cli/workflow-host-adapter.test.js +35 -0
  475. package/dist/config/config.d.ts +17 -0
  476. package/dist/config/config.js +21 -0
  477. package/dist/contracts/fire-hook.d.ts +14 -0
  478. package/dist/contracts/fire-hook.js +14 -0
  479. package/dist/contracts/fire-hook.test.d.ts +1 -0
  480. package/dist/contracts/fire-hook.test.js +34 -0
  481. package/dist/contracts/hooks.d.ts +186 -0
  482. package/dist/contracts/hooks.js +7 -0
  483. package/dist/contracts/index.d.ts +4 -0
  484. package/dist/contracts/index.js +4 -0
  485. package/dist/index.d.ts +15 -0
  486. package/dist/index.js +15 -1269
  487. package/dist/orchestration/agent-instance.d.ts +84 -0
  488. package/dist/orchestration/agent-instance.js +535 -0
  489. package/dist/orchestration/context/context-collapse.d.ts +58 -0
  490. package/dist/orchestration/context/context-collapse.js +134 -0
  491. package/dist/orchestration/context/reactive-compact.d.ts +73 -0
  492. package/dist/orchestration/context/reactive-compact.js +78 -0
  493. package/dist/orchestration/context/turn-loop-guard.d.ts +86 -0
  494. package/dist/orchestration/context/turn-loop-guard.js +100 -0
  495. package/dist/orchestration/dag-scheduler.d.ts +167 -0
  496. package/dist/orchestration/dag-scheduler.js +546 -0
  497. package/dist/orchestration/error-handling/error-classification.d.ts +3 -0
  498. package/dist/orchestration/error-handling/error-classification.js +35 -0
  499. package/dist/orchestration/error-handling/failover-classification.d.ts +8 -0
  500. package/dist/orchestration/error-handling/failover-classification.js +381 -0
  501. package/dist/orchestration/error-handling/retry-loop.d.ts +69 -0
  502. package/dist/orchestration/error-handling/retry-loop.js +96 -0
  503. package/dist/orchestration/index.d.ts +15 -0
  504. package/dist/orchestration/index.js +18 -0
  505. package/dist/orchestration/product-budget.d.ts +56 -0
  506. package/dist/orchestration/product-budget.js +112 -0
  507. package/dist/orchestration/product-checkpoint.d.ts +46 -0
  508. package/dist/orchestration/product-checkpoint.js +74 -0
  509. package/dist/orchestration/product-dag-mutation-applier.d.ts +10 -0
  510. package/dist/orchestration/product-dag-mutation-applier.js +91 -0
  511. package/dist/orchestration/product-persistence.d.ts +35 -0
  512. package/dist/orchestration/product-persistence.js +55 -0
  513. package/dist/orchestration/product-planner.d.ts +146 -0
  514. package/dist/orchestration/product-planner.js +379 -0
  515. package/dist/orchestration/product-run-coordinator.d.ts +31 -0
  516. package/dist/orchestration/product-run-coordinator.js +31 -0
  517. package/dist/orchestration/product-worktree.d.ts +12 -0
  518. package/dist/orchestration/product-worktree.js +69 -0
  519. package/dist/orchestration/skill-improvement.d.ts +129 -0
  520. package/dist/orchestration/skill-improvement.js +243 -0
  521. package/dist/orchestration/solo-evaluator.d.ts +124 -0
  522. package/dist/orchestration/solo-evaluator.js +611 -0
  523. package/dist/orchestration/solo-persistence.d.ts +48 -0
  524. package/dist/orchestration/solo-persistence.js +67 -0
  525. package/dist/orchestration/solo-spec-builder.d.ts +48 -0
  526. package/dist/orchestration/solo-spec-builder.js +139 -0
  527. package/dist/orchestration/subagent/agent-registry.d.ts +46 -0
  528. package/dist/orchestration/subagent/agent-registry.js +129 -0
  529. package/dist/orchestration/subagent/fork-subagent.d.ts +100 -0
  530. package/dist/orchestration/subagent/fork-subagent.js +101 -0
  531. package/dist/orchestration/subagent/task-types.d.ts +1 -0
  532. package/dist/orchestration/subagent/task-types.js +1 -0
  533. package/dist/orchestration/tool-cascade.d.ts +49 -0
  534. package/dist/orchestration/tool-cascade.js +86 -0
  535. package/dist/orchestration/tool-loop/conversation-repair.d.ts +61 -0
  536. package/dist/orchestration/tool-loop/conversation-repair.js +429 -0
  537. package/dist/orchestration/tool-loop/tool-choice-policy.d.ts +54 -0
  538. package/dist/orchestration/tool-loop/tool-choice-policy.js +164 -0
  539. package/dist/orchestration/tool-loop/tool-loop-state.d.ts +50 -0
  540. package/dist/orchestration/tool-loop/tool-loop-state.js +133 -0
  541. package/dist/orchestration/tool-loop/tool-schema.d.ts +46 -0
  542. package/dist/orchestration/tool-loop/tool-schema.js +208 -0
  543. package/dist/orchestration/workflow/budget-permission-gate.d.ts +85 -0
  544. package/dist/orchestration/workflow/budget-permission-gate.js +134 -0
  545. package/dist/orchestration/workflow/builtin-executors.d.ts +18 -0
  546. package/dist/orchestration/workflow/builtin-executors.js +191 -0
  547. package/dist/orchestration/workflow/capability-catalog.d.ts +64 -0
  548. package/dist/orchestration/workflow/capability-catalog.js +166 -0
  549. package/dist/orchestration/workflow/cron-schedule.d.ts +37 -0
  550. package/dist/orchestration/workflow/cron-schedule.js +199 -0
  551. package/dist/orchestration/workflow/data-item.d.ts +39 -0
  552. package/dist/orchestration/workflow/data-item.js +52 -0
  553. package/dist/orchestration/workflow/expression.d.ts +60 -0
  554. package/dist/orchestration/workflow/expression.js +474 -0
  555. package/dist/orchestration/workflow/host-executors.d.ts +15 -0
  556. package/dist/orchestration/workflow/host-executors.js +207 -0
  557. package/dist/orchestration/workflow/n8n-expression.d.ts +48 -0
  558. package/dist/orchestration/workflow/n8n-expression.js +95 -0
  559. package/dist/orchestration/workflow/n8n-import.d.ts +68 -0
  560. package/dist/orchestration/workflow/n8n-import.js +319 -0
  561. package/dist/orchestration/workflow/node-registry.d.ts +19 -0
  562. package/dist/orchestration/workflow/node-registry.js +45 -0
  563. package/dist/orchestration/workflow/node-schema.d.ts +232 -0
  564. package/dist/orchestration/workflow/node-schema.js +29 -0
  565. package/dist/orchestration/workflow/qla-executor-host.d.ts +77 -0
  566. package/dist/orchestration/workflow/qla-executor-host.js +124 -0
  567. package/dist/orchestration/workflow/run-checkpoint-store.d.ts +53 -0
  568. package/dist/orchestration/workflow/run-checkpoint-store.js +59 -0
  569. package/dist/orchestration/workflow/run-history-store.d.ts +65 -0
  570. package/dist/orchestration/workflow/run-history-store.js +104 -0
  571. package/dist/orchestration/workflow/trigger-validation.d.ts +22 -0
  572. package/dist/orchestration/workflow/trigger-validation.js +241 -0
  573. package/dist/orchestration/workflow/workflow-audit-store.d.ts +31 -0
  574. package/dist/orchestration/workflow/workflow-audit-store.js +55 -0
  575. package/dist/orchestration/workflow/workflow-bundle.d.ts +65 -0
  576. package/dist/orchestration/workflow/workflow-bundle.js +168 -0
  577. package/dist/orchestration/workflow/workflow-controller.d.ts +219 -0
  578. package/dist/orchestration/workflow/workflow-controller.js +522 -0
  579. package/dist/orchestration/workflow/workflow-patch.d.ts +116 -0
  580. package/dist/orchestration/workflow/workflow-patch.js +369 -0
  581. package/dist/orchestration/workflow/workflow-render.d.ts +41 -0
  582. package/dist/orchestration/workflow/workflow-render.js +108 -0
  583. package/dist/orchestration/workflow/workflow-runtime.d.ts +171 -0
  584. package/dist/orchestration/workflow/workflow-runtime.js +474 -0
  585. package/dist/orchestration/workflow/workflow-scheduler.d.ts +111 -0
  586. package/dist/orchestration/workflow/workflow-scheduler.js +230 -0
  587. package/dist/orchestration/workflow/workflow-service.d.ts +14 -0
  588. package/dist/orchestration/workflow/workflow-service.js +18 -0
  589. package/dist/orchestration/workflow/workflow-store.d.ts +81 -0
  590. package/dist/orchestration/workflow/workflow-store.js +123 -0
  591. package/dist/orchestration/workflow/workflow-trigger.d.ts +35 -0
  592. package/dist/orchestration/workflow/workflow-trigger.js +1 -0
  593. package/dist/orchestration/workflow-chat-builder.d.ts +57 -0
  594. package/dist/orchestration/workflow-chat-builder.js +202 -0
  595. package/dist/permissions.d.ts +2 -0
  596. package/dist/permissions.js +1 -1
  597. package/dist/permissions.public-api.test.d.ts +1 -0
  598. package/dist/permissions.public-api.test.js +32 -0
  599. package/dist/pet-contracts.d.ts +1 -0
  600. package/dist/pet-contracts.js +1 -1
  601. package/dist/protocol/index.d.ts +7 -0
  602. package/dist/protocol/index.js +7 -0
  603. package/dist/protocol/methods.d.ts +1190 -0
  604. package/dist/protocol/methods.js +110 -0
  605. package/dist/protocol/notifications.d.ts +9 -0
  606. package/dist/protocol/notifications.js +9 -0
  607. package/dist/protocol/wire/acp-agent-management.d.ts +456 -0
  608. package/dist/protocol/wire/acp-agent-management.js +7 -0
  609. package/dist/protocol/wire/acp-protocol.d.ts +369 -0
  610. package/dist/protocol/wire/acp-protocol.js +120 -0
  611. package/dist/protocol/wire/agent-events.d.ts +32 -0
  612. package/dist/protocol/wire/agent-events.js +113 -0
  613. package/dist/protocol/wire/agent-methods.d.ts +564 -0
  614. package/dist/protocol/wire/agent-methods.js +11 -0
  615. package/dist/protocol/wire/agent-rpc.d.ts +100 -0
  616. package/dist/protocol/wire/agent-rpc.js +72 -0
  617. package/dist/protocol/wire/capability-manifest.d.ts +112 -0
  618. package/dist/protocol/wire/capability-manifest.js +149 -0
  619. package/dist/protocol/wire/capability-transport.d.ts +207 -0
  620. package/dist/protocol/wire/capability-transport.js +1 -0
  621. package/dist/protocol/wire/channel-ingress.d.ts +29 -0
  622. package/dist/protocol/wire/channel-ingress.js +1 -0
  623. package/dist/protocol/wire/channel.d.ts +89 -0
  624. package/dist/protocol/wire/channel.js +1 -0
  625. package/dist/protocol/wire/chat-types.d.ts +106 -0
  626. package/dist/protocol/wire/chat-types.js +7 -0
  627. package/dist/protocol/wire/checkpoint-runtime.d.ts +61 -0
  628. package/dist/protocol/wire/checkpoint-runtime.js +499 -0
  629. package/dist/protocol/wire/checkpoint.d.ts +72 -0
  630. package/dist/protocol/wire/checkpoint.js +12 -0
  631. package/dist/protocol/wire/execution.d.ts +391 -0
  632. package/dist/protocol/wire/execution.js +1 -0
  633. package/dist/protocol/wire/gateway-contract.d.ts +61 -0
  634. package/dist/protocol/wire/gateway-contract.js +236 -0
  635. package/dist/protocol/wire/gateway-contract.test.d.ts +1 -0
  636. package/dist/protocol/wire/gateway-contract.test.js +123 -0
  637. package/dist/protocol/wire/gateway-rpc.d.ts +652 -0
  638. package/dist/protocol/wire/gateway-rpc.js +58 -0
  639. package/dist/protocol/wire/gateway.d.ts +62 -0
  640. package/dist/protocol/wire/gateway.js +1 -0
  641. package/dist/protocol/wire/hook-protocol.d.ts +37 -0
  642. package/dist/protocol/wire/hook-protocol.js +2 -0
  643. package/dist/protocol/wire/index.d.ts +28 -0
  644. package/dist/protocol/wire/index.js +27 -0
  645. package/dist/protocol/wire/memory-provider-lifecycle.d.ts +82 -0
  646. package/dist/protocol/wire/memory-provider-lifecycle.js +24 -0
  647. package/dist/protocol/wire/notification-payloads.d.ts +918 -0
  648. package/dist/protocol/wire/notification-payloads.js +13 -0
  649. package/dist/protocol/wire/pet-contracts.d.ts +76 -0
  650. package/dist/protocol/wire/pet-contracts.js +23 -0
  651. package/dist/protocol/wire/provider-runtime-contract.d.ts +66 -0
  652. package/dist/protocol/wire/provider-runtime-contract.js +23 -0
  653. package/dist/protocol/wire/provider-runtime-core.d.ts +147 -0
  654. package/dist/protocol/wire/provider-runtime-core.js +488 -0
  655. package/dist/protocol/wire/provider-runtime-io.d.ts +20 -0
  656. package/dist/protocol/wire/provider-runtime-io.js +57 -0
  657. package/dist/protocol/wire/resource-manifest.d.ts +68 -0
  658. package/dist/protocol/wire/resource-manifest.js +174 -0
  659. package/dist/protocol/wire/session.d.ts +32 -0
  660. package/dist/protocol/wire/session.js +1 -0
  661. package/dist/protocol/wire/thread-protocol.d.ts +145 -0
  662. package/dist/protocol/wire/thread-protocol.js +13 -0
  663. package/dist/protocol/wire/transport.d.ts +57 -0
  664. package/dist/protocol/wire/transport.js +1 -0
  665. package/dist/protocol/wire/turn.d.ts +208 -0
  666. package/dist/protocol/wire/turn.js +1 -0
  667. package/dist/protocol/wire/web-capability.d.ts +54 -0
  668. package/dist/protocol/wire/web-capability.js +52 -0
  669. package/dist/runtime/community/community-consent-client.d.ts +142 -0
  670. package/dist/runtime/community/community-consent-client.js +381 -0
  671. package/dist/runtime/community/community-consent-client.test.d.ts +1 -0
  672. package/dist/runtime/community/community-consent-client.test.js +491 -0
  673. package/dist/runtime/community/community-desensitization-red-team-cli.d.ts +7 -0
  674. package/dist/runtime/community/community-desensitization-red-team-cli.js +43 -0
  675. package/dist/runtime/community/community-desensitization-red-team-cli.test.d.ts +1 -0
  676. package/dist/runtime/community/community-desensitization-red-team-cli.test.js +23 -0
  677. package/dist/runtime/community/community-desensitization.d.ts +29 -0
  678. package/dist/runtime/community/community-desensitization.js +81 -0
  679. package/dist/runtime/community/community-desensitization.test.d.ts +1 -0
  680. package/dist/runtime/community/community-desensitization.test.js +43 -0
  681. package/dist/runtime/community/community-discovery-cache.d.ts +24 -0
  682. package/dist/runtime/community/community-discovery-cache.js +52 -0
  683. package/dist/runtime/community/community-discovery-coordinator.d.ts +33 -0
  684. package/dist/runtime/community/community-discovery-coordinator.js +84 -0
  685. package/dist/runtime/community/community-discovery-coordinator.test.d.ts +1 -0
  686. package/dist/runtime/community/community-discovery-coordinator.test.js +97 -0
  687. package/dist/runtime/community/community-pet-publisher.d.ts +30 -0
  688. package/dist/runtime/community/community-pet-publisher.js +53 -0
  689. package/dist/runtime/community/community-pet-publisher.test.d.ts +1 -0
  690. package/dist/runtime/community/community-pet-publisher.test.js +53 -0
  691. package/dist/runtime/community/community-signal-reporter.d.ts +33 -0
  692. package/dist/runtime/community/community-signal-reporter.js +85 -0
  693. package/dist/runtime/community/community-signal-reporter.test.d.ts +1 -0
  694. package/dist/runtime/community/community-signal-reporter.test.js +100 -0
  695. package/dist/runtime/community/community-telemetry-metadata.d.ts +4 -0
  696. package/dist/runtime/community/community-telemetry-metadata.js +42 -0
  697. package/dist/runtime/community/community-telemetry-recorder.d.ts +6 -0
  698. package/dist/runtime/community/community-telemetry-recorder.js +31 -0
  699. package/dist/runtime/community/community-telemetry-types.d.ts +1 -0
  700. package/dist/runtime/community/community-telemetry-types.js +1 -0
  701. package/dist/runtime/config/tunable-defaults.d.ts +255 -0
  702. package/dist/runtime/config/tunable-defaults.js +293 -0
  703. package/dist/runtime/context/context-compression-strategies.d.ts +301 -0
  704. package/dist/runtime/context/context-compression-strategies.js +860 -0
  705. package/dist/runtime/execution/dream-agent.d.ts +260 -0
  706. package/dist/runtime/execution/dream-agent.js +974 -0
  707. package/dist/runtime/execution/dream-category-context.d.ts +47 -0
  708. package/dist/runtime/execution/dream-category-context.js +226 -0
  709. package/dist/runtime/execution/dream-lock.test.d.ts +1 -0
  710. package/dist/runtime/execution/dream-lock.test.js +54 -0
  711. package/dist/runtime/execution/fork-context.d.ts +14 -0
  712. package/dist/runtime/execution/fork-context.js +20 -0
  713. package/dist/runtime/execution/fork-context.test.d.ts +1 -0
  714. package/dist/runtime/execution/fork-context.test.js +101 -0
  715. package/dist/runtime/execution/forked-agent.d.ts +111 -0
  716. package/dist/runtime/execution/forked-agent.js +172 -0
  717. package/dist/runtime/execution/index.d.ts +7 -0
  718. package/dist/runtime/execution/index.js +8 -0
  719. package/dist/runtime/execution/memory-decay.d.ts +69 -0
  720. package/dist/runtime/execution/memory-decay.js +80 -0
  721. package/dist/runtime/execution/progress-tracker.d.ts +78 -0
  722. package/dist/runtime/execution/progress-tracker.js +107 -0
  723. package/dist/runtime/execution/streaming-tool-executor.d.ts +102 -0
  724. package/dist/runtime/execution/streaming-tool-executor.js +345 -0
  725. package/dist/runtime/execution/streaming-tool-executor.test.d.ts +1 -0
  726. package/dist/runtime/execution/streaming-tool-executor.test.js +49 -0
  727. package/dist/runtime/execution/tool-eligibility.d.ts +36 -0
  728. package/dist/runtime/execution/tool-eligibility.js +94 -0
  729. package/dist/runtime/execution/tool-eligibility.test.d.ts +1 -0
  730. package/dist/runtime/execution/tool-eligibility.test.js +96 -0
  731. package/dist/runtime/execution/tool-result-storage.d.ts +87 -0
  732. package/dist/runtime/execution/tool-result-storage.js +274 -0
  733. package/dist/runtime/hooks/context-compression.d.ts +61 -0
  734. package/dist/runtime/hooks/context-compression.js +334 -0
  735. package/dist/runtime/hooks/hook-registry.d.ts +12 -0
  736. package/dist/runtime/hooks/hook-registry.js +61 -0
  737. package/dist/runtime/hooks/hook-registry.test.d.ts +1 -0
  738. package/dist/runtime/hooks/hook-registry.test.js +51 -0
  739. package/dist/runtime/hooks/index.d.ts +4 -0
  740. package/dist/runtime/hooks/index.js +5 -0
  741. package/dist/runtime/hooks/memory-hooks.d.ts +75 -0
  742. package/dist/runtime/hooks/memory-hooks.js +356 -0
  743. package/dist/runtime/hooks/skill-recall-hooks.d.ts +37 -0
  744. package/dist/runtime/hooks/skill-recall-hooks.js +263 -0
  745. package/dist/runtime/hooks/skill-recall-hooks.test.d.ts +1 -0
  746. package/dist/runtime/hooks/skill-recall-hooks.test.js +52 -0
  747. package/dist/runtime/index.d.ts +5 -0
  748. package/dist/runtime/index.js +13 -0
  749. package/dist/runtime/infra/acp-detector.d.ts +133 -0
  750. package/dist/runtime/infra/acp-detector.js +862 -0
  751. package/dist/runtime/infra/acp-detector.test.d.ts +1 -0
  752. package/dist/runtime/infra/acp-detector.test.js +164 -0
  753. package/dist/runtime/infra/acp-host-handler.d.ts +31 -0
  754. package/dist/runtime/infra/acp-host-handler.js +123 -0
  755. package/dist/runtime/infra/acp-host-handler.test.d.ts +1 -0
  756. package/dist/runtime/infra/acp-host-handler.test.js +64 -0
  757. package/dist/runtime/infra/acp-protocol-adapter.d.ts +146 -0
  758. package/dist/runtime/infra/acp-protocol-adapter.js +382 -0
  759. package/dist/runtime/infra/acp-protocol-adapter.test.d.ts +1 -0
  760. package/dist/runtime/infra/acp-protocol-adapter.test.js +180 -0
  761. package/dist/runtime/infra/acp-usage-tracker.d.ts +46 -0
  762. package/dist/runtime/infra/acp-usage-tracker.js +92 -0
  763. package/dist/runtime/infra/agent-catalog.test.d.ts +1 -0
  764. package/dist/runtime/infra/agent-catalog.test.js +174 -0
  765. package/dist/runtime/infra/agent-config-store.d.ts +30 -0
  766. package/dist/runtime/infra/agent-config-store.js +115 -0
  767. package/dist/runtime/infra/agent-install-runner.d.ts +57 -0
  768. package/dist/runtime/infra/agent-install-runner.js +123 -0
  769. package/dist/runtime/infra/agent-install-runner.test.d.ts +1 -0
  770. package/dist/runtime/infra/agent-install-runner.test.js +103 -0
  771. package/dist/runtime/infra/agent-paths.d.ts +67 -0
  772. package/dist/runtime/infra/agent-paths.js +167 -0
  773. package/dist/runtime/infra/agent-paths.test.d.ts +1 -0
  774. package/dist/runtime/infra/agent-paths.test.js +49 -0
  775. package/dist/runtime/infra/agent-process.d.ts +299 -0
  776. package/dist/runtime/infra/agent-process.js +1318 -0
  777. package/dist/runtime/infra/background-tasks.d.ts +115 -0
  778. package/dist/runtime/infra/background-tasks.js +249 -0
  779. package/dist/runtime/infra/background-tasks.test.d.ts +1 -0
  780. package/dist/runtime/infra/background-tasks.test.js +242 -0
  781. package/dist/runtime/infra/checkpoint-backend.d.ts +8 -0
  782. package/dist/runtime/infra/checkpoint-backend.js +110 -0
  783. package/dist/runtime/infra/cleanup-registry.d.ts +23 -0
  784. package/dist/runtime/infra/cleanup-registry.js +34 -0
  785. package/dist/runtime/infra/default-path-service.d.ts +33 -0
  786. package/dist/runtime/infra/default-path-service.js +76 -0
  787. package/dist/runtime/infra/default-path-service.test.d.ts +1 -0
  788. package/dist/runtime/infra/default-path-service.test.js +31 -0
  789. package/dist/runtime/infra/disk-storage.d.ts +20 -0
  790. package/dist/runtime/infra/disk-storage.js +64 -0
  791. package/dist/runtime/infra/external-agent-approvals.d.ts +41 -0
  792. package/dist/runtime/infra/external-agent-approvals.js +101 -0
  793. package/dist/runtime/infra/external-agent-approvals.test.d.ts +1 -0
  794. package/dist/runtime/infra/external-agent-approvals.test.js +99 -0
  795. package/dist/runtime/infra/external-agent-pool.d.ts +54 -0
  796. package/dist/runtime/infra/external-agent-pool.js +0 -0
  797. package/dist/runtime/infra/external-agent-pool.test.d.ts +1 -0
  798. package/dist/runtime/infra/external-agent-pool.test.js +102 -0
  799. package/dist/runtime/infra/file-watcher.d.ts +72 -0
  800. package/dist/runtime/infra/file-watcher.js +154 -0
  801. package/dist/runtime/infra/index.d.ts +19 -0
  802. package/dist/runtime/infra/index.js +19 -0
  803. package/dist/runtime/infra/key-injection.test.d.ts +1 -0
  804. package/dist/runtime/infra/key-injection.test.js +88 -0
  805. package/dist/runtime/infra/key-pool.d.ts +122 -0
  806. package/dist/runtime/infra/key-pool.js +378 -0
  807. package/dist/runtime/infra/key-pool.test.d.ts +1 -0
  808. package/dist/runtime/infra/key-pool.test.js +36 -0
  809. package/dist/runtime/infra/llmrouter-catalog.d.ts +84 -0
  810. package/dist/runtime/infra/llmrouter-catalog.js +287 -0
  811. package/dist/runtime/infra/llmrouter-catalog.test.d.ts +1 -0
  812. package/dist/runtime/infra/llmrouter-catalog.test.js +80 -0
  813. package/dist/runtime/infra/llmrouter-zero-config.test.d.ts +1 -0
  814. package/dist/runtime/infra/llmrouter-zero-config.test.js +64 -0
  815. package/dist/runtime/infra/mcp-bridge.d.ts +166 -0
  816. package/dist/runtime/infra/mcp-bridge.js +161 -0
  817. package/dist/runtime/infra/media-persistence.d.ts +87 -0
  818. package/dist/runtime/infra/media-persistence.js +278 -0
  819. package/dist/runtime/infra/migrate-project-skills.d.ts +21 -0
  820. package/dist/runtime/infra/migrate-project-skills.js +131 -0
  821. package/dist/runtime/infra/migrate-project-skills.test.d.ts +1 -0
  822. package/dist/runtime/infra/migrate-project-skills.test.js +69 -0
  823. package/dist/runtime/infra/model-id-translator.d.ts +22 -0
  824. package/dist/runtime/infra/model-id-translator.js +74 -0
  825. package/dist/runtime/infra/model-registry.d.ts +148 -0
  826. package/dist/runtime/infra/model-registry.js +529 -0
  827. package/dist/runtime/infra/model-registry.test.d.ts +1 -0
  828. package/dist/runtime/infra/model-registry.test.js +253 -0
  829. package/dist/runtime/infra/process-config-port.d.ts +2 -0
  830. package/dist/runtime/infra/process-config-port.js +5 -0
  831. package/dist/runtime/infra/profile-storage.test.d.ts +1 -0
  832. package/dist/runtime/infra/profile-storage.test.js +41 -0
  833. package/dist/runtime/infra/project-instructions-store.d.ts +30 -0
  834. package/dist/runtime/infra/project-instructions-store.js +124 -0
  835. package/dist/runtime/infra/project-skill-manifest.d.ts +32 -0
  836. package/dist/runtime/infra/project-skill-manifest.js +160 -0
  837. package/dist/runtime/infra/project-skill-manifest.test.d.ts +1 -0
  838. package/dist/runtime/infra/project-skill-manifest.test.js +42 -0
  839. package/dist/runtime/infra/project-store.d.ts +48 -0
  840. package/dist/runtime/infra/project-store.js +284 -0
  841. package/dist/runtime/infra/secure-storage.d.ts +81 -0
  842. package/dist/runtime/infra/secure-storage.js +117 -0
  843. package/dist/runtime/infra/skill-injector.d.ts +59 -0
  844. package/dist/runtime/infra/skill-injector.js +155 -0
  845. package/dist/runtime/infra/skill-injector.test.d.ts +1 -0
  846. package/dist/runtime/infra/skill-injector.test.js +9 -0
  847. package/dist/runtime/infra/skill-resolver.d.ts +51 -0
  848. package/dist/runtime/infra/skill-resolver.js +109 -0
  849. package/dist/runtime/infra/skill-resolver.test.d.ts +1 -0
  850. package/dist/runtime/infra/skill-resolver.test.js +72 -0
  851. package/dist/runtime/infra/task-runtime.d.ts +71 -0
  852. package/dist/runtime/infra/task-runtime.js +181 -0
  853. package/dist/runtime/infra/token-budget.d.ts +92 -0
  854. package/dist/runtime/infra/token-budget.js +170 -0
  855. package/dist/runtime/infra/worktree-backend.d.ts +86 -0
  856. package/dist/runtime/infra/worktree-backend.js +522 -0
  857. package/dist/runtime/memory/categories.d.ts +5 -0
  858. package/dist/runtime/memory/categories.js +4 -0
  859. package/dist/runtime/memory/find-relevant-memories.d.ts +70 -0
  860. package/dist/runtime/memory/find-relevant-memories.js +270 -0
  861. package/dist/runtime/memory/implicit-extraction.d.ts +58 -0
  862. package/dist/runtime/memory/implicit-extraction.js +187 -0
  863. package/dist/runtime/memory/recall-category-filter.d.ts +54 -0
  864. package/dist/runtime/memory/recall-category-filter.js +215 -0
  865. package/dist/runtime/permission-model.d.ts +19 -0
  866. package/dist/runtime/permission-model.js +24 -0
  867. package/dist/runtime/permission-model.test.d.ts +1 -0
  868. package/dist/runtime/permission-model.test.js +32 -0
  869. package/dist/runtime/pet/hatch-pet-runner.d.ts +18 -0
  870. package/dist/runtime/pet/hatch-pet-runner.js +120 -0
  871. package/dist/runtime/pet/hatch-pet-runner.test.d.ts +1 -0
  872. package/dist/runtime/pet/hatch-pet-runner.test.js +28 -0
  873. package/dist/runtime/pet/index.d.ts +18 -0
  874. package/dist/runtime/pet/index.js +9 -0
  875. package/dist/runtime/pet/pet-community-assets.d.ts +13 -0
  876. package/dist/runtime/pet/pet-community-assets.js +106 -0
  877. package/dist/runtime/pet/pet-file-loader.d.ts +5 -0
  878. package/dist/runtime/pet/pet-file-loader.js +11 -0
  879. package/dist/runtime/pet/pet-growth-engine.d.ts +2 -0
  880. package/dist/runtime/pet/pet-growth-engine.js +1 -0
  881. package/dist/runtime/pet/pet-profile-service.d.ts +91 -0
  882. package/dist/runtime/pet/pet-profile-service.js +296 -0
  883. package/dist/runtime/pet/pet-profile-service.test.d.ts +1 -0
  884. package/dist/runtime/pet/pet-profile-service.test.js +171 -0
  885. package/dist/runtime/pet/pet-reaction-engine.d.ts +11 -0
  886. package/dist/runtime/pet/pet-reaction-engine.js +11 -0
  887. package/dist/runtime/pet/pet-reaction-engine.test.d.ts +1 -0
  888. package/dist/runtime/pet/pet-reaction-engine.test.js +12 -0
  889. package/dist/runtime/pet/pet-soul-service.d.ts +21 -0
  890. package/dist/runtime/pet/pet-soul-service.js +63 -0
  891. package/dist/runtime/pet/pet-soul-service.test.d.ts +1 -0
  892. package/dist/runtime/pet/pet-soul-service.test.js +115 -0
  893. package/dist/runtime/pet/pet-types.d.ts +1 -0
  894. package/dist/runtime/pet/pet-types.js +1 -0
  895. package/dist/runtime/pet/petdex-asset.d.ts +32 -0
  896. package/dist/runtime/pet/petdex-asset.js +242 -0
  897. package/dist/runtime/pet/petdex-asset.test.d.ts +1 -0
  898. package/dist/runtime/pet/petdex-asset.test.js +257 -0
  899. package/dist/runtime/pet/petdex-forge-service.d.ts +19 -0
  900. package/dist/runtime/pet/petdex-forge-service.js +820 -0
  901. package/dist/runtime/pet/petdex-forge-service.test.d.ts +1 -0
  902. package/dist/runtime/pet/petdex-forge-service.test.js +142 -0
  903. package/dist/runtime/ports/agent-execution-contracts.d.ts +182 -0
  904. package/dist/runtime/ports/agent-execution-contracts.js +1 -0
  905. package/dist/runtime/ports/agent-runtime-ports.d.ts +76 -0
  906. package/dist/runtime/ports/agent-runtime-ports.js +1 -0
  907. package/dist/runtime/ports/checkpoint-contracts.d.ts +19 -0
  908. package/dist/runtime/ports/checkpoint-contracts.js +1 -0
  909. package/dist/runtime/ports/config-port.d.ts +4 -0
  910. package/dist/runtime/ports/config-port.js +5 -0
  911. package/dist/runtime/ports/index.d.ts +19 -0
  912. package/dist/runtime/ports/index.js +5 -0
  913. package/dist/runtime/ports/memory-provider.d.ts +181 -0
  914. package/dist/runtime/ports/memory-provider.js +1 -0
  915. package/dist/runtime/ports/memory-recall-source.d.ts +3 -0
  916. package/dist/runtime/ports/memory-recall-source.js +1 -0
  917. package/dist/runtime/ports/memory-writer.d.ts +21 -0
  918. package/dist/runtime/ports/memory-writer.js +1 -0
  919. package/dist/runtime/ports/model-transport-contracts.d.ts +125 -0
  920. package/dist/runtime/ports/model-transport-contracts.js +9 -0
  921. package/dist/runtime/ports/path-service.d.ts +31 -0
  922. package/dist/runtime/ports/path-service.js +1 -0
  923. package/dist/runtime/ports/permission-contracts.d.ts +128 -0
  924. package/dist/runtime/ports/permission-contracts.js +5 -0
  925. package/dist/runtime/ports/project-memory-store.d.ts +44 -0
  926. package/dist/runtime/ports/project-memory-store.js +1 -0
  927. package/dist/runtime/ports/source-provider.d.ts +39 -0
  928. package/dist/runtime/ports/source-provider.js +4 -0
  929. package/dist/runtime/ports/tool-call-contracts.d.ts +16 -0
  930. package/dist/runtime/ports/tool-call-contracts.js +13 -0
  931. package/dist/runtime/ports/tool-contracts.d.ts +87 -0
  932. package/dist/runtime/ports/tool-contracts.js +3 -0
  933. package/dist/runtime/ports/tool-risk.d.ts +7 -0
  934. package/dist/runtime/ports/tool-risk.js +16 -0
  935. package/dist/runtime/ports/web-search-contracts.d.ts +21 -0
  936. package/dist/runtime/ports/web-search-contracts.js +1 -0
  937. package/dist/runtime/ports/worktree-contracts.d.ts +22 -0
  938. package/dist/runtime/ports/worktree-contracts.js +1 -0
  939. package/dist/runtime/prompt/environment-context.d.ts +60 -0
  940. package/dist/runtime/prompt/environment-context.js +410 -0
  941. package/dist/runtime/prompt/environment-context.test.d.ts +1 -0
  942. package/dist/runtime/prompt/environment-context.test.js +75 -0
  943. package/dist/runtime/prompt/fresh-workspace-evidence.d.ts +21 -0
  944. package/dist/runtime/prompt/fresh-workspace-evidence.js +224 -0
  945. package/dist/runtime/prompt/fresh-workspace-evidence.test.d.ts +1 -0
  946. package/dist/runtime/prompt/fresh-workspace-evidence.test.js +163 -0
  947. package/dist/runtime/prompt/index.d.ts +5 -0
  948. package/dist/runtime/prompt/index.js +6 -0
  949. package/dist/runtime/prompt/instruction-loader.d.ts +70 -0
  950. package/dist/runtime/prompt/instruction-loader.js +515 -0
  951. package/dist/runtime/prompt/instruction-loader.test.d.ts +1 -0
  952. package/dist/runtime/prompt/instruction-loader.test.js +64 -0
  953. package/dist/runtime/prompt/prompt-policy.d.ts +12 -0
  954. package/dist/runtime/prompt/prompt-policy.js +40 -0
  955. package/dist/runtime/prompt/system-prompt-sections.d.ts +65 -0
  956. package/dist/runtime/prompt/system-prompt-sections.js +93 -0
  957. package/dist/runtime/prompt/task-domain.d.ts +82 -0
  958. package/dist/runtime/prompt/task-domain.js +248 -0
  959. package/dist/runtime/sandbox/index.d.ts +2 -0
  960. package/dist/runtime/sandbox/index.js +2 -0
  961. package/dist/runtime/sandbox/skill-sandbox.d.ts +53 -0
  962. package/dist/runtime/sandbox/skill-sandbox.js +93 -0
  963. package/dist/runtime/sandbox/skill-sandbox.test.d.ts +1 -0
  964. package/dist/runtime/sandbox/skill-sandbox.test.js +172 -0
  965. package/dist/runtime/sandbox/windows-skill-sandbox.d.ts +78 -0
  966. package/dist/runtime/sandbox/windows-skill-sandbox.js +128 -0
  967. package/dist/runtime/session/group-session-split.d.ts +38 -0
  968. package/dist/runtime/session/group-session-split.js +99 -0
  969. package/dist/runtime/session/index.d.ts +4 -0
  970. package/dist/runtime/session/index.js +5 -0
  971. package/dist/runtime/session/session-catalog.d.ts +4 -0
  972. package/dist/runtime/session/session-catalog.js +59 -0
  973. package/dist/runtime/session/session-locator.d.ts +26 -0
  974. package/dist/runtime/session/session-locator.js +91 -0
  975. package/dist/runtime/session/session-locator.test.d.ts +1 -0
  976. package/dist/runtime/session/session-locator.test.js +59 -0
  977. package/dist/runtime/session/session-metadata-store.d.ts +8 -0
  978. package/dist/runtime/session/session-metadata-store.js +167 -0
  979. package/dist/runtime/session/session-paths.d.ts +9 -0
  980. package/dist/runtime/session/session-paths.js +27 -0
  981. package/dist/runtime/session/session-persistence.d.ts +16 -0
  982. package/dist/runtime/session/session-persistence.js +16 -0
  983. package/dist/runtime/session/session-persistence.test.d.ts +1 -0
  984. package/dist/runtime/session/session-persistence.test.js +237 -0
  985. package/dist/runtime/session/session-resume.d.ts +4 -0
  986. package/dist/runtime/session/session-resume.js +60 -0
  987. package/dist/runtime/session/session-schema.d.ts +10 -0
  988. package/dist/runtime/session/session-schema.js +35 -0
  989. package/dist/runtime/session/session-state.d.ts +96 -0
  990. package/dist/runtime/session/session-state.js +180 -0
  991. package/dist/runtime/session/session-summary.d.ts +5 -0
  992. package/dist/runtime/session/session-summary.js +67 -0
  993. package/dist/runtime/session/session-transcript-store.d.ts +13 -0
  994. package/dist/runtime/session/session-transcript-store.js +109 -0
  995. package/dist/runtime/session/session-types.d.ts +77 -0
  996. package/dist/runtime/session/session-types.js +1 -0
  997. package/dist/runtime/session/session-write-queue.d.ts +2 -0
  998. package/dist/runtime/session/session-write-queue.js +48 -0
  999. package/dist/runtime/tasks/task-types.d.ts +166 -0
  1000. package/dist/runtime/tasks/task-types.js +64 -0
  1001. package/dist/server/search-svc.d.ts +1 -0
  1002. package/dist/server/search-svc.js +113 -0
  1003. package/dist/skills/index.d.ts +6 -0
  1004. package/dist/skills/index.js +5 -0
  1005. package/dist/skills/mcp/index.d.ts +1 -0
  1006. package/dist/skills/mcp/index.js +3 -0
  1007. package/dist/skills/mcp/mcp-manager.d.ts +75 -0
  1008. package/dist/skills/mcp/mcp-manager.js +358 -0
  1009. package/dist/skills/mcp/mcp-tool-metadata.d.ts +18 -0
  1010. package/dist/skills/mcp/mcp-tool-metadata.js +48 -0
  1011. package/dist/skills/memory/categories.d.ts +1 -0
  1012. package/dist/skills/memory/categories.js +1 -0
  1013. package/dist/skills/memory/find-relevant-memories.d.ts +1 -0
  1014. package/dist/skills/memory/find-relevant-memories.js +1 -0
  1015. package/dist/skills/memory/implicit-extraction.d.ts +1 -0
  1016. package/dist/skills/memory/implicit-extraction.js +1 -0
  1017. package/dist/skills/memory/local-embedding.d.ts +80 -0
  1018. package/dist/skills/memory/local-embedding.js +210 -0
  1019. package/dist/skills/memory/local-memory-provider.d.ts +257 -0
  1020. package/dist/skills/memory/local-memory-provider.js +486 -0
  1021. package/dist/skills/memory/local-store-records.d.ts +184 -0
  1022. package/dist/skills/memory/local-store-records.js +1 -0
  1023. package/dist/skills/memory/local-store.d.ts +479 -0
  1024. package/dist/skills/memory/local-store.js +1022 -0
  1025. package/dist/skills/memory/memdir.d.ts +93 -0
  1026. package/dist/skills/memory/memdir.js +530 -0
  1027. package/dist/skills/memory/memory-attachment-store.d.ts +62 -0
  1028. package/dist/skills/memory/memory-attachment-store.js +0 -0
  1029. package/dist/skills/memory/memory-consolidation.d.ts +43 -0
  1030. package/dist/skills/memory/memory-consolidation.js +462 -0
  1031. package/dist/skills/memory/memory-db-path.d.ts +13 -0
  1032. package/dist/skills/memory/memory-db-path.js +27 -0
  1033. package/dist/skills/memory/memory-embedding-config.d.ts +31 -0
  1034. package/dist/skills/memory/memory-embedding-config.js +66 -0
  1035. package/dist/skills/memory/memory-provider-factory.d.ts +33 -0
  1036. package/dist/skills/memory/memory-provider-factory.js +79 -0
  1037. package/dist/skills/memory/memory-tool.d.ts +85 -0
  1038. package/dist/skills/memory/memory-tool.js +326 -0
  1039. package/dist/skills/memory/memory-vector-utils.d.ts +2 -0
  1040. package/dist/skills/memory/memory-vector-utils.js +19 -0
  1041. package/dist/skills/memory/recall-category-filter.d.ts +1 -0
  1042. package/dist/skills/memory/recall-category-filter.js +1 -0
  1043. package/dist/skills/memory/sqlite-memory-mappers.d.ts +6 -0
  1044. package/dist/skills/memory/sqlite-memory-mappers.js +104 -0
  1045. package/dist/skills/memory/sqlite-memory-schema.d.ts +3 -0
  1046. package/dist/skills/memory/sqlite-memory-schema.js +152 -0
  1047. package/dist/skills/permissions/bash-classifier.d.ts +30 -0
  1048. package/dist/skills/permissions/bash-classifier.js +174 -0
  1049. package/dist/skills/permissions/classifier-cache.d.ts +51 -0
  1050. package/dist/skills/permissions/classifier-cache.js +103 -0
  1051. package/dist/skills/permissions/community-sandbox-policy.d.ts +3 -0
  1052. package/dist/skills/permissions/community-sandbox-policy.js +233 -0
  1053. package/dist/skills/permissions/community-sandbox-red-team-cli.d.ts +7 -0
  1054. package/dist/skills/permissions/community-sandbox-red-team-cli.js +43 -0
  1055. package/dist/skills/permissions/community-sandbox-red-team.d.ts +32 -0
  1056. package/dist/skills/permissions/community-sandbox-red-team.js +221 -0
  1057. package/dist/skills/permissions/denial-audit-log.d.ts +52 -0
  1058. package/dist/skills/permissions/denial-audit-log.js +80 -0
  1059. package/dist/skills/permissions/denial-tracking.d.ts +42 -0
  1060. package/dist/skills/permissions/denial-tracking.js +60 -0
  1061. package/dist/skills/permissions/group-security-policy.d.ts +15 -0
  1062. package/dist/skills/permissions/group-security-policy.js +60 -0
  1063. package/dist/skills/permissions/hook-runner.d.ts +120 -0
  1064. package/dist/skills/permissions/hook-runner.js +545 -0
  1065. package/dist/skills/permissions/index.d.ts +13 -0
  1066. package/dist/skills/permissions/index.js +8 -0
  1067. package/dist/skills/permissions/operation-classifier.d.ts +43 -0
  1068. package/dist/skills/permissions/operation-classifier.js +251 -0
  1069. package/dist/skills/permissions/permission-classifier.d.ts +41 -0
  1070. package/dist/skills/permissions/permission-classifier.js +186 -0
  1071. package/dist/skills/permissions/rule-engine.d.ts +49 -0
  1072. package/dist/skills/permissions/rule-engine.js +285 -0
  1073. package/dist/skills/permissions/settings-watcher.d.ts +19 -0
  1074. package/dist/skills/permissions/settings-watcher.js +121 -0
  1075. package/dist/skills/permissions/types.d.ts +2 -0
  1076. package/dist/skills/permissions/types.js +1 -0
  1077. package/dist/skills/plugins/index.d.ts +2 -0
  1078. package/dist/skills/plugins/index.js +3 -0
  1079. package/dist/skills/plugins/plugin-api.d.ts +38 -0
  1080. package/dist/skills/plugins/plugin-api.js +18 -0
  1081. package/dist/skills/plugins/plugin-loader.d.ts +57 -0
  1082. package/dist/skills/plugins/plugin-loader.js +254 -0
  1083. package/dist/skills/plugins/plugin-marketplace.d.ts +61 -0
  1084. package/dist/skills/plugins/plugin-marketplace.js +229 -0
  1085. package/dist/skills/portable-tool.d.ts +165 -0
  1086. package/dist/skills/portable-tool.js +34 -0
  1087. package/dist/skills/skill-system/skill-frontmatter.d.ts +19 -0
  1088. package/dist/skills/skill-system/skill-frontmatter.js +344 -0
  1089. package/dist/skills/skill-system/skill-guard.d.ts +23 -0
  1090. package/dist/skills/skill-system/skill-guard.js +229 -0
  1091. package/dist/skills/skill-system/skill-lifecycle.d.ts +93 -0
  1092. package/dist/skills/skill-system/skill-lifecycle.js +236 -0
  1093. package/dist/skills/skill-system/skill-source.d.ts +38 -0
  1094. package/dist/skills/skill-system/skill-source.js +75 -0
  1095. package/dist/skills/skill-system/skill-types.d.ts +140 -0
  1096. package/dist/skills/skill-system/skill-types.js +6 -0
  1097. package/dist/skills/skill-system/skill-validation.d.ts +29 -0
  1098. package/dist/skills/skill-system/skill-validation.js +154 -0
  1099. package/dist/skills/tool-access.d.ts +30 -0
  1100. package/dist/skills/tool-access.js +58 -0
  1101. package/dist/skills/tools/agent-tool.d.ts +102 -0
  1102. package/dist/skills/tools/agent-tool.js +159 -0
  1103. package/dist/skills/tools/ask-user-tool.d.ts +80 -0
  1104. package/dist/skills/tools/ask-user-tool.js +121 -0
  1105. package/dist/skills/tools/brief-tool.d.ts +74 -0
  1106. package/dist/skills/tools/brief-tool.js +95 -0
  1107. package/dist/skills/tools/browser-tool.d.ts +114 -0
  1108. package/dist/skills/tools/browser-tool.js +160 -0
  1109. package/dist/skills/tools/checkpoint-tool.d.ts +66 -0
  1110. package/dist/skills/tools/checkpoint-tool.js +102 -0
  1111. package/dist/skills/tools/config-tool.d.ts +61 -0
  1112. package/dist/skills/tools/config-tool.js +123 -0
  1113. package/dist/skills/tools/cron-tool.d.ts +96 -0
  1114. package/dist/skills/tools/cron-tool.js +165 -0
  1115. package/dist/skills/tools/edit-tool.d.ts +43 -0
  1116. package/dist/skills/tools/edit-tool.js +72 -0
  1117. package/dist/skills/tools/exec-tool.d.ts +117 -0
  1118. package/dist/skills/tools/exec-tool.js +354 -0
  1119. package/dist/skills/tools/file-management-tool.d.ts +90 -0
  1120. package/dist/skills/tools/file-management-tool.js +166 -0
  1121. package/dist/skills/tools/image-generate-tool.d.ts +74 -0
  1122. package/dist/skills/tools/image-generate-tool.js +91 -0
  1123. package/dist/skills/tools/instructions-tool.d.ts +65 -0
  1124. package/dist/skills/tools/instructions-tool.js +209 -0
  1125. package/dist/skills/tools/lsp-tool.d.ts +153 -0
  1126. package/dist/skills/tools/lsp-tool.js +230 -0
  1127. package/dist/skills/tools/media-cancel-tool.d.ts +30 -0
  1128. package/dist/skills/tools/media-cancel-tool.js +46 -0
  1129. package/dist/skills/tools/monitor-tool.d.ts +113 -0
  1130. package/dist/skills/tools/monitor-tool.js +129 -0
  1131. package/dist/skills/tools/music-generate-tool.d.ts +80 -0
  1132. package/dist/skills/tools/music-generate-tool.js +98 -0
  1133. package/dist/skills/tools/notebook-edit-tool.d.ts +15 -0
  1134. package/dist/skills/tools/notebook-edit-tool.js +206 -0
  1135. package/dist/skills/tools/patch-tool.d.ts +52 -0
  1136. package/dist/skills/tools/patch-tool.js +556 -0
  1137. package/dist/skills/tools/petdex-create-tool.d.ts +47 -0
  1138. package/dist/skills/tools/petdex-create-tool.js +95 -0
  1139. package/dist/skills/tools/plan-mode-tool.d.ts +98 -0
  1140. package/dist/skills/tools/plan-mode-tool.js +164 -0
  1141. package/dist/skills/tools/read-tool.d.ts +51 -0
  1142. package/dist/skills/tools/read-tool.js +88 -0
  1143. package/dist/skills/tools/search-tool.d.ts +112 -0
  1144. package/dist/skills/tools/search-tool.js +226 -0
  1145. package/dist/skills/tools/shell/bash-provider.d.ts +26 -0
  1146. package/dist/skills/tools/shell/bash-provider.js +125 -0
  1147. package/dist/skills/tools/shell/command-classification.d.ts +44 -0
  1148. package/dist/skills/tools/shell/command-classification.js +119 -0
  1149. package/dist/skills/tools/shell/command-semantics.d.ts +14 -0
  1150. package/dist/skills/tools/shell/command-semantics.js +87 -0
  1151. package/dist/skills/tools/shell/destructive-command-warning.d.ts +10 -0
  1152. package/dist/skills/tools/shell/destructive-command-warning.js +80 -0
  1153. package/dist/skills/tools/shell/exec-permissions.d.ts +52 -0
  1154. package/dist/skills/tools/shell/exec-permissions.js +277 -0
  1155. package/dist/skills/tools/shell/index.d.ts +18 -0
  1156. package/dist/skills/tools/shell/index.js +18 -0
  1157. package/dist/skills/tools/shell/powershell-provider.d.ts +15 -0
  1158. package/dist/skills/tools/shell/powershell-provider.js +80 -0
  1159. package/dist/skills/tools/shell/sandbox/helper-resolver.d.ts +7 -0
  1160. package/dist/skills/tools/shell/sandbox/helper-resolver.js +20 -0
  1161. package/dist/skills/tools/shell/sandbox/landlock-argv.d.ts +6 -0
  1162. package/dist/skills/tools/shell/sandbox/landlock-argv.js +13 -0
  1163. package/dist/skills/tools/shell/sandbox/platform.d.ts +3 -0
  1164. package/dist/skills/tools/shell/sandbox/platform.js +13 -0
  1165. package/dist/skills/tools/shell/sandbox/sandbox-launcher.d.ts +15 -0
  1166. package/dist/skills/tools/shell/sandbox/sandbox-launcher.js +59 -0
  1167. package/dist/skills/tools/shell/sandbox/sandbox-scope.d.ts +6 -0
  1168. package/dist/skills/tools/shell/sandbox/sandbox-scope.js +17 -0
  1169. package/dist/skills/tools/shell/sandbox/sandbox-types.d.ts +47 -0
  1170. package/dist/skills/tools/shell/sandbox/sandbox-types.js +1 -0
  1171. package/dist/skills/tools/shell/sandbox/seatbelt-profile.d.ts +6 -0
  1172. package/dist/skills/tools/shell/sandbox/seatbelt-profile.js +28 -0
  1173. package/dist/skills/tools/shell/shell-command.d.ts +54 -0
  1174. package/dist/skills/tools/shell/shell-command.js +347 -0
  1175. package/dist/skills/tools/shell/shell-exec.d.ts +38 -0
  1176. package/dist/skills/tools/shell/shell-exec.js +202 -0
  1177. package/dist/skills/tools/shell/shell-provider.d.ts +85 -0
  1178. package/dist/skills/tools/shell/shell-provider.js +38 -0
  1179. package/dist/skills/tools/shell/subprocess-env.d.ts +6 -0
  1180. package/dist/skills/tools/shell/subprocess-env.js +87 -0
  1181. package/dist/skills/tools/shell/task-output.d.ts +44 -0
  1182. package/dist/skills/tools/shell/task-output.js +137 -0
  1183. package/dist/skills/tools/skill-tool.d.ts +106 -0
  1184. package/dist/skills/tools/skill-tool.js +265 -0
  1185. package/dist/skills/tools/sleep-tool.d.ts +49 -0
  1186. package/dist/skills/tools/sleep-tool.js +81 -0
  1187. package/dist/skills/tools/structured-output-tool.d.ts +116 -0
  1188. package/dist/skills/tools/structured-output-tool.js +176 -0
  1189. package/dist/skills/tools/stt-tool.d.ts +33 -0
  1190. package/dist/skills/tools/stt-tool.js +58 -0
  1191. package/dist/skills/tools/task-tool.d.ts +125 -0
  1192. package/dist/skills/tools/task-tool.js +390 -0
  1193. package/dist/skills/tools/team-tool.d.ts +156 -0
  1194. package/dist/skills/tools/team-tool.js +173 -0
  1195. package/dist/skills/tools/three-d-generate-tool.d.ts +46 -0
  1196. package/dist/skills/tools/three-d-generate-tool.js +66 -0
  1197. package/dist/skills/tools/tool-search-tool.d.ts +62 -0
  1198. package/dist/skills/tools/tool-search-tool.js +187 -0
  1199. package/dist/skills/tools/tts-tool.d.ts +50 -0
  1200. package/dist/skills/tools/tts-tool.js +58 -0
  1201. package/dist/skills/tools/video-edit-tool.d.ts +72 -0
  1202. package/dist/skills/tools/video-edit-tool.js +84 -0
  1203. package/dist/skills/tools/video-generate-tool.d.ts +162 -0
  1204. package/dist/skills/tools/video-generate-tool.js +178 -0
  1205. package/dist/skills/tools/video-merge-tool.d.ts +105 -0
  1206. package/dist/skills/tools/video-merge-tool.js +95 -0
  1207. package/dist/skills/tools/video-upscale-tool.d.ts +45 -0
  1208. package/dist/skills/tools/video-upscale-tool.js +57 -0
  1209. package/dist/skills/tools/voice-clone-tool.d.ts +40 -0
  1210. package/dist/skills/tools/voice-clone-tool.js +58 -0
  1211. package/dist/skills/tools/web-answer-tool.d.ts +27 -0
  1212. package/dist/skills/tools/web-answer-tool.js +124 -0
  1213. package/dist/skills/tools/web-fetch-tool.d.ts +80 -0
  1214. package/dist/skills/tools/web-fetch-tool.js +95 -0
  1215. package/dist/skills/tools/web-research-tool.d.ts +48 -0
  1216. package/dist/skills/tools/web-research-tool.js +254 -0
  1217. package/dist/skills/tools/web-search-tool.d.ts +46 -0
  1218. package/dist/skills/tools/web-search-tool.js +95 -0
  1219. package/dist/skills/tools/workflow-tool.d.ts +45 -0
  1220. package/dist/skills/tools/workflow-tool.js +113 -0
  1221. package/dist/skills/tools/worktree-tool.d.ts +69 -0
  1222. package/dist/skills/tools/worktree-tool.js +147 -0
  1223. package/dist/skills/tools/write-tool.d.ts +45 -0
  1224. package/dist/skills/tools/write-tool.js +83 -0
  1225. package/dist/skills/tools.d.ts +45 -0
  1226. package/dist/skills/tools.js +165 -0
  1227. package/dist/skills/web-search/brave-source.d.ts +2 -0
  1228. package/dist/skills/web-search/brave-source.js +36 -0
  1229. package/dist/skills/web-search/crawl4ai-extractor.d.ts +15 -0
  1230. package/dist/skills/web-search/crawl4ai-extractor.js +92 -0
  1231. package/dist/skills/web-search/embedding-rerank.d.ts +13 -0
  1232. package/dist/skills/web-search/embedding-rerank.js +44 -0
  1233. package/dist/skills/web-search/exa-source.d.ts +2 -0
  1234. package/dist/skills/web-search/exa-source.js +43 -0
  1235. package/dist/skills/web-search/multi-source-backend.d.ts +23 -0
  1236. package/dist/skills/web-search/multi-source-backend.js +99 -0
  1237. package/dist/skills/web-search/redis-source-cache.d.ts +6 -0
  1238. package/dist/skills/web-search/redis-source-cache.js +44 -0
  1239. package/dist/skills/web-search/search-svc-source.d.ts +4 -0
  1240. package/dist/skills/web-search/search-svc-source.js +64 -0
  1241. package/dist/skills/web-search/searxng-source.d.ts +2 -0
  1242. package/dist/skills/web-search/searxng-source.js +91 -0
  1243. package/dist/skills/web-search/serper-source.d.ts +2 -0
  1244. package/dist/skills/web-search/serper-source.js +33 -0
  1245. package/dist/skills/web-search/source-factory.d.ts +5 -0
  1246. package/dist/skills/web-search/source-factory.js +15 -0
  1247. package/dist/skills/web-search/stability.d.ts +26 -0
  1248. package/dist/skills/web-search/stability.js +57 -0
  1249. package/dist/transport/acp-event-emitter.d.ts +21 -0
  1250. package/dist/transport/acp-event-emitter.js +142 -0
  1251. package/dist/transport/acp-event-emitter.test.d.ts +1 -0
  1252. package/dist/transport/acp-event-emitter.test.js +87 -0
  1253. package/dist/transport/acp-server.d.ts +169 -0
  1254. package/dist/transport/acp-server.js +480 -0
  1255. package/dist/transport/acp-server.test.d.ts +1 -0
  1256. package/dist/transport/acp-server.test.js +230 -0
  1257. package/dist/transport/index.d.ts +7 -0
  1258. package/dist/transport/index.js +5 -0
  1259. package/dist/transport/io-transport.d.ts +19 -0
  1260. package/dist/transport/io-transport.js +8 -0
  1261. package/package.json +2 -2
@@ -0,0 +1,1017 @@
1
+ /**
2
+ * Tool loop state machine - CC query.ts aligned.
3
+ *
4
+ * Architecture:
5
+ * - Infinite while(true) loop with centralized State object (CC parity)
6
+ * - 7 labeled continue sites matching CC's query loop transitions
7
+ * - Error Withholding: 413 / max_output_tokens / media errors are
8
+ * withheld from callers during recovery attempts
9
+ * - Context Collapse drain: staged collapses committed on 413
10
+ * BEFORE falling through to reactive compact
11
+ * - Media error recovery: image/media errors -> reactive compact retry
12
+ * - Hermes delta suppression preserved
13
+ * - StreamingToolExecutor preserved
14
+ * - Sub-agent fork depth preserved
15
+ * - Skill learning evaluation preserved
16
+ *
17
+ * CC reference: src/query.ts queryLoop()
18
+ *
19
+ * Zero imports from express/pg/ioredis/ws.
20
+ */
21
+ import { accumulateToolCalls } from "../runtime/ports/index.js";
22
+ import { fireHook } from "../contracts/fire-hook.js";
23
+ import { advanceToolLoopState, applyToolChoicePolicy, buildAssistantToolCallMessage, buildToolResultMessage, recoverToolLoopStateFromChatConversation, settleToolLoopState, calculateTokenWarningState, resolveApiErrorRecovery, resolveOutputTokenEscalation, shouldAbortTurn, createTurnLoopGuardState, shouldAttemptReactiveCompact, createReactiveCompactState, classifyError, createCollapseStore, recoverContextCollapseFromOverflow, } from "../orchestration/index.js";
24
+ import { DEFAULT_TEMPERATURE, MAX_CONSECUTIVE_FAILURES, MAX_IDENTICAL_CALL_REPEATS, DEFAULT_CONTEXT_WINDOW_TOKENS, RESPONSE_BUFFER_TOKENS, DEFAULT_MAX_OUTPUT_TOKENS, DEFAULT_MODEL_MAX_OUTPUT_TOKENS, MAX_OUTPUT_TOKENS_RECOVERY_LIMIT, ESCALATED_MAX_OUTPUT_TOKENS, MAX_API_RETRIES, } from "./tunable-defaults.js";
25
+ import { createToolMediaResultEvents, createToolResultEvent } from "./tool-loop/tool-result-events.js";
26
+ import { createToolSidecarEvents } from "./tool-loop/artifact-events.js";
27
+ import { findLastToolError, isEmptyToolResult, resolveToolLoopBudget, summarizeToolInput, synthesizeFallbackContent, } from "./tool-loop/loop-helpers.js";
28
+ import { isMaxOutputTokensTruncation, isMediaSizeError, isPromptTooLongError, } from "./tool-loop/recovery-helpers.js";
29
+ import { executeSingleLLMRound } from "./tool-loop/single-round.js";
30
+ import { runCompressionPipeline } from "./tool-loop/compression-pipeline.js";
31
+ import { handleStreamError } from "./tool-loop/stream-error-recovery.js";
32
+ import { resolveCompletionActionPolicy } from "./tool-loop/completion-action-policy.js";
33
+ import { resolveCompletionStopPolicy } from "./tool-loop/completion-stop-policy.js";
34
+ import { resolveBudgetContinuationPolicy } from "./tool-loop/budget-continuation-policy.js";
35
+ import { resolveToolUsageSkillInstruction } from "./tool-loop/skill-instruction-policy.js";
36
+ import { newVariantFailureNudges, recordToolFailureResult, splitVariantToolCalls, variantBlockNudge, } from "./tool-loop/tool-failure-policy.js";
37
+ // - Main tool loop -
38
+ /**
39
+ * Execute the tool loop -CC query.ts queryLoop() aligned.
40
+ *
41
+ * Yields TurnEvent stream. The caller (Agent class) wraps this with
42
+ * start/end lifecycle and error handling.
43
+ *
44
+ * Architecture: infinite while(true) with centralized State + 7 continue
45
+ * labels. Error withholding gates recoverable errors through collapse
46
+ * drain ->reactive compact ->escalation ->recovery message pipeline
47
+ * before surfacing to callers.
48
+ */
49
+ export async function* executeToolLoop(params, transport, toolInvoker, log) {
50
+ const { turnId, sessionId, messages: inputMessages, tools, model, apiKey, temperature = DEFAULT_TEMPERATURE, hooks, signal, } = params;
51
+ const hookCtx = { sessionId, turnId };
52
+ const maxTurns = params.maxTurns ?? 0;
53
+ const querySource = params.querySource;
54
+ // - Tool eligibility filtering (allow/ask/deny + unified risk) -
55
+ const eligibility = params.runtimePorts.resolveToolEligibility(tools, params.toolEligibilityContext);
56
+ const effectiveTools = eligibility.eligibleTools;
57
+ // Emit blocked tool events
58
+ for (const blocked of eligibility.blockedTools) {
59
+ yield { type: "tool_blocked", turnId, callId: "", name: blocked.toolName, reason: "blocked-by-policy" };
60
+ }
61
+ // - No tools: single LLM call, no loop -
62
+ if (!effectiveTools.length) {
63
+ yield* executeSingleLLMRound(turnId, model, inputMessages, apiKey, temperature, signal, transport, log);
64
+ return;
65
+ }
66
+ // - Immutable setup -
67
+ const toolBudget = resolveToolLoopBudget(params.maxRounds);
68
+ // Turn-loop-guard config (CC-aligned)
69
+ const guardConfig = {
70
+ contextWindowTokens: params.contextWindowTokens ?? DEFAULT_CONTEXT_WINDOW_TOKENS,
71
+ responseBufferTokens: RESPONSE_BUFFER_TOKENS,
72
+ maxOutputTokens: params.maxOutputTokens ?? DEFAULT_MAX_OUTPUT_TOKENS,
73
+ abortSignal: signal,
74
+ reactiveCompactEnabled: true,
75
+ outputEscalationEnabled: true,
76
+ };
77
+ // Skill learning metrics (loop-local, not on State)
78
+ const distinctToolNames = new Set();
79
+ let totalToolCallCount = 0;
80
+ // Mutable tool list -refreshed between turns if refreshTools callback provided (CC parity)
81
+ let currentTools = effectiveTools;
82
+ // Pending tool use summary -fire-and-forget promise from previous turn (CC pendingToolUseSummary parity)
83
+ let pendingToolUseSummary;
84
+ let requiredToolChoiceSatisfied = false;
85
+ let requiredToolChoiceRetryCount = 0;
86
+ // - Mutable cross-iteration state (CC State parity) -
87
+ // The loop body destructures this at the top of each iteration.
88
+ // Continue sites write `state = { ...next }` instead of N separate assignments.
89
+ let state = {
90
+ messages: [...inputMessages],
91
+ maxOutputTokensRecoveryCount: 0,
92
+ hasAttemptedReactiveCompact: false,
93
+ maxOutputTokensOverride: undefined,
94
+ turnCount: 1,
95
+ transition: undefined,
96
+ guardState: createTurnLoopGuardState(guardConfig),
97
+ reactiveCompactState: createReactiveCompactState(),
98
+ toolLoopState: recoverToolLoopStateFromChatConversation({
99
+ maxRounds: toolBudget,
100
+ replayMessages: [...inputMessages],
101
+ }).state,
102
+ consecutiveFailedRounds: 0,
103
+ finalText: "",
104
+ totalUsage: { inputTokens: 0, outputTokens: 0 },
105
+ collapseStore: createCollapseStore(),
106
+ currentModel: model,
107
+ consecutive529Errors: 0,
108
+ consecutiveApiRetries: 0,
109
+ stopHookActive: undefined,
110
+ lastResponseId: undefined,
111
+ snipRemovedIds: new Set(),
112
+ contentReplacementState: params.runtimePorts.createContentReplacementState(),
113
+ budgetContinuationCount: 0,
114
+ lastBudgetDeltaTokens: 0,
115
+ lastBudgetGlobalTokens: 0,
116
+ identicalCallCounts: new Map(),
117
+ toolFailureCounts: new Map(),
118
+ fileReadCounts: new Map(),
119
+ recoveryTrace: new Map(),
120
+ };
121
+ // P0: hard iteration cap -safety net against infinite recovery loops.
122
+ // Unlike turnCount (only incremented on successful tool-call rounds),
123
+ // this counter increments on EVERY while-loop iteration including
124
+ // recovery retries. CC relies on bounded retry limits per recovery path;
125
+ // this provides a catch-all for any path that might loop unboundedly.
126
+ const MAX_TOTAL_ITERATIONS = Math.max(maxTurns * 5, 200);
127
+ let totalIterations = 0;
128
+ // Record + emit a recovery event. Centralizes the per-turn recovery trace so the
129
+ // path a turn took is observable (surfaced on the final `end` event). Named
130
+ // emitRecovery, not `recovery`, to avoid shadowing the local resolveApiErrorRecovery
131
+ // result inside the stream-error handler.
132
+ const emitRecovery = (action, detail) => {
133
+ state.recoveryTrace.set(action, (state.recoveryTrace.get(action) ?? 0) + 1);
134
+ return { type: "recovery", turnId, action, detail };
135
+ };
136
+ // Build the terminal `end` event, attaching the recovery trace when non-empty.
137
+ const endEvent = (content) => ({
138
+ type: "end",
139
+ turnId,
140
+ content,
141
+ usage: state.totalUsage,
142
+ model: state.currentModel,
143
+ ...(state.recoveryTrace.size > 0 ? { recoveryTrace: Object.fromEntries(state.recoveryTrace) } : {}),
144
+ });
145
+ // - Main loop (CC while(true) parity) -
146
+ // eslint-disable-next-line no-constant-condition
147
+ while (true) {
148
+ // P0: hard iteration cap -terminate if recovery loops go unbounded
149
+ totalIterations++;
150
+ if (totalIterations > MAX_TOTAL_ITERATIONS) {
151
+ log.info(`hard iteration cap reached (${MAX_TOTAL_ITERATIONS}), forcing completion`);
152
+ const endContent = state.finalText || synthesizeFallbackContent(state.messages, log);
153
+ yield endEvent(endContent);
154
+ return;
155
+ }
156
+ // Destructure state at the top of each iteration (CC pattern)
157
+ const { messages, maxOutputTokensRecoveryCount, maxOutputTokensOverride, turnCount, guardState, reactiveCompactState, collapseStore, } = state;
158
+ let { toolLoopState } = state;
159
+ // - Pre-round checks -
160
+ // Yield pending tool use summary from previous turn (CC pendingToolUseSummary parity)
161
+ if (pendingToolUseSummary) {
162
+ try {
163
+ const summary = await pendingToolUseSummary;
164
+ if (summary) {
165
+ yield { type: "tool_use_summary", turnId, summary };
166
+ }
167
+ }
168
+ catch { /* non-blocking */ }
169
+ pendingToolUseSummary = undefined;
170
+ }
171
+ // Tool refresh between turns (CC refreshTools parity)
172
+ if (params.refreshTools && turnCount > 1) {
173
+ const refreshed = params.refreshTools();
174
+ if (refreshed !== currentTools) {
175
+ currentTools = refreshed;
176
+ log.debug(`tools refreshed: ${refreshed.length} tools`);
177
+ }
178
+ }
179
+ // Abort check
180
+ if (shouldAbortTurn(guardState, guardConfig)) {
181
+ log.info(`turn aborted by guard at turn ${turnCount}`);
182
+ yield { type: "error", turnId, error: "Turn aborted", code: "ABORTED", usage: state.totalUsage };
183
+ return;
184
+ }
185
+ // Token budget pre-check
186
+ const tokenWarning = calculateTokenWarningState(guardState, guardConfig);
187
+ if (tokenWarning.level === "blocking") {
188
+ if (tokenWarning.reason === "prompt_too_long" &&
189
+ shouldAttemptReactiveCompact(reactiveCompactState)) {
190
+ reactiveCompactState.attemptedThisTurn = true;
191
+ guardState.hasAttemptedReactiveCompact = true;
192
+ log.info(`token budget blocking (${tokenWarning.reason}), reactive compact needed`);
193
+ yield emitRecovery("reactive_compact", "token budget pre-check");
194
+ }
195
+ log.info(`token budget blocking (${tokenWarning.reason}), ending tool loop`);
196
+ break;
197
+ }
198
+ if (tokenWarning.level === "warning") {
199
+ log.info(`token budget warning: ${tokenWarning.usagePercent}% used, ${tokenWarning.remainingTokens} remaining`);
200
+ }
201
+ // - Context compression pipeline (CC query.ts parity) -
202
+ // tool-result-budget → snip → microcompact → collapse → autocompact → whitespace
203
+ // filter. Extracted to tool-loop/compression-pipeline.ts (see it for stage detail);
204
+ // no control-flow escape, so it is a clean `yield*` boundary.
205
+ let messagesForQuery = yield* runCompressionPipeline({
206
+ messages,
207
+ contentReplacementState: state.contentReplacementState,
208
+ snipRemovedIds: state.snipRemovedIds,
209
+ collapseStore,
210
+ guardState,
211
+ guardConfig,
212
+ runtimePorts: params.runtimePorts,
213
+ hooks,
214
+ hookCtx,
215
+ sessionId,
216
+ currentModel: state.currentModel,
217
+ log,
218
+ recovery: emitRecovery,
219
+ onAutocompact: () => { state.hasAttemptedReactiveCompact = false; },
220
+ });
221
+ // - Build tool loop request -
222
+ const roundToolChoice = params.toolChoice === "required" && requiredToolChoiceSatisfied
223
+ ? "auto"
224
+ : (params.toolChoice ?? "auto");
225
+ const toolChoiceResult = applyToolChoicePolicy({
226
+ tools: currentTools,
227
+ toolChoice: roundToolChoice,
228
+ });
229
+ const repaired = recoverToolLoopStateFromChatConversation({
230
+ maxRounds: toolBudget,
231
+ replayMessages: messagesForQuery,
232
+ lastStopReason: toolLoopState.lastStopReason,
233
+ options: { stopReason: toolLoopState.lastStopReason },
234
+ });
235
+ const requestMessages = toolChoiceResult.extraSystemPrompt
236
+ ? [
237
+ { role: "system", content: toolChoiceResult.extraSystemPrompt },
238
+ ...repaired.state.replayMessages,
239
+ ]
240
+ : repaired.state.replayMessages;
241
+ toolLoopState = repaired.state;
242
+ if (repaired.recoveryActions.length > 0) {
243
+ log.debug(`tool loop recovery: ${repaired.recoveryActions.map((a) => a.detail ?? a.kind).join("; ")}`);
244
+ }
245
+ log.debug(`turn ${turnCount}, messages: ${requestMessages.length}`);
246
+ // Hook: turn.before_inference
247
+ fireHook(hooks, "turn.before_inference", { ...hookCtx, model: state.currentModel }, log);
248
+ // - Streaming LLM round with Hermes delta suppression -
249
+ let hasToolCalls = false;
250
+ const textChunks = [];
251
+ const toolCallAccumulator = new Map();
252
+ let finishReason = "stop";
253
+ let roundUsage;
254
+ let streamError = null;
255
+ // Error Withholding: track whether the response is a recoverable error
256
+ let withheldError = false;
257
+ let sawTerminalChunk = false;
258
+ // Anthropic thinking blocks -accumulated for passback in subsequent requests
259
+ const thinkingChunks = [];
260
+ const thinkingBlocks = [];
261
+ try {
262
+ for await (const chunk of transport.stream({
263
+ model: state.currentModel,
264
+ messages: requestMessages,
265
+ tools: toolChoiceResult.tools,
266
+ toolChoice: toolChoiceResult.normalizedToolChoice ??
267
+ "auto",
268
+ temperature,
269
+ maxTokens: (maxOutputTokensOverride ?? guardState.currentMaxOutputTokens) || undefined,
270
+ streamRequired: params.streamRequired,
271
+ previousResponseId: state.lastResponseId,
272
+ reasoning: params.reasoning,
273
+ promptCacheKey: params.promptCacheKey,
274
+ promptCacheRetention: params.promptCacheRetention,
275
+ serviceTier: params.serviceTier,
276
+ openaiBuiltinTools: params.openaiBuiltinTools,
277
+ maxToolCalls: params.maxToolCalls,
278
+ parallelToolCalls: params.parallelToolCalls,
279
+ textVerbosity: params.textVerbosity,
280
+ }, apiKey, signal)) {
281
+ switch (chunk.type) {
282
+ case "delta":
283
+ textChunks.push(chunk.text);
284
+ break;
285
+ case "tool_call_delta":
286
+ hasToolCalls = true;
287
+ accumulateToolCalls(toolCallAccumulator, chunk);
288
+ break;
289
+ case "reasoning_delta":
290
+ thinkingChunks.push(chunk.text);
291
+ break;
292
+ case "reasoning_block_complete":
293
+ // Finalize thinking block with accumulated text + signature.
294
+ // CC parity (stripSignatureBlocks): only store blocks with
295
+ // valid signatures. DeepSeek may not emit signature_delta,
296
+ // leaving signature as "". Sending empty signatures back
297
+ // to the API causes 400 errors.
298
+ if (chunk.signature) {
299
+ thinkingBlocks.push({
300
+ thinking: thinkingChunks.join(""),
301
+ signature: chunk.signature,
302
+ });
303
+ }
304
+ thinkingChunks.length = 0;
305
+ break;
306
+ case "usage":
307
+ roundUsage = {
308
+ inputTokens: chunk.promptTokens,
309
+ outputTokens: chunk.completionTokens,
310
+ reasoningTokens: chunk.reasoningTokens,
311
+ cacheRead: chunk.cacheReadTokens,
312
+ cacheWrite: chunk.cacheCreationTokens,
313
+ };
314
+ break;
315
+ case "response_id":
316
+ // Capture for server-side context chain (previous_response_id)
317
+ state.lastResponseId = chunk.id;
318
+ break;
319
+ case "annotations":
320
+ // Forward citation annotations to UI
321
+ yield { type: "annotations", turnId, annotations: chunk.annotations };
322
+ break;
323
+ case "builtin_tool_status":
324
+ // Forward platform builtin tool progress as heartbeat
325
+ yield { type: "heartbeat", turnId, message: `${chunk.toolType}: ${chunk.event}` };
326
+ break;
327
+ case "done":
328
+ sawTerminalChunk = true;
329
+ finishReason = chunk.finishReason;
330
+ break;
331
+ }
332
+ }
333
+ // Hook: turn.after_inference (success path)
334
+ if (!hasToolCalls) {
335
+ fireHook(hooks, "turn.after_inference", { ...hookCtx, model: state.currentModel }, log);
336
+ }
337
+ // Post-sampling hooks -fire-and-forget (CC executePostSamplingHooks parity)
338
+ if (params.postSamplingHooks && params.postSamplingHooks.length > 0) {
339
+ const pshModel = state.currentModel;
340
+ for (const hook of params.postSamplingHooks) {
341
+ try {
342
+ void hook({ messages: [...messagesForQuery], model: pshModel, sessionId });
343
+ }
344
+ catch { /* non-blocking */ }
345
+ }
346
+ }
347
+ }
348
+ catch (err) {
349
+ // Stream-error recovery (FallbackTriggeredError / stale-connection / max_tokens
350
+ // overflow / 429·529 transient) is extracted to tool-loop/stream-error-recovery.ts.
351
+ // It yields any user-facing events and returns a control-flow decision the loop
352
+ // applies here — keeping the loop's densest branch behind one named boundary.
353
+ const decision = yield* handleStreamError(err, {
354
+ state,
355
+ guardState,
356
+ fallbackModel: params.fallbackModel,
357
+ signal,
358
+ querySource,
359
+ turnId,
360
+ log,
361
+ emitRecovery,
362
+ });
363
+ if (decision.kind === "return")
364
+ return;
365
+ if (decision.kind === "continue") {
366
+ state = { ...state, ...decision.patch };
367
+ continue;
368
+ }
369
+ streamError = decision.streamError;
370
+ }
371
+ if (!streamError && !sawTerminalChunk) {
372
+ const message = "LLM stream closed before a terminal event; the response was likely truncated upstream.";
373
+ fireHook(hooks, "stop.failure", { sessionId, reason: "RETRYABLE_TRANSIENT", error: message }, log);
374
+ yield { type: "error", turnId, error: message, code: "RETRYABLE_TRANSIENT", usage: state.totalUsage };
375
+ return;
376
+ }
377
+ // Hook: turn.after_inference (error path)
378
+ if (streamError) {
379
+ fireHook(hooks, "turn.after_inference", { ...hookCtx, model: state.currentModel, response: { error: streamError.message } }, log);
380
+ }
381
+ // - Handle LLM errors with Error Withholding (CC parity) -
382
+ if (streamError) {
383
+ // Check if this is a recoverable prompt-too-long error
384
+ if (isPromptTooLongError(streamError)) {
385
+ // Withhold the error -attempt recovery before surfacing
386
+ withheldError = true;
387
+ log.info(`withheld prompt_too_long error (status=${streamError.status})`);
388
+ }
389
+ else if (isMediaSizeError(streamError)) {
390
+ // P1: Media error withholding (CC ImageSizeError/ImageResizeError parity)
391
+ // Withhold for reactive compact strip-retry
392
+ withheldError = true;
393
+ log.info(`withheld media_size error (status=${streamError.status})`);
394
+ }
395
+ else {
396
+ // Non-recoverable errors: handle via turn-loop-guard
397
+ const recovery = resolveApiErrorRecovery({ status: streamError.status ?? 500, message: streamError.message }, guardState, guardConfig);
398
+ if (recovery.action === "reactive_compact" &&
399
+ shouldAttemptReactiveCompact(reactiveCompactState)) {
400
+ reactiveCompactState.attemptedThisTurn = true;
401
+ guardState.hasAttemptedReactiveCompact = true;
402
+ yield emitRecovery("reactive_compact", `API ${streamError.status ?? 500}: ${streamError.message}`);
403
+ }
404
+ if (recovery.action === "retry") {
405
+ const nextRetries = (state.consecutiveApiRetries ?? 0) + 1;
406
+ if (nextRetries > MAX_API_RETRIES) {
407
+ log.info(`API retry limit reached (${MAX_API_RETRIES}), aborting`);
408
+ const category = classifyError(streamError.status, streamError.message);
409
+ yield { type: "error", turnId, error: streamError.message, code: category, usage: state.totalUsage };
410
+ return;
411
+ }
412
+ yield emitRecovery("retry", recovery.reason);
413
+ state = { ...state, consecutiveApiRetries: nextRetries, transition: undefined };
414
+ continue;
415
+ }
416
+ // Unrecoverable
417
+ const category = classifyError(streamError.status, streamError.message);
418
+ fireHook(hooks, "stop.failure", { sessionId, reason: category, error: streamError.message }, log);
419
+ yield { type: "error", turnId, error: streamError.message, code: category, usage: state.totalUsage };
420
+ return;
421
+ }
422
+ }
423
+ // Accumulate usage
424
+ if (roundUsage) {
425
+ state.totalUsage.inputTokens += roundUsage.inputTokens;
426
+ state.totalUsage.outputTokens += roundUsage.outputTokens;
427
+ if (roundUsage.reasoningTokens) {
428
+ state.totalUsage.reasoningTokens = (state.totalUsage.reasoningTokens ?? 0) + roundUsage.reasoningTokens;
429
+ }
430
+ // CC accumulateUsage parity: forward cache tokens
431
+ if (roundUsage.cacheRead) {
432
+ state.totalUsage.cacheRead = (state.totalUsage.cacheRead ?? 0) + roundUsage.cacheRead;
433
+ }
434
+ if (roundUsage.cacheWrite) {
435
+ state.totalUsage.cacheWrite = (state.totalUsage.cacheWrite ?? 0) + roundUsage.cacheWrite;
436
+ }
437
+ }
438
+ // Turn-loop-guard: update token state from usage feedback
439
+ if (roundUsage?.inputTokens) {
440
+ guardState.promptTokens = roundUsage.inputTokens;
441
+ }
442
+ const roundText = textChunks.join("");
443
+ // Convert accumulated tool call deltas to OpenAiToolCall[]
444
+ let toolCalls = [...toolCallAccumulator.values()].map((tc) => ({
445
+ id: tc.id || `tc_${turnId}_${turnCount}_${Math.random().toString(36).slice(2, 8)}`,
446
+ type: "function",
447
+ function: { name: tc.name, arguments: tc.arguments },
448
+ }));
449
+ // - No tool calls: recovery checks + completion -
450
+ if (toolCalls.length === 0 && !hasToolCalls) {
451
+ if (roundText) {
452
+ state.finalText = roundText;
453
+ }
454
+ if (params.toolChoice === "required" &&
455
+ !requiredToolChoiceSatisfied &&
456
+ currentTools.length > 0 &&
457
+ requiredToolChoiceRetryCount < 2) {
458
+ requiredToolChoiceRetryCount++;
459
+ const toolNames = currentTools
460
+ .map((tool) => tool.function.name)
461
+ .filter(Boolean)
462
+ .slice(0, 8)
463
+ .join(", ");
464
+ state = {
465
+ ...state,
466
+ messages: [
467
+ ...messages,
468
+ {
469
+ role: "user",
470
+ content: `You must call one available tool before answering. ` +
471
+ `Available tools for this request: ${toolNames}. ` +
472
+ `Do not answer from memory, prior context, or guesses.`,
473
+ },
474
+ ],
475
+ finalText: "",
476
+ transition: { reason: "next_turn" },
477
+ };
478
+ continue;
479
+ }
480
+ // - 1. Withheld prompt-too-long recovery (CC collapse_drain_retry + reactive_compact_retry) -
481
+ if (withheldError && streamError && isPromptTooLongError(streamError)) {
482
+ // CC label: collapse_drain_retry
483
+ // First: drain all staged context-collapses.
484
+ // Skip if we already drained on the previous iteration.
485
+ if (state.transition?.reason !== "collapse_drain_retry") {
486
+ const drained = recoverContextCollapseFromOverflow(messagesForQuery, collapseStore);
487
+ if (drained.committed > 0) {
488
+ log.info(`collapse drain: committed ${drained.committed} stages`);
489
+ yield emitRecovery("collapse_drain", `${drained.committed} stages committed`);
490
+ state = {
491
+ ...state,
492
+ messages: drained.messages,
493
+ transition: { reason: "collapse_drain_retry", committed: drained.committed },
494
+ };
495
+ continue; // CC: collapse_drain_retry
496
+ }
497
+ }
498
+ // CC label: reactive_compact_retry
499
+ // Collapse drain exhausted or insufficient -try reactive compact.
500
+ if (shouldAttemptReactiveCompact(reactiveCompactState)) {
501
+ reactiveCompactState.attemptedThisTurn = true;
502
+ guardState.hasAttemptedReactiveCompact = true;
503
+ log.info("withheld 413: reactive compact attempt");
504
+ yield emitRecovery("reactive_compact", "withheld prompt_too_long");
505
+ state = {
506
+ ...state,
507
+ hasAttemptedReactiveCompact: true,
508
+ transition: { reason: "reactive_compact_retry" },
509
+ };
510
+ continue; // CC: reactive_compact_retry
511
+ }
512
+ // Recovery exhausted -surface the withheld error
513
+ log.info("withheld 413: recovery exhausted, surfacing error");
514
+ // CC executeStopFailureHooks parity: fire stop.failure on recovery exhaustion
515
+ fireHook(hooks, "stop.failure", { sessionId, reason: "prompt_too_long", error: streamError.message }, log);
516
+ yield { type: "error", turnId, error: streamError.message, code: "PROMPT_TOO_LONG", usage: state.totalUsage };
517
+ return;
518
+ }
519
+ // - 1b. Withheld media error recovery (CC ImageSizeError strip-retry) -
520
+ if (withheldError && streamError && isMediaSizeError(streamError)) {
521
+ if (shouldAttemptReactiveCompact(reactiveCompactState)) {
522
+ reactiveCompactState.attemptedThisTurn = true;
523
+ guardState.hasAttemptedReactiveCompact = true;
524
+ log.info("withheld media error: reactive compact strip-retry");
525
+ yield emitRecovery("reactive_compact", "media error strip-retry");
526
+ state = {
527
+ ...state,
528
+ hasAttemptedReactiveCompact: true,
529
+ transition: { reason: "reactive_compact_retry" },
530
+ };
531
+ continue; // CC: reactive_compact_retry (media variant)
532
+ }
533
+ // Recovery exhausted -surface as image_error
534
+ log.info("withheld media error: recovery exhausted");
535
+ fireHook(hooks, "stop.failure", { sessionId, reason: "media_error", error: streamError.message }, log);
536
+ yield { type: "error", turnId, error: streamError.message, code: "IMAGE_ERROR", usage: state.totalUsage };
537
+ return;
538
+ }
539
+ // - 2. Max output tokens recovery (CC max_output_tokens_escalate + max_output_tokens_recovery) -
540
+ if (isMaxOutputTokensTruncation(finishReason)) {
541
+ // Turn-loop-guard: escalate output budget
542
+ guardState.consecutiveTruncations += 1;
543
+ const modelMaxOutput = params.modelMaxOutputTokens ?? DEFAULT_MODEL_MAX_OUTPUT_TOKENS;
544
+ const escalation = resolveOutputTokenEscalation(guardState, guardConfig, modelMaxOutput);
545
+ // CC label: max_output_tokens_escalate
546
+ // First escalation: retry with higher output token limit (no message injection)
547
+ if (escalation.shouldEscalate &&
548
+ maxOutputTokensOverride === undefined) {
549
+ guardState.currentMaxOutputTokens = escalation.newMax;
550
+ log.info(`max_output_tokens escalate: ${escalation.newMax} tokens`);
551
+ yield emitRecovery("output_escalation", `${escalation.newMax} tokens`);
552
+ state = {
553
+ ...state,
554
+ maxOutputTokensOverride: ESCALATED_MAX_OUTPUT_TOKENS,
555
+ transition: { reason: "max_output_tokens_escalate" },
556
+ };
557
+ continue; // CC: max_output_tokens_escalate
558
+ }
559
+ // CC label: max_output_tokens_recovery
560
+ // Escalation exhausted or already escalated -inject recovery message
561
+ if (maxOutputTokensRecoveryCount < MAX_OUTPUT_TOKENS_RECOVERY_LIMIT) {
562
+ const recoveryMsg = {
563
+ role: "user",
564
+ content: "Output token limit hit. Resume directly - no apology, no recap of what you were doing. " +
565
+ "Pick up mid-thought if that is where the cut happened. Break remaining work into smaller pieces.",
566
+ };
567
+ log.info(`max_output_tokens recovery #${maxOutputTokensRecoveryCount + 1}`);
568
+ yield emitRecovery("max_output_tokens_recovery", `attempt ${maxOutputTokensRecoveryCount + 1}`);
569
+ state = {
570
+ ...state,
571
+ messages: [...messagesForQuery, recoveryMsg],
572
+ maxOutputTokensRecoveryCount: maxOutputTokensRecoveryCount + 1,
573
+ maxOutputTokensOverride: undefined,
574
+ transition: { reason: "max_output_tokens_recovery", attempt: maxOutputTokensRecoveryCount + 1 },
575
+ };
576
+ continue; // CC: max_output_tokens_recovery
577
+ }
578
+ // Recovery exhausted -surface truncation as completion
579
+ log.info("max_output_tokens recovery exhausted, completing with partial content");
580
+ }
581
+ else {
582
+ guardState.consecutiveTruncations = 0;
583
+ }
584
+ // - 3. Normal completion path -
585
+ toolLoopState = settleToolLoopState(toolLoopState, {
586
+ replayMessages: messages,
587
+ lastStopReason: "completed",
588
+ });
589
+ const stopPolicy = await resolveCompletionStopPolicy({
590
+ hooks,
591
+ sessionId,
592
+ messages,
593
+ finalText: state.finalText,
594
+ thinkingBlocks,
595
+ log,
596
+ });
597
+ if (stopPolicy?.action === "end") {
598
+ yield endEvent(stopPolicy.content);
599
+ return;
600
+ }
601
+ if (stopPolicy?.action === "continue") {
602
+ state = {
603
+ ...state,
604
+ messages: stopPolicy.messages,
605
+ stopHookActive: stopPolicy.stopHookActive,
606
+ transition: stopPolicy.transition,
607
+ };
608
+ continue;
609
+ }
610
+ const budgetPolicy = resolveBudgetContinuationPolicy({
611
+ tokenBudget: params.tokenBudget,
612
+ totalUsage: state.totalUsage,
613
+ budgetContinuationCount: state.budgetContinuationCount,
614
+ lastBudgetDeltaTokens: state.lastBudgetDeltaTokens,
615
+ lastBudgetGlobalTokens: state.lastBudgetGlobalTokens,
616
+ messages,
617
+ finalText: state.finalText,
618
+ thinkingBlocks,
619
+ getBudgetContinuationMessage: params.runtimePorts.getBudgetContinuationMessage,
620
+ log,
621
+ });
622
+ if (budgetPolicy) {
623
+ yield emitRecovery("budget_continuation", budgetPolicy.recoveryDetail);
624
+ state = {
625
+ ...state,
626
+ messages: budgetPolicy.messages,
627
+ budgetContinuationCount: budgetPolicy.budgetContinuationCount,
628
+ lastBudgetDeltaTokens: budgetPolicy.lastBudgetDeltaTokens,
629
+ lastBudgetGlobalTokens: budgetPolicy.lastBudgetGlobalTokens,
630
+ transition: budgetPolicy.transition,
631
+ };
632
+ continue;
633
+ }
634
+ const completionPolicy = resolveCompletionActionPolicy({
635
+ inputMessages,
636
+ messages,
637
+ finalText: state.finalText,
638
+ thinkingBlocks,
639
+ stopHookActive: state.stopHookActive,
640
+ totalToolCallCount,
641
+ distinctToolNames,
642
+ log,
643
+ });
644
+ if (completionPolicy) {
645
+ state = {
646
+ ...state,
647
+ messages: completionPolicy.messages,
648
+ stopHookActive: completionPolicy.stopHookActive,
649
+ transition: completionPolicy.transition,
650
+ };
651
+ continue;
652
+ }
653
+ const skillInstruction = resolveToolUsageSkillInstruction({
654
+ totalToolCallCount,
655
+ distinctToolNames,
656
+ projectRoot: params.projectRoot,
657
+ });
658
+ if (skillInstruction) {
659
+ yield { type: "skill_instruction", turnId, instruction: skillInstruction };
660
+ }
661
+ // OpenAI format compensation (CC parity): when LLM ends with empty text
662
+ // after tool execution rounds, synthesize content from tool results so
663
+ // the user doesn't see a blank response.
664
+ const endContent = state.finalText || synthesizeFallbackContent(messages, log);
665
+ for (const text of textChunks) {
666
+ yield { type: "delta", turnId, text };
667
+ }
668
+ yield endEvent(endContent);
669
+ return;
670
+ }
671
+ // - Has tool calls ->execute them -
672
+ // Emit tool_call events for allowed calls (non-variant-blocked).
673
+ // Variant-blocked calls are suppressed from the event stream to prevent
674
+ // inflating the client's tool_call count with synthetic blocked responses.
675
+ // NOTE: This emission is done BEFORE blocking checks for the allowed subset,
676
+ // so we need to re-emit only for the final variantAllowed set below.
677
+ // Build assistant message with tool calls.
678
+ // CC parity: preserve text alongside tool_use (Anthropic content block coexistence).
679
+ // In OpenAI streaming, text deltas may arrive before tool_call_deltas;
680
+ // we keep that text so the LLM can reference its own reasoning in subsequent turns.
681
+ // A3 parity: For OpenAI-chat transport, reasoning_delta events accumulate in
682
+ // thinkingChunks but no reasoning_block_complete is emitted (Anthropic-only).
683
+ // Pass leftover thinkingChunks as reasoning_content so GLM/DeepSeek can see
684
+ // the model's reasoning chain across tool-call rounds.
685
+ const leftoverReasoning = thinkingBlocks.length === 0 && thinkingChunks.length > 0
686
+ ? thinkingChunks.join("")
687
+ : undefined;
688
+ messages.push(buildAssistantToolCallMessage(toolCalls, undefined, thinkingBlocks.length > 0 ? thinkingBlocks : undefined, leftoverReasoning));
689
+ // Advance tool loop state
690
+ toolLoopState = advanceToolLoopState(toolLoopState, {
691
+ replayMessages: messages,
692
+ pendingToolCallIds: toolCalls.map((tc) => tc.id),
693
+ completedToolCallIds: toolLoopState.completedToolCallIds,
694
+ lastStopReason: "tool_calls",
695
+ });
696
+ // - AP4: Pre-execution identical call detection -
697
+ // Block calls that exceed MAX_IDENTICAL_CALL_REPEATS BEFORE execution.
698
+ // This saves time (no wasted API/disk calls) and forces the LLM to adapt.
699
+ const identicalCallCounts = state.identicalCallCounts;
700
+ const allowedCalls = [];
701
+ const blockedByAP4 = [];
702
+ let identicalCallNudgeInjected = false;
703
+ for (const tc of toolCalls) {
704
+ const callKey = `${tc.function.name}::${tc.function.arguments}`;
705
+ const prev = identicalCallCounts.get(callKey) ?? 0;
706
+ identicalCallCounts.set(callKey, prev + 1);
707
+ if (prev + 1 > MAX_IDENTICAL_CALL_REPEATS) {
708
+ blockedByAP4.push(tc);
709
+ if (!identicalCallNudgeInjected) {
710
+ identicalCallNudgeInjected = true;
711
+ log.info(`AP4 blocked: ${tc.function.name} repeated ${prev + 1}x`);
712
+ }
713
+ }
714
+ else {
715
+ allowedCalls.push(tc);
716
+ }
717
+ }
718
+ // Synthesize error results for blocked calls (before executor runs)
719
+ const executedToolCallIds = [];
720
+ for (const tc of blockedByAP4) {
721
+ const repeatCount = identicalCallCounts.get(`${tc.function.name}::${tc.function.arguments}`);
722
+ // Extract last error from previous tool results for the same tool
723
+ const lastError = findLastToolError(messages, tc.function.name);
724
+ const errorMsg = lastError
725
+ ? `This exact tool call has been attempted ${repeatCount} times. Last error: ${lastError}. Do not retry. Report this error to the user.`
726
+ : `This exact tool call has been attempted ${repeatCount} times and keeps failing. Do not retry it. Report the issue to the user or try a completely different approach.`;
727
+ const msg = buildToolResultMessage(tc.id, { ok: false, error: errorMsg });
728
+ messages.push(msg);
729
+ executedToolCallIds.push(tc.id);
730
+ distinctToolNames.add(tc.function.name);
731
+ totalToolCallCount++;
732
+ yield {
733
+ type: "tool_result",
734
+ turnId,
735
+ callId: tc.id,
736
+ name: tc.function.name,
737
+ ok: false,
738
+ error: errorMsg,
739
+ };
740
+ }
741
+ // Inject nudge if any calls were blocked
742
+ if (blockedByAP4.length > 0) {
743
+ const lastToolError = findLastToolError(messages, blockedByAP4[0].function.name);
744
+ const nudgeMsg = {
745
+ role: "user",
746
+ content: `Tool calls were blocked because you repeated them with identical arguments too many times. ` +
747
+ (lastToolError
748
+ ? `The error was: "${lastToolError}". Tell the user about this error. `
749
+ : `The operation is not working. `) +
750
+ `Stop retrying and report the result to the user.`,
751
+ };
752
+ messages.push(nudgeMsg);
753
+ }
754
+ const variantPolicy = splitVariantToolCalls(allowedCalls, state.toolFailureCounts);
755
+ const variantAllowed = variantPolicy.allowed;
756
+ if (variantPolicy.blocked.length > 0) {
757
+ for (const blocked of variantPolicy.blocked) {
758
+ const tc = blocked.call;
759
+ const msg = buildToolResultMessage(tc.id, { ok: false, error: blocked.error });
760
+ messages.push(msg);
761
+ executedToolCallIds.push(tc.id);
762
+ distinctToolNames.add(tc.function.name);
763
+ totalToolCallCount++;
764
+ yield {
765
+ type: "tool_result",
766
+ turnId,
767
+ callId: tc.id,
768
+ name: tc.function.name,
769
+ ok: false,
770
+ error: blocked.error,
771
+ };
772
+ log.info(`variant tool blocked: ${tc.function.name} failed ${blocked.failCount}x with different args`);
773
+ }
774
+ messages.push(variantBlockNudge());
775
+ }
776
+ // - Emit tool_call events for non-blocked calls only -
777
+ // Deferred from above: only emit for calls that will actually be attempted.
778
+ for (const tc of variantAllowed) {
779
+ let emittedArguments = tc.function.arguments;
780
+ const toolDef = currentTools.find((t) => t.function.name === tc.function.name);
781
+ if (toolDef?.backfillObservableInput) {
782
+ try {
783
+ const parsed = JSON.parse(tc.function.arguments);
784
+ const copy = { ...parsed };
785
+ toolDef.backfillObservableInput(copy);
786
+ const addedFields = Object.keys(copy).some((k) => !(k in parsed));
787
+ if (addedFields) {
788
+ emittedArguments = JSON.stringify(copy);
789
+ }
790
+ }
791
+ catch { /* parse failure - emit original */ }
792
+ }
793
+ yield {
794
+ type: "tool_call",
795
+ turnId,
796
+ callId: tc.id,
797
+ name: tc.function.name,
798
+ arguments: emittedArguments,
799
+ inputSummary: summarizeToolInput(emittedArguments),
800
+ };
801
+ }
802
+ // - Execute tool calls via StreamingToolExecutor (CC parity) -
803
+ // Snapshot failure counts before execution so we can detect threshold crossings after
804
+ const variantFailureSnapshot = new Map(state.toolFailureCounts);
805
+ try {
806
+ const executor = params.runtimePorts.createStreamingToolExecutor({
807
+ toolInvoker,
808
+ hooks,
809
+ sessionId,
810
+ turnId,
811
+ log,
812
+ signal,
813
+ maxConcurrentTools: params?.maxConcurrentTools,
814
+ });
815
+ // Feed only allowed (non-blocked) tool calls into the executor
816
+ for (const tc of variantAllowed) {
817
+ executor.addTool(tc);
818
+ }
819
+ // Drain results as tools complete
820
+ for await (const r of executor.getRemainingResults()) {
821
+ if (r.blocked) {
822
+ yield { type: "tool_blocked", turnId, callId: r.callId, name: r.toolName, reason: r.blockReason ?? "blocked" };
823
+ }
824
+ messages.push(r.message);
825
+ executedToolCallIds.push(r.callId);
826
+ distinctToolNames.add(r.toolName);
827
+ totalToolCallCount++;
828
+ recordToolFailureResult({
829
+ toolFailureCounts: state.toolFailureCounts,
830
+ toolName: r.toolName,
831
+ ok: r.ok,
832
+ softEmpty: r.ok && isEmptyToolResult(r),
833
+ });
834
+ // AP5: file read cycle detection -track file paths read and detect circular traversal
835
+ if (r.ok && r.toolName === "read") {
836
+ const originalCall = variantAllowed.find(tc => tc.id === r.callId);
837
+ if (originalCall) {
838
+ try {
839
+ const args = JSON.parse(originalCall.function.arguments);
840
+ const filePath = (args.file_path ?? args.path ?? args.filePath ?? "");
841
+ if (filePath) {
842
+ const prev = state.fileReadCounts.get(filePath) ?? 0;
843
+ state.fileReadCounts.set(filePath, prev + 1);
844
+ }
845
+ }
846
+ catch { /* ignore parse errors */ }
847
+ }
848
+ }
849
+ yield createToolResultEvent(turnId, r);
850
+ for (const event of createToolMediaResultEvents(turnId, r)) {
851
+ yield event;
852
+ }
853
+ // - Sidecar event emission: plan_update + artifact -
854
+ for (const event of createToolSidecarEvents({ turnId, result: r, toolCalls })) {
855
+ yield event;
856
+ }
857
+ }
858
+ }
859
+ catch (err) {
860
+ const message = err instanceof Error ? err.message : String(err);
861
+ yield { type: "error", turnId, error: message, code: "TOOL_EXECUTION_ERROR", usage: state.totalUsage };
862
+ return;
863
+ }
864
+ messages.push(...newVariantFailureNudges({
865
+ toolFailureCounts: state.toolFailureCounts,
866
+ snapshot: variantFailureSnapshot,
867
+ }));
868
+ // Settle tool loop state
869
+ toolLoopState = settleToolLoopState(toolLoopState, {
870
+ replayMessages: messages,
871
+ completedToolCallIds: [
872
+ ...toolLoopState.completedToolCallIds,
873
+ ...executedToolCallIds,
874
+ ],
875
+ lastStopReason: "tool_calls",
876
+ });
877
+ if (params.toolChoice === "required" && toolCalls.length > 0) {
878
+ requiredToolChoiceSatisfied = true;
879
+ }
880
+ // Fire-and-forget tool use summary (CC generateToolUseSummary parity)
881
+ // Promise resolves during next turn's LLM streaming (~5-30s), yielded at iteration start.
882
+ if (params.generateToolUseSummary && toolCalls.length > 0) {
883
+ const summaryInput = toolCalls.map((tc) => ({
884
+ name: tc.function.name,
885
+ arguments: tc.function.arguments,
886
+ }));
887
+ pendingToolUseSummary = params.generateToolUseSummary(summaryInput).catch(() => null);
888
+ }
889
+ // - Consecutive failure tracking -
890
+ // Check all tool results from this round (both AP4-blocked and executor results).
891
+ // AP4-blocked calls always fail. Executor results check content prefix.
892
+ const allFailed = toolCalls.length > 0 && toolCalls.every((tc) => {
893
+ // Find the tool result message for this call ID
894
+ const resultMsg = messages.find((m) => m?.role === "tool" &&
895
+ m?.tool_call_id === tc.id);
896
+ if (!resultMsg)
897
+ return true; // missing = failed
898
+ const content = resultMsg.content;
899
+ return typeof content === "string" && content.startsWith("Error: ");
900
+ });
901
+ let nextConsecutiveFailedRounds = state.consecutiveFailedRounds;
902
+ if (allFailed) {
903
+ nextConsecutiveFailedRounds += 1;
904
+ if (nextConsecutiveFailedRounds >= MAX_CONSECUTIVE_FAILURES) {
905
+ // CC parity: exit early on repeated tool failures -don't burn iterations
906
+ // waiting for the model to give up. Use synthesizeFallbackContent when
907
+ // LLM hasn't produced any text yet (e.g. sandbox/injection paths that
908
+ // fail immediately, before any assistant text block).
909
+ const endContent = state.finalText || synthesizeFallbackContent(messages, log);
910
+ log.info(`early exit: ${nextConsecutiveFailedRounds} consecutive failed rounds, returning ${state.finalText ? "partial" : "fallback"} response`);
911
+ yield endEvent(endContent);
912
+ return;
913
+ }
914
+ }
915
+ else {
916
+ nextConsecutiveFailedRounds = 0;
917
+ }
918
+ // - AP5: File read cycle detection -
919
+ // If any single file has been read 3+ times this turn, the LLM is likely
920
+ // stuck in a circular import/dependency chain. Inject a nudge and force
921
+ // one final round to let it summarize.
922
+ const MAX_FILE_READS = 3;
923
+ const cycledFiles = [...state.fileReadCounts.entries()].filter(([, count]) => count >= MAX_FILE_READS);
924
+ if (cycledFiles.length > 0) {
925
+ const fileNames = cycledFiles.map(([f]) => f).join(", ");
926
+ log.info(`AP5: file read cycle detected on ${fileNames}, injecting nudge`);
927
+ const nudge = {
928
+ role: "user",
929
+ content: `You are reading the same files repeatedly (${fileNames}). This indicates a circular dependency or cycle. ` +
930
+ `Stop reading files, summarize your findings so far, and explain the circular structure to the user.`,
931
+ };
932
+ messages.push(nudge);
933
+ // Clear counts so we don't re-trigger on the final round
934
+ state.fileReadCounts.clear();
935
+ }
936
+ // - Max turns check (CC maxTurns parity) -
937
+ const nextTurnCount = turnCount + 1;
938
+ if (maxTurns > 0 && nextTurnCount > maxTurns) {
939
+ log.info(`max turns reached (${maxTurns}), completing`);
940
+ // CC multi-reason stop hook parity: fire stop hook on max_turns
941
+ if (hooks) {
942
+ const stopResult = await hooks.invoke("stop", { sessionId, reason: "max_turns" });
943
+ if (stopResult.action === "abort") {
944
+ const reason = stopResult.reason ?? "Stop hook requested continuation after max_turns";
945
+ const maxTurnsAssistantMsg = { role: "assistant", content: state.finalText, ...(thinkingBlocks.length > 0 && { thinkingBlocks: [...thinkingBlocks] }) };
946
+ state = {
947
+ ...state,
948
+ messages: [...messages, maxTurnsAssistantMsg, { role: "user", content: reason }],
949
+ stopHookActive: true,
950
+ transition: { reason: "stop_hook_blocking" },
951
+ };
952
+ continue;
953
+ }
954
+ }
955
+ // OpenAI format compensation: when LLM only produced tool_calls (no text),
956
+ // finalText is empty. Synthesize from last tool results so user doesn't
957
+ // see blank. CC doesn't need this -Anthropic text+tool_use coexist.
958
+ const endContent = state.finalText || synthesizeFallbackContent(messages, log);
959
+ yield endEvent(endContent);
960
+ return;
961
+ }
962
+ // - Tool budget exhaustion check (CC max_turns parity) -
963
+ // CC returns directly on budget exhaustion -no forced text-only round.
964
+ // OpenAI format note: unlike Anthropic where text+tool_use blocks coexist,
965
+ // OpenAI responses often have null content when tool_calls are present.
966
+ // We synthesize fallback content from tool results when finalText is empty.
967
+ if (nextTurnCount > toolBudget) {
968
+ log.info(`tool loop budget exhausted (${toolBudget} rounds), returning`);
969
+ const skillInstruction = resolveToolUsageSkillInstruction({
970
+ totalToolCallCount,
971
+ distinctToolNames,
972
+ projectRoot: params.projectRoot,
973
+ });
974
+ if (skillInstruction) {
975
+ yield { type: "skill_instruction", turnId, instruction: skillInstruction };
976
+ }
977
+ const endContent = state.finalText || synthesizeFallbackContent(messages, log);
978
+ yield endEvent(endContent);
979
+ return;
980
+ }
981
+ // - CC label: next_turn -
982
+ state = {
983
+ messages,
984
+ maxOutputTokensRecoveryCount: 0,
985
+ hasAttemptedReactiveCompact: false,
986
+ maxOutputTokensOverride: undefined,
987
+ turnCount: nextTurnCount,
988
+ transition: { reason: "next_turn" },
989
+ guardState,
990
+ reactiveCompactState,
991
+ toolLoopState,
992
+ consecutiveFailedRounds: nextConsecutiveFailedRounds,
993
+ finalText: state.finalText,
994
+ totalUsage: state.totalUsage,
995
+ collapseStore,
996
+ // Propagate P0 state across iterations
997
+ currentModel: state.currentModel,
998
+ consecutive529Errors: 0, // reset on successful tool round
999
+ consecutiveApiRetries: 0, // reset on successful tool round
1000
+ stopHookActive: state.stopHookActive,
1001
+ lastResponseId: state.lastResponseId,
1002
+ snipRemovedIds: state.snipRemovedIds,
1003
+ contentReplacementState: state.contentReplacementState,
1004
+ // Propagate across rounds: budget policy bounds total continuation
1005
+ // nudges per TURN. Resetting per tool round defeated the cap (model alternating
1006
+ // tool-call/done could be nudged forever) and broke diminishing-returns
1007
+ // detection (which compares usage deltas across checks).
1008
+ budgetContinuationCount: state.budgetContinuationCount,
1009
+ lastBudgetDeltaTokens: state.lastBudgetDeltaTokens,
1010
+ lastBudgetGlobalTokens: state.lastBudgetGlobalTokens,
1011
+ identicalCallCounts, // propagate across rounds
1012
+ toolFailureCounts: state.toolFailureCounts, // propagate across rounds
1013
+ fileReadCounts: state.fileReadCounts, // propagate across rounds
1014
+ recoveryTrace: state.recoveryTrace, // propagate across rounds
1015
+ };
1016
+ } // while (true)
1017
+ }