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,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the Workflow tool — a deterministic JS orchestration runtime
|
|
3
|
+
* built on this framework's subagent runner.
|
|
4
|
+
*
|
|
5
|
+
* The runtime (`runtime.ts`) is framework-agnostic: it speaks only to the host
|
|
6
|
+
* through `WorkflowHostHooks`. The host (`Runner.buildWorkflowTool`) implements
|
|
7
|
+
* those hooks against `runLoop` / `ConversationContext`, so token usage and
|
|
8
|
+
* structured output are backed by real accounting rather than stubs.
|
|
9
|
+
*/
|
|
10
|
+
export interface WorkflowPhaseMeta {
|
|
11
|
+
title: string;
|
|
12
|
+
detail?: string;
|
|
13
|
+
model?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkflowMeta {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
whenToUse?: string;
|
|
20
|
+
phases?: WorkflowPhaseMeta[];
|
|
21
|
+
}
|
|
22
|
+
export interface ParsedWorkflow {
|
|
23
|
+
meta: WorkflowMeta;
|
|
24
|
+
/** Everything after the `export const meta = {...}` statement. */
|
|
25
|
+
scriptBody: string;
|
|
26
|
+
}
|
|
27
|
+
/** Options accepted by the in-script `agent(prompt, opts)` hook. */
|
|
28
|
+
export interface AgentHookOptions {
|
|
29
|
+
label?: string;
|
|
30
|
+
phase?: string;
|
|
31
|
+
/** JSON Schema — when present, the subagent must return a matching object. */
|
|
32
|
+
schema?: Record<string, unknown>;
|
|
33
|
+
model?: string;
|
|
34
|
+
/** Subagent type to spawn (resolved against the parent's available agents). */
|
|
35
|
+
agentType?: string;
|
|
36
|
+
/** When 'worktree', request isolation (best-effort; see host). */
|
|
37
|
+
isolation?: string;
|
|
38
|
+
}
|
|
39
|
+
/** One agent execution as the host runs it. */
|
|
40
|
+
export interface WorkflowAgentRunArgs {
|
|
41
|
+
readonly index: number;
|
|
42
|
+
readonly prompt: string;
|
|
43
|
+
readonly label: string;
|
|
44
|
+
readonly phase?: string;
|
|
45
|
+
readonly model?: string;
|
|
46
|
+
readonly agentType?: string;
|
|
47
|
+
readonly isolation?: string;
|
|
48
|
+
/** When set, the host must force + validate structured output against this schema. */
|
|
49
|
+
readonly schema?: Record<string, unknown>;
|
|
50
|
+
readonly signal: AbortSignal;
|
|
51
|
+
/**
|
|
52
|
+
* Called once the host has assigned the subagent its identity, BEFORE running it — lets
|
|
53
|
+
* the runtime journal a `started` marker and correlate orchestration progress with the
|
|
54
|
+
* child's full Session AgentEvent stream.
|
|
55
|
+
*/
|
|
56
|
+
readonly onStart: (identity: WorkflowAgentIdentity) => void;
|
|
57
|
+
}
|
|
58
|
+
export interface WorkflowAgentIdentity {
|
|
59
|
+
readonly agentId: string;
|
|
60
|
+
readonly address: string;
|
|
61
|
+
}
|
|
62
|
+
export interface WorkflowAgentRunResult extends WorkflowAgentIdentity {
|
|
63
|
+
/** The subagent's answer: a parsed object when `schema` was set, else the text. */
|
|
64
|
+
readonly value: unknown;
|
|
65
|
+
/** Output tokens spent by this agent across all internal attempts. */
|
|
66
|
+
readonly outputTokens: number;
|
|
67
|
+
}
|
|
68
|
+
/** Progress event emitted by the runtime back to the host (for display). */
|
|
69
|
+
import type { WorkflowProgressEvent } from "../../events/index.ts";
|
|
70
|
+
export type { WorkflowProgressEvent, WorkflowAgentRecord } from "../../events/index.ts";
|
|
71
|
+
/** Token budget directive for the turn. `total: null` = unbounded. */
|
|
72
|
+
export interface WorkflowBudget {
|
|
73
|
+
total: number | null;
|
|
74
|
+
/** Output tokens already spent this turn OUTSIDE the workflow (its baseline). */
|
|
75
|
+
getTurnSpent: () => number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Host callbacks the runtime uses to talk back to the tool layer. Keeps the
|
|
79
|
+
* sandbox runtime decoupled from the runner / subagent machinery.
|
|
80
|
+
*/
|
|
81
|
+
export interface WorkflowHostHooks {
|
|
82
|
+
/** Run one subagent to completion. Resolves with its value + output-token spend. */
|
|
83
|
+
runAgent: (args: WorkflowAgentRunArgs) => Promise<WorkflowAgentRunResult>;
|
|
84
|
+
/** Emit a progress event (phase started / agent state change / log line). */
|
|
85
|
+
emitProgress: (event: WorkflowProgressEvent) => void;
|
|
86
|
+
/** Resolve a named/saved workflow's script for the `workflow()` hook. */
|
|
87
|
+
resolveWorkflowScript?: (name: string) => Promise<string | null>;
|
|
88
|
+
/** Max number of concurrent agents. */
|
|
89
|
+
concurrency: number;
|
|
90
|
+
budget: WorkflowBudget;
|
|
91
|
+
abortSignal: AbortSignal;
|
|
92
|
+
}
|
|
93
|
+
export declare const WORKFLOW_SCRIPT_MAX_BYTES = 524288;
|
|
94
|
+
export declare const WORKFLOW_VM_TIMEOUT_MS = 30000;
|
|
95
|
+
export declare const WORKFLOW_AGENT_CAP = 1000;
|
|
96
|
+
/** Max items a single parallel()/pipeline() call accepts. */
|
|
97
|
+
export declare const WORKFLOW_MAX_ITEMS_PER_CALL = 4096;
|
|
98
|
+
/** Absolute per-agent timeout — a hung subagent is aborted after this. */
|
|
99
|
+
export declare const WORKFLOW_AGENT_TIMEOUT_MS: number;
|
|
100
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the Workflow tool — a deterministic JS orchestration runtime
|
|
3
|
+
* built on this framework's subagent runner.
|
|
4
|
+
*
|
|
5
|
+
* The runtime (`runtime.ts`) is framework-agnostic: it speaks only to the host
|
|
6
|
+
* through `WorkflowHostHooks`. The host (`Runner.buildWorkflowTool`) implements
|
|
7
|
+
* those hooks against `runLoop` / `ConversationContext`, so token usage and
|
|
8
|
+
* structured output are backed by real accounting rather than stubs.
|
|
9
|
+
*/
|
|
10
|
+
export const WORKFLOW_SCRIPT_MAX_BYTES = 524_288;
|
|
11
|
+
export const WORKFLOW_VM_TIMEOUT_MS = 30_000;
|
|
12
|
+
export const WORKFLOW_AGENT_CAP = 1000;
|
|
13
|
+
/** Max items a single parallel()/pipeline() call accepts. */
|
|
14
|
+
export const WORKFLOW_MAX_ITEMS_PER_CALL = 4096;
|
|
15
|
+
/** Absolute per-agent timeout — a hung subagent is aborted after this. */
|
|
16
|
+
export const WORKFLOW_AGENT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Machine } from "../tool/machine.ts";
|
|
2
|
+
/**
|
|
3
|
+
* An isolated working copy handed to a subagent that mutates files, so parallel
|
|
4
|
+
* agents don't clobber each other. `machine` is scoped to the copy (its getcwd()
|
|
5
|
+
* is `cwd`); `cleanup` tears it down (the worktree is removed only if the agent
|
|
6
|
+
* left no changes — a dirty copy is kept for inspection).
|
|
7
|
+
*/
|
|
8
|
+
export interface WorktreeHandle {
|
|
9
|
+
readonly machine: Machine;
|
|
10
|
+
readonly cwd: string;
|
|
11
|
+
cleanup(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Where isolated worktrees are created, relative to the repository root.
|
|
15
|
+
*
|
|
16
|
+
* Inside the repo on purpose: a worktree has to live on the same filesystem as
|
|
17
|
+
* the repo it forks, and keeping it adjacent means a dirty one left for
|
|
18
|
+
* inspection is found where the work was. Consumers should gitignore it — an
|
|
19
|
+
* abandoned worktree is a checkout, so it shows up as untracked otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export declare const WORKTREES_DIR = ".operon/worktrees";
|
|
22
|
+
/**
|
|
23
|
+
* Create an isolated git worktree for a subagent and return a machine scoped to it.
|
|
24
|
+
*
|
|
25
|
+
* This is workflow/orchestration policy built entirely on a machine's existing
|
|
26
|
+
* capabilities — git runs through `machine.exec`, and the scoped machine comes from
|
|
27
|
+
* `machine.withCwd`. It is therefore backend-agnostic: any machine whose target host
|
|
28
|
+
* has git (local, ssh, sandbox) can isolate. Whether isolation happens is decided at
|
|
29
|
+
* runtime by git itself — a host without git, or a cwd that isn't a repo, makes the
|
|
30
|
+
* git command fail and we return `null`, and the caller degrades to the shared
|
|
31
|
+
* workspace (surfacing that isolation was unavailable rather than failing silently).
|
|
32
|
+
* Cleanup removes the worktree only if the agent left it clean; a dirty worktree is
|
|
33
|
+
* kept for inspection.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createWorktree(machine: Machine, options?: {
|
|
36
|
+
label?: string;
|
|
37
|
+
}): Promise<WorktreeHandle | null>;
|
|
38
|
+
//# sourceMappingURL=worktree.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Where isolated worktrees are created, relative to the repository root.
|
|
4
|
+
*
|
|
5
|
+
* Inside the repo on purpose: a worktree has to live on the same filesystem as
|
|
6
|
+
* the repo it forks, and keeping it adjacent means a dirty one left for
|
|
7
|
+
* inspection is found where the work was. Consumers should gitignore it — an
|
|
8
|
+
* abandoned worktree is a checkout, so it shows up as untracked otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export const WORKTREES_DIR = ".operon/worktrees";
|
|
11
|
+
/**
|
|
12
|
+
* Create an isolated git worktree for a subagent and return a machine scoped to it.
|
|
13
|
+
*
|
|
14
|
+
* This is workflow/orchestration policy built entirely on a machine's existing
|
|
15
|
+
* capabilities — git runs through `machine.exec`, and the scoped machine comes from
|
|
16
|
+
* `machine.withCwd`. It is therefore backend-agnostic: any machine whose target host
|
|
17
|
+
* has git (local, ssh, sandbox) can isolate. Whether isolation happens is decided at
|
|
18
|
+
* runtime by git itself — a host without git, or a cwd that isn't a repo, makes the
|
|
19
|
+
* git command fail and we return `null`, and the caller degrades to the shared
|
|
20
|
+
* workspace (surfacing that isolation was unavailable rather than failing silently).
|
|
21
|
+
* Cleanup removes the worktree only if the agent left it clean; a dirty worktree is
|
|
22
|
+
* kept for inspection.
|
|
23
|
+
*/
|
|
24
|
+
export async function createWorktree(machine, options) {
|
|
25
|
+
const root = (await runGit(machine, ["-C", machine.getcwd(), "rev-parse", "--show-toplevel"])).ok?.trim();
|
|
26
|
+
if (!root)
|
|
27
|
+
return null; // no git, or cwd isn't a repo → no isolation available
|
|
28
|
+
const id = randomBytes(4).toString("hex");
|
|
29
|
+
const safeLabel = (options?.label ?? "wt").replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "wt";
|
|
30
|
+
const branch = `wf/${safeLabel}-${id}`;
|
|
31
|
+
// git uses forward slashes on every platform (incl. Windows); normpath fixes display.
|
|
32
|
+
// `.operon/` — the project's name. It was `.agent-framework/`, which this repo
|
|
33
|
+
// has not been called for some time; the directory is created inside the user's
|
|
34
|
+
// own repository, so the stale name was visible to every one of them.
|
|
35
|
+
const wtPath = machine.normpath(`${root}/${WORKTREES_DIR}/${safeLabel}-${id}`);
|
|
36
|
+
const added = await runGit(machine, ["-C", root, "worktree", "add", "--quiet", "-b", branch, wtPath, "HEAD"]);
|
|
37
|
+
if (added.ok === undefined)
|
|
38
|
+
return null; // creation failed → caller degrades to shared workspace
|
|
39
|
+
const cleanup = async () => {
|
|
40
|
+
const status = await runGit(machine, ["-C", wtPath, "status", "--porcelain"]);
|
|
41
|
+
if (status.ok !== undefined && status.ok.trim() === "") {
|
|
42
|
+
await runGit(machine, ["-C", root, "worktree", "remove", "--force", wtPath]);
|
|
43
|
+
await runGit(machine, ["-C", root, "branch", "-D", branch]);
|
|
44
|
+
}
|
|
45
|
+
// else: leave the dirty/locked worktree in place for inspection. Errors are
|
|
46
|
+
// swallowed by runGit; cleanup is best-effort and never throws into the run.
|
|
47
|
+
};
|
|
48
|
+
return { machine: machine.withCwd(wtPath), cwd: wtPath, cleanup };
|
|
49
|
+
}
|
|
50
|
+
/** Run `git <args>` on the machine's host; `ok` is stdout on exit 0, undefined otherwise. */
|
|
51
|
+
async function runGit(machine, args) {
|
|
52
|
+
// `.catch` covers git-not-found / the backend refusing to spawn at all.
|
|
53
|
+
const result = await machine.run(["git", ...args]).catch(() => undefined);
|
|
54
|
+
return result?.exitCode === 0 ? { ok: result.stdout } : {};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=worktree.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BeforeRunHook, LoopHooks, ShouldContinueAfterStopHook } from "../loop/types.ts";
|
|
2
|
+
import type { Tool } from "../tool/types.ts";
|
|
3
|
+
import type { AssembledGates, Capability, CapabilityContext, CapabilityDiagnostic } from "./capability.ts";
|
|
4
|
+
import { InjectionManager } from "./injection.ts";
|
|
5
|
+
export interface AssembleCapabilitiesOptions {
|
|
6
|
+
/** Max time to wait for a single capability's start(). Default 10s. */
|
|
7
|
+
readonly startTimeoutMs?: number;
|
|
8
|
+
/** Max time to wait for a single capability's stop(). Default 5s. */
|
|
9
|
+
readonly stopTimeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class AssembledCapabilities {
|
|
12
|
+
readonly diagnostics: CapabilityDiagnostic[];
|
|
13
|
+
readonly loopHookParts: Array<Partial<LoopHooks>>;
|
|
14
|
+
readonly boundaryContinuations: ShouldContinueAfterStopHook[];
|
|
15
|
+
readonly runStarts: BeforeRunHook[];
|
|
16
|
+
/**
|
|
17
|
+
* Stable arrays handed to `CapabilityContext.gates`. Capabilities are started and absorbed one
|
|
18
|
+
* at a time, so a consumer that snapshotted at `start()` would miss every gate registered by a
|
|
19
|
+
* capability ordered after it — reading through this live reference avoids depending on order.
|
|
20
|
+
*/
|
|
21
|
+
readonly gates: AssembledGates;
|
|
22
|
+
readonly injection: InjectionManager;
|
|
23
|
+
private readonly staticTools;
|
|
24
|
+
private readonly toolProviders;
|
|
25
|
+
private readonly toolFilters;
|
|
26
|
+
private readonly started;
|
|
27
|
+
private readonly ctx;
|
|
28
|
+
private readonly stopTimeoutMs;
|
|
29
|
+
constructor(ctx: CapabilityContext, options?: AssembleCapabilitiesOptions);
|
|
30
|
+
listTools(): Promise<Tool[]>;
|
|
31
|
+
/** Apply every capability's tool filter in registration order. A thrower is skipped. */
|
|
32
|
+
applyToolFilters(tools: readonly Tool[]): readonly Tool[];
|
|
33
|
+
private absorb;
|
|
34
|
+
markStarted(capability: Capability): void;
|
|
35
|
+
stop(): Promise<void>;
|
|
36
|
+
_absorb(capability: Capability): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function assembleCapabilities(capabilities: readonly Capability[], ctx: CapabilityContext, options?: AssembleCapabilitiesOptions): Promise<AssembledCapabilities>;
|
|
39
|
+
//# sourceMappingURL=assembler.d.ts.map
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { InjectionManager } from "./injection.js";
|
|
2
|
+
const STOP_TIMEOUT_MS = 5_000;
|
|
3
|
+
const START_TIMEOUT_MS = 10_000;
|
|
4
|
+
export class AssembledCapabilities {
|
|
5
|
+
diagnostics = [];
|
|
6
|
+
loopHookParts = [];
|
|
7
|
+
boundaryContinuations = [];
|
|
8
|
+
runStarts = [];
|
|
9
|
+
/**
|
|
10
|
+
* Stable arrays handed to `CapabilityContext.gates`. Capabilities are started and absorbed one
|
|
11
|
+
* at a time, so a consumer that snapshotted at `start()` would miss every gate registered by a
|
|
12
|
+
* capability ordered after it — reading through this live reference avoids depending on order.
|
|
13
|
+
*/
|
|
14
|
+
gates = { compaction: [] };
|
|
15
|
+
injection = new InjectionManager();
|
|
16
|
+
staticTools = [];
|
|
17
|
+
toolProviders = [];
|
|
18
|
+
toolFilters = [];
|
|
19
|
+
started = [];
|
|
20
|
+
ctx;
|
|
21
|
+
stopTimeoutMs;
|
|
22
|
+
constructor(ctx, options = {}) {
|
|
23
|
+
this.ctx = ctx;
|
|
24
|
+
this.stopTimeoutMs = options.stopTimeoutMs ?? STOP_TIMEOUT_MS;
|
|
25
|
+
}
|
|
26
|
+
async listTools() {
|
|
27
|
+
const tools = [...this.staticTools];
|
|
28
|
+
for (const provider of this.toolProviders) {
|
|
29
|
+
try {
|
|
30
|
+
tools.push(...(await provider.listTools(this.ctx)));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
this.diagnostics.push({
|
|
34
|
+
capability: provider.id,
|
|
35
|
+
phase: "start",
|
|
36
|
+
level: "warn",
|
|
37
|
+
message: `toolProvider "${provider.id}" listTools failed: ${messageOf(error)}`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return tools;
|
|
42
|
+
}
|
|
43
|
+
/** Apply every capability's tool filter in registration order. A thrower is skipped. */
|
|
44
|
+
applyToolFilters(tools) {
|
|
45
|
+
let current = tools;
|
|
46
|
+
for (const filter of this.toolFilters) {
|
|
47
|
+
try {
|
|
48
|
+
current = filter(current);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
this.diagnostics.push({
|
|
52
|
+
capability: "toolFilter",
|
|
53
|
+
phase: "start",
|
|
54
|
+
level: "warn",
|
|
55
|
+
message: `tool filter failed; toolset left unchanged: ${messageOf(error)}`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return current;
|
|
60
|
+
}
|
|
61
|
+
absorb(capability) {
|
|
62
|
+
for (const tool of capability.tools ?? [])
|
|
63
|
+
this.staticTools.push(tool);
|
|
64
|
+
for (const provider of capability.toolProviders ?? [])
|
|
65
|
+
this.toolProviders.push(provider);
|
|
66
|
+
for (const filter of capability.toolFilters ?? [])
|
|
67
|
+
this.toolFilters.push(filter);
|
|
68
|
+
if (capability.gates?.compaction)
|
|
69
|
+
this.gates.compaction.push(capability.gates.compaction);
|
|
70
|
+
// capability.policies are session-tier contributions — collected once by
|
|
71
|
+
// Session.buildPermissionManager (the manager is session-lived), not per run.
|
|
72
|
+
if (capability.hooks) {
|
|
73
|
+
// Run-tier hooks are driven by the Runner itself, not composed into the step machine.
|
|
74
|
+
const { shouldContinueAfterStop, beforeRun, ...loopHooks } = capability.hooks;
|
|
75
|
+
if (Object.keys(loopHooks).length > 0)
|
|
76
|
+
this.loopHookParts.push(loopHooks);
|
|
77
|
+
if (shouldContinueAfterStop)
|
|
78
|
+
this.boundaryContinuations.push(shouldContinueAfterStop);
|
|
79
|
+
if (beforeRun)
|
|
80
|
+
this.runStarts.push(beforeRun);
|
|
81
|
+
}
|
|
82
|
+
this.injection.registerAll(capability.injectors ?? []);
|
|
83
|
+
}
|
|
84
|
+
markStarted(capability) {
|
|
85
|
+
this.started.push(capability);
|
|
86
|
+
}
|
|
87
|
+
async stop() {
|
|
88
|
+
for (const capability of [...this.started].reverse()) {
|
|
89
|
+
if (!capability.stop)
|
|
90
|
+
continue;
|
|
91
|
+
try {
|
|
92
|
+
// The timeout races AND aborts: the run stops waiting at the deadline, and the
|
|
93
|
+
// straggling stop() is told to release its resources instead of running on
|
|
94
|
+
// unobserved in the background (cancellation is cooperative — see Capability.stop).
|
|
95
|
+
const cancel = new AbortController();
|
|
96
|
+
await withTimeout(Promise.resolve(capability.stop(cancel.signal)), this.stopTimeoutMs, cancel);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
this.diagnostics.push({
|
|
100
|
+
capability: capability.name,
|
|
101
|
+
phase: "stop",
|
|
102
|
+
level: "warn",
|
|
103
|
+
message: `stop failed/timed out: ${messageOf(error)}`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Internal: expose absorb to the assemble function.
|
|
109
|
+
_absorb(capability) {
|
|
110
|
+
this.absorb(capability);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export async function assembleCapabilities(capabilities, ctx, options = {}) {
|
|
114
|
+
const assembled = new AssembledCapabilities(ctx, options);
|
|
115
|
+
const startTimeoutMs = options.startTimeoutMs ?? START_TIMEOUT_MS;
|
|
116
|
+
const seenNames = new Set();
|
|
117
|
+
// like compaction can resync injector watermarks after collapsing the prefix.
|
|
118
|
+
const startCtx = { ...ctx, injection: assembled.injection, gates: assembled.gates };
|
|
119
|
+
for (const capability of capabilities) {
|
|
120
|
+
if (seenNames.has(capability.name)) {
|
|
121
|
+
assembled.diagnostics.push({
|
|
122
|
+
capability: capability.name,
|
|
123
|
+
phase: "register",
|
|
124
|
+
level: "error",
|
|
125
|
+
message: `duplicate capability name "${capability.name}"; second registration skipped.`,
|
|
126
|
+
});
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
seenNames.add(capability.name);
|
|
130
|
+
try {
|
|
131
|
+
if (capability.start) {
|
|
132
|
+
// Same contract as stop(): the deadline wins the race, and the losing start()
|
|
133
|
+
// is aborted so it can release partially acquired resources.
|
|
134
|
+
const cancel = new AbortController();
|
|
135
|
+
await withTimeout(Promise.resolve(capability.start(startCtx, cancel.signal)), startTimeoutMs, cancel);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
assembled.diagnostics.push({
|
|
140
|
+
capability: capability.name,
|
|
141
|
+
phase: "start",
|
|
142
|
+
level: "error",
|
|
143
|
+
message: `start failed/timed out; capability absent: ${messageOf(error)}`,
|
|
144
|
+
});
|
|
145
|
+
continue; // fault isolation — none of its contributions register
|
|
146
|
+
}
|
|
147
|
+
assembled.markStarted(capability);
|
|
148
|
+
assembled._absorb(capability);
|
|
149
|
+
}
|
|
150
|
+
return assembled;
|
|
151
|
+
}
|
|
152
|
+
function messageOf(error) {
|
|
153
|
+
return error instanceof Error ? error.message : String(error);
|
|
154
|
+
}
|
|
155
|
+
function withTimeout(promise, ms, cancel) {
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
const timer = setTimeout(() => {
|
|
158
|
+
const error = new Error(`timed out after ${ms}ms`);
|
|
159
|
+
cancel?.abort(error);
|
|
160
|
+
reject(error);
|
|
161
|
+
}, ms);
|
|
162
|
+
promise.then((value) => {
|
|
163
|
+
clearTimeout(timer);
|
|
164
|
+
resolve(value);
|
|
165
|
+
}, (error) => {
|
|
166
|
+
clearTimeout(timer);
|
|
167
|
+
reject(error);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=assembler.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { BackgroundTask, BackgroundTaskInfoBase, BackgroundTaskSink, TaskOutputLocation } from "./task.ts";
|
|
2
|
+
export interface AgentBackgroundTaskInfo extends BackgroundTaskInfoBase {
|
|
3
|
+
readonly kind: "agent";
|
|
4
|
+
readonly agentId?: string;
|
|
5
|
+
readonly subagentType?: string;
|
|
6
|
+
/** The subagent run's own terminal status (finer than the task status), once settled. */
|
|
7
|
+
readonly agentStatus?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AgentBackgroundTaskOptions {
|
|
10
|
+
readonly timeoutMs?: number;
|
|
11
|
+
readonly abort?: () => void;
|
|
12
|
+
readonly agentId?: string;
|
|
13
|
+
readonly subagentType?: string;
|
|
14
|
+
readonly parentAddress?: string;
|
|
15
|
+
readonly toolCallId?: string;
|
|
16
|
+
/** The sub-agent's own conversation shard — every background agent must have one. */
|
|
17
|
+
readonly address: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A sub-agent run as a background task.
|
|
21
|
+
*
|
|
22
|
+
* Holds NO output. The sub-agent's answer is the last assistant message of its shard, written
|
|
23
|
+
* there by its own conversation as the run proceeds — so this task states the address and
|
|
24
|
+
* stops, exactly as {@link CommandBackgroundTask} states a log path. Copying the answer into
|
|
25
|
+
* the sink as well would make a third copy (after the shard and the projection that folds the
|
|
26
|
+
* same events), authoritative in none of them, and — because the copy is only written when the
|
|
27
|
+
* run settles — would leave a reader of a RUNNING agent staring at an empty buffer while the
|
|
28
|
+
* shard already holds every message so far.
|
|
29
|
+
*/
|
|
30
|
+
export declare class AgentBackgroundTask implements BackgroundTask {
|
|
31
|
+
readonly kind: "agent";
|
|
32
|
+
readonly idPrefix: string;
|
|
33
|
+
readonly description: string;
|
|
34
|
+
readonly timeoutMs?: number;
|
|
35
|
+
readonly agentId?: string;
|
|
36
|
+
readonly subagentType?: string;
|
|
37
|
+
readonly parentAddress?: string;
|
|
38
|
+
readonly toolCallId?: string;
|
|
39
|
+
readonly outputLocation?: TaskOutputLocation;
|
|
40
|
+
private agentStatus?;
|
|
41
|
+
private readonly run;
|
|
42
|
+
private readonly abort?;
|
|
43
|
+
constructor(run: Promise<{
|
|
44
|
+
agentStatus: string;
|
|
45
|
+
}> | (() => Promise<{
|
|
46
|
+
agentStatus: string;
|
|
47
|
+
}>), description: string, options: AgentBackgroundTaskOptions);
|
|
48
|
+
start(sink: BackgroundTaskSink): Promise<void>;
|
|
49
|
+
toInfo(base: BackgroundTaskInfoBase): AgentBackgroundTaskInfo;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=agent-task.d.ts.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { errorMessage, isAbortError } from "../../loop/errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* A sub-agent run as a background task.
|
|
4
|
+
*
|
|
5
|
+
* Holds NO output. The sub-agent's answer is the last assistant message of its shard, written
|
|
6
|
+
* there by its own conversation as the run proceeds — so this task states the address and
|
|
7
|
+
* stops, exactly as {@link CommandBackgroundTask} states a log path. Copying the answer into
|
|
8
|
+
* the sink as well would make a third copy (after the shard and the projection that folds the
|
|
9
|
+
* same events), authoritative in none of them, and — because the copy is only written when the
|
|
10
|
+
* run settles — would leave a reader of a RUNNING agent staring at an empty buffer while the
|
|
11
|
+
* shard already holds every message so far.
|
|
12
|
+
*/
|
|
13
|
+
export class AgentBackgroundTask {
|
|
14
|
+
kind = "agent";
|
|
15
|
+
idPrefix = "agent";
|
|
16
|
+
description;
|
|
17
|
+
timeoutMs;
|
|
18
|
+
agentId;
|
|
19
|
+
subagentType;
|
|
20
|
+
parentAddress;
|
|
21
|
+
toolCallId;
|
|
22
|
+
outputLocation;
|
|
23
|
+
agentStatus;
|
|
24
|
+
run;
|
|
25
|
+
abort;
|
|
26
|
+
constructor(run, description, options) {
|
|
27
|
+
if (typeof options.address !== "string" || options.address.length === 0) {
|
|
28
|
+
throw new Error("A background Agent requires its durable conversation address.");
|
|
29
|
+
}
|
|
30
|
+
this.run = typeof run === "function" ? run : () => run;
|
|
31
|
+
this.description = description;
|
|
32
|
+
this.timeoutMs = options.timeoutMs;
|
|
33
|
+
this.abort = options.abort;
|
|
34
|
+
this.agentId = options.agentId;
|
|
35
|
+
this.subagentType = options.subagentType;
|
|
36
|
+
this.parentAddress = options.parentAddress;
|
|
37
|
+
this.toolCallId = options.toolCallId;
|
|
38
|
+
this.outputLocation = { kind: "conversation", address: options.address };
|
|
39
|
+
}
|
|
40
|
+
async start(sink) {
|
|
41
|
+
const requestAbort = () => {
|
|
42
|
+
this.abort?.();
|
|
43
|
+
};
|
|
44
|
+
if (sink.signal.aborted) {
|
|
45
|
+
requestAbort();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
sink.signal.addEventListener("abort", requestAbort, { once: true });
|
|
49
|
+
}
|
|
50
|
+
const deadlineTimeout = Symbol("background-agent-deadline");
|
|
51
|
+
const raceInputs = [this.run()];
|
|
52
|
+
const timeoutMs = this.timeoutMs;
|
|
53
|
+
let timer;
|
|
54
|
+
if (timeoutMs !== undefined && timeoutMs > 0) {
|
|
55
|
+
raceInputs.push(new Promise((resolve) => {
|
|
56
|
+
timer = setTimeout(() => resolve(deadlineTimeout), timeoutMs);
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const outcome = await Promise.race(raceInputs);
|
|
61
|
+
if (outcome === deadlineTimeout) {
|
|
62
|
+
this.abort?.();
|
|
63
|
+
await sink.settle({ status: "timed_out" });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.agentStatus = outcome.agentStatus;
|
|
67
|
+
await sink.settle({ status: taskStatusFromAgent(outcome.agentStatus) });
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (sink.signal.aborted && isAbortError(error)) {
|
|
71
|
+
await sink.settle({ status: "killed" });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await sink.settle({ status: "failed", stopReason: errorMessage(error) });
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
if (timer !== undefined)
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
sink.signal.removeEventListener("abort", requestAbort);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
toInfo(base) {
|
|
83
|
+
return {
|
|
84
|
+
...base,
|
|
85
|
+
kind: "agent",
|
|
86
|
+
agentId: this.agentId,
|
|
87
|
+
subagentType: this.subagentType,
|
|
88
|
+
agentStatus: this.agentStatus,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function taskStatusFromAgent(status) {
|
|
93
|
+
if (status === "completed")
|
|
94
|
+
return "completed";
|
|
95
|
+
if (status === "paused")
|
|
96
|
+
return "paused";
|
|
97
|
+
if (status === "cancelled")
|
|
98
|
+
return "killed";
|
|
99
|
+
return "failed";
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=agent-task.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CommandStarter, ProcessSpawnOptions } from "../../tool/background.ts";
|
|
2
|
+
import type { BackgroundTask, BackgroundTaskInfoBase, BackgroundTaskSink, TaskOutputLocation } from "./task.ts";
|
|
3
|
+
export interface CommandBackgroundTaskInfo extends BackgroundTaskInfoBase {
|
|
4
|
+
/** Wire value kept as "process" — persisted task records use it. */
|
|
5
|
+
readonly kind: "process";
|
|
6
|
+
readonly command: string;
|
|
7
|
+
readonly exitCode: number | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A shell command running as a background task.
|
|
11
|
+
*
|
|
12
|
+
* Driven by a {@link CommandStarter}, NOT by a process handle. The distinction is the whole
|
|
13
|
+
* point: a background task needs to stream output, be stopped, and report how it ended —
|
|
14
|
+
* all three of which are `run`'s intent fields, and all three of which every backend can
|
|
15
|
+
* deliver natively. Requiring a live process handle instead would demand a capability that
|
|
16
|
+
* sandbox transports cannot provide honestly, which is what used to force a fake handle
|
|
17
|
+
* whose `kill()` did nothing.
|
|
18
|
+
*
|
|
19
|
+
* No `forceStop`: SIGTERM → grace → SIGKILL escalation belongs to the Machine layer, which
|
|
20
|
+
* is where killing is real. Aborting the signal is the whole stop protocol.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CommandBackgroundTask implements BackgroundTask {
|
|
23
|
+
readonly kind: "process";
|
|
24
|
+
readonly idPrefix = "bash";
|
|
25
|
+
readonly command: string;
|
|
26
|
+
readonly description: string;
|
|
27
|
+
/**
|
|
28
|
+
* Where this command's output actually lives. A FACT, not a behaviour: the task states the
|
|
29
|
+
* location and nothing else, and whoever wants to look owns every decision about how much
|
|
30
|
+
* to read. BackgroundManager rejects process tasks without this file.
|
|
31
|
+
*/
|
|
32
|
+
readonly outputLocation?: TaskOutputLocation;
|
|
33
|
+
private readonly start_;
|
|
34
|
+
readonly parentAddress?: string;
|
|
35
|
+
readonly toolCallId?: string;
|
|
36
|
+
private exitCodeValue;
|
|
37
|
+
constructor(start: CommandStarter, command: string, description: string, options?: ProcessSpawnOptions);
|
|
38
|
+
/** Latest known exit status; null until the command settles, or when it reported none. */
|
|
39
|
+
get exitCode(): number | null;
|
|
40
|
+
start(sink: BackgroundTaskSink): Promise<void>;
|
|
41
|
+
toInfo(base: BackgroundTaskInfoBase): CommandBackgroundTaskInfo;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=command-task.d.ts.map
|