maka-agent 0.2.2-dev.92.20261019 → 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 (364) hide show
  1. package/LICENSE +7 -7
  2. package/README.md +78 -18
  3. package/README.zh-CN.md +73 -15
  4. package/THIRD_PARTY_NOTICES.txt +12 -12
  5. package/dist/pi-goal.js +13 -0
  6. package/dist/pi-tui-runner.js +44 -1
  7. package/dist/run-command-core.js +111 -70
  8. package/dist/run-session-command.js +91 -15
  9. package/dist/run-turn-outcome.js +2 -33
  10. package/dist/runtime-host-session-channel.js +3 -1
  11. package/dist/runtime-host-session-driver.js +5 -0
  12. package/dist/tui-copy-catalog.js +24 -0
  13. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  14. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
  15. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
  16. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
  17. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
  18. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  19. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  20. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
  21. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  22. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
  23. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  24. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  25. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
  26. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
  27. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
  28. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
  29. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  30. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  31. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
  32. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
  33. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  34. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  35. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
  36. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
  37. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
  38. package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
  39. package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
  40. package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
  41. package/node_modules/@maka/core/dist/event-wait.js +28 -10
  42. package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
  43. package/node_modules/@maka/core/dist/model-catalog.js +19 -1
  44. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
  45. package/node_modules/@maka/core/dist/model-metadata.js +42 -1
  46. package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
  47. package/node_modules/@maka/core/dist/provider-registry.js +16 -2
  48. package/node_modules/@maka/core/dist/runtime-event.js +8 -0
  49. package/node_modules/@maka/core/dist/session-checkin.js +31 -0
  50. package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
  51. package/node_modules/@maka/core/package.json +2 -0
  52. package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
  53. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  54. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
  55. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  56. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
  57. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  58. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  59. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  60. package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
  61. package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
  62. package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  63. package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  64. package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
  65. package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
  66. package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
  67. package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
  68. package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
  69. package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
  70. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
  71. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  72. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  73. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
  74. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  75. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  76. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  77. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  78. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
  79. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  80. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  81. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  82. package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
  83. package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  84. package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  85. package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
  86. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
  87. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
  88. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
  89. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
  90. package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
  91. package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
  92. package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
  93. package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
  94. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  95. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  96. package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
  97. package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
  98. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  99. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  100. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
  101. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  102. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
  103. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
  104. package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  105. package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  106. package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
  107. package/node_modules/@maka/mcp/package.json +1 -1
  108. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +22 -9
  109. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
  110. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +101 -127
  111. package/node_modules/@maka/runtime/dist/event-wait-tool.js +2 -2
  112. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +32 -1
  113. package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
  114. package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
  115. package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
  116. package/node_modules/@maka/runtime/dist/model-history.js +16 -3
  117. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +7 -2
  118. package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
  119. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
  120. package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
  121. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
  122. package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
  123. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
  124. package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
  125. package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
  126. package/node_modules/@maka/runtime/dist/tool-runtime.js +8 -0
  127. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
  128. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
  129. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
  130. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
  131. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
  132. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  133. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  134. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
  135. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  136. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
  137. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  138. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  139. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
  140. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
  141. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
  142. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
  143. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  144. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  145. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
  146. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
  147. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  148. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  149. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
  150. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
  151. package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
  152. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  153. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
  154. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  155. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
  156. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  157. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  158. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  159. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
  160. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
  161. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  162. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  163. package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
  164. package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
  165. package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
  166. package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
  167. package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
  168. package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
  169. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
  170. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  171. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  172. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
  173. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  174. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  175. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  176. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  177. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
  178. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  179. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  180. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  181. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
  182. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  183. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  184. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
  185. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
  186. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
  187. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
  188. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
  189. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
  190. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
  191. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
  192. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
  193. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  194. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  195. package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
  196. package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
  197. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  198. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  199. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
  200. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  201. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
  202. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
  203. package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  204. package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  205. package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
  206. package/node_modules/@maka/runtime/package.json +2 -0
  207. package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
  208. package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
  209. package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +64 -13
  210. package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
  211. package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
  212. package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
  213. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
  214. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
  215. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
  216. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
  217. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
  218. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
  219. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
  220. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +1 -1
  221. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
  222. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
  223. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
  224. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
  225. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +35 -5
  226. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
  227. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
  228. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
  229. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
  230. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +1 -1
  231. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
  232. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
  233. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +87 -23
  234. package/node_modules/@maka/runtime-host/dist/assistant/service.js +49 -5
  235. package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
  236. package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -1
  237. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
  238. package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
  239. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
  240. package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
  241. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
  242. package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +63 -12
  243. package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
  244. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +123 -11
  245. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
  246. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +126 -4
  247. package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +58 -19
  248. package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
  249. package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
  250. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
  251. package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
  252. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
  253. package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
  254. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
  255. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
  256. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
  257. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
  258. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
  259. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
  260. package/node_modules/@maka/storage/dist/execution-stores.js +36 -1
  261. package/node_modules/@maka/storage/dist/local-execution-persistence.js +26 -0
  262. package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
  263. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  264. package/node_modules/@maka/storage/dist/session-bundle-policy.js +86 -16
  265. package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
  266. package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
  267. package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
  268. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
  269. package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
  270. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +31 -0
  271. package/node_modules/@maka/storage/package.json +3 -0
  272. package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
  273. package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
  274. package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
  275. package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
  276. package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
  277. package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
  278. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
  279. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
  280. package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
  281. package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
  282. package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
  283. package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
  284. package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
  285. package/node_modules/@modelcontextprotocol/client/package.json +5 -5
  286. package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
  287. package/node_modules/fast-uri/README.md +8 -0
  288. package/node_modules/fast-uri/index.js +98 -18
  289. package/node_modules/fast-uri/lib/utils.js +52 -0
  290. package/node_modules/fast-uri/package.json +1 -1
  291. package/node_modules/follow-redirects/index.js +10 -1
  292. package/node_modules/follow-redirects/package.json +1 -1
  293. package/node_modules/ip-address/README.md +104 -104
  294. package/node_modules/ip-address/dist/ipv4.js +7 -0
  295. package/node_modules/ip-address/dist/ipv6.js +7 -4
  296. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  297. package/node_modules/ip-address/package.json +2 -1
  298. package/node_modules/undici/README.md +25 -3
  299. package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  300. package/node_modules/undici/docs/docs/api/Client.md +11 -6
  301. package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  302. package/node_modules/undici/docs/docs/api/Errors.md +76 -1
  303. package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  304. package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  305. package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  306. package/node_modules/undici/docs/docs/index.md +12 -12
  307. package/node_modules/undici/docs/docs/type-map.json +66 -66
  308. package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  309. package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  310. package/node_modules/undici/lib/core/connect.js +10 -4
  311. package/node_modules/undici/lib/core/constants.js +12 -1
  312. package/node_modules/undici/lib/core/errors.js +38 -1
  313. package/node_modules/undici/lib/core/request.js +16 -1
  314. package/node_modules/undici/lib/core/symbols.js +2 -0
  315. package/node_modules/undici/lib/core/util.js +26 -1
  316. package/node_modules/undici/lib/dispatcher/agent.js +6 -2
  317. package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  318. package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  319. package/node_modules/undici/lib/dispatcher/client.js +4 -1
  320. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  321. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  322. package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  323. package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  324. package/node_modules/undici/lib/dispatcher/pool.js +11 -8
  325. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  326. package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  327. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  328. package/node_modules/undici/lib/handler/cache-handler.js +153 -15
  329. package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  330. package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  331. package/node_modules/undici/lib/handler/retry-handler.js +44 -11
  332. package/node_modules/undici/lib/interceptor/cache.js +11 -3
  333. package/node_modules/undici/lib/interceptor/decompress.js +22 -9
  334. package/node_modules/undici/lib/interceptor/dns.js +11 -0
  335. package/node_modules/undici/lib/interceptor/response-error.js +72 -28
  336. package/node_modules/undici/lib/milo/LICENSE.md +7 -0
  337. package/node_modules/undici/lib/milo/no-simd.js +1002 -0
  338. package/node_modules/undici/lib/milo/simd.js +1002 -0
  339. package/node_modules/undici/lib/mock/mock-agent.js +11 -0
  340. package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  341. package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  342. package/node_modules/undici/lib/util/cache.js +11 -5
  343. package/node_modules/undici/lib/web/cookies/util.js +19 -2
  344. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  345. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  346. package/node_modules/undici/lib/web/fetch/body.js +47 -38
  347. package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  348. package/node_modules/undici/lib/web/fetch/headers.js +2 -2
  349. package/node_modules/undici/lib/web/fetch/index.js +8 -4
  350. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  351. package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  352. package/node_modules/undici/package.json +9 -7
  353. package/node_modules/zod/package.json +1 -1
  354. package/node_modules/zod/v4/core/compile.cjs +8 -0
  355. package/node_modules/zod/v4/core/compile.js +8 -0
  356. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  357. package/node_modules/zod/v4/core/schemas.js +30 -0
  358. package/node_modules/zod/v4/core/util.cjs +15 -0
  359. package/node_modules/zod/v4/core/util.js +14 -0
  360. package/node_modules/zod/v4/core/versions.cjs +1 -1
  361. package/node_modules/zod/v4/core/versions.js +1 -1
  362. package/package.json +2 -2
  363. package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
  364. package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
