maka-agent 0.2.1-dev.91.20261018 → 0.2.2-dev.97.20261024

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 (418) hide show
  1. package/DISCLAIMER-WIP +1 -1
  2. package/LICENSE +15 -11
  3. package/README.md +173 -1
  4. package/README.zh-CN.md +156 -0
  5. package/THIRD_PARTY_NOTICES.txt +12 -12
  6. package/dist/cli-core.js +1 -0
  7. package/dist/pi-goal.js +13 -0
  8. package/dist/pi-tui-runner.js +44 -1
  9. package/dist/run-command-core.js +256 -48
  10. package/dist/run-session-command.js +534 -0
  11. package/dist/run-session-result.js +38 -0
  12. package/dist/run-turn-outcome.js +174 -0
  13. package/dist/runtime-host-cli.js +32 -17
  14. package/dist/runtime-host-run-command.js +53 -165
  15. package/dist/runtime-host-run-mcp.js +3 -0
  16. package/dist/runtime-host-session-channel.js +3 -1
  17. package/dist/runtime-host-session-driver.js +5 -0
  18. package/dist/runtime-host-setup-command.js +114 -7
  19. package/dist/tui-copy-catalog.js +24 -0
  20. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  21. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
  22. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
  23. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
  24. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
  25. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  26. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  27. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
  28. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  29. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
  30. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  31. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  32. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
  33. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
  34. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
  35. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
  36. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  37. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  38. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
  39. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
  40. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  41. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  42. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
  43. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
  44. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
  45. package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
  46. package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
  47. package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
  48. package/node_modules/@maka/core/dist/bot-chat-settings.js +10 -1
  49. package/node_modules/@maka/core/dist/event-wait-delivery.js +67 -0
  50. package/node_modules/@maka/core/dist/event-wait.js +75 -10
  51. package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
  52. package/node_modules/@maka/core/dist/goal.js +54 -2
  53. package/node_modules/@maka/core/dist/model-catalog.js +19 -1
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
  55. package/node_modules/@maka/core/dist/model-metadata.js +42 -1
  56. package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
  57. package/node_modules/@maka/core/dist/provider-registry.js +16 -2
  58. package/node_modules/@maka/core/dist/runtime-event-store.js +0 -1
  59. package/node_modules/@maka/core/dist/runtime-event.js +24 -2
  60. package/node_modules/@maka/core/dist/runtime-invocation.js +10 -0
  61. package/node_modules/@maka/core/dist/session-checkin.js +31 -0
  62. package/node_modules/@maka/core/dist/tool-ledger-scanner.js +1 -9
  63. package/node_modules/@maka/core/dist/tool-recovery-bundle.js +1 -14
  64. package/node_modules/@maka/core/dist/turn-origin.js +14 -2
  65. package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
  66. package/node_modules/@maka/core/package.json +3 -0
  67. package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
  68. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  69. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
  70. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  71. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
  72. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  73. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  74. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  75. package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
  76. package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
  77. package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  78. package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  79. package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
  80. package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
  81. package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
  82. package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
  83. package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
  84. package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
  85. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
  86. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  87. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  88. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
  89. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  90. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  91. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  92. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  93. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
  94. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  95. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  96. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  97. package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
  98. package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  99. package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  100. package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
  101. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
  102. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
  103. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
  104. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
  105. package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
  106. package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
  107. package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
  108. package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
  109. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  110. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  111. package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
  112. package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
  113. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  114. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  115. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
  116. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  117. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
  118. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
  119. package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  120. package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  121. package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
  122. package/node_modules/@maka/mcp/package.json +1 -1
  123. package/node_modules/@maka/runtime/dist/agent-run.js +5 -1
  124. package/node_modules/@maka/runtime/dist/agent-swarm-status-tool.js +0 -1
  125. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +29 -15
  126. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
  127. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +125 -131
  128. package/node_modules/@maka/runtime/dist/bots/bot-registry.js +19 -3
  129. package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +178 -6
  130. package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +163 -9
  131. package/node_modules/@maka/runtime/dist/context-budget-policy.js +9 -2
  132. package/node_modules/@maka/runtime/dist/event-wait-tool.js +69 -0
  133. package/node_modules/@maka/runtime/dist/goal-continuation.js +195 -117
  134. package/node_modules/@maka/runtime/dist/goal-state.js +8 -0
  135. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +34 -4
  136. package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
  137. package/node_modules/@maka/runtime/dist/memory-extraction.js +0 -2
  138. package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
  139. package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
  140. package/node_modules/@maka/runtime/dist/model-history.js +16 -3
  141. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +15 -5
  142. package/node_modules/@maka/runtime/dist/plan-tools.js +0 -3
  143. package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
  144. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
  145. package/node_modules/@maka/runtime/dist/provider-error-classification.js +2 -0
  146. package/node_modules/@maka/runtime/dist/recovery-resolver.js +2 -1
  147. package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
  148. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
  149. package/node_modules/@maka/runtime/dist/sandbox-boundary-path.js +79 -2
  150. package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
  151. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
  152. package/node_modules/@maka/runtime/dist/session-manager.js +5 -1
  153. package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
  154. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -3
  155. package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
  156. package/node_modules/@maka/runtime/dist/tool-runtime.js +11 -2
  157. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
  158. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
  159. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
  160. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
  161. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
  162. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  163. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  164. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
  165. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  166. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
  167. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  168. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  169. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
  170. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
  171. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
  172. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
  173. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  174. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  175. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
  176. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
  177. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  178. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  179. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
  180. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
  181. package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
  182. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  183. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
  184. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  185. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
  186. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  187. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  188. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  189. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
  190. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
  191. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  192. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  193. package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
  194. package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
  195. package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
  196. package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
  197. package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
  198. package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
  199. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
  200. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  201. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  202. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
  203. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  204. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  205. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  206. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  207. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
  208. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  209. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  210. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  211. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
  212. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  213. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  214. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
  215. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
  216. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
  217. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
  218. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
  219. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
  220. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
  221. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
  222. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
  223. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  224. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  225. package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
  226. package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
  227. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  228. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  229. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
  230. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  231. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
  232. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
  233. package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  234. package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  235. package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
  236. package/node_modules/@maka/runtime/package.json +3 -0
  237. package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
  238. package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
  239. package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +92 -22
  240. package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
  241. package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
  242. package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
  243. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
  244. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
  245. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
  246. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
  247. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
  248. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
  249. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
  250. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +203 -71
  251. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/host.js +21 -5
  252. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
  253. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
  254. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
  255. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
  256. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +37 -5
  257. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
  258. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
  259. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
  260. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
  261. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +68 -14
  262. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
  263. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
  264. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +93 -23
  265. package/node_modules/@maka/runtime-host/dist/assistant/service.js +72 -16
  266. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +30 -1
  267. package/node_modules/@maka/runtime-host/dist/client/ssh-operator-activation.js +9 -2
  268. package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
  269. package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -3
  270. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
  271. package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
  272. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
  273. package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
  274. package/node_modules/@maka/runtime-host/dist/server/agent-settings-tools.js +0 -1
  275. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
  276. package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +151 -20
  277. package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
  278. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +127 -11
  279. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
  280. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +11 -0
  281. package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +5 -2
  282. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +343 -53
  283. package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +457 -0
  284. package/node_modules/@maka/runtime-host/dist/server/goal-execution-coordinator.js +23 -6
  285. package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
  286. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +5 -1
  287. package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
  288. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
  289. package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
  290. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +8 -0
  291. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
  292. package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
  293. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
  294. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
  295. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
  296. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
  297. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
  298. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +14 -3
  299. package/node_modules/@maka/storage/dist/agent-run-store.js +10 -0
  300. package/node_modules/@maka/storage/dist/codex-session-adapter.js +20 -3
  301. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
  302. package/node_modules/@maka/storage/dist/event-wait-authority.js +18 -1
  303. package/node_modules/@maka/storage/dist/event-wait-bridge.js +336 -0
  304. package/node_modules/@maka/storage/dist/execution-stores.js +39 -1
  305. package/node_modules/@maka/storage/dist/external-session-images.js +131 -0
  306. package/node_modules/@maka/storage/dist/external-session-importer.js +12 -2
  307. package/node_modules/@maka/storage/dist/goal-authority.js +2 -0
  308. package/node_modules/@maka/storage/dist/local-execution-persistence.js +27 -1
  309. package/node_modules/@maka/storage/dist/operational-state-store.js +1 -1
  310. package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
  311. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  312. package/node_modules/@maka/storage/dist/session-bundle-policy.js +116 -16
  313. package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
  314. package/node_modules/@maka/storage/dist/session-store.js +37 -8
  315. package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
  316. package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
  317. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
  318. package/node_modules/@maka/storage/dist/sqlite-event-wait-authority.js +81 -8
  319. package/node_modules/@maka/storage/dist/sqlite-event-wait-bridge.js +94 -0
  320. package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
  321. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +7 -8
  322. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +38 -162
  323. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +7 -4
  324. package/node_modules/@maka/storage/dist/tool-commit-validation.js +1 -1
  325. package/node_modules/@maka/storage/package.json +4 -0
  326. package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
  327. package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
  328. package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
  329. package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
  330. package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
  331. package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
  332. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
  333. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
  334. package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
  335. package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
  336. package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
  337. package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
  338. package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
  339. package/node_modules/@modelcontextprotocol/client/package.json +5 -5
  340. package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
  341. package/node_modules/fast-uri/README.md +8 -0
  342. package/node_modules/fast-uri/index.js +98 -18
  343. package/node_modules/fast-uri/lib/utils.js +52 -0
  344. package/node_modules/fast-uri/package.json +1 -1
  345. package/node_modules/follow-redirects/index.js +10 -1
  346. package/node_modules/follow-redirects/package.json +1 -1
  347. package/node_modules/ip-address/README.md +104 -104
  348. package/node_modules/ip-address/dist/ipv4.js +7 -0
  349. package/node_modules/ip-address/dist/ipv6.js +7 -4
  350. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  351. package/node_modules/ip-address/package.json +2 -1
  352. package/node_modules/undici/README.md +25 -3
  353. package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  354. package/node_modules/undici/docs/docs/api/Client.md +11 -6
  355. package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  356. package/node_modules/undici/docs/docs/api/Errors.md +76 -1
  357. package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  358. package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  359. package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  360. package/node_modules/undici/docs/docs/index.md +12 -12
  361. package/node_modules/undici/docs/docs/type-map.json +66 -66
  362. package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  363. package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  364. package/node_modules/undici/lib/core/connect.js +10 -4
  365. package/node_modules/undici/lib/core/constants.js +12 -1
  366. package/node_modules/undici/lib/core/errors.js +38 -1
  367. package/node_modules/undici/lib/core/request.js +16 -1
  368. package/node_modules/undici/lib/core/symbols.js +2 -0
  369. package/node_modules/undici/lib/core/util.js +26 -1
  370. package/node_modules/undici/lib/dispatcher/agent.js +6 -2
  371. package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  372. package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  373. package/node_modules/undici/lib/dispatcher/client.js +4 -1
  374. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  375. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  376. package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  377. package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  378. package/node_modules/undici/lib/dispatcher/pool.js +11 -8
  379. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  380. package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  381. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  382. package/node_modules/undici/lib/handler/cache-handler.js +153 -15
  383. package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  384. package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  385. package/node_modules/undici/lib/handler/retry-handler.js +44 -11
  386. package/node_modules/undici/lib/interceptor/cache.js +11 -3
  387. package/node_modules/undici/lib/interceptor/decompress.js +22 -9
  388. package/node_modules/undici/lib/interceptor/dns.js +11 -0
  389. package/node_modules/undici/lib/interceptor/response-error.js +72 -28
  390. package/node_modules/undici/lib/milo/LICENSE.md +7 -0
  391. package/node_modules/undici/lib/milo/no-simd.js +1002 -0
  392. package/node_modules/undici/lib/milo/simd.js +1002 -0
  393. package/node_modules/undici/lib/mock/mock-agent.js +11 -0
  394. package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  395. package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  396. package/node_modules/undici/lib/util/cache.js +11 -5
  397. package/node_modules/undici/lib/web/cookies/util.js +19 -2
  398. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  399. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  400. package/node_modules/undici/lib/web/fetch/body.js +47 -38
  401. package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  402. package/node_modules/undici/lib/web/fetch/headers.js +2 -2
  403. package/node_modules/undici/lib/web/fetch/index.js +8 -4
  404. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  405. package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  406. package/node_modules/undici/package.json +9 -7
  407. package/node_modules/zod/package.json +1 -1
  408. package/node_modules/zod/v4/core/compile.cjs +8 -0
  409. package/node_modules/zod/v4/core/compile.js +8 -0
  410. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  411. package/node_modules/zod/v4/core/schemas.js +30 -0
  412. package/node_modules/zod/v4/core/util.cjs +15 -0
  413. package/node_modules/zod/v4/core/util.js +14 -0
  414. package/node_modules/zod/v4/core/versions.cjs +1 -1
  415. package/node_modules/zod/v4/core/versions.js +1 -1
  416. package/package.json +2 -2
  417. package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
  418. package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
