operon-agents-core 0.1.0-alpha.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/LICENSE +55 -0
- package/README.md +7 -0
- package/dist/agent/agent.d.ts +65 -0
- package/dist/agent/agent.js +39 -0
- package/dist/agent/compose-hooks.d.ts +13 -0
- package/dist/agent/compose-hooks.js +197 -0
- package/dist/agent/concurrency.d.ts +22 -0
- package/dist/agent/concurrency.js +70 -0
- package/dist/agent/context-report.d.ts +60 -0
- package/dist/agent/context-report.js +45 -0
- package/dist/agent/graph.d.ts +48 -0
- package/dist/agent/graph.js +129 -0
- package/dist/agent/guardrail.d.ts +105 -0
- package/dist/agent/guardrail.js +314 -0
- package/dist/agent/handoff-executor.d.ts +21 -0
- package/dist/agent/handoff-executor.js +95 -0
- package/dist/agent/handoff.d.ts +42 -0
- package/dist/agent/handoff.js +70 -0
- package/dist/agent/index.d.ts +25 -0
- package/dist/agent/index.js +19 -0
- package/dist/agent/instruction-context.d.ts +33 -0
- package/dist/agent/instruction-context.js +100 -0
- package/dist/agent/pause.d.ts +12 -0
- package/dist/agent/pause.js +82 -0
- package/dist/agent/profile-builtins.d.ts +8 -0
- package/dist/agent/profile-builtins.js +130 -0
- package/dist/agent/profiles.d.ts +94 -0
- package/dist/agent/profiles.js +264 -0
- package/dist/agent/recovery.d.ts +10 -0
- package/dist/agent/recovery.js +151 -0
- package/dist/agent/run-support.d.ts +79 -0
- package/dist/agent/run-support.js +211 -0
- package/dist/agent/runner.d.ts +246 -0
- package/dist/agent/runner.js +786 -0
- package/dist/agent/session.d.ts +363 -0
- package/dist/agent/session.js +937 -0
- package/dist/agent/subagent-tools.d.ts +18 -0
- package/dist/agent/subagent-tools.js +650 -0
- package/dist/agent/subagent.d.ts +56 -0
- package/dist/agent/subagent.js +50 -0
- package/dist/agent/toolset.d.ts +24 -0
- package/dist/agent/toolset.js +112 -0
- package/dist/agent/workflow/index.d.ts +9 -0
- package/dist/agent/workflow/index.js +8 -0
- package/dist/agent/workflow/journal.d.ts +180 -0
- package/dist/agent/workflow/journal.js +224 -0
- package/dist/agent/workflow/manager.d.ts +27 -0
- package/dist/agent/workflow/manager.js +33 -0
- package/dist/agent/workflow/parse.d.ts +17 -0
- package/dist/agent/workflow/parse.js +174 -0
- package/dist/agent/workflow/prompt.d.ts +8 -0
- package/dist/agent/workflow/prompt.js +84 -0
- package/dist/agent/workflow/runtime.d.ts +64 -0
- package/dist/agent/workflow/runtime.js +380 -0
- package/dist/agent/workflow/sandbox.d.ts +35 -0
- package/dist/agent/workflow/sandbox.js +90 -0
- package/dist/agent/workflow/snapshot.d.ts +36 -0
- package/dist/agent/workflow/snapshot.js +9 -0
- package/dist/agent/workflow/structured.d.ts +35 -0
- package/dist/agent/workflow/structured.js +79 -0
- package/dist/agent/workflow/tool.d.ts +14 -0
- package/dist/agent/workflow/tool.js +569 -0
- package/dist/agent/workflow/types.d.ts +100 -0
- package/dist/agent/workflow/types.js +17 -0
- package/dist/agent/worktree.d.ts +38 -0
- package/dist/agent/worktree.js +56 -0
- package/dist/capabilities/assembler.d.ts +39 -0
- package/dist/capabilities/assembler.js +171 -0
- package/dist/capabilities/background/agent-task.d.ts +51 -0
- package/dist/capabilities/background/agent-task.js +101 -0
- package/dist/capabilities/background/command-task.d.ts +43 -0
- package/dist/capabilities/background/command-task.js +86 -0
- package/dist/capabilities/background/index.d.ts +20 -0
- package/dist/capabilities/background/index.js +57 -0
- package/dist/capabilities/background/manager.d.ts +194 -0
- package/dist/capabilities/background/manager.js +1131 -0
- package/dist/capabilities/background/persist-disk.d.ts +17 -0
- package/dist/capabilities/background/persist-disk.js +66 -0
- package/dist/capabilities/background/persist.d.ts +61 -0
- package/dist/capabilities/background/persist.js +117 -0
- package/dist/capabilities/background/question-task.d.ts +32 -0
- package/dist/capabilities/background/question-task.js +56 -0
- package/dist/capabilities/background/registrar.d.ts +12 -0
- package/dist/capabilities/background/registrar.js +9 -0
- package/dist/capabilities/background/swappable-sink.d.ts +20 -0
- package/dist/capabilities/background/swappable-sink.js +20 -0
- package/dist/capabilities/background/task.d.ts +114 -0
- package/dist/capabilities/background/task.js +20 -0
- package/dist/capabilities/background/tools.d.ts +6 -0
- package/dist/capabilities/background/tools.js +190 -0
- package/dist/capabilities/background/workflow-task.d.ts +48 -0
- package/dist/capabilities/background/workflow-task.js +91 -0
- package/dist/capabilities/capability-state.d.ts +13 -0
- package/dist/capabilities/capability-state.js +37 -0
- package/dist/capabilities/capability.d.ts +145 -0
- package/dist/capabilities/capability.js +2 -0
- package/dist/capabilities/compaction/full.d.ts +27 -0
- package/dist/capabilities/compaction/full.js +155 -0
- package/dist/capabilities/compaction/index.d.ts +17 -0
- package/dist/capabilities/compaction/index.js +145 -0
- package/dist/capabilities/compaction/instruction.d.ts +2 -0
- package/dist/capabilities/compaction/instruction.js +31 -0
- package/dist/capabilities/compaction/micro.d.ts +17 -0
- package/dist/capabilities/compaction/micro.js +57 -0
- package/dist/capabilities/compaction/service.d.ts +28 -0
- package/dist/capabilities/compaction/service.js +52 -0
- package/dist/capabilities/compaction/strategy.d.ts +43 -0
- package/dist/capabilities/compaction/strategy.js +116 -0
- package/dist/capabilities/compaction/tokens.d.ts +5 -0
- package/dist/capabilities/compaction/tokens.js +28 -0
- package/dist/capabilities/goal/goal-store.d.ts +69 -0
- package/dist/capabilities/goal/goal-store.js +172 -0
- package/dist/capabilities/goal/index.d.ts +6 -0
- package/dist/capabilities/goal/index.js +31 -0
- package/dist/capabilities/goal/injector.d.ts +9 -0
- package/dist/capabilities/goal/injector.js +79 -0
- package/dist/capabilities/goal/tools.d.ts +6 -0
- package/dist/capabilities/goal/tools.js +86 -0
- package/dist/capabilities/index.d.ts +25 -0
- package/dist/capabilities/index.js +22 -0
- package/dist/capabilities/injection.d.ts +44 -0
- package/dist/capabilities/injection.js +112 -0
- package/dist/capabilities/plan/index.d.ts +6 -0
- package/dist/capabilities/plan/index.js +25 -0
- package/dist/capabilities/plan/injector.d.ts +13 -0
- package/dist/capabilities/plan/injector.js +83 -0
- package/dist/capabilities/plan/plan-mode.d.ts +38 -0
- package/dist/capabilities/plan/plan-mode.js +113 -0
- package/dist/capabilities/plan/policies.d.ts +6 -0
- package/dist/capabilities/plan/policies.js +89 -0
- package/dist/capabilities/plan/tools.d.ts +15 -0
- package/dist/capabilities/plan/tools.js +87 -0
- package/dist/capabilities/skills/flow-provider.d.ts +6 -0
- package/dist/capabilities/skills/flow-provider.js +50 -0
- package/dist/capabilities/skills/index.d.ts +43 -0
- package/dist/capabilities/skills/index.js +48 -0
- package/dist/capabilities/skills/injector.d.ts +11 -0
- package/dist/capabilities/skills/injector.js +27 -0
- package/dist/capabilities/skills/parser.d.ts +36 -0
- package/dist/capabilities/skills/parser.js +334 -0
- package/dist/capabilities/skills/registry.d.ts +33 -0
- package/dist/capabilities/skills/registry.js +118 -0
- package/dist/capabilities/skills/scanner.d.ts +26 -0
- package/dist/capabilities/skills/scanner.js +154 -0
- package/dist/capabilities/skills/service.d.ts +39 -0
- package/dist/capabilities/skills/service.js +68 -0
- package/dist/capabilities/skills/skill-tool.d.ts +13 -0
- package/dist/capabilities/skills/skill-tool.js +72 -0
- package/dist/capabilities/skills/types.d.ts +62 -0
- package/dist/capabilities/skills/types.js +26 -0
- package/dist/capabilities/task/index.d.ts +23 -0
- package/dist/capabilities/task/index.js +38 -0
- package/dist/capabilities/task/injector.d.ts +9 -0
- package/dist/capabilities/task/injector.js +62 -0
- package/dist/capabilities/task/persist-disk.d.ts +19 -0
- package/dist/capabilities/task/persist-disk.js +84 -0
- package/dist/capabilities/task/persist.d.ts +52 -0
- package/dist/capabilities/task/persist.js +84 -0
- package/dist/capabilities/task/task-store.d.ts +44 -0
- package/dist/capabilities/task/task-store.js +106 -0
- package/dist/capabilities/task/tools.d.ts +12 -0
- package/dist/capabilities/task/tools.js +164 -0
- package/dist/capabilities/todo/index.d.ts +8 -0
- package/dist/capabilities/todo/index.js +21 -0
- package/dist/capabilities/todo/injector.d.ts +9 -0
- package/dist/capabilities/todo/injector.js +68 -0
- package/dist/capabilities/todo/todo-store.d.ts +19 -0
- package/dist/capabilities/todo/todo-store.js +36 -0
- package/dist/capabilities/todo/tools.d.ts +6 -0
- package/dist/capabilities/todo/tools.js +70 -0
- package/dist/capabilities/tool-provider.d.ts +12 -0
- package/dist/capabilities/tool-provider.js +20 -0
- package/dist/capabilities/user-hooks/engine.d.ts +22 -0
- package/dist/capabilities/user-hooks/engine.js +105 -0
- package/dist/capabilities/user-hooks/index.d.ts +13 -0
- package/dist/capabilities/user-hooks/index.js +126 -0
- package/dist/capabilities/user-hooks/types.d.ts +26 -0
- package/dist/capabilities/user-hooks/types.js +19 -0
- package/dist/capabilities/workflow/index.d.ts +16 -0
- package/dist/capabilities/workflow/index.js +15 -0
- package/dist/commands/index.d.ts +31 -0
- package/dist/commands/index.js +318 -0
- package/dist/config/config-store.d.ts +29 -0
- package/dist/config/config-store.js +103 -0
- package/dist/config/file-source.d.ts +40 -0
- package/dist/config/file-source.js +78 -0
- package/dist/config/flags.d.ts +13 -0
- package/dist/config/flags.js +25 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +10 -0
- package/dist/config/merge.d.ts +5 -0
- package/dist/config/merge.js +57 -0
- package/dist/config/model-catalog.d.ts +17 -0
- package/dist/config/model-catalog.js +37 -0
- package/dist/config/paths.d.ts +31 -0
- package/dist/config/paths.js +28 -0
- package/dist/config/provider-manager.d.ts +57 -0
- package/dist/config/provider-manager.js +344 -0
- package/dist/config/resolver.d.ts +40 -0
- package/dist/config/resolver.js +52 -0
- package/dist/config/schema.d.ts +389 -0
- package/dist/config/schema.js +132 -0
- package/dist/events/events.d.ts +348 -0
- package/dist/events/events.js +146 -0
- package/dist/events/index.d.ts +10 -0
- package/dist/events/index.js +5 -0
- package/dist/events/projection.d.ts +207 -0
- package/dist/events/projection.js +438 -0
- package/dist/events/publisher.d.ts +48 -0
- package/dist/events/publisher.js +404 -0
- package/dist/events/redacting-sink.d.ts +11 -0
- package/dist/events/redacting-sink.js +31 -0
- package/dist/home.d.ts +16 -0
- package/dist/home.js +20 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/internal.d.ts +33 -0
- package/dist/internal.js +29 -0
- package/dist/llm/auth.d.ts +22 -0
- package/dist/llm/auth.js +112 -0
- package/dist/llm/capability.d.ts +13 -0
- package/dist/llm/capability.js +45 -0
- package/dist/llm/define-model.d.ts +110 -0
- package/dist/llm/define-model.js +252 -0
- package/dist/llm/errors.d.ts +33 -0
- package/dist/llm/errors.js +154 -0
- package/dist/llm/index.d.ts +14 -0
- package/dist/llm/index.js +8 -0
- package/dist/llm/model.d.ts +43 -0
- package/dist/llm/model.js +9 -0
- package/dist/llm/retry.d.ts +35 -0
- package/dist/llm/retry.js +160 -0
- package/dist/llm/runtime.d.ts +25 -0
- package/dist/llm/runtime.js +38 -0
- package/dist/logging/diagnostics.d.ts +21 -0
- package/dist/logging/diagnostics.js +46 -0
- package/dist/logging/index.d.ts +11 -0
- package/dist/logging/index.js +7 -0
- package/dist/logging/logger.d.ts +25 -0
- package/dist/logging/logger.js +54 -0
- package/dist/logging/paths.d.ts +11 -0
- package/dist/logging/paths.js +20 -0
- package/dist/logging/policy.d.ts +5 -0
- package/dist/logging/policy.js +19 -0
- package/dist/logging/redact.d.ts +10 -0
- package/dist/logging/redact.js +95 -0
- package/dist/logging/sinks.d.ts +67 -0
- package/dist/logging/sinks.js +117 -0
- package/dist/loop/context.d.ts +69 -0
- package/dist/loop/context.js +129 -0
- package/dist/loop/errors.d.ts +8 -0
- package/dist/loop/errors.js +27 -0
- package/dist/loop/events.d.ts +14 -0
- package/dist/loop/events.js +2 -0
- package/dist/loop/index.d.ts +10 -0
- package/dist/loop/index.js +7 -0
- package/dist/loop/interruption.d.ts +118 -0
- package/dist/loop/interruption.js +191 -0
- package/dist/loop/run-turn.d.ts +54 -0
- package/dist/loop/run-turn.js +203 -0
- package/dist/loop/scheduler.d.ts +18 -0
- package/dist/loop/scheduler.js +71 -0
- package/dist/loop/steer.d.ts +122 -0
- package/dist/loop/steer.js +209 -0
- package/dist/loop/tool-call.d.ts +41 -0
- package/dist/loop/tool-call.js +326 -0
- package/dist/loop/turn-step.d.ts +57 -0
- package/dist/loop/turn-step.js +298 -0
- package/dist/loop/types.d.ts +217 -0
- package/dist/loop/types.js +2 -0
- package/dist/loop/usage.d.ts +6 -0
- package/dist/loop/usage.js +44 -0
- package/dist/mcp/auth-tool.d.ts +12 -0
- package/dist/mcp/auth-tool.js +92 -0
- package/dist/mcp/capability.d.ts +7 -0
- package/dist/mcp/capability.js +91 -0
- package/dist/mcp/config-loader.d.ts +28 -0
- package/dist/mcp/config-loader.js +115 -0
- package/dist/mcp/filter.d.ts +18 -0
- package/dist/mcp/filter.js +35 -0
- package/dist/mcp/index.d.ts +23 -0
- package/dist/mcp/index.js +13 -0
- package/dist/mcp/manager.d.ts +51 -0
- package/dist/mcp/manager.js +412 -0
- package/dist/mcp/mock-transport.d.ts +40 -0
- package/dist/mcp/mock-transport.js +68 -0
- package/dist/mcp/oauth/callback-server.d.ts +14 -0
- package/dist/mcp/oauth/callback-server.js +122 -0
- package/dist/mcp/oauth/index.d.ts +9 -0
- package/dist/mcp/oauth/index.js +5 -0
- package/dist/mcp/oauth/provider.d.ts +39 -0
- package/dist/mcp/oauth/provider.js +121 -0
- package/dist/mcp/oauth/service.d.ts +34 -0
- package/dist/mcp/oauth/service.js +130 -0
- package/dist/mcp/oauth/store.d.ts +40 -0
- package/dist/mcp/oauth/store.js +134 -0
- package/dist/mcp/output.d.ts +12 -0
- package/dist/mcp/output.js +110 -0
- package/dist/mcp/provider.d.ts +7 -0
- package/dist/mcp/provider.js +56 -0
- package/dist/mcp/sdk-transport.d.ts +25 -0
- package/dist/mcp/sdk-transport.js +228 -0
- package/dist/mcp/server.d.ts +77 -0
- package/dist/mcp/server.js +120 -0
- package/dist/mcp/tool-naming.d.ts +4 -0
- package/dist/mcp/tool-naming.js +26 -0
- package/dist/mcp/types.d.ts +75 -0
- package/dist/mcp/types.js +2 -0
- package/dist/net/index.d.ts +3 -0
- package/dist/net/index.js +2 -0
- package/dist/net/proxy.d.ts +16 -0
- package/dist/net/proxy.js +42 -0
- package/dist/permission/auto-approver/index.d.ts +3 -0
- package/dist/permission/auto-approver/index.js +3 -0
- package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
- package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
- package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
- package/dist/permission/auto-approver/prompts-data.js +155 -0
- package/dist/permission/auto-approver/prompts.d.ts +18 -0
- package/dist/permission/auto-approver/prompts.js +40 -0
- package/dist/permission/auto-approver/transcript.d.ts +22 -0
- package/dist/permission/auto-approver/transcript.js +75 -0
- package/dist/permission/auto-approver/xml.d.ts +5 -0
- package/dist/permission/auto-approver/xml.js +25 -0
- package/dist/permission/index.d.ts +7 -0
- package/dist/permission/index.js +5 -0
- package/dist/permission/manager.d.ts +74 -0
- package/dist/permission/manager.js +162 -0
- package/dist/permission/matches-rule.d.ts +27 -0
- package/dist/permission/matches-rule.js +54 -0
- package/dist/permission/policies.d.ts +14 -0
- package/dist/permission/policies.js +233 -0
- package/dist/permission/types.d.ts +84 -0
- package/dist/permission/types.js +2 -0
- package/dist/plugins/archive.d.ts +3 -0
- package/dist/plugins/archive.js +58 -0
- package/dist/plugins/github-resolver.d.ts +13 -0
- package/dist/plugins/github-resolver.js +20 -0
- package/dist/plugins/hooks.d.ts +28 -0
- package/dist/plugins/hooks.js +296 -0
- package/dist/plugins/index.d.ts +23 -0
- package/dist/plugins/index.js +23 -0
- package/dist/plugins/injector.d.ts +11 -0
- package/dist/plugins/injector.js +32 -0
- package/dist/plugins/manager.d.ts +37 -0
- package/dist/plugins/manager.js +330 -0
- package/dist/plugins/manifest.d.ts +9 -0
- package/dist/plugins/manifest.js +234 -0
- package/dist/plugins/marketplace.d.ts +85 -0
- package/dist/plugins/marketplace.js +205 -0
- package/dist/plugins/source.d.ts +23 -0
- package/dist/plugins/source.js +87 -0
- package/dist/plugins/store.d.ts +20 -0
- package/dist/plugins/store.js +30 -0
- package/dist/plugins/types.d.ts +118 -0
- package/dist/plugins/types.js +5 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +2 -0
- package/dist/protocol/tool-schema.d.ts +6 -0
- package/dist/protocol/tool-schema.js +2 -0
- package/dist/store/blob-store.d.ts +45 -0
- package/dist/store/blob-store.js +120 -0
- package/dist/store/catalog-store.d.ts +32 -0
- package/dist/store/catalog-store.js +73 -0
- package/dist/store/disk-store.d.ts +58 -0
- package/dist/store/disk-store.js +369 -0
- package/dist/store/index.d.ts +23 -0
- package/dist/store/index.js +15 -0
- package/dist/store/lock.d.ts +86 -0
- package/dist/store/lock.js +104 -0
- package/dist/store/log-store.d.ts +89 -0
- package/dist/store/log-store.js +296 -0
- package/dist/store/migrate.d.ts +26 -0
- package/dist/store/migrate.js +32 -0
- package/dist/store/origin.d.ts +89 -0
- package/dist/store/origin.js +16 -0
- package/dist/store/pg.d.ts +90 -0
- package/dist/store/pg.js +344 -0
- package/dist/store/redacting-store.d.ts +21 -0
- package/dist/store/redacting-store.js +46 -0
- package/dist/store/redis.d.ts +89 -0
- package/dist/store/redis.js +370 -0
- package/dist/store/repository.d.ts +150 -0
- package/dist/store/repository.js +508 -0
- package/dist/store/session-catalog.d.ts +32 -0
- package/dist/store/session-catalog.js +117 -0
- package/dist/store/storage.d.ts +27 -0
- package/dist/store/storage.js +54 -0
- package/dist/store/store.d.ts +262 -0
- package/dist/store/store.js +129 -0
- package/dist/store/workdir-key.d.ts +4 -0
- package/dist/store/workdir-key.js +28 -0
- package/dist/tool/access.d.ts +37 -0
- package/dist/tool/access.js +79 -0
- package/dist/tool/ask.d.ts +22 -0
- package/dist/tool/ask.js +38 -0
- package/dist/tool/background.d.ts +109 -0
- package/dist/tool/background.js +39 -0
- package/dist/tool/builtin/ask-user-question.d.ts +2 -0
- package/dist/tool/builtin/ask-user-question.js +175 -0
- package/dist/tool/builtin/bash.d.ts +2 -0
- package/dist/tool/builtin/bash.js +407 -0
- package/dist/tool/builtin/edit.d.ts +2 -0
- package/dist/tool/builtin/edit.js +202 -0
- package/dist/tool/builtin/glob.d.ts +3 -0
- package/dist/tool/builtin/glob.js +260 -0
- package/dist/tool/builtin/grep.d.ts +2 -0
- package/dist/tool/builtin/grep.js +574 -0
- package/dist/tool/builtin/line-endings.d.ts +10 -0
- package/dist/tool/builtin/line-endings.js +41 -0
- package/dist/tool/builtin/read.d.ts +28 -0
- package/dist/tool/builtin/read.js +498 -0
- package/dist/tool/builtin/write.d.ts +2 -0
- package/dist/tool/builtin/write.js +179 -0
- package/dist/tool/define.d.ts +46 -0
- package/dist/tool/define.js +45 -0
- package/dist/tool/file-freshness.d.ts +81 -0
- package/dist/tool/file-freshness.js +67 -0
- package/dist/tool/filesystem-tools.d.ts +16 -0
- package/dist/tool/filesystem-tools.js +19 -0
- package/dist/tool/git-context.d.ts +20 -0
- package/dist/tool/git-context.js +114 -0
- package/dist/tool/index.d.ts +37 -0
- package/dist/tool/index.js +34 -0
- package/dist/tool/machine-base.d.ts +138 -0
- package/dist/tool/machine-base.js +388 -0
- package/dist/tool/machine-local.d.ts +35 -0
- package/dist/tool/machine-local.js +316 -0
- package/dist/tool/machine-null.d.ts +36 -0
- package/dist/tool/machine-null.js +64 -0
- package/dist/tool/machine-ssh.d.ts +86 -0
- package/dist/tool/machine-ssh.js +576 -0
- package/dist/tool/machine.d.ts +333 -0
- package/dist/tool/machine.js +15 -0
- package/dist/tool/policies/path-access.d.ts +48 -0
- package/dist/tool/policies/path-access.js +186 -0
- package/dist/tool/policies/sensitive.d.ts +3 -0
- package/dist/tool/policies/sensitive.js +60 -0
- package/dist/tool/questions.d.ts +40 -0
- package/dist/tool/questions.js +8 -0
- package/dist/tool/search/activation.d.ts +13 -0
- package/dist/tool/search/activation.js +31 -0
- package/dist/tool/search/deferral.d.ts +37 -0
- package/dist/tool/search/deferral.js +128 -0
- package/dist/tool/search/search-tool.d.ts +9 -0
- package/dist/tool/search/search-tool.js +62 -0
- package/dist/tool/shell-env.d.ts +9 -0
- package/dist/tool/shell-env.js +34 -0
- package/dist/tool/support/bash-destructive.d.ts +24 -0
- package/dist/tool/support/bash-destructive.js +63 -0
- package/dist/tool/support/bash-paths.d.ts +7 -0
- package/dist/tool/support/bash-paths.js +247 -0
- package/dist/tool/support/bash-read-only.d.ts +8 -0
- package/dist/tool/support/bash-read-only.js +165 -0
- package/dist/tool/support/bash-rule-match.d.ts +20 -0
- package/dist/tool/support/bash-rule-match.js +191 -0
- package/dist/tool/support/file-type.d.ts +10 -0
- package/dist/tool/support/file-type.js +149 -0
- package/dist/tool/support/git-worktree.d.ts +10 -0
- package/dist/tool/support/git-worktree.js +63 -0
- package/dist/tool/support/image-compress.d.ts +69 -0
- package/dist/tool/support/image-compress.js +265 -0
- package/dist/tool/support/machine-ops.d.ts +34 -0
- package/dist/tool/support/machine-ops.js +34 -0
- package/dist/tool/support/path-glob-match.d.ts +12 -0
- package/dist/tool/support/path-glob-match.js +84 -0
- package/dist/tool/support/result-builder.d.ts +27 -0
- package/dist/tool/support/result-builder.js +108 -0
- package/dist/tool/support/rg-locator.d.ts +20 -0
- package/dist/tool/support/rg-locator.js +42 -0
- package/dist/tool/support/ripgrep-run.d.ts +65 -0
- package/dist/tool/support/ripgrep-run.js +40 -0
- package/dist/tool/support/rule-match.d.ts +6 -0
- package/dist/tool/support/rule-match.js +23 -0
- package/dist/tool/support/tool-path.d.ts +8 -0
- package/dist/tool/support/tool-path.js +28 -0
- package/dist/tool/support/workspace.d.ts +5 -0
- package/dist/tool/support/workspace.js +2 -0
- package/dist/tool/types.d.ts +131 -0
- package/dist/tool/types.js +2 -0
- package/dist/tool/web/fetch-url.d.ts +4 -0
- package/dist/tool/web/fetch-url.js +61 -0
- package/dist/tool/web/index.d.ts +11 -0
- package/dist/tool/web/index.js +7 -0
- package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
- package/dist/tool/web/providers/direct-fetch.js +198 -0
- package/dist/tool/web/providers/firecrawl.d.ts +16 -0
- package/dist/tool/web/providers/firecrawl.js +59 -0
- package/dist/tool/web/providers/tavily.d.ts +14 -0
- package/dist/tool/web/providers/tavily.js +43 -0
- package/dist/tool/web/types.d.ts +41 -0
- package/dist/tool/web/types.js +7 -0
- package/dist/tool/web/web-search.d.ts +4 -0
- package/dist/tool/web/web-search.js +68 -0
- package/dist/tool/workspace-spec.d.ts +74 -0
- package/dist/tool/workspace-spec.js +177 -0
- package/dist/tracing/bridge.d.ts +7 -0
- package/dist/tracing/bridge.js +171 -0
- package/dist/tracing/index.d.ts +9 -0
- package/dist/tracing/index.js +5 -0
- package/dist/tracing/otel.d.ts +38 -0
- package/dist/tracing/otel.js +221 -0
- package/dist/tracing/processor.d.ts +47 -0
- package/dist/tracing/processor.js +94 -0
- package/dist/tracing/spans.d.ts +94 -0
- package/dist/tracing/spans.js +56 -0
- package/dist/ui/ai-sdk.d.ts +114 -0
- package/dist/ui/ai-sdk.js +175 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/package.json +101 -0
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The subagent-spawning tools — extracted from the Engine so all three spawn tools
|
|
3
|
+
* (`agent_<name>`, the unified `Agent`, and `Workflow`) live outside the Runner and share
|
|
4
|
+
* the same seam: the `SubagentSpawner` (resolve/derive/run/ctxFor) + the parent `RunState`.
|
|
5
|
+
*
|
|
6
|
+
* Neither tool reaches into the Engine: they run a sub-agent by forking a child frame
|
|
7
|
+
* (`spawner.derive`) and calling `spawner.run` (which IS `Engine.run`). Only TYPES are
|
|
8
|
+
* imported from `../runner.ts`, so there is no value-level import cycle (mirrors
|
|
9
|
+
* `workflow/tool.ts`).
|
|
10
|
+
*/
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { addUsage, subtractUsage } from "../loop/usage.js";
|
|
13
|
+
import { ConversationContext, replayContext } from "../loop/context.js";
|
|
14
|
+
import { historyChangeEmitter } from "./run-support.js";
|
|
15
|
+
import { SteerBus } from "../loop/steer.js";
|
|
16
|
+
import { ToolInterruptionSignal, findAnchoredAssistant, getInterruptionState, } from "../loop/interruption.js";
|
|
17
|
+
import { defineTool } from "../tool/define.js";
|
|
18
|
+
import { ToolAccesses } from "../tool/access.js";
|
|
19
|
+
import { joinAddress } from "../events/index.js";
|
|
20
|
+
import { AgentBackgroundTask } from "../capabilities/background/agent-task.js";
|
|
21
|
+
import { asTaskRegistrar } from "../capabilities/background/registrar.js";
|
|
22
|
+
import { isGuardrailTripwireError, runInputGuardrails } from "./guardrail.js";
|
|
23
|
+
import { toFunctionToolName } from "./handoff.js";
|
|
24
|
+
import { SUBAGENT_META, invalidAgentName, newAgentId, readSubagentMeta, } from "./subagent.js";
|
|
25
|
+
import { spawnLimiterFor } from "./concurrency.js";
|
|
26
|
+
/**
|
|
27
|
+
* The `agent_<name>` tool for a STATIC sub-agent on the active agent's graph. A thin
|
|
28
|
+
* delegation: seed the sub-agent with the prompt, run it to completion in its own shard,
|
|
29
|
+
* fold its usage back into the parent, and return its final text.
|
|
30
|
+
*/
|
|
31
|
+
export function buildSubagentTool(sub, spawner, parent) {
|
|
32
|
+
const toolName = `agent_${toFunctionToolName(sub.name)}`;
|
|
33
|
+
return defineTool({
|
|
34
|
+
name: toolName,
|
|
35
|
+
description: sub.handoffDescription ?? `Delegate a sub-task to the ${sub.name} sub-agent and return its result.`,
|
|
36
|
+
params: z.object({ input: z.string().describe(`The task or prompt for the ${sub.name} sub-agent.`) }),
|
|
37
|
+
resolve: (args) => ({
|
|
38
|
+
approvalRule: toolName,
|
|
39
|
+
// Conservative: a sub-agent can do anything, so serialize it against everything.
|
|
40
|
+
accesses: ToolAccesses.all(),
|
|
41
|
+
// Delegation is control flow — the sub-agent's OWN tools are permission-checked.
|
|
42
|
+
controlFlow: true,
|
|
43
|
+
display: { title: `Sub-agent: ${sub.name}`, detail: args.input },
|
|
44
|
+
run: async (ctx) => {
|
|
45
|
+
const continuation = childContinuation(parent, ctx.toolCallId);
|
|
46
|
+
if (continuation) {
|
|
47
|
+
const result = await resumeInterruptedChild(sub, continuation, spawner, parent, ctx.toolCallId, parent.signal);
|
|
48
|
+
settleChild(parent, result, continuation.execution.usage);
|
|
49
|
+
return subagentResult(sub.name, result.output, result.usage, result.status, continuation.agentInstanceId);
|
|
50
|
+
}
|
|
51
|
+
// Per-instance shard, same scheme as the unified Agent tool. A fixed
|
|
52
|
+
// `<parent>/<sub.name>` address would make repeated calls to the same static
|
|
53
|
+
// sub-agent append their seeds to one shared shard — live runs look fine (each
|
|
54
|
+
// seeds a fresh in-memory context) but replay/interruption-resume would reduce
|
|
55
|
+
// the mixed log into one polluted transcript.
|
|
56
|
+
const agentId = newAgentId(sub.name);
|
|
57
|
+
const address = joinAddress(parent.address, agentId);
|
|
58
|
+
// Meta record (as the Agent tool writes at spawn) so the shard is resumable by id.
|
|
59
|
+
if (parent.store !== undefined) {
|
|
60
|
+
await parent.store.appendRecord({
|
|
61
|
+
address,
|
|
62
|
+
type: "custom",
|
|
63
|
+
name: SUBAGENT_META,
|
|
64
|
+
data: {
|
|
65
|
+
agentId,
|
|
66
|
+
type: sub.name,
|
|
67
|
+
background: false,
|
|
68
|
+
parentAddress: parent.address,
|
|
69
|
+
parentToolCallId: ctx.toolCallId,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const result = await runFreshChild(sub, spawner, parent, {
|
|
74
|
+
address,
|
|
75
|
+
agentInstanceId: agentId,
|
|
76
|
+
prompt: args.input,
|
|
77
|
+
parentToolCallId: ctx.toolCallId,
|
|
78
|
+
});
|
|
79
|
+
settleChild(parent, result);
|
|
80
|
+
return subagentResult(sub.name, result.output, result.usage, result.status, agentId);
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build the `agent_<name>` tool's result from a finished child run. Unlike `spawnResult`
|
|
87
|
+
* (the unified `Agent` tool's registry row, which never sets `isError`), this is the ONLY
|
|
88
|
+
* result the parent model sees for this delegation — so an abnormal terminal status (the
|
|
89
|
+
* child errored or was aborted) must set `isError`, or the parent reads a failed/empty
|
|
90
|
+
* child run as a normal success.
|
|
91
|
+
*/
|
|
92
|
+
function subagentResult(name, output, usage, status, agentId) {
|
|
93
|
+
const isError = status === "error" || status === "aborted";
|
|
94
|
+
const text = status === "completed" ? output : [`status: ${status}`, "", output].join("\n");
|
|
95
|
+
return {
|
|
96
|
+
content: [{ type: "text", text }],
|
|
97
|
+
details: { agent: name, usage, status, ...(agentId !== undefined ? { agentId } : {}) },
|
|
98
|
+
...(isError ? { isError } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The unified `Agent` tool: spawn (or resume) a sub-agent BY TYPE, optionally in the
|
|
103
|
+
* background. Types come from the active agent's static `subagents` ∪ the runtime provider,
|
|
104
|
+
* surfaced through the `spawner`.
|
|
105
|
+
*/
|
|
106
|
+
export function buildAgentTool(spawner, parent) {
|
|
107
|
+
const defaultName = spawner.defaultType;
|
|
108
|
+
const backgroundAvailable = asTaskRegistrar(parent.background) !== undefined && parent.store !== undefined;
|
|
109
|
+
const backgroundNote = backgroundAvailable
|
|
110
|
+
? "When run_in_background=true, the subagent runs detached from this turn. A metadata-only completion notice arrives automatically; call BackgroundOutput(task_id) when you need the result. You do not need to poll or sleep. Continue with other work. Never fabricate or predict what the result will say."
|
|
111
|
+
: "Background execution requires both a BackgroundManager and a durable session store. Do not set run_in_background=true in this session.";
|
|
112
|
+
const description = [
|
|
113
|
+
"Launch a subagent to handle a task. The subagent runs as a same-session loop instance with its own context and journal shard.",
|
|
114
|
+
"",
|
|
115
|
+
"Writing the prompt:",
|
|
116
|
+
"- The subagent starts with zero context — it has not seen this conversation. Brief it like a colleague who just walked into the room: state the goal, list what you already know, hand over the specifics.",
|
|
117
|
+
"- Lookups (read this file, run that test): put the exact path or command in the prompt — the subagent should not have to search for what you already know.",
|
|
118
|
+
"- Investigations (figure out X, find why Y): give the question, not prescribed steps — fixed steps become dead weight when the premise is wrong.",
|
|
119
|
+
"- Do not delegate understanding: if the task hinges on a file path or line number, find it yourself first and write it into the prompt.",
|
|
120
|
+
"",
|
|
121
|
+
"Usage notes:",
|
|
122
|
+
"- Pass `name` when you will refer to this subagent later — resuming it, or naming it to a teammate. `name` becomes its agent id, so Agent(resume=\"dba\") beats resuming an opaque generated id. Names must be unique within this session.",
|
|
123
|
+
"- When the task continues earlier work a subagent already did, prefer resuming it (pass its agent_id via resume) over spawning a fresh instance — the resumed agent keeps its prior context. Requires a durable session store.",
|
|
124
|
+
"- A subagent's result is only visible to you, not the user. When the user needs to see what a subagent produced, summarize the relevant parts yourself.",
|
|
125
|
+
"- Subagents use a fixed 30-minute timeout. If one times out, resume the same agent instead of starting over.",
|
|
126
|
+
"- Skip delegation for trivial work you can do directly in a step or two — delegation has a context-handoff cost that only pays off on substantial tasks.",
|
|
127
|
+
"",
|
|
128
|
+
backgroundNote,
|
|
129
|
+
"",
|
|
130
|
+
"Available agent types (pass via subagent_type):",
|
|
131
|
+
...spawner.available.map((a) => `- ${a.name}${a.description ? `: ${a.description}` : ""}`),
|
|
132
|
+
].join("\n");
|
|
133
|
+
const input = z.preprocess((raw) => {
|
|
134
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
135
|
+
return raw;
|
|
136
|
+
const record = raw;
|
|
137
|
+
if (typeof record["subagent_type"] === "string" && record["subagent_type"].length > 0)
|
|
138
|
+
return raw;
|
|
139
|
+
if (typeof record["resume"] === "string" && record["resume"].trim().length > 0)
|
|
140
|
+
return raw;
|
|
141
|
+
return { ...record, subagent_type: defaultName };
|
|
142
|
+
}, z.object({
|
|
143
|
+
prompt: z.string().describe("Full task prompt for the subagent."),
|
|
144
|
+
description: z.string().describe("Short task description (3-5 words) for UI display."),
|
|
145
|
+
name: z
|
|
146
|
+
.string()
|
|
147
|
+
.optional()
|
|
148
|
+
.describe("Name this subagent, e.g. \"dba\". Becomes its agent id — what you pass to resume, and what teammates address it by. Letters, digits, _ and - only; must be unused in this session. Omit for a generated id."),
|
|
149
|
+
subagent_type: z.string().optional().describe("One of the available agent types. Defaults to coder when available, otherwise the first available subagent."),
|
|
150
|
+
resume: z.string().optional().describe("Agent ID (returned by a prior spawn) to continue that subagent with a new prompt."),
|
|
151
|
+
run_in_background: z.boolean().optional().describe("If true, return immediately without waiting for completion."),
|
|
152
|
+
}));
|
|
153
|
+
return defineTool({
|
|
154
|
+
name: "Agent",
|
|
155
|
+
description,
|
|
156
|
+
params: input,
|
|
157
|
+
resolve: (args) => {
|
|
158
|
+
const requested = args.subagent_type ?? defaultName;
|
|
159
|
+
return {
|
|
160
|
+
approvalRule: "Agent",
|
|
161
|
+
// The Agent call itself touches nothing directly — the spawned subagent runs its own
|
|
162
|
+
// tools, each declaring its own accesses and going through its own approval. Declare
|
|
163
|
+
// none() so delegation isn't gated as a mutator (the subagent enforces plan-mode /
|
|
164
|
+
// permissions on its side).
|
|
165
|
+
accesses: ToolAccesses.none(),
|
|
166
|
+
controlFlow: true,
|
|
167
|
+
display: {
|
|
168
|
+
title: args.run_in_background === true ? `Background sub-agent: ${requested}` : `Sub-agent: ${requested}`,
|
|
169
|
+
detail: args.description,
|
|
170
|
+
},
|
|
171
|
+
run: async (ctx) => {
|
|
172
|
+
const continuation = childContinuation(parent, ctx.toolCallId);
|
|
173
|
+
if (continuation) {
|
|
174
|
+
if (parent.store === undefined) {
|
|
175
|
+
return errResult("Agent interruption resume requires a durable session store; none is configured.");
|
|
176
|
+
}
|
|
177
|
+
const meta = await readSubagentMeta(parent.store, continuation.address);
|
|
178
|
+
if (!meta)
|
|
179
|
+
return errResult(`Cannot resume interrupted agent "${continuation.agentInstanceId}": subagent metadata is missing.`);
|
|
180
|
+
const root = await spawner.resolve(meta.type);
|
|
181
|
+
if (!root)
|
|
182
|
+
return errResult(`Cannot resume interrupted agent: type "${meta.type}" is not available here.`);
|
|
183
|
+
const deadline = createDeadline(parent.signal, AGENT_TIMEOUT_MS);
|
|
184
|
+
let result;
|
|
185
|
+
try {
|
|
186
|
+
result = await resumeInterruptedChild(root, continuation, spawner, parent, ctx.toolCallId, deadline.signal);
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
deadline.clear();
|
|
190
|
+
}
|
|
191
|
+
settleChild(parent, result, continuation.execution.usage);
|
|
192
|
+
if (deadline.timedOut())
|
|
193
|
+
return timeoutResult(root.name, continuation.agentInstanceId);
|
|
194
|
+
return spawnResult(root.name, continuation.agentInstanceId, "completed", result.output, result.usage, settleStatus(result.status));
|
|
195
|
+
}
|
|
196
|
+
const resumeId = args.resume?.trim();
|
|
197
|
+
if (resumeId !== undefined && resumeId.length > 0 && args.subagent_type !== undefined && args.subagent_type.length > 0) {
|
|
198
|
+
return errResult("Cannot set subagent_type when resuming an existing agent. Resume by agent id only.");
|
|
199
|
+
}
|
|
200
|
+
if (resumeId !== undefined && resumeId.length > 0 && args.name !== undefined && args.name.trim().length > 0) {
|
|
201
|
+
return errResult("Cannot set name when resuming an existing agent — it already has one. Resume by agent id only.");
|
|
202
|
+
}
|
|
203
|
+
// ── Resume an existing subagent by id: reload its shard and continue ──
|
|
204
|
+
if (resumeId !== undefined && resumeId.length > 0) {
|
|
205
|
+
if (parent.store === undefined) {
|
|
206
|
+
return errResult("Agent resume requires a durable session store; none is configured for this session.");
|
|
207
|
+
}
|
|
208
|
+
// Recover the subagent's type from the meta record in its OWN shard (written at
|
|
209
|
+
// spawn), so resume needs no registry/fold over the parent conversation. The shard
|
|
210
|
+
// address is the per-instance address, identical to how it was assigned at spawn.
|
|
211
|
+
const address = joinAddress(parent.address, resumeId);
|
|
212
|
+
const meta = await readSubagentMeta(parent.store, address);
|
|
213
|
+
if (meta === undefined) {
|
|
214
|
+
return errResult(`Unknown agent id "${resumeId}". Spawn a new subagent, or check the id returned by a prior spawn.`);
|
|
215
|
+
}
|
|
216
|
+
const sub = await spawner.resolve(meta.type);
|
|
217
|
+
if (sub === undefined) {
|
|
218
|
+
return errResult(`Cannot resume "${resumeId}": its agent type "${meta.type}" is not available here.`);
|
|
219
|
+
}
|
|
220
|
+
const deadline = createDeadline(parent.signal, AGENT_TIMEOUT_MS);
|
|
221
|
+
const childState = spawner.derive({ address, signal: deadline.signal, parentToolCallId: ctx.toolCallId, steer: new SteerBus() });
|
|
222
|
+
// Rebuild the subagent's context, validate the new prompt, then append it only
|
|
223
|
+
// after acceptance. A rejected prompt is audit-only in the child shard.
|
|
224
|
+
const childContext = await replayContext(parent.store, address);
|
|
225
|
+
const promptMessage = { role: "user", content: [{ type: "text", text: args.prompt }], timestamp: Date.now() };
|
|
226
|
+
await guardSubagentInput(sub, [promptMessage], childState, spawner);
|
|
227
|
+
childContext.appendMessage(promptMessage);
|
|
228
|
+
// Same contract as a fresh spawn: the resumed frame is live at its address, so its
|
|
229
|
+
// inbox must be reachable via `session.steerTo` for the duration of the run.
|
|
230
|
+
const unregisterBus = parent.session.registerFrameBus(childState.address, childState.steer);
|
|
231
|
+
let result;
|
|
232
|
+
try {
|
|
233
|
+
result = await spawner.run(sub, childContext, childState);
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
deadline.clear();
|
|
237
|
+
unregisterBus();
|
|
238
|
+
await childContext.flush();
|
|
239
|
+
}
|
|
240
|
+
settleChild(parent, result);
|
|
241
|
+
if (deadline.timedOut())
|
|
242
|
+
return timeoutResult(sub.name, resumeId);
|
|
243
|
+
return spawnResult(sub.name, resumeId, "resumed", result.output, result.usage, settleStatus(result.status));
|
|
244
|
+
}
|
|
245
|
+
// ── Fresh spawn: assign a per-instance id + shard, register, run ──
|
|
246
|
+
const sub = await spawner.resolve(requested);
|
|
247
|
+
if (sub === undefined) {
|
|
248
|
+
return errResult(`Unknown subagent_type "${requested}". Available: ${spawner.available.map((a) => a.name).join(", ")}`);
|
|
249
|
+
}
|
|
250
|
+
// A caller-chosen name IS the agent's id: it addresses the shard, resume looks it up,
|
|
251
|
+
// and peers message it by that name. So it has to be unique here — silently
|
|
252
|
+
// uniquifying it would hand the caller a name that reaches a different agent.
|
|
253
|
+
const chosenName = args.name?.trim();
|
|
254
|
+
if (chosenName !== undefined && chosenName.length > 0) {
|
|
255
|
+
const invalid = invalidAgentName(chosenName);
|
|
256
|
+
if (invalid !== undefined)
|
|
257
|
+
return errResult(invalid);
|
|
258
|
+
if (parent.store !== undefined && (await readSubagentMeta(parent.store, joinAddress(parent.address, chosenName))) !== undefined) {
|
|
259
|
+
return errResult(`Agent name "${chosenName}" is already taken in this session. Continue that agent with Agent(resume="${chosenName}", prompt=...), or choose a different name.`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const agentId = chosenName !== undefined && chosenName.length > 0 ? chosenName : newAgentId(sub.name);
|
|
263
|
+
const address = joinAddress(parent.address, agentId);
|
|
264
|
+
const background = args.run_in_background === true;
|
|
265
|
+
if (background && parent.store === undefined) {
|
|
266
|
+
return errResult("Background Agent execution requires a durable session store because the result lives in the subagent's conversation shard.");
|
|
267
|
+
}
|
|
268
|
+
// Record the subagent's identity in its OWN shard so resume can recover its type by
|
|
269
|
+
// id without folding the parent conversation.
|
|
270
|
+
// `custom` entries are audit-only — never replayed into history — so this stays out
|
|
271
|
+
// of the run's context. Foreground subagents get one too: they are plain tool calls,
|
|
272
|
+
// but their shard is still resumable by id.
|
|
273
|
+
if (parent.store !== undefined) {
|
|
274
|
+
await parent.store.appendRecord({
|
|
275
|
+
address,
|
|
276
|
+
type: "custom",
|
|
277
|
+
name: SUBAGENT_META,
|
|
278
|
+
data: {
|
|
279
|
+
agentId,
|
|
280
|
+
type: sub.name,
|
|
281
|
+
description: args.description,
|
|
282
|
+
background,
|
|
283
|
+
parentAddress: parent.address,
|
|
284
|
+
parentToolCallId: ctx.toolCallId,
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
const runSubagent = (signal) => runFreshChild(sub, spawner, parent, {
|
|
289
|
+
address,
|
|
290
|
+
agentInstanceId: agentId,
|
|
291
|
+
prompt: args.prompt,
|
|
292
|
+
parentToolCallId: ctx.toolCallId,
|
|
293
|
+
signal,
|
|
294
|
+
description: args.description,
|
|
295
|
+
});
|
|
296
|
+
if (background) {
|
|
297
|
+
const registrar = asTaskRegistrar(parent.background);
|
|
298
|
+
if (registrar === undefined) {
|
|
299
|
+
return errResult("Background agent execution is unavailable because no BackgroundManager is attached.");
|
|
300
|
+
}
|
|
301
|
+
const controller = new AbortController();
|
|
302
|
+
// `agentStatus` rides the task into the settle notification, whose journaled
|
|
303
|
+
// tag is the durable settle record the subagent fold reads.
|
|
304
|
+
// Only the status: the run's own answer is already the last message of its shard,
|
|
305
|
+
// which the task names as its output location rather than carrying a copy of.
|
|
306
|
+
const taskId = registrar.registerTask(new AgentBackgroundTask(() => runSubagent(controller.signal).then((result) => ({
|
|
307
|
+
agentStatus: settleStatus(result.status),
|
|
308
|
+
})), args.description, {
|
|
309
|
+
timeoutMs: AGENT_TIMEOUT_MS,
|
|
310
|
+
subagentType: sub.name,
|
|
311
|
+
agentId,
|
|
312
|
+
address,
|
|
313
|
+
parentAddress: parent.address,
|
|
314
|
+
toolCallId: ctx.toolCallId,
|
|
315
|
+
abort: () => controller.abort(),
|
|
316
|
+
}));
|
|
317
|
+
const status = registrar.getTask(taskId)?.status ?? "running";
|
|
318
|
+
return {
|
|
319
|
+
content: [
|
|
320
|
+
{
|
|
321
|
+
type: "text",
|
|
322
|
+
text: [
|
|
323
|
+
`task_id: ${taskId}`,
|
|
324
|
+
`agent_id: ${agentId}`,
|
|
325
|
+
`status: ${status}`,
|
|
326
|
+
`actual_subagent_type: ${sub.name}`,
|
|
327
|
+
"automatic_notification: true",
|
|
328
|
+
"",
|
|
329
|
+
`description: ${args.description}`,
|
|
330
|
+
"",
|
|
331
|
+
`next_step: The completion arrives automatically in a later turn. BackgroundOutput(task_id="${taskId}", block=false) to peek; resume later with Agent(resume="${agentId}", prompt=...).`,
|
|
332
|
+
].join("\n"),
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
// The spawn ack IS the registry row: the fold opens the record from these details.
|
|
336
|
+
details: {
|
|
337
|
+
agent: sub.name,
|
|
338
|
+
agentId,
|
|
339
|
+
type: sub.name,
|
|
340
|
+
status: "running",
|
|
341
|
+
background: true,
|
|
342
|
+
taskId,
|
|
343
|
+
description: args.description,
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const detachSignal = ctx.detachSignal;
|
|
348
|
+
const fgRegistrar = detachSignal !== undefined && parent.store !== undefined ? asTaskRegistrar(parent.background) : undefined;
|
|
349
|
+
// Non-detachable foreground (no detach trigger or no manager): run inline as before.
|
|
350
|
+
if (detachSignal === undefined || fgRegistrar === undefined) {
|
|
351
|
+
const deadline = createDeadline(parent.signal, AGENT_TIMEOUT_MS);
|
|
352
|
+
let result;
|
|
353
|
+
try {
|
|
354
|
+
result = await runSubagent(deadline.signal);
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
deadline.clear();
|
|
358
|
+
}
|
|
359
|
+
settleChild(parent, result);
|
|
360
|
+
if (deadline.timedOut())
|
|
361
|
+
return timeoutResult(sub.name, agentId);
|
|
362
|
+
return spawnResult(sub.name, agentId, "completed", result.output, result.usage, settleStatus(result.status), args.description);
|
|
363
|
+
}
|
|
364
|
+
// Detachable foreground: run on our OWN controller (bridged from parent.signal + the
|
|
365
|
+
// agent timeout) so `ctx.detachSignal` can peel the still-running subagent into a
|
|
366
|
+
// background task without the turn's abort killing it. The completion promise carries
|
|
367
|
+
// the whole result, so a promise-based task adopts it cleanly — no stream handoff.
|
|
368
|
+
ctx.onUpdate?.({ kind: "custom", customKind: "detachable" }); // UI: offer "move to background"
|
|
369
|
+
const controller = new AbortController();
|
|
370
|
+
const bridge = () => controller.abort();
|
|
371
|
+
let timedOut = false;
|
|
372
|
+
if (parent.signal.aborted)
|
|
373
|
+
controller.abort();
|
|
374
|
+
else
|
|
375
|
+
parent.signal.addEventListener("abort", bridge, { once: true });
|
|
376
|
+
const deadlineTimer = setTimeout(() => {
|
|
377
|
+
timedOut = true;
|
|
378
|
+
controller.abort();
|
|
379
|
+
}, AGENT_TIMEOUT_MS);
|
|
380
|
+
const runPromise = runSubagent(controller.signal);
|
|
381
|
+
const detachP = new Promise((resolve) => {
|
|
382
|
+
const onDetach = () => resolve("detach");
|
|
383
|
+
if (detachSignal.aborted)
|
|
384
|
+
onDetach();
|
|
385
|
+
else
|
|
386
|
+
detachSignal.addEventListener("abort", onDetach, { once: true });
|
|
387
|
+
});
|
|
388
|
+
const winner = await Promise.race([runPromise.then(() => "done", () => "done"), detachP]);
|
|
389
|
+
if (winner === "detach") {
|
|
390
|
+
parent.signal.removeEventListener("abort", bridge); // drop the kill bridge: turn-end must not kill it
|
|
391
|
+
clearTimeout(deadlineTimer);
|
|
392
|
+
const completion = runPromise.then((result) => ({
|
|
393
|
+
agentStatus: settleStatus(result.status),
|
|
394
|
+
}));
|
|
395
|
+
const taskId = fgRegistrar.registerTask(new AgentBackgroundTask(() => completion, args.description, {
|
|
396
|
+
subagentType: sub.name,
|
|
397
|
+
agentId,
|
|
398
|
+
address,
|
|
399
|
+
parentAddress: parent.address,
|
|
400
|
+
toolCallId: ctx.toolCallId,
|
|
401
|
+
abort: () => controller.abort(),
|
|
402
|
+
}));
|
|
403
|
+
ctx.onUpdate?.({ kind: "custom", customKind: "detached", customData: { taskId } });
|
|
404
|
+
const status = fgRegistrar.getTask(taskId)?.status ?? "running";
|
|
405
|
+
return {
|
|
406
|
+
content: [
|
|
407
|
+
{
|
|
408
|
+
type: "text",
|
|
409
|
+
text: [
|
|
410
|
+
`Moved to background task ${taskId}.`,
|
|
411
|
+
`agent_id: ${agentId}`,
|
|
412
|
+
`status: ${status}`,
|
|
413
|
+
`actual_subagent_type: ${sub.name}`,
|
|
414
|
+
"automatic_notification: true",
|
|
415
|
+
"",
|
|
416
|
+
`description: ${args.description}`,
|
|
417
|
+
"",
|
|
418
|
+
`next_step: The completion arrives automatically in a later turn. BackgroundOutput(task_id="${taskId}", block=false) to peek; resume later with Agent(resume="${agentId}", prompt=...).`,
|
|
419
|
+
].join("\n"),
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
details: {
|
|
423
|
+
agent: sub.name,
|
|
424
|
+
agentId,
|
|
425
|
+
type: sub.name,
|
|
426
|
+
status: "running",
|
|
427
|
+
background: true,
|
|
428
|
+
movedToBackground: true,
|
|
429
|
+
taskId,
|
|
430
|
+
description: args.description,
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
parent.signal.removeEventListener("abort", bridge);
|
|
435
|
+
clearTimeout(deadlineTimer);
|
|
436
|
+
const result = await runPromise;
|
|
437
|
+
settleChild(parent, result);
|
|
438
|
+
if (timedOut)
|
|
439
|
+
return timeoutResult(sub.name, agentId);
|
|
440
|
+
return spawnResult(sub.name, agentId, "completed", result.output, result.usage, settleStatus(result.status), args.description);
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
},
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
// ── Shared child-run flow ────────────────────────────────────────────────────────────────
|
|
447
|
+
/**
|
|
448
|
+
* Run a FRESH child to completion in its own journal shard: fork the frame, guard the
|
|
449
|
+
* prompt, seed a new context, run, and always flush. The one spawn flow shared by the
|
|
450
|
+
* static `agent_<name>` tool and the unified `Agent` tool's foreground and background
|
|
451
|
+
* spawn paths (resume paths differ — they replay an existing shard instead of seeding).
|
|
452
|
+
*/
|
|
453
|
+
async function runFreshChild(sub, spawner, parent, opts) {
|
|
454
|
+
// Root-frame fan-out queues behind a session-wide limiter; a nested spawn does not (holding a
|
|
455
|
+
// permit while waiting for a child that needs one is a deadlock). See `spawnLimiterFor`.
|
|
456
|
+
const limiter = spawnLimiterFor(parent, parent.maxConcurrentSubagents);
|
|
457
|
+
return limiter === undefined ? runFreshChildInner(sub, spawner, parent, opts) : limiter.run(() => runFreshChildInner(sub, spawner, parent, opts));
|
|
458
|
+
}
|
|
459
|
+
async function runFreshChildInner(sub, spawner, parent, opts) {
|
|
460
|
+
// Its OWN SteerBus. Without this the child inherits the parent's (`deriveChild` spreads
|
|
461
|
+
// `steer`) and the two frames drain one queue: a message aimed at the child could be consumed
|
|
462
|
+
// by the parent, and — today, before any peer messaging exists — a user steer typed at the main
|
|
463
|
+
// session gets eaten by whichever subagent happens to be running. Separate queues are what make
|
|
464
|
+
// addressing a subagent meaningful at all.
|
|
465
|
+
const childState = spawner.derive({
|
|
466
|
+
address: opts.address,
|
|
467
|
+
parentToolCallId: opts.parentToolCallId,
|
|
468
|
+
agentInstanceId: opts.agentInstanceId,
|
|
469
|
+
steer: new SteerBus(),
|
|
470
|
+
...(opts.signal ? { signal: opts.signal } : {}),
|
|
471
|
+
});
|
|
472
|
+
const childMessages = [
|
|
473
|
+
{ role: "user", content: [{ type: "text", text: opts.prompt }], timestamp: Date.now() },
|
|
474
|
+
];
|
|
475
|
+
await guardSubagentInput(sub, childMessages, childState, spawner);
|
|
476
|
+
// The sub-agent journals to its own shard (`main/<child>`), isolated for replay.
|
|
477
|
+
const childContext = new ConversationContext({
|
|
478
|
+
store: childState.store,
|
|
479
|
+
address: childState.address,
|
|
480
|
+
...(childState.store === undefined
|
|
481
|
+
? { onHistoryChange: historyChangeEmitter(childState.events, childState.sessionId) }
|
|
482
|
+
: {}),
|
|
483
|
+
});
|
|
484
|
+
childContext.seed(childMessages);
|
|
485
|
+
// Publish this frame's inbox for the duration of the run, so an external coordinator can reach
|
|
486
|
+
// it by address (`session.steerTo`). Unregistered on the way out — a finished frame must not
|
|
487
|
+
// keep receiving.
|
|
488
|
+
const unregisterBus = parent.session.registerFrameBus(childState.address, childState.steer);
|
|
489
|
+
try {
|
|
490
|
+
return await spawner.run(sub, childContext, childState);
|
|
491
|
+
}
|
|
492
|
+
finally {
|
|
493
|
+
unregisterBus();
|
|
494
|
+
await childContext.flush();
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Fold a settled FOREGROUND child run into the parent frame: account its usage (minus
|
|
499
|
+
* `priorUsage` when resuming a continuation whose earlier turns were already accounted)
|
|
500
|
+
* and re-throw an interruption as the structured tool-suspension signal. Background
|
|
501
|
+
* children never come through here — their usage stays in their own ledger.
|
|
502
|
+
*/
|
|
503
|
+
function settleChild(parent, result, priorUsage) {
|
|
504
|
+
parent.usage = addUsage(parent.usage, priorUsage !== undefined ? subtractUsage(result.usage, priorUsage) : result.usage);
|
|
505
|
+
bubbleInterruption(result);
|
|
506
|
+
}
|
|
507
|
+
// ── Foreground interruption continuation ─────────────────────────────────────────────────
|
|
508
|
+
function childContinuation(parent, parentToolCallId) {
|
|
509
|
+
const interruption = parent.interruption;
|
|
510
|
+
if (!interruption)
|
|
511
|
+
return undefined;
|
|
512
|
+
const parentFrame = interruption.frames[parent.frameId];
|
|
513
|
+
const childFrameId = parentFrame?.children[parentToolCallId];
|
|
514
|
+
return childFrameId ? interruption.frames[childFrameId] : undefined;
|
|
515
|
+
}
|
|
516
|
+
async function resumeInterruptedChild(root, frame, spawner, parent, parentToolCallId, signal) {
|
|
517
|
+
if (!parent.store)
|
|
518
|
+
throw new Error("Cannot resume an interrupted sub-agent without a durable session store.");
|
|
519
|
+
const active = spawner.resolveInGraph(root, frame.agent.key);
|
|
520
|
+
if (!active)
|
|
521
|
+
throw new Error(`Cannot resume sub-agent: active agent "${frame.agent.key}" is unavailable.`);
|
|
522
|
+
const childState = spawner.derive({
|
|
523
|
+
address: frame.address,
|
|
524
|
+
parentToolCallId,
|
|
525
|
+
signal,
|
|
526
|
+
resumeFrame: frame,
|
|
527
|
+
steer: new SteerBus(),
|
|
528
|
+
});
|
|
529
|
+
const childContext = await replayContext(parent.store, frame.address);
|
|
530
|
+
childState.session.setLiveContext(frame.address, childContext);
|
|
531
|
+
const resumeFrom = findAnchoredAssistant(childContext.messages, frame.anchor);
|
|
532
|
+
// Same contract as a fresh spawn: the resumed frame must be steerable at its address.
|
|
533
|
+
const unregisterBus = parent.session.registerFrameBus(frame.address, childState.steer);
|
|
534
|
+
try {
|
|
535
|
+
return await spawner.run(active, childContext, childState, resumeFrom);
|
|
536
|
+
}
|
|
537
|
+
finally {
|
|
538
|
+
unregisterBus();
|
|
539
|
+
await childContext.flush();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function bubbleInterruption(result) {
|
|
543
|
+
if (result.status !== "interrupted")
|
|
544
|
+
return;
|
|
545
|
+
const interruption = getInterruptionState(result);
|
|
546
|
+
if (!interruption)
|
|
547
|
+
throw new Error("Interrupted sub-agent did not provide structured continuation state.");
|
|
548
|
+
throw new ToolInterruptionSignal(interruption);
|
|
549
|
+
}
|
|
550
|
+
export async function guardSubagentInput(agent, input, state, spawner) {
|
|
551
|
+
try {
|
|
552
|
+
await runInputGuardrails(agent.guardrails.input ?? [], {
|
|
553
|
+
agent,
|
|
554
|
+
input,
|
|
555
|
+
context: spawner.ctxFor(state),
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
catch (error) {
|
|
559
|
+
if (!isGuardrailTripwireError(error))
|
|
560
|
+
throw error;
|
|
561
|
+
const blocked = {
|
|
562
|
+
type: "guardrail.blocked",
|
|
563
|
+
stage: error.stage,
|
|
564
|
+
guardrail: error.guardrailName,
|
|
565
|
+
agent: error.agentName ?? agent.name,
|
|
566
|
+
message: error.message,
|
|
567
|
+
};
|
|
568
|
+
if (state.store) {
|
|
569
|
+
await state.store.appendRecord({
|
|
570
|
+
...blocked,
|
|
571
|
+
address: state.address,
|
|
572
|
+
input: [...input],
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
await state.events.emit({
|
|
577
|
+
...blocked,
|
|
578
|
+
address: state.address,
|
|
579
|
+
sessionId: state.sessionId,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
throw error;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// ── Deadline + result helpers ────────────────────────────────────────────────────────────
|
|
586
|
+
/** 30 minutes — the fixed foreground + background subagent deadline. */
|
|
587
|
+
const AGENT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
588
|
+
/** A child abort signal that fires when `parent` aborts OR after `ms` elapses. `timedOut()`
|
|
589
|
+
* distinguishes the deadline from a parent/user abort so the caller reports the right cause. */
|
|
590
|
+
function createDeadline(parent, ms) {
|
|
591
|
+
const controller = new AbortController();
|
|
592
|
+
let timedOut = false;
|
|
593
|
+
const onParentAbort = () => controller.abort(parent.reason);
|
|
594
|
+
if (parent.aborted) {
|
|
595
|
+
controller.abort(parent.reason);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
parent.addEventListener("abort", onParentAbort, { once: true });
|
|
599
|
+
}
|
|
600
|
+
const timer = setTimeout(() => {
|
|
601
|
+
timedOut = true;
|
|
602
|
+
controller.abort(new Error("Agent deadline exceeded"));
|
|
603
|
+
}, ms);
|
|
604
|
+
// Don't let the pending timer keep the process alive.
|
|
605
|
+
timer.unref?.();
|
|
606
|
+
return {
|
|
607
|
+
signal: controller.signal,
|
|
608
|
+
timedOut: () => timedOut,
|
|
609
|
+
clear: () => {
|
|
610
|
+
clearTimeout(timer);
|
|
611
|
+
parent.removeEventListener("abort", onParentAbort);
|
|
612
|
+
},
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function timeoutResult(name, agentId) {
|
|
616
|
+
return {
|
|
617
|
+
content: [
|
|
618
|
+
{
|
|
619
|
+
type: "text",
|
|
620
|
+
text: [
|
|
621
|
+
`agent_id: ${agentId}`,
|
|
622
|
+
`actual_subagent_type: ${name}`,
|
|
623
|
+
"status: failed",
|
|
624
|
+
"",
|
|
625
|
+
"subagent error: Agent timed out after 30 minutes.",
|
|
626
|
+
`resume_hint: Continue with Agent(resume="${agentId}", prompt="continue"). Use agent_id only; do not set subagent_type. The subagent retains its prior context; redo any unfinished tool call if its result was lost.`,
|
|
627
|
+
].join("\n"),
|
|
628
|
+
},
|
|
629
|
+
],
|
|
630
|
+
isError: true,
|
|
631
|
+
details: { agent: name, agentId, type: name, status: "error" },
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function settleStatus(status) {
|
|
635
|
+
// "skipped" folds into "completed": a capability answered instead of the model, but from the
|
|
636
|
+
// parent's point of view the child finished and produced output.
|
|
637
|
+
return status === "interrupted" ? "paused" : status === "aborted" ? "cancelled" : status === "error" ? "error" : "completed";
|
|
638
|
+
}
|
|
639
|
+
function errResult(text) {
|
|
640
|
+
return { content: [{ type: "text", text }], isError: true };
|
|
641
|
+
}
|
|
642
|
+
function spawnResult(name, agentId, verb, output, usage, status, description) {
|
|
643
|
+
return {
|
|
644
|
+
content: [{ type: "text", text: [`agent_id: ${agentId}`, `actual_subagent_type: ${name}`, `status: ${verb}`, "", "[summary]", output].join("\n") }],
|
|
645
|
+
// These details are the spawn/settle record the subagent fold reads — the tool result
|
|
646
|
+
// is the registry row, not an input to some separate ledger.
|
|
647
|
+
details: { agent: name, agentId, usage, type: name, status, background: false, description },
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
//# sourceMappingURL=subagent-tools.js.map
|