@sema-agent/core 7.67.2 → 7.68.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 +1533 -0
- package/README.md +18 -9
- package/README.zh-CN.md +16 -8
- package/dist/agents/agent-definition.d.ts +1 -1
- package/dist/agents/agent-definition.js +4 -1
- package/dist/agents/cascade.d.ts +2 -2
- package/dist/agents/cascade.js +3 -1
- package/dist/agents/cumulative-stats.d.ts +2 -1
- package/dist/agents/cumulative-stats.js +4 -1
- package/dist/agents/list-agents-tool.d.ts +30 -0
- package/dist/agents/list-agents-tool.js +45 -3
- package/dist/agents/peer-admission.d.ts +2 -2
- package/dist/agents/peer-session-drain.d.ts +2 -0
- package/dist/agents/peer-session-drain.js +1 -0
- package/dist/agents/repair-loop.js +3 -1
- package/dist/agents/retain-ledger.d.ts +61 -8
- package/dist/agents/retain-ledger.js +25 -3
- package/dist/agents/roster-store.d.ts +4 -2
- package/dist/agents/send-message-tool.d.ts +1 -1
- package/dist/agents/send-message-tool.js +20 -15
- package/dist/agents/subagent-steps.js +2 -10
- package/dist/agents/subagent.d.ts +3 -0
- package/dist/agents/subagent.js +106 -76
- package/dist/agents/tool-filter.d.ts +20 -11
- package/dist/agents/tool-filter.js +8 -4
- package/dist/agents/verify.d.ts +3 -1
- package/dist/agents/verify.js +2 -0
- package/dist/brain/anthropic.js +4 -4
- package/dist/brain/errors.d.ts +20 -0
- package/dist/brain/errors.js +114 -0
- package/dist/brain/open-responses.js +3 -1
- package/dist/brain/openai.js +3 -1
- package/dist/brain/provider-message.d.ts +5 -3
- package/dist/brain/provider-message.js +35 -8
- package/dist/brain/reasoning-request.d.ts +73 -19
- package/dist/brain/reasoning-request.js +164 -72
- package/dist/brain/reasoning-stamp.d.ts +26 -0
- package/dist/brain/reasoning-stamp.js +10 -0
- package/dist/brain/reasoning.d.ts +95 -162
- package/dist/brain/reasoning.js +31 -86
- package/dist/brain/route-adjudicator.d.ts +9 -7
- package/dist/brain/route-adjudicator.js +12 -10
- package/dist/brain/status-sink.d.ts +19 -64
- package/dist/brain/status-sink.js +5 -21
- package/dist/brain/stream-engine.d.ts +11 -2
- package/dist/brain/stream-engine.js +10 -0
- package/dist/core/a2a.d.ts +17 -5
- package/dist/core/a2a.js +11 -3
- package/dist/core/allow-entry.d.ts +35 -15
- package/dist/core/allow-entry.js +47 -60
- package/dist/core/ask-headline.d.ts +68 -0
- package/dist/core/ask-headline.js +23 -0
- package/dist/core/ask-origin.d.ts +36 -8
- package/dist/core/ask-origin.js +17 -10
- package/dist/core/ask-question.d.ts +34 -7
- package/dist/core/ask-question.js +10 -1
- package/dist/core/ask-unresolvable-notice.d.ts +7 -0
- package/dist/core/ask-unresolvable-notice.js +9 -3
- package/dist/core/auto-strip.d.ts +53 -0
- package/dist/core/auto-strip.js +76 -0
- package/dist/core/background-agent-store.d.ts +45 -5
- package/dist/core/background-agent-store.js +69 -15
- package/dist/core/background-shell.d.ts +2 -2
- package/dist/core/caller-text.js +2 -2
- package/dist/core/canonical-json.d.ts +13 -0
- package/dist/core/canonical-json.js +7 -0
- package/dist/core/checkpoint-features.d.ts +66 -20
- package/dist/core/checkpoint-features.js +12 -1
- package/dist/core/checkpoint-generation.d.ts +1 -1
- package/dist/core/checkpoint-queries.d.ts +1 -1
- package/dist/core/checkpoint-queries.js +4 -1
- package/dist/core/checkpoint-requirements.d.ts +25 -1
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-row-verdict.d.ts +1 -0
- package/dist/core/checkpoint-row-verdict.js +4 -0
- package/dist/core/checkpoint-store.d.ts +66 -38
- package/dist/core/checkpoint-store.js +15 -6
- package/dist/core/child-clamp-seats.d.ts +6 -0
- package/dist/core/child-clamp-seats.js +1 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +1 -0
- package/dist/core/delegation-frames.d.ts +9 -12
- package/dist/core/delegation-frames.js +9 -8
- package/dist/core/engine-capabilities.d.ts +21 -8
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +147 -34
- package/dist/core/engine-notice.js +27 -16
- package/dist/core/engine-storage-backend.d.ts +2 -1
- package/dist/core/env-budget.js +3 -3
- package/dist/core/env-knob-announce.d.ts +10 -10
- package/dist/core/env-knob-announce.js +3 -6
- package/dist/core/file-history-store.d.ts +29 -4
- package/dist/core/file-history-store.js +13 -0
- package/dist/core/frame-settlement.d.ts +2 -1
- package/dist/core/gate-fold.js +1 -1
- package/dist/core/gate-lanes.js +56 -49
- package/dist/core/governance-codes.d.ts +39 -3
- package/dist/core/governance-codes.js +61 -3
- package/dist/core/hooks.d.ts +29 -11
- package/dist/core/hooks.js +5 -2
- package/dist/core/human-input-projection.js +3 -3
- package/dist/core/input-author.d.ts +17 -3
- package/dist/core/input-author.js +15 -3
- package/dist/core/leg-identity.d.ts +10 -28
- package/dist/core/leg-identity.js +1 -21
- package/dist/core/lsp.d.ts +18 -13
- package/dist/core/lsp.js +30 -22
- package/dist/core/mailbox-store.d.ts +1 -1
- package/dist/core/mailbox-store.js +4 -4
- package/dist/core/mcp-connection-pool.d.ts +93 -4
- package/dist/core/mcp-connection-pool.js +104 -1
- package/dist/core/mcp-failure.d.ts +38 -12
- package/dist/core/mcp-failure.js +9 -13
- package/dist/core/mcp-probe.d.ts +4 -3
- package/dist/core/mcp-server-link.d.ts +4 -2
- package/dist/core/mcp-server-link.js +4 -5
- package/dist/core/mcp-server-spec.d.ts +3 -3
- package/dist/core/mcp-server-unavailable-notice.d.ts +22 -8
- package/dist/core/mcp-server-unavailable-notice.js +18 -4
- package/dist/core/mcp.d.ts +40 -6
- package/dist/core/mcp.js +39 -13
- package/dist/core/memory-engine/content-origin.js +2 -2
- package/dist/core/memory-engine/control-objects.d.ts +2 -4
- package/dist/core/memory-engine/control-objects.js +2 -10
- package/dist/core/memory-engine/delegation-settlement.js +6 -1
- package/dist/core/memory-engine/dual-root.js +3 -0
- package/dist/core/memory-engine/engine.d.ts +6 -4
- package/dist/core/memory-engine/engine.js +32 -29
- package/dist/core/memory-engine/file-backend.d.ts +20 -5
- package/dist/core/memory-engine/file-backend.js +21 -31
- package/dist/core/memory-engine/frontmatter.d.ts +2 -0
- package/dist/core/memory-engine/frontmatter.js +4 -0
- package/dist/core/memory-engine/layout.d.ts +114 -20
- package/dist/core/memory-engine/layout.js +340 -22
- package/dist/core/memory-engine/memory-deployment.d.ts +7 -5
- package/dist/core/memory-engine/mount-failed-notice.d.ts +19 -7
- package/dist/core/memory-engine/mount-failed-notice.js +43 -10
- package/dist/core/memory-engine/sync-client.js +4 -5
- package/dist/core/model-fallbacks.d.ts +5 -1
- package/dist/core/model-fallbacks.js +3 -3
- package/dist/core/model-receipt.d.ts +2 -1
- package/dist/core/model-receipt.js +12 -1
- package/dist/core/mods/kernel/dispatch.d.ts +2 -2
- package/dist/core/mods/kernel/dispatch.js +14 -6
- package/dist/core/mods/kernel/events.d.ts +8 -5
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/kernel/index.d.ts +1 -1
- package/dist/core/mods/kernel/registration.d.ts +9 -0
- package/dist/core/mods/package.js +1 -1
- package/dist/core/mods/session-append.d.ts +4 -2
- package/dist/core/mods/session-append.js +3 -0
- package/dist/core/mods/stations.d.ts +7 -11
- package/dist/core/mods/stations.js +4 -7
- package/dist/core/mods/tool-call.d.ts +10 -8
- package/dist/core/mods/tool-call.js +15 -18
- package/dist/core/mounted-mcp.d.ts +0 -4
- package/dist/core/mounted-mcp.js +1 -1
- package/dist/core/park-noun.d.ts +24 -0
- package/dist/core/park-noun.js +21 -0
- package/dist/core/park-resumability.d.ts +60 -0
- package/dist/core/park-resumability.js +30 -0
- package/dist/core/permission-rule-provider.d.ts +24 -2
- package/dist/core/permission-rule-provider.js +11 -8
- package/dist/core/permission-rule-store.d.ts +8 -1
- package/dist/core/permission-rule-store.js +2 -3
- package/dist/core/permission-rules.d.ts +2 -1
- package/dist/core/permission-rules.js +8 -4
- package/dist/core/persisted-rule-arms.d.ts +3 -0
- package/dist/core/persisted-rule-arms.js +2 -1
- package/dist/core/present-plan-tool.d.ts +47 -3
- package/dist/core/present-plan-tool.js +62 -4
- package/dist/core/principal-name.d.ts +1 -1
- package/dist/core/principal-name.js +5 -5
- package/dist/core/process-identity.js +10 -5
- package/dist/core/protocol-http-auth.d.ts +30 -9
- package/dist/core/protocol-http-auth.js +113 -59
- package/dist/core/read-only-shell.js +9 -5
- package/dist/core/redaction-marks.d.ts +4 -26
- package/dist/core/redaction-marks.js +9 -21
- package/dist/core/remote-env.d.ts +43 -16
- package/dist/core/remote-env.js +1 -1
- package/dist/core/request-copy-projection.d.ts +1 -1
- package/dist/core/request-copy-projection.js +40 -50
- package/dist/core/resume-config-judge.js +1 -1
- package/dist/core/resume-startup-cause.d.ts +35 -18
- package/dist/core/resume-startup-cause.js +13 -10
- package/dist/core/retention.d.ts +167 -25
- package/dist/core/retention.js +100 -20
- package/dist/core/roles.d.ts +6 -0
- package/dist/core/roles.js +11 -5
- package/dist/core/rule-lane-reads.d.ts +3 -0
- package/dist/core/rule-lane-reads.js +5 -1
- package/dist/core/rule-store-fault.d.ts +70 -0
- package/dist/core/rule-store-fault.js +102 -0
- package/dist/core/runner/advertised-writable-dirs.js +16 -31
- package/dist/core/runner/announce-once-ledger.d.ts +19 -2
- package/dist/core/runner/announce-once-ledger.js +24 -2
- package/dist/core/runner/assemble-result.d.ts +6 -0
- package/dist/core/runner/assemble-result.js +1 -1
- package/dist/core/runner/auto-strip-notice.d.ts +36 -0
- package/dist/core/runner/auto-strip-notice.js +59 -0
- package/dist/core/runner/branch-window.d.ts +3 -0
- package/dist/core/runner/branch-window.js +37 -0
- package/dist/core/runner/caller-roster.d.ts +8 -3
- package/dist/core/runner/capability-withheld-seat.js +3 -9
- package/dist/core/runner/clock-and-limits.d.ts +22 -1
- package/dist/core/runner/clock-and-limits.js +30 -0
- package/dist/core/runner/contracts.d.ts +58 -35
- package/dist/core/runner/credential-refusal-seat.d.ts +2 -0
- package/dist/core/runner/credential-refusal-seat.js +47 -0
- package/dist/core/runner/cross-boundary-lane.js +6 -4
- package/dist/core/runner/decide-continuation.js +1 -1
- package/dist/core/runner/file-history-restore.d.ts +53 -2
- package/dist/core/runner/file-history-restore.js +29 -10
- package/dist/core/runner/forward-sink.d.ts +14 -1
- package/dist/core/runner/forward-sink.js +14 -12
- package/dist/core/runner/gate-exit.d.ts +8 -7
- package/dist/core/runner/gate-exit.js +13 -13
- package/dist/core/runner/git-status-frame.js +2 -4
- package/dist/core/runner/initial-run-state.js +1 -1
- package/dist/core/runner/main-call-account.d.ts +3 -1
- package/dist/core/runner/main-call-account.js +5 -3
- package/dist/core/runner/mcp-redial.d.ts +2 -5
- package/dist/core/runner/mcp-redial.js +2 -2
- package/dist/core/runner/nested-memory-content.d.ts +7 -1
- package/dist/core/runner/nested-memory-content.js +73 -13
- package/dist/core/runner/nested-memory-lane.d.ts +44 -19
- package/dist/core/runner/nested-memory-lane.js +152 -76
- package/dist/core/runner/park-commit.js +3 -1
- package/dist/core/runner/permission-rule-lanes.d.ts +8 -2
- package/dist/core/runner/permission-rule-lanes.js +29 -3
- package/dist/core/runner/person-path-rows.d.ts +3 -11
- package/dist/core/runner/person-path-rows.js +21 -24
- package/dist/core/runner/prepare-acquire-reconcile.js +3 -1
- package/dist/core/runner/prepare-artifact.d.ts +1 -1
- package/dist/core/runner/prepare-artifact.js +20 -14
- package/dist/core/runner/prepare-ask-lane.d.ts +9 -6
- package/dist/core/runner/prepare-ask-lane.js +6 -5
- package/dist/core/runner/prepare-boundary-parks.d.ts +7 -1
- package/dist/core/runner/prepare-boundary-parks.js +27 -24
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +9 -24
- package/dist/core/runner/prepare-config-doors.js +58 -41
- package/dist/core/runner/prepare-context-lane.d.ts +2 -2
- package/dist/core/runner/prepare-context-lane.js +3 -5
- package/dist/core/runner/prepare-defer-classify.d.ts +1 -1
- package/dist/core/runner/prepare-defer-classify.js +1 -1
- package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
- package/dist/core/runner/prepare-delegation-surface.js +3 -2
- package/dist/core/runner/prepare-file-history.d.ts +62 -26
- package/dist/core/runner/prepare-file-history.js +117 -46
- package/dist/core/runner/prepare-gate-stations.d.ts +4 -0
- package/dist/core/runner/prepare-gate-stations.js +6 -5
- package/dist/core/runner/prepare-hands-readface.d.ts +9 -4
- package/dist/core/runner/prepare-hands-readface.js +8 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +11 -4
- package/dist/core/runner/prepare-inherited-gate.js +6 -6
- package/dist/core/runner/prepare-listings.d.ts +1 -1
- package/dist/core/runner/prepare-listings.js +1 -1
- package/dist/core/runner/prepare-memory.js +2 -2
- package/dist/core/runner/prepare-offload-wrappers.d.ts +1 -1
- package/dist/core/runner/prepare-offload-wrappers.js +1 -1
- package/dist/core/runner/prepare-park-ask.d.ts +10 -3
- package/dist/core/runner/prepare-park-ask.js +7 -9
- package/dist/core/runner/prepare-policy-chain.d.ts +18 -9
- package/dist/core/runner/prepare-policy-chain.js +18 -13
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +5 -3
- package/dist/core/runner/prepare-prompt-assembly.js +2 -1
- package/dist/core/runner/prepare-prompt-inputs.d.ts +2 -2
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -5
- package/dist/core/runner/prepare-protocol-tools.js +7 -7
- package/dist/core/runner/prepare-question-face.d.ts +4 -2
- package/dist/core/runner/prepare-run-refs.d.ts +7 -2
- package/dist/core/runner/prepare-run-refs.js +8 -7
- package/dist/core/runner/prepare-safety-scan.d.ts +4 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +3 -7
- package/dist/core/runner/prepare-suspend-saga.js +4 -3
- package/dist/core/runner/prepare-task.js +66 -53
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +3 -2
- package/dist/core/runner/prepare-tool-disclosure-mount.js +2 -1
- package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
- package/dist/core/runner/prepare-turn-wiring.js +1 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +9 -4
- package/dist/core/runner/prepare-wiring-manifest.js +14 -6
- package/dist/core/runner/prepare-workspace-restore.d.ts +4 -4
- package/dist/core/runner/prepare-workspace-restore.js +15 -6
- package/dist/core/runner/remote-env-retry.d.ts +3 -3
- package/dist/core/runner/restore-seat.d.ts +41 -0
- package/dist/core/runner/restore-seat.js +38 -0
- package/dist/core/runner/resume-admission.js +1 -1
- package/dist/core/runner/resume-apply.js +4 -3
- package/dist/core/runner/resume-checkpoint-screen.js +2 -1
- package/dist/core/runner/resume-internals-and-config.js +2 -1
- package/dist/core/runner/resume-preflight.js +2 -1
- package/dist/core/runner/rewind-files.js +22 -6
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -0
- package/dist/core/runner/rule-store-unreadable-notice.js +11 -0
- package/dist/core/runner/run-brain-sinks.d.ts +3 -6
- package/dist/core/runner/run-brain-sinks.js +6 -6
- package/dist/core/runner/run-compaction-machinery.d.ts +2 -2
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +2 -1
- package/dist/core/runner/run-harness-handlers.js +5 -4
- package/dist/core/runner/run-identity-wiring.js +20 -12
- package/dist/core/runner/run-leg.js +31 -72
- package/dist/core/runner/run-notification-lane.d.ts +3 -0
- package/dist/core/runner/run-notification-lane.js +2 -4
- package/dist/core/runner/run-reasoning-seat.d.ts +5 -6
- package/dist/core/runner/run-reasoning-seat.js +13 -18
- package/dist/core/runner/run-settle-and-teardown.js +13 -9
- package/dist/core/runner/run-terminal-adoption.js +4 -8
- package/dist/core/runner/run-turn-boundary.js +6 -3
- package/dist/core/runner/runtask.d.ts +9 -4
- package/dist/core/runner/runtask.js +29 -22
- package/dist/core/runner/session-rule-policy.d.ts +11 -1
- package/dist/core/runner/shell-env-withheld.js +2 -7
- package/dist/core/runner/side-call-account.d.ts +5 -6
- package/dist/core/runner/side-call-account.js +2 -2
- package/dist/core/runner/stream-lifecycle-verbs.d.ts +3 -0
- package/dist/core/runner/stream-lifecycle-verbs.js +5 -3
- package/dist/core/runner/stream-settle-backstop.js +4 -6
- package/dist/core/runner/stream-steer-verb.d.ts +1 -1
- package/dist/core/runner/stream-steer-verb.js +4 -4
- package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -3
- package/dist/core/runner/sub-agent-deny-lists.js +7 -4
- package/dist/core/runner/teardown-bounded.d.ts +7 -0
- package/dist/core/runner/teardown-bounded.js +7 -0
- package/dist/core/runner/terminal-account.js +41 -13
- package/dist/core/runner/terminal-projection.d.ts +1 -5
- package/dist/core/runner/tool-end-body.d.ts +9 -3
- package/dist/core/runner/tool-end-body.js +6 -3
- package/dist/core/runner/tool-output-projection.d.ts +13 -4
- package/dist/core/runner/tool-output-projection.js +10 -14
- package/dist/core/runner/turn-attachments.d.ts +3 -2
- package/dist/core/runner/turn-attachments.js +12 -5
- package/dist/core/runner-deps.d.ts +6 -6
- package/dist/core/runtime-caps.d.ts +2 -1
- package/dist/core/secret-env.d.ts +20 -3
- package/dist/core/secret-env.js +13 -15
- package/dist/core/session-checkout.d.ts +115 -15
- package/dist/core/session-checkout.js +435 -136
- package/dist/core/session-policy-store.js +21 -3
- package/dist/core/session-reconcile.js +1 -0
- package/dist/core/session-store.js +2 -0
- package/dist/core/session.d.ts +11 -1
- package/dist/core/shell-run-candidates.d.ts +1 -0
- package/dist/core/shell-run-candidates.js +1 -1
- package/dist/core/shutdown-debug.d.ts +6 -5
- package/dist/core/shutdown-debug.js +5 -1
- package/dist/core/skill-grant.js +4 -1
- package/dist/core/skills-directory.js +5 -3
- package/dist/core/spec-contract.d.ts +1 -1
- package/dist/core/store-contracts/checkpoint-store-contract.js +2 -7
- package/dist/core/store-contracts/file-history-store-contract.js +26 -2
- package/dist/core/store-contracts/session-deletion-cascade-contract.js +130 -14
- package/dist/core/store-contracts/task-list-store-contract.d.ts +2 -1
- package/dist/core/store-contracts/task-list-store-contract.js +28 -1
- package/dist/core/task-event.d.ts +48 -27
- package/dist/core/task-notification.d.ts +15 -9
- package/dist/core/task-notification.js +12 -0
- package/dist/core/task-registry-agent.d.ts +24 -22
- package/dist/core/task-registry-agent.js +65 -46
- package/dist/core/task-registry-shared.d.ts +17 -5
- package/dist/core/task-registry.d.ts +17 -6
- package/dist/core/task-registry.js +6 -1
- package/dist/core/task-result.d.ts +71 -25
- package/dist/core/task-spec-members.d.ts +0 -1
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +60 -52
- package/dist/core/task-stream.d.ts +45 -12
- package/dist/core/terminal-cause.d.ts +45 -8
- package/dist/core/terminal-cause.js +5 -0
- package/dist/core/tool-card-bound.d.ts +32 -0
- package/dist/core/tool-card-bound.js +33 -0
- package/dist/core/tool-catalog-entries.d.ts +9 -0
- package/dist/core/tool-catalog-entries.js +48 -0
- package/dist/core/tool-errors.d.ts +4 -3
- package/dist/core/tool-face.d.ts +3 -3
- package/dist/core/tool-mount-facts.d.ts +3 -2
- package/dist/core/tool-mount-facts.js +1 -1
- package/dist/core/tool-mount-static.js +7 -5
- package/dist/core/tool-policy.d.ts +21 -19
- package/dist/core/tool-policy.js +5 -6
- package/dist/core/tool-registry.d.ts +3 -1
- package/dist/core/tool-registry.js +15 -1
- package/dist/core/tool-result-store.d.ts +9 -3
- package/dist/core/tool-result-store.js +14 -1
- package/dist/core/tool-roster.d.ts +6 -0
- package/dist/core/tool-roster.js +18 -0
- package/dist/core/tool-spec.d.ts +17 -8
- package/dist/core/trace.d.ts +35 -31
- package/dist/core/types.d.ts +2 -2
- package/dist/core/untrusted-egress.d.ts +19 -7
- package/dist/core/untrusted-egress.js +26 -7
- package/dist/core/untrusted-text.d.ts +6 -18
- package/dist/core/untrusted-text.js +11 -4
- package/dist/core/user-attachment.d.ts +9 -6
- package/dist/core/user-attachment.js +12 -10
- package/dist/core/user-row-origin.d.ts +44 -25
- package/dist/core/user-row-origin.js +30 -20
- package/dist/core/wiring-manifest.d.ts +26 -7
- package/dist/core/wiring-manifest.js +14 -11
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +23 -16
- package/dist/engine/execution-env/node-execution-env.js +127 -67
- package/dist/engine/harness/agent-harness.d.ts +4 -5
- package/dist/engine/harness/agent-harness.js +2 -7
- package/dist/engine/harness/types.d.ts +51 -19
- package/dist/engine/harness/types.js +28 -1
- package/dist/engine/llm/types.d.ts +26 -14
- package/dist/engine/llm/types.js +2 -2
- package/dist/engine/loop/agent-loop.d.ts +2 -2
- package/dist/engine/loop/agent-loop.js +51 -275
- package/dist/engine/loop/types.d.ts +0 -18
- package/dist/engine/session/import-validate.d.ts +3 -0
- package/dist/engine/session/import-validate.js +34 -2
- package/dist/engine/session/repo-utils.d.ts +42 -4
- package/dist/engine/session/repo-utils.js +33 -5
- package/dist/engine/session/session.d.ts +41 -14
- package/dist/engine/session/session.js +96 -25
- package/dist/index.d.ts +21 -16
- package/dist/index.js +16 -10
- package/dist/orchestration/run-spec.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +12 -9
- package/dist/orchestration/run-workflow-tool.js +15 -19
- package/dist/orchestration/workflow-governance.js +13 -21
- package/dist/orchestration/workflow-observe.d.ts +4 -3
- package/dist/orchestration/workflow-primitives.d.ts +1 -1
- package/dist/orchestration/workflow-record-artifact.d.ts +14 -0
- package/dist/orchestration/workflow-record-artifact.js +32 -0
- package/dist/orchestration/workflow-script-store.d.ts +9 -0
- package/dist/orchestration/workflow-script-store.js +20 -1
- package/dist/orchestration/workflow-types.d.ts +33 -3
- package/dist/orchestration/workflow.d.ts +24 -14
- package/dist/orchestration/workflow.js +52 -23
- package/dist/prompt-assembly/artifact.js +4 -8
- package/dist/prompt-assembly/catalog/engine.d.ts +263 -0
- package/dist/prompt-assembly/catalog/engine.js +30 -0
- package/dist/prompt-assembly/catalog/index.d.ts +1 -1
- package/dist/prompt-assembly/catalog/index.js +2 -2
- package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +1 -1
- package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +29 -0
- package/dist/prompt-assembly/epoch.js +6 -8
- package/dist/prompt-assembly/turn-snapshot.js +8 -9
- package/dist/stores/file/background-agent-store.js +5 -6
- package/dist/stores/file/checkpoint-store.d.ts +0 -4
- package/dist/stores/file/checkpoint-store.js +7 -3
- package/dist/stores/file/file-history-store.d.ts +8 -0
- package/dist/stores/file/file-history-store.js +72 -0
- package/dist/stores/file/fs-atomic.js +17 -12
- package/dist/stores/file/index.js +11 -5
- package/dist/stores/file/mailbox-store.js +13 -4
- package/dist/stores/file/permission-rule-store.js +14 -13
- package/dist/stores/file/shared-ledger.d.ts +4 -0
- package/dist/stores/file/shared-ledger.js +4 -0
- package/dist/stores/file/task-list-store.js +12 -3
- package/dist/stores/file/workflow-run-store.js +1 -0
- package/dist/tools/fs/bash-program-position.d.ts +4 -2
- package/dist/tools/fs/bash-program-position.js +1 -1
- package/dist/tools/fs/bash-readonly-classifier.js +1 -1
- package/dist/tools/fs/bound-open.d.ts +97 -0
- package/dist/tools/fs/bound-open.js +103 -0
- package/dist/tools/fs/containment-face.d.ts +2 -2
- package/dist/tools/fs/fs-pdf.d.ts +7 -1
- package/dist/tools/fs/fs-pdf.js +31 -23
- package/dist/tools/fs/fs-read.d.ts +24 -17
- package/dist/tools/fs/fs-read.js +84 -53
- package/dist/tools/fs/fs-shared.d.ts +14 -12
- package/dist/tools/fs/fs-shared.js +5 -4
- package/dist/tools/fs/fs-write.d.ts +2 -2
- package/dist/tools/fs/fs-write.js +20 -12
- package/dist/tools/fs/index.d.ts +4 -4
- package/dist/tools/fs/index.js +2 -2
- package/dist/tools/fs/notebook.d.ts +1 -1
- package/dist/tools/fs/pdf.d.ts +12 -3
- package/dist/tools/fs/pdf.js +22 -9
- package/dist/tools/fs/read-deny-home.d.ts +3 -2
- package/dist/tools/fs/read-deny-home.js +8 -11
- package/dist/tools/fs/safety.d.ts +3 -2
- package/dist/tools/fs/shell-read-check.js +10 -9
- package/dist/tools/monitor.d.ts +6 -5
- package/dist/tools/task-list.d.ts +16 -6
- package/dist/tools/task-list.js +4 -0
- package/dist/tools/web.d.ts +9 -1
- package/dist/tools/web.js +8 -3
- package/dist/tools/worktree.d.ts +7 -5
- package/dist/tools/worktree.js +4 -3
- package/package.json +4 -3
- package/test/export-surface.snapshot.json +93 -7
- package/wire-changes/core-stores-sql@7.67.3.json +39 -0
- package/wire-changes/core-stores-sql@7.68.0.json +39 -0
- package/wire-changes/core@7.67.3.json +65 -0
- package/wire-changes/core@7.68.0.json +4257 -0
- package/wire-changes/mods-kernel@7.67.3.json +39 -0
- package/wire-changes/mods-kernel@7.68.0.json +129 -0
- package/wire-changes/primitives@7.67.3.json +39 -0
- package/wire-changes/primitives@7.68.0.json +253 -0
- package/wire-changes/wiki-gate@7.67.3.json +39 -0
- package/wire-changes/wiki-gate@7.68.0.json +39 -0
- package/dist/core/runner/credential-origin-seat.d.ts +0 -2
- package/dist/core/runner/credential-origin-seat.js +0 -20
package/dist/agents/subagent.js
CHANGED
|
@@ -8,7 +8,7 @@ import { resumeRefusalDetailOf, resumeStartupCauseOf } from "../core/resume-star
|
|
|
8
8
|
import { errorCodeOf } from "../core/runner/terminal-account.js";
|
|
9
9
|
import { applyParentSpecSeat, parentSpecSeatOfCtx } from "../core/parent-spec-seat.js";
|
|
10
10
|
import { isolationScopeOf } from "../core/isolation-scope.js";
|
|
11
|
-
import { delegationRootOf } from "../core/background-agent-store.js";
|
|
11
|
+
import { delegationRootOf, nextCycleSeq } from "../core/background-agent-store.js";
|
|
12
12
|
import { declaredCheckpointScope } from "../core/runner/checkpoint-scope.js";
|
|
13
13
|
import { sanitizedTtlMs } from "../core/runner/park-commit.js";
|
|
14
14
|
import { ADVISOR_FORK_SENTENCE, ADVISOR_TOOL_NAME } from "../core/advisor-verdict.js";
|
|
@@ -57,7 +57,7 @@ import { agentOutcomeIsError } from "../core/task-registry-agent.js";
|
|
|
57
57
|
import { readDurableOrgAdmission } from "../core/memory-admission.js";
|
|
58
58
|
import { governanceRetryClass } from "../core/governance-codes.js";
|
|
59
59
|
import { readSkillGrantCapture } from "../core/skill-grant.js";
|
|
60
|
-
import { admitsBackgroundLaunch, completionResultField, moveTerminalDelivery, oweTerminalDelivery, resolveCompletionSink, terminalFrameFacets } from "../core/task-notification.js";
|
|
60
|
+
import { admitsBackgroundLaunch, completionResultField, moveTerminalDelivery, oweTerminalDelivery, refusedAsksText, resolveCompletionSink, terminalFrameFacets } from "../core/task-notification.js";
|
|
61
61
|
import { deliverEngineNotice } from "../core/engine-notice.js";
|
|
62
62
|
import { resumeLaneMissingNotice, rootSessionAddressOf, rootSessionLaneOf, rootSessionSink } from "./root-session-lane.js";
|
|
63
63
|
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";
|
|
@@ -86,7 +86,7 @@ function providerFaultField(child) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
export { RETAIN_DEFAULT_TTL_MS, RETAIN_DEFAULT_MAX };
|
|
89
|
-
import { SUBAGENT_RESUME_CAP, SubagentRetainLedger, getOrCreateSessionRetainLedger, ensureSessionReapHook, createResumePrompt, holdChildDeclarations, } from "./retain-ledger.js";
|
|
89
|
+
import { SUBAGENT_RESUME_CAP, SubagentRetainLedger, getOrCreateSessionRetainLedger, ensureSessionReapHook, createResumePrompt, holdChildDeclarations, resumabilityClaim, } from "./retain-ledger.js";
|
|
90
90
|
import { createPeerInboundChainRef, createPeerSelfRef } from "./peer-admission.js";
|
|
91
91
|
import { recordRosterSpawn } from "./roster-store.js";
|
|
92
92
|
import { LAUNCH_RECEIPT_OWN_WORDS_CLAUSE, launchReceiptNoQuoteClause } from "./launch-receipt-contract.js";
|
|
@@ -379,17 +379,24 @@ function continuationSentence(toolName, durableRevival, forkOffered) {
|
|
|
379
379
|
function launchContinuationSentence(taskId) {
|
|
380
380
|
return `Where the SendMessage tool is mounted, use it with to: '${taskId}', summary: '<5-10 word recap>' to continue this agent.`;
|
|
381
381
|
}
|
|
382
|
-
function resumabilityClaim(f) {
|
|
383
|
-
if (f.status === "killed" && f.stoppedBy === "user")
|
|
384
|
-
return false;
|
|
385
|
-
if (f.liveRetainPresent)
|
|
386
|
-
return f.liveRetainHasBudget;
|
|
387
|
-
return f.durableRow && f.named;
|
|
388
|
-
}
|
|
389
382
|
const BG_AGENT_COLLATERAL_REAP_REASON = "its parent run ended";
|
|
390
383
|
export const RESERVED_AGENT_NAMES = new Set([OUTPUT_TOOL_NAME, TOOL_SEARCH_NAME, OFFLOAD_TOOL_NAME, REPORT_BLOCKED_TOOL_NAME, DEFAULT_SUBAGENT_TOOL_NAME]);
|
|
391
384
|
export const REPORT_FIELD_MAX = 300;
|
|
392
385
|
const ROSTER_ECHO_MAX = 400;
|
|
386
|
+
function saySettlementWriteFailed(runner, at, lastErr) {
|
|
387
|
+
const notice = settlementWriteFailedNotice(at, lastErr);
|
|
388
|
+
if (runner.emitNotice !== undefined)
|
|
389
|
+
runner.emitNotice(notice);
|
|
390
|
+
else
|
|
391
|
+
deliverEngineNotice(undefined, notice);
|
|
392
|
+
}
|
|
393
|
+
function settlementWriteFailedNotice(at, lastErr) {
|
|
394
|
+
return {
|
|
395
|
+
code: "delegation.settlement_write_failed",
|
|
396
|
+
message: `[sema] delegation settlement terminal write failed (${at.fork ? "fork, " : ""}verdict ${at.verdict}, session ${at.sessionId}): ${childThrownText(lastErr)} — the pending row expires as unproven at the settlement window`,
|
|
397
|
+
detail: { verdict: at.verdict, sessionId: at.sessionId, fork: at.fork },
|
|
398
|
+
};
|
|
399
|
+
}
|
|
393
400
|
function configError(message, code) {
|
|
394
401
|
return codedRefusal(code, message);
|
|
395
402
|
}
|
|
@@ -558,6 +565,7 @@ export function createSubagentResume(deps) {
|
|
|
558
565
|
assertNoRetiredKeys(deps, RETIRED_RESUME_CLAMP_KEYS, "createSubagentResume");
|
|
559
566
|
assertClampRecord(deps.currentClamps, "createSubagentResume currentClamps");
|
|
560
567
|
const notifier = createSafeNotifier(deps.onNotifyError !== undefined ? { onError: deps.onNotifyError } : undefined);
|
|
568
|
+
let rowlessCycle = 1;
|
|
561
569
|
const resumeAs = (by) => async (content) => {
|
|
562
570
|
const ledger = deps.ledger;
|
|
563
571
|
if (!ledger) {
|
|
@@ -594,6 +602,7 @@ export function createSubagentResume(deps) {
|
|
|
594
602
|
const childRunner = entry.runner ?? deps.runner;
|
|
595
603
|
let stream;
|
|
596
604
|
let reviveCycle;
|
|
605
|
+
let cycle;
|
|
597
606
|
let reviveEmit;
|
|
598
607
|
let releaseCycleSlot = noopRelease;
|
|
599
608
|
let marker;
|
|
@@ -616,7 +625,6 @@ export function createSubagentResume(deps) {
|
|
|
616
625
|
reviveStartedAt = Date.now();
|
|
617
626
|
marker = `resume-${markerFragment()}`;
|
|
618
627
|
entry.resumeCount += 1;
|
|
619
|
-
entry.cycleSeq += 1;
|
|
620
628
|
const wakeClamps = foldClampSources(entry.specSnapshot, deps.currentClamps);
|
|
621
629
|
const resumeSpec = applyClampSeats({
|
|
622
630
|
...entry.specSnapshot,
|
|
@@ -631,7 +639,6 @@ export function createSubagentResume(deps) {
|
|
|
631
639
|
const revived = await deps.registry.reviveBackgroundAgent(deps.taskId, deps.taskAccess, abort);
|
|
632
640
|
if (!revived.ok) {
|
|
633
641
|
entry.resumeCount -= 1;
|
|
634
|
-
entry.cycleSeq -= 1;
|
|
635
642
|
throw configError(revived.reason === "still_running"
|
|
636
643
|
?
|
|
637
644
|
"resume unavailable: the agent's registry row is not available for a resume right now (it is running, or another revival claimed it) — wait for its completion notification and send again."
|
|
@@ -640,11 +647,7 @@ export function createSubagentResume(deps) {
|
|
|
640
647
|
: "resume unavailable: the agent's registry row no longer exists (terminal GC) — relaunch a new agent instead.", revived.reason === "still_running" ? "steering.still_running" : revived.reason === "recycling" ? "resume.row_recycling" : "resume.row_gone");
|
|
641
648
|
}
|
|
642
649
|
reviveCycle = revived.cycle;
|
|
643
|
-
|
|
644
|
-
const settledSeq = deps.registry.backgroundAgentCycleSeq(deps.taskId);
|
|
645
|
-
if (settledSeq !== undefined && settledSeq > entry.cycleSeq)
|
|
646
|
-
entry.cycleSeq = settledSeq;
|
|
647
|
-
}
|
|
650
|
+
cycle = deps.registry.backgroundAgentCycleSeq(deps.taskId);
|
|
648
651
|
if (deps.bgSink !== undefined) {
|
|
649
652
|
reviveEmit = (event) => {
|
|
650
653
|
try {
|
|
@@ -661,7 +664,7 @@ export function createSubagentResume(deps) {
|
|
|
661
664
|
...(deps.rowScope !== undefined ? { scope: deps.rowScope } : {}),
|
|
662
665
|
description: `${deps.rowDescription ?? "sub-agent"} (resumed ${marker})`,
|
|
663
666
|
...(deps.rowAgentType !== undefined ? { agentType: deps.rowAgentType } : {}),
|
|
664
|
-
seq:
|
|
667
|
+
...(cycle !== undefined ? { seq: cycle } : {}),
|
|
665
668
|
...(deps.rowName !== undefined ? { name: deps.rowName } : {}),
|
|
666
669
|
sessionId: entry.childSessionId,
|
|
667
670
|
transcriptId: entry.childSessionId,
|
|
@@ -673,6 +676,10 @@ export function createSubagentResume(deps) {
|
|
|
673
676
|
});
|
|
674
677
|
}
|
|
675
678
|
}
|
|
679
|
+
else {
|
|
680
|
+
rowlessCycle = nextCycleSeq({ seq: rowlessCycle });
|
|
681
|
+
cycle = rowlessCycle;
|
|
682
|
+
}
|
|
676
683
|
reviveStartedAt = Date.now();
|
|
677
684
|
const reviveActivityBeat = createBgActivityBeat(deps.parentToolCallId, (toolStarts) => {
|
|
678
685
|
if (reviveEmit === undefined)
|
|
@@ -687,7 +694,7 @@ export function createSubagentResume(deps) {
|
|
|
687
694
|
transcriptId: entry.childSessionId,
|
|
688
695
|
sessionId: entry.childSessionId,
|
|
689
696
|
...(deps.parentToolCallId !== undefined ? { parentToolCallId: deps.parentToolCallId } : {}),
|
|
690
|
-
seq:
|
|
697
|
+
...(cycle !== undefined ? { seq: cycle } : {}),
|
|
691
698
|
progressTaskId: wakeTaskId,
|
|
692
699
|
...(currentAction !== undefined ? { currentAction } : {}),
|
|
693
700
|
...(currentTool !== undefined ? { currentTool } : {}),
|
|
@@ -701,7 +708,7 @@ export function createSubagentResume(deps) {
|
|
|
701
708
|
...inheritedHostSeats(deps.currentMcpHostSeats, resumeSpec.mcp ?? []),
|
|
702
709
|
...(deps.currentPlacementTarget !== undefined ? { placementTarget: deps.currentPlacementTarget } : {}),
|
|
703
710
|
objectiveAuthor: by.author,
|
|
704
|
-
cycleSeq:
|
|
711
|
+
...(cycle !== undefined ? { cycleSeq: cycle } : {}),
|
|
705
712
|
parentInteractionPosture: postureUnderClamps(entry.internalsSnapshot.parentInteractionPosture, { interactiveTools: resumeSpec.interactiveTools, approvalReach: resumeSpec.approvalReach }, "interactive"),
|
|
706
713
|
...(true
|
|
707
714
|
? {
|
|
@@ -718,7 +725,7 @@ export function createSubagentResume(deps) {
|
|
|
718
725
|
sessionId: entry.childSessionId,
|
|
719
726
|
transcriptId: entry.childSessionId,
|
|
720
727
|
...(deps.parentToolCallId !== undefined ? { parentToolCallId: deps.parentToolCallId } : {}),
|
|
721
|
-
seq:
|
|
728
|
+
...(cycle !== undefined ? { seq: cycle } : {}),
|
|
722
729
|
progressTaskId: e.taskId,
|
|
723
730
|
...(e.parentTaskId !== undefined ? { progressParentTaskId: e.parentTaskId } : {}),
|
|
724
731
|
...(e.name !== undefined ? { name: e.name } : {}),
|
|
@@ -794,6 +801,7 @@ export function createSubagentResume(deps) {
|
|
|
794
801
|
const winner = deps.registry.settleRevivedAgent(deps.taskId, reviveCycle, {
|
|
795
802
|
status,
|
|
796
803
|
...resultSettleFields(resumeHandbackResult),
|
|
804
|
+
...(child.refusedAsks !== undefined ? { refusedAsks: child.refusedAsks } : {}),
|
|
797
805
|
...(status !== "completed" ? { error: (childFace.errorMessage ?? `resumed run ${status}`).slice(0, 500) } : {}),
|
|
798
806
|
...(errCodeRevive !== undefined ? { errorCode: errCodeRevive } : {}),
|
|
799
807
|
...(errClassRevive !== undefined ? { retryable: errClassRevive.retryable, errorKind: errClassRevive.errorKind } : {}),
|
|
@@ -821,7 +829,7 @@ export function createSubagentResume(deps) {
|
|
|
821
829
|
liveRetainPresent: ledger.get(deps.parentToolCallId) === entry,
|
|
822
830
|
liveRetainHasBudget: entry.resumeCount < SUBAGENT_RESUME_CAP,
|
|
823
831
|
durableRow: reviveDurableRow,
|
|
824
|
-
|
|
832
|
+
durableRungServes: deps.rowName !== undefined,
|
|
825
833
|
});
|
|
826
834
|
const ownsTerminalFacesRevive = deps.registry !== undefined && deps.taskId !== undefined ? deps.registry.claimAgentTerminalNotify(deps.taskId) : true;
|
|
827
835
|
const resumeResultField = await completionResultField(resumeHandbackResult, (report) => persistTaskArtifact(deps.currentTaskArtifacts, wakeTaskId, report), (ref) => {
|
|
@@ -836,7 +844,7 @@ export function createSubagentResume(deps) {
|
|
|
836
844
|
status,
|
|
837
845
|
...terminalFrameFacets({ spawnName: deps.rowName, result: resumeHandbackResult, warning: resumeHandbackWarning, compaction: child.compaction }),
|
|
838
846
|
...(stoppedByRevive !== undefined ? { stoppedBy: stoppedByRevive } : {}),
|
|
839
|
-
seq:
|
|
847
|
+
...(cycle !== undefined ? { seq: cycle } : {}),
|
|
840
848
|
summary: reviveTerminalSummary,
|
|
841
849
|
...(failReasonRevive !== undefined ? { error: failReasonRevive.slice(0, REPORT_FIELD_MAX) } : {}),
|
|
842
850
|
...(status === "failed" && errCodeRevive !== undefined ? { errorCode: errCodeRevive } : {}),
|
|
@@ -844,6 +852,7 @@ export function createSubagentResume(deps) {
|
|
|
844
852
|
...(resumeResultField !== undefined ? { result: resumeResultField.text } : {}),
|
|
845
853
|
...(status === "killed" && child.result ? { partial: true } : {}),
|
|
846
854
|
...resumeResidual(),
|
|
855
|
+
...(child.refusedAsks !== undefined ? { refusedAsks: child.refusedAsks } : {}),
|
|
847
856
|
resumable: resumableRevive,
|
|
848
857
|
usage: { tokens: child.stats.tokens, turns: child.stats.turns, ...delegatedCostField(child.stats), ...delegatedGranularityFieldsWire(child.stats, reviveElapsedMs) },
|
|
849
858
|
...(completionIdRevive !== undefined ? { completionId: completionIdRevive } : {}),
|
|
@@ -900,7 +909,7 @@ export function createSubagentResume(deps) {
|
|
|
900
909
|
task_type: "background_agent",
|
|
901
910
|
toolUseId: deps.parentToolCallId,
|
|
902
911
|
status: abort.signal.aborted ? "killed" : "failed",
|
|
903
|
-
seq:
|
|
912
|
+
...(cycle !== undefined ? { seq: cycle } : {}),
|
|
904
913
|
...(stoppedByReject !== undefined ? { stoppedBy: stoppedByReject } : {}),
|
|
905
914
|
summary: `Agent "${rejectName}" (resumed) ${abort.signal.aborted ? "stopped" : `failed: ${msgRevive}`}${ccElapsedTag(Date.now() - reviveStartedAt)}`.slice(0, 300) + (abort.signal.aborted ? "" : errorKindClause(errClassReviveReject)),
|
|
906
915
|
...(abort.signal.aborted ? {} : { error: msgRevive.slice(0, REPORT_FIELD_MAX) }),
|
|
@@ -1328,6 +1337,7 @@ export function asyncLaunchedReceipt(p) {
|
|
|
1328
1337
|
const noteLines = (p.notes ?? []).filter((n) => n !== undefined && n !== "");
|
|
1329
1338
|
return (`Async agent launched successfully. (${launchReceiptNoQuoteClause(", including the task_id below,")})\n` +
|
|
1330
1339
|
`task_id: ${p.taskId} (internal ID - do not mention to user. ${launchContinuationSentence(p.taskId)})\n` +
|
|
1340
|
+
(p.name !== undefined ? `name: ${p.name}\n` : "") +
|
|
1331
1341
|
`${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` +
|
|
1332
1342
|
noteLines.map((n) => `${n}\n`).join("") +
|
|
1333
1343
|
`${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.`);
|
|
@@ -1573,7 +1583,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1573
1583
|
const refusal = subagentTypeRefusal(args.subagent_type, acceptedSubagentTypes());
|
|
1574
1584
|
return refusal === undefined ? { ok: true } : { ok: false, message: refusal.content, code: refusal.error };
|
|
1575
1585
|
},
|
|
1576
|
-
execute: async (args, ctx) => {
|
|
1586
|
+
execute: releasingSpawnNameClaim(async (args, ctx, holdNameClaim) => {
|
|
1577
1587
|
const a = canonicalSubagentTypeArgs(args, acceptedSubagentTypes(), generalPurposeShadowed);
|
|
1578
1588
|
const parentSpecSeat = parentSpecSeatOfCtx(ctx);
|
|
1579
1589
|
const background = opts.background, backgroundRegistry = delegationRegistryOf(ctx, background);
|
|
@@ -1624,17 +1634,17 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1624
1634
|
if (a.name !== undefined && typeof a.name !== "string") {
|
|
1625
1635
|
return notStartedResult({ isError: true, content: "Sub-agent not started: name must be a string.", details: { error: "name.invalid" } });
|
|
1626
1636
|
}
|
|
1627
|
-
const
|
|
1628
|
-
if (
|
|
1629
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(
|
|
1637
|
+
const requestedName = reviveClaim !== undefined ? chosenAgentName(reviveClaim.row.handle, a.name) : a.name;
|
|
1638
|
+
if (requestedName !== undefined) {
|
|
1639
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(requestedName)) {
|
|
1630
1640
|
return notStartedResult({
|
|
1631
1641
|
isError: true,
|
|
1632
1642
|
content: "Sub-agent not started: name must start with a letter or digit and contain only letters, digits, underscores, or hyphens (max 64 chars).",
|
|
1633
1643
|
details: { error: "name.invalid" },
|
|
1634
1644
|
});
|
|
1635
1645
|
}
|
|
1636
|
-
if (reservedPeerNameReason(
|
|
1637
|
-
return notStartedResult({ isError: true, content: normalizePeerName(
|
|
1646
|
+
if (reservedPeerNameReason(requestedName) !== undefined) {
|
|
1647
|
+
return notStartedResult({ isError: true, content: normalizePeerName(requestedName) === "main" ? 'Sub-agent not started: "main" is reserved — SendMessage routes it to the main conversation.' : 'Sub-agent not started: name must not be a reserved name ("main", "team-lead", "user" or "system", in any spelling) or have the shape of an agent id — those already address an agent directly.', details: { error: "name.reserved" } });
|
|
1638
1648
|
}
|
|
1639
1649
|
if (ctx.spawnedAgentName !== undefined && reviveClaim === undefined) {
|
|
1640
1650
|
return notStartedResult({
|
|
@@ -1644,6 +1654,14 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
1644
1654
|
});
|
|
1645
1655
|
}
|
|
1646
1656
|
}
|
|
1657
|
+
const treeScope = reviveClaim?.row.scope ?? isolationScopeOf(parentSpecSeat ?? {}) ?? background?.scope;
|
|
1658
|
+
const poolSession = ctx.rootSessionId ?? ctx.sessionId;
|
|
1659
|
+
const nameClaim = requestedName !== undefined && reviveClaim === undefined && backgroundRegistry !== undefined
|
|
1660
|
+
? backgroundRegistry.claimAgentName(requestedName, { owner: ctx.taskId ?? background.owner, ...(treeScope !== undefined ? { scope: treeScope } : {}), ...(poolSession !== undefined ? { sessionId: poolSession } : {}) })
|
|
1661
|
+
: undefined;
|
|
1662
|
+
if (nameClaim !== undefined)
|
|
1663
|
+
holdNameClaim(nameClaim);
|
|
1664
|
+
const agentName = nameClaim?.name ?? requestedName;
|
|
1647
1665
|
const backgroundAsked = background !== undefined && (a.run_in_background !== false || def?.background === true || agentName !== undefined);
|
|
1648
1666
|
const wantsBackground = backgroundLane && backgroundAsked;
|
|
1649
1667
|
const ranSyncNote = backgroundAsked && !backgroundLane ? AGENT_RAN_SYNC_NO_CHANNEL_NOTE : undefined;
|
|
@@ -2213,7 +2231,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2213
2231
|
const editedFiles = stepRecorder.editedFiles();
|
|
2214
2232
|
return { ...(recentSteps ? { recentSteps } : {}), ...(editedFiles ? { editedFiles } : {}) };
|
|
2215
2233
|
};
|
|
2216
|
-
const treeScope = reviveClaim?.row.scope ?? isolationScopeOf(parentSpecSeat ?? {}) ?? background?.scope;
|
|
2217
2234
|
const entryCapPoolAnchor = backgroundRegistry ?? opts;
|
|
2218
2235
|
const entryCaps = ctx.delegationEntryCaps ?? { maxConcurrent: DELEGATION_MAX_CONCURRENT_DEFAULT, maxCumulativePerSession: DELEGATION_MAX_PER_SESSION_DEFAULT };
|
|
2219
2236
|
const entryCapRoot = reviveClaim !== undefined
|
|
@@ -2240,7 +2257,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2240
2257
|
...(ctx.onSubtreeActivity !== undefined ? { onSubtreeActivity: ctx.onSubtreeActivity } : {}),
|
|
2241
2258
|
...(ctx.toolSelector !== undefined ? { toolCeiling: childCeiling, ...(childListsJudged !== undefined ? { toolListsJudged: childListsJudged } : {}) } : {}),
|
|
2242
2259
|
...(childListsDigest !== undefined ? { ownToolLists: { toolName, ...(def !== undefined ? { definition: def.name } : {}), lists: childListsDigest } } : {}),
|
|
2243
|
-
...(
|
|
2260
|
+
...(ctx.mcpPool !== undefined ? { mcpPool: ctx.mcpPool } : {}),
|
|
2244
2261
|
...inheritedHostSeats(mountedMcpNow?.hostSeats, childMcp),
|
|
2245
2262
|
...(childPick.modelRef !== undefined ? { inheritedModelRef: childPick.modelRef } : {}),
|
|
2246
2263
|
...(inheritedSkillGrants.length > 0 ? { inheritedSkillGrants } : {}),
|
|
@@ -2572,6 +2589,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2572
2589
|
stepRecorder.lockTo(forkedId);
|
|
2573
2590
|
const forkWorktreeNote = worktreeDir !== undefined ? forkWorktreeTranslationNote(ctx.parentCwd, worktreeDir) : undefined;
|
|
2574
2591
|
const forkObjective = `${FORK_DIRECTIVE_FRAME}${prompt}${forkWorktreeNote !== undefined ? `\n\n${forkWorktreeNote}` : ""}${parentSpecSeat?.advisorModel !== undefined ? `\n\n${ADVISOR_FORK_SENTENCE}` : ""}`;
|
|
2592
|
+
const forkChildSpec = (signal) => ({ ...buildChildSpec(signal), sessionId: forkedId, requireExistingSession: true, objective: forkObjective, checkpointStore: "disabled" });
|
|
2575
2593
|
if (wantsBackground) {
|
|
2576
2594
|
const bg = background, bgRegistry = backgroundRegistry;
|
|
2577
2595
|
const notify = backgroundSink;
|
|
@@ -2642,10 +2660,8 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2642
2660
|
catch {
|
|
2643
2661
|
}
|
|
2644
2662
|
}
|
|
2645
|
-
if (!settled)
|
|
2646
|
-
|
|
2647
|
-
console.warn(`[sema] delegation settlement terminal write failed (fork, verdict ${verdict}, session ${forkSettlementSeat.sessionId}): ${detail} — the pending row expires as unproven at the settlement window`);
|
|
2648
|
-
}
|
|
2663
|
+
if (!settled)
|
|
2664
|
+
saySettlementWriteFailed(opts.runner, { verdict, sessionId: forkSettlementSeat.sessionId, fork: true }, lastErr);
|
|
2649
2665
|
};
|
|
2650
2666
|
let taskId;
|
|
2651
2667
|
try {
|
|
@@ -2696,22 +2712,23 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2696
2712
|
bgRegistry.bindBackgroundAgentSession(taskId, forkedId, opts.runner.sessions);
|
|
2697
2713
|
stepRecorder.lockTo(taskId);
|
|
2698
2714
|
const forkBgHangAt = Date.now();
|
|
2715
|
+
const bgForkCycleSeq = bgRegistry.backgroundAgentCycleSeq(taskId);
|
|
2699
2716
|
bgRegistry.attachAgentTerminalNotifier(taskId, () => {
|
|
2700
2717
|
const stoppedByReap = bgRegistry.getStopAttribution(taskId) ?? "system";
|
|
2701
2718
|
const completionIdReap = bgRegistry.getCompletionId(taskId);
|
|
2702
|
-
const seqReap = bgRegistry.backgroundAgentCycleSeq(taskId);
|
|
2703
2719
|
const reapFrame = {
|
|
2704
2720
|
task_id: taskId,
|
|
2705
2721
|
task_type: "background_agent",
|
|
2706
2722
|
toolUseId: ctx.toolCallId,
|
|
2707
2723
|
status: "killed",
|
|
2724
|
+
...(bgForkCycleSeq !== undefined ? { seq: bgForkCycleSeq } : {}),
|
|
2708
2725
|
stoppedBy: stoppedByReap,
|
|
2709
2726
|
summary: ccCompletionText(shortDesc, "killed", "killed", Date.now() - forkBgHangAt),
|
|
2710
2727
|
sessionId: forkedId,
|
|
2711
2728
|
resumable: false,
|
|
2712
2729
|
...(completionIdReap !== undefined ? { completionId: completionIdReap } : {}),
|
|
2713
2730
|
};
|
|
2714
|
-
sinkEmit(backgroundChildTerminal(reapFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId
|
|
2731
|
+
sinkEmit(backgroundChildTerminal(reapFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId }));
|
|
2715
2732
|
notifier.notify(() => notify(reapFrame, { priority: "next" }), "subagent.reapTerminalNotify");
|
|
2716
2733
|
});
|
|
2717
2734
|
if (agentName !== undefined) {
|
|
@@ -2725,7 +2742,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2725
2742
|
catch {
|
|
2726
2743
|
}
|
|
2727
2744
|
};
|
|
2728
|
-
const bgForkCycleSeq = bgRegistry.backgroundAgentCycleSeq(taskId);
|
|
2729
2745
|
sinkEmit({
|
|
2730
2746
|
kind: "spawn",
|
|
2731
2747
|
taskId,
|
|
@@ -2746,7 +2762,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2746
2762
|
startedAt: Date.now(),
|
|
2747
2763
|
});
|
|
2748
2764
|
const forkBgStartedAt = Date.now();
|
|
2749
|
-
const bgForkSpecBase =
|
|
2765
|
+
const bgForkSpecBase = forkChildSpec(abort.signal);
|
|
2750
2766
|
const forkQuestionStrip = sessionScopedBg ? stripSpawnTurnQuestionFace(bgForkSpecBase) : undefined;
|
|
2751
2767
|
const bgForkSpec = forkQuestionStrip !== undefined ? forkQuestionStrip.spec : bgForkSpecBase;
|
|
2752
2768
|
const s2ForkNotifyReady = (inject) => {
|
|
@@ -2859,6 +2875,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2859
2875
|
cycle: 0,
|
|
2860
2876
|
status: okBg ? "completed" : reapedBg ? "killed" : "failed",
|
|
2861
2877
|
...resultSettleFields(forkBgResult),
|
|
2878
|
+
...(child.refusedAsks !== undefined ? { refusedAsks: child.refusedAsks } : {}),
|
|
2862
2879
|
...(!okBg ? { error: reapedBg ? (collateralBg ? BG_AGENT_COLLATERAL_REAP_REASON : BG_AGENT_REAP_STOP_ERROR) : childFace.errorMessage ?? childFace.status } : {}),
|
|
2863
2880
|
...(errCodeFork !== undefined ? { errorCode: errCodeFork } : {}),
|
|
2864
2881
|
...(errClassFork !== undefined ? { retryable: errClassFork.retryable, errorKind: errClassFork.errorKind } : {}),
|
|
@@ -2886,6 +2903,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2886
2903
|
toolUseId: ctx.toolCallId,
|
|
2887
2904
|
status: settledBg,
|
|
2888
2905
|
...terminalFrameFacets({ spawnName: agentName, result: forkBgResult, warning: forkBgWarning, compaction: child.compaction }),
|
|
2906
|
+
...(bgForkCycleSeq !== undefined ? { seq: bgForkCycleSeq } : {}),
|
|
2889
2907
|
...(stoppedByBg !== undefined ? { stoppedBy: stoppedByBg } : {}),
|
|
2890
2908
|
summary: forkTerminalSummary,
|
|
2891
2909
|
...(failReasonFork !== undefined ? { error: failReasonFork.slice(0, REPORT_FIELD_MAX) } : {}),
|
|
@@ -2895,12 +2913,13 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2895
2913
|
...(forkResultField !== undefined ? { result: forkResultField.text } : {}),
|
|
2896
2914
|
...(settledBg === "killed" && child.result ? { partial: true } : {}),
|
|
2897
2915
|
...residualFork,
|
|
2916
|
+
...(child.refusedAsks !== undefined ? { refusedAsks: child.refusedAsks } : {}),
|
|
2898
2917
|
resumable: resumableFork,
|
|
2899
2918
|
usage: { tokens: child.stats.tokens, turns: child.stats.turns, ...delegatedCostField(child.stats), ...delegatedGranularityFieldsWire(child.stats, forkElapsedMs) },
|
|
2900
2919
|
...(completionIdFork !== undefined ? { completionId: completionIdFork } : {}),
|
|
2901
2920
|
};
|
|
2902
2921
|
if (ownsTerminalFacesFork)
|
|
2903
|
-
sinkEmit(backgroundChildTerminal(forkFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkTranscriptId, ...(stillbornFork ? {} : { transcriptId: forkTranscriptId }), parentToolCallId: ctx.toolCallId
|
|
2922
|
+
sinkEmit(backgroundChildTerminal(forkFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkTranscriptId, ...(stillbornFork ? {} : { transcriptId: forkTranscriptId }), parentToolCallId: ctx.toolCallId }));
|
|
2904
2923
|
try {
|
|
2905
2924
|
if (ownsTerminalFacesFork)
|
|
2906
2925
|
notify(forkFrame, { priority: "next" });
|
|
@@ -2935,6 +2954,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2935
2954
|
status: settledBg,
|
|
2936
2955
|
...terminalFrameFacets({ spawnName: agentName }),
|
|
2937
2956
|
sessionId: forkedId,
|
|
2957
|
+
...(bgForkCycleSeq !== undefined ? { seq: bgForkCycleSeq } : {}),
|
|
2938
2958
|
...(stoppedByBg !== undefined ? { stoppedBy: stoppedByBg } : {}),
|
|
2939
2959
|
summary: summaryBg,
|
|
2940
2960
|
...(settledBg === "failed" ? { error: msgFork.slice(0, REPORT_FIELD_MAX) } : {}),
|
|
@@ -2942,7 +2962,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2942
2962
|
...(completionIdForkReject !== undefined ? { completionId: completionIdForkReject } : {}),
|
|
2943
2963
|
};
|
|
2944
2964
|
if (ownsTerminalFacesForkReject)
|
|
2945
|
-
sinkEmit(backgroundChildTerminal(forkRejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId
|
|
2965
|
+
sinkEmit(backgroundChildTerminal(forkRejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: forkedId, transcriptId: forkedId, parentToolCallId: ctx.toolCallId }));
|
|
2946
2966
|
try {
|
|
2947
2967
|
if (ownsTerminalFacesForkReject)
|
|
2948
2968
|
notify(forkRejectFrame, { priority: "next" });
|
|
@@ -2954,6 +2974,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2954
2974
|
content: asyncLaunchedReceipt({
|
|
2955
2975
|
taskId,
|
|
2956
2976
|
workingLine: `The forked agent inherits your full current context and works on its prompt in the background.`,
|
|
2977
|
+
...(agentName !== undefined ? { name: agentName } : {}),
|
|
2957
2978
|
notes: [
|
|
2958
2979
|
modelNote,
|
|
2959
2980
|
extraToolsNote,
|
|
@@ -2965,7 +2986,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2965
2986
|
: `Note: it is stopped automatically (killed) if still running when this task ends — do not promise the user results beyond this task.`,
|
|
2966
2987
|
],
|
|
2967
2988
|
}),
|
|
2968
|
-
details: { type: "agent", subagent_type: FORK_SUBAGENT_TYPE, status: "async_launched", isAsync: true, task_id: taskId, description: shortDesc, prompt, ...(forkSettleId !== undefined ? { settle_id: forkSettleId } : {}) },
|
|
2989
|
+
details: { type: "agent", subagent_type: FORK_SUBAGENT_TYPE, status: "async_launched", isAsync: true, task_id: taskId, description: shortDesc, prompt, ...(agentName !== undefined ? { name: agentName } : {}), ...(forkSettleId !== undefined ? { settle_id: forkSettleId } : {}) },
|
|
2969
2990
|
};
|
|
2970
2991
|
}
|
|
2971
2992
|
const bgIgnoredNote = ranSyncNote ??
|
|
@@ -2996,7 +3017,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
2996
3017
|
}
|
|
2997
3018
|
let forkChild;
|
|
2998
3019
|
try {
|
|
2999
|
-
forkChild = await opts.runner.runTask(
|
|
3020
|
+
forkChild = await opts.runner.runTask(forkChildSpec(ctx.signal), forkInternals);
|
|
3000
3021
|
if (forkChild.terminal.kind === "failed" && forkChild.terminal.code === "resume.session_not_found") {
|
|
3001
3022
|
try {
|
|
3002
3023
|
await (releaseForked ? releaseForked() : opts.runner.sessions.release?.(forkedId));
|
|
@@ -3031,9 +3052,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3031
3052
|
tasks: 1 + (nsf?.tasks ?? 0),
|
|
3032
3053
|
costMicroUsd: rollupDelegatedCost(forkChild.stats, nsf),
|
|
3033
3054
|
});
|
|
3034
|
-
if (isDurablePause(forkChild.terminal)) {
|
|
3035
|
-
return durablePauseDelegationReport(` · ${FORK_SUBAGENT_TYPE}`, forkChild.terminal);
|
|
3036
|
-
}
|
|
3037
3055
|
const wtLine = reportedWorktreeLine(await finishWorktree());
|
|
3038
3056
|
const forkFace = childTerminalFace(forkChild.terminal);
|
|
3039
3057
|
const forkErr = classifySubagentError(forkChild.terminal);
|
|
@@ -3048,6 +3066,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3048
3066
|
forkFace.blockedReason ? `blocked_reason: ${inlineUntrusted(forkFace.blockedReason, REPORT_FIELD_MAX)}` : "",
|
|
3049
3067
|
forkFace.errorMessage ? `error: ${inlineUntrusted(forkFace.errorMessage, REPORT_FIELD_MAX)}` : "",
|
|
3050
3068
|
forkErr ? `error_kind: ${forkErr.errorKind} (retryable: ${forkErr.retryable})` : "",
|
|
3069
|
+
forkChild.refusedAsks !== undefined ? `refused_asks: ${refusedAsksText(forkChild.refusedAsks)}` : "",
|
|
3051
3070
|
`stats: turns=${forkChild.stats.turns} tokens=${forkChild.stats.tokens}`,
|
|
3052
3071
|
"",
|
|
3053
3072
|
"result:",
|
|
@@ -3165,10 +3184,8 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3165
3184
|
catch {
|
|
3166
3185
|
}
|
|
3167
3186
|
}
|
|
3168
|
-
if (!settled)
|
|
3169
|
-
|
|
3170
|
-
console.warn(`[sema] delegation settlement terminal write failed (verdict ${verdict}, session ${settlementSeat.sessionId}): ${detail} — the pending row expires as unproven at the settlement window`);
|
|
3171
|
-
}
|
|
3187
|
+
if (!settled)
|
|
3188
|
+
saySettlementWriteFailed(opts.runner, { verdict, sessionId: settlementSeat.sessionId, fork: false }, lastErr);
|
|
3172
3189
|
};
|
|
3173
3190
|
let taskId;
|
|
3174
3191
|
try {
|
|
@@ -3264,13 +3281,10 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3264
3281
|
const bgStartedAt = Date.now();
|
|
3265
3282
|
stepRecorder.lockTo(taskId);
|
|
3266
3283
|
bgRegistry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
|
|
3267
|
-
|
|
3268
|
-
let retainedCycle;
|
|
3269
|
-
const cycleSeqOfFrames = () => retainedCycle?.cycleSeq ?? (parkedResume !== undefined ? (reviveRow?.seq ?? 1) + 1 : reviveRow?.seq);
|
|
3284
|
+
let bgCycleSeq = bgRegistry.backgroundAgentCycleSeq(taskId);
|
|
3270
3285
|
bgRegistry.attachAgentTerminalNotifier(taskId, (ending) => {
|
|
3271
3286
|
const stoppedByLanded = ending.status === "killed" ? bgRegistry.getStopAttribution(taskId) ?? "system" : undefined;
|
|
3272
3287
|
const completionIdLanded = bgRegistry.getCompletionId(taskId);
|
|
3273
|
-
const seqLanded = bgRegistry.backgroundAgentCycleSeq(taskId);
|
|
3274
3288
|
const landedElapsedMs = Date.now() - bgStartedAt;
|
|
3275
3289
|
const landedFrame = {
|
|
3276
3290
|
task_id: taskId,
|
|
@@ -3278,7 +3292,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3278
3292
|
toolUseId: ctx.toolCallId,
|
|
3279
3293
|
status: ending.status,
|
|
3280
3294
|
...terminalFrameFacets({ spawnName: agentName }),
|
|
3281
|
-
...(
|
|
3295
|
+
...(bgCycleSeq !== undefined ? { seq: bgCycleSeq } : {}),
|
|
3282
3296
|
...(stoppedByLanded !== undefined ? { stoppedBy: stoppedByLanded } : {}),
|
|
3283
3297
|
summary: ending.status === "failed" ? `Agent "${shortDesc}" failed: ${ending.error ?? "ended"}${ccElapsedTag(landedElapsedMs)}`.slice(0, 300) : ccCompletionText(shortDesc, "killed", "killed", landedElapsedMs),
|
|
3284
3298
|
...(ending.status === "failed" && ending.error !== undefined ? { error: ending.error.slice(0, REPORT_FIELD_MAX) } : {}),
|
|
@@ -3286,13 +3300,13 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3286
3300
|
resumable: false,
|
|
3287
3301
|
...(completionIdLanded !== undefined ? { completionId: completionIdLanded } : {}),
|
|
3288
3302
|
};
|
|
3289
|
-
sinkEmit(backgroundChildTerminal(landedFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId
|
|
3303
|
+
sinkEmit(backgroundChildTerminal(landedFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId }));
|
|
3290
3304
|
const landedLane = ending.parkLane ?? cycleSink;
|
|
3291
3305
|
notifier.notify(() => landedLane?.(landedFrame, { priority: "next" }), "subagent.landedTerminalNotify");
|
|
3292
3306
|
});
|
|
3293
3307
|
const bgDurableProbe = bgRegistry.durableAgentRowProbe(taskId);
|
|
3294
3308
|
const bgRowConfirmed = async () => (bgDurableProbe ? await bgDurableProbe().catch(() => false) : false);
|
|
3295
|
-
sinkEmit({
|
|
3309
|
+
const emitSpawnFrame = () => sinkEmit({
|
|
3296
3310
|
kind: "spawn",
|
|
3297
3311
|
taskId,
|
|
3298
3312
|
sessionScoped: sessionScopedBg === true,
|
|
@@ -3319,6 +3333,8 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3319
3333
|
}),
|
|
3320
3334
|
startedAt: reviveRow?.spawnedAt ?? Date.now(),
|
|
3321
3335
|
});
|
|
3336
|
+
if (parkedResume === undefined)
|
|
3337
|
+
emitSpawnFrame();
|
|
3322
3338
|
const bgRetainLedger = reviveRow !== undefined
|
|
3323
3339
|
? undefined
|
|
3324
3340
|
: sessionScopedBg
|
|
@@ -3329,7 +3345,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3329
3345
|
if (sessionScopedBg && bgRetainLedger)
|
|
3330
3346
|
ensureSessionReapHook(bgRegistry);
|
|
3331
3347
|
const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, { registry: bgRegistry, taskId }, backgroundLegFacts(taskId));
|
|
3332
|
-
retainedCycle = bgRetain;
|
|
3333
3348
|
if (bgRetain) {
|
|
3334
3349
|
bgRegistry.markRetainedContinuation(taskId);
|
|
3335
3350
|
const origRelease = bgRetain.release;
|
|
@@ -3339,9 +3354,10 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3339
3354
|
};
|
|
3340
3355
|
}
|
|
3341
3356
|
bgRegistry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
|
|
3342
|
-
const
|
|
3357
|
+
const builtChildSpec = buildChildSpec(abort.signal);
|
|
3358
|
+
const forwardDurableApproval = ctx.durableApprovalForChildren !== undefined && parkCapable && builtChildSpec.durableApproval !== false;
|
|
3343
3359
|
const bgSpecBase = {
|
|
3344
|
-
...
|
|
3360
|
+
...builtChildSpec,
|
|
3345
3361
|
sessionId: bgChildSessionId,
|
|
3346
3362
|
...(forwardDurableApproval ? { durableApproval: { ...ctx.durableApprovalForChildren } } : {}),
|
|
3347
3363
|
...(legYield !== undefined ? { preemptSignal: legYield.signal } : {}),
|
|
@@ -3434,7 +3450,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3434
3450
|
bgActivityBeat(e);
|
|
3435
3451
|
},
|
|
3436
3452
|
};
|
|
3437
|
-
const bgInternals = legYield !== undefined ? { ...bgLaneInternals, reportSuspendLane: ({ ready }) => bgRegistry.attachYieldLeg(taskId, legYield, ready) } : bgLaneInternals;
|
|
3453
|
+
const bgInternals = legYield !== undefined ? { ...bgLaneInternals, parkLaneHeld: true, reportSuspendLane: ({ ready }) => bgRegistry.attachYieldLeg(taskId, legYield, ready) } : bgLaneInternals;
|
|
3438
3454
|
const driveParkedResume = async () => {
|
|
3439
3455
|
const pr = parkedResume;
|
|
3440
3456
|
const claimStores = { agentStore: bg.agentStore, checkpointStore: childParkStore };
|
|
@@ -3501,13 +3517,16 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3501
3517
|
}
|
|
3502
3518
|
const afterCheckpointResolve = async () => {
|
|
3503
3519
|
attemptEnding = "failed";
|
|
3504
|
-
const
|
|
3505
|
-
if (
|
|
3520
|
+
const opened = await bgRegistry.consumeParkedFlip(taskId, { agentStore: bg.agentStore }, pr.ticket);
|
|
3521
|
+
if (opened === undefined)
|
|
3506
3522
|
throw new Error("the parked row moved under the resume (a stop or another transition won) — resume aborted");
|
|
3523
|
+
bgCycleSeq = opened;
|
|
3524
|
+
emitSpawnFrame();
|
|
3507
3525
|
moveTerminalDelivery(heldInRegistry, notify, { task_id: taskId, task_type: "background_agent" });
|
|
3508
3526
|
cycleSink = notify;
|
|
3509
3527
|
if (rowRoot !== undefined)
|
|
3510
3528
|
deliverEngineNotice(undefined, resumeLaneMissingNotice(taskId, reviveRow?.rootSessionId, rootSessionLaneOf(opts.runner, rowRoot.address)));
|
|
3529
|
+
return { cycleSeq: opened };
|
|
3511
3530
|
};
|
|
3512
3531
|
let childResult;
|
|
3513
3532
|
try {
|
|
@@ -3605,7 +3624,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3605
3624
|
}
|
|
3606
3625
|
catch {
|
|
3607
3626
|
}
|
|
3608
|
-
const seqAtSettle = cycleSeqOfFrames();
|
|
3609
3627
|
const bgHandbackWarning = isDurablePause(child.terminal)
|
|
3610
3628
|
? undefined
|
|
3611
3629
|
: await reviewHandback({
|
|
@@ -3660,7 +3678,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3660
3678
|
const parked = attested && !abort.signal.aborted
|
|
3661
3679
|
? bgRegistry.parkBackgroundAgent(taskId, {
|
|
3662
3680
|
checkpointToken: token,
|
|
3663
|
-
seq: seqAtSettle ?? 1,
|
|
3664
3681
|
completionSink: cycleSink,
|
|
3665
3682
|
resolveStop: async () => {
|
|
3666
3683
|
const cpS = childParkStore;
|
|
@@ -3699,8 +3716,8 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3699
3716
|
const settleWinnerBg = bgRegistry.settleBackgroundAgent(taskId, {
|
|
3700
3717
|
cycle: 0,
|
|
3701
3718
|
status: ok ? "completed" : reaped ? "killed" : "failed",
|
|
3702
|
-
seq: seqAtSettle ?? 1,
|
|
3703
3719
|
...resultSettleFields(bgHandbackResult),
|
|
3720
|
+
...(child.refusedAsks !== undefined ? { refusedAsks: child.refusedAsks } : {}),
|
|
3704
3721
|
...(!ok ? { error: reaped ? (collateral ? BG_AGENT_COLLATERAL_REAP_REASON : BG_AGENT_REAP_STOP_ERROR) : unparkedPauseReason ?? childFace.errorMessage ?? childFace.status } : {}),
|
|
3705
3722
|
...(errCodeBg !== undefined ? { errorCode: errCodeBg } : {}),
|
|
3706
3723
|
...(errClassBg !== undefined ? { retryable: errClassBg.retryable, errorKind: errClassBg.errorKind } : {}),
|
|
@@ -3722,7 +3739,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3722
3739
|
liveRetainPresent: settled !== "killed" && bgRetain !== undefined && bgRetainLedger?.get(ctx.toolCallId) === bgRetain,
|
|
3723
3740
|
liveRetainHasBudget: bgRetain !== undefined && bgRetain.resumeCount < SUBAGENT_RESUME_CAP,
|
|
3724
3741
|
durableRow: bgDurableRow,
|
|
3725
|
-
|
|
3742
|
+
durableRungServes: agentName !== undefined,
|
|
3726
3743
|
});
|
|
3727
3744
|
const failReasonBg = settled === "failed" ? unparkedPauseReason ?? childFace.errorMessage : undefined;
|
|
3728
3745
|
const bgElapsedMs = Date.now() - bgStartedAt;
|
|
@@ -3738,7 +3755,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3738
3755
|
toolUseId: ctx.toolCallId,
|
|
3739
3756
|
status: settled,
|
|
3740
3757
|
...terminalFrameFacets({ spawnName: agentName, result: bgHandbackResult, warning: bgHandbackWarning, compaction: child.compaction }),
|
|
3741
|
-
...(
|
|
3758
|
+
...(bgCycleSeq !== undefined ? { seq: bgCycleSeq } : {}),
|
|
3742
3759
|
...(stoppedBy !== undefined ? { stoppedBy } : {}),
|
|
3743
3760
|
summary: bgTerminalSummary,
|
|
3744
3761
|
...(failReasonBg !== undefined ? { error: failReasonBg.slice(0, REPORT_FIELD_MAX) } : {}),
|
|
@@ -3748,12 +3765,13 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3748
3765
|
...(bgResultField !== undefined ? { result: bgResultField.text } : {}),
|
|
3749
3766
|
...(settled === "killed" && child.result ? { partial: true } : {}),
|
|
3750
3767
|
...residual,
|
|
3768
|
+
...(child.refusedAsks !== undefined ? { refusedAsks: child.refusedAsks } : {}),
|
|
3751
3769
|
resumable: resumableBg,
|
|
3752
3770
|
usage: { tokens: child.stats.tokens, turns: child.stats.turns, ...delegatedCostField(child.stats), ...delegatedGranularityFieldsWire(child.stats, bgElapsedMs) },
|
|
3753
3771
|
...(completionIdBg !== undefined ? { completionId: completionIdBg } : {}),
|
|
3754
3772
|
};
|
|
3755
3773
|
if (ownsTerminalFaces)
|
|
3756
|
-
sinkEmit(backgroundChildTerminal(completionFrame, { taskId, sessionScoped: sessionScopedBg === true, ...(child.sessionId ? { sessionId: child.sessionId, transcriptId: child.sessionId } : {}), parentToolCallId: ctx.toolCallId
|
|
3774
|
+
sinkEmit(backgroundChildTerminal(completionFrame, { taskId, sessionScoped: sessionScopedBg === true, ...(child.sessionId ? { sessionId: child.sessionId, transcriptId: child.sessionId } : {}), parentToolCallId: ctx.toolCallId }));
|
|
3757
3775
|
const gateOwners = ownsTerminalFaces && settled === "completed" && bgRetain !== undefined ? childOwnerKeys(child.taskId, bgRetain.childSessionId) : [];
|
|
3758
3776
|
const aliveBgCount = runningBackgroundUnder(bgRegistry, gateOwners);
|
|
3759
3777
|
if (bgRetain !== undefined && aliveBgCount > 0) {
|
|
@@ -3782,7 +3800,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3782
3800
|
const rejected = (await bgChildRejection) ?? rejectedChildOf(e);
|
|
3783
3801
|
void finishWorktree();
|
|
3784
3802
|
const killed = abort.signal.aborted;
|
|
3785
|
-
const seqAtSettle = cycleSeqOfFrames();
|
|
3786
3803
|
if (bgRetain) {
|
|
3787
3804
|
if (killed)
|
|
3788
3805
|
void bgRetainLedger?.evict(ctx.toolCallId);
|
|
@@ -3796,7 +3813,6 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3796
3813
|
cycle: 0,
|
|
3797
3814
|
status: killed ? "killed" : "failed",
|
|
3798
3815
|
error: msg,
|
|
3799
|
-
seq: seqAtSettle ?? 1,
|
|
3800
3816
|
...(errCodeBgReject !== undefined ? { errorCode: errCodeBgReject } : {}),
|
|
3801
3817
|
...(errClassBgReject !== undefined ? { retryable: errClassBgReject.retryable, errorKind: errClassBgReject.errorKind } : {}),
|
|
3802
3818
|
});
|
|
@@ -3816,7 +3832,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3816
3832
|
status: settled,
|
|
3817
3833
|
...terminalFrameFacets({ spawnName: agentName }),
|
|
3818
3834
|
sessionId: bgChildSessionId,
|
|
3819
|
-
...(
|
|
3835
|
+
...(bgCycleSeq !== undefined ? { seq: bgCycleSeq } : {}),
|
|
3820
3836
|
...(stoppedBy !== undefined ? { stoppedBy } : {}),
|
|
3821
3837
|
summary: `${settled === "failed" ? `Agent "${shortDesc}" failed: ${msg}${ccElapsedTag(Date.now() - bgStartedAt)}` : ccCompletionText(shortDesc, settled, settled, Date.now() - bgStartedAt)}${observerNote}`.slice(0, 300) + (settled === "failed" ? errorKindClause(errClassBgReject) : ""),
|
|
3822
3838
|
...(settled === "failed" ? { error: msg.slice(0, REPORT_FIELD_MAX) } : {}),
|
|
@@ -3824,7 +3840,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3824
3840
|
...(completionIdBgReject !== undefined ? { completionId: completionIdBgReject } : {}),
|
|
3825
3841
|
};
|
|
3826
3842
|
if (ownsTerminalFacesReject)
|
|
3827
|
-
sinkEmit(backgroundChildTerminal(rejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId
|
|
3843
|
+
sinkEmit(backgroundChildTerminal(rejectFrame, { taskId, sessionScoped: sessionScopedBg === true, sessionId: bgChildSessionId, transcriptId: bgChildSessionId, parentToolCallId: ctx.toolCallId }));
|
|
3828
3844
|
try {
|
|
3829
3845
|
if (ownsTerminalFacesReject)
|
|
3830
3846
|
rejectSink(rejectFrame, { priority: "next" });
|
|
@@ -3866,6 +3882,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3866
3882
|
content: asyncLaunchedReceipt({
|
|
3867
3883
|
taskId,
|
|
3868
3884
|
workingLine: `The agent is working in the background.`,
|
|
3885
|
+
...(agentName !== undefined ? { name: agentName } : {}),
|
|
3869
3886
|
notes: [
|
|
3870
3887
|
modelNote,
|
|
3871
3888
|
extraToolsNote,
|
|
@@ -3877,7 +3894,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
3877
3894
|
: `Note: it is stopped automatically (killed) if still running when this task ends — do not promise the user results beyond this task.`,
|
|
3878
3895
|
],
|
|
3879
3896
|
}),
|
|
3880
|
-
details: { type: "agent", status: "async_launched", isAsync: true, task_id: taskId, description: shortDesc, prompt, ...(bgSettleId !== undefined ? { settle_id: bgSettleId } : {}) },
|
|
3897
|
+
details: { type: "agent", status: "async_launched", isAsync: true, task_id: taskId, description: shortDesc, prompt, ...(agentName !== undefined ? { name: agentName } : {}), ...(bgSettleId !== undefined ? { settle_id: bgSettleId } : {}) },
|
|
3881
3898
|
};
|
|
3882
3899
|
}
|
|
3883
3900
|
let child;
|
|
@@ -4004,6 +4021,7 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
4004
4021
|
childFace.blockedReason ? `blocked_reason: ${inlineUntrusted(childFace.blockedReason, REPORT_FIELD_MAX)}` : "",
|
|
4005
4022
|
childFace.errorMessage ? `error: ${inlineUntrusted(childFace.errorMessage, REPORT_FIELD_MAX)}` : "",
|
|
4006
4023
|
errClass ? `error_kind: ${errClass.errorKind} (retryable: ${errClass.retryable})` : "",
|
|
4024
|
+
child.refusedAsks !== undefined ? `refused_asks: ${refusedAsksText(child.refusedAsks)}` : "",
|
|
4007
4025
|
observerFailure !== undefined
|
|
4008
4026
|
? `observer: failed (${inlineUntrusted(observerFailure, REPORT_FIELD_MAX)})`
|
|
4009
4027
|
: observerDegradedCount > 0
|
|
@@ -4064,6 +4082,18 @@ function buildSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
|
|
|
4064
4082
|
})(),
|
|
4065
4083
|
}),
|
|
4066
4084
|
};
|
|
4067
|
-
},
|
|
4085
|
+
}),
|
|
4068
4086
|
});
|
|
4069
4087
|
}
|
|
4088
|
+
function releasingSpawnNameClaim(execute) {
|
|
4089
|
+
return async (args, ctx) => {
|
|
4090
|
+
const held = [];
|
|
4091
|
+
try {
|
|
4092
|
+
return await execute(args, ctx, (claim) => void held.push(claim));
|
|
4093
|
+
}
|
|
4094
|
+
finally {
|
|
4095
|
+
for (const claim of held)
|
|
4096
|
+
claim.release();
|
|
4097
|
+
}
|
|
4098
|
+
};
|
|
4099
|
+
}
|