@@ -0,0 +1,336 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { createHash } from 'node:crypto';
20
+ import { isDeepStrictEqual as equal } from 'node:util';
21
+ import { decodeEventWaitRecord } from '@maka/core/event-wait';
22
+ import { decodeGoalAuthorityRecord, sameGoalControlLease, } from '@maka/core/goal';
23
+ import { readLogicalRuntimeExecution } from '@maka/core/runtime-logical-execution';
24
+ export function eventWaitProvenance(wait) {
25
+ if (wait.status !== 'resolved' && wait.status !== 'expired')
26
+ throw new Error('Wait has no result');
27
+ return {
28
+ waitId: wait.waitId,
29
+ deliveryKey: wait.deliveryKey,
30
+ sourceTurnId: wait.sourceTurnId,
31
+ sourceToolCallId: wait.sourceToolCallId,
32
+ generation: wait.goalControlLease.generation,
33
+ outcome: wait.status === 'expired' ? 'expired' : wait.resolution.outcome,
34
+ resultDigest: `sha256:${createHash('sha256')
35
+ .update(JSON.stringify(wait.status === 'expired' ? { expiredAt: wait.expiredAt } : wait.resolution))
36
+ .digest('hex')}`,
37
+ };
38
+ }
39
+ function owningGoal(goal, wait) {
40
+ if (!goal ||
41
+ goal.record.goal.sessionId !== wait.sessionId ||
42
+ !sameGoalControlLease(goal.record.controlLease, wait.goalControlLease) ||
43
+ !['active', 'waiting'].includes(goal.record.goal.status))
44
+ throw new Error('Event wait Goal is unavailable');
45
+ return goal;
46
+ }
47
+ function update(goal, record) {
48
+ return {
49
+ authorityRevision: goal.authorityRevision + 1,
50
+ record: decodeGoalAuthorityRecord(record),
51
+ };
52
+ }
53
+ /** Authenticate immutable handoff membership before the joint write. The write
54
+ * rechecks the admission and that the physical source has not ended or sealed. */
55
+ export async function readGoalWaitRootExecution(runtime, input, source) {
56
+ if (!source)
57
+ return undefined;
58
+ const root = { sessionId: source.sessionId, turnId: source.turnId, runId: source.runId };
59
+ if (equal(root, input.sourceExecution))
60
+ return root;
61
+ const logical = await readLogicalRuntimeExecution(runtime, root);
62
+ if (!logical ||
63
+ logical.pendingHandoff ||
64
+ logical.tip.runId !== input.sourceExecution.runId ||
65
+ logical.tip.sessionId !== input.sourceExecution.sessionId ||
66
+ logical.tip.turnId !== input.sourceExecution.turnId)
67
+ throw new Error('Invalid source execution for wait registration');
68
+ return root;
69
+ }
70
+ /** A later user Turn may arrive while a completed ordinary Goal Turn awaits
71
+ * evaluation. Authenticate its logical termination before replacing that slot;
72
+ * a handoff seal alone does not finish the execution. */
73
+ export async function readCompletedGoalWaitExecution(runtime, current, source) {
74
+ if (!current || equal(current.execution, source))
75
+ return undefined;
76
+ const logical = await readLogicalRuntimeExecution(runtime, current.execution);
77
+ if (!logical || logical.pendingHandoff || logical.tip.terminalEvent?.status !== 'completed')
78
+ return undefined;
79
+ return current.execution;
80
+ }
81
+ /** Only a current ordinary checkpoint still owns an outstanding settlement.
82
+ * Stale checkpoints and revoked control generations must not be charged again. */
83
+ export function goalWaitPredecessor(record, sourceTurnId) {
84
+ const current = record.currentExecution;
85
+ return record.goal.status === 'active' &&
86
+ current &&
87
+ current.execution.turnId !== sourceTurnId &&
88
+ current.checkpoint.goalId === record.goal.id &&
89
+ current.checkpoint.revision === record.goal.revision &&
90
+ sameGoalControlLease(current.controlLease, record.controlLease)
91
+ ? current
92
+ : undefined;
93
+ }
94
+ export function registerGoalWait(input, current, existing, source, logicalSource, completedExecution) {
95
+ const record = decodeEventWaitRecord(input.record);
96
+ const goal = owningGoal(current, record);
97
+ if (existing) {
98
+ const a = existing.record;
99
+ if (!equal([
100
+ record.waitId,
101
+ record.sessionId,
102
+ record.goalControlLease,
103
+ record.sourceTurnId,
104
+ record.sourceToolCallId,
105
+ record.resource,
106
+ record.condition,
107
+ record.createdAt,
108
+ record.deadlineAt,
109
+ ], [
110
+ a.waitId,
111
+ a.sessionId,
112
+ a.goalControlLease,
113
+ a.sourceTurnId,
114
+ a.sourceToolCallId,
115
+ a.resource,
116
+ a.condition,
117
+ a.createdAt,
118
+ a.deadlineAt,
119
+ ]))
120
+ throw new Error('Conflicting wait registration');
121
+ if (goal.record.activeEventWait?.waitId !== record.waitId ||
122
+ goal.record.activeEventWait.reason !== input.reason ||
123
+ !equal(goal.record.activeEventWait.sourceExecution, input.sourceExecution))
124
+ throw new Error('Wait no longer owns the Goal');
125
+ return { wait: existing, goal };
126
+ }
127
+ if (record.status !== 'waiting' ||
128
+ record.delivery ||
129
+ record.observation ||
130
+ goal.record.goal.revision !== input.expectedGoalRevision ||
131
+ goal.record.activeEventWait ||
132
+ goal.record.pendingContinuation?.eventWait ||
133
+ !source ||
134
+ source.sessionId !== record.sessionId ||
135
+ source.turnId !== record.sourceTurnId ||
136
+ input.sourceExecution.sessionId !== record.sessionId ||
137
+ input.sourceExecution.turnId !== record.sourceTurnId ||
138
+ !equal(logicalSource, {
139
+ sessionId: record.sessionId,
140
+ turnId: record.sourceTurnId,
141
+ runId: source.runId,
142
+ }) ||
143
+ (goal.record.currentExecution &&
144
+ !equal(goal.record.currentExecution.execution, logicalSource) &&
145
+ !equal(goal.record.currentExecution.execution, completedExecution)))
146
+ throw new Error('Invalid source execution for wait registration');
147
+ const predecessor = goalWaitPredecessor(goal.record, record.sourceTurnId);
148
+ const settlement = input.previousTurnSettlement;
149
+ if (predecessor
150
+ ? !settlement ||
151
+ !equal(settlement.execution, predecessor.execution) ||
152
+ settlement.goal.id !== goal.record.goal.id ||
153
+ settlement.goal.sessionId !== record.sessionId ||
154
+ settlement.goal.revision !== input.expectedGoalRevision + 1 ||
155
+ settlement.goal.status !== 'active'
156
+ : settlement !== undefined)
157
+ throw new Error('Previous Goal Turn settlement does not match');
158
+ // Explicit waiting replaces the old ordinary drive in this same transaction.
159
+ // Wake legacy waiting without charging work or changing its control generation.
160
+ const nextGoal = settlement?.goal ??
161
+ (goal.record.goal.status === 'waiting'
162
+ ? { ...goal.record.goal, status: 'active', revision: goal.record.goal.revision + 1 }
163
+ : goal.record.goal);
164
+ const checkpoint = { goalId: nextGoal.id, revision: nextGoal.revision };
165
+ return {
166
+ wait: { authorityRevision: 0, record },
167
+ goal: update(goal, {
168
+ ...goal.record,
169
+ goal: nextGoal,
170
+ pendingContinuation: null,
171
+ currentExecution: {
172
+ execution: logicalSource,
173
+ checkpoint,
174
+ controlLease: goal.record.controlLease,
175
+ },
176
+ activeEventWait: {
177
+ waitId: record.waitId,
178
+ sourceExecution: input.sourceExecution,
179
+ controlLease: record.goalControlLease,
180
+ reason: input.reason,
181
+ settled: false,
182
+ },
183
+ }),
184
+ };
185
+ }
186
+ export function assertSourceYield(wait, source, events) {
187
+ if (!events.some((e) => e.sessionId === wait.sessionId &&
188
+ e.runId === source.runId &&
189
+ e.turnId === wait.sourceTurnId &&
190
+ e.status === 'completed' &&
191
+ e.actions?.stateDelta?.stopReason === 'event_wait'))
192
+ throw new Error('Source Turn has no durable event-wait yield termination');
193
+ }
194
+ export function settleGoalWait(input, current, wait, events) {
195
+ const goal = owningGoal(current, wait.record), gate = goal.record.activeEventWait;
196
+ if (!gate || gate.waitId !== input.waitId || input.sessionId !== wait.record.sessionId)
197
+ throw new Error('Wait gate changed');
198
+ assertSourceYield(wait.record, gate.sourceExecution, events);
199
+ if (gate.settled)
200
+ return { goal, wait };
201
+ if (goal.record.goal.revision !== input.expectedGoalRevision ||
202
+ input.goal.revision !== input.expectedGoalRevision + 1 ||
203
+ input.goal.id !== goal.record.goal.id ||
204
+ input.goal.sessionId !== input.sessionId)
205
+ throw new Error('Wait settlement revision changed');
206
+ if (!['active', 'waiting'].includes(input.goal.status)) {
207
+ const { activeEventWait: _gate, ...record } = goal.record;
208
+ return {
209
+ wait: suppressGoalWait(wait, wait.record.updatedAt),
210
+ goal: update(goal, {
211
+ ...record,
212
+ goal: input.goal,
213
+ currentExecution: null,
214
+ pendingContinuation: null,
215
+ }),
216
+ };
217
+ }
218
+ return {
219
+ wait,
220
+ goal: update(goal, {
221
+ ...goal.record,
222
+ goal: input.goal,
223
+ currentExecution: null,
224
+ pendingContinuation: null,
225
+ activeEventWait: { ...gate, settled: true },
226
+ }),
227
+ };
228
+ }
229
+ export function queueGoalWait(input, current, wait, events) {
230
+ const goal = owningGoal(current, wait.record), gate = goal.record.activeEventWait;
231
+ if (!gate?.settled ||
232
+ gate.waitId !== input.waitId ||
233
+ goal.record.currentExecution ||
234
+ wait.record.delivery ||
235
+ input.sessionId !== wait.record.sessionId)
236
+ throw new Error('Wait is not ready for delivery');
237
+ assertSourceYield(wait.record, gate.sourceExecution, events);
238
+ if (goal.record.pendingContinuation) {
239
+ if (!equal(goal.record.pendingContinuation, input.pending))
240
+ throw new Error('Conflicting event continuation');
241
+ return { goal, wait };
242
+ }
243
+ if (goal.record.goal.revision !== input.expectedGoalRevision ||
244
+ !input.pending.eventWait ||
245
+ !equal(input.pending.eventWait.provenance, eventWaitProvenance(wait.record)))
246
+ throw new Error('Event continuation result changed');
247
+ assertGoalWaitBudget(goal.record.goal);
248
+ return { wait, goal: update(goal, { ...goal.record, pendingContinuation: input.pending }) };
249
+ }
250
+ export function assertGoalWaitBudget(goal) {
251
+ if (goal.iterations >= goal.maxIterations ||
252
+ (goal.tokenBudget !== undefined &&
253
+ !goal.tokensBaselinePending &&
254
+ goal.tokensNow - goal.tokensAtStart >= goal.tokenBudget))
255
+ throw new Error('Event wait Goal budget exhausted');
256
+ }
257
+ export function admitGoalWait(admission, current, wait) {
258
+ const goal = owningGoal(current, wait.record), pending = goal.record.pendingContinuation;
259
+ const event = pending?.eventWait;
260
+ if (admission.execution.kind !== 'goal' ||
261
+ !admission.execution.eventWait ||
262
+ !event ||
263
+ !pending ||
264
+ !goal.record.activeEventWait?.settled ||
265
+ goal.record.activeEventWait.waitId !== wait.record.waitId ||
266
+ wait.record.delivery ||
267
+ goal.record.currentExecution ||
268
+ !equal(event.execution, {
269
+ sessionId: admission.sessionId,
270
+ turnId: admission.turnId,
271
+ runId: admission.runId,
272
+ }) ||
273
+ event.userMessageId !== admission.userMessageId ||
274
+ !equal(admission.normalizedInput, { text: pending.prompt }) ||
275
+ admission.sourceMessages.length !== 0 ||
276
+ !equal(event.provenance, admission.execution.eventWait) ||
277
+ !equal(event.provenance, eventWaitProvenance(wait.record)) ||
278
+ admission.execution.goalId !== goal.record.goal.id)
279
+ throw new Error('Event wait admission changed');
280
+ assertGoalWaitBudget(goal.record.goal);
281
+ const { activeEventWait: _gate, ...record } = goal.record;
282
+ const at = Math.max(admission.admittedAt, wait.record.updatedAt);
283
+ return {
284
+ goal: update(goal, {
285
+ ...record,
286
+ pendingContinuation: null,
287
+ currentExecution: {
288
+ execution: event.execution,
289
+ checkpoint: pending.checkpoint,
290
+ controlLease: pending.controlLease,
291
+ },
292
+ }),
293
+ wait: {
294
+ authorityRevision: wait.authorityRevision + 1,
295
+ record: decodeEventWaitRecord({
296
+ ...wait.record,
297
+ updatedAt: at,
298
+ delivery: {
299
+ kind: 'admitted',
300
+ turnId: admission.turnId,
301
+ runId: admission.runId,
302
+ userMessageId: admission.userMessageId,
303
+ at,
304
+ },
305
+ }),
306
+ },
307
+ };
308
+ }
309
+ export function suppressGoalWait(wait, at) {
310
+ if (wait.record.delivery)
311
+ return wait;
312
+ at = Math.max(at, wait.record.updatedAt);
313
+ const r = wait.record;
314
+ const reason = 'Goal wait cancelled or control generation ended';
315
+ const record = r.status === 'waiting' || r.status === 'resolved'
316
+ ? {
317
+ ...r,
318
+ status: 'cancelled',
319
+ updatedAt: at,
320
+ cancelledAt: at,
321
+ reason,
322
+ ...(r.status === 'resolved'
323
+ ? { priorResolution: { resolvedAt: r.resolvedAt, resolution: r.resolution } }
324
+ : {}),
325
+ }
326
+ : { ...r, updatedAt: at };
327
+ // Remove resolved-only fields when cancelling, retaining the immutable receipt explicitly.
328
+ if (r.status === 'resolved') {
329
+ delete record.resolvedAt;
330
+ delete record.resolution;
331
+ }
332
+ return {
333
+ authorityRevision: wait.authorityRevision + 1,
334
+ record: decodeEventWaitRecord({ ...record, delivery: { kind: 'suppressed', at, reason } }),
335
+ };
336
+ }
@@ -17,6 +17,7 @@
17
17
  * under the License.
