@namzu/sdk 49.0.0 → 50.0.0
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/CHANGELOG.md +507 -0
- package/README.md +137 -125
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +1 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/examples/SupervisorAgent.js +1 -0
- package/dist/agents/examples/SupervisorAgent.js.map +1 -1
- package/dist/agents/runAgent.d.ts +2 -0
- package/dist/agents/runAgent.d.ts.map +1 -1
- package/dist/agents/runAgent.js +1 -0
- package/dist/agents/runAgent.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +16 -1
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +8 -2
- package/dist/bridge/acp/permission.d.ts.map +1 -1
- package/dist/bridge/acp/permission.js +1 -0
- package/dist/bridge/acp/permission.js.map +1 -1
- package/dist/bridge/acp/server.d.ts +25 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +205 -21
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/bridge/acp/tasks.d.ts +5 -0
- package/dist/bridge/acp/tasks.d.ts.map +1 -0
- package/dist/bridge/acp/tasks.js +19 -0
- package/dist/bridge/acp/tasks.js.map +1 -0
- package/dist/bridge/acp/update.d.ts.map +1 -1
- package/dist/bridge/acp/update.js +148 -13
- package/dist/bridge/acp/update.js.map +1 -1
- package/dist/config/runtime.d.ts +31 -31
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +11 -4
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +6 -3
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/constants/acp/index.d.ts +3 -0
- package/dist/constants/acp/index.d.ts.map +1 -1
- package/dist/constants/acp/index.js +3 -0
- package/dist/constants/acp/index.js.map +1 -1
- package/dist/contracts/a2a.d.ts +80 -80
- package/dist/contracts/schemas.d.ts +2 -2
- package/dist/contracts/session/schemas.d.ts +10 -10
- package/dist/manager/agent/lifecycle.d.ts +11 -0
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +178 -3
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/plan/lifecycle.d.ts +7 -8
- package/dist/manager/plan/lifecycle.d.ts.map +1 -1
- package/dist/manager/plan/lifecycle.js +7 -8
- package/dist/manager/plan/lifecycle.js.map +1 -1
- package/dist/manager/resident/consumption.d.ts +8 -8
- package/dist/manager/resident/learning-cycle.d.ts +2 -2
- package/dist/manager/resident/learning-observation.d.ts +12 -12
- package/dist/manager/resident/learning.d.ts +82 -82
- package/dist/manager/resident/outbox.d.ts +8 -8
- package/dist/manager/resident/proposal.d.ts +2 -2
- package/dist/manager/resident/store.d.ts +10 -10
- package/dist/manager/session/attribution.d.ts +1 -0
- package/dist/manager/session/attribution.d.ts.map +1 -1
- package/dist/manager/session/attribution.js +9 -1
- package/dist/manager/session/attribution.js.map +1 -1
- package/dist/manager/session/streamed-message-identity.d.ts +6 -0
- package/dist/manager/session/streamed-message-identity.d.ts.map +1 -0
- package/dist/manager/session/streamed-message-identity.js +14 -0
- package/dist/manager/session/streamed-message-identity.js.map +1 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +4 -3
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/pals/activity/causality.d.ts +23 -0
- package/dist/pals/activity/causality.d.ts.map +1 -0
- package/dist/pals/activity/causality.js +205 -0
- package/dist/pals/activity/causality.js.map +1 -0
- package/dist/pals/activity/projection.d.ts +5 -0
- package/dist/pals/activity/projection.d.ts.map +1 -0
- package/dist/pals/activity/projection.js +79 -0
- package/dist/pals/activity/projection.js.map +1 -0
- package/dist/pals/activity/source.d.ts +16 -0
- package/dist/pals/activity/source.d.ts.map +1 -0
- package/dist/pals/activity/source.js +235 -0
- package/dist/pals/activity/source.js.map +1 -0
- package/dist/pals/activity/subscription-policy.d.ts +38 -0
- package/dist/pals/activity/subscription-policy.d.ts.map +1 -0
- package/dist/pals/activity/subscription-policy.js +183 -0
- package/dist/pals/activity/subscription-policy.js.map +1 -0
- package/dist/pals/activity/subscription-schema.d.ts +353 -0
- package/dist/pals/activity/subscription-schema.d.ts.map +1 -0
- package/dist/pals/activity/subscription-schema.js +24 -0
- package/dist/pals/activity/subscription-schema.js.map +1 -0
- package/dist/pals/activity/subscription-store.d.ts +25 -0
- package/dist/pals/activity/subscription-store.d.ts.map +1 -0
- package/dist/pals/activity/subscription-store.js +152 -0
- package/dist/pals/activity/subscription-store.js.map +1 -0
- package/dist/pals/activity/subscription-types.d.ts +42 -0
- package/dist/pals/activity/subscription-types.d.ts.map +1 -0
- package/dist/pals/activity/subscription-types.js +2 -0
- package/dist/pals/activity/subscription-types.js.map +1 -0
- package/dist/pals/activity/subscriptions.d.ts +32 -0
- package/dist/pals/activity/subscriptions.d.ts.map +1 -0
- package/dist/pals/activity/subscriptions.js +151 -0
- package/dist/pals/activity/subscriptions.js.map +1 -0
- package/dist/pals/activity/types.d.ts +77 -0
- package/dist/pals/activity/types.d.ts.map +1 -0
- package/dist/pals/activity/types.js +2 -0
- package/dist/pals/activity/types.js.map +1 -0
- package/dist/pals/channels/ingress.d.ts +9 -0
- package/dist/pals/channels/ingress.d.ts.map +1 -0
- package/dist/pals/channels/ingress.js +131 -0
- package/dist/pals/channels/ingress.js.map +1 -0
- package/dist/pals/channels/routes.d.ts +20 -0
- package/dist/pals/channels/routes.d.ts.map +1 -0
- package/dist/pals/channels/routes.js +111 -0
- package/dist/pals/channels/routes.js.map +1 -0
- package/dist/pals/channels/routing.d.ts +37 -0
- package/dist/pals/channels/routing.d.ts.map +1 -0
- package/dist/pals/channels/routing.js +150 -0
- package/dist/pals/channels/routing.js.map +1 -0
- package/dist/pals/channels/schema.d.ts +234 -0
- package/dist/pals/channels/schema.d.ts.map +1 -0
- package/dist/pals/channels/schema.js +94 -0
- package/dist/pals/channels/schema.js.map +1 -0
- package/dist/pals/channels/types.d.ts +115 -0
- package/dist/pals/channels/types.d.ts.map +1 -0
- package/dist/pals/channels/types.js +2 -0
- package/dist/pals/channels/types.js.map +1 -0
- package/dist/pals/communication/broker.d.ts +8 -0
- package/dist/pals/communication/broker.d.ts.map +1 -0
- package/dist/pals/communication/broker.js +121 -0
- package/dist/pals/communication/broker.js.map +1 -0
- package/dist/pals/communication/dispatch.d.ts +4 -0
- package/dist/pals/communication/dispatch.d.ts.map +1 -0
- package/dist/pals/communication/dispatch.js +57 -0
- package/dist/pals/communication/dispatch.js.map +1 -0
- package/dist/pals/communication/inbound.d.ts +9 -0
- package/dist/pals/communication/inbound.d.ts.map +1 -0
- package/dist/pals/communication/inbound.js +155 -0
- package/dist/pals/communication/inbound.js.map +1 -0
- package/dist/pals/communication/ingress-dispatch.d.ts +5 -0
- package/dist/pals/communication/ingress-dispatch.d.ts.map +1 -0
- package/dist/pals/communication/ingress-dispatch.js +51 -0
- package/dist/pals/communication/ingress-dispatch.js.map +1 -0
- package/dist/pals/communication/ingress-inbound.d.ts +9 -0
- package/dist/pals/communication/ingress-inbound.d.ts.map +1 -0
- package/dist/pals/communication/ingress-inbound.js +222 -0
- package/dist/pals/communication/ingress-inbound.js.map +1 -0
- package/dist/pals/communication/ingress-schema.d.ts +7829 -0
- package/dist/pals/communication/ingress-schema.d.ts.map +1 -0
- package/dist/pals/communication/ingress-schema.js +479 -0
- package/dist/pals/communication/ingress-schema.js.map +1 -0
- package/dist/pals/communication/ingress-types.d.ts +187 -0
- package/dist/pals/communication/ingress-types.d.ts.map +1 -0
- package/dist/pals/communication/ingress-types.js +73 -0
- package/dist/pals/communication/ingress-types.js.map +1 -0
- package/dist/pals/communication/operator.d.ts +75 -0
- package/dist/pals/communication/operator.d.ts.map +1 -0
- package/dist/pals/communication/operator.js +217 -0
- package/dist/pals/communication/operator.js.map +1 -0
- package/dist/pals/communication/policy.d.ts +41 -0
- package/dist/pals/communication/policy.d.ts.map +1 -0
- package/dist/pals/communication/policy.js +138 -0
- package/dist/pals/communication/policy.js.map +1 -0
- package/dist/pals/communication/schema.d.ts +2000 -0
- package/dist/pals/communication/schema.d.ts.map +1 -0
- package/dist/pals/communication/schema.js +170 -0
- package/dist/pals/communication/schema.js.map +1 -0
- package/dist/pals/communication/store.d.ts +61 -0
- package/dist/pals/communication/store.d.ts.map +1 -0
- package/dist/pals/communication/store.js +450 -0
- package/dist/pals/communication/store.js.map +1 -0
- package/dist/pals/communication/tools.d.ts +23 -0
- package/dist/pals/communication/tools.d.ts.map +1 -0
- package/dist/pals/communication/tools.js +107 -0
- package/dist/pals/communication/tools.js.map +1 -0
- package/dist/pals/communication/types.d.ts +168 -0
- package/dist/pals/communication/types.d.ts.map +1 -0
- package/dist/pals/communication/types.js +24 -0
- package/dist/pals/communication/types.js.map +1 -0
- package/dist/pals/communication/verify.d.ts +22 -0
- package/dist/pals/communication/verify.d.ts.map +1 -0
- package/dist/pals/communication/verify.js +142 -0
- package/dist/pals/communication/verify.js.map +1 -0
- package/dist/pals/lifecycle.d.ts +37 -0
- package/dist/pals/lifecycle.d.ts.map +1 -0
- package/dist/pals/lifecycle.js +22 -0
- package/dist/pals/lifecycle.js.map +1 -0
- package/dist/pals/prompt.d.ts +30 -0
- package/dist/pals/prompt.d.ts.map +1 -0
- package/dist/pals/prompt.js +65 -0
- package/dist/pals/prompt.js.map +1 -0
- package/dist/pals/reference-images.d.ts +44 -0
- package/dist/pals/reference-images.d.ts.map +1 -0
- package/dist/pals/reference-images.js +248 -0
- package/dist/pals/reference-images.js.map +1 -0
- package/dist/pals/runtime.d.ts +46 -0
- package/dist/pals/runtime.d.ts.map +1 -0
- package/dist/pals/runtime.js +624 -0
- package/dist/pals/runtime.js.map +1 -0
- package/dist/pals/store.d.ts +26 -0
- package/dist/pals/store.d.ts.map +1 -0
- package/dist/pals/store.js +334 -0
- package/dist/pals/store.js.map +1 -0
- package/dist/pals/types.d.ts +145 -0
- package/dist/pals/types.d.ts.map +1 -0
- package/dist/pals/types.js +2 -0
- package/dist/pals/types.js.map +1 -0
- package/dist/peers/envelope.js +1 -1
- package/dist/peers/envelope.js.map +1 -1
- package/dist/peers/protocol.d.ts +83 -83
- package/dist/peers/record.d.ts +10 -10
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +7 -2
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/process/kill-tree.d.ts.map +1 -1
- package/dist/process/kill-tree.js +9 -1
- package/dist/process/kill-tree.js.map +1 -1
- package/dist/provider/errors.d.ts +19 -0
- package/dist/provider/errors.d.ts.map +1 -1
- package/dist/provider/errors.js +123 -2
- package/dist/provider/errors.js.map +1 -1
- package/dist/public-runtime.d.ts +41 -13
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +35 -7
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +8 -3
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +8 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +27 -7
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/tool/presentation.d.ts +1 -0
- package/dist/registry/tool/presentation.d.ts.map +1 -1
- package/dist/registry/tool/presentation.js +9 -7
- package/dist/registry/tool/presentation.js.map +1 -1
- package/dist/runtime/harness-session/index.d.ts +5 -0
- package/dist/runtime/harness-session/index.d.ts.map +1 -0
- package/dist/runtime/harness-session/index.js +928 -0
- package/dist/runtime/harness-session/index.js.map +1 -0
- package/dist/runtime/harness-session/journal.d.ts +37 -0
- package/dist/runtime/harness-session/journal.d.ts.map +1 -0
- package/dist/runtime/harness-session/journal.js +177 -0
- package/dist/runtime/harness-session/journal.js.map +1 -0
- package/dist/runtime/harness-session/saved-view.d.ts +8 -0
- package/dist/runtime/harness-session/saved-view.d.ts.map +1 -0
- package/dist/runtime/harness-session/saved-view.js +112 -0
- package/dist/runtime/harness-session/saved-view.js.map +1 -0
- package/dist/runtime/jobs/awaited-jobs.d.ts +2 -1
- package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -1
- package/dist/runtime/jobs/awaited-jobs.js +2 -1
- package/dist/runtime/jobs/awaited-jobs.js.map +1 -1
- package/dist/runtime/jobs/registry.d.ts +56 -1
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +351 -34
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/abandon-turn.d.ts +12 -1
- package/dist/runtime/query/abandon-turn.d.ts.map +1 -1
- package/dist/runtime/query/abandon-turn.js +3 -1
- package/dist/runtime/query/abandon-turn.js.map +1 -1
- package/dist/runtime/query/checkpoint.d.ts +4 -0
- package/dist/runtime/query/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/checkpoint.js +10 -0
- package/dist/runtime/query/checkpoint.js.map +1 -1
- package/dist/runtime/query/durable-inbound.d.ts +5 -0
- package/dist/runtime/query/durable-inbound.d.ts.map +1 -0
- package/dist/runtime/query/durable-inbound.js +89 -0
- package/dist/runtime/query/durable-inbound.js.map +1 -0
- package/dist/runtime/query/events.d.ts +4 -0
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +22 -5
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts +5 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +85 -13
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +41 -18
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +227 -114
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +3 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +21 -4
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +18 -6
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +144 -67
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.d.ts +9 -5
- package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
- package/dist/runtime/query/iteration/outstanding-work.js +61 -6
- package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +99 -16
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/observation-context.d.ts +2 -2
- package/dist/runtime/query/observation-context.d.ts.map +1 -1
- package/dist/runtime/query/observation-context.js +20 -13
- package/dist/runtime/query/observation-context.js.map +1 -1
- package/dist/runtime/query/prepare-turn.js +2 -2
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/prompt-cache.d.ts +1 -0
- package/dist/runtime/query/prompt-cache.d.ts.map +1 -1
- package/dist/runtime/query/prompt-cache.js +2 -0
- package/dist/runtime/query/prompt-cache.js.map +1 -1
- package/dist/runtime/query/prompt.d.ts +2 -0
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +23 -1
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/runtime/query/repeat-call.d.ts +12 -3
- package/dist/runtime/query/repeat-call.d.ts.map +1 -1
- package/dist/runtime/query/repeat-call.js +33 -10
- package/dist/runtime/query/repeat-call.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts +5 -6
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +30 -3
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/resume-session.js +1 -1
- package/dist/runtime/query/resume-session.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +8 -1
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +6 -0
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/saved-presentation.d.ts +13 -0
- package/dist/runtime/query/saved-presentation.d.ts.map +1 -0
- package/dist/runtime/query/saved-presentation.js +63 -0
- package/dist/runtime/query/saved-presentation.js.map +1 -0
- package/dist/runtime/query/steering.d.ts +6 -9
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/runtime/query/tool-executions.d.ts +7 -3
- package/dist/runtime/query/tool-executions.d.ts.map +1 -1
- package/dist/runtime/query/tool-executions.js +89 -9
- package/dist/runtime/query/tool-executions.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +3 -1
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +3 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts +25 -1
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +102 -8
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/scheduler/delegating.d.ts.map +1 -1
- package/dist/scheduler/delegating.js +5 -0
- package/dist/scheduler/delegating.js.map +1 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +2 -0
- package/dist/scheduler/local.js.map +1 -1
- package/dist/session/summary/materialize.d.ts +10 -6
- package/dist/session/summary/materialize.d.ts.map +1 -1
- package/dist/session/summary/materialize.js +41 -8
- package/dist/session/summary/materialize.js.map +1 -1
- package/dist/store/budget/ledger.d.ts +9 -0
- package/dist/store/budget/ledger.d.ts.map +1 -1
- package/dist/store/budget/ledger.js +58 -6
- package/dist/store/budget/ledger.js.map +1 -1
- package/dist/store/evidence/index-page.d.ts +12 -12
- package/dist/store/evidence/source-text.d.ts +4 -4
- package/dist/store/session/disk.d.ts +9 -4
- package/dist/store/session/disk.d.ts.map +1 -1
- package/dist/store/session/disk.js +57 -11
- package/dist/store/session/disk.js.map +1 -1
- package/dist/store/session/memory.d.ts +5 -3
- package/dist/store/session/memory.d.ts.map +1 -1
- package/dist/store/session/memory.js +24 -7
- package/dist/store/session/memory.js.map +1 -1
- package/dist/store/session-log/core.d.ts +26 -6
- package/dist/store/session-log/core.d.ts.map +1 -1
- package/dist/store/session-log/core.js +61 -8
- package/dist/store/session-log/core.js.map +1 -1
- package/dist/store/session-log/disk.d.ts +2 -2
- package/dist/store/session-log/disk.d.ts.map +1 -1
- package/dist/store/session-log/disk.js +1 -0
- package/dist/store/session-log/disk.js.map +1 -1
- package/dist/store/session-log/fold.d.ts +7 -0
- package/dist/store/session-log/fold.d.ts.map +1 -1
- package/dist/store/session-log/fold.js +21 -0
- package/dist/store/session-log/fold.js.map +1 -1
- package/dist/store/session-log/index.d.ts +5 -3
- package/dist/store/session-log/index.d.ts.map +1 -1
- package/dist/store/session-log/index.js +3 -1
- package/dist/store/session-log/index.js.map +1 -1
- package/dist/store/session-log/memory.d.ts +1 -1
- package/dist/store/session-log/memory.d.ts.map +1 -1
- package/dist/store/session-log/memory.js +1 -0
- package/dist/store/session-log/memory.js.map +1 -1
- package/dist/store/session-log/spill.d.ts +10 -3
- package/dist/store/session-log/spill.d.ts.map +1 -1
- package/dist/store/session-log/spill.js +70 -5
- package/dist/store/session-log/spill.js.map +1 -1
- package/dist/store/session-log/structured-result.d.ts +21 -0
- package/dist/store/session-log/structured-result.d.ts.map +1 -0
- package/dist/store/session-log/structured-result.js +67 -0
- package/dist/store/session-log/structured-result.js.map +1 -0
- package/dist/store/task/disk.d.ts +11 -0
- package/dist/store/task/disk.d.ts.map +1 -1
- package/dist/store/task/disk.js +41 -2
- package/dist/store/task/disk.js.map +1 -1
- package/dist/store/task/memory.d.ts.map +1 -1
- package/dist/store/task/memory.js +15 -3
- package/dist/store/task/memory.js.map +1 -1
- package/dist/tools/admit-facts.d.ts +13 -0
- package/dist/tools/admit-facts.d.ts.map +1 -0
- package/dist/tools/admit-facts.js +142 -0
- package/dist/tools/admit-facts.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts +4 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +108 -22
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser.d.ts +10 -10
- package/dist/tools/builtins/computer-use.d.ts +90 -90
- package/dist/tools/builtins/edit.d.ts +17 -0
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +34 -0
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/file-write-result.d.ts.map +1 -1
- package/dist/tools/builtins/file-write-result.js +13 -0
- package/dist/tools/builtins/file-write-result.js.map +1 -1
- package/dist/tools/builtins/glob.d.ts.map +1 -1
- package/dist/tools/builtins/glob.js +12 -0
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +14 -0
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +2 -0
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +1 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +4 -1
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/lsp.d.ts +2 -2
- package/dist/tools/builtins/read-file.d.ts.map +1 -1
- package/dist/tools/builtins/read-file.js +49 -0
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/view-image.d.ts +24 -0
- package/dist/tools/builtins/view-image.d.ts.map +1 -0
- package/dist/tools/builtins/view-image.js +385 -0
- package/dist/tools/builtins/view-image.js.map +1 -0
- package/dist/tools/builtins/wait-for-job-bounds.d.ts +2 -0
- package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job-bounds.js +1 -0
- package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts +2 -0
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +104 -6
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +1 -0
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/command-shell.d.ts +37 -2
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +100 -3
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/tools/coordinator/agent.d.ts +9 -19
- package/dist/tools/coordinator/agent.d.ts.map +1 -1
- package/dist/tools/coordinator/agent.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +127 -67
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/coordinator/wait-with-idle-bound.d.ts +2 -0
- package/dist/tools/coordinator/wait-with-idle-bound.d.ts.map +1 -1
- package/dist/tools/coordinator/wait-with-idle-bound.js +1 -1
- package/dist/tools/coordinator/wait-with-idle-bound.js.map +1 -1
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +4 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/failure-facts.d.ts +8 -0
- package/dist/tools/failure-facts.d.ts.map +1 -0
- package/dist/tools/failure-facts.js +24 -0
- package/dist/tools/failure-facts.js.map +1 -0
- package/dist/tools/host-output.d.ts +24 -0
- package/dist/tools/host-output.d.ts.map +1 -0
- package/dist/tools/host-output.js +117 -0
- package/dist/tools/host-output.js.map +1 -0
- package/dist/tools/oem-code-pages.d.ts +8 -0
- package/dist/tools/oem-code-pages.d.ts.map +1 -0
- package/dist/tools/oem-code-pages.js +23 -0
- package/dist/tools/oem-code-pages.js.map +1 -0
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +35 -6
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +23 -3
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/tools/task/list.d.ts.map +1 -1
- package/dist/tools/task/list.js +14 -6
- package/dist/tools/task/list.js.map +1 -1
- package/dist/tools/task/present.d.ts.map +1 -1
- package/dist/tools/task/present.js +26 -6
- package/dist/tools/task/present.js.map +1 -1
- package/dist/tools/task/update.d.ts.map +1 -1
- package/dist/tools/task/update.js +12 -5
- package/dist/tools/task/update.js.map +1 -1
- package/dist/tools/text-window.d.ts +19 -0
- package/dist/tools/text-window.d.ts.map +1 -0
- package/dist/tools/text-window.js +83 -0
- package/dist/tools/text-window.js.map +1 -0
- package/dist/toolsets/manager.d.ts +11 -0
- package/dist/toolsets/manager.d.ts.map +1 -1
- package/dist/toolsets/manager.js +45 -1
- package/dist/toolsets/manager.js.map +1 -1
- package/dist/types/acp/index.d.ts +137 -1
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/agent/base.d.ts +3 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/manager.d.ts +8 -23
- package/dist/types/agent/manager.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +10 -1
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +4 -0
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +30 -30
- package/dist/types/connector/mcp.d.ts +7 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/errors/catalog.d.ts.map +1 -1
- package/dist/types/errors/catalog.js +4 -2
- package/dist/types/errors/catalog.js.map +1 -1
- package/dist/types/harness/schema.d.ts +354 -0
- package/dist/types/harness/schema.d.ts.map +1 -0
- package/dist/types/harness/schema.js +203 -0
- package/dist/types/harness/schema.js.map +1 -0
- package/dist/types/harness/session.d.ts +278 -0
- package/dist/types/harness/session.d.ts.map +1 -0
- package/dist/types/harness/session.js +2 -0
- package/dist/types/harness/session.js.map +1 -0
- package/dist/types/hitl/index.d.ts +12 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/job/index.d.ts +47 -0
- package/dist/types/job/index.d.ts.map +1 -0
- package/dist/types/job/index.js +2 -0
- package/dist/types/job/index.js.map +1 -0
- package/dist/types/message/inbound-delivery.d.ts +44 -0
- package/dist/types/message/inbound-delivery.d.ts.map +1 -0
- package/dist/types/message/inbound-delivery.js +14 -0
- package/dist/types/message/inbound-delivery.js.map +1 -0
- package/dist/types/message/index.d.ts +4 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +5 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +6 -6
- package/dist/types/sandbox/index.d.ts +39 -2
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/session/checkpoint.d.ts +24 -17
- package/dist/types/session/checkpoint.d.ts.map +1 -1
- package/dist/types/session/checkpoint.js +1 -0
- package/dist/types/session/checkpoint.js.map +1 -1
- package/dist/types/session/events.d.ts +23 -1
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/session/records.d.ts +1514 -565
- package/dist/types/session/records.d.ts.map +1 -1
- package/dist/types/session/records.js +89 -1
- package/dist/types/session/records.js.map +1 -1
- package/dist/types/session/step.d.ts +2 -0
- package/dist/types/session/step.d.ts.map +1 -1
- package/dist/types/session/step.js.map +1 -1
- package/dist/types/session/store.d.ts +19 -10
- package/dist/types/session/store.d.ts.map +1 -1
- package/dist/types/session/tool-execution.d.ts +6 -0
- package/dist/types/session/tool-execution.d.ts.map +1 -1
- package/dist/types/structured-output/index.d.ts +12 -2
- package/dist/types/structured-output/index.d.ts.map +1 -1
- package/dist/types/summary/ref.d.ts +3 -1
- package/dist/types/summary/ref.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +32 -4
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +106 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/dist/utils/json-snapshot.d.ts +6 -2
- package/dist/utils/json-snapshot.d.ts.map +1 -1
- package/dist/utils/json-snapshot.js +19 -9
- package/dist/utils/json-snapshot.js.map +1 -1
- package/dist/utils/structured-result-json.d.ts +5 -0
- package/dist/utils/structured-result-json.d.ts.map +1 -0
- package/dist/utils/structured-result-json.js +10 -0
- package/dist/utils/structured-result-json.js.map +1 -0
- package/package.json +1 -1
- package/src/agents/QueryAgent.ts +1 -0
- package/src/agents/examples/SupervisorAgent.ts +1 -0
- package/src/agents/runAgent.ts +3 -0
- package/src/authorization/shell-lexer.ts +16 -1
- package/src/bridge/acp/permission.ts +17 -3
- package/src/bridge/acp/server.ts +271 -25
- package/src/bridge/acp/tasks.ts +23 -0
- package/src/bridge/acp/update.ts +167 -13
- package/src/connector/mcp/adapter.ts +16 -4
- package/src/connector/mcp/client.ts +6 -2
- package/src/constants/acp/index.ts +4 -0
- package/src/manager/agent/lifecycle.ts +230 -3
- package/src/manager/plan/lifecycle.ts +11 -9
- package/src/manager/session/attribution.ts +12 -2
- package/src/manager/session/streamed-message-identity.ts +21 -0
- package/src/manager/session/turn-recorder.ts +4 -3
- package/src/pals/activity/causality.ts +261 -0
- package/src/pals/activity/projection.ts +89 -0
- package/src/pals/activity/source.ts +240 -0
- package/src/pals/activity/subscription-policy.ts +230 -0
- package/src/pals/activity/subscription-schema.ts +27 -0
- package/src/pals/activity/subscription-store.ts +172 -0
- package/src/pals/activity/subscription-types.ts +48 -0
- package/src/pals/activity/subscriptions.ts +209 -0
- package/src/pals/activity/types.ts +108 -0
- package/src/pals/channels/ingress.ts +153 -0
- package/src/pals/channels/routes.ts +118 -0
- package/src/pals/channels/routing.ts +197 -0
- package/src/pals/channels/schema.ts +108 -0
- package/src/pals/channels/types.ts +156 -0
- package/src/pals/communication/broker.ts +131 -0
- package/src/pals/communication/dispatch.ts +66 -0
- package/src/pals/communication/inbound.ts +193 -0
- package/src/pals/communication/ingress-dispatch.ts +63 -0
- package/src/pals/communication/ingress-inbound.ts +269 -0
- package/src/pals/communication/ingress-schema.ts +526 -0
- package/src/pals/communication/ingress-types.ts +336 -0
- package/src/pals/communication/operator.ts +315 -0
- package/src/pals/communication/policy.ts +174 -0
- package/src/pals/communication/schema.ts +173 -0
- package/src/pals/communication/store.ts +577 -0
- package/src/pals/communication/tools.ts +139 -0
- package/src/pals/communication/types.ts +227 -0
- package/src/pals/communication/verify.ts +220 -0
- package/src/pals/lifecycle.ts +54 -0
- package/src/pals/prompt.ts +101 -0
- package/src/pals/reference-images.ts +322 -0
- package/src/pals/runtime.ts +670 -0
- package/src/pals/store.ts +369 -0
- package/src/pals/types.ts +157 -0
- package/src/peers/envelope.ts +1 -1
- package/src/plugin/shell-hook.ts +8 -2
- package/src/process/kill-tree.ts +10 -1
- package/src/provider/errors.ts +135 -2
- package/src/public-runtime.ts +117 -12
- package/src/public-tools.ts +13 -1
- package/src/public-types.ts +69 -7
- package/src/registry/tool/presentation.ts +9 -4
- package/src/runtime/harness-session/index.ts +1125 -0
- package/src/runtime/harness-session/journal.ts +209 -0
- package/src/runtime/harness-session/saved-view.ts +122 -0
- package/src/runtime/jobs/awaited-jobs.ts +2 -1
- package/src/runtime/jobs/registry.ts +397 -41
- package/src/runtime/query/abandon-turn.ts +18 -2
- package/src/runtime/query/checkpoint.ts +11 -0
- package/src/runtime/query/durable-inbound.ts +101 -0
- package/src/runtime/query/events.ts +22 -5
- package/src/runtime/query/executor/tool-call-admission.ts +125 -32
- package/src/runtime/query/executor.ts +316 -130
- package/src/runtime/query/index.ts +24 -4
- package/src/runtime/query/iteration/index.ts +218 -104
- package/src/runtime/query/iteration/outstanding-work.ts +55 -7
- package/src/runtime/query/iteration/phases/context.ts +4 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +118 -21
- package/src/runtime/query/observation-context.ts +22 -16
- package/src/runtime/query/prepare-turn.ts +2 -2
- package/src/runtime/query/prompt-cache.ts +3 -0
- package/src/runtime/query/prompt.ts +32 -1
- package/src/runtime/query/repeat-call.ts +40 -10
- package/src/runtime/query/resume-pending.ts +60 -7
- package/src/runtime/query/resume-session.ts +1 -1
- package/src/runtime/query/review-policy.ts +23 -2
- package/src/runtime/query/saved-presentation.ts +70 -0
- package/src/runtime/query/steering.ts +6 -9
- package/src/runtime/query/tool-executions.ts +108 -9
- package/src/runtime/query/tooling.ts +6 -1
- package/src/scheduler/completion-inbox.ts +108 -7
- package/src/scheduler/delegating.ts +5 -0
- package/src/scheduler/local.ts +2 -0
- package/src/session/summary/materialize.ts +51 -9
- package/src/store/budget/ledger.ts +60 -5
- package/src/store/session/disk.ts +77 -10
- package/src/store/session/memory.ts +32 -7
- package/src/store/session-log/core.ts +118 -11
- package/src/store/session-log/disk.ts +9 -2
- package/src/store/session-log/fold.ts +22 -0
- package/src/store/session-log/index.ts +5 -0
- package/src/store/session-log/memory.ts +2 -1
- package/src/store/session-log/spill.ts +89 -6
- package/src/store/session-log/structured-result.ts +96 -0
- package/src/store/task/disk.ts +46 -2
- package/src/store/task/memory.ts +13 -3
- package/src/tools/admit-facts.ts +145 -0
- package/src/tools/builtins/bash.ts +132 -24
- package/src/tools/builtins/edit.ts +42 -0
- package/src/tools/builtins/file-write-result.ts +14 -0
- package/src/tools/builtins/glob.ts +12 -0
- package/src/tools/builtins/grep.ts +14 -0
- package/src/tools/builtins/index.ts +2 -0
- package/src/tools/builtins/job.ts +4 -1
- package/src/tools/builtins/read-file.ts +57 -0
- package/src/tools/builtins/view-image.ts +409 -0
- package/src/tools/builtins/wait-for-job-bounds.ts +3 -0
- package/src/tools/builtins/wait-for-job.ts +141 -32
- package/src/tools/builtins/write-file.ts +4 -2
- package/src/tools/command-shell.ts +132 -5
- package/src/tools/coordinator/agent.ts +9 -19
- package/src/tools/coordinator/index.ts +150 -75
- package/src/tools/coordinator/wait-with-idle-bound.ts +3 -1
- package/src/tools/defineTool.ts +4 -0
- package/src/tools/failure-facts.ts +24 -0
- package/src/tools/host-output.ts +136 -0
- package/src/tools/oem-code-pages.ts +22 -0
- package/src/tools/schedules/schedule-tool.ts +38 -5
- package/src/tools/schedules/types.ts +23 -3
- package/src/tools/task/list.ts +15 -7
- package/src/tools/task/present.ts +37 -7
- package/src/tools/task/update.ts +12 -5
- package/src/tools/text-window.ts +87 -0
- package/src/toolsets/manager.ts +58 -1
- package/src/types/acp/index.ts +150 -4
- package/src/types/agent/base.ts +3 -0
- package/src/types/agent/manager.ts +8 -23
- package/src/types/agent/scheduler.ts +10 -1
- package/src/types/agent/task.ts +4 -0
- package/src/types/connector/mcp.ts +7 -0
- package/src/types/errors/catalog.ts +4 -2
- package/src/types/harness/schema.ts +203 -0
- package/src/types/harness/session.ts +306 -0
- package/src/types/hitl/index.ts +17 -1
- package/src/types/job/index.ts +42 -0
- package/src/types/message/inbound-delivery.ts +63 -0
- package/src/types/message/index.ts +8 -1
- package/src/types/sandbox/index.ts +46 -0
- package/src/types/session/checkpoint.ts +4 -1
- package/src/types/session/events.ts +23 -1
- package/src/types/session/records.ts +114 -2
- package/src/types/session/step.ts +2 -0
- package/src/types/session/store.ts +23 -9
- package/src/types/session/tool-execution.ts +6 -0
- package/src/types/structured-output/index.ts +13 -2
- package/src/types/summary/ref.ts +3 -1
- package/src/types/tool/index.ts +39 -5
- package/src/types/tool/presentation.ts +121 -0
- package/src/utils/json-snapshot.ts +26 -9
- package/src/utils/structured-result-json.ts +10 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { parseSessionLogLine } from '../../session/log-hash.js'
|
|
4
|
+
import { SessionLogChain, type SessionLogEntry } from '../../store/session-log/chain.js'
|
|
5
|
+
import { type RecordPointer, SESSION_RECORD_MAX_BYTES } from '../../types/session/records.js'
|
|
6
|
+
import { isEntityId } from '../../utils/id.js'
|
|
7
|
+
import { projectPalActivity } from './projection.js'
|
|
8
|
+
import type {
|
|
9
|
+
PalActivityCursor,
|
|
10
|
+
PalActivityFact,
|
|
11
|
+
PalActivityReadOptions,
|
|
12
|
+
PalActivityScope,
|
|
13
|
+
PalActivitySource,
|
|
14
|
+
PalActivitySourceOptions,
|
|
15
|
+
} from './types.js'
|
|
16
|
+
|
|
17
|
+
export class PalActivityAccessDeniedError extends Error {
|
|
18
|
+
override readonly name = 'PalActivityAccessDeniedError'
|
|
19
|
+
constructor() {
|
|
20
|
+
super('Current Pal activity observation permission is required.')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class PalActivityIntegrityError extends Error {
|
|
24
|
+
override readonly name = 'PalActivityIntegrityError'
|
|
25
|
+
constructor() {
|
|
26
|
+
super('Pal activity journal ownership or anchor evidence is invalid or incomplete.')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class PalActivityReadLimitError extends Error {
|
|
30
|
+
override readonly name = 'PalActivityReadLimitError'
|
|
31
|
+
constructor() {
|
|
32
|
+
super('The Pal activity byte budget cannot cover another complete record and its anchors.')
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const positive = z.number().int().positive().safe()
|
|
37
|
+
const digest = z.string().regex(/^[a-f0-9]{64}$/)
|
|
38
|
+
const pointer = z
|
|
39
|
+
.object({
|
|
40
|
+
seq: positive,
|
|
41
|
+
offset: z.number().int().nonnegative().safe(),
|
|
42
|
+
length: positive.max(SESSION_RECORD_MAX_BYTES),
|
|
43
|
+
sha256: digest,
|
|
44
|
+
})
|
|
45
|
+
.strict()
|
|
46
|
+
const scopeSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
tenantId: z.custom<PalActivityScope['tenantId']>((v) => isEntityId(v, 'tenant')),
|
|
49
|
+
projectId: z.custom<PalActivityScope['projectId']>((v) => isEntityId(v, 'project')),
|
|
50
|
+
sessionId: z.custom<PalActivityScope['sessionId']>((v) => isEntityId(v, 'session')),
|
|
51
|
+
palId: z.string().uuid(),
|
|
52
|
+
profileRevision: positive,
|
|
53
|
+
})
|
|
54
|
+
.strict()
|
|
55
|
+
const cursorSchema = z
|
|
56
|
+
.object({
|
|
57
|
+
v: z.literal(1),
|
|
58
|
+
scopeHash: digest,
|
|
59
|
+
root: pointer,
|
|
60
|
+
after: pointer,
|
|
61
|
+
generation: z.number().int().nonnegative().safe(),
|
|
62
|
+
})
|
|
63
|
+
.strict()
|
|
64
|
+
function samePointer(one: RecordPointer, two: RecordPointer): boolean {
|
|
65
|
+
return (
|
|
66
|
+
one.seq === two.seq &&
|
|
67
|
+
one.offset === two.offset &&
|
|
68
|
+
one.length === two.length &&
|
|
69
|
+
one.sha256 === two.sha256
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
function immutableCursor(value: PalActivityCursor): PalActivityCursor {
|
|
73
|
+
return Object.freeze({
|
|
74
|
+
...value,
|
|
75
|
+
root: Object.freeze({ ...value.root }),
|
|
76
|
+
after: Object.freeze({ ...value.after }),
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Bounded original-byte reads, with current host consent and exact Pal-root admission. */
|
|
81
|
+
export function createPalActivitySource(options: PalActivitySourceOptions): PalActivitySource {
|
|
82
|
+
const scope = Object.freeze(scopeSchema.parse(options.scope))
|
|
83
|
+
const { pals, authorize, openJournal } = options
|
|
84
|
+
if (typeof authorize !== 'function' || typeof openJournal !== 'function')
|
|
85
|
+
throw new TypeError('Pal activity requires explicit authorization and original-journal ports.')
|
|
86
|
+
return {
|
|
87
|
+
scope,
|
|
88
|
+
async read(input: PalActivityReadOptions) {
|
|
89
|
+
const { signal } = input
|
|
90
|
+
const maxRecords = positive.max(256).parse(input.maxRecords)
|
|
91
|
+
const maxReadBytes = positive.max(16 * 1024 * 1024).parse(input.maxReadBytes)
|
|
92
|
+
const supplied = input.cursor ? cursorSchema.parse(input.cursor) : undefined
|
|
93
|
+
signal.throwIfAborted()
|
|
94
|
+
if ((await authorize(scope, signal)) !== true) throw new PalActivityAccessDeniedError()
|
|
95
|
+
signal.throwIfAborted()
|
|
96
|
+
const definition = pals.getRevision(scope.palId, scope.profileRevision)
|
|
97
|
+
if (definition.id !== scope.palId || definition.revision !== scope.profileRevision)
|
|
98
|
+
throw new PalActivityIntegrityError()
|
|
99
|
+
const workspace = definition.workspace
|
|
100
|
+
const scopeHash = createHash('sha256')
|
|
101
|
+
.update(
|
|
102
|
+
JSON.stringify([
|
|
103
|
+
'pal-activity/1',
|
|
104
|
+
scope.tenantId,
|
|
105
|
+
scope.projectId,
|
|
106
|
+
scope.palId,
|
|
107
|
+
scope.profileRevision,
|
|
108
|
+
scope.sessionId,
|
|
109
|
+
workspace,
|
|
110
|
+
]),
|
|
111
|
+
)
|
|
112
|
+
.digest('hex')
|
|
113
|
+
if (supplied && supplied.scopeHash !== scopeHash) throw new PalActivityIntegrityError()
|
|
114
|
+
const journal = await openJournal(scope, signal)
|
|
115
|
+
signal.throwIfAborted()
|
|
116
|
+
if (journal.log.sessionId !== scope.sessionId) throw new PalActivityIntegrityError()
|
|
117
|
+
const bytes = journal.bytes
|
|
118
|
+
const size = await bytes.size()
|
|
119
|
+
signal.throwIfAborted()
|
|
120
|
+
if (!Number.isSafeInteger(size) || size < 1) throw new PalActivityIntegrityError()
|
|
121
|
+
if ((await authorize(scope, signal)) !== true) throw new PalActivityAccessDeniedError()
|
|
122
|
+
signal.throwIfAborted()
|
|
123
|
+
let readBytes = 0
|
|
124
|
+
const read = async (offset: number, length: number): Promise<Uint8Array> => {
|
|
125
|
+
signal.throwIfAborted()
|
|
126
|
+
if (length > maxReadBytes - readBytes) throw new PalActivityReadLimitError()
|
|
127
|
+
readBytes += length
|
|
128
|
+
const raw = await bytes.read(offset, length)
|
|
129
|
+
signal.throwIfAborted()
|
|
130
|
+
if (raw.byteLength !== length) throw new PalActivityIntegrityError()
|
|
131
|
+
return Uint8Array.from(raw)
|
|
132
|
+
}
|
|
133
|
+
const lineAt = async (offset: number): Promise<Uint8Array> => {
|
|
134
|
+
const parts: Uint8Array[] = []
|
|
135
|
+
let length = 0
|
|
136
|
+
while (offset + length < size) {
|
|
137
|
+
const available = maxReadBytes - readBytes
|
|
138
|
+
if (available === 0) throw new PalActivityReadLimitError()
|
|
139
|
+
const chunk = await read(
|
|
140
|
+
offset + length,
|
|
141
|
+
Math.min(1024, available, size - offset - length),
|
|
142
|
+
)
|
|
143
|
+
const newline = chunk.indexOf(10)
|
|
144
|
+
const part = newline < 0 ? chunk : chunk.subarray(0, newline + 1)
|
|
145
|
+
parts.push(part)
|
|
146
|
+
length += part.byteLength
|
|
147
|
+
if (length > SESSION_RECORD_MAX_BYTES) throw new PalActivityReadLimitError()
|
|
148
|
+
if (newline >= 0) return Buffer.concat(parts)
|
|
149
|
+
}
|
|
150
|
+
throw new PalActivityIntegrityError()
|
|
151
|
+
}
|
|
152
|
+
const first = await lineAt(0)
|
|
153
|
+
let root: SessionLogEntry
|
|
154
|
+
try {
|
|
155
|
+
root = new SessionLogChain({ head: null, sessionId: scope.sessionId }).accept(first, 0)
|
|
156
|
+
} catch {
|
|
157
|
+
throw new PalActivityIntegrityError()
|
|
158
|
+
}
|
|
159
|
+
const owner = root.record
|
|
160
|
+
if (
|
|
161
|
+
owner.type !== 'session_started' ||
|
|
162
|
+
owner.parent ||
|
|
163
|
+
owner.forkedFrom ||
|
|
164
|
+
owner.tenantId !== scope.tenantId ||
|
|
165
|
+
owner.projectId !== scope.projectId ||
|
|
166
|
+
owner.cwd !== workspace ||
|
|
167
|
+
owner.origin?.protocol !== 'desktop' ||
|
|
168
|
+
owner.origin.externalSessionId !==
|
|
169
|
+
JSON.stringify(['namzu-pal', scope.palId, scope.profileRevision, scope.sessionId])
|
|
170
|
+
)
|
|
171
|
+
throw new PalActivityIntegrityError()
|
|
172
|
+
if ((await read(size - 1, 1))[0] !== 10) throw new PalActivityIntegrityError()
|
|
173
|
+
let after = root.pointer
|
|
174
|
+
let generation = root.record.gen
|
|
175
|
+
if (supplied) {
|
|
176
|
+
const anchorEnd = supplied.after.offset + supplied.after.length
|
|
177
|
+
if (
|
|
178
|
+
!samePointer(root.pointer, supplied.root) ||
|
|
179
|
+
!Number.isSafeInteger(anchorEnd) ||
|
|
180
|
+
anchorEnd > size ||
|
|
181
|
+
supplied.after.seq < 1 ||
|
|
182
|
+
(supplied.after.seq > 1 && supplied.after.offset < root.pointer.length)
|
|
183
|
+
)
|
|
184
|
+
throw new PalActivityIntegrityError()
|
|
185
|
+
let anchor: ReturnType<typeof parseSessionLogLine>
|
|
186
|
+
try {
|
|
187
|
+
anchor = parseSessionLogLine(await read(supplied.after.offset, supplied.after.length))
|
|
188
|
+
} catch (error) {
|
|
189
|
+
signal.throwIfAborted()
|
|
190
|
+
if (error instanceof PalActivityReadLimitError) throw error
|
|
191
|
+
throw new PalActivityIntegrityError()
|
|
192
|
+
}
|
|
193
|
+
if (
|
|
194
|
+
anchor.sha256 !== supplied.after.sha256 ||
|
|
195
|
+
anchor.record.sessionId !== scope.sessionId ||
|
|
196
|
+
anchor.record.seq !== supplied.after.seq ||
|
|
197
|
+
anchor.record.gen !== supplied.generation ||
|
|
198
|
+
(supplied.after.seq === 1 && !samePointer(supplied.after, root.pointer))
|
|
199
|
+
)
|
|
200
|
+
throw new PalActivityIntegrityError()
|
|
201
|
+
after = supplied.after
|
|
202
|
+
generation = anchor.record.gen
|
|
203
|
+
}
|
|
204
|
+
const chain = new SessionLogChain({
|
|
205
|
+
head: after,
|
|
206
|
+
sessionId: scope.sessionId,
|
|
207
|
+
gen: generation,
|
|
208
|
+
})
|
|
209
|
+
const facts: PalActivityFact[] = []
|
|
210
|
+
let scannedRecords = 0
|
|
211
|
+
while (chain.end < size && scannedRecords < maxRecords) {
|
|
212
|
+
const raw = await lineAt(chain.end)
|
|
213
|
+
let entry: SessionLogEntry
|
|
214
|
+
let fact: PalActivityFact | null
|
|
215
|
+
try {
|
|
216
|
+
entry = chain.accept(raw, chain.end)
|
|
217
|
+
fact = projectPalActivity(entry, scopeHash)
|
|
218
|
+
} catch {
|
|
219
|
+
throw new PalActivityIntegrityError()
|
|
220
|
+
}
|
|
221
|
+
scannedRecords++
|
|
222
|
+
if (fact) facts.push(fact)
|
|
223
|
+
after = entry.pointer
|
|
224
|
+
generation = entry.record.gen
|
|
225
|
+
}
|
|
226
|
+
if ((await bytes.size()) < size) throw new PalActivityIntegrityError()
|
|
227
|
+
signal.throwIfAborted()
|
|
228
|
+
if ((await authorize(scope, signal)) !== true) throw new PalActivityAccessDeniedError()
|
|
229
|
+
signal.throwIfAborted()
|
|
230
|
+
return Object.freeze({
|
|
231
|
+
scope,
|
|
232
|
+
facts: Object.freeze(facts),
|
|
233
|
+
cursor: immutableCursor({ v: 1, scopeHash, root: root.pointer, after, generation }),
|
|
234
|
+
complete: chain.end === size,
|
|
235
|
+
scannedRecords,
|
|
236
|
+
readBytes,
|
|
237
|
+
})
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { chmodSync, lstatSync, mkdirSync, readdirSync, realpathSync } from 'node:fs'
|
|
2
|
+
import { join, resolve } from 'node:path'
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
import { DiskRevisionRecordStore } from '../../store/kv/revision-record-store.js'
|
|
6
|
+
import { defineSchema } from '../../store/schema.js'
|
|
7
|
+
import {
|
|
8
|
+
observationRouteKeySchema,
|
|
9
|
+
observationSourceSchema,
|
|
10
|
+
} from '../communication/ingress-schema.js'
|
|
11
|
+
import type { PalIngressAuthorizationRequest } from '../communication/ingress-types.js'
|
|
12
|
+
import { addressSchema, freezeCommunicationValue } from '../communication/schema.js'
|
|
13
|
+
import type { PalMessageAuthorization } from '../communication/types.js'
|
|
14
|
+
import { subscriptionSchema } from './subscription-schema.js'
|
|
15
|
+
import type {
|
|
16
|
+
PalActivitySubscriptionAuthorizationRequest,
|
|
17
|
+
PalActivitySubscriptionStore,
|
|
18
|
+
} from './subscription-types.js'
|
|
19
|
+
|
|
20
|
+
export interface PalActivitySubscriptionPermission {
|
|
21
|
+
readonly v: 1
|
|
22
|
+
readonly subscriptionId: string
|
|
23
|
+
readonly revision: number
|
|
24
|
+
readonly observe: boolean
|
|
25
|
+
readonly disclose: boolean
|
|
26
|
+
readonly receive: boolean
|
|
27
|
+
readonly wake: boolean
|
|
28
|
+
}
|
|
29
|
+
export interface PalActivitySubscriptionPermissionUpdate
|
|
30
|
+
extends Omit<PalActivitySubscriptionPermission, 'v' | 'revision'> {
|
|
31
|
+
readonly expectedRevision: number
|
|
32
|
+
}
|
|
33
|
+
export class PalActivitySubscriptionPermissionConflictError extends Error {
|
|
34
|
+
override readonly name = 'PalActivitySubscriptionPermissionConflictError'
|
|
35
|
+
}
|
|
36
|
+
const permissionSchema = z
|
|
37
|
+
.object({
|
|
38
|
+
v: z.literal(1),
|
|
39
|
+
subscriptionId: z.string().uuid(),
|
|
40
|
+
revision: z.number().int().positive().safe(),
|
|
41
|
+
observe: z.boolean(),
|
|
42
|
+
disclose: z.boolean(),
|
|
43
|
+
receive: z.boolean(),
|
|
44
|
+
wake: z.boolean(),
|
|
45
|
+
})
|
|
46
|
+
.strict()
|
|
47
|
+
const updateSchema = permissionSchema
|
|
48
|
+
.omit({ v: true, revision: true })
|
|
49
|
+
.extend({ expectedRevision: z.number().int().nonnegative().safe() })
|
|
50
|
+
const denied = (): PalMessageAuthorization => ({
|
|
51
|
+
allow: false,
|
|
52
|
+
reason: 'No current permission for this exact Pal activity subscription.',
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/** Explicit local operator consent. Missing rules deny and each phase rereads current records. */
|
|
56
|
+
export class DiskPalActivitySubscriptionPolicy {
|
|
57
|
+
private readonly root: string
|
|
58
|
+
private readonly secure: (path: string) => void
|
|
59
|
+
private readonly subscriptions: PalActivitySubscriptionStore
|
|
60
|
+
private readonly records = new DiskRevisionRecordStore<PalActivitySubscriptionPermission>(
|
|
61
|
+
defineSchema({
|
|
62
|
+
kind: 'pal-activity-subscription-permission',
|
|
63
|
+
current: 1,
|
|
64
|
+
migrations: {},
|
|
65
|
+
}),
|
|
66
|
+
'Pal activity subscription permission',
|
|
67
|
+
(value) => value.revision,
|
|
68
|
+
)
|
|
69
|
+
constructor(options: {
|
|
70
|
+
root: string
|
|
71
|
+
subscriptions: PalActivitySubscriptionStore
|
|
72
|
+
secureDirectory?: (path: string) => void
|
|
73
|
+
}) {
|
|
74
|
+
this.root = resolve(options.root)
|
|
75
|
+
this.subscriptions = options.subscriptions
|
|
76
|
+
this.secure =
|
|
77
|
+
options.secureDirectory ??
|
|
78
|
+
((path) => {
|
|
79
|
+
if (process.platform !== 'win32') chmodSync(path, 0o700)
|
|
80
|
+
})
|
|
81
|
+
this.directory(this.root)
|
|
82
|
+
}
|
|
83
|
+
private directory(path: string) {
|
|
84
|
+
mkdirSync(path, { recursive: true, mode: 0o700 })
|
|
85
|
+
const stat = lstatSync(path)
|
|
86
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || realpathSync(path) !== path)
|
|
87
|
+
throw new Error('Pal activity permissions require real directories without aliases.')
|
|
88
|
+
this.secure(path)
|
|
89
|
+
}
|
|
90
|
+
private location(id: string) {
|
|
91
|
+
const key = z.string().uuid().parse(id)
|
|
92
|
+
this.directory(this.root)
|
|
93
|
+
const directory = join(this.root, key)
|
|
94
|
+
this.directory(directory)
|
|
95
|
+
const revisionsDir = join(directory, 'revisions')
|
|
96
|
+
this.directory(revisionsDir)
|
|
97
|
+
for (const name of readdirSync(revisionsDir)) {
|
|
98
|
+
if (!/^[1-9][0-9]*\.json$/u.test(name)) continue
|
|
99
|
+
const stat = lstatSync(join(revisionsDir, name))
|
|
100
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
101
|
+
throw new Error('Pal permission commits must be real files.')
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
legacyPath: join(directory, 'permission.json'),
|
|
105
|
+
revisionsDir,
|
|
106
|
+
publishLegacyProjection: false,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
private checked(input: unknown, id: string) {
|
|
110
|
+
const { schemaVersion: _schemaVersion, ...value } = permissionSchema
|
|
111
|
+
.extend({ schemaVersion: z.literal(1).optional() })
|
|
112
|
+
.parse(input)
|
|
113
|
+
if (value.subscriptionId !== id) throw new Error('Foreign Pal subscription permission.')
|
|
114
|
+
return freezeCommunicationValue(value)
|
|
115
|
+
}
|
|
116
|
+
async get(id: string): Promise<PalActivitySubscriptionPermission | null> {
|
|
117
|
+
const record = await this.records.read(this.location(id))
|
|
118
|
+
return record === null ? null : this.checked(record, id)
|
|
119
|
+
}
|
|
120
|
+
async update(
|
|
121
|
+
input: PalActivitySubscriptionPermissionUpdate,
|
|
122
|
+
): Promise<PalActivitySubscriptionPermission> {
|
|
123
|
+
const captured = updateSchema.parse(input)
|
|
124
|
+
if (!(await this.subscriptions.get(captured.subscriptionId)))
|
|
125
|
+
throw new Error('Unknown Pal activity subscription.')
|
|
126
|
+
return this.records.transact(this.location(captured.subscriptionId), (stored) => {
|
|
127
|
+
const current = stored === null ? null : this.checked(stored, captured.subscriptionId)
|
|
128
|
+
if ((current?.revision ?? 0) !== captured.expectedRevision)
|
|
129
|
+
throw new PalActivitySubscriptionPermissionConflictError(
|
|
130
|
+
'Subscription permission changed; reload before updating.',
|
|
131
|
+
)
|
|
132
|
+
const { expectedRevision, ...values } = captured
|
|
133
|
+
const record = this.checked(
|
|
134
|
+
{ ...values, v: 1, revision: expectedRevision + 1 },
|
|
135
|
+
values.subscriptionId,
|
|
136
|
+
)
|
|
137
|
+
return { record, result: record }
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
async authorizeSubscription(
|
|
141
|
+
request: PalActivitySubscriptionAuthorizationRequest,
|
|
142
|
+
): Promise<PalMessageAuthorization> {
|
|
143
|
+
const phase = z.enum(['observe', 'disclose', 'receive', 'accept']).parse(request.phase)
|
|
144
|
+
const permitted = (rule: PalActivitySubscriptionPermission | null) =>
|
|
145
|
+
phase === 'accept' ? rule?.observe && rule.disclose && rule.receive : rule?.[phase]
|
|
146
|
+
const captured = freezeCommunicationValue(subscriptionSchema.parse(request.subscription))
|
|
147
|
+
const stored = await this.subscriptions.get(captured.id)
|
|
148
|
+
const subscription = stored ? freezeCommunicationValue(subscriptionSchema.parse(stored)) : null
|
|
149
|
+
if (
|
|
150
|
+
!subscription?.enabled ||
|
|
151
|
+
subscription.configurationRevision !== captured.configurationRevision ||
|
|
152
|
+
!isDeepStrictEqual(subscription.scope, captured.scope) ||
|
|
153
|
+
!isDeepStrictEqual(subscription.recipient, captured.recipient)
|
|
154
|
+
)
|
|
155
|
+
return denied()
|
|
156
|
+
const observed = await this.get(subscription.id)
|
|
157
|
+
if (!permitted(observed)) return denied()
|
|
158
|
+
const current = await this.subscriptions.get(subscription.id)
|
|
159
|
+
if (
|
|
160
|
+
!current?.enabled ||
|
|
161
|
+
current.configurationRevision !== captured.configurationRevision ||
|
|
162
|
+
!isDeepStrictEqual(current.scope, captured.scope) ||
|
|
163
|
+
!isDeepStrictEqual(current.recipient, captured.recipient)
|
|
164
|
+
)
|
|
165
|
+
return denied()
|
|
166
|
+
const rule = await this.get(subscription.id)
|
|
167
|
+
if (!rule || !permitted(rule)) return denied()
|
|
168
|
+
return {
|
|
169
|
+
allow: true,
|
|
170
|
+
grant: {
|
|
171
|
+
id: `pal-subscription:${subscription.id}:${phase}`,
|
|
172
|
+
revision: String(rule.revision),
|
|
173
|
+
},
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async authorizeIngress(input: PalIngressAuthorizationRequest): Promise<PalMessageAuthorization> {
|
|
177
|
+
if (!('kind' in input) || input.kind !== 'observation') return denied()
|
|
178
|
+
const request = freezeCommunicationValue(
|
|
179
|
+
z
|
|
180
|
+
.object({
|
|
181
|
+
kind: z.literal('observation'),
|
|
182
|
+
phase: z.enum(['accept', 'deliver', 'wake']),
|
|
183
|
+
source: observationSourceSchema,
|
|
184
|
+
routeKey: observationRouteKeySchema,
|
|
185
|
+
recipient: addressSchema,
|
|
186
|
+
})
|
|
187
|
+
.parse(input),
|
|
188
|
+
)
|
|
189
|
+
const id = z.string().uuid().parse(request.source.subscriptionId)
|
|
190
|
+
const phase = z.enum(['accept', 'deliver', 'wake']).parse(request.phase)
|
|
191
|
+
const stored = await this.subscriptions.get(id)
|
|
192
|
+
const subscription = stored ? freezeCommunicationValue(subscriptionSchema.parse(stored)) : null
|
|
193
|
+
if (
|
|
194
|
+
!subscription?.enabled ||
|
|
195
|
+
request.routeKey.kind !== 'observation' ||
|
|
196
|
+
request.routeKey.subscriptionId !== id ||
|
|
197
|
+
!isDeepStrictEqual(request.source.scope, subscription.scope) ||
|
|
198
|
+
!isDeepStrictEqual(request.routeKey.scope, subscription.scope) ||
|
|
199
|
+
!isDeepStrictEqual(request.recipient, subscription.recipient) ||
|
|
200
|
+
!isDeepStrictEqual(request.routeKey.recipient, subscription.recipient)
|
|
201
|
+
)
|
|
202
|
+
return denied()
|
|
203
|
+
const observed = await this.get(id)
|
|
204
|
+
if (
|
|
205
|
+
!observed?.observe ||
|
|
206
|
+
!observed.disclose ||
|
|
207
|
+
!observed.receive ||
|
|
208
|
+
(phase === 'wake' && !observed.wake)
|
|
209
|
+
)
|
|
210
|
+
return denied()
|
|
211
|
+
const current = await this.subscriptions.get(id)
|
|
212
|
+
if (
|
|
213
|
+
!current?.enabled ||
|
|
214
|
+
current.configurationRevision !== subscription.configurationRevision ||
|
|
215
|
+
!isDeepStrictEqual(current.scope, subscription.scope) ||
|
|
216
|
+
!isDeepStrictEqual(current.recipient, subscription.recipient)
|
|
217
|
+
)
|
|
218
|
+
return denied()
|
|
219
|
+
const rule = await this.get(id)
|
|
220
|
+
if (!rule?.observe || !rule.disclose || !rule.receive || (phase === 'wake' && !rule.wake))
|
|
221
|
+
return denied()
|
|
222
|
+
return {
|
|
223
|
+
allow: true,
|
|
224
|
+
grant: {
|
|
225
|
+
id: `pal-subscription:${id}:${phase}`,
|
|
226
|
+
revision: String(rule.revision),
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { activityCursorSchema, activityScopeSchema } from '../communication/ingress-schema.js'
|
|
3
|
+
import { addressSchema } from '../communication/schema.js'
|
|
4
|
+
|
|
5
|
+
const positive = z.number().int().positive().safe()
|
|
6
|
+
export const subscriptionScopeSchema = activityScopeSchema
|
|
7
|
+
export const subscriptionCursorSchema = activityCursorSchema
|
|
8
|
+
const subscriptionObjectSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
v: z.literal(1),
|
|
11
|
+
id: z.string().uuid(),
|
|
12
|
+
revision: positive,
|
|
13
|
+
configurationRevision: positive,
|
|
14
|
+
scope: subscriptionScopeSchema,
|
|
15
|
+
recipient: addressSchema,
|
|
16
|
+
enabled: z.boolean(),
|
|
17
|
+
cursor: subscriptionCursorSchema.nullable(),
|
|
18
|
+
})
|
|
19
|
+
.strict()
|
|
20
|
+
export const subscriptionSchema = subscriptionObjectSchema.refine(
|
|
21
|
+
(v) => v.scope.tenantId === v.recipient.tenantId,
|
|
22
|
+
'Cross-tenant observation is refused.',
|
|
23
|
+
)
|
|
24
|
+
export const storedSubscriptionSchema = subscriptionObjectSchema
|
|
25
|
+
.extend({ schemaVersion: z.literal(1).optional() })
|
|
26
|
+
.transform(({ schemaVersion: _schemaVersion, ...value }) => value)
|
|
27
|
+
.pipe(subscriptionSchema)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { chmodSync, lstatSync, mkdirSync, readdirSync, realpathSync } from 'node:fs'
|
|
2
|
+
import { join, resolve } from 'node:path'
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
import { DiskRevisionRecordStore } from '../../store/kv/revision-record-store.js'
|
|
6
|
+
import { defineSchema } from '../../store/schema.js'
|
|
7
|
+
import { freezeCommunicationValue } from '../communication/schema.js'
|
|
8
|
+
import {
|
|
9
|
+
storedSubscriptionSchema,
|
|
10
|
+
subscriptionCursorSchema,
|
|
11
|
+
subscriptionSchema,
|
|
12
|
+
} from './subscription-schema.js'
|
|
13
|
+
import type { PalActivitySubscription, PalActivitySubscriptionStore } from './subscription-types.js'
|
|
14
|
+
import type { PalActivityCursor } from './types.js'
|
|
15
|
+
|
|
16
|
+
export class PalActivitySubscriptionConflictError extends Error {
|
|
17
|
+
override readonly name = 'PalActivitySubscriptionConflictError'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Private immutable revision commits. No cursors are accepted from a client or model. */
|
|
21
|
+
export class DiskPalActivitySubscriptionStore implements PalActivitySubscriptionStore {
|
|
22
|
+
private readonly root: string
|
|
23
|
+
private readonly secure: (path: string) => void
|
|
24
|
+
private readonly records = new DiskRevisionRecordStore<PalActivitySubscription>(
|
|
25
|
+
defineSchema({
|
|
26
|
+
kind: 'pal-activity-subscription',
|
|
27
|
+
current: 1,
|
|
28
|
+
migrations: {},
|
|
29
|
+
}),
|
|
30
|
+
'Pal activity subscription',
|
|
31
|
+
(value) => value.revision,
|
|
32
|
+
)
|
|
33
|
+
constructor(options: {
|
|
34
|
+
root: string
|
|
35
|
+
secureDirectory?: (path: string) => void
|
|
36
|
+
}) {
|
|
37
|
+
this.root = resolve(options.root)
|
|
38
|
+
this.secure =
|
|
39
|
+
options.secureDirectory ??
|
|
40
|
+
((path) => {
|
|
41
|
+
if (process.platform !== 'win32') chmodSync(path, 0o700)
|
|
42
|
+
})
|
|
43
|
+
this.directory(this.root)
|
|
44
|
+
}
|
|
45
|
+
private directory(path: string) {
|
|
46
|
+
mkdirSync(path, { recursive: true, mode: 0o700 })
|
|
47
|
+
const stat = lstatSync(path)
|
|
48
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || realpathSync(path) !== path)
|
|
49
|
+
throw new Error('Pal subscriptions require real directories without aliases.')
|
|
50
|
+
this.secure(path)
|
|
51
|
+
}
|
|
52
|
+
private location(input: string) {
|
|
53
|
+
const id = z.string().uuid().parse(input)
|
|
54
|
+
this.directory(this.root)
|
|
55
|
+
const directory = join(this.root, id)
|
|
56
|
+
this.directory(directory)
|
|
57
|
+
const revisionsDir = join(directory, 'revisions')
|
|
58
|
+
this.directory(revisionsDir)
|
|
59
|
+
for (const name of readdirSync(revisionsDir)) {
|
|
60
|
+
if (!/^[1-9][0-9]*\.json$/u.test(name)) continue
|
|
61
|
+
const stat = lstatSync(join(revisionsDir, name))
|
|
62
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
63
|
+
throw new Error('Pal subscription commits must be real files.')
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
legacyPath: join(directory, 'subscription.json'),
|
|
67
|
+
revisionsDir,
|
|
68
|
+
publishLegacyProjection: false,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
private checked(input: unknown, id: string): PalActivitySubscription {
|
|
72
|
+
const value = storedSubscriptionSchema.parse(input)
|
|
73
|
+
if (value.id !== id || value.configurationRevision > value.revision)
|
|
74
|
+
throw new Error('Foreign or invalid Pal activity subscription.')
|
|
75
|
+
return freezeCommunicationValue(value)
|
|
76
|
+
}
|
|
77
|
+
async get(id: string): Promise<PalActivitySubscription | null> {
|
|
78
|
+
const value = await this.records.read(this.location(id))
|
|
79
|
+
return value === null ? null : this.checked(value, id)
|
|
80
|
+
}
|
|
81
|
+
/** Complete current records for trusted host projection; a bad record rejects the whole list. */
|
|
82
|
+
async list(): Promise<readonly PalActivitySubscription[]> {
|
|
83
|
+
try {
|
|
84
|
+
const entry = lstatSync(this.root)
|
|
85
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || realpathSync(this.root) !== this.root)
|
|
86
|
+
throw new Error('Pal subscriptions require real directories without aliases.')
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return Object.freeze([])
|
|
89
|
+
throw error
|
|
90
|
+
}
|
|
91
|
+
const subscriptions: PalActivitySubscription[] = []
|
|
92
|
+
for (const name of readdirSync(this.root).sort()) {
|
|
93
|
+
if (!z.string().uuid().safeParse(name).success) continue
|
|
94
|
+
const value = await this.get(name)
|
|
95
|
+
if (value) subscriptions.push(value)
|
|
96
|
+
}
|
|
97
|
+
return Object.freeze(subscriptions)
|
|
98
|
+
}
|
|
99
|
+
async create(input: Parameters<PalActivitySubscriptionStore['create']>[0]) {
|
|
100
|
+
const value = subscriptionSchema.parse({
|
|
101
|
+
...input,
|
|
102
|
+
v: 1,
|
|
103
|
+
revision: 1,
|
|
104
|
+
configurationRevision: 1,
|
|
105
|
+
cursor: null,
|
|
106
|
+
})
|
|
107
|
+
const proposed = this.checked(value, value.id)
|
|
108
|
+
return this.records.transact(this.location(proposed.id), (stored) => {
|
|
109
|
+
if (stored !== null)
|
|
110
|
+
throw new PalActivitySubscriptionConflictError('Subscription identity already exists.')
|
|
111
|
+
return { record: proposed, result: proposed }
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
async setEnabled(input: Parameters<PalActivitySubscriptionStore['setEnabled']>[0]) {
|
|
115
|
+
const captured = z
|
|
116
|
+
.object({
|
|
117
|
+
id: z.string().uuid(),
|
|
118
|
+
expectedRevision: z.number().int().positive().safe(),
|
|
119
|
+
enabled: z.boolean(),
|
|
120
|
+
})
|
|
121
|
+
.strict()
|
|
122
|
+
.parse(input)
|
|
123
|
+
return this.records.transact(this.location(captured.id), (stored) => {
|
|
124
|
+
const current = stored === null ? null : this.checked(stored, captured.id)
|
|
125
|
+
if (!current || current.revision !== captured.expectedRevision)
|
|
126
|
+
throw new PalActivitySubscriptionConflictError(
|
|
127
|
+
'Subscription changed; reload before changing consent.',
|
|
128
|
+
)
|
|
129
|
+
const record = this.checked(
|
|
130
|
+
{
|
|
131
|
+
...current,
|
|
132
|
+
enabled: captured.enabled,
|
|
133
|
+
revision: current.revision + 1,
|
|
134
|
+
configurationRevision: current.configurationRevision + 1,
|
|
135
|
+
},
|
|
136
|
+
current.id,
|
|
137
|
+
)
|
|
138
|
+
return { record, result: record }
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
async advance(input: PalActivitySubscription, inputCursor: PalActivityCursor) {
|
|
142
|
+
const parsed = subscriptionSchema.parse(input)
|
|
143
|
+
const captured = this.checked(parsed, parsed.id)
|
|
144
|
+
const cursor = freezeCommunicationValue(subscriptionCursorSchema.parse(inputCursor))
|
|
145
|
+
if (cursor.after.seq < cursor.root.seq || cursor.after.offset < cursor.root.offset)
|
|
146
|
+
throw new Error('Subscription cursor cannot precede its root.')
|
|
147
|
+
if (captured.cursor) {
|
|
148
|
+
const previous = captured.cursor
|
|
149
|
+
if (
|
|
150
|
+
cursor.scopeHash !== previous.scopeHash ||
|
|
151
|
+
!isDeepStrictEqual(cursor.root, previous.root) ||
|
|
152
|
+
cursor.after.seq < previous.after.seq ||
|
|
153
|
+
cursor.after.offset < previous.after.offset ||
|
|
154
|
+
cursor.generation < previous.generation ||
|
|
155
|
+
(cursor.after.seq === previous.after.seq && !isDeepStrictEqual(cursor, previous))
|
|
156
|
+
)
|
|
157
|
+
throw new Error('Subscription cursor identity changed or moved backwards.')
|
|
158
|
+
}
|
|
159
|
+
return this.records.transact(this.location(captured.id), (stored) => {
|
|
160
|
+
const current = stored === null ? null : this.checked(stored, captured.id)
|
|
161
|
+
if (!current || !current.enabled || !isDeepStrictEqual(current, captured))
|
|
162
|
+
throw new PalActivitySubscriptionConflictError(
|
|
163
|
+
'Subscription changed before accepted progress could commit.',
|
|
164
|
+
)
|
|
165
|
+
const record = this.checked(
|
|
166
|
+
{ ...current, revision: current.revision + 1, cursor },
|
|
167
|
+
current.id,
|
|
168
|
+
)
|
|
169
|
+
return { record, result: record }
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
}
|