maka-agent 0.2.2-dev.92.20261019 → 0.2.2-dev.98.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
|
@@ -0,0 +1,253 @@
|
|
|
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 { randomUUID } from 'node:crypto';
|
|
20
|
+
import { assertObservedEventWaitTransition, decodeObservedEventWaitRecord, eventWaitDeliveryKey, } from '@maka/core/event-wait';
|
|
21
|
+
import { conditionId, normalizeCondition, parseConditionResult, } from './condition.js';
|
|
22
|
+
/** Shares Matter's DB transaction: settlement, wait installation and wake delivery are atomic. */
|
|
23
|
+
export class MatterConditions {
|
|
24
|
+
db;
|
|
25
|
+
now;
|
|
26
|
+
transaction;
|
|
27
|
+
matter;
|
|
28
|
+
deliver;
|
|
29
|
+
constructor(db, now, transaction, matter, deliver) {
|
|
30
|
+
this.db = db;
|
|
31
|
+
this.now = now;
|
|
32
|
+
this.transaction = transaction;
|
|
33
|
+
this.matter = matter;
|
|
34
|
+
this.deliver = deliver;
|
|
35
|
+
db.exec(`CREATE TABLE IF NOT EXISTS matter_checkers(id TEXT PRIMARY KEY, matter_id TEXT NOT NULL, payload TEXT NOT NULL);
|
|
36
|
+
CREATE TABLE IF NOT EXISTS matter_conditions(id TEXT PRIMARY KEY, matter_id TEXT NOT NULL, revision INTEGER NOT NULL, payload TEXT NOT NULL);
|
|
37
|
+
CREATE INDEX IF NOT EXISTS matter_conditions_owner ON matter_conditions(matter_id);
|
|
38
|
+
CREATE TABLE IF NOT EXISTS matter_condition_sources(id TEXT PRIMARY KEY, cooldown INTEGER NOT NULL DEFAULT 0, token TEXT, reserved_until INTEGER NOT NULL DEFAULT 0);`);
|
|
39
|
+
}
|
|
40
|
+
saveTest(matterId, definition, result) {
|
|
41
|
+
const captured = normalizeCondition(definition);
|
|
42
|
+
const checked = parseConditionResult(result);
|
|
43
|
+
const record = {
|
|
44
|
+
id: conditionId(matterId, captured),
|
|
45
|
+
matterId,
|
|
46
|
+
definition: captured,
|
|
47
|
+
testedAt: this.now(),
|
|
48
|
+
result: checked,
|
|
49
|
+
};
|
|
50
|
+
this.db
|
|
51
|
+
.prepare('INSERT INTO matter_checkers(id,matter_id,payload) VALUES(?,?,?) ON CONFLICT(id) DO UPDATE SET payload=excluded.payload')
|
|
52
|
+
.run(record.id, matterId, JSON.stringify(record));
|
|
53
|
+
return record;
|
|
54
|
+
}
|
|
55
|
+
checker(id, matterId) {
|
|
56
|
+
const row = this.db
|
|
57
|
+
.prepare('SELECT payload FROM matter_checkers WHERE id=? AND matter_id=?')
|
|
58
|
+
.get(id, matterId);
|
|
59
|
+
if (!row)
|
|
60
|
+
throw new Error('Checker must be successfully tested in this matter first');
|
|
61
|
+
return JSON.parse(String(row.payload));
|
|
62
|
+
}
|
|
63
|
+
/** Called only inside the settlement transaction. Testing alone never starts observation. */
|
|
64
|
+
install(m, checkerId, intervalMs, submittedAt) {
|
|
65
|
+
if (!Number.isSafeInteger(intervalMs) || intervalMs < 1000 || intervalMs > 86400000)
|
|
66
|
+
throw new Error('Condition intervalMs must be 1000–86400000');
|
|
67
|
+
this.checker(checkerId, m.id);
|
|
68
|
+
const id = randomUUID();
|
|
69
|
+
const record = decodeObservedEventWaitRecord({
|
|
70
|
+
schemaVersion: 1,
|
|
71
|
+
waitId: id,
|
|
72
|
+
sessionId: m.sessionId,
|
|
73
|
+
sourceTurnId: m.activation.turnId,
|
|
74
|
+
sourceToolCallId: m.activation.id,
|
|
75
|
+
resource: {
|
|
76
|
+
providerId: 'matter',
|
|
77
|
+
connectionId: m.sessionId,
|
|
78
|
+
resourceType: 'checker',
|
|
79
|
+
resourceId: m.id,
|
|
80
|
+
},
|
|
81
|
+
condition: { typeId: 'code', version: 1, parameters: { checkerId, intervalMs } },
|
|
82
|
+
deliveryKey: eventWaitDeliveryKey(id),
|
|
83
|
+
createdAt: submittedAt,
|
|
84
|
+
updatedAt: submittedAt,
|
|
85
|
+
deadlineAt: Math.min(...m.wakes.map((w) => w.at)),
|
|
86
|
+
status: 'waiting',
|
|
87
|
+
});
|
|
88
|
+
this.db
|
|
89
|
+
.prepare('INSERT INTO matter_conditions(id,matter_id,revision,payload) VALUES(?,?,1,?)')
|
|
90
|
+
.run(id, m.id, JSON.stringify(record));
|
|
91
|
+
m.conditionWaitId = id;
|
|
92
|
+
}
|
|
93
|
+
read(id) {
|
|
94
|
+
const row = this.db
|
|
95
|
+
.prepare('SELECT revision,payload FROM matter_conditions WHERE id=?')
|
|
96
|
+
.get(id);
|
|
97
|
+
return row
|
|
98
|
+
? {
|
|
99
|
+
authorityRevision: Number(row.revision),
|
|
100
|
+
record: decodeObservedEventWaitRecord(JSON.parse(String(row.payload))),
|
|
101
|
+
}
|
|
102
|
+
: null;
|
|
103
|
+
}
|
|
104
|
+
/** The caller is already inside a Matter transaction; retirement also clears the time fallback. */
|
|
105
|
+
retire(m, reason) {
|
|
106
|
+
if (!m.conditionWaitId)
|
|
107
|
+
return;
|
|
108
|
+
const snapshot = this.read(m.conditionWaitId);
|
|
109
|
+
if (snapshot?.record.status === 'waiting') {
|
|
110
|
+
const record = {
|
|
111
|
+
...snapshot.record,
|
|
112
|
+
status: 'cancelled',
|
|
113
|
+
reason,
|
|
114
|
+
updatedAt: Math.max(this.now(), snapshot.record.updatedAt),
|
|
115
|
+
cancelledAt: Math.max(this.now(), snapshot.record.updatedAt),
|
|
116
|
+
};
|
|
117
|
+
this.write(snapshot, record);
|
|
118
|
+
}
|
|
119
|
+
m.conditionWaitId = null;
|
|
120
|
+
m.wakes = [];
|
|
121
|
+
}
|
|
122
|
+
/** Called by the existing time scanner, independent of source availability. */
|
|
123
|
+
expire(m) {
|
|
124
|
+
if (!m.conditionWaitId)
|
|
125
|
+
return false;
|
|
126
|
+
const snapshot = this.read(m.conditionWaitId);
|
|
127
|
+
if (snapshot?.record.status === 'waiting' && this.now() >= snapshot.record.deadlineAt) {
|
|
128
|
+
const record = {
|
|
129
|
+
...snapshot.record,
|
|
130
|
+
status: 'expired',
|
|
131
|
+
expiredAt: this.now(),
|
|
132
|
+
updatedAt: this.now(),
|
|
133
|
+
};
|
|
134
|
+
this.write(snapshot, record);
|
|
135
|
+
this.deliver(m, record);
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
write(before, record) {
|
|
140
|
+
assertObservedEventWaitTransition(before.record, record);
|
|
141
|
+
const snapshot = { authorityRevision: before.authorityRevision + 1, record };
|
|
142
|
+
this.db
|
|
143
|
+
.prepare('UPDATE matter_conditions SET revision=?,payload=? WHERE id=?')
|
|
144
|
+
.run(snapshot.authorityRevision, JSON.stringify(record), record.waitId);
|
|
145
|
+
return snapshot;
|
|
146
|
+
}
|
|
147
|
+
eligible(r) {
|
|
148
|
+
const m = this.matter(r.resource.resourceId);
|
|
149
|
+
return m.conditionWaitId === r.waitId && m.status === 'waiting' && !m.activation;
|
|
150
|
+
}
|
|
151
|
+
assertLease(owner) {
|
|
152
|
+
const row = this.db.prepare('SELECT owner,until_ms FROM plugin_lease WHERE id=1').get();
|
|
153
|
+
if (!row || row.owner !== owner || Number(row.until_ms) <= this.now())
|
|
154
|
+
throw new Error('Matter observation lease lost');
|
|
155
|
+
}
|
|
156
|
+
observationStore(owner) {
|
|
157
|
+
const sourceId = (x) => JSON.stringify([x.providerId, x.connectionId]);
|
|
158
|
+
const source = (x) => {
|
|
159
|
+
const id = sourceId(x);
|
|
160
|
+
this.db.prepare('INSERT OR IGNORE INTO matter_condition_sources(id) VALUES(?)').run(id);
|
|
161
|
+
return this.db.prepare('SELECT * FROM matter_condition_sources WHERE id=?').get(id);
|
|
162
|
+
};
|
|
163
|
+
const guarded = (fn) => this.transaction(() => {
|
|
164
|
+
this.assertLease(owner);
|
|
165
|
+
return fn();
|
|
166
|
+
});
|
|
167
|
+
const waits = () => this.db
|
|
168
|
+
.prepare(`SELECT c.id FROM matter_conditions c JOIN matters m ON m.id=c.matter_id
|
|
169
|
+
WHERE json_extract(m.payload,'$.conditionWaitId')=c.id
|
|
170
|
+
AND json_extract(m.payload,'$.status')='waiting'
|
|
171
|
+
AND json_extract(m.payload,'$.activation') IS NULL ORDER BY c.id`)
|
|
172
|
+
.all()
|
|
173
|
+
.map((row) => this.read(String(row.id)))
|
|
174
|
+
.filter((s) => this.eligible(s.record));
|
|
175
|
+
return {
|
|
176
|
+
read: async ({ sessionId, waitId }) => guarded(() => {
|
|
177
|
+
const s = this.read(waitId);
|
|
178
|
+
return s?.record.sessionId === sessionId ? s : null;
|
|
179
|
+
}),
|
|
180
|
+
listByStatus: async ({ status, afterWaitId, limit }) => guarded(() => {
|
|
181
|
+
const all = waits().filter((s) => s.record.status === status && (!afterWaitId || s.record.waitId > afterWaitId));
|
|
182
|
+
const items = all.slice(0, limit);
|
|
183
|
+
return { items, nextCursor: all.length > limit ? items.at(-1).record.waitId : null };
|
|
184
|
+
}),
|
|
185
|
+
listForObservation: async (input) => guarded(() => {
|
|
186
|
+
const excluded = new Set(input.excludedWaitIds), sources = new Set(input.excludedSources?.map(sourceId));
|
|
187
|
+
const items = waits().filter(({ record: r }) => r.status === 'waiting' &&
|
|
188
|
+
!excluded.has(r.waitId) &&
|
|
189
|
+
!sources.has(sourceId(r.resource)) &&
|
|
190
|
+
(!input.scan?.afterWaitId || r.waitId > input.scan.afterWaitId) &&
|
|
191
|
+
input.now >= (r.observation?.nextPollAt ?? r.createdAt));
|
|
192
|
+
if (!input.scan)
|
|
193
|
+
items.sort((a, b) => (a.record.observation?.lastAttemptAt ?? 0) -
|
|
194
|
+
(b.record.observation?.lastAttemptAt ?? 0));
|
|
195
|
+
return items.slice(0, input.limit);
|
|
196
|
+
}),
|
|
197
|
+
commit: async (input) => guarded(() => {
|
|
198
|
+
const before = this.read(input.waitId);
|
|
199
|
+
if (!before || before.authorityRevision !== input.expectedAuthorityRevision)
|
|
200
|
+
return {
|
|
201
|
+
kind: 'revision_conflict',
|
|
202
|
+
actualAuthorityRevision: before?.authorityRevision ?? null,
|
|
203
|
+
};
|
|
204
|
+
if (before.record.sessionId !== input.sessionId || !this.eligible(before.record))
|
|
205
|
+
return { kind: 'session_unavailable' };
|
|
206
|
+
let record = decodeObservedEventWaitRecord(input.record);
|
|
207
|
+
if (record.status === 'waiting' && record.observation?.outcome === 'pending') {
|
|
208
|
+
const next = (record.observation.lastObservedAt ?? record.observation.lastAttemptAt) +
|
|
209
|
+
Number(record.condition.parameters.intervalMs);
|
|
210
|
+
record = {
|
|
211
|
+
...record,
|
|
212
|
+
observation: { ...record.observation, nextObserveAt: next, nextPollAt: next },
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const snapshot = this.write(before, record);
|
|
216
|
+
if (record.status !== 'waiting') {
|
|
217
|
+
// Source revocation/cancellation must be visible to the worker too, not silently forgotten.
|
|
218
|
+
this.deliver(this.matter(record.resource.resourceId), record);
|
|
219
|
+
}
|
|
220
|
+
return { kind: 'committed', snapshot };
|
|
221
|
+
}),
|
|
222
|
+
readSourceCooldown: async (x) => guarded(() => {
|
|
223
|
+
const r = source(x);
|
|
224
|
+
return Math.max(Number(r.cooldown), Number(r.reserved_until)) || null;
|
|
225
|
+
}),
|
|
226
|
+
extendSourceCooldown: async (x) => guarded(() => {
|
|
227
|
+
const until = Math.max(Number(source(x).cooldown), x.until);
|
|
228
|
+
this.db
|
|
229
|
+
.prepare('UPDATE matter_condition_sources SET cooldown=? WHERE id=?')
|
|
230
|
+
.run(until, sourceId(x));
|
|
231
|
+
return until;
|
|
232
|
+
}),
|
|
233
|
+
reserveSourceDispatch: async (x) => guarded(() => {
|
|
234
|
+
const r = source(x);
|
|
235
|
+
if (Math.max(Number(r.cooldown), Number(r.reserved_until)) > x.observedAt)
|
|
236
|
+
return false;
|
|
237
|
+
this.db
|
|
238
|
+
.prepare('UPDATE matter_condition_sources SET token=?,reserved_until=? WHERE id=?')
|
|
239
|
+
.run(x.token, x.until, sourceId(x));
|
|
240
|
+
return true;
|
|
241
|
+
}),
|
|
242
|
+
completeSourceDispatch: async (x) => guarded(() => {
|
|
243
|
+
const r = source(x);
|
|
244
|
+
if (r.token === x.token)
|
|
245
|
+
this.db
|
|
246
|
+
.prepare('UPDATE matter_condition_sources SET token=NULL,reserved_until=0,cooldown=? WHERE id=?')
|
|
247
|
+
.run(Math.max(Number(r.cooldown), x.until), sourceId(x));
|
|
248
|
+
const current = source(x);
|
|
249
|
+
return Math.max(Number(current.cooldown), Number(current.reserved_until));
|
|
250
|
+
}),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
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 } from 'node:crypto';
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
import { executeCodeCell } from '@maka/runtime/code-mode';
|
|
22
|
+
const json = z.record(z.string(), z.json());
|
|
23
|
+
export const conditionInput = z.object({
|
|
24
|
+
code: z
|
|
25
|
+
.string()
|
|
26
|
+
.min(1)
|
|
27
|
+
.max(24000)
|
|
28
|
+
.optional()
|
|
29
|
+
.describe('Async JavaScript body. Read input and checkpoint; call only tools.SourceList({}), SourceQuery({source,query}), SourceRead({source,object}), SessionRead({source,id,query}). Return {status:"pending"|"triggered",reason,evidence?:string[],checkpoint?:JSON object}. No Node, shell or unrestricted network. Verify the result against real evidence before waiting.'),
|
|
30
|
+
preset: z
|
|
31
|
+
.enum(['source-appeared', 'session-revision'])
|
|
32
|
+
.optional()
|
|
33
|
+
.describe('Use instead of code. source-appeared: input {source,query}, triggers when the narrowed query returns any object. session-revision: input {source?,id,revision}, triggers when the session history revision changes. Inspect the test result to verify scope.'),
|
|
34
|
+
input: json.default({}),
|
|
35
|
+
});
|
|
36
|
+
const presets = {
|
|
37
|
+
'source-appeared': `const page = await tools.SourceQuery({source:input.source,query:input.query});
|
|
38
|
+
return {status:page.items.length ? "triggered" : "pending",reason:page.items.length ? "Source query found matching objects" : "No matching objects",evidence:page.items.slice(0,7).map(item => item.id)};`,
|
|
39
|
+
'session-revision': `const snapshot = await tools.SessionRead({source:input.source ?? "maka",id:input.id,query:{limit:1}});
|
|
40
|
+
if (!snapshot || typeof snapshot.session.historyRevision !== "string" || typeof input.revision !== "string") throw Error("Session and baseline must expose a history revision");
|
|
41
|
+
return {status:snapshot.session.historyRevision !== input.revision ? "triggered" : "pending",reason:"Session history revision compared with the supplied baseline",evidence:[input.id]};`,
|
|
42
|
+
};
|
|
43
|
+
export function normalizeCondition(value) {
|
|
44
|
+
const input = conditionInput.parse(value);
|
|
45
|
+
if (Boolean(input.code) === Boolean(input.preset))
|
|
46
|
+
throw new Error('Supply either code or preset');
|
|
47
|
+
return { code: input.code ?? presets[input.preset], input: input.input };
|
|
48
|
+
}
|
|
49
|
+
export const conditionResult = z
|
|
50
|
+
.object({
|
|
51
|
+
status: z.enum(['pending', 'triggered']),
|
|
52
|
+
reason: z.string().min(1).max(1000),
|
|
53
|
+
evidence: z.array(z.string().min(1).max(512)).max(7).default([]),
|
|
54
|
+
checkpoint: json.optional(),
|
|
55
|
+
})
|
|
56
|
+
.strict();
|
|
57
|
+
export function conditionId(matterId, definition) {
|
|
58
|
+
return createHash('sha256')
|
|
59
|
+
.update(JSON.stringify([matterId, definition]))
|
|
60
|
+
.digest('hex');
|
|
61
|
+
}
|
|
62
|
+
export function parseConditionResult(value) {
|
|
63
|
+
const result = conditionResult.parse(value);
|
|
64
|
+
// Fits the observation engine's durable cursor, including UTF-8 and JSON escaping.
|
|
65
|
+
if (Buffer.byteLength(JSON.stringify(result.checkpoint ?? {})) > 1800)
|
|
66
|
+
throw new Error('Checker checkpoint exceeds 1800 bytes; keep only a bounded cursor.');
|
|
67
|
+
if ([result.reason, ...result.evidence].some((value) => Buffer.byteLength(value) > 1024))
|
|
68
|
+
throw new Error('Checker evidence or reason exceeds 1024 bytes');
|
|
69
|
+
if ([result.reason, ...result.evidence].some((value) => /[\u0000-\u001f\u007f-\u009f\ud800-\udfff]/u.test(value)))
|
|
70
|
+
throw new Error('Checker reason and evidence must be single-line valid Unicode text');
|
|
71
|
+
if (Buffer.byteLength(JSON.stringify([result.reason, ...result.evidence])) > 5000)
|
|
72
|
+
throw new Error('Checker evidence exceeds the wake event budget');
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
const names = ['SourceList', 'SourceQuery', 'SourceRead', 'SessionRead'];
|
|
76
|
+
export async function runCondition(definition, checkpoint, read, signal) {
|
|
77
|
+
const result = await executeCodeCell({
|
|
78
|
+
code: `const input = ${JSON.stringify(definition.input)}; const checkpoint = ${JSON.stringify(checkpoint ?? null)};\n${definition.code}`,
|
|
79
|
+
tools: names.map((name) => ({ name })),
|
|
80
|
+
callTool: async (name, args, signal) => {
|
|
81
|
+
if (!names.includes(name))
|
|
82
|
+
throw new Error('Read-only checker capability unavailable');
|
|
83
|
+
return read(name, args, signal);
|
|
84
|
+
},
|
|
85
|
+
isFatalToolError: () => true,
|
|
86
|
+
signal,
|
|
87
|
+
});
|
|
88
|
+
if (!result.ok)
|
|
89
|
+
throw new Error(`Checker ${result.error.kind}: ${result.error.message}`);
|
|
90
|
+
return parseConditionResult(result.value);
|
|
91
|
+
}
|
|
92
|
+
/** The same scoped read bridge is used for the Agent's test and background observations. */
|
|
93
|
+
export function conditionReader(ctx, invocation) {
|
|
94
|
+
return (name, value, signal) => ctx.agents.withInvocation({
|
|
95
|
+
...invocation,
|
|
96
|
+
abortSignal: signal,
|
|
97
|
+
emitOutput: () => { },
|
|
98
|
+
}, async () => {
|
|
99
|
+
signal.throwIfAborted();
|
|
100
|
+
const args = z.record(z.string(), z.unknown()).parse(value ?? {});
|
|
101
|
+
switch (name) {
|
|
102
|
+
case 'SourceList':
|
|
103
|
+
return ctx.sources.list();
|
|
104
|
+
case 'SourceQuery': {
|
|
105
|
+
const source = z.string().parse(args.source);
|
|
106
|
+
const page = await ctx.sources.query(source, z.record(z.string(), z.unknown()).parse(args.query ?? {}));
|
|
107
|
+
const allowed = new Set(await ctx.sources.authorize(source, page.items));
|
|
108
|
+
if (page.items.some((item) => !allowed.has(item.id)))
|
|
109
|
+
throw new Error('Source read permission denied');
|
|
110
|
+
return page;
|
|
111
|
+
}
|
|
112
|
+
case 'SourceRead': {
|
|
113
|
+
const object = z
|
|
114
|
+
.object({
|
|
115
|
+
id: z.string(),
|
|
116
|
+
revision: z.string(),
|
|
117
|
+
kind: z.string(),
|
|
118
|
+
locator: z.record(z.string(), z.unknown()),
|
|
119
|
+
})
|
|
120
|
+
.passthrough()
|
|
121
|
+
.parse(args.object);
|
|
122
|
+
const result = await ctx.sources.read(z.string().parse(args.source), object);
|
|
123
|
+
if (result.status === 'unavailable' || result.status === 'version_unavailable')
|
|
124
|
+
throw new Error(`Source ${result.status}`);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
case 'SessionRead':
|
|
128
|
+
return ctx.sessionQuery.sourceQuery(z.string().parse(args.source ?? 'maka'), z.string().parse(args.id), z.record(z.string(), z.unknown()).parse(args.query ?? {}));
|
|
129
|
+
default:
|
|
130
|
+
throw new Error('Unsupported checker read');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { matterInput } from './settlement-context.js';
|
|
19
20
|
import { randomUUID } from 'node:crypto';
|
|
20
21
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
22
|
+
import { isPendingActivationTurnId } from './matter.js';
|
|
21
23
|
import { buildMatterPrompt, buildMatterStepContext } from './prompt.js';
|
|
22
24
|
import { awaitingUser, executionFailure } from '../execution-outcome.js';
|
|
23
25
|
/** Owns enrolled follow-up work. It restores authority only for sessions explicitly enrolled in its DB. */
|
|
@@ -65,7 +67,7 @@ export class MatterController {
|
|
|
65
67
|
return this.ctx.agents.withInvocation({
|
|
66
68
|
sessionId,
|
|
67
69
|
cwd,
|
|
68
|
-
turnId: `matter-host
|
|
70
|
+
turnId: `matter-host-${this.owner}`,
|
|
69
71
|
toolCallId: `matter-host:${randomUUID()}`,
|
|
70
72
|
abortSignal: this.stopping.signal,
|
|
71
73
|
emitOutput: () => { },
|
|
@@ -94,6 +96,13 @@ export class MatterController {
|
|
|
94
96
|
this.store.recover();
|
|
95
97
|
this.ready = true;
|
|
96
98
|
}
|
|
99
|
+
try {
|
|
100
|
+
await this.options.observer?.start();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// Observation failure must not block time fallbacks or unrelated Matter work.
|
|
104
|
+
this.lastError = String(error);
|
|
105
|
+
}
|
|
97
106
|
this.store.enqueueDue();
|
|
98
107
|
for (const m of this.store.list()) {
|
|
99
108
|
if (!this.active || this.runs.size >= 15)
|
|
@@ -142,7 +151,7 @@ export class MatterController {
|
|
|
142
151
|
if (result.disposition === 'turn_started') {
|
|
143
152
|
const latest = this.store.get(m.id).matter;
|
|
144
153
|
if (latest.activation?.id === activationId &&
|
|
145
|
-
latest.activation.turnId
|
|
154
|
+
isPendingActivationTurnId(latest.activation.turnId))
|
|
146
155
|
this.store.bindTurn(m.id, activationId, result.turnId);
|
|
147
156
|
}
|
|
148
157
|
else if (result.disposition === 'followup')
|
|
@@ -153,7 +162,7 @@ export class MatterController {
|
|
|
153
162
|
// A queued wake binds via MatterRead(activationId). Never re-submit an uncertain wake.
|
|
154
163
|
const completion = async () => {
|
|
155
164
|
if (queued) {
|
|
156
|
-
while (this.store.get(m.id).matter.activation?.turnId
|
|
165
|
+
while (isPendingActivationTurnId(this.store.get(m.id).matter.activation?.turnId)) {
|
|
157
166
|
await delay(25, undefined, { signal: this.stopping.signal });
|
|
158
167
|
}
|
|
159
168
|
}
|
|
@@ -184,7 +193,7 @@ export class MatterController {
|
|
|
184
193
|
// A live activation has no wall-clock deadline. Runtime failures and explicit
|
|
185
194
|
// user/Host cancellation still end it through the ordinary completion path.
|
|
186
195
|
await completion();
|
|
187
|
-
if (this.store.get(m.id).matter.activation?.turnId
|
|
196
|
+
if (isPendingActivationTurnId(this.store.get(m.id).matter.activation?.turnId))
|
|
188
197
|
throw new Error('Queued wake ended without claiming its activation; inspect conversation before resuming');
|
|
189
198
|
this.store.finish(m.id, activationId);
|
|
190
199
|
}
|
|
@@ -192,7 +201,7 @@ export class MatterController {
|
|
|
192
201
|
this.lastError = String(e);
|
|
193
202
|
const live = this.store.get(m.id).matter;
|
|
194
203
|
if (live.activation?.id === activationId &&
|
|
195
|
-
live.activation.turnId
|
|
204
|
+
isPendingActivationTurnId(live.activation.turnId) &&
|
|
196
205
|
/Runtime Host is not ready for Plugin Agent messages/.test(String(e))) {
|
|
197
206
|
this.store.deferAdmission(m.id, activationId, String(e));
|
|
198
207
|
return;
|
|
@@ -271,17 +280,20 @@ export class MatterController {
|
|
|
271
280
|
const m = this.store.forSession(sessionId);
|
|
272
281
|
if (!m || ['completed', 'cancelled'].includes(m.status))
|
|
273
282
|
return undefined;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
283
|
+
return buildMatterStepContext();
|
|
284
|
+
}
|
|
285
|
+
stepInboxContext(sessionId, turnId) {
|
|
286
|
+
const m = this.store.forSession(sessionId);
|
|
287
|
+
if (!m ||
|
|
288
|
+
['completed', 'cancelled'].includes(m.status) ||
|
|
289
|
+
!m.activation ||
|
|
290
|
+
m.activation.turnId !== turnId ||
|
|
291
|
+
m.activation.settled)
|
|
292
|
+
return undefined;
|
|
277
293
|
const snapshot = this.store.get(m.id);
|
|
278
294
|
const workspace = this.store.workspace(m.id, m.activation.id);
|
|
279
|
-
return
|
|
280
|
-
|
|
281
|
-
activationId: m.activation.id,
|
|
282
|
-
revision: m.revision,
|
|
283
|
-
events: snapshot.events,
|
|
284
|
-
pendingEventCount: snapshot.pendingEventCount,
|
|
295
|
+
return `Current task inbox (persisted inputs, not a new delegation; refreshed before every model request). User entries are user requirements; coordinator entries are assistant-authored amendments and bot_clarification entries are coordinator answers; both are coordinator context, not new user authorization. Reassess your next action against these inputs. Settlement checks the exact delivered input boundary automatically. Rendering this context does not acknowledge or consume inputs.\n${JSON.stringify({
|
|
296
|
+
...matterInput(snapshot),
|
|
285
297
|
inboxFile: workspace.files.inbox,
|
|
286
298
|
})}`;
|
|
287
299
|
}
|
|
@@ -319,6 +331,7 @@ export class MatterController {
|
|
|
319
331
|
this.active = false;
|
|
320
332
|
clearTimeout(this.timer);
|
|
321
333
|
await this.ticking;
|
|
334
|
+
await this.options.observer?.close();
|
|
322
335
|
// Fence writes before retiring this service’s run observers.
|
|
323
336
|
for (const id of this.runs.keys()) {
|
|
324
337
|
const m = this.store.get(id).matter;
|
|
@@ -23,6 +23,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
23
23
|
import { join } from 'node:path';
|
|
24
24
|
import { z } from 'zod';
|
|
25
25
|
import { taskDelivery } from './delivery.js';
|
|
26
|
+
import { workerTools } from './settlement-context.js';
|
|
26
27
|
/** Parent chat owns delegation; each work item retains its existing Matter Session. */
|
|
27
28
|
export function registerDelegation(ctx, directory, store, controller) {
|
|
28
29
|
const db = new DatabaseSync(join(directory, 'delegations.sqlite'));
|
|
@@ -31,6 +32,9 @@ export function registerDelegation(ctx, directory, store, controller) {
|
|
|
31
32
|
owner TEXT NOT NULL, task_key TEXT NOT NULL, session TEXT NOT NULL UNIQUE,
|
|
32
33
|
title TEXT NOT NULL, request TEXT NOT NULL, PRIMARY KEY(owner,task_key));`);
|
|
33
34
|
ctx.onClose(() => db.close());
|
|
35
|
+
ctx.tools.filter?.((sessionId, tools) => db.prepare('SELECT 1 FROM delegations WHERE session=?').get(sessionId)
|
|
36
|
+
? workerTools(tools)
|
|
37
|
+
: tools);
|
|
34
38
|
ctx.backgroundSessions?.register(() => db
|
|
35
39
|
.prepare('SELECT session FROM delegations')
|
|
36
40
|
.all()
|
|
@@ -54,6 +58,22 @@ export function registerDelegation(ctx, directory, store, controller) {
|
|
|
54
58
|
state: m.stateText,
|
|
55
59
|
waitingFor: m.waitingFor,
|
|
56
60
|
wakes: m.wakes,
|
|
61
|
+
condition: m.conditionWaitId
|
|
62
|
+
? (() => {
|
|
63
|
+
const wait = store.conditions.read(m.conditionWaitId)?.record;
|
|
64
|
+
return wait
|
|
65
|
+
? {
|
|
66
|
+
waitId: wait.waitId,
|
|
67
|
+
status: wait.status,
|
|
68
|
+
intervalMs: wait.condition.parameters.intervalMs,
|
|
69
|
+
attempts: wait.observation?.attempts ?? 0,
|
|
70
|
+
nextCheckAt: wait.observation?.nextPollAt ?? wait.createdAt,
|
|
71
|
+
lastObservedAt: wait.observation?.lastObservedAt ?? null,
|
|
72
|
+
diagnostic: wait.observation?.reason ?? null,
|
|
73
|
+
}
|
|
74
|
+
: null;
|
|
75
|
+
})()
|
|
76
|
+
: null,
|
|
57
77
|
retryAt: m.retryAt,
|
|
58
78
|
revision: m.revision,
|
|
59
79
|
lastError: m.lastError,
|
|
@@ -64,6 +84,16 @@ export function registerDelegation(ctx, directory, store, controller) {
|
|
|
64
84
|
.slice(0, 10)
|
|
65
85
|
.map(({ id, text, createdAt }) => ({ id, text, createdAt })),
|
|
66
86
|
});
|
|
87
|
+
// UI polling must not transport working notes, requests or report history.
|
|
88
|
+
const preview = (m) => ({
|
|
89
|
+
id: m.id,
|
|
90
|
+
sessionId: m.sessionId,
|
|
91
|
+
title: m.title,
|
|
92
|
+
status: m.status,
|
|
93
|
+
summary: m.progressSummary ?? '',
|
|
94
|
+
updatedAt: m.updatedAt,
|
|
95
|
+
retryAt: m.retryAt ?? null,
|
|
96
|
+
});
|
|
67
97
|
const creating = new Set();
|
|
68
98
|
const creationLabel = (row) => `matter-creation:${String(row.session).slice(9)}`;
|
|
69
99
|
const recover = async (row, call) => {
|
|
@@ -92,10 +122,10 @@ export function registerDelegation(ctx, directory, store, controller) {
|
|
|
92
122
|
continue;
|
|
93
123
|
try {
|
|
94
124
|
const snapshot = (await (await controller.agent(m.sessionId)).snapshot());
|
|
95
|
-
items.push({ ...
|
|
125
|
+
items.push({ ...preview(m), runtimeStatus: snapshot?.agent?.status });
|
|
96
126
|
}
|
|
97
|
-
catch
|
|
98
|
-
items.push({ ...
|
|
127
|
+
catch {
|
|
128
|
+
items.push({ ...preview(m), runtimeError: true });
|
|
99
129
|
}
|
|
100
130
|
}
|
|
101
131
|
return items;
|
|
@@ -114,7 +144,7 @@ export function registerDelegation(ctx, directory, store, controller) {
|
|
|
114
144
|
return JSON.parse(JSON.stringify(await impl(parameters.parse(input), call)));
|
|
115
145
|
},
|
|
116
146
|
});
|
|
117
|
-
register('MatterOverview', 'Read this conversation tasks, feedback status and unassigned legacy tasks. Does not adopt or change anything.', z.object({}), false, async (_, call) => {
|
|
147
|
+
register('MatterOverview', 'Read this conversation tasks, feedback status and unassigned legacy tasks as a compact directory with AI-authored progress summaries (at most 30 characters). Full task content is available through MatterTasks with an ID. Does not adopt or change anything.', z.object({}), false, async (_, call) => {
|
|
118
148
|
const owner = call.sessionId;
|
|
119
149
|
const rows = db.prepare('SELECT * FROM delegations').all();
|
|
120
150
|
return {
|
|
@@ -123,7 +153,7 @@ export function registerDelegation(ctx, directory, store, controller) {
|
|
|
123
153
|
legacy: store
|
|
124
154
|
.list()
|
|
125
155
|
.filter((m) => !rows.some((r) => r.session === m.sessionId))
|
|
126
|
-
.map(
|
|
156
|
+
.map(preview),
|
|
127
157
|
notifications: delivery.status(owner),
|
|
128
158
|
};
|
|
129
159
|
});
|
|
@@ -154,7 +154,7 @@ export function taskDelivery(ctx, db, store, controller) {
|
|
|
154
154
|
const agent = await ctx.agents.withInvocation({
|
|
155
155
|
sessionId: n.owner,
|
|
156
156
|
cwd,
|
|
157
|
-
turnId: `task-notification
|
|
157
|
+
turnId: `task-notification-${n.id}`,
|
|
158
158
|
toolCallId: randomUUID(),
|
|
159
159
|
abortSignal: abort.signal,
|
|
160
160
|
}, () => ctx.agents.resume({ sessionId: n.owner }));
|
|
@@ -22,6 +22,9 @@ import { z } from 'zod';
|
|
|
22
22
|
import { createMatterStore } from './store.js';
|
|
23
23
|
import { MatterController } from './controller.js';
|
|
24
24
|
import { buildMatterTools } from './tools.js';
|
|
25
|
+
import { createMatterObserver } from './condition-observer.js';
|
|
26
|
+
import { conditionReader, runCondition } from './condition.js';
|
|
27
|
+
import { deliveredMatterInput } from './settlement-context.js';
|
|
25
28
|
import { MATTER_INSTRUCTIONS } from './prompt.js';
|
|
26
29
|
const startInput = z.object({
|
|
27
30
|
title: z.string().trim().min(1).max(120),
|
|
@@ -41,6 +44,9 @@ export async function initializeMatters(ctx, directory, config = {}) {
|
|
|
41
44
|
const controller = new MatterController(ctx, store, {
|
|
42
45
|
tickMs: config.tickMs ?? 5000,
|
|
43
46
|
});
|
|
47
|
+
controller.options.observer = createMatterObserver(ctx, store, controller.owner, (error) => {
|
|
48
|
+
controller.lastError = String(error);
|
|
49
|
+
});
|
|
44
50
|
ctx.onClose(() => store.close());
|
|
45
51
|
const activate = () => {
|
|
46
52
|
controller.start();
|
|
@@ -54,10 +60,11 @@ export async function initializeMatters(ctx, directory, config = {}) {
|
|
|
54
60
|
throw new Error('This session has no follow-up');
|
|
55
61
|
return m;
|
|
56
62
|
};
|
|
63
|
+
ctx.tools.registerSessionAccess?.((sessionId) => store.isAuthorizedSession(sessionId) || !!store.forSession(sessionId));
|
|
57
64
|
registerDelegation(ctx, location.value, store, controller);
|
|
58
65
|
ctx.tools.register({
|
|
59
66
|
name: 'MatterStart',
|
|
60
|
-
description: 'Start durable follow-up only in a session opened from the long-task dialog. Read returned file paths, work normally, then
|
|
67
|
+
description: 'Start durable follow-up only in a session opened from the long-task dialog. Read returned file paths, work normally, then call MatterSettle with the result. One follow-up per conversation.',
|
|
61
68
|
parameters: startInput,
|
|
62
69
|
categoryHint: 'file_write',
|
|
63
70
|
executionSemantics: 'exclusive_step',
|
|
@@ -65,6 +72,8 @@ export async function initializeMatters(ctx, directory, config = {}) {
|
|
|
65
72
|
});
|
|
66
73
|
for (const tool of buildMatterTools({
|
|
67
74
|
store,
|
|
75
|
+
deliveredInput: async (call) => deliveredMatterInput((await ctx.readRuntimeEvents?.(call.sessionId, call.runId)) ?? [], call),
|
|
76
|
+
testCondition: (definition, call) => runCondition(definition, null, conditionReader(ctx, call), AbortSignal.any([call.abortSignal, AbortSignal.timeout(30_000)])),
|
|
68
77
|
review: (submission) => reviewMatter(ctx, submission),
|
|
69
78
|
changed() { },
|
|
70
79
|
authorize() {
|
|
@@ -111,7 +120,7 @@ export async function initializeMatters(ctx, directory, config = {}) {
|
|
|
111
120
|
return { allow: true };
|
|
112
121
|
return {
|
|
113
122
|
allow: false,
|
|
114
|
-
feedback: 'This follow-up turn has no exit decision yet. Keep doing useful work, or
|
|
123
|
+
feedback: 'This follow-up turn has no exit decision yet. Keep doing useful work, or call MatterSettle with continue, wait (a concrete waitingFor condition and future check time), or complete.',
|
|
115
124
|
};
|
|
116
125
|
},
|
|
117
126
|
});
|
|
@@ -120,6 +129,11 @@ export async function initializeMatters(ctx, directory, config = {}) {
|
|
|
120
129
|
order: 800,
|
|
121
130
|
text: ({ sessionId, turnId }) => controller.stepContext(sessionId, turnId),
|
|
122
131
|
});
|
|
132
|
+
ctx.systemPrompt.context({
|
|
133
|
+
name: 'proactive-matters.inbox',
|
|
134
|
+
order: 801,
|
|
135
|
+
text: ({ sessionId, turnId }) => controller.stepInboxContext(sessionId, turnId),
|
|
136
|
+
});
|
|
123
137
|
// Internal service operations. Desktop protocol exposes only the assistant's owner-bound API.
|
|
124
138
|
ctx.api.register('matters.list', () => controller.snapshot());
|
|
125
139
|
ctx.api.register('matters.authorize-session', (input) => {
|