@sema-agent/core 7.60.0 → 7.62.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 +917 -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 +71 -12
- package/dist/agents/cascade.js +61 -21
- 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-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- 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 +49 -10
- 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 +36 -41
- package/dist/agents/subagent.js +245 -200
- package/dist/agents/suspend-guard.d.ts +47 -16
- package/dist/agents/suspend-guard.js +13 -4
- package/dist/agents/verify.d.ts +41 -14
- package/dist/agents/verify.js +41 -30
- 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-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-requirements.d.ts +33 -5
- package/dist/core/checkpoint-requirements.js +18 -5
- package/dist/core/checkpoint-row-verdict.d.ts +99 -0
- package/dist/core/checkpoint-row-verdict.js +225 -0
- package/dist/core/checkpoint-store.d.ts +107 -738
- package/dist/core/checkpoint-store.js +45 -143
- 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 +68 -21
- package/dist/core/engine-notice.js +9 -2
- 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 +4 -3
- 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 +14 -4
- package/dist/core/governance-codes.js +19 -4
- package/dist/core/hooks.d.ts +25 -4
- package/dist/core/hooks.js +11 -4
- package/dist/core/host-floor.js +3 -5
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +47 -7
- 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 +4 -3
- 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 +225 -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-driver.d.ts +1 -1
- 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/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/mode-policy.d.ts +8 -8
- package/dist/core/mode-policy.js +8 -6
- package/dist/core/mods/agent-stations.d.ts +39 -4
- package/dist/core/mods/agent-stations.js +59 -10
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +94 -1
- package/dist/core/mods/dollar.js +13 -1
- 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 +14 -3
- package/dist/core/mods/kernel/events.js +18 -15
- package/dist/core/mods/kernel/registration.d.ts +3 -0
- package/dist/core/mods/kernel/registration.js +5 -0
- package/dist/core/mods/kernel/site-rules.d.ts +6 -3
- package/dist/core/mods/kernel/site-rules.js +10 -2
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +118 -0
- package/dist/core/mods/session-append.js +318 -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 +138 -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 +88 -21
- package/dist/core/mods/stations.js +149 -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 +68 -2
- package/dist/core/own-property-receipt.js +45 -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/read-root-candidate.js +1 -1
- package/dist/core/remote-env.d.ts +74 -26
- package/dist/core/remote-env.js +20 -0
- package/dist/core/resume-startup-cause.d.ts +5 -4
- 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 +18 -3
- 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 +116 -34
- 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/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- 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/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- 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 +7 -2
- package/dist/core/runner/permission-rule-lanes.js +28 -9
- package/dist/core/runner/person-path-rows.d.ts +15 -0
- package/dist/core/runner/person-path-rows.js +27 -4
- package/dist/core/runner/placement-fence.d.ts +26 -0
- package/dist/core/runner/placement-fence.js +38 -0
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- 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 +3 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -1
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +19 -21
- 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 +6 -6
- package/dist/core/runner/prepare-hands-readface.js +32 -11
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -0
- package/dist/core/runner/prepare-inherited-gate.js +10 -3
- 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 +61 -30
- 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 +8 -6
- package/dist/core/runner/resume-admission.js +23 -6
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +14 -5
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- 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.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +6 -2
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +5 -4
- 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 +64 -36
- 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 +12 -9
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- 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 +34 -18
- package/dist/core/runner/runtask.d.ts +18 -3
- package/dist/core/runner/runtask.js +33 -17
- 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/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- 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 +16 -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-face-overlay.js +2 -0
- 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 +8 -2
- package/dist/core/runner/turn-attachments.js +2 -2
- 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 +26 -27
- package/dist/core/secret-env.d.ts +19 -16
- package/dist/core/secret-env.js +45 -27
- 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 +3 -1
- package/dist/core/session-store.js +10 -8
- package/dist/core/session.d.ts +16 -5
- 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 +8 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +83 -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/session-store-contract.js +22 -8
- 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 +24 -9
- package/dist/core/task-limits.d.ts +5 -0
- package/dist/core/task-notification.d.ts +89 -12
- package/dist/core/task-notification.js +89 -14
- package/dist/core/task-registry-agent.d.ts +32 -50
- package/dist/core/task-registry-agent.js +36 -56
- 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 +22 -112
- package/dist/core/task-registry-shared.js +3 -41
- package/dist/core/task-registry-workflow.js +5 -21
- package/dist/core/task-registry.d.ts +32 -62
- package/dist/core/task-registry.js +30 -110
- package/dist/core/task-result.d.ts +29 -12
- 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 +11 -11
- 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 +36 -6
- 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 +8 -5
- package/dist/core/tool-face.js +1 -1
- 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 +109 -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-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +23 -6
- package/dist/core/trace.d.ts +18 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.js +1 -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 +37 -9
- package/dist/engine/execution-env/node-execution-env.js +221 -22
- 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 +52 -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/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.js +1 -1
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/fixtures/index.d.ts +7 -5
- package/dist/fixtures/index.js +5 -3
- package/dist/index.d.ts +29 -18
- package/dist/index.js +19 -11
- package/dist/internal/harness-types.d.ts +2 -0
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- 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 +14 -17
- package/dist/orchestration/run-workflow-tool.js +43 -50
- package/dist/orchestration/workflow-types.d.ts +2 -2
- package/dist/orchestration/workflow.d.ts +7 -0
- package/dist/orchestration/workflow.js +10 -12
- package/dist/stores/file/background-agent-store.js +18 -15
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +13 -9
- package/dist/stores/file/file-history-store.js +3 -2
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +7 -12
- package/dist/stores/file/index.js +25 -12
- 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 +26 -7
- package/dist/stores/file/session-store.js +59 -35
- 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/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +7 -7
- 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/removal-targets.js +2 -2
- package/dist/tools/fs/search.d.ts +3 -2
- package/dist/tools/fs/search.js +6 -6
- package/dist/tools/fs/shell-read-argv.d.ts +4 -2
- package/dist/tools/fs/shell-read-argv.js +14 -3
- package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
- package/dist/tools/fs/shell-read-bindings.js +148 -68
- package/dist/tools/fs/shell-read-check.js +20 -4
- package/dist/tools/fs/shell-read-establish.js +25 -9
- package/dist/tools/fs/shell-read-functions.js +2 -2
- 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/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +8 -0
- package/dist/tools/fs/shell-read-plan.js +47 -30
- package/dist/tools/fs/shell-read-start.d.ts +66 -13
- package/dist/tools/fs/shell-read-start.js +89 -17
- package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
- package/dist/tools/fs/shell-read-workdir.js +31 -8
- 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 +112 -42
- package/wire-changes/core-stores-sql@7.61.0.json +480 -0
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core@7.61.0.json +4405 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/mods-kernel@7.61.0.json +65 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/primitives@7.61.0.json +30 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/runner/image-removed-seat.d.ts +0 -12
- package/dist/core/runner/image-removed-seat.js +0 -19
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
package/dist/agents/subagent.js
CHANGED
|
@@ -2,7 +2,8 @@ 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 {
|
|
5
|
+
import { authoredSteerOf } from "../core/input-author.js";
|
|
6
|
+
import { DELEGATION_OWNER_UNBOUND, delegationOwnerOf, rowOwnerReading } from "../core/runner/delegation-owner.js";
|
|
6
7
|
import { resumeRefusalDetailOf, resumeStartupCauseOf } from "../core/resume-startup-cause.js";
|
|
7
8
|
import { errorCodeOf, thrownFailureOf } from "../core/runner/terminal-account.js";
|
|
8
9
|
import { applyParentSpecSeat, parentSpecSeatOfCtx } from "../core/parent-spec-seat.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) => {
|
|
@@ -1094,6 +1084,28 @@ function chargeLocalDelegationInFlight(anchor, key) {
|
|
|
1094
1084
|
live.delete(key);
|
|
1095
1085
|
};
|
|
1096
1086
|
}
|
|
1087
|
+
const REFUSAL_OCCUPANTS_LISTED = 5;
|
|
1088
|
+
function reachableOccupants(registry, scope, root, caller) {
|
|
1089
|
+
const face = registry === undefined ? undefined : registry.activeDelegationOccupants;
|
|
1090
|
+
if (typeof face !== "function")
|
|
1091
|
+
return new Map();
|
|
1092
|
+
try {
|
|
1093
|
+
return new Map(face.call(registry, scope, root, caller).filter((o) => o.reachable).map((o) => [o.id, o.name]));
|
|
1094
|
+
}
|
|
1095
|
+
catch {
|
|
1096
|
+
return new Map();
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
function concurrencyOccupants(active, reachable, local) {
|
|
1100
|
+
const listed = active.filter((id) => reachable.has(id)).slice(0, REFUSAL_OCCUPANTS_LISTED);
|
|
1101
|
+
const parts = listed.map((id) => `task_id ${id} (${JSON.stringify(reachable.get(id))})`);
|
|
1102
|
+
const rest = active.length - listed.length;
|
|
1103
|
+
if (rest > 0)
|
|
1104
|
+
parts.push(`${rest} ${listed.length > 0 ? "more " : ""}registered`);
|
|
1105
|
+
if (local > 0)
|
|
1106
|
+
parts.push(`${local} running synchronously inside a call of this tree, no task_id`);
|
|
1107
|
+
return { text: parts.join(", "), stoppable: listed.length > 0 };
|
|
1108
|
+
}
|
|
1097
1109
|
const spawnAbortedResult = (wt, fault) => notStartedResult({
|
|
1098
1110
|
isError: true,
|
|
1099
1111
|
content: `Sub-agent not started: the delegating call was aborted.${wt ? `\n${wt}` : ""}`,
|
|
@@ -1121,16 +1133,24 @@ async function untilAbort(p, signal) {
|
|
|
1121
1133
|
signal.removeEventListener("abort", onAbort);
|
|
1122
1134
|
}
|
|
1123
1135
|
}
|
|
1136
|
+
const delegationPoolKey = (scope, root) => JSON.stringify([scope, root]);
|
|
1137
|
+
function delegationEntryPool(seat) {
|
|
1138
|
+
if (seat.root === undefined)
|
|
1139
|
+
return { key: undefined, occupy: () => noopRelease };
|
|
1140
|
+
const key = delegationPoolKey(seat.scope ?? DELEGATION_POOL_DEFAULT_SCOPE, seat.root);
|
|
1141
|
+
return { key, occupy: (kind) => (kind === "local" ? chargeLocalDelegationInFlight(seat.poolAnchor, key) : noopRelease) };
|
|
1142
|
+
}
|
|
1124
1143
|
async function openDelegationEntryGate(input) {
|
|
1125
|
-
const { poolAnchor, registry, store, root, caps,
|
|
1144
|
+
const { poolAnchor, registry, store, root, caps, signal, caller } = input;
|
|
1145
|
+
const pool = delegationEntryPool(input);
|
|
1126
1146
|
if (root === undefined)
|
|
1127
|
-
return {
|
|
1147
|
+
return { ...pool, admit: () => ({ admitted: true, release: noopRelease }) };
|
|
1128
1148
|
const scope = input.scope ?? DELEGATION_POOL_DEFAULT_SCOPE;
|
|
1129
|
-
const key =
|
|
1130
|
-
const occupy =
|
|
1149
|
+
const key = delegationPoolKey(scope, root);
|
|
1150
|
+
const { occupy } = pool;
|
|
1131
1151
|
let storedHandles = [];
|
|
1132
1152
|
let storedEnumerationOk = false;
|
|
1133
|
-
if (store !== undefined
|
|
1153
|
+
if (store !== undefined) {
|
|
1134
1154
|
try {
|
|
1135
1155
|
storedHandles = (await untilAbort(store.listBySession(scope, root), signal)).map((r) => r.handle);
|
|
1136
1156
|
storedEnumerationOk = true;
|
|
@@ -1145,47 +1165,47 @@ async function openDelegationEntryGate(input) {
|
|
|
1145
1165
|
const local = localDelegationInFlightCount(poolAnchor, key);
|
|
1146
1166
|
const running = active.length + local;
|
|
1147
1167
|
if (running >= caps.maxConcurrent) {
|
|
1168
|
+
const who = concurrencyOccupants(active, reachableOccupants(registry, scope, root, { ...caller, scope }), local);
|
|
1169
|
+
const stop = who.stoppable ? " or stop a listed one (TaskStop with its task_id)" : "";
|
|
1148
1170
|
return {
|
|
1149
1171
|
admitted: false,
|
|
1150
1172
|
refusal: {
|
|
1151
1173
|
code: "delegation.concurrency_cap",
|
|
1152
|
-
text: `this session tree already has ${running} agents running — the concurrency cap (${caps.maxConcurrent}; RunnerDeps.delegationEntryCaps.maxConcurrent) refuses another. ${kind === "registered" ?
|
|
1174
|
+
text: `this session tree already has ${running} agents running${who.text === "" ? "" : ` (${who.text})`} — the concurrency cap (${caps.maxConcurrent}; RunnerDeps.delegationEntryCaps.maxConcurrent) refuses another. ${kind === "registered" ? `Wait for one to complete (you will be notified)${stop}, then relaunch.` : `Wait for one of them to finish${stop}, then try again.`}`,
|
|
1153
1175
|
},
|
|
1154
1176
|
};
|
|
1155
1177
|
}
|
|
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
|
-
}
|
|
1178
|
+
const ledger = delegationEntryLedger(poolAnchor, key);
|
|
1179
|
+
let retained;
|
|
1180
|
+
if (store !== undefined && storedEnumerationOk) {
|
|
1181
|
+
const keep = new Set([...storedHandles, ...active]);
|
|
1182
|
+
if (kind === "registered") {
|
|
1183
|
+
for (const h of [...ledger])
|
|
1184
|
+
if (!keep.has(h))
|
|
1185
|
+
ledger.delete(h);
|
|
1186
|
+
retained = new Set([...storedHandles, ...ledger]).size;
|
|
1174
1187
|
}
|
|
1175
1188
|
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
|
-
};
|
|
1189
|
+
const survivors = new Set(storedHandles);
|
|
1190
|
+
for (const h of ledger)
|
|
1191
|
+
if (keep.has(h))
|
|
1192
|
+
survivors.add(h);
|
|
1193
|
+
retained = survivors.size;
|
|
1187
1194
|
}
|
|
1188
1195
|
}
|
|
1196
|
+
else {
|
|
1197
|
+
retained = ledger.size;
|
|
1198
|
+
}
|
|
1199
|
+
const cumulative = retained + local;
|
|
1200
|
+
if (cumulative >= caps.maxCumulativePerSession) {
|
|
1201
|
+
return {
|
|
1202
|
+
admitted: false,
|
|
1203
|
+
refusal: {
|
|
1204
|
+
code: "delegation.session_cap",
|
|
1205
|
+
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.`,
|
|
1206
|
+
},
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1189
1209
|
return { admitted: true, release: occupy(kind) };
|
|
1190
1210
|
};
|
|
1191
1211
|
return { key, admit, occupy };
|
|
@@ -1271,13 +1291,9 @@ export function asyncLaunchedReceipt(p) {
|
|
|
1271
1291
|
const noteLines = (p.notes ?? []).filter((n) => n !== undefined && n !== "");
|
|
1272
1292
|
return (`Async agent launched successfully. (${launchReceiptNoQuoteClause(", including the task_id below,")})\n` +
|
|
1273
1293
|
`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`) +
|
|
1294
|
+
`${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
1295
|
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.`));
|
|
1296
|
+
`${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
1297
|
}
|
|
1282
1298
|
function runnerModelCatalog(runner) {
|
|
1283
1299
|
try {
|
|
@@ -1447,7 +1463,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1447
1463
|
: `- Each agent type's model, thinking level, and tools come from its agent definition.\n`) +
|
|
1448
1464
|
`- \`isolation: "worktree"\` gives the agent its own git worktree (auto-cleaned if unchanged).` +
|
|
1449
1465
|
(opts.background
|
|
1450
|
-
? `\n- Subagents run in the background by default
|
|
1466
|
+
? `\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
1467
|
`- ${continuationSentence(opts.name ?? DEFAULT_SUBAGENT_TOOL_NAME, opts.background.agentStore !== undefined, forkOffered)}`
|
|
1452
1468
|
: `\n- \`run_in_background\` is unavailable here — only synchronous subagents.`),
|
|
1453
1469
|
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 +1492,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1476
1492
|
`\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
1493
|
(opts.background
|
|
1478
1494
|
?
|
|
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}`) +
|
|
1495
|
+
`\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
1496
|
` ${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.
|
|
1497
|
+
`\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
1498
|
: `\n\nThe run_in_background parameter is not available in this context. Only synchronous subagents are supported.`) }],
|
|
1485
1499
|
parameters: Type.Object({
|
|
1486
1500
|
subagent_type: Type.Optional(Type.String({ description: "The type of specialized agent to use for this task" })),
|
|
@@ -1507,9 +1521,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1507
1521
|
...(opts.background
|
|
1508
1522
|
? {
|
|
1509
1523
|
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).",
|
|
1524
|
+
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
1525
|
})),
|
|
1514
1526
|
}
|
|
1515
1527
|
: {}),
|
|
@@ -1523,10 +1535,12 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1523
1535
|
const a = canonicalSubagentTypeArgs(args, acceptedSubagentTypes(), generalPurposeShadowed);
|
|
1524
1536
|
const parentSpecSeat = parentSpecSeatOfCtx(ctx);
|
|
1525
1537
|
const reviveClaim = ctx.reviveClaim;
|
|
1526
|
-
|
|
1538
|
+
const backgroundSink = opts.background !== undefined ? resolveCompletionSink(ctx.onTaskNotification, opts.background.notify) : undefined;
|
|
1539
|
+
const backgroundLane = opts.background !== undefined && admitsBackgroundLaunch(backgroundSink);
|
|
1540
|
+
if (reviveClaim !== undefined && !backgroundLane) {
|
|
1527
1541
|
return notStartedResult({
|
|
1528
1542
|
isError: true,
|
|
1529
|
-
content: "Sub-agent not revived: this delegation tool has no background surface
|
|
1543
|
+
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
1544
|
details: { error: "revive.no_background" },
|
|
1531
1545
|
});
|
|
1532
1546
|
}
|
|
@@ -1584,7 +1598,14 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1584
1598
|
});
|
|
1585
1599
|
}
|
|
1586
1600
|
}
|
|
1587
|
-
const
|
|
1601
|
+
const backgroundAsked = opts.background !== undefined && (a.run_in_background !== false || def?.background === true || agentName !== undefined);
|
|
1602
|
+
const wantsBackground = backgroundLane && backgroundAsked;
|
|
1603
|
+
const ranSyncNote = backgroundAsked && !backgroundLane ? AGENT_RAN_SYNC_NO_CHANNEL_NOTE : undefined;
|
|
1604
|
+
const stations = reviveClaim === undefined ? ctx.agentStations : undefined;
|
|
1605
|
+
const extensionSpawn = stations?.extensionSpawn(ctx.toolCallId);
|
|
1606
|
+
if (extensionSpawn !== undefined && !wantsBackground) {
|
|
1607
|
+
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" } });
|
|
1608
|
+
}
|
|
1588
1609
|
if (a.cwd !== undefined && typeof a.cwd !== "string") {
|
|
1589
1610
|
return notStartedResult({ isError: true, content: "Sub-agent not started: cwd must be an absolute path string.", details: { error: "cwd.relative" } });
|
|
1590
1611
|
}
|
|
@@ -1745,8 +1766,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1745
1766
|
details: { error: "skill_grants.unreadable" },
|
|
1746
1767
|
});
|
|
1747
1768
|
}
|
|
1748
|
-
|
|
1749
|
-
if (stations?.listens("agent.offer") === true) {
|
|
1769
|
+
if (extensionSpawn === undefined && stations?.listens("agent.offer") === true) {
|
|
1750
1770
|
const listed = agentListing.find((entry) => entry.name === spawnAgentType);
|
|
1751
1771
|
const offered = await stations.offered([{ name: spawnAgentType, description: listed?.description ?? "" }], ctx.signal);
|
|
1752
1772
|
if (offered.length === 0) {
|
|
@@ -1819,6 +1839,10 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1819
1839
|
...(cause !== undefined ? { cause: childThrownText(cause) } : {}),
|
|
1820
1840
|
...(worktreeFault !== undefined ? { worktreeCause: worktreeFault } : {}),
|
|
1821
1841
|
});
|
|
1842
|
+
const ownerUnboundResult = async (background, tree) => {
|
|
1843
|
+
const wt = await finishWorktree();
|
|
1844
|
+
return notStartedResult(errorResult(`${background ? "Sub-agent not started in background" : "Sub-agent not started"}: the delegation tree's owner does not bind — ${tree.reason.slice(0, 600)}.${wt ? `\n${wt.slice(0, 1600)}` : ""}`, { error: DELEGATION_OWNER_UNBOUND, code: DELEGATION_OWNER_UNBOUND, ...faultDetails(tree.fault) }));
|
|
1845
|
+
};
|
|
1822
1846
|
let injectedTools = [];
|
|
1823
1847
|
let extraToolsNote;
|
|
1824
1848
|
const treeBudget = extraToolsBudget ?? { used: 0 };
|
|
@@ -1947,13 +1971,13 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1947
1971
|
pendingTrigger = [];
|
|
1948
1972
|
return joined;
|
|
1949
1973
|
};
|
|
1950
|
-
const injectObservedRequest = async (text,
|
|
1974
|
+
const injectObservedRequest = async (text, author) => {
|
|
1951
1975
|
const steer = observedSteerRef.steer;
|
|
1952
1976
|
if (!steer)
|
|
1953
1977
|
throw new Error("observed child has no steer lane (report undeliverable)");
|
|
1954
|
-
if (
|
|
1978
|
+
if (author !== "observer")
|
|
1955
1979
|
pendingTrigger.push(text);
|
|
1956
|
-
await steer(text);
|
|
1980
|
+
await steer(author, text);
|
|
1957
1981
|
};
|
|
1958
1982
|
if (observerArm) {
|
|
1959
1983
|
pendingTrigger.push(prompt);
|
|
@@ -2004,7 +2028,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2004
2028
|
...(parentGate.shellGate !== undefined ? { shellGate: parentGate.shellGate } : {}),
|
|
2005
2029
|
admittedOrgScopes: parentGate.admittedOrgScopes,
|
|
2006
2030
|
};
|
|
2007
|
-
const observerInternals = { ...(ctx.interactionPosture !== undefined ? { parentInteractionPosture: ctx.interactionPosture } : {}), ...(pickedRef !== undefined ? { inheritedModelRef: pickedRef } : {}), ...(observerGate !== undefined ? { inheritedGate: observerGate } : {}), toolCeiling: [...childCeiling, childOwnLayer], observerLeg: true };
|
|
2031
|
+
const observerInternals = { ...(ctx.interactionPosture !== undefined ? { parentInteractionPosture: ctx.interactionPosture } : {}), ...(pickedRef !== undefined ? { inheritedModelRef: pickedRef } : {}), ...(observerGate !== undefined ? { inheritedGate: observerGate } : {}), toolCeiling: [...childCeiling, childOwnLayer], observerLeg: true, objectiveAuthor: "observer" };
|
|
2008
2032
|
const r = await opts.runner.runTask(spec, observerInternals);
|
|
2009
2033
|
if (r.terminal.kind !== "completed") {
|
|
2010
2034
|
const endedFace = childTerminalFace(r.terminal);
|
|
@@ -2146,15 +2170,14 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2146
2170
|
const entryCapRoot = reviveClaim !== undefined
|
|
2147
2171
|
? (reviveClaim.row.rootSessionId ?? reviveClaim.row.parentSessionId ?? (reviveClaim.row.sessionScoped ? reviveClaim.row.owner : undefined))
|
|
2148
2172
|
: (ctx.rootSessionId ?? ctx.sessionId);
|
|
2173
|
+
const entryPoolSeat = { poolAnchor: entryCapPoolAnchor, scope: treeScope, root: entryCapRoot };
|
|
2149
2174
|
const openEntryGate = () => openDelegationEntryGate({
|
|
2150
|
-
|
|
2175
|
+
...entryPoolSeat,
|
|
2151
2176
|
registry: opts.background?.registry,
|
|
2152
2177
|
store: opts.background?.agentStore,
|
|
2153
|
-
scope: treeScope,
|
|
2154
|
-
root: entryCapRoot,
|
|
2155
2178
|
caps: entryCaps,
|
|
2156
|
-
revival: reviveClaim !== undefined,
|
|
2157
2179
|
signal: ctx.signal,
|
|
2180
|
+
caller: { owner: ctx.taskId ?? opts.background?.owner, ...(ctx.sessionId !== undefined ? { sessionId: ctx.sessionId } : {}) },
|
|
2158
2181
|
});
|
|
2159
2182
|
const provenanceRequest = ctx.delegationProvenanceForChildren?.();
|
|
2160
2183
|
const childProvenanceRef = provenanceRequest !== undefined ? { current: newDelegationProvenanceAggregate() } : undefined;
|
|
@@ -2174,6 +2197,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2174
2197
|
...(inheritedAllowedTools !== undefined && inheritedAllowedTools.length > 0 ? { inheritedAllowedTools: [...inheritedAllowedTools] } : {}),
|
|
2175
2198
|
...(childProvenanceRef !== undefined && provenanceRequest !== undefined ? { delegationProvenance: { ref: childProvenanceRef, contentSafety: provenanceRequest } } : {}),
|
|
2176
2199
|
...(reviveClaim === undefined && ctx.crossBoundaryTreeForChildren !== undefined ? { crossBoundaryTree: ctx.crossBoundaryTreeForChildren } : {}),
|
|
2200
|
+
...(reviveClaim === undefined && ctx.delegationOwner !== undefined ? { delegationOwner: ctx.delegationOwner } : {}),
|
|
2177
2201
|
...(treeScope !== undefined ? { registryScope: treeScope } : {}),
|
|
2178
2202
|
...(ctx.checkpointScopeForChildren !== undefined ? { checkpointScope: ctx.checkpointScopeForChildren } : {}),
|
|
2179
2203
|
...(ctx.inheritedGateForChildren ? { inheritedGate: ctx.inheritedGateForChildren() } : {}),
|
|
@@ -2188,6 +2212,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2188
2212
|
peerInboundChainRef: createPeerInboundChainRef(reviveClaim?.peerSeed?.hopChain),
|
|
2189
2213
|
...(childDefaultPersona !== undefined ? { defaultSystemPrompt: childDefaultPersona } : {}),
|
|
2190
2214
|
isDelegatedChild: true,
|
|
2215
|
+
objectiveAuthor: reviveClaim !== undefined ? "peer" : "parent_model",
|
|
2191
2216
|
...(childPosture !== undefined ? { parentInteractionPosture: childPosture } : {}),
|
|
2192
2217
|
...(reviveClaim === undefined
|
|
2193
2218
|
? {
|
|
@@ -2232,6 +2257,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2232
2257
|
...(ctx.subagentRetain !== undefined ? { parentRetainLedger: ctx.subagentRetain } : {}),
|
|
2233
2258
|
onForwardEvent: recordingForward,
|
|
2234
2259
|
...(ctx.parentCwd !== undefined ? { callerRoot: ctx.parentCwd } : {}),
|
|
2260
|
+
...(ctx.placementTarget !== undefined ? { placementTarget: ctx.placementTarget } : {}),
|
|
2235
2261
|
...(worktreeDir !== undefined
|
|
2236
2262
|
? { parentCwd: worktreeDir, worktreeOffered: true, onWorkspaceResolved: (ws) => void (childPlacement = ws) }
|
|
2237
2263
|
: childCwd !== undefined
|
|
@@ -2318,7 +2344,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2318
2344
|
...(plainSpec.alwaysLoadTools !== undefined ? { alwaysLoadTools: [...plainSpec.alwaysLoadTools] } : {}),
|
|
2319
2345
|
...(Array.isArray(plainSpec.restoreGatedTools) ? { restoreGatedTools: [...plainSpec.restoreGatedTools] } : {}),
|
|
2320
2346
|
}),
|
|
2321
|
-
internalsSnapshot: { ...
|
|
2347
|
+
internalsSnapshot: { ...withoutWakerSeats(childInternals), ...retainStrip.internalsFlag, ...(internalsExtra ?? {}) },
|
|
2322
2348
|
release: releaseEntry,
|
|
2323
2349
|
});
|
|
2324
2350
|
if (entry) {
|
|
@@ -2387,7 +2413,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2387
2413
|
...(plainSpec.alwaysLoadTools !== undefined ? { alwaysLoadTools: [...plainSpec.alwaysLoadTools] } : {}),
|
|
2388
2414
|
...(Array.isArray(plainSpec.restoreGatedTools) ? { restoreGatedTools: [...plainSpec.restoreGatedTools] } : {}),
|
|
2389
2415
|
}),
|
|
2390
|
-
internalsSnapshot: { ...
|
|
2416
|
+
internalsSnapshot: { ...withoutWakerSeats(childInternals), ...failedRetainStrip.internalsFlag },
|
|
2391
2417
|
release: releaseChild,
|
|
2392
2418
|
});
|
|
2393
2419
|
if (entry) {
|
|
@@ -2465,6 +2491,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2465
2491
|
if (wantsFork) {
|
|
2466
2492
|
let forkedId;
|
|
2467
2493
|
let releaseForked;
|
|
2494
|
+
const forkTree = await delegationOwnerOf(ctx.delegationOwner);
|
|
2495
|
+
if (!forkTree.bound)
|
|
2496
|
+
return ownerUnboundResult(false, forkTree);
|
|
2468
2497
|
try {
|
|
2469
2498
|
if (ctx.hostSessionFork) {
|
|
2470
2499
|
const forkHandle = await ctx.hostSessionFork();
|
|
@@ -2472,7 +2501,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2472
2501
|
releaseForked = forkHandle?.release;
|
|
2473
2502
|
}
|
|
2474
2503
|
else {
|
|
2475
|
-
forkedId = (await opts.runner.sessions.fork?.(ctx.sessionId,
|
|
2504
|
+
forkedId = (await opts.runner.sessions.fork?.(ctx.sessionId, forkTree.owner)) ?? null;
|
|
2476
2505
|
}
|
|
2477
2506
|
}
|
|
2478
2507
|
catch (e) {
|
|
@@ -2489,7 +2518,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2489
2518
|
const forkObjective = `${FORK_DIRECTIVE_FRAME}${prompt}${forkWorktreeNote !== undefined ? `\n\n${forkWorktreeNote}` : ""}${parentSpecSeat?.advisorModel !== undefined ? `\n\n${ADVISOR_FORK_SENTENCE}` : ""}`;
|
|
2490
2519
|
if (wantsBackground) {
|
|
2491
2520
|
const bg = opts.background;
|
|
2492
|
-
const notify =
|
|
2521
|
+
const notify = backgroundSink;
|
|
2493
2522
|
const abort = new AbortController();
|
|
2494
2523
|
const sessionScopedBg = ctx.backgroundScope === "session" && ctx.sessionId !== undefined;
|
|
2495
2524
|
const onHostAbort = () => abort.abort();
|
|
@@ -2603,7 +2632,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2603
2632
|
chargeDelegationEntryHandle(bg.registry, forkEntryGate.key, bg.agentStore, taskId);
|
|
2604
2633
|
oweTerminalDelivery(notify, { task_id: taskId, task_type: "background_agent" });
|
|
2605
2634
|
childInternals.peerSelfRef?.addAxis("h", taskId);
|
|
2606
|
-
bg.registry.bindBackgroundAgentSession(taskId, forkedId);
|
|
2635
|
+
bg.registry.bindBackgroundAgentSession(taskId, forkedId, opts.runner.sessions);
|
|
2636
|
+
stepRecorder.lockTo(taskId);
|
|
2607
2637
|
const forkBgHangAt = Date.now();
|
|
2608
2638
|
bg.registry.attachAgentTerminalNotifier(taskId, () => {
|
|
2609
2639
|
const stoppedByReap = bg.registry.getStopAttribution(taskId) ?? "system";
|
|
@@ -2621,7 +2651,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2621
2651
|
...(completionIdReap !== undefined ? { completionId: completionIdReap } : {}),
|
|
2622
2652
|
};
|
|
2623
2653
|
sinkEmit(backgroundChildTerminal(reapFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId, ...(seqReap !== undefined ? { generation: seqReap } : {}) }));
|
|
2624
|
-
notifier.notify(() => notify
|
|
2654
|
+
notifier.notify(() => notify(reapFrame, { priority: "next" }), "subagent.reapTerminalNotify");
|
|
2625
2655
|
});
|
|
2626
2656
|
if (agentName !== undefined) {
|
|
2627
2657
|
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 +2701,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2671
2701
|
transcriptId: forkedId,
|
|
2672
2702
|
sessionId: forkedId,
|
|
2673
2703
|
parentToolCallId: ctx.toolCallId,
|
|
2674
|
-
progressTaskId:
|
|
2704
|
+
progressTaskId: taskId,
|
|
2675
2705
|
agentType: spawnAgentType,
|
|
2676
2706
|
...(spawnModel !== undefined ? { model: spawnModel } : {}),
|
|
2677
2707
|
...(bgForkCycleSeq !== undefined ? { seq: bgForkCycleSeq } : {}),
|
|
@@ -2685,8 +2715,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2685
2715
|
...forkInternals,
|
|
2686
2716
|
...(forkQuestionStrip !== undefined ? forkQuestionStrip.internalsFlag : {}),
|
|
2687
2717
|
onNotifyInjectorReady: s2ForkNotifyReady,
|
|
2688
|
-
|
|
2689
|
-
...(bgForkCycleSeq !== undefined ? { cycleSeq: bgForkCycleSeq } : {}),
|
|
2718
|
+
...backgroundLegFacts(taskId, bgForkCycleSeq),
|
|
2690
2719
|
onForwardEvent: (e) => {
|
|
2691
2720
|
try {
|
|
2692
2721
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -2721,8 +2750,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2721
2750
|
...forkInternals,
|
|
2722
2751
|
...(forkQuestionStrip !== undefined ? forkQuestionStrip.internalsFlag : {}),
|
|
2723
2752
|
onNotifyInjectorReady: s2ForkNotifyReady,
|
|
2724
|
-
|
|
2725
|
-
...(bgForkCycleSeq !== undefined ? { cycleSeq: bgForkCycleSeq } : {}),
|
|
2753
|
+
...backgroundLegFacts(taskId, bgForkCycleSeq),
|
|
2726
2754
|
onForwardEvent: (e) => {
|
|
2727
2755
|
try {
|
|
2728
2756
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -2732,8 +2760,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2732
2760
|
bgForkActivityBeat(e);
|
|
2733
2761
|
},
|
|
2734
2762
|
};
|
|
2735
|
-
|
|
2736
|
-
|
|
2763
|
+
const bgForkChild = opts.runner.runTask(bgForkSpec, bgForkInternals);
|
|
2764
|
+
extensionSpawn?.launched(taskId, spawnModel);
|
|
2765
|
+
void bgForkChild
|
|
2737
2766
|
.then(async (child) => {
|
|
2738
2767
|
const childFace = childTerminalFace(child.terminal);
|
|
2739
2768
|
settleForkRow(child.terminal);
|
|
@@ -2764,16 +2793,17 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2764
2793
|
const failedFork = !okBg && !reapedBg;
|
|
2765
2794
|
const errCodeFork = failedFork ? childFace.errorCode : undefined;
|
|
2766
2795
|
const errClassFork = failedFork ? classifySubagentError({ kind: "failed", ...(childFace.errorCode !== undefined ? { code: childFace.errorCode } : {}) }) : undefined;
|
|
2767
|
-
const
|
|
2796
|
+
const settleWinnerFork = bg.registry.settleBackgroundAgent(taskId, {
|
|
2768
2797
|
cycle: 0,
|
|
2769
2798
|
status: okBg ? "completed" : reapedBg ? "killed" : "failed",
|
|
2770
2799
|
...resultSettleFields(forkBgResult),
|
|
2771
2800
|
...(!okBg ? { error: reapedBg ? (collateralBg ? BG_AGENT_COLLATERAL_REAP_REASON : BG_AGENT_REAP_STOP_ERROR) : childFace.errorMessage ?? childFace.status } : {}),
|
|
2772
2801
|
...(errCodeFork !== undefined ? { errorCode: errCodeFork } : {}),
|
|
2773
2802
|
...(errClassFork !== undefined ? { retryable: errClassFork.retryable, errorKind: errClassFork.errorKind } : {}),
|
|
2774
|
-
})
|
|
2803
|
+
});
|
|
2804
|
+
const completionIdFork = settleWinnerFork !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
2805
|
+
const settledBg = settleWinnerFork ?? (abort.signal.aborted ? "killed" : okBg ? "completed" : "failed");
|
|
2775
2806
|
const stoppedByBg = settledBg === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
2776
|
-
const completionIdFork = bg.registry.getCompletionId(taskId);
|
|
2777
2807
|
const stillbornFork = child.terminal.kind === "failed" && child.terminal.code === "resume.session_not_found";
|
|
2778
2808
|
if (stillbornFork) {
|
|
2779
2809
|
await releaseBoundChildSession({ registry: bg.registry, taskId }, forkedId, () => (releaseForked ? releaseForked() : opts.runner.sessions.release?.(forkedId)));
|
|
@@ -2787,9 +2817,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2787
2817
|
? `Agent "${shortDesc}" failed: ${failReasonFork}${ccElapsedTag(forkElapsedMs)}`.slice(0, 300) + errorKindClause(errClassFork)
|
|
2788
2818
|
: `${ccCompletionText(shortDesc, settledBg, childFace.status, forkElapsedMs)}`;
|
|
2789
2819
|
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);
|
|
2820
|
+
const forkResultField = await completionResultField(forkBgResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bg.registry.recordArtifactRef(taskId, ref, completionIdFork), notifier);
|
|
2793
2821
|
const forkFrame = {
|
|
2794
2822
|
task_id: taskId,
|
|
2795
2823
|
task_type: "background_agent",
|
|
@@ -2813,7 +2841,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2813
2841
|
sinkEmit(backgroundChildTerminal(forkFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkTranscriptId, ...(stillbornFork ? {} : { transcriptId: forkTranscriptId }), parentToolCallId: ctx.toolCallId, ...(bgForkCycleSeq !== undefined ? { generation: bgForkCycleSeq } : {}) }));
|
|
2814
2842
|
try {
|
|
2815
2843
|
if (ownsTerminalFacesFork)
|
|
2816
|
-
notify
|
|
2844
|
+
notify(forkFrame, { priority: "next" });
|
|
2817
2845
|
}
|
|
2818
2846
|
catch {
|
|
2819
2847
|
}
|
|
@@ -2826,15 +2854,16 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2826
2854
|
const msgFork = childThrownText(e);
|
|
2827
2855
|
const errCodeForkReject = killed ? undefined : thrownErrorCode(e);
|
|
2828
2856
|
const errClassForkReject = killed ? undefined : classifySubagentError({ kind: "failed", ...(errCodeForkReject !== undefined ? { code: errCodeForkReject } : {}) });
|
|
2829
|
-
const
|
|
2857
|
+
const settleWinnerForkReject = bg.registry.settleBackgroundAgent(taskId, {
|
|
2830
2858
|
cycle: 0,
|
|
2831
2859
|
status: killed ? "killed" : "failed",
|
|
2832
2860
|
error: killed ? BG_AGENT_REAP_STOP_ERROR : msgFork,
|
|
2833
2861
|
...(errCodeForkReject !== undefined ? { errorCode: errCodeForkReject } : {}),
|
|
2834
2862
|
...(errClassForkReject !== undefined ? { retryable: errClassForkReject.retryable, errorKind: errClassForkReject.errorKind } : {}),
|
|
2835
|
-
})
|
|
2863
|
+
});
|
|
2864
|
+
const completionIdForkReject = settleWinnerForkReject !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
2865
|
+
const settledBg = settleWinnerForkReject ?? (killed ? "killed" : "failed");
|
|
2836
2866
|
const stoppedByBg = settledBg === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
2837
|
-
const completionIdForkReject = bg.registry.getCompletionId(taskId);
|
|
2838
2867
|
const summaryBg = `${shortDesc} — ${settledBg === "failed" ? `failed: ${msgFork}` : settledBg}`.slice(0, 300) + (settledBg === "failed" ? errorKindClause(errClassForkReject) : "");
|
|
2839
2868
|
const ownsTerminalFacesForkReject = bg.registry.claimAgentTerminalNotify(taskId);
|
|
2840
2869
|
const forkRejectFrame = {
|
|
@@ -2854,7 +2883,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2854
2883
|
sinkEmit(backgroundChildTerminal(forkRejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId, ...(bgForkCycleSeq !== undefined ? { generation: bgForkCycleSeq } : {}) }));
|
|
2855
2884
|
try {
|
|
2856
2885
|
if (ownsTerminalFacesForkReject)
|
|
2857
|
-
notify
|
|
2886
|
+
notify(forkRejectFrame, { priority: "next" });
|
|
2858
2887
|
}
|
|
2859
2888
|
catch {
|
|
2860
2889
|
}
|
|
@@ -2863,7 +2892,6 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2863
2892
|
content: asyncLaunchedReceipt({
|
|
2864
2893
|
taskId,
|
|
2865
2894
|
workingLine: `The forked agent inherits your full current context and works on its prompt in the background.`,
|
|
2866
|
-
notify: Boolean(notify),
|
|
2867
2895
|
notes: [
|
|
2868
2896
|
modelNote,
|
|
2869
2897
|
extraToolsNote,
|
|
@@ -2878,9 +2906,10 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2878
2906
|
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
2907
|
};
|
|
2880
2908
|
}
|
|
2881
|
-
const bgIgnoredNote =
|
|
2882
|
-
|
|
2883
|
-
|
|
2909
|
+
const bgIgnoredNote = ranSyncNote ??
|
|
2910
|
+
(a.run_in_background === true
|
|
2911
|
+
? `note: run_in_background was ignored for subagent_type "${FORK_SUBAGENT_TYPE}" — the fork ran synchronously (this delegation tool has no background surface configured).`
|
|
2912
|
+
: undefined);
|
|
2884
2913
|
const syncForkEntryGate = await openEntryGate();
|
|
2885
2914
|
if (ctx.signal?.aborted) {
|
|
2886
2915
|
try {
|
|
@@ -2987,7 +3016,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2987
3016
|
if (ctx.checkpointStoreForChildren !== undefined && ctx.checkpointStoreForChildren !== "disabled" && bg.checkpointStore !== undefined && bg.checkpointStore !== ctx.checkpointStoreForChildren)
|
|
2988
3017
|
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
3018
|
const childParkStore = ctx.checkpointStoreForChildren === undefined ? bg.checkpointStore : ctx.checkpointStoreForChildren === "disabled" ? undefined : ctx.checkpointStoreForChildren;
|
|
2990
|
-
const notify =
|
|
3019
|
+
const notify = backgroundSink;
|
|
2991
3020
|
const abort = new AbortController();
|
|
2992
3021
|
const reviveRow = reviveClaim?.row;
|
|
2993
3022
|
const parkedResume = reviveClaim?.parkedResume;
|
|
@@ -3004,10 +3033,24 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3004
3033
|
const shortDesc = reviveRow?.description ?? String(a.description ?? "sub-agent").slice(0, 200);
|
|
3005
3034
|
const bgOwner = reviveRow !== undefined ? reviveRow.owner : sessionScopedBg ? ctx.sessionId : ctx.taskId ?? bg.owner;
|
|
3006
3035
|
const bgScope = treeScope;
|
|
3007
|
-
const
|
|
3008
|
-
|
|
3009
|
-
{
|
|
3010
|
-
const
|
|
3036
|
+
const childTreeOwner = () => (reviveRow !== undefined ? rowOwnerReading(opts.runner.sessions, reviveRow.sessionId) : delegationOwnerOf(ctx.delegationOwner));
|
|
3037
|
+
let placedTreeOwner;
|
|
3038
|
+
if (reviveRow === undefined && bg.agentStore !== undefined && opts.runner.sessions.placements?.subagent !== undefined) {
|
|
3039
|
+
const tree = await childTreeOwner();
|
|
3040
|
+
if (!tree.bound) {
|
|
3041
|
+
dropHostAbortListener();
|
|
3042
|
+
await cancelObserver();
|
|
3043
|
+
return ownerUnboundResult(true, tree);
|
|
3044
|
+
}
|
|
3045
|
+
placedTreeOwner = tree.owner;
|
|
3046
|
+
}
|
|
3047
|
+
const bgEntryPool = delegationEntryPool(entryPoolSeat);
|
|
3048
|
+
const capLedgerKey = bgEntryPool.key;
|
|
3049
|
+
if (reviveRow !== undefined) {
|
|
3050
|
+
bgEntryPool.occupy("registered");
|
|
3051
|
+
}
|
|
3052
|
+
else {
|
|
3053
|
+
const admission = (await openEntryGate()).admit("registered");
|
|
3011
3054
|
if (!admission.admitted) {
|
|
3012
3055
|
dropHostAbortListener();
|
|
3013
3056
|
await cancelObserver();
|
|
@@ -3145,8 +3188,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3145
3188
|
};
|
|
3146
3189
|
const bgChildSessionId = reviveRow?.sessionId ?? uuidv7();
|
|
3147
3190
|
const bgStartedAt = Date.now();
|
|
3148
|
-
stepRecorder.lockTo(
|
|
3149
|
-
bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId);
|
|
3191
|
+
stepRecorder.lockTo(taskId);
|
|
3192
|
+
bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
|
|
3150
3193
|
const bgCycleSeq = bg.registry.backgroundAgentCycleSeq(taskId);
|
|
3151
3194
|
bg.registry.attachAgentTerminalNotifier(taskId, () => {
|
|
3152
3195
|
const stoppedByReap = bg.registry.getStopAttribution(taskId) ?? "system";
|
|
@@ -3165,7 +3208,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3165
3208
|
...(completionIdReap !== undefined ? { completionId: completionIdReap } : {}),
|
|
3166
3209
|
};
|
|
3167
3210
|
sinkEmit(backgroundChildTerminal(reapFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId, ...(seqReap !== undefined ? { generation: seqReap } : {}) }));
|
|
3168
|
-
notifier.notify(() => notify
|
|
3211
|
+
notifier.notify(() => notify(reapFrame, { priority: "next" }), "subagent.reapTerminalNotify");
|
|
3169
3212
|
});
|
|
3170
3213
|
const bgDurableProbe = bg.registry.durableAgentRowProbe(taskId);
|
|
3171
3214
|
const bgRowConfirmed = async () => (bgDurableProbe ? await bgDurableProbe().catch(() => false) : false);
|
|
@@ -3205,9 +3248,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3205
3248
|
: ctx.subagentRetain;
|
|
3206
3249
|
if (sessionScopedBg && bgRetainLedger)
|
|
3207
3250
|
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
|
-
});
|
|
3251
|
+
const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, { registry: bg.registry, taskId }, backgroundLegFacts(taskId));
|
|
3211
3252
|
if (bgRetain) {
|
|
3212
3253
|
bg.registry.markRetainedContinuation(taskId);
|
|
3213
3254
|
const origRelease = bgRetain.release;
|
|
@@ -3216,7 +3257,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3216
3257
|
await origRelease();
|
|
3217
3258
|
};
|
|
3218
3259
|
}
|
|
3219
|
-
bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId);
|
|
3260
|
+
bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
|
|
3220
3261
|
const forwardDurableApproval = ctx.durableApprovalForChildren !== undefined &&
|
|
3221
3262
|
bg.agentStore !== undefined &&
|
|
3222
3263
|
childParkStore !== undefined &&
|
|
@@ -3250,7 +3291,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3250
3291
|
transcriptId: bgChildSessionId,
|
|
3251
3292
|
sessionId: bgChildSessionId,
|
|
3252
3293
|
parentToolCallId: ctx.toolCallId,
|
|
3253
|
-
progressTaskId:
|
|
3294
|
+
progressTaskId: taskId,
|
|
3254
3295
|
agentType: spawnAgentType,
|
|
3255
3296
|
...(spawnModel !== undefined ? { model: spawnModel } : {}),
|
|
3256
3297
|
...(bgCycleSeq !== undefined ? { seq: bgCycleSeq } : {}),
|
|
@@ -3259,15 +3300,16 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3259
3300
|
usage: { toolUses: toolStarts },
|
|
3260
3301
|
});
|
|
3261
3302
|
}, () => bg.registry.noteBackgroundAgentActivity(taskId));
|
|
3262
|
-
const bgPlacementRoot =
|
|
3263
|
-
const bgPlacementParent =
|
|
3264
|
-
const bgPlacement =
|
|
3303
|
+
const bgPlacementRoot = ctx.rootSessionId ?? ctx.sessionId;
|
|
3304
|
+
const bgPlacementParent = ctx.sessionId;
|
|
3305
|
+
const bgPlacement = placedTreeOwner !== undefined
|
|
3265
3306
|
? {
|
|
3266
3307
|
kind: "subagent",
|
|
3267
3308
|
...(bgScope !== undefined ? { scope: bgScope } : {}),
|
|
3268
3309
|
...(bgPlacementParent !== undefined ? { parentSessionId: bgPlacementParent } : {}),
|
|
3269
3310
|
...(bgPlacementRoot !== undefined ? { rootSessionId: bgPlacementRoot } : {}),
|
|
3270
3311
|
handle: taskId,
|
|
3312
|
+
owner: placedTreeOwner,
|
|
3271
3313
|
}
|
|
3272
3314
|
: undefined;
|
|
3273
3315
|
const bgInternals = bgSink
|
|
@@ -3276,8 +3318,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3276
3318
|
...(bgQuestionStrip !== undefined ? bgQuestionStrip.internalsFlag : {}),
|
|
3277
3319
|
...(bgPlacement !== undefined ? { sessionPlacement: bgPlacement } : {}),
|
|
3278
3320
|
onNotifyInjectorReady: s2NotifyReady,
|
|
3279
|
-
|
|
3280
|
-
...(bgCycleSeq !== undefined ? { cycleSeq: bgCycleSeq } : {}),
|
|
3321
|
+
...backgroundLegFacts(taskId, bgCycleSeq),
|
|
3281
3322
|
onForwardEvent: (e) => {
|
|
3282
3323
|
try {
|
|
3283
3324
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -3313,8 +3354,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3313
3354
|
...(bgQuestionStrip !== undefined ? bgQuestionStrip.internalsFlag : {}),
|
|
3314
3355
|
...(bgPlacement !== undefined ? { sessionPlacement: bgPlacement } : {}),
|
|
3315
3356
|
onNotifyInjectorReady: s2NotifyReady,
|
|
3316
|
-
|
|
3317
|
-
...(bgCycleSeq !== undefined ? { cycleSeq: bgCycleSeq } : {}),
|
|
3357
|
+
...backgroundLegFacts(taskId, bgCycleSeq),
|
|
3318
3358
|
onForwardEvent: (e) => {
|
|
3319
3359
|
try {
|
|
3320
3360
|
recordingForward(e, { bgAgentId: taskId });
|
|
@@ -3420,7 +3460,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3420
3460
|
...(pr.inheritedGate !== undefined ? { inheritedGate: pr.inheritedGate } : {}),
|
|
3421
3461
|
afterCheckpointResolve,
|
|
3422
3462
|
});
|
|
3423
|
-
observedSteerRef.steer = (
|
|
3463
|
+
observedSteerRef.steer = authoredSteerOf(bgStream);
|
|
3424
3464
|
for await (const ev of bgStream)
|
|
3425
3465
|
observerTap?.record(ev);
|
|
3426
3466
|
childResult = await bgStream.result();
|
|
@@ -3458,7 +3498,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3458
3498
|
: observerPairing
|
|
3459
3499
|
? (() => {
|
|
3460
3500
|
const bgStream = opts.runner.runTaskStream(bgSpec, undefined, bgInternals);
|
|
3461
|
-
observedSteerRef.steer = (
|
|
3501
|
+
observedSteerRef.steer = authoredSteerOf(bgStream);
|
|
3462
3502
|
return (async () => {
|
|
3463
3503
|
for await (const ev of bgStream)
|
|
3464
3504
|
observerTap?.record(ev);
|
|
@@ -3466,6 +3506,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3466
3506
|
})();
|
|
3467
3507
|
})()
|
|
3468
3508
|
: opts.runner.runTask(bgSpec, bgInternals);
|
|
3509
|
+
extensionSpawn?.launched(taskId, spawnModel);
|
|
3469
3510
|
void bgChildPromise
|
|
3470
3511
|
.then(async (child) => {
|
|
3471
3512
|
const childFace = childTerminalFace(child.terminal);
|
|
@@ -3527,7 +3568,10 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3527
3568
|
else {
|
|
3528
3569
|
let attested = false;
|
|
3529
3570
|
try {
|
|
3530
|
-
await
|
|
3571
|
+
const tree = placedTreeOwner !== undefined ? { bound: true, owner: placedTreeOwner } : await childTreeOwner();
|
|
3572
|
+
if (!tree.bound)
|
|
3573
|
+
throw new Error(tree.reason);
|
|
3574
|
+
await bg.ensureChildSessionDurable(bgChildSessionId, { owner: tree.owner });
|
|
3531
3575
|
attested = true;
|
|
3532
3576
|
}
|
|
3533
3577
|
catch {
|
|
@@ -3571,7 +3615,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3571
3615
|
: childFace.errorCode
|
|
3572
3616
|
: undefined;
|
|
3573
3617
|
const errClassBg = failedBg ? classifySubagentError({ kind: "failed", ...(childFace.errorCode !== undefined ? { code: childFace.errorCode } : {}) }) : undefined;
|
|
3574
|
-
const
|
|
3618
|
+
const settleWinnerBg = bg.registry.settleBackgroundAgent(taskId, {
|
|
3575
3619
|
cycle: 0,
|
|
3576
3620
|
status: ok ? "completed" : reaped ? "killed" : "failed",
|
|
3577
3621
|
seq: seqAtSettle ?? 1,
|
|
@@ -3580,13 +3624,14 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3580
3624
|
...(errCodeBg !== undefined ? { errorCode: errCodeBg } : {}),
|
|
3581
3625
|
...(errClassBg !== undefined ? { retryable: errClassBg.retryable, errorKind: errClassBg.errorKind } : {}),
|
|
3582
3626
|
...(failedBg && child.retryAfterMs !== undefined ? { retryAfterMs: child.retryAfterMs } : {}),
|
|
3583
|
-
})
|
|
3627
|
+
});
|
|
3628
|
+
const completionIdBg = settleWinnerBg !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
3629
|
+
const settled = settleWinnerBg ??
|
|
3584
3630
|
(abort.signal.aborted ? "killed" : ok ? "completed" : "failed");
|
|
3585
3631
|
if (!bgRetain && reviveRow === undefined && !(await bgRowConfirmed())) {
|
|
3586
3632
|
await releaseBoundChildSession({ registry: bg.registry, taskId }, child.sessionId, () => opts.runner.sessions.release(child.sessionId));
|
|
3587
3633
|
}
|
|
3588
3634
|
const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
3589
|
-
const completionIdBg = bg.registry.getCompletionId(taskId);
|
|
3590
3635
|
const observerNote = observerNoteFor(await startBoundedObserverDrain());
|
|
3591
3636
|
const residual = residualFields();
|
|
3592
3637
|
const bgDurableRow = await bgRowConfirmed();
|
|
@@ -3604,9 +3649,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3604
3649
|
? `Agent "${shortDesc}" failed: ${failReasonBg}${ccElapsedTag(bgElapsedMs)}${observerNote}`.slice(0, 300) + errorKindClause(errClassBg)
|
|
3605
3650
|
: `${ccCompletionText(shortDesc, settled, childFace.status, bgElapsedMs)}${observerNote}`;
|
|
3606
3651
|
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);
|
|
3652
|
+
const bgResultField = await completionResultField(bgHandbackResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bg.registry.recordArtifactRef(taskId, ref, completionIdBg), notifier);
|
|
3610
3653
|
const completionFrame = {
|
|
3611
3654
|
task_id: taskId,
|
|
3612
3655
|
task_type: "background_agent",
|
|
@@ -3629,21 +3672,21 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3629
3672
|
};
|
|
3630
3673
|
if (ownsTerminalFaces)
|
|
3631
3674
|
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 (
|
|
3675
|
+
const gateOwners = ownsTerminalFaces && settled === "completed" && bgRetain !== undefined ? childOwnerKeys(child.taskId, bgRetain.childSessionId) : [];
|
|
3676
|
+
const aliveBgCount = runningBackgroundUnder(bg.registry, gateOwners);
|
|
3677
|
+
if (bgRetain !== undefined && aliveBgCount > 0) {
|
|
3635
3678
|
parkCompletionNotify({
|
|
3636
3679
|
registry: bg.registry,
|
|
3637
3680
|
entry: bgRetain,
|
|
3638
|
-
|
|
3681
|
+
owners: gateOwners,
|
|
3639
3682
|
pendingCount: aliveBgCount,
|
|
3640
3683
|
payload: completionFrame,
|
|
3641
|
-
notify
|
|
3684
|
+
notify,
|
|
3642
3685
|
});
|
|
3643
3686
|
}
|
|
3644
3687
|
else if (ownsTerminalFaces) {
|
|
3645
3688
|
try {
|
|
3646
|
-
notify
|
|
3689
|
+
notify(completionFrame, { priority: "next" });
|
|
3647
3690
|
}
|
|
3648
3691
|
catch {
|
|
3649
3692
|
}
|
|
@@ -3665,19 +3708,20 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3665
3708
|
const msg = childThrownText(e);
|
|
3666
3709
|
const errCodeBgReject = killed ? undefined : thrownErrorCode(e);
|
|
3667
3710
|
const errClassBgReject = killed ? undefined : classifySubagentError({ kind: "failed", ...(errCodeBgReject !== undefined ? { code: errCodeBgReject } : {}) });
|
|
3668
|
-
const
|
|
3711
|
+
const settleWinnerBgReject = bg.registry.settleBackgroundAgent(taskId, {
|
|
3669
3712
|
cycle: 0,
|
|
3670
3713
|
status: killed ? "killed" : "failed",
|
|
3671
3714
|
error: msg,
|
|
3672
3715
|
seq: seqAtSettle ?? 1,
|
|
3673
3716
|
...(errCodeBgReject !== undefined ? { errorCode: errCodeBgReject } : {}),
|
|
3674
3717
|
...(errClassBgReject !== undefined ? { retryable: errClassBgReject.retryable, errorKind: errClassBgReject.errorKind } : {}),
|
|
3675
|
-
})
|
|
3718
|
+
});
|
|
3719
|
+
const completionIdBgReject = settleWinnerBgReject !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
|
|
3720
|
+
const settled = settleWinnerBgReject ?? (killed ? "killed" : "failed");
|
|
3676
3721
|
if (!bgRetain && reviveRow === undefined && !(await bgRowConfirmed())) {
|
|
3677
3722
|
await releaseBoundChildSession({ registry: bg.registry, taskId }, bgChildSessionId, () => opts.runner.sessions.release(bgChildSessionId));
|
|
3678
3723
|
}
|
|
3679
3724
|
const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
3680
|
-
const completionIdBgReject = bg.registry.getCompletionId(taskId);
|
|
3681
3725
|
const observerNote = observerNoteFor(await startBoundedObserverDrain());
|
|
3682
3726
|
const ownsTerminalFacesReject = bg.registry.claimAgentTerminalNotify(taskId);
|
|
3683
3727
|
const rejectFrame = {
|
|
@@ -3698,7 +3742,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3698
3742
|
sinkEmit(backgroundChildTerminal(rejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId, ...(bgCycleSeq !== undefined ? { generation: bgCycleSeq } : {}) }));
|
|
3699
3743
|
try {
|
|
3700
3744
|
if (ownsTerminalFacesReject)
|
|
3701
|
-
notify
|
|
3745
|
+
notify(rejectFrame, { priority: "next" });
|
|
3702
3746
|
}
|
|
3703
3747
|
catch {
|
|
3704
3748
|
}
|
|
@@ -3733,7 +3777,6 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3733
3777
|
content: asyncLaunchedReceipt({
|
|
3734
3778
|
taskId,
|
|
3735
3779
|
workingLine: `The agent is working in the background.`,
|
|
3736
|
-
notify: Boolean(notify),
|
|
3737
3780
|
notes: [
|
|
3738
3781
|
modelNote,
|
|
3739
3782
|
extraToolsNote,
|
|
@@ -3769,7 +3812,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3769
3812
|
if (retainEntry)
|
|
3770
3813
|
stepRecorder.lockTo(retainEntry.childSessionId);
|
|
3771
3814
|
const stream = opts.runner.runTaskStream({ ...buildChildSpec(ctx.signal), ...(retainEntry ? { sessionId: retainEntry.childSessionId } : {}) }, undefined, childInternals);
|
|
3772
|
-
observedSteerRef.steer = (
|
|
3815
|
+
observedSteerRef.steer = authoredSteerOf(stream);
|
|
3773
3816
|
let settleResolve;
|
|
3774
3817
|
const settled = new Promise((r) => { settleResolve = r; });
|
|
3775
3818
|
if (ctx.onSubagentSpawn) {
|
|
@@ -3785,6 +3828,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3785
3828
|
...(ctx.onQuestion !== undefined ? { currentOnQuestion: ctx.onQuestion } : {}),
|
|
3786
3829
|
...(ctx.autoModeReview !== undefined ? { currentAutoModeReview: ctx.autoModeReview } : {}),
|
|
3787
3830
|
currentMcpHostSeats: ctx.mountedMcp?.().hostSeats,
|
|
3831
|
+
currentPlacementTarget: ctx.placementTarget,
|
|
3788
3832
|
});
|
|
3789
3833
|
notifier.notify(() => ctx.onSubagentSpawn?.(createSteerHandle(stream, ctx.toolCallId, childAgentName, settled, {
|
|
3790
3834
|
resume,
|
|
@@ -3866,6 +3910,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3866
3910
|
`status: ${childFace.status}`,
|
|
3867
3911
|
modelNote ?? "",
|
|
3868
3912
|
extraToolsNote ?? "",
|
|
3913
|
+
ranSyncNote ?? "",
|
|
3869
3914
|
worktreeLine ?? "",
|
|
3870
3915
|
childFace.blockedReason ? `blocked_reason: ${inlineUntrusted(childFace.blockedReason, REPORT_FIELD_MAX)}` : "",
|
|
3871
3916
|
childFace.errorMessage ? `error: ${inlineUntrusted(childFace.errorMessage, REPORT_FIELD_MAX)}` : "",
|