18
18
  */
19
19
  import { openInteractiveEventWaitAuthorityForWrite, } from './event-wait-authority.js';
20
+ import { SnapshotOperationGate } from './snapshot-operation-gate.js';
20
21
  import { createSqliteAgentRunStore, } from './agent-run-store.js';
21
22
  import { createSessionStore } from './session-store.js';
22
23
  import { assertStorageRootLease, assertStorageRootLeaseActive, runWithStorageRootLease, StorageRootAuthorityError, } from './root-authority.js';
@@ -102,6 +103,7 @@ async function createExecutionStoresForWrite(lease, provider) {
102
103
  let closed = false;
103
104
  let closeTask;
104
105
  const active = new Set();
106
+ const snapshotGate = new SnapshotOperationGate();
105
107
  const subscriptions = new Set();
106
108
  const run = (operation) => {
107
109
  if (closed)
@@ -109,7 +111,7 @@ async function createExecutionStoresForWrite(lease, provider) {
109
111
  const pending = runWithStorageRootLease(lease, kind, 'write', () => {
110
112
  if (closed)
111
113
  throw invalidExecutionStores(kind, 'write');
112
- return operation();
114
+ return snapshotGate.run(operation);
113
115
  });
114
116
  active.add(pending);
115
117
  void pending.finally(() => active.delete(pending)).catch(() => undefined);
@@ -167,6 +169,9 @@ async function createExecutionStoresForWrite(lease, provider) {
167
169
  extendSourceCooldown: (input) => run(async () => persistence.eventWaitStore.extendSourceCooldown(input)),
168
170
  reserveSourceDispatch: (input) => run(async () => persistence.eventWaitStore.reserveSourceDispatch(input)),
169
171
  completeSourceDispatch: (input) => run(async () => persistence.eventWaitStore.completeSourceDispatch(input)),
172
+ registerGoalWait: (input) => run(async () => persistence.eventWaitStore.registerGoalWait(input)),
173
+ settleGoalWait: (input) => run(async () => persistence.eventWaitStore.settleGoalWait(input)),
174
+ queueGoalWait: (input) => run(async () => persistence.eventWaitStore.queueGoalWait(input)),
170
175
  commit: (input) => run(async () => persistence.eventWaitStore.commit(input)),
171
176
  close: () => { },
172
177
  });
@@ -276,6 +281,37 @@ async function createExecutionStoresForWrite(lease, provider) {
276
281
  close: () => { },
277
282
  });
278
283
  const stores = {
284
+ ...(persistence.createSnapshotStatePreparer
285
+ ? {
286
+ snapshot: Object.freeze({
287
+ runExclusive(operation) {
288
+ if (closed)
289
+ return Promise.reject(invalidExecutionStores(kind, 'write'));
290
+ const pending = snapshotGate.exclusive(() => runWithStorageRootLease(lease, kind, 'write', async () => {
291
+ if (closed)
292
+ throw invalidExecutionStores(kind, 'write');
293
+ const state = persistence.createSnapshotStatePreparer(lease);
294
+ let scopeActive = true;
295
+ try {
296
+ return await operation({
297
+ prepareState: (input) => {
298
+ if (!scopeActive || closed)
299
+ return Promise.reject(invalidExecutionStores(kind, 'write'));
300
+ return state.prepareState(input);
301
+ },
302
+ });
303
+ }
304
+ finally {
305
+ scopeActive = false;
306
+ }
307
+ }));
308
+ active.add(pending);
309
+ void pending.finally(() => active.delete(pending)).catch(() => { });
310
+ return pending;
311
+ },
312
+ }),
313
+ }
314
+ : {}),
279
315
  interactionStore,
280
316
  graphControlStore,
281
317
  goalStore,
@@ -407,6 +443,7 @@ async function createExecutionStoresForWrite(lease, provider) {
407
443
  }
408
444
  : {}),
409
445
  scanRuntimeEvents: (sessionId, runId, budget, visit) => run(() => runtimeEventStore.scanRuntimeEvents(sessionId, runId, budget, visit)),
446
+ readToolProvenanceEvents: (sessionId, runId, toolCallId, budget) => run(() => runtimeEventStore.readToolProvenanceEvents(sessionId, runId, toolCallId, budget)),
410
447
  readRuntimeEventsBounded: (sessionId, runId, budget) => run(() => runtimeEventStore.readRuntimeEventsBounded(sessionId, runId, budget)),
411
448
  readImmutableRuntimeEvents: (sessionId, runId) => run(() => runtimeEventStore.readImmutableRuntimeEvents(sessionId, runId)),
412
449
  readRecoveryMessageEvents: (input) => run(() => runtimeEventStore.readRecoveryMessageEvents(input)),
@@ -524,6 +561,7 @@ async function openExecutionStoresForRead(lease, kind, extension) {
524
561
  readSessionRuntimeSnapshot: (sessionId) => run(() => runtimeEventStore.readSessionRuntimeSnapshot(sessionId)),
525
562
  }
526
563
  : {}),
