@sema-agent/core 7.60.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 +605 -0
- package/README.md +2 -2
- package/dist/agents/agent-transcript-tool.d.ts +2 -2
- package/dist/agents/agent-transcript-tool.js +1 -1
- package/dist/agents/cascade.d.ts +61 -10
- package/dist/agents/cascade.js +60 -20
- 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 -0
- package/dist/agents/inherited-tool-pool.d.ts +5 -3
- package/dist/agents/inherited-tool-pool.js +2 -2
- 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.js +3 -1
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/roster-store.js +7 -4
- package/dist/agents/send-message-tool.d.ts +8 -10
- package/dist/agents/send-message-tool.js +43 -23
- 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 +30 -40
- package/dist/agents/subagent.js +187 -196
- package/dist/agents/suspend-guard.d.ts +9 -0
- package/dist/agents/suspend-guard.js +4 -0
- package/dist/agents/verify.d.ts +41 -14
- package/dist/agents/verify.js +37 -27
- package/dist/brain/anthropic.js +1 -0
- 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/stream-engine.d.ts +3 -0
- package/dist/brain/stream-engine.js +4 -0
- package/dist/core/agent-state.d.ts +1 -1
- package/dist/core/allow-entry.d.ts +59 -23
- package/dist/core/allow-entry.js +131 -38
- 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.js +3 -5
- package/dist/core/background-agent-store.d.ts +7 -5
- package/dist/core/background-agent-store.js +12 -11
- package/dist/core/checkpoint-requirements.d.ts +24 -3
- package/dist/core/checkpoint-requirements.js +9 -1
- package/dist/core/checkpoint-store.d.ts +78 -19
- package/dist/core/checkpoint-store.js +8 -4
- 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/context-settings.js +3 -5
- package/dist/core/cross-boundary-taint.d.ts +1 -1
- 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 +49 -18
- 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 +10 -0
- package/dist/core/frame-settlement.js +6 -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 +2 -1
- package/dist/core/gate-lanes.js +7 -4
- 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 +12 -4
- package/dist/core/governance-codes.js +16 -4
- package/dist/core/hooks.d.ts +12 -4
- package/dist/core/hooks.js +11 -4
- package/dist/core/host-floor.js +3 -5
- package/dist/core/image-admission.d.ts +48 -8
- package/dist/core/image-admission.js +35 -4
- package/dist/core/input-author.d.ts +36 -0
- package/dist/core/input-author.js +39 -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 +2 -1
- package/dist/core/locked-config.js +5 -3
- 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-connection-pool.d.ts +6 -20
- package/dist/core/mcp-connection-pool.js +10 -28
- package/dist/core/mcp-failure.d.ts +76 -15
- package/dist/core/mcp-failure.js +60 -33
- package/dist/core/mcp-host-seat.d.ts +92 -53
- package/dist/core/mcp-host-seat.js +220 -46
- package/dist/core/mcp-probe.js +2 -2
- 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 +2 -1
- 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 +6 -49
- package/dist/core/mcp.js +115 -111
- 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-engine/consolidation.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.js +7 -1
- 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/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/sync-client.d.ts +39 -18
- package/dist/core/memory-engine/sync-client.js +72 -14
- package/dist/core/memory-engine/sync-report.d.ts +7 -4
- package/dist/core/memory-engine/sync.d.ts +9 -1
- package/dist/core/mode-policy.d.ts +8 -8
- package/dist/core/mode-policy.js +7 -5
- package/dist/core/mods/agent-stations.d.ts +39 -4
- package/dist/core/mods/agent-stations.js +59 -10
- 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 +4 -3
- package/dist/core/mods/kernel/dispatch.js +4 -4
- package/dist/core/mods/kernel/events.d.ts +4 -1
- package/dist/core/mods/kernel/events.js +6 -6
- 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/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 +38 -16
- package/dist/core/mods/stations.js +25 -11
- package/dist/core/mods/tool-call.d.ts +2 -0
- package/dist/core/mods/tool-call.js +4 -4
- package/dist/core/output-style.js +3 -4
- package/dist/core/own-property-receipt.d.ts +61 -2
- package/dist/core/own-property-receipt.js +42 -2
- package/dist/core/park-selfcheck.js +4 -2
- 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 +3 -3
- package/dist/core/peer-seat.js +20 -8
- package/dist/core/permission-rule-consent.d.ts +21 -5
- package/dist/core/permission-rule-consent.js +21 -1
- package/dist/core/permission-rule-model.d.ts +34 -11
- package/dist/core/permission-rule-model.js +47 -10
- 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/remote-env.d.ts +74 -26
- package/dist/core/remote-env.js +20 -0
- 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/retired-keys.d.ts +4 -4
- package/dist/core/row-admission.d.ts +10 -0
- package/dist/core/row-admission.js +5 -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 -3
- package/dist/core/runner/assemble-result.js +12 -7
- 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/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 +2 -2
- package/dist/core/runner/contracts.d.ts +98 -26
- package/dist/core/runner/cross-boundary-lane.d.ts +1 -1
- 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/expire-settle.d.ts +44 -0
- package/dist/core/runner/expire-settle.js +55 -0
- package/dist/core/runner/git-status-frame.d.ts +3 -3
- package/dist/core/runner/git-status-frame.js +2 -1
- package/dist/core/runner/halt-attribution.d.ts +2 -1
- package/dist/core/runner/halt-attribution.js +2 -1
- 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/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 +28 -9
- 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 +4 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -0
- package/dist/core/runner/prepare-config-doors.js +16 -17
- 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 +9 -9
- package/dist/core/runner/prepare-delegation-surface.js +4 -5
- 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-gate-stations.d.ts +19 -14
- package/dist/core/runner/prepare-gate-stations.js +6 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -5
- package/dist/core/runner/prepare-hands-readface.js +4 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -0
- package/dist/core/runner/prepare-inherited-gate.js +3 -0
- package/dist/core/runner/prepare-lsp.d.ts +3 -0
- package/dist/core/runner/prepare-lsp.js +2 -2
- package/dist/core/runner/prepare-park-ask.d.ts +5 -2
- package/dist/core/runner/prepare-park-ask.js +4 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +10 -21
- package/dist/core/runner/prepare-policy-chain.js +16 -25
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -4
- package/dist/core/runner/prepare-prompt-inputs.js +3 -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 -7
- package/dist/core/runner/prepare-suspend-saga.js +17 -7
- package/dist/core/runner/prepare-task.d.ts +1 -1
- package/dist/core/runner/prepare-task.js +56 -28
- 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-wiring-manifest.d.ts +3 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -1
- package/dist/core/runner/prepare-workspace-restore.d.ts +5 -0
- package/dist/core/runner/prepare-workspace-restore.js +10 -6
- 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-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 +2 -0
- package/dist/core/runner/run-git-lane.js +2 -1
- package/dist/core/runner/run-harness-handlers.js +2 -2
- package/dist/core/runner/run-identity-wiring.d.ts +2 -2
- package/dist/core/runner/run-identity-wiring.js +14 -5
- package/dist/core/runner/run-leg.d.ts +3 -3
- package/dist/core/runner/run-leg.js +40 -29
- package/dist/core/runner/run-notification-lane.js +20 -2
- package/dist/core/runner/run-recovery-lanes.js +3 -2
- package/dist/core/runner/run-settle-and-teardown.js +9 -7
- 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 +27 -14
- package/dist/core/runner/runtask.d.ts +18 -3
- package/dist/core/runner/runtask.js +27 -11
- 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/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/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 -2
- 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-output-projection.d.ts +3 -3
- package/dist/core/runner/tool-output-projection.js +7 -6
- 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 +3 -2
- package/dist/core/runner/turn-attachments.js +1 -1
- 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 +24 -25
- package/dist/core/secret-env.d.ts +11 -11
- 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 +1 -1
- package/dist/core/session-policy-store.js +5 -2
- package/dist/core/session-reconcile.d.ts +3 -2
- package/dist/core/session-reconcile.js +7 -4
- package/dist/core/session-store.d.ts +2 -0
- package/dist/core/session-store.js +5 -7
- 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.js +1 -1
- 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 +30 -0
- package/dist/core/task-event.d.ts +17 -8
- package/dist/core/task-limits.d.ts +5 -0
- package/dist/core/task-notification.d.ts +89 -12
- package/dist/core/task-notification.js +87 -13
- package/dist/core/task-registry-agent.d.ts +5 -43
- package/dist/core/task-registry-agent.js +24 -51
- package/dist/core/task-registry-monitor.d.ts +1 -1
- package/dist/core/task-registry-monitor.js +15 -60
- package/dist/core/task-registry-shared.d.ts +15 -112
- package/dist/core/task-registry-shared.js +3 -41
- package/dist/core/task-registry-workflow.js +4 -21
- package/dist/core/task-registry.d.ts +19 -60
- package/dist/core/task-registry.js +19 -106
- package/dist/core/task-result.d.ts +24 -7
- 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 +10 -10
- 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 +2 -5
- 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.js +3 -2
- package/dist/core/tool-face.d.ts +2 -3
- package/dist/core/tool-name-aliases.d.ts +5 -29
- package/dist/core/tool-name-aliases.js +9 -5
- 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 +108 -18
- package/dist/core/tool-policy.js +84 -14
- package/dist/core/tool-result-store.d.ts +23 -0
- package/dist/core/tool-result-store.js +3 -2
- package/dist/core/tool-spec.d.ts +19 -6
- package/dist/core/trace.d.ts +18 -1
- package/dist/core/user-attachment.js +26 -21
- 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 +34 -9
- package/dist/engine/execution-env/node-execution-env.js +213 -21
- package/dist/engine/harness/agent-harness.d.ts +65 -18
- package/dist/engine/harness/agent-harness.js +90 -23
- package/dist/engine/harness/messages.d.ts +4 -3
- package/dist/engine/harness/messages.js +2 -2
- package/dist/engine/harness/types.d.ts +41 -7
- 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 +6 -1
- package/dist/engine/loop/agent-loop.js +20 -11
- package/dist/engine/loop/types.d.ts +12 -3
- 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 +21 -11
- package/dist/index.js +15 -7
- package/dist/internal/harness-types.d.ts +2 -0
- 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 +11 -17
- package/dist/orchestration/run-workflow-tool.js +19 -42
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-types.d.ts +2 -2
- package/dist/orchestration/workflow.d.ts +4 -0
- package/dist/orchestration/workflow.js +8 -5
- package/dist/stores/file/background-agent-store.js +18 -15
- package/dist/stores/file/checkpoint-store.js +7 -4
- package/dist/stores/file/file-history-store.js +3 -2
- package/dist/stores/file/index.d.ts +5 -3
- package/dist/stores/file/index.js +23 -8
- 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.js +42 -22
- package/dist/stores/file/memory-store.js +3 -2
- 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.js +3 -2
- package/dist/stores/file/session-store.d.ts +16 -3
- package/dist/stores/file/session-store.js +21 -20
- package/dist/stores/file/tool-result-store.d.ts +11 -0
- package/dist/stores/file/tool-result-store.js +57 -3
- package/dist/stores/file/usage-window-store.js +3 -2
- package/dist/stores/file/workflow-journal-store.d.ts +0 -2
- package/dist/stores/file/workflow-journal-store.js +3 -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/dead-cwd.d.ts +5 -5
- package/dist/tools/fs/dead-cwd.js +4 -11
- package/dist/tools/fs/fs-bash-background-text.d.ts +6 -0
- package/dist/tools/fs/fs-bash-background-text.js +6 -0
- package/dist/tools/fs/fs-bash.d.ts +3 -18
- package/dist/tools/fs/fs-bash.js +37 -124
- package/dist/tools/fs/fs-pdf.js +8 -6
- package/dist/tools/fs/fs-read.js +2 -2
- package/dist/tools/fs/fs-shared.d.ts +28 -3
- package/dist/tools/fs/fs-shared.js +15 -0
- package/dist/tools/fs/index.d.ts +1 -1
- package/dist/tools/fs/index.js +4 -14
- 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 +13 -5
- package/dist/tools/fs/read-floor.js +206 -2
- package/dist/tools/fs/search.d.ts +3 -2
- package/dist/tools/fs/search.js +6 -6
- 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 +8 -7
- package/dist/tools/monitor.js +12 -10
- package/dist/tools/worktree.d.ts +5 -1
- package/dist/tools/worktree.js +20 -17
- package/package.json +6 -3
- package/test/export-surface.snapshot.json +92 -10
- package/wire-changes/core-stores-sql@7.61.0.json +480 -0
- package/wire-changes/core@7.61.0.json +4405 -0
- package/wire-changes/mods-kernel@7.61.0.json +65 -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
package/dist/agents/subagent.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Type } from "typebox";
|
|
|
2
2
|
import { isAbsolute } from "node:path";
|
|
3
3
|
import { backgroundChildTerminal } from "../core/delegation-frames.js";
|
|
4
4
|
import { bindDelegationName } from "../core/delegation-name.js";
|
|
5
|
+
import { authoredSteerOf } from "../core/input-author.js";
|
|
5
6
|
import { principalNameOf } from "../core/principal-name.js";
|
|
6
7
|
import { resumeRefusalDetailOf, resumeStartupCauseOf } from "../core/resume-startup-cause.js";
|
|
7
8
|
import { errorCodeOf, thrownFailureOf } from "../core/runner/terminal-account.js";
|
|
@@ -35,6 +36,7 @@ import { hasSessionFork } from "../core/session.js";
|
|
|
35
36
|
import { isDurablePause, pauseFamily } from "./suspend-guard.js";
|
|
36
37
|
import { childRejection, childTerminalFace, childThrownText } from "./child-failure.js";
|
|
37
38
|
import { forwardSafely } from "../core/runner/forward-sink.js";
|
|
39
|
+
import { legTaskIdOf } from "../core/leg-identity.js";
|
|
38
40
|
import { delimitUntrusted, inlineUntrusted } from "../core/untrusted-text.js";
|
|
39
41
|
import { createSafeNotifier } from "../core/safe-notify.js";
|
|
40
42
|
import { boundedRedactedSummary } from "../core/untrusted-egress.js";
|
|
@@ -45,7 +47,7 @@ import { BG_AGENT_REAP_STOP_ERROR, chosenAgentName } from "../core/task-registry
|
|
|
45
47
|
import { readDurableOrgAdmission } from "../core/memory-admission.js";
|
|
46
48
|
import { governanceRetryClass } from "../core/governance-codes.js";
|
|
47
49
|
import { readSkillGrantCapture } from "../core/skill-grant.js";
|
|
48
|
-
import { completionResultField, oweTerminalDelivery, resolveCompletionSink,
|
|
50
|
+
import { admitsBackgroundLaunch, completionResultField, oweTerminalDelivery, resolveCompletionSink, terminalFrameFacets } from "../core/task-notification.js";
|
|
49
51
|
import { RETAIN_DEFAULT_TTL_MS, RETAIN_DEFAULT_MAX, RUNNING_AGENT_OBSERVE_EVERY_BEATS, DELEGATION_MAX_CONCURRENT_DEFAULT, DELEGATION_MAX_PER_SESSION_DEFAULT } from "../config/defaults.js";
|
|
50
52
|
function rollupDelegatedCost(stats, nested) {
|
|
51
53
|
if (stats.costMicroUsd === undefined)
|
|
@@ -78,9 +80,10 @@ import { recordRosterSpawn } from "./roster-store.js";
|
|
|
78
80
|
import { LAUNCH_RECEIPT_OWN_WORDS_CLAUSE, launchReceiptNoQuoteClause } from "./launch-receipt-contract.js";
|
|
79
81
|
import { ObserverDigestTap, ObserverPairing, createObserverReportToolSpec, markObserverTaskId, unmarkObserverTaskId, isObserverTaskId, ObserverResumeStateError, ObserverStoppedByUserError, observerFramingPrompt, observerSlug, resolveObserverDeclaration, } from "./observer.js";
|
|
80
82
|
import { SubagentStepRecorder, redactThenCut } from "./subagent-steps.js";
|
|
83
|
+
import { childOwnerKeys, parkCompletionNotify, runningBackgroundUnder } from "./subagent-completion-gate.js";
|
|
81
84
|
import { OUTPUT_TOOL_NAME, mountRuleFace, toolFace } from "../core/tool-catalog-entries.js";
|
|
82
85
|
import { canonicalNameValue } from "../core/permission-rule-model.js";
|
|
83
|
-
import { definitionAllowTools, inheritedChildPool, inheritedHostSeats, inheritedMcpDeclarations, withDefinitionServers,
|
|
86
|
+
import { definitionAllowTools, inheritedChildPool, inheritedHostSeats, inheritedMcpDeclarations, withDefinitionServers, withoutWakerSeats } from "./inherited-tool-pool.js";
|
|
84
87
|
import { readMember, thrownText } from "../core/thrown-value.js";
|
|
85
88
|
const BG_AGENT_RESULT_MAX = 4_000;
|
|
86
89
|
const BG_AGENT_RESULT_FULL_MAX = 200_000;
|
|
@@ -289,11 +292,12 @@ const isolationUnavailable = (content) => notStartedResult({
|
|
|
289
292
|
content,
|
|
290
293
|
details: { error: "isolation.unavailable" },
|
|
291
294
|
});
|
|
292
|
-
export function createSubagentWorktreeHelper(baseEnv, repoRoot) {
|
|
295
|
+
export function createSubagentWorktreeHelper(baseEnv, repoRoot, parentFloor) {
|
|
293
296
|
const handles = new Map();
|
|
297
|
+
const readFloorNow = () => { const readFloor = parentFloor(); return readFloor !== undefined ? { readFloor } : {}; };
|
|
294
298
|
return {
|
|
295
299
|
async mint(childId) {
|
|
296
|
-
const probe = await baseEnv.exec("git rev-parse --is-inside-work-tree", { cwd: repoRoot });
|
|
300
|
+
const probe = await baseEnv.exec("git rev-parse --is-inside-work-tree", { cwd: repoRoot, ...readFloorNow() });
|
|
297
301
|
if (!probe.ok || probe.value.exitCode !== 0) {
|
|
298
302
|
const detail = probe.ok ? (probe.value.stderr || probe.value.stdout).trim().split("\n")[0] : thrownText(probe.error);
|
|
299
303
|
throw Object.assign(new Error(`the working directory ${repoRoot} is not a git repository${detail ? ` (${detail})` : ""}`), { code: WORKTREE_NOT_A_REPOSITORY });
|
|
@@ -301,13 +305,14 @@ export function createSubagentWorktreeHelper(baseEnv, repoRoot) {
|
|
|
301
305
|
const { env, worktreeDir } = await addWorktree(baseEnv, {
|
|
302
306
|
repoRoot,
|
|
303
307
|
sessionId: childId,
|
|
308
|
+
readFloor: parentFloor,
|
|
304
309
|
rootEnvAt: (dir) => Object.create(baseEnv, {
|
|
305
310
|
cwd: { value: dir, configurable: true },
|
|
306
311
|
destroy: { value: undefined, writable: true, configurable: true },
|
|
307
312
|
}),
|
|
308
313
|
});
|
|
309
|
-
const baseSha = await
|
|
310
|
-
.exec("git rev-parse HEAD", { cwd: worktreeDir })
|
|
314
|
+
const baseSha = await Promise.resolve()
|
|
315
|
+
.then(() => baseEnv.exec("git rev-parse HEAD", { cwd: worktreeDir, ...readFloorNow() }))
|
|
311
316
|
.then((r) => (r.ok && r.value.exitCode === 0 ? r.value.stdout.trim() : undefined))
|
|
312
317
|
.catch(() => undefined);
|
|
313
318
|
handles.set(worktreeDir, { destroy: () => env.destroy(), baseSha });
|
|
@@ -317,13 +322,18 @@ export function createSubagentWorktreeHelper(baseEnv, repoRoot) {
|
|
|
317
322
|
const handle = handles.get(worktreeDir);
|
|
318
323
|
handles.delete(worktreeDir);
|
|
319
324
|
let changed = true;
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
try {
|
|
326
|
+
const status = await baseEnv.exec("git status --porcelain", { cwd: worktreeDir, ...readFloorNow() });
|
|
327
|
+
if (status.ok && status.value.exitCode === 0 && handle?.baseSha !== undefined) {
|
|
328
|
+
const dirtyFiles = status.value.stdout.split("\n").filter((l) => l.trim() !== "").length;
|
|
329
|
+
const ahead = await baseEnv.exec(`git rev-list --count ${shellQuote(`${handle.baseSha}..HEAD`)}`, { cwd: worktreeDir, ...readFloorNow() });
|
|
330
|
+
const commits = ahead.ok && ahead.value.exitCode === 0 ? parseInt(ahead.value.stdout.trim(), 10) || 0 : -1;
|
|
331
|
+
if (commits >= 0)
|
|
332
|
+
changed = dirtyFiles > 0 || commits > 0;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
return "kept";
|
|
327
337
|
}
|
|
328
338
|
if (changed)
|
|
329
339
|
return "kept";
|
|
@@ -344,6 +354,7 @@ const ccElapsedTag = (ms) => {
|
|
|
344
354
|
};
|
|
345
355
|
const ccCompletionText = (desc, settled, rawStatus, elapsedMs) => `Agent "${desc}" ${settled === "killed" ? "stopped" : settled === "completed" ? "finished" : rawStatus}${ccElapsedTag(elapsedMs)}`;
|
|
346
356
|
const SYNC_ESCAPE_SENTENCE = "Pass `run_in_background: false` for a synchronous run when you need the result before continuing (a named agent always runs in the background).";
|
|
357
|
+
export const AGENT_RAN_SYNC_NO_CHANNEL_NOTE = "note: this agent ran synchronously — no completion would come back from a background agent on this mount, so the background lane is not used here.";
|
|
347
358
|
function continuationSentence(toolName, durableRevival, forkOffered) {
|
|
348
359
|
return (`Where the SendMessage tool is mounted, use it with the agent's ID or name to message a RUNNING agent, or — when session retention${durableRevival ? " or durable named-agent revival" : ""} is enabled — ` +
|
|
349
360
|
`to continue a COMPLETED one with its context intact; a new ${toolName} call starts fresh${forkOffered ? ` (except subagent_type: "${FORK_SUBAGENT_TYPE}", which inherits your context)` : ""}.`);
|
|
@@ -486,6 +497,9 @@ function createBgActivityBeat(parentToolCallId, emitTick, noteActivity) {
|
|
|
486
497
|
emitTick(starts);
|
|
487
498
|
};
|
|
488
499
|
}
|
|
500
|
+
function backgroundLegFacts(taskId, cycleSeq) {
|
|
501
|
+
return { delegationTaskType: "background_agent", rowTaskId: taskId, ...(cycleSeq !== undefined ? { cycleSeq } : {}) };
|
|
502
|
+
}
|
|
489
503
|
export function markerFragment() {
|
|
490
504
|
return uuidv7().replace(/-/g, "").slice(-12);
|
|
491
505
|
}
|
|
@@ -517,7 +531,7 @@ export function createSubagentResume(deps) {
|
|
|
517
531
|
assertNoRetiredKeys(deps, RETIRED_RESUME_CLAMP_KEYS, "createSubagentResume");
|
|
518
532
|
assertClampRecord(deps.currentClamps, "createSubagentResume currentClamps");
|
|
519
533
|
const notifier = createSafeNotifier(deps.onNotifyError !== undefined ? { onError: deps.onNotifyError } : undefined);
|
|
520
|
-
const resumeAs = (
|
|
534
|
+
const resumeAs = (by) => async (content) => {
|
|
521
535
|
const ledger = deps.ledger;
|
|
522
536
|
if (!ledger) {
|
|
523
537
|
throw configError("resume unavailable: the parent run did not enable TaskSpec.retainSubagentSessions.", "resume.retain_off");
|
|
@@ -542,8 +556,9 @@ export function createSubagentResume(deps) {
|
|
|
542
556
|
entry.running = true;
|
|
543
557
|
const abort = new AbortController();
|
|
544
558
|
entry.activeAbort = abort;
|
|
559
|
+
const wakeTaskId = legTaskIdOf(entry.specSnapshot, entry.internalsSnapshot, entry.childSessionId);
|
|
545
560
|
const resumeStepRecorder = new SubagentStepRecorder(deps.parentToolCallId);
|
|
546
|
-
resumeStepRecorder.lockTo(
|
|
561
|
+
resumeStepRecorder.lockTo(wakeTaskId);
|
|
547
562
|
const resumeResidual = () => {
|
|
548
563
|
const recentSteps = resumeStepRecorder.recentSteps();
|
|
549
564
|
const editedFiles = resumeStepRecorder.editedFiles();
|
|
@@ -578,7 +593,7 @@ export function createSubagentResume(deps) {
|
|
|
578
593
|
const wakeClamps = foldClampSources(entry.specSnapshot, deps.currentClamps);
|
|
579
594
|
const resumeSpec = applyClampSeats({
|
|
580
595
|
...entry.specSnapshot,
|
|
581
|
-
objective: createResumePrompt(marker, content,
|
|
596
|
+
objective: createResumePrompt(marker, content, by.author),
|
|
582
597
|
sessionId: entry.childSessionId,
|
|
583
598
|
requireExistingSession: true,
|
|
584
599
|
...(deps.currentOnQuestion !== undefined ? { onQuestion: deps.currentOnQuestion } : {}),
|
|
@@ -646,7 +661,7 @@ export function createSubagentResume(deps) {
|
|
|
646
661
|
sessionId: entry.childSessionId,
|
|
647
662
|
...(deps.parentToolCallId !== undefined ? { parentToolCallId: deps.parentToolCallId } : {}),
|
|
648
663
|
seq: entry.cycleSeq,
|
|
649
|
-
progressTaskId:
|
|
664
|
+
progressTaskId: wakeTaskId,
|
|
650
665
|
...(currentAction !== undefined ? { currentAction } : {}),
|
|
651
666
|
...(currentTool !== undefined ? { currentTool } : {}),
|
|
652
667
|
usage: { toolUses: toolStarts },
|
|
@@ -656,7 +671,8 @@ export function createSubagentResume(deps) {
|
|
|
656
671
|
stream = childRunner.runTaskStream(resumeSpec, undefined, {
|
|
657
672
|
...entry.internalsSnapshot,
|
|
658
673
|
...inheritedHostSeats(deps.currentMcpHostSeats, resumeSpec.mcp ?? []),
|
|
659
|
-
...(
|
|
674
|
+
...(deps.currentPlacementTarget !== undefined ? { placementTarget: deps.currentPlacementTarget } : {}),
|
|
675
|
+
objectiveAuthor: by.author,
|
|
660
676
|
cycleSeq: entry.cycleSeq,
|
|
661
677
|
parentInteractionPosture: postureUnderClamps(entry.internalsSnapshot.parentInteractionPosture, { interactiveTools: resumeSpec.interactiveTools, approvalReach: resumeSpec.approvalReach }),
|
|
662
678
|
...(true
|
|
@@ -687,7 +703,7 @@ export function createSubagentResume(deps) {
|
|
|
687
703
|
...(deps.currentParentNotify !== undefined
|
|
688
704
|
? { parentNotify: deps.currentParentNotify, parentPeerRef: deps.currentParentPeerRef }
|
|
689
705
|
: {}),
|
|
690
|
-
peerInboundChainRef: createPeerInboundChainRef(
|
|
706
|
+
peerInboundChainRef: createPeerInboundChainRef(by.author === "peer" ? by.hopChain : undefined),
|
|
691
707
|
...(reviveCycle !== undefined
|
|
692
708
|
? {
|
|
693
709
|
onNotifyInjectorReady: (inject) => {
|
|
@@ -719,7 +735,7 @@ export function createSubagentResume(deps) {
|
|
|
719
735
|
entry.deferredNotify = undefined;
|
|
720
736
|
notifier.notify(() => parked.cancel(), "subagent.resume.park_cancel");
|
|
721
737
|
}
|
|
722
|
-
oweTerminalDelivery(deps.notify, { task_id:
|
|
738
|
+
oweTerminalDelivery(deps.notify, { task_id: wakeTaskId, task_type: "background_agent" });
|
|
723
739
|
let settleResolve;
|
|
724
740
|
const settled = new Promise((r) => {
|
|
725
741
|
settleResolve = r;
|
|
@@ -744,6 +760,7 @@ export function createSubagentResume(deps) {
|
|
|
744
760
|
const resumeHandbackResult = withHandbackWarning(resumeHandbackWarning, child.result);
|
|
745
761
|
const errCodeRevive = status === "failed" ? childFace.errorCode : undefined;
|
|
746
762
|
const errClassRevive = status === "failed" ? classifySubagentError({ kind: "failed", ...(childFace.errorCode !== undefined ? { code: childFace.errorCode } : {}) }) : undefined;
|
|
763
|
+
let completionIdRevive;
|
|
747
764
|
if (reviveCycle !== undefined && deps.registry !== undefined && deps.taskId !== undefined) {
|
|
748
765
|
try {
|
|
749
766
|
const winner = deps.registry.settleRevivedAgent(deps.taskId, reviveCycle, {
|
|
@@ -753,14 +770,15 @@ export function createSubagentResume(deps) {
|
|
|
753
770
|
...(errCodeRevive !== undefined ? { errorCode: errCodeRevive } : {}),
|
|
754
771
|
...(errClassRevive !== undefined ? { retryable: errClassRevive.retryable, errorKind: errClassRevive.errorKind } : {}),
|
|
755
772
|
});
|
|
756
|
-
if (winner !== undefined)
|
|
773
|
+
if (winner !== undefined) {
|
|
757
774
|
status = winner;
|
|
775
|
+
completionIdRevive = deps.registry.getCompletionId(deps.taskId);
|
|
776
|
+
}
|
|
758
777
|
}
|
|
759
778
|
catch {
|
|
760
779
|
}
|
|
761
780
|
}
|
|
762
781
|
const stoppedByRevive = status === "killed" ? deps.registry?.getStopAttribution(deps.taskId ?? "") ?? "system" : undefined;
|
|
763
|
-
const completionIdRevive = deps.registry?.getCompletionId(deps.taskId ?? "");
|
|
764
782
|
const reviveName = deps.rowDescription ?? `sub-agent ${marker}`;
|
|
765
783
|
const failReasonRevive = status === "failed" ? childFace.errorMessage : undefined;
|
|
766
784
|
const reviveElapsedMs = Date.now() - reviveStartedAt;
|
|
@@ -778,11 +796,12 @@ export function createSubagentResume(deps) {
|
|
|
778
796
|
named: deps.rowName !== undefined,
|
|
779
797
|
});
|
|
780
798
|
const ownsTerminalFacesRevive = deps.registry !== undefined && deps.taskId !== undefined ? deps.registry.claimAgentTerminalNotify(deps.taskId) : true;
|
|
781
|
-
const resumeResultField = await completionResultField(resumeHandbackResult, (report) => persistTaskArtifact(deps.currentTaskArtifacts,
|
|
782
|
-
|
|
783
|
-
|
|
799
|
+
const resumeResultField = await completionResultField(resumeHandbackResult, (report) => persistTaskArtifact(deps.currentTaskArtifacts, wakeTaskId, report), (ref) => {
|
|
800
|
+
if (deps.taskId !== undefined)
|
|
801
|
+
deps.registry?.recordArtifactRef(deps.taskId, ref, completionIdRevive);
|
|
802
|
+
}, notifier);
|
|
784
803
|
const resumeFrame = {
|
|
785
|
-
task_id:
|
|
804
|
+
task_id: wakeTaskId,
|
|
786
805
|
...(entry.childSessionId !== undefined ? { sessionId: entry.childSessionId } : {}),
|
|
787
806
|
task_type: "background_agent",
|
|
788
807
|
toolUseId: deps.parentToolCallId,
|
|
@@ -803,15 +822,15 @@ export function createSubagentResume(deps) {
|
|
|
803
822
|
};
|
|
804
823
|
if (ownsTerminalFacesRevive)
|
|
805
824
|
reviveEmit?.(backgroundChildTerminal(resumeFrame, { taskId: deps.taskId, sessionScoped: deps.sessionScoped === true, sessionId: entry.childSessionId, transcriptId: entry.childSessionId, ...(deps.parentToolCallId !== undefined ? { parentToolCallId: deps.parentToolCallId } : {}) }));
|
|
806
|
-
const
|
|
807
|
-
? entry.childSessionId
|
|
808
|
-
:
|
|
809
|
-
const aliveBgCount =
|
|
810
|
-
if (
|
|
825
|
+
const gateOwners = ownsTerminalFacesRevive && status === "completed" && deps.notify !== undefined && deps.registry !== undefined && ledger.get(deps.parentToolCallId) === entry
|
|
826
|
+
? childOwnerKeys(child.taskId, entry.childSessionId)
|
|
827
|
+
: [];
|
|
828
|
+
const aliveBgCount = deps.registry !== undefined ? runningBackgroundUnder(deps.registry, gateOwners) : 0;
|
|
829
|
+
if (aliveBgCount > 0) {
|
|
811
830
|
parkCompletionNotify({
|
|
812
831
|
registry: deps.registry,
|
|
813
832
|
entry,
|
|
814
|
-
|
|
833
|
+
owners: gateOwners,
|
|
815
834
|
pendingCount: aliveBgCount,
|
|
816
835
|
payload: resumeFrame,
|
|
817
836
|
notify: deps.notify,
|
|
@@ -829,24 +848,26 @@ export function createSubagentResume(deps) {
|
|
|
829
848
|
const msgRevive = childThrownText(e);
|
|
830
849
|
const errCodeReviveReject = abort.signal.aborted ? undefined : thrownErrorCode(e);
|
|
831
850
|
const errClassReviveReject = abort.signal.aborted ? undefined : classifySubagentError({ kind: "failed", ...(errCodeReviveReject !== undefined ? { code: errCodeReviveReject } : {}) });
|
|
851
|
+
let completionIdRejectRevive;
|
|
832
852
|
if (reviveCycle !== undefined && deps.registry !== undefined && deps.taskId !== undefined) {
|
|
833
853
|
try {
|
|
834
|
-
deps.registry.settleRevivedAgent(deps.taskId, reviveCycle, {
|
|
854
|
+
const winnerReject = deps.registry.settleRevivedAgent(deps.taskId, reviveCycle, {
|
|
835
855
|
status: abort.signal.aborted ? "killed" : "failed",
|
|
836
856
|
error: msgRevive.slice(0, 500),
|
|
837
857
|
...(errCodeReviveReject !== undefined ? { errorCode: errCodeReviveReject } : {}),
|
|
838
858
|
...(errClassReviveReject !== undefined ? { retryable: errClassReviveReject.retryable, errorKind: errClassReviveReject.errorKind } : {}),
|
|
839
859
|
});
|
|
860
|
+
if (winnerReject !== undefined)
|
|
861
|
+
completionIdRejectRevive = deps.registry.getCompletionId(deps.taskId);
|
|
840
862
|
}
|
|
841
863
|
catch {
|
|
842
864
|
}
|
|
843
865
|
}
|
|
844
866
|
const stoppedByReject = abort.signal.aborted ? deps.registry?.getStopAttribution(deps.taskId ?? "") ?? "system" : undefined;
|
|
845
|
-
const completionIdRejectRevive = deps.registry?.getCompletionId(deps.taskId ?? "");
|
|
846
867
|
const rejectName = deps.rowDescription ?? `sub-agent ${marker}`;
|
|
847
868
|
const ownsTerminalFacesReviveReject = deps.registry !== undefined && deps.taskId !== undefined ? deps.registry.claimAgentTerminalNotify(deps.taskId) : true;
|
|
848
869
|
const reviveRejectFrame = {
|
|
849
|
-
task_id:
|
|
870
|
+
task_id: wakeTaskId,
|
|
850
871
|
...(entry.childSessionId !== undefined ? { sessionId: entry.childSessionId } : {}),
|
|
851
872
|
task_type: "background_agent",
|
|
852
873
|
toolUseId: deps.parentToolCallId,
|
|
@@ -878,39 +899,8 @@ export function createSubagentResume(deps) {
|
|
|
878
899
|
})();
|
|
879
900
|
return marker;
|
|
880
901
|
};
|
|
881
|
-
const operatorResume = resumeAs(
|
|
882
|
-
return deps.peerOrigin === undefined ? operatorResume : resumeAs(deps.peerOrigin);
|
|
883
|
-
}
|
|
884
|
-
function parkCompletionNotify(deps) {
|
|
885
|
-
const { registry, entry, owner, pendingCount, payload, notify } = deps;
|
|
886
|
-
let done = false;
|
|
887
|
-
const deliver = (decorated) => {
|
|
888
|
-
if (done)
|
|
889
|
-
return;
|
|
890
|
-
done = true;
|
|
891
|
-
unsubscribe();
|
|
892
|
-
if (entry.deferredNotify?.cancel === cancel)
|
|
893
|
-
entry.deferredNotify = undefined;
|
|
894
|
-
try {
|
|
895
|
-
notify(decorated
|
|
896
|
-
? {
|
|
897
|
-
...payload,
|
|
898
|
-
summary: `${payload.summary} (delivered after ${pendingCount} background ${pendingCount === 1 ? "child" : "children"} settled)`,
|
|
899
|
-
}
|
|
900
|
-
: payload, { priority: "next" });
|
|
901
|
-
}
|
|
902
|
-
catch {
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
const unsubscribe = registry.onBackgroundQuiescence(owner, (reason) => deliver(reason === "quiescent"));
|
|
906
|
-
const cancel = () => {
|
|
907
|
-
if (done)
|
|
908
|
-
return;
|
|
909
|
-
done = true;
|
|
910
|
-
unsubscribe();
|
|
911
|
-
retireTerminalDelivery(notify, payload);
|
|
912
|
-
};
|
|
913
|
-
entry.deferredNotify = { ...(payload.seq !== undefined ? { seq: payload.seq } : {}), cancel, flush: () => deliver(false) };
|
|
902
|
+
const operatorResume = resumeAs({ author: "operator" });
|
|
903
|
+
return deps.peerOrigin === undefined ? operatorResume : resumeAs({ author: "peer", hopChain: deps.peerOrigin.hopChain });
|
|
914
904
|
}
|
|
915
905
|
export function resolveDelegationEntryCaps(caps) {
|
|
916
906
|
const bad = (member, value) => {
|
|
@@ -1121,16 +1111,24 @@ async function untilAbort(p, signal) {
|
|
|
1121
1111
|
signal.removeEventListener("abort", onAbort);
|
|
1122
1112
|
}
|
|
1123
1113
|
}
|
|
1114
|
+
const delegationPoolKey = (scope, root) => JSON.stringify([scope, root]);
|
|
1115
|
+
function delegationEntryPool(seat) {
|
|
1116
|
+
if (seat.root === undefined)
|
|
1117
|
+
return { key: undefined, occupy: () => noopRelease };
|
|
1118
|
+
const key = delegationPoolKey(seat.scope ?? DELEGATION_POOL_DEFAULT_SCOPE, seat.root);
|
|
1119
|
+
return { key, occupy: (kind) => (kind === "local" ? chargeLocalDelegationInFlight(seat.poolAnchor, key) : noopRelease) };
|
|
1120
|
+
}
|
|
1124
1121
|
async function openDelegationEntryGate(input) {
|
|
1125
|
-
const { poolAnchor, registry, store, root, caps,
|
|
1122
|
+
const { poolAnchor, registry, store, root, caps, signal } = input;
|
|
1123
|
+
const pool = delegationEntryPool(input);
|
|
1126
1124
|
if (root === undefined)
|
|
1127
|
-
return {
|
|
1125
|
+
return { ...pool, admit: () => ({ admitted: true, release: noopRelease }) };
|
|
1128
1126
|
const scope = input.scope ?? DELEGATION_POOL_DEFAULT_SCOPE;
|
|
1129
|
-
const key =
|
|
1130
|
-
const occupy =
|
|
1127
|
+
const key = delegationPoolKey(scope, root);
|
|
1128
|
+
const { occupy } = pool;
|
|
1131
1129
|
let storedHandles = [];
|
|
1132
1130
|
let storedEnumerationOk = false;
|
|
1133
|
-
if (store !== undefined
|
|
1131
|
+
if (store !== undefined) {
|
|
1134
1132
|
try {
|
|
1135
1133
|
storedHandles = (await untilAbort(store.listBySession(scope, root), signal)).map((r) => r.handle);
|
|
1136
1134
|
storedEnumerationOk = true;
|
|
@@ -1153,39 +1151,37 @@ async function openDelegationEntryGate(input) {
|
|
|
1153
1151
|
},
|
|
1154
1152
|
};
|
|
1155
1153
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
retained = new Set([...storedHandles, ...ledger]).size;
|
|
1166
|
-
}
|
|
1167
|
-
else {
|
|
1168
|
-
const survivors = new Set(storedHandles);
|
|
1169
|
-
for (const h of ledger)
|
|
1170
|
-
if (keep.has(h))
|
|
1171
|
-
survivors.add(h);
|
|
1172
|
-
retained = survivors.size;
|
|
1173
|
-
}
|
|
1154
|
+
const ledger = delegationEntryLedger(poolAnchor, key);
|
|
1155
|
+
let retained;
|
|
1156
|
+
if (store !== undefined && storedEnumerationOk) {
|
|
1157
|
+
const keep = new Set([...storedHandles, ...active]);
|
|
1158
|
+
if (kind === "registered") {
|
|
1159
|
+
for (const h of [...ledger])
|
|
1160
|
+
if (!keep.has(h))
|
|
1161
|
+
ledger.delete(h);
|
|
1162
|
+
retained = new Set([...storedHandles, ...ledger]).size;
|
|
1174
1163
|
}
|
|
1175
1164
|
else {
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
admitted: false,
|
|
1182
|
-
refusal: {
|
|
1183
|
-
code: "delegation.session_cap",
|
|
1184
|
-
text: `this session tree has already launched ${cumulative} agents in its retained window — the cumulative cap (${caps.maxCumulativePerSession}; RunnerDeps.delegationEntryCaps.maxCumulativePerSession) refuses more. Continue an existing agent (SendMessage) instead of launching new ones.`,
|
|
1185
|
-
},
|
|
1186
|
-
};
|
|
1165
|
+
const survivors = new Set(storedHandles);
|
|
1166
|
+
for (const h of ledger)
|
|
1167
|
+
if (keep.has(h))
|
|
1168
|
+
survivors.add(h);
|
|
1169
|
+
retained = survivors.size;
|
|
1187
1170
|
}
|
|
1188
1171
|
}
|
|
1172
|
+
else {
|
|
1173
|
+
retained = ledger.size;
|
|
1174
|
+
}
|
|
1175
|
+
const cumulative = retained + local;
|
|
1176
|
+
if (cumulative >= caps.maxCumulativePerSession) {
|
|
1177
|
+
return {
|
|
1178
|
+
admitted: false,
|
|
1179
|
+
refusal: {
|
|
1180
|
+
code: "delegation.session_cap",
|
|
1181
|
+
text: `this session tree has already launched ${cumulative} agents in its retained window — the cumulative cap (${caps.maxCumulativePerSession}; RunnerDeps.delegationEntryCaps.maxCumulativePerSession) refuses more. Continue an existing agent (SendMessage) instead of launching new ones.`,
|
|
1182
|
+
},
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1189
1185
|
return { admitted: true, release: occupy(kind) };
|
|
1190
1186
|
};
|
|
1191
1187
|
return { key, admit, occupy };
|
|
@@ -1271,13 +1267,9 @@ export function asyncLaunchedReceipt(p) {
|
|
|
1271
1267
|
const noteLines = (p.notes ?? []).filter((n) => n !== undefined && n !== "");
|
|
1272
1268
|
return (`Async agent launched successfully. (${launchReceiptNoQuoteClause(", including the task_id below,")})\n` +
|
|
1273
1269
|
`task_id: ${p.taskId} (internal ID - do not mention to user. ${launchContinuationSentence(p.taskId)})\n` +
|
|
1274
|
-
|
|
1275
|
-
? `${p.workingLine} You will be notified automatically when it completes. You know nothing about its results until that notification arrives — do not report, assume, or predict them; continue other work or respond to the user in the meantime.\n`
|
|
1276
|
-
: `${p.workingLine} Its result is NOT pushed automatically — retrieve progress and results with TaskOutput(task_id) where mounted.\n`) +
|
|
1270
|
+
`${p.workingLine} You will be notified automatically when it completes. You know nothing about its results until that notification arrives — do not report, assume, or predict them; continue other work or respond to the user in the meantime.\n` +
|
|
1277
1271
|
noteLines.map((n) => `${n}\n`).join("") +
|
|
1278
|
-
|
|
1279
|
-
? `${LAUNCH_RECEIPT_OWN_WORDS_CLAUSE} Agent results will arrive in a subsequent message. If the user asks for progress, say the agent is still running.`
|
|
1280
|
-
: `${LAUNCH_RECEIPT_OWN_WORDS_CLAUSE} The result will NOT arrive on its own — retrieve it with TaskOutput(task_id) where mounted before relying on it.`));
|
|
1272
|
+
`${LAUNCH_RECEIPT_OWN_WORDS_CLAUSE} Agent results will arrive in a subsequent message. If the user asks for progress, say the agent is still running.`);
|
|
1281
1273
|
}
|
|
1282
1274
|
function runnerModelCatalog(runner) {
|
|
1283
1275
|
try {
|
|
@@ -1447,7 +1439,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1447
1439
|
: `- Each agent type's model, thinking level, and tools come from its agent definition.\n`) +
|
|
1448
1440
|
`- \`isolation: "worktree"\` gives the agent its own git worktree (auto-cleaned if unchanged).` +
|
|
1449
1441
|
(opts.background
|
|
1450
|
-
? `\n- Subagents run in the background by default
|
|
1442
|
+
? `\n- Subagents run in the background by default; you'll be notified when one completes. ${SYNC_ESCAPE_SENTENCE} Never fabricate or predict a pending agent's results — the notification is never something you write yourself; if the user asks before it arrives, say it's still running.\n` +
|
|
1451
1443
|
`- ${continuationSentence(opts.name ?? DEFAULT_SUBAGENT_TOOL_NAME, opts.background.agentStore !== undefined, forkOffered)}`
|
|
1452
1444
|
: `\n- \`run_in_background\` is unavailable here — only synchronous subagents.`),
|
|
1453
1445
|
descriptionVariants: [{ id: "classic", traits: { noneOf: ["lean_prompt"] }, text: `Launch a new agent. Delegate a self-contained subtask to an isolated sub-agent and get back a single report. ` +
|
|
@@ -1476,11 +1468,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1476
1468
|
`\nSet isolation: "worktree" to give the agent its own detached git worktree (auto-removed if it made no changes; kept for you to inspect/merge when it did).` +
|
|
1477
1469
|
(opts.background
|
|
1478
1470
|
?
|
|
1479
|
-
|
|
1480
|
-
? `\n\nAgents run in the background by default. When an agent runs in the background, you will be automatically notified when it completes — do NOT sleep, poll, or proactively check on its progress. Continue with other work or respond to the user instead. ${SYNC_ESCAPE_SENTENCE}`
|
|
1481
|
-
: `\n\nAgents run in the background by default. A background agent's result is not pushed automatically — the launch receipt's task_id retrieves progress and results via the TaskOutput tool where mounted. ${SYNC_ESCAPE_SENTENCE}`) +
|
|
1471
|
+
`\n\nAgents run in the background by default. When an agent runs in the background, you will be automatically notified when it completes — do NOT sleep, poll, or proactively check on its progress. Continue with other work or respond to the user instead. ${SYNC_ESCAPE_SENTENCE}` +
|
|
1482
1472
|
` ${continuationSentence(opts.name ?? DEFAULT_SUBAGENT_TOOL_NAME, opts.background.agentStore !== undefined, forkOffered)}` +
|
|
1483
|
-
`\n\n**Don't race.** After launching, you know nothing about what the agent found. Never fabricate or predict agent results in any format — not as prose, summary, or structured output.
|
|
1473
|
+
`\n\n**Don't race.** After launching, you know nothing about what the agent found. Never fabricate or predict agent results in any format — not as prose, summary, or structured output. The notification arrives as a user-role message in a later turn; it is never something you write yourself.`
|
|
1484
1474
|
: `\n\nThe run_in_background parameter is not available in this context. Only synchronous subagents are supported.`) }],
|
|
1485
1475
|
parameters: Type.Object({
|
|
1486
1476
|
subagent_type: Type.Optional(Type.String({ description: "The type of specialized agent to use for this task" })),
|
|
@@ -1507,9 +1497,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1507
1497
|
...(opts.background
|
|
1508
1498
|
? {
|
|
1509
1499
|
run_in_background: Type.Optional(Type.Boolean({
|
|
1510
|
-
description:
|
|
1511
|
-
? "Agents run in the background by default; you will be notified when one completes. Set to false to run this agent synchronously when you need its result before continuing (a named agent always runs in the background)."
|
|
1512
|
-
: "Agents run in the background by default; the launch receipt's task_id retrieves progress and results via the TaskOutput tool where mounted. Set to false to run this agent synchronously when you need its result before continuing (a named agent always runs in the background).",
|
|
1500
|
+
description: "Agents run in the background by default; you will be notified when one completes. Set to false to run this agent synchronously when you need its result before continuing (a named agent always runs in the background).",
|
|
1513
1501
|
})),
|
|
1514
1502
|
}
|
|
1515
1503
|
: {}),
|
|
@@ -1523,10 +1511,12 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1523
1511
|
const a = canonicalSubagentTypeArgs(args, acceptedSubagentTypes(), generalPurposeShadowed);
|
|
1524
1512
|
const parentSpecSeat = parentSpecSeatOfCtx(ctx);
|
|
1525
1513
|
const reviveClaim = ctx.reviveClaim;
|
|
1526
|
-
|
|
1514
|
+
const backgroundSink = opts.background !== undefined ? resolveCompletionSink(ctx.onTaskNotification, opts.background.notify) : undefined;
|
|
1515
|
+
const backgroundLane = opts.background !== undefined && admitsBackgroundLaunch(backgroundSink);
|
|
1516
|
+
if (reviveClaim !== undefined && !backgroundLane) {
|
|
1527
1517
|
return notStartedResult({
|
|
1528
1518
|
isError: true,
|
|
1529
|
-
content: "Sub-agent not revived: this delegation tool has no background surface
|
|
1519
|
+
content: "Sub-agent not revived: no background lane is available here (this delegation tool has no background surface, or no completion would come back from a background agent on this mount), and a revival is a background run by definition.",
|
|
1530
1520
|
details: { error: "revive.no_background" },
|
|
1531
1521
|
});
|
|
1532
1522
|
}
|
|
@@ -1584,7 +1574,14 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1584
1574
|
});
|
|
1585
1575
|
}
|
|
1586
1576
|
}
|
|
1587
|
-
const
|
|
1577
|
+
const backgroundAsked = opts.background !== undefined && (a.run_in_background !== false || def?.background === true || agentName !== undefined);
|
|
1578
|
+
const wantsBackground = backgroundLane && backgroundAsked;
|
|
1579
|
+
const ranSyncNote = backgroundAsked && !backgroundLane ? AGENT_RAN_SYNC_NO_CHANNEL_NOTE : undefined;
|
|
1580
|
+
const stations = reviveClaim === undefined ? ctx.agentStations : undefined;
|
|
1581
|
+
const extensionSpawn = stations?.extensionSpawn(ctx.toolCallId);
|
|
1582
|
+
if (extensionSpawn !== undefined && !wantsBackground) {
|
|
1583
|
+
return notStartedResult({ isError: true, content: `Sub-agent not started: an extension's spawn runs in the background, and this one would hold the foreground (${backgroundLane ? "the call as it was let go asks to run in the foreground" : "this delegation tool has no background lane here"}).`, details: { error: "mods.spawn_foreground" } });
|
|
1584
|
+
}
|
|
1588
1585
|
if (a.cwd !== undefined && typeof a.cwd !== "string") {
|
|
1589
1586
|
return notStartedResult({ isError: true, content: "Sub-agent not started: cwd must be an absolute path string.", details: { error: "cwd.relative" } });
|
|
1590
1587
|
}
|
|
@@ -1745,8 +1742,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1745
1742
|
details: { error: "skill_grants.unreadable" },
|
|
1746
1743
|
});
|
|
1747
1744
|
}
|
|
1748
|
-
|
|
1749
|
-
if (stations?.listens("agent.offer") === true) {
|
|
1745
|
+
if (extensionSpawn === undefined && stations?.listens("agent.offer") === true) {
|
|
1750
1746
|
const listed = agentListing.find((entry) => entry.name === spawnAgentType);
|
|
1751
1747
|
const offered = await stations.offered([{ name: spawnAgentType, description: listed?.description ?? "" }], ctx.signal);
|
|
1752
1748
|
if (offered.length === 0) {
|
|
@@ -1947,13 +1943,13 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1947
1943
|
pendingTrigger = [];
|
|
1948
1944
|
return joined;
|
|
1949
1945
|
};
|
|
1950
|
-
const injectObservedRequest = async (text,
|
|
1946
|
+
const injectObservedRequest = async (text, author) => {
|
|
1951
1947
|
const steer = observedSteerRef.steer;
|
|
1952
1948
|
if (!steer)
|
|
1953
1949
|
throw new Error("observed child has no steer lane (report undeliverable)");
|
|
1954
|
-
if (
|
|
1950
|
+
if (author !== "observer")
|
|
1955
1951
|
pendingTrigger.push(text);
|
|
1956
|
-
await steer(text);
|
|
1952
|
+
await steer(author, text);
|
|
1957
1953
|
};
|
|
1958
1954
|
if (observerArm) {
|
|
1959
1955
|
pendingTrigger.push(prompt);
|
|
@@ -2004,7 +2000,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2004
2000
|
...(parentGate.shellGate !== undefined ? { shellGate: parentGate.shellGate } : {}),
|
|
2005
2001
|
admittedOrgScopes: parentGate.admittedOrgScopes,
|
|
2006
2002
|
};
|
|
2007
|
-
const observerInternals = { ...(ctx.interactionPosture !== undefined ? { parentInteractionPosture: ctx.interactionPosture } : {}), ...(pickedRef !== undefined ? { inheritedModelRef: pickedRef } : {}), ...(observerGate !== undefined ? { inheritedGate: observerGate } : {}), toolCeiling: [...childCeiling, childOwnLayer], observerLeg: true };
|
|
2003
|
+
const observerInternals = { ...(ctx.interactionPosture !== undefined ? { parentInteractionPosture: ctx.interactionPosture } : {}), ...(pickedRef !== undefined ? { inheritedModelRef: pickedRef } : {}), ...(observerGate !== undefined ? { inheritedGate: observerGate } : {}), toolCeiling: [...childCeiling, childOwnLayer], observerLeg: true, objectiveAuthor: "observer" };
|
|
2008
2004
|
const r = await opts.runner.runTask(spec, observerInternals);
|
|
2009
2005
|
if (r.terminal.kind !== "completed") {
|
|
2010
2006
|
const endedFace = childTerminalFace(r.terminal);
|
|
@@ -2146,16 +2142,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2146
2142
|
const entryCapRoot = reviveClaim !== undefined
|
|
2147
2143
|
? (reviveClaim.row.rootSessionId ?? reviveClaim.row.parentSessionId ?? (reviveClaim.row.sessionScoped ? reviveClaim.row.owner : undefined))
|
|
2148
2144
|
: (ctx.rootSessionId ?? ctx.sessionId);
|
|
2149
|
-
const
|
|
2150
|
-
|
|
2151
|
-
registry: opts.background?.registry,
|
|
2152
|
-
store: opts.background?.agentStore,
|
|
2153
|
-
scope: treeScope,
|
|
2154
|
-
root: entryCapRoot,
|
|
2155
|
-
caps: entryCaps,
|
|
2156
|
-
revival: reviveClaim !== undefined,
|
|
2157
|
-
signal: ctx.signal,
|
|
2158
|
-
});
|
|
2145
|
+
const entryPoolSeat = { poolAnchor: entryCapPoolAnchor, scope: treeScope, root: entryCapRoot };
|
|
2146
|
+
const openEntryGate = () => openDelegationEntryGate({ ...entryPoolSeat, registry: opts.background?.registry, store: opts.background?.agentStore, caps: entryCaps, signal: ctx.signal });
|
|
2159
2147
|
const provenanceRequest = ctx.delegationProvenanceForChildren?.();
|
|
2160
2148
|
const childProvenanceRef = provenanceRequest !== undefined ? { current: newDelegationProvenanceAggregate() } : undefined;
|
|
2161
2149
|
const childAttestation = (completed) => childProvenanceRef !== undefined ? reduceDelegationAttestation(childProvenanceRef.current, { completed }) : undefined;
|
|
@@ -2188,6 +2176,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2188
2176
|
peerInboundChainRef: createPeerInboundChainRef(reviveClaim?.peerSeed?.hopChain),
|
|
2189
2177
|
...(childDefaultPersona !== undefined ? { defaultSystemPrompt: childDefaultPersona } : {}),
|
|
2190
2178
|
isDelegatedChild: true,
|
|
2179
|
+
objectiveAuthor: reviveClaim !== undefined ? "peer" : "parent_model",
|
|
2191
2180
|
...(childPosture !== undefined ? { parentInteractionPosture: childPosture } : {}),
|
|
2192
2181
|
...(reviveClaim === undefined
|
|
2193
2182
|
? {
|
|
@@ -2232,6 +2221,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2232
2221
|
...(ctx.subagentRetain !== undefined ? { parentRetainLedger: ctx.subagentRetain } : {}),
|
|
2233
2222
|
onForwardEvent: recordingForward,
|
|
2234
2223
|
...(ctx.parentCwd !== undefined ? { callerRoot: ctx.parentCwd } : {}),
|
|
2224
|
+
...(ctx.placementTarget !== undefined ? { placementTarget: ctx.placementTarget } : {}),
|
|
2235
2225
|
...(worktreeDir !== undefined
|
|
2236
2226
|
? { parentCwd: worktreeDir, worktreeOffered: true, onWorkspaceResolved: (ws) => void (childPlacement = ws) }
|
|
2237
2227
|
: childCwd !== undefined
|
|
@@ -2318,7 +2308,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2318
2308
|
...(plainSpec.alwaysLoadTools !== undefined ? { alwaysLoadTools: [...plainSpec.alwaysLoadTools] } : {}),
|
|
2319
2309
|
...(Array.isArray(plainSpec.restoreGatedTools) ? { restoreGatedTools: [...plainSpec.restoreGatedTools] } : {}),
|
|
2320
2310
|
}),
|
|
2321
|
-
internalsSnapshot: { ...
|
|
2311
|
+
internalsSnapshot: { ...withoutWakerSeats(childInternals), ...retainStrip.internalsFlag, ...(internalsExtra ?? {}) },
|
|
2322
2312
|
release: releaseEntry,
|
|
2323
2313
|
});
|
|
2324
2314
|
if (entry) {
|
|
@@ -2387,7 +2377,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2387
2377
|
...(plainSpec.alwaysLoadTools !== undefined ? { alwaysLoadTools: [...plainSpec.alwaysLoadTools] } : {}),
|
|
2388
2378
|
...(Array.isArray(plainSpec.restoreGatedTools) ? { restoreGatedTools: [...plainSpec.restoreGatedTools] } : {}),
|
|
2389
2379
|
}),
|
|
2390
|
-
internalsSnapshot: { ...
|
|
2380
|
+
internalsSnapshot: { ...withoutWakerSeats(childInternals), ...failedRetainStrip.internalsFlag },
|
|
2391
2381
|
release: releaseChild,
|
|
2392
2382
|
});
|
|
2393
2383
|
if (entry) {
|
|
@@ -2489,7 +2479,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2489
2479
|
const forkObjective = `${FORK_DIRECTIVE_FRAME}${prompt}${forkWorktreeNote !== undefined ? `\n\n${forkWorktreeNote}` : ""}${parentSpecSeat?.advisorModel !== undefined ? `\n\n${ADVISOR_FORK_SENTENCE}` : ""}`;
|
|
2490
2480
|
if (wantsBackground) {
|
|
2491
2481
|
const bg = opts.background;
|
|
2492
|
-
const notify =
|
|
2482
|
+
const notify = backgroundSink;
|
|
2493
2483
|
const abort = new AbortController();
|
|
2494
2484
|
const sessionScopedBg = ctx.backgroundScope === "session" && ctx.sessionId !== undefined;
|
|
2495
2485
|
const onHostAbort = () => abort.abort();
|
|
@@ -2604,6 +2594,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2604
2594
|
oweTerminalDelivery(notify, { task_id: taskId, task_type: "background_agent" });
|
|
2605
2595
|
childInternals.peerSelfRef?.addAxis("h", taskId);
|
|
2606
2596
|
bg.registry.bindBackgroundAgentSession(taskId, forkedId);
|
|
2597
|
+
stepRecorder.lockTo(taskId);
|
|
2607
2598
|
const forkBgHangAt = Date.now();
|
|
2608
2599
|
bg.registry.attachAgentTerminalNotifier(taskId, () => {
|
|
2609
2600
|
const stoppedByReap = bg.registry.getStopAttribution(taskId) ?? "system";
|
|
@@ -2621,7 +2612,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2621
2612
|
...(completionIdReap !== undefined ? { completionId: completionIdReap } : {}),
|
|
2622
2613
|
};
|
|
2623
2614
|
sinkEmit(backgroundChildTerminal(reapFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId, ...(seqReap !== undefined ? { generation: seqReap } : {}) }));
|
|
2624
|
-
notifier.notify(() => notify
|
|
2615
|
+
notifier.notify(() => notify(reapFrame, { priority: "next" }), "subagent.reapTerminalNotify");
|
|
2625
2616
|
});
|
|
2626
2617
|
if (agentName !== undefined) {
|
|
2627
2618
|
recordRosterSpawn(ctx.roster, { name: agentName, agentId: taskId, sessionId: forkedId, toolUseId: ctx.toolCallId, owner: bgOwner, scope: bgScope, ...(rowModelKey !== undefined ? { model: rowModelKey } : {}), ...(modelFallback !== undefined ? { modelFallback } : {}), ...((ctx.rootSessionId ?? ctx.sessionId) !== undefined ? { rootSessionId: ctx.rootSessionId ?? ctx.sessionId } : {}), ...(sessionScopedBg ? { sessionScoped: true } : {}), createdAt: Date.now() }, (err) => opts.onObserverError?.(err, { site: "roster.recordSpawn" }));
|
|
@@ -2671,7 +2662,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2671
2662
|
transcriptId: forkedId,
|
|
2672
2663
|
sessionId: forkedId,
|
|
2673
2664
|
parentToolCallId: ctx.toolCallId,
|
|
2674
|
-
progressTaskId:
|
|
2665
|
+
progressTaskId: taskId,
|
|
2675
2666
|
agentType: spawnAgentType,
|
|
2676
2667
|
...(spawnModel !== undefined ? { model: spawnModel } : {}),
|
|
2677
2668
|
...(bgForkCycleSeq !== undefined ? { seq: bgForkCycleSeq } : {}),
|
|
@@ -2685,8 +2676,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2685
2676
|
...forkInternals,
|
|
2686
2677
|
...(forkQuestionStrip !== undefined ? forkQuestionStrip.internalsFlag : {}),
|
|
2687
2678
|
onNotifyInjectorReady: s2ForkNotifyReady,
|
|
2688
|
-
|
|
2689
|
-
...(bgForkCycleSeq !== undefined ? { cycleSeq: bgForkCycleSeq } : {}),
|
|
2679
|
+
...backgroundLegFacts(taskId, bgForkCycleSeq),
|
|
2690
2680
|
onForwardEvent: (e) => {
|
|
2691
2681
|
try {
|
|
2692
2682
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -2721,8 +2711,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2721
2711
|
...forkInternals,
|
|
2722
2712
|
...(forkQuestionStrip !== undefined ? forkQuestionStrip.internalsFlag : {}),
|
|
2723
2713
|
onNotifyInjectorReady: s2ForkNotifyReady,
|
|
2724
|
-
|
|
2725
|
-
...(bgForkCycleSeq !== undefined ? { cycleSeq: bgForkCycleSeq } : {}),
|
|
2714
|
+
...backgroundLegFacts(taskId, bgForkCycleSeq),
|
|
2726
2715
|
onForwardEvent: (e) => {
|
|
2727
2716
|
try {
|
|
2728
2717
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -2732,8 +2721,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2732
2721
|
bgForkActivityBeat(e);
|
|
2733
2722
|
},
|
|
2734
2723
|
};
|
|
2735
|
-
|
|
2736
|
-
|
|
2724
|
+
const bgForkChild = opts.runner.runTask(bgForkSpec, bgForkInternals);
|
|
2725
|
+
extensionSpawn?.launched(taskId, spawnModel);
|
|
2726
|
+
void bgForkChild
|
|
2737
2727
|
.then(async (child) => {
|
|
2738
2728
|
const childFace = childTerminalFace(child.terminal);
|
|
2739
2729
|
settleForkRow(child.terminal);
|
|
@@ -2764,16 +2754,17 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2764
2754
|
const failedFork = !okBg && !reapedBg;
|
|
2765
2755
|
const errCodeFork = failedFork ? childFace.errorCode : undefined;
|
|
2766
2756
|
const errClassFork = failedFork ? classifySubagentError({ kind: "failed", ...(childFace.errorCode !== undefined ? { code: childFace.errorCode } : {}) }) : undefined;
|
|
2767
|
-
const
|
|
2757
|
+
const settleWinnerFork = bg.registry.settleBackgroundAgent(taskId, {
|
|
2768
2758
|
cycle: 0,
|
|
2769
2759
|
status: okBg ? "completed" : reapedBg ? "killed" : "failed",
|
|
2770
2760
|
...resultSettleFields(forkBgResult),
|
|
2771
2761
|
...(!okBg ? { error: reapedBg ? (collateralBg ? BG_AGENT_COLLATERAL_REAP_REASON : BG_AGENT_REAP_STOP_ERROR) : childFace.errorMessage ?? childFace.status } : {}),
|
|
2772
2762
|
...(errCodeFork !== undefined ? { errorCode: errCodeFork } : {}),
|
|
2773
2763
|
...(errClassFork !== undefined ? { retryable: errClassFork.retryable, errorKind: errClassFork.errorKind } : {}),
|
|
2774
|
-
})
|
|
2764
|
+
});
|
|
2765
|
+
const completionIdFork = settleWinnerFork !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
2766
|
+
const settledBg = settleWinnerFork ?? (abort.signal.aborted ? "killed" : okBg ? "completed" : "failed");
|
|
2775
2767
|
const stoppedByBg = settledBg === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
2776
|
-
const completionIdFork = bg.registry.getCompletionId(taskId);
|
|
2777
2768
|
const stillbornFork = child.terminal.kind === "failed" && child.terminal.code === "resume.session_not_found";
|
|
2778
2769
|
if (stillbornFork) {
|
|
2779
2770
|
await releaseBoundChildSession({ registry: bg.registry, taskId }, forkedId, () => (releaseForked ? releaseForked() : opts.runner.sessions.release?.(forkedId)));
|
|
@@ -2787,9 +2778,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2787
2778
|
? `Agent "${shortDesc}" failed: ${failReasonFork}${ccElapsedTag(forkElapsedMs)}`.slice(0, 300) + errorKindClause(errClassFork)
|
|
2788
2779
|
: `${ccCompletionText(shortDesc, settledBg, childFace.status, forkElapsedMs)}`;
|
|
2789
2780
|
const ownsTerminalFacesFork = bg.registry.claimAgentTerminalNotify(taskId);
|
|
2790
|
-
const forkResultField = await completionResultField(forkBgResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report));
|
|
2791
|
-
if (forkResultField?.ref !== undefined)
|
|
2792
|
-
bg.registry.recordArtifactRef(taskId, forkResultField.ref, 0);
|
|
2781
|
+
const forkResultField = await completionResultField(forkBgResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bg.registry.recordArtifactRef(taskId, ref, completionIdFork), notifier);
|
|
2793
2782
|
const forkFrame = {
|
|
2794
2783
|
task_id: taskId,
|
|
2795
2784
|
task_type: "background_agent",
|
|
@@ -2813,7 +2802,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2813
2802
|
sinkEmit(backgroundChildTerminal(forkFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkTranscriptId, ...(stillbornFork ? {} : { transcriptId: forkTranscriptId }), parentToolCallId: ctx.toolCallId, ...(bgForkCycleSeq !== undefined ? { generation: bgForkCycleSeq } : {}) }));
|
|
2814
2803
|
try {
|
|
2815
2804
|
if (ownsTerminalFacesFork)
|
|
2816
|
-
notify
|
|
2805
|
+
notify(forkFrame, { priority: "next" });
|
|
2817
2806
|
}
|
|
2818
2807
|
catch {
|
|
2819
2808
|
}
|
|
@@ -2826,15 +2815,16 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2826
2815
|
const msgFork = childThrownText(e);
|
|
2827
2816
|
const errCodeForkReject = killed ? undefined : thrownErrorCode(e);
|
|
2828
2817
|
const errClassForkReject = killed ? undefined : classifySubagentError({ kind: "failed", ...(errCodeForkReject !== undefined ? { code: errCodeForkReject } : {}) });
|
|
2829
|
-
const
|
|
2818
|
+
const settleWinnerForkReject = bg.registry.settleBackgroundAgent(taskId, {
|
|
2830
2819
|
cycle: 0,
|
|
2831
2820
|
status: killed ? "killed" : "failed",
|
|
2832
2821
|
error: killed ? BG_AGENT_REAP_STOP_ERROR : msgFork,
|
|
2833
2822
|
...(errCodeForkReject !== undefined ? { errorCode: errCodeForkReject } : {}),
|
|
2834
2823
|
...(errClassForkReject !== undefined ? { retryable: errClassForkReject.retryable, errorKind: errClassForkReject.errorKind } : {}),
|
|
2835
|
-
})
|
|
2824
|
+
});
|
|
2825
|
+
const completionIdForkReject = settleWinnerForkReject !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
2826
|
+
const settledBg = settleWinnerForkReject ?? (killed ? "killed" : "failed");
|
|
2836
2827
|
const stoppedByBg = settledBg === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
2837
|
-
const completionIdForkReject = bg.registry.getCompletionId(taskId);
|
|
2838
2828
|
const summaryBg = `${shortDesc} — ${settledBg === "failed" ? `failed: ${msgFork}` : settledBg}`.slice(0, 300) + (settledBg === "failed" ? errorKindClause(errClassForkReject) : "");
|
|
2839
2829
|
const ownsTerminalFacesForkReject = bg.registry.claimAgentTerminalNotify(taskId);
|
|
2840
2830
|
const forkRejectFrame = {
|
|
@@ -2854,7 +2844,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2854
2844
|
sinkEmit(backgroundChildTerminal(forkRejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId, ...(bgForkCycleSeq !== undefined ? { generation: bgForkCycleSeq } : {}) }));
|
|
2855
2845
|
try {
|
|
2856
2846
|
if (ownsTerminalFacesForkReject)
|
|
2857
|
-
notify
|
|
2847
|
+
notify(forkRejectFrame, { priority: "next" });
|
|
2858
2848
|
}
|
|
2859
2849
|
catch {
|
|
2860
2850
|
}
|
|
@@ -2863,7 +2853,6 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2863
2853
|
content: asyncLaunchedReceipt({
|
|
2864
2854
|
taskId,
|
|
2865
2855
|
workingLine: `The forked agent inherits your full current context and works on its prompt in the background.`,
|
|
2866
|
-
notify: Boolean(notify),
|
|
2867
2856
|
notes: [
|
|
2868
2857
|
modelNote,
|
|
2869
2858
|
extraToolsNote,
|
|
@@ -2878,9 +2867,10 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2878
2867
|
details: { type: "agent", subagent_type: FORK_SUBAGENT_TYPE, status: "async_launched", isAsync: true, task_id: taskId, description: shortDesc, prompt, ...(forkSettleId !== undefined ? { settle_id: forkSettleId } : {}) },
|
|
2879
2868
|
};
|
|
2880
2869
|
}
|
|
2881
|
-
const bgIgnoredNote =
|
|
2882
|
-
|
|
2883
|
-
|
|
2870
|
+
const bgIgnoredNote = ranSyncNote ??
|
|
2871
|
+
(a.run_in_background === true
|
|
2872
|
+
? `note: run_in_background was ignored for subagent_type "${FORK_SUBAGENT_TYPE}" — the fork ran synchronously (this delegation tool has no background surface configured).`
|
|
2873
|
+
: undefined);
|
|
2884
2874
|
const syncForkEntryGate = await openEntryGate();
|
|
2885
2875
|
if (ctx.signal?.aborted) {
|
|
2886
2876
|
try {
|
|
@@ -2987,7 +2977,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2987
2977
|
if (ctx.checkpointStoreForChildren !== undefined && ctx.checkpointStoreForChildren !== "disabled" && bg.checkpointStore !== undefined && bg.checkpointStore !== ctx.checkpointStoreForChildren)
|
|
2988
2978
|
throw configError("background.checkpointStore is not the store this run's children park in (the host's resolved checkpoint seat, TaskSpec/RunnerDeps.checkpointStore) — wire the one store, or leave the option unset and let the seat ride.", "config.invalid_checkpoint_store");
|
|
2989
2979
|
const childParkStore = ctx.checkpointStoreForChildren === undefined ? bg.checkpointStore : ctx.checkpointStoreForChildren === "disabled" ? undefined : ctx.checkpointStoreForChildren;
|
|
2990
|
-
const notify =
|
|
2980
|
+
const notify = backgroundSink;
|
|
2991
2981
|
const abort = new AbortController();
|
|
2992
2982
|
const reviveRow = reviveClaim?.row;
|
|
2993
2983
|
const parkedResume = reviveClaim?.parkedResume;
|
|
@@ -3004,10 +2994,13 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3004
2994
|
const shortDesc = reviveRow?.description ?? String(a.description ?? "sub-agent").slice(0, 200);
|
|
3005
2995
|
const bgOwner = reviveRow !== undefined ? reviveRow.owner : sessionScopedBg ? ctx.sessionId : ctx.taskId ?? bg.owner;
|
|
3006
2996
|
const bgScope = treeScope;
|
|
3007
|
-
const
|
|
3008
|
-
const capLedgerKey =
|
|
3009
|
-
{
|
|
3010
|
-
|
|
2997
|
+
const bgEntryPool = delegationEntryPool(entryPoolSeat);
|
|
2998
|
+
const capLedgerKey = bgEntryPool.key;
|
|
2999
|
+
if (reviveRow !== undefined) {
|
|
3000
|
+
bgEntryPool.occupy("registered");
|
|
3001
|
+
}
|
|
3002
|
+
else {
|
|
3003
|
+
const admission = (await openEntryGate()).admit("registered");
|
|
3011
3004
|
if (!admission.admitted) {
|
|
3012
3005
|
dropHostAbortListener();
|
|
3013
3006
|
await cancelObserver();
|
|
@@ -3145,7 +3138,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3145
3138
|
};
|
|
3146
3139
|
const bgChildSessionId = reviveRow?.sessionId ?? uuidv7();
|
|
3147
3140
|
const bgStartedAt = Date.now();
|
|
3148
|
-
stepRecorder.lockTo(
|
|
3141
|
+
stepRecorder.lockTo(taskId);
|
|
3149
3142
|
bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId);
|
|
3150
3143
|
const bgCycleSeq = bg.registry.backgroundAgentCycleSeq(taskId);
|
|
3151
3144
|
bg.registry.attachAgentTerminalNotifier(taskId, () => {
|
|
@@ -3165,7 +3158,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3165
3158
|
...(completionIdReap !== undefined ? { completionId: completionIdReap } : {}),
|
|
3166
3159
|
};
|
|
3167
3160
|
sinkEmit(backgroundChildTerminal(reapFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId, ...(seqReap !== undefined ? { generation: seqReap } : {}) }));
|
|
3168
|
-
notifier.notify(() => notify
|
|
3161
|
+
notifier.notify(() => notify(reapFrame, { priority: "next" }), "subagent.reapTerminalNotify");
|
|
3169
3162
|
});
|
|
3170
3163
|
const bgDurableProbe = bg.registry.durableAgentRowProbe(taskId);
|
|
3171
3164
|
const bgRowConfirmed = async () => (bgDurableProbe ? await bgDurableProbe().catch(() => false) : false);
|
|
@@ -3205,9 +3198,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3205
3198
|
: ctx.subagentRetain;
|
|
3206
3199
|
if (sessionScopedBg && bgRetainLedger)
|
|
3207
3200
|
ensureSessionReapHook(bg.registry);
|
|
3208
|
-
const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, { registry: bg.registry, taskId },
|
|
3209
|
-
delegationTaskType: "background_agent",
|
|
3210
|
-
});
|
|
3201
|
+
const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, { registry: bg.registry, taskId }, backgroundLegFacts(taskId));
|
|
3211
3202
|
if (bgRetain) {
|
|
3212
3203
|
bg.registry.markRetainedContinuation(taskId);
|
|
3213
3204
|
const origRelease = bgRetain.release;
|
|
@@ -3250,7 +3241,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3250
3241
|
transcriptId: bgChildSessionId,
|
|
3251
3242
|
sessionId: bgChildSessionId,
|
|
3252
3243
|
parentToolCallId: ctx.toolCallId,
|
|
3253
|
-
progressTaskId:
|
|
3244
|
+
progressTaskId: taskId,
|
|
3254
3245
|
agentType: spawnAgentType,
|
|
3255
3246
|
...(spawnModel !== undefined ? { model: spawnModel } : {}),
|
|
3256
3247
|
...(bgCycleSeq !== undefined ? { seq: bgCycleSeq } : {}),
|
|
@@ -3276,8 +3267,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3276
3267
|
...(bgQuestionStrip !== undefined ? bgQuestionStrip.internalsFlag : {}),
|
|
3277
3268
|
...(bgPlacement !== undefined ? { sessionPlacement: bgPlacement } : {}),
|
|
3278
3269
|
onNotifyInjectorReady: s2NotifyReady,
|
|
3279
|
-
|
|
3280
|
-
...(bgCycleSeq !== undefined ? { cycleSeq: bgCycleSeq } : {}),
|
|
3270
|
+
...backgroundLegFacts(taskId, bgCycleSeq),
|
|
3281
3271
|
onForwardEvent: (e) => {
|
|
3282
3272
|
try {
|
|
3283
3273
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -3313,8 +3303,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3313
3303
|
...(bgQuestionStrip !== undefined ? bgQuestionStrip.internalsFlag : {}),
|
|
3314
3304
|
...(bgPlacement !== undefined ? { sessionPlacement: bgPlacement } : {}),
|
|
3315
3305
|
onNotifyInjectorReady: s2NotifyReady,
|
|
3316
|
-
|
|
3317
|
-
...(bgCycleSeq !== undefined ? { cycleSeq: bgCycleSeq } : {}),
|
|
3306
|
+
...backgroundLegFacts(taskId, bgCycleSeq),
|
|
3318
3307
|
onForwardEvent: (e) => {
|
|
3319
3308
|
try {
|
|
3320
3309
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -3420,7 +3409,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3420
3409
|
...(pr.inheritedGate !== undefined ? { inheritedGate: pr.inheritedGate } : {}),
|
|
3421
3410
|
afterCheckpointResolve,
|
|
3422
3411
|
});
|
|
3423
|
-
observedSteerRef.steer = (
|
|
3412
|
+
observedSteerRef.steer = authoredSteerOf(bgStream);
|
|
3424
3413
|
for await (const ev of bgStream)
|
|
3425
3414
|
observerTap?.record(ev);
|
|
3426
3415
|
childResult = await bgStream.result();
|
|
@@ -3458,7 +3447,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3458
3447
|
: observerPairing
|
|
3459
3448
|
? (() => {
|
|
3460
3449
|
const bgStream = opts.runner.runTaskStream(bgSpec, undefined, bgInternals);
|
|
3461
|
-
observedSteerRef.steer = (
|
|
3450
|
+
observedSteerRef.steer = authoredSteerOf(bgStream);
|
|
3462
3451
|
return (async () => {
|
|
3463
3452
|
for await (const ev of bgStream)
|
|
3464
3453
|
observerTap?.record(ev);
|
|
@@ -3466,6 +3455,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3466
3455
|
})();
|
|
3467
3456
|
})()
|
|
3468
3457
|
: opts.runner.runTask(bgSpec, bgInternals);
|
|
3458
|
+
extensionSpawn?.launched(taskId, spawnModel);
|
|
3469
3459
|
void bgChildPromise
|
|
3470
3460
|
.then(async (child) => {
|
|
3471
3461
|
const childFace = childTerminalFace(child.terminal);
|
|
@@ -3571,7 +3561,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3571
3561
|
: childFace.errorCode
|
|
3572
3562
|
: undefined;
|
|
3573
3563
|
const errClassBg = failedBg ? classifySubagentError({ kind: "failed", ...(childFace.errorCode !== undefined ? { code: childFace.errorCode } : {}) }) : undefined;
|
|
3574
|
-
const
|
|
3564
|
+
const settleWinnerBg = bg.registry.settleBackgroundAgent(taskId, {
|
|
3575
3565
|
cycle: 0,
|
|
3576
3566
|
status: ok ? "completed" : reaped ? "killed" : "failed",
|
|
3577
3567
|
seq: seqAtSettle ?? 1,
|
|
@@ -3580,13 +3570,14 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3580
3570
|
...(errCodeBg !== undefined ? { errorCode: errCodeBg } : {}),
|
|
3581
3571
|
...(errClassBg !== undefined ? { retryable: errClassBg.retryable, errorKind: errClassBg.errorKind } : {}),
|
|
3582
3572
|
...(failedBg && child.retryAfterMs !== undefined ? { retryAfterMs: child.retryAfterMs } : {}),
|
|
3583
|
-
})
|
|
3573
|
+
});
|
|
3574
|
+
const completionIdBg = settleWinnerBg !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
3575
|
+
const settled = settleWinnerBg ??
|
|
3584
3576
|
(abort.signal.aborted ? "killed" : ok ? "completed" : "failed");
|
|
3585
3577
|
if (!bgRetain && reviveRow === undefined && !(await bgRowConfirmed())) {
|
|
3586
3578
|
await releaseBoundChildSession({ registry: bg.registry, taskId }, child.sessionId, () => opts.runner.sessions.release(child.sessionId));
|
|
3587
3579
|
}
|
|
3588
3580
|
const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
3589
|
-
const completionIdBg = bg.registry.getCompletionId(taskId);
|
|
3590
3581
|
const observerNote = observerNoteFor(await startBoundedObserverDrain());
|
|
3591
3582
|
const residual = residualFields();
|
|
3592
3583
|
const bgDurableRow = await bgRowConfirmed();
|
|
@@ -3604,9 +3595,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3604
3595
|
? `Agent "${shortDesc}" failed: ${failReasonBg}${ccElapsedTag(bgElapsedMs)}${observerNote}`.slice(0, 300) + errorKindClause(errClassBg)
|
|
3605
3596
|
: `${ccCompletionText(shortDesc, settled, childFace.status, bgElapsedMs)}${observerNote}`;
|
|
3606
3597
|
const ownsTerminalFaces = bg.registry.claimAgentTerminalNotify(taskId);
|
|
3607
|
-
const bgResultField = await completionResultField(bgHandbackResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report));
|
|
3608
|
-
if (bgResultField?.ref !== undefined)
|
|
3609
|
-
bg.registry.recordArtifactRef(taskId, bgResultField.ref, 0);
|
|
3598
|
+
const bgResultField = await completionResultField(bgHandbackResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bg.registry.recordArtifactRef(taskId, ref, completionIdBg), notifier);
|
|
3610
3599
|
const completionFrame = {
|
|
3611
3600
|
task_id: taskId,
|
|
3612
3601
|
task_type: "background_agent",
|
|
@@ -3629,21 +3618,21 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3629
3618
|
};
|
|
3630
3619
|
if (ownsTerminalFaces)
|
|
3631
3620
|
sinkEmit(backgroundChildTerminal(completionFrame, { taskId, sessionScoped: sessionScopedBg === true, ...(child.sessionId ? { sessionId: child.sessionId, transcriptId: child.sessionId } : {}), parentToolCallId: ctx.toolCallId, ...(bgCycleSeq !== undefined ? { generation: bgCycleSeq } : {}) }));
|
|
3632
|
-
const
|
|
3633
|
-
const aliveBgCount =
|
|
3634
|
-
if (
|
|
3621
|
+
const gateOwners = ownsTerminalFaces && settled === "completed" && bgRetain !== undefined ? childOwnerKeys(child.taskId, bgRetain.childSessionId) : [];
|
|
3622
|
+
const aliveBgCount = runningBackgroundUnder(bg.registry, gateOwners);
|
|
3623
|
+
if (bgRetain !== undefined && aliveBgCount > 0) {
|
|
3635
3624
|
parkCompletionNotify({
|
|
3636
3625
|
registry: bg.registry,
|
|
3637
3626
|
entry: bgRetain,
|
|
3638
|
-
|
|
3627
|
+
owners: gateOwners,
|
|
3639
3628
|
pendingCount: aliveBgCount,
|
|
3640
3629
|
payload: completionFrame,
|
|
3641
|
-
notify
|
|
3630
|
+
notify,
|
|
3642
3631
|
});
|
|
3643
3632
|
}
|
|
3644
3633
|
else if (ownsTerminalFaces) {
|
|
3645
3634
|
try {
|
|
3646
|
-
notify
|
|
3635
|
+
notify(completionFrame, { priority: "next" });
|
|
3647
3636
|
}
|
|
3648
3637
|
catch {
|
|
3649
3638
|
}
|
|
@@ -3665,19 +3654,20 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3665
3654
|
const msg = childThrownText(e);
|
|
3666
3655
|
const errCodeBgReject = killed ? undefined : thrownErrorCode(e);
|
|
3667
3656
|
const errClassBgReject = killed ? undefined : classifySubagentError({ kind: "failed", ...(errCodeBgReject !== undefined ? { code: errCodeBgReject } : {}) });
|
|
3668
|
-
const
|
|
3657
|
+
const settleWinnerBgReject = bg.registry.settleBackgroundAgent(taskId, {
|
|
3669
3658
|
cycle: 0,
|
|
3670
3659
|
status: killed ? "killed" : "failed",
|
|
3671
3660
|
error: msg,
|
|
3672
3661
|
seq: seqAtSettle ?? 1,
|
|
3673
3662
|
...(errCodeBgReject !== undefined ? { errorCode: errCodeBgReject } : {}),
|
|
3674
3663
|
...(errClassBgReject !== undefined ? { retryable: errClassBgReject.retryable, errorKind: errClassBgReject.errorKind } : {}),
|
|
3675
|
-
})
|
|
3664
|
+
});
|
|
3665
|
+
const completionIdBgReject = settleWinnerBgReject !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
3666
|
+
const settled = settleWinnerBgReject ?? (killed ? "killed" : "failed");
|
|
3676
3667
|
if (!bgRetain && reviveRow === undefined && !(await bgRowConfirmed())) {
|
|
3677
3668
|
await releaseBoundChildSession({ registry: bg.registry, taskId }, bgChildSessionId, () => opts.runner.sessions.release(bgChildSessionId));
|
|
3678
3669
|
}
|
|
3679
3670
|
const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
3680
|
-
const completionIdBgReject = bg.registry.getCompletionId(taskId);
|
|
3681
3671
|
const observerNote = observerNoteFor(await startBoundedObserverDrain());
|
|
3682
3672
|
const ownsTerminalFacesReject = bg.registry.claimAgentTerminalNotify(taskId);
|
|
3683
3673
|
const rejectFrame = {
|
|
@@ -3698,7 +3688,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3698
3688
|
sinkEmit(backgroundChildTerminal(rejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId, ...(bgCycleSeq !== undefined ? { generation: bgCycleSeq } : {}) }));
|
|
3699
3689
|
try {
|
|
3700
3690
|
if (ownsTerminalFacesReject)
|
|
3701
|
-
notify
|
|
3691
|
+
notify(rejectFrame, { priority: "next" });
|
|
3702
3692
|
}
|
|
3703
3693
|
catch {
|
|
3704
3694
|
}
|
|
@@ -3733,7 +3723,6 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3733
3723
|
content: asyncLaunchedReceipt({
|
|
3734
3724
|
taskId,
|
|
3735
3725
|
workingLine: `The agent is working in the background.`,
|
|
3736
|
-
notify: Boolean(notify),
|
|
3737
3726
|
notes: [
|
|
3738
3727
|
modelNote,
|
|
3739
3728
|
extraToolsNote,
|
|
@@ -3769,7 +3758,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3769
3758
|
if (retainEntry)
|
|
3770
3759
|
stepRecorder.lockTo(retainEntry.childSessionId);
|
|
3771
3760
|
const stream = opts.runner.runTaskStream({ ...buildChildSpec(ctx.signal), ...(retainEntry ? { sessionId: retainEntry.childSessionId } : {}) }, undefined, childInternals);
|
|
3772
|
-
observedSteerRef.steer = (
|
|
3761
|
+
observedSteerRef.steer = authoredSteerOf(stream);
|
|
3773
3762
|
let settleResolve;
|
|
3774
3763
|
const settled = new Promise((r) => { settleResolve = r; });
|
|
3775
3764
|
if (ctx.onSubagentSpawn) {
|
|
@@ -3785,6 +3774,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3785
3774
|
...(ctx.onQuestion !== undefined ? { currentOnQuestion: ctx.onQuestion } : {}),
|
|
3786
3775
|
...(ctx.autoModeReview !== undefined ? { currentAutoModeReview: ctx.autoModeReview } : {}),
|
|
3787
3776
|
currentMcpHostSeats: ctx.mountedMcp?.().hostSeats,
|
|
3777
|
+
currentPlacementTarget: ctx.placementTarget,
|
|
3788
3778
|
});
|
|
3789
3779
|
notifier.notify(() => ctx.onSubagentSpawn?.(createSteerHandle(stream, ctx.toolCallId, childAgentName, settled, {
|
|
3790
3780
|
resume,
|
|
@@ -3866,6 +3856,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3866
3856
|
`status: ${childFace.status}`,
|
|
3867
3857
|
modelNote ?? "",
|
|
3868
3858
|
extraToolsNote ?? "",
|
|
3859
|
+
ranSyncNote ?? "",
|
|
3869
3860
|
worktreeLine ?? "",
|
|
3870
3861
|
childFace.blockedReason ? `blocked_reason: ${inlineUntrusted(childFace.blockedReason, REPORT_FIELD_MAX)}` : "",
|
|
3871
3862
|
childFace.errorMessage ? `error: ${inlineUntrusted(childFace.errorMessage, REPORT_FIELD_MAX)}` : "",
|