@sema-agent/server 7.145.0 → 7.147.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 +876 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/USAGE.md +374 -99
- package/deploy/facts/CHANGES.json +25 -0
- package/deploy/facts/README.md +57 -0
- package/deploy/facts/lanes.json +61 -0
- package/deploy/facts/lanes.schema.json +57 -0
- package/deploy/facts/sandbox-rbac.json +113 -0
- package/deploy/facts/sandbox-rbac.schema.json +74 -0
- package/deploy/facts/sealed-key.json +9 -0
- package/deploy/facts/sealed-key.schema.json +52 -0
- package/deploy/sema-up/README.md +2 -2
- package/deploy/sema-up/chart/templates/_helpers.tpl +41 -0
- package/deploy/sema-up/chart/templates/sandbox-rbac.yaml +47 -7
- package/deploy/sema-up/chart/templates/server-v4pro.yaml +9 -4
- package/deploy/sema-up/chart/templates/server.yaml +9 -4
- package/deploy/sema-up/chart/values.yaml +8 -1
- package/deploy/sema-up/cluster-up.sh +2 -1
- package/deploy/sema-up/lib/flagshape.sh +4 -0
- package/deploy/sema-up/lib/lanes.json +2 -5
- package/deploy/sema-up/sema-up.sh +12 -9
- package/deploy/sema-up/stack/compose.yaml +5 -4
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +34 -17
- package/dist/adoption/import-limits.d.ts +6 -0
- package/dist/adoption/import-limits.js +7 -0
- package/dist/adoption/import.d.ts +62 -0
- package/dist/adoption/import.js +107 -0
- package/dist/adoption/wire.d.ts +52 -0
- package/dist/adoption/wire.js +9 -0
- package/dist/approval-ask-machine.d.ts +2 -2
- package/dist/approval-card.d.ts +7 -16
- package/dist/approval-card.js +0 -4
- package/dist/approval-gate-currency.d.ts +1 -1
- package/dist/approval-gate-currency.js +1 -1
- package/dist/approval-reconciler.d.ts +1 -1
- package/dist/approval.d.ts +3 -3
- package/dist/audit.js +2 -2
- package/dist/bench/s1/live-deps.js +3 -1
- package/dist/boot/crash-last.js +2 -1
- package/dist/boot/deployment-mods.d.ts +11 -1
- package/dist/boot/deployment-mods.js +15 -2
- package/dist/boot/device-lane.js +7 -5
- package/dist/boot/engine-lease.d.ts +195 -22
- package/dist/boot/engine-lease.js +146 -20
- package/dist/boot/execution-env.d.ts +5 -0
- package/dist/boot/execution-env.js +57 -33
- package/dist/boot/execution-lane.d.ts +37 -9
- package/dist/boot/execution-lane.js +74 -20
- package/dist/boot/exit-boundary.d.ts +50 -0
- package/dist/boot/exit-boundary.js +32 -0
- package/dist/boot/exit-last.d.ts +20 -4
- package/dist/boot/exit-last.js +23 -5
- package/dist/boot/governance-seams.d.ts +2 -2
- package/dist/boot/governance-seams.js +1 -0
- package/dist/boot/leader.js +1 -1
- package/dist/boot/memory-boundary.d.ts +11 -11
- package/dist/boot/memory-boundary.js +3 -3
- package/dist/boot/memory-consolidation.d.ts +42 -41
- package/dist/boot/memory-consolidation.js +26 -28
- package/dist/boot/org-memory.js +3 -2
- package/dist/boot/parked-revive-gate.d.ts +1 -1
- package/dist/boot/parked-revive-gate.js +1 -1
- package/dist/boot/reapers.d.ts +12 -4
- package/dist/boot/reapers.js +40 -16
- package/dist/boot/resolve-spec.d.ts +2 -0
- package/dist/boot/resolve-spec.js +126 -123
- package/dist/boot/retention-lane.d.ts +4 -42
- package/dist/boot/runner-deps.js +1 -1
- package/dist/boot/session-faces.d.ts +1 -0
- package/dist/boot/session-faces.js +11 -3
- package/dist/boot/shutdown.js +27 -9
- package/dist/boot/stage-01-config.d.ts +1 -1
- package/dist/boot/stage-01-config.js +7 -3
- package/dist/boot/stage-02-web-admin-pull.d.ts +1 -1
- package/dist/boot/stage-02-web-admin-pull.js +10 -8
- package/dist/boot/stage-03-store-backend.d.ts +2 -1
- package/dist/boot/stage-03-store-backend.js +2 -2
- package/dist/boot/stage-04-stores.d.ts +2 -1
- package/dist/boot/stage-05-execution-env.d.ts +4 -1
- package/dist/boot/stage-05-execution-env.js +6 -6
- package/dist/boot/stage-06-runners.d.ts +5 -2
- package/dist/boot/stage-06-runners.js +12 -13
- package/dist/boot/stage-07-capability-layer.d.ts +5 -2
- package/dist/boot/stage-07-capability-layer.js +7 -7
- package/dist/boot/stage-08-reapers.d.ts +5 -2
- package/dist/boot/stage-08-reapers.js +3 -3
- package/dist/boot/stage-09-leader.d.ts +6 -2
- package/dist/boot/stage-10-http-server.d.ts +6 -2
- package/dist/boot/stage-10-http-server.js +5 -3
- package/dist/boot/stores.d.ts +10 -0
- package/dist/boot/stores.js +53 -26
- package/dist/boot/web-admin.js +3 -3
- package/dist/boot/workflow-orchestration.d.ts +1 -1
- package/dist/boot/workflow-orchestration.js +2 -1
- package/dist/capabilities/center-plugins.d.ts +2 -0
- package/dist/capabilities/center-plugins.js +6 -2
- package/dist/capabilities/composite-members.d.ts +4 -1
- package/dist/capabilities/composite-members.js +4 -1
- package/dist/capabilities/execution-lane.d.ts +7 -7
- package/dist/capabilities/execution-lane.js +2 -2
- package/dist/capabilities/hands-lane.d.ts +1 -1
- package/dist/capabilities/scenarios.d.ts +34 -20
- package/dist/capabilities/scenarios.js +13 -9
- package/dist/capabilities/settings-contract.d.ts +29 -0
- package/dist/capabilities/settings-contract.js +14 -0
- package/dist/capabilities/skills.d.ts +5 -5
- package/dist/capability-facts.d.ts +56 -1
- package/dist/capability-facts.js +59 -8
- package/dist/center-credential-renewer.js +3 -2
- package/dist/checkpoint-ctx-seal-m28.d.ts +1 -1
- package/dist/config-catalog.js +19 -9
- package/dist/config-invariants.d.ts +18 -3
- package/dist/config-invariants.js +36 -19
- package/dist/config-lkg.d.ts +1 -1
- package/dist/config-lkg.js +5 -6
- package/dist/config-provider.d.ts +2 -2
- package/dist/config-provider.js +2 -0
- package/dist/config-types.d.ts +228 -185
- package/dist/config.d.ts +74 -6
- package/dist/config.js +146 -64
- package/dist/degenerate-instrument.js +1 -1
- package/dist/deleted-session-ids.d.ts +19 -0
- package/dist/deleted-session-ids.js +26 -0
- package/dist/deploy-facts.d.ts +155 -0
- package/dist/deploy-facts.js +95 -0
- package/dist/deployment-shape.d.ts +21 -12
- package/dist/deployment-shape.js +24 -6
- package/dist/device-ws-hub.d.ts +48 -3
- package/dist/device-ws-hub.js +48 -2
- package/dist/env-facts.d.ts +7 -5
- package/dist/env-facts.js +10 -6
- package/dist/error-code-family.d.ts +35 -0
- package/dist/error-code-family.js +26 -0
- package/dist/execution-config-root.d.ts +5 -5
- package/dist/execution-config-root.js +5 -5
- package/dist/execution-env-purpose.d.ts +14 -0
- package/dist/execution-env-purpose.js +29 -0
- package/dist/execution-lane-caps.d.ts +49 -86
- package/dist/execution-lane-caps.js +52 -62
- package/dist/execution-placement.d.ts +18 -2
- package/dist/execution-placement.js +19 -0
- package/dist/file-history-disclosure.d.ts +2 -2
- package/dist/fleet/drain-entry.d.ts +46 -3
- package/dist/fleet/drain-entry.js +6 -0
- package/dist/fleet/fleet-bus.d.ts +2 -1
- package/dist/fleet/serving-lease.js +3 -4
- package/dist/history-anchor.d.ts +22 -0
- package/dist/history-anchor.js +14 -0
- package/dist/hooks/branch-transcript.d.ts +1 -1
- package/dist/hooks/branch-transcript.js +1 -0
- package/dist/hooks/classic-stations.d.ts +25 -8
- package/dist/hooks/classic-stations.js +29 -3
- package/dist/hooks/command-spawn.d.ts +1 -4
- package/dist/hooks/command-spawn.js +0 -11
- package/dist/hooks/hook-runner.d.ts +85 -24
- package/dist/hooks/hook-runner.js +326 -109
- package/dist/hooks/hook-source.d.ts +14 -2
- package/dist/hooks/hook-source.js +8 -0
- package/dist/http/active-run-conflict.d.ts +1 -1
- package/dist/http/active-run-conflict.js +1 -1
- package/dist/http/admission.js +11 -1
- package/dist/http/approval-sweeps.d.ts +2 -5
- package/dist/http/approval-sweeps.js +3 -2
- package/dist/http/checkpoint-ctx.d.ts +76 -71
- package/dist/http/checkpoint-ctx.js +40 -40
- package/dist/http/claim-latency.d.ts +10 -0
- package/dist/http/claim-latency.js +12 -0
- package/dist/http/dispatch.js +19 -3
- package/dist/http/durable-run-leg.d.ts +5 -0
- package/dist/http/durable-run-leg.js +3 -1
- package/dist/http/execution-context.d.ts +7 -1
- package/dist/http/execution-context.js +13 -0
- package/dist/http/health-self-report.d.ts +6 -2
- package/dist/http/health-self-report.js +3 -2
- package/dist/http/memory-compliance-failure-reply.d.ts +2 -2
- package/dist/http/memory-compliance-failure-reply.js +5 -15
- package/dist/http/memory-control-plane-corrupt-reply.d.ts +25 -0
- package/dist/http/memory-control-plane-corrupt-reply.js +19 -0
- package/dist/http/memory-store-refusal-reply.d.ts +3 -3
- package/dist/http/memory-store-refusal-reply.js +3 -0
- package/dist/http/owner-access.d.ts +11 -0
- package/dist/http/owner-access.js +7 -4
- package/dist/http/principal-gate.d.ts +28 -16
- package/dist/http/principal-gate.js +10 -19
- package/dist/http/request-guards.d.ts +2 -2
- package/dist/http/request-guards.js +5 -5
- package/dist/http/resume-legs.d.ts +29 -10
- package/dist/http/resume-legs.js +94 -56
- package/dist/http/rewind-files-reply.d.ts +34 -0
- package/dist/http/rewind-files-reply.js +36 -0
- package/dist/http/route-ctx.d.ts +43 -26
- package/dist/http/route-table.js +4 -0
- package/dist/http/routes/adoption.d.ts +11 -0
- package/dist/http/routes/adoption.js +80 -6
- package/dist/http/routes/agents-roster.js +1 -0
- package/dist/http/routes/approvals-assistant.js +7 -26
- package/dist/http/routes/background.js +1 -0
- package/dist/http/routes/capabilities.js +12 -3
- package/dist/http/routes/devices.js +1 -1
- package/dist/http/routes/diagnostics.d.ts +9 -14
- package/dist/http/routes/diagnostics.js +10 -20
- package/dist/http/routes/engine.d.ts +31 -0
- package/dist/http/routes/engine.js +81 -0
- package/dist/http/routes/memory-bundle.js +3 -0
- package/dist/http/routes/memory-consolidation.js +3 -5
- package/dist/http/routes/memory-origin.d.ts +2 -2
- package/dist/http/routes/memory-origin.js +2 -4
- package/dist/http/routes/memory-policy.js +5 -1
- package/dist/http/routes/notify-wake.js +2 -1
- package/dist/http/routes/observability.js +3 -6
- package/dist/http/routes/projects.d.ts +70 -0
- package/dist/http/routes/projects.js +86 -0
- package/dist/http/routes/rules.js +30 -2
- package/dist/http/routes/runs.js +15 -11
- package/dist/http/routes/session-sync.js +39 -35
- package/dist/http/routes/sessions-list.d.ts +1 -1
- package/dist/http/routes/sessions.d.ts +7 -1
- package/dist/http/routes/sessions.js +108 -2
- package/dist/http/routes/tasks.js +32 -8
- package/dist/http/routes/trace-usage.js +1 -1
- package/dist/http/run-concurrency-cap.d.ts +86 -0
- package/dist/http/run-concurrency-cap.js +54 -0
- package/dist/http/server.d.ts +31 -14
- package/dist/http/server.js +29 -3
- package/dist/http/stored-body-replay.d.ts +12 -7
- package/dist/http/stored-body-replay.js +28 -5
- package/dist/http/wire-types.d.ts +27 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/instruction-source-notice.d.ts +1 -1
- package/dist/json-body-limit.d.ts +8 -0
- package/dist/json-body-limit.js +2 -0
- package/dist/leader/diffout.d.ts +1 -1
- package/dist/local-data-root.d.ts +2 -2
- package/dist/memory-embedder-reembed.d.ts +38 -0
- package/dist/memory-embedder-reembed.js +20 -0
- package/dist/memory-incident-sink.d.ts +0 -28
- package/dist/memory-incident-sink.js +5 -0
- package/dist/memory-operator-faces.d.ts +9 -4
- package/dist/memory-scope-stores.d.ts +9 -7
- package/dist/memory-scope-stores.js +3 -14
- package/dist/memory-scope.d.ts +38 -2
- package/dist/memory-scope.js +33 -2
- package/dist/memory-store-refusal.d.ts +17 -4
- package/dist/memory-store-refusal.js +1 -1
- package/dist/memory-sync-client.d.ts +2 -0
- package/dist/memory-sync-client.js +13 -11
- package/dist/memory-sync.js +1 -1
- package/dist/model-compat.d.ts +35 -21
- package/dist/model-compat.js +49 -21
- package/dist/model-entry-refusal.d.ts +11 -1
- package/dist/model-entry-refusal.js +7 -0
- package/dist/namespaced-rule-name.d.ts +18 -1
- package/dist/namespaced-rule-name.js +12 -0
- package/dist/net-address.d.ts +53 -0
- package/dist/net-address.js +111 -0
- package/dist/observability/fail-open.d.ts +29 -17
- package/dist/observability/fail-open.js +29 -17
- package/dist/observability/metrics.d.ts +2 -0
- package/dist/observability/metrics.js +2 -0
- package/dist/observability/secret-env-scrub.d.ts +30 -4
- package/dist/observability/secret-env-scrub.js +15 -3
- package/dist/orchestration/workflow-agent-session-index.d.ts +7 -12
- package/dist/orchestration/workflow-agent-session-index.js +1 -6
- package/dist/orchestration/workflow-completion-inbox.d.ts +26 -6
- package/dist/orchestration/workflow-completion-inbox.js +63 -45
- package/dist/orchestration/workflow-notify-journal.js +2 -3
- package/dist/org-delivery-gate.js +1 -1
- package/dist/org-memory-admission.d.ts +5 -2
- package/dist/org-memory-admission.js +25 -10
- package/dist/parked-decide.d.ts +33 -26
- package/dist/parked-decide.js +36 -44
- package/dist/peer-directory.d.ts +6 -12
- package/dist/peer-directory.js +5 -1
- package/dist/plugins/approval-ask-store-file.d.ts +10 -2
- package/dist/plugins/approval-ask-store-file.js +37 -4
- package/dist/plugins/approval-ask-store-memory.d.ts +5 -3
- package/dist/plugins/approval-ask-store-memory.js +11 -2
- package/dist/plugins/approval-ask-store-sql.d.ts +3 -0
- package/dist/plugins/approval-ask-store-sql.js +3 -1
- package/dist/plugins/blob-backend.d.ts +38 -195
- package/dist/plugins/blob-backend.js +33 -229
- package/dist/plugins/caching-session-store.d.ts +12 -5
- package/dist/plugins/caching-session-store.js +3 -0
- package/dist/plugins/checkpoint-index-columns.d.ts +1 -1
- package/dist/plugins/checkpoint-index-columns.js +3 -2
- package/dist/plugins/checkpoint-store-face.d.ts +426 -0
- package/dist/plugins/checkpoint-store-face.js +152 -0
- package/dist/plugins/device-store-sql.d.ts +2 -2
- package/dist/plugins/device-store-sql.js +5 -10
- package/dist/plugins/execution-lane-rename-m40.d.ts +20 -0
- package/dist/plugins/execution-lane-rename-m40.js +10 -0
- package/dist/plugins/execution-placement-sql.d.ts +63 -88
- package/dist/plugins/execution-placement-sql.js +94 -54
- package/dist/plugins/file-run-store.d.ts +26 -18
- package/dist/plugins/file-run-store.js +64 -75
- package/dist/plugins/fork-routing-session-store.d.ts +6 -2
- package/dist/plugins/fork-routing-session-store.js +2 -2
- package/dist/plugins/imported-layer-root-retirement.d.ts +22 -11
- package/dist/plugins/imported-layer-root-retirement.js +4 -8
- package/dist/plugins/inbox-payload-column.d.ts +14 -0
- package/dist/plugins/inbox-payload-column.js +13 -0
- package/dist/plugins/local-checkpoint-store.d.ts +7 -2
- package/dist/plugins/local-checkpoint-store.js +13 -8
- package/dist/plugins/local-data-dir-modes-m39.d.ts +48 -0
- package/dist/plugins/local-data-dir-modes-m39.js +182 -0
- package/dist/plugins/local-engine-high-water.d.ts +11 -0
- package/dist/plugins/local-engine-high-water.js +59 -0
- package/dist/plugins/local-session-store.d.ts +119 -30
- package/dist/plugins/local-session-store.js +156 -53
- package/dist/plugins/local-task-attachment-store.d.ts +2 -0
- package/dist/plugins/local-task-attachment-store.js +10 -11
- package/dist/plugins/memory-embedder-fingerprint.d.ts +33 -10
- package/dist/plugins/memory-embedder-fingerprint.js +52 -12
- package/dist/plugins/memory-embedder.d.ts +1 -1
- package/dist/plugins/memory-embedder.js +2 -2
- package/dist/plugins/memory-engine-pg.d.ts +30 -6
- package/dist/plugins/memory-engine-pg.js +96 -214
- package/dist/plugins/memory-engine-sql-apply.d.ts +130 -0
- package/dist/plugins/memory-engine-sql-apply.js +358 -0
- package/dist/plugins/memory-engine-tidb.d.ts +38 -9
- package/dist/plugins/memory-engine-tidb.js +99 -230
- package/dist/plugins/memory-key-guards.d.ts +1 -1
- package/dist/plugins/memory-origin-law.d.ts +3 -3
- package/dist/plugins/one-time-migrations.d.ts +169 -83
- package/dist/plugins/one-time-migrations.js +295 -235
- package/dist/plugins/owner-only-file-mode.d.ts +29 -0
- package/dist/plugins/owner-only-file-mode.js +141 -0
- package/dist/plugins/permission-rule-store-file.d.ts +17 -3
- package/dist/plugins/permission-rule-store-file.js +20 -1
- package/dist/plugins/pg-pool.d.ts +2 -1
- package/dist/plugins/pg-pool.js +12 -5
- package/dist/plugins/release-version.d.ts +20 -0
- package/dist/plugins/release-version.js +28 -0
- package/dist/plugins/remote-env-adb.d.ts +20 -4
- package/dist/plugins/remote-env-adb.js +39 -11
- package/dist/plugins/remote-env-e2b.d.ts +12 -3
- package/dist/plugins/remote-env-e2b.js +6 -4
- package/dist/plugins/remote-env-host.d.ts +9 -1
- package/dist/plugins/remote-env-host.js +6 -5
- package/dist/plugins/remote-env-k8s.d.ts +5 -2
- package/dist/plugins/remote-env-k8s.js +15 -4
- package/dist/plugins/remote-env-local-docker.d.ts +4 -1
- package/dist/plugins/remote-env-local-docker.js +3 -3
- package/dist/plugins/remote-env-ssh.d.ts +8 -2
- package/dist/plugins/remote-env-ssh.js +26 -24
- package/dist/plugins/remote-shell.d.ts +59 -30
- package/dist/plugins/remote-shell.js +175 -62
- package/dist/plugins/retention-declaration.d.ts +37 -0
- package/dist/plugins/retention-declaration.js +9 -0
- package/dist/plugins/retention-deployment.d.ts +126 -0
- package/dist/plugins/retention-deployment.js +88 -0
- package/dist/plugins/retention-lane-store-sql.d.ts +74 -4
- package/dist/plugins/retention-lane-store-sql.js +103 -1
- package/dist/plugins/retention-sql.d.ts +29 -0
- package/dist/plugins/retention-sql.js +8 -0
- package/dist/plugins/run-store-sql.js +2 -2
- package/dist/plugins/schema-consistency.d.ts +0 -6
- package/dist/plugins/schema-consistency.js +1 -2
- package/dist/plugins/schema-ensure-legs.d.ts +1 -1
- package/dist/plugins/schema-ensure-legs.js +13 -3
- package/dist/plugins/session-ext-table.d.ts +74 -0
- package/dist/plugins/session-ext-table.js +121 -0
- package/dist/plugins/session-fork.d.ts +31 -9
- package/dist/plugins/session-fork.js +3 -2
- package/dist/plugins/session-placement.d.ts +4 -2
- package/dist/plugins/session-row-sql.d.ts +8 -7
- package/dist/plugins/session-row-sql.js +15 -7
- package/dist/plugins/session-store-sql.d.ts +131 -0
- package/dist/plugins/session-store-sql.js +298 -0
- package/dist/plugins/session-workspace-cell.d.ts +2 -2
- package/dist/plugins/session-workspace-cell.js +2 -2
- package/dist/plugins/shared-memory-store-sql.d.ts +10 -0
- package/dist/plugins/shared-memory-store-sql.js +13 -13
- package/dist/plugins/snapshot-bucket-presence.js +1 -1
- package/dist/plugins/sql-driver.d.ts +23 -7
- package/dist/plugins/sql-driver.js +41 -8
- package/dist/plugins/sql-errors.d.ts +5 -2
- package/dist/plugins/sql-errors.js +4 -0
- package/dist/plugins/sql-json-column.d.ts +5 -1
- package/dist/plugins/store-backend.d.ts +46 -16
- package/dist/plugins/store-backend.js +192 -69
- package/dist/plugins/store-contracts.d.ts +10 -13
- package/dist/plugins/store-contracts.js +1 -9
- package/dist/plugins/store-sweep.d.ts +63 -0
- package/dist/plugins/store-sweep.js +48 -0
- package/dist/plugins/task-attachment-store.d.ts +6 -8
- package/dist/plugins/task-attachment-store.js +15 -10
- package/dist/plugins/task-list-store-sql.d.ts +1 -1
- package/dist/plugins/text-column-capacity.d.ts +21 -0
- package/dist/plugins/text-column-capacity.js +5 -0
- package/dist/plugins/tidb-pool.d.ts +3 -2
- package/dist/plugins/tidb-pool.js +20 -32
- package/dist/plugins/user-input-ledger-sql.d.ts +1 -1
- package/dist/prompt-screen.d.ts +6 -9
- package/dist/prompt-screen.js +2 -5
- package/dist/read-face-posture.d.ts +6 -6
- package/dist/read-face-posture.js +2 -2
- package/dist/request-value-closure.d.ts +5 -5
- package/dist/request-value-closure.js +1 -1
- package/dist/rules-consent.d.ts +48 -27
- package/dist/rules-consent.js +147 -23
- package/dist/run-cancel-context.d.ts +4 -1
- package/dist/run-cancel-context.js +2 -1
- package/dist/run-local.js +17 -13
- package/dist/runs.d.ts +48 -30
- package/dist/runs.js +27 -17
- package/dist/runtime-caps-resolver.d.ts +15 -8
- package/dist/runtime-caps-resolver.js +14 -10
- package/dist/sandbox-egress-policy.js +6 -11
- package/dist/sandbox-rbac-rules.d.ts +88 -0
- package/dist/sandbox-rbac-rules.js +80 -0
- package/dist/sealed-key-layout.d.ts +16 -0
- package/dist/sealed-key-layout.js +3 -0
- package/dist/sealed-key.js +8 -6
- package/dist/security.d.ts +43 -9
- package/dist/security.js +9 -2
- package/dist/sema-config-dir.js +2 -2
- package/dist/server-secret-env.d.ts +2 -0
- package/dist/service-version.d.ts +2 -1
- package/dist/service-version.js +2 -2
- package/dist/session-error-wire.d.ts +1 -1
- package/dist/session-incarnation.d.ts +8 -5
- package/dist/session-notify-door.d.ts +5 -3
- package/dist/session-resident-background.d.ts +110 -0
- package/dist/session-resident-background.js +88 -0
- package/dist/session-row.d.ts +1 -1
- package/dist/session-sync-kernel.d.ts +53 -14
- package/dist/session-sync-kernel.js +70 -1
- package/dist/session-sync.d.ts +5 -3
- package/dist/session-workspace.d.ts +12 -2
- package/dist/session-workspace.js +6 -0
- package/dist/sighup-idle.d.ts +9 -7
- package/dist/sighup-idle.js +4 -5
- package/dist/spec-fields.d.ts +16 -0
- package/dist/spec-fields.js +7 -0
- package/dist/store-posture.d.ts +2 -1
- package/dist/stored-request-env-credentials-m38.d.ts +3 -0
- package/dist/stored-request-env-credentials-m38.js +8 -0
- package/dist/stored-request-hooks-m20.d.ts +3 -2
- package/dist/stored-request-hooks-m20.js +19 -14
- package/dist/stored-request-prompt-profile-m30.d.ts +1 -1
- package/dist/stores-sql/blob-index-sql.d.ts +148 -0
- package/dist/stores-sql/blob-index-sql.js +154 -0
- package/dist/{plugins → stores-sql}/checkpoint-store-sql.d.ts +14 -428
- package/dist/{plugins → stores-sql}/checkpoint-store-sql.js +43 -220
- package/dist/{plugins → stores-sql}/file-history-store-sql.d.ts +23 -11
- package/dist/{plugins → stores-sql}/file-history-store-sql.js +23 -18
- package/dist/{plugins → stores-sql}/mailbox-store-sql.d.ts +2 -2
- package/dist/{plugins → stores-sql}/mailbox-store-sql.js +4 -4
- package/dist/{plugins → stores-sql}/pg-session-storage.d.ts +27 -67
- package/dist/{plugins → stores-sql}/pg-session-storage.js +82 -207
- package/dist/{plugins → stores-sql}/retention-store-sql.d.ts +123 -217
- package/dist/{plugins → stores-sql}/retention-store-sql.js +66 -190
- package/dist/{plugins → stores-sql}/roster-store-sql.d.ts +2 -2
- package/dist/{plugins → stores-sql}/roster-store-sql.js +1 -1
- package/dist/{plugins → stores-sql}/session-event-payload.d.ts +1 -1
- package/dist/{plugins → stores-sql}/session-event-payload.js +1 -1
- package/dist/stores-sql/session-policy-store-sql.d.ts +1 -1
- package/dist/stores-sql/session-write-hooks.d.ts +59 -0
- package/dist/stores-sql/session-write-hooks.js +2 -0
- package/dist/{plugins → stores-sql}/tidb-session-storage.d.ts +10 -11
- package/dist/{plugins → stores-sql}/tidb-session-storage.js +10 -21
- package/dist/{plugins → stores-sql}/tidb-session-store.d.ts +35 -112
- package/dist/{plugins → stores-sql}/tidb-session-store.js +73 -169
- package/dist/{plugins → stores-sql}/tool-result-store-sql.d.ts +3 -3
- package/dist/{plugins → stores-sql}/tool-result-store-sql.js +6 -6
- package/dist/stores-sql/windowed-session-storage.d.ts +56 -0
- package/dist/stores-sql/windowed-session-storage.js +61 -0
- package/dist/{plugins → stores-sql}/workflow-journal-store-sql.d.ts +7 -12
- package/dist/{plugins → stores-sql}/workflow-journal-store-sql.js +3 -8
- package/dist/task-a2a.d.ts +7 -1
- package/dist/task-a2a.js +15 -14
- package/dist/task-cwd.d.ts +11 -3
- package/dist/task-cwd.js +17 -1
- package/dist/task-mcp.d.ts +10 -2
- package/dist/task-mcp.js +13 -16
- package/dist/task-settings.d.ts +68 -8
- package/dist/task-settings.js +63 -6
- package/dist/tool-approval.d.ts +23 -10
- package/dist/tool-approval.js +10 -6
- package/dist/trace/core-keyset-guard.d.ts +17 -10
- package/dist/trace/engine-notice-wire.d.ts +1 -1
- package/dist/trace/engine-notice-wire.js +4 -0
- package/dist/trace/exit-seat.d.ts +29 -1
- package/dist/trace/exit-seat.js +4 -0
- package/dist/trace/project.d.ts +33 -16
- package/dist/trace/project.js +21 -9
- package/dist/trace/redact.d.ts +13 -2
- package/dist/trace/redact.js +347 -78
- package/dist/trace/self-minted-wire.d.ts +587 -16
- package/dist/trace/self-minted-wire.js +215 -9
- package/dist/trace/sema-provenance.d.ts +45 -41
- package/dist/trace/sema-provenance.js +81 -10
- package/dist/trace/task-notification-facets.d.ts +70 -2
- package/dist/trace/task-notification-facets.js +71 -1
- package/dist/trace/wire-projection-faces.d.ts +39 -3
- package/dist/trace/wire-projection-faces.js +27 -2
- package/dist/unread-request-members.d.ts +66 -0
- package/dist/unread-request-members.js +41 -0
- package/dist/usage-analytics.d.ts +4 -0
- package/dist/user-input-ledger.d.ts +2 -2
- package/dist/web-admin-client/apply-effective.js +22 -26
- package/dist/web-admin-client/candidate-gate.d.ts +35 -3
- package/dist/web-admin-client/candidate-gate.js +53 -5
- package/dist/web-admin-client/center-request.d.ts +4 -1
- package/dist/web-admin-client/center-request.js +2 -1
- package/dist/web-admin-client/effective-keys.js +0 -1
- package/dist/web-admin-client/facade.d.ts +1 -1
- package/dist/web-admin-client/http-client.d.ts +1 -0
- package/dist/web-admin-client/http-client.js +17 -9
- package/dist/web-admin-client/restart-signal.js +5 -2
- package/dist/web-admin-client/skills-mcp.d.ts +20 -6
- package/dist/web-admin-client/skills-mcp.js +26 -21
- package/dist/web-admin-client/types.d.ts +34 -49
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +2 -2
- package/package.json +22 -13
- package/scripts/drain-check-local.mjs +8 -55
- package/scripts/drain-check.mysql.sql +3 -40
- package/scripts/drain-check.pg.sql +3 -40
- package/skills/update-config.md +1 -1
- package/wire-changes/server@7.146.0.json +3221 -0
- package/wire-changes/server@7.147.0.json +813 -0
- package/dist/approval-batch-census.d.ts +0 -27
- package/dist/approval-batch-census.js +0 -27
|
@@ -12,18 +12,40 @@
|
|
|
12
12
|
* (`RunRegistry` / `RouteHelpers` / `RouteLegs` / `ReturnType<typeof createRequestGuards>`),不手抄签名 ⇒ 不会漂。
|
|
13
13
|
*/
|
|
14
14
|
import type { IncomingMessage } from "node:http";
|
|
15
|
-
import { CheckpointError, type QuestionAnswer, type CheckpointToken } from "@sema-agent/core";
|
|
15
|
+
import { CheckpointError, type QuestionAnswer, type CheckpointToken, type PendingSteerInput } from "@sema-agent/core";
|
|
16
16
|
import type { DecideBinding, DecidedAction } from "./wire-types.js";
|
|
17
17
|
import type { CheckpointStoreFull } from "../plugins/store-backend.js";
|
|
18
18
|
import type { HostDecision } from "../host-decision.js";
|
|
19
19
|
import { type GateSighting } from "../approval-gate-currency.js";
|
|
20
20
|
import { type PlanApprovePermissionModeAfter } from "../task-settings.js";
|
|
21
|
-
import type { RouteCtxBase, DriveResumeArgs, PreparedPlanReview, ResumeLegOutcome, WorkflowDecisionDelivery } from "./route-ctx.js";
|
|
21
|
+
import type { RouteCtxBase, DriveResumeArgs, PreparedPlanReview, RememberSessionRequest, ResumeCheckpointOutcome, ResumeLegOutcome, WorkflowDecisionDelivery } from "./route-ctx.js";
|
|
22
22
|
import type { RunRegistry, RouteHelpers, RouteLegs } from "./route-ctx.js";
|
|
23
23
|
import type { createRequestGuards } from "./request-guards.js";
|
|
24
24
|
import type { FlatServiceDeps } from "./server.js";
|
|
25
25
|
import { type ResumeRefusalAnswer } from "./checkpoint-ctx.js";
|
|
26
26
|
import { type ResumeRestatement } from "./resume-restatement.js";
|
|
27
|
+
/**
|
|
28
|
+
* 🔴 **resume / 决断腿上一次 `CheckpointError` 拒的处置 —— 一张表:core 的码闭集 → 处置词**(唯一读口 {@link resumeRefusalDisposition};
|
|
29
|
+
* 7.113.0 提货车 UP ⑤ 起穷举,此前是 catch 臂里一串 `e.code === … ||` 手列)。
|
|
30
|
+
*
|
|
31
|
+
* doctrine(只写这一次):处置词说的是**这张卡与这条 run 行此刻的处境**,不是「重试会不会成」——
|
|
32
|
+
* · `retriable` —— PRE-CAS 拒:**卡仍 pending ⇒ run 行重新 park**(`suspended` / `needs_review`),wire 体自述 `retriable:true`
|
|
33
|
+
* (契约附录 A.1 注的定义:「卡仍 pending,不是『重试会成功』」)。出路(改那一格 / 重取坐标 / 回到写它的那一版引擎 / 换对 worker / 取消)
|
|
34
|
+
* 由码、`field`、`writerVersion` / `readerVersion` 与报文说,**不由 `retriable` 说**;
|
|
35
|
+
* · `terminal` —— 卡已消费 / 已不在 / 本腿读不懂 ⇒ 驱行终局,wire 体不带 `retriable`;
|
|
36
|
+
* · `cancelled` —— 取消 ⇒ 取消终局。
|
|
37
|
+
* 行的落点与 wire 的 `retriable` 读**同一次**求值(catch 臂一处),所以同一处境只有一个答案。决断口 409 的成因({@link decisionRefusalCauseOf})只决定码名、
|
|
38
|
+
* 不另答处置:决断类三词都出自 `checkpoint.invalid_outcome`,落点读本表那一行。「停驻行的格式比本引擎新」只有 core 一个来源(`checkpoint.unsupported_version`
|
|
39
|
+
* + `version_newer` ⇒ `retriable`);续跑上下文的写者版本只让那一码的 409 体多带 `writerVersion` / `readerVersion` 两件事实,不参与判处置。
|
|
40
|
+
* 同码多铸点、可恢复性不同的码再按它自己的判别位闭集分(`"by_reason"` → {@link WORKER_SWAP_REDEEMABLE})。
|
|
41
|
+
* 表是 `Record<CheckpointError["code"], …>` ⇒ core 加一个码而本表没跟 = **tsc 红**(手列串的病:新码不在串里 ⇒ 静默落终局 —— core 7.39.0 的
|
|
42
|
+
* `checkpoint.config_refused` 提货当拍就是这样把一张 pending 卡孤儿化的,钉 `test/durable-resume-http.test.ts` [ref] 两格)。
|
|
43
|
+
*
|
|
44
|
+
* 驱终局为什么危险(原 catch 臂注,D-1 / core 1.101):PRE-CAS 拒时卡仍 pending,驱终局会释放 task_active 并孤儿化那张卡(下一次 /decide → 404);
|
|
45
|
+
* re-park 让改正后的重试能再认领。驱终局只给「卡已消费或已不在」的码,免得留一条僵尸 `running` 行让 reapStale 误标并攥着会话锁 ~runStaleSec。
|
|
46
|
+
*/
|
|
47
|
+
export type CheckpointErrorDispositionWord = "cancelled" | "retriable" | "terminal" | "by_reason";
|
|
48
|
+
export declare const CHECKPOINT_ERROR_DISPOSITION: Readonly<Record<CheckpointError["code"], CheckpointErrorDispositionWord>>;
|
|
27
49
|
/**
|
|
28
50
|
* 🔴 **一次 `CheckpointError` 拒的处置 —— 唯一读口**:{@link CHECKPOINT_ERROR_DISPOSITION} 的读法(doctrine 在那张表头)。resume 腿的 catch 臂只调它一次,
|
|
29
51
|
* 行的落点与 wire 的 `retriable` 都读这一个结果。纯函数,钉直接调。运行期遇到表外的码(装树 core 比本二进制多一个码的版本偏斜 —— 型面上拼不出来)
|
|
@@ -53,13 +75,10 @@ export declare function createResumeLegs(ctx: {
|
|
|
53
75
|
runnerFor: FlatServiceDeps["runnerFor"];
|
|
54
76
|
} & RunRegistry & RouteHelpers & Pick<RouteLegs, "prepareSpec" | "finalizeTaskResult"> & Pick<ReturnType<typeof createRequestGuards>, "ownerCostQuotaDenied" | "ownerFleetLeaseDenied" | "usageWindowDenialFor">): {
|
|
55
77
|
routeCtxBase: RouteCtxBase;
|
|
56
|
-
resumeCheckpoint: (sessionId: string, decision: "approve" | "deny", reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, answer: QuestionAnswer | undefined, binding: DecideBinding,
|
|
57
|
-
overrideSessionId?: string;
|
|
58
|
-
rememberableToolName: string | null;
|
|
59
|
-
}) => Promise<void>, acceptEarly?: boolean, decider?: {
|
|
78
|
+
resumeCheckpoint: (sessionId: string, decision: "approve" | "deny", reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, answer: QuestionAnswer | undefined, binding: DecideBinding, remember?: RememberSessionRequest, acceptEarly?: boolean, decider?: {
|
|
60
79
|
principal?: string;
|
|
61
80
|
explicitOperator: boolean;
|
|
62
|
-
}, restatement?: ResumeRestatement) => Promise<
|
|
81
|
+
}, restatement?: ResumeRestatement) => Promise<ResumeCheckpointOutcome>;
|
|
63
82
|
driveResumeIntoRunLog: (args: DriveResumeArgs) => Promise<ResumeLegOutcome>;
|
|
64
83
|
driveResumeLeg: (args: DriveResumeArgs, onAccepted?: (receipt: {
|
|
65
84
|
status: number;
|
|
@@ -74,14 +93,14 @@ export declare function createResumeLegs(ctx: {
|
|
|
74
93
|
explicitOperator: boolean;
|
|
75
94
|
}, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
|
|
76
95
|
startFreshHostTurn: (sessionId: string, objective: string, principal: string | undefined, req: IncomingMessage, workflowDecision: WorkflowDecisionDelivery, runId: string, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
|
|
77
|
-
resumeWake: (sessionId: string, message:
|
|
96
|
+
resumeWake: (sessionId: string, message: PendingSteerInput | undefined, caller: string | undefined, req: IncomingMessage | undefined, acceptEarly?: boolean, workflowDecision?: WorkflowDecisionDelivery, ownerLeaseAdmittedFor?: string, restatement?: ResumeRestatement) => Promise<ResumeLegOutcome>;
|
|
78
97
|
preparePlanReview: (sessionId: string, log?: {
|
|
79
98
|
taskId?: string;
|
|
80
99
|
principalPresent?: boolean;
|
|
81
100
|
}, decider?: {
|
|
82
101
|
principal?: string;
|
|
83
102
|
explicitOperator: boolean;
|
|
84
|
-
}, sighting?: GateSighting) => Promise<{
|
|
103
|
+
}, sighting?: GateSighting, restatement?: ResumeRestatement) => Promise<{
|
|
85
104
|
readonly ok: false;
|
|
86
105
|
readonly answer: {
|
|
87
106
|
status: number;
|
|
@@ -91,7 +110,7 @@ export declare function createResumeLegs(ctx: {
|
|
|
91
110
|
readonly ok: true;
|
|
92
111
|
readonly prepared: PreparedPlanReview;
|
|
93
112
|
}>;
|
|
94
|
-
drivePlanReview: (prepared: PreparedPlanReview, decision: "approve" | "edit" | "reject", editedPlan: string | undefined, reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, acceptEarly?: boolean, permissionModeAfter?: PlanApprovePermissionModeAfter
|
|
113
|
+
drivePlanReview: (prepared: PreparedPlanReview, decision: "approve" | "edit" | "reject", editedPlan: string | undefined, reason: string | undefined, hostDecision: HostDecision, req: IncomingMessage | undefined, acceptEarly?: boolean, permissionModeAfter?: PlanApprovePermissionModeAfter) => Promise<ResumeLegOutcome>;
|
|
95
114
|
sessionNotifyDoor: import("../session-notify-door.js").SessionNotifyDoor;
|
|
96
115
|
};
|
|
97
116
|
//# sourceMappingURL=resume-legs.d.ts.map
|
package/dist/http/resume-legs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { redactErrorMessage, redactHead } from "../observability/run-terminal.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
import { uuidv7, resumeWithVerification, CheckpointError, defaultTaskRegistry, taskNotificationDedupKey, validatePendingSteer, GLOBAL_USAGE_KEY } from "@sema-agent/core";
|
|
3
|
+
import { uuidv7, resumeWithVerification, CheckpointError, judgeCheckpointRow, defaultTaskRegistry, taskNotificationDedupKey, validatePendingSteer, GLOBAL_USAGE_KEY } from "@sema-agent/core";
|
|
4
4
|
import { decideParkedAgent, denyWorkflowParkForked, denyWorkflowParksUnreadable, findParkOrigin, heldWorkflowParkDecisions, planWorkflowParkedDecide } from "../parked-decide.js";
|
|
5
5
|
import { parkDecisionFingerprint } from "../orchestration/workflow-park-decision.js";
|
|
6
6
|
import { headReadOf } from "../session-incarnation.js";
|
|
@@ -22,12 +22,12 @@ import { approverFacingArgs, createApprovalCardEmitter, declaredApprovalFrameFam
|
|
|
22
22
|
import { buildCheckpointAnchorHash } from "../approval-ask-audit-store.js";
|
|
23
23
|
import { APPROVAL_ENDING_CAUSES } from "../approval-deny-reasons.js";
|
|
24
24
|
import { serviceVersion } from "../service-version.js";
|
|
25
|
-
import { TERMINAL_PARK_GATE_KINDS } from "../plugins/checkpoint-store-
|
|
25
|
+
import { TERMINAL_PARK_GATE_KINDS, UnreadableCheckpointRowError } from "../plugins/checkpoint-store-face.js";
|
|
26
26
|
import { withPrincipal } from "../observability/principal-context.js";
|
|
27
27
|
import { withModelReachScope } from "../model-reach-scope.js";
|
|
28
28
|
import { legFactsOf } from "../leg-facts.js";
|
|
29
29
|
import { createInstructionSelectionLeg } from "../instruction-selection.js";
|
|
30
|
-
import { modelTextEventData, appendParkRow, turnEndEventData, contextUsageEventData, toolStartEventData, toolEndEventData, taskProgressEventData, taskStartedEventData, taskNotificationEventData, compactedEventData, diagnosticsEventData, brainStatusEventData, steeringInjectedEventData, compactionOutcomeEventData, compactionStartedEventData, workspaceChangedEventData, wiringManifestEventData, toolRosterDeltaEventData, toolDisclosureEventData, humanInputEventData, appendModelUsageDelta,
|
|
30
|
+
import { modelTextEventData, appendParkRow, turnEndEventData, contextUsageEventData, toolStartEventData, toolEndEventData, taskProgressEventData, taskStartedEventData, taskNotificationEventData, compactedEventData, diagnosticsEventData, brainStatusEventData, steeringInjectedEventData, compactionOutcomeEventData, compactionStartedEventData, workspaceChangedEventData, wiringManifestEventData, toolRosterDeltaEventData, toolDisclosureEventData, humanInputEventData, appendModelUsageDelta, attachModelUsage, createPromptManifestSeat } from "../trace/project.js";
|
|
31
31
|
import { redactSecrets } from "../trace/redact.js";
|
|
32
32
|
import { buildRunObjectivePreview } from "../user-authored-text.js";
|
|
33
33
|
import { createForwardAppendFailedNote, createLedgerSink, createSerialLedgerAppend } from "../trace/ledger-sink.js";
|
|
@@ -49,13 +49,14 @@ import { createCapabilitiesLocal } from "./routes/capabilities.js";
|
|
|
49
49
|
import { gatedPrincipal, explicitOperatorOk, runIdentityOf } from "./principal-gate.js";
|
|
50
50
|
import { buildActiveRunConflict, resumeEntryForGate } from "./active-run-conflict.js";
|
|
51
51
|
import { commitExecutionContext, isRootSessionGoneError, resolveExecutionContext, rootSessionAbsentAnswer, stampSpecRoot } from "./execution-context.js";
|
|
52
|
+
import { timeClaim } from "./claim-latency.js";
|
|
52
53
|
import { commitSessionInheritEnv } from "./session-inherit-env.js";
|
|
53
54
|
import { ASK_USER_QUESTION_TOOL_NAME, isApprovalGateKind, isEngineQuestionRow } from "../approval-content-kind.js";
|
|
54
55
|
import { deploymentListAsks } from "../approval.js";
|
|
55
56
|
import { isParkLedgerEventType } from "../trace/ledger-events.js";
|
|
56
57
|
import { readResumeCtx, resumeCtxCorruptAnswer, resumeCtxUnsealableAnswer } from "./resume-ctx-read.js";
|
|
57
58
|
import { objectiveWithheldIn } from "./submit-ctx.js";
|
|
58
|
-
import { buildCheckpointVersionKeys,
|
|
59
|
+
import { buildCheckpointVersionKeys, resumeAssemblyRefusalAnswer, resumeRefusalWithCard, sealCheckpointCtx, storedBodyReplayAnswer, storedBodyReplayLogFields, withPermissionModeRewritten } from "./checkpoint-ctx.js";
|
|
59
60
|
import { refusalBody, resumeRefusalFacts } from "./refusal-body.js";
|
|
60
61
|
import { storedBodyReplayRefusal } from "./stored-body-replay.js";
|
|
61
62
|
import { restateResumeCtx } from "./resume-restatement.js";
|
|
@@ -103,7 +104,7 @@ const WORKER_SWAP_REDEEMABLE = {
|
|
|
103
104
|
function checkpointRowRedeemableElsewhere(reason) {
|
|
104
105
|
return reason !== undefined && WORKER_SWAP_REDEEMABLE[reason] === true;
|
|
105
106
|
}
|
|
106
|
-
const CHECKPOINT_ERROR_DISPOSITION = {
|
|
107
|
+
export const CHECKPOINT_ERROR_DISPOSITION = {
|
|
107
108
|
"checkpoint.resume_aborted": "cancelled",
|
|
108
109
|
"checkpoint.invalid_outcome": "retriable",
|
|
109
110
|
"checkpoint.reopen_revote": "retriable",
|
|
@@ -184,13 +185,13 @@ const WIRE_CODE_OF_DECISION_REFUSAL = {
|
|
|
184
185
|
[APPROVAL_ENDING_CAUSES.ANSWER_INVALID]: "resume_outcome_invalid",
|
|
185
186
|
[APPROVAL_ENDING_CAUSES.OUTCOME_CELL_INVALID]: "resume_outcome_invalid",
|
|
186
187
|
};
|
|
187
|
-
const UNCLASSIFIED_INVALID_OUTCOME_CODE = WIRE_CODE_OF_DECISION_REFUSAL[APPROVAL_ENDING_CAUSES.BINDING_CHANGED];
|
|
188
188
|
function decisionRefusalCauseOf(e, gate) {
|
|
189
|
-
if (
|
|
190
|
-
return
|
|
189
|
+
if (e.detail?.reason !== undefined)
|
|
190
|
+
return undefined;
|
|
191
191
|
const field = e.detail?.field;
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
if (field !== undefined)
|
|
193
|
+
return Object.hasOwn(CHECKPOINT_ERROR_FIELD_ROLE, field) ? FIELD_ROLE_CAUSE[CHECKPOINT_ERROR_FIELD_ROLE[field]] : undefined;
|
|
194
|
+
return gate === "policy_ask" ? undefined : APPROVAL_ENDING_CAUSES.OUTCOME_CELL_INVALID;
|
|
194
195
|
}
|
|
195
196
|
function notResumableAnswer() {
|
|
196
197
|
return { status: 409, body: refusalBody({ errorCode: "conflict.not_resumable", message: "run is not in a resumable (suspended) state (already resumed, decided, or expired)" }) };
|
|
@@ -208,6 +209,13 @@ function approvalStaleAnswer(facts) {
|
|
|
208
209
|
}),
|
|
209
210
|
};
|
|
210
211
|
}
|
|
212
|
+
function rowRefusalAnswer(verdict, diagnostic, ctx) {
|
|
213
|
+
const refusal = new CheckpointError(verdict.code, diagnostic === undefined ? verdict.sentence : `${verdict.sentence} Diagnostic: ${diagnostic}`, verdict.reason === undefined ? undefined : { reason: verdict.reason });
|
|
214
|
+
return checkpointRefusalAnswer(refusal, { gate: "policy_ask", retriable: resumeRefusalDisposition(refusal) === "retriable", versionKeys: refusalVersionKeys(refusal, ctx) });
|
|
215
|
+
}
|
|
216
|
+
function refusalVersionKeys(e, ctx) {
|
|
217
|
+
return e.code === "checkpoint.unsupported_version" ? buildCheckpointVersionKeys(ctx.writerVersion, serviceVersion()) : {};
|
|
218
|
+
}
|
|
211
219
|
function acceptableFormFacts(detail) {
|
|
212
220
|
const rewritten = detail !== null && typeof detail === "object" ? detail.editRewritten : undefined;
|
|
213
221
|
if (rewritten === null || typeof rewritten !== "object" || !Object.hasOwn(rewritten, "acceptableForm"))
|
|
@@ -222,7 +230,7 @@ export function checkpointRefusalAnswer(e, at) {
|
|
|
222
230
|
status: e.code === "checkpoint.not_found" ? 404 : 409,
|
|
223
231
|
body: refusalBody({
|
|
224
232
|
message: e.message,
|
|
225
|
-
errorCode:
|
|
233
|
+
errorCode: refusalCause === undefined ? e.code : WIRE_CODE_OF_DECISION_REFUSAL[refusalCause],
|
|
226
234
|
facts: {
|
|
227
235
|
...(at.taskId !== undefined ? { taskId: at.taskId } : {}),
|
|
228
236
|
...resumeRefusalFacts(detail),
|
|
@@ -241,11 +249,36 @@ export function decidedActionOf(binding) {
|
|
|
241
249
|
return missingKeys.length === 0 ? { action: { boundCallId: boundCallId, boundInputHash: boundInputHash } } : { missingKeys };
|
|
242
250
|
}
|
|
243
251
|
export function createResumeLegs(ctx) {
|
|
244
|
-
const { deps, runnerFor, idemCache, inflightRuns, preemptableRuns, steerableRuns, wakeParkMints, counters, readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk, prepareSpec, finalizeTaskResult, ownerCostQuotaDenied, ownerFleetLeaseDenied, usageWindowDenialFor } = ctx;
|
|
252
|
+
const { deps, runnerFor, idemCache, inflightRuns, preemptableRuns, steerableRuns, wakeParkMints, counters, readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, admitRun, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk, prepareSpec, finalizeTaskResult, ownerCostQuotaDenied, ownerFleetLeaseDenied, usageWindowDenialFor } = ctx;
|
|
245
253
|
const ctxOpening = (sessionId) => ({ sessionId, opener: deps.checkpointCtxSealing });
|
|
246
254
|
const resumeFleetScope = (req, auth) => req ? (gatedPrincipal(req, deps.config) ?? "default") : (auth.principal ?? "default");
|
|
247
|
-
|
|
255
|
+
function createRememberIntent(sessionId, remember) {
|
|
256
|
+
let pending;
|
|
257
|
+
return {
|
|
258
|
+
laneCannotRecord: remember.laneCannotRecord,
|
|
259
|
+
record: async (grant) => {
|
|
260
|
+
if (grant.rememberableToolName !== null)
|
|
261
|
+
pending = { sessionId: grant.overrideSessionId ?? sessionId, toolName: grant.rememberableToolName };
|
|
262
|
+
},
|
|
263
|
+
settle: async (committed) => {
|
|
264
|
+
const store = deps.approvalExemptionStore;
|
|
265
|
+
if (!committed || pending === undefined || store === undefined)
|
|
266
|
+
return false;
|
|
267
|
+
try {
|
|
268
|
+
await store.grant(pending.sessionId, pending.toolName, remember.grantedBy);
|
|
269
|
+
deps.logger?.info?.("approval_exemption_granted", { sessionId: pending.sessionId, toolName: pending.toolName, grantedBy: remember.grantedBy });
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
catch (e) {
|
|
273
|
+
deps.logger?.warn?.("approval_exemption_grant_failed", { sessionId: pending.sessionId, toolName: pending.toolName, error: String(e).slice(0, 200) });
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
async function resumeCheckpoint(sessionId, decision, reason, hostDecision, req, answer, binding, remember, acceptEarly, decider, restatement) {
|
|
248
280
|
const cs = deps.checkpointStore;
|
|
281
|
+
const intent = remember !== undefined ? createRememberIntent(sessionId, remember) : undefined;
|
|
249
282
|
const token = await currentApprovalGateToken(cs, sessionId);
|
|
250
283
|
if (binding.checkpointToken && !sightsCurrentGate({ face: "checkpointToken", value: binding.checkpointToken }, token ? { checkpointToken: token } : null)) {
|
|
251
284
|
let seenUnreadable = false;
|
|
@@ -293,6 +326,7 @@ export function createResumeLegs(ctx) {
|
|
|
293
326
|
const ctxPromise = cs.getCtx(sessionId);
|
|
294
327
|
void ctxPromise.catch(() => { });
|
|
295
328
|
const noApproval = { status: 404, body: refusalBody({ errorCode: "not_found.approval", message: "approval not found" }) };
|
|
329
|
+
const rowOwnRefusal = async (verdict, diagnostic) => rowRefusalAnswer(verdict, diagnostic, verdict.code === "checkpoint.unsupported_version" ? ((await ctxPromise.catch(() => null)) ?? {}) : {});
|
|
296
330
|
let cp;
|
|
297
331
|
try {
|
|
298
332
|
cp = await cpPromise;
|
|
@@ -303,7 +337,9 @@ export function createResumeLegs(ctx) {
|
|
|
303
337
|
deps.logger?.warn?.("approval_decide_unreadable_row_withheld", { sessionId, note: "row unreadable and the caller's ownership of THAT token is unproven — folded into the uniform 404" });
|
|
304
338
|
return noApproval;
|
|
305
339
|
}
|
|
306
|
-
|
|
340
|
+
if (e instanceof UnreadableCheckpointRowError && e.rowVerdict.kind !== "ok")
|
|
341
|
+
return rowOwnRefusal(e.rowVerdict, errorText(e));
|
|
342
|
+
return { status: 409, body: refusalBody({ errorCode: "conflict.checkpoint_unreadable", message: errorText(e) }) };
|
|
307
343
|
}
|
|
308
344
|
if (!cp) {
|
|
309
345
|
if (!(await mayDiscloseRowError(cs, token, decider)))
|
|
@@ -319,20 +355,20 @@ export function createResumeLegs(ctx) {
|
|
|
319
355
|
}
|
|
320
356
|
const decideGateKind = cp.gate?.kind;
|
|
321
357
|
if (!isApprovalGateKind(decideGateKind)) {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
358
|
+
const verdict = judgeCheckpointRow(cp);
|
|
359
|
+
if (verdict.kind !== "ok")
|
|
360
|
+
return rowOwnRefusal(verdict);
|
|
361
|
+
if (typeof decideGateKind !== "string" || decideGateKind === "") {
|
|
362
|
+
return { status: 409, body: refusalBody({ errorCode: "gate_not_tool_approval", message: "task is suspended on a gate whose kind this engine cannot read, so it cannot say which endpoint resolves it" }) };
|
|
363
|
+
}
|
|
364
|
+
const activeForPath = await deps.runStore?.getActiveTaskId(sessionId).catch(() => undefined);
|
|
365
|
+
const gnPath = activeForPath ? resumeEntryForGate(decideGateKind, { sessionId, taskId: activeForPath }) : null;
|
|
328
366
|
return {
|
|
329
367
|
status: 409,
|
|
330
368
|
body: refusalBody({
|
|
331
369
|
errorCode: "gate_not_tool_approval",
|
|
332
|
-
message: `task is suspended on a '${decideGateKind
|
|
333
|
-
facts: {
|
|
334
|
-
...(decideGateKind ? { pendingGate: { kind: decideGateKind, ...(gnPath ? { decidePath: gnPath } : {}) } } : {}),
|
|
335
|
-
},
|
|
370
|
+
message: `task is suspended on a '${decideGateKind}' gate, not a tool approval — a plan_review gate is resolved via POST /v1/assistant/tasks/:id/plan_review, a resource_limit suspension via POST /v1/assistant/tasks/:id/resume`,
|
|
371
|
+
facts: { pendingGate: { kind: decideGateKind, ...(gnPath ? { decidePath: gnPath } : {}) } },
|
|
336
372
|
}),
|
|
337
373
|
};
|
|
338
374
|
}
|
|
@@ -370,8 +406,8 @@ export function createResumeLegs(ctx) {
|
|
|
370
406
|
standingAnswerDurablyRecordable(parkRowStandingAnswerFacts(paForGrant, cp.gate, deps.config, deploymentListAsks(deps.config, { toolName: paForGrant.toolName })))
|
|
371
407
|
? paForGrant.toolName
|
|
372
408
|
: null;
|
|
373
|
-
const boundGrant =
|
|
374
|
-
? (overrideSessionId) =>
|
|
409
|
+
const boundGrant = intent
|
|
410
|
+
? (overrideSessionId) => intent.record({ ...(overrideSessionId !== undefined ? { overrideSessionId } : {}), rememberableToolName: rememberableTool })
|
|
375
411
|
: undefined;
|
|
376
412
|
const lateSettleSink = deps.approvalLateSettle;
|
|
377
413
|
const lateSettleAnchor = lateSettleSink !== undefined && req !== undefined && token
|
|
@@ -381,8 +417,8 @@ export function createResumeLegs(ctx) {
|
|
|
381
417
|
checkpointTokenHash: buildCheckpointAnchorHash(token),
|
|
382
418
|
}
|
|
383
419
|
: undefined;
|
|
384
|
-
const noteLateSettleIfAccepted = (
|
|
385
|
-
if (lateSettleSink === undefined || lateSettleAnchor === undefined
|
|
420
|
+
const noteLateSettleIfAccepted = (committed) => {
|
|
421
|
+
if (!committed || lateSettleSink === undefined || lateSettleAnchor === undefined)
|
|
386
422
|
return;
|
|
387
423
|
try {
|
|
388
424
|
lateSettleSink.recordLateSettle({ ...lateSettleAnchor, outcome: decision === "approve" ? "allowed" : "denied", decidedBy: hostDecision.decidedBy, ...(hostDecision.approver !== undefined ? { approver: hostDecision.approver } : {}), settledAtMs: Date.now() });
|
|
@@ -391,6 +427,11 @@ export function createResumeLegs(ctx) {
|
|
|
391
427
|
recordFailOpen("server.approval-ask-audit.append-failed", `kind=late_settle err=${e instanceof Error ? e.message : String(e)}`);
|
|
392
428
|
}
|
|
393
429
|
};
|
|
430
|
+
const landAfterCommit = async (out) => {
|
|
431
|
+
const committed = decisionCommittedOf(out);
|
|
432
|
+
noteLateSettleIfAccepted(committed);
|
|
433
|
+
return intent === undefined ? out : { ...out, rememberApplied: await intent.settle(committed) };
|
|
434
|
+
};
|
|
394
435
|
const parkedForkQuotaDenial = req !== undefined ? ownerCostQuotaDenied(decodeCheckpointScope(cp.scope)) : undefined;
|
|
395
436
|
if (parkedForkQuotaDenial)
|
|
396
437
|
return parkedForkQuotaDenial;
|
|
@@ -416,7 +457,7 @@ export function createResumeLegs(ctx) {
|
|
|
416
457
|
binding: { ...(({ checkpointToken: _staleGuardOnly, ...rest }) => rest)(binding), ...action },
|
|
417
458
|
...(answer !== undefined ? { answer } : {}),
|
|
418
459
|
...(restatement !== undefined ? { restatement } : {}),
|
|
419
|
-
...(boundGrant ? {
|
|
460
|
+
...(boundGrant && intent ? { remember: { anchor: (rootSessionId) => boundGrant(rootSessionId), laneCannotRecord: intent.laneCannotRecord } } : {}),
|
|
420
461
|
};
|
|
421
462
|
if (origin?.kind === "background" && parkedAgentStore !== undefined && parkedSurface !== undefined) {
|
|
422
463
|
const parked = await withPrincipal(decodeCheckpointScope(cp.scope), () => decideParkedAgent({
|
|
@@ -437,7 +478,7 @@ export function createResumeLegs(ctx) {
|
|
|
437
478
|
if (isRootSessionGoneError(e))
|
|
438
479
|
return { ok: false, gone: true };
|
|
439
480
|
if (e instanceof HttpError)
|
|
440
|
-
return { ok: false, gone: false, answer: resumeRefusalWithCard(
|
|
481
|
+
return { ok: false, gone: false, answer: resumeRefusalWithCard(resumeAssemblyRefusalAnswer(e.status, httpErrorRefusal(e)), true) };
|
|
441
482
|
throw e;
|
|
442
483
|
}
|
|
443
484
|
const occupant = ctx.occupant;
|
|
@@ -451,8 +492,7 @@ export function createResumeLegs(ctx) {
|
|
|
451
492
|
...(deps.logger ? { warn: parkWarn } : {}),
|
|
452
493
|
}, { ...parkedReq, selectedGate: captureSelectedGate() }, { handle: origin.handle, row: origin.row }));
|
|
453
494
|
void ctxPromise.catch(() => { });
|
|
454
|
-
|
|
455
|
-
return parked;
|
|
495
|
+
return await landAfterCommit(parked);
|
|
456
496
|
}
|
|
457
497
|
if (origin?.kind === "workflow_parks_unreadable") {
|
|
458
498
|
void ctxPromise.catch(() => { });
|
|
@@ -503,7 +543,7 @@ export function createResumeLegs(ctx) {
|
|
|
503
543
|
const admittedPayer = decodeCheckpointScope(cp.scope);
|
|
504
544
|
const out = hostToken
|
|
505
545
|
? await resumeWake(plan.hostSessionId, plan.message, decider?.principal, req, acceptEarly, delivery, admittedPayer, restatement)
|
|
506
|
-
: await startFreshHostTurn(plan.hostSessionId, plan.message, admittedPayer, req, delivery, plan.runId, restatement);
|
|
546
|
+
: await startFreshHostTurn(plan.hostSessionId, plan.message.text, admittedPayer, req, delivery, plan.runId, restatement);
|
|
507
547
|
if (recordFailure !== undefined)
|
|
508
548
|
throw recordFailure.err;
|
|
509
549
|
if (acceptedTaskIdOf(out) === undefined)
|
|
@@ -548,8 +588,7 @@ export function createResumeLegs(ctx) {
|
|
|
548
588
|
};
|
|
549
589
|
const verifyRounds = verifyRoundsFromBody(ctx.body);
|
|
550
590
|
const driven = await driveResumeIntoRunLog({ peerLease: resolved.peerLease, execution: resolved.execution, runner: resolved.runner, legFacts: resolved.legFacts, token, sessionId: cp.sessionId, principal: auth.principal, fleetScope: resumeFleetScope(req, auth), taskConfig, resumeObjective, outcome, commitment: { kind: "gate_resolved", ...captureSelectedGate() }, verifyRounds, resumeCtx: { sessionId, ctx }, ...(engineNotices.length > 0 ? { engineNotices } : {}), ...(boundGrant ? { onResumeCommitted: boundGrant } : {}), ...(acceptEarly === true ? { acceptEarly: true } : {}), ...(req !== undefined ? { callerInitiated: true } : {}), ...(ownerLeaseAdmittedHere ? { ownerLeaseAdmitted: true } : {}) });
|
|
551
|
-
|
|
552
|
-
return driven;
|
|
591
|
+
return await landAfterCommit(driven);
|
|
553
592
|
}
|
|
554
593
|
finally {
|
|
555
594
|
resolved.peerLease.release();
|
|
@@ -588,7 +627,7 @@ export function createResumeLegs(ctx) {
|
|
|
588
627
|
catch (e) {
|
|
589
628
|
lease.release();
|
|
590
629
|
if (e instanceof HttpError) {
|
|
591
|
-
return { ok: false, answer: resumeRefusalWithCard(
|
|
630
|
+
return { ok: false, answer: resumeRefusalWithCard(resumeAssemblyRefusalAnswer(e.status, httpErrorRefusal(e)), true) };
|
|
592
631
|
}
|
|
593
632
|
throw e;
|
|
594
633
|
}
|
|
@@ -652,11 +691,11 @@ export function createResumeLegs(ctx) {
|
|
|
652
691
|
}
|
|
653
692
|
if (!taskId && args.mintFreshRun && deps.runStore) {
|
|
654
693
|
const freshId = uuidv7();
|
|
655
|
-
const created = await deps.runStore.createRun(freshId, sessionId, principal ?? null, deps.instanceId ?? "default", {
|
|
694
|
+
const created = await timeClaim(deps.metrics, "run_claim", deps.runStore.createRun(freshId, sessionId, principal ?? null, deps.instanceId ?? "default", {
|
|
656
695
|
source: args.mintFreshRun.source,
|
|
657
696
|
identity: args.mintFreshRun.identity,
|
|
658
697
|
objectivePreview: heldObjective === undefined ? null : buildRunObjectivePreview(heldObjective),
|
|
659
|
-
});
|
|
698
|
+
}));
|
|
660
699
|
if (created.existing) {
|
|
661
700
|
throw new Error(`wake fresh run: createRun observed an existing row for the freshly minted taskId ${freshId} (no idempotency key was sent) — refusing to treat it as a busy session`);
|
|
662
701
|
}
|
|
@@ -742,12 +781,12 @@ export function createResumeLegs(ctx) {
|
|
|
742
781
|
return { reopened: pending, leg };
|
|
743
782
|
};
|
|
744
783
|
let resumeHeartbeat;
|
|
745
|
-
let
|
|
784
|
+
let resumeManifestSeat;
|
|
746
785
|
let resumeStreamRef;
|
|
747
786
|
let resumeLegLive = false;
|
|
748
787
|
const subagentHandleEvictions = [];
|
|
749
788
|
let claimedRow = false;
|
|
750
|
-
const cancelCtrl = createRunAbort();
|
|
789
|
+
const cancelCtrl = createRunAbort(principal ?? null);
|
|
751
790
|
let cancelLedgerAppend;
|
|
752
791
|
const preemptCtrl = new AbortController();
|
|
753
792
|
if (taskId && deps.runStore) {
|
|
@@ -778,7 +817,7 @@ export function createResumeLegs(ctx) {
|
|
|
778
817
|
}, HEARTBEAT_MS);
|
|
779
818
|
resumeHeartbeat.unref?.();
|
|
780
819
|
deps.modelUsage?.register(taskId);
|
|
781
|
-
|
|
820
|
+
resumeManifestSeat = createPromptManifestSeat(deps.promptManifests, taskId);
|
|
782
821
|
}
|
|
783
822
|
if (args.workflowDecision !== undefined && taskId === undefined) {
|
|
784
823
|
throw new Error("workflow decision delivery: no run row was claimed for the delivering leg — refusing to start a delivery whose decision could not be recorded against it");
|
|
@@ -890,7 +929,7 @@ export function createResumeLegs(ctx) {
|
|
|
890
929
|
const rs2 = deps.runStore;
|
|
891
930
|
try {
|
|
892
931
|
const ap = vAppend;
|
|
893
|
-
await
|
|
932
|
+
await resumeManifestSeat?.drain(ap);
|
|
894
933
|
if (reSuspended || vrReopened) {
|
|
895
934
|
const vrParkCallId = reSuspended ? await parkToolCallId(vr, deps.checkpointStore) : undefined;
|
|
896
935
|
await appendParkRow(ap, { modelUsage: deps.modelUsage, taskId }, reParkEvent ?? reparkStatus, { terminal: vrPaused, ...(vrParkCallId !== undefined ? { toolCallId: vrParkCallId } : {}) }, vrReopened ? (failureCodeOf(vr.terminal) ?? null) : undefined);
|
|
@@ -938,7 +977,7 @@ export function createResumeLegs(ctx) {
|
|
|
938
977
|
? async (eventId) => { const leaf = (await headOf(sessionId))?.leafId; if (leaf)
|
|
939
978
|
await deps.resumeAnchorStore.put(sessionId, eventId, leaf, anchorOwner); }
|
|
940
979
|
: undefined;
|
|
941
|
-
const captureUserMessageAnchor = deps.resumeAnchorStore && taskId
|
|
980
|
+
const captureUserMessageAnchor = deps.resumeAnchorStore && taskId && freshRunClaimed
|
|
942
981
|
? async (entryId) => { await deps.resumeAnchorStore.put(sessionId, taskId, entryId, anchorOwner); }
|
|
943
982
|
: undefined;
|
|
944
983
|
const anchor = new TurnAnchorCapture(captureTurnAnchor, "resume", captureUserMessageAnchor);
|
|
@@ -1039,7 +1078,7 @@ export function createResumeLegs(ctx) {
|
|
|
1039
1078
|
fleetPub?.onEvent(ev);
|
|
1040
1079
|
await deps.userInputLedger?.observeLegEvent(stream, ev);
|
|
1041
1080
|
await resumeWorkspace.observe(ev);
|
|
1042
|
-
await
|
|
1081
|
+
await resumeManifestSeat?.drain(append);
|
|
1043
1082
|
switch (ev.type) {
|
|
1044
1083
|
case "text_delta":
|
|
1045
1084
|
block += ev.delta;
|
|
@@ -1247,7 +1286,7 @@ export function createResumeLegs(ctx) {
|
|
|
1247
1286
|
settleFleet("failed");
|
|
1248
1287
|
}
|
|
1249
1288
|
}
|
|
1250
|
-
return checkpointRefusalAnswer(e, { gate: outcome.gate, retriable, ...(taskId !== undefined ? { taskId } : {}), versionKeys: e
|
|
1289
|
+
return checkpointRefusalAnswer(e, { gate: outcome.gate, retriable, ...(taskId !== undefined ? { taskId } : {}), versionKeys: refusalVersionKeys(e, resumeCtx.ctx) });
|
|
1251
1290
|
}
|
|
1252
1291
|
const thrownCause = cancelCtrl.cause();
|
|
1253
1292
|
if (thrownCause !== undefined) {
|
|
@@ -1281,7 +1320,7 @@ export function createResumeLegs(ctx) {
|
|
|
1281
1320
|
for (const evict of subagentHandleEvictions)
|
|
1282
1321
|
evict();
|
|
1283
1322
|
deps.modelUsage?.clear(taskId);
|
|
1284
|
-
|
|
1323
|
+
resumeManifestSeat?.release();
|
|
1285
1324
|
}
|
|
1286
1325
|
if (resumeHeartbeat)
|
|
1287
1326
|
clearInterval(resumeHeartbeat);
|
|
@@ -1488,10 +1527,9 @@ export function createResumeLegs(ctx) {
|
|
|
1488
1527
|
if (gateKind !== "task_done") {
|
|
1489
1528
|
return { status: 409, body: refusalBody({ errorCode: "wake.gate_pending", message: `cannot wake: this session is waiting on a pending gate decision (gate "${gateKind ?? "unknown"}") — resolve it through its own decide entry` }) };
|
|
1490
1529
|
}
|
|
1491
|
-
const trusted = operator;
|
|
1492
1530
|
if (message !== undefined) {
|
|
1493
1531
|
try {
|
|
1494
|
-
validatePendingSteer(
|
|
1532
|
+
validatePendingSteer(message);
|
|
1495
1533
|
}
|
|
1496
1534
|
catch (e) {
|
|
1497
1535
|
if (e instanceof CheckpointError && e.code === "steering.invalid_content") {
|
|
@@ -1526,7 +1564,7 @@ export function createResumeLegs(ctx) {
|
|
|
1526
1564
|
fleetScope: resumeFleetScope(req, auth),
|
|
1527
1565
|
taskConfig,
|
|
1528
1566
|
resumeObjective,
|
|
1529
|
-
outcome: { gate: "wake", ...(message !== undefined ? { message
|
|
1567
|
+
outcome: { gate: "wake", ...(message !== undefined ? { message } : {}) },
|
|
1530
1568
|
commitment: { kind: "delivered" },
|
|
1531
1569
|
verifyRounds: undefined,
|
|
1532
1570
|
resumeCtx: { sessionId, ctx },
|
|
@@ -1542,7 +1580,7 @@ export function createResumeLegs(ctx) {
|
|
|
1542
1580
|
resolved.peerLease.release();
|
|
1543
1581
|
}
|
|
1544
1582
|
}
|
|
1545
|
-
async function preparePlanReview(sessionId, log, decider, sighting) {
|
|
1583
|
+
async function preparePlanReview(sessionId, log, decider, sighting, restatement) {
|
|
1546
1584
|
const cs = deps.checkpointStore;
|
|
1547
1585
|
const refuse = (answer) => ({ ok: false, answer });
|
|
1548
1586
|
const log404 = (r) => deps.logger?.info?.("decide_404", {
|
|
@@ -1614,14 +1652,14 @@ export function createResumeLegs(ctx) {
|
|
|
1614
1652
|
return refuse(resumeCtxUnsealableAnswer(ctxRead));
|
|
1615
1653
|
if (ctxRead.kind === "absent")
|
|
1616
1654
|
return refuse({ status: 409, body: refusalBody({ errorCode: "conflict.resume_context_unavailable", message: "resume context missing — cannot rebuild task config" }) });
|
|
1617
|
-
const
|
|
1655
|
+
const ctx = restateResumeCtx(ctxRead.ctx, restatement);
|
|
1656
|
+
const replay = storedBodyReplayRefusal(ctx, deps.config);
|
|
1618
1657
|
if (replay !== undefined)
|
|
1619
1658
|
return refuse(refuseStoredBodyReplay(sessionId, replay));
|
|
1620
|
-
return { ok: true, prepared: { sessionId, token, cp, ctx
|
|
1659
|
+
return { ok: true, prepared: { sessionId, token, cp, ctx } };
|
|
1621
1660
|
}
|
|
1622
|
-
async function drivePlanReview(prepared, decision, editedPlan, reason, hostDecision, req, acceptEarly, permissionModeAfter
|
|
1623
|
-
const { sessionId, token, cp } = prepared;
|
|
1624
|
-
const ctx = restateResumeCtx(prepared.ctx, restatement);
|
|
1661
|
+
async function drivePlanReview(prepared, decision, editedPlan, reason, hostDecision, req, acceptEarly, permissionModeAfter) {
|
|
1662
|
+
const { sessionId, token, cp, ctx } = prepared;
|
|
1625
1663
|
if ((await deps.checkpointStore.findPendingTokenBySession(sessionId, undefined, { gateKinds: ["plan_review"] })) !== token)
|
|
1626
1664
|
return notResumableAnswer();
|
|
1627
1665
|
const auth = { sessionId: cp.sessionId, principal: decodeCheckpointScope(cp.scope), memoryScope: ctx.memoryScope };
|
|
@@ -1662,7 +1700,7 @@ export function createResumeLegs(ctx) {
|
|
|
1662
1700
|
const routeCtxBase = {
|
|
1663
1701
|
deps,
|
|
1664
1702
|
registry: { idemCache, inflightRuns, preemptableRuns, steerableRuns, wakeParkMints, counters },
|
|
1665
|
-
helpers: { readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk },
|
|
1703
|
+
helpers: { readJson, readRawBody, rateLimited, quotaExceeded, ownerQuotaDenied, leaseDenied, ownerLeaseDenied, usageWindowDenied, admitRun, safeDecode, runOwnerOk, sessionOwnerOk, runSessionAcceptOk },
|
|
1666
1704
|
local: { images: createImagesLocal(deps), sessions: createSessionsLocal(), sessionSync: createSessionSyncLocal(), capabilities: createCapabilitiesLocal() },
|
|
1667
1705
|
legs: { prepareSpec, finalizeTaskResult, resumeCheckpoint, driveResumeIntoRunLog, resumePreempted, resumeWake, preparePlanReview, drivePlanReview, sessionNotify: sessionNotifyDoor },
|
|
1668
1706
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run 外回退口 `POST /v1/sessions/:id/rewind-files` 的 200 体 —— 引擎 `Runner.rewindFiles` 的结果(`RewindFilesResult`)**原形**,文本叶经出口座出门。
|
|
3
|
+
*
|
|
4
|
+
* 规则一句:形照引擎(`dryRun:true` ⇒ `{ preview }`,`null` 仍是 `null`;`dryRun:false` ⇒ `{ restore }` 台账,空数组仍是空数组),每一片自由文本叶只经
|
|
5
|
+
* {@link seatText} 的一行 —— 被跟踪文件的路径(台账 `filesChanged` / `identicalSkipped` / `refused[].path` / `failed[].path`、预览 `filesChanged`;源头是模型交的
|
|
6
|
+
* 路径参数)走 `rewind-ledger-path`(不设界:截过的路径就不是那个文件了);拒因 / 故障句(`refused[].reason` / `failed[].reason` / `error.message`)走
|
|
7
|
+
* `rewind-ledger-reason`;闭集词 / 计数逐字。台账上的店故障(core `FileHistoryError`)按本仓错误体的唯一机读键律出门:引擎的 `code` 成员在 wire 上叫
|
|
8
|
+
* `errorCode`(值逐字),`message` 经座,`permanence` 逐字 —— 本仓的 wire 上没有叫 `code` 的错误键。两张叶表与故障的三键按 core 型的键穷举 ——
|
|
9
|
+
* core 给台账 / 统计 / 故障加一格而这里不表态 ⇒ tsc 红;表外的运行期键不出门(按表取键,不展开原对象)。唯一调用方 = `http/routes/sessions.ts` 的 `session-rewind-files` 臂。
|
|
10
|
+
*/
|
|
11
|
+
import type { FileHistoryDiffStats, FileHistoryError, FileHistoryRestoreResult, RewindFilesResult } from "@sema-agent/core";
|
|
12
|
+
/** 台账上的店故障在 wire 上的形:码键 = `errorCode`(本仓错误体的唯一机读键),其余两键同引擎。 */
|
|
13
|
+
export interface RewindLedgerError {
|
|
14
|
+
readonly errorCode: FileHistoryError["code"];
|
|
15
|
+
readonly message: string;
|
|
16
|
+
readonly permanence?: FileHistoryError["permanence"];
|
|
17
|
+
}
|
|
18
|
+
/** 台账在 wire 上的形 = 引擎台账,`error` 换成 {@link RewindLedgerError}。 */
|
|
19
|
+
export type RewindLedgerReply = Omit<FileHistoryRestoreResult, "error"> & {
|
|
20
|
+
readonly error?: RewindLedgerError;
|
|
21
|
+
};
|
|
22
|
+
/** 200 体在 wire 上的形(引擎 `RewindFilesResult`,台账的 `error` 按 {@link RewindLedgerError})。 */
|
|
23
|
+
export type RewindFilesReply = {
|
|
24
|
+
readonly dryRun: true;
|
|
25
|
+
readonly preview: FileHistoryDiffStats | null;
|
|
26
|
+
} | {
|
|
27
|
+
readonly dryRun: false;
|
|
28
|
+
readonly restore: RewindLedgerReply & {
|
|
29
|
+
readonly outcome: "complete" | "partial";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/** 200 体(纯数据)。 */
|
|
33
|
+
export declare function buildRewindFilesReply(result: RewindFilesResult): RewindFilesReply;
|
|
34
|
+
//# sourceMappingURL=rewind-files-reply.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { seatText } from "../trace/exit-seat.js";
|
|
2
|
+
function applyLeafTable(obj, table) {
|
|
3
|
+
const out = {};
|
|
4
|
+
for (const key of Object.keys(table)) {
|
|
5
|
+
const v = obj[key];
|
|
6
|
+
if (v !== undefined && v !== null)
|
|
7
|
+
out[key] = table[key](v);
|
|
8
|
+
}
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
const pathLeaf = (p) => seatText("rewind-ledger-path", p);
|
|
12
|
+
const reasonLeaf = (t) => seatText("rewind-ledger-reason", t);
|
|
13
|
+
function ledgerErrorOf(e) {
|
|
14
|
+
return { errorCode: e.code, message: reasonLeaf(e.message), ...(e.permanence !== undefined ? { permanence: e.permanence } : {}) };
|
|
15
|
+
}
|
|
16
|
+
const RESTORE_LEDGER_LEAVES = {
|
|
17
|
+
outcome: (v) => v,
|
|
18
|
+
filesChanged: (v) => v.map(pathLeaf),
|
|
19
|
+
identicalSkipped: (v) => v.map(pathLeaf),
|
|
20
|
+
refused: (v) => v.map((f) => ({ path: pathLeaf(f.path), reason: reasonLeaf(f.reason), class: f.class })),
|
|
21
|
+
failed: (v) => v.map((f) => ({ path: pathLeaf(f.path), reason: reasonLeaf(f.reason) })),
|
|
22
|
+
modeNotPreserved: (v) => v,
|
|
23
|
+
};
|
|
24
|
+
const DIFF_STATS_LEAVES = {
|
|
25
|
+
filesChanged: (v) => v.map(pathLeaf),
|
|
26
|
+
insertions: (v) => v,
|
|
27
|
+
deletions: (v) => v,
|
|
28
|
+
};
|
|
29
|
+
export function buildRewindFilesReply(result) {
|
|
30
|
+
if (result.dryRun)
|
|
31
|
+
return { dryRun: true, preview: result.preview === null ? null : applyLeafTable(result.preview, DIFF_STATS_LEAVES) };
|
|
32
|
+
const { error, ...ledger } = result.restore;
|
|
33
|
+
const projected = applyLeafTable(ledger, RESTORE_LEDGER_LEAVES);
|
|
34
|
+
return { dryRun: false, restore: { ...projected, outcome: result.restore.outcome, ...(error !== undefined ? { error: ledgerErrorOf(error) } : {}) } };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=rewind-files-reply.js.map
|