maka-agent 0.2.2-dev.92.20261019 → 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/LICENSE +7 -7
- package/README.md +78 -18
- package/README.zh-CN.md +73 -15
- package/THIRD_PARTY_NOTICES.txt +12 -12
- package/dist/pi-goal.js +13 -0
- package/dist/pi-tui-runner.js +44 -1
- package/dist/run-command-core.js +111 -70
- package/dist/run-session-command.js +91 -15
- package/dist/run-turn-outcome.js +2 -33
- package/dist/runtime-host-session-channel.js +3 -1
- package/dist/runtime-host-session-driver.js +5 -0
- 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/event-wait.js +28 -10
- package/node_modules/@maka/core/dist/executor-catalog.js +3 -1
- 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.js +8 -0
- package/node_modules/@maka/core/dist/session-checkin.js +31 -0
- package/node_modules/@maka/core/dist/usage-stats/types.js +1 -0
- package/node_modules/@maka/core/package.json +2 -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/ai-sdk-compaction.js +22 -9
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +10 -1
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +101 -127
- package/node_modules/@maka/runtime/dist/event-wait-tool.js +2 -2
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +32 -1
- package/node_modules/@maka/runtime/dist/history-compaction.js +7 -0
- 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 +7 -2
- 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/runtime-context.js +53 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +3 -0
- 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/shell-run-manager.js +34 -0
- package/node_modules/@maka/runtime/dist/telemetry/builtin-pricing.js +21 -2
- package/node_modules/@maka/runtime/dist/tool-runtime.js +8 -0
- 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 +2 -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 +64 -13
- 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 +1 -1
- 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 +35 -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 +1 -1
- 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 +87 -23
- package/node_modules/@maka/runtime-host/dist/assistant/service.js +49 -5
- package/node_modules/@maka/runtime-host/dist/protocol/goal.js +119 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -1
- 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/canonical-session-projection.js +3 -2
- package/node_modules/@maka/runtime-host/dist/server/event-wait-manager.js +63 -12
- 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 +123 -11
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +47 -3
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +126 -4
- package/node_modules/@maka/runtime-host/dist/server/goal-event-waits.js +58 -19
- package/node_modules/@maka/runtime-host/dist/server/goal-projection.js +24 -3
- 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/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/context-offload-snapshot.js +2 -1
- package/node_modules/@maka/storage/dist/execution-stores.js +36 -1
- package/node_modules/@maka/storage/dist/local-execution-persistence.js +26 -0
- 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 +86 -16
- package/node_modules/@maka/storage/dist/session-checkpoint-publication-store.js +204 -0
- 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-reclamation-checkpoint.js +37 -0
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +31 -0
- package/node_modules/@maka/storage/package.json +3 -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
|
@@ -127,6 +127,18 @@ export function createFileSessionSnapshotWorkspacePreparer(options) {
|
|
|
127
127
|
* unreconciled.
|
|
128
128
|
*/
|
|
129
129
|
export async function createFileProductionSessionSnapshotService(options) {
|
|
130
|
+
// Retain the original adapter's stricter state/config layout contract.
|
|
131
|
+
await assertProductionRootsSeparate({
|
|
132
|
+
stateRoot: options.stateRoot,
|
|
133
|
+
configRoot: options.configRoot,
|
|
134
|
+
});
|
|
135
|
+
return createProductionSessionSnapshotService({
|
|
136
|
+
...options,
|
|
137
|
+
sourceRoots: [options.stateRoot, options.configRoot],
|
|
138
|
+
state: createFileSessionSnapshotStatePreparer(options),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
export async function createProductionSessionSnapshotService(options) {
|
|
130
142
|
const session = requireProductionSessionSnapshotBinding(options.session);
|
|
131
143
|
assertSessionBundleLimits(options.limits);
|
|
132
144
|
const limits = Object.freeze({ ...options.limits });
|
|
@@ -138,17 +150,13 @@ export async function createFileProductionSessionSnapshotService(options) {
|
|
|
138
150
|
});
|
|
139
151
|
await stagingCleanup.recover();
|
|
140
152
|
await assertProductionRootsSeparate({
|
|
141
|
-
|
|
142
|
-
configRoot: options.configRoot,
|
|
153
|
+
...Object.fromEntries(options.sourceRoots.map((root, index) => [`source${index}`, root])),
|
|
143
154
|
workspaceRoot: options.workspaceRoot,
|
|
144
155
|
stagingParent: stagingCleanup.stagingParent,
|
|
145
156
|
cleanupStateRoot: options.cleanupStateRoot,
|
|
146
157
|
});
|
|
147
158
|
const stateBudgetsByStagingRoot = new Map();
|
|
148
|
-
const fileStatePreparer =
|
|
149
|
-
stateRoot: options.stateRoot,
|
|
150
|
-
configRoot: options.configRoot,
|
|
151
|
-
});
|
|
159
|
+
const fileStatePreparer = options.state;
|
|
152
160
|
const state = {
|
|
153
161
|
async prepareState(input) {
|
|
154
162
|
const identity = await fileStatePreparer.prepareState(input);
|
|
@@ -47,6 +47,7 @@ export async function openRuntimeEventReadPersistence(input) {
|
|
|
47
47
|
listSessionInvocationsPage: (sessionId, input) => store.listSessionInvocationsPage(sessionId, input),
|
|
48
48
|
readInvocation: (sessionId, invocationId) => store.readInvocation(sessionId, invocationId),
|
|
49
49
|
readRuntimeEvents: (sessionId, runId) => store.readRuntimeEvents(sessionId, runId),
|
|
50
|
+
readToolProvenanceEvents: (sessionId, runId, toolCallId, budget) => store.readToolProvenanceEvents(sessionId, runId, toolCallId, budget),
|
|
50
51
|
readRuntimeEventsBounded: (sessionId, runId, budget) => store.readRuntimeEventsBounded(sessionId, runId, budget),
|
|
51
52
|
readImmutableRuntimeEvents: (sessionId, runId) => store.readImmutableRuntimeEvents(sessionId, runId),
|
|
52
53
|
readSessionRuntimeEvents: (sessionId) => store.readSessionRuntimeEvents(sessionId),
|
|
@@ -44,7 +44,7 @@ async function withBundleArtifactWriterLock(stateRoot, lease, operation) {
|
|
|
44
44
|
}
|
|
45
45
|
import { runWithContextValueMutation } from './context-value-mutation-gate.js';
|
|
46
46
|
import { withOfflineContextSnapshot, copyContextSnapshot, validateContextSnapshot, planContextSnapshotFiles, } from './context-offload-snapshot.js';
|
|
47
|
-
import { CONTEXT_OFFLOAD_DATABASE_NAME, CONTEXT_OFFLOAD_VALUES_DIRECTORY_NAME, } from './sqlite-context-offload-store.js';
|
|
47
|
+
import { CONTEXT_OFFLOAD_DATABASE_NAME, CONTEXT_OFFLOAD_VALUES_DIRECTORY_NAME, SqliteContextOffloadStore, } from './sqlite-context-offload-store.js';
|
|
48
48
|
import { acquireOperationalStateDatabase, inspectOperationalStateSchema, OPERATIONAL_STATE_DATABASE_NAME, OperationalStateMigrationBlockedError, } from './operational-state-store.js';
|
|
49
49
|
import { TERMINAL_RUNTIME_EVENT_SQL } from './runtime-transcript-query.js';
|
|
50
50
|
import { isSafeStorageId } from './storage-id.js';
|
|
@@ -169,7 +169,7 @@ export async function planSessionBundleExport(input) {
|
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
export async function exportSessionBundleState(input) {
|
|
172
|
-
return withOfflineContextSnapshot(input.stateRoot, (contextLocked) => withBundleArtifactWriterLock(input.stateRoot, input.lease, async (stateRoot) => {
|
|
172
|
+
return withOfflineContextSnapshot(input.stateRoot, (contextLocked) => withBundleArtifactWriterLock(input.stateRoot, input.lease, async (stateRoot) => runWithContextValueMutation(stateRoot, async () => {
|
|
173
173
|
const destinationRoot = resolve(input.destinationRoot);
|
|
174
174
|
await assertDestinationMissing(destinationRoot);
|
|
175
175
|
const stagingRoot = `${destinationRoot}.${process.pid}.${randomUUID()}.tmp`;
|
|
@@ -183,7 +183,8 @@ export async function exportSessionBundleState(input) {
|
|
|
183
183
|
await backupOperationalState(stateRoot, databasePath);
|
|
184
184
|
const plan = await planSessionBundleExport({ ...input, stateRoot, databasePath });
|
|
185
185
|
for (const entry of plan.entries) {
|
|
186
|
-
if (entry.source === 'context_snapshot' ||
|
|
186
|
+
if (entry.source === 'context_snapshot' ||
|
|
187
|
+
entry.source === 'filtered_runtime_sqlite') {
|
|
187
188
|
continue;
|
|
188
189
|
}
|
|
189
190
|
const destination = resolveInside(stagingRoot, entry.relativePath);
|
|
@@ -209,7 +210,7 @@ export async function exportSessionBundleState(input) {
|
|
|
209
210
|
await rm(stagingRoot, { recursive: true, force: true }).catch(() => { });
|
|
210
211
|
throw error;
|
|
211
212
|
}
|
|
212
|
-
}), input.lease ? { lease: input.lease } : {});
|
|
213
|
+
})), input.lease ? { lease: input.lease } : {});
|
|
213
214
|
}
|
|
214
215
|
/**
|
|
215
216
|
* Take the private copy the whole export is derived from.
|
|
@@ -320,6 +321,20 @@ async function filterBackedUpDatabase(destinationPath, sessionIds, options) {
|
|
|
320
321
|
for (const row of tables) {
|
|
321
322
|
if (typeof row.name !== 'string' || PORTABLE_GLOBAL_TABLES.has(row.name))
|
|
322
323
|
continue;
|
|
324
|
+
if (row.name === EVENT_WAIT_SOURCE_TABLE && !options.omitEventWaits) {
|
|
325
|
+
// A checkpoint must retain the source throttle/reservation constraining
|
|
326
|
+
// its waits, not merely their cursors. Select by Session explicitly so
|
|
327
|
+
// this is independent of SQLite's table iteration order. Unrelated
|
|
328
|
+
// sources are not part of this checkpoint's closure.
|
|
329
|
+
database
|
|
330
|
+
.prepare(`DELETE FROM ${EVENT_WAIT_SOURCE_TABLE} WHERE source_key NOT IN (
|
|
331
|
+
SELECT json_array(json_extract(record_json, '$.resource.providerId'),
|
|
332
|
+
json_extract(record_json, '$.resource.connectionId'))
|
|
333
|
+
FROM ${EVENT_WAIT_TABLE} WHERE session_id IN (${sessionIds.map(() => '?').join(', ')})
|
|
334
|
+
)`)
|
|
335
|
+
.run(...sessionIds);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
323
338
|
if (options.omitEventWaits && row.name === EVENT_WAIT_TABLE) {
|
|
324
339
|
// Keep the schema while leaving root-owned wait authority behind.
|
|
325
340
|
database.exec(`DELETE FROM ${quoteIdentifier(row.name)}`);
|
|
@@ -509,6 +524,7 @@ const LOCAL_SEQUENCE_COLUMNS = new Map([
|
|
|
509
524
|
['message_admissions', 'sequence'],
|
|
510
525
|
]);
|
|
511
526
|
const EVENT_WAIT_TABLE = 'workflow_event_waits';
|
|
527
|
+
const EVENT_WAIT_SOURCE_TABLE = 'workflow_event_wait_source_cooldowns';
|
|
512
528
|
const PORTABLE_GLOBAL_TABLES = new Set([
|
|
513
529
|
'operational_schema_migrations',
|
|
514
530
|
'session_metadata_schema',
|
|
@@ -765,17 +781,31 @@ export async function importSessionBundleState(input) {
|
|
|
765
781
|
// a Session already visible whose bytes never arrived -- and which a
|
|
766
782
|
// retry could not fix, because the ids are now taken.
|
|
767
783
|
const artifacts = await copyBundleArtifacts(bundleStateRoot, stateRoot);
|
|
784
|
+
let contextRefs;
|
|
768
785
|
try {
|
|
769
|
-
|
|
786
|
+
contextRefs = await mergeBundleContext(bundleStateRoot, stateRoot, contextLocked, sessionIds);
|
|
770
787
|
const inserted = mergeBundleDatabase(lease, bundleDatabasePath);
|
|
771
788
|
return { sessionIds: inserted, artifactFiles: artifacts.copied, contextRefs };
|
|
772
789
|
}
|
|
773
790
|
catch (error) {
|
|
774
|
-
//
|
|
775
|
-
//
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
791
|
+
// A failure after COMMIT (for example while detaching the bundle)
|
|
792
|
+
// must not remove bytes the published Session now references.
|
|
793
|
+
try {
|
|
794
|
+
const present = lease.database.prepare('SELECT 1 FROM session_metadata WHERE session_id = ?');
|
|
795
|
+
const unpublished = sessionIds.filter((id) => present.get(id) === undefined);
|
|
796
|
+
if (contextRefs !== undefined && contextRefs > 0) {
|
|
797
|
+
await releaseUnpublishedBundleContext(stateRoot, unpublished);
|
|
798
|
+
}
|
|
799
|
+
for (const path of artifacts.created) {
|
|
800
|
+
const artifactPath = relative(resolveInside(stateRoot, 'artifacts'), path);
|
|
801
|
+
if (unpublished.some((id) => isArtifactPathForSession(artifactPath, id))) {
|
|
802
|
+
await rm(path, { force: true }).catch(() => { });
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
catch {
|
|
807
|
+
// Preserve the import error if storage also refuses cleanup.
|
|
808
|
+
}
|
|
779
809
|
throw error;
|
|
780
810
|
}
|
|
781
811
|
}
|
|
@@ -1010,7 +1040,8 @@ export function listSessionBundleMergeTables(target) {
|
|
|
1010
1040
|
TRIGGER_MAINTAINED_TABLES.has(name) ||
|
|
1011
1041
|
// Older bundles and snapshots can contain wait rows. Import is a
|
|
1012
1042
|
// Session transfer, so it must independently refuse to copy them.
|
|
1013
|
-
name === EVENT_WAIT_TABLE
|
|
1043
|
+
name === EVENT_WAIT_TABLE ||
|
|
1044
|
+
name === EVENT_WAIT_SOURCE_TABLE) {
|
|
1014
1045
|
continue;
|
|
1015
1046
|
}
|
|
1016
1047
|
// Mirror the export's own classification instead of trusting that it
|
|
@@ -1158,18 +1189,35 @@ async function mergeBundleContextDatabase(bundleContext, stateRoot, sessionIds)
|
|
|
1158
1189
|
database.exec('BEGIN IMMEDIATE');
|
|
1159
1190
|
try {
|
|
1160
1191
|
database.exec('INSERT OR IGNORE INTO main.context_blobs SELECT * FROM bundle.context_blobs');
|
|
1192
|
+
// The payload files are already published. Adopt their representation
|
|
1193
|
+
// when the target still holds the same bytes inline after a v2 upgrade,
|
|
1194
|
+
// so retiring the last reference also collects the imported file.
|
|
1195
|
+
database.exec(`
|
|
1196
|
+
UPDATE main.context_blobs AS target
|
|
1197
|
+
SET storage_kind = 'managed_file', payload = source.payload
|
|
1198
|
+
FROM bundle.context_blobs AS source
|
|
1199
|
+
WHERE target.blob_id = source.blob_id
|
|
1200
|
+
AND target.storage_kind = 'inline'
|
|
1201
|
+
AND source.storage_kind = 'managed_file'
|
|
1202
|
+
`);
|
|
1161
1203
|
// A retry re-inserts the same rows. Skipping an identical one is what
|
|
1162
1204
|
// makes the second attempt work; skipping a DIFFERENT row that happens
|
|
1163
1205
|
// to share an id would hide a real collision, so the two are separated.
|
|
1164
1206
|
const colliding = database
|
|
1165
1207
|
.prepare(`
|
|
1166
1208
|
SELECT b.ref_id FROM bundle.context_refs b
|
|
1167
|
-
JOIN main.context_refs m
|
|
1168
|
-
|
|
1209
|
+
JOIN main.context_refs m ON m.ref_id = b.ref_id OR (
|
|
1210
|
+
m.session_id = b.session_id AND m.owner_kind = b.owner_kind AND m.owner_id = b.owner_id
|
|
1211
|
+
)
|
|
1212
|
+
WHERE m.ref_id <> b.ref_id OR m.session_id <> b.session_id
|
|
1213
|
+
OR m.owner_kind <> b.owner_kind OR m.owner_id <> b.owner_id
|
|
1214
|
+
OR m.blob_id <> b.blob_id OR m.media_type <> b.media_type
|
|
1215
|
+
OR m.created_at <> b.created_at
|
|
1216
|
+
LIMIT 1
|
|
1169
1217
|
`)
|
|
1170
|
-
.
|
|
1171
|
-
if (colliding
|
|
1172
|
-
throw new SessionBundleImportError('conflict', `Context reference already names different content: ${
|
|
1218
|
+
.get();
|
|
1219
|
+
if (colliding) {
|
|
1220
|
+
throw new SessionBundleImportError('conflict', `Context reference already names different content: ${colliding.ref_id}`);
|
|
1173
1221
|
}
|
|
1174
1222
|
database.exec('INSERT OR IGNORE INTO main.context_refs SELECT * FROM bundle.context_refs');
|
|
1175
1223
|
// A blob the target already held may have been queued for collection
|
|
@@ -1223,6 +1271,28 @@ async function mergeBundleContextDatabase(bundleContext, stateRoot, sessionIds)
|
|
|
1223
1271
|
}
|
|
1224
1272
|
return countContextRefs(targetContext, sessionIds);
|
|
1225
1273
|
}
|
|
1274
|
+
async function releaseUnpublishedBundleContext(stateRoot, sessionIds) {
|
|
1275
|
+
if (sessionIds.length === 0)
|
|
1276
|
+
return;
|
|
1277
|
+
await runWithContextValueMutation(stateRoot, async () => {
|
|
1278
|
+
// Reuse retirement's accounting and GC candidate updates. Retirement does
|
|
1279
|
+
// not add payloads, so it needs no write quota.
|
|
1280
|
+
const store = new SqliteContextOffloadStore(resolveInside(stateRoot, CONTEXT_OFFLOAD_DATABASE_NAME), {
|
|
1281
|
+
limits: {
|
|
1282
|
+
ownerMaxBytes: { read_image_snapshot: 0, tool_result_archive: 0 },
|
|
1283
|
+
sessionLogicalBytes: 0,
|
|
1284
|
+
workspacePhysicalBytes: 0,
|
|
1285
|
+
},
|
|
1286
|
+
});
|
|
1287
|
+
try {
|
|
1288
|
+
for (const sessionId of sessionIds)
|
|
1289
|
+
await store.retireSession(sessionId);
|
|
1290
|
+
}
|
|
1291
|
+
finally {
|
|
1292
|
+
store.close();
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1226
1296
|
/**
|
|
1227
1297
|
* Copy a managed-payload tree, structure and all.
|
|
1228
1298
|
*
|
|
@@ -0,0 +1,204 @@
|
|
|
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 { createHash, randomUUID } from 'node:crypto';
|
|
20
|
+
import { mkdir } from 'node:fs/promises';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import { writeAtomicFile } from './atomic-file-write.js';
|
|
23
|
+
import { readStableBoundedFile } from './stable-storage.js';
|
|
24
|
+
import { withProcessLifetimeFileUpdateLock } from './process-lifetime-file-update-lock.js';
|
|
25
|
+
import { createSessionCheckpointManifestV1, encodeSessionCheckpointManifestV1, SESSION_CHECKPOINT_MANIFEST_MEDIA_TYPE, } from './session-repository.js';
|
|
26
|
+
const MAX_DOCUMENT_BYTES = 4 * 1024 * 1024;
|
|
27
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
28
|
+
/**
|
|
29
|
+
* Host operation recovery facts, NOT a second checkpoint Head. The Repository
|
|
30
|
+
* remains the only authority for the current revision. Documents are bounded;
|
|
31
|
+
* receipts are never silently expired to make space.
|
|
32
|
+
*/
|
|
33
|
+
export async function openSessionCheckpointPublicationStore(input) {
|
|
34
|
+
await mkdir(input.directory, { recursive: true, mode: 0o700 });
|
|
35
|
+
const authorityPath = join(input.directory, 'authority-v1.json');
|
|
36
|
+
const agentId = await withProcessLifetimeFileUpdateLock(authorityPath, async () => {
|
|
37
|
+
const existing = await readOptional(authorityPath);
|
|
38
|
+
if (existing !== undefined) {
|
|
39
|
+
if (!record(existing) ||
|
|
40
|
+
existing.schemaVersion !== 1 ||
|
|
41
|
+
existing.rootId !== input.rootId ||
|
|
42
|
+
!identifier(existing.agentId) ||
|
|
43
|
+
!UUID.test(existing.agentId))
|
|
44
|
+
throw invalid();
|
|
45
|
+
return existing.agentId;
|
|
46
|
+
}
|
|
47
|
+
const agentId = randomUUID();
|
|
48
|
+
await writeDocument(authorityPath, { schemaVersion: 1, rootId: input.rootId, agentId });
|
|
49
|
+
return agentId;
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
async withSession(makaSessionId, operation) {
|
|
53
|
+
if (!identifier(makaSessionId))
|
|
54
|
+
throw new TypeError('Invalid checkpoint Session identity');
|
|
55
|
+
const key = createHash('sha256').update(makaSessionId).digest('hex');
|
|
56
|
+
const path = join(input.directory, `session-${key}.json`);
|
|
57
|
+
return withProcessLifetimeFileUpdateLock(path, async () => {
|
|
58
|
+
const existing = await readOptional(path);
|
|
59
|
+
const document = existing === undefined
|
|
60
|
+
? {
|
|
61
|
+
schemaVersion: 1,
|
|
62
|
+
rootId: input.rootId,
|
|
63
|
+
binding: { makaSessionId, repositorySessionId: randomUUID(), agentId },
|
|
64
|
+
requests: [],
|
|
65
|
+
}
|
|
66
|
+
: decode(existing, input.rootId, makaSessionId, agentId);
|
|
67
|
+
const save = async () => {
|
|
68
|
+
decode(document, input.rootId, makaSessionId, agentId);
|
|
69
|
+
await writeDocument(path, document);
|
|
70
|
+
};
|
|
71
|
+
if (existing === undefined)
|
|
72
|
+
await save();
|
|
73
|
+
return operation(document, save);
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function decode(value, rootId, sessionId, agentId) {
|
|
79
|
+
if (!record(value) ||
|
|
80
|
+
value.schemaVersion !== 1 ||
|
|
81
|
+
value.rootId !== rootId ||
|
|
82
|
+
!record(value.binding) ||
|
|
83
|
+
value.binding.makaSessionId !== sessionId ||
|
|
84
|
+
value.binding.agentId !== agentId ||
|
|
85
|
+
!identifier(value.binding.repositorySessionId) ||
|
|
86
|
+
!UUID.test(value.binding.repositorySessionId) ||
|
|
87
|
+
!Array.isArray(value.requests))
|
|
88
|
+
throw invalid();
|
|
89
|
+
const ids = new Set();
|
|
90
|
+
const commits = new Set();
|
|
91
|
+
let pending = 0;
|
|
92
|
+
for (const request of value.requests) {
|
|
93
|
+
if (!record(request) ||
|
|
94
|
+
!identifier(request.requestId) ||
|
|
95
|
+
!identifier(request.commitId) ||
|
|
96
|
+
!UUID.test(request.commitId) ||
|
|
97
|
+
ids.has(request.requestId) ||
|
|
98
|
+
commits.has(request.commitId) ||
|
|
99
|
+
!(request.expectedRevision === null || identifier(request.expectedRevision)) ||
|
|
100
|
+
!(request.snapshotCleanupPending === undefined || request.snapshotCleanupPending === true) ||
|
|
101
|
+
!(request.bundleCleanupPending === undefined || request.bundleCleanupPending === true) ||
|
|
102
|
+
!(request.confirmationGrantId === undefined || identifier(request.confirmationGrantId)))
|
|
103
|
+
throw invalid();
|
|
104
|
+
ids.add(request.requestId);
|
|
105
|
+
commits.add(request.commitId);
|
|
106
|
+
if (request.phase === 'capturing' || request.phase === 'aborted') {
|
|
107
|
+
if (request.checkpoint !== undefined || request.result !== undefined)
|
|
108
|
+
throw invalid();
|
|
109
|
+
if (request.phase === 'capturing')
|
|
110
|
+
pending++;
|
|
111
|
+
}
|
|
112
|
+
else if (request.phase === 'prepared' ||
|
|
113
|
+
request.phase === 'conflicted' ||
|
|
114
|
+
request.phase === 'committed') {
|
|
115
|
+
assertCheckpoint(request.checkpoint);
|
|
116
|
+
if (request.phase !== 'committed') {
|
|
117
|
+
if (request.phase === 'prepared')
|
|
118
|
+
pending++;
|
|
119
|
+
if (request.result !== undefined)
|
|
120
|
+
throw invalid();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const result = request.result;
|
|
124
|
+
if (!record(result) ||
|
|
125
|
+
!record(result.ref) ||
|
|
126
|
+
result.ref.sessionId !== value.binding.repositorySessionId ||
|
|
127
|
+
!identifier(result.ref.revision) ||
|
|
128
|
+
result.agentId !== agentId ||
|
|
129
|
+
result.forkedFrom !== undefined ||
|
|
130
|
+
result.lastCommittedActivationId !== undefined)
|
|
131
|
+
throw invalid();
|
|
132
|
+
assertCheckpoint(result.checkpoint);
|
|
133
|
+
if (JSON.stringify(result.checkpoint) !== JSON.stringify(request.checkpoint))
|
|
134
|
+
throw invalid();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
throw invalid();
|
|
139
|
+
}
|
|
140
|
+
if (pending > 1)
|
|
141
|
+
throw invalid();
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
function assertCheckpoint(value) {
|
|
145
|
+
try {
|
|
146
|
+
if (!record(value) ||
|
|
147
|
+
!record(value.value) ||
|
|
148
|
+
value.value.schemaVersion !== 1 ||
|
|
149
|
+
!record(value.manifest))
|
|
150
|
+
throw invalid();
|
|
151
|
+
const manifest = createSessionCheckpointManifestV1(value.value.compatibilityBundle);
|
|
152
|
+
const bytes = encodeSessionCheckpointManifestV1(manifest);
|
|
153
|
+
if (!identifier(value.manifest.objectRef) ||
|
|
154
|
+
value.manifest.mediaType !== SESSION_CHECKPOINT_MANIFEST_MEDIA_TYPE ||
|
|
155
|
+
value.manifest.bytes !== bytes.byteLength ||
|
|
156
|
+
value.manifest.digest !== `sha256:${createHash('sha256').update(bytes).digest('hex')}`)
|
|
157
|
+
throw invalid();
|
|
158
|
+
}
|
|
159
|
+
catch (cause) {
|
|
160
|
+
throw invalid(cause);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function readOptional(path) {
|
|
164
|
+
try {
|
|
165
|
+
const bytes = await readStableBoundedFile({
|
|
166
|
+
path,
|
|
167
|
+
maxBytes: MAX_DOCUMENT_BYTES,
|
|
168
|
+
invalidFile: invalid,
|
|
169
|
+
});
|
|
170
|
+
return JSON.parse(bytes.toString('utf8'));
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
174
|
+
return undefined;
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async function writeDocument(path, document) {
|
|
179
|
+
const bytes = `${JSON.stringify(document)}\n`;
|
|
180
|
+
// Reserve the duplicated checkpoint plus binding/revision envelope BEFORE
|
|
181
|
+
// admitting CAS. Otherwise a prepared record near the quota could commit a
|
|
182
|
+
// Head whose receipt can never fit, permanently blocking reconciliation.
|
|
183
|
+
const receiptReserve = record(document) && Array.isArray(document.requests)
|
|
184
|
+
? document.requests.reduce((total, request) => total +
|
|
185
|
+
(record(request) && request.phase === 'prepared'
|
|
186
|
+
? Buffer.byteLength(JSON.stringify(request.checkpoint)) + 8192
|
|
187
|
+
: 0), 0)
|
|
188
|
+
: 0;
|
|
189
|
+
if (Buffer.byteLength(bytes) + receiptReserve > MAX_DOCUMENT_BYTES)
|
|
190
|
+
throw new Error('Checkpoint publication journal quota exceeded');
|
|
191
|
+
await writeAtomicFile(path, bytes, { fileMode: 0o600 });
|
|
192
|
+
}
|
|
193
|
+
function record(value) {
|
|
194
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
195
|
+
}
|
|
196
|
+
function identifier(value) {
|
|
197
|
+
return (typeof value === 'string' &&
|
|
198
|
+
value.length > 0 &&
|
|
199
|
+
value.length <= 512 &&
|
|
200
|
+
!/[\u0000-\u001f]/u.test(value));
|
|
201
|
+
}
|
|
202
|
+
function invalid(cause) {
|
|
203
|
+
return new Error('Invalid checkpoint publication recovery record', cause === undefined ? undefined : { cause });
|
|
204
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { AsyncLocalStorage } from 'node:async_hooks';
|
|
20
|
+
/** Normal operations remain concurrent; an explicit snapshot drains and fences them. */
|
|
21
|
+
export class SnapshotOperationGate {
|
|
22
|
+
#active = new Set();
|
|
23
|
+
#context = new AsyncLocalStorage();
|
|
24
|
+
#barrier;
|
|
25
|
+
run(operation) {
|
|
26
|
+
if (this.#context.getStore()?.active)
|
|
27
|
+
return operation();
|
|
28
|
+
const barrier = this.#barrier;
|
|
29
|
+
const task = barrier ? barrier.then(operation) : operation();
|
|
30
|
+
return this.#track(task);
|
|
31
|
+
}
|
|
32
|
+
exclusive(operation) {
|
|
33
|
+
if (this.#context.getStore()?.active) {
|
|
34
|
+
return Promise.reject(new Error('Cannot nest an execution snapshot boundary'));
|
|
35
|
+
}
|
|
36
|
+
// Register the barrier synchronously, before draining existing operations.
|
|
37
|
+
const previous = [...this.#active];
|
|
38
|
+
const precedingBarrier = this.#barrier;
|
|
39
|
+
let release;
|
|
40
|
+
const barrier = new Promise((resolve) => {
|
|
41
|
+
release = resolve;
|
|
42
|
+
});
|
|
43
|
+
this.#barrier = barrier;
|
|
44
|
+
const task = (async () => {
|
|
45
|
+
await precedingBarrier;
|
|
46
|
+
await Promise.allSettled(previous);
|
|
47
|
+
const context = { active: true };
|
|
48
|
+
try {
|
|
49
|
+
return await this.#context.run(context, operation);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
context.active = false;
|
|
53
|
+
release();
|
|
54
|
+
if (this.#barrier === barrier)
|
|
55
|
+
this.#barrier = undefined;
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
return this.#track(task);
|
|
59
|
+
}
|
|
60
|
+
#track(task) {
|
|
61
|
+
this.#active.add(task);
|
|
62
|
+
void task.finally(() => this.#active.delete(task)).catch(() => { });
|
|
63
|
+
return task;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -222,7 +222,7 @@ export function migrateSqliteContextOffloadDatabase(db) {
|
|
|
222
222
|
throw newerSchemaError(observedVersion);
|
|
223
223
|
}
|
|
224
224
|
if (observedVersion === SQLITE_CONTEXT_OFFLOAD_SCHEMA_VERSION) {
|
|
225
|
-
|
|
225
|
+
validateSqliteContextOffloadSchema(db);
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
228
|
db.exec('BEGIN IMMEDIATE');
|
|
@@ -248,7 +248,7 @@ export function migrateSqliteContextOffloadDatabase(db) {
|
|
|
248
248
|
db.exec(`PRAGMA user_version = ${SQLITE_CONTEXT_OFFLOAD_SCHEMA_VERSION}`);
|
|
249
249
|
current = SQLITE_CONTEXT_OFFLOAD_SCHEMA_VERSION;
|
|
250
250
|
}
|
|
251
|
-
|
|
251
|
+
validateSqliteContextOffloadSchema(db);
|
|
252
252
|
db.exec('COMMIT');
|
|
253
253
|
}
|
|
254
254
|
catch (error) {
|
|
@@ -264,7 +264,7 @@ export function readSqliteContextOffloadSchemaVersion(db) {
|
|
|
264
264
|
}
|
|
265
265
|
return value;
|
|
266
266
|
}
|
|
267
|
-
function
|
|
267
|
+
export function validateSqliteContextOffloadSchema(db) {
|
|
268
268
|
const autoVacuum = db.prepare('PRAGMA auto_vacuum').get();
|
|
269
269
|
if (autoVacuum?.auto_vacuum !== 2) {
|
|
270
270
|
throw new Error('Incomplete context-offload SQLite schema: incremental auto-vacuum required');
|
|
@@ -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() {
|
|
@@ -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
|
+
}
|
|
@@ -984,6 +984,37 @@ export class SqliteRuntimeStore {
|
|
|
984
984
|
}
|
|
985
985
|
return true;
|
|
986
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
|
+
}
|
|
987
1018
|
async readRuntimeEventsBounded(sessionId, runId, budget) {
|
|
988
1019
|
assertEvidenceReadBudget(budget);
|
|
989
1020
|
const rows = this.db
|
|
@@ -44,6 +44,9 @@
|
|
|
44
44
|
"./scheduled-task-store": "./dist/scheduled-task-store.js",
|
|
45
45
|
"./quiescent-session-snapshot": "./dist/quiescent-session-snapshot.js",
|
|
46
46
|
"./production-session-snapshot": "./dist/production-session-snapshot.js",
|
|
47
|
+
"./session-repository": "./dist/session-repository.js",
|
|
48
|
+
"./file-session-repository": "./dist/file-session-repository.js",
|
|
49
|
+
"./session-checkpoint-publication-store": "./dist/session-checkpoint-publication-store.js",
|
|
47
50
|
"./session-bundle-contract": "./dist/session-bundle-contract.js",
|
|
48
51
|
"./session-bundle-file-service": "./dist/session-bundle-file-service.js",
|
|
49
52
|
"./session-bundle-policy": "./dist/session-bundle-policy.js",
|