564
+ readToolProvenanceEvents: (sessionId, runId, toolCallId, budget) => run(() => runtimeEventStore.readToolProvenanceEvents(sessionId, runId, toolCallId, budget)),
527
565
  readRuntimeEventsBounded: (sessionId, runId, budget) => run(() => runtimeEventStore.readRuntimeEventsBounded(sessionId, runId, budget)),
528
566
  readImmutableRuntimeEvents: (sessionId, runId) => run(() => runtimeEventStore.readImmutableRuntimeEvents(sessionId, runId)),
529
567
  listSessionInvocations: (sessionId) => run(() => runtimeEventStore.listSessionInvocations(sessionId)),
@@ -0,0 +1,131 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { randomUUID } from 'node:crypto';
20
+ import { constants } from 'node:fs';
21
+ import { open } from 'node:fs/promises';
22
+ import { basename, isAbsolute } from 'node:path';
23
+ import { MAX_ATTACHMENT_BYTES, MAX_ATTACHMENT_COUNT, sniffAttachmentMimeType, } from '@maka/core/attachments';
24
+ // Bound disk growth and I/O independently of the transcript's text budget.
25
+ const MAX_IMPORT_IMAGE_BYTES = 256 * 1024 * 1024;
26
+ /** Source paths never become published references: only verified, durable bytes do. */
27
+ export async function prepareExternalSessionImages(sessionId, messages, sources, artifacts) {
28
+ const byMessage = new Map();
29
+ for (const source of sources) {
30
+ const paths = byMessage.get(source.messageId) ?? [];
31
+ paths.push(source.path);
32
+ byMessage.set(source.messageId, paths);
33
+ }
34
+ const prepared = [];
35
+ let totalBytes = 0;
36
+ try {
37
+ for (const message of messages) {
38
+ const paths = message.type === 'user' ? byMessage.get(message.id) : undefined;
39
+ if (message.type !== 'user' || !paths?.length) {
40
+ prepared.push(message);
41
+ continue;
42
+ }
43
+ const attachments = [...(message.attachments ?? [])];
44
+ const unavailable = [];
45
+ for (const [index, path] of paths.entries()) {
46
+ if (!artifacts ||
47
+ index >= MAX_ATTACHMENT_COUNT ||
48
+ attachments.length >= MAX_ATTACHMENT_COUNT) {
49
+ unavailable.push(index + 1);
50
+ continue;
51
+ }
52
+ const image = await readSourceImage(path, MAX_IMPORT_IMAGE_BYTES - totalBytes);
53
+ if (!image) {
54
+ unavailable.push(index + 1);
55
+ continue;
56
+ }
57
+ const id = `import_image_${randomUUID()}`;
58
+ const record = await artifacts.create({
59
+ id,
60
+ sessionId,
61
+ // Match native uploads: the artifact owns an upload key, not a source Turn id.
62
+ turnId: id,
63
+ name: basename(path),
64
+ kind: 'image',
65
+ content: image.bytes,
66
+ mimeType: image.mimeType,
67
+ source: 'user_upload',
68
+ });
69
+ totalBytes += image.bytes.byteLength;
70
+ attachments.push({
71
+ kind: 'image',
72
+ name: record.name,
73
+ mimeType: image.mimeType,
74
+ bytes: record.sizeBytes,
75
+ ref: { kind: 'session_file', sessionId, relativePath: record.id },
76
+ });
77
+ }
78
+ const fallback = unavailable.length > 0
79
+ ? `\n\n[${unavailable.length} imported image attachment(s) unavailable (source positions: ${unavailable.join(', ')}): the original file could not be recovered within attachment limits.]`
80
+ : '';
81
+ prepared.push({
82
+ ...message,
83
+ // Keep all source text, including useful metadata for unavailable originals.
84
+ text: message.text + fallback,
85
+ ...(message.displayText !== undefined
86
+ ? { displayText: message.displayText + fallback }
87
+ : {}),
88
+ ...(attachments.length ? { attachments } : {}),
89
+ });
90
+ }
91
+ return prepared;
92
+ }
93
+ catch (error) {
94
+ // No Session metadata has been committed while this preparation callback runs.
95
+ await artifacts?.purgeSessionArtifacts(sessionId);
96
+ throw error;
97
+ }
98
+ }
99
+ async function readSourceImage(path, remaining) {
100
+ if (!isAbsolute(path) || remaining <= 0)
101
+ return undefined;
102
+ try {
103
+ const handle = await open(path, constants.O_RDONLY | constants.O_NONBLOCK);
104
+ try {
105
+ const metadata = await handle.stat();
106
+ const limit = Math.min(MAX_ATTACHMENT_BYTES, remaining);
107
+ if (!metadata.isFile() || metadata.size <= 0 || metadata.size > limit)
108
+ return undefined;
109
+ // One extra byte detects growth without ever buffering an unbounded source.
110
+ const bytes = Buffer.alloc(metadata.size + 1);
111
+ let total = 0;
112
+ while (total < bytes.length) {
113
+ const read = await handle.read(bytes, total, bytes.length - total, total);
114
+ if (read.bytesRead === 0)
115
+ break;
116
+ total += read.bytesRead;
117
+ }
118
+ if (total !== metadata.size)
119
+ return undefined;
120
+ const payload = bytes.subarray(0, total);
121
+ const mimeType = sniffAttachmentMimeType(payload);
122
+ return mimeType?.startsWith('image/') ? { bytes: payload, mimeType } : undefined;
123
+ }
124
+ finally {
125
+ await handle.close();
126
+ }
127
+ }
128
+ catch {
129
+ return undefined;
130
+ }
131
+ }
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { decodeCanonicalMessage, isConversationTextMessage } from '@maka/core/session';
20
20
  import { sanitizeExternalSessionCwd, sanitizeExternalSessionTitle, } from '@maka/core/external-session';
