@sema-agent/server 7.147.0 → 7.148.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/MIGRATION.md +1039 -24
- package/README.md +20 -7
- package/README.zh-CN.md +14 -8
- package/USAGE.md +380 -163
- package/deploy/sema-up/README.md +16 -5
- package/deploy/sema-up/chart/templates/NOTES.txt +1 -1
- package/deploy/sema-up/chart/templates/_helpers.tpl +20 -4
- package/deploy/sema-up/chart/values.yaml +3 -2
- package/deploy/sema-up/cluster-up.sh +74 -176
- package/deploy/sema-up/kube-up.sh +29 -49
- package/deploy/sema-up/lib/chart-run.sh +23 -0
- package/deploy/sema-up/lib/dataroot.sh +3 -3
- package/deploy/sema-up/lib/health.sh +62 -13
- package/deploy/sema-up/lib/helm-values-cluster.py +18 -0
- package/deploy/sema-up/lib/helm-values-kube.py +35 -0
- package/deploy/sema-up/lib/regcred.py +8 -0
- package/deploy/sema-up/lib/remote/helm-install.sh +3 -0
- package/deploy/sema-up/lib/remote/image-import.sh +6 -0
- package/deploy/sema-up/lib/remote/machine-precheck.sh +11 -0
- package/deploy/sema-up/lib/remote/region-probe.sh +3 -0
- package/deploy/sema-up/lib/remote/stack-ready.sh +26 -0
- package/deploy/sema-up/lib/remote/vxlan-guard.sh +8 -0
- package/deploy/sema-up/lib/render-stack.py +17 -0
- package/deploy/sema-up/lib/shell-text.sh +87 -0
- package/deploy/sema-up/lib/usage-flags.txt +10 -0
- package/deploy/sema-up/lib/usage-head.txt +1 -0
- package/deploy/sema-up/lib/usage-tail.txt +13 -0
- package/deploy/sema-up/preflight.sh +10 -8
- package/deploy/sema-up/sema-up.sh +14 -39
- package/deploy/sema-up/smoke.sh +7 -6
- package/deploy/sema-up/stack/compose.dataroot.yaml +3 -0
- package/deploy/sema-up/stack/compose.yaml +13 -1
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +21 -0
- package/dist/adoption/plan.d.ts +24 -0
- package/dist/adoption/plan.js +53 -1
- package/dist/adoption/runner.d.ts +10 -1
- package/dist/adoption/runner.js +36 -16
- package/dist/adoption/wire.d.ts +3 -3
- package/dist/approval-card.d.ts +28 -30
- package/dist/approval-gate-currency.js +3 -2
- package/dist/approval-reconciler.d.ts +4 -13
- package/dist/approval-reconciler.js +2 -2
- package/dist/approval.d.ts +13 -11
- package/dist/approval.js +3 -3
- package/dist/audit.d.ts +10 -3
- package/dist/audit.js +15 -7
- package/dist/auth-bridge.d.ts +0 -14
- package/dist/auth-bridge.js +0 -7
- package/dist/auto-mode-face.d.ts +10 -7
- package/dist/auto-mode-face.js +7 -4
- package/dist/background-agent-name.d.ts +19 -1
- package/dist/background-agent-name.js +12 -2
- package/dist/background-session-reap.d.ts +1 -1
- package/dist/bake-runner/main.js +9 -6
- package/dist/bench/s1/arms.js +6 -5
- package/dist/bench/s1/live-deps.js +5 -2
- package/dist/bench/s1/run-firm.js +6 -5
- package/dist/bind-host.d.ts +25 -0
- package/dist/bind-host.js +25 -0
- package/dist/boot/adoption.d.ts +3 -0
- package/dist/boot/adoption.js +1 -0
- package/dist/boot/deployment-mods.d.ts +1 -1
- package/dist/boot/execution-env.d.ts +17 -7
- package/dist/boot/execution-env.js +37 -31
- package/dist/boot/exit-boundary.d.ts +2 -2
- package/dist/boot/exit-boundary.js +6 -5
- package/dist/boot/fatal-exit.d.ts +3 -5
- package/dist/boot/fatal-exit.js +2 -2
- package/dist/boot/leader.d.ts +15 -0
- package/dist/boot/leader.js +17 -15
- package/dist/boot/memory-consolidation.d.ts +37 -29
- package/dist/boot/memory-consolidation.js +11 -5
- package/dist/boot/org-memory.js +1 -1
- package/dist/boot/parked-revive-gate.js +2 -2
- package/dist/boot/reapers.d.ts +4 -3
- package/dist/boot/reapers.js +19 -16
- package/dist/boot/resolve-spec.d.ts +5 -3
- package/dist/boot/resolve-spec.js +55 -67
- package/dist/boot/retention-lane.d.ts +4 -4
- package/dist/boot/retention-lane.js +2 -2
- package/dist/boot/runner-deps.d.ts +28 -7
- package/dist/boot/runner-deps.js +11 -4
- package/dist/boot/runtime-caps.d.ts +2 -2
- package/dist/boot/runtime-caps.js +16 -2
- package/dist/boot/session-faces.d.ts +16 -7
- package/dist/boot/session-faces.js +114 -94
- package/dist/boot/shutdown.d.ts +5 -4
- package/dist/boot/shutdown.js +6 -4
- package/dist/boot/stage-01-config.js +9 -1
- package/dist/boot/stage-02-web-admin-pull.d.ts +1 -0
- package/dist/boot/stage-02-web-admin-pull.js +6 -1
- package/dist/boot/stage-03-store-backend.d.ts +3 -0
- package/dist/boot/stage-03-store-backend.js +4 -3
- package/dist/boot/stage-04-stores.d.ts +2 -0
- package/dist/boot/stage-04-stores.js +2 -2
- package/dist/boot/stage-05-execution-env.d.ts +7 -3
- package/dist/boot/stage-05-execution-env.js +2 -2
- package/dist/boot/stage-06-runners.d.ts +10 -12
- package/dist/boot/stage-06-runners.js +23 -15
- package/dist/boot/stage-07-capability-layer.d.ts +11 -8
- package/dist/boot/stage-07-capability-layer.js +5 -3
- package/dist/boot/stage-08-reapers.d.ts +11 -8
- package/dist/boot/stage-08-reapers.js +3 -3
- package/dist/boot/stage-09-leader.d.ts +12 -15
- package/dist/boot/stage-09-leader.js +12 -4
- package/dist/boot/stage-10-http-server.d.ts +12 -15
- package/dist/boot/stage-10-http-server.js +7 -4
- package/dist/boot/store-evidence.d.ts +20 -0
- package/dist/boot/store-evidence.js +13 -0
- package/dist/boot/stores.d.ts +3 -0
- package/dist/boot/stores.js +21 -10
- package/dist/boot/task-list-lane.d.ts +4 -4
- package/dist/boot/web-admin.d.ts +4 -2
- package/dist/boot/web-admin.js +55 -35
- package/dist/boot/webfetch-summarize-lane.d.ts +1 -1
- package/dist/boot-reclaim.d.ts +3 -1
- package/dist/boot-reclaim.js +1 -1
- package/dist/brain.d.ts +7 -18
- package/dist/brain.js +5 -17
- package/dist/budget.js +6 -6
- package/dist/capabilities/center-plugins.d.ts +7 -1
- package/dist/capabilities/center-plugins.js +32 -10
- package/dist/capabilities/center-wiring.js +1 -1
- package/dist/capabilities/composite-members.d.ts +2 -2
- package/dist/capabilities/composite-members.js +2 -2
- package/dist/capabilities/repo-tools.d.ts +2 -0
- package/dist/capabilities/repo-tools.js +14 -12
- package/dist/capabilities/scenarios.d.ts +6 -15
- package/dist/capabilities/scenarios.js +11 -16
- package/dist/capabilities/skills.d.ts +1 -1
- package/dist/capabilities/tool-defer.d.ts +1 -1
- package/dist/capability-facts.d.ts +38 -11
- package/dist/capability-facts.js +47 -8
- package/dist/card-void.d.ts +4 -4
- package/dist/card-void.js +1 -1
- package/dist/center-credential-renewer.d.ts +6 -2
- package/dist/center-credential-renewer.js +7 -3
- package/dist/config-catalog.d.ts +16 -1
- package/dist/config-catalog.js +62 -56
- package/dist/config-dir-trust.d.ts +37 -4
- package/dist/config-dir-trust.js +88 -44
- package/dist/config-invariants.d.ts +42 -3
- package/dist/config-invariants.js +69 -5
- package/dist/config-lkg.d.ts +23 -1
- package/dist/config-lkg.js +17 -3
- package/dist/config-provider.d.ts +9 -9
- package/dist/config-provider.js +25 -110
- package/dist/config-pull-failure.d.ts +50 -0
- package/dist/config-pull-failure.js +48 -0
- package/dist/config-types.d.ts +26 -17
- package/dist/config.d.ts +8 -16
- package/dist/config.js +113 -47
- package/dist/delegated-session-owner.d.ts +1 -1
- package/dist/deleted-session-ids.d.ts +3 -2
- package/dist/deployment-governance.d.ts +3 -3
- package/dist/deployment-shape.d.ts +30 -4
- package/dist/deployment-shape.js +7 -0
- package/dist/egress-redirect.d.ts +25 -7
- package/dist/egress-redirect.js +20 -2
- package/dist/elicitation.d.ts +6 -5
- package/dist/elicitation.js +23 -22
- package/dist/engine-identity.d.ts +28 -0
- package/dist/engine-identity.js +10 -0
- package/dist/entry-problems.d.ts +5 -7
- package/dist/entry-problems.js +1 -1
- package/dist/env-facts.js +2 -1
- package/dist/env-witness.d.ts +7 -0
- package/dist/env-witness.js +16 -0
- package/dist/execution-lane-caps.d.ts +5 -18
- package/dist/execution-lane-caps.js +0 -22
- package/dist/execution-placement.d.ts +58 -18
- package/dist/execution-placement.js +41 -2
- package/dist/field-conflict.d.ts +7 -11
- package/dist/field-conflict.js +3 -3
- package/dist/file-history-capture.d.ts +3 -3
- package/dist/file-history-disclosure.js +1 -0
- package/dist/fleet/fleet-bus.d.ts +21 -3
- package/dist/fleet/fleet-bus.js +35 -25
- package/dist/fleet/fleet-reconciler.js +2 -2
- package/dist/fleet/serving-lease.js +3 -3
- package/dist/fleet-client.js +3 -3
- package/dist/fleet-lease.d.ts +0 -1
- package/dist/fleet-lease.js +4 -5
- package/dist/history-anchor.d.ts +23 -3
- package/dist/history-anchor.js +24 -4
- package/dist/hitl-delivery.d.ts +90 -0
- package/dist/hitl-delivery.js +98 -0
- package/dist/hooks/classic-stations.d.ts +8 -11
- package/dist/hooks/classic-stations.js +0 -7
- package/dist/hooks/hook-llm.d.ts +5 -1
- package/dist/hooks/hook-llm.js +24 -15
- package/dist/hooks/hook-runner.d.ts +67 -57
- package/dist/hooks/hook-runner.js +260 -186
- package/dist/host-lsp-manager.d.ts +22 -8
- package/dist/host-lsp-manager.js +4 -1
- package/dist/http/active-run-conflict.d.ts +2 -43
- package/dist/http/active-run-conflict.js +3 -7
- package/dist/http/admission.d.ts +4 -18
- package/dist/http/admission.js +75 -78
- package/dist/http/approval-sweeps.d.ts +3 -3
- package/dist/http/approval-sweeps.js +54 -30
- package/dist/http/caller-trust.d.ts +8 -10
- package/dist/http/caller-trust.js +1 -2
- package/dist/http/claim-heartbeat.d.ts +49 -0
- package/dist/http/claim-heartbeat.js +46 -0
- package/dist/http/claimed-run.d.ts +4 -3
- package/dist/http/dispatch.d.ts +8 -1
- package/dist/http/dispatch.js +76 -30
- package/dist/http/durable-run-leg.d.ts +3 -3
- package/dist/http/durable-run-leg.js +17 -12
- package/dist/http/execution-context.d.ts +17 -43
- package/dist/http/execution-context.js +7 -5
- package/dist/http/health-reader.d.ts +36 -0
- package/dist/http/health-reader.js +21 -0
- package/dist/http/health-self-report.d.ts +9 -9
- package/dist/http/health-self-report.js +4 -4
- package/dist/http/idempotency.d.ts +9 -5
- package/dist/http/idempotency.js +4 -4
- package/dist/http/memory-compliance-failure-reply.d.ts +15 -16
- package/dist/http/memory-compliance-failure-reply.js +4 -2
- package/dist/http/memory-face-fault-reply.d.ts +67 -0
- package/dist/http/memory-face-fault-reply.js +71 -0
- package/dist/http/memory-store-refusal-reply.d.ts +1 -1
- package/dist/http/memory-store-refusal-reply.js +3 -0
- package/dist/http/owner-access.d.ts +391 -67
- package/dist/http/owner-access.js +371 -35
- package/dist/http/principal-gate.d.ts +24 -81
- package/dist/http/principal-gate.js +24 -68
- package/dist/http/refusal-body.d.ts +35 -2
- package/dist/http/refusal-body.js +34 -0
- package/dist/http/request-guards.d.ts +9 -13
- package/dist/http/request-guards.js +34 -68
- package/dist/http/resume-composition.d.ts +37 -0
- package/dist/http/resume-composition.js +18 -0
- package/dist/http/resume-ctx-read.d.ts +35 -12
- package/dist/http/resume-ctx-read.js +25 -6
- package/dist/http/resume-legs.d.ts +21 -18
- package/dist/http/resume-legs.js +189 -129
- package/dist/http/retired-skill-manifest.d.ts +1 -1
- package/dist/http/route-ctx.d.ts +25 -32
- package/dist/http/routes/a2a-serve.d.ts +43 -5
- package/dist/http/routes/a2a-serve.js +58 -37
- package/dist/http/routes/admin-config-refresh.js +2 -2
- package/dist/http/routes/admin-drain.js +2 -2
- package/dist/http/routes/admin-memory-optout.js +4 -3
- package/dist/http/routes/adoption.d.ts +3 -0
- package/dist/http/routes/adoption.js +17 -10
- package/dist/http/routes/agents-roster.js +13 -7
- package/dist/http/routes/approvals-assistant.js +70 -65
- package/dist/http/routes/attachments.js +2 -2
- package/dist/http/routes/background.d.ts +3 -3
- package/dist/http/routes/background.js +9 -17
- package/dist/http/routes/capabilities.js +15 -18
- package/dist/http/routes/config-catalog.js +2 -2
- package/dist/http/routes/devices.d.ts +3 -3
- package/dist/http/routes/devices.js +4 -4
- package/dist/http/routes/diagnostics.d.ts +27 -3
- package/dist/http/routes/diagnostics.js +27 -21
- package/dist/http/routes/engine.js +2 -2
- package/dist/http/routes/fleet.js +5 -3
- package/dist/http/routes/images.js +10 -6
- package/dist/http/routes/leader.d.ts +7 -2
- package/dist/http/routes/leader.js +12 -3
- package/dist/http/routes/mcp-reconnect.d.ts +1 -1
- package/dist/http/routes/mcp-reconnect.js +7 -15
- package/dist/http/routes/memory-bundle.js +4 -7
- package/dist/http/routes/memory-compliance.js +4 -4
- package/dist/http/routes/memory-consolidation.js +6 -9
- package/dist/http/routes/memory-origin.d.ts +2 -0
- package/dist/http/routes/memory-origin.js +7 -8
- package/dist/http/routes/memory-policy.js +17 -12
- package/dist/http/routes/notify-wake.js +10 -19
- package/dist/http/routes/observability.js +3 -3
- package/dist/http/routes/principal-inbox.d.ts +1 -1
- package/dist/http/routes/principal-inbox.js +2 -2
- package/dist/http/routes/projects.d.ts +1 -1
- package/dist/http/routes/projects.js +3 -2
- package/dist/http/routes/retention-ops.js +6 -9
- package/dist/http/routes/rules.js +20 -5
- package/dist/http/routes/run-memory-capture.d.ts +2 -2
- package/dist/http/routes/run-memory-capture.js +6 -12
- package/dist/http/routes/run-permission-mode.d.ts +2 -2
- package/dist/http/routes/run-permission-mode.js +10 -17
- package/dist/http/routes/runs.js +146 -231
- package/dist/http/routes/session-memory-sync.d.ts +2 -2
- package/dist/http/routes/session-memory-sync.js +7 -13
- package/dist/http/routes/session-sync.d.ts +4 -2
- package/dist/http/routes/session-sync.js +21 -20
- package/dist/http/routes/sessions-list.d.ts +3 -3
- package/dist/http/routes/sessions-list.js +9 -9
- package/dist/http/routes/sessions.js +87 -124
- package/dist/http/routes/shared-memory.js +6 -6
- package/dist/http/routes/side-query.js +2 -2
- package/dist/http/routes/tasks.js +136 -120
- package/dist/http/routes/trace-usage.d.ts +0 -12
- package/dist/http/routes/trace-usage.js +40 -46
- package/dist/http/routes/workflows.d.ts +39 -4
- package/dist/http/routes/workflows.js +42 -14
- package/dist/http/run-concurrency-cap.d.ts +20 -12
- package/dist/http/run-concurrency-cap.js +39 -26
- package/dist/http/run-read-face.d.ts +3 -5
- package/dist/http/run-read-face.js +8 -13
- package/dist/http/send.d.ts +12 -3
- package/dist/http/send.js +42 -6
- package/dist/http/server.d.ts +39 -40
- package/dist/http/server.js +36 -11
- package/dist/http/sse-log.d.ts +17 -10
- package/dist/http/sse-log.js +7 -7
- package/dist/http/stored-body-replay.d.ts +12 -0
- package/dist/http/stored-body-replay.js +2 -2
- package/dist/http/submit-ctx.d.ts +16 -8
- package/dist/http/submit-ctx.js +6 -2
- package/dist/http/submit-replay.d.ts +19 -6
- package/dist/http/submit-replay.js +18 -6
- package/dist/http/sync-submit-body.d.ts +3 -4
- package/dist/http/sync-submit-body.js +4 -5
- package/dist/http/wire-types.d.ts +4 -3
- package/dist/identity-source.d.ts +36 -5
- package/dist/identity-source.js +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-resolver.d.ts +32 -0
- package/dist/key-resolver.js +23 -9
- package/dist/leader/diffup.js +2 -1
- package/dist/leader/endpoint.d.ts +26 -5
- package/dist/leader/endpoint.js +154 -14
- package/dist/leader/fanout.d.ts +3 -0
- package/dist/leader/fanout.js +78 -63
- package/dist/leader/leader.d.ts +16 -0
- package/dist/leader/leader.js +43 -3
- package/dist/leader/merge.d.ts +9 -1
- package/dist/leader/merge.js +16 -1
- package/dist/leader/repair-wire.js +1 -1
- package/dist/leader/wire.d.ts +36 -3
- package/dist/leader/wire.js +59 -18
- package/dist/lsp-evict.d.ts +6 -4
- package/dist/lsp-evict.js +2 -3
- package/dist/memory-operator-faces.d.ts +5 -4
- package/dist/memory-operator-faces.js +1 -1
- package/dist/memory-scope.d.ts +29 -2
- package/dist/memory-scope.js +64 -15
- package/dist/memory-store-refusal.d.ts +5 -2
- package/dist/memory-sync-client.d.ts +3 -2
- package/dist/memory-sync-client.js +6 -3
- package/dist/model-compat.d.ts +17 -8
- package/dist/model-compat.js +6 -2
- package/dist/model-context-window.d.ts +18 -0
- package/dist/model-context-window.js +2 -0
- package/dist/model-entry-headers.d.ts +46 -4
- package/dist/model-entry-headers.js +2 -2
- package/dist/model-entry-refusal.d.ts +35 -16
- package/dist/model-entry-refusal.js +40 -27
- package/dist/model-plane-face.d.ts +19 -11
- package/dist/model-plane-face.js +9 -1
- package/dist/model-plane-probe.d.ts +2 -0
- package/dist/model-plane-probe.js +17 -0
- package/dist/model-provider.d.ts +3 -3
- package/dist/model-route-endpoint.d.ts +9 -5
- package/dist/model-route-endpoint.js +29 -7
- package/dist/model-select.d.ts +16 -0
- package/dist/model-select.js +4 -0
- package/dist/mountinfo.d.ts +37 -0
- package/dist/mountinfo.js +47 -0
- package/dist/namespaced-rule-name.d.ts +23 -14
- package/dist/namespaced-rule-name.js +8 -11
- package/dist/net-address.d.ts +1 -1
- package/dist/observability/corrupt-read-seat.d.ts +4 -4
- package/dist/observability/corrupt-read-seat.js +5 -3
- package/dist/observability/fail-open.d.ts +58 -38
- package/dist/observability/fail-open.js +60 -38
- package/dist/observability/logger.d.ts +22 -1
- package/dist/observability/logger.js +89 -12
- package/dist/observability/metrics.js +3 -4
- package/dist/observability/otel-exporter.js +2 -1
- package/dist/observability/principal-context.d.ts +14 -7
- package/dist/observability/principal-context.js +8 -3
- package/dist/observability/run-terminal.d.ts +7 -1
- package/dist/observability/run-terminal.js +5 -2
- package/dist/orchestration/hardened-vm-runner.d.ts +1 -0
- package/dist/orchestration/hardened-vm-runner.js +11 -5
- package/dist/orchestration/hardened-vm-worker-runner.d.ts +0 -14
- package/dist/orchestration/hardened-vm-worker-runner.js +5 -0
- package/dist/orchestration/hardened-vm-worker.js +2 -1
- package/dist/orchestration/workflow-completion-inbox.d.ts +3 -3
- package/dist/orchestration/workflow-completion-inbox.js +3 -2
- package/dist/org-delivery-gate.d.ts +5 -4
- package/dist/org-delivery-gate.js +7 -6
- package/dist/outbound-dispatcher.d.ts +1 -1
- package/dist/outbound-dispatcher.js +6 -12
- package/dist/owner-brands.d.ts +81 -0
- package/dist/owner-brands.js +42 -0
- package/dist/owner-faces.d.ts +531 -0
- package/dist/owner-faces.js +126 -0
- package/dist/parked-decide.d.ts +67 -5
- package/dist/parked-decide.js +127 -5
- package/dist/parked-revive-surface.d.ts +14 -4
- package/dist/parked-revive-surface.js +5 -4
- package/dist/peer-directory.d.ts +6 -8
- package/dist/peer-directory.js +3 -2
- package/dist/permission-rule-vocab.d.ts +53 -8
- package/dist/permission-rule-vocab.js +30 -2
- package/dist/plugins/adoption-log-sql.d.ts +0 -22
- package/dist/plugins/adoption-log-sql.js +5 -3
- package/dist/plugins/approval-ask-retired-delete-by-task-m50.d.ts +7 -0
- package/dist/plugins/approval-ask-retired-delete-by-task-m50.js +17 -0
- package/dist/plugins/approval-ask-store-file.d.ts +18 -7
- package/dist/plugins/approval-ask-store-file.js +37 -14
- package/dist/plugins/approval-ask-store-memory.d.ts +12 -4
- package/dist/plugins/approval-ask-store-memory.js +24 -10
- package/dist/plugins/approval-ask-store-sql.d.ts +39 -20
- package/dist/plugins/approval-ask-store-sql.js +41 -10
- package/dist/plugins/approval-exemption-skill-m46.d.ts +20 -0
- package/dist/plugins/approval-exemption-skill-m46.js +25 -0
- package/dist/plugins/approval-exemption-store.d.ts +6 -1
- package/dist/plugins/approval-exemption-store.js +14 -0
- package/dist/plugins/approval-nonce-store.d.ts +39 -12
- package/dist/plugins/approval-nonce-store.js +72 -23
- package/dist/plugins/blob-backend.d.ts +2 -0
- package/dist/plugins/blob-backend.js +9 -6
- package/dist/plugins/caching-session-store.d.ts +13 -1
- package/dist/plugins/caching-session-store.js +43 -4
- package/dist/plugins/checkpoint-index-columns.d.ts +32 -5
- package/dist/plugins/checkpoint-index-columns.js +36 -1
- package/dist/plugins/checkpoint-store-face.d.ts +83 -10
- package/dist/plugins/checkpoint-store-face.js +18 -1
- package/dist/plugins/device-store-sql.js +1 -0
- package/dist/plugins/ensure-index.d.ts +13 -1
- package/dist/plugins/ensure-index.js +154 -21
- package/dist/plugins/ensure-schema-lock-policy.d.ts +0 -15
- package/dist/plugins/ensure-schema-lock-policy.js +3 -2
- package/dist/plugins/file-run-store.d.ts +63 -23
- package/dist/plugins/file-run-store.js +138 -83
- package/dist/plugins/host-platform.d.ts +24 -3
- package/dist/plugins/host-platform.js +15 -1
- package/dist/plugins/image-bake-store-sql.js +2 -0
- package/dist/plugins/imported-layer-root-retirement.d.ts +2 -2
- package/dist/plugins/k8s-pod-reaper.d.ts +1 -3
- package/dist/plugins/k8s-pod-reaper.js +0 -1
- package/dist/plugins/leader-run-store-sql.d.ts +22 -0
- package/dist/plugins/leader-run-store-sql.js +34 -4
- package/dist/plugins/local-checkpoint-store.d.ts +58 -23
- package/dist/plugins/local-checkpoint-store.js +195 -76
- package/dist/plugins/local-data-dir-modes-m39.js +2 -1
- package/dist/plugins/local-docker-capacity.d.ts +93 -0
- package/dist/plugins/local-docker-capacity.js +194 -0
- package/dist/plugins/local-docker-reaper.d.ts +92 -0
- package/dist/plugins/local-docker-reaper.js +102 -0
- package/dist/plugins/local-engine-high-water.d.ts +4 -2
- package/dist/plugins/local-engine-high-water.js +4 -1
- package/dist/plugins/local-session-store.d.ts +358 -125
- package/dist/plugins/local-session-store.js +824 -251
- package/dist/plugins/local-session-window.d.ts +3 -2
- package/dist/plugins/local-session-window.js +3 -2
- package/dist/plugins/local-sidecar-quarantine.js +3 -2
- package/dist/plugins/local-task-attachment-store.d.ts +18 -1
- package/dist/plugins/local-task-attachment-store.js +22 -1
- package/dist/plugins/memory-embedder.js +9 -7
- package/dist/plugins/memory-engine-pg.d.ts +3 -2
- package/dist/plugins/memory-engine-pg.js +14 -5
- package/dist/plugins/memory-engine-sql-apply.d.ts +8 -4
- package/dist/plugins/memory-engine-sql-apply.js +6 -8
- package/dist/plugins/memory-engine-tidb.d.ts +4 -2
- package/dist/plugins/memory-engine-tidb.js +11 -2
- package/dist/plugins/memory-optout-grant-store-sql.d.ts +1 -1
- package/dist/plugins/memory-optout-grant-store-sql.js +3 -3
- package/dist/plugins/memory-run-store.d.ts +39 -27
- package/dist/plugins/memory-run-store.js +72 -70
- package/dist/plugins/one-time-migration-marker.d.ts +10 -0
- package/dist/plugins/one-time-migration-marker.js +7 -0
- package/dist/plugins/one-time-migrations.d.ts +186 -45
- package/dist/plugins/one-time-migrations.js +442 -119
- package/dist/plugins/org-delivery-quota-store.js +2 -1
- package/dist/plugins/permission-rule-store-file.d.ts +3 -3
- package/dist/plugins/permission-rule-store-sql.d.ts +4 -63
- package/dist/plugins/permission-rule-store-sql.js +6 -86
- package/dist/plugins/pg-pool.d.ts +1 -31
- package/dist/plugins/pg-pool.js +16 -7
- package/dist/plugins/remote-env-e2b.d.ts +7 -25
- package/dist/plugins/remote-env-e2b.js +34 -25
- package/dist/plugins/remote-env-host.d.ts +2 -9
- package/dist/plugins/remote-env-host.js +34 -22
- package/dist/plugins/remote-env-k8s.d.ts +40 -45
- package/dist/plugins/remote-env-k8s.js +107 -58
- package/dist/plugins/remote-env-local-docker.d.ts +148 -14
- package/dist/plugins/remote-env-local-docker.js +367 -72
- package/dist/plugins/remote-scratchpad.js +4 -0
- package/dist/plugins/retention-deployment.d.ts +49 -17
- package/dist/plugins/retention-deployment.js +39 -8
- package/dist/plugins/run-preview-m45.d.ts +11 -0
- package/dist/plugins/run-preview-m45.js +19 -0
- package/dist/plugins/run-store-sql.d.ts +56 -68
- package/dist/plugins/run-store-sql.js +127 -116
- package/dist/plugins/s3-answer.d.ts +2 -1
- package/dist/plugins/sandbox-reaper.d.ts +26 -0
- package/dist/plugins/sandbox-reaper.js +2 -0
- package/dist/plugins/scenario-prefix-switch-m42.d.ts +54 -0
- package/dist/plugins/scenario-prefix-switch-m42.js +55 -0
- package/dist/plugins/scheduler-support.d.ts +16 -1
- package/dist/plugins/scheduler-support.js +22 -2
- package/dist/plugins/schema-consistency.d.ts +42 -9
- package/dist/plugins/schema-consistency.js +212 -11
- package/dist/plugins/schema-drift-sentence.d.ts +4 -1
- package/dist/plugins/schema-drift-sentence.js +4 -4
- package/dist/plugins/schema-ensure-legs.d.ts +9 -0
- package/dist/plugins/schema-ensure-legs.js +1 -1
- package/dist/plugins/schema-indexes.js +3 -0
- package/dist/plugins/schema-live-columns.d.ts +14 -5
- package/dist/plugins/schema-live-columns.js +10 -10
- package/dist/plugins/send-user-file.js +2 -1
- package/dist/plugins/session-birth.d.ts +37 -0
- package/dist/plugins/session-birth.js +38 -0
- package/dist/plugins/session-epoch-anchor.d.ts +40 -12
- package/dist/plugins/session-epoch-anchor.js +33 -11
- package/dist/plugins/session-ext-table.d.ts +27 -3
- package/dist/plugins/session-ext-table.js +19 -6
- package/dist/plugins/session-fork.d.ts +15 -1
- package/dist/plugins/session-fork.js +3 -0
- package/dist/plugins/session-ownership.d.ts +1 -1
- package/dist/plugins/session-placement.d.ts +22 -16
- package/dist/plugins/session-placement.js +15 -12
- package/dist/plugins/session-row-sql.d.ts +12 -0
- package/dist/plugins/session-row-sql.js +3 -3
- package/dist/plugins/session-run-rollup.d.ts +29 -0
- package/dist/plugins/session-run-rollup.js +40 -0
- package/dist/plugins/session-store-sql.d.ts +38 -12
- package/dist/plugins/session-store-sql.js +130 -30
- package/dist/plugins/session-withdraw-sql.d.ts +36 -0
- package/dist/plugins/session-withdraw-sql.js +42 -0
- package/dist/plugins/shared-memory-store-sql.d.ts +0 -69
- package/dist/plugins/shared-memory-store-sql.js +2 -1
- package/dist/plugins/shell-sentinel-owner-m48.d.ts +20 -0
- package/dist/plugins/shell-sentinel-owner-m48.js +3 -0
- package/dist/plugins/snapshot-bucket-presence.d.ts +2 -1
- package/dist/plugins/sql-driver.d.ts +1 -1
- package/dist/plugins/sql-driver.js +2 -1
- package/dist/plugins/sql-errors.d.ts +32 -5
- package/dist/plugins/sql-errors.js +55 -7
- package/dist/plugins/sql-json-column.d.ts +8 -7
- package/dist/plugins/sql-json-column.js +10 -6
- package/dist/plugins/store-backend.d.ts +84 -15
- package/dist/plugins/store-backend.js +186 -55
- package/dist/plugins/store-contracts.d.ts +90 -30
- package/dist/plugins/store-contracts.js +22 -1
- package/dist/plugins/store-fault.d.ts +28 -2
- package/dist/plugins/store-fault.js +20 -2
- package/dist/plugins/task-attachment-store.d.ts +15 -3
- package/dist/plugins/task-attachment-store.js +22 -9
- package/dist/plugins/tidb-pool.js +23 -8
- package/dist/plugins/web-search.js +5 -3
- package/dist/plugins/workflow-run-store-sql.d.ts +6 -1
- package/dist/plugins/workflow-run-store-sql.js +11 -5
- package/dist/principal-jwt.d.ts +4 -4
- package/dist/principal-jwt.js +20 -5
- package/dist/principal-shape.d.ts +41 -0
- package/dist/principal-shape.js +19 -0
- package/dist/question.d.ts +13 -23
- package/dist/question.js +21 -39
- package/dist/request-declaration-refusal.d.ts +35 -12
- package/dist/request-declaration-refusal.js +21 -9
- package/dist/request-form.d.ts +58 -0
- package/dist/request-form.js +72 -0
- package/dist/request-image-urls.d.ts +8 -2
- package/dist/request-image-urls.js +2 -1
- package/dist/request-images.d.ts +20 -0
- package/dist/request-images.js +59 -0
- package/dist/request-key-closure.d.ts +6 -7
- package/dist/request-key-closure.js +15 -2
- package/dist/resource-suspend.d.ts +7 -16
- package/dist/resource-suspend.js +1 -1
- package/dist/retired-name-host-notice.d.ts +21 -0
- package/dist/retired-name-host-notice.js +12 -0
- package/dist/rule-entry-list.d.ts +2 -2
- package/dist/rule-entry-list.js +3 -4
- package/dist/rule-issue-reading.d.ts +58 -0
- package/dist/rule-issue-reading.js +14 -0
- package/dist/rules-consent.d.ts +5 -3
- package/dist/rules-consent.js +1 -0
- package/dist/run-acceptance.d.ts +3 -1
- package/dist/run-acceptance.js +3 -0
- package/dist/run-local.d.ts +14 -6
- package/dist/run-local.js +92 -80
- package/dist/run-stale-default.d.ts +7 -0
- package/dist/run-stale-default.js +2 -0
- package/dist/runs.d.ts +26 -15
- package/dist/runs.js +39 -27
- package/dist/runtime-caps-resolver.d.ts +21 -6
- package/dist/runtime-caps-resolver.js +17 -4
- package/dist/runtime-governance.d.ts +2 -2
- package/dist/runtime-governance.js +5 -3
- package/dist/sealed-key-layout.d.ts +12 -5
- package/dist/sealed-key-layout.js +5 -0
- package/dist/sealed-key.d.ts +12 -2
- package/dist/sealed-key.js +115 -27
- package/dist/security.d.ts +128 -158
- package/dist/security.js +163 -59
- package/dist/sema-config-dir.d.ts +20 -0
- package/dist/sema-config-dir.js +25 -0
- package/dist/server-secret-env.d.ts +21 -5
- package/dist/server-secret-env.js +14 -4
- package/dist/session-children-retire.d.ts +7 -5
- package/dist/session-children-retire.js +7 -2
- package/dist/session-deletion.d.ts +88 -0
- package/dist/session-deletion.js +8 -0
- package/dist/session-erase.d.ts +145 -0
- package/dist/session-erase.js +115 -0
- package/dist/session-error-wire.d.ts +5 -5
- package/dist/session-error-wire.js +1 -1
- package/dist/session-incarnation.d.ts +52 -5
- package/dist/session-incarnation.js +19 -2
- package/dist/session-policy-wire.d.ts +6 -3
- package/dist/session-policy-wire.js +11 -1
- package/dist/session-resident-background.d.ts +0 -71
- package/dist/session-resident-background.js +4 -3
- package/dist/session-row.d.ts +2 -1
- package/dist/session-rules-seat.d.ts +12 -0
- package/dist/session-rules-seat.js +19 -0
- package/dist/session-titler.d.ts +7 -15
- package/dist/session-titler.js +1 -1
- package/dist/spec-fields.d.ts +57 -3
- package/dist/spec-fields.js +72 -51
- package/dist/store-posture.d.ts +136 -20
- package/dist/store-posture.js +188 -3
- package/dist/stored-request-hooks-m20.js +2 -2
- package/dist/stores-sql/background-agent-store-sql.d.ts +11 -2
- package/dist/stores-sql/background-agent-store-sql.js +73 -20
- package/dist/stores-sql/checkpoint-store-sql.d.ts +33 -28
- package/dist/stores-sql/checkpoint-store-sql.js +75 -44
- package/dist/stores-sql/mailbox-store-sql.d.ts +7 -4
- package/dist/stores-sql/mailbox-store-sql.js +31 -32
- package/dist/stores-sql/pg-session-storage.d.ts +7 -5
- package/dist/stores-sql/pg-session-storage.js +54 -46
- package/dist/stores-sql/retention-store-sql.d.ts +87 -19
- package/dist/stores-sql/retention-store-sql.js +92 -27
- package/dist/stores-sql/session-policy-store-sql.d.ts +32 -10
- package/dist/stores-sql/session-policy-store-sql.js +44 -36
- package/dist/stores-sql/session-write-hooks.d.ts +12 -6
- package/dist/stores-sql/tidb-session-storage.d.ts +4 -4
- package/dist/stores-sql/tidb-session-storage.js +13 -8
- package/dist/stores-sql/tidb-session-store.d.ts +36 -17
- package/dist/stores-sql/tidb-session-store.js +69 -39
- package/dist/stores-sql/windowed-session-storage.d.ts +5 -0
- package/dist/stores-sql/windowed-session-storage.js +9 -0
- package/dist/submission-exit.d.ts +50 -0
- package/dist/submission-exit.js +108 -0
- package/dist/task-a2a.d.ts +1 -1
- package/dist/task-a2a.js +3 -3
- package/dist/task-cwd.d.ts +20 -0
- package/dist/task-cwd.js +8 -0
- package/dist/task-mcp.d.ts +1 -1
- package/dist/task-mcp.js +3 -3
- package/dist/task-settings.d.ts +14 -10
- package/dist/task-settings.js +18 -7
- package/dist/terminal.d.ts +25 -43
- package/dist/terminal.js +31 -11
- package/dist/tool-approval.d.ts +131 -129
- package/dist/tool-approval.js +189 -193
- package/dist/trace/core-keyset-guard.d.ts +13 -6
- package/dist/trace/core-vocab-wire.d.ts +95 -0
- package/dist/trace/core-vocab-wire.js +15 -0
- package/dist/trace/exit-seat.d.ts +30 -4
- package/dist/trace/exit-seat.js +40 -36
- package/dist/trace/extension-call-face.d.ts +3 -2
- package/dist/trace/extension-call-face.js +3 -1
- package/dist/trace/ledger-events.d.ts +4 -7
- package/dist/trace/ledger-sink.d.ts +1 -30
- package/dist/trace/ledger-sink.js +0 -11
- package/dist/trace/model-segment.d.ts +5 -5
- package/dist/trace/model-segment.js +5 -5
- package/dist/trace/project.d.ts +55 -42
- package/dist/trace/project.js +52 -19
- package/dist/trace/redact.d.ts +123 -27
- package/dist/trace/redact.js +880 -260
- package/dist/trace/self-minted-wire.d.ts +487 -19
- package/dist/trace/self-minted-wire.js +172 -23
- package/dist/trace/wire-projection-faces.d.ts +5 -6
- package/dist/trace/wire-projection-faces.js +2 -2
- package/dist/upstream-body.d.ts +23 -0
- package/dist/upstream-body.js +16 -0
- package/dist/url-refusal.d.ts +3 -3
- package/dist/url-refusal.js +11 -4
- package/dist/user-authored-text.d.ts +1 -1
- package/dist/user-input-ledger.d.ts +7 -8
- package/dist/user-input-ledger.js +1 -1
- package/dist/web-admin-client/apply-effective.d.ts +6 -3
- package/dist/web-admin-client/apply-effective.js +13 -16
- package/dist/web-admin-client/apply-ledger.d.ts +16 -7
- package/dist/web-admin-client/apply-ledger.js +5 -2
- package/dist/web-admin-client/center-request.d.ts +2 -2
- package/dist/web-admin-client/center-request.js +15 -15
- package/dist/web-admin-client/effective-keys.d.ts +1 -1
- package/dist/web-admin-client/effective-keys.js +1 -1
- package/dist/web-admin-client/entry-metadata.d.ts +8 -0
- package/dist/web-admin-client/entry-metadata.js +13 -0
- package/dist/web-admin-client/http-client.d.ts +1 -1
- package/dist/web-admin-client/http-client.js +23 -4
- package/dist/web-admin-client/mcp-revocation.d.ts +1 -1
- package/dist/web-admin-client/mcp-revocation.js +2 -1
- package/dist/web-admin-client/read-warnings.d.ts +1 -0
- package/dist/web-admin-client/read-warnings.js +1 -0
- package/dist/web-admin-client/restart-signal.js +8 -4
- package/dist/web-admin-client/skills-mcp.d.ts +2 -2
- package/dist/web-admin-client/types.d.ts +1 -2
- package/dist/workspace-space.d.ts +3 -2
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +4 -4
- package/package.json +6 -3
- package/scripts/drain-check-local.mjs +118 -147
- package/scripts/drain-check.mysql.sql +22 -2
- package/scripts/drain-check.pg.sql +22 -2
- package/wire-changes/server@7.148.0.json +1517 -0
- package/dist/http/memory-control-plane-corrupt-reply.d.ts +0 -25
- package/dist/http/memory-control-plane-corrupt-reply.js +0 -19
- package/dist/http/memory-layer-reply.d.ts +0 -30
- package/dist/http/memory-layer-reply.js +0 -24
- package/dist/lsp/e2b-bridge.d.ts +0 -57
- package/dist/lsp/e2b-bridge.js +0 -139
- package/dist/lsp/e2b-manager.d.ts +0 -93
- package/dist/lsp/e2b-manager.js +0 -178
- package/dist/lsp/lsp-frames.d.ts +0 -14
- package/dist/lsp/lsp-frames.js +0 -25
- package/dist/lsp/manager.d.ts +0 -129
- package/dist/lsp/manager.js +0 -127
- package/dist/lsp/types.d.ts +0 -12
- package/dist/lsp/types.js +0 -2
- package/dist/lsp/ws-transport.d.ts +0 -40
- package/dist/lsp/ws-transport.js +0 -210
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { type Checkpoint, type CheckpointSummary, type CheckpointToken, type PendingSteerInput, type ReopenReason, type ResolveExpectation, type ExecutionOutcomeRecordWord, type GateOutcome, type ResumeOutcome, type StoreDurability, type StoreFidelity } from "@sema-agent/core";
|
|
2
|
-
import { type CheckpointAskCandidate, type CtxClaimRewrite, type CtxRowRewrite, type CtxRowsRewrite, type DecidedApprovalRecord, type PendingCheckpoint, type PendingRowBinding } from "./checkpoint-store-face.js";
|
|
3
|
-
import { type
|
|
2
|
+
import { type CheckpointAskCandidate, type CtxClaimPut, type CtxClaimRewrite, type CtxRowRewrite, type CtxRowsRewrite, type DecidedApprovalRecord, type ExpiredApprovalGate, type ExpiredGatePosition, type PendingCheckpoint, type PendingRowBinding } from "./checkpoint-store-face.js";
|
|
3
|
+
import { type CtxWriteClaim } from "./store-contracts.js";
|
|
4
4
|
import type { SealedCheckpointCtx } from "../http/checkpoint-ctx.js";
|
|
5
|
+
/**
|
|
6
|
+
* 一只会话的续跑输入档**严格**删(提交出口撤回一只刚铸会话时的 local 一形;SQL 孪生是撤回事务里的 `DELETE FROM checkpoint_ctx WHERE session_id = ?`):
|
|
7
|
+
* 档不在 ⇒ 照常;删不掉 ⇒ **抛**(撤回的删序还没落标记 ⇒ 会话完整可见,不吞成「删了」);删掉之后 fsync ctx 目录(win32 不 fsync 目录)。
|
|
8
|
+
* 只按路径动档,不建店实例(本部署没开续跑输入时目录里本就没有这只档)。路径与 {@link LocalCheckpointStore} 的写口同一只(`localCheckpointStoreDirsFor` + {@link ctxFileOf})。
|
|
9
|
+
*/
|
|
10
|
+
export declare function dropLocalCheckpointCtxStrict(root: string, sessionId: string): void;
|
|
5
11
|
export interface LocalCheckpointStoreOptions {
|
|
6
|
-
/**
|
|
12
|
+
/** 会话认领联结(the local FileRunStore's `getActiveTaskId`)—— 停驻行 `taskId` 的第二格读数([ref],写者 `parkedLegTaskId`)。Absent ⇒ 只剩行上的记录。 */
|
|
7
13
|
getActiveTaskId?: (sessionId: string) => Promise<string | undefined>;
|
|
8
14
|
/** E21 owner guard (the LocalSessionStore's owner read, `headOf(id)?.owner`: `undefined` = no session row). Absent ⇒ owner guard degrades
|
|
9
15
|
* to null-owner-only (a non-null owner with no owner source purges NOTHING — fail-closed, mirrors the SQL EXISTS guard). */
|
|
10
16
|
readSessionOwner?: (sessionId: string) => Promise<string | null | undefined>;
|
|
11
|
-
/** ctx 改写的认领栅栏({@link LocalCheckpointStore.rewriteCtxWhileClaimed}):同一数据根上的文件 run 店(进程内栅栏形)。缺席 ⇒ 那一口响亮抛(装配缺陷)。 */
|
|
12
|
-
claims?: InProcessClaimFence;
|
|
13
17
|
}
|
|
14
18
|
/** checkpoint 店在数据根下自己铸的目录(构造器与一次性迁移 M39 的名册同读这一只)。 */
|
|
15
19
|
export declare function localCheckpointStoreDirsFor(root: string): {
|
|
@@ -68,8 +72,30 @@ export declare class LocalCheckpointStore {
|
|
|
68
72
|
* suspend→crash→expire-later lifecycle visible. Entries are never dropped while the inner row exists
|
|
69
73
|
* (a `resolved` row can be reopen()ed back to pending — pruning it would be wrong). */
|
|
70
74
|
private readonly sessionTokens;
|
|
75
|
+
/**
|
|
76
|
+
* **归属索引**:每张卡归在哪只会话上(SQL 孪生的 `checkpoint.host_session_id` 列在本店的同一个事实;读法 `hostSessionOf`,`put` 求值一次)。
|
|
77
|
+
* `hostTokens` = 归属会话 → 卡,`hostOfToken` = 反查(内存,由前者建)。持久化在 `checkpoint-host-sessions.json`,与 scope 注册表 / 会话索引同一条落盘先后
|
|
78
|
+
* (先登记、后内核 put:崩在两步之间 ⇒ 一条指向不存在的行的归属,读者按 `get` 为空跳过;反过来 ⇒ 一张谁的 run 都找不到的卡)。
|
|
79
|
+
* 存量卡由一次性迁移 M49 自卡的会话回填({@link backfillHostSessionsM49})。按 run 找卡的读口(取消 / 收割探针 / 续跑输入回收 / 运维队列行的 run)只读它。
|
|
80
|
+
*/
|
|
81
|
+
private readonly hostTokens;
|
|
82
|
+
private readonly hostOfToken;
|
|
83
|
+
private readonly hostSessionsPath;
|
|
71
84
|
private readonly opts;
|
|
72
85
|
constructor(root: string, opts?: LocalCheckpointStoreOptions);
|
|
86
|
+
/**
|
|
87
|
+
* 三份旁索引(scope 注册表 / 会话索引 / 归属索引)在 `put` 里的**唯一**登记形:内存先记、整档落盘;落盘抛 ⇒ 内存那一笔撤回再抛。
|
|
88
|
+
* 撤回是这条规则的要害:三份索引都按「内存里已有 ⇒ 不再落盘」判,一笔留在内存里的失败登记会让同一张卡的重试 `put` 跳过落盘、内核行照提交
|
|
89
|
+
* —— 文件里永远没有它(重启之后:scope 枚举不到这张卡;会话索引漏它;归属被 M49 自卡的会话回填,cascade 级上的卡丢了它的 run)。
|
|
90
|
+
* `record` 交回「这一次记下了新东西」,`undo` 只撤这一次记下的那一笔。
|
|
91
|
+
*/
|
|
92
|
+
private registerDurably;
|
|
93
|
+
/** 归属索引的内存两面一起记(不落盘;落盘见 {@link persistHostSessions})。交回这一次新记下的卡数。 */
|
|
94
|
+
private indexHost;
|
|
95
|
+
/** {@link indexHost} 的一张卡的逆(只给 {@link registerDurably} 的撤回用)。 */
|
|
96
|
+
private unindexHost;
|
|
97
|
+
/** Persist the card→host-session index (whole-file atomic replace — same cadence as the session→tokens index). */
|
|
98
|
+
private persistHostSessions;
|
|
73
99
|
/** Persist the session→tokens index (whole-file atomic replace — puts are per-suspend, low frequency). */
|
|
74
100
|
private persistSessionTokens;
|
|
75
101
|
put(token: CheckpointToken, cp: Checkpoint): Promise<void>;
|
|
@@ -116,22 +142,22 @@ export declare class LocalCheckpointStore {
|
|
|
116
142
|
* session 两条 pending 时答哪条取决于 sidecar 里 scope 的插入序 —— 与 SQL 无序 `LIMIT 1` 同病。
|
|
117
143
|
*/
|
|
118
144
|
findPendingTokenBySession(sessionId: string, scope?: string, binding?: PendingRowBinding): Promise<CheckpointToken | null>;
|
|
145
|
+
/** 会话那一轴的候选集(`PendingRowBinding.axis`):卡自己的对话 ⇒ 内核的按会话读口;卡归属的 run 会话 ⇒ 归属索引({@link runPendings})。 */
|
|
146
|
+
private axisPendings;
|
|
119
147
|
/** [ref]:候选集 → 读口该答的那一条(过滤 sessionId + 门型,再取「最新优先」)。 */
|
|
120
148
|
private pickPendingRow;
|
|
121
|
-
/** [ref] read-only probe face: does this session have an EXPIRED checkpoint
|
|
122
|
-
* `EXISTS (SELECT 1 FROM checkpoint ce WHERE ce.
|
|
123
|
-
* run stores' failSuspendedWithExpiredCheckpoint. Scans the session
|
|
124
|
-
* cross-status read core's File store offers)
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
|
|
128
|
-
* 旧存量锁死的恢复把手 = cancel verb([ref]①,不依赖本索引);增量行全覆盖。 */
|
|
129
|
-
hasExpiredBySession(sessionId: string): Promise<boolean>;
|
|
149
|
+
/** [ref] read-only probe face: does this RUN session have an EXPIRED checkpoint filed under it? The local twin of the SQL
|
|
150
|
+
* `EXISTS (SELECT 1 FROM checkpoint ce WHERE ce.host_session_id = tr.session_id AND ce.status = 'expired')` that drives the
|
|
151
|
+
* run stores' failSuspendedWithExpiredCheckpoint. Scans the card→host-session index (get(token) is the only
|
|
152
|
+
* cross-status read core's File store offers). Backed by a persisted registry, so it stays honest — never a guessed "true".
|
|
153
|
+
* ⚠️ 存量限制(如实):M49 从会话索引与此刻的待决行回填归属 —— [ref] 会话索引建立之前就已不是 pending 的老卡两边都不在,
|
|
154
|
+
* 其 expired 对本探针不可见;旧存量锁死的恢复把手 = cancel verb([ref]①)。 */
|
|
155
|
+
hasExpiredForRun(runSessionId: string): Promise<boolean>;
|
|
130
156
|
/**
|
|
131
157
|
* [ref] 件1 —— SQL 孪生 `findDecidedApprovalsForBinding` 的本地形(判据、词表、失败方向逐条同源;
|
|
132
158
|
* 那处顶注是唯一真源,这里只记两处**本地形自己的**差别)。
|
|
133
159
|
*
|
|
134
|
-
* · 枚举面走 [ref] 的 `sessionTokens` 索引
|
|
160
|
+
* · 枚举面走 [ref] 的 `sessionTokens` 索引(按卡的对话;core 的 File store
|
|
135
161
|
* 只能 pending-only 枚举,跨态读只有 `get(token)`),所以它那条**存量限制**在这里逐字同样成立:
|
|
136
162
|
* 索引建立之前 park 的老行对本口不可见 ⇒ 回放判别不出 ⇒ 调用方逐字回落 404(保守方向)。
|
|
137
163
|
* · **没有排序**:本口交出全部命中行,由调用方按「判词一致才回放」判(理由见 SQL 孪生顶注的
|
|
@@ -155,7 +181,7 @@ export declare class LocalCheckpointStore {
|
|
|
155
181
|
* 补齐,而不是给下游那两处各加一条「这台机器绑不了」的特判。
|
|
156
182
|
*
|
|
157
183
|
* 形差(逐条,如实):
|
|
158
|
-
* · **枚举面**走 [ref] 的 `sessionTokens` 索引(与 `
|
|
184
|
+
* · **枚举面**走 [ref] 的 `sessionTokens` 索引(与 `findDecidedApprovalsForBinding`
|
|
159
185
|
* 同一条路),所以它那条**存量限制**在这里逐字同样成立:索引建立之前 put 的老行对本口不可见 ⇒ 判据 1
|
|
160
186
|
* 不命中 ⇒ 行落判据 ②③④⑤(保守方向,与读口缺席时的既有降级同向)。
|
|
161
187
|
* · **没有列,所以没有列/blob 一致性门**:SQL 孪生的两道矛盾门(`tool_call_id` 与 `bound_input_hash`
|
|
@@ -181,6 +207,15 @@ export declare class LocalCheckpointStore {
|
|
|
181
207
|
/** `undefined` = no pending row; else the owner scope (local scopes are always strings — never null).
|
|
182
208
|
* [ref]:与 `findPendingTokenBySession` 同一个 {@link pickPendingRow}(同 binding ⇒ 同一行)。 */
|
|
183
209
|
peekPendingScope(sessionId: string, binding?: PendingRowBinding): Promise<string | null | undefined>;
|
|
210
|
+
/** 归在这只 run 会话上的待决卡(归属索引 → 逐张 `get`;只认 pending,scope 给了就再判一次)。 */
|
|
211
|
+
private runPendings;
|
|
212
|
+
/** SQL 孪生 `hostSessionOfCard` 的本地形:`undefined` = 没有这一行;`null` = 行在、归属索引里没有它(M49 还没回填到的存量卡)。 */
|
|
213
|
+
hostSessionOfCard(token: CheckpointToken): Promise<string | null | undefined>;
|
|
214
|
+
/**
|
|
215
|
+
* M49 的本地腿:存量卡的归属自卡的会话回填(SQL 孪生 `UPDATE … SET host_session_id = session_id WHERE host_session_id IS NULL` 的同义)。来源两份:会话索引
|
|
216
|
+
* (自 [ref] 起每一张 put 过的卡,键 = 卡的会话)与此刻的全部待决行(更早的待决卡)。已有归属的卡不动;交回新记下的卡数(第二跑零)。
|
|
217
|
+
*/
|
|
218
|
+
backfillHostSessionsM49(): Promise<number>;
|
|
184
219
|
/**
|
|
185
220
|
* [ref] D-D global expiry sweep — same split as the SQL twin: the deadline branch abort-expires every row
|
|
186
221
|
* EXCEPT an approval-kind row whose gate core reads as facet `A` (those get the graceful resolve-DENY via
|
|
@@ -191,11 +226,9 @@ export declare class LocalCheckpointStore {
|
|
|
191
226
|
*/
|
|
192
227
|
reapExpired(cutoff: number): Promise<number>;
|
|
193
228
|
/** [ref] D-D SLA deny-sweep input — pending approval-kind gates past deadline that core reads as facet `A`
|
|
194
|
-
* (`facetOf`: a `question`-card gate is `B` and is voided by reapExpired instead; same predicate as the SQL twin).
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
scope: string;
|
|
198
|
-
}>>;
|
|
229
|
+
* (`facetOf`: a `question`-card gate is `B` and is voided by reapExpired instead; same predicate as the SQL twin).
|
|
230
|
+
* Same order and paging as the SQL twin: deadline, then token; `after` returns only the rows strictly after that position ([ref]). */
|
|
231
|
+
listExpiredApprovalGates(cutoff: number, limit?: number, after?: ExpiredGatePosition): Promise<ExpiredApprovalGate[]>;
|
|
199
232
|
/**
|
|
200
233
|
* 🔴 **写腿的形闸与 SQL 孪生逐字同一条**(codex 对抗复审 r1 [medium],验真后按类修):TS 的 `object` 说不出
|
|
201
234
|
* 「序列化之后是一只 JSON 对象」—— 数组 / `Date` / `toJSON()` 返回标量或 `null` 的对象全都通得过类型面,
|
|
@@ -207,7 +240,7 @@ export declare class LocalCheckpointStore {
|
|
|
207
240
|
* 一个 `toJSON(k){ return k === "ctx" ? null : {…} }` 的对象验的是 `{…}`、写的是 `{"ctx":null}`
|
|
208
241
|
* (实测两串逐字不同)。有状态的序列化器同理。⇒ 整条记录**只序列化一次**,闸判那一串,写也写那一串。
|
|
209
242
|
*/
|
|
210
|
-
putCtx(sessionId: string, ctx: SealedCheckpointCtx): Promise<
|
|
243
|
+
putCtx(sessionId: string, ctx: SealedCheckpointCtx, claim?: CtxWriteClaim): Promise<CtxClaimPut>;
|
|
211
244
|
/**
|
|
212
245
|
* 🔴 **坏体 ⇒ 拒,绝不读成缺席**([ref],与 SQL 孪生同一条判据)。修前这里是
|
|
213
246
|
* `catch { return null }` + `(rec.ctx as T) ?? null`,于是一个撕裂 / 手改 / 权限读不动的 ctx 文件与
|
|
@@ -224,7 +257,9 @@ export declare class LocalCheckpointStore {
|
|
|
224
257
|
* 本孪生的栅栏是进程内形(`store-contracts.ts` `InProcessClaimFence`):判认领、刷新活性、问腿判据与本口的落盘是**同一个同步段**(原子写本就同步),
|
|
225
258
|
* 中间没有让出,所以认领在写落定之前挪不动。只改既有档(档不在 ⇒ `context_absent`,不建档);形闸同 {@link LocalCheckpointStore.putCtx},在栅栏之前判。
|
|
226
259
|
*/
|
|
227
|
-
rewriteCtxWhileClaimed(sessionId: string,
|
|
260
|
+
rewriteCtxWhileClaimed(sessionId: string, ctx: SealedCheckpointCtx, claim: CtxWriteClaim): Promise<CtxClaimRewrite>;
|
|
261
|
+
/** 两只 ctx 栅栏写(`putCtx` 交认领的那一形 / `rewriteCtxWhileClaimed`)共用的栅栏例程(SQL 孪生同名例程的进程内形):交来的栅栏是 SQL 事务形 ⇒ 响亮抛(装配缺陷);形闸在栅栏之前;判认领、问腿判据、落盘同一个同步段。 */
|
|
262
|
+
private writeCtxWhileClaimed;
|
|
228
263
|
/**
|
|
229
264
|
* 🔴 **一次性迁移的 ctx 行改写店腿**(local 孪生;`checkpoint-store-face.ts` `CheckpointCtxRowsRewriter`,判词与 SQL 孪生 `rewriteCtxRows` 逐条同):
|
|
230
265
|
* 逐档读(信封经读腿**同一只**判形 —— 读不出 ⇒ 计数、跳过、**不删**),`rewrite` 交回新体 ⇒ 信封原样(`sessionId` / `updatedAt` 不动:收割按 `updatedAt` 判)
|
|
@@ -1,24 +1,66 @@
|
|
|
1
|
+
import { writeLogText } from "../observability/logger.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { denySweepOwns, parkedApprovalCard } from "../approval-content-kind.js";
|
|
3
4
|
import { parkRowFacts, skillCardFacts } from "../approval-card.js";
|
|
4
5
|
import { durableRowIdentity } from "../checkpoint-identity.js";
|
|
5
6
|
import { createHash } from "node:crypto";
|
|
6
|
-
import { existsSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
7
|
+
import { closeSync, existsSync, fsyncSync, openSync, readFileSync, readdirSync, rmSync, unlinkSync } from "node:fs";
|
|
8
|
+
import { IS_WIN32 } from "./host-platform.js";
|
|
7
9
|
import { join } from "node:path";
|
|
8
|
-
import { CHECKPOINT_LIST_LIMITS, FileCheckpointStore, atomicWriteFile, ensureDir, executionVerdict, sanitizePathComponent, } from "@sema-agent/core";
|
|
10
|
+
import { CHECKPOINT_LIST_LIMITS, FileCheckpointStore, atomicWriteFile, checkpointDeadlinePassed, ensureDir, executionVerdict, sanitizePathComponent, } from "@sema-agent/core";
|
|
9
11
|
import { approvalPayloadFingerprint } from "./approval-payload-fingerprint.js";
|
|
10
|
-
import { approvalDecisionOfWinner, boundedRuleOffers, boundedToolInput, candidateIdentityOf, pendingRowPrecedes, queueRowGateKind, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS } from "./checkpoint-store-face.js";
|
|
12
|
+
import { approvalDecisionOfWinner, boundedRuleOffers, boundedToolInput, candidateIdentityOf, DENY_SWEEP_PAGE_ROWS, isUnreadableSummaryForm, parkedLegTaskId, pendingRowPrecedes, queueRowGateKind, queueTriageOrder, readRiskDescriptorBody, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS, } from "./checkpoint-store-face.js";
|
|
11
13
|
import { quarantineUnreadableSidecar } from "./local-sidecar-quarantine.js";
|
|
12
|
-
import {
|
|
14
|
+
import { hostSessionOf } from "./checkpoint-index-columns.js";
|
|
15
|
+
import { createZodColumnReader, decodeJsonColumn, foldJsonColumn, isJsonObject, readStringArrayColumn } from "./sql-json-column.js";
|
|
13
16
|
import { UNMANAGED_RETENTION } from "./retention-declaration.js";
|
|
14
17
|
import { assertJsonColumnWritable, createObjectColumnReader } from "./sql-json-column.js";
|
|
15
18
|
import { FENCE_LANDED } from "./store-contracts.js";
|
|
19
|
+
import { recordFailOpen } from "../observability/fail-open.js";
|
|
20
|
+
const isFiniteNumber = (v) => typeof v === "number" && Number.isFinite(v);
|
|
16
21
|
function terminalAtOf(cp) {
|
|
17
|
-
|
|
22
|
+
const createdAt = cp.createdAt;
|
|
23
|
+
const deadline = cp.deadline;
|
|
24
|
+
const deadlineTerm = deadline === undefined ? 0 : isFiniteNumber(deadline) ? deadline : undefined;
|
|
25
|
+
if (!isFiniteNumber(createdAt) || deadlineTerm === undefined)
|
|
26
|
+
return -Infinity;
|
|
27
|
+
return Math.max(createdAt + TERMINAL_BACKSTOP_MS, deadlineTerm + TERMINAL_GRACE_MS);
|
|
28
|
+
}
|
|
29
|
+
function sweepDeadlineKey(deadline) {
|
|
30
|
+
return isFiniteNumber(deadline) ? deadline : -Infinity;
|
|
31
|
+
}
|
|
32
|
+
function sweepPositionPrecedes(a, b) {
|
|
33
|
+
return a.deadline < b.deadline || (a.deadline === b.deadline && a.token < b.token);
|
|
34
|
+
}
|
|
35
|
+
function queueRiskDescriptorOf(gate) {
|
|
36
|
+
const raw = isJsonObject(gate) ? gate.riskDescriptor : undefined;
|
|
37
|
+
if (raw === undefined || raw === null)
|
|
38
|
+
return null;
|
|
39
|
+
const shape = readRiskDescriptorBody(raw);
|
|
40
|
+
if (shape.problem === undefined)
|
|
41
|
+
return shape.value;
|
|
42
|
+
recordFailOpen("server.approvals.risk-descriptor-cell-unreadable");
|
|
43
|
+
return null;
|
|
18
44
|
}
|
|
19
45
|
function ctxFileOf(sessionId) {
|
|
20
46
|
return `${sanitizePathComponent(sessionId).slice(0, 48)}-${createHash("sha256").update(sessionId).digest("hex").slice(0, 12)}.json`;
|
|
21
47
|
}
|
|
48
|
+
export function dropLocalCheckpointCtxStrict(root, sessionId) {
|
|
49
|
+
const dir = localCheckpointStoreDirsFor(root).ctx;
|
|
50
|
+
const path = join(dir, ctxFileOf(sessionId));
|
|
51
|
+
if (!existsSync(path))
|
|
52
|
+
return;
|
|
53
|
+
rmSync(path, { force: true });
|
|
54
|
+
if (IS_WIN32)
|
|
55
|
+
return;
|
|
56
|
+
const fd = openSync(dir, "r");
|
|
57
|
+
try {
|
|
58
|
+
fsyncSync(fd);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
closeSync(fd);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
22
64
|
const CtxRecordSchema = z.object({
|
|
23
65
|
sessionId: z.string(),
|
|
24
66
|
updatedAt: z.number(),
|
|
@@ -62,12 +104,16 @@ export class LocalCheckpointStore {
|
|
|
62
104
|
tmpDir;
|
|
63
105
|
scopes = new Set();
|
|
64
106
|
sessionTokens = new Map();
|
|
107
|
+
hostTokens = new Map();
|
|
108
|
+
hostOfToken = new Map();
|
|
109
|
+
hostSessionsPath;
|
|
65
110
|
opts;
|
|
66
111
|
constructor(root, opts = {}) {
|
|
67
112
|
this.inner = new FileCheckpointStore(root);
|
|
68
113
|
this.opts = opts;
|
|
69
114
|
this.scopesPath = join(root, "checkpoint-scopes.json");
|
|
70
115
|
this.sessionTokensPath = join(root, "checkpoint-session-tokens.json");
|
|
116
|
+
this.hostSessionsPath = join(root, "checkpoint-host-sessions.json");
|
|
71
117
|
const dirs = localCheckpointStoreDirsFor(root);
|
|
72
118
|
this.ctxDir = dirs.ctx;
|
|
73
119
|
this.tmpDir = dirs.tmp;
|
|
@@ -81,7 +127,7 @@ export class LocalCheckpointStore {
|
|
|
81
127
|
catch (e) {
|
|
82
128
|
quarantineUnreadableSidecar(this.scopesPath, "LocalCheckpointStore scope registry", e instanceof Error ? e.message : String(e));
|
|
83
129
|
this.scopeRegistryCorrupt = true;
|
|
84
|
-
|
|
130
|
+
writeLogText("stderr", "LocalCheckpointStore: will rebuild the scope set from the data plane on first read (core listScopes) — enumeration is EMPTY until then");
|
|
85
131
|
}
|
|
86
132
|
}
|
|
87
133
|
if (existsSync(this.sessionTokensPath)) {
|
|
@@ -94,21 +140,66 @@ export class LocalCheckpointStore {
|
|
|
94
140
|
quarantineUnreadableSidecar(this.sessionTokensPath, "LocalCheckpointStore session→tokens index", e instanceof Error ? e.message : String(e));
|
|
95
141
|
}
|
|
96
142
|
}
|
|
143
|
+
if (existsSync(this.hostSessionsPath)) {
|
|
144
|
+
for (const [host, toks] of Object.entries(decodeJsonColumn(readFileSync(this.hostSessionsPath, "utf8"), readSessionTokenIndex, "checkpoint-host-sessions.json (the local card→host-session index)"))) {
|
|
145
|
+
this.indexHost(host, toks);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
registerDurably(record, undo, persist) {
|
|
150
|
+
if (!record())
|
|
151
|
+
return;
|
|
152
|
+
try {
|
|
153
|
+
persist();
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
undo();
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
indexHost(host, tokens) {
|
|
161
|
+
let added = 0;
|
|
162
|
+
for (const t of tokens) {
|
|
163
|
+
if (this.hostOfToken.has(t))
|
|
164
|
+
continue;
|
|
165
|
+
const set = this.hostTokens.get(host) ?? new Set();
|
|
166
|
+
set.add(t);
|
|
167
|
+
this.hostTokens.set(host, set);
|
|
168
|
+
this.hostOfToken.set(t, host);
|
|
169
|
+
added += 1;
|
|
170
|
+
}
|
|
171
|
+
return added;
|
|
172
|
+
}
|
|
173
|
+
unindexHost(host, token) {
|
|
174
|
+
const set = this.hostTokens.get(host);
|
|
175
|
+
set?.delete(token);
|
|
176
|
+
if (set?.size === 0)
|
|
177
|
+
this.hostTokens.delete(host);
|
|
178
|
+
this.hostOfToken.delete(token);
|
|
179
|
+
}
|
|
180
|
+
persistHostSessions() {
|
|
181
|
+
atomicWriteFile(this.tmpDir, this.hostSessionsPath, JSON.stringify(Object.fromEntries([...this.hostTokens].map(([host, set]) => [host, [...set]]))));
|
|
97
182
|
}
|
|
98
183
|
persistSessionTokens() {
|
|
99
184
|
atomicWriteFile(this.tmpDir, this.sessionTokensPath, JSON.stringify(Object.fromEntries([...this.sessionTokens].map(([sid, set]) => [sid, [...set]]))));
|
|
100
185
|
}
|
|
101
186
|
async put(token, cp) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
187
|
+
const host = hostSessionOf(cp);
|
|
188
|
+
this.registerDurably(() => !this.scopes.has(cp.scope) && (this.scopes.add(cp.scope), true), () => this.scopes.delete(cp.scope), () => atomicWriteFile(this.tmpDir, this.scopesPath, JSON.stringify([...this.scopes])));
|
|
189
|
+
this.registerDurably(() => this.indexHost(host, [token]) > 0, () => this.unindexHost(host, token), () => this.persistHostSessions());
|
|
190
|
+
this.registerDurably(() => {
|
|
191
|
+
if (this.sessionTokens.get(cp.sessionId)?.has(token))
|
|
192
|
+
return false;
|
|
107
193
|
const set = this.sessionTokens.get(cp.sessionId) ?? new Set();
|
|
108
194
|
set.add(token);
|
|
109
195
|
this.sessionTokens.set(cp.sessionId, set);
|
|
110
|
-
|
|
111
|
-
}
|
|
196
|
+
return true;
|
|
197
|
+
}, () => {
|
|
198
|
+
const set = this.sessionTokens.get(cp.sessionId);
|
|
199
|
+
set?.delete(token);
|
|
200
|
+
if (set?.size === 0)
|
|
201
|
+
this.sessionTokens.delete(cp.sessionId);
|
|
202
|
+
}, () => this.persistSessionTokens());
|
|
112
203
|
return this.inner.put(token, cp);
|
|
113
204
|
}
|
|
114
205
|
get(token) {
|
|
@@ -150,7 +241,7 @@ export class LocalCheckpointStore {
|
|
|
150
241
|
this.scopes.add(s);
|
|
151
242
|
this.scopeRegistryCorrupt = false;
|
|
152
243
|
atomicWriteFile(this.tmpDir, this.scopesPath, JSON.stringify([...this.scopes]));
|
|
153
|
-
|
|
244
|
+
writeLogText("stderr", `LocalCheckpointStore: scope registry REBUILT from the data plane (${rebuilt.length} scope(s) with pending gates) — enumeration restored`);
|
|
154
245
|
}
|
|
155
246
|
async pendings(scope) {
|
|
156
247
|
await this.ensureScopesRebuilt();
|
|
@@ -189,26 +280,34 @@ export class LocalCheckpointStore {
|
|
|
189
280
|
async listPending(scope) {
|
|
190
281
|
const rows = [];
|
|
191
282
|
for (const { token, cp, summary } of await this.pendings(scope)) {
|
|
192
|
-
const
|
|
193
|
-
const gate = cp.gate;
|
|
194
|
-
const gateKind = queueRowGateKind(gate?.kind);
|
|
283
|
+
const gateKind = queueRowGateKind(summary.gateKind);
|
|
195
284
|
if (gateKind === undefined)
|
|
196
285
|
continue;
|
|
286
|
+
const joinKey = durableRowIdentity("approvals-queue", summary.checkpointId, token);
|
|
287
|
+
const host = this.hostOfToken.get(token);
|
|
288
|
+
const taskId = parkedLegTaskId(cp.state?.rowTaskId, host === undefined ? null : ((await this.opts.getActiveTaskId?.(host)) ?? null));
|
|
289
|
+
const createdAt = summary.createdAt !== undefined ? { createdAt: summary.createdAt } : {};
|
|
290
|
+
const deadline = summary.deadline ?? null;
|
|
291
|
+
if (isUnreadableSummaryForm(summary)) {
|
|
292
|
+
rows.push({ sessionId: summary.sessionId, ...joinKey, scope: summary.scope, toolName: null, toolCallId: null, gateKind, taskId, input: null, ...createdAt, deadline, riskDescriptor: null, rowVerdict: summary.rowVerdict });
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const pa = cp.pendingAction;
|
|
197
296
|
const toolCallId = pa?.toolCallId ?? null;
|
|
198
297
|
rows.push({
|
|
199
|
-
sessionId:
|
|
200
|
-
...
|
|
201
|
-
scope:
|
|
298
|
+
sessionId: summary.sessionId,
|
|
299
|
+
...joinKey,
|
|
300
|
+
scope: summary.scope,
|
|
202
301
|
toolName: pa?.toolName ?? null,
|
|
203
302
|
toolCallId,
|
|
204
303
|
...(toolCallId !== null ? { boundCallId: toolCallId } : {}),
|
|
205
304
|
...(pa?.boundInputHash !== undefined ? { boundInputHash: pa.boundInputHash } : {}),
|
|
206
305
|
gateKind,
|
|
207
|
-
taskId
|
|
306
|
+
taskId,
|
|
208
307
|
input: boundedToolInput(pa?.args),
|
|
209
|
-
createdAt
|
|
210
|
-
deadline
|
|
211
|
-
riskDescriptor: gate
|
|
308
|
+
...createdAt,
|
|
309
|
+
deadline,
|
|
310
|
+
riskDescriptor: queueRiskDescriptorOf(cp.gate),
|
|
212
311
|
...(() => {
|
|
213
312
|
const rs = boundedRuleOffers(pa?.ruleOffers);
|
|
214
313
|
return rs !== undefined ? { ruleOffers: rs } : {};
|
|
@@ -220,15 +319,18 @@ export class LocalCheckpointStore {
|
|
|
220
319
|
rowVerdict: summary.rowVerdict,
|
|
221
320
|
});
|
|
222
321
|
}
|
|
223
|
-
return rows.sort(
|
|
322
|
+
return rows.sort(queueTriageOrder);
|
|
224
323
|
}
|
|
225
324
|
async findPendingTokenBySession(sessionId, scope, binding) {
|
|
226
|
-
return this.pickPendingRow(await this.
|
|
325
|
+
return this.pickPendingRow(await this.axisPendings(sessionId, scope || undefined, binding), binding?.axis === "run" ? undefined : sessionId, binding)?.token ?? null;
|
|
326
|
+
}
|
|
327
|
+
axisPendings(sessionId, scope, binding) {
|
|
328
|
+
return binding?.axis === "run" ? this.runPendings(sessionId, scope) : this.sessionPendings(sessionId, scope);
|
|
227
329
|
}
|
|
228
|
-
pickPendingRow(rows,
|
|
330
|
+
pickPendingRow(rows, cardSessionId, binding) {
|
|
229
331
|
let best;
|
|
230
332
|
for (const row of rows) {
|
|
231
|
-
if (row.cp.sessionId !==
|
|
333
|
+
if (cardSessionId !== undefined && row.cp.sessionId !== cardSessionId)
|
|
232
334
|
continue;
|
|
233
335
|
if (binding?.gateKinds !== undefined) {
|
|
234
336
|
const kind = row.cp.gate?.kind;
|
|
@@ -240,30 +342,11 @@ export class LocalCheckpointStore {
|
|
|
240
342
|
}
|
|
241
343
|
return best;
|
|
242
344
|
}
|
|
243
|
-
async
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
return false;
|
|
247
|
-
let pruned = false;
|
|
248
|
-
for (const t of [...tokens]) {
|
|
249
|
-
const cp = await this.inner.get(t);
|
|
250
|
-
if (!cp) {
|
|
251
|
-
tokens.delete(t);
|
|
252
|
-
pruned = true;
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
if (cp.status === "expired")
|
|
345
|
+
async hasExpiredForRun(runSessionId) {
|
|
346
|
+
for (const t of this.hostTokens.get(runSessionId) ?? []) {
|
|
347
|
+
if ((await this.inner.get(t))?.status === "expired")
|
|
256
348
|
return true;
|
|
257
349
|
}
|
|
258
|
-
if (pruned) {
|
|
259
|
-
if (tokens.size === 0)
|
|
260
|
-
this.sessionTokens.delete(sessionId);
|
|
261
|
-
try {
|
|
262
|
-
this.persistSessionTokens();
|
|
263
|
-
}
|
|
264
|
-
catch {
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
350
|
return false;
|
|
268
351
|
}
|
|
269
352
|
async findDecidedApprovalsForBinding(sessionId, boundCallId) {
|
|
@@ -315,34 +398,68 @@ export class LocalCheckpointStore {
|
|
|
315
398
|
return (await this.inner.get(token))?.scope;
|
|
316
399
|
}
|
|
317
400
|
async peekPendingScope(sessionId, binding) {
|
|
318
|
-
return this.pickPendingRow(await this.
|
|
401
|
+
return this.pickPendingRow(await this.axisPendings(sessionId, undefined, binding), binding?.axis === "run" ? undefined : sessionId, binding)?.cp.scope;
|
|
402
|
+
}
|
|
403
|
+
async runPendings(runSessionId, scope) {
|
|
404
|
+
const out = [];
|
|
405
|
+
for (const token of this.hostTokens.get(runSessionId) ?? []) {
|
|
406
|
+
const cp = await this.inner.get(token);
|
|
407
|
+
if (cp === null || cp.status !== "pending" || (scope !== undefined && cp.scope !== scope))
|
|
408
|
+
continue;
|
|
409
|
+
out.push({ token, cp });
|
|
410
|
+
}
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
async hostSessionOfCard(token) {
|
|
414
|
+
const host = this.hostOfToken.get(token);
|
|
415
|
+
if (host !== undefined)
|
|
416
|
+
return host;
|
|
417
|
+
return (await this.inner.get(token)) === null ? undefined : null;
|
|
418
|
+
}
|
|
419
|
+
async backfillHostSessionsM49() {
|
|
420
|
+
let added = 0;
|
|
421
|
+
for (const [sessionId, toks] of this.sessionTokens)
|
|
422
|
+
added += this.indexHost(sessionId, toks);
|
|
423
|
+
for (const { token, cp } of await this.pendings())
|
|
424
|
+
added += this.indexHost(cp.sessionId, [token]);
|
|
425
|
+
if (added > 0)
|
|
426
|
+
this.persistHostSessions();
|
|
427
|
+
return added;
|
|
319
428
|
}
|
|
320
429
|
async reapExpired(cutoff) {
|
|
321
430
|
let n = 0;
|
|
322
431
|
for (const { token, cp } of await this.pendings()) {
|
|
323
|
-
const deadlineBranch = cp.deadline
|
|
432
|
+
const deadlineBranch = checkpointDeadlinePassed(cp.deadline, cutoff) && !denySweepOwns(cp.gate);
|
|
324
433
|
const terminalBranch = terminalAtOf(cp) <= cutoff;
|
|
325
434
|
if ((deadlineBranch || terminalBranch) && (await this.inner.expire(token, cp.scope)))
|
|
326
435
|
n++;
|
|
327
436
|
}
|
|
328
437
|
return n;
|
|
329
438
|
}
|
|
330
|
-
async listExpiredApprovalGates(cutoff, limit =
|
|
439
|
+
async listExpiredApprovalGates(cutoff, limit = DENY_SWEEP_PAGE_ROWS, after) {
|
|
331
440
|
const hits = [];
|
|
332
|
-
for (const { cp } of await this.pendings()) {
|
|
333
|
-
if (denySweepOwns(cp.gate)
|
|
334
|
-
|
|
441
|
+
for (const { token, cp } of await this.pendings()) {
|
|
442
|
+
if (!denySweepOwns(cp.gate) || !checkpointDeadlinePassed(cp.deadline, cutoff))
|
|
443
|
+
continue;
|
|
444
|
+
const position = { deadline: sweepDeadlineKey(cp.deadline), token };
|
|
445
|
+
if (after !== undefined && !sweepPositionPrecedes(after, position))
|
|
446
|
+
continue;
|
|
447
|
+
hits.push({ sessionId: cp.sessionId, scope: cp.scope, position });
|
|
335
448
|
}
|
|
336
|
-
return hits
|
|
337
|
-
.sort((a, b) => a.deadline - b.deadline)
|
|
338
|
-
.slice(0, limit)
|
|
339
|
-
.map(({ sessionId, scope }) => ({ sessionId, scope }));
|
|
449
|
+
return hits.sort((a, b) => (sweepPositionPrecedes(a.position, b.position) ? -1 : sweepPositionPrecedes(b.position, a.position) ? 1 : 0)).slice(0, limit);
|
|
340
450
|
}
|
|
341
|
-
async putCtx(sessionId, ctx) {
|
|
451
|
+
async putCtx(sessionId, ctx, claim) {
|
|
452
|
+
if (claim !== undefined) {
|
|
453
|
+
return this.writeCtxWhileClaimed(sessionId, ctx, claim, "local claim-fenced write", (path, text) => {
|
|
454
|
+
atomicWriteFile(this.tmpDir, path, text);
|
|
455
|
+
return "written";
|
|
456
|
+
});
|
|
457
|
+
}
|
|
342
458
|
const rec = { sessionId, updatedAt: Date.now(), ctx };
|
|
343
459
|
const text = JSON.stringify(rec);
|
|
344
460
|
assertJsonColumnWritable(text, createCtxRecordReader(), `checkpoint ctx for session ${JSON.stringify(sessionId)} (local write leg)`);
|
|
345
461
|
atomicWriteFile(this.tmpDir, join(this.ctxDir, ctxFileOf(sessionId)), text);
|
|
462
|
+
return "written";
|
|
346
463
|
}
|
|
347
464
|
async getCtx(sessionId) {
|
|
348
465
|
const p = join(this.ctxDir, ctxFileOf(sessionId));
|
|
@@ -351,23 +468,25 @@ export class LocalCheckpointStore {
|
|
|
351
468
|
const rec = refusingCtx(sessionId, () => decodeJsonColumn(readFileSync(p, "utf8"), createCtxRecordReader(), `checkpoint-ctx ${ctxFileOf(sessionId)} for session ${JSON.stringify(sessionId)}`));
|
|
352
469
|
return rec.sessionId === sessionId ? rec.ctx : null;
|
|
353
470
|
}
|
|
354
|
-
async rewriteCtxWhileClaimed(sessionId,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
471
|
+
async rewriteCtxWhileClaimed(sessionId, ctx, claim) {
|
|
472
|
+
return this.writeCtxWhileClaimed(sessionId, ctx, claim, "local claim-fenced rewrite", (path, text) => {
|
|
473
|
+
if (!existsSync(path))
|
|
474
|
+
return "context_absent";
|
|
475
|
+
atomicWriteFile(this.tmpDir, path, text);
|
|
476
|
+
return "written";
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
writeCtxWhileClaimed(sessionId, ctx, claim, leg, write) {
|
|
480
|
+
const fence = claim.fence;
|
|
481
|
+
if ("db" in fence)
|
|
482
|
+
throw new Error(`LocalCheckpointStore ${leg}: the claim fence must be the in-process run store on this data root (wiring defect: the run store and the checkpoint store come from one backend)`);
|
|
358
483
|
const rec = { sessionId, updatedAt: Date.now(), ctx };
|
|
359
484
|
const text = JSON.stringify(rec);
|
|
360
|
-
assertJsonColumnWritable(text, createCtxRecordReader(), `checkpoint ctx for session ${JSON.stringify(sessionId)} (
|
|
485
|
+
assertJsonColumnWritable(text, createCtxRecordReader(), `checkpoint ctx for session ${JSON.stringify(sessionId)} (${leg})`);
|
|
361
486
|
const path = join(this.ctxDir, ctxFileOf(sessionId));
|
|
362
|
-
let outcome = "
|
|
363
|
-
const held =
|
|
364
|
-
|
|
365
|
-
outcome = "claim_released";
|
|
366
|
-
}
|
|
367
|
-
else if (existsSync(path)) {
|
|
368
|
-
atomicWriteFile(this.tmpDir, path, text);
|
|
369
|
-
outcome = "written";
|
|
370
|
-
}
|
|
487
|
+
let outcome = "claim_released";
|
|
488
|
+
const held = fence.whileHoldingClaim(sessionId, claim.taskId, (run) => {
|
|
489
|
+
outcome = claim.legHolds(run) ? write(path, text) : "claim_released";
|
|
371
490
|
return FENCE_LANDED;
|
|
372
491
|
});
|
|
373
492
|
return held ? outcome : "claim_released";
|
|
@@ -413,7 +532,7 @@ export class LocalCheckpointStore {
|
|
|
413
532
|
}
|
|
414
533
|
if (rec.updatedAt >= cutoff)
|
|
415
534
|
continue;
|
|
416
|
-
if ((await this.findPendingTokenBySession(rec.sessionId)) !== null)
|
|
535
|
+
if ((await this.findPendingTokenBySession(rec.sessionId, undefined, { axis: "run" })) !== null)
|
|
417
536
|
continue;
|
|
418
537
|
if ((await this.opts.getActiveTaskId?.(rec.sessionId)) !== undefined)
|
|
419
538
|
continue;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createLogger } from "../observability/logger.js";
|
|
1
2
|
import { closeSync, constants as FS, fchmodSync, fstatSync, lstatSync, openSync, readdirSync } from "node:fs";
|
|
2
3
|
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
4
|
import { physicalPathOf } from "@sema-agent/core";
|
|
@@ -45,7 +46,7 @@ const emit = (sink, msg, meta) => {
|
|
|
45
46
|
sink(msg, meta);
|
|
46
47
|
}
|
|
47
48
|
catch {
|
|
48
|
-
|
|
49
|
+
createLogger().warn(msg, meta);
|
|
49
50
|
}
|
|
50
51
|
};
|
|
51
52
|
const sameObject = (a, b) => a.dev === b.dev && a.ino === b.ino;
|