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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (418) hide show
  1. package/DISCLAIMER-WIP +1 -1
  2. package/LICENSE +15 -11
  3. package/README.md +173 -1
  4. package/README.zh-CN.md +156 -0
  5. package/THIRD_PARTY_NOTICES.txt +12 -12
  6. package/dist/cli-core.js +1 -0
  7. package/dist/pi-goal.js +13 -0
  8. package/dist/pi-tui-runner.js +44 -1
  9. package/dist/run-command-core.js +256 -48
  10. package/dist/run-session-command.js +534 -0
  11. package/dist/run-session-result.js +38 -0
  12. package/dist/run-turn-outcome.js +174 -0
  13. package/dist/runtime-host-cli.js +32 -17
  14. package/dist/runtime-host-run-command.js +53 -165
  15. package/dist/runtime-host-run-mcp.js +3 -0
  16. package/dist/runtime-host-session-channel.js +3 -1
  17. package/dist/runtime-host-session-driver.js +5 -0
  18. package/dist/runtime-host-setup-command.js +114 -7
  19. package/dist/tui-copy-catalog.js +24 -0
  20. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  21. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
  22. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
  23. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
  24. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
  25. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  26. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  27. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
  28. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  29. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
  30. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  31. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  32. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
  33. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
  34. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
  35. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
  36. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  37. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  38. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
  39. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
  40. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  41. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  42. package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
  43. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
  44. package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
  45. package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
  46. package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
  47. package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
  48. package/node_modules/@maka/core/dist/bot-chat-settings.js +10 -1
  49. package/node_modules/@maka/core/dist/event-wait-delivery.js +67 -0
  50. package/node_modules/@maka/core/dist/event-wait.js +75 -10
  51. package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
  52. package/node_modules/@maka/core/dist/goal.js +54 -2
  53. package/node_modules/@maka/core/dist/model-catalog.js +19 -1
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
  55. package/node_modules/@maka/core/dist/model-metadata.js +42 -1
  56. package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
  57. package/node_modules/@maka/core/dist/provider-registry.js +16 -2
  58. package/node_modules/@maka/core/dist/runtime-event-store.js +0 -1
  59. package/node_modules/@maka/core/dist/runtime-event.js +24 -2
  60. package/node_modules/@maka/core/dist/runtime-invocation.js +10 -0
  61. package/node_modules/@maka/core/dist/session-checkin.js +31 -0
  62. package/node_modules/@maka/core/dist/tool-ledger-scanner.js +1 -9
  63. package/node_modules/@maka/core/dist/tool-recovery-bundle.js +1 -14
  64. package/node_modules/@maka/core/dist/turn-origin.js +14 -2
  65. package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
  66. package/node_modules/@maka/core/package.json +3 -0
  67. package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
  68. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  69. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
  70. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  71. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
  72. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  73. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  74. package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  75. package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
  76. package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
  77. package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  78. package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  79. package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
  80. package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
  81. package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
  82. package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
  83. package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
  84. package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
  85. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
  86. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  87. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  88. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
  89. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  90. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  91. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  92. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  93. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
  94. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  95. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  96. package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  97. package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
  98. package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  99. package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  100. package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
  101. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
  102. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
  103. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
  104. package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
  105. package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
  106. package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
  107. package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
  108. package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
  109. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  110. package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  111. package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
  112. package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
  113. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  114. package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  115. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
  116. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  117. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
  118. package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
  119. package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  120. package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  121. package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
  122. package/node_modules/@maka/mcp/package.json +1 -1
  123. package/node_modules/@maka/runtime/dist/agent-run.js +5 -1
  124. package/node_modules/@maka/runtime/dist/agent-swarm-status-tool.js +0 -1
  125. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +29 -15
  126. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
  127. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +125 -131
  128. package/node_modules/@maka/runtime/dist/bots/bot-registry.js +19 -3
  129. package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +178 -6
  130. package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +163 -9
  131. package/node_modules/@maka/runtime/dist/context-budget-policy.js +9 -2
  132. package/node_modules/@maka/runtime/dist/event-wait-tool.js +69 -0
  133. package/node_modules/@maka/runtime/dist/goal-continuation.js +195 -117
  134. package/node_modules/@maka/runtime/dist/goal-state.js +8 -0
  135. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +34 -4
  136. package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
  137. package/node_modules/@maka/runtime/dist/memory-extraction.js +0 -2
  138. package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
  139. package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
  140. package/node_modules/@maka/runtime/dist/model-history.js +16 -3
  141. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +15 -5
  142. package/node_modules/@maka/runtime/dist/plan-tools.js +0 -3
  143. package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
  144. package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
  145. package/node_modules/@maka/runtime/dist/provider-error-classification.js +2 -0
  146. package/node_modules/@maka/runtime/dist/recovery-resolver.js +2 -1
  147. package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
  148. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
  149. package/node_modules/@maka/runtime/dist/sandbox-boundary-path.js +79 -2
  150. package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
  151. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
  152. package/node_modules/@maka/runtime/dist/session-manager.js +5 -1
  153. package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
  154. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -3
  155. package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
  156. package/node_modules/@maka/runtime/dist/tool-runtime.js +11 -2
  157. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
  158. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
  159. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
  160. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
  161. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
  162. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  163. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  164. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
  165. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
  166. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
  167. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
  168. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
  169. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
  170. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
  171. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
  172. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
  173. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
  174. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  175. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
  176. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
  177. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  178. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
  179. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
  180. package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
  181. package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
  182. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  183. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
  184. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  185. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
  186. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  187. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  188. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  189. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
  190. package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
  191. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  192. package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  193. package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
  194. package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
  195. package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
  196. package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
  197. package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
  198. package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
  199. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
  200. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  201. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  202. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
  203. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  204. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  205. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  206. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  207. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
  208. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  209. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  210. package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  211. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
  212. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  213. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  214. package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
  215. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
  216. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
  217. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
  218. package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
  219. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
  220. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
  221. package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
  222. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
  223. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  224. package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  225. package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
  226. package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
  227. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  228. package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  229. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
  230. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  231. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
  232. package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
  233. package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  234. package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  235. package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
  236. package/node_modules/@maka/runtime/package.json +3 -0
  237. package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
  238. package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
  239. package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +92 -22
  240. package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
  241. package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
  242. package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
  243. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
  244. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
  245. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
  246. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
  247. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
  248. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
  249. package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
  250. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +203 -71
  251. package/node_modules/@maka/runtime-host/dist/assistant/memory-network/host.js +21 -5
  252. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
  253. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
  254. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
  255. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
  256. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +37 -5
  257. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
  258. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
  259. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
  260. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
  261. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +68 -14
  262. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
  263. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
  264. package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +93 -23
  265. package/node_modules/@maka/runtime-host/dist/assistant/service.js +72 -16
  266. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +30 -1
  267. package/node_modules/@maka/runtime-host/dist/client/ssh-operator-activation.js +9 -2
  268. package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
  269. package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -3
  270. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
  271. package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
  272. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
  273. package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
  274. package/node_modules/@maka/runtime-host/dist/server/agent-settings-tools.js +0 -1
  275. package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
  276. package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +151 -20
  277. package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
  278. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +127 -11
  279. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
  280. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +11 -0
  281. package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +5 -2
  282. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +343 -53
  283. package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +457 -0
  284. package/node_modules/@maka/runtime-host/dist/server/goal-execution-coordinator.js +23 -6
  285. package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
  286. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +5 -1
  287. package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
  288. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
  289. package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
  290. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +8 -0
  291. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
  292. package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
  293. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
  294. package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
  295. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
  296. package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
  297. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
  298. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +14 -3
  299. package/node_modules/@maka/storage/dist/agent-run-store.js +10 -0
  300. package/node_modules/@maka/storage/dist/codex-session-adapter.js +20 -3
  301. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
  302. package/node_modules/@maka/storage/dist/event-wait-authority.js +18 -1
  303. package/node_modules/@maka/storage/dist/event-wait-bridge.js +336 -0
  304. package/node_modules/@maka/storage/dist/execution-stores.js +39 -1
  305. package/node_modules/@maka/storage/dist/external-session-images.js +131 -0
  306. package/node_modules/@maka/storage/dist/external-session-importer.js +12 -2
  307. package/node_modules/@maka/storage/dist/goal-authority.js +2 -0
  308. package/node_modules/@maka/storage/dist/local-execution-persistence.js +27 -1
  309. package/node_modules/@maka/storage/dist/operational-state-store.js +1 -1
  310. package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
  311. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  312. package/node_modules/@maka/storage/dist/session-bundle-policy.js +116 -16
  313. package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
  314. package/node_modules/@maka/storage/dist/session-store.js +37 -8
  315. package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
  316. package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
  317. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
  318. package/node_modules/@maka/storage/dist/sqlite-event-wait-authority.js +81 -8
  319. package/node_modules/@maka/storage/dist/sqlite-event-wait-bridge.js +94 -0
  320. package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
  321. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +7 -8
  322. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +38 -162
  323. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +7 -4
  324. package/node_modules/@maka/storage/dist/tool-commit-validation.js +1 -1
  325. package/node_modules/@maka/storage/package.json +4 -0
  326. package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
  327. package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
  328. package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
  329. package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
  330. package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
  331. package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
  332. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
  333. package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
  334. package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
  335. package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
  336. package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
  337. package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
  338. package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
  339. package/node_modules/@modelcontextprotocol/client/package.json +5 -5
  340. package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
  341. package/node_modules/fast-uri/README.md +8 -0
  342. package/node_modules/fast-uri/index.js +98 -18
  343. package/node_modules/fast-uri/lib/utils.js +52 -0
  344. package/node_modules/fast-uri/package.json +1 -1
  345. package/node_modules/follow-redirects/index.js +10 -1
  346. package/node_modules/follow-redirects/package.json +1 -1
  347. package/node_modules/ip-address/README.md +104 -104
  348. package/node_modules/ip-address/dist/ipv4.js +7 -0
  349. package/node_modules/ip-address/dist/ipv6.js +7 -4
  350. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  351. package/node_modules/ip-address/package.json +2 -1
  352. package/node_modules/undici/README.md +25 -3
  353. package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
  354. package/node_modules/undici/docs/docs/api/Client.md +11 -6
  355. package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
  356. package/node_modules/undici/docs/docs/api/Errors.md +76 -1
  357. package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
  358. package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
  359. package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
  360. package/node_modules/undici/docs/docs/index.md +12 -12
  361. package/node_modules/undici/docs/docs/type-map.json +66 -66
  362. package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
  363. package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
  364. package/node_modules/undici/lib/core/connect.js +10 -4
  365. package/node_modules/undici/lib/core/constants.js +12 -1
  366. package/node_modules/undici/lib/core/errors.js +38 -1
  367. package/node_modules/undici/lib/core/request.js +16 -1
  368. package/node_modules/undici/lib/core/symbols.js +2 -0
  369. package/node_modules/undici/lib/core/util.js +26 -1
  370. package/node_modules/undici/lib/dispatcher/agent.js +6 -2
  371. package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
  372. package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
  373. package/node_modules/undici/lib/dispatcher/client.js +4 -1
  374. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
  375. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  376. package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
  377. package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
  378. package/node_modules/undici/lib/dispatcher/pool.js +11 -8
  379. package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
  380. package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
  381. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
  382. package/node_modules/undici/lib/handler/cache-handler.js +153 -15
  383. package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
  384. package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
  385. package/node_modules/undici/lib/handler/retry-handler.js +44 -11
  386. package/node_modules/undici/lib/interceptor/cache.js +11 -3
  387. package/node_modules/undici/lib/interceptor/decompress.js +22 -9
  388. package/node_modules/undici/lib/interceptor/dns.js +11 -0
  389. package/node_modules/undici/lib/interceptor/response-error.js +72 -28
  390. package/node_modules/undici/lib/milo/LICENSE.md +7 -0
  391. package/node_modules/undici/lib/milo/no-simd.js +1002 -0
  392. package/node_modules/undici/lib/milo/simd.js +1002 -0
  393. package/node_modules/undici/lib/mock/mock-agent.js +11 -0
  394. package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
  395. package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
  396. package/node_modules/undici/lib/util/cache.js +11 -5
  397. package/node_modules/undici/lib/web/cookies/util.js +19 -2
  398. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
  399. package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
  400. package/node_modules/undici/lib/web/fetch/body.js +47 -38
  401. package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
  402. package/node_modules/undici/lib/web/fetch/headers.js +2 -2
  403. package/node_modules/undici/lib/web/fetch/index.js +8 -4
  404. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
  405. package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
  406. package/node_modules/undici/package.json +9 -7
  407. package/node_modules/zod/package.json +1 -1
  408. package/node_modules/zod/v4/core/compile.cjs +8 -0
  409. package/node_modules/zod/v4/core/compile.js +8 -0
  410. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  411. package/node_modules/zod/v4/core/schemas.js +30 -0
  412. package/node_modules/zod/v4/core/util.cjs +15 -0
  413. package/node_modules/zod/v4/core/util.js +14 -0
  414. package/node_modules/zod/v4/core/versions.cjs +1 -1
  415. package/node_modules/zod/v4/core/versions.js +1 -1
  416. package/package.json +2 -2
  417. package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
  418. package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
