@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,928 @@
|
|
|
1
|
+
import { posix, win32 } from 'node:path';
|
|
2
|
+
import { HarnessBindingSchema, HarnessDecisionSchema, HarnessEventSchema, HarnessNativeTurnSchema, HarnessReviewRequestSchema, harnessSnapshot, } from '../../types/harness/schema.js';
|
|
3
|
+
import { generateMessageId, generateToolCallId, generateTurnId, isEntityId, } from '../../utils/id.js';
|
|
4
|
+
import { HarnessJournal, HarnessSessionError, harnessDigest } from './journal.js';
|
|
5
|
+
import { engineSavedView } from './saved-view.js';
|
|
6
|
+
/** Vendor execution remains outside the Namzu query kernel and tool executor. */
|
|
7
|
+
export function createHarnessSession(options) {
|
|
8
|
+
return new ExternalHarnessSession(options);
|
|
9
|
+
}
|
|
10
|
+
export { HarnessSessionError } from './journal.js';
|
|
11
|
+
class ExternalHarnessSession {
|
|
12
|
+
scope;
|
|
13
|
+
journal;
|
|
14
|
+
openAdapter;
|
|
15
|
+
admit;
|
|
16
|
+
publish;
|
|
17
|
+
review;
|
|
18
|
+
currentBinding;
|
|
19
|
+
connection;
|
|
20
|
+
active;
|
|
21
|
+
phase = 'disconnected';
|
|
22
|
+
operation = false;
|
|
23
|
+
cancelling = false;
|
|
24
|
+
epoch = 0;
|
|
25
|
+
events = Promise.resolve();
|
|
26
|
+
eventError;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.scope = harnessSnapshot(options.scope);
|
|
29
|
+
if (!isEntityId(this.scope.sessionId, 'session') ||
|
|
30
|
+
!isEntityId(this.scope.projectId, 'project') ||
|
|
31
|
+
!isEntityId(this.scope.tenantId, 'tenant') ||
|
|
32
|
+
!isEntityId(this.scope.topicId, 'topic') ||
|
|
33
|
+
!(posix.isAbsolute(this.scope.cwd) || win32.isAbsolute(this.scope.cwd)) ||
|
|
34
|
+
Array.from(this.scope.cwd).some((c) => c.charCodeAt(0) < 32))
|
|
35
|
+
throw new HarnessSessionError('invalid-scope', 'An exact owner scope and canonical absolute native directory are required.');
|
|
36
|
+
if (typeof options.assertAdmission !== 'function' ||
|
|
37
|
+
typeof options.onEvent !== 'function' ||
|
|
38
|
+
typeof options.onReview !== 'function')
|
|
39
|
+
throw new HarnessSessionError('invalid-host', 'Explicit admission, event and review host ports are required.');
|
|
40
|
+
this.journal = new HarnessJournal(options.sessionLog, this.scope, options.adapter.engineId, options.adapter.profileRef);
|
|
41
|
+
this.openAdapter = options.adapter.open.bind(options.adapter);
|
|
42
|
+
this.admit = options.assertAdmission;
|
|
43
|
+
this.publish = options.onEvent;
|
|
44
|
+
this.review = options.onReview;
|
|
45
|
+
}
|
|
46
|
+
get binding() {
|
|
47
|
+
return this.currentBinding;
|
|
48
|
+
}
|
|
49
|
+
get currentTurnId() {
|
|
50
|
+
return this.active?.turnId;
|
|
51
|
+
}
|
|
52
|
+
get status() {
|
|
53
|
+
return this.phase;
|
|
54
|
+
}
|
|
55
|
+
hasUnresolved() {
|
|
56
|
+
return (!!this.active || this.phase === 'reconciliation-required' || this.eventError !== undefined);
|
|
57
|
+
}
|
|
58
|
+
reserve() {
|
|
59
|
+
if (this.phase === 'closed')
|
|
60
|
+
throw new HarnessSessionError('closed', 'This harness session is closed.');
|
|
61
|
+
if (this.operation || this.cancelling)
|
|
62
|
+
throw new HarnessSessionError('busy', 'Another harness operation is pending.');
|
|
63
|
+
this.operation = true;
|
|
64
|
+
let released = false;
|
|
65
|
+
return () => {
|
|
66
|
+
if (released)
|
|
67
|
+
return;
|
|
68
|
+
released = true;
|
|
69
|
+
this.operation = false;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async authorize(kind, signal, request) {
|
|
73
|
+
if (signal?.aborted)
|
|
74
|
+
throw new HarnessSessionError('aborted', 'The operation was aborted before dispatch.');
|
|
75
|
+
await this.admit(harnessSnapshot({
|
|
76
|
+
kind,
|
|
77
|
+
scope: this.scope,
|
|
78
|
+
...(this.currentBinding ? { binding: this.currentBinding } : {}),
|
|
79
|
+
...(this.active?.nativeTurn ? { nativeTurn: this.active.nativeTurn } : {}),
|
|
80
|
+
...(request ? { review: request } : {}),
|
|
81
|
+
}), signal);
|
|
82
|
+
if (signal?.aborted)
|
|
83
|
+
throw new HarnessSessionError('aborted', 'The operation was aborted before dispatch.');
|
|
84
|
+
}
|
|
85
|
+
async history() {
|
|
86
|
+
const state = await this.journal.inspect();
|
|
87
|
+
this.currentBinding ??= state.binding;
|
|
88
|
+
return harnessSnapshot(await this.journal.log.messages());
|
|
89
|
+
}
|
|
90
|
+
requireConnection() {
|
|
91
|
+
if (!this.connection)
|
|
92
|
+
throw new HarnessSessionError('disconnected', 'The native connection is not ready.');
|
|
93
|
+
return this.connection;
|
|
94
|
+
}
|
|
95
|
+
capture(connection) {
|
|
96
|
+
const binding = harnessSnapshot(HarnessBindingSchema.parse(connection.binding));
|
|
97
|
+
this.journal.validateBinding(binding);
|
|
98
|
+
if (this.currentBinding && harnessDigest(this.currentBinding) !== harnessDigest(binding))
|
|
99
|
+
throw new HarnessSessionError('binding-mismatch', 'The adapter resumed a different native session.');
|
|
100
|
+
return Object.freeze({
|
|
101
|
+
binding,
|
|
102
|
+
capabilities: harnessSnapshot(connection.capabilities),
|
|
103
|
+
models: connection.models.bind(connection),
|
|
104
|
+
dispatch: connection.dispatch.bind(connection),
|
|
105
|
+
interrupt: connection.interrupt.bind(connection),
|
|
106
|
+
respond: connection.respond.bind(connection),
|
|
107
|
+
readHistory: connection.readHistory.bind(connection),
|
|
108
|
+
close: connection.close.bind(connection),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async connect(model, signal) {
|
|
112
|
+
if (this.connection)
|
|
113
|
+
return;
|
|
114
|
+
const stored = await this.journal.inspect();
|
|
115
|
+
this.currentBinding = stored.binding;
|
|
116
|
+
await this.authorize(stored.binding ? 'reconnect' : 'open', signal);
|
|
117
|
+
await this.journal.claim();
|
|
118
|
+
await this.authorize(stored.binding ? 'reconnect' : 'open', signal);
|
|
119
|
+
const epoch = ++this.epoch;
|
|
120
|
+
let accepting = false;
|
|
121
|
+
const early = [];
|
|
122
|
+
let earlyBytes = 0;
|
|
123
|
+
const sink = (input) => {
|
|
124
|
+
if (epoch !== this.epoch || this.phase === 'closed')
|
|
125
|
+
return Promise.resolve();
|
|
126
|
+
let event;
|
|
127
|
+
try {
|
|
128
|
+
event = harnessSnapshot(HarnessEventSchema.parse(input));
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
return this.enqueueTask(() => Promise.reject(error), epoch);
|
|
132
|
+
}
|
|
133
|
+
if (!accepting) {
|
|
134
|
+
earlyBytes += JSON.stringify(event).length;
|
|
135
|
+
if (early.length >= 256 || earlyBytes > 1024 * 1024)
|
|
136
|
+
return this.enqueueTask(() => Promise.reject(new HarnessSessionError('early-events-overflow', 'The adapter exceeded the bounded pre-binding event queue.')), epoch);
|
|
137
|
+
early.push(event);
|
|
138
|
+
return Promise.resolve();
|
|
139
|
+
}
|
|
140
|
+
return this.enqueue(event, epoch);
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
const opened = await this.openAdapter({
|
|
144
|
+
cwd: this.scope.cwd,
|
|
145
|
+
...(model ? { model } : {}),
|
|
146
|
+
...(stored.binding ? { resume: stored.binding } : {}),
|
|
147
|
+
...(signal ? { signal } : {}),
|
|
148
|
+
}, sink);
|
|
149
|
+
// Retain even an invalid returned handle until owned cleanup is confirmed.
|
|
150
|
+
this.connection = opened;
|
|
151
|
+
this.connection = this.capture(opened);
|
|
152
|
+
this.currentBinding = this.connection.binding;
|
|
153
|
+
await this.authorize(stored.binding ? 'reconnect' : 'open', signal);
|
|
154
|
+
await this.journal.start(this.currentBinding);
|
|
155
|
+
await this.restoreActive(stored.transitions);
|
|
156
|
+
accepting = true;
|
|
157
|
+
for (const event of early)
|
|
158
|
+
await this.enqueue(event, epoch);
|
|
159
|
+
if (stored.binding && !this.active && this.connection.capabilities.history === 'snapshot') {
|
|
160
|
+
const snapshot = harnessSnapshot(await this.connection.readHistory(signal));
|
|
161
|
+
if (!snapshot.complete ||
|
|
162
|
+
harnessDigest(snapshot.binding) !== harnessDigest(this.currentBinding) ||
|
|
163
|
+
snapshot.activeTurn ||
|
|
164
|
+
snapshot.pendingReviews.length)
|
|
165
|
+
throw new HarnessSessionError('reconciliation-required', 'Native session history did not confirm an idle exact binding.');
|
|
166
|
+
}
|
|
167
|
+
if (!this.active && this.phase !== 'reconciliation-required')
|
|
168
|
+
this.phase = 'idle';
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (this.connection) {
|
|
172
|
+
try {
|
|
173
|
+
await this.connection.close();
|
|
174
|
+
this.connection = undefined;
|
|
175
|
+
++this.epoch;
|
|
176
|
+
await this.journal.release();
|
|
177
|
+
}
|
|
178
|
+
catch (cleanup) {
|
|
179
|
+
this.phase = 'reconciliation-required';
|
|
180
|
+
throw new AggregateError([error, cleanup], 'Harness open failed and its process could not be confirmed stopped.');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else
|
|
184
|
+
await this.journal.release();
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
makeActive(turnId, operationId, startedAt) {
|
|
189
|
+
let resolve;
|
|
190
|
+
let reject;
|
|
191
|
+
const done = new Promise((yes, no) => {
|
|
192
|
+
resolve = yes;
|
|
193
|
+
reject = no;
|
|
194
|
+
});
|
|
195
|
+
void done.catch(() => undefined);
|
|
196
|
+
return {
|
|
197
|
+
turnId,
|
|
198
|
+
operationId,
|
|
199
|
+
startedAt,
|
|
200
|
+
items: new Map(),
|
|
201
|
+
reviews: new Map(),
|
|
202
|
+
resolve,
|
|
203
|
+
reject,
|
|
204
|
+
done,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
async restoreActive(transitions) {
|
|
208
|
+
const pending = await this.journal.log.activeTurn({ lease: await this.journal.current() });
|
|
209
|
+
if (!pending) {
|
|
210
|
+
this.active?.removeAbort?.();
|
|
211
|
+
this.active = undefined;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const prepared = [...transitions]
|
|
215
|
+
.reverse()
|
|
216
|
+
.find((e) => e.kind === 'dispatch-prepared' && e.turnId === pending.turnId);
|
|
217
|
+
if (!prepared || prepared.kind !== 'dispatch-prepared')
|
|
218
|
+
throw new HarnessSessionError('invalid-journal', 'The active harness turn has no prepared dispatch receipt.');
|
|
219
|
+
const active = this.makeActive(pending.turnId, prepared.operationId, Date.now());
|
|
220
|
+
for (const entry of transitions) {
|
|
221
|
+
if (!('turnId' in entry) || entry.turnId !== pending.turnId)
|
|
222
|
+
continue;
|
|
223
|
+
if (entry.kind === 'dispatch-accepted') {
|
|
224
|
+
if (entry.operationId !== active.operationId)
|
|
225
|
+
throw new HarnessSessionError('invalid-journal', 'Dispatch receipt does not match the prepared operation.');
|
|
226
|
+
this.validateNative(entry.nativeTurn, active);
|
|
227
|
+
active.nativeTurn = harnessSnapshot(entry.nativeTurn);
|
|
228
|
+
}
|
|
229
|
+
else if (entry.kind === 'item-bound') {
|
|
230
|
+
this.validateNative(entry.nativeItem, active);
|
|
231
|
+
active.items.set(entry.nativeItem.nativeItemId, {
|
|
232
|
+
messageId: entry.messageId,
|
|
233
|
+
toolUseId: entry.toolUseId,
|
|
234
|
+
started: false,
|
|
235
|
+
content: '',
|
|
236
|
+
blocks: new Map(),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
else if (entry.kind === 'review-requested') {
|
|
240
|
+
this.validateNative(entry.request, active);
|
|
241
|
+
if (harnessDigest(entry.request) !== entry.digest)
|
|
242
|
+
throw new HarnessSessionError('invalid-journal', 'The native review digest does not match its captured request.');
|
|
243
|
+
active.reviews.set(entry.request.requestId, {
|
|
244
|
+
request: harnessSnapshot(entry.request),
|
|
245
|
+
digest: entry.digest,
|
|
246
|
+
resolved: false,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
else if (entry.kind === 'review-decided') {
|
|
250
|
+
const review = active.reviews.get(entry.requestId);
|
|
251
|
+
if (!review ||
|
|
252
|
+
review.digest !== entry.requestDigest ||
|
|
253
|
+
harnessDigest(entry.decision) !== entry.decisionDigest)
|
|
254
|
+
throw new HarnessSessionError('invalid-journal', 'The native decision does not match its recorded request.');
|
|
255
|
+
review.decision = entry.decisionDigest;
|
|
256
|
+
}
|
|
257
|
+
else if (entry.kind === 'review-resolved') {
|
|
258
|
+
const review = active.reviews.get(entry.requestId);
|
|
259
|
+
if (review)
|
|
260
|
+
review.resolved = true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const { entries } = await this.journal.log.readAll();
|
|
264
|
+
for (const { record } of entries) {
|
|
265
|
+
if (record.turnId !== active.turnId)
|
|
266
|
+
continue;
|
|
267
|
+
if (record.type === 'turn_started')
|
|
268
|
+
active.startedAt = Date.parse(record.ts);
|
|
269
|
+
if (record.type === 'message')
|
|
270
|
+
for (const item of active.items.values())
|
|
271
|
+
if (item.messageId === record.messageId && record.role === 'assistant') {
|
|
272
|
+
item.started = true;
|
|
273
|
+
item.completed = harnessDigest(record.content);
|
|
274
|
+
item.content = typeof record.content.content === 'string' ? record.content.content : '';
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
this.active = active;
|
|
278
|
+
this.phase = 'reconciliation-required';
|
|
279
|
+
}
|
|
280
|
+
async run(input) {
|
|
281
|
+
const signal = input.signal;
|
|
282
|
+
const prompt = harnessSnapshot({
|
|
283
|
+
prompt: input.prompt,
|
|
284
|
+
model: input.model,
|
|
285
|
+
permissionMode: input.permissionMode,
|
|
286
|
+
...(input.effort ? { effort: input.effort } : {}),
|
|
287
|
+
});
|
|
288
|
+
const release = this.reserve();
|
|
289
|
+
if (!prompt.prompt ||
|
|
290
|
+
prompt.prompt.length > 1024 * 1024 ||
|
|
291
|
+
!prompt.model ||
|
|
292
|
+
prompt.model.length > 4096) {
|
|
293
|
+
release();
|
|
294
|
+
throw new HarnessSessionError('invalid-prompt', 'A bounded prompt and explicit model are required.');
|
|
295
|
+
}
|
|
296
|
+
let active;
|
|
297
|
+
let dispatchInvoked = false;
|
|
298
|
+
try {
|
|
299
|
+
if (this.hasUnresolved())
|
|
300
|
+
throw new HarnessSessionError('reconciliation-required', 'A previous turn must be reconciled before sending another prompt.');
|
|
301
|
+
await this.connect(prompt.model, signal);
|
|
302
|
+
if (this.hasUnresolved())
|
|
303
|
+
throw new HarnessSessionError('reconciliation-required', 'The journal contains an unresolved native dispatch; it will not be resent.');
|
|
304
|
+
const connection = this.connection;
|
|
305
|
+
if (!connection.capabilities.reviewModes.includes(prompt.permissionMode))
|
|
306
|
+
throw new HarnessSessionError('unsupported-mode', 'This harness does not support the selected review mode.');
|
|
307
|
+
if (prompt.effort && !connection.capabilities.effortLevels?.includes(prompt.effort))
|
|
308
|
+
throw new HarnessSessionError('unsupported-effort', 'This harness does not support the selected effort.');
|
|
309
|
+
await this.authorize('run', signal);
|
|
310
|
+
const lease = await this.journal.current();
|
|
311
|
+
const turnId = generateTurnId();
|
|
312
|
+
const promptId = generateMessageId();
|
|
313
|
+
const operationId = `${turnId}:${promptId}`;
|
|
314
|
+
active = this.makeActive(turnId, operationId, Date.now());
|
|
315
|
+
this.active = active;
|
|
316
|
+
const entry = await this.journal.log.beginTurn(lease, {
|
|
317
|
+
turnId,
|
|
318
|
+
userMessageId: promptId,
|
|
319
|
+
config: { model: prompt.model, tokenBudget: 0, timeoutMs: 0 },
|
|
320
|
+
origin: { protocol: 'sdk', kind: 'prompt' },
|
|
321
|
+
});
|
|
322
|
+
await this.journal.append({
|
|
323
|
+
type: 'message',
|
|
324
|
+
turnId,
|
|
325
|
+
messageId: promptId,
|
|
326
|
+
role: 'user',
|
|
327
|
+
kind: 'prompt',
|
|
328
|
+
content: { role: 'user', content: prompt.prompt },
|
|
329
|
+
});
|
|
330
|
+
await this.journal.transition({
|
|
331
|
+
kind: 'dispatch-prepared',
|
|
332
|
+
model: prompt.model,
|
|
333
|
+
permissionMode: prompt.permissionMode,
|
|
334
|
+
...(prompt.effort ? { effort: prompt.effort } : {}),
|
|
335
|
+
operationId,
|
|
336
|
+
turnId,
|
|
337
|
+
promptId,
|
|
338
|
+
digest: harnessDigest(prompt),
|
|
339
|
+
});
|
|
340
|
+
this.phase = 'running';
|
|
341
|
+
await this.publish({
|
|
342
|
+
type: 'turn_started',
|
|
343
|
+
sessionId: this.scope.sessionId,
|
|
344
|
+
turnId,
|
|
345
|
+
userMessageId: promptId,
|
|
346
|
+
config: { model: prompt.model, tokenBudget: 0, timeoutMs: 0 },
|
|
347
|
+
v: 1,
|
|
348
|
+
seq: entry.record.seq,
|
|
349
|
+
generation: entry.record.gen,
|
|
350
|
+
});
|
|
351
|
+
// Recheck current host authority and writer immediately before the external effect.
|
|
352
|
+
await this.authorize('run', signal);
|
|
353
|
+
await this.journal.current();
|
|
354
|
+
if (signal) {
|
|
355
|
+
const ownTurn = active;
|
|
356
|
+
const abort = () => {
|
|
357
|
+
ownTurn.abortRequested = true;
|
|
358
|
+
if (ownTurn.nativeTurn)
|
|
359
|
+
void this.cancel(ownTurn.turnId).catch((error) => ownTurn.reject(error));
|
|
360
|
+
};
|
|
361
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
362
|
+
active.removeAbort = () => signal.removeEventListener('abort', abort);
|
|
363
|
+
}
|
|
364
|
+
release(); // cancellation/review is admitted while the durable native turn runs
|
|
365
|
+
dispatchInvoked = true;
|
|
366
|
+
const nativeTurn = harnessSnapshot(HarnessNativeTurnSchema.parse(await connection.dispatch({ ...prompt, operationId, ...(signal ? { signal } : {}) })));
|
|
367
|
+
await this.events;
|
|
368
|
+
if (this.eventError)
|
|
369
|
+
throw this.eventError;
|
|
370
|
+
if (this.active === active)
|
|
371
|
+
await this.bindNative(nativeTurn, active);
|
|
372
|
+
else
|
|
373
|
+
this.validateNative(nativeTurn, active); // terminal before ACK must not reactivate
|
|
374
|
+
return await active.done;
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
if (active && this.active === active) {
|
|
378
|
+
if (dispatchInvoked)
|
|
379
|
+
await this.uncertain('dispatch-unconfirmed', error);
|
|
380
|
+
else
|
|
381
|
+
await this.failBeforeDispatch(active);
|
|
382
|
+
}
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
finally {
|
|
386
|
+
release();
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async failBeforeDispatch(active) {
|
|
390
|
+
const settlement = this.settlement(active, 'failed');
|
|
391
|
+
await this.emit(active, {
|
|
392
|
+
type: 'turn_failed',
|
|
393
|
+
error: 'The host refused this prompt before native dispatch.',
|
|
394
|
+
settlement,
|
|
395
|
+
});
|
|
396
|
+
active.removeAbort?.();
|
|
397
|
+
active.reject(new HarnessSessionError('dispatch-refused', 'No native dispatch occurred.'));
|
|
398
|
+
this.active = undefined;
|
|
399
|
+
this.phase = 'idle';
|
|
400
|
+
}
|
|
401
|
+
validateNative(native, active) {
|
|
402
|
+
if (native.nativeSessionId !== this.currentBinding?.nativeSessionId ||
|
|
403
|
+
(native.turnIdSource === 'operation' && native.nativeTurnId !== active.operationId))
|
|
404
|
+
throw new HarnessSessionError('native-owner-mismatch', 'Native event does not belong to this session and dispatch operation.');
|
|
405
|
+
if (active.nativeTurn &&
|
|
406
|
+
(active.nativeTurn.nativeSessionId !== native.nativeSessionId ||
|
|
407
|
+
active.nativeTurn.nativeTurnId !== native.nativeTurnId ||
|
|
408
|
+
(active.nativeTurn.turnIdSource ?? 'engine') !== (native.turnIdSource ?? 'engine')))
|
|
409
|
+
throw new HarnessSessionError('native-turn-mismatch', 'Native event names a different turn.');
|
|
410
|
+
}
|
|
411
|
+
async bindNative(native, active) {
|
|
412
|
+
this.validateNative(native, active);
|
|
413
|
+
if (active.nativeTurn)
|
|
414
|
+
return;
|
|
415
|
+
active.nativeTurn = harnessSnapshot({
|
|
416
|
+
nativeSessionId: native.nativeSessionId,
|
|
417
|
+
nativeTurnId: native.nativeTurnId,
|
|
418
|
+
...(native.turnIdSource ? { turnIdSource: native.turnIdSource } : {}),
|
|
419
|
+
});
|
|
420
|
+
await this.journal.transition({
|
|
421
|
+
kind: 'dispatch-accepted',
|
|
422
|
+
operationId: active.operationId,
|
|
423
|
+
turnId: active.turnId,
|
|
424
|
+
nativeTurn: active.nativeTurn,
|
|
425
|
+
});
|
|
426
|
+
if (active.abortRequested)
|
|
427
|
+
void this.cancel(active.turnId).catch((error) => active.reject(error));
|
|
428
|
+
}
|
|
429
|
+
enqueue(event, epoch) {
|
|
430
|
+
return this.enqueueTask(() => this.consume(event), epoch);
|
|
431
|
+
}
|
|
432
|
+
enqueueTask(operation, epoch) {
|
|
433
|
+
const next = this.events.then(async () => {
|
|
434
|
+
if (epoch !== this.epoch)
|
|
435
|
+
return;
|
|
436
|
+
if (this.eventError !== undefined)
|
|
437
|
+
throw this.eventError;
|
|
438
|
+
await operation();
|
|
439
|
+
});
|
|
440
|
+
this.events = next.catch(async (error) => {
|
|
441
|
+
if (this.eventError === undefined) {
|
|
442
|
+
this.eventError = error;
|
|
443
|
+
await this.uncertain('event-rejected', error);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
return next;
|
|
447
|
+
}
|
|
448
|
+
async uncertain(code, error) {
|
|
449
|
+
this.phase = 'reconciliation-required';
|
|
450
|
+
const active = this.active;
|
|
451
|
+
active?.removeAbort?.();
|
|
452
|
+
active?.reject(error);
|
|
453
|
+
try {
|
|
454
|
+
await this.journal.transition({
|
|
455
|
+
kind: 'connection-lost',
|
|
456
|
+
...(active ? { turnId: active.turnId } : {}),
|
|
457
|
+
code,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
catch {
|
|
461
|
+
/* writer failure remains retained; never report confirmed stop */
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
async item(native, active, kind) {
|
|
465
|
+
let item = active.items.get(native.nativeItemId);
|
|
466
|
+
if (!item) {
|
|
467
|
+
item = { started: false, content: '', blocks: new Map() };
|
|
468
|
+
active.items.set(native.nativeItemId, item);
|
|
469
|
+
}
|
|
470
|
+
if (kind === 'message' && !item.messageId)
|
|
471
|
+
item.messageId = generateMessageId();
|
|
472
|
+
else if (kind === 'tool' && !item.toolUseId)
|
|
473
|
+
item.toolUseId = generateToolCallId();
|
|
474
|
+
else
|
|
475
|
+
return item;
|
|
476
|
+
await this.journal.transition({
|
|
477
|
+
kind: 'item-bound',
|
|
478
|
+
turnId: active.turnId,
|
|
479
|
+
nativeItem: {
|
|
480
|
+
nativeSessionId: native.nativeSessionId,
|
|
481
|
+
nativeTurnId: native.nativeTurnId,
|
|
482
|
+
nativeItemId: native.nativeItemId,
|
|
483
|
+
...(native.turnIdSource ? { turnIdSource: native.turnIdSource } : {}),
|
|
484
|
+
},
|
|
485
|
+
...(item.messageId ? { messageId: item.messageId } : {}),
|
|
486
|
+
...(item.toolUseId ? { toolUseId: item.toolUseId } : {}),
|
|
487
|
+
});
|
|
488
|
+
return item;
|
|
489
|
+
}
|
|
490
|
+
async emit(active, event) {
|
|
491
|
+
await this.journal.event({ ...event, sessionId: this.scope.sessionId, turnId: active.turnId }, this.publish);
|
|
492
|
+
}
|
|
493
|
+
async consume(event) {
|
|
494
|
+
if (event.kind === 'connection-lost') {
|
|
495
|
+
const error = new HarnessSessionError('connection-lost', 'Native connection was lost; dispatch recovery is required.');
|
|
496
|
+
this.eventError = error;
|
|
497
|
+
await this.uncertain(event.code, error);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const active = this.active;
|
|
501
|
+
if (!active)
|
|
502
|
+
return; // never revive a terminal turn from transport tails
|
|
503
|
+
const native = event.kind === 'review-requested' ? event.request : event;
|
|
504
|
+
await this.bindNative(native, active);
|
|
505
|
+
switch (event.kind) {
|
|
506
|
+
case 'turn-started':
|
|
507
|
+
return;
|
|
508
|
+
case 'review-requested': {
|
|
509
|
+
const digest = harnessDigest(event.request);
|
|
510
|
+
const old = active.reviews.get(event.request.requestId);
|
|
511
|
+
if (old) {
|
|
512
|
+
if (old.digest !== digest)
|
|
513
|
+
throw new HarnessSessionError('review-conflict', 'Native request ID was reused with different input.');
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
active.reviews.set(event.request.requestId, {
|
|
517
|
+
request: event.request,
|
|
518
|
+
digest,
|
|
519
|
+
resolved: false,
|
|
520
|
+
});
|
|
521
|
+
await this.journal.transition({
|
|
522
|
+
kind: 'review-requested',
|
|
523
|
+
turnId: active.turnId,
|
|
524
|
+
request: event.request,
|
|
525
|
+
digest,
|
|
526
|
+
});
|
|
527
|
+
this.phase = 'waiting';
|
|
528
|
+
await this.review(event.request);
|
|
529
|
+
const presented = active.reviews.get(event.request.requestId);
|
|
530
|
+
if (presented)
|
|
531
|
+
presented.presented = true;
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
case 'review-resolved': {
|
|
535
|
+
const review = active.reviews.get(event.requestId);
|
|
536
|
+
if (!review || review.resolved)
|
|
537
|
+
return;
|
|
538
|
+
review.resolved = true;
|
|
539
|
+
await this.journal.transition({
|
|
540
|
+
kind: 'review-resolved',
|
|
541
|
+
turnId: active.turnId,
|
|
542
|
+
requestId: event.requestId,
|
|
543
|
+
});
|
|
544
|
+
if (![...active.reviews.values()].some((r) => !r.resolved))
|
|
545
|
+
this.phase = 'running';
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
case 'turn-completed':
|
|
549
|
+
await this.finish(active, event);
|
|
550
|
+
return;
|
|
551
|
+
case 'tool-started': {
|
|
552
|
+
const item = await this.item(event, active, 'tool');
|
|
553
|
+
if (item.started)
|
|
554
|
+
return;
|
|
555
|
+
item.started = true;
|
|
556
|
+
item.input = event.input;
|
|
557
|
+
await this.emit(active, {
|
|
558
|
+
type: 'tool_executing',
|
|
559
|
+
toolUseId: item.toolUseId,
|
|
560
|
+
toolName: `${this.currentBinding?.engineId}:${event.name}`,
|
|
561
|
+
input: event.input,
|
|
562
|
+
});
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
case 'tool-output': {
|
|
566
|
+
const item = await this.item(event, active, 'tool');
|
|
567
|
+
await this.emit(active, {
|
|
568
|
+
type: 'tool_progress',
|
|
569
|
+
toolUseId: item.toolUseId,
|
|
570
|
+
toolName: this.currentBinding?.engineId ?? 'harness',
|
|
571
|
+
message: event.text,
|
|
572
|
+
});
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
case 'tool-completed': {
|
|
576
|
+
const item = await this.item(event, active, 'tool');
|
|
577
|
+
const digest = harnessDigest(event);
|
|
578
|
+
if (item.completed === digest)
|
|
579
|
+
return;
|
|
580
|
+
if (item.completed)
|
|
581
|
+
throw new HarnessSessionError('item-conflict', 'Native tool completion changed after settlement.');
|
|
582
|
+
item.completed = digest;
|
|
583
|
+
await this.emit(active, {
|
|
584
|
+
type: 'tool_completed',
|
|
585
|
+
toolUseId: item.toolUseId,
|
|
586
|
+
toolName: `${this.currentBinding?.engineId}:${event.name}`,
|
|
587
|
+
result: event.result,
|
|
588
|
+
isError: event.status !== 'completed',
|
|
589
|
+
savedPresentation: engineSavedView(event.name, item.input),
|
|
590
|
+
...(event.durationMs === undefined ? {} : { durationMs: event.durationMs }),
|
|
591
|
+
});
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
case 'message-started':
|
|
595
|
+
case 'text-delta':
|
|
596
|
+
case 'message-completed':
|
|
597
|
+
case 'reasoning': {
|
|
598
|
+
const item = await this.item(event, active, 'message');
|
|
599
|
+
const messageId = item.messageId;
|
|
600
|
+
if (!item.started) {
|
|
601
|
+
item.started = true;
|
|
602
|
+
await this.emit(active, { type: 'message_started', iteration: 0, messageId });
|
|
603
|
+
}
|
|
604
|
+
if (event.kind === 'text-delta') {
|
|
605
|
+
if (item.completed)
|
|
606
|
+
return;
|
|
607
|
+
item.content += event.text;
|
|
608
|
+
await this.emit(active, {
|
|
609
|
+
type: 'text_delta',
|
|
610
|
+
iteration: 0,
|
|
611
|
+
messageId,
|
|
612
|
+
text: event.text,
|
|
613
|
+
...(event.part ? { textPart: event.part } : {}),
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
else if (event.kind === 'message-completed') {
|
|
617
|
+
await this.completeMessage(active, item, event.content, event.parts, event.stopReason);
|
|
618
|
+
}
|
|
619
|
+
else if (event.kind === 'reasoning') {
|
|
620
|
+
let index = item.blocks.get(event.blockId);
|
|
621
|
+
if (index === undefined) {
|
|
622
|
+
index = item.blocks.size;
|
|
623
|
+
item.blocks.set(event.blockId, index);
|
|
624
|
+
await this.emit(active, {
|
|
625
|
+
type: 'reasoning_started',
|
|
626
|
+
iteration: 0,
|
|
627
|
+
messageId,
|
|
628
|
+
blockIndex: index,
|
|
629
|
+
reasoningType: event.text === undefined ? 'redacted_thinking' : 'thinking',
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
if (event.status === 'pending' && event.text)
|
|
633
|
+
await this.emit(active, {
|
|
634
|
+
type: 'reasoning_delta',
|
|
635
|
+
iteration: 0,
|
|
636
|
+
messageId,
|
|
637
|
+
blockIndex: index,
|
|
638
|
+
text: event.text,
|
|
639
|
+
});
|
|
640
|
+
if (event.status === 'completed')
|
|
641
|
+
await this.emit(active, {
|
|
642
|
+
type: 'reasoning_completed',
|
|
643
|
+
iteration: 0,
|
|
644
|
+
messageId,
|
|
645
|
+
blockIndex: index,
|
|
646
|
+
signed: false,
|
|
647
|
+
...(event.text === undefined ? {} : { text: event.text }),
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
async completeMessage(active, item, content, parts, stopReason) {
|
|
655
|
+
const message = {
|
|
656
|
+
role: 'assistant',
|
|
657
|
+
content,
|
|
658
|
+
...(parts ? { textParts: parts } : {}),
|
|
659
|
+
};
|
|
660
|
+
const digest = harnessDigest(message);
|
|
661
|
+
if (item.completed === digest)
|
|
662
|
+
return;
|
|
663
|
+
if (item.completed)
|
|
664
|
+
await this.journal.append({
|
|
665
|
+
type: 'message_replaced',
|
|
666
|
+
turnId: active.turnId,
|
|
667
|
+
targetMessageId: item.messageId,
|
|
668
|
+
content: message,
|
|
669
|
+
reason: 'history-repair',
|
|
670
|
+
});
|
|
671
|
+
else
|
|
672
|
+
await this.journal.append({
|
|
673
|
+
type: 'message',
|
|
674
|
+
turnId: active.turnId,
|
|
675
|
+
messageId: item.messageId,
|
|
676
|
+
role: 'assistant',
|
|
677
|
+
content: message,
|
|
678
|
+
});
|
|
679
|
+
item.completed = digest;
|
|
680
|
+
item.content = content;
|
|
681
|
+
await this.emit(active, {
|
|
682
|
+
type: 'message_completed',
|
|
683
|
+
iteration: 0,
|
|
684
|
+
messageId: item.messageId,
|
|
685
|
+
content,
|
|
686
|
+
...(parts ? { textParts: parts } : {}),
|
|
687
|
+
stopReason,
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
async finish(active, event) {
|
|
691
|
+
let final = event.finalItemId ? active.items.get(event.finalItemId) : undefined;
|
|
692
|
+
if (event.result !== undefined) {
|
|
693
|
+
if (!final && event.finalItemId)
|
|
694
|
+
final = await this.item({ ...event, nativeItemId: event.finalItemId }, active, 'message');
|
|
695
|
+
if (final?.messageId && (final.content !== event.result || !final.completed))
|
|
696
|
+
await this.completeMessage(active, final, event.result, undefined, event.status === 'cancelled' ? 'cancelled' : 'end_turn');
|
|
697
|
+
}
|
|
698
|
+
const result = event.result ?? final?.content ?? '';
|
|
699
|
+
const settlement = this.settlement(active, event.status, final?.messageId);
|
|
700
|
+
if (event.status === 'failed')
|
|
701
|
+
await this.emit(active, {
|
|
702
|
+
type: 'turn_failed',
|
|
703
|
+
error: event.error?.message ?? 'External harness turn failed.',
|
|
704
|
+
settlement,
|
|
705
|
+
});
|
|
706
|
+
else
|
|
707
|
+
await this.emit(active, {
|
|
708
|
+
type: 'turn_completed',
|
|
709
|
+
result,
|
|
710
|
+
stopReason: event.status === 'cancelled' ? 'cancelled' : 'end_turn',
|
|
711
|
+
settlement,
|
|
712
|
+
});
|
|
713
|
+
active.removeAbort?.();
|
|
714
|
+
this.active = undefined;
|
|
715
|
+
this.phase = 'idle';
|
|
716
|
+
active.resolve({
|
|
717
|
+
turnId: active.turnId,
|
|
718
|
+
nativeTurn: active.nativeTurn,
|
|
719
|
+
status: event.status,
|
|
720
|
+
messages: harnessSnapshot(await this.journal.log.messages()),
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
settlement(active, status, resultMessageId) {
|
|
724
|
+
return {
|
|
725
|
+
status,
|
|
726
|
+
iterations: 0,
|
|
727
|
+
usage: {
|
|
728
|
+
promptTokens: 0,
|
|
729
|
+
completionTokens: 0,
|
|
730
|
+
totalTokens: 0,
|
|
731
|
+
cachedTokens: 0,
|
|
732
|
+
cacheWriteTokens: 0,
|
|
733
|
+
},
|
|
734
|
+
cost: { totalCost: 0, cacheDiscount: 0, unpricedTokens: 0 },
|
|
735
|
+
durationMs: Math.max(0, Date.now() - active.startedAt),
|
|
736
|
+
resultSource: 'model',
|
|
737
|
+
...(resultMessageId ? { resultMessageId } : {}),
|
|
738
|
+
abandonedJobIds: [],
|
|
739
|
+
abandonedTaskIds: [],
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
async respond(input, value) {
|
|
743
|
+
const request = harnessSnapshot(HarnessReviewRequestSchema.parse(input));
|
|
744
|
+
const decision = harnessSnapshot(HarnessDecisionSchema.parse(value));
|
|
745
|
+
const release = this.reserve();
|
|
746
|
+
let reserved = false;
|
|
747
|
+
try {
|
|
748
|
+
const active = this.active;
|
|
749
|
+
const review = active?.reviews.get(request.requestId);
|
|
750
|
+
if (!active ||
|
|
751
|
+
!review ||
|
|
752
|
+
review.resolved ||
|
|
753
|
+
review.decision ||
|
|
754
|
+
this.phase !== 'waiting' ||
|
|
755
|
+
review.digest !== harnessDigest(request))
|
|
756
|
+
throw new HarnessSessionError('stale-review', 'This native review request is stale, altered or already decided.');
|
|
757
|
+
if (!request.decisions.includes(decision.kind))
|
|
758
|
+
throw new HarnessSessionError('unsupported-decision', 'The native request does not permit this decision.');
|
|
759
|
+
await this.authorize('approval', undefined, request);
|
|
760
|
+
await this.journal.current();
|
|
761
|
+
if (this.active !== active || review.resolved || review.decision)
|
|
762
|
+
throw new HarnessSessionError('stale-review', 'The native request ended while authorization was pending.');
|
|
763
|
+
const digest = harnessDigest(decision);
|
|
764
|
+
await this.journal.transition({
|
|
765
|
+
kind: 'review-decided',
|
|
766
|
+
turnId: active.turnId,
|
|
767
|
+
requestId: request.requestId,
|
|
768
|
+
requestDigest: review.digest,
|
|
769
|
+
decisionDigest: digest,
|
|
770
|
+
decision,
|
|
771
|
+
});
|
|
772
|
+
reserved = true;
|
|
773
|
+
review.decision = digest; // durable reservation precedes native answer; unknown ACK is not retried
|
|
774
|
+
await this.authorize('approval', undefined, request);
|
|
775
|
+
await this.journal.current();
|
|
776
|
+
if (this.active !== active || review.resolved)
|
|
777
|
+
throw new HarnessSessionError('stale-review', 'The request ended before its decision could be sent.');
|
|
778
|
+
await this.connection.respond(request, decision);
|
|
779
|
+
}
|
|
780
|
+
catch (error) {
|
|
781
|
+
if (reserved)
|
|
782
|
+
await this.uncertain('decision-unconfirmed', error);
|
|
783
|
+
throw error;
|
|
784
|
+
}
|
|
785
|
+
finally {
|
|
786
|
+
release();
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
async cancel(expectedTurnId) {
|
|
790
|
+
if (this.operation || this.cancelling)
|
|
791
|
+
throw new HarnessSessionError('busy', 'Another harness operation is pending.');
|
|
792
|
+
const active = this.active;
|
|
793
|
+
if (!active || active.turnId !== expectedTurnId)
|
|
794
|
+
throw new HarnessSessionError('stale-turn', 'Stop does not name the current admitted turn.');
|
|
795
|
+
if (!active.nativeTurn || !this.connection)
|
|
796
|
+
throw new HarnessSessionError('dispatch-unconfirmed', 'The native dispatch is not confirmed; reconcile or close this session.');
|
|
797
|
+
this.cancelling = true;
|
|
798
|
+
try {
|
|
799
|
+
await this.journal.current();
|
|
800
|
+
if (this.connection.capabilities.interrupt === 'unavailable')
|
|
801
|
+
throw new HarnessSessionError('unsupported-cancel', 'The native engine cannot confirm interruption.');
|
|
802
|
+
if (this.connection.capabilities.interrupt === 'process-stop') {
|
|
803
|
+
await this.connection.close();
|
|
804
|
+
this.connection = undefined;
|
|
805
|
+
++this.epoch;
|
|
806
|
+
if (this.active === active)
|
|
807
|
+
await this.finish(active, {
|
|
808
|
+
kind: 'turn-completed',
|
|
809
|
+
...active.nativeTurn,
|
|
810
|
+
status: 'cancelled',
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
await this.connection.interrupt(active.nativeTurn);
|
|
815
|
+
await active.done; // ACK is not completion; exact terminal event is required
|
|
816
|
+
}
|
|
817
|
+
return { stopped: true, turnId: expectedTurnId };
|
|
818
|
+
}
|
|
819
|
+
finally {
|
|
820
|
+
this.cancelling = false;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
async reconnect(signal) {
|
|
824
|
+
const release = this.reserve();
|
|
825
|
+
try {
|
|
826
|
+
if (this.active && this.phase !== 'reconciliation-required')
|
|
827
|
+
throw new HarnessSessionError('busy', 'A native turn is still running.');
|
|
828
|
+
await this.authorize('reconnect', signal);
|
|
829
|
+
if (this.connection) {
|
|
830
|
+
await this.connection.close();
|
|
831
|
+
this.connection = undefined;
|
|
832
|
+
++this.epoch;
|
|
833
|
+
}
|
|
834
|
+
await this.events;
|
|
835
|
+
this.eventError = undefined;
|
|
836
|
+
await this.connect(undefined, signal);
|
|
837
|
+
if (!this.active) {
|
|
838
|
+
this.phase = 'idle';
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
await this.authorize('reconnect', signal);
|
|
842
|
+
const snapshot = harnessSnapshot(await this.requireConnection().readHistory(signal));
|
|
843
|
+
await this.reconcile(snapshot);
|
|
844
|
+
}
|
|
845
|
+
finally {
|
|
846
|
+
release();
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
async reconcile(snapshot) {
|
|
850
|
+
if (!snapshot.complete ||
|
|
851
|
+
harnessDigest(snapshot.binding) !== harnessDigest(this.currentBinding))
|
|
852
|
+
throw new HarnessSessionError('reconciliation-required', 'This engine cannot provide a complete history for the uncertain dispatch.');
|
|
853
|
+
const active = this.active;
|
|
854
|
+
if (!active?.nativeTurn)
|
|
855
|
+
throw new HarnessSessionError('reconciliation-required', 'An unacknowledged dispatch has no trustworthy native turn correlation; it will not be resent.');
|
|
856
|
+
if (snapshot.activeTurn)
|
|
857
|
+
this.validateNative(snapshot.activeTurn, active);
|
|
858
|
+
for (const input of snapshot.events) {
|
|
859
|
+
const event = harnessSnapshot(HarnessEventSchema.parse(input));
|
|
860
|
+
if (event.kind === 'connection-lost')
|
|
861
|
+
continue;
|
|
862
|
+
const native = event.kind === 'review-requested' ? event.request : event;
|
|
863
|
+
if (native.nativeTurnId !== active.nativeTurn.nativeTurnId)
|
|
864
|
+
continue;
|
|
865
|
+
await this.consume(event);
|
|
866
|
+
}
|
|
867
|
+
if (!this.active)
|
|
868
|
+
return;
|
|
869
|
+
if (!snapshot.activeTurn)
|
|
870
|
+
throw new HarnessSessionError('reconciliation-required', 'Native history did not prove a terminal or an active exact turn.');
|
|
871
|
+
for (const input of snapshot.pendingReviews) {
|
|
872
|
+
const request = harnessSnapshot(HarnessReviewRequestSchema.parse(input));
|
|
873
|
+
this.validateNative(request, active);
|
|
874
|
+
const pending = active.reviews.get(request.requestId);
|
|
875
|
+
if (pending?.decision)
|
|
876
|
+
throw new HarnessSessionError('reconciliation-required', 'A durable decision has no confirmed native resolution; it will not be sent again.');
|
|
877
|
+
if (pending) {
|
|
878
|
+
if (pending.resolved || pending.digest !== harnessDigest(request))
|
|
879
|
+
throw new HarnessSessionError('reconciliation-required', 'Native pending review contradicts its recorded request or resolution.');
|
|
880
|
+
if (!pending.presented) {
|
|
881
|
+
await this.review(pending.request);
|
|
882
|
+
pending.presented = true;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
else
|
|
886
|
+
await this.consume({ kind: 'review-requested', request });
|
|
887
|
+
}
|
|
888
|
+
const pendingIds = new Set(snapshot.pendingReviews.map((request) => request.requestId));
|
|
889
|
+
if ([...active.reviews.values()].some((request) => !request.resolved && !pendingIds.has(request.request.requestId)))
|
|
890
|
+
throw new HarnessSessionError('reconciliation-required', 'Native history did not prove the resolution of a recorded pending review.');
|
|
891
|
+
this.phase = [...active.reviews.values()].some((r) => !r.resolved) ? 'waiting' : 'running';
|
|
892
|
+
}
|
|
893
|
+
async close() {
|
|
894
|
+
if (this.phase === 'closed')
|
|
895
|
+
return;
|
|
896
|
+
const release = this.reserve();
|
|
897
|
+
try {
|
|
898
|
+
if (this.connection) {
|
|
899
|
+
await this.connection.close(); // failure retains the exact cleanup authority and writer
|
|
900
|
+
this.connection = undefined;
|
|
901
|
+
++this.epoch;
|
|
902
|
+
}
|
|
903
|
+
await this.events;
|
|
904
|
+
if (this.active && !(await this.journal.log.activeTurn())) {
|
|
905
|
+
this.active.removeAbort?.();
|
|
906
|
+
this.active.reject(new HarnessSessionError('terminal-recorded', 'The native terminal was recorded before its live notification failed.'));
|
|
907
|
+
this.active = undefined;
|
|
908
|
+
}
|
|
909
|
+
if (this.active?.nativeTurn)
|
|
910
|
+
await this.finish(this.active, {
|
|
911
|
+
kind: 'turn-completed',
|
|
912
|
+
...this.active.nativeTurn,
|
|
913
|
+
status: 'cancelled',
|
|
914
|
+
});
|
|
915
|
+
else if (this.active) {
|
|
916
|
+
this.active.removeAbort?.();
|
|
917
|
+
this.active.reject(new HarnessSessionError('reconciliation-required', 'Unacknowledged dispatch remains unresolved in the durable log.'));
|
|
918
|
+
this.active = undefined;
|
|
919
|
+
}
|
|
920
|
+
await this.journal.release();
|
|
921
|
+
this.phase = 'closed';
|
|
922
|
+
}
|
|
923
|
+
finally {
|
|
924
|
+
release();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
//# sourceMappingURL=index.js.map
|