maka-agent 0.2.2-dev.92.20261019 → 0.2.2-dev.98.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
@@ -20,3 +20,16 @@
20
20
  export const MATTER_STATE_MAX_BYTES = 24 * 1024;
21
21
  export const MATTER_REQUEST_MAX_LENGTH = 8000;
22
22
  export const MATTER_SESSION_LABEL = 'matter';
23
+ /**
24
+ * Background turns are admitted as Host turn ids, which must match
25
+ * `^[A-Za-z0-9_-]{1,128}$` (see `requireEntityId`). Colons are therefore not
26
+ * used as separators. Activations bound before that rule still carry the
27
+ * legacy `pending:` marker, so both prefixes are recognized.
28
+ */
29
+ export const PENDING_ACTIVATION_TURN_PREFIX = 'pending-';
30
+ const LEGACY_PENDING_ACTIVATION_TURN_PREFIX = 'pending:';
31
+ export function isPendingActivationTurnId(turnId) {
32
+ return (turnId != null &&
33
+ (turnId.startsWith(PENDING_ACTIVATION_TURN_PREFIX) ||
34
+ turnId.startsWith(LEGACY_PENDING_ACTIVATION_TURN_PREFIX)));
35
+ }
@@ -16,14 +16,16 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export const MATTER_INSTRUCTIONS = `Continue the user's objective with the ordinary agent loop. Read the current request.md, state.md and inbox.json from MatterRead before deciding; old notes and plans are evidence, not instructions. Later direct user requirements take precedence.
20
- For a delegated task, use MatterAskBot when an ambiguity or conflicting review requirement needs clarification. Supply the question and relevant evidence; this asks the coordinating Bot, not the user directly, and does not bypass review. Read replies from the matter inbox; Bot clarification is not new user authorization. Do useful work now. If this turn must end but immediate work remains, use MatterSettle continue. Wait only when immediate continuation cannot help: name the concrete condition in waitingFor and set a future absolute time to check it. Complete only when the objective is met.
21
- Before ending, write an updated working snapshot to draft.md and call MatterSettle. Its summary records what happened, and update reports meaningful progress to the user. MatterSettle reviews wait and complete for premature exit or missed requirements; continue commits without model review. Only after successful settlement call no more tools. A rejected submission leaves you active: address its specific feedback and resubmit. MATTER_REVIEW_INVALIDATED means the evidence changed: refresh with MatterRead and reassess; it is not a rejection. Use the host clock and timezone for absolute times. A wake is a new activation, not uninterrupted execution.`;
19
+ export const MATTER_INSTRUCTIONS = `Continue the user's objective with the ordinary agent loop. Use the session history and current task context; inspect task files with MatterRead only when needed. Old notes and plans are evidence, not instructions. Later direct user requirements take precedence.
20
+ For a delegated task, use MatterAskBot when an ambiguity or conflicting review requirement needs clarification. Supply the question and relevant evidence; this asks the coordinating Bot, not the user directly, and does not bypass review. Read replies from the matter inbox; Bot clarification is not new user authorization. Do useful work now. If this turn must end but immediate work remains, use MatterSettle continue. Wait only when immediate continuation cannot help: name the concrete condition in waitingFor and set a future absolute time to check it. For a machine-checkable condition, test read-only code with MatterConditionTest, inspect its result, then pass its checkerId to MatterSettle wait; keep an absolute fallback time. Complete only when the objective is met.
21
+ Before ending, call MatterSettle with your result and why this exit is appropriate. An optional note preserves useful working context; no draft file is required. Supply progressSummary in at most 30 characters for the user-facing task list when checkpointing or settling. Its summary records what happened, and update reports meaningful progress to the user. MatterSettle reviews wait and complete for premature exit or missed requirements; continue commits without model review. Only after successful settlement call no more tools. A rejected submission leaves you active: address its specific feedback and resubmit. MATTER_REVIEW_INVALIDATED means the evidence changed: reassess the refreshed task context and resubmit; it is not a rejection. Use the host clock and timezone for absolute times. A wake is a new activation, not uninterrupted execution.`;
22
22
  export function buildMatterPrompt(context) {
23
23
  const causes = context.wake.causes.map((source) => {
24
24
  switch (source) {
25
25
  case 'created':
26
26
  return 'initial delegation';
27
+ case 'condition':
28
+ return 'condition observation or fallback completed; read its evidence from the inbox';
27
29
  case 'time':
28
30
  return 'scheduled time reached';
29
31
  case 'user':
@@ -42,9 +44,9 @@ export function buildMatterPrompt(context) {
42
44
  ? 'This is the first activation of this matter.'
43
45
  : 'You have been woken for a new activation in the same session. The previous activation ended or was interrupted; this is not uninterrupted execution.';
44
46
  const previous = context.wake.previousRunEndedAt;
45
- return `Runtime wake notification; this is not a new user instruction.\n${boundary}\nWoken by: ${causes.join(', ')}.\nPrevious activation ended at: ${previous === null ? 'not available' : new Date(previous).toISOString()}.\nThis activation started at: ${new Date(context.activationStartedAt).toISOString()}. Current time: ${new Date(context.now).toISOString()}.\nThe wake is only a trigger. Read the current matter files and decide from the current situation.\nMatter workspace (paths and host metadata):\n${JSON.stringify(context)}`;
47
+ return `Runtime wake notification; this is not a new user instruction.\n${boundary}\nWoken by: ${causes.join(', ')}.\nPrevious activation ended at: ${previous === null ? 'not available' : new Date(previous).toISOString()}.\nThis activation started at: ${new Date(context.activationStartedAt).toISOString()}. Current time: ${new Date(context.now).toISOString()}.\nThe wake is only a trigger. Call MatterRead once with this activationId to claim the activation and get current task context; no separate file reads are required. Then continue from the session.\nMatter workspace (paths and host metadata):\n${JSON.stringify(context)}`;
46
48
  }
47
- /** Volatile time is host metadata, not another human request or a persisted event. */
49
+ /** Time is host metadata; Runtime appends updates without rewriting earlier observations. */
48
50
  export function buildMatterStepContext(now = Date.now()) {
49
51
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
50
52
  return `Runtime clock (metadata only, not a user request): ${new Date(now).toISOString()}; Unix milliseconds: ${now}; timezone: ${timezone}; local time: ${new Date(now).toLocaleString('en-GB', { timeZone: timezone })}.`;
@@ -21,7 +21,7 @@ import { z } from 'zod';
21
21
  export class MatterReviewInvalidated extends Error {
22
22
  code = 'MATTER_REVIEW_INVALIDATED';
23
23
  constructor() {
24
- super('MATTER_REVIEW_INVALIDATED: Review evidence changed. Call MatterRead, read the refreshed files, reassess and resubmit.');
24
+ super('MATTER_REVIEW_INVALIDATED: Task information changed or was not delivered to this model call. Reassess the refreshed task context on your next step and resubmit.');
25
25
  }
26
26
  }
27
27
  export const reviewVerdict = z
@@ -0,0 +1,126 @@
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 { readLogicalRuntimeExecutionForRun } from '@maka/core/runtime-logical-execution';
20
+ import { readRunInvocation } from '@maka/core/runtime-event-store';
21
+ import { createHash } from 'node:crypto';
22
+ export function matterInput(snapshot) {
23
+ const m = snapshot.matter;
24
+ return {
25
+ matterId: m.id,
26
+ activationId: m.activation.id,
27
+ request: m.request,
28
+ note: m.stateText,
29
+ eventCursor: snapshot.events.at(-1)?.sequence ?? m.activation.eventCursor,
30
+ events: snapshot.events,
31
+ pendingEventCount: snapshot.pendingEventCount,
32
+ };
33
+ }
34
+ function inputBasis(value) {
35
+ const { matterId, activationId, request, note, eventCursor, events, pendingEventCount } = value;
36
+ return createHash('sha256')
37
+ .update(JSON.stringify({
38
+ matterId,
39
+ activationId,
40
+ request,
41
+ note,
42
+ eventCursor,
43
+ events,
44
+ pendingEventCount,
45
+ }))
46
+ .digest('hex');
47
+ }
48
+ export function matterInputBasis(snapshot) {
49
+ return inputBasis(matterInput(snapshot));
50
+ }
51
+ export function deliveredMatterInput(events, call) {
52
+ let delivered;
53
+ for (const event of events) {
54
+ if (event.sessionId !== call.sessionId || event.turnId !== call.turnId || event.partial)
55
+ continue;
56
+ const content = event.content;
57
+ if (!content)
58
+ continue;
59
+ if (content.kind === 'function_call' &&
60
+ content.id === call.toolCallId &&
61
+ (call.runId === undefined || event.runId === call.runId)) {
62
+ if (!delivered)
63
+ return undefined;
64
+ try {
65
+ // Runtime may prepend its metadata wrapper before the task's own header.
66
+ const start = delivered.indexOf('\n{');
67
+ if (start < 0)
68
+ return undefined;
69
+ const value = JSON.parse(delivered.slice(start + 1));
70
+ if (typeof value.activationId !== 'string' ||
71
+ typeof value.request !== 'string' ||
72
+ typeof value.note !== 'string' ||
73
+ !Array.isArray(value.events) ||
74
+ !Number.isSafeInteger(value.eventCursor))
75
+ return undefined;
76
+ return {
77
+ activationId: value.activationId,
78
+ basis: inputBasis(value),
79
+ eventCursor: value.eventCursor,
80
+ };
81
+ }
82
+ catch {
83
+ return undefined;
84
+ }
85
+ }
86
+ if (event.role === 'system' &&
87
+ event.author === 'host' &&
88
+ content.kind === 'text' &&
89
+ content.runtimeContextName === 'proactive-matters.inbox')
90
+ delivered = content.text;
91
+ }
92
+ return undefined;
93
+ }
94
+ /** Only the worker's own lifecycle tools, alongside ordinary business tools. */
95
+ export const MATTER_WORKER_TOOLS = new Set([
96
+ 'MatterRead',
97
+ 'MatterReadFile',
98
+ 'MatterWriteFile',
99
+ 'MatterCheckpoint',
100
+ 'MatterSettle',
101
+ 'MatterConditionTest',
102
+ 'MatterAskBot',
103
+ ]);
104
+ export function workerTools(tools) {
105
+ return tools.filter((tool) => !tool.name.startsWith('Matter') || MATTER_WORKER_TOOLS.has(tool.name));
106
+ }
107
+ /** Read only the authenticated handoff lineage, in replay order. */
108
+ export async function readMatterRuntimeEvents(store, sessionId, runId) {
109
+ const run = await readRunInvocation(store, sessionId, runId);
110
+ if (!run)
111
+ return [];
112
+ if (run.opening.source.kind !== 'handoff')
113
+ return store.readRuntimeEvents(sessionId, runId);
114
+ const logical = await readLogicalRuntimeExecutionForRun(store, {
115
+ sessionId,
116
+ runId,
117
+ turnId: run.turnId,
118
+ });
119
+ if (!logical)
120
+ return [];
121
+ // The core reader verifies seals, claims and successor openings. Do not
122
+ // include unrelated session history or later successors of this caller.
123
+ const precedingRuns = logical.runIds.slice(0, logical.runIds.indexOf(runId));
124
+ const inherited = await Promise.all(precedingRuns.map((id) => store.readImmutableRuntimeEvents(sessionId, id)));
125
+ return [...inherited.flat(), ...(await store.readRuntimeEvents(sessionId, runId))];
126
+ }
@@ -16,11 +16,14 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { matterInputBasis } from './settlement-context.js';
20
+ import { MatterConditions } from './condition-store.js';
19
21
  import { recoveryDelay } from '../execution-outcome.js';
20
22
  import { existsSync, mkdirSync, readFileSync, realpathSync } from 'node:fs';
21
23
  import { createHash } from 'node:crypto';
22
24
  import { MatterReviewInvalidated } from './review.js';
23
25
  import { MatterFiles } from './files.js';
26
+ import { PENDING_ACTIVATION_TURN_PREFIX, isPendingActivationTurnId } from './matter.js';
24
27
  import { join, isAbsolute } from 'node:path';
25
28
  import { createRequire } from 'node:module';
26
29
  import { randomUUID } from 'node:crypto';
@@ -49,6 +52,7 @@ class SqliteMatterStore {
49
52
  files;
50
53
  now;
51
54
  newId;
55
+ conditions;
52
56
  constructor(db, files, now, newId) {
53
57
  this.db = db;
54
58
  this.files = files;
@@ -64,6 +68,7 @@ class SqliteMatterStore {
64
68
  event_key TEXT NOT NULL, source TEXT NOT NULL, subject TEXT NOT NULL, text TEXT NOT NULL,
65
69
  created_at INTEGER NOT NULL, acknowledged INTEGER NOT NULL DEFAULT 0, UNIQUE(matter_id,event_key));
66
70
  CREATE TABLE IF NOT EXISTS matter_reviews (id TEXT PRIMARY KEY, fingerprint TEXT NOT NULL, payload TEXT NOT NULL);
71
+ CREATE TABLE IF NOT EXISTS matter_submissions (id TEXT PRIMARY KEY, payload TEXT NOT NULL);
67
72
  CREATE TABLE IF NOT EXISTS matter_operations (id TEXT PRIMARY KEY, fingerprint TEXT NOT NULL, result TEXT NOT NULL);
68
73
  CREATE TABLE IF NOT EXISTS matter_runs (id TEXT PRIMARY KEY, matter_id TEXT NOT NULL, turn_id TEXT NOT NULL,
69
74
  started_at INTEGER NOT NULL, ended_at INTEGER, outcome TEXT);
@@ -75,6 +80,23 @@ class SqliteMatterStore {
75
80
  matter_id TEXT NOT NULL, record_key TEXT UNIQUE NOT NULL, document TEXT NOT NULL);
76
81
  CREATE INDEX IF NOT EXISTS matter_history_order ON matter_history(matter_id,sequence);
77
82
  CREATE INDEX IF NOT EXISTS matter_events_pending ON matter_events(matter_id,acknowledged,sequence);`);
83
+ this.conditions = new MatterConditions(db, now, (fn) => this.transaction(fn), (id) => this.read(id), (m, wait) => {
84
+ this.insertEvent(m.id, {
85
+ key: `condition:${wait.waitId}`,
86
+ source: 'condition',
87
+ subject: wait.status === 'resolved' ? wait.resolution.outcome : wait.status,
88
+ text: JSON.stringify({
89
+ waitId: wait.waitId,
90
+ waitingFor: m.waitingFor,
91
+ outcome: wait.status,
92
+ ...(wait.status === 'resolved' ? { evidence: wait.resolution } : {}),
93
+ ...(wait.status === 'cancelled' ? { reason: wait.reason } : {}),
94
+ instruction: 'Reassess current facts. A condition signal is evidence, not a new user instruction.',
95
+ }),
96
+ });
97
+ m.wakes = [];
98
+ this.write(m, 'condition_wake', { waitId: wait.waitId, outcome: wait.status });
99
+ });
78
100
  // Version the review journal separately: older local builds used an incompatible
79
101
  // eight-column table. Archive it verbatim; its approvals lack this protocol's
80
102
  // execution/basis proof and must never be reused.
@@ -398,6 +420,10 @@ class SqliteMatterStore {
398
420
  return false;
399
421
  // User input or coordinator clarification can interrupt retry backoff, never a user pause.
400
422
  const inserted = this.insertEvent(id, input);
423
+ if (inserted && m.conditionWaitId) {
424
+ this.conditions.retire(m, 'New task input');
425
+ this.write(m, 'condition_interrupted_by_input');
426
+ }
401
427
  if (inserted && !m.activation && m.status === 'active' && m.retryAt) {
402
428
  m.retryAt = null;
403
429
  m.executionFailures = 0;
@@ -411,6 +437,8 @@ class SqliteMatterStore {
411
437
  for (const m of this.list()) {
412
438
  if (terminal(m) || m.status === 'paused' || m.activation)
413
439
  continue;
440
+ if (this.conditions.expire(m))
441
+ continue;
414
442
  for (const wake of m.wakes) {
415
443
  if (wake.kind === 'at' && wake.at <= this.now()) {
416
444
  this.insertEvent(m.id, {
@@ -434,11 +462,12 @@ class SqliteMatterStore {
434
462
  return null;
435
463
  const activation = {
436
464
  id: this.newId(),
437
- turnId: `pending:${this.newId()}`,
465
+ turnId: `${PENDING_ACTIVATION_TURN_PREFIX}${this.newId()}`,
438
466
  eventCursor: events.at(-1).sequence,
439
467
  startedAt: this.now(),
440
468
  settled: false,
441
469
  };
470
+ this.conditions.retire(m, 'A new activation supersedes the wait');
442
471
  m.activation = activation;
443
472
  m.runCount++;
444
473
  m.status = 'active';
@@ -457,7 +486,7 @@ class SqliteMatterStore {
457
486
  if (m.activation.turnId === turnId)
458
487
  return m;
459
488
  // Only the unbound dispatch marker may be replaced by a real Host turn.
460
- if (!m.activation.turnId.startsWith('pending:'))
489
+ if (!isPendingActivationTurnId(m.activation.turnId))
461
490
  throw new Error('Activation is already bound to another turn');
462
491
  m.activation.turnId = turnId;
463
492
  m.retryAt = null;
@@ -527,12 +556,27 @@ class SqliteMatterStore {
527
556
  return m;
528
557
  });
529
558
  }
530
- checkpoint(id, activationId, revision, body, operationId) {
559
+ checkpoint(id, activationId, revision, body, operationId, progressSummary) {
531
560
  const content = stateText(body);
532
- return this.mutate(id, activationId, revision, operationId, JSON.stringify(['checkpoint', id, activationId, revision, content]), (m) => {
561
+ if (progressSummary !== undefined)
562
+ this.validateProgressSummary(progressSummary);
563
+ return this.mutate(id, activationId, revision, operationId, JSON.stringify([
564
+ 'checkpoint',
565
+ id,
566
+ activationId,
567
+ revision,
568
+ content,
569
+ ...(progressSummary === undefined ? [] : [progressSummary]),
570
+ ]), (m) => {
533
571
  m.stateText = content;
572
+ if (progressSummary !== undefined)
573
+ m.progressSummary = progressSummary.trim();
534
574
  });
535
575
  }
576
+ validateProgressSummary(value) {
577
+ if (!value.trim() || Array.from(value.trim()).length > 30)
578
+ throw new Error('Progress summary must contain 1–30 characters');
579
+ }
536
580
  reviewBasis(id, activationId, draftPath) {
537
581
  return createHash('sha256')
538
582
  .update(JSON.stringify({
@@ -541,10 +585,43 @@ class SqliteMatterStore {
541
585
  historySequence: this.db
542
586
  .prepare('SELECT MAX(sequence) AS sequence FROM matter_history WHERE matter_id=?')
543
587
  .get(id)?.sequence,
544
- draft: this.readDraft(id, activationId, draftPath),
588
+ draft: draftPath === undefined ? undefined : this.readDraft(id, activationId, draftPath),
545
589
  }))
546
590
  .digest('hex');
547
591
  }
592
+ submittedInput(operationId) {
593
+ const row = this.db
594
+ .prepare('SELECT payload FROM matter_submissions WHERE id=?')
595
+ .get(operationId);
596
+ return row ? JSON.parse(String(row.payload)) : undefined;
597
+ }
598
+ saveSubmission(operationId, input) {
599
+ const previous = this.submittedInput(operationId);
600
+ if (previous && JSON.stringify(previous) !== JSON.stringify(input))
601
+ throw new Error('Operation identity reused with different arguments');
602
+ this.db
603
+ .prepare('INSERT OR IGNORE INTO matter_submissions(id,payload) VALUES(?,?)')
604
+ .run(operationId, JSON.stringify(input));
605
+ }
606
+ adoptDeliveredInput(id, activationId, basis, eventCursor) {
607
+ return this.transaction(() => {
608
+ const m = this.assertActive(id, activationId);
609
+ if (matterInputBasis(this.get(id)) !== basis ||
610
+ !Number.isSafeInteger(eventCursor) ||
611
+ eventCursor < m.activation.eventCursor)
612
+ throw new MatterReviewInvalidated();
613
+ const batch = this.eventBatch(id);
614
+ const last = batch.events.at(-1)?.sequence ?? m.activation.eventCursor;
615
+ if (eventCursor !== last)
616
+ throw new MatterReviewInvalidated();
617
+ // Acknowledge only the exact bounded batch materialized before this model call.
618
+ if (eventCursor > m.activation.eventCursor) {
619
+ m.activation.eventCursor = eventCursor;
620
+ this.write(m, 'observe');
621
+ }
622
+ return m;
623
+ });
624
+ }
548
625
  beginReview(id, activationId, input, operationId, draftPath) {
549
626
  return this.transaction(() => {
550
627
  const fingerprint = createHash('sha256')
@@ -646,6 +723,8 @@ class SqliteMatterStore {
646
723
  stateText(input.stateText);
647
724
  text(input.reason, 2000, 'reason');
648
725
  text(input.summary, 4000, 'summary');
726
+ if (input.progressSummary !== undefined)
727
+ this.validateProgressSummary(input.progressSummary);
649
728
  if (input.next !== undefined)
650
729
  text(input.next, 2000, 'next');
651
730
  if (!['continue', 'wait', 'complete'].includes(input.disposition))
@@ -669,12 +748,16 @@ class SqliteMatterStore {
669
748
  text(input.waitingFor ?? '', 1000, 'waiting condition');
670
749
  else if (input.waitingFor !== undefined)
671
750
  throw new Error('Only wait dispositions accept a waiting condition');
751
+ if (input.condition && input.disposition !== 'wait')
752
+ throw new Error('Only wait accepts a checker');
672
753
  const update = input.update ? text(input.update, 2000, 'update') : undefined;
673
754
  if (input.disposition === 'complete' &&
674
755
  this.events(id).some((e) => e.sequence > m.activation.eventCursor)) {
675
756
  throw new Error('Unread events remain. Call MatterRead and reassess; if the batch is full, settle with continue to process the next batch before completing.');
676
757
  }
677
758
  m.stateText = input.stateText;
759
+ if (input.progressSummary !== undefined)
760
+ m.progressSummary = input.progressSummary.trim();
678
761
  m.activation.settled = true;
679
762
  m.executionFailures = 0;
680
763
  m.lastFailure = null;
@@ -686,6 +769,8 @@ class SqliteMatterStore {
686
769
  : input.disposition === 'wait'
687
770
  ? 'waiting'
688
771
  : 'active';
772
+ if (input.condition)
773
+ this.conditions.install(m, input.condition.checkerId, input.condition.intervalMs, validationTime);
689
774
  this.db
690
775
  .prepare('UPDATE matter_events SET acknowledged=1 WHERE matter_id=? AND sequence<=?')
691
776
  .run(id, m.activation.eventCursor);
@@ -720,7 +805,7 @@ class SqliteMatterStore {
720
805
  this.transaction(() => {
721
806
  const m = this.read(id);
722
807
  if (m.activation?.id !== activationId ||
723
- !m.activation.turnId.startsWith('pending:') ||
808
+ !isPendingActivationTurnId(m.activation.turnId) ||
724
809
  m.activation.settled)
725
810
  throw Error('Only an explicitly rejected, unbound wake can be retried');
726
811
  m.admissionFailures = (m.admissionFailures ?? 0) + 1;
@@ -786,6 +871,7 @@ class SqliteMatterStore {
786
871
  throw new Error('Invalid action');
787
872
  if (terminal(m))
788
873
  throw new Error('This matter has ended');
874
+ this.conditions.retire(m, `User control: ${action}`);
789
875
  const interrupted = m.activation;
790
876
  if (action === 'pause' || action === 'cancel') {
791
877
  m.status = action === 'pause' ? 'paused' : 'cancelled';
@@ -16,8 +16,10 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { conditionInput, normalizeCondition, } from './condition.js';
19
20
  import { z } from 'zod';
20
21
  import { MatterReviewInvalidated } from './review.js';
22
+ import { isPendingActivationTurnId } from './matter.js';
21
23
  export function buildMatterTools(deps) {
22
24
  const own = (ctx) => {
23
25
  deps.authorize?.(ctx);
@@ -35,10 +37,42 @@ export function buildMatterTools(deps) {
35
37
  kind: z.literal('at'),
36
38
  at: z.number().describe('Future absolute Unix milliseconds'),
37
39
  });
40
+ const progressSummary = z
41
+ .string()
42
+ .trim()
43
+ .min(1)
44
+ .refine((value) => Array.from(value).length <= 30, 'Progress summary must be at most 30 characters')
45
+ .describe('用不超过30字概括当前进展,供用户在任务列表查看。由你概括,不要截断正文。');
38
46
  return [
47
+ {
48
+ name: 'MatterConditionTest',
49
+ discovery: 'direct',
50
+ description: 'Test and save a read-only JavaScript condition checker against real data. Inspect the returned result and fix/retest until it matches the intended condition. Testing does not register a wait. Pass checkerId to MatterSettle wait with an absolute fallback time in wakes. Code/parameters are immutable for that ID; changed code must be tested again. Background checks use the same read-only capabilities and current source permissions, without a model. A trigger, repeated failure or fallback time wakes this task once.',
51
+ parameters: conditionInput,
52
+ categoryHint: 'file_write',
53
+ executionSemantics: 'exclusive_step',
54
+ impl: async (input, ctx) => {
55
+ const o = own(ctx);
56
+ deps.store.assertActive(o.id, o.activationId);
57
+ if (!deps.testCondition)
58
+ throw new Error('Condition execution is unavailable');
59
+ const definition = normalizeCondition(input);
60
+ const result = await deps.testCondition(definition, ctx);
61
+ ctx.abortSignal.throwIfAborted();
62
+ deps.store.assertActive(o.id, o.activationId);
63
+ const saved = deps.store.conditions.saveTest(o.id, definition, result);
64
+ return {
65
+ checkerId: saved.id,
66
+ testedAt: saved.testedAt,
67
+ result: saved.result,
68
+ waiting: false,
69
+ };
70
+ },
71
+ },
39
72
  {
40
73
  name: 'MatterRead',
41
- description: 'Refresh file paths, revision and current time. This writes observation state and may bind a queued activation; it is not read-only. Read request.md, state.md and inbox.json with MatterReadFile; their contents are not returned here. Call alone.',
74
+ discovery: 'direct',
75
+ description: 'Refresh file paths, revision and current time. This writes observation state and may bind a queued activation; it is not read-only. Use only when you need task files/history; not required before settlement. Call alone.',
42
76
  parameters: z.object({
43
77
  activationId: z
44
78
  .string()
@@ -54,17 +88,24 @@ export function buildMatterTools(deps) {
54
88
  m &&
55
89
  m.activation &&
56
90
  m.activation.id === input.activationId &&
57
- m.activation.turnId.startsWith('pending:'))
91
+ isPendingActivationTurnId(m.activation.turnId))
58
92
  deps.store.bindTurn(m.id, input.activationId, ctx.turnId);
59
93
  const o = own(ctx);
60
94
  deps.store.observe(o.id, o.activationId);
61
- return deps.store.workspace(o.id, o.activationId);
95
+ const snapshot = deps.store.get(o.id);
96
+ return {
97
+ ...deps.store.workspace(o.id, o.activationId),
98
+ request: snapshot.matter.request,
99
+ note: snapshot.matter.stateText,
100
+ events: snapshot.events,
101
+ };
62
102
  },
63
103
  },
64
104
  {
65
105
  name: 'MatterCheckpoint',
66
106
  description: 'Save current working state after meaningful progress. Does not end this run or change the user objective.',
67
107
  parameters: z.object({
108
+ progressSummary,
68
109
  expectedRevision: z.number().int().positive(),
69
110
  stateFile: z
70
111
  .string()
@@ -74,21 +115,33 @@ export function buildMatterTools(deps) {
74
115
  executionSemantics: 'exclusive_step',
75
116
  impl: (input, ctx) => {
76
117
  const o = own(ctx);
77
- const result = deps.store.checkpoint(o.id, o.activationId, input.expectedRevision, deps.store.readDraft(o.id, o.activationId, input.stateFile), operation(ctx));
118
+ const result = deps.store.checkpoint(o.id, o.activationId, input.expectedRevision, deps.store.readDraft(o.id, o.activationId, input.stateFile), operation(ctx), input.progressSummary);
78
119
  deps.changed();
79
120
  return deps.store.workspace(result.id, o.activationId);
80
121
  },
81
122
  },
82
123
  {
83
124
  name: 'MatterSettle',
84
- description: 'Commit state and finish this activation: continue immediately, wait for a specific external condition, or complete the original objective. Continue commits without model review; wait and complete are reviewed for premature exit or missed requirements, not for reprinting historical evidence. No business tools may execute after success.',
125
+ discovery: 'direct',
126
+ description: 'Submit your result directly (optional note, no draft file required) and finish this activation: continue immediately, wait for a specific external condition, or complete the original objective. Continue commits without model review; wait and complete are reviewed for premature exit or missed requirements, not for reprinting historical evidence. No business tools may execute after success.',
85
127
  parameters: z.object({
86
- expectedRevision: z.number().int().positive(),
87
- stateFile: z
128
+ note: z
88
129
  .string()
89
- .describe('Absolute path to this activation’s draft.md, edited with MatterWriteFile before submitting'),
130
+ .max(24000)
131
+ .optional()
132
+ .describe('Optional working note to retain for future activations. Omit to keep the previous note; no draft file is needed.'),
133
+ progressSummary,
90
134
  disposition: z.enum(['continue', 'wait', 'complete']),
91
135
  wakes: z.array(wake).max(10).optional(),
136
+ condition: z
137
+ .object({
138
+ checkerId: z
139
+ .string()
140
+ .describe('ID returned by a successful MatterConditionTest in this task'),
141
+ intervalMs: z.number().int().min(1000).max(86400000).default(60000),
142
+ })
143
+ .optional()
144
+ .describe('Optional tested condition for wait. wakes must still include an absolute fallback time; the first trigger or fallback wins. Testing alone does not wait.'),
92
145
  waitingFor: z
93
146
  .string()
94
147
  .trim()
@@ -96,18 +149,11 @@ export function buildMatterTools(deps) {
96
149
  .max(1000)
97
150
  .optional()
98
151
  .describe('For wait only: the concrete condition that prevents useful work now. A wake time is only when to check it.'),
99
- reason: z.string().min(1).max(2000),
100
152
  summary: z
101
153
  .string()
102
154
  .min(1)
103
155
  .max(4000)
104
- .describe('What this activation actually did and found. The host appends this to history with a timestamp.'),
105
- next: z
106
- .string()
107
- .min(1)
108
- .max(2000)
109
- .optional()
110
- .describe('Possible next actions, based on the current judgment; future activations must reassess them.'),
156
+ .describe('What you did and found, and why continuing, waiting or completing is appropriate. The host saves this with a timestamp.'),
111
157
  update: z
112
158
  .string()
113
159
  .max(2000)
@@ -118,19 +164,37 @@ export function buildMatterTools(deps) {
118
164
  executionSemantics: 'exclusive_step',
119
165
  impl: async (input, ctx) => {
120
166
  const o = own(ctx);
121
- const { stateFile, ...commit } = input;
122
- const submission = {
123
- ...commit,
124
- stateText: deps.store.readDraft(o.id, o.activationId, stateFile),
125
- };
126
167
  try {
168
+ const { note, ...commit } = input;
169
+ const previous = deps.store.submittedInput(operation(ctx));
170
+ let revision;
171
+ let state;
172
+ if (previous) {
173
+ revision = previous.expectedRevision;
174
+ state = previous.stateText;
175
+ }
176
+ else {
177
+ const delivered = await deps.deliveredInput?.(ctx);
178
+ if (!delivered || delivered.activationId !== o.activationId)
179
+ throw new MatterReviewInvalidated();
180
+ const m = deps.store.adoptDeliveredInput(o.id, o.activationId, delivered.basis, delivered.eventCursor);
181
+ revision = m.revision;
182
+ state = m.stateText;
183
+ }
184
+ const submission = {
185
+ ...commit,
186
+ expectedRevision: revision,
187
+ stateText: note ?? state,
188
+ reason: commit.summary.slice(0, 2000),
189
+ };
190
+ deps.store.saveSubmission(operation(ctx), submission);
127
191
  if (submission.disposition === 'continue') {
128
192
  ctx.abortSignal.throwIfAborted();
129
193
  const result = deps.store.settle(o.id, o.activationId, submission, operation(ctx));
130
194
  deps.changed();
131
195
  return deps.store.workspace(result.id, o.activationId);
132
196
  }
133
- const review = deps.store.beginReview(o.id, o.activationId, submission, operation(ctx), stateFile);
197
+ const review = deps.store.beginReview(o.id, o.activationId, submission, operation(ctx));
134
198
  const verdict = review.committed ? review.verdict : await deps.review(review);
135
199
  ctx.abortSignal.throwIfAborted();
136
200
  if (!review.verdict)
@@ -164,7 +228,7 @@ export function buildMatterTools(deps) {
164
228
  },
165
229
  {
166
230
  name: 'MatterWriteFile',
167
- description: 'Write the entire draft.md file for this activation. This edits a working file only; publish it with MatterCheckpoint or MatterSettle. Other matter files are host-owned.',
231
+ description: 'Optional legacy draft editor for this activation. Publish this file with MatterCheckpoint. MatterSettle accepts an inline note instead and does not read the draft. Other matter files are host-owned.',
168
232
  parameters: z.object({ path: z.string(), content: z.string() }),
169
233
  categoryHint: 'file_write',
170
234
  executionSemantics: 'exclusive_step',