@sema-agent/core 7.59.0 → 7.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1169 -0
- package/README.md +2 -2
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-definition.js +12 -0
- package/dist/agents/agent-transcript-tool.d.ts +4 -3
- package/dist/agents/agent-transcript-tool.js +4 -2
- package/dist/agents/cascade.d.ts +61 -10
- package/dist/agents/cascade.js +60 -20
- package/dist/agents/child-model-seat.js +6 -3
- package/dist/agents/composition-allowance.d.ts +53 -0
- package/dist/agents/composition-allowance.js +49 -0
- package/dist/agents/composition-placement.d.ts +29 -0
- package/dist/agents/composition-placement.js +24 -0
- package/dist/agents/cumulative-stats.d.ts +4 -0
- package/dist/agents/cumulative-stats.js +3 -1
- package/dist/agents/inherited-tool-pool.d.ts +28 -1
- package/dist/agents/inherited-tool-pool.js +22 -0
- package/dist/agents/list-agents-tool.d.ts +1 -1
- package/dist/agents/peer-notice-route.d.ts +1 -1
- package/dist/agents/peer-notice-route.js +4 -3
- package/dist/agents/peer-notices.d.ts +4 -4
- package/dist/agents/peer-notices.js +8 -4
- package/dist/agents/peer-session-drain.d.ts +8 -1
- package/dist/agents/peer-session-drain.js +36 -7
- package/dist/agents/repair-loop.js +16 -6
- package/dist/agents/retain-ledger.d.ts +11 -1
- package/dist/agents/retain-ledger.js +16 -3
- package/dist/agents/roster-store.d.ts +2 -2
- package/dist/agents/roster-store.js +8 -3
- package/dist/agents/send-message-tool.d.ts +14 -27
- package/dist/agents/send-message-tool.js +47 -54
- package/dist/agents/subagent-completion-gate.d.ts +35 -0
- package/dist/agents/subagent-completion-gate.js +62 -0
- package/dist/agents/subagent-steps.d.ts +7 -6
- package/dist/agents/subagent.d.ts +52 -28
- package/dist/agents/subagent.js +276 -246
- package/dist/agents/suspend-guard.d.ts +9 -0
- package/dist/agents/suspend-guard.js +4 -0
- package/dist/agents/tool-filter.d.ts +1 -3
- package/dist/agents/tool-filter.js +4 -12
- package/dist/agents/verify.d.ts +41 -14
- package/dist/agents/verify.js +37 -27
- package/dist/bench/metrics.d.ts +3 -5
- package/dist/bench/metrics.js +0 -1
- package/dist/brain/anthropic.js +1 -0
- package/dist/brain/degrading.js +3 -1
- package/dist/brain/errors.d.ts +7 -1
- package/dist/brain/errors.js +6 -0
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +1 -0
- package/dist/brain/openai.js +1 -0
- package/dist/brain/provider-dialect.d.ts +10 -0
- package/dist/brain/provider-dialect.js +13 -2
- package/dist/brain/route-adjudicator.js +3 -1
- package/dist/brain/status-sink.d.ts +7 -1
- package/dist/brain/status-sink.js +6 -0
- package/dist/brain/stream-engine.d.ts +3 -0
- package/dist/brain/stream-engine.js +4 -0
- package/dist/brain/timeout.d.ts +3 -1
- package/dist/brain/timeout.js +18 -5
- package/dist/core/a2a.d.ts +15 -5
- package/dist/core/a2a.js +34 -19
- package/dist/core/agent-definition.d.ts +20 -0
- package/dist/core/agent-state.d.ts +1 -1
- package/dist/core/allow-entry.d.ts +61 -23
- package/dist/core/allow-entry.js +134 -39
- package/dist/core/artifact-host.d.ts +0 -2
- package/dist/core/artifact-host.js +0 -1
- package/dist/core/ask-origin.d.ts +79 -0
- package/dist/core/ask-origin.js +76 -0
- package/dist/core/ask-question.d.ts +19 -13
- package/dist/core/ask-question.js +8 -2
- package/dist/core/auto-compaction.d.ts +2 -0
- package/dist/core/auto-compaction.js +2 -1
- package/dist/core/auto-mode-defaults.d.ts +8 -0
- package/dist/core/auto-mode-defaults.js +1 -0
- package/dist/core/auto-mode-rebuild.d.ts +2 -1
- package/dist/core/auto-mode.d.ts +39 -4
- package/dist/core/auto-mode.js +66 -17
- package/dist/core/background-agent-store.d.ts +17 -6
- package/dist/core/background-agent-store.js +15 -13
- package/dist/core/background-shell.d.ts +12 -1
- package/dist/core/background-shell.js +12 -0
- package/dist/core/checkpoint-requirements.d.ts +24 -3
- package/dist/core/checkpoint-requirements.js +9 -1
- package/dist/core/checkpoint-store.d.ts +86 -32
- package/dist/core/checkpoint-store.js +10 -5
- package/dist/core/child-clamp-seats.d.ts +3 -2
- package/dist/core/child-clamp-seats.js +4 -3
- package/dist/core/closest-name.d.ts +13 -0
- package/dist/core/closest-name.js +35 -0
- package/dist/core/compliance.d.ts +1 -1
- package/dist/core/context-settings.js +3 -5
- package/dist/core/credential-echo.d.ts +52 -0
- package/dist/core/credential-echo.js +65 -0
- package/dist/core/credential-vocabulary.d.ts +13 -3
- package/dist/core/credential-vocabulary.js +12 -4
- package/dist/core/cross-boundary-taint.d.ts +5 -6
- package/dist/core/decision-receipt.d.ts +14 -1
- package/dist/core/decision-receipt.js +6 -3
- package/dist/core/delegation-frames.d.ts +13 -9
- package/dist/core/effective-path-target.js +2 -3
- package/dist/core/engine-attestation.d.ts +11 -1
- package/dist/core/engine-attestation.js +2 -0
- package/dist/core/engine-notice.d.ts +106 -32
- package/dist/core/file-history-retention.d.ts +8 -0
- package/dist/core/file-history-retention.js +14 -11
- package/dist/core/file-history-store.d.ts +31 -1
- package/dist/core/file-history-store.js +31 -2
- package/dist/core/frame-settlement.d.ts +15 -0
- package/dist/core/frame-settlement.js +10 -1
- package/dist/core/fs-write-gate-policy.d.ts +3 -3
- package/dist/core/fs-write-gate-policy.js +8 -7
- package/dist/core/gate-fold.js +9 -6
- package/dist/core/gate-lanes.js +46 -12
- package/dist/core/gate-outcome.d.ts +40 -1
- package/dist/core/gate-outcome.js +10 -0
- package/dist/core/git-worktree-env.d.ts +7 -3
- package/dist/core/git-worktree-env.js +16 -13
- package/dist/core/governance-codes.d.ts +19 -3
- package/dist/core/governance-codes.js +27 -3
- package/dist/core/hands-band-screen.js +0 -1
- package/dist/core/hands-band.d.ts +0 -3
- package/dist/core/hooks.d.ts +51 -60
- package/dist/core/hooks.js +131 -78
- package/dist/core/host-floor.js +3 -5
- package/dist/core/image-admission.d.ts +145 -52
- package/dist/core/image-admission.js +202 -47
- package/dist/core/image-downsample.d.ts +36 -69
- package/dist/core/image-downsample.js +111 -73
- package/dist/core/input-author.d.ts +36 -0
- package/dist/core/input-author.js +39 -0
- package/dist/core/integer-option.d.ts +21 -0
- package/dist/core/integer-option.js +13 -0
- package/dist/core/leg-identity.d.ts +62 -0
- package/dist/core/leg-identity.js +18 -0
- package/dist/core/locked-config.d.ts +55 -3
- package/dist/core/locked-config.js +84 -51
- package/dist/core/lsp.d.ts +5 -3
- package/dist/core/lsp.js +3 -2
- package/dist/core/mailbox-store.d.ts +85 -10
- package/dist/core/mailbox-store.js +31 -10
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-call-meta.js +9 -10
- package/dist/core/mcp-connection-pool.d.ts +6 -20
- package/dist/core/mcp-connection-pool.js +10 -28
- package/dist/core/mcp-failure.d.ts +83 -16
- package/dist/core/mcp-failure.js +67 -30
- package/dist/core/mcp-host-seat.d.ts +131 -0
- package/dist/core/mcp-host-seat.js +305 -0
- package/dist/core/mcp-probe.d.ts +7 -2
- package/dist/core/mcp-probe.js +9 -4
- package/dist/core/mcp-server-link.d.ts +18 -6
- package/dist/core/mcp-server-link.js +19 -4
- package/dist/core/mcp-server-spec.d.ts +39 -9
- package/dist/core/mcp-server-spec.js +55 -21
- package/dist/core/mcp-session-end.d.ts +1 -2
- package/dist/core/mcp-session-end.js +1 -1
- package/dist/core/mcp.d.ts +23 -55
- package/dist/core/mcp.js +172 -156
- package/dist/core/media-byte-cap.d.ts +21 -46
- package/dist/core/media-byte-cap.js +55 -55
- package/dist/core/member-group.d.ts +7 -0
- package/dist/core/member-group.js +35 -0
- package/dist/core/memory-admission.d.ts +23 -6
- package/dist/core/memory-admission.js +19 -9
- package/dist/core/memory-engine/consolidation.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.js +7 -1
- package/dist/core/memory-engine/content-origin.d.ts +13 -0
- package/dist/core/memory-engine/content-origin.js +21 -3
- package/dist/core/memory-engine/dual-root.d.ts +31 -0
- package/dist/core/memory-engine/dual-root.js +59 -11
- package/dist/core/memory-engine/engine.js +27 -24
- package/dist/core/memory-engine/file-backend.d.ts +13 -0
- package/dist/core/memory-engine/file-backend.js +35 -15
- package/dist/core/memory-engine/index.d.ts +2 -1
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/layout.d.ts +3 -0
- package/dist/core/memory-engine/layout.js +13 -3
- package/dist/core/memory-engine/memory-deployment.d.ts +110 -0
- package/dist/core/memory-engine/memory-deployment.js +182 -0
- package/dist/core/memory-engine/scope-contract.d.ts +13 -3
- package/dist/core/memory-engine/scope-contract.js +2 -2
- package/dist/core/memory-engine/sync-client.d.ts +68 -13
- package/dist/core/memory-engine/sync-client.js +147 -18
- package/dist/core/memory-engine/sync-report.d.ts +106 -0
- package/dist/core/memory-engine/sync-report.js +119 -0
- package/dist/core/memory-engine/sync.d.ts +13 -3
- package/dist/core/mode-policy.d.ts +15 -7
- package/dist/core/mode-policy.js +18 -6
- package/dist/core/model-receipt.d.ts +39 -0
- package/dist/core/model-receipt.js +139 -0
- package/dist/core/mods/agent-stations.d.ts +100 -0
- package/dist/core/mods/agent-stations.js +154 -0
- package/dist/core/mods/dollar.d.ts +62 -0
- package/dist/core/mods/extension-call.d.ts +15 -1
- package/dist/core/mods/extension-call.js +7 -2
- package/dist/core/mods/kernel/dispatch.d.ts +9 -4
- package/dist/core/mods/kernel/dispatch.js +8 -8
- package/dist/core/mods/kernel/events.d.ts +13 -4
- package/dist/core/mods/kernel/events.js +14 -10
- package/dist/core/mods/kernel/receive.d.ts +5 -0
- package/dist/core/mods/kernel/receive.js +10 -0
- package/dist/core/mods/kernel/registration.d.ts +3 -0
- package/dist/core/mods/kernel/registration.js +5 -0
- package/dist/core/mods/kernel/site-rules.d.ts +6 -3
- package/dist/core/mods/kernel/site-rules.js +10 -2
- package/dist/core/mods/lifecycle-stations.d.ts +41 -0
- package/dist/core/mods/lifecycle-stations.js +35 -0
- package/dist/core/mods/session-append.d.ts +115 -0
- package/dist/core/mods/session-append.js +311 -0
- package/dist/core/mods/session-compact.d.ts +48 -0
- package/dist/core/mods/session-compact.js +194 -0
- package/dist/core/mods/session-receive.d.ts +93 -0
- package/dist/core/mods/session-receive.js +141 -0
- package/dist/core/mods/session-send.d.ts +72 -0
- package/dist/core/mods/session-send.js +88 -0
- package/dist/core/mods/stations.d.ts +89 -75
- package/dist/core/mods/stations.js +57 -53
- package/dist/core/mods/tool-call.d.ts +12 -4
- package/dist/core/mods/tool-call.js +32 -16
- package/dist/core/mounted-mcp.d.ts +5 -0
- package/dist/core/mounted-mcp.js +2 -2
- package/dist/core/namespaced-rule-name.d.ts +7 -1
- package/dist/core/namespaced-rule-name.js +13 -2
- package/dist/core/oracle-isolation.js +1 -1
- package/dist/core/output-style.js +3 -4
- package/dist/core/own-property-receipt.d.ts +62 -0
- package/dist/core/own-property-receipt.js +43 -0
- package/dist/core/park-selfcheck.js +12 -10
- package/dist/core/path-identity.d.ts +11 -0
- package/dist/core/path-identity.js +4 -0
- package/dist/core/path-rule-binding.d.ts +3 -1
- package/dist/core/path-rule-binding.js +3 -1
- package/dist/core/peer-seat.d.ts +66 -11
- package/dist/core/peer-seat.js +199 -42
- package/dist/core/permission-rule-consent.d.ts +21 -26
- package/dist/core/permission-rule-consent.js +22 -3
- package/dist/core/permission-rule-model.d.ts +38 -13
- package/dist/core/permission-rule-model.js +54 -16
- package/dist/core/permission-rule-org.d.ts +1 -1
- package/dist/core/permission-rule-provider.js +4 -1
- package/dist/core/permission-rules.d.ts +4 -0
- package/dist/core/permission-rules.js +11 -16
- package/dist/core/protocol-http-auth.d.ts +14 -2
- package/dist/core/protocol-http-auth.js +16 -7
- package/dist/core/read-face-seats.d.ts +7 -5
- package/dist/core/read-face-seats.js +4 -1
- package/dist/core/redaction-marks.d.ts +4 -3
- package/dist/core/redaction-marks.js +2 -2
- package/dist/core/remote-env.d.ts +218 -122
- package/dist/core/remote-env.js +133 -14
- package/dist/core/retention-policy.d.ts +24 -23
- package/dist/core/retention-policy.js +36 -2
- package/dist/core/retention.d.ts +4 -1
- package/dist/core/retention.js +37 -12
- package/dist/core/retired-keys.d.ts +8 -3
- package/dist/core/retired-keys.js +4 -1
- package/dist/core/rewrite-rejudge.d.ts +12 -5
- package/dist/core/rewrite-rejudge.js +9 -5
- package/dist/core/roles.d.ts +37 -3
- package/dist/core/roles.js +126 -78
- package/dist/core/row-admission.d.ts +10 -0
- package/dist/core/row-admission.js +5 -0
- package/dist/core/rule-owner.d.ts +3 -0
- package/dist/core/runner/advisor-instructions.d.ts +2 -1
- package/dist/core/runner/advisor-instructions.js +2 -1
- package/dist/core/runner/announce-once-ledger.d.ts +4 -4
- package/dist/core/runner/assemble-result.d.ts +13 -8
- package/dist/core/runner/assemble-result.js +12 -8
- package/dist/core/runner/call-hook-stations.d.ts +17 -10
- package/dist/core/runner/call-hook-stations.js +21 -10
- package/dist/core/runner/caller-roster.d.ts +12 -9
- package/dist/core/runner/caller-roster.js +5 -2
- package/dist/core/runner/checkpoint-scope.d.ts +16 -1
- package/dist/core/runner/checkpoint-scope.js +21 -0
- package/dist/core/runner/child-tree.d.ts +7 -8
- package/dist/core/runner/child-tree.js +6 -6
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +39 -8
- package/dist/core/runner/compact-session.js +14 -2
- package/dist/core/runner/compaction-call-options.d.ts +1 -1
- package/dist/core/runner/compaction-restate.d.ts +2 -2
- package/dist/core/runner/compaction-restate.js +4 -3
- package/dist/core/runner/construction-doors.d.ts +2 -2
- package/dist/core/runner/construction-doors.js +7 -2
- package/dist/core/runner/contracts.d.ts +158 -65
- package/dist/core/runner/cross-boundary-lane.d.ts +4 -6
- package/dist/core/runner/cross-boundary-lane.js +11 -2
- package/dist/core/runner/decide-continuation.d.ts +4 -2
- package/dist/core/runner/decide-continuation.js +7 -4
- package/dist/core/runner/denial-limit-arms.d.ts +15 -21
- package/dist/core/runner/denial-limit-arms.js +17 -10
- package/dist/core/runner/env-capability-census.d.ts +15 -20
- package/dist/core/runner/env-capability-census.js +25 -34
- package/dist/core/runner/expire-settle.d.ts +44 -0
- package/dist/core/runner/expire-settle.js +55 -0
- package/dist/core/runner/file-history-request.d.ts +2 -2
- package/dist/core/runner/file-history-request.js +0 -8
- package/dist/core/runner/gate-exit.d.ts +75 -7
- package/dist/core/runner/gate-exit.js +20 -1
- package/dist/core/runner/git-status-frame.d.ts +5 -2
- package/dist/core/runner/git-status-frame.js +4 -4
- package/dist/core/runner/halt-attribution.d.ts +2 -1
- package/dist/core/runner/halt-attribution.js +2 -1
- package/dist/core/runner/image.d.ts +7 -2
- package/dist/core/runner/image.js +14 -8
- package/dist/core/runner/inline-image.d.ts +10 -8
- package/dist/core/runner/inline-image.js +11 -9
- package/dist/core/runner/local-claims.d.ts +17 -0
- package/dist/core/runner/local-claims.js +18 -0
- package/dist/core/runner/media-removed-seat.d.ts +46 -0
- package/dist/core/runner/media-removed-seat.js +88 -0
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/park-commit.d.ts +2 -2
- package/dist/core/runner/permission-rule-lanes.d.ts +5 -1
- package/dist/core/runner/permission-rule-lanes.js +29 -10
- package/dist/core/runner/person-path-rows.js +1 -1
- package/dist/core/runner/placement-fence.d.ts +26 -0
- package/dist/core/runner/placement-fence.js +38 -0
- package/dist/core/runner/prepare-ask-lane.d.ts +6 -12
- package/dist/core/runner/prepare-ask-lane.js +4 -4
- package/dist/core/runner/prepare-boundary-parks.d.ts +6 -3
- package/dist/core/runner/prepare-boundary-parks.js +4 -4
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +6 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +5 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -1
- package/dist/core/runner/prepare-config-doors.js +30 -26
- package/dist/core/runner/prepare-context-lane.d.ts +6 -2
- package/dist/core/runner/prepare-context-lane.js +13 -13
- package/dist/core/runner/prepare-delegation-surface.d.ts +13 -11
- package/dist/core/runner/prepare-delegation-surface.js +7 -8
- package/dist/core/runner/prepare-execution-env.d.ts +5 -2
- package/dist/core/runner/prepare-execution-env.js +7 -4
- package/dist/core/runner/prepare-file-history.d.ts +10 -12
- package/dist/core/runner/prepare-file-history.js +3 -12
- package/dist/core/runner/prepare-gate-stations.d.ts +23 -17
- package/dist/core/runner/prepare-gate-stations.js +10 -7
- package/dist/core/runner/prepare-hands-readface.d.ts +8 -6
- package/dist/core/runner/prepare-hands-readface.js +19 -11
- package/dist/core/runner/prepare-inherited-gate.d.ts +11 -4
- package/dist/core/runner/prepare-inherited-gate.js +12 -5
- package/dist/core/runner/prepare-lsp.d.ts +3 -0
- package/dist/core/runner/prepare-lsp.js +2 -2
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +2 -2
- package/dist/core/runner/prepare-memory.js +2 -2
- package/dist/core/runner/prepare-park-ask.d.ts +8 -7
- package/dist/core/runner/prepare-park-ask.js +6 -12
- package/dist/core/runner/prepare-policy-chain.d.ts +15 -25
- package/dist/core/runner/prepare-policy-chain.js +131 -128
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +8 -5
- package/dist/core/runner/prepare-prompt-inputs.d.ts +4 -0
- package/dist/core/runner/prepare-prompt-inputs.js +4 -2
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
- package/dist/core/runner/prepare-protocol-tools.js +9 -2
- package/dist/core/runner/prepare-question-face.d.ts +6 -4
- package/dist/core/runner/prepare-question-face.js +2 -2
- package/dist/core/runner/prepare-run-refs.d.ts +3 -0
- package/dist/core/runner/prepare-run-refs.js +2 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +11 -9
- package/dist/core/runner/prepare-suspend-saga.js +21 -13
- package/dist/core/runner/prepare-task.d.ts +1 -1
- package/dist/core/runner/prepare-task.js +84 -42
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +6 -0
- package/dist/core/runner/prepare-tool-disclosure-mount.js +3 -1
- package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
- package/dist/core/runner/prepare-turn-wiring.js +7 -2
- package/dist/core/runner/prepare-wiring-manifest.d.ts +7 -3
- package/dist/core/runner/prepare-wiring-manifest.js +34 -19
- package/dist/core/runner/prepare-workspace-restore.d.ts +5 -0
- package/dist/core/runner/prepare-workspace-restore.js +12 -8
- package/dist/core/runner/read-root-grant.d.ts +1 -1
- package/dist/core/runner/read-root-grant.js +2 -1
- package/dist/core/runner/resume-admission.d.ts +5 -3
- package/dist/core/runner/resume-admission.js +17 -3
- package/dist/core/runner/resume-apply.js +3 -1
- package/dist/core/runner/resume-checkpoint-screen.js +4 -4
- package/dist/core/runner/resume-claim.d.ts +8 -3
- package/dist/core/runner/resume-claim.js +28 -12
- package/dist/core/runner/resume-internals-and-config.d.ts +2 -2
- package/dist/core/runner/resume-internals-and-config.js +10 -1
- package/dist/core/runner/resume-preflight.d.ts +3 -2
- package/dist/core/runner/resume-preflight.js +13 -26
- package/dist/core/runner/retired-runner-deps.js +6 -1
- package/dist/core/runner/run-attachment-seats.js +3 -3
- package/dist/core/runner/run-brain-sinks.js +1 -0
- package/dist/core/runner/run-git-lane.d.ts +3 -1
- package/dist/core/runner/run-git-lane.js +3 -2
- package/dist/core/runner/run-harness-handlers.d.ts +3 -1
- package/dist/core/runner/run-harness-handlers.js +5 -3
- package/dist/core/runner/run-identity-wiring.d.ts +2 -2
- package/dist/core/runner/run-identity-wiring.js +15 -6
- package/dist/core/runner/run-leg.d.ts +3 -3
- package/dist/core/runner/run-leg.js +65 -56
- package/dist/core/runner/run-notification-lane.d.ts +3 -1
- package/dist/core/runner/run-notification-lane.js +36 -12
- package/dist/core/runner/run-recovery-lanes.js +3 -2
- package/dist/core/runner/run-settle-and-teardown.js +14 -8
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
- package/dist/core/runner/run-stop-and-final-verify.js +12 -4
- package/dist/core/runner/run-telemetry-and-budget-seats.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.js +26 -17
- package/dist/core/runner/run-turn-boundary.js +37 -19
- package/dist/core/runner/runtask.d.ts +25 -7
- package/dist/core/runner/runtask.js +46 -22
- package/dist/core/runner/session-rule-policy.d.ts +1 -1
- package/dist/core/runner/session-rule-policy.js +6 -1
- package/dist/core/runner/shell-env-withheld.d.ts +1 -1
- package/dist/core/runner/skills-seat.js +2 -2
- package/dist/core/runner/stream-halt-verbs.d.ts +1 -14
- package/dist/core/runner/stream-halt-verbs.js +4 -3
- package/dist/core/runner/stream-reap.d.ts +7 -6
- package/dist/core/runner/stream-reap.js +13 -16
- package/dist/core/runner/stream-settle-backstop.d.ts +3 -2
- package/dist/core/runner/stream-settle-backstop.js +5 -3
- package/dist/core/runner/stream-steer-verb.d.ts +5 -2
- package/dist/core/runner/stream-steer-verb.js +8 -7
- package/dist/core/runner/sub-agent-deny-lists.js +10 -7
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/terminal-account.d.ts +11 -1
- package/dist/core/runner/terminal-account.js +20 -0
- package/dist/core/runner/terminal-projection.d.ts +8 -2
- package/dist/core/runner/terminal-projection.js +2 -2
- package/dist/core/runner/tool-disclosure.d.ts +3 -0
- package/dist/core/runner/tool-disclosure.js +5 -4
- package/dist/core/runner/tool-end-body.d.ts +3 -3
- package/dist/core/runner/tool-end-body.js +1 -1
- package/dist/core/runner/tool-face-overlay.d.ts +1 -1
- package/dist/core/runner/tool-face-overlay.js +26 -19
- package/dist/core/runner/tool-output-projection.d.ts +3 -3
- package/dist/core/runner/tool-output-projection.js +7 -6
- package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
- package/dist/core/runner/tool-result-media-seat.js +17 -1
- package/dist/core/runner/tool-table-view.d.ts +56 -0
- package/dist/core/runner/tool-table-view.js +51 -0
- package/dist/core/runner/turn-attachments.d.ts +6 -7
- package/dist/core/runner/turn-attachments.js +4 -17
- package/dist/core/runner/void-verifier-pause.d.ts +33 -0
- package/dist/core/runner/void-verifier-pause.js +41 -0
- package/dist/core/runner-deps.d.ts +55 -43
- package/dist/core/secret-env.d.ts +14 -13
- package/dist/core/secret-env.js +8 -9
- package/dist/core/session-log-transfer.js +9 -10
- package/dist/core/session-policy-store.d.ts +10 -3
- package/dist/core/session-policy-store.js +21 -3
- package/dist/core/session-reconcile.d.ts +3 -2
- package/dist/core/session-reconcile.js +7 -4
- package/dist/core/session-store.d.ts +5 -2
- package/dist/core/session-store.js +53 -16
- package/dist/core/session.d.ts +2 -1
- package/dist/core/shell-confinement.d.ts +37 -0
- package/dist/core/shell-confinement.js +56 -0
- package/dist/core/skill-grant.d.ts +9 -0
- package/dist/core/skill-grant.js +18 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +2 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +15 -2
- package/dist/core/store-contracts/file-history-store-contract.d.ts +5 -2
- package/dist/core/store-contracts/file-history-store-contract.js +25 -1
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +12 -5
- package/dist/core/store-contracts/mailbox-store-contract.js +156 -9
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +67 -0
- package/dist/core/stub-env.d.ts +5 -5
- package/dist/core/stub-env.js +11 -1
- package/dist/core/swappable-deps.d.ts +17 -43
- package/dist/core/swappable-deps.js +15 -5
- package/dist/core/synthetic-read-verdict.d.ts +1 -1
- package/dist/core/task-event.d.ts +35 -10
- package/dist/core/task-limits.d.ts +5 -0
- package/dist/core/task-notification.d.ts +172 -12
- package/dist/core/task-notification.js +209 -12
- package/dist/core/task-registry-agent.d.ts +23 -55
- package/dist/core/task-registry-agent.js +41 -56
- package/dist/core/task-registry-monitor.d.ts +8 -1
- package/dist/core/task-registry-monitor.js +43 -61
- package/dist/core/task-registry-shared.d.ts +52 -114
- package/dist/core/task-registry-shared.js +24 -48
- package/dist/core/task-registry-workflow.js +5 -22
- package/dist/core/task-registry.d.ts +64 -90
- package/dist/core/task-registry.js +73 -119
- package/dist/core/task-result.d.ts +27 -19
- package/dist/core/task-spec-members.d.ts +39 -0
- package/dist/core/task-spec-members.js +92 -0
- package/dist/core/task-spec.d.ts +13 -16
- package/dist/core/task-stream.d.ts +1 -1
- package/dist/core/task-tool-shape.d.ts +7 -57
- package/dist/core/task-tool-shape.js +7 -66
- package/dist/core/terminal-cause.d.ts +30 -0
- package/dist/core/terminal-cause.js +1 -0
- package/dist/core/tool-catalog-entries.js +3 -6
- package/dist/core/tool-check-reading.js +16 -10
- package/dist/core/tool-conformance.js +1 -2
- package/dist/core/tool-errors.d.ts +6 -3
- package/dist/core/tool-errors.js +2 -0
- package/dist/core/tool-face-reader.d.ts +7 -6
- package/dist/core/tool-face-reader.js +6 -4
- package/dist/core/tool-face.d.ts +2 -3
- package/dist/core/tool-name-aliases.d.ts +23 -28
- package/dist/core/tool-name-aliases.js +63 -7
- package/dist/core/tool-name-readings.d.ts +14 -3
- package/dist/core/tool-name-readings.js +2 -0
- package/dist/core/tool-policy.d.ts +113 -22
- package/dist/core/tool-policy.js +85 -15
- package/dist/core/tool-registry.d.ts +5 -5
- package/dist/core/tool-registry.js +2 -2
- package/dist/core/tool-result-store.d.ts +111 -5
- package/dist/core/tool-result-store.js +52 -12
- package/dist/core/tool-spec.d.ts +39 -10
- package/dist/core/trace.d.ts +18 -2
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-text.js +1 -1
- package/dist/core/user-attachment.d.ts +10 -5
- package/dist/core/user-attachment.js +40 -27
- package/dist/core/workflow-journal-store.d.ts +1 -1
- package/dist/core/workflow-run-store.d.ts +2 -0
- package/dist/core/workflow-run-store.js +6 -5
- package/dist/core/workflow-settled-run.d.ts +5 -0
- package/dist/core/workflow-settled-run.js +7 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +37 -7
- package/dist/engine/execution-env/node-execution-env.js +224 -21
- package/dist/engine/harness/agent-harness.d.ts +66 -19
- package/dist/engine/harness/agent-harness.js +98 -27
- package/dist/engine/harness/messages.d.ts +4 -3
- package/dist/engine/harness/messages.js +2 -2
- package/dist/engine/harness/types.d.ts +151 -34
- package/dist/engine/llm/media-removed.d.ts +14 -0
- package/dist/engine/llm/media-removed.js +9 -0
- package/dist/engine/llm/rejected-images.d.ts +35 -25
- package/dist/engine/llm/rejected-images.js +59 -10
- package/dist/engine/llm/types.d.ts +24 -3
- package/dist/engine/llm/types.js +7 -3
- package/dist/engine/loop/agent-loop.d.ts +18 -13
- package/dist/engine/loop/agent-loop.js +173 -32
- package/dist/engine/loop/types.d.ts +21 -5
- package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
- package/dist/engine/lsp/node-lsp-manager.js +32 -13
- package/dist/engine/session/import-validate.js +7 -0
- package/dist/fixtures/index.d.ts +7 -5
- package/dist/fixtures/index.js +5 -3
- package/dist/index.d.ts +41 -23
- package/dist/index.js +29 -16
- package/dist/internal/harness-types.d.ts +3 -1
- package/dist/internal/llm.d.ts +2 -1
- package/dist/internal/llm.js +1 -0
- package/dist/orchestration/goal.d.ts +6 -2
- package/dist/orchestration/goal.js +6 -3
- package/dist/orchestration/run-workflow-tool.d.ts +20 -20
- package/dist/orchestration/run-workflow-tool.js +63 -56
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-governance.js +2 -1
- package/dist/orchestration/workflow-types.d.ts +2 -2
- package/dist/orchestration/workflow.d.ts +8 -0
- package/dist/orchestration/workflow.js +33 -9
- package/dist/prompts/default.d.ts +1 -10
- package/dist/prompts/default.js +0 -2
- package/dist/stores/file/background-agent-store.d.ts +1 -1
- package/dist/stores/file/background-agent-store.js +19 -14
- package/dist/stores/file/checkpoint-store.d.ts +127 -2
- package/dist/stores/file/checkpoint-store.js +24 -16
- package/dist/stores/file/file-history-store.d.ts +1 -1
- package/dist/stores/file/file-history-store.js +4 -1
- package/dist/stores/file/index.d.ts +9 -6
- package/dist/stores/file/index.js +33 -9
- package/dist/stores/file/ledger-tuning.d.ts +23 -0
- package/dist/stores/file/ledger-tuning.js +21 -0
- package/dist/stores/file/mailbox-store.d.ts +1 -1
- package/dist/stores/file/mailbox-store.js +43 -21
- package/dist/stores/file/memory-store.d.ts +1 -1
- package/dist/stores/file/memory-store.js +4 -1
- package/dist/stores/file/permission-rule-adopt.js +24 -21
- package/dist/stores/file/permission-rule-store.js +6 -3
- package/dist/stores/file/session-policy-store.d.ts +1 -1
- package/dist/stores/file/session-policy-store.js +4 -1
- package/dist/stores/file/session-store.d.ts +17 -4
- package/dist/stores/file/session-store.js +22 -19
- package/dist/stores/file/shared-ledger.d.ts +26 -0
- package/dist/stores/file/shared-ledger.js +38 -9
- package/dist/stores/file/tool-result-store.d.ts +31 -2
- package/dist/stores/file/tool-result-store.js +129 -7
- package/dist/stores/file/usage-window-store.d.ts +1 -1
- package/dist/stores/file/usage-window-store.js +4 -1
- package/dist/stores/file/workflow-journal-store.d.ts +1 -13
- package/dist/stores/file/workflow-journal-store.js +4 -18
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/stores/file/workflow-run-store.js +15 -10
- package/dist/tools/fs/containment-face.d.ts +5 -0
- package/dist/tools/fs/dead-cwd.d.ts +5 -5
- package/dist/tools/fs/dead-cwd.js +4 -11
- package/dist/tools/fs/encoding.d.ts +13 -4
- package/dist/tools/fs/encoding.js +17 -2
- package/dist/tools/fs/fs-bash-background-text.d.ts +13 -0
- package/dist/tools/fs/fs-bash-background-text.js +7 -0
- package/dist/tools/fs/fs-bash.d.ts +11 -22
- package/dist/tools/fs/fs-bash.js +58 -154
- package/dist/tools/fs/fs-pdf.d.ts +2 -2
- package/dist/tools/fs/fs-pdf.js +34 -27
- package/dist/tools/fs/fs-read.d.ts +5 -4
- package/dist/tools/fs/fs-read.js +35 -18
- package/dist/tools/fs/fs-search-tools.js +4 -1
- package/dist/tools/fs/fs-shared.d.ts +39 -16
- package/dist/tools/fs/fs-shared.js +25 -6
- package/dist/tools/fs/fs-write.js +5 -5
- package/dist/tools/fs/index.d.ts +15 -9
- package/dist/tools/fs/index.js +12 -18
- package/dist/tools/fs/pdf.d.ts +4 -4
- package/dist/tools/fs/pdf.js +6 -6
- package/dist/tools/fs/read-deny-home.js +8 -1
- package/dist/tools/fs/read-deny.d.ts +26 -2
- package/dist/tools/fs/read-deny.js +9 -2
- package/dist/tools/fs/read-floor.d.ts +57 -6
- package/dist/tools/fs/read-floor.js +241 -2
- package/dist/tools/fs/removal-targets.d.ts +9 -4
- package/dist/tools/fs/removal-targets.js +17 -9
- package/dist/tools/fs/search.d.ts +6 -5
- package/dist/tools/fs/search.js +10 -10
- package/dist/tools/fs/shell-read-establish.js +3 -1
- package/dist/tools/fs/shell-read-identity.d.ts +3 -1
- package/dist/tools/fs/shell-read-identity.js +4 -2
- package/dist/tools/fs/shell-read-judge.d.ts +7 -1
- package/dist/tools/fs/shell-read-judge.js +1 -1
- package/dist/tools/monitor.d.ts +12 -10
- package/dist/tools/monitor.js +22 -13
- package/dist/tools/scheduler-tools.js +42 -4
- package/dist/tools/web.d.ts +0 -10
- package/dist/tools/web.js +1 -4
- package/dist/tools/worktree.d.ts +5 -1
- package/dist/tools/worktree.js +20 -17
- package/package.json +8 -3
- package/test/export-surface.snapshot.json +166 -30
- package/wire-changes/core-stores-sql@7.60.0.json +30 -0
- package/wire-changes/core-stores-sql@7.61.0.json +480 -0
- package/wire-changes/core@7.60.0.json +3274 -0
- package/wire-changes/core@7.61.0.json +4405 -0
- package/wire-changes/mods-kernel@7.60.0.json +62 -0
- package/wire-changes/mods-kernel@7.61.0.json +65 -0
- package/wire-changes/primitives@7.60.0.json +30 -0
- package/wire-changes/primitives@7.61.0.json +30 -0
- package/dist/core/runner/image-removed-seat.d.ts +0 -12
- package/dist/core/runner/image-removed-seat.js +0 -19
|
@@ -4,7 +4,7 @@ import { egressText } from "./untrusted-egress.js";
|
|
|
4
4
|
import { PEER_MESSAGE_NOTICE } from "../agents/peer-admission.js";
|
|
5
5
|
import { buildCrossSessionEnvelope, CROSS_PRINCIPAL_MESSAGE_NOTICE, CROSS_SESSION_MESSAGE_NOTICE, neutralizePeerBody } from "../agents/cross-session-envelope.js";
|
|
6
6
|
export const TASK_NOTIFICATION_TERMINAL_STATUSES = Object.freeze(["completed", "failed", "killed", "cancelled"]);
|
|
7
|
-
export const NOTIFICATION_INJECTION_OUTCOMES = Object.freeze(["queued", "parked", "parked_durably", "dropped_duplicate"]);
|
|
7
|
+
export const NOTIFICATION_INJECTION_OUTCOMES = Object.freeze(["queued", "parked", "parked_durably", "dropped_duplicate", "refused"]);
|
|
8
8
|
export function isNotificationInjectionOutcome(value) {
|
|
9
9
|
return typeof value === "string" && NOTIFICATION_INJECTION_OUTCOMES.includes(value);
|
|
10
10
|
}
|
|
@@ -95,6 +95,8 @@ export function renderCrossSessionNoticeLine(notice) {
|
|
|
95
95
|
}
|
|
96
96
|
export const RESUPPLIED_FRAME_PREAMBLE = "[Re-supplied] You were shown this message once before; the compaction that replaced older context with a summary did not keep it, so the engine is handing it over again. It is the SAME message, not a new one \u2014 act on it once.";
|
|
97
97
|
export function renderTaskNotificationXml(n) {
|
|
98
|
+
if (n.received !== undefined)
|
|
99
|
+
return n.received.text;
|
|
98
100
|
const body = renderTaskNotificationCarrier(n);
|
|
99
101
|
return n.resupplied === true ? `${RESUPPLIED_FRAME_PREAMBLE}\n\n${body}` : body;
|
|
100
102
|
}
|
|
@@ -178,13 +180,35 @@ export function terminalFrameFacets(facts) {
|
|
|
178
180
|
};
|
|
179
181
|
}
|
|
180
182
|
const COMPLETION_REPORT_MAX = 2_000;
|
|
181
|
-
|
|
183
|
+
function cutReportReading(artifact) {
|
|
184
|
+
switch (artifact.kind) {
|
|
185
|
+
case "stored":
|
|
186
|
+
return `read the full text with ReadToolResult (ref "${artifact.ref}")`;
|
|
187
|
+
case "unconfirmed":
|
|
188
|
+
return "the full text could not be stored (the write failed or went unconfirmed), so no ref can read it back and it is not readable in this session — ask the agent for it via SendMessage";
|
|
189
|
+
case "no_store":
|
|
190
|
+
return "the full text is not stored behind a ref (no offload store), so it is not readable in this session — ask the agent for it via SendMessage";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
export const SHORT_REPORT_UNSTORED = "a background task's report could not be stored (the write failed or went unconfirmed): its completion frame carried the whole report, but its task row keeps no read handle for a later list";
|
|
194
|
+
export async function completionResultField(result, persist, record, notifier) {
|
|
182
195
|
if (!result)
|
|
183
196
|
return undefined;
|
|
184
197
|
const report = egressText("same-principal", result);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
if (report.length <= COMPLETION_REPORT_MAX) {
|
|
199
|
+
void notifier.notifyAsync(async () => {
|
|
200
|
+
const artifact = await persist(report);
|
|
201
|
+
if (artifact.kind === "unconfirmed")
|
|
202
|
+
throw new Error(SHORT_REPORT_UNSTORED);
|
|
203
|
+
if (artifact.kind === "stored")
|
|
204
|
+
record(artifact.ref);
|
|
205
|
+
}, "completionResultField.shortReportWrite");
|
|
206
|
+
return { text: report };
|
|
207
|
+
}
|
|
208
|
+
const artifact = await persist(report);
|
|
209
|
+
if (artifact.kind === "stored")
|
|
210
|
+
record(artifact.ref);
|
|
211
|
+
return { text: `${report.slice(0, COMPLETION_REPORT_MAX)}\n[result truncated: ${report.length} chars total — ${cutReportReading(artifact)}]` };
|
|
188
212
|
}
|
|
189
213
|
export const ENGINE_FRAME_CODEC_VERSION = 1;
|
|
190
214
|
export const ENGINE_FRAME_TASK_TYPES = Object.freeze(["background_agent", "monitor", "workflow"]);
|
|
@@ -276,6 +300,92 @@ export function isDelegatedAgentTerminal(n) {
|
|
|
276
300
|
export function isTerminalTaskNotification(n) {
|
|
277
301
|
return TERMINAL_STATUSES.has(n.status);
|
|
278
302
|
}
|
|
303
|
+
export function resolveCompletionSink(callSink, mountSink) {
|
|
304
|
+
return callSink ?? mountSink;
|
|
305
|
+
}
|
|
306
|
+
export function admitsBackgroundLaunch(sink, deploymentChannel = false) {
|
|
307
|
+
return sink !== undefined || deploymentChannel;
|
|
308
|
+
}
|
|
309
|
+
export class DeliveryObligations {
|
|
310
|
+
owed = new Map();
|
|
311
|
+
counted = new Set();
|
|
312
|
+
wakers = new Set();
|
|
313
|
+
waitDeadline;
|
|
314
|
+
owe(task) {
|
|
315
|
+
const lane = taskNotificationLaneKey(task);
|
|
316
|
+
this.owed.set(lane, (this.owed.get(lane) ?? 0) + 1);
|
|
317
|
+
}
|
|
318
|
+
discharge(frame) {
|
|
319
|
+
const lane = taskNotificationLaneKey(frame);
|
|
320
|
+
const key = taskNotificationDedupKey(frame);
|
|
321
|
+
if (!this.owed.has(lane) || this.counted.has(key))
|
|
322
|
+
return;
|
|
323
|
+
this.counted.add(key);
|
|
324
|
+
this.release(lane);
|
|
325
|
+
}
|
|
326
|
+
retire(task) {
|
|
327
|
+
this.release(taskNotificationLaneKey(task));
|
|
328
|
+
}
|
|
329
|
+
release(lane) {
|
|
330
|
+
const cycles = this.owed.get(lane);
|
|
331
|
+
if (cycles === undefined)
|
|
332
|
+
return;
|
|
333
|
+
if (cycles > 1)
|
|
334
|
+
this.owed.set(lane, cycles - 1);
|
|
335
|
+
else
|
|
336
|
+
this.owed.delete(lane);
|
|
337
|
+
this.wake();
|
|
338
|
+
}
|
|
339
|
+
wake() {
|
|
340
|
+
for (const wake of [...this.wakers])
|
|
341
|
+
wake();
|
|
342
|
+
}
|
|
343
|
+
get pending() {
|
|
344
|
+
return [...this.owed.keys()];
|
|
345
|
+
}
|
|
346
|
+
nextDischarge(signal, withinMs) {
|
|
347
|
+
if (this.owed.size === 0 || signal.aborted || withinMs <= 0)
|
|
348
|
+
return Promise.resolve();
|
|
349
|
+
return new Promise((resolve) => {
|
|
350
|
+
const timer = setTimeout(() => wake(), withinMs);
|
|
351
|
+
timer.unref?.();
|
|
352
|
+
const wake = () => {
|
|
353
|
+
clearTimeout(timer);
|
|
354
|
+
this.wakers.delete(wake);
|
|
355
|
+
signal.removeEventListener("abort", wake);
|
|
356
|
+
resolve();
|
|
357
|
+
};
|
|
358
|
+
this.wakers.add(wake);
|
|
359
|
+
signal.addEventListener("abort", wake, { once: true });
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
async waitOut(signal, keepWaiting, onInput) {
|
|
363
|
+
if (this.owed.size === 0)
|
|
364
|
+
return;
|
|
365
|
+
this.waitDeadline ??= performance.now() + ONE_SHOT_WAIT_CEILING_MS;
|
|
366
|
+
const unsubscribe = onInput(() => this.wake());
|
|
367
|
+
try {
|
|
368
|
+
while (this.owed.size > 0 && keepWaiting() && !signal.aborted && performance.now() < this.waitDeadline)
|
|
369
|
+
await this.nextDischarge(signal, this.waitDeadline - performance.now());
|
|
370
|
+
}
|
|
371
|
+
finally {
|
|
372
|
+
unsubscribe();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const ONE_SHOT_WAIT_CEILING_MS = 600_000;
|
|
377
|
+
const LANE_OBLIGATIONS = new WeakMap();
|
|
378
|
+
export function bindDeliveryObligations(sink, book) {
|
|
379
|
+
LANE_OBLIGATIONS.set(sink, book);
|
|
380
|
+
}
|
|
381
|
+
export function oweTerminalDelivery(sink, task) {
|
|
382
|
+
if (typeof sink === "function")
|
|
383
|
+
LANE_OBLIGATIONS.get(sink)?.owe(task);
|
|
384
|
+
}
|
|
385
|
+
export function retireTerminalDelivery(sink, task) {
|
|
386
|
+
if (typeof sink === "function")
|
|
387
|
+
LANE_OBLIGATIONS.get(sink)?.retire(task);
|
|
388
|
+
}
|
|
279
389
|
export function createLiveNotificationLane(seat) {
|
|
280
390
|
const handedOff = new Set();
|
|
281
391
|
const enter = (admits) => (payload, priority, onDisposition) => {
|
|
@@ -363,7 +473,63 @@ export class PendingSessionNotifications {
|
|
|
363
473
|
sessionBoxFor(sessionId) {
|
|
364
474
|
return this.sessionBoxes.get(sessionId);
|
|
365
475
|
}
|
|
366
|
-
|
|
476
|
+
settleBoxDebts(sessionId, signal) {
|
|
477
|
+
const owed = this.sessions.get(sessionId)?.boxDebts;
|
|
478
|
+
if (owed === undefined || owed.size === 0)
|
|
479
|
+
return undefined;
|
|
480
|
+
const debts = [...owed];
|
|
481
|
+
return (async () => {
|
|
482
|
+
for (const [copy, debt] of debts) {
|
|
483
|
+
if (signal?.aborted === true)
|
|
484
|
+
return;
|
|
485
|
+
await this.settleBoxDebt(sessionId, copy, debt);
|
|
486
|
+
}
|
|
487
|
+
})();
|
|
488
|
+
}
|
|
489
|
+
keepBackOwing(sessionId, s) {
|
|
490
|
+
const debts = s.boxDebts;
|
|
491
|
+
const owing = debts === undefined ? [] : s.items.filter((n) => debts.has(n));
|
|
492
|
+
if (owing.length === 0)
|
|
493
|
+
return s;
|
|
494
|
+
const tiers = new Map();
|
|
495
|
+
for (const n of owing) {
|
|
496
|
+
const p = s.priorities?.get(n);
|
|
497
|
+
if (p !== undefined)
|
|
498
|
+
tiers.set(n, p);
|
|
499
|
+
}
|
|
500
|
+
this.sessions.set(sessionId, { items: owing, dropped: new Map(), keys: new Set(owing.map((n) => taskNotificationDedupKey(n))), priorities: tiers, boxDebts: debts });
|
|
501
|
+
const rest = s.items.filter((n) => !debts.has(n));
|
|
502
|
+
return rest.length === 0 && s.dropped.size === 0 ? undefined : { ...s, items: rest };
|
|
503
|
+
}
|
|
504
|
+
async settleBoxDebt(sessionId, copy, debt) {
|
|
505
|
+
let answered = false;
|
|
506
|
+
try {
|
|
507
|
+
await debt.box.mailbox.append(debt.box.scope, debt.box.handle, debt.record);
|
|
508
|
+
answered = true;
|
|
509
|
+
}
|
|
510
|
+
catch (e) {
|
|
511
|
+
try {
|
|
512
|
+
debt.box.onError?.(e);
|
|
513
|
+
}
|
|
514
|
+
catch {
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
const s = this.sessions.get(sessionId);
|
|
518
|
+
if (s?.boxDebts?.get(copy) !== debt)
|
|
519
|
+
return;
|
|
520
|
+
s.boxDebts.delete(copy);
|
|
521
|
+
const at = s.items.indexOf(copy);
|
|
522
|
+
if (!answered || at === -1)
|
|
523
|
+
return;
|
|
524
|
+
s.items.splice(at, 1);
|
|
525
|
+
const key = taskNotificationDedupKey(copy);
|
|
526
|
+
s.keys.delete(key);
|
|
527
|
+
s.priorities?.delete(copy);
|
|
528
|
+
this.noteDurablePark(sessionId, key);
|
|
529
|
+
if (s.items.length === 0 && s.dropped.size === 0)
|
|
530
|
+
this.sessions.delete(sessionId);
|
|
531
|
+
}
|
|
532
|
+
pend(sessionId, n, priority, debt) {
|
|
367
533
|
let s = this.sessions.get(sessionId);
|
|
368
534
|
if (s === undefined) {
|
|
369
535
|
if (this.sessions.size >= MAX_PENDING_SESSIONS) {
|
|
@@ -395,6 +561,8 @@ export class PendingSessionNotifications {
|
|
|
395
561
|
s.items.push(n);
|
|
396
562
|
if (priority !== undefined)
|
|
397
563
|
s.priorities?.set(n, priority);
|
|
564
|
+
if (debt !== undefined)
|
|
565
|
+
(s.boxDebts ??= new Map()).set(n, debt);
|
|
398
566
|
const lane = taskNotificationLaneKey(n);
|
|
399
567
|
let mine = 0;
|
|
400
568
|
for (const i of s.items)
|
|
@@ -407,9 +575,11 @@ export class PendingSessionNotifications {
|
|
|
407
575
|
}
|
|
408
576
|
drain(sessionId) {
|
|
409
577
|
this.routed.delete(sessionId);
|
|
410
|
-
const
|
|
411
|
-
if (
|
|
578
|
+
const parked = this.sessions.get(sessionId);
|
|
579
|
+
if (parked !== undefined)
|
|
412
580
|
this.sessions.delete(sessionId);
|
|
581
|
+
const s = parked !== undefined ? this.keepBackOwing(sessionId, parked) : undefined;
|
|
582
|
+
if (s !== undefined) {
|
|
413
583
|
const rank = (n) => {
|
|
414
584
|
const p = s.priorities?.get(n);
|
|
415
585
|
return p === "now" ? 0 : p === "next" ? 1 : 2;
|
|
@@ -533,7 +703,7 @@ export function routeOrParkNotification(store, sessionId, payload, priority, onD
|
|
|
533
703
|
});
|
|
534
704
|
const settled = appended.then(() => onDisposition?.("parked_durably"), () => {
|
|
535
705
|
store.forgetDurablePark(sessionId, dedupKey);
|
|
536
|
-
store.pend(sessionId, payload, priority);
|
|
706
|
+
store.pend(sessionId, payload, priority, { box, record });
|
|
537
707
|
onDisposition?.("parked");
|
|
538
708
|
});
|
|
539
709
|
DurableAppendObligations.current()?.track(settled);
|
|
@@ -571,11 +741,12 @@ function evictOldest(s, match) {
|
|
|
571
741
|
const victim = s.items.splice(idx, 1)[0];
|
|
572
742
|
s.keys.delete(taskNotificationDedupKey(victim));
|
|
573
743
|
s.priorities?.delete(victim);
|
|
744
|
+
s.boxDebts?.delete(victim);
|
|
574
745
|
const laneKey = taskNotificationLaneKey(victim);
|
|
575
746
|
const prior = s.dropped.get(laneKey);
|
|
576
747
|
s.dropped.set(laneKey, { count: (prior?.count ?? 0) + 1, taskType: victim.task_type, taskId: victim.task_id });
|
|
577
748
|
}
|
|
578
|
-
export function discloseDroppedPending(drained) {
|
|
749
|
+
export function discloseDroppedPending(drained, readHandleOf, tasks) {
|
|
579
750
|
const hasSessionLoss = drained.droppedWholeSession !== undefined && drained.droppedWholeSession > 0;
|
|
580
751
|
if (!hasSessionLoss && drained.dropped.size === 0)
|
|
581
752
|
return drained.items;
|
|
@@ -585,7 +756,7 @@ export function discloseDroppedPending(drained) {
|
|
|
585
756
|
task_id: "session",
|
|
586
757
|
task_type: "background_agent",
|
|
587
758
|
status: "event",
|
|
588
|
-
summary: `${drained.droppedWholeSession} pending notification(s) for this session were dropped before this turn (the pending store evicted the whole session under its session-count cap). Which tasks they came from is no longer known
|
|
759
|
+
summary: `${drained.droppedWholeSession} pending notification(s) for this session were dropped before this turn (the pending store evicted the whole session under its session-count cap). Which tasks they came from is no longer known.${tasks === undefined ? "" : sessionLossTableClause(tasks())}`,
|
|
589
760
|
},
|
|
590
761
|
]
|
|
591
762
|
: [];
|
|
@@ -627,11 +798,37 @@ export function discloseDroppedPending(drained) {
|
|
|
627
798
|
task_id: taskId,
|
|
628
799
|
task_type: dropped.taskType,
|
|
629
800
|
status: "event",
|
|
630
|
-
summary: `[${taskId}] ${dropped.count} pending notification(s) from this task were dropped (pending-queue overflow) before this turn; nothing else from it survived.
|
|
801
|
+
summary: `[${taskId}] ${dropped.count} pending notification(s) from this task were dropped (pending-queue overflow) before this turn; nothing else from it survived.${dropped.taskType === "external" || readHandleOf === undefined ? "" : droppedReadClause(readHandleOf(taskId))}`,
|
|
631
802
|
});
|
|
632
803
|
}
|
|
633
804
|
return [...out, ...sessionLine];
|
|
634
805
|
}
|
|
806
|
+
function droppedReadClause(read) {
|
|
807
|
+
return read !== undefined ? ` Its ${read}.` : " Its row is no longer readable from this run.";
|
|
808
|
+
}
|
|
809
|
+
const BACKGROUND_TASK_TABLE_ROWS_MAX = 50;
|
|
810
|
+
const BACKGROUND_TASK_TABLE_DESCRIPTION_MAX = 80;
|
|
811
|
+
export function renderBackgroundTaskTable(tasks) {
|
|
812
|
+
const unlisted = tasks.length - BACKGROUND_TASK_TABLE_ROWS_MAX;
|
|
813
|
+
const lines = tasks.slice(0, BACKGROUND_TASK_TABLE_ROWS_MAX).map((t) => {
|
|
814
|
+
const phrase = t.status === "completed"
|
|
815
|
+
? "completed in background"
|
|
816
|
+
: t.status === "killed"
|
|
817
|
+
? "stopped"
|
|
818
|
+
: t.status === "running"
|
|
819
|
+
? "still running in background"
|
|
820
|
+
: t.status === "parked"
|
|
821
|
+
? "parked awaiting an out-of-band approval — do NOT re-issue the gated call"
|
|
822
|
+
: t.status;
|
|
823
|
+
return `- [${t.id}] Task "${(t.description ?? "background task").slice(0, BACKGROUND_TASK_TABLE_DESCRIPTION_MAX)}" ${phrase}${t.read !== undefined ? ` — ${t.read}` : ""}`;
|
|
824
|
+
});
|
|
825
|
+
return lines.join("\n") + (unlisted > 0 ? `\n(+${unlisted} more background tasks, not listed here)` : "");
|
|
826
|
+
}
|
|
827
|
+
function sessionLossTableClause(rows) {
|
|
828
|
+
return rows.length === 0
|
|
829
|
+
? " This run has no background task left to read."
|
|
830
|
+
: ` This run's background tasks (read output where its row says, terminate with TaskStop):\n${renderBackgroundTaskTable(rows)}`;
|
|
831
|
+
}
|
|
635
832
|
export class SystemInjectionQueue {
|
|
636
833
|
queues = {
|
|
637
834
|
now: [],
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type BackgroundAgentRecord, type BackgroundAgentStore } from "./background-agent-store.js";
|
|
2
|
-
import { type StopSource, type TaskAccess, type TaskRetrievalStatus, type UnifiedTaskOutput, type UnifiedTaskResult, type BackgroundAgentTaskHandle, type DurableAgentCore, type ParkedClaimTicket, type RegisterBackgroundAgentInput } from "./task-registry-shared.js";
|
|
3
|
-
import { type ToolResultStore } from "./tool-result-store.js";
|
|
2
|
+
import { type StopSource, type TaskAccess, type TaskRetrievalStatus, type UnifiedTaskOutput, type UnifiedTaskResult, type BackgroundAgentTaskHandle, type RegisteredTaskHandle, type DurableAgentCore, type ParkedClaimTicket, type RegisterBackgroundAgentInput } from "./task-registry-shared.js";
|
|
4
3
|
import { type AgentState } from "./agent-state.js";
|
|
5
4
|
import type { CheckpointSeat } from "./checkpoint-seat.js";
|
|
6
5
|
/**
|
|
@@ -117,13 +116,24 @@ export declare function reapDurableAgentsLane(core: DurableAgentCore, scope: str
|
|
|
117
116
|
skippedNoSessions: number;
|
|
118
117
|
orphanPlacedReleased: number;
|
|
119
118
|
}>;
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
export declare function
|
|
119
|
+
/** The child session a background-agent row is anchored to right now — the session its child runs on
|
|
120
|
+
* or keeps (transcript / resume anchor) — or `undefined` before the bind, after the anchor's release,
|
|
121
|
+
* and on every other task type. The ONE reading of the anchor: the list row's `sessionId` and the
|
|
122
|
+
* release match below both read it here. */
|
|
123
|
+
export declare function childSessionAnchorOf(handle: RegisteredTaskHandle): string | undefined;
|
|
124
|
+
/** A successful release of the child session `sessionId` ends the row's claim on it: both copies of
|
|
125
|
+
* the anchor go — the handle's (the list row reads it) and the durable record's (the heartbeat's F-1
|
|
126
|
+
* arm keeps re-driving a flush-failed lane, so a later successful flush would otherwise persist a row
|
|
127
|
+
* pointing at the session the caller just released). The clear matches the PAIR (row, session): a late
|
|
128
|
+
* clear for a session the row no longer names leaves the current anchor alone. State/result survive,
|
|
129
|
+
* the transcript does not. */
|
|
130
|
+
export declare function releaseDurableTranscriptAnchorLane(core: DurableAgentCore, id: string, sessionId: string): void;
|
|
125
131
|
/** design/151 S1a — bind the child's freshly-minted store session id onto the row (the transcript /
|
|
126
|
-
* resume anchor; absent at register time because the child session is created after registration).
|
|
132
|
+
* resume anchor; absent at register time because the child session is created after registration).
|
|
133
|
+
* A row already anchored to that session is left as it is (one fact, no second durable write). A row anchored to ANOTHER session
|
|
134
|
+
* is refused: an anchor changes only by its release ({@link releaseDurableTranscriptAnchorLane}) and a fresh bind, never by being
|
|
135
|
+
* written over, so the earlier session is never silently left unowned. An id that is no non-empty string is no anchor and is
|
|
136
|
+
* refused whatever the row holds. */
|
|
127
137
|
export declare function bindBackgroundAgentSessionLane(core: DurableAgentCore, id: string, sessionId: string): void;
|
|
128
138
|
/**
|
|
129
139
|
* #22 — record the org-memory admission verdict THIS leg adjudicated onto the durable row, so the
|
|
@@ -436,7 +446,7 @@ export declare function deliverToRunningAgentLane(core: DurableAgentCore, id: st
|
|
|
436
446
|
disposition: "queued" | "parked" | "pending";
|
|
437
447
|
} | {
|
|
438
448
|
ok: false;
|
|
439
|
-
reason: "not_found" | "not_running" | "no_channel" | "queue_full";
|
|
449
|
+
reason: "not_found" | "not_running" | "no_channel" | "queue_full" | "refused";
|
|
440
450
|
}>;
|
|
441
451
|
/** CC `ugo`/`rxo` (206:575227-575243 = 220:467937-467951): `id (label)` rows for a not-found footer —
|
|
442
452
|
* running bg agents the CALLER can address (canAccess scopes; CC's self/observer exclusions have no
|
|
@@ -458,8 +468,8 @@ export declare function runningBackgroundAgentLabelsLane(core: DurableAgentCore,
|
|
|
458
468
|
* rows. CC filters `!n.has(i.id)` — a NAMED agent is deliberately NOT repeated here, because
|
|
459
469
|
* its addressable form is the name, not the id. The pre-RB-332 sema code merged both legs
|
|
460
470
|
* into one list and justified it with "named has no counterpart", a claim [c209-D] retired
|
|
461
|
-
* when the explicit `name` field landed. The id stays in these rows because
|
|
462
|
-
*
|
|
471
|
+
* when the explicit `name` field landed. The id stays in these rows because the task faces
|
|
472
|
+
* resolve exact ids: an agent nobody named is the one a retry can reach by its id alone.
|
|
463
473
|
* CC's `YEd` "Running teammates:" leg has no sema counterpart (no teammate registry on this face) and is
|
|
464
474
|
* honestly absent rather than faked.
|
|
465
475
|
*/
|
|
@@ -467,8 +477,8 @@ export declare function runningAgentFooterLane(core: DurableAgentCore, access: T
|
|
|
467
477
|
named: string[];
|
|
468
478
|
background: string[];
|
|
469
479
|
};
|
|
470
|
-
/** The not-found TAIL both task faces share (CC `rxo`, appended by `uMs` for TaskStop
|
|
471
|
-
*
|
|
480
|
+
/** The not-found TAIL both task faces share (CC `rxo`, appended by `uMs` for TaskStop;
|
|
481
|
+
* the host poll's not-found carries the same tail). Empty string when the caller has nothing running. */
|
|
472
482
|
export declare function notFoundRunningAgentsTail(footer: {
|
|
473
483
|
named: string[];
|
|
474
484
|
background: string[];
|
|
@@ -524,49 +534,7 @@ export declare function serveDurableAgentRowLane(row: BackgroundAgentRecord,
|
|
|
524
534
|
* {@link import("./agent-state.js").agentStateSourceOfRecord}(row)): rendered as the `state:` line and
|
|
525
535
|
* carried as `details.agentState`. Absent ⇒ neither appears (a serving layer that does not read it). */
|
|
526
536
|
agentState?: AgentState): UnifiedTaskResult;
|
|
527
|
-
/**
|
|
528
|
-
* design/158 S1 (RB-205-B 半) — spill the FULL text behind a CLIPPED background_agent result to the
|
|
529
|
-
* offload store, and append a ref-disclosure so the middle `clipTaskOutput` drops is not gone for good.
|
|
530
|
-
* `RegisterBackgroundAgentInput` deliberately carries no `outputFile` (ref-not-path is the design/158
|
|
531
|
-
* §2.4 divergence — TOC/TOB compatible, unlike a local path), so this is the only pageback this lane
|
|
532
|
-
* gets; it reuses the SAME vocabulary as the offload face (design/108: {@link OFFLOAD_TOOL_NAME},
|
|
533
|
-
* {@link buildToolResultRef} — RB-273's single mint point) instead of inventing a parallel one.
|
|
534
|
-
*
|
|
535
|
-
* Lazy: only writes on the FIRST poll whose clip actually cut something (`clipped !== full`) — a short
|
|
536
|
-
* result never touches the store, matching design/158 §2.1 ("spill is a fidelity layer, not a new
|
|
537
|
-
* source of truth"). Idempotent PER REVIVE CYCLE: the ref folds in `handle.reviveCycle` (a revive clears
|
|
538
|
-
* `handle.spillRef` — see {@link reviveBackgroundAgentLane} — but `handle.id` itself does NOT change
|
|
539
|
-
* across a revive, so without the cycle in the ref, cycle 2's spill would mint the SAME ref string as
|
|
540
|
-
* cycle 1's and the store's write-once contract would silently keep cycle 1's STALE text under a ref
|
|
541
|
-
* now disclosed as cycle 2's current result). Caching the minted ref on the handle (rather than just
|
|
542
|
-
* re-deriving+re-`put`ting every poll and trusting the store's own write-once no-op) keeps the disclosed
|
|
543
|
-
* ref byte-stable across polls and avoids a redundant round-trip to a durable backend on every poll.
|
|
544
|
-
*
|
|
545
|
-
* No store configured (a deployment that never wired a `toolResultStore`) ⇒ returns `clipped` UNCHANGED
|
|
546
|
-
* — the legal degrade design/158 §2.2 calls for, byte-identical to pre-S1 behavior.
|
|
547
|
-
*
|
|
548
|
-
* Backlog #169 — a FAILING `put` (throwing or rejecting; the store contract admits both dialects) is
|
|
549
|
-
* NOT fatal to the poll: the clipped text is still served, with {@link AGENT_SPILL_FAILED_NOTE} in
|
|
550
|
-
* place of the ref disclosure (advertising a ref nobody can read back would be a false promise), and
|
|
551
|
-
* `handle.spillFailed` latches so later polls of the same cycle repeat the honest note instead of
|
|
552
|
-
* retrying the write — see the catch below for why latch-not-retry. Same "store failure is never
|
|
553
|
-
* fatal" posture as the monitor/offload/budget/compaction write sites. A put that settles AFTER a
|
|
554
|
-
* revive (stale cycle) is generation-guarded: it answers its own caller honestly but never writes
|
|
555
|
-
* spill state onto the new cycle (see `mintCycle` below).
|
|
556
|
-
*/
|
|
557
|
-
export declare function spillClippedAgentResult(handle: BackgroundAgentTaskHandle, full: string, clipped: string, store: ToolResultStore | undefined, sessionId: string | undefined): Promise<string>;
|
|
558
537
|
export declare function pollBackgroundAgentLane(handle: BackgroundAgentTaskHandle, deadline?: number, signal?: AbortSignal,
|
|
559
|
-
/** Mirrors {@link import("./types.js").TaskSpec.oneShot} (see
|
|
560
|
-
* {@link import("./task-registry.js").TaskToolOptions.oneShot} for the full contract): this run has
|
|
561
|
-
* no later turn for an async background notification to land in, so the still-running body must
|
|
562
|
-
* not teach "you will be notified when it completes". */
|
|
563
|
-
oneShot?: boolean,
|
|
564
|
-
/** design/158 S1 — the offload store a clipped result's full text spills to (see
|
|
565
|
-
* {@link spillClippedAgentResult}). Absent ⇒ legal degrade, byte-identical to pre-S1 output. */
|
|
566
|
-
store?: ToolResultStore,
|
|
567
|
-
/** design/158 S1 — the caller's session id, folded into the minted ref for global uniqueness (same
|
|
568
|
-
* role `sessionId` plays at every other {@link buildToolResultRef} call site). */
|
|
569
|
-
sessionId?: string,
|
|
570
538
|
/** The run's checkpoint seat — the store a parked row's approval card is read from
|
|
571
539
|
* ({@link import("./agent-state.js").readAgentState}). Absent ⇒ a parked row reads `approval unreadable`. */
|
|
572
540
|
checkpointSeat?: CheckpointSeat): Promise<UnifiedTaskResult>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { receiveRetentionPolicy } from "./retention-policy.js";
|
|
3
3
|
import { uuidv7 } from "../internal/harness.js";
|
|
4
|
-
import { canAccessAgentRecord, BackgroundAgentStoreError, clearRevivedRowTerminalPayload, REVIVED_ROW_CLEARED_FIELDS, STALE_RUNNING_REAP_ATTRIBUTION, } from "./background-agent-store.js";
|
|
4
|
+
import { BACKGROUND_AGENT_REAP_KNOBS, canAccessAgentRecord, BackgroundAgentStoreError, clearRevivedRowTerminalPayload, REVIVED_ROW_CLEARED_FIELDS, STALE_RUNNING_REAP_ATTRIBUTION, } from "./background-agent-store.js";
|
|
5
5
|
import { shutdownDebug } from "./shutdown-debug.js";
|
|
6
6
|
import { delimitUntrusted } from "./untrusted-text.js";
|
|
7
7
|
import { boundedRedactedSummary } from "./untrusted-egress.js";
|
|
8
|
-
import { mintCompletionId, commitCompletionIdIfEmpty, clipTaskOutput, assertOwnership, sleepPollStep, alreadyTerminalStopNote, canAccess, normalizeAgentName, engineAgentName, chosenAgentName,
|
|
9
|
-
import { buildToolResultRef, OFFLOAD_TOOL_NAME, toolResultProvenanceOf } from "./tool-result-store.js";
|
|
8
|
+
import { mintCompletionId, commitCompletionIdIfEmpty, clipTaskOutput, assertOwnership, sleepPollStep, alreadyTerminalStopNote, canAccess, normalizeAgentName, engineAgentName, chosenAgentName, DURABLE_AGENT_HEARTBEAT_MS, DURABLE_AGENT_HANDLE_RE, BG_AGENT_REAP_STOP_ERROR, } from "./task-registry-shared.js";
|
|
10
9
|
import { thrownLabel } from "./thrown-value.js";
|
|
10
|
+
import { closestName } from "./closest-name.js";
|
|
11
11
|
import { agentStateSourceOfHandle, agentStateSummary, readAgentState } from "./agent-state.js";
|
|
12
12
|
export function activeDelegationHandlesLane(core, scope, rootSessionId) {
|
|
13
13
|
const out = [];
|
|
@@ -183,24 +183,24 @@ export function endDurableClaimLane(core, id) {
|
|
|
183
183
|
core.claimingHandles.delete(id);
|
|
184
184
|
}
|
|
185
185
|
export async function reapDurableAgentsLane(core, scope, deps, policy) {
|
|
186
|
-
|
|
187
|
-
const now =
|
|
188
|
-
if (
|
|
189
|
-
await deps.store.reap(scope, now, { staleRunningMaxAgeMs:
|
|
186
|
+
const knobs = receiveRetentionPolicy("reapDurableAgents", policy, BACKGROUND_AGENT_REAP_KNOBS, ["now"]);
|
|
187
|
+
const now = knobs.now ?? Date.now();
|
|
188
|
+
if (knobs.staleRunningMaxAgeMs !== undefined) {
|
|
189
|
+
await deps.store.reap(scope, now, { staleRunningMaxAgeMs: knobs.staleRunningMaxAgeMs });
|
|
190
190
|
}
|
|
191
|
-
if (
|
|
191
|
+
if (knobs.maxAgeMs === undefined && knobs.keep === undefined)
|
|
192
192
|
return { rowsReaped: 0, sessionsReleased: 0, skippedNoSessions: 0, orphanPlacedReleased: 0 };
|
|
193
193
|
const terminal = (await deps.store.listByScope(scope)).filter((r) => r.status !== "running" && r.status !== "parked");
|
|
194
194
|
terminal.sort((a, b) => b.spawnedAt - a.spawnedAt);
|
|
195
195
|
const doomed = new Map();
|
|
196
|
-
if (
|
|
196
|
+
if (knobs.maxAgeMs !== undefined) {
|
|
197
197
|
for (const r of terminal) {
|
|
198
|
-
if ((r.settledAt ?? r.spawnedAt) < now -
|
|
198
|
+
if ((r.settledAt ?? r.spawnedAt) < now - knobs.maxAgeMs)
|
|
199
199
|
doomed.set(r.handle, r);
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
|
-
if (
|
|
203
|
-
for (const r of terminal.slice(Math.max(0,
|
|
202
|
+
if (knobs.keep !== undefined) {
|
|
203
|
+
for (const r of terminal.slice(Math.max(0, knobs.keep)))
|
|
204
204
|
doomed.set(r.handle, r);
|
|
205
205
|
}
|
|
206
206
|
let rowsReaped = 0;
|
|
@@ -265,10 +265,10 @@ export async function reapDurableAgentsLane(core, scope, deps, policy) {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
let orphanPlacedReleased = 0;
|
|
268
|
-
if (
|
|
268
|
+
if (knobs.maxAgeMs !== undefined && deps.sessions !== undefined && typeof deps.sessions.listPlaced === "function") {
|
|
269
269
|
let placed = [];
|
|
270
270
|
try {
|
|
271
|
-
placed = await deps.sessions.listPlaced("subagent", { olderThanMs:
|
|
271
|
+
placed = await deps.sessions.listPlaced("subagent", { olderThanMs: knobs.maxAgeMs, scope });
|
|
272
272
|
}
|
|
273
273
|
catch {
|
|
274
274
|
placed = [];
|
|
@@ -296,6 +296,7 @@ export async function reapDurableAgentsLane(core, scope, deps, policy) {
|
|
|
296
296
|
await deps.sessions.unpin?.(p.sessionId);
|
|
297
297
|
await deps.sessions.release(p.sessionId);
|
|
298
298
|
orphanPlacedReleased++;
|
|
299
|
+
releaseDurableTranscriptAnchorLane(core, p.handle, p.sessionId);
|
|
299
300
|
}
|
|
300
301
|
catch {
|
|
301
302
|
}
|
|
@@ -310,16 +311,29 @@ export async function reapDurableAgentsLane(core, scope, deps, policy) {
|
|
|
310
311
|
}
|
|
311
312
|
return { rowsReaped, sessionsReleased, skippedNoSessions, orphanPlacedReleased };
|
|
312
313
|
}
|
|
313
|
-
export function
|
|
314
|
+
export function childSessionAnchorOf(handle) {
|
|
315
|
+
return handle.type === "background_agent" ? handle.sessionId : undefined;
|
|
316
|
+
}
|
|
317
|
+
export function releaseDurableTranscriptAnchorLane(core, id, sessionId) {
|
|
314
318
|
const handle = core.handles.get(id);
|
|
315
319
|
if (!handle || handle.type !== "background_agent")
|
|
316
320
|
return;
|
|
321
|
+
if (childSessionAnchorOf(handle) !== sessionId)
|
|
322
|
+
return;
|
|
323
|
+
delete handle.sessionId;
|
|
317
324
|
durableAgentWriteLane(handle, {}, ["sessionId"]);
|
|
318
325
|
}
|
|
319
326
|
export function bindBackgroundAgentSessionLane(core, id, sessionId) {
|
|
327
|
+
if (typeof sessionId !== "string" || sessionId === "")
|
|
328
|
+
throw new Error(`TaskRegistry: a background-agent session anchor must be a non-empty session id (got ${typeof sessionId === "string" ? "an empty string" : `a ${sessionId === null ? "null" : typeof sessionId}`})`);
|
|
320
329
|
const handle = core.handles.get(id);
|
|
321
330
|
if (!handle || handle.type !== "background_agent")
|
|
322
331
|
return;
|
|
332
|
+
const anchored = childSessionAnchorOf(handle);
|
|
333
|
+
if (anchored === sessionId)
|
|
334
|
+
return;
|
|
335
|
+
if (anchored !== undefined)
|
|
336
|
+
throw new Error(`TaskRegistry: background-agent row ${id} is anchored to a session already — release that anchor before binding another (the row keeps its anchor)`);
|
|
323
337
|
handle.sessionId = sessionId;
|
|
324
338
|
durableAgentWriteLane(handle, { sessionId });
|
|
325
339
|
}
|
|
@@ -1093,8 +1107,7 @@ export async function reviveBackgroundAgentLane(core, id, access, abort) {
|
|
|
1093
1107
|
handle.abort = abort;
|
|
1094
1108
|
handle.result = undefined;
|
|
1095
1109
|
handle.resultFull = undefined;
|
|
1096
|
-
handle.
|
|
1097
|
-
handle.spillFailed = undefined;
|
|
1110
|
+
handle.artifactRef = undefined;
|
|
1098
1111
|
handle.error = undefined;
|
|
1099
1112
|
handle.errorCode = undefined;
|
|
1100
1113
|
handle.errorRetryable = undefined;
|
|
@@ -1246,6 +1259,9 @@ export async function deliverToRunningAgentLane(core, id, access, notification,
|
|
|
1246
1259
|
if (d === "parked" || d === "parked_durably") {
|
|
1247
1260
|
result = handle.retainedContinuation === true ? { ok: true, disposition: "parked" } : { ok: false, reason: "not_running" };
|
|
1248
1261
|
}
|
|
1262
|
+
else if (d === "refused") {
|
|
1263
|
+
result = { ok: false, reason: "refused" };
|
|
1264
|
+
}
|
|
1249
1265
|
else {
|
|
1250
1266
|
result = { ok: true, disposition: "queued" };
|
|
1251
1267
|
}
|
|
@@ -1308,7 +1324,7 @@ export function serveDurableAgentRowLane(row, agentState) {
|
|
|
1308
1324
|
const stateLine = agentState !== undefined ? `state: ${agentStateSummary(agentState)}\n` : "";
|
|
1309
1325
|
if (row.status === "parked") {
|
|
1310
1326
|
return {
|
|
1311
|
-
content: delimitUntrusted(`
|
|
1327
|
+
content: delimitUntrusted(`task ${row.handle}`, `status: parked
|
|
1312
1328
|
${stateLine}The agent is durably suspended, waiting for an approval decision. It resumes when the pending approval is decided (durable approval inbox), or lands failed if the approval expires.`),
|
|
1313
1329
|
details: buildAgentPollDetails({
|
|
1314
1330
|
taskId: row.handle,
|
|
@@ -1327,7 +1343,7 @@ ${stateLine}${row.error ? `error: ${row.error}${kindClause}
|
|
|
1327
1343
|
` : ""}${row.finalOutput ? `--- result${row.resultIsPartial ? " (partial — produced before the task was stopped)" : ""} ---
|
|
1328
1344
|
${clipTaskOutput(row.finalOutputFull ?? row.finalOutput)}` : "(no result text)"}`;
|
|
1329
1345
|
return {
|
|
1330
|
-
content: delimitUntrusted(`
|
|
1346
|
+
content: delimitUntrusted(`task ${row.handle}`, body),
|
|
1331
1347
|
details: buildAgentPollDetails({
|
|
1332
1348
|
taskId: row.handle,
|
|
1333
1349
|
status: row.status,
|
|
@@ -1345,35 +1361,7 @@ ${clipTaskOutput(row.finalOutputFull ?? row.finalOutput)}` : "(no result text)"}
|
|
|
1345
1361
|
...(row.status === "failed" ? { isError: true } : {}),
|
|
1346
1362
|
};
|
|
1347
1363
|
}
|
|
1348
|
-
|
|
1349
|
-
export async function spillClippedAgentResult(handle, full, clipped, store, sessionId) {
|
|
1350
|
-
if (clipped === full)
|
|
1351
|
-
return clipped;
|
|
1352
|
-
if (store === undefined)
|
|
1353
|
-
return clipped;
|
|
1354
|
-
const disclose = (ref) => `${clipped}\n\n[full output persisted — call ${OFFLOAD_TOOL_NAME} with ref "${ref}" to read it back.]`;
|
|
1355
|
-
if (handle.spillRef !== undefined)
|
|
1356
|
-
return disclose(handle.spillRef);
|
|
1357
|
-
if (handle.spillFailed === true)
|
|
1358
|
-
return `${clipped}${AGENT_SPILL_FAILED_NOTE}`;
|
|
1359
|
-
const mintCycle = handle.reviveCycle ?? 0;
|
|
1360
|
-
const ref = buildToolResultRef(sessionId ?? "no-session", handle.id, `c${mintCycle}`);
|
|
1361
|
-
try {
|
|
1362
|
-
await store.put(ref, full, sessionId === undefined ? undefined : toolResultProvenanceOf(sessionId));
|
|
1363
|
-
}
|
|
1364
|
-
catch {
|
|
1365
|
-
if ((handle.reviveCycle ?? 0) === mintCycle) {
|
|
1366
|
-
if (handle.spillRef !== undefined)
|
|
1367
|
-
return disclose(handle.spillRef);
|
|
1368
|
-
handle.spillFailed = true;
|
|
1369
|
-
}
|
|
1370
|
-
return `${clipped}${AGENT_SPILL_FAILED_NOTE}`;
|
|
1371
|
-
}
|
|
1372
|
-
if ((handle.reviveCycle ?? 0) === mintCycle)
|
|
1373
|
-
handle.spillRef = ref;
|
|
1374
|
-
return disclose(ref);
|
|
1375
|
-
}
|
|
1376
|
-
export async function pollBackgroundAgentLane(handle, deadline, signal, oneShot, store, sessionId, checkpointSeat) {
|
|
1364
|
+
export async function pollBackgroundAgentLane(handle, deadline, signal, checkpointSeat) {
|
|
1377
1365
|
while (handle.status === "running" && deadline !== undefined && Date.now() < deadline && !signal?.aborted) {
|
|
1378
1366
|
await sleepPollStep(deadline, signal);
|
|
1379
1367
|
}
|
|
@@ -1384,7 +1372,7 @@ export async function pollBackgroundAgentLane(handle, deadline, signal, oneShot,
|
|
|
1384
1372
|
const parkedSeq = handle.cycleSeq;
|
|
1385
1373
|
const agentState = await readAgentState(parkedSource, checkpointSeat, Date.now());
|
|
1386
1374
|
return {
|
|
1387
|
-
content: delimitUntrusted(`
|
|
1375
|
+
content: delimitUntrusted(`task ${handle.id}`, `status: parked
|
|
1388
1376
|
state: ${agentStateSummary(agentState)}
|
|
1389
1377
|
The agent is durably suspended, waiting for an approval decision. It resumes when the pending approval is decided (durable approval inbox), or lands failed if the approval expires.`),
|
|
1390
1378
|
details: buildAgentPollDetails({
|
|
@@ -1413,23 +1401,20 @@ The agent is durably suspended, waiting for an approval decision. It resumes whe
|
|
|
1413
1401
|
const stateRead = readAgentState(agentStateSourceOfHandle({ status: snap.status, updatedAt: snap.updatedAt }), checkpointSeat, Date.now());
|
|
1414
1402
|
const agentState = stateRead instanceof Promise ? await stateRead : stateRead;
|
|
1415
1403
|
const fullResult = snap.result ? (handle.resultFull ?? snap.result) : undefined;
|
|
1416
|
-
const resultText = fullResult !== undefined ?
|
|
1404
|
+
const resultText = fullResult !== undefined ? clipTaskOutput(fullResult, handle.outputFile) : undefined;
|
|
1417
1405
|
const kindClause = snap.status === "failed" && snap.errorKind !== undefined && snap.errorRetryable !== undefined
|
|
1418
1406
|
? ` (error_kind: ${snap.errorKind}, retryable: ${snap.errorRetryable}${snap.errorRetryAfterMs !== undefined ? `, retry_after_ms: ${snap.errorRetryAfterMs}` : ""})`
|
|
1419
1407
|
: "";
|
|
1420
1408
|
const stateLine = `state: ${agentStateSummary(agentState)}\n`;
|
|
1421
1409
|
const body = running
|
|
1422
|
-
?
|
|
1423
|
-
? `status: running
|
|
1424
|
-
${stateLine}This is a ONE-SHOT submission — there is no later turn for a background notification to land in, so do NOT end your turn expecting one. Actively wait instead: TaskOutput({ task_id: "${handle.id}", block: true }). If it is still running after the wait, wait again (bounded) rather than ending the turn, or write out your best available answer now if you are near your own time budget.`
|
|
1425
|
-
: `status: running
|
|
1410
|
+
? `status: running
|
|
1426
1411
|
${stateLine}The agent is still working — you will be notified when it completes.`
|
|
1427
1412
|
: `status: ${snap.status}
|
|
1428
1413
|
${stateLine}${snap.error ? `error: ${snap.error}${kindClause}
|
|
1429
1414
|
` : ""}${snap.result ? `--- result${snap.resultIsPartial ? " (partial — produced before the task was stopped)" : ""} ---
|
|
1430
1415
|
${resultText}` : "(no result text)"}`;
|
|
1431
1416
|
return {
|
|
1432
|
-
content: delimitUntrusted(`
|
|
1417
|
+
content: delimitUntrusted(`task ${handle.id}`, body),
|
|
1433
1418
|
details: buildAgentPollDetails({
|
|
1434
1419
|
taskId: handle.id,
|
|
1435
1420
|
status: snap.status,
|