21
+ import { prepareExternalSessionImages } from './external-session-images.js';
21
22
  /**
22
23
  * Converts no formats itself. The selected adapter returns Maka StoredMessages;
23
24
  * the importer only chooses target Session settings and commits them atomically.
@@ -25,9 +26,11 @@ import { sanitizeExternalSessionCwd, sanitizeExternalSessionTitle, } from '@maka
25
26
  export class ExternalSessionImporter {
26
27
  adapters;
27
28
  sessions;
28
- constructor(adapters, sessions) {
29
+ artifacts;
30
+ constructor(adapters, sessions, artifacts) {
29
31
  this.adapters = adapters;
30
32
  this.sessions = sessions;
33
+ this.artifacts = artifacts;
31
34
  }
32
35
  async import(request) {
33
36
  const adapter = this.adapters.require(request.adapterId);
@@ -59,6 +62,13 @@ export class ExternalSessionImporter {
59
62
  }, messages, {
60
63
  adapterId: request.adapterId,
61
64
  sourceSessionId: request.sourceSessionId,
62
- });
65
+ }, external.sourceImages?.length
66
+ ? {
67
+ discardPreparedMessages: async (sessionId) => {
68
+ await this.artifacts?.purgeSessionArtifacts(sessionId);
69
+ },
70
+ prepareMessages: (sessionId, sourceMessages) => prepareExternalSessionImages(sessionId, sourceMessages, external.sourceImages, this.artifacts),
71
+ }
72
+ : undefined);
63
73
  }
64
74
  }
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { suppressPreviousBridgeWait } from './sqlite-event-wait-bridge.js';
19
20
  import { decodeGoalAuthorityRecord } from '@maka/core/goal';
20
21
  import { acquireOperationalStateDatabase, } from './operational-state-store.js';
21
22
  import { assertStorageRootLease, runWithStorageRootLease, StorageRootAuthorityError, } from './root-authority.js';
@@ -165,6 +166,7 @@ class SqliteGoalAuthority {
165
166
  if (current !== input.expectedAuthorityRevision) {
166
167
  return { kind: 'revision_conflict', actualAuthorityRevision: current };
167
168
  }
169
+ suppressPreviousBridgeWait(this.#database.database, input.sessionId, input.record);
168
170
  if (input.record === null) {
169
171
  this.#database.database
170
172
  .prepare('DELETE FROM workflow_goal_authority WHERE session_id = ?')
@@ -24,6 +24,9 @@ import { createAgentGraphControlStore } from './agent-graph-control-store.js';
24
24
  import { createSqliteEventWaitAuthority } from './sqlite-event-wait-authority.js';
25
25
  import { createSqliteGoalAuthority } from './goal-authority.js';
26
26
  import { createSqliteInteractionStore } from './interaction-store.js';
27
+ import { exportSessionBundleState } from './session-bundle-policy.js';
28
+ import { createSessionSnapshotStateIdentity } from './production-session-snapshot.js';
29
+ import { runWithStorageRootLease } from './root-authority.js';
27
30
  export const localExecutionPersistenceProvider = Object.freeze({
28
31
  async open({ canonicalPath }) {
29
32
  const closes = [];
@@ -52,7 +55,7 @@ export const localExecutionPersistenceProvider = Object.freeze({
52
55
  closes.push(() => operational.close());
53
56
  const graphControlStore = createAgentGraphControlStore(canonicalPath);
54
57
  closes.push(() => graphControlStore.close());
55
- const eventWaitStore = createSqliteEventWaitAuthority(canonicalPath);
58
+ const eventWaitStore = createSqliteEventWaitAuthority(canonicalPath, runtime.runtimeEventStore);
56
59
  closes.push(() => eventWaitStore.close());
57
60
  const goalStore = createSqliteGoalAuthority(canonicalPath);
58
61
  closes.push(() => goalStore.close());
@@ -60,6 +63,29 @@ export const localExecutionPersistenceProvider = Object.freeze({
60
63
  closes.push(() => interactionStore.close());
61
64
  await Promise.all([sessionStore.ready(), agentRunStore.ready?.(), interactionStore.ready()]);
62
65
  return {
66
+ createSnapshotStatePreparer(lease) {
67
+ if (lease.canonicalPath !== canonicalPath)
68
+ throw new Error('Snapshot lease belongs to another backend');
69
+ return {
70
+ async prepareState(input) {
71
+ input.cancellation.signal.throwIfAborted();
72
+ // Lock order: execution fence -> Artifact writer -> context values.
73
+ // The exporter holds the Artifact lock until both databases and
74
+ // their payloads are private. GC/publication uses these same locks.
75
+ await runWithStorageRootLease(lease, 'interactive', 'write', () => exportSessionBundleState({
76
+ stateRoot: canonicalPath,
77
+ configRoot: canonicalPath,
78
+ allowShared: true,
79
+ destinationRoot: input.destinationRoot,
80
+ sessionId: input.makaSessionId,
81
+ requireQuiescent: true,
82
+ lease,
83
+ }));
84
+ input.cancellation.signal.throwIfAborted();
85
+ return createSessionSnapshotStateIdentity(input.makaSessionId);
86
+ },
87
+ };
88
+ },
63
89
  sessionStore,
64
90
  agentRunStore,
65
91
  runtimeEventStore: runtime.runtimeEventStore,
@@ -153,7 +153,7 @@ class OperationalStateDatabaseOwner {
153
153
  configureSqliteRuntimeLockWait(this.database);
154
154
  this.database.exec('PRAGMA foreign_keys = ON');
155
155
  if (options.schemaMigration !== 'require_current') {
156
- configureSqliteRuntimeAutoVacuumForNewDatabase(this.database, databaseExisted);
156
+ configureSqliteRuntimeAutoVacuumForNewDatabase(this.database);
157
157
  }
158
158
  if (options.schemaMigration === 'require_current') {
159
159
  requireCurrentOperationalState(this.database);