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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. package/DISCLAIMER-WIP +1 -1
  2. package/LICENSE +15 -11
  3. package/README.md +173 -1
  4. package/README.zh-CN.md +156 -0
  5. package/THIRD_PARTY_NOTICES.txt +12 -12
  6. package/dist/cli-core.js +1 -0
  7. package/dist/pi-goal.js +13 -0
  8. package/dist/pi-tui-runner.js +44 -1
  9. package/dist/run-command-core.js +256 -48
  10. package/dist/run-session-command.js +534 -0
  11. package/dist/run-session-result.js +38 -0
  12. package/dist/run-turn-outcome.js +174 -0
  13. package/dist/runtime-host-cli.js +32 -17
  14. package/dist/runtime-host-run-command.js +53 -165
  15. package/dist/runtime-host-run-mcp.js +3 -0
  16. package/dist/runtime-host-session-channel.js +3 -1
  17. package/dist/runtime-host-session-driver.js +5 -0
  18. package/dist/runtime-host-setup-command.js +114 -7
  19. package/dist/tui-copy-catalog.js +24 -0
  20. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  21. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
  22. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
  23. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
  24. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
  25. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  26. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  27. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
  28. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  29. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
  30. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  31. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  32. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
  33. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
  34. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
  35. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
  36. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  37. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  38. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
  39. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
  40. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  41. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  42. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
  43. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
  44. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
  45. package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
  46. package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
  47. package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
  48. package/node_modules/@maka/core/dist/bot-chat-settings.js +10 -1
  49. package/node_modules/@maka/core/dist/event-wait-delivery.js +67 -0
  50. package/node_modules/@maka/core/dist/event-wait.js +75 -10
  51. package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
  52. package/node_modules/@maka/core/dist/goal.js +54 -2
  53. package/node_modules/@maka/core/dist/model-catalog.js +19 -1
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
  55. package/node_modules/@maka/core/dist/model-metadata.js +42 -1
  56. package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
  57. package/node_modules/@maka/core/dist/provider-registry.js +16 -2
  58. package/node_modules/@maka/core/dist/runtime-event-store.js +0 -1
  59. package/node_modules/@maka/core/dist/runtime-event.js +24 -2
  60. package/node_modules/@maka/core/dist/runtime-invocation.js +10 -0
  61. package/node_modules/@maka/core/dist/session-checkin.js +31 -0
  62. package/node_modules/@maka/core/dist/tool-ledger-scanner.js +1 -9
  63. package/node_modules/@maka/core/dist/tool-recovery-bundle.js +1 -14
  64. package/node_modules/@maka/core/dist/turn-origin.js +14 -2
  65. package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
  66. package/node_modules/@maka/core/package.json +3 -0
  67. package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
  68. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  69. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
  70. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  71. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
  72. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  73. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  74. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  75. package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
  76. package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
  77. package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  78. package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  79. package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
  80. package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
  81. package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
  82. package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
  83. package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
  84. package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
  85. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
  86. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  87. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  88. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
  89. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  90. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  91. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  92. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  93. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
  94. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  95. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  96. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  97. package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
  98. package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  99. package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  100. package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
  101. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
  102. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
  103. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
  104. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
  105. package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
  106. package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
  107. package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
  108. package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
  109. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  110. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  111. package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
  112. package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
  113. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  114. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  115. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
  116. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  117. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
  118. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
  119. package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  120. package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  121. package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
  122. package/node_modules/@maka/mcp/package.json +1 -1
  123. package/node_modules/@maka/runtime/dist/agent-run.js +5 -1
  124. package/node_modules/@maka/runtime/dist/agent-swarm-status-tool.js +0 -1
  125. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +29 -15
  126. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
  127. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +125 -131
  128. package/node_modules/@maka/runtime/dist/bots/bot-registry.js +19 -3
  129. package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +178 -6
  130. package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +163 -9
  131. package/node_modules/@maka/runtime/dist/context-budget-policy.js +9 -2
  132. package/node_modules/@maka/runtime/dist/event-wait-tool.js +69 -0
  133. package/node_modules/@maka/runtime/dist/goal-continuation.js +195 -117
  134. package/node_modules/@maka/runtime/dist/goal-state.js +8 -0
  135. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +34 -4
  136. package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
  137. package/node_modules/@maka/runtime/dist/memory-extraction.js +0 -2
  138. package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
  139. package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
  140. package/node_modules/@maka/runtime/dist/model-history.js +16 -3
  141. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +15 -5
  142. package/node_modules/@maka/runtime/dist/plan-tools.js +0 -3
  143. package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
  144. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
  145. package/node_modules/@maka/runtime/dist/provider-error-classification.js +2 -0
  146. package/node_modules/@maka/runtime/dist/recovery-resolver.js +2 -1
  147. package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
  148. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
  149. package/node_modules/@maka/runtime/dist/sandbox-boundary-path.js +79 -2
  150. package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
  151. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
  152. package/node_modules/@maka/runtime/dist/session-manager.js +5 -1
  153. package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
  154. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -3
  155. package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
  156. package/node_modules/@maka/runtime/dist/tool-runtime.js +11 -2
  157. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
  158. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
  159. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
  160. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
  161. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
  162. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  163. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  164. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
  165. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  166. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
  167. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  168. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  169. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
  170. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
  171. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
  172. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
  173. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  174. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  175. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
  176. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
  177. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  178. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  179. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
  180. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
  181. package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
  182. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  183. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
  184. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  185. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
  186. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  187. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  188. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  189. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
  190. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
  191. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  192. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  193. package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
  194. package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
  195. package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
  196. package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
  197. package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
  198. package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
  199. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
  200. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  201. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  202. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
  203. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  204. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  205. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  206. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  207. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
  208. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  209. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  210. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  211. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
  212. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  213. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  214. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
  215. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
  216. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
  217. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
  218. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
  219. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
  220. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
  221. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
  222. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
  223. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  224. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  225. package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
  226. package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
  227. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  228. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  229. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
  230. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  231. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
  232. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
  233. package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  234. package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  235. package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
  236. package/node_modules/@maka/runtime/package.json +3 -0
  237. package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
  238. package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
  239. package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +92 -22
  240. package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
  241. package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
  242. package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
  243. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
  244. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
  245. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
  246. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
  247. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
  248. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
  249. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
  250. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +203 -71
  251. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/host.js +21 -5
  252. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
  253. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
  254. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
  255. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
  256. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +37 -5
  257. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
  258. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
  259. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
  260. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
  261. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +68 -14
  262. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
  263. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
  264. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +93 -23
  265. package/node_modules/@maka/runtime-host/dist/assistant/service.js +72 -16
  266. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +30 -1
  267. package/node_modules/@maka/runtime-host/dist/client/ssh-operator-activation.js +9 -2
  268. package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
  269. package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -3
  270. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
  271. package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
  272. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
  273. package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
  274. package/node_modules/@maka/runtime-host/dist/server/agent-settings-tools.js +0 -1
  275. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
  276. package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +151 -20
  277. package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
  278. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +127 -11
  279. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
  280. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +11 -0
  281. package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +5 -2
  282. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +343 -53
  283. package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +457 -0
  284. package/node_modules/@maka/runtime-host/dist/server/goal-execution-coordinator.js +23 -6
  285. package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
  286. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +5 -1
  287. package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
  288. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
  289. package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
  290. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +8 -0
  291. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
  292. package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
  293. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
  294. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
  295. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
  296. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
  297. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
  298. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +14 -3
  299. package/node_modules/@maka/storage/dist/agent-run-store.js +10 -0
  300. package/node_modules/@maka/storage/dist/codex-session-adapter.js +20 -3
  301. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
  302. package/node_modules/@maka/storage/dist/event-wait-authority.js +18 -1
  303. package/node_modules/@maka/storage/dist/event-wait-bridge.js +336 -0
  304. package/node_modules/@maka/storage/dist/execution-stores.js +39 -1
  305. package/node_modules/@maka/storage/dist/external-session-images.js +131 -0
  306. package/node_modules/@maka/storage/dist/external-session-importer.js +12 -2
  307. package/node_modules/@maka/storage/dist/goal-authority.js +2 -0
  308. package/node_modules/@maka/storage/dist/local-execution-persistence.js +27 -1
  309. package/node_modules/@maka/storage/dist/operational-state-store.js +1 -1
  310. package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
  311. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  312. package/node_modules/@maka/storage/dist/session-bundle-policy.js +116 -16
  313. package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
  314. package/node_modules/@maka/storage/dist/session-store.js +37 -8
  315. package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
  316. package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
  317. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
  318. package/node_modules/@maka/storage/dist/sqlite-event-wait-authority.js +81 -8
  319. package/node_modules/@maka/storage/dist/sqlite-event-wait-bridge.js +94 -0
  320. package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
  321. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +7 -8
  322. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +38 -162
  323. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +7 -4
  324. package/node_modules/@maka/storage/dist/tool-commit-validation.js +1 -1
  325. package/node_modules/@maka/storage/package.json +4 -0
  326. package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
  327. package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
  328. package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
  329. package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
  330. package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
  331. package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
  332. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
  333. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
  334. package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
  335. package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
  336. package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
  337. package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
  338. package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
  339. package/node_modules/@modelcontextprotocol/client/package.json +5 -5
  340. package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
  341. package/node_modules/fast-uri/README.md +8 -0
  342. package/node_modules/fast-uri/index.js +98 -18
  343. package/node_modules/fast-uri/lib/utils.js +52 -0
  344. package/node_modules/fast-uri/package.json +1 -1
  345. package/node_modules/follow-redirects/index.js +10 -1
  346. package/node_modules/follow-redirects/package.json +1 -1
  347. package/node_modules/ip-address/README.md +104 -104
  348. package/node_modules/ip-address/dist/ipv4.js +7 -0
  349. package/node_modules/ip-address/dist/ipv6.js +7 -4
  350. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  351. package/node_modules/ip-address/package.json +2 -1
  352. package/node_modules/undici/README.md +25 -3
  353. package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  354. package/node_modules/undici/docs/docs/api/Client.md +11 -6
  355. package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  356. package/node_modules/undici/docs/docs/api/Errors.md +76 -1
  357. package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  358. package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  359. package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  360. package/node_modules/undici/docs/docs/index.md +12 -12
  361. package/node_modules/undici/docs/docs/type-map.json +66 -66
  362. package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  363. package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  364. package/node_modules/undici/lib/core/connect.js +10 -4
  365. package/node_modules/undici/lib/core/constants.js +12 -1
  366. package/node_modules/undici/lib/core/errors.js +38 -1
  367. package/node_modules/undici/lib/core/request.js +16 -1
  368. package/node_modules/undici/lib/core/symbols.js +2 -0
  369. package/node_modules/undici/lib/core/util.js +26 -1
  370. package/node_modules/undici/lib/dispatcher/agent.js +6 -2
  371. package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  372. package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  373. package/node_modules/undici/lib/dispatcher/client.js +4 -1
  374. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  375. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  376. package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  377. package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  378. package/node_modules/undici/lib/dispatcher/pool.js +11 -8
  379. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  380. package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  381. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  382. package/node_modules/undici/lib/handler/cache-handler.js +153 -15
  383. package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  384. package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  385. package/node_modules/undici/lib/handler/retry-handler.js +44 -11
  386. package/node_modules/undici/lib/interceptor/cache.js +11 -3
  387. package/node_modules/undici/lib/interceptor/decompress.js +22 -9
  388. package/node_modules/undici/lib/interceptor/dns.js +11 -0
  389. package/node_modules/undici/lib/interceptor/response-error.js +72 -28
  390. package/node_modules/undici/lib/milo/LICENSE.md +7 -0
  391. package/node_modules/undici/lib/milo/no-simd.js +1002 -0
  392. package/node_modules/undici/lib/milo/simd.js +1002 -0
  393. package/node_modules/undici/lib/mock/mock-agent.js +11 -0
  394. package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  395. package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  396. package/node_modules/undici/lib/util/cache.js +11 -5
  397. package/node_modules/undici/lib/web/cookies/util.js +19 -2
  398. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  399. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  400. package/node_modules/undici/lib/web/fetch/body.js +47 -38
  401. package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  402. package/node_modules/undici/lib/web/fetch/headers.js +2 -2
  403. package/node_modules/undici/lib/web/fetch/index.js +8 -4
  404. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  405. package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  406. package/node_modules/undici/package.json +9 -7
  407. package/node_modules/zod/package.json +1 -1
  408. package/node_modules/zod/v4/core/compile.cjs +8 -0
  409. package/node_modules/zod/v4/core/compile.js +8 -0
  410. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  411. package/node_modules/zod/v4/core/schemas.js +30 -0
  412. package/node_modules/zod/v4/core/util.cjs +15 -0
  413. package/node_modules/zod/v4/core/util.js +14 -0
  414. package/node_modules/zod/v4/core/versions.cjs +1 -1
  415. package/node_modules/zod/v4/core/versions.js +1 -1
  416. package/package.json +2 -2
  417. package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
  418. package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