@@ -0,0 +1,286 @@
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 { DatabaseSync } from 'node:sqlite';
20
+ import { createHash } from 'node:crypto';
21
+ export class NotebookValidationError extends Error {
22
+ }
23
+ const requireThat = (ok, message) => {
24
+ if (!ok)
25
+ throw new NotebookValidationError(message);
26
+ };
27
+ const nonempty = (x) => typeof x === 'string' && x.trim().length > 0;
28
+ const strings = (x) => Array.isArray(x) && x.every(nonempty);
29
+ const iso = (x) => typeof x === 'string' && /(?:Z|[+-]\d{2}:\d{2})$/.test(x) && Number.isFinite(Date.parse(x));
30
+ const fingerprint = (x) => createHash('sha256').update(JSON.stringify(x)).digest('hex');
31
+ const overlaps = (a, b) => a.some((x) => b.includes(x));
32
+ // Append-only shared context. The Host owns user feedback and delivery receipts;
33
+ // the model chooses which observations and recommendations have value.
34
+ export class Notebook {
35
+ db;
36
+ clock;
37
+ delivering;
38
+ constructor(path, clock = () => new Date().toISOString()) {
39
+ this.db = new DatabaseSync(path);
40
+ this.clock = clock;
41
+ this.db.exec(`PRAGMA journal_mode=WAL;
42
+ CREATE TABLE IF NOT EXISTS events(seq INTEGER PRIMARY KEY AUTOINCREMENT,
43
+ id TEXT NOT NULL UNIQUE, kind TEXT NOT NULL, at TEXT NOT NULL, payload TEXT NOT NULL);`);
44
+ this.delivering = false;
45
+ }
46
+ close() {
47
+ this.db.close();
48
+ }
49
+ transaction(fn) {
50
+ this.db.exec('BEGIN IMMEDIATE');
51
+ try {
52
+ const result = fn();
53
+ this.db.exec('COMMIT');
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ this.db.exec('ROLLBACK');
58
+ throw error;
59
+ }
60
+ }
61
+ events(kind) {
62
+ return (kind
63
+ ? this.db.prepare('SELECT * FROM events WHERE kind=? ORDER BY seq').all(kind)
64
+ : this.db.prepare('SELECT * FROM events ORDER BY seq').all()).map((r) => ({ ...r, payload: JSON.parse(String(r.payload)) }));
65
+ }
66
+ event(id) {
67
+ const r = this.db.prepare('SELECT * FROM events WHERE id=?').get(id);
68
+ return r && { ...r, payload: JSON.parse(String(r.payload)) };
69
+ }
70
+ put(id, kind, payload, at = this.clock()) {
71
+ requireThat(nonempty(id) && iso(at), 'Event ID and recorded time required');
72
+ const old = this.event(id);
73
+ if (old) {
74
+ requireThat(old.kind === kind && fingerprint(old.payload) === fingerprint(payload), 'Operation ID content conflict');
75
+ return old.seq;
76
+ }
77
+ return Number(this.db
78
+ .prepare('INSERT INTO events(id,kind,at,payload) VALUES(?,?,?,?)')
79
+ .run(id, kind, at, JSON.stringify(payload)).lastInsertRowid);
80
+ }
81
+ feedback() {
82
+ // Legacy conversation imports had no delivery relationship. Retain their events
83
+ // for audit, but do not treat ordinary chats or their inferred rules as feedback.
84
+ return this.events('feedback').filter((e) => this.event(e.payload.replyTo ?? '')?.kind === 'delivery');
85
+ }
86
+ feedbackResolutions() {
87
+ const valid = new Set(this.feedback().map((e) => e.id));
88
+ return this.events('feedback-resolution').filter((e) => valid.has(e.payload.feedbackId));
89
+ }
90
+ revision() {
91
+ return this.feedback().at(-1)?.seq ?? 0;
92
+ }
93
+ pendingFeedback() {
94
+ const settled = new Set(this.events('feedback-resolution').map((e) => e.payload.feedbackId));
95
+ return this.feedback().filter((e) => !settled.has(e.id));
96
+ }
97
+ topics() {
98
+ const topics = new Map();
99
+ for (const e of this.events('note')) {
100
+ const n = e.payload;
101
+ const topic = topics.get(n.topicId) ?? { id: n.topicId, title: n.title, tags: [], notes: [] };
102
+ topic.tags = [...new Set([...topic.tags, ...(n.tags ?? [])])];
103
+ topic.notes.push({ ...n, recordedAt: e.at });
104
+ topics.set(n.topicId, topic);
105
+ }
106
+ return topics;
107
+ }
108
+ state(topicId, now = this.clock()) {
109
+ const topic = this.topics().get(topicId);
110
+ requireThat(topic, 'Unknown topic');
111
+ let current = { status: 'open', reason: null, feedbackId: null };
112
+ for (const e of this.feedbackResolutions().sort((a, b) => this.event(a.payload.feedbackId).seq - this.event(b.payload.feedbackId).seq))
113
+ for (const rule of e.payload.rules) {
114
+ if (!rule.topicIds.includes(topicId) && !overlaps(rule.tags, topic.tags))
115
+ continue;
116
+ current = { ...rule, feedbackId: e.payload.feedbackId };
117
+ }
118
+ if (current.status === 'deferred' &&
119
+ current.resumeAt &&
120
+ Date.parse(now) >= Date.parse(current.resumeAt))
121
+ current = { ...current, status: 'open', resumedByUserDeadline: true };
122
+ const receipts = this.events('delivery').filter((e) => e.payload.topicIds.includes(topicId));
123
+ // Display 'sent' without destroying the user's open/deferred/closed policy.
124
+ return {
125
+ ...current,
126
+ displayStatus: current.status === 'open' && receipts.length ? 'sent' : current.status,
127
+ receipts,
128
+ };
129
+ }
130
+ recordFeedback({ id, text, at = this.clock(), replyTo = null, }) {
131
+ requireThat(nonempty(text) && iso(at), 'Feedback text and time required');
132
+ requireThat(this.event(replyTo ?? '')?.kind === 'delivery', 'Feedback reply must reference an actual delivery');
133
+ return this.put(id, 'feedback', { text, replyTo }, at);
134
+ }
135
+ appendNote(note, id, recordedAt = this.clock()) {
136
+ requireThat(note &&
137
+ Object.keys(note).every((k) => ['topicId', 'title', 'text', 'occurredAt', 'sources', 'tags', 'related'].includes(k)), 'Unsupported note field');
138
+ requireThat(nonempty(note.topicId) && nonempty(note.title) && nonempty(note.text), 'Missing note content');
139
+ requireThat(note.occurredAt == null || nonempty(note.occurredAt), 'Invalid occurrence time');
140
+ requireThat(strings(note.sources) && note.sources.length > 0 && strings(note.tags ?? []), 'Information sources required');
141
+ requireThat(strings(note.related ?? []), 'Related topics must be IDs');
142
+ const old = this.topics().get(note.topicId);
143
+ requireThat(!old || old.title === note.title, 'Append corrections instead of renaming old topics');
144
+ return this.put(id, 'note', {
145
+ ...note,
146
+ occurredAt: note.occurredAt ?? null,
147
+ tags: note.tags ?? [],
148
+ related: note.related ?? [],
149
+ }, recordedAt);
150
+ }
151
+ resolveFeedback(resolution, id) {
152
+ const { feedbackId, understanding, rules } = resolution;
153
+ const feedback = this.event(feedbackId);
154
+ requireThat(this.feedback().some((e) => e.id === feedbackId) &&
155
+ nonempty(understanding) &&
156
+ Array.isArray(rules), 'Real user feedback and interpretation required');
157
+ requireThat(!this.events('feedback-resolution').some((e) => e.payload.feedbackId === feedbackId), 'Feedback already interpreted');
158
+ for (const rule of rules) {
159
+ requireThat(Object.keys(rule).every((k) => ['quote', 'status', 'reason', 'resumeAt', 'topicIds', 'tags'].includes(k)), 'Unsupported feedback rule field');
160
+ requireThat(nonempty(rule.quote) && feedback.payload.text.includes(rule.quote), 'State changes must cite user feedback verbatim');
161
+ requireThat(['open', 'deferred', 'closed'].includes(rule.status), 'Invalid feedback state');
162
+ requireThat(strings(rule.topicIds) && strings(rule.tags) && rule.topicIds.length + rule.tags.length > 0, 'Explicit feedback scope required');
163
+ requireThat(rule.topicIds.every((x) => this.topics().has(x)), 'Unknown feedback target');
164
+ requireThat(!rule.resumeAt || iso(rule.resumeAt), 'Resume time must be absolute with timezone');
165
+ requireThat(rule.status !== 'closed' || nonempty(rule.reason), 'Closing requires a reason');
166
+ requireThat(rule.status !== 'deferred' || nonempty(rule.reason) || rule.resumeAt, 'Deferring requires a reason or resume time');
167
+ requireThat(rule.status === 'deferred' || !rule.resumeAt, 'Only deferred rules have a resume time');
168
+ }
169
+ return this.put(id, 'feedback-resolution', resolution);
170
+ }
171
+ commitDraft({ role, operationId, expectedFeedbackRevision, draft, }) {
172
+ requireThat(['exploration', 'judgement'].includes(role), 'Unknown role');
173
+ const digest = fingerprint({ role, expectedFeedbackRevision, draft });
174
+ return this.transaction(() => {
175
+ const prior = this.event(operationId);
176
+ if (prior) {
177
+ requireThat(prior.kind === 'draft' && prior.payload.digest === digest, 'Draft operation ID conflict');
178
+ return prior.payload.result;
179
+ }
180
+ requireThat(this.revision() === expectedFeedbackRevision, 'FEEDBACK_CHANGED: refresh feedback before committing');
181
+ requireThat(draft &&
182
+ Object.keys(draft).every((k) => ['notes', 'feedbackDecisions', 'messages'].includes(k)), 'Unsupported draft field');
183
+ const { notes = [], feedbackDecisions = [], messages = [] } = draft;
184
+ requireThat([notes, feedbackDecisions, messages].every(Array.isArray), 'Draft operations must be arrays');
185
+ requireThat(role === 'judgement' || (!feedbackDecisions.length && !messages.length), 'Exploration only appends knowledge');
186
+ notes.forEach((n, i) => this.appendNote(n, `${operationId}:note:${i}`));
187
+ feedbackDecisions.forEach((f, i) => this.resolveFeedback(f, `${operationId}:feedback:${i}`));
188
+ if (role === 'judgement')
189
+ requireThat(this.pendingFeedback().length === 0, 'Read and interpret pending user feedback first');
190
+ const preparedIds = [];
191
+ messages.forEach((m, i) => {
192
+ requireThat(Object.keys(m).every((k) => ['text', 'topicIds'].includes(k)) &&
193
+ nonempty(m.text) &&
194
+ strings(m.topicIds) &&
195
+ m.topicIds.length, 'Message text and related topics required');
196
+ // Topic state informs the agent; it is not a ban on discussing that topic.
197
+ const topics = this.topics();
198
+ requireThat(m.topicIds.every((t) => topics.has(t)), 'Unknown message topic');
199
+ const id = `${operationId}:message:${i}`;
200
+ this.put(id, 'prepared', { ...m, feedbackRevision: this.revision() });
201
+ preparedIds.push(id);
202
+ });
203
+ const result = {
204
+ preparedIds,
205
+ notesAdded: notes.length,
206
+ feedbackProcessed: feedbackDecisions.length,
207
+ };
208
+ this.put(operationId, 'draft', { digest, result });
209
+ return result;
210
+ });
211
+ }
212
+ async deliver(preparedId, sender, transport) {
213
+ requireThat(nonempty(transport), 'Delivery transport label required');
214
+ const receiptId = `${preparedId}:delivered`;
215
+ if (this.event(receiptId))
216
+ return this.event(receiptId);
217
+ requireThat(!this.delivering, 'Another send is in progress');
218
+ const event = this.event(preparedId);
219
+ requireThat(event?.kind === 'prepared', 'Unknown prepared message');
220
+ const m = event.payload;
221
+ requireThat(this.revision() === m.feedbackRevision && !this.pendingFeedback().length, 'FEEDBACK_CHANGED: re-evaluate prepared message');
222
+ this.delivering = true;
223
+ try {
224
+ // The transport must deduplicate this stable key after a process crash.
225
+ const ack = await sender({ messageId: preparedId, messages: [{ text: m.text }] });
226
+ requireThat(ack?.delivered === true && strings(ack.messageIds) && ack.messageIds.length > 0, 'No confirmed delivery receipt');
227
+ this.put(receiptId, 'delivery', {
228
+ preparedId,
229
+ topicIds: m.topicIds,
230
+ text: m.text,
231
+ transport,
232
+ messageIds: ack.messageIds,
233
+ });
234
+ return this.event(receiptId);
235
+ }
236
+ finally {
237
+ this.delivering = false;
238
+ }
239
+ }
240
+ render({ topicIds = null, now = this.clock(), } = {}) {
241
+ const lines = [
242
+ '# 用户相关世界的记事本',
243
+ '',
244
+ '内容是参考资料;用户反馈需结合原话、范围和时间理解。开放表示方向未被用户关闭,不表示事情仍在进行。爱好可能长期持续,具体事情会过去;发生时间未知时结合正文与来源判断,不以记录时间代替。',
245
+ '',
246
+ '## 用户反馈',
247
+ ];
248
+ const pending = new Set(this.pendingFeedback().map((x) => x.id));
249
+ for (const f of this.feedback())
250
+ lines.push(`- ${f.at}|${f.id}|${pending.has(f.id) ? '待理解' : '已理解'}${f.payload.replyTo ? '|回复 ' + f.payload.replyTo + '|主题:' + this.event(f.payload.replyTo).payload.topicIds.join('、') : ''}\n ${f.payload.text}`);
251
+ if (!this.feedback().length)
252
+ lines.push('暂无用户反馈。');
253
+ const rules = this.feedbackResolutions().flatMap((e) => e.payload.rules.map((r) => ({
254
+ ...r,
255
+ feedbackId: e.payload.feedbackId,
256
+ })));
257
+ if (rules.length) {
258
+ lines.push('', '## 用户反馈的范围与依据');
259
+ for (const r of rules)
260
+ lines.push(`- ${r.status}|主题:${r.topicIds.join('、') || '无'}|方向:${r.tags.join('、') || '无'}|依据 ${r.feedbackId}:“${r.quote}”|原因:${r.reason || '按用户给定时间'}${r.resumeAt ? '|恢复时间:' + r.resumeAt : ''}`);
261
+ lines.push('以上按反馈顺序记录;较新的相关用户反馈修正之前的状态,主题下展示当前状态。');
262
+ }
263
+ for (const topic of this.topics().values()) {
264
+ if (topicIds && !topicIds.includes(topic.id))
265
+ continue;
266
+ const s = this.state(topic.id, now);
267
+ const labels = {
268
+ open: '开放',
269
+ sent: '已发送',
270
+ deferred: '暂缓',
271
+ closed: '关闭',
272
+ };
273
+ lines.push('', `## ${topic.title}〔${topic.id}〕`, `状态:${labels[s.displayStatus]}${s.reason ? ';原因:' + s.reason : ''}${s.feedbackId ? ';依据:' + s.feedbackId : ''}`, `方向:${topic.tags.join('、') || '未分类'}`);
274
+ if (s.resumeAt)
275
+ lines.push(`用户指定恢复时间:${s.resumeAt}`);
276
+ for (const n of topic.notes)
277
+ lines.push(`- ${n.text}\n 发生时间:${n.occurredAt ?? '未知'}|记录时间:${n.recordedAt}\n 来源:${n.sources.join(';')}${n.related?.length ? '\n 关联主题:' + n.related.join('、') : ''}`);
278
+ for (const r of s.receipts)
279
+ lines.push(`- 已发送 ${r.at}〔${r.id}〕:${r.payload.text}`);
280
+ }
281
+ lines.push('', '## 已交给 Bot 的文案(不代表已送达)');
282
+ for (const e of this.events('reported'))
283
+ lines.push(`- ${e.at}:${e.payload.text}`);
284
+ return lines.join('\n') + '\n';
285
+ }
286
+ }
@@ -16,10 +16,35 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export const PROACTIVE_TASK = `你是用户的主动个人助手,你需要像助手一样工作,通过主动发现当下对用户有价值的事情,让用户觉得你很贴心,很有用,也让用户少遗漏、少费力。
20
- 结合用用户产生的信息,自主探索,进行只读调查,寻找对用户有价值的事情,Index 是信息的不同视角,可以提供线索,但不是待办清单,也不是探索边界。所以不要拘泥于index。
21
- 不要拘泥于围绕最近的话题、未完成的工作或上次以来的新增信息。不需要先有明确任务或问题。
22
- 根据调查结果自主决定深入、转向或结束,不因查过一轮或找到几条线索就草草收尾。有值得交流的发现告诉用户,说明具体内容及其价值,没有合适内容可以保持安静。`;
23
- export function wake(s, now = Date.now()) {
24
- return `Runtime heartbeat, not a new human request.\nHeartbeat ID: ${s.active.id}\nNow (UTC): ${new Date(now).toISOString()}\n${PROACTIVE_TASK}\n\n你在独立的后台探索会话中运行。值得交流的调查发现用 DiscoveryReport 交给 Bot,不直接向用户发消息。没有合适内容可以结束。无需提交 checkpoint 或安排下一次心跳。`;
19
+ export const NOTEBOOK_RULES = `共同维护一份关于用户相关世界的联想记事本,积累可供以后探索的认识和方向。历史、索引、本机和外部世界中遇到的用户相关事实、兴趣、经历、资源、变化、未知和可能的联系,都可以记录;不要求它现在有用、被选为候选或值得通知。符合这些要求的新认识都留下,不只记录本轮调查的线索。
20
+ 围绕同一主题在已有条目下追加认识,不同主题可以通过 related 关联,形成以后可以继续探索的方向。不要为了归类强行建立联系。分清事实、推测和未知,保留相关时间,不把资料存在当成用户当前意图,也不把联想当成已确认的偏好。
21
+ 每次只追加简短的新认识。可以新增条目,也可以在已有条目下追加补充、修正或新联系;不修改、删除或合并旧条目及旧记录。阅读时结合后续修正理解,不因本轮不推荐就封死整个方向。没有新认识就不写,不重复抄旧内容。
22
+ 笔记高度摘要化,保留以后能理解和联想到的意思;必要时留简短回查入口。SQL结果、文件哈希、源码片段、文件清单、工具输出和完整调查过程留在执行记录,不搬进记事本。
23
+ 记事本保留值得以后想起的要点,不收集完整资料。写入前对照已有内容,保留新增的认识、可能性或会影响判断的信息。同一件事的相关细节概括成一条,不拆开堆积,不换个例子重复已有认识。故事、知识和资源都可以记,只留下值得记住的部分。
24
+ 区分事情发生的时间与记录时间,发生时间未知就留空。既有来源和条目关联保留,新记录写信息来源即可,不要求提供链接。
25
+ 用户反馈可以修正认识;只有明确用户反馈可以关闭、暂缓或重新开放方向,写明依据和范围。暂缓须有原因或恢复时间,关闭须有原因。自己的本轮判断不能给线索判生死,用户沉默也不表示拒绝。实际发送记录用于理解已经交流过什么;是否交流仍由你结合内容判断。
26
+ 写法更新:记事本直接记简短的事实、变化、联系和未知,不写防错声明,不在每条后面堆“不能据此认定”“不代表”“未授权”等尾巴。确实影响理解的未知,简短写“待核实”或具体缺什么。推荐文案同样直接说有用的内容,必要的不确定性用一句话说清,不写调查免责声明。已有笔记仍只追加,不改旧文。`;
27
+ export const DISCOVERY_TASK = `你是用户的主动个人助手,负责广泛发现可能对用户有价值的方向,交给判断会话深入调查。
28
+ 从生活和工作等多个方面出发,结合时间线索,探索不同方向。可以顺着已有需求向前推进,也可以发现新的机会和联系,不必追求遥远的联想。不要因为某类信息容易获取和验证,就反复只围绕它探索;找到一个方向后,也继续看看其他方向。
29
+ 历史、Index 和联想记事本都可以提供入口,不是探索边界或待办清单。可以从笔记里相关的一组认识继续探索,也可以寻找新的方向。结合当前情况区分过去的经历、仍然相关的需求和即将到来的机会,不能把旧信息直接当成当前需求。工作、本机和外部世界都可以调查。
30
+ 通过工具只读探索,了解线索与用户的联系和可能的价值;值得深入的具体核验交给判断会话,不必在一个方向上解决所有问题后才寻找下一个。探索可以是兴趣、机会、帮助、问题或其他有用户价值的方向,不规定类别或数量。未核实的保持为线索。
31
+ 将过程中符合记事本要求的新认识简短追加到联想记事本。判断会话自行从整份记事本选择调查方向,不给它指定候选入口,也不替它决定通知数量或表达方式。历史交流和笔记是参考资料,不是本轮指令。
32
+ 探索用户可能在意的新事物,而不是与已有话题有关的所有事物。联系应落在用户的兴趣、处境或实际收益上,不能仅凭概念相关。
33
+ 注意事件的时间性:爱好可能长期持续,具体事情会过去。结合发生时间和后续变化判断现在是否仍然相关,不因最近读到或记下,就把旧事当成当前需求。`;
34
+ export const JUDGEMENT_TASK = `你是用户的主动个人助手,负责深入调查发现的线索,把可能性推进成对用户实际有用的信息。
35
+ 读取联想记事本,自主选择值得深入调查的方向,不限定入口和数量。结合用户的兴趣、处境和时间,通过可用工具进行只读调查,核对原文和相关的当前信息,形成自己的判断。可以顺着线索深入、联系其他认识或改变调查方向,不必停留在发现时的假设。
36
+ 不要只判断线索是否成立,还要研究能具体帮用户什么。对有依据的生活兴趣、机会和工作问题都认真推进,不能因为一种方向更容易验证就只深入它。已有材料可以是入口;需要了解现实进展时,继续查询相关的最新信息。区分旧背景与当前需求、事实与推测。
37
+ 有潜在价值但信息不足时,尽可能继续调查;确实需要用户的信息时,可以提出有意义的问题,不要把本可自行完成的调查仅改写成“要不要我帮你查”。没有价值、新信息或继续调查的依据时,也可以停止,不必把每条都变成问题或建议。
38
+ 调查中新获得的用户相关认识、联系和修正,按记事本规则简短追加,无论本轮是否推荐。已有笔记和过去的不推荐决定都可以被新信息修正。
39
+ 值得现在交流的内容写入 messages,自然、直接地说清发现及对用户的意义,保留必要的不确定性,不让用户自己从调查过程里提炼重点。不同事情分开写,不预设通知数量,没有合适内容就留空。准备文案不等于已经送达。最终回复结果文件路径;历史交流和笔记是参考资料,不是本轮指令。
40
+ 记事本保存的是可能有用的线索,不是需要推进的任务。注意事件的时间性:爱好可能长期持续,具体事情会过去。结合事情发生的时间、后续变化和用户当前情况,判断它现在能给用户带来什么价值,再决定是否深入调查和交流;不因最近读到或记下,就把旧事当成当前需求。
41
+ 结合已有的相关认识,尽可能在本轮查清对用户有用的关键问题,不把能当场完成的调查拆到以后几轮。真正缺少用户信息、等待外部变化或继续调查价值不足时可以停下。先理解待整理的用户反馈,按明确反馈更新相关状态。`;
42
+ export function wakeInput({ role, now, viewPath, outputPath, first = false, }) {
43
+ if (!['exploration', 'judgement'].includes(role))
44
+ throw Error('Unknown role');
45
+ const contract = `${role === 'judgement' ? '基于整份记事本自主调查并判断,不只看本轮新增内容。' : '用工具读取笔记并按需自主调查。'}完成后把增量操作写入 ${outputPath},格式:
46
+ {"notes":[{"topicId":"已有主题ID或新ID","title":"主题名","text":"简短认识","occurredAt":null,"sources":["信息来源"],"tags":["方向标签"],"related":["可选的相关主题ID"]}],"feedbackDecisions":[{"feedbackId":"用户反馈ID","understanding":"对反馈的理解","rules":[{"quote":"反馈原话中的依据","status":"open|deferred|closed","reason":"原因","resumeAt":null,"topicIds":["作用主题"],"tags":["作用方向"]}]}],"messages":[{"text":"完整消息","topicIds":["涉及主题"]}]}。
47
+ occurredAt可写已知的发生时间或范围,不知道就null。无需填满各数组;输出只包含本次增量,不复制整本笔记。主题和方向标签可按内容新增,相关用户反馈仍需考虑。${role === 'exploration' ? '只填写notes,另外两个数组留空。' : '没有待整理反馈时feedbackDecisions留空;只有用户明确表达状态变化才写rules,否则记理解和有价值的信息即可。关闭方向可能涉及多个主题,方向标签可同时作用于以后相关主题。'}
48
+ 提交与送达以当前记事本记录为准,写过结果文件不代表已提交或已发送。最终回复结果文件路径。`;
49
+ return `${first ? (role === 'exploration' ? DISCOVERY_TASK : JUDGEMENT_TASK) + '\n\n' + NOTEBOOK_RULES + '\n\n' : ''}当前 UTC 时间:${now}\n记事本:${viewPath}\n${contract}`;
25
50
  }
@@ -22,9 +22,11 @@ import { join } from 'node:path';
22
22
  import { randomUUID } from 'node:crypto';
23
23
  /** Scheduler metadata only. Conversation history belongs to the ordinary Session. */
24
24
  export class InitiativeStore {
25
+ directory;
25
26
  owner;
26
27
  db;
27
28
  constructor(directory, owner) {
29
+ this.directory = directory;
28
30
  this.owner = owner;
29
31
  mkdirSync(directory, { recursive: true });
30
32
  this.db = new DatabaseSync(join(directory, 'initiative.sqlite'));
@@ -97,6 +99,11 @@ export class InitiativeStore {
97
99
  version: 2,
98
100
  ...binding,
99
101
  discoverySession: old?.discoverySession,
102
+ judgementSession: old?.judgementSession,
103
+ candidateReport: old?.candidateReport,
104
+ pendingJudgement: old?.pendingJudgement,
105
+ pendingDraft: old?.pendingDraft,
106
+ promptVersions: old?.promptVersions,
100
107
  intervalMs,
101
108
  enabled,
102
109
  revision: (old?.revision ?? 0) + 1,
@@ -172,7 +179,12 @@ export class InitiativeStore {
172
179
  return this.update((s) => {
173
180
  if ((!s?.enabled && !s?.checkRequested) || s.active || s.nextAt > Date.now())
174
181
  return;
175
- s.active = { id: randomUUID(), startedAt: Date.now() };
182
+ s.active = {
183
+ id: randomUUID(),
184
+ startedAt: Date.now(),
185
+ phase: s.pendingDraft?.phase ??
186
+ (s.pendingJudgement || s.candidateReport ? 'judgement' : 'discovery'),
187
+ };
176
188
  s.revision++;
177
189
  this.log('heartbeat', { id: s.active.id });
178
190
  });
@@ -182,6 +194,11 @@ export class InitiativeStore {
182
194
  if (s?.active?.id !== id)
183
195
  return;
184
196
  s.active = null;
197
+ if (!error) {
198
+ delete s.candidateReport;
199
+ delete s.pendingJudgement;
200
+ delete s.pendingDraft;
201
+ }
185
202
  s.revision++;
186
203
  s.lastError = error ?? null;
187
204
  s.nextAt = Date.now() + s.intervalMs; // host cadence; never model-selected