@sema-agent/server 7.132.0 → 7.133.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 +266 -0
- package/README.md +8 -9
- package/README.zh-CN.md +7 -6
- package/USAGE.md +174 -55
- package/deploy/sema-up/README.md +19 -1
- package/deploy/sema-up/chart/templates/server-v4pro.yaml +5 -2
- package/deploy/sema-up/chart/templates/server.yaml +5 -2
- package/deploy/sema-up/stack/compose.yaml +3 -0
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +4 -2
- package/dist/adoption/plan.d.ts +3 -2
- package/dist/adoption/plan.js +7 -5
- package/dist/adoption/runner.js +3 -10
- package/dist/adoption/sql.d.ts +3 -2
- package/dist/adoption/sql.js +3 -5
- package/dist/adoption/wire.d.ts +4 -1
- package/dist/adoption/wire.js +1 -0
- package/dist/approval-ask-audit-store.d.ts +31 -13
- package/dist/approval-ask-audit-store.js +272 -74
- package/dist/approval-ask-machine.d.ts +15 -0
- package/dist/approval-ask-machine.js +6 -0
- package/dist/approval-ask-retention.d.ts +136 -0
- package/dist/approval-ask-retention.js +102 -0
- package/dist/approval-card.d.ts +79 -19
- package/dist/approval-card.js +44 -13
- package/dist/approval-deny-reasons.d.ts +1 -1
- package/dist/approval.d.ts +9 -0
- package/dist/approval.js +24 -3
- package/dist/audit.d.ts +27 -10
- package/dist/audit.js +12 -16
- package/dist/bake-runner/main.js +3 -2
- package/dist/boot/deferred-sandbox-path-env.js +1 -1
- package/dist/boot/execution-env.js +9 -7
- package/dist/boot/execution-lane.js +11 -0
- package/dist/boot/leader.js +2 -0
- package/dist/boot/memory-boundary.js +2 -2
- package/dist/boot/memory-consolidation.d.ts +5 -4
- package/dist/boot/memory-consolidation.js +7 -6
- package/dist/boot/org-delivery.d.ts +28 -0
- package/dist/boot/org-delivery.js +20 -0
- package/dist/boot/reapers.d.ts +3 -0
- package/dist/boot/reapers.js +21 -1
- package/dist/boot/resolve-spec.d.ts +3 -0
- package/dist/boot/resolve-spec.js +60 -81
- package/dist/boot/runner-deps.js +1 -0
- package/dist/boot/session-faces.d.ts +1 -0
- package/dist/boot/session-faces.js +4 -2
- package/dist/boot/stage-02-web-admin-pull.js +4 -1
- package/dist/boot/stage-06-runners.d.ts +2 -0
- package/dist/boot/stage-06-runners.js +6 -3
- package/dist/boot/stage-07-capability-layer.d.ts +2 -0
- package/dist/boot/stage-07-capability-layer.js +24 -3
- package/dist/boot/stage-08-reapers.d.ts +2 -0
- package/dist/boot/stage-08-reapers.js +2 -2
- package/dist/boot/stage-09-leader.d.ts +3 -0
- package/dist/boot/stage-10-http-server.d.ts +3 -0
- package/dist/boot/stage-10-http-server.js +5 -6
- package/dist/boot/stores.js +2 -2
- package/dist/boot/web-admin.d.ts +4 -0
- package/dist/boot/web-admin.js +151 -63
- package/dist/boot/workflow-orchestration.d.ts +2 -0
- package/dist/boot/workflow-orchestration.js +2 -1
- package/dist/brain.js +8 -3
- package/dist/breaker-key.d.ts +6 -0
- package/dist/breaker-key.js +29 -0
- package/dist/caller-text-echo.d.ts +9 -6
- package/dist/caller-text-echo.js +8 -11
- package/dist/capabilities/center-plugins.d.ts +7 -0
- package/dist/capabilities/center-plugins.js +1 -1
- package/dist/capabilities/composite-members.d.ts +1 -1
- package/dist/capabilities/composite-members.js +1 -1
- package/dist/capabilities/execution-lane.js +2 -2
- package/dist/capabilities/hands-lane.d.ts +21 -0
- package/dist/capabilities/hands-lane.js +10 -0
- package/dist/capabilities/mcp-probe.d.ts +36 -4
- package/dist/capabilities/mcp-probe.js +27 -4
- package/dist/capabilities/scenarios.d.ts +63 -7
- package/dist/capabilities/scenarios.js +39 -7
- package/dist/capability-facts.d.ts +34 -4
- package/dist/capability-facts.js +28 -2
- package/dist/center-config-tier.d.ts +69 -0
- package/dist/center-config-tier.js +42 -0
- package/dist/checkpoint-identity.d.ts +16 -0
- package/dist/checkpoint-identity.js +19 -0
- package/dist/config-catalog.d.ts +17 -10
- package/dist/config-catalog.js +43 -28
- package/dist/config-d-migration.d.ts +3 -1
- package/dist/config-d-migration.js +2 -2
- package/dist/config-dir-trust.d.ts +114 -0
- package/dist/config-dir-trust.js +388 -0
- package/dist/config-invariants.d.ts +18 -5
- package/dist/config-invariants.js +35 -3
- package/dist/config-provider.d.ts +6 -1
- package/dist/config-provider.js +6 -2
- package/dist/config-types.d.ts +71 -14
- package/dist/config-types.js +8 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +121 -59
- package/dist/delegated-session-owner.d.ts +185 -0
- package/dist/delegated-session-owner.js +119 -0
- package/dist/device-protocol.d.ts +5 -3
- package/dist/device-protocol.js +1 -1
- package/dist/device-ws-hub.js +21 -2
- package/dist/device-ws-protocol.d.ts +70 -6
- package/dist/device-ws-protocol.js +50 -23
- package/dist/elicitation.js +3 -2
- package/dist/entry-problems.d.ts +34 -0
- package/dist/entry-problems.js +14 -0
- package/dist/execution-lane-caps.d.ts +49 -10
- package/dist/execution-lane-caps.js +43 -4
- package/dist/field-conflict.d.ts +43 -0
- package/dist/field-conflict.js +20 -0
- package/dist/fleet/fleet-bus.d.ts +80 -6
- package/dist/fleet/fleet-bus.js +41 -9
- package/dist/hooks/classic-stations.d.ts +10 -5
- package/dist/hooks/classic-stations.js +4 -4
- package/dist/hooks/command-spawn.d.ts +57 -0
- package/dist/hooks/command-spawn.js +139 -0
- package/dist/hooks/hook-llm.js +2 -2
- package/dist/hooks/hook-runner.d.ts +127 -25
- package/dist/hooks/hook-runner.js +668 -287
- package/dist/hooks/hook-source.d.ts +44 -0
- package/dist/hooks/hook-source.js +40 -0
- package/dist/http/active-run-conflict.d.ts +5 -13
- package/dist/http/active-run-conflict.js +17 -27
- package/dist/http/admission.js +103 -60
- package/dist/http/approval-sweeps.js +55 -18
- package/dist/http/caller-trust.d.ts +77 -0
- package/dist/http/caller-trust.js +143 -0
- package/dist/http/checkpoint-ctx.d.ts +16 -16
- package/dist/http/checkpoint-ctx.js +13 -10
- package/dist/http/claimed-run.d.ts +4 -3
- package/dist/http/device-placement.d.ts +2 -4
- package/dist/http/device-placement.js +2 -1
- package/dist/http/dispatch.js +10 -4
- package/dist/http/durable-run-leg.d.ts +4 -32
- package/dist/http/durable-run-leg.js +34 -10
- package/dist/http/owner-access.d.ts +56 -0
- package/dist/http/owner-access.js +42 -0
- package/dist/http/principal-gate.d.ts +48 -23
- package/dist/http/principal-gate.js +39 -12
- package/dist/http/readiness.d.ts +11 -5
- package/dist/http/readiness.js +10 -3
- package/dist/http/request-guards.d.ts +16 -23
- package/dist/http/request-guards.js +30 -15
- package/dist/http/resume-ctx-read.d.ts +2 -5
- package/dist/http/resume-ctx-read.js +7 -4
- package/dist/http/resume-legs.d.ts +3 -4
- package/dist/http/resume-legs.js +126 -69
- package/dist/http/retired-service-deps.d.ts +43 -0
- package/dist/http/retired-service-deps.js +18 -0
- package/dist/http/route-ctx.d.ts +44 -28
- package/dist/http/route-ctx.js +4 -0
- package/dist/http/route-table.js +2 -0
- package/dist/http/routes/a2a-serve.js +3 -4
- package/dist/http/routes/admin-config-refresh.js +1 -1
- package/dist/http/routes/admin-drain.js +1 -1
- package/dist/http/routes/admin-memory-optout.js +5 -1
- package/dist/http/routes/adoption.js +2 -9
- package/dist/http/routes/approvals-assistant.js +49 -48
- package/dist/http/routes/background.js +3 -2
- package/dist/http/routes/capabilities.js +20 -4
- package/dist/http/routes/config-catalog.d.ts +3 -3
- package/dist/http/routes/config-catalog.js +1 -1
- package/dist/http/routes/devices.js +3 -17
- package/dist/http/routes/diagnostics.js +5 -1
- package/dist/http/routes/images.js +6 -7
- package/dist/http/routes/leader.js +1 -8
- package/dist/http/routes/mcp-reconnect.d.ts +1 -1
- package/dist/http/routes/mcp-reconnect.js +3 -2
- package/dist/http/routes/memory-bundle.js +1 -1
- package/dist/http/routes/memory-compliance.js +1 -1
- package/dist/http/routes/memory-consolidation.js +1 -1
- package/dist/http/routes/memory-origin.js +1 -1
- package/dist/http/routes/memory-policy.d.ts +1 -1
- package/dist/http/routes/memory-policy.js +3 -2
- package/dist/http/routes/notify-wake.js +8 -21
- package/dist/http/routes/observability.js +2 -2
- package/dist/http/routes/principal-inbox.d.ts +39 -0
- package/dist/http/routes/principal-inbox.js +76 -0
- package/dist/http/routes/retention-ops.js +2 -9
- package/dist/http/routes/rules.js +5 -18
- package/dist/http/routes/runs.d.ts +5 -0
- package/dist/http/routes/runs.js +33 -106
- package/dist/http/routes/session-sync.js +15 -28
- package/dist/http/routes/sessions.js +30 -40
- package/dist/http/routes/side-query.js +6 -4
- package/dist/http/routes/tasks.js +50 -14
- package/dist/http/routes/workflows.d.ts +351 -0
- package/dist/http/routes/workflows.js +153 -119
- package/dist/http/send.d.ts +24 -3
- package/dist/http/send.js +14 -2
- package/dist/http/server.d.ts +17 -18
- package/dist/http/server.js +15 -13
- package/dist/http/stored-body-replay.js +17 -4
- package/dist/http/submit-ctx.js +4 -3
- package/dist/http/submit-replay.d.ts +4 -3
- package/dist/http/submit-replay.js +5 -4
- package/dist/http/wire-types.d.ts +10 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -1
- package/dist/lane-home-probe.d.ts +78 -9
- package/dist/lane-home-probe.js +78 -12
- package/dist/leader/endpoint.d.ts +4 -1
- package/dist/leader/endpoint.js +11 -10
- package/dist/limit-refusal.d.ts +17 -5
- package/dist/limit-refusal.js +4 -1
- package/dist/mcp-assertion-header.d.ts +31 -10
- package/dist/mcp-assertion-header.js +10 -3
- package/dist/mcp-tool-faces.js +1 -3
- package/dist/memory-project-layer.d.ts +37 -0
- package/dist/memory-project-layer.js +46 -0
- package/dist/memory-scope.d.ts +23 -16
- package/dist/memory-scope.js +24 -8
- package/dist/memory-sync-client.d.ts +27 -13
- package/dist/memory-sync-client.js +107 -18
- package/dist/model-entry-refusal.d.ts +9 -1
- package/dist/model-entry-refusal.js +6 -1
- package/dist/model-plane-face.d.ts +51 -0
- package/dist/model-plane-face.js +24 -0
- package/dist/model-provider.d.ts +5 -0
- package/dist/model-provider.js +4 -2
- package/dist/model-route-endpoint.d.ts +8 -11
- package/dist/model-route-endpoint.js +4 -7
- package/dist/model-route-env.d.ts +22 -0
- package/dist/model-route-env.js +2 -0
- package/dist/model-route-gap.d.ts +60 -30
- package/dist/model-route-gap.js +21 -15
- package/dist/observability/corrupt-read-seat.d.ts +7 -0
- package/dist/observability/corrupt-read-seat.js +9 -0
- package/dist/observability/err-text.d.ts +6 -0
- package/dist/observability/err-text.js +18 -4
- package/dist/observability/fail-open.d.ts +35 -9
- package/dist/observability/fail-open.js +35 -9
- package/dist/observability/metrics.js +1 -0
- package/dist/observability/prompt-manifest.d.ts +3 -17
- package/dist/observability/prompt-manifest.js +45 -42
- package/dist/observability/tool-trace.js +9 -9
- package/dist/operator-ask.d.ts +10 -0
- package/dist/operator-ask.js +3 -0
- package/dist/orchestration/workflow-agent-session-index.d.ts +12 -12
- package/dist/orchestration/workflow-agent-session-index.js +9 -13
- package/dist/orchestration/workflow-completion-inbox.d.ts +42 -15
- package/dist/orchestration/workflow-completion-inbox.js +13 -0
- package/dist/orchestration/workflow-notify-journal.d.ts +13 -32
- package/dist/orchestration/workflow-notify-journal.js +27 -34
- package/dist/orchestration/workflow-park-decision.d.ts +89 -0
- package/dist/orchestration/workflow-park-decision.js +118 -0
- package/dist/org-delivery-gate.d.ts +81 -0
- package/dist/org-delivery-gate.js +59 -0
- package/dist/panel-tool-names.d.ts +23 -0
- package/dist/panel-tool-names.js +8 -0
- package/dist/parked-decide.d.ts +39 -6
- package/dist/parked-decide.js +98 -51
- package/dist/parked-revive-surface.d.ts +9 -2
- package/dist/parked-revive-surface.js +11 -8
- package/dist/permission-rule-list.d.ts +1 -1
- package/dist/permission-rule-list.js +2 -2
- package/dist/plugins/approval-ask-store-file.d.ts +16 -1
- package/dist/plugins/approval-ask-store-file.js +21 -0
- package/dist/plugins/approval-ask-store-memory.d.ts +18 -1
- package/dist/plugins/approval-ask-store-memory.js +34 -2
- package/dist/plugins/approval-ask-store-sql.d.ts +25 -0
- package/dist/plugins/approval-ask-store-sql.js +37 -1
- package/dist/plugins/blob-backend.d.ts +38 -25
- package/dist/plugins/blob-backend.js +29 -19
- package/dist/plugins/breaker-state-sql.d.ts +2 -2
- package/dist/plugins/breaker-state-sql.js +4 -4
- package/dist/plugins/caching-session-store.d.ts +3 -0
- package/dist/plugins/caching-session-store.js +3 -0
- package/dist/plugins/checkpoint-store-sql.d.ts +14 -0
- package/dist/plugins/checkpoint-store-sql.js +20 -2
- package/dist/plugins/file-history-store-sql.d.ts +5 -2
- package/dist/plugins/file-history-store-sql.js +3 -1
- package/dist/plugins/file-run-store.d.ts +5 -13
- package/dist/plugins/file-run-store.js +9 -0
- package/dist/plugins/fork-routing-session-store.d.ts +9 -1
- package/dist/plugins/fork-routing-session-store.js +12 -1
- package/dist/plugins/host-platform.d.ts +2 -0
- package/dist/plugins/host-platform.js +2 -1
- package/dist/plugins/local-checkpoint-store.d.ts +2 -0
- package/dist/plugins/local-checkpoint-store.js +6 -1
- package/dist/plugins/local-session-store.d.ts +1 -1
- package/dist/plugins/local-session-window.d.ts +39 -0
- package/dist/plugins/local-session-window.js +54 -0
- package/dist/plugins/mailbox-recipient-lifecycle.d.ts +3 -2
- package/dist/plugins/mailbox-store-sql.d.ts +30 -48
- package/dist/plugins/mailbox-store-sql.js +77 -52
- package/dist/plugins/memory-embedder-fingerprint.js +2 -1
- package/dist/plugins/memory-run-store.d.ts +5 -13
- package/dist/plugins/memory-run-store.js +8 -0
- package/dist/plugins/one-time-migrations.d.ts +110 -5
- package/dist/plugins/one-time-migrations.js +320 -8
- package/dist/plugins/org-delivery-quota-store.d.ts +123 -0
- package/dist/plugins/org-delivery-quota-store.js +228 -0
- package/dist/plugins/pg-pool.js +39 -7
- package/dist/plugins/pg-session-storage.d.ts +17 -4
- package/dist/plugins/pg-session-storage.js +29 -6
- package/dist/plugins/remote-env-adb.d.ts +6 -12
- package/dist/plugins/remote-env-adb.js +12 -2
- package/dist/plugins/remote-env-k8s.d.ts +8 -12
- package/dist/plugins/remote-env-k8s.js +23 -5
- package/dist/plugins/remote-env-local-docker.d.ts +10 -15
- package/dist/plugins/remote-env-local-docker.js +12 -9
- package/dist/plugins/remote-env-ssh.d.ts +10 -16
- package/dist/plugins/remote-env-ssh.js +17 -11
- package/dist/plugins/run-store-sql.d.ts +16 -14
- package/dist/plugins/run-store-sql.js +22 -2
- package/dist/plugins/schema-indexes.js +2 -0
- package/dist/plugins/send-user-file.js +2 -2
- package/dist/plugins/session-epoch-anchor.d.ts +32 -6
- package/dist/plugins/session-epoch-anchor.js +2 -3
- package/dist/plugins/session-store.d.ts +18 -8
- package/dist/plugins/session-store.js +15 -4
- package/dist/plugins/sql-driver.d.ts +74 -11
- package/dist/plugins/sql-driver.js +210 -12
- package/dist/plugins/sql-errors.d.ts +23 -0
- package/dist/plugins/sql-errors.js +21 -0
- package/dist/plugins/store-backend.d.ts +36 -1
- package/dist/plugins/store-backend.js +40 -14
- package/dist/plugins/store-contracts.d.ts +42 -0
- package/dist/plugins/store-contracts.js +1 -0
- package/dist/plugins/tidb-pool.d.ts +6 -1
- package/dist/plugins/tidb-pool.js +44 -10
- package/dist/plugins/tidb-session-storage.d.ts +3 -2
- package/dist/plugins/tidb-session-storage.js +2 -2
- package/dist/plugins/tidb-session-store.d.ts +24 -4
- package/dist/plugins/tidb-session-store.js +28 -4
- package/dist/plugins/workflow-journal-store-sql.d.ts +73 -19
- package/dist/plugins/workflow-journal-store-sql.js +19 -6
- package/dist/plugins/workflow-run-store-sql.d.ts +30 -8
- package/dist/plugins/workflow-run-store-sql.js +50 -9
- package/dist/posture-source.d.ts +18 -10
- package/dist/posture-source.js +4 -1
- package/dist/project-identity.d.ts +45 -6
- package/dist/project-identity.js +162 -8
- package/dist/project-layer-key.d.ts +28 -0
- package/dist/project-layer-key.js +29 -0
- package/dist/question.js +3 -2
- package/dist/read-deny-entry.d.ts +25 -0
- package/dist/read-deny-entry.js +12 -0
- package/dist/read-face-posture.d.ts +37 -11
- package/dist/read-face-posture.js +32 -3
- package/dist/request-key-closure.d.ts +7 -0
- package/dist/request-key-closure.js +9 -1
- package/dist/request-value-closure.d.ts +5 -0
- package/dist/request-value-closure.js +11 -3
- package/dist/rule-entry-list.d.ts +26 -2
- package/dist/rule-entry-list.js +72 -12
- package/dist/rules-consent.js +3 -4
- package/dist/run-acceptance.d.ts +19 -3
- package/dist/run-acceptance.js +13 -1
- package/dist/run-local.js +36 -6
- package/dist/runs.d.ts +10 -9
- package/dist/runs.js +21 -3
- package/dist/runtime-caps-resolver.d.ts +16 -6
- package/dist/runtime-caps-resolver.js +18 -5
- package/dist/sandbox-pkg-source.d.ts +19 -1
- package/dist/sandbox-pkg-source.js +29 -7
- package/dist/security.d.ts +87 -9
- package/dist/security.js +52 -9
- package/dist/session-error-wire.d.ts +19 -2
- package/dist/session-error-wire.js +5 -1
- package/dist/session-titled-frame.d.ts +33 -0
- package/dist/session-titled-frame.js +4 -0
- package/dist/session-titler.d.ts +9 -1
- package/dist/session-titler.js +15 -4
- package/dist/spec-fields.js +21 -2
- package/dist/sql-engine-posture.d.ts +3 -1
- package/dist/task-cwd.d.ts +1 -1
- package/dist/task-mcp.d.ts +3 -3
- package/dist/task-mcp.js +7 -66
- package/dist/task-settings.d.ts +89 -88
- package/dist/task-settings.js +71 -63
- package/dist/text-bidi.d.ts +0 -4
- package/dist/text-bidi.js +1 -3
- package/dist/tighten-only-seats.d.ts +150 -0
- package/dist/tighten-only-seats.js +196 -0
- package/dist/tool-approval.d.ts +303 -87
- package/dist/tool-approval.js +623 -239
- package/dist/trace/core-keyset-guard.d.ts +104 -22
- package/dist/trace/exit-seat.d.ts +28 -0
- package/dist/trace/exit-seat.js +76 -0
- package/dist/trace/ledger-events.d.ts +3 -2
- package/dist/trace/project.d.ts +80 -12
- package/dist/trace/project.js +41 -28
- package/dist/trace/projection-table.d.ts +100 -0
- package/dist/trace/projection-table.js +130 -0
- package/dist/trace/redact.d.ts +54 -0
- package/dist/trace/redact.js +778 -152
- package/dist/trace/self-minted-wire.d.ts +345 -1
- package/dist/trace/self-minted-wire.js +117 -1
- package/dist/trace/wire-projection-faces.d.ts +298 -2
- package/dist/trace/wire-projection-faces.js +154 -13
- package/dist/url-refusal.js +2 -0
- package/dist/web-admin-client/apply-effective.d.ts +12 -0
- package/dist/web-admin-client/apply-effective.js +56 -5
- package/dist/web-admin-client/facade.d.ts +1 -1
- package/dist/web-admin-client/facade.js +1 -1
- package/dist/web-admin-client/read-face.js +5 -9
- package/dist/web-admin-client/skills-mcp.js +4 -5
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +57 -9
- package/package.json +7 -3
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { dropProjectedFace } from "../trace/projection-drop.js";
|
|
2
|
+
import { WIRE_PROJECTION_FACES } from "../trace/wire-projection-faces.js";
|
|
2
3
|
const ABSENT = Symbol("absent");
|
|
3
|
-
const OPTIONAL_CELL = Symbol("optional-cell");
|
|
4
4
|
const text = (v) => (typeof v === "string" ? v : undefined);
|
|
5
5
|
const finite = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
|
6
6
|
const flag = (v) => (typeof v === "boolean" ? v : undefined);
|
|
7
7
|
const onlyTrue = (v) => (v === true ? true : undefined);
|
|
8
8
|
const plainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : undefined;
|
|
9
9
|
function optional(read) {
|
|
10
|
-
return
|
|
10
|
+
return (v) => (v === undefined ? ABSENT : read(v));
|
|
11
11
|
}
|
|
12
|
-
function objectOf(
|
|
12
|
+
function objectOf(cells) {
|
|
13
13
|
return (v) => {
|
|
14
14
|
const o = plainObject(v);
|
|
15
15
|
if (o === undefined)
|
|
16
16
|
return undefined;
|
|
17
17
|
const out = {};
|
|
18
|
-
for (const [key, read] of
|
|
18
|
+
for (const [key, read] of cells) {
|
|
19
19
|
const r = read(o[key]);
|
|
20
20
|
if (r === undefined)
|
|
21
21
|
return undefined;
|
|
@@ -72,46 +72,49 @@ function rowsOf(member, read) {
|
|
|
72
72
|
return v.length > 0 && out.length === 0 ? ABSENT : out;
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
75
|
+
const FACES = WIRE_PROJECTION_FACES;
|
|
76
|
+
function exhausted(shape) {
|
|
77
|
+
throw new Error("清单行声明里有不认得的值形:" + JSON.stringify(shape));
|
|
78
|
+
}
|
|
79
|
+
function readerOfShape(shape, member, building) {
|
|
80
|
+
switch (shape.is) {
|
|
81
|
+
case "text":
|
|
82
|
+
return text;
|
|
83
|
+
case "count":
|
|
84
|
+
return finite;
|
|
85
|
+
case "flag":
|
|
86
|
+
return flag;
|
|
87
|
+
case "true":
|
|
88
|
+
return onlyTrue;
|
|
89
|
+
case "object":
|
|
90
|
+
return objectOf(cellsOfFace(shape.face, building));
|
|
91
|
+
case "list":
|
|
92
|
+
return listOf(readerOfShape(shape.of, member, building));
|
|
93
|
+
case "rows":
|
|
94
|
+
return rowsOf(member, readerOfShape(shape.of, member, building));
|
|
95
|
+
case "entries":
|
|
96
|
+
return entriesOf(readerOfShape(shape.of, member, building));
|
|
97
|
+
default:
|
|
98
|
+
return exhausted(shape);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function cellsOfFace(face, building) {
|
|
102
|
+
if (building.includes(face))
|
|
103
|
+
throw new Error("清单行声明成环:" + [...building, face].join(" → "));
|
|
104
|
+
const keys = FACES[face]?.keys;
|
|
105
|
+
if (keys === undefined)
|
|
106
|
+
throw new Error("清单行声明引用了没有 keys 的面:" + face);
|
|
107
|
+
return Object.entries(keys).map(([key, declared]) => {
|
|
108
|
+
const read = readerOfShape(declared, key, [...building, face]);
|
|
109
|
+
return [key, declared.optional === true ? optional(read) : read];
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const ROW = cellsOfFace("prompt_manifest", []);
|
|
108
113
|
export function promptManifestRecordOf(e) {
|
|
114
|
+
const frame = e;
|
|
109
115
|
const out = {};
|
|
110
|
-
for (const [member, read] of
|
|
111
|
-
const
|
|
112
|
-
if (v === undefined)
|
|
113
|
-
continue;
|
|
114
|
-
const r = read(v);
|
|
116
|
+
for (const [member, read] of ROW) {
|
|
117
|
+
const r = read(frame[member]);
|
|
115
118
|
if (r === undefined)
|
|
116
119
|
drop(member, "does not read as the engine's type");
|
|
117
120
|
else if (r !== ABSENT)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isClassifierDenyCause, isDeniedBy } from "@sema-agent/core";
|
|
2
2
|
import { observeClassic } from "../hooks/classic-stations.js";
|
|
3
3
|
import { redactSecrets } from "../trace/redact.js";
|
|
4
|
+
import { echoCallerText } from "../caller-text-echo.js";
|
|
4
5
|
export const PERMISSION_DENIED_METER_REGISTRATION = "server.permission-denied-meter";
|
|
5
6
|
export const TOOL_TRACE_REGISTRATION = "server.tool-trace";
|
|
6
7
|
function deniedByLabel(gate) {
|
|
@@ -50,7 +51,7 @@ export function createToolTracer(logger) {
|
|
|
50
51
|
isError: true,
|
|
51
52
|
isInterrupt: e.failure.isInterrupt,
|
|
52
53
|
...(e.failure.durationMs !== undefined ? { durationMs: e.failure.durationMs } : {}),
|
|
53
|
-
out:
|
|
54
|
+
out: echoCallerText(redactSecrets(e.failure.error), { maxChars: TRACE_OUT_ECHO_CHARS }),
|
|
54
55
|
});
|
|
55
56
|
});
|
|
56
57
|
observeClassic(on, "classic.PermissionDenied", (payload) => {
|
|
@@ -61,34 +62,33 @@ export function createToolTracer(logger) {
|
|
|
61
62
|
deniedBy: deniedByLabel(payload.gate),
|
|
62
63
|
...(payload.gate.origin === undefined ? {} : { origin: payload.gate.origin }),
|
|
63
64
|
...(payload.gate.settlement === undefined ? {} : { settlement: payload.gate.settlement.kind }),
|
|
64
|
-
reason:
|
|
65
|
+
reason: echoCallerText(redactSecrets(payload.reason), { maxChars: TRACE_OUT_ECHO_CHARS }),
|
|
65
66
|
arg: summarize(payload.input),
|
|
66
67
|
});
|
|
67
68
|
});
|
|
68
69
|
},
|
|
69
70
|
};
|
|
70
71
|
}
|
|
72
|
+
const TRACE_ARG_ECHO_CHARS = 120;
|
|
73
|
+
const TRACE_OUT_ECHO_CHARS = 200;
|
|
71
74
|
function summarize(input) {
|
|
72
75
|
if (!input || typeof input !== "object")
|
|
73
|
-
return { v:
|
|
76
|
+
return { v: echoCallerText(redactSecrets(String(input)), { maxChars: TRACE_ARG_ECHO_CHARS }) };
|
|
74
77
|
const o = input;
|
|
75
78
|
const s = {};
|
|
76
79
|
for (const k of ["path", "file_path", "command", "cmd", "pattern", "glob", "old_string", "new_string"]) {
|
|
77
80
|
if (typeof o[k] === "string")
|
|
78
|
-
s[k] =
|
|
81
|
+
s[k] = echoCallerText(redactSecrets(o[k]), { maxChars: TRACE_ARG_ECHO_CHARS });
|
|
79
82
|
}
|
|
80
83
|
if (typeof o.content === "string")
|
|
81
84
|
s.contentLen = o.content.length;
|
|
82
|
-
return Object.keys(s).length ? s : { keys: Object.keys(o) };
|
|
85
|
+
return Object.keys(s).length ? s : { keys: Object.keys(o).map((k) => echoCallerText(k, { maxChars: TRACE_ARG_ECHO_CHARS })) };
|
|
83
86
|
}
|
|
84
87
|
function textOf(content) {
|
|
85
88
|
const text = content
|
|
86
89
|
.map((c) => (c && typeof c === "object" && typeof c.text === "string" ? c.text : ""))
|
|
87
90
|
.join("")
|
|
88
91
|
.trim();
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
function clip(s, n) {
|
|
92
|
-
return s.length > n ? `${s.slice(0, n)}…(${s.length})` : s;
|
|
92
|
+
return echoCallerText(redactSecrets(text), { maxChars: TRACE_OUT_ECHO_CHARS });
|
|
93
93
|
}
|
|
94
94
|
//# sourceMappingURL=tool-trace.js.map
|
package/dist/operator-ask.d.ts
CHANGED
|
@@ -66,6 +66,16 @@ export declare function operatorAsk(rule: string, message: string): OperatorAskR
|
|
|
66
66
|
* 名单卡要带「本会话放行」,而强制卡上没有。「恒问人」两类盖出身 ⇒ core 读 `operator_forced`、盖 `mandated`,站着的答案在哪一层都退不掉它们。
|
|
67
67
|
*/
|
|
68
68
|
export declare function operatorAlwaysHumanAsk(rule: string, message: string): OperatorAskResult;
|
|
69
|
+
/**
|
|
70
|
+
* 🔴 **S-1351 —— 请求写下的「恒问人」**(`settings.permissions.neverAuto`):在 {@link operatorAsk} 之上再盖 `requiresRealApproval: true`(core 的治理位 ——
|
|
71
|
+
* 「只有判断能清它」:空白的 `onAsk: "allow"`、任何站着的答案(持久规则、会话授权)、auto 分类器都清不掉,只有**这一次**的真人应答能答),不盖部署出身。
|
|
72
|
+
*
|
|
73
|
+
* 为什么不盖 `authoredBy: "deployment"`:出身位说的是「部署自己的治理层写的」,请求里的声明不是部署写的 —— 盖了就是在审计面冒名。`requiresRealApproval` 是 core 明文开给
|
|
74
|
+
* 策略自报的位(顶注:自报只会把**自己的** ask 退出自动裁决,方向是收紧、冒报安全),它把这一问推进「只有判断能清」的那一门(`ruleClearanceOf` 的治理门),
|
|
75
|
+
* 效果与部署的 `APPROVAL_NEVER_AUTO` 同级 —— 每个权限模式词下的仲裁读数逐位相同(`test/tighten-only-seats-assembly.test.ts` 逐词钉住)。
|
|
76
|
+
* 出处串(`rule` 写 `settings.permissions.neverAuto(<命中的名>)`,不写成 `APPROVAL_NEVER_AUTO(…)`)进 `matchedAskRule`:引擎闸内部消费、不上卡(同部署那一条),审计 / 单测读它区分来源。
|
|
77
|
+
*/
|
|
78
|
+
export declare function requestAlwaysHumanAsk(rule: string, message: string): OperatorAskResult;
|
|
69
79
|
/**
|
|
70
80
|
* 🔴 **S-958 —— 治理层的叶策略包装**:`leaf` 产的每一只 ask 盖部署出身(经 {@link withDeploymentAuthorship}),allow / deny 原物交回;
|
|
71
81
|
* 成员(`projection` / `pathRules` / `writeTargetGuard` / `nameSets`)经 core `wrapToolPolicy` 随行(契约「包装至少拒内层所拒」:
|
package/dist/operator-ask.js
CHANGED
|
@@ -5,6 +5,9 @@ export function operatorAsk(rule, message) {
|
|
|
5
5
|
export function operatorAlwaysHumanAsk(rule, message) {
|
|
6
6
|
return withDeploymentAuthorship(operatorAsk(rule, message));
|
|
7
7
|
}
|
|
8
|
+
export function requestAlwaysHumanAsk(rule, message) {
|
|
9
|
+
return { ...operatorAsk(rule, message), requiresRealApproval: true };
|
|
10
|
+
}
|
|
8
11
|
function withDeploymentAuthorship(ask) {
|
|
9
12
|
return { ...ask, authoredBy: "deployment" };
|
|
10
13
|
}
|
|
@@ -15,11 +15,12 @@ export interface WorkflowAgentSessionRow {
|
|
|
15
15
|
/**
|
|
16
16
|
* 索引面的两个动词。**写者只有一个**(见文件头),读者是判别式。
|
|
17
17
|
*
|
|
18
|
-
* `
|
|
19
|
-
*
|
|
18
|
+
* `ensurePointers` 语义 = 「rows 里的每一枚指针此后都在」:upsert,**从不删**(唯一的删除是 run 收割的级联)。幂等、可重放;写者在记录落盘
|
|
19
|
+
* **之前**调它(文件头「指针先于记录」)。
|
|
20
|
+
* `listByAgentSession` = 点名这个子会话的**全部**指针(各 run 一行;顺序不承重)—— 点名者的超集。
|
|
20
21
|
*/
|
|
21
22
|
export interface WorkflowAgentSessionIndex {
|
|
22
|
-
|
|
23
|
+
ensurePointers(runId: string, rows: readonly WorkflowAgentSessionRow[]): Promise<void>;
|
|
23
24
|
listByAgentSession(sessionId: string): Promise<WorkflowAgentSessionRow[]>;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
@@ -50,8 +51,8 @@ export declare function readRunParks(run: unknown): WorkflowRunParkKey[] | undef
|
|
|
50
51
|
export declare function heldParksOf(recordId: string, parks: readonly WorkflowRunParkKey[]): WorkflowRunParkKey[];
|
|
51
52
|
/**
|
|
52
53
|
* 派生的**唯一属主**:一只 `WorkflowRun` 的指针行 = 它 `parks[]` 里点名的每一个子会话(一个子会话一行)。`parks` 缺席 ⇒ 零条
|
|
53
|
-
* ({@link readRunParks}:没有条目)⇒
|
|
54
|
-
* `parks[]` 读不出 ⇒ `undefined`(**派生不出来**,不是「零条」)
|
|
54
|
+
* ({@link readRunParks}:没有条目)⇒ 没有要写的指针。
|
|
55
|
+
* `parks[]` 读不出 ⇒ `undefined`(**派生不出来**,不是「零条」):写者据此不写指针(文件头「指针先于记录」段)。
|
|
55
56
|
*/
|
|
56
57
|
export declare function buildParkSessionRows(runId: string, run: {
|
|
57
58
|
scope: string;
|
|
@@ -99,9 +100,7 @@ export type WorkflowParkRoute = {
|
|
|
99
100
|
* 🔴 **窗与删码**:规则 ③ 的 `older_engine` 读臂是一次性迁移 M9 的读侧半场(升级那一刻还停驻着的存量记录)。窗口与删码清单见 `plugins/one-time-migrations.ts` 登记表 M9 一行,随 M9 一起删;这里不写第二份窗。
|
|
100
101
|
*/
|
|
101
102
|
export declare function routeWorkflowPark(sessionId: string, candidates: readonly WorkflowRun[]): WorkflowParkRoute;
|
|
102
|
-
/**
|
|
103
|
-
export declare function sameAgentSessionRows(a: readonly WorkflowAgentSessionRow[], b: readonly WorkflowAgentSessionRow[]): boolean;
|
|
104
|
-
/** 账本一行的**内域形**:一次 `syncRun` 的整份行集快照(`{runId, rows}`)。 */
|
|
103
|
+
/** 账本一行的**内域形**:一条 run 当时的整份指针快照(`{runId, rows}`;同一条 run 后写的一行整份覆盖先写的 —— 本仓只增不删,所以后一行恒是前一行的超集)。 */
|
|
105
104
|
export interface WorkflowAgentSessionLedgerLine {
|
|
106
105
|
runId: string;
|
|
107
106
|
rows: WorkflowAgentSessionRow[];
|
|
@@ -112,7 +111,7 @@ export interface WorkflowAgentSessionLedgerLine {
|
|
|
112
111
|
* 姿态与 SQL 孪生逐字同源:那边 `listByAgentSession` 逐字段收窄(`String(r.session_id)` …),这边逐字段
|
|
113
112
|
* 判形 —— 一张索引面、两个后端、**一种**入域姿态。
|
|
114
113
|
*
|
|
115
|
-
* **整行成败制**(与既有的撕裂行臂同一条规则):一行 =
|
|
114
|
+
* **整行成败制**(与既有的撕裂行臂同一条规则):一行 = 一条 run 的**整份**快照,任一位读不出来就说明
|
|
116
115
|
* 这份快照重建不出来 ⇒ 整行不 apply(那条 run 保留上一份已知良好的快照)。不做「丢掉坏成员、留下好成员」
|
|
117
116
|
* ——那会静默铸出一份**比真相少几条 park** 的行集,而这条索引的消费面正是 park 的赎回路由。
|
|
118
117
|
* 读不出来 ⇒ 调用方**响亮**记一笔([ref]:安全轴不许静默),不吞整档。
|
|
@@ -125,7 +124,7 @@ export declare function readAgentSessionLedgerLine(v: unknown): WorkflowAgentSes
|
|
|
125
124
|
* 逐字同形:0o700 目录 + 0o600 账本、按行重放),重启后 park 仍可 join;缺席 ⇒ 纯内存
|
|
126
125
|
* (`WORKFLOW_RUN_STORE=memory` 的显式易失车道,与它的 run 店同寿命)。
|
|
127
126
|
*
|
|
128
|
-
* 账本的一行 =
|
|
127
|
+
* 账本的一行 = **一条 run 当时的整份指针集**(按 runId 后写覆盖;指针只增不删 ⇒ 后一行恒是前一行的超集),所以重放即收敛,不需要压缩腿。
|
|
129
128
|
*
|
|
130
129
|
* 追加 / 重放走本仓 JSONL 店的**共用口**(S-977;此前 ctor 里自写 `truncateTornTail` + 手写 `split("\n") + JSON.parse` 重放):
|
|
131
130
|
* 追加 = core `AppendLog`(惰性打开、撕尾在**打开与每次追加前**修 —— 修前只在 boot 修,运行期半写后的下一次成功写仍会被粘进残尾),
|
|
@@ -141,9 +140,10 @@ export declare class LocalWorkflowAgentSessionIndex implements WorkflowAgentSess
|
|
|
141
140
|
private readonly bySession;
|
|
142
141
|
private log;
|
|
143
142
|
constructor(root?: string, fsyncEnabled?: boolean);
|
|
144
|
-
/** 内存两张表的收敛(重放与写路径共用一份逻辑)
|
|
143
|
+
/** 内存两张表的收敛(重放与写路径共用一份逻辑):这条 run 的指针集 = 这一行的整份快照。 */
|
|
145
144
|
private apply;
|
|
146
|
-
|
|
145
|
+
/** 只增不删:这条 run 已有的指针 ∪ 这几枚,写成一行整份快照(盘上一行仍是「这条 run 的指针集」,与早年的账本行同一种读法)。 */
|
|
146
|
+
ensurePointers(runId: string, rows: readonly WorkflowAgentSessionRow[]): Promise<void>;
|
|
147
147
|
listByAgentSession(sessionId: string): Promise<WorkflowAgentSessionRow[]>;
|
|
148
148
|
}
|
|
149
149
|
//# sourceMappingURL=workflow-agent-session-index.d.ts.map
|
|
@@ -88,16 +88,6 @@ function highestHolders(sessionId, readable) {
|
|
|
88
88
|
}
|
|
89
89
|
return top;
|
|
90
90
|
}
|
|
91
|
-
export function sameAgentSessionRows(a, b) {
|
|
92
|
-
if (a.length !== b.length)
|
|
93
|
-
return false;
|
|
94
|
-
const key = (r) => `${r.sessionId}\u0000${r.runId}\u0000${r.agentKey}\u0000${r.scope}`;
|
|
95
|
-
const left = new Set(a.map(key));
|
|
96
|
-
for (const r of b)
|
|
97
|
-
if (!left.has(key(r)))
|
|
98
|
-
return false;
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
91
|
export function readAgentSessionLedgerLine(v) {
|
|
102
92
|
if (typeof v !== "object" || v === null)
|
|
103
93
|
return undefined;
|
|
@@ -173,12 +163,18 @@ export class LocalWorkflowAgentSessionIndex {
|
|
|
173
163
|
runs.set(runId, r);
|
|
174
164
|
}
|
|
175
165
|
}
|
|
176
|
-
async
|
|
166
|
+
async ensurePointers(runId, rows) {
|
|
167
|
+
const held = this.byRun.get(runId) ?? [];
|
|
168
|
+
const named = new Set(held.map((r) => r.sessionId));
|
|
169
|
+
const added = rows.filter((r) => !named.has(r.sessionId));
|
|
170
|
+
if (added.length === 0)
|
|
171
|
+
return;
|
|
172
|
+
const merged = [...held, ...added];
|
|
177
173
|
if (this.ledgerPath !== undefined) {
|
|
178
174
|
this.log ??= new AppendLog(this.ledgerPath);
|
|
179
|
-
this.log.append({ runId, rows }, this.fsyncEnabled);
|
|
175
|
+
this.log.append({ runId, rows: merged }, this.fsyncEnabled);
|
|
180
176
|
}
|
|
181
|
-
this.apply(runId,
|
|
177
|
+
this.apply(runId, merged);
|
|
182
178
|
}
|
|
183
179
|
async listByAgentSession(sessionId) {
|
|
184
180
|
return [...(this.bySession.get(sessionId)?.values() ?? [])];
|
|
@@ -228,26 +228,26 @@ diag?: {
|
|
|
228
228
|
connection: string;
|
|
229
229
|
log(msg: string, meta?: Record<string, unknown>): void;
|
|
230
230
|
}): Promise<void>;
|
|
231
|
-
/**
|
|
232
|
-
*
|
|
233
|
-
|
|
234
|
-
* injection covers a LIVE harness; a completion that lands after the leg ended had NO durable path (idle no-show,
|
|
235
|
-
* lost across restart). Bounded + redacted HERE (the store carries only egress-safe bytes; summary/result are
|
|
236
|
-
* UNTRUSTED free text). `status` collapses onto the inbox's completed|failed column; the ORIGINAL status rides
|
|
237
|
-
* the payload extras and overrides on drain (killed/cancelled reach the shell verbatim). Workflow-type
|
|
238
|
-
* notifications are the CALLER's job to filter (they have their own durable chain — double-enqueueing here would
|
|
239
|
-
* re-open the poll-served double-push).
|
|
240
|
-
*/
|
|
241
|
-
export declare function taskNotificationInboxEntry(sessionId: string, owner: string | null, n: {
|
|
231
|
+
/** 停驻收件条目的**共享字段** —— 引擎递来的完成与本服务铸的 external 通知都有的那几位。三只入参型都写成类型字面量(不是 interface):
|
|
232
|
+
* 调用方手里的是一只记录形的 payload,字面量型才与它可比(interface 没有隐式索引签名)。 */
|
|
233
|
+
type ParkedNotificationFields = {
|
|
242
234
|
task_id: string;
|
|
243
|
-
task_type: string;
|
|
244
|
-
toolUseId?: string;
|
|
245
235
|
status: string;
|
|
246
236
|
summary: string;
|
|
247
237
|
result?: string;
|
|
238
|
+
seq?: number;
|
|
239
|
+
/** 通知的来源标签(external 通知的入站体键,core 载荷同名键;live 投影过 `redactSecrets`,这里同读法)。 */
|
|
240
|
+
source?: string;
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* **引擎递来的一次完成**(`onTaskNotification` 的 payload,执行腿父腿已收尾时入箱)—— 停驻收件的入参型。四处调用(bg 腿 `runs.ts`、sync 腿
|
|
244
|
+
* `routes/tasks.ts`、两条续跑腿 `resume-legs.ts`)原样交 core 的那只 payload。
|
|
245
|
+
*/
|
|
246
|
+
export type EngineNotificationParkInput = ParkedNotificationFields & {
|
|
247
|
+
task_type: string;
|
|
248
|
+
toolUseId?: string;
|
|
248
249
|
output_file?: string;
|
|
249
250
|
sessionId?: string;
|
|
250
|
-
seq?: number;
|
|
251
251
|
lines?: string[];
|
|
252
252
|
stoppedBy?: string;
|
|
253
253
|
recentSteps?: Array<{
|
|
@@ -281,7 +281,33 @@ export declare function taskNotificationInboxEntry(sessionId: string, owner: str
|
|
|
281
281
|
};
|
|
282
282
|
resupplied?: boolean;
|
|
283
283
|
attempt?: number;
|
|
284
|
-
|
|
284
|
+
/**
|
|
285
|
+
* 引擎的**一次完成**的相关 id(fill-once,`SemaTaskHandle.completionId`)—— live 投影(`trace/project.ts`)逐字透传的同一个值,
|
|
286
|
+
* 停驻收件条目照带 ⇒ 同一次完成在 live 帧与下一次开流的补投帧上同一个 id。引擎铸的不透明标识:逐字、不脱敏、不进折叠键;本仓零自铸。
|
|
287
|
+
*/
|
|
288
|
+
completionId?: string;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* **本服务自己铸的 external 通知**(`POST /v1/sessions/:id/notify` 的 idle 半场)—— 停驻收件的入参型。类型上**不许**带 `completionId`:
|
|
292
|
+
* 那一位是引擎的一次完成的相关 id,本服务铸的通知没有它(编一个 = 凭空造一次「完成」)。
|
|
293
|
+
*/
|
|
294
|
+
export type ExternalNotificationParkInput = ParkedNotificationFields & {
|
|
295
|
+
task_type: "external";
|
|
296
|
+
completionId?: never;
|
|
297
|
+
};
|
|
298
|
+
/** external 通知 → 停驻收件条目(逐键取共享字段:运行期硬塞进来的别的键 —— 包括 `completionId` —— 一个都不过)。 */
|
|
299
|
+
export declare function externalNotificationInboxEntry(sessionId: string, owner: string | null, n: ExternalNotificationParkInput, enqueuedAt: number): WorkflowCompletionInboxEntry;
|
|
300
|
+
/**
|
|
301
|
+
* The durable half is the deployment's job: map a core `TaskNotificationPayload`
|
|
302
|
+
* (background subagent / background bash completion) onto an inbox entry, for the IDLE gap — core's in-process
|
|
303
|
+
* injection covers a LIVE harness; a completion that lands after the leg ended had NO durable path (idle no-show,
|
|
304
|
+
* lost across restart). Bounded + redacted HERE (the store carries only egress-safe bytes; summary/result are
|
|
305
|
+
* UNTRUSTED free text). `status` collapses onto the inbox's completed|failed column; the ORIGINAL status rides
|
|
306
|
+
* the payload extras and overrides on drain (killed/cancelled reach the shell verbatim). Workflow-type
|
|
307
|
+
* notifications are the CALLER's job to filter (they have their own durable chain — double-enqueueing here would
|
|
308
|
+
* re-open the poll-served double-push). External notifications enter through {@link externalNotificationInboxEntry}.
|
|
309
|
+
*/
|
|
310
|
+
export declare function taskNotificationInboxEntry(sessionId: string, owner: string | null, n: EngineNotificationParkInput, enqueuedAt: number,
|
|
285
311
|
/** lead-b (dual-ID audit): the PARENT run's durable taskId (the uuid the shell's footer rows
|
|
286
312
|
* key on) — rides the drained frame so a consumer can bind the a*-keyed child notification to its uuid-keyed
|
|
287
313
|
* parent row without a side lookup. */
|
|
@@ -341,4 +367,5 @@ export declare function resolveServedSession(p: {
|
|
|
341
367
|
}, getRun?: (taskId: string) => Promise<{
|
|
342
368
|
sessionId?: string | null;
|
|
343
369
|
} | undefined | null>): Promise<string | undefined>;
|
|
370
|
+
export {};
|
|
344
371
|
//# sourceMappingURL=workflow-completion-inbox.d.ts.map
|
|
@@ -315,6 +315,17 @@ export async function emitPendingWorkflowCompletions(inbox, sessionId, callerPri
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
+
export function externalNotificationInboxEntry(sessionId, owner, n, enqueuedAt) {
|
|
319
|
+
return taskNotificationInboxEntry(sessionId, owner, {
|
|
320
|
+
task_id: n.task_id,
|
|
321
|
+
task_type: "external",
|
|
322
|
+
status: n.status,
|
|
323
|
+
summary: n.summary,
|
|
324
|
+
...(n.result !== undefined ? { result: n.result } : {}),
|
|
325
|
+
...(n.seq !== undefined ? { seq: n.seq } : {}),
|
|
326
|
+
...(n.source !== undefined ? { source: n.source } : {}),
|
|
327
|
+
}, enqueuedAt);
|
|
328
|
+
}
|
|
318
329
|
export function taskNotificationInboxEntry(sessionId, owner, n, enqueuedAt, parentTaskId, priority) {
|
|
319
330
|
const cap = (s, max) => (s.length > max ? `${s.slice(0, max)}…[+${s.length - max} chars]` : s);
|
|
320
331
|
const extras = {
|
|
@@ -328,6 +339,8 @@ export function taskNotificationInboxEntry(sessionId, owner, n, enqueuedAt, pare
|
|
|
328
339
|
...(n.toolUseId ? { toolUseId: n.toolUseId } : {}),
|
|
329
340
|
...(n.status !== "completed" && n.status !== "failed" ? { status: n.status } : {}),
|
|
330
341
|
...(n.seq !== undefined ? { seq: n.seq } : {}),
|
|
342
|
+
...(n.completionId !== undefined ? { completionId: n.completionId } : {}),
|
|
343
|
+
...(n.source !== undefined ? { source: redactSecrets(n.source) } : {}),
|
|
331
344
|
...(n.lines !== undefined ? { lines: n.lines.map((l) => cap(redactSecrets(l), 1024)) } : {}),
|
|
332
345
|
...(n.stoppedBy !== undefined ? { stoppedBy: n.stoppedBy } : {}),
|
|
333
346
|
...(n.diagnostics !== undefined ? { diagnostics: cap(n.diagnostics, 4_000) } : {}),
|
|
@@ -291,39 +291,20 @@ export declare class JournalingWorkflowRunStore implements WorkflowRunStore {
|
|
|
291
291
|
* 的派生投影,写点必须与 fleet 行投影/notify journal 同一个(见 index 模块的文件头「单写者」段)。
|
|
292
292
|
* 可选:缺席 ⇒ 一位不维护(与 fleet 半场同姿势,行为逐字不变)。 */
|
|
293
293
|
agentSessionIndex?: WorkflowAgentSessionIndex | undefined);
|
|
294
|
-
/**
|
|
294
|
+
/** 本进程**亲眼看着落进索引**的指针:run → 它点名过的子会话。只用来跳过重复的 upsert,不是缓存(指针只增不删,记着的必在索引里)。
|
|
295
295
|
*
|
|
296
|
-
* 为什么需要:workflow 的进度写是每只 agent 状态变化一次,而 park 是罕见事件 ⇒
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
*
|
|
307
|
-
|
|
308
|
-
* 记不记 = 变更检测的正确性;摘不摘 = 表的有界性。**不**加「首次空集跳过」这类依赖进程内历史的特判。 */
|
|
309
|
-
private readonly indexedRows;
|
|
310
|
-
/**
|
|
311
|
-
* 写腿的**不变式守卫**(codex r1 [medium],验真后修):`indexedRows` 只保留一次**我们亲眼看着落地**
|
|
312
|
-
* 的写。持久化抛错时这条 run 的盘上状态未知(而 core 会吞掉这次失败、这条 run 往往再也不被写),
|
|
313
|
-
* 若把 memo 留着,那一条 `{runId → rows}` 就永久留在表里 —— 终态驱逐等不到它的终态写。
|
|
314
|
-
*
|
|
315
|
-
* ⚠️ 如实登记的残余:一条**最后一次写成功、随后被放弃**的 run(进程崩前没跑到终态)仍会在本进程的
|
|
316
|
-
* memo 里留一条空集。它与 fleet 活行登记簿同一量级(都随本世进程消亡),刻意**不**为它加清扫腿:
|
|
317
|
-
* 那是给一个不产生错误答案的形加机制。
|
|
318
|
-
*/
|
|
319
|
-
private forgetIndexMemoIfWriteOutcomeUnknown;
|
|
320
|
-
/** 索引的一次收敛(put/update 成功后调用)。
|
|
321
|
-
*
|
|
322
|
-
* **自吞错**:索引是观察面的派生物,它的故障绝不能把一次已成功的 run 持久化变成失败 —— 与
|
|
323
|
-
* `publishFleet` 的姿态同源。但自吞 ≠ 静默([ref]):留痕走**登记过的** fail-open tag
|
|
324
|
-
* `server.workflow-park-index.sync-failed`(P-DEBT;射程、后果与欠账的唯一属主 = 那条词表项的
|
|
325
|
-
* `note`,census 里有对应行);记录的 `parks[]` 读不出而不同步的那一臂另走 `server.workflow-park-index.parks-unreadable`(F 类,见下)。 */
|
|
326
|
-
private syncAgentSessionIndex;
|
|
296
|
+
* 为什么需要:workflow 的进度写是每只 agent 状态变化一次,而 park 是罕见事件 ⇒ 无条件 upsert 会给每一次写多打几发语句(SQL)
|
|
297
|
+
* 或多追加一行账本(file,无界增长)。判据只有一条:**这次记录点名的子会话,有没有还没亲眼看着落盘的** —— 没有就不写。
|
|
298
|
+
* 有界性:这条 run 不会再被本进程写的那一刻就摘表 —— 写到终态、CAS 输掉(owner 已不是本副本)、或这次写抛了(盘上状态未知)。 */
|
|
299
|
+
private readonly pointedSessions;
|
|
300
|
+
/** **指针先于记录**(索引模块头注的那条律):这次记录点名的子会话,指针在记录落盘之前 upsert。写不进 ⇒ 抛 —— 调用方的记录写
|
|
301
|
+
* 因此不发生,错误交给引擎 persist 的失败臂(与库写失败同一条路),不吞、不计 fail-open。
|
|
302
|
+
* 记录的 `parks[]` 读不出(在场却不是列表 / 条目形坏)⇒ 派生不出 ⇒ 不写指针,记录照写(读口据记录响亮拒);留痕走
|
|
303
|
+
* `server.workflow-park-index.parks-unreadable`(F 类)。`parks` 缺席不在这一臂:那是没有条目(读者答 `[]`),没有要写的指针。 */
|
|
304
|
+
private ensurePointersFor;
|
|
305
|
+
/** 一次记录写的整形:先指针、再记录;记录没落(`landed` 答否 / 写抛)或写到终态 ⇒ 摘表(见 {@link pointedSessions} 的有界性)。
|
|
306
|
+
* 终态判据走 fleet 半场那张**同一张**终态闭集表,不在这里手写第二份「哪些词算终态」。 */
|
|
307
|
+
private writeWithPointers;
|
|
327
308
|
/** Derive + publish the MF-Fleet workflow row from a WorkflowRun (doneCount/totalCount from agents, tokens from
|
|
328
309
|
* stats); a terminal workflow LEAVES the fleet (publish terminal then remove), a running one stays/updates. */
|
|
329
310
|
private publishFleet;
|
|
@@ -2,7 +2,7 @@ import { join } from "node:path";
|
|
|
2
2
|
import { AppendLog, ensureDir } from "@sema-agent/core";
|
|
3
3
|
import { buildFleetWorkflowRow } from "../fleet/fleet-bus.js";
|
|
4
4
|
import { isTerminalWorkflowRowStatus, seedTerminalWorkflowRow } from "../fleet/fleet-terminal-window.js";
|
|
5
|
-
import { buildParkSessionRows
|
|
5
|
+
import { buildParkSessionRows } from "./workflow-agent-session-index.js";
|
|
6
6
|
import { recordFailOpen } from "../observability/fail-open.js";
|
|
7
7
|
import { replayJsonlSkipping } from "../observability/corrupt-read-seat.js";
|
|
8
8
|
const SUMMARY_MAX = 500;
|
|
@@ -264,41 +264,39 @@ export class JournalingWorkflowRunStore {
|
|
|
264
264
|
this.fleetBus = fleetBus;
|
|
265
265
|
this.agentSessionIndex = agentSessionIndex;
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
async
|
|
269
|
-
try {
|
|
270
|
-
return await write();
|
|
271
|
-
}
|
|
272
|
-
catch (e) {
|
|
273
|
-
this.indexedRows.delete(id);
|
|
274
|
-
throw e;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
async syncAgentSessionIndex(id, run) {
|
|
267
|
+
pointedSessions = new Map();
|
|
268
|
+
async ensurePointersFor(id, run) {
|
|
278
269
|
const index = this.agentSessionIndex;
|
|
279
270
|
if (index === undefined)
|
|
280
271
|
return;
|
|
281
272
|
const rows = buildParkSessionRows(id, run);
|
|
282
273
|
if (rows === undefined) {
|
|
283
|
-
this.indexedRows.delete(id);
|
|
284
274
|
recordFailOpen("server.workflow-park-index.parks-unreadable", `runId=${id}`);
|
|
285
275
|
return;
|
|
286
276
|
}
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
277
|
+
const known = this.pointedSessions.get(id);
|
|
278
|
+
const fresh = rows.filter((r) => known?.has(r.sessionId) !== true);
|
|
279
|
+
if (fresh.length === 0)
|
|
280
|
+
return;
|
|
281
|
+
await index.ensurePointers(id, fresh);
|
|
282
|
+
const landed = known ?? new Set();
|
|
283
|
+
for (const r of fresh)
|
|
284
|
+
landed.add(r.sessionId);
|
|
285
|
+
this.pointedSessions.set(id, landed);
|
|
286
|
+
}
|
|
287
|
+
async writeWithPointers(id, run, write, landed) {
|
|
288
|
+
await this.ensurePointersFor(id, run);
|
|
289
|
+
let result;
|
|
290
|
+
try {
|
|
291
|
+
result = await write();
|
|
297
292
|
}
|
|
298
|
-
|
|
299
|
-
this.
|
|
300
|
-
|
|
301
|
-
|
|
293
|
+
catch (e) {
|
|
294
|
+
this.pointedSessions.delete(id);
|
|
295
|
+
throw e;
|
|
296
|
+
}
|
|
297
|
+
if (!landed(result) || isTerminalWorkflowRowStatus(run.status))
|
|
298
|
+
this.pointedSessions.delete(id);
|
|
299
|
+
return result;
|
|
302
300
|
}
|
|
303
301
|
publishFleet(id, run) {
|
|
304
302
|
if (!this.fleetBus)
|
|
@@ -322,16 +320,11 @@ export class JournalingWorkflowRunStore {
|
|
|
322
320
|
runId: id,
|
|
323
321
|
scope: run.scope,
|
|
324
322
|
});
|
|
325
|
-
await this.
|
|
326
|
-
await this.syncAgentSessionIndex(id, run);
|
|
323
|
+
await this.writeWithPointers(id, run, () => this.inner.put(id, run), () => true);
|
|
327
324
|
this.publishFleet(id, run);
|
|
328
325
|
}
|
|
329
326
|
async update(id, scope, run, expect) {
|
|
330
|
-
const ok = await this.
|
|
331
|
-
if (!ok)
|
|
332
|
-
this.indexedRows.delete(id);
|
|
333
|
-
if (ok)
|
|
334
|
-
await this.syncAgentSessionIndex(id, run);
|
|
327
|
+
const ok = await this.writeWithPointers(id, run, () => this.inner.update(id, scope, run, expect), (won) => won);
|
|
335
328
|
if (ok)
|
|
336
329
|
this.publishFleet(id, run);
|
|
337
330
|
return ok;
|