@@ -0,0 +1,257 @@
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 { isWorkHubCoordinationSessionId, userFacingText, } from '@maka/core/session';
20
+ import { SIDE_CONVERSATION_SESSION_LABEL } from '@maka/core/side-conversation';
21
+ import { buildCheckinPrompt, CHECKIN_LOOKBACK_MS, decodeCheckinModelOutput, selectCheckinCandidates, validateCheckinCards, } from '@maka/runtime/session-checkin';
22
+ import { abortable } from '../client/wait-for-ready.js';
23
+ /** Sessions read in full per check-in; the rest of the catalog is judged by its row. */
24
+ const CHECKIN_DEEP_READ_MAX = 24;
25
+ const CHECKIN_TIMEOUT_MS = 60_000;
26
+ const CHECKIN_EFFECTS_RETAINED = 16;
27
+ const EXCLUDED_LABELS = new Set([
28
+ SIDE_CONVERSATION_SESSION_LABEL,
29
+ 'mode:bot',
30
+ 'mode:deep_research',
31
+ 'scheduled-task',
32
+ ]);
33
+ /**
34
+ * Runs one check-in per effect identity: a retry with the same identity gets
35
+ * the same answer and never pays for a second model call while this Host runs.
36
+ */
37
+ export class HostSessionCheckinCoordinator {
38
+ ports;
39
+ handlers = {
40
+ 'session.checkin.generate': (input, context) => this.generate(input, context),
41
+ };
42
+ #effects = new Map();
43
+ #aborts = new Set();
44
+ #closed = false;
45
+ constructor(ports) {
46
+ this.ports = ports;
47
+ }
48
+ generate(input, context) {
49
+ if (this.#closed)
50
+ return Promise.resolve(draining());
51
+ const existing = this.#effects.get(input.effectId);
52
+ if (existing) {
53
+ return existing.since === input.since
54
+ ? existing.task
55
+ : Promise.resolve({
56
+ ok: false,
57
+ error: {
58
+ code: 'operation_conflict',
59
+ message: 'Check-in effect identity is already in use',
60
+ },
61
+ });
62
+ }
63
+ const residency = context.acquireResidency();
64
+ const abort = new AbortController();
65
+ this.#aborts.add(abort);
66
+ const signal = AbortSignal.any([
67
+ abort.signal,
68
+ AbortSignal.timeout(this.ports.timeoutMs ?? CHECKIN_TIMEOUT_MS),
69
+ ]);
70
+ const task = this.#run(input, context, signal)
71
+ .then((result) => ({ ok: true, result }), () => this.#closed
72
+ ? draining()
73
+ : { ok: false, error: { code: 'internal_failure', message: 'Check-in failed' } })
74
+ .finally(() => {
75
+ this.#aborts.delete(abort);
76
+ residency.release();
77
+ });
78
+ this.#effects.set(input.effectId, { since: input.since, task });
79
+ while (this.#effects.size > CHECKIN_EFFECTS_RETAINED) {
80
+ this.#effects.delete(this.#effects.keys().next().value);
81
+ }
82
+ return task;
83
+ }
84
+ beginDrain() {
85
+ this.#closed = true;
86
+ for (const abort of this.#aborts)
87
+ abort.abort();
88
+ }
89
+ async close() {
90
+ this.beginDrain();
91
+ await Promise.allSettled([...this.#effects.values()].map((effect) => effect.task));
92
+ }
93
+ async #run(input, context, signal) {
94
+ const effectId = input.effectId;
95
+ if (!(await abortable(() => this.ports.allowed(), signal)))
96
+ return { kind: 'empty', effectId };
97
+ const target = await abortable(() => this.ports.readModelTarget(), signal);
98
+ if (!target)
99
+ return { kind: 'failed', effectId, errorClass: 'configuration' };
100
+ const now = this.ports.now?.() ?? Date.now();
101
+ const sessions = await abortable(() => this.ports.listSessions(context), signal);
102
+ const recent = sessions
103
+ .filter((session) => checkinMayRead(session, now))
104
+ .sort((a, b) => b.activityAt - a.activityAt)
105
+ .slice(0, CHECKIN_DEEP_READ_MAX);
106
+ const states = [];
107
+ let unreadable = 0;
108
+ for (const session of recent) {
109
+ const state = await abortable(() => this.ports.readSession(session), signal).catch((error) => {
110
+ if (signal.aborted)
111
+ throw error;
112
+ unreadable += 1;
113
+ return undefined;
114
+ });
115
+ if (state)
116
+ states.push(state);
117
+ }
118
+ // One unreadable Session is skipped; reading none at all is a broken check-in, not a quiet one.
119
+ if (unreadable > 0 && states.length === 0) {
120
+ return { kind: 'failed', effectId, errorClass: 'unknown' };
121
+ }
122
+ const candidates = selectCheckinCandidates(states, { now, since: input.since });
123
+ if (candidates.length === 0)
124
+ return { kind: 'empty', effectId };
125
+ const model = await this.ports.generate({
126
+ target,
127
+ prompt: buildCheckinPrompt(candidates),
128
+ abortSignal: signal,
129
+ });
130
+ if (!model.ok)
131
+ return { kind: 'failed', effectId, errorClass: model.errorClass };
132
+ const decoded = decodeCheckinModelOutput(model.text);
133
+ if (!decoded.ok)
134
+ return { kind: 'failed', effectId, errorClass: 'invalid_response' };
135
+ const validation = validateCheckinCards(decoded.cards, candidates);
136
+ return {
137
+ kind: 'generated',
138
+ effectId,
139
+ cards: validation.cards,
140
+ dropped: validation.dropped.length,
141
+ };
142
+ }
143
+ }
144
+ const CATALOG_PAGES_MAX = 10;
145
+ const MESSAGES_KEPT = 20;
146
+ /** Reads catalog pages until they run out or the page budget does. */
147
+ export async function listCheckinCatalogSessions(query) {
148
+ const sessions = [];
149
+ let next = { kind: 'list_start' };
150
+ for (let page = 0; page < CATALOG_PAGES_MAX; page += 1) {
151
+ const outcome = await query(next);
152
+ if (!outcome.ok || outcome.result.kind !== 'page')
153
+ break;
154
+ for (const item of outcome.result.sessions) {
155
+ if (!('kind' in item))
156
+ sessions.push(item);
157
+ }
158
+ if (!outcome.result.nextCursor)
159
+ break;
160
+ next = {
161
+ kind: 'list_continue',
162
+ revision: outcome.result.revision,
163
+ cursor: outcome.result.nextCursor,
164
+ };
165
+ }
166
+ return sessions;
167
+ }
168
+ /** Maps what the Host recorded about one Session into the check-in's view of it. */
169
+ export function checkinSessionState(input) {
170
+ const turn = input.canonical.rootTurn;
171
+ const waitingForUser = input.session.status === 'waiting_for_user' ||
172
+ input.canonical.interactions.pending.length > 0 ||
173
+ turn?.status === 'waiting_for_user';
174
+ let lastTurn = null;
175
+ if (!turn && !waitingForUser)
176
+ lastTurn = recordedLastTurn(input.turns);
177
+ if (turn && !waitingForUser) {
178
+ if (turn.status === 'completed')
179
+ lastTurn = { status: 'completed' };
180
+ else if (turn.status === 'failed') {
181
+ lastTurn = {
182
+ status: 'failed',
183
+ failureClass: turn.failureClass,
184
+ ...(turn.failureMessage ? { failureMessage: turn.failureMessage } : {}),
185
+ };
186
+ }
187
+ else if (turn.status === 'cancelled') {
188
+ lastTurn = { status: 'cancelled', abortSource: turn.abortSource };
189
+ }
190
+ else
191
+ lastTurn = { status: 'in_progress' };
192
+ }
193
+ const goal = input.canonical.goal;
194
+ const texts = [];
195
+ for (const message of input.messages) {
196
+ if (message.type === 'user' && !message.origin && typeof message.text === 'string') {
197
+ texts.push({ role: 'user', text: userFacingText(message) });
198
+ }
199
+ else if (message.type === 'assistant' && typeof message.text === 'string') {
200
+ texts.push({ role: 'assistant', text: message.text });
201
+ }
202
+ }
203
+ const first = texts.find((message) => message.role === 'user');
204
+ const recent = texts.slice(-MESSAGES_KEPT);
205
+ return {
206
+ sessionId: input.session.id,
207
+ revision: input.session.revision,
208
+ name: input.session.name,
209
+ activityAt: input.session.activityAt,
210
+ lastTurn,
211
+ waitingForUser,
212
+ goal: goal
213
+ ? { status: goal.status, condition: goal.condition, lastReason: goal.lastReason }
214
+ : null,
215
+ todos: input.todos,
216
+ messages: first && !recent.includes(first) ? [first, ...recent] : recent,
217
+ };
218
+ }
219
+ /**
220
+ * A Session written before Root Turn admissions, or imported, still carries
221
+ * `turn_state` records. Only a recorded status counts; an inferred one is a
222
+ * reading of old data, not evidence.
223
+ */
224
+ function recordedLastTurn(turns) {
225
+ const turn = turns.at(-1);
226
+ if (!turn || turn.statusSource !== 'recorded')
227
+ return null;
228
+ switch (turn.status) {
229
+ case 'completed':
230
+ return { status: 'completed' };
231
+ case 'failed':
232
+ return {
233
+ status: 'failed',
234
+ failureClass: turn.errorClass ?? 'unknown',
235
+ ...(turn.failureMessage ? { failureMessage: turn.failureMessage } : {}),
236
+ };
237
+ case 'aborted':
238
+ return { status: 'cancelled', abortSource: turn.abortSource ?? 'unknown' };
239
+ case 'running':
240
+ return { status: 'in_progress' };
241
+ }
242
+ }
243
+ /** Judged from the catalog row alone, before any Session is read in full. */
244
+ export function checkinMayRead(session, now) {
245
+ return (!session.isArchived &&
246
+ !session.subagent &&
247
+ !session.parentSessionId &&
248
+ session.backend === 'ai-sdk' &&
249
+ session.status !== 'running' &&
250
+ !(session.liveRunState?.runningTurnIds.length ?? 0) &&
251
+ !isWorkHubCoordinationSessionId(session.id) &&
252
+ !session.labels.some((label) => EXCLUDED_LABELS.has(label)) &&
253
+ session.activityAt >= now - CHECKIN_LOOKBACK_MS);
254
+ }
255
+ function draining() {
256
+ return { ok: false, error: { code: 'host_draining', message: 'Runtime Host is draining' } };
257
+ }
@@ -0,0 +1,282 @@
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 { publishSessionCheckpointV1, SessionRepositoryError, } from '@maka/storage/session-repository';
21
+ import { SessionSnapshotError } from '@maka/storage/quiescent-session-snapshot';
22
+ export class HostCheckpointError extends Error {
23
+ code;
24
+ constructor(code, message, options) {
25
+ super(message, options);
26
+ this.code = code;
27
+ this.name = 'HostCheckpointError';
28
+ }
29
+ }
30
+ /** Explicit management API, not a model tool, automatic live write, or second Head. */
31
+ export class HostSessionCheckpointCoordinator {
32
+ dependencies;
33
+ #active = new Set();
34
+ #drain = new AbortController();
35
+ #closed = false;
36
+ constructor(dependencies) {
37
+ this.dependencies = dependencies;
38
+ }
39
+ publish(input) {
40
+ if (this.#closed)
41
+ return Promise.reject(new HostCheckpointError('closed', 'Checkpoint publication is closed'));
42
+ const accepted = { ...input };
43
+ if (!validId(accepted.sessionId) ||
44
+ !validId(accepted.requestId) ||
45
+ (accepted.signal !== undefined && !(accepted.signal instanceof AbortSignal)) ||
46
+ (accepted.confirmationGrantId !== undefined &&
47
+ !/^[A-Za-z0-9_-]{1,128}$/u.test(accepted.confirmationGrantId)) ||
48
+ (accepted.deadlineAt !== undefined && !Number.isSafeInteger(accepted.deadlineAt))) {
49
+ return Promise.reject(new HostCheckpointError('invalid_input', 'Invalid checkpoint publication request'));
50
+ }
51
+ // Cooperative deadline for the whole attempt, not part of commit identity.
52
+ const deadlineAt = Math.min(accepted.deadlineAt ?? Infinity, Date.now() + 60_000);
53
+ if (deadlineAt <= Date.now())
54
+ return Promise.reject(new HostCheckpointError('cancelled', 'Checkpoint deadline has expired'));
55
+ const timer = AbortSignal.timeout(Math.max(0, deadlineAt - Date.now()));
56
+ const signal = AbortSignal.any([
57
+ timer,
58
+ this.#drain.signal,
59
+ ...(accepted.signal ? [accepted.signal] : []),
60
+ ]);
61
+ const task = this.dependencies
62
+ .runAuthorized(() => this.#publish(accepted, signal, deadlineAt))
63
+ .catch((error) => {
64
+ throw normalizeError(error);
65
+ });
66
+ this.#active.add(task);
67
+ void task.finally(() => this.#active.delete(task)).catch(() => { });
68
+ return task;
69
+ }
70
+ beginDrain() {
71
+ this.#closed = true;
72
+ this.#drain.abort();
73
+ }
74
+ async close() {
75
+ this.beginDrain();
76
+ await Promise.allSettled([...this.#active]);
77
+ }
78
+ async #publish(input, signal, deadlineAt) {
79
+ const deps = this.dependencies;
80
+ signal.throwIfAborted();
81
+ return deps.journal.withSession(input.sessionId, async (document, save) => {
82
+ signal.throwIfAborted();
83
+ const releaseBundle = async (position) => {
84
+ const pending = document.requests[position];
85
+ if (!pending.bundleCleanupPending)
86
+ return 'released';
87
+ try {
88
+ await deps.cleanupBundle(pending.commitId);
89
+ const { bundleCleanupPending: _pending, ...released } = pending;
90
+ document.requests[position] = released;
91
+ try {
92
+ await save();
93
+ }
94
+ catch (error) {
95
+ document.requests[position] = pending;
96
+ throw error;
97
+ }
98
+ return 'released';
99
+ }
100
+ catch {
101
+ // The terminal outcome is already durable. Retain cleanup ownership
102
+ // for the next request/restart, without changing that outcome.
103
+ return 'pending_recovery';
104
+ }
105
+ };
106
+ let index = document.requests.findIndex((request) => request.requestId === input.requestId);
107
+ let request = document.requests[index];
108
+ if (request && request.confirmationGrantId !== input.confirmationGrantId) {
109
+ throw new HostCheckpointError('conflict', 'Checkpoint request identity was reused with different input');
110
+ }
111
+ // Holding this process-safe lock proves no earlier capture is still running.
112
+ // Its bytes were never durably fixed, so the identity can only be aborted.
113
+ for (let position = 0; position < document.requests.length; position++) {
114
+ const previous = document.requests[position];
115
+ if (previous.phase === 'capturing') {
116
+ document.requests[position] = { ...previous, phase: 'aborted' };
117
+ await save();
118
+ }
119
+ if (previous.phase !== 'prepared')
120
+ await releaseBundle(position);
121
+ }
122
+ request = document.requests[index];
123
+ if (request?.phase === 'aborted') {
124
+ throw new HostCheckpointError('interrupted', 'Snapshot capture did not complete; use a new request identity');
125
+ }
126
+ if (request?.phase === 'conflicted')
127
+ throw new HostCheckpointError('conflict', 'Checkpoint publication previously conflicted');
128
+ if (!request) {
129
+ if (document.requests.some((record) => record.phase === 'prepared')) {
130
+ throw new HostCheckpointError('busy', 'A prepared checkpoint must be reconciled using its original request identity');
131
+ }
132
+ let current;
133
+ try {
134
+ current = await deps.repository.checkoutCurrent(document.binding.repositorySessionId);
135
+ }
136
+ catch (error) {
137
+ if (!(error instanceof SessionRepositoryError) || error.code !== 'session_not_found')
138
+ throw error;
139
+ }
140
+ if (current && current.agentId !== document.binding.agentId) {
141
+ throw new HostCheckpointError('conflict', 'Repository Session binding does not match this Host');
142
+ }
143
+ request = {
144
+ requestId: input.requestId,
145
+ commitId: randomUUID(),
146
+ ...(input.confirmationGrantId ? { confirmationGrantId: input.confirmationGrantId } : {}),
147
+ expectedRevision: current?.ref.revision ?? null,
148
+ bundleCleanupPending: true,
149
+ phase: 'capturing',
150
+ };
151
+ index = document.requests.length;
152
+ document.requests.push(request);
153
+ await save();
154
+ signal.throwIfAborted();
155
+ const artifact = await deps.capture({
156
+ binding: document.binding,
157
+ commitId: request.commitId,
158
+ confirmationGrantId: input.confirmationGrantId,
159
+ signal,
160
+ deadlineAt,
161
+ });
162
+ signal.throwIfAborted();
163
+ const checkpoint = await publishSessionCheckpointV1({
164
+ objectStore: deps.objects,
165
+ compatibilityBundle: artifact,
166
+ });
167
+ request = {
168
+ ...request,
169
+ phase: 'prepared',
170
+ checkpoint,
171
+ ...(artifact.snapshotCleanup.state === 'pending_recovery'
172
+ ? { snapshotCleanupPending: true }
173
+ : {}),
174
+ };
175
+ document.requests[index] = request;
176
+ // On an uncertain journal write, leave recovery to a fresh read. Never
177
+ // overwrite a possibly prepared record with a fabricated failure.
178
+ await save();
179
+ }
180
+ if (request.phase === 'committed') {
181
+ await deps.objects.assertReadable(request.checkpoint.manifest);
182
+ await deps.objects.assertReadable(request.checkpoint.value.compatibilityBundle);
183
+ return structuredClone({
184
+ requestId: request.requestId,
185
+ binding: document.binding,
186
+ committed: request.result,
187
+ stagingCleanup: request.snapshotCleanupPending ? 'pending_recovery' : 'released',
188
+ bundleCleanup: request.bundleCleanupPending ? 'pending_recovery' : 'released',
189
+ });
190
+ }
191
+ if (request.phase !== 'prepared')
192
+ throw new Error('Invalid checkpoint publication transition');
193
+ signal.throwIfAborted();
194
+ // No cancellation point between CAS and receipt persistence: after CAS
195
+ // succeeds, reporting cancellation would falsely suggest nothing committed.
196
+ let committed;
197
+ try {
198
+ committed =
199
+ request.expectedRevision === null
200
+ ? await deps.repository
201
+ .createSession({
202
+ sessionId: document.binding.repositorySessionId,
203
+ agentId: document.binding.agentId,
204
+ checkpoint: request.checkpoint,
205
+ })
206
+ .catch(async (error) => {
207
+ if (!(error instanceof SessionRepositoryError) ||
208
+ error.code !== 'session_already_exists')
209
+ throw error;
210
+ const existing = await deps.repository.checkoutCurrent(document.binding.repositorySessionId);
211
+ if (existing.agentId !== document.binding.agentId ||
212
+ existing.forkedFrom !== undefined ||
213
+ existing.lastCommittedActivationId !== undefined ||
214
+ JSON.stringify(existing.checkpoint) !== JSON.stringify(request.checkpoint))
215
+ throw error;
216
+ return existing;
217
+ })
218
+ : await deps.repository.commit({
219
+ sessionId: document.binding.repositorySessionId,
220
+ expectedRevision: request.expectedRevision,
221
+ checkpoint: request.checkpoint,
222
+ commitId: request.commitId,
223
+ });
224
+ }
225
+ catch (error) {
226
+ if (error instanceof SessionRepositoryError &&
227
+ ['revision_conflict', 'session_already_exists', 'idempotency_conflict'].includes(error.code)) {
228
+ document.requests[index] = { ...request, phase: 'conflicted' };
229
+ await save();
230
+ await releaseBundle(index);
231
+ }
232
+ throw error;
233
+ }
234
+ const completed = {
235
+ ...request,
236
+ phase: 'committed',
237
+ result: committed,
238
+ };
239
+ document.requests[index] = completed;
240
+ await save();
241
+ const bundleCleanup = await releaseBundle(index);
242
+ return structuredClone({
243
+ requestId: request.requestId,
244
+ binding: document.binding,
245
+ committed,
246
+ stagingCleanup: request.snapshotCleanupPending ? 'pending_recovery' : 'released',
247
+ bundleCleanup,
248
+ });
249
+ });
250
+ }
251
+ }
252
+ function validId(value) {
253
+ return typeof value === 'string' && /^[A-Za-z0-9_-]{1,128}$/u.test(value);
254
+ }
255
+ function normalizeError(error) {
256
+ if (error instanceof HostCheckpointError)
257
+ return error;
258
+ // The generic snapshot layer wraps Host eligibility failures. Preserve their
259
+ // bounded public classification without exposing arbitrary provider errors.
260
+ if (error instanceof SessionSnapshotError && error.cause instanceof HostCheckpointError)
261
+ return error.cause;
262
+ if (error instanceof SessionRepositoryError) {
263
+ const code = ['revision_conflict', 'session_already_exists', 'idempotency_conflict'].includes(error.code)
264
+ ? 'conflict'
265
+ : 'publication_failed';
266
+ return new HostCheckpointError(code, 'Checkpoint Repository rejected publication', {
267
+ cause: error,
268
+ });
269
+ }
270
+ if (error instanceof SessionSnapshotError) {
271
+ if (error.code === 'snapshot_busy' || error.code === 'session_not_quiescent') {
272
+ return new HostCheckpointError('busy', 'Session is not quiescent', { cause: error });
273
+ }
274
+ }
275
+ if ((error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError')) ||
276
+ (error instanceof SessionSnapshotError && error.code === 'snapshot_cancelled')) {
277
+ return new HostCheckpointError('cancelled', 'Checkpoint publication attempt was cancelled', {
278
+ cause: error,
279
+ });
280
+ }
281
+ return new HostCheckpointError('publication_failed', 'Checkpoint publication failed; retry the same request to reconcile', { cause: error });
282
+ }