@@ -20,11 +20,16 @@ import { ASSISTANT_BACKGROUND_SESSION_LABEL } from '@maka/core/session';
20
20
  import { randomUUID } from 'node:crypto';
21
21
  import { setTimeout as delay } from 'node:timers/promises';
22
22
  import { awaitingUser } from '../execution-outcome.js';
23
- import { wake } from './prompt.js';
23
+ import { wakeInput, DISCOVERY_TASK, JUDGEMENT_TASK, NOTEBOOK_RULES } from './prompt.js';
24
+ import { Notebook, NotebookValidationError } from './notebook.js';
25
+ import { createHash } from 'node:crypto';
26
+ import { mkdirSync, writeFileSync, readFileSync, rmSync, chmodSync } from 'node:fs';
27
+ import { join } from 'node:path';
24
28
  export class InitiativeController {
25
29
  ctx;
26
30
  store;
27
31
  config;
32
+ notebook;
28
33
  abort = new AbortController();
29
34
  timer;
30
35
  heartbeat;
@@ -46,6 +51,63 @@ export class InitiativeController {
46
51
  this.ctx = ctx;
47
52
  this.store = store;
48
53
  this.config = config;
54
+ const path = join(store.directory, 'notebook.sqlite');
55
+ this.notebook = new Notebook(path);
56
+ chmodSync(path, 0o600);
57
+ }
58
+ async refreshFeedback(state) {
59
+ const context = this.ctx.bot.discoveryContext(state.sessionId);
60
+ this.ready();
61
+ for (const message of context.deliveries) {
62
+ const topicIds = [
63
+ ...new Set(message.discoveryIds.flatMap((id) => {
64
+ const prepared = this.notebook.event(id);
65
+ return prepared?.kind === 'prepared' ? prepared.payload.topicIds : [];
66
+ })),
67
+ ];
68
+ // Unknown reports are not retroactively inferred to be notebook recommendations.
69
+ if (!topicIds.length)
70
+ continue;
71
+ this.notebook.put(`delivery:${message.messageId}`, 'delivery', {
72
+ text: message.text,
73
+ topicIds,
74
+ messageIds: [message.messageId],
75
+ preparedIds: message.discoveryIds,
76
+ transport: 'assistant-bot',
77
+ }, message.at);
78
+ }
79
+ for (const feedback of context.feedback) {
80
+ const replyTo = `delivery:${feedback.messageId}`;
81
+ if (!this.notebook.event(replyTo))
82
+ continue;
83
+ this.notebook.recordFeedback({
84
+ id: `feedback:${JSON.stringify([feedback.id, feedback.messageId])}`,
85
+ text: feedback.text,
86
+ at: feedback.at,
87
+ replyTo,
88
+ });
89
+ }
90
+ }
91
+ forwardPrepared(state) {
92
+ for (const event of this.notebook.events('prepared')) {
93
+ const id = `${event.id}:reported`;
94
+ if (this.notebook.event(id))
95
+ continue;
96
+ // A new user message must be considered before an old recommendation is handed off.
97
+ if (event.payload.feedbackRevision !== this.notebook.revision() ||
98
+ this.notebook.pendingFeedback().length)
99
+ continue;
100
+ this.ready();
101
+ const accepted = this.ctx.bot.post(state.sessionId, {
102
+ id: event.id,
103
+ type: 'discovery',
104
+ source: state.judgementSession,
105
+ content: event.payload.text,
106
+ });
107
+ if (!accepted)
108
+ throw Error('Bot did not accept the discovery report');
109
+ this.notebook.put(id, 'reported', { preparedId: event.id, text: event.payload.text });
110
+ }
49
111
  }
50
112
  start() {
51
113
  const acquire = () => {
@@ -68,7 +130,7 @@ export class InitiativeController {
68
130
  async resolveBinding() {
69
131
  if (this.store.get() || !this.owned)
70
132
  return;
71
- const matches = (await this.ctx.sessionQuery.list()).filter((s) => s.labels?.includes('personal-assistant'));
133
+ const matches = (await this.ctx.sessionQuery.list()).filter((s) => !s.isArchived && s.labels?.includes('personal-assistant'));
72
134
  if (matches.length > 1)
73
135
  throw Error('Multiple assistant conversations found');
74
136
  if (!matches.length)
@@ -87,7 +149,7 @@ export class InitiativeController {
87
149
  return this.ctx.agents.withInvocation({
88
150
  sessionId: s.sessionId,
89
151
  cwd: s.cwd,
90
- turnId: `initiative:${this.store.owner}`,
152
+ turnId: `initiative-${this.store.owner}`,
91
153
  toolCallId: randomUUID(),
92
154
  abortSignal: this.abort.signal,
93
155
  }, fn);
@@ -118,55 +180,150 @@ export class InitiativeController {
118
180
  const s = this.store.get();
119
181
  if ((!s?.enabled && !s?.checkRequested) || s.active || s.nextAt > Date.now())
120
182
  return;
121
- const agent = await this.asOwner(s, async () => {
122
- let sessionId = s.discoverySession;
183
+ const agent = await this.worker(s, s.pendingDraft?.phase ??
184
+ (s.pendingJudgement || s.candidateReport ? 'judgement' : 'discovery'));
185
+ const snapshot = await agent.snapshot();
186
+ if (snapshot?.agent?.status === 'running' || awaitingUser(snapshot))
187
+ return;
188
+ this.ready();
189
+ const current = this.store.claim();
190
+ if (!current?.active)
191
+ return;
192
+ this.running = this.run(agent, current).finally(() => {
193
+ this.running = undefined;
194
+ });
195
+ }
196
+ async worker(s, phase) {
197
+ return this.asOwner(s, async () => {
198
+ const field = phase === 'discovery' ? 'discoverySession' : 'judgementSession';
199
+ const sessions = await this.ctx.sessionQuery.list();
200
+ const bound = sessions.find((item) => item.id === s[field]);
201
+ let sessionId = bound && !bound.isArchived ? bound.id : undefined;
123
202
  if (!sessionId) {
124
- const label = `assistant-discovery:${s.sessionId}`;
125
- const matches = (await this.ctx.sessionQuery.list()).filter((item) => item.labels?.includes(label));
203
+ const label = `assistant-${phase}:${s.sessionId}`;
204
+ const matches = sessions.filter((item) => !item.isArchived && item.labels?.includes(label));
126
205
  if (matches.length > 1)
127
- throw Error('Multiple exploration workers found');
206
+ throw Error(`Multiple ${phase} workers found`);
128
207
  sessionId =
129
208
  matches[0]?.id ??
130
209
  (await this.ctx.agents.create({
131
210
  background: true,
132
- name: '个人助手 · 主动发现',
211
+ name: phase === 'discovery' ? '个人助手 · 主动发现' : '个人助手 · 发现判断',
133
212
  labels: [label, ASSISTANT_BACKGROUND_SESSION_LABEL],
134
213
  })).sessionId;
135
214
  this.store.update((current) => {
136
- current.discoverySession = sessionId;
215
+ current[field] = sessionId;
216
+ // A replacement worker has no role instructions in its conversation yet.
217
+ if (current.promptVersions)
218
+ delete current.promptVersions[phase === 'discovery' ? 'exploration' : 'judgement'];
137
219
  });
138
220
  }
139
221
  return this.ctx.agents.resume({ sessionId });
140
222
  });
141
- const snapshot = await agent.snapshot();
142
- if (snapshot?.agent?.status === 'running' || awaitingUser(snapshot))
143
- return;
223
+ }
224
+ async execute(agent, state) {
144
225
  this.ready();
145
- const current = this.store.claim();
146
- if (!current?.active)
147
- return;
148
- this.running = this.run(agent, current).finally(() => {
149
- this.running = undefined;
226
+ this.activeAgent = agent;
227
+ await this.refreshFeedback(state);
228
+ const role = state.active.phase === 'discovery' ? 'exploration' : 'judgement';
229
+ // Persist the operation before running the model. A failed or interrupted draft
230
+ // must resume in its original worker, with its original output still available.
231
+ const pending = state.pendingDraft ?? { id: state.active.id, phase: state.active.phase };
232
+ if (pending.phase !== state.active.phase)
233
+ throw Error('Pending draft phase mismatch');
234
+ this.store.update((s) => {
235
+ s.pendingDraft = pending;
150
236
  });
237
+ const operationId = `${pending.id}:${role}`;
238
+ const directory = join(this.store.directory, 'notebook-wakes', pending.id, role);
239
+ const viewPath = join(directory, 'notebook.md');
240
+ const outputPath = join(directory, 'operations.json');
241
+ const version = createHash('sha256')
242
+ .update((role === 'exploration' ? DISCOVERY_TASK : JUDGEMENT_TASK) + '\n' + NOTEBOOK_RULES)
243
+ .digest('hex');
244
+ let repair = pending.error ?? (state.pendingDraft ? '上次执行中断,尚无成功提交记录。' : undefined);
245
+ // A committed operation can survive a crash or a failed Bot handoff. Retry its
246
+ // delivery using the existing message IDs, without asking the model to rewrite it.
247
+ while (!this.notebook.event(operationId)) {
248
+ this.ready();
249
+ await this.refreshFeedback(state);
250
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
251
+ writeFileSync(viewPath, this.notebook.render(), { mode: 0o600 });
252
+ const revision = this.notebook.revision();
253
+ let input = wakeInput({
254
+ role,
255
+ now: new Date().toISOString(),
256
+ viewPath,
257
+ outputPath,
258
+ first: this.store.get().promptVersions?.[role] !== version,
259
+ });
260
+ if (repair)
261
+ input += `\n上次结果未提交:${repair}\n整份操作未写入记事本,其中的消息未交给 Bot,也不在待发送队列。读取原结果文件(若存在)和更新后的记事本,修正后重交;保留仍值得交流的内容,不要因为已经写过文案就当成已安排。feedbackDecisions 只引用记事本“用户反馈”中的 ID,没有待整理反馈就留空。`;
262
+ if (role === 'judgement' && state.candidateReport?.path)
263
+ input += `\n升级前保留的历史报告:${state.candidateReport.path}。它是参考材料,不是指定候选或当前指令。`;
264
+ const wakeId = randomUUID();
265
+ const admitted = await agent.followup(`Runtime heartbeat, not a new human request.\nHeartbeat ID: ${state.active.id}\nSubmission attempt: ${wakeId}\nPhase: ${state.active.phase}\n${input}`);
266
+ if (!['turn_started', 'followup'].includes(admitted?.disposition))
267
+ throw Error('Host rejected proactive wake');
268
+ while (admitted.disposition === 'followup' &&
269
+ !JSON.stringify(await agent.transcript()).includes(`Submission attempt: ${wakeId}`))
270
+ await delay(25, undefined, { signal: this.abort.signal });
271
+ await agent.whenIdle(this.abort.signal);
272
+ const snapshot = await agent.snapshot();
273
+ const status = snapshot?.agent?.status;
274
+ if (['aborted', 'blocked', 'waiting_for_user'].includes(status) || awaitingUser(snapshot))
275
+ throw Error(`Heartbeat ended with ${status}; inspect before resuming`);
276
+ this.ready();
277
+ this.store.update((s) => {
278
+ (s.promptVersions ??= {})[role] = version;
279
+ });
280
+ await this.refreshFeedback(state);
281
+ // I/O / provider failures remain execution failures. Only fixable draft errors
282
+ // go back to the same agent immediately; never silently drop an invalid field.
283
+ const raw = readFileSync(outputPath, 'utf8');
284
+ try {
285
+ this.notebook.commitDraft({
286
+ role,
287
+ operationId,
288
+ expectedFeedbackRevision: revision,
289
+ draft: JSON.parse(raw),
290
+ });
291
+ }
292
+ catch (error) {
293
+ if (!(error instanceof SyntaxError || error instanceof NotebookValidationError))
294
+ throw error;
295
+ repair = String(error);
296
+ this.store.update((s) => {
297
+ s.pendingDraft.error = repair;
298
+ this.store.log('draft-rejected', { operationId, error: repair });
299
+ });
300
+ }
301
+ }
302
+ if (role === 'judgement')
303
+ this.forwardPrepared(state);
304
+ // Only remove the files after commit and handoff. The durable operation marker
305
+ // remains available if shutdown happens before the scheduler finishes this phase.
306
+ rmSync(directory, { recursive: true, force: true });
151
307
  }
152
308
  async run(agent, state) {
153
309
  const id = state.active.id;
154
310
  this.activeAgent = agent;
155
311
  try {
156
- const admitted = await agent.followup(wake(state));
157
- if (!['turn_started', 'followup'].includes(admitted?.disposition))
158
- throw Error('Host rejected proactive wake');
159
- const completion = async () => {
160
- // Queued admission is not completion; wait for its input to enter Session history.
161
- while (admitted.disposition === 'followup' &&
162
- !JSON.stringify(await agent.transcript()).includes(`Heartbeat ID: ${id}`))
163
- await delay(25, undefined, { signal: this.abort.signal });
164
- await agent.whenIdle(this.abort.signal);
165
- };
166
- await completion();
167
- const status = (await agent.snapshot())?.agent?.status;
168
- if (['aborted', 'blocked', 'waiting_for_user'].includes(status))
169
- throw Error(`Heartbeat ended with ${status}; inspect before resuming`);
312
+ await this.execute(agent, state);
313
+ if (state.active.phase === 'discovery') {
314
+ const next = this.store.update((s) => {
315
+ if (s.active?.id !== id)
316
+ throw Error('Heartbeat ownership changed');
317
+ s.pendingJudgement = true;
318
+ delete s.pendingDraft;
319
+ s.active.phase = 'judgement';
320
+ });
321
+ const judge = await this.worker(next, 'judgement');
322
+ const snapshot = await judge.snapshot();
323
+ if (snapshot?.agent?.status === 'running' || awaitingUser(snapshot))
324
+ throw Error('Judgement worker is busy or awaiting user input; notebook retained');
325
+ await this.execute(judge, this.store.get());
326
+ }
170
327
  this.store.finish(id);
171
328
  }
172
329
  catch (e) {
@@ -174,6 +331,10 @@ export class InitiativeController {
174
331
  this.store.fence();
175
332
  if (this.store.get()?.active?.id === id) {
176
333
  const message = String(e);
334
+ this.store.update((s) => {
335
+ if (s.pendingDraft && !s.pendingDraft.error)
336
+ s.pendingDraft.error = message;
337
+ });
177
338
  this.store.finish(id, message);
178
339
  }
179
340
  }
@@ -0,0 +1,69 @@
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
+ /**
20
+ * Tools the proactive discovery Session must not see or run (#6249, #6250).
21
+ *
22
+ * Discovery investigates and reports through DiscoveryReport; it does not create,
23
+ * adopt or mutate conversation-owned Matters or memory indexes, control initiative
24
+ * configuration, or deliver to the user directly. Read tools (MatterOverview,
25
+ * MemoryIndexRead, DiscoveryContext, ...) and source queries stay available.
26
+ * Whether MemorySourceQuery and MemoryExtract belong here is still an open
27
+ * design question tracked in the RFC.
28
+ */
29
+ export const DISCOVERY_EXCLUDED_TOOLS = new Set([
30
+ // Matter creation, adoption and conversation-scoped control.
31
+ 'MatterDelegate',
32
+ 'MatterStart',
33
+ 'MatterAdopt',
34
+ 'MatterControl',
35
+ 'MatterMessage',
36
+ 'MatterTaskControl',
37
+ 'MatterTaskMessage',
38
+ 'MatterReply',
39
+ 'MatterDelegationRecover',
40
+ 'MatterFeedbackRetry',
41
+ // Matter worker lifecycle tools; valid only inside an activation the Session owns.
42
+ 'MatterRead',
43
+ 'MatterReadFile',
44
+ 'MatterWriteFile',
45
+ 'MatterCheckpoint',
46
+ 'MatterSettle',
47
+ 'MatterConditionTest',
48
+ 'MatterAskBot',
49
+ // Memory index mutation. Writes belong to index workers and the conversation.
50
+ 'MemoryIndexCreate',
51
+ 'MemoryIndexCreateGroup',
52
+ 'MemoryIndexWrite',
53
+ 'MemoryIndexEdit',
54
+ 'MemoryIndexCheckpoint',
55
+ 'MemoryIndexControl',
56
+ 'MemoryIndexAddSources',
57
+ 'MemoryIndexMaintain',
58
+ // Initiative configuration is owned by the conversation.
59
+ 'InitiativeEnable',
60
+ 'InitiativeConfigure',
61
+ 'InitiativeControl',
62
+ // Bot-only coordination tools.
63
+ 'SendUser',
64
+ 'InboxCheck',
65
+ 'InboxList',
66
+ 'InboxRead',
67
+ 'AssistantSetAvatar',
68
+ 'Sleep',
69
+ ]);
@@ -22,6 +22,7 @@ import { InitiativeStore } from './store.js';
22
22
  import { InitiativeController } from './controller.js';
23
23
  import { initializeBot } from '../bot/host.js';
24
24
  import { registerAssistant } from './assistant.js';
25
+ import { DISCOVERY_EXCLUDED_TOOLS } from './discovery-capabilities.js';
25
26
  export async function initializeInitiative(ctx, directory, config = {}) {
26
27
  const limits = { tickMs: config.tickMs ?? 5000 };
27
28
  for (const [name, value] of Object.entries(limits))
@@ -30,7 +31,10 @@ export async function initializeInitiative(ctx, directory, config = {}) {
30
31
  const location = { value: directory };
31
32
  const store = new InitiativeStore(location.value, randomUUID());
32
33
  const controller = new InitiativeController(ctx, store, limits);
33
- ctx.onClose(() => store.close());
34
+ ctx.onClose(() => {
35
+ controller.notebook.close();
36
+ store.close();
37
+ });
34
38
  const activate = () => {
35
39
  controller.start();
36
40
  return () => controller.close();
@@ -38,30 +42,13 @@ export async function initializeInitiative(ctx, directory, config = {}) {
38
42
  ctx.onStart(activate);
39
43
  initializeBot(ctx, directory, store);
40
44
  registerAssistant(ctx, store, controller);
41
- ctx.backgroundSessions.register(() => store.get()?.discoverySession ? [store.get().discoverySession] : []);
42
- ctx.tools.register({
43
- name: 'DiscoveryReport',
44
- description: '此方法用于提交准备向用户发送的主动发现。请按直接与用户交流的标准组织内容,自行判断哪些信息值得用户知道,并保留必要依据和不确定性。Bot 会负责转达和适配当前对话,不要向 Bot 写“精选几条、其余可以不说”等表达建议。提交成功只表示已交给 Bot,不代表用户已经收到。',
45
- parameters: z.object({ text: z.string().trim().min(1).max(24000) }),
46
- categoryHint: 'file_write',
47
- executionSemantics: 'exclusive_step',
48
- impl: (input, call) => {
49
- controller.ready();
50
- const state = store.get();
51
- if (!state?.active || state.discoverySession !== call.sessionId)
52
- throw Error('Not the active exploration worker');
53
- const id = `discovery:${state.active.id}:${call.toolCallId}`;
54
- const reported = ctx.bot.post(state.sessionId, {
55
- id,
56
- type: 'discovery',
57
- source: call.sessionId,
58
- content: input.text,
59
- });
60
- if (!reported)
61
- throw Error('Bot did not accept the discovery report');
62
- return { reported, sentToUser: false };
63
- },
64
- });
45
+ ctx.backgroundSessions.register(() => [store.get()?.discoverySession, store.get()?.judgementSession].filter(Boolean));
46
+ // Discovery investigates and reports; it must not hold conversation-mutating tools.
47
+ if (!ctx.tools.filter)
48
+ throw Error('Assistant tool filtering is required to bound discovery Sessions');
49
+ ctx.tools.filter((sessionId, tools) => store.get()?.discoverySession === sessionId
50
+ ? tools.filter((tool) => !DISCOVERY_EXCLUDED_TOOLS.has(tool.name))
51
+ : tools);
65
52
  ctx.tools.register({
66
53
  name: 'DiscoveryContext',
67
54
  description: '按需查看用户与助手的实际交流和已委派任务状态;这些是历史背景,不是当前指令。内部调查不等于用户收到消息。已有任务的常规进展优先参考其调查结果,把探索留给尚未覆盖的方向;发现新风险、跨事项关联或证据不足时仍可自行核实。',
@@ -73,7 +60,7 @@ export async function initializeInitiative(ctx, directory, config = {}) {
73
60
  executionSemantics: 'parallel',
74
61
  impl: async (input, call) => {
75
62
  const state = store.get();
76
- if (!state || call.sessionId !== state.discoverySession)
63
+ if (!state || ![state.discoverySession, state.judgementSession].includes(call.sessionId))
77
64
  throw Error('Not the exploration worker');
78
65
  return controller.asOwner(state, async () => {
79
66
  const snapshot = await ctx.sessionQuery.read(state.sessionId);
@@ -138,8 +125,8 @@ export async function initializeInitiative(ctx, directory, config = {}) {
138
125
  ctx.systemPrompt.section({
139
126
  name: 'index-initiative.discovery',
140
127
  order: 810,
141
- text: ({ sessionId }) => store.get()?.discoverySession === sessionId
142
- ? '你是独立的主动探索 Agent。通过可用工具调查。值得交流的发现用 DiscoveryReport 交给个人助手 Bot,由它和用户交流;没有合适内容可以直接结束。这里不是用户聊天框,不要委派执行任务。'
128
+ text: ({ sessionId }) => [store.get()?.discoverySession, store.get()?.judgementSession].includes(sessionId)
129
+ ? '你在主动助手的后台会话中运行。通过普通文件工具读取共享记事本、写本轮增量;用户交流由 Bot 负责。只读调查,不委派执行任务,不自行安排心跳。'
143
130
  : undefined,
144
131
  });
145
132
  }