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
|
@@ -25,6 +25,7 @@ import { CONTEXT_OFFLOAD_ID_MAX_CODE_POINTS, } from '@maka/core/context-offload'
|
|
|
25
25
|
import { configureSqliteContextOffloadDatabase, migrateSqliteContextOffloadDatabase, } from './sqlite-context-offload-schema.js';
|
|
26
26
|
import { readStableBoundedFile, syncDirectory, syncDirectoryChain, syncFile, } from './stable-storage.js';
|
|
27
27
|
import { runWithContextValueMutation } from './context-value-mutation-gate.js';
|
|
28
|
+
import { SqliteReclamationCheckpoint } from './sqlite-reclamation-checkpoint.js';
|
|
28
29
|
const MAX_MEDIA_TYPE_CODE_POINTS = 256;
|
|
29
30
|
const SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
30
31
|
const MANAGED_FILE_LOCATOR_PATTERN = /^sha256\/([0-9a-f]{2})\/([0-9a-f]{64})$/;
|
|
@@ -42,6 +43,7 @@ export class SqliteContextOffloadStore {
|
|
|
42
43
|
#storageRoot;
|
|
43
44
|
#valueRoot;
|
|
44
45
|
#mutationGateKey;
|
|
46
|
+
#reclamationCheckpoint = new SqliteReclamationCheckpoint();
|
|
45
47
|
#closed = false;
|
|
46
48
|
constructor(path, options) {
|
|
47
49
|
if (!path)
|
|
@@ -359,6 +361,7 @@ export class SqliteContextOffloadStore {
|
|
|
359
361
|
this.#assertOpen();
|
|
360
362
|
// Probe under a read transaction so an idle tick never takes the write lock.
|
|
361
363
|
if (this.#readTransaction(() => this.#freelistPages()) === 0) {
|
|
364
|
+
this.#reclamationCheckpoint.run(this.#database, 0);
|
|
362
365
|
return { reclaimedPages: 0, hasMore: false };
|
|
363
366
|
}
|
|
364
367
|
const result = this.#writeTransaction(() => {
|
|
@@ -372,8 +375,7 @@ export class SqliteContextOffloadStore {
|
|
|
372
375
|
return { reclaimedPages: before - after, hasMore: after > 0 && after < before };
|
|
373
376
|
});
|
|
374
377
|
// PASSIVE never waits on readers; it moves the shrink into the main file.
|
|
375
|
-
|
|
376
|
-
this.#database.exec('PRAGMA wal_checkpoint(PASSIVE)');
|
|
378
|
+
this.#reclamationCheckpoint.run(this.#database, result.reclaimedPages);
|
|
377
379
|
return result;
|
|
378
380
|
}
|
|
379
381
|
#freelistPages() {
|
|
@@ -16,15 +16,34 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { registerGoalWait, readGoalWaitRootExecution, readCompletedGoalWaitExecution, settleGoalWait, queueGoalWait, } from './event-wait-bridge.js';
|
|
20
|
+
import { readBridgeGoal, readBridgeWait, readBridgeTermination, writeBridgeSnapshot, assertBridgeSession, } from './sqlite-event-wait-bridge.js';
|
|
21
|
+
import { createWorkspaceRuntimeStore } from './runtime-event-persistence.js';
|
|
22
|
+
import { normalizeRootTurnAdmission } from './agent-run-store-contract.js';
|
|
19
23
|
import { isDeepStrictEqual } from 'node:util';
|
|
20
24
|
import { assertEventWaitTransition, decodeEventWaitRecord, EVENT_WAIT_LIMITS, } from '@maka/core/event-wait';
|
|
21
25
|
import { eventWaitPage, eventWaitSourceKey, EVENT_WAIT_PAGE_LIMIT, normalizeEventWaitCommit, validateEventWaitPage, validateEventWaitRead, validateEventWaitStatusPage, validateEventWaitObservationList, validateEventWaitSource, validateEventWaitSourceCooldown, validateEventWaitSourceDispatch, } from './event-wait-authority.js';
|
|
22
26
|
import { acquireOperationalStateDatabase, } from './operational-state-store.js';
|
|
23
27
|
class SqliteEventWaitAuthority {
|
|
24
28
|
#database;
|
|
29
|
+
#runtime;
|
|
30
|
+
#closeRuntime;
|
|
25
31
|
#closed = false;
|
|
26
|
-
constructor(root) {
|
|
32
|
+
constructor(root, runtime) {
|
|
27
33
|
this.#database = acquireOperationalStateDatabase(root);
|
|
34
|
+
try {
|
|
35
|
+
if (runtime)
|
|
36
|
+
this.#runtime = runtime;
|
|
37
|
+
else {
|
|
38
|
+
const owned = createWorkspaceRuntimeStore(root);
|
|
39
|
+
this.#runtime = owned;
|
|
40
|
+
this.#closeRuntime = () => owned.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.#database.close();
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
28
47
|
}
|
|
29
48
|
#assertOpen() {
|
|
30
49
|
if (this.#closed)
|
|
@@ -52,7 +71,7 @@ class SqliteEventWaitAuthority {
|
|
|
52
71
|
this.#assertOpen();
|
|
53
72
|
validateEventWaitPage(input);
|
|
54
73
|
return this.#database.transaction('read', () => eventWaitPage(this.#database.database
|
|
55
|
-
.prepare("SELECT * FROM workflow_event_waits WHERE status IN ('waiting', 'resolved') AND wait_id > ? ORDER BY wait_id LIMIT ?")
|
|
74
|
+
.prepare("SELECT * FROM workflow_event_waits WHERE status IN ('waiting', 'resolved') AND json_extract(record_json, '$.delivery') IS NULL AND wait_id > ? ORDER BY wait_id LIMIT ?")
|
|
56
75
|
.all(input.afterWaitId ?? '', input.limit + 1)
|
|
57
76
|
.map(readRow), input.limit));
|
|
58
77
|
}
|
|
@@ -60,7 +79,7 @@ class SqliteEventWaitAuthority {
|
|
|
60
79
|
this.#assertOpen();
|
|
61
80
|
validateEventWaitStatusPage(input);
|
|
62
81
|
return this.#database.transaction('read', () => eventWaitPage(this.#database.database
|
|
63
|
-
.prepare(
|
|
82
|
+
.prepare(`SELECT * FROM workflow_event_waits WHERE status = ? ${input.deliveryOutstanding ? "AND json_extract(record_json, '$.delivery') IS NULL" : ''} AND wait_id > ? ORDER BY wait_id LIMIT ?`)
|
|
64
83
|
.all(input.status, input.afterWaitId ?? '', input.limit + 1)
|
|
65
84
|
.map(readRow), input.limit));
|
|
66
85
|
}
|
|
@@ -193,15 +212,18 @@ class SqliteEventWaitAuthority {
|
|
|
193
212
|
actualAuthorityRevision: current?.authorityRevision ?? null,
|
|
194
213
|
};
|
|
195
214
|
if (current) {
|
|
215
|
+
if (!isDeepStrictEqual(current.record.delivery, input.record.delivery))
|
|
216
|
+
throw new Error('Delivery requires joint Goal admission');
|
|
196
217
|
assertEventWaitTransition(current.record, input.record);
|
|
197
218
|
if (isDeepStrictEqual(current.record, input.record))
|
|
198
219
|
return { kind: 'committed', snapshot: current };
|
|
199
220
|
}
|
|
200
221
|
else if (input.record.status !== 'waiting')
|
|
201
222
|
throw new TypeError('Event waits must be created waiting');
|
|
202
|
-
if (input.record.
|
|
223
|
+
if (!input.record.delivery &&
|
|
224
|
+
(input.record.status === 'waiting' || input.record.status === 'resolved')) {
|
|
203
225
|
const other = db
|
|
204
|
-
.prepare("SELECT wait_id FROM workflow_event_waits WHERE session_id = ? AND status IN ('waiting', 'resolved') AND wait_id <> ?")
|
|
226
|
+
.prepare("SELECT wait_id FROM workflow_event_waits WHERE session_id = ? AND status IN ('waiting', 'resolved') AND json_extract(record_json, '$.delivery') IS NULL AND wait_id <> ?")
|
|
205
227
|
.get(input.sessionId, input.waitId);
|
|
206
228
|
if (other)
|
|
207
229
|
return { kind: 'active_wait_conflict', waitId: String(other.wait_id) };
|
|
@@ -216,13 +238,64 @@ class SqliteEventWaitAuthority {
|
|
|
216
238
|
return { kind: 'committed', snapshot: { authorityRevision, record: r } };
|
|
217
239
|
});
|
|
218
240
|
}
|
|
241
|
+
async registerGoalWait(input) {
|
|
242
|
+
this.#assertOpen();
|
|
243
|
+
const r = input.record;
|
|
244
|
+
const readSource = () => {
|
|
245
|
+
const row = this.#database.database
|
|
246
|
+
.prepare('SELECT record_json FROM core_root_turn_admissions WHERE session_id = ? AND turn_id = ?')
|
|
247
|
+
.get(r.sessionId, r.sourceTurnId);
|
|
248
|
+
return row
|
|
249
|
+
? normalizeRootTurnAdmission(JSON.parse(String(row.record_json)), r.sessionId, r.sourceTurnId)
|
|
250
|
+
: undefined;
|
|
251
|
+
};
|
|
252
|
+
const logicalSource = await readGoalWaitRootExecution(this.#runtime, input, this.#database.transaction('read', readSource));
|
|
253
|
+
const completedExecution = await readCompletedGoalWaitExecution(this.#runtime, this.#database.transaction('read', () => readBridgeGoal(this.#database.database, r.sessionId)?.record.currentExecution), logicalSource);
|
|
254
|
+
this.#assertOpen();
|
|
255
|
+
return this.#database.transaction('write', () => {
|
|
256
|
+
const db = this.#database.database;
|
|
257
|
+
assertBridgeSession(db, r.sessionId);
|
|
258
|
+
const old = readBridgeWait(db, r.sessionId, r.waitId);
|
|
259
|
+
if (!old &&
|
|
260
|
+
db
|
|
261
|
+
.prepare("SELECT 1 FROM runtime_events WHERE session_id = ? AND run_id = ? AND (json_extract(payload_json, '$.actions.endInvocation') = 1 OR json_extract(payload_json, '$.status') IN ('completed', 'failed', 'cancelled', 'aborted')) LIMIT 1")
|
|
262
|
+
.get(r.sessionId, input.sourceExecution.runId))
|
|
263
|
+
throw new Error('Source already ended');
|
|
264
|
+
return writeBridgeSnapshot(db, registerGoalWait(input, readBridgeGoal(db, r.sessionId), old, readSource(), logicalSource, completedExecution));
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
settleGoalWait(input) {
|
|
268
|
+
return this.#updateGoalWait(input, 'settle');
|
|
269
|
+
}
|
|
270
|
+
queueGoalWait(input) {
|
|
271
|
+
return this.#updateGoalWait(input, 'queue');
|
|
272
|
+
}
|
|
273
|
+
#updateGoalWait(input, operation) {
|
|
274
|
+
this.#assertOpen();
|
|
275
|
+
return this.#database.transaction('write', () => {
|
|
276
|
+
const db = this.#database.database;
|
|
277
|
+
assertBridgeSession(db, input.sessionId);
|
|
278
|
+
const goal = readBridgeGoal(db, input.sessionId), wait = readBridgeWait(db, input.sessionId, input.waitId);
|
|
279
|
+
if (!wait || !goal?.record.activeEventWait)
|
|
280
|
+
throw new Error('Wait gate missing');
|
|
281
|
+
const events = readBridgeTermination(db, input.sessionId, goal.record.activeEventWait.sourceExecution.runId);
|
|
282
|
+
return writeBridgeSnapshot(db, operation === 'settle'
|
|
283
|
+
? settleGoalWait(input, goal, wait, events)
|
|
284
|
+
: queueGoalWait(input, goal, wait, events));
|
|
285
|
+
});
|
|
286
|
+
}
|
|
219
287
|
close() {
|
|
220
288
|
this.#closed = true;
|
|
221
|
-
|
|
289
|
+
try {
|
|
290
|
+
this.#closeRuntime?.();
|
|
291
|
+
}
|
|
292
|
+
finally {
|
|
293
|
+
this.#database.close();
|
|
294
|
+
}
|
|
222
295
|
}
|
|
223
296
|
}
|
|
224
|
-
export function createSqliteEventWaitAuthority(root) {
|
|
225
|
-
return new SqliteEventWaitAuthority(root);
|
|
297
|
+
export function createSqliteEventWaitAuthority(root, runtime) {
|
|
298
|
+
return new SqliteEventWaitAuthority(root, runtime);
|
|
226
299
|
}
|
|
227
300
|
function readRow(value) {
|
|
228
301
|
if (!value || typeof value !== 'object')
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { decodeGoalAuthorityRecord } from '@maka/core/goal';
|
|
20
|
+
import { decodeEventWaitRecord } from '@maka/core/event-wait';
|
|
21
|
+
import { suppressGoalWait } from './event-wait-bridge.js';
|
|
22
|
+
export function readBridgeGoal(db, sessionId) {
|
|
23
|
+
const row = db
|
|
24
|
+
.prepare('SELECT * FROM workflow_goal_authority WHERE session_id = ?')
|
|
25
|
+
.get(sessionId);
|
|
26
|
+
if (!row)
|
|
27
|
+
return null;
|
|
28
|
+
const record = decodeGoalAuthorityRecord(JSON.parse(String(row.record_json)));
|
|
29
|
+
if (record.goal.sessionId !== sessionId ||
|
|
30
|
+
row.goal_id !== record.goal.id ||
|
|
31
|
+
row.goal_revision !== record.goal.revision ||
|
|
32
|
+
row.status !== record.goal.status ||
|
|
33
|
+
typeof row.authority_revision !== 'number' ||
|
|
34
|
+
!Number.isSafeInteger(row.authority_revision) ||
|
|
35
|
+
row.authority_revision < 0)
|
|
36
|
+
throw new Error('Corrupt Goal authority');
|
|
37
|
+
return { authorityRevision: row.authority_revision, record };
|
|
38
|
+
}
|
|
39
|
+
export function readBridgeWait(db, sessionId, waitId) {
|
|
40
|
+
const row = db.prepare('SELECT * FROM workflow_event_waits WHERE wait_id = ?').get(waitId);
|
|
41
|
+
if (!row)
|
|
42
|
+
return null;
|
|
43
|
+
const record = decodeEventWaitRecord(JSON.parse(String(row.record_json)));
|
|
44
|
+
if (record.sessionId !== sessionId ||
|
|
45
|
+
row.session_id !== sessionId ||
|
|
46
|
+
record.waitId !== waitId ||
|
|
47
|
+
row.status !== record.status ||
|
|
48
|
+
row.delivery_key !== record.deliveryKey ||
|
|
49
|
+
row.deadline_at !== record.deadlineAt ||
|
|
50
|
+
typeof row.authority_revision !== 'number' ||
|
|
51
|
+
!Number.isSafeInteger(row.authority_revision) ||
|
|
52
|
+
row.authority_revision < 0)
|
|
53
|
+
throw new Error('Event wait ownership or indexed authority mismatch');
|
|
54
|
+
return { authorityRevision: row.authority_revision, record };
|
|
55
|
+
}
|
|
56
|
+
export function readBridgeTermination(db, sessionId, runId) {
|
|
57
|
+
return db
|
|
58
|
+
.prepare("SELECT payload_json FROM runtime_events WHERE session_id = ? AND run_id = ? AND json_extract(payload_json, '$.status') IN ('completed', 'failed', 'cancelled', 'aborted') ORDER BY event_seq DESC LIMIT 1")
|
|
59
|
+
.all(sessionId, runId)
|
|
60
|
+
.map((row) => JSON.parse(String(row.payload_json)));
|
|
61
|
+
}
|
|
62
|
+
export function assertBridgeSession(db, sessionId) {
|
|
63
|
+
if (!db
|
|
64
|
+
.prepare('SELECT 1 FROM session_metadata WHERE session_id = ? AND is_archived = 0 AND NOT EXISTS (SELECT 1 FROM session_metadata_tombstones WHERE session_id = ?)')
|
|
65
|
+
.get(sessionId, sessionId))
|
|
66
|
+
throw new Error('Event wait Session is unavailable');
|
|
67
|
+
}
|
|
68
|
+
export function writeBridgeWait(db, wait) {
|
|
69
|
+
const r = wait.record;
|
|
70
|
+
db.prepare(`INSERT INTO workflow_event_waits(wait_id, session_id, authority_revision, status, delivery_key, deadline_at, record_json) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
71
|
+
ON CONFLICT(wait_id) DO UPDATE SET authority_revision = excluded.authority_revision, status = excluded.status, record_json = excluded.record_json`).run(r.waitId, r.sessionId, wait.authorityRevision, r.status, r.deliveryKey, r.deadlineAt, JSON.stringify(r));
|
|
72
|
+
}
|
|
73
|
+
export function writeBridgeSnapshot(db, snapshot) {
|
|
74
|
+
writeBridgeWait(db, snapshot.wait);
|
|
75
|
+
const { goal, authorityRevision } = {
|
|
76
|
+
goal: snapshot.goal.record,
|
|
77
|
+
authorityRevision: snapshot.goal.authorityRevision,
|
|
78
|
+
};
|
|
79
|
+
db.prepare('UPDATE workflow_goal_authority SET authority_revision = ?, goal_id = ?, goal_revision = ?, status = ?, record_json = ? WHERE session_id = ?').run(authorityRevision, goal.goal.id, goal.goal.revision, goal.goal.status, JSON.stringify(goal), goal.goal.sessionId);
|
|
80
|
+
return snapshot;
|
|
81
|
+
}
|
|
82
|
+
export function suppressPreviousBridgeWait(db, sessionId, next) {
|
|
83
|
+
const old = readBridgeGoal(db, sessionId)?.record;
|
|
84
|
+
const gate = old?.activeEventWait;
|
|
85
|
+
if (!gate ||
|
|
86
|
+
(next?.activeEventWait?.waitId === gate.waitId &&
|
|
87
|
+
next.controlLease.goalId === gate.controlLease.goalId &&
|
|
88
|
+
next.controlLease.generation === gate.controlLease.generation &&
|
|
89
|
+
['active', 'waiting'].includes(next.goal.status)))
|
|
90
|
+
return;
|
|
91
|
+
const wait = readBridgeWait(db, sessionId, gate.waitId);
|
|
92
|
+
if (wait)
|
|
93
|
+
writeBridgeWait(db, suppressGoalWait(wait, Date.now()));
|
|
94
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
/** Retains an unfinished reclamation checkpoint across idle maintenance ticks. */
|
|
20
|
+
export class SqliteReclamationCheckpoint {
|
|
21
|
+
#pending = false;
|
|
22
|
+
run(database, reclaimedPages) {
|
|
23
|
+
if (reclaimedPages > 0)
|
|
24
|
+
this.#pending = true;
|
|
25
|
+
if (!this.#pending)
|
|
26
|
+
return;
|
|
27
|
+
// Call outside transactions. PASSIVE never waits for a reader or writer;
|
|
28
|
+
// completion affects the next idle tick, not the maintenance lane's hasMore.
|
|
29
|
+
const row = database.prepare('PRAGMA wal_checkpoint(PASSIVE)').get();
|
|
30
|
+
if (typeof row?.busy !== 'number' ||
|
|
31
|
+
typeof row.log !== 'number' ||
|
|
32
|
+
typeof row.checkpointed !== 'number') {
|
|
33
|
+
throw new Error('Invalid SQLite wal_checkpoint result');
|
|
34
|
+
}
|
|
35
|
+
this.#pending = row.busy !== 0 || row.checkpointed < row.log;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -902,14 +902,13 @@ export function configureSqliteRuntimeDatabase(db) {
|
|
|
902
902
|
db.exec('PRAGMA synchronous = FULL');
|
|
903
903
|
db.exec('PRAGMA foreign_keys = ON');
|
|
904
904
|
}
|
|
905
|
-
/** Set the reclamation mode before
|
|
906
|
-
export function configureSqliteRuntimeAutoVacuumForNewDatabase(db
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
if (existingSchema?.present === 1)
|
|
905
|
+
/** Set the reclamation mode before an uninitialized database gets its first page. */
|
|
906
|
+
export function configureSqliteRuntimeAutoVacuumForNewDatabase(db) {
|
|
907
|
+
// Another opener may have created the file without initializing its header.
|
|
908
|
+
// File existence cannot tell us whether it still needs this configuration.
|
|
909
|
+
// Preserve initialized databases, including those with no application tables.
|
|
910
|
+
const pages = db.prepare('PRAGMA page_count').get();
|
|
911
|
+
if (pages.page_count !== 0)
|
|
913
912
|
return;
|
|
914
913
|
db.exec('PRAGMA auto_vacuum = INCREMENTAL');
|
|
915
914
|
const configured = db.prepare('PRAGMA auto_vacuum').get();
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { mkdirSync } from 'node:fs';
|
|
20
20
|
import { createRequire } from 'node:module';
|
|
21
21
|
import { dirname } from 'node:path';
|
|
22
22
|
import { isDeepStrictEqual } from 'node:util';
|
|
23
23
|
import { assertHandoffClaimSource } from '@maka/core/runtime-handoff';
|
|
24
24
|
import { buildWorkspaceBaselineAuthorityEvents, buildWorkspaceSuccessorAuthorityEvent, scanWorkspaceBaselineAuthority, WORKSPACE_AUTHORITY_SESSION_ID, WORKSPACE_VERSION_AUTHORITY_CAPABILITY_V1, } from '@maka/core/workspace-version-authority';
|
|
25
25
|
import { decodeRuntimeEvent, decodeRuntimeInvocationOpened, isPartialRuntimeEvent, isTerminalRuntimeEvent, runtimeEventInvocationOpening, } from '@maka/core/runtime-event';
|
|
26
|
-
import { RunSealedError, RUNTIME_CONTINUATION_AUTHORITY_V1,
|
|
26
|
+
import { RunSealedError, RUNTIME_CONTINUATION_AUTHORITY_V1, } from '@maka/core/runtime-event-store';
|
|
27
27
|
import { mayBeTranscriptLedgerInvocationId, } from '@maka/core/runtime-invocation';
|
|
28
28
|
import { stableJsonStringify } from '@maka/core/tool-args-identity';
|
|
29
29
|
import { mergeRuntimePartialSnapshots, groupRuntimePartialSnapshots, compareRuntimePartialSnapshots, partialRuntimeStream, completedPartialRuntimeStreamKey, } from './runtime-partial-values.js';
|
|
@@ -31,8 +31,8 @@ import { assertPreparedInput, assertOutcomeInput, assertPreparedIdentity, assert
|
|
|
31
31
|
import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event';
|
|
32
32
|
import { scanToolLedger, referencedToolOperationIds, ToolLedgerCorruptionError, ToolLedgerRejectionError, validateGenericToolLedgerAppend, validateToolLedgerTransition, } from '@maka/core/tool-ledger-scanner';
|
|
33
33
|
import { buildImmutableRuntimePrefix, buildImmutableRuntimePrefixProof, continuationStartEventMatchesClaim, decodeContinuationClaim, } from '@maka/core/runtime-boundary';
|
|
34
|
-
import {
|
|
35
|
-
import { configureSqliteRuntimeDatabase, configureSqliteRuntimeAutoVacuumForNewDatabase, migrateSqliteRuntimeDatabase, readUserVersion, RUNTIME_RECOVERY_AUTHORITY_CAPABILITY, RUNTIME_RECOVERY_AUTHORITY_CAPABILITY_VERSION, RUNTIME_CONTINUATION_AUTHORITY_CAPABILITY, RUNTIME_CONTINUATION_AUTHORITY_CAPABILITY_VERSION, RUNTIME_WORKSPACE_VERSION_AUTHORITY_CAPABILITY, RUNTIME_WORKSPACE_VERSION_AUTHORITY_CAPABILITY_VERSION, runtimeEventKind, SQLITE_RUNTIME_SCHEMA_VERSION, } from './sqlite-runtime-schema.js';
|
|
34
|
+
import { interpretScannedToolRecovery } from '@maka/core/tool-recovery-bundle';
|
|
35
|
+
import { configureSqliteRuntimeDatabase, configureSqliteRuntimeAutoVacuumForNewDatabase, configureSqliteRuntimeLockWait, migrateSqliteRuntimeDatabase, readUserVersion, RUNTIME_RECOVERY_AUTHORITY_CAPABILITY, RUNTIME_RECOVERY_AUTHORITY_CAPABILITY_VERSION, RUNTIME_CONTINUATION_AUTHORITY_CAPABILITY, RUNTIME_CONTINUATION_AUTHORITY_CAPABILITY_VERSION, RUNTIME_WORKSPACE_VERSION_AUTHORITY_CAPABILITY, RUNTIME_WORKSPACE_VERSION_AUTHORITY_CAPABILITY_VERSION, runtimeEventKind, SQLITE_RUNTIME_SCHEMA_VERSION, } from './sqlite-runtime-schema.js';
|
|
36
36
|
import { registerWorkspaceBaselineAuthorityWriterInternal, } from './workspace-version-authority-internal.js';
|
|
37
37
|
import { assertEvidenceReadBudget, measureEvidenceRows, } from './bounded-evidence.js';
|
|
38
38
|
import { assertFoldedSearchTerm, recallFoldedMatchClause, registerRecallFoldFunction, } from './recall-fold.js';
|
|
@@ -90,7 +90,6 @@ export class SqliteRuntimeStore {
|
|
|
90
90
|
options;
|
|
91
91
|
durability = 'canonical';
|
|
92
92
|
toolBoundaryProtocol = 't1_after_preflight_v1';
|
|
93
|
-
recoveryBundleCapability = TOOL_RECOVERY_BUNDLE_CAPABILITY_V1;
|
|
94
93
|
continuationAuthorityCapability = RUNTIME_CONTINUATION_AUTHORITY_V1;
|
|
95
94
|
workspaceVersionAuthorityCapability = WORKSPACE_VERSION_AUTHORITY_CAPABILITY_V1;
|
|
96
95
|
db;
|
|
@@ -118,7 +117,6 @@ export class SqliteRuntimeStore {
|
|
|
118
117
|
return;
|
|
119
118
|
}
|
|
120
119
|
const DatabaseSync = loadDatabaseSync();
|
|
121
|
-
const databaseExisted = path !== ':memory:' && existsSync(path);
|
|
122
120
|
this.db = options.readOnly
|
|
123
121
|
? new DatabaseSync(path, { readOnly: true })
|
|
124
122
|
: new DatabaseSync(path);
|
|
@@ -131,7 +129,8 @@ export class SqliteRuntimeStore {
|
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
else {
|
|
134
|
-
|
|
132
|
+
configureSqliteRuntimeLockWait(this.db);
|
|
133
|
+
configureSqliteRuntimeAutoVacuumForNewDatabase(this.db);
|
|
135
134
|
configureSqliteRuntimeDatabase(this.db);
|
|
136
135
|
migrateSqliteRuntimeDatabase(this.db);
|
|
137
136
|
}
|
|
@@ -985,6 +984,37 @@ export class SqliteRuntimeStore {
|
|
|
985
984
|
}
|
|
986
985
|
return true;
|
|
987
986
|
}
|
|
987
|
+
async readToolProvenanceEvents(sessionId, runId, toolCallId, budget) {
|
|
988
|
+
assertEvidenceReadBudget(budget);
|
|
989
|
+
assertRuntimeStorageSafeId(sessionId, 'Invalid session id');
|
|
990
|
+
assertRuntimeStorageSafeId(runId, 'Invalid run id');
|
|
991
|
+
return this.readTransaction(() => {
|
|
992
|
+
// Select immutable call/T1/T2 facts only. Unrelated output never consumes the
|
|
993
|
+
// proof budget, and sizes are checked before payloads cross into JavaScript.
|
|
994
|
+
const predicate = `session_id = ? AND run_id = ? AND (
|
|
995
|
+
json_extract(payload_json, '$.content.id') = ? OR
|
|
996
|
+
json_extract(payload_json, '$.refs.toolCallId') = ? OR
|
|
997
|
+
json_extract(payload_json, '$.actions.toolDispatch.providerToolCallId') = ?
|
|
998
|
+
)`;
|
|
999
|
+
const parameters = [sessionId, runId, toolCallId, toolCallId, toolCallId];
|
|
1000
|
+
const rows = this.db
|
|
1001
|
+
.prepare(`SELECT length(CAST(payload_json AS BLOB)) AS stored_bytes
|
|
1002
|
+
FROM runtime_events WHERE ${predicate} ORDER BY event_seq, event_id LIMIT ?`)
|
|
1003
|
+
.all(...parameters, budget.maxRecords + 1);
|
|
1004
|
+
const measurement = measureEvidenceRows(rows, budget, 'Invalid tool provenance measurement');
|
|
1005
|
+
if (!measurement)
|
|
1006
|
+
return { status: 'limit_exceeded' };
|
|
1007
|
+
const facts = this.db
|
|
1008
|
+
.prepare(`SELECT event_id, session_id, invocation_id, run_id, turn_id, payload_json
|
|
1009
|
+
FROM runtime_events WHERE ${predicate} ORDER BY event_seq, event_id LIMIT ?`)
|
|
1010
|
+
.all(...parameters, budget.maxRecords + 1);
|
|
1011
|
+
return {
|
|
1012
|
+
status: 'complete',
|
|
1013
|
+
records: facts.map(decodeRuntimeEventStorageRow),
|
|
1014
|
+
...measurement,
|
|
1015
|
+
};
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
988
1018
|
async readRuntimeEventsBounded(sessionId, runId, budget) {
|
|
989
1019
|
assertEvidenceReadBudget(budget);
|
|
990
1020
|
const rows = this.db
|
|
@@ -2661,71 +2691,6 @@ export class SqliteRuntimeStore {
|
|
|
2661
2691
|
assertOutcomeInput(canonicalInput);
|
|
2662
2692
|
return this.transaction(() => this.commitToolOutcomeSync(canonicalInput));
|
|
2663
2693
|
}
|
|
2664
|
-
async commitToolRecoveryBundle(input) {
|
|
2665
|
-
const canonicalInput = {
|
|
2666
|
-
...input,
|
|
2667
|
-
reconcileRuntimeEvent: canonicalizeRuntimeEventForStorage(input.reconcileRuntimeEvent),
|
|
2668
|
-
...(input.outcomeRuntimeEvent
|
|
2669
|
-
? { outcomeRuntimeEvent: canonicalizeRuntimeEventForStorage(input.outcomeRuntimeEvent) }
|
|
2670
|
-
: {}),
|
|
2671
|
-
decisionRuntimeEvent: canonicalizeRuntimeEventForStorage(input.decisionRuntimeEvent),
|
|
2672
|
-
};
|
|
2673
|
-
assertNoReservedWorkspaceAuthorityAppend(canonicalInput.reconcileRuntimeEvent);
|
|
2674
|
-
assertNoReservedWorkspaceAuthorityAppend(canonicalInput.decisionRuntimeEvent);
|
|
2675
|
-
if (canonicalInput.outcomeRuntimeEvent) {
|
|
2676
|
-
assertNoReservedWorkspaceAuthorityAppend(canonicalInput.outcomeRuntimeEvent);
|
|
2677
|
-
assertNoReservedRecoveryFact(canonicalInput.outcomeRuntimeEvent);
|
|
2678
|
-
}
|
|
2679
|
-
this.transaction(() => {
|
|
2680
|
-
const operation = this.readToolOperationSync(canonicalInput.operationId);
|
|
2681
|
-
if (!operation)
|
|
2682
|
-
throw new Error(`Unknown tool operation ${canonicalInput.operationId}`);
|
|
2683
|
-
if (!operation.dispatchEventId) {
|
|
2684
|
-
throw new Error('Recovery bundle requires a durable dispatch RuntimeEvent');
|
|
2685
|
-
}
|
|
2686
|
-
assertToolRecoveryEventBundle({
|
|
2687
|
-
operation: recoveryOperationIdentity(operation),
|
|
2688
|
-
callEvent: this.readRequiredRuntimeEvent(operation.callEventId),
|
|
2689
|
-
dispatchEvent: this.readRequiredRuntimeEvent(operation.dispatchEventId),
|
|
2690
|
-
reconcileEvent: canonicalInput.reconcileRuntimeEvent,
|
|
2691
|
-
outcomeEvent: canonicalInput.outcomeRuntimeEvent,
|
|
2692
|
-
decisionEvent: canonicalInput.decisionRuntimeEvent,
|
|
2693
|
-
});
|
|
2694
|
-
assertStrictRuntimeEventOrder([
|
|
2695
|
-
this.runtimeEventSeq(operation.callEventId),
|
|
2696
|
-
this.runtimeEventSeq(operation.dispatchEventId),
|
|
2697
|
-
]);
|
|
2698
|
-
this.assertToolLedgerTransition([
|
|
2699
|
-
canonicalInput.reconcileRuntimeEvent,
|
|
2700
|
-
...(canonicalInput.outcomeRuntimeEvent ? [canonicalInput.outcomeRuntimeEvent] : []),
|
|
2701
|
-
canonicalInput.decisionRuntimeEvent,
|
|
2702
|
-
], 'recovery_bundle');
|
|
2703
|
-
if (operation.currentState !== 'prepared' || operation.resultEventId !== undefined) {
|
|
2704
|
-
this.assertExactRecoveryBundleAlreadyCommitted(canonicalInput, operation);
|
|
2705
|
-
return;
|
|
2706
|
-
}
|
|
2707
|
-
this.commitRecoveryFactSync(operation, canonicalInput.reconcileRuntimeEvent, 'reconcile_observed');
|
|
2708
|
-
this.options.failpoint?.('after_recovery_reconcile');
|
|
2709
|
-
if (canonicalInput.outcomeRuntimeEvent) {
|
|
2710
|
-
this.commitToolOutcomeSync({
|
|
2711
|
-
operationId: canonicalInput.operationId,
|
|
2712
|
-
journalEventId: `${canonicalInput.operationId}_outcome`,
|
|
2713
|
-
runtimeEvent: canonicalInput.outcomeRuntimeEvent,
|
|
2714
|
-
committedAt: canonicalInput.outcomeRuntimeEvent.ts,
|
|
2715
|
-
});
|
|
2716
|
-
this.options.failpoint?.('after_recovery_outcome');
|
|
2717
|
-
}
|
|
2718
|
-
const decision = canonicalInput.decisionRuntimeEvent.actions?.toolRecovery;
|
|
2719
|
-
if (!decision || decision.kind !== 'maka.tool.recovery_decision') {
|
|
2720
|
-
throw new Error('Recovery bundle requires a recovery decision');
|
|
2721
|
-
}
|
|
2722
|
-
const current = this.readToolOperationSync(canonicalInput.operationId);
|
|
2723
|
-
if (!current)
|
|
2724
|
-
throw new Error(`Unknown tool operation ${canonicalInput.operationId}`);
|
|
2725
|
-
this.commitRecoveryFactSync(current, canonicalInput.decisionRuntimeEvent, decision.payload.disposition === 'completed' ? 'recovery_completed' : 'recovery_parked', decision.payload);
|
|
2726
|
-
this.options.failpoint?.('after_recovery_decision');
|
|
2727
|
-
});
|
|
2728
|
-
}
|
|
2729
2694
|
async readToolOperation(operationId) {
|
|
2730
2695
|
return this.readToolOperationSync(operationId);
|
|
2731
2696
|
}
|
|
@@ -3054,42 +3019,6 @@ export class SqliteRuntimeStore {
|
|
|
3054
3019
|
}
|
|
3055
3020
|
return { created: true, runtimeEventSeq };
|
|
3056
3021
|
}
|
|
3057
|
-
commitRecoveryFactSync(operation, event, state, decision) {
|
|
3058
|
-
this.insertRuntimeEvent(event, event.ts, false);
|
|
3059
|
-
this.options.failpoint?.('after_runtime_event_insert');
|
|
3060
|
-
this.insertToolJournalEvent(operation, event, state);
|
|
3061
|
-
if (state === 'reconcile_observed') {
|
|
3062
|
-
const updated = this.db
|
|
3063
|
-
.prepare('UPDATE tool_operations SET version = version + 1 WHERE operation_id = ?')
|
|
3064
|
-
.run(operation.operationId);
|
|
3065
|
-
if (updated.changes !== 1) {
|
|
3066
|
-
throw new Error(`Tool operation compare-and-set failed for ${operation.operationId}`);
|
|
3067
|
-
}
|
|
3068
|
-
return;
|
|
3069
|
-
}
|
|
3070
|
-
if (state === 'recovery_completed' &&
|
|
3071
|
-
(decision?.disposition !== 'completed' ||
|
|
3072
|
-
operation.currentState !== 'outcome_committed' ||
|
|
3073
|
-
operation.resultEventId !== decision.outcomeEventId)) {
|
|
3074
|
-
throw new Error('Completed recovery decision does not match the persisted outcome');
|
|
3075
|
-
}
|
|
3076
|
-
if (state === 'recovery_parked' &&
|
|
3077
|
-
(decision?.disposition !== 'parked' ||
|
|
3078
|
-
operation.currentState !== 'prepared' ||
|
|
3079
|
-
operation.resultEventId !== undefined)) {
|
|
3080
|
-
throw new Error('Parked recovery decision does not match the prepared operation');
|
|
3081
|
-
}
|
|
3082
|
-
const updated = this.db
|
|
3083
|
-
.prepare(`
|
|
3084
|
-
UPDATE tool_operations
|
|
3085
|
-
SET current_state = ?, version = version + 1
|
|
3086
|
-
WHERE operation_id = ? AND current_state = ?
|
|
3087
|
-
`)
|
|
3088
|
-
.run(state, operation.operationId, state === 'recovery_completed' ? 'outcome_committed' : 'prepared');
|
|
3089
|
-
if (updated.changes !== 1) {
|
|
3090
|
-
throw new Error(`Tool operation compare-and-set failed for ${operation.operationId}`);
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
3093
3022
|
insertToolJournalEvent(operation, event, state, journalEventId = `${event.id}_journal`, committedAt = event.ts) {
|
|
3094
3023
|
this.db
|
|
3095
3024
|
.prepare(`
|
|
@@ -3101,32 +3030,6 @@ export class SqliteRuntimeStore {
|
|
|
3101
3030
|
.run(journalEventId, operation.operationId, operation.invocationId, operation.runId, operation.turnId, state, event.id, operation.canonicalArgsHash, operation.recoveryMode, event.actions?.toolRecovery ? JSON.stringify(event.actions.toolRecovery) : null, committedAt);
|
|
3102
3031
|
this.options.failpoint?.('after_journal_event_insert');
|
|
3103
3032
|
}
|
|
3104
|
-
assertExactRecoveryBundleAlreadyCommitted(input, operation) {
|
|
3105
|
-
const decision = input.decisionRuntimeEvent.actions?.toolRecovery;
|
|
3106
|
-
const completed = decision?.kind === 'maka.tool.recovery_decision' &&
|
|
3107
|
-
decision.payload.disposition === 'completed';
|
|
3108
|
-
if ((completed &&
|
|
3109
|
-
(!input.outcomeRuntimeEvent ||
|
|
3110
|
-
operation.currentState !== 'recovery_completed' ||
|
|
3111
|
-
operation.resultEventId !== input.outcomeRuntimeEvent.id)) ||
|
|
3112
|
-
(!completed &&
|
|
3113
|
-
(input.outcomeRuntimeEvent !== undefined ||
|
|
3114
|
-
operation.currentState !== 'recovery_parked' ||
|
|
3115
|
-
operation.resultEventId !== undefined))) {
|
|
3116
|
-
throw new Error(`Tool operation ${operation.operationId} is already settled`);
|
|
3117
|
-
}
|
|
3118
|
-
for (const event of [
|
|
3119
|
-
input.reconcileRuntimeEvent,
|
|
3120
|
-
...(input.outcomeRuntimeEvent ? [input.outcomeRuntimeEvent] : []),
|
|
3121
|
-
input.decisionRuntimeEvent,
|
|
3122
|
-
]) {
|
|
3123
|
-
const stored = this.readRuntimeEventJson(event.id);
|
|
3124
|
-
if (stored === undefined) {
|
|
3125
|
-
throw new Error(`Tool recovery bundle is incomplete for ${operation.operationId}`);
|
|
3126
|
-
}
|
|
3127
|
-
assertStoredRuntimeEventEquals(event, stored);
|
|
3128
|
-
}
|
|
3129
|
-
}
|
|
3130
3033
|
transaction(operation) {
|
|
3131
3034
|
if (this.databaseLease) {
|
|
3132
3035
|
return this.databaseLease.transaction('write', operation);
|
|
@@ -3898,11 +3801,6 @@ function assertStoredRuntimeEventEquals(event, storedJson) {
|
|
|
3898
3801
|
function canonicalizeRuntimeEventForStorage(event) {
|
|
3899
3802
|
return encodeCanonicalRuntimeEvent(event).event;
|
|
3900
3803
|
}
|
|
3901
|
-
function assertNoReservedRecoveryFact(event) {
|
|
3902
|
-
if (event.actions?.toolRecovery !== undefined) {
|
|
3903
|
-
throw new Error('Tool recovery facts require the atomic recovery bundle writer');
|
|
3904
|
-
}
|
|
3905
|
-
}
|
|
3906
3804
|
function assertNoReservedToolLedgerFact(event) {
|
|
3907
3805
|
assertNoReservedWorkspaceAuthorityAppend(event);
|
|
3908
3806
|
if (event.actions?.continuationStart !== undefined) {
|
|
@@ -3912,7 +3810,7 @@ function assertNoReservedToolLedgerFact(event) {
|
|
|
3912
3810
|
if (validation.ok)
|
|
3913
3811
|
return;
|
|
3914
3812
|
if (validation.code === 'reserved_recovery_fact') {
|
|
3915
|
-
throw new Error('
|
|
3813
|
+
throw new Error('Historical tool recovery facts are read-only');
|
|
3916
3814
|
}
|
|
3917
3815
|
if (validation.code === 'reserved_tool_boundary_fact') {
|
|
3918
3816
|
throw new Error('Durable tool facts require the atomic tool boundary writer');
|
|
@@ -3925,28 +3823,6 @@ function isToolLedgerBearingEvent(event) {
|
|
|
3925
3823
|
event.actions?.toolDispatch !== undefined ||
|
|
3926
3824
|
event.actions?.toolRecovery !== undefined);
|
|
3927
3825
|
}
|
|
3928
|
-
function recoveryOperationIdentity(operation) {
|
|
3929
|
-
if (!operation.dispatchEventId) {
|
|
3930
|
-
throw new Error('Recovery bundle requires a durable dispatch RuntimeEvent');
|
|
3931
|
-
}
|
|
3932
|
-
return {
|
|
3933
|
-
operationId: operation.operationId,
|
|
3934
|
-
invocationId: operation.invocationId,
|
|
3935
|
-
runId: operation.runId,
|
|
3936
|
-
turnId: operation.turnId,
|
|
3937
|
-
providerToolCallId: operation.providerToolCallId,
|
|
3938
|
-
toolName: operation.toolName,
|
|
3939
|
-
canonicalArgsHash: operation.canonicalArgsHash,
|
|
3940
|
-
recoveryMode: operation.recoveryMode,
|
|
3941
|
-
callEventId: operation.callEventId,
|
|
3942
|
-
dispatchEventId: operation.dispatchEventId,
|
|
3943
|
-
};
|
|
3944
|
-
}
|
|
3945
|
-
function assertStrictRuntimeEventOrder(eventSequences) {
|
|
3946
|
-
if (eventSequences.some((eventSequence, index) => index > 0 && eventSequence <= (eventSequences[index - 1] ?? -1))) {
|
|
3947
|
-
throw new Error('Recovery facts violate canonical RuntimeEvent causal order');
|
|
3948
|
-
}
|
|
3949
|
-
}
|
|
3950
3826
|
function requireRuntimeEventOrder(eventOrder, eventId) {
|
|
3951
3827
|
const order = eventOrder.get(eventId);
|
|
3952
3828
|
if (order === undefined)
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
//
|
|
20
|
-
export const SQLITE_WORKFLOW_SCHEMA_VERSION =
|
|
19
|
+
// v15 excludes acknowledged deliveries from active wait ownership and delivery scans.
|
|
20
|
+
export const SQLITE_WORKFLOW_SCHEMA_VERSION = 15;
|
|
21
21
|
const RELEASED_WORKFLOW_PROJECTION_TABLES = [
|
|
22
22
|
{
|
|
23
23
|
name: 'workflow_task_ledger_projections',
|
|
@@ -37,6 +37,7 @@ const RELEASED_WORKFLOW_PROJECTION_TABLES = [
|
|
|
37
37
|
];
|
|
38
38
|
export function migrateSqliteWorkflowDatabase(db) {
|
|
39
39
|
retireReleasedWorkflowProjections(db);
|
|
40
|
+
db.exec('DROP INDEX IF EXISTS workflow_event_waits_one_active_session; DROP INDEX IF EXISTS workflow_event_waits_pending');
|
|
40
41
|
db.exec(`
|
|
41
42
|
DROP INDEX IF EXISTS workflow_plan_reminders_order;
|
|
42
43
|
DROP TABLE IF EXISTS workflow_plan_reminders;
|
|
@@ -160,9 +161,11 @@ export function migrateSqliteWorkflowDatabase(db) {
|
|
|
160
161
|
ON workflow_event_waits(COALESCE(json_extract(record_json, '$.observation.lastAttemptAt'), 0), wait_id)
|
|
161
162
|
WHERE status = 'waiting';
|
|
162
163
|
CREATE INDEX IF NOT EXISTS workflow_event_waits_pending
|
|
163
|
-
ON workflow_event_waits(wait_id) WHERE status IN ('waiting', 'resolved');
|
|
164
|
+
ON workflow_event_waits(wait_id) WHERE status IN ('waiting', 'resolved') AND json_extract(record_json, '$.delivery') IS NULL;
|
|
164
165
|
CREATE UNIQUE INDEX IF NOT EXISTS workflow_event_waits_one_active_session
|
|
165
|
-
ON workflow_event_waits(session_id) WHERE status IN ('waiting', 'resolved');
|
|
166
|
+
ON workflow_event_waits(session_id) WHERE status IN ('waiting', 'resolved') AND json_extract(record_json, '$.delivery') IS NULL;
|
|
167
|
+
|
|
168
|
+
CREATE INDEX IF NOT EXISTS workflow_event_waits_delivery ON workflow_event_waits(status, wait_id) WHERE status IN ('resolved', 'expired') AND json_extract(record_json, '$.delivery') IS NULL;
|
|
166
169
|
|
|
167
170
|
CREATE TABLE IF NOT EXISTS workflow_event_wait_source_cooldowns (
|
|
168
171
|
source_key TEXT PRIMARY KEY,
|