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.
- package/DISCLAIMER-WIP +1 -1
- package/LICENSE +15 -11
- package/README.md +173 -1
- package/README.zh-CN.md +156 -0
- package/THIRD_PARTY_NOTICES.txt +12 -12
- package/dist/cli-core.js +1 -0
- package/dist/pi-goal.js +13 -0
- package/dist/pi-tui-runner.js +44 -1
- package/dist/run-command-core.js +256 -48
- package/dist/run-session-command.js +534 -0
- package/dist/run-session-result.js +38 -0
- package/dist/run-turn-outcome.js +174 -0
- package/dist/runtime-host-cli.js +32 -17
- package/dist/runtime-host-run-command.js +53 -165
- package/dist/runtime-host-run-mcp.js +3 -0
- package/dist/runtime-host-session-channel.js +3 -1
- package/dist/runtime-host-session-driver.js +5 -0
- package/dist/runtime-host-setup-command.js +114 -7
- package/dist/tui-copy-catalog.js +24 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/docs/docs/api/Client.md +2 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/core/symbols.js +1 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/client.js +3 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/cache-handler.js +48 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/handler/redirect-handler.js +8 -1
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/interceptor/decompress.js +15 -5
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/index.js +3 -1
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/parse.js +138 -137
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/cookies/util.js +21 -2
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/fetch/index.js +3 -3
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/infra/index.js +14 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/lib/web/websocket/receiver.js +13 -0
- package/node_modules/@ai-sdk/provider-utils/node_modules/undici/package.json +1 -1
- package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog-store.js +87 -0
- package/node_modules/@maka/acp-executor-plugin/dist/acp-catalog.js +98 -21
- package/node_modules/@maka/acp-executor-plugin/dist/index.js +90 -14
- package/node_modules/@maka/acp-executor-plugin/dist/plugin.mjs +3997 -56
- package/node_modules/@maka/core/dist/assistant-turn-ids.js +34 -0
- package/node_modules/@maka/core/dist/bot-chat-settings.js +10 -1
- package/node_modules/@maka/core/dist/event-wait-delivery.js +67 -0
- package/node_modules/@maka/core/dist/event-wait.js +75 -10
- package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
- package/node_modules/@maka/core/dist/goal.js +54 -2
- package/node_modules/@maka/core/dist/model-catalog.js +19 -1
- package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -14
- package/node_modules/@maka/core/dist/model-metadata.js +42 -1
- package/node_modules/@maka/core/dist/models-dev-projection.js +32 -1
- package/node_modules/@maka/core/dist/provider-registry.js +16 -2
- package/node_modules/@maka/core/dist/runtime-event-store.js +0 -1
- package/node_modules/@maka/core/dist/runtime-event.js +24 -2
- package/node_modules/@maka/core/dist/runtime-invocation.js +10 -0
- package/node_modules/@maka/core/dist/session-checkin.js +31 -0
- package/node_modules/@maka/core/dist/tool-ledger-scanner.js +1 -9
- package/node_modules/@maka/core/dist/tool-recovery-bundle.js +1 -14
- package/node_modules/@maka/core/dist/turn-origin.js +14 -2
- package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
- package/node_modules/@maka/core/package.json +3 -0
- package/node_modules/@maka/eval/node_modules/undici/README.md +25 -3
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Client.md +11 -6
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Errors.md +76 -1
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/index.md +12 -12
- package/node_modules/@maka/eval/node_modules/undici/docs/docs/type-map.json +66 -66
- package/node_modules/@maka/eval/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
- package/node_modules/@maka/eval/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@maka/eval/node_modules/undici/lib/core/constants.js +12 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/core/errors.js +38 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/core/request.js +16 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/core/symbols.js +2 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/core/util.js +26 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/client.js +4 -1
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/pool.js +11 -8
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/cache-handler.js +153 -15
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/redirect-handler.js +28 -8
- package/node_modules/@maka/eval/node_modules/undici/lib/handler/retry-handler.js +44 -11
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/cache.js +11 -3
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/decompress.js +22 -9
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/dns.js +11 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/interceptor/response-error.js +72 -28
- package/node_modules/@maka/eval/node_modules/undici/lib/milo/LICENSE.md +7 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/milo/no-simd.js +1002 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/milo/simd.js +1002 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/mock/mock-agent.js +11 -0
- package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/util/cache.js +11 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/web/cookies/util.js +19 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
- package/node_modules/@maka/eval/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/body.js +47 -38
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/headers.js +2 -2
- package/node_modules/@maka/eval/node_modules/undici/lib/web/fetch/index.js +8 -4
- package/node_modules/@maka/eval/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@maka/eval/node_modules/undici/lib/web/websocket/receiver.js +25 -4
- package/node_modules/@maka/eval/node_modules/undici/package.json +9 -7
- package/node_modules/@maka/mcp/package.json +1 -1
- package/node_modules/@maka/runtime/dist/agent-run.js +5 -1
- package/node_modules/@maka/runtime/dist/agent-swarm-status-tool.js +0 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +29 -15
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +125 -131
- package/node_modules/@maka/runtime/dist/bots/bot-registry.js +19 -3
- package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +178 -6
- package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +163 -9
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +9 -2
- package/node_modules/@maka/runtime/dist/event-wait-tool.js +69 -0
- package/node_modules/@maka/runtime/dist/goal-continuation.js +195 -117
- package/node_modules/@maka/runtime/dist/goal-state.js +8 -0
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +34 -4
- package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
- package/node_modules/@maka/runtime/dist/memory-extraction.js +0 -2
- package/node_modules/@maka/runtime/dist/model-factory.js +26 -6
- package/node_modules/@maka/runtime/dist/model-fetcher.js +8 -1
- package/node_modules/@maka/runtime/dist/model-history.js +16 -3
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +15 -5
- package/node_modules/@maka/runtime/dist/plan-tools.js +0 -3
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +49 -2
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +12 -3
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +2 -0
- package/node_modules/@maka/runtime/dist/recovery-resolver.js +2 -1
- package/node_modules/@maka/runtime/dist/runtime-context.js +53 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
- package/node_modules/@maka/runtime/dist/sandbox-boundary-path.js +79 -2
- package/node_modules/@maka/runtime/dist/session-checkin.js +331 -0
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +7 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +5 -1
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +34 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -3
- package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
- package/node_modules/@maka/runtime/dist/tool-runtime.js +11 -2
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +50 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/docs/docs/api/Client.md +2 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/core/symbols.js +1 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/client.js +3 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/dispatcher/dispatcher-base.js +12 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/cache-handler.js +48 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/deduplication-handler.js +57 -13
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/handler/redirect-handler.js +8 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/interceptor/decompress.js +15 -5
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/index.js +3 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/parse.js +138 -137
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/cookies/util.js +21 -2
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource-stream.js +90 -9
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/fetch/index.js +3 -3
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/infra/index.js +14 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/lib/web/websocket/receiver.js +13 -0
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/node_modules/undici/package.json +1 -1
- package/node_modules/@maka/runtime/node_modules/@slack/socket-mode/package.json +1 -1
- package/node_modules/@maka/runtime/node_modules/undici/README.md +25 -3
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Client.md +11 -6
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Errors.md +76 -1
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/index.md +12 -12
- package/node_modules/@maka/runtime/node_modules/undici/docs/docs/type-map.json +66 -66
- package/node_modules/@maka/runtime/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
- package/node_modules/@maka/runtime/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/constants.js +12 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/errors.js +38 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/request.js +16 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/symbols.js +2 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/core/util.js +26 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/client.js +4 -1
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/pool.js +11 -8
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/cache-handler.js +153 -15
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/redirect-handler.js +28 -8
- package/node_modules/@maka/runtime/node_modules/undici/lib/handler/retry-handler.js +44 -11
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/cache.js +11 -3
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/decompress.js +22 -9
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/dns.js +11 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/interceptor/response-error.js +72 -28
- package/node_modules/@maka/runtime/node_modules/undici/lib/milo/LICENSE.md +7 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/milo/no-simd.js +1002 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/milo/simd.js +1002 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/mock/mock-agent.js +11 -0
- package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/util/cache.js +11 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/cookies/util.js +19 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/body.js +47 -38
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/headers.js +2 -2
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/fetch/index.js +8 -4
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/@maka/runtime/node_modules/undici/lib/web/websocket/receiver.js +25 -4
- package/node_modules/@maka/runtime/node_modules/undici/package.json +9 -7
- package/node_modules/@maka/runtime/package.json +3 -0
- package/node_modules/@maka/runtime-host/dist/assistant/bot/bridge.js +8 -0
- package/node_modules/@maka/runtime-host/dist/assistant/bot/capabilities.js +1 -0
- package/node_modules/@maka/runtime-host/dist/assistant/bot/controller.js +92 -22
- package/node_modules/@maka/runtime-host/dist/assistant/bot/host.js +11 -2
- package/node_modules/@maka/runtime-host/dist/assistant/bot/store.js +71 -2
- package/node_modules/@maka/runtime-host/dist/assistant/bot/turn-ids.js +38 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/assistant.js +7 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/controller.js +193 -32
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/discovery-capabilities.js +69 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/host.js +15 -28
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/notebook.js +286 -0
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/prompt.js +31 -6
- package/node_modules/@maka/runtime-host/dist/assistant/index-initiative/store.js +18 -1
- package/node_modules/@maka/runtime-host/dist/assistant/memory-network/controller.js +203 -71
- package/node_modules/@maka/runtime-host/dist/assistant/memory-network/host.js +21 -5
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-observer.js +94 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition-store.js +253 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/condition.js +133 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/controller.js +27 -14
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delegation.js +37 -5
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/delivery.js +1 -1
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/host.js +16 -2
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/matter.js +13 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/prompt.js +7 -5
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/review.js +68 -14
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/settlement-context.js +126 -0
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/store.js +92 -6
- package/node_modules/@maka/runtime-host/dist/assistant/proactive-matters/tools.js +93 -23
- package/node_modules/@maka/runtime-host/dist/assistant/service.js +72 -16
- package/node_modules/@maka/runtime-host/dist/client/host-profile.js +30 -1
- package/node_modules/@maka/runtime-host/dist/client/ssh-operator-activation.js +9 -2
- package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -3
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/personal-assistant.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +7 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-checkin.js +133 -0
- package/node_modules/@maka/runtime-host/dist/server/agent-settings-tools.js +0 -1
- package/node_modules/@maka/runtime-host/dist/server/canonical-session-projection.js +3 -2
- package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +151 -20
- package/node_modules/@maka/runtime-host/dist/server/event-wait-observation-store.js +19 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +127 -11
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +11 -0
- package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +5 -2
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +343 -53
- package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +457 -0
- package/node_modules/@maka/runtime-host/dist/server/goal-execution-coordinator.js +23 -6
- package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +5 -1
- package/node_modules/@maka/runtime-host/dist/server/index.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +44 -2
- package/node_modules/@maka/runtime-host/dist/server/personal-assistant-workspace.js +78 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +8 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +73 -3
- package/node_modules/@maka/runtime-host/dist/server/session-checkin.js +257 -0
- package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-coordinator.js +282 -0
- package/node_modules/@maka/runtime-host/dist/server/session-checkpoint-publication.js +250 -0
- package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-access.js +166 -0
- package/node_modules/@maka/runtime-host/dist/server/shell-run-event-wait-adapter.js +59 -0
- package/node_modules/@maka/runtime-host/dist/server/skill-catalog-repository.js +4 -2
- package/node_modules/@maka/storage/dist/agent-run-store-contract.js +14 -3
- package/node_modules/@maka/storage/dist/agent-run-store.js +10 -0
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +20 -3
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +2 -1
- package/node_modules/@maka/storage/dist/event-wait-authority.js +18 -1
- package/node_modules/@maka/storage/dist/event-wait-bridge.js +336 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +39 -1
- package/node_modules/@maka/storage/dist/external-session-images.js +131 -0
- package/node_modules/@maka/storage/dist/external-session-importer.js +12 -2
- package/node_modules/@maka/storage/dist/goal-authority.js +2 -0
- package/node_modules/@maka/storage/dist/local-execution-persistence.js +27 -1
- package/node_modules/@maka/storage/dist/operational-state-store.js +1 -1
- package/node_modules/@maka/storage/dist/production-session-snapshot.js +14 -6
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +116 -16
- package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
- package/node_modules/@maka/storage/dist/session-store.js +37 -8
- package/node_modules/@maka/storage/dist/snapshot-operation-gate.js +65 -0
- package/node_modules/@maka/storage/dist/sqlite-context-offload-schema.js +3 -3
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +4 -2
- package/node_modules/@maka/storage/dist/sqlite-event-wait-authority.js +81 -8
- package/node_modules/@maka/storage/dist/sqlite-event-wait-bridge.js +94 -0
- package/node_modules/@maka/storage/dist/sqlite-reclamation-checkpoint.js +37 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +7 -8
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +38 -162
- package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +7 -4
- package/node_modules/@maka/storage/dist/tool-commit-validation.js +1 -1
- package/node_modules/@maka/storage/package.json +4 -0
- package/node_modules/@modelcontextprotocol/client/dist/index-B-4n9P0J.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/index-J2FaQ-KY.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/client/dist/index.cjs +76 -22
- package/node_modules/@modelcontextprotocol/client/dist/index.d.cts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/index.d.mts.map +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/index.mjs +76 -22
- package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.cjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/shimsWorkerd.mjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/{src-oZBjf3U1.cjs → src-DpAS0jfg.cjs} +105 -8
- package/node_modules/@modelcontextprotocol/client/dist/{src-xKF0PJN-.mjs → src-WCy6ifGf.mjs} +88 -9
- package/node_modules/@modelcontextprotocol/client/dist/stdio.cjs +1 -1
- package/node_modules/@modelcontextprotocol/client/dist/stdio.mjs +1 -1
- package/node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/package.json +2 -2
- package/node_modules/@modelcontextprotocol/client/package.json +5 -5
- package/node_modules/fast-uri/.github/workflows/release.yml +35 -0
- package/node_modules/fast-uri/README.md +8 -0
- package/node_modules/fast-uri/index.js +98 -18
- package/node_modules/fast-uri/lib/utils.js +52 -0
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/follow-redirects/index.js +10 -1
- package/node_modules/follow-redirects/package.json +1 -1
- package/node_modules/ip-address/README.md +104 -104
- package/node_modules/ip-address/dist/ipv4.js +7 -0
- package/node_modules/ip-address/dist/ipv6.js +7 -4
- package/node_modules/ip-address/dist/v6/constants.js +3 -0
- package/node_modules/ip-address/package.json +2 -1
- package/node_modules/undici/README.md +25 -3
- package/node_modules/undici/docs/docs/api/CacheStore.md +24 -9
- package/node_modules/undici/docs/docs/api/Client.md +11 -6
- package/node_modules/undici/docs/docs/api/Dispatcher.md +3 -0
- package/node_modules/undici/docs/docs/api/Errors.md +76 -1
- package/node_modules/undici/docs/docs/api/H2CClient.md +3 -2
- package/node_modules/undici/docs/docs/api/Interceptors.md +28 -8
- package/node_modules/undici/docs/docs/api/RedirectHandler.md +13 -10
- package/node_modules/undici/docs/docs/index.md +12 -12
- package/node_modules/undici/docs/docs/type-map.json +66 -66
- package/node_modules/undici/lib/cache/memory-cache-store.js +48 -13
- package/node_modules/undici/lib/cache/sqlite-cache-store.js +83 -5
- package/node_modules/undici/lib/core/connect.js +10 -4
- package/node_modules/undici/lib/core/constants.js +12 -1
- package/node_modules/undici/lib/core/errors.js +38 -1
- package/node_modules/undici/lib/core/request.js +16 -1
- package/node_modules/undici/lib/core/symbols.js +2 -0
- package/node_modules/undici/lib/core/util.js +26 -1
- package/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/undici/lib/dispatcher/client-h1.js +116 -80
- package/node_modules/undici/lib/dispatcher/client-h2.js +124 -17
- package/node_modules/undici/lib/dispatcher/client.js +4 -1
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +3 -2
- package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +20 -3
- package/node_modules/undici/lib/dispatcher/parser-h1.js +1064 -0
- package/node_modules/undici/lib/dispatcher/pool-base.js +85 -31
- package/node_modules/undici/lib/dispatcher/pool.js +11 -8
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +18 -8
- package/node_modules/undici/lib/dispatcher/retry-agent.js +10 -0
- package/node_modules/undici/lib/dispatcher/round-robin-pool.js +15 -5
- package/node_modules/undici/lib/handler/cache-handler.js +153 -15
- package/node_modules/undici/lib/handler/deduplication-handler.js +112 -51
- package/node_modules/undici/lib/handler/redirect-handler.js +28 -8
- package/node_modules/undici/lib/handler/retry-handler.js +44 -11
- package/node_modules/undici/lib/interceptor/cache.js +11 -3
- package/node_modules/undici/lib/interceptor/decompress.js +22 -9
- package/node_modules/undici/lib/interceptor/dns.js +11 -0
- package/node_modules/undici/lib/interceptor/response-error.js +72 -28
- package/node_modules/undici/lib/milo/LICENSE.md +7 -0
- package/node_modules/undici/lib/milo/no-simd.js +1002 -0
- package/node_modules/undici/lib/milo/simd.js +1002 -0
- package/node_modules/undici/lib/mock/mock-agent.js +11 -0
- package/node_modules/undici/lib/mock/snapshot-recorder.js +3 -2
- package/node_modules/undici/lib/mock/snapshot-utils.js +3 -2
- package/node_modules/undici/lib/util/cache.js +11 -5
- package/node_modules/undici/lib/web/cookies/util.js +19 -2
- package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +69 -15
- package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -2
- package/node_modules/undici/lib/web/fetch/body.js +47 -38
- package/node_modules/undici/lib/web/fetch/formdata-parser.js +12 -4
- package/node_modules/undici/lib/web/fetch/headers.js +2 -2
- package/node_modules/undici/lib/web/fetch/index.js +8 -4
- package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +5 -5
- package/node_modules/undici/lib/web/websocket/receiver.js +25 -4
- package/node_modules/undici/package.json +9 -7
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +2 -2
- package/node_modules/@modelcontextprotocol/client/dist/index-D_CiY-T3.d.cts.map +0 -1
- package/node_modules/@modelcontextprotocol/client/dist/index-D_QDtbiv.d.mts.map +0 -1
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { HostGoalEventWaitBridge } from './goal-event-waits.js';
|
|
19
20
|
import { randomUUID } from 'node:crypto';
|
|
20
21
|
import { sameGoalControlLease, } from '@maka/core/goal';
|
|
21
22
|
import { GoalContinuationCoordinator, } from '@maka/runtime/goal-continuation';
|
|
@@ -24,6 +25,8 @@ import { buildGoalTools } from '@maka/runtime/goal-tools';
|
|
|
24
25
|
import { isSessionNotFoundError } from '@maka/storage/execution-stores';
|
|
25
26
|
import { authenticateInteractiveGoalAuthorityWriter, } from '@maka/storage/goal-authority';
|
|
26
27
|
import { projectGoalState } from './goal-projection.js';
|
|
28
|
+
import { GOAL_EVENT_WAIT_SUMMARY_LIMITS, } from '../protocol/goal.js';
|
|
29
|
+
import { truncateUtf8 } from '@maka/core/diagnostic-log';
|
|
27
30
|
import { waitForHostedExecutionTerminal } from './hosted-execution-wait.js';
|
|
28
31
|
import { goalTurnOutcomeFromHostedExecution } from './goal-execution-coordinator.js';
|
|
29
32
|
import { buildGoalEvaluationContext } from './goal-evaluation-context.js';
|
|
@@ -33,6 +36,7 @@ export class HostGoalCoordinator {
|
|
|
33
36
|
'goal.query': (input) => this.#query(input.sessionId),
|
|
34
37
|
'goal.arm': (input) => this.#arm(input),
|
|
35
38
|
'goal.control': (input) => this.#control(input),
|
|
39
|
+
'goal.event-wait.cancel': (input) => this.#cancelEventWait(input),
|
|
36
40
|
};
|
|
37
41
|
manager;
|
|
38
42
|
continuation;
|
|
@@ -50,7 +54,7 @@ export class HostGoalCoordinator {
|
|
|
50
54
|
/**
|
|
51
55
|
* Token count per Session as of the last continuation read, which is what a
|
|
52
56
|
* settling Turn reports so the Goal can measure its budget. It is not a
|
|
53
|
-
* baseline for a new Goal: only
|
|
57
|
+
* baseline for a new Goal: only evaluation context reads refresh it. A Session that
|
|
54
58
|
* has never run one has no entry, and `tokensBaselinePending` on the Goal is
|
|
55
59
|
* what carries that until the first Turn carrying it settles.
|
|
56
60
|
*/
|
|
@@ -60,6 +64,10 @@ export class HostGoalCoordinator {
|
|
|
60
64
|
#queuedAuthorityCommits = new Map();
|
|
61
65
|
#persistenceLane = Promise.resolve();
|
|
62
66
|
#persistenceFailure;
|
|
67
|
+
eventWaitBridge;
|
|
68
|
+
#jointLane = Promise.resolve();
|
|
69
|
+
#jointBusy = false;
|
|
70
|
+
#deferredGoalChanges = [];
|
|
63
71
|
#prepared = false;
|
|
64
72
|
#draining = false;
|
|
65
73
|
constructor(options) {
|
|
@@ -84,6 +92,28 @@ export class HostGoalCoordinator {
|
|
|
84
92
|
const tokenCache = this.#tokenCache;
|
|
85
93
|
this.continuation = new GoalContinuationCoordinator({
|
|
86
94
|
goalManager: this.manager,
|
|
95
|
+
eventWait: {
|
|
96
|
+
isGated: (sessionId) => !!this.#authorityBySession.get(sessionId)?.record.activeEventWait,
|
|
97
|
+
ownsSource: (sessionId, turnId, controlLease) => {
|
|
98
|
+
const record = this.#authorityBySession.get(sessionId)?.record;
|
|
99
|
+
const gate = record?.activeEventWait;
|
|
100
|
+
return (record?.goal.status === 'active' &&
|
|
101
|
+
!!gate &&
|
|
102
|
+
!gate.settled &&
|
|
103
|
+
gate.sourceExecution.sessionId === sessionId &&
|
|
104
|
+
gate.sourceExecution.turnId === turnId &&
|
|
105
|
+
sameGoalControlLease(gate.controlLease, controlLease) &&
|
|
106
|
+
sameGoalControlLease(record.controlLease, controlLease));
|
|
107
|
+
},
|
|
108
|
+
settleCompleted: async (sessionId, turnId, controlLease) => {
|
|
109
|
+
if (!this.eventWaitBridge)
|
|
110
|
+
throw new Error('Event wait persistence is unavailable');
|
|
111
|
+
await this.eventWaitBridge.settleCompleted(sessionId, turnId, controlLease);
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
mutateGoal: (operation) => this.#mutateGoal(() => operation({
|
|
115
|
+
recordPendingContinuation: (pending) => this.#recordPendingContinuation(pending, () => this.#flushGoalPersistence()),
|
|
116
|
+
})),
|
|
87
117
|
acquireActivity: () => this.#acquireResidency(),
|
|
88
118
|
evaluator: options.evaluator,
|
|
89
119
|
getRecentContext: async (sessionId) => {
|
|
@@ -104,13 +134,63 @@ export class HostGoalCoordinator {
|
|
|
104
134
|
settleCurrentExecution: (sessionId, turnId) => this.#settleCurrentExecution(sessionId, turnId),
|
|
105
135
|
},
|
|
106
136
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
137
|
+
if (options.stores.eventWaitStore && options.stores.runtimeEventStore) {
|
|
138
|
+
this.eventWaitBridge = new HostGoalEventWaitBridge({
|
|
139
|
+
stores: {
|
|
140
|
+
eventWaitStore: options.stores.eventWaitStore,
|
|
141
|
+
runtimeEventStore: options.stores.runtimeEventStore,
|
|
142
|
+
agentRunStore: options.stores.agentRunStore,
|
|
143
|
+
},
|
|
144
|
+
authority: (sessionId) => this.#authorityBySession.get(sessionId),
|
|
145
|
+
changed: this.#onProjectionChanged,
|
|
146
|
+
mutate: (sessionId, operation) => this.#mutateWait(sessionId, operation),
|
|
147
|
+
settleAdditional: (sessionId, tokensNow, controlLease) => this.#mutateGoal(async () => {
|
|
148
|
+
const goal = this.manager.get(sessionId);
|
|
149
|
+
if (goal?.status === 'active' &&
|
|
150
|
+
this.manager.matchesControlLease(sessionId, controlLease))
|
|
151
|
+
this.manager.settleTurn(sessionId, {
|
|
152
|
+
checkpoint: { goalId: goal.id, revision: goal.revision },
|
|
153
|
+
verdict: 'continue',
|
|
154
|
+
tokensNow,
|
|
155
|
+
reason: goal.lastReason ?? 'Explicit event wait remains outstanding.',
|
|
156
|
+
});
|
|
157
|
+
}),
|
|
158
|
+
getTokens: async (sessionId, throughTurnId) => {
|
|
159
|
+
const { messages } = await options.readSessionContext(sessionId);
|
|
160
|
+
return tokenCount(messages, throughTurnId);
|
|
161
|
+
},
|
|
162
|
+
gate: (sessionId) => this.continuation.gateEventWait(sessionId),
|
|
163
|
+
canRegister: (sessionId, turnId) => this.continuation.mutationStanding(sessionId, turnId).kind === 'held',
|
|
164
|
+
deliver: (pending) => this.continuation.recoverPendingContinuation(pending),
|
|
165
|
+
pause: (sessionId, reason, controlLease, waitId) => this.#mutateGoal(async () => {
|
|
166
|
+
if (!this.manager.matchesControlLease(sessionId, controlLease) ||
|
|
167
|
+
this.#authorityBySession.get(sessionId)?.record.activeEventWait?.waitId !== waitId)
|
|
168
|
+
return;
|
|
169
|
+
this.manager.pause(sessionId, { reason });
|
|
170
|
+
this.continuation.invalidateSession(sessionId);
|
|
171
|
+
}),
|
|
172
|
+
onError: (error) => {
|
|
173
|
+
this.#persistenceFailure ??= error;
|
|
174
|
+
this.#requestDrain();
|
|
175
|
+
},
|
|
176
|
+
now,
|
|
177
|
+
newId: this.#newId,
|
|
178
|
+
}, options.eventWaitSources);
|
|
179
|
+
}
|
|
180
|
+
this.tools = Object.freeze([
|
|
181
|
+
...buildGoalTools({
|
|
182
|
+
goalManager: this.manager,
|
|
183
|
+
goalContinuation: this.continuation,
|
|
184
|
+
isAvailable: () => !this.#draining,
|
|
185
|
+
// These tool implementations execute inside the same lane as joint writes.
|
|
186
|
+
flush: () => this.#flushGoalPersistence(),
|
|
187
|
+
now,
|
|
188
|
+
}).map((tool) => ({
|
|
189
|
+
...tool,
|
|
190
|
+
impl: (input, context) => this.#mutateGoal(() => tool.impl(input, context)),
|
|
191
|
+
})),
|
|
192
|
+
...(this.eventWaitBridge?.tools ?? []),
|
|
193
|
+
]);
|
|
114
194
|
}
|
|
115
195
|
async prepareRecovery() {
|
|
116
196
|
if (this.#prepared)
|
|
@@ -167,10 +247,128 @@ export class HostGoalCoordinator {
|
|
|
167
247
|
this.continuation.recoverActiveGoal(snapshot.record.goal.sessionId);
|
|
168
248
|
}
|
|
169
249
|
}
|
|
250
|
+
await this.eventWaitBridge?.start();
|
|
170
251
|
}
|
|
171
252
|
readProjection(sessionId) {
|
|
253
|
+
// Canonical/query callers hold the Session lane. Do not wait for the
|
|
254
|
+
// mutation lane here: a committed wait write can have a delayed receipt
|
|
255
|
+
// while Root admission must still publish and start. #project rechecks the
|
|
256
|
+
// adopted binding after I/O and excludes durably admitted/suppressed waits.
|
|
257
|
+
return this.#project(sessionId);
|
|
258
|
+
}
|
|
259
|
+
async #project(sessionId) {
|
|
260
|
+
const authority = this.#authorityBySession.get(sessionId);
|
|
261
|
+
const gate = authority?.record.activeEventWait;
|
|
262
|
+
const wait = gate && this.#stores.eventWaitStore
|
|
263
|
+
? await this.#stores.eventWaitStore.read({ sessionId, waitId: gate.waitId })
|
|
264
|
+
: undefined;
|
|
172
265
|
const goal = this.manager.get(sessionId);
|
|
173
|
-
|
|
266
|
+
if (!goal)
|
|
267
|
+
return null;
|
|
268
|
+
const projection = projectGoalState(goal);
|
|
269
|
+
const current = this.#authorityBySession.get(sessionId);
|
|
270
|
+
if (!wait ||
|
|
271
|
+
!gate ||
|
|
272
|
+
!current ||
|
|
273
|
+
current.record.activeEventWait?.waitId !== gate.waitId ||
|
|
274
|
+
!sameGoalControlLease(current.record.controlLease, wait.record.goalControlLease) ||
|
|
275
|
+
!this.manager.matchesControlLease(sessionId, wait.record.goalControlLease) ||
|
|
276
|
+
wait.record.delivery ||
|
|
277
|
+
wait.record.status === 'cancelled' ||
|
|
278
|
+
!['active', 'waiting'].includes(goal.status))
|
|
279
|
+
return projection;
|
|
280
|
+
const r = wait.record, observation = r.observation;
|
|
281
|
+
// Checking is an attempt reservation, not a new source fact. Its retained
|
|
282
|
+
// checkpoint describes the last completed observation until this read settles.
|
|
283
|
+
const observationOutcome = observation?.outcome === 'checking' && observation.lastObservedAt !== null
|
|
284
|
+
? observation.consecutiveErrors > 0
|
|
285
|
+
? 'unknown'
|
|
286
|
+
: 'pending'
|
|
287
|
+
: observation?.outcome;
|
|
288
|
+
return {
|
|
289
|
+
...projection,
|
|
290
|
+
eventWait: {
|
|
291
|
+
waitId: r.waitId,
|
|
292
|
+
controlGeneration: r.goalControlLease.generation,
|
|
293
|
+
waitRevision: wait.authorityRevision,
|
|
294
|
+
resource: {
|
|
295
|
+
providerId: r.resource.providerId,
|
|
296
|
+
resourceType: r.resource.resourceType,
|
|
297
|
+
resourceId: truncateUtf8(r.resource.resourceId, GOAL_EVENT_WAIT_SUMMARY_LIMITS.resourceIdBytes, '…'),
|
|
298
|
+
},
|
|
299
|
+
reason: gate.reason,
|
|
300
|
+
deadlineAt: r.deadlineAt,
|
|
301
|
+
phase: r.status === 'waiting' ? 'observing' : 'awaiting_admission',
|
|
302
|
+
observation: r.status !== 'waiting'
|
|
303
|
+
? null
|
|
304
|
+
: {
|
|
305
|
+
state: observationOutcome === 'unknown'
|
|
306
|
+
? 'unknown'
|
|
307
|
+
: observationOutcome === 'pending'
|
|
308
|
+
? 'pending'
|
|
309
|
+
: 'checking',
|
|
310
|
+
lastObservedAt: observation?.lastObservedAt ?? null,
|
|
311
|
+
reasonCode: observation?.reason
|
|
312
|
+
? truncateUtf8(observation.reason, GOAL_EVENT_WAIT_SUMMARY_LIMITS.reasonCodeBytes, '…')
|
|
313
|
+
: null,
|
|
314
|
+
},
|
|
315
|
+
outcome: r.status === 'resolved'
|
|
316
|
+
? r.resolution.outcome
|
|
317
|
+
: r.status === 'expired'
|
|
318
|
+
? 'expired'
|
|
319
|
+
: null,
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
#cancelEventWait(input) {
|
|
324
|
+
return this.#sessionAdmission.run(input.sessionId, () => this.#mutateGoal(async () => {
|
|
325
|
+
if (this.#draining)
|
|
326
|
+
return hostDraining();
|
|
327
|
+
let header;
|
|
328
|
+
try {
|
|
329
|
+
header = await this.#stores.sessionStore.readHeaderSnapshot(input.sessionId);
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
if (isSessionNotFoundError(error))
|
|
333
|
+
return notFound('Session does not exist');
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
if (header.isArchived)
|
|
337
|
+
return sessionArchived('Archived Session cannot cancel a wait');
|
|
338
|
+
const wait = await this.#stores.eventWaitStore?.read({
|
|
339
|
+
sessionId: input.sessionId,
|
|
340
|
+
waitId: input.waitId,
|
|
341
|
+
});
|
|
342
|
+
const current = this.#authorityBySession.get(input.sessionId)?.record;
|
|
343
|
+
let outcome = 'conflict';
|
|
344
|
+
if (wait?.record.goalControlLease.goalId === input.goalId &&
|
|
345
|
+
wait.record.goalControlLease.generation === input.controlGeneration) {
|
|
346
|
+
if (wait.record.delivery?.kind === 'admitted')
|
|
347
|
+
outcome = 'already_admitted';
|
|
348
|
+
else if (wait.record.status === 'cancelled' ||
|
|
349
|
+
wait.record.delivery?.kind === 'suppressed')
|
|
350
|
+
outcome = 'already_cancelled';
|
|
351
|
+
else if (current?.activeEventWait?.waitId === input.waitId &&
|
|
352
|
+
current.goal.id === input.goalId &&
|
|
353
|
+
current.controlLease.generation === input.controlGeneration &&
|
|
354
|
+
current.goal.revision === input.expectedGoalRevision) {
|
|
355
|
+
this.manager.pause(input.sessionId, {
|
|
356
|
+
reason: 'Event wait cancelled. The background task keeps running.',
|
|
357
|
+
});
|
|
358
|
+
this.continuation.invalidateSession(input.sessionId);
|
|
359
|
+
await this.#flushGoalPersistence();
|
|
360
|
+
outcome = 'cancelled';
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
ok: true,
|
|
365
|
+
result: {
|
|
366
|
+
sessionId: input.sessionId,
|
|
367
|
+
outcome,
|
|
368
|
+
goal: await this.#project(input.sessionId),
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
}));
|
|
174
372
|
}
|
|
175
373
|
beginObservedTurn(sessionId, turnId) {
|
|
176
374
|
return this.continuation.beginObservedTurn(sessionId, turnId);
|
|
@@ -284,6 +482,7 @@ export class HostGoalCoordinator {
|
|
|
284
482
|
return;
|
|
285
483
|
this.#draining = true;
|
|
286
484
|
this.#recoveryAbort.abort();
|
|
485
|
+
this.eventWaitBridge?.beginDrain();
|
|
287
486
|
this.continuation.dispose();
|
|
288
487
|
this.manager.dispose();
|
|
289
488
|
this.#tokenCache.clear();
|
|
@@ -295,6 +494,8 @@ export class HostGoalCoordinator {
|
|
|
295
494
|
this.beginDrain();
|
|
296
495
|
return Promise.all([
|
|
297
496
|
this.continuation.close(),
|
|
497
|
+
this.eventWaitBridge?.close(),
|
|
498
|
+
this.#jointLane,
|
|
298
499
|
this.#flushGoalState(),
|
|
299
500
|
...this.#recoveryWaits,
|
|
300
501
|
]).then(() => undefined);
|
|
@@ -312,7 +513,7 @@ export class HostGoalCoordinator {
|
|
|
312
513
|
}
|
|
313
514
|
return {
|
|
314
515
|
ok: true,
|
|
315
|
-
result: { sessionId, goal: this.readProjection(sessionId) },
|
|
516
|
+
result: { sessionId, goal: await this.readProjection(sessionId) },
|
|
316
517
|
};
|
|
317
518
|
});
|
|
318
519
|
}
|
|
@@ -330,7 +531,7 @@ export class HostGoalCoordinator {
|
|
|
330
531
|
* after it is the first the Goal drives.
|
|
331
532
|
*/
|
|
332
533
|
#arm(input) {
|
|
333
|
-
return this.#sessionAdmission.run(input.sessionId, async () => {
|
|
534
|
+
return this.#sessionAdmission.run(input.sessionId, () => this.#mutateGoal(async () => {
|
|
334
535
|
// Admission is a queue, and the composition begins to drain without
|
|
335
536
|
// waiting for it to empty. An arm let through before that can still be
|
|
336
537
|
// waiting behind another operation when the Goal manager is disposed,
|
|
@@ -358,15 +559,14 @@ export class HostGoalCoordinator {
|
|
|
358
559
|
if (created.kind === 'unfinished') {
|
|
359
560
|
return operationConflict(`Session already has an unfinished Goal in status ${created.goal.status}`);
|
|
360
561
|
}
|
|
361
|
-
await this.#flushGoalState(input.sessionId);
|
|
362
562
|
return {
|
|
363
563
|
ok: true,
|
|
364
564
|
result: { sessionId: input.sessionId, goal: projectGoalState(created.goal) },
|
|
365
565
|
};
|
|
366
|
-
});
|
|
566
|
+
}));
|
|
367
567
|
}
|
|
368
568
|
#control(input) {
|
|
369
|
-
return this.#sessionAdmission.run(input.sessionId, async () => {
|
|
569
|
+
return this.#sessionAdmission.run(input.sessionId, () => this.#mutateGoal(async () => {
|
|
370
570
|
let header;
|
|
371
571
|
try {
|
|
372
572
|
header = await this.#stores.sessionStore.readHeaderSnapshot(input.sessionId);
|
|
@@ -405,28 +605,43 @@ export class HostGoalCoordinator {
|
|
|
405
605
|
if (!changed) {
|
|
406
606
|
return operationConflict(`Goal cannot ${input.action} from status ${current.status}`);
|
|
407
607
|
}
|
|
408
|
-
await this.#flushGoalState(input.sessionId);
|
|
409
608
|
return {
|
|
410
609
|
ok: true,
|
|
411
610
|
result: { sessionId: input.sessionId, goal: projectGoalState(changed) },
|
|
412
611
|
};
|
|
413
|
-
});
|
|
612
|
+
}));
|
|
414
613
|
}
|
|
415
614
|
#enqueueGoalState(goal, controlLease) {
|
|
615
|
+
if (this.#jointBusy) {
|
|
616
|
+
this.#deferredGoalChanges.push([goal, controlLease]);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
416
619
|
const current = this.#authorityBySession.get(goal.sessionId);
|
|
417
620
|
this.#enqueueAuthorityCommit(goal.sessionId, {
|
|
418
621
|
schemaVersion: 1,
|
|
419
622
|
goal,
|
|
420
623
|
controlLease,
|
|
624
|
+
...(current?.record.activeEventWait &&
|
|
625
|
+
sameGoalControlLease(current.record.controlLease, controlLease) &&
|
|
626
|
+
['active', 'waiting'].includes(goal.status)
|
|
627
|
+
? { activeEventWait: current.record.activeEventWait }
|
|
628
|
+
: {}),
|
|
421
629
|
currentExecution: current?.record.goal.id === goal.id && goal.revision >= current.record.goal.revision
|
|
422
630
|
? current.record.currentExecution
|
|
423
631
|
: null,
|
|
424
|
-
pendingContinuation: current?.record.goal.id === goal.id &&
|
|
425
|
-
|
|
632
|
+
pendingContinuation: current?.record.goal.id === goal.id &&
|
|
633
|
+
sameGoalControlLease(current.record.controlLease, controlLease) &&
|
|
634
|
+
['active', 'waiting'].includes(goal.status) &&
|
|
635
|
+
current.record.pendingContinuation &&
|
|
636
|
+
(goal.revision === current.record.goal.revision || current.record.activeEventWait)
|
|
637
|
+
? {
|
|
638
|
+
...current.record.pendingContinuation,
|
|
639
|
+
checkpoint: { goalId: goal.id, revision: goal.revision },
|
|
640
|
+
}
|
|
426
641
|
: null,
|
|
427
642
|
});
|
|
428
643
|
}
|
|
429
|
-
async #recordPendingContinuation(pending) {
|
|
644
|
+
async #recordPendingContinuation(pending, flush = () => this.#flushGoalState()) {
|
|
430
645
|
const sessionId = this.manager.getSessionIdByGoalId(pending.checkpoint.goalId);
|
|
431
646
|
const authority = sessionId ? this.#authorityBySession.get(sessionId) : undefined;
|
|
432
647
|
if (!authority ||
|
|
@@ -440,34 +655,36 @@ export class HostGoalCoordinator {
|
|
|
440
655
|
currentExecution: null,
|
|
441
656
|
pendingContinuation: pending,
|
|
442
657
|
});
|
|
443
|
-
await
|
|
658
|
+
await flush();
|
|
444
659
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
!
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
660
|
+
#clearPendingContinuation(sessionId, controlLease) {
|
|
661
|
+
return this.#mutateGoal(() => {
|
|
662
|
+
const authority = this.#authorityBySession.get(sessionId);
|
|
663
|
+
if (!authority ||
|
|
664
|
+
!sameGoalControlLease(authority.record.controlLease, controlLease) ||
|
|
665
|
+
!authority.record.pendingContinuation) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
this.#enqueueAuthorityCommit(sessionId, {
|
|
669
|
+
...authority.record,
|
|
670
|
+
pendingContinuation: null,
|
|
671
|
+
});
|
|
455
672
|
});
|
|
456
|
-
await this.#flushGoalState(sessionId);
|
|
457
673
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
authority
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
674
|
+
#recordCurrentExecution(current) {
|
|
675
|
+
return this.#mutateGoal(() => {
|
|
676
|
+
const authority = this.#authorityBySession.get(current.execution.sessionId);
|
|
677
|
+
if (!authority ||
|
|
678
|
+
authority.record.goal.id !== current.checkpoint.goalId ||
|
|
679
|
+
!sameGoalControlLease(authority.record.controlLease, current.controlLease)) {
|
|
680
|
+
throw new Error('Goal execution no longer matches its durable authority');
|
|
681
|
+
}
|
|
682
|
+
this.#enqueueAuthorityCommit(current.execution.sessionId, {
|
|
683
|
+
...authority.record,
|
|
684
|
+
currentExecution: current,
|
|
685
|
+
pendingContinuation: null,
|
|
686
|
+
});
|
|
469
687
|
});
|
|
470
|
-
await this.#flushGoalState(current.execution.sessionId);
|
|
471
688
|
}
|
|
472
689
|
async #recoverCurrentExecution(current) {
|
|
473
690
|
const durableAdmission = await this.#stores.agentRunStore.readRootTurnAdmission(current.execution.sessionId, current.execution.turnId);
|
|
@@ -504,15 +721,18 @@ export class HostGoalCoordinator {
|
|
|
504
721
|
.finally(() => this.#recoveryWaits.delete(tracked));
|
|
505
722
|
this.#recoveryWaits.add(tracked);
|
|
506
723
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
724
|
+
#settleCurrentExecution(sessionId, turnId) {
|
|
725
|
+
return this.#mutateGoal(() => {
|
|
726
|
+
// A revoked registration can finish while a new wait commit is awaiting acknowledgement.
|
|
727
|
+
// Read the adopted authority inside the lane before clearing this Turn's ownership.
|
|
728
|
+
const authority = this.#authorityBySession.get(sessionId);
|
|
729
|
+
if (!authority || authority.record.currentExecution?.execution.turnId !== turnId)
|
|
730
|
+
return;
|
|
731
|
+
this.#enqueueAuthorityCommit(sessionId, {
|
|
732
|
+
...authority.record,
|
|
733
|
+
currentExecution: null,
|
|
734
|
+
});
|
|
514
735
|
});
|
|
515
|
-
await this.#flushGoalState(sessionId);
|
|
516
736
|
}
|
|
517
737
|
#enqueueAuthorityCommit(sessionId, record) {
|
|
518
738
|
const current = this.#authorityBySession.get(sessionId);
|
|
@@ -595,6 +815,56 @@ export class HostGoalCoordinator {
|
|
|
595
815
|
})
|
|
596
816
|
.finally(() => residency.release());
|
|
597
817
|
}
|
|
818
|
+
#mutateGoal(operation) {
|
|
819
|
+
const task = this.#jointLane.then(async () => {
|
|
820
|
+
await this.#flushGoalPersistence();
|
|
821
|
+
const result = await operation();
|
|
822
|
+
await this.#flushGoalPersistence();
|
|
823
|
+
return result;
|
|
824
|
+
});
|
|
825
|
+
this.#jointLane = task.catch(() => undefined);
|
|
826
|
+
return task;
|
|
827
|
+
}
|
|
828
|
+
#mutateWait(sessionId, operation) {
|
|
829
|
+
const task = this.#jointLane.then(async () => {
|
|
830
|
+
this.#jointBusy = true;
|
|
831
|
+
try {
|
|
832
|
+
// This task owns the joint lane; only prior ordinary writes can be awaited here.
|
|
833
|
+
await this.#flushGoalPersistence();
|
|
834
|
+
const result = await operation();
|
|
835
|
+
this.#adoptWaitAuthority(result.goal);
|
|
836
|
+
return result;
|
|
837
|
+
}
|
|
838
|
+
finally {
|
|
839
|
+
this.#jointBusy = false;
|
|
840
|
+
for (const [goal, lease] of this.#deferredGoalChanges.splice(0))
|
|
841
|
+
this.#enqueueGoalState(goal, lease);
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
this.#jointLane = task.catch(() => undefined);
|
|
845
|
+
return task;
|
|
846
|
+
}
|
|
847
|
+
#adoptWaitAuthority(snapshot) {
|
|
848
|
+
const current = this.#authorityBySession.get(snapshot.record.goal.sessionId);
|
|
849
|
+
// Root admission may commit while an idempotent queue operation is returning.
|
|
850
|
+
if (current && current.authorityRevision > snapshot.authorityRevision)
|
|
851
|
+
return;
|
|
852
|
+
this.#authorityBySession.set(snapshot.record.goal.sessionId, snapshot);
|
|
853
|
+
// A control operation may have changed the live manager while I/O was pending.
|
|
854
|
+
if (!this.#deferredGoalChanges.some(([g]) => g.sessionId === snapshot.record.goal.sessionId)) {
|
|
855
|
+
this.manager.adoptAuthority(snapshot.record.goal, snapshot.record.controlLease);
|
|
856
|
+
this.#syncResidency(snapshot.record.goal, this.#acquireResidency);
|
|
857
|
+
}
|
|
858
|
+
this.#onProjectionChanged(snapshot.record.goal.sessionId);
|
|
859
|
+
}
|
|
860
|
+
async admitted(input) {
|
|
861
|
+
if (input.descriptor.kind !== 'goal' || !input.descriptor.eventWait)
|
|
862
|
+
return;
|
|
863
|
+
const snapshot = await this.#store.read(input.sessionId);
|
|
864
|
+
if (!snapshot)
|
|
865
|
+
throw new Error('Admitted event wait lost Goal authority');
|
|
866
|
+
this.#adoptWaitAuthority(snapshot);
|
|
867
|
+
}
|
|
598
868
|
async #deleteOrphanedAuthority(snapshot) {
|
|
599
869
|
const result = await this.#store.commit({
|
|
600
870
|
sessionId: snapshot.record.goal.sessionId,
|
|
@@ -606,6 +876,12 @@ export class HostGoalCoordinator {
|
|
|
606
876
|
}
|
|
607
877
|
}
|
|
608
878
|
async #flushGoalState(_sessionId) {
|
|
879
|
+
// A control change made during a joint operation is enqueued in its finally block.
|
|
880
|
+
// Acknowledge it only after that operation and the resulting ordinary write finish.
|
|
881
|
+
await this.#jointLane;
|
|
882
|
+
await this.#flushGoalPersistence();
|
|
883
|
+
}
|
|
884
|
+
async #flushGoalPersistence() {
|
|
609
885
|
await this.#persistenceLane;
|
|
610
886
|
if (this.#persistenceFailure !== undefined)
|
|
611
887
|
throw this.#persistenceFailure;
|
|
@@ -621,8 +897,22 @@ export class HostGoalCoordinator {
|
|
|
621
897
|
this.#residencies.delete(goal.sessionId);
|
|
622
898
|
}
|
|
623
899
|
}
|
|
624
|
-
function tokenCount(messages) {
|
|
625
|
-
|
|
900
|
+
function tokenCount(messages, throughTurnId) {
|
|
901
|
+
// Root admission can release the Session before Goal settlement reads its facts.
|
|
902
|
+
// Keep later user Turns out of this Turn's baseline, including when the wait
|
|
903
|
+
// source spans multiple physical Runs through handoff.
|
|
904
|
+
let end = messages.length;
|
|
905
|
+
if (throughTurnId !== undefined) {
|
|
906
|
+
while (end > 0) {
|
|
907
|
+
const message = messages[end - 1];
|
|
908
|
+
if ('turnId' in message && message.turnId === throughTurnId)
|
|
909
|
+
break;
|
|
910
|
+
end--;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (throughTurnId !== undefined && end === 0)
|
|
914
|
+
throw new Error('Completed Goal Turn is missing from token accounting facts');
|
|
915
|
+
return messages.slice(0, end).reduce((total, message) => {
|
|
626
916
|
if (message.type !== 'token_usage')
|
|
627
917
|
return total;
|
|
628
918
|
return total + (message.total ?? message.input + message.output);
|