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
package/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yingjie Qiao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
-------------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
THIRD-PARTY LICENSES
|
|
27
|
+
|
|
28
|
+
Portions of this software were adapted from kimi-code, which is distributed
|
|
29
|
+
under the MIT License. Its copyright and permission notice is reproduced below.
|
|
30
|
+
|
|
31
|
+
-------------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
kimi-code
|
|
34
|
+
|
|
35
|
+
MIT License
|
|
36
|
+
|
|
37
|
+
Copyright (c) 2026 Moonshot AI
|
|
38
|
+
|
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
40
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
41
|
+
in the Software without restriction, including without limitation the rights
|
|
42
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
43
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
44
|
+
furnished to do so, subject to the following conditions:
|
|
45
|
+
|
|
46
|
+
The above copyright notice and this permission notice shall be included in all
|
|
47
|
+
copies or substantial portions of the Software.
|
|
48
|
+
|
|
49
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
50
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
51
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
52
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
53
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
54
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
55
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# operon-agents-core
|
|
2
|
+
|
|
3
|
+
Internal engine for `operon-agents`.
|
|
4
|
+
|
|
5
|
+
Application code should import from `operon-agents`. This package intentionally
|
|
6
|
+
contains lower-level runtime, loop, permission, storage, and capability modules
|
|
7
|
+
that may change as the engine evolves.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ChatModel } from "../llm/define-model.ts";
|
|
2
|
+
import type { ModelSettings } from "../llm/model.ts";
|
|
3
|
+
import type { Tool } from "../tool/types.ts";
|
|
4
|
+
import type { Machine } from "../tool/machine.ts";
|
|
5
|
+
import type { Handoff } from "./handoff.ts";
|
|
6
|
+
import type { InputGuardrail, OutputGuardrail, ToolInputGuardrail, ToolOutputGuardrail } from "./guardrail.ts";
|
|
7
|
+
import type { SystemPromptContext } from "./instruction-context.ts";
|
|
8
|
+
export interface AgentRunContext<TContext = unknown> {
|
|
9
|
+
readonly sessionId: string;
|
|
10
|
+
readonly address: string;
|
|
11
|
+
readonly signal: AbortSignal;
|
|
12
|
+
readonly context?: TContext;
|
|
13
|
+
/** Machine of the current runtime frame (root/subagent/worktree), never captured by Agent. */
|
|
14
|
+
readonly machine?: Machine;
|
|
15
|
+
/** Lazily resolves Session-cached environment + AGENTS.md data for this runtime frame. */
|
|
16
|
+
readonly resolveSystemPromptContext?: () => Promise<SystemPromptContext>;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentGuardrails<TContext = unknown> {
|
|
19
|
+
readonly input?: readonly InputGuardrail<TContext>[];
|
|
20
|
+
readonly output?: readonly OutputGuardrail<TContext>[];
|
|
21
|
+
readonly toolInput?: readonly ToolInputGuardrail<TContext>[];
|
|
22
|
+
readonly toolOutput?: readonly ToolOutputGuardrail<TContext>[];
|
|
23
|
+
}
|
|
24
|
+
export interface AgentConfig<TContext = unknown> {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly instructions?: string | ((ctx: AgentRunContext<TContext>) => string | Promise<string>);
|
|
27
|
+
readonly handoffDescription?: string;
|
|
28
|
+
readonly model?: string | ChatModel;
|
|
29
|
+
/**
|
|
30
|
+
* Static per-request model behavior for this agent. Session-level runtime overrides
|
|
31
|
+
* (`setThinkingLevel()`) win over what is set here — see `resolveModelParams`.
|
|
32
|
+
*/
|
|
33
|
+
readonly modelSettings?: ModelSettings;
|
|
34
|
+
readonly tools?: readonly Tool[];
|
|
35
|
+
readonly handoffs?: readonly Handoff<TContext>[];
|
|
36
|
+
readonly subagents?: readonly Agent<TContext>[];
|
|
37
|
+
readonly guardrails?: AgentGuardrails<TContext>;
|
|
38
|
+
readonly outputType?: unknown;
|
|
39
|
+
readonly maxStepsPerTurn?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Opt into deferred tool loading: capability/MCP tools are discovered on
|
|
42
|
+
* demand through SearchTool, then pi materializes their definitions from
|
|
43
|
+
* `ToolResultMessage.addedToolNames`. A no-op for models whose compat data
|
|
44
|
+
* does not advertise native deferred-tool support. Off by default.
|
|
45
|
+
*/
|
|
46
|
+
readonly deferTools?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export declare class Agent<TContext = unknown> {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly instructions?: AgentConfig<TContext>["instructions"];
|
|
51
|
+
readonly handoffDescription?: string;
|
|
52
|
+
readonly model?: string | ChatModel;
|
|
53
|
+
readonly modelSettings?: AgentConfig<TContext>["modelSettings"];
|
|
54
|
+
readonly tools: readonly Tool[];
|
|
55
|
+
readonly handoffs: readonly Handoff<TContext>[];
|
|
56
|
+
readonly subagents: readonly Agent<TContext>[];
|
|
57
|
+
readonly guardrails: AgentGuardrails<TContext>;
|
|
58
|
+
readonly outputType?: unknown;
|
|
59
|
+
readonly maxStepsPerTurn?: number;
|
|
60
|
+
readonly deferTools?: boolean;
|
|
61
|
+
constructor(config: AgentConfig<TContext>);
|
|
62
|
+
resolveInstructions(ctx: AgentRunContext<TContext>): Promise<string | undefined>;
|
|
63
|
+
}
|
|
64
|
+
export declare function defineAgent<TContext = unknown>(config: AgentConfig<TContext>): Agent<TContext>;
|
|
65
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class Agent {
|
|
2
|
+
name;
|
|
3
|
+
instructions;
|
|
4
|
+
handoffDescription;
|
|
5
|
+
model;
|
|
6
|
+
modelSettings;
|
|
7
|
+
tools;
|
|
8
|
+
handoffs;
|
|
9
|
+
subagents;
|
|
10
|
+
guardrails;
|
|
11
|
+
outputType;
|
|
12
|
+
maxStepsPerTurn;
|
|
13
|
+
deferTools;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
if (!config.name)
|
|
16
|
+
throw new Error("Agent requires a non-empty `name`.");
|
|
17
|
+
this.name = config.name;
|
|
18
|
+
this.instructions = config.instructions;
|
|
19
|
+
this.handoffDescription = config.handoffDescription;
|
|
20
|
+
this.model = config.model;
|
|
21
|
+
this.modelSettings = config.modelSettings;
|
|
22
|
+
this.tools = config.tools ?? [];
|
|
23
|
+
this.handoffs = config.handoffs ?? [];
|
|
24
|
+
this.subagents = config.subagents ?? [];
|
|
25
|
+
this.guardrails = config.guardrails ?? {};
|
|
26
|
+
this.outputType = config.outputType;
|
|
27
|
+
this.maxStepsPerTurn = config.maxStepsPerTurn;
|
|
28
|
+
this.deferTools = config.deferTools;
|
|
29
|
+
}
|
|
30
|
+
async resolveInstructions(ctx) {
|
|
31
|
+
if (typeof this.instructions === "function")
|
|
32
|
+
return this.instructions(ctx);
|
|
33
|
+
return this.instructions;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function defineAgent(config) {
|
|
37
|
+
return new Agent(config);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LoopHooks } from "../loop/types.ts";
|
|
2
|
+
import type { Tool } from "../tool/types.ts";
|
|
3
|
+
import type { ConversationContext } from "../loop/context.ts";
|
|
4
|
+
import type { Agent } from "./agent.ts";
|
|
5
|
+
import type { RunState } from "./runner.ts";
|
|
6
|
+
/**
|
|
7
|
+
* The loop hooks for one turn of `active` under a frame: capability hook parts
|
|
8
|
+
* (compaction beforeStep/afterStep …) → permission authorizer (single) → tool guardrails.
|
|
9
|
+
* Extracted from the Engine; only TYPES are imported from `runner.ts`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildRunHooks<TContext>(active: Agent<TContext>, state: RunState<TContext>, context: ConversationContext, tools: readonly Tool[]): LoopHooks;
|
|
12
|
+
export declare function composeLoopHooks(parts: ReadonlyArray<Partial<LoopHooks> | undefined>): LoopHooks;
|
|
13
|
+
//# sourceMappingURL=compose-hooks.d.ts.map
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { toolInputGuardrailHook, toolOutputGuardrailHook } from "./guardrail.js";
|
|
2
|
+
import { runCtxFor } from "./run-support.js";
|
|
3
|
+
import { withToolCallRecoveryContext } from "./recovery.js";
|
|
4
|
+
/**
|
|
5
|
+
* The loop hooks for one turn of `active` under a frame: capability hook parts
|
|
6
|
+
* (compaction beforeStep/afterStep …) → permission authorizer (single) → tool guardrails.
|
|
7
|
+
* Extracted from the Engine; only TYPES are imported from `runner.ts`.
|
|
8
|
+
*/
|
|
9
|
+
export function buildRunHooks(active, state, context, tools) {
|
|
10
|
+
const ctx = runCtxFor(state);
|
|
11
|
+
const parts = [...state.capabilities.loopHookParts];
|
|
12
|
+
parts.push({ authorizeToolExecution: buildAuthorizer(state, context, tools) });
|
|
13
|
+
if (active.guardrails.toolInput && active.guardrails.toolInput.length > 0) {
|
|
14
|
+
parts.push({ prepareToolExecution: toolInputGuardrailHook(active, ctx, active.guardrails.toolInput) });
|
|
15
|
+
}
|
|
16
|
+
if (active.guardrails.toolOutput && active.guardrails.toolOutput.length > 0) {
|
|
17
|
+
parts.push({ finalizeToolResult: toolOutputGuardrailHook(active, ctx, active.guardrails.toolOutput) });
|
|
18
|
+
}
|
|
19
|
+
// Last request transform: capability hooks may rewrite the message list, so recovery must
|
|
20
|
+
// inspect their final shape. It is request-only and never journals synthetic history.
|
|
21
|
+
parts.push({
|
|
22
|
+
beforeModelRequest: async ({ request }) => {
|
|
23
|
+
const recovered = await withToolCallRecoveryContext(state, request);
|
|
24
|
+
return recovered === request ? undefined : { request: recovered };
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return composeLoopHooks(parts);
|
|
28
|
+
}
|
|
29
|
+
function buildAuthorizer(state, context, tools) {
|
|
30
|
+
// The `auto`-mode judge needs THIS frame's live transcript + tool registry (the authorize
|
|
31
|
+
// ctx carries neither). Bind them per turn as closure state — the manager is a session
|
|
32
|
+
// singleton shared by concurrent frames, so they must never be stored on it.
|
|
33
|
+
const base = state.permission.authorizerFor({ getTranscript: () => context.messages, getTools: () => tools });
|
|
34
|
+
const answers = state.answers;
|
|
35
|
+
if (!answers)
|
|
36
|
+
return base;
|
|
37
|
+
return async (ctx) => {
|
|
38
|
+
const answer = answers[ctx.toolCall.id];
|
|
39
|
+
if (answer) {
|
|
40
|
+
// Audit record: this is the single chokepoint both live and durable approvals
|
|
41
|
+
// flow through (the responder/resume answer is applied here).
|
|
42
|
+
context.record({ type: "permission.record_approval", toolCallId: ctx.toolCall.id, toolName: ctx.toolCall.name, decision: answer.decision, feedback: answer.feedback, approvalRule: ctx.plan.approvalRule, scope: answer.scope });
|
|
43
|
+
const ok = state.permission.applyApproval(ctx.plan.approvalRule, answer);
|
|
44
|
+
if (ok)
|
|
45
|
+
return undefined;
|
|
46
|
+
return { block: true, reason: answer.feedback ?? `Tool ${ctx.toolCall.name} was ${answer.decision}.` };
|
|
47
|
+
}
|
|
48
|
+
return base(ctx);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function composeLoopHooks(parts) {
|
|
52
|
+
const list = parts.filter((h) => h !== undefined);
|
|
53
|
+
const beforeSteps = list.map((h) => h.beforeStep).filter(isDefined);
|
|
54
|
+
const afterSteps = list.map((h) => h.afterStep).filter(isDefined);
|
|
55
|
+
const beforeModelRequests = list.map((h) => h.beforeModelRequest).filter(isDefined);
|
|
56
|
+
const afterModelResponses = list.map((h) => h.afterModelResponse).filter(isDefined);
|
|
57
|
+
const prepares = list.map((h) => h.prepareToolExecution).filter(isDefined);
|
|
58
|
+
const authorizers = list.map((h) => h.authorizeToolExecution).filter(isDefined);
|
|
59
|
+
const finalizers = list.map((h) => h.finalizeToolResult).filter(isDefined);
|
|
60
|
+
const continuers = list.map((h) => h.shouldContinueAfterStop).filter(isDefined);
|
|
61
|
+
const recoverers = list.map((h) => h.recoverStepError).filter(isDefined);
|
|
62
|
+
const composed = {};
|
|
63
|
+
if (beforeSteps.length > 0) {
|
|
64
|
+
composed.beforeStep = async (ctx) => {
|
|
65
|
+
// `system` chains like the other transform slots: each hook sees the previous rewrite,
|
|
66
|
+
// and only a real change is reported back so the step keeps the agent-resolved default.
|
|
67
|
+
let system = ctx.system;
|
|
68
|
+
let changed = false;
|
|
69
|
+
for (const hook of beforeSteps) {
|
|
70
|
+
const result = await hook(changed ? { ...ctx, system } : ctx);
|
|
71
|
+
if (result?.block === true)
|
|
72
|
+
return result;
|
|
73
|
+
if (result?.system !== undefined) {
|
|
74
|
+
system = result.system;
|
|
75
|
+
changed = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return changed ? { system } : undefined;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (afterSteps.length > 0) {
|
|
82
|
+
composed.afterStep = async (ctx) => {
|
|
83
|
+
let stopTurn = false;
|
|
84
|
+
for (const hook of afterSteps) {
|
|
85
|
+
const result = await hook(ctx);
|
|
86
|
+
if (result?.stopTurn === true)
|
|
87
|
+
stopTurn = true;
|
|
88
|
+
}
|
|
89
|
+
return stopTurn ? { stopTurn: true } : undefined;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (beforeModelRequests.length > 0) {
|
|
93
|
+
composed.beforeModelRequest = async (ctx) => {
|
|
94
|
+
let request = ctx.request;
|
|
95
|
+
let merged;
|
|
96
|
+
for (const hook of beforeModelRequests) {
|
|
97
|
+
const result = await hook({ ...ctx, request });
|
|
98
|
+
if (!result)
|
|
99
|
+
continue;
|
|
100
|
+
if (result.block === true)
|
|
101
|
+
return result;
|
|
102
|
+
if (result.request !== undefined) {
|
|
103
|
+
request = result.request;
|
|
104
|
+
merged = { ...merged, request };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return merged;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (afterModelResponses.length > 0) {
|
|
111
|
+
composed.afterModelResponse = chainModelResponses(afterModelResponses);
|
|
112
|
+
}
|
|
113
|
+
if (prepares.length > 0) {
|
|
114
|
+
composed.prepareToolExecution = async (ctx) => {
|
|
115
|
+
let merged;
|
|
116
|
+
let args = ctx.args;
|
|
117
|
+
for (const hook of prepares) {
|
|
118
|
+
const result = await hook({ ...ctx, args });
|
|
119
|
+
if (!result)
|
|
120
|
+
continue;
|
|
121
|
+
if (result.syntheticResult || result.block === true)
|
|
122
|
+
return result;
|
|
123
|
+
if (result.updatedArgs !== undefined) {
|
|
124
|
+
args = result.updatedArgs;
|
|
125
|
+
merged = { ...merged, updatedArgs: args };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return merged;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (authorizers.length > 0) {
|
|
132
|
+
composed.authorizeToolExecution = async (ctx) => {
|
|
133
|
+
for (const hook of authorizers) {
|
|
134
|
+
const result = await hook(ctx);
|
|
135
|
+
if (result)
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (finalizers.length > 0) {
|
|
142
|
+
composed.finalizeToolResult = chainFinalizers(finalizers);
|
|
143
|
+
}
|
|
144
|
+
if (continuers.length > 0) {
|
|
145
|
+
composed.shouldContinueAfterStop = async (ctx) => {
|
|
146
|
+
let cont = false;
|
|
147
|
+
for (const hook of continuers) {
|
|
148
|
+
const result = await hook(ctx);
|
|
149
|
+
if (result?.continue === true)
|
|
150
|
+
cont = true;
|
|
151
|
+
}
|
|
152
|
+
return cont ? { continue: true } : undefined;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (recoverers.length > 0) {
|
|
156
|
+
// First claim wins (like `authorizeToolExecution`): the claimant has already acted on the
|
|
157
|
+
// failure (e.g. compacted), so consulting later hooks would recover the same error twice.
|
|
158
|
+
composed.recoverStepError = async (ctx) => {
|
|
159
|
+
for (const hook of recoverers) {
|
|
160
|
+
const result = await hook(ctx);
|
|
161
|
+
if (result?.recovered === true)
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return composed;
|
|
168
|
+
}
|
|
169
|
+
function chainModelResponses(hooks) {
|
|
170
|
+
return async (ctx) => {
|
|
171
|
+
let response = ctx.response;
|
|
172
|
+
let changed = false;
|
|
173
|
+
for (const hook of hooks) {
|
|
174
|
+
const next = await hook({ ...ctx, response });
|
|
175
|
+
if (next !== undefined) {
|
|
176
|
+
response = next;
|
|
177
|
+
changed = true;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return changed ? response : undefined;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function chainFinalizers(finalizers) {
|
|
184
|
+
return async (ctx) => {
|
|
185
|
+
let result = ctx.result;
|
|
186
|
+
for (const hook of finalizers) {
|
|
187
|
+
const next = await hook({ ...ctx, result });
|
|
188
|
+
if (next)
|
|
189
|
+
result = next;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function isDefined(value) {
|
|
195
|
+
return value !== undefined;
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=compose-hooks.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RunState } from "./runner.ts";
|
|
2
|
+
/** Concurrency limiter (semaphore). */
|
|
3
|
+
export declare class Semaphore {
|
|
4
|
+
private active;
|
|
5
|
+
private readonly queue;
|
|
6
|
+
private readonly max;
|
|
7
|
+
constructor(max: number);
|
|
8
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
/** Same shape the Workflow tool uses, so both spawn paths default alike. */
|
|
11
|
+
export declare function defaultSpawnConcurrency(): number;
|
|
12
|
+
/**
|
|
13
|
+
* The limiter a spawn should queue on, or `undefined` when this spawn must NOT queue.
|
|
14
|
+
*
|
|
15
|
+
* Only ROOT-frame spawns are limited. A subagent that spawns its own child is deliberately let
|
|
16
|
+
* through: if a frame held a permit while waiting for a child that needs one, a full pool would
|
|
17
|
+
* deadlock — every holder blocked on a permit no holder will release. Bounding the root fan-out
|
|
18
|
+
* is what actually matters (one assistant message asking for twenty subagents); the nested case
|
|
19
|
+
* is already bounded by `maxRecursionDepth`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function spawnLimiterFor<TContext>(state: RunState<TContext>, limit: number | undefined): Semaphore | undefined;
|
|
22
|
+
//# sourceMappingURL=concurrency.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concurrency limiting for spawned agents.
|
|
3
|
+
*
|
|
4
|
+
* Shared by the `Workflow` runtime and the `Agent`/`agent_<name>` spawn tools so one deployment
|
|
5
|
+
* does not end up with a bounded workflow fan-out beside an unbounded `Agent` fan-out.
|
|
6
|
+
*/
|
|
7
|
+
import { cpus } from "node:os";
|
|
8
|
+
/** Concurrency limiter (semaphore). */
|
|
9
|
+
export class Semaphore {
|
|
10
|
+
active = 0;
|
|
11
|
+
queue = [];
|
|
12
|
+
max;
|
|
13
|
+
constructor(max) {
|
|
14
|
+
this.max = max;
|
|
15
|
+
}
|
|
16
|
+
async run(fn) {
|
|
17
|
+
if (this.active >= this.max) {
|
|
18
|
+
// The releaser hands its slot to the woken waiter without ever dropping `active`,
|
|
19
|
+
// so a caller arriving between release and wake-up still sees the pool as full.
|
|
20
|
+
await new Promise((resolve) => this.queue.push(resolve));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.active++;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return await fn();
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
const next = this.queue.shift();
|
|
30
|
+
if (next)
|
|
31
|
+
next();
|
|
32
|
+
else
|
|
33
|
+
this.active--;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Same shape the Workflow tool uses, so both spawn paths default alike. */
|
|
38
|
+
export function defaultSpawnConcurrency() {
|
|
39
|
+
return Math.min(16, Math.max(2, cpus().length - 2));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One limiter per session. Keyed off the session port (not the frame) because a run's frames come
|
|
43
|
+
* and go while the session is what actually owns the machine's capacity; a session holds its run
|
|
44
|
+
* lock, so this bounds the whole tree beneath one prompt.
|
|
45
|
+
*/
|
|
46
|
+
const perSession = new WeakMap();
|
|
47
|
+
/**
|
|
48
|
+
* The limiter a spawn should queue on, or `undefined` when this spawn must NOT queue.
|
|
49
|
+
*
|
|
50
|
+
* Only ROOT-frame spawns are limited. A subagent that spawns its own child is deliberately let
|
|
51
|
+
* through: if a frame held a permit while waiting for a child that needs one, a full pool would
|
|
52
|
+
* deadlock — every holder blocked on a permit no holder will release. Bounding the root fan-out
|
|
53
|
+
* is what actually matters (one assistant message asking for twenty subagents); the nested case
|
|
54
|
+
* is already bounded by `maxRecursionDepth`.
|
|
55
|
+
*/
|
|
56
|
+
export function spawnLimiterFor(state, limit) {
|
|
57
|
+
if (state.parentFrameId !== undefined)
|
|
58
|
+
return undefined;
|
|
59
|
+
const max = limit ?? defaultSpawnConcurrency();
|
|
60
|
+
if (max <= 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
const key = state.session;
|
|
63
|
+
let semaphore = perSession.get(key);
|
|
64
|
+
if (semaphore === undefined) {
|
|
65
|
+
semaphore = new Semaphore(max);
|
|
66
|
+
perSession.set(key, semaphore);
|
|
67
|
+
}
|
|
68
|
+
return semaphore;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=concurrency.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context breakdown — a per-turn snapshot of how the model's context window is spent,
|
|
3
|
+
* mirroring what a `/context` view shows: system prompt, tool schemas, conversation, the
|
|
4
|
+
* turn-boundary injections (skills catalog, todo/task mirrors, …), the compaction reserve,
|
|
5
|
+
* and the free remainder.
|
|
6
|
+
*
|
|
7
|
+
* The numbers are ESTIMATES (same char/4 heuristic the compaction strategy uses), computed
|
|
8
|
+
* from exactly the `{ system, tools, messages }` the Runner is about to send — so the buckets
|
|
9
|
+
* sum to the real request, not a separate re-derivation.
|
|
10
|
+
*/
|
|
11
|
+
import type { ChatModel } from "../llm/define-model.ts";
|
|
12
|
+
import type { Message } from "../protocol/index.ts";
|
|
13
|
+
import type { Tool } from "../tool/types.ts";
|
|
14
|
+
/** One additive slice of the context window: its token estimate and share of the whole window. */
|
|
15
|
+
export interface ContextSlice {
|
|
16
|
+
readonly tokens: number;
|
|
17
|
+
/** Percent of the full context window, 0..100. */
|
|
18
|
+
readonly percent: number;
|
|
19
|
+
}
|
|
20
|
+
/** A single turn-boundary injector's contribution (a subset of the conversation framing). */
|
|
21
|
+
export interface ContextInjectionSlice extends ContextSlice {
|
|
22
|
+
/** The injector id (e.g. `skill_catalog`, `todo`, `task`, `plan_mode`, `goal`). */
|
|
23
|
+
readonly id: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ContextBreakdown {
|
|
26
|
+
/** The active model's full context window (tokens). */
|
|
27
|
+
readonly contextWindow: number;
|
|
28
|
+
readonly model: string;
|
|
29
|
+
/** systemPrompt + tools + messages + injections (everything actually sent this turn). */
|
|
30
|
+
readonly used: number;
|
|
31
|
+
readonly usedPercent: number;
|
|
32
|
+
readonly systemPrompt: ContextSlice;
|
|
33
|
+
/** Built-in / handoff / spawn tool schemas. */
|
|
34
|
+
readonly toolsBuiltin: ContextSlice;
|
|
35
|
+
/** MCP tool schemas (`mcp__*`). */
|
|
36
|
+
readonly toolsMcp: ContextSlice;
|
|
37
|
+
/** Conversation messages, EXCLUDING the turn-boundary injections broken out below. */
|
|
38
|
+
readonly messages: ContextSlice;
|
|
39
|
+
/** Turn-boundary injections (skills/todo/task/…), largest first. */
|
|
40
|
+
readonly injections: readonly ContextInjectionSlice[];
|
|
41
|
+
/** Tokens the compaction strategy reserves before the window fills (0 if no compaction). */
|
|
42
|
+
readonly compactBuffer: ContextSlice;
|
|
43
|
+
/** contextWindow − used − compactBuffer, clamped at 0. */
|
|
44
|
+
readonly free: ContextSlice;
|
|
45
|
+
/** Epoch ms the snapshot was taken (turn boundary). */
|
|
46
|
+
readonly capturedAt: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ComputeContextBreakdownInput {
|
|
49
|
+
readonly model: ChatModel;
|
|
50
|
+
readonly system: string | undefined;
|
|
51
|
+
readonly tools: readonly Tool[];
|
|
52
|
+
readonly messages: readonly Message[];
|
|
53
|
+
/** Per-injector token estimates captured while injecting at the turn boundary. */
|
|
54
|
+
readonly injectionTokens: ReadonlyMap<string, number>;
|
|
55
|
+
/** Compaction reserve (`CompactionService.reservedContextTokens`), or 0 if absent. */
|
|
56
|
+
readonly compactBufferTokens: number;
|
|
57
|
+
readonly capturedAt: number;
|
|
58
|
+
}
|
|
59
|
+
export declare function computeContextBreakdown(input: ComputeContextBreakdownInput): ContextBreakdown;
|
|
60
|
+
//# sourceMappingURL=context-report.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { estimateTokens, estimateTokensForMessages } from "../capabilities/compaction/tokens.js";
|
|
2
|
+
import { isMcpToolName } from "../mcp/tool-naming.js";
|
|
3
|
+
export function computeContextBreakdown(input) {
|
|
4
|
+
const window = input.model.contextWindow;
|
|
5
|
+
const pct = (tokens) => (window > 0 ? (tokens / window) * 100 : 0);
|
|
6
|
+
const slice = (tokens) => ({ tokens, percent: pct(tokens) });
|
|
7
|
+
const systemTokens = estimateTokens(input.system ?? "");
|
|
8
|
+
let builtinTools = 0;
|
|
9
|
+
let mcpTools = 0;
|
|
10
|
+
for (const tool of input.tools) {
|
|
11
|
+
const tokens = estimateTokens(JSON.stringify(tool.schema));
|
|
12
|
+
if (isMcpToolName(tool.schema.name))
|
|
13
|
+
mcpTools += tokens;
|
|
14
|
+
else
|
|
15
|
+
builtinTools += tokens;
|
|
16
|
+
}
|
|
17
|
+
// `messages` includes the injection reminders (they are appended as messages at the boundary);
|
|
18
|
+
// subtract the per-injector estimates so the two lines don't double-count.
|
|
19
|
+
const messagesTotal = estimateTokensForMessages(input.messages);
|
|
20
|
+
let injectionsTotal = 0;
|
|
21
|
+
const injections = [];
|
|
22
|
+
for (const [id, tokens] of input.injectionTokens) {
|
|
23
|
+
injectionsTotal += tokens;
|
|
24
|
+
injections.push({ id, tokens, percent: pct(tokens) });
|
|
25
|
+
}
|
|
26
|
+
injections.sort((a, b) => b.tokens - a.tokens);
|
|
27
|
+
const conversationTokens = Math.max(0, messagesTotal - injectionsTotal);
|
|
28
|
+
const used = systemTokens + builtinTools + mcpTools + messagesTotal;
|
|
29
|
+
const free = Math.max(0, window - used - input.compactBufferTokens);
|
|
30
|
+
return {
|
|
31
|
+
contextWindow: window,
|
|
32
|
+
model: input.model.id,
|
|
33
|
+
used,
|
|
34
|
+
usedPercent: pct(used),
|
|
35
|
+
systemPrompt: slice(systemTokens),
|
|
36
|
+
toolsBuiltin: slice(builtinTools),
|
|
37
|
+
toolsMcp: slice(mcpTools),
|
|
38
|
+
messages: slice(conversationTokens),
|
|
39
|
+
injections,
|
|
40
|
+
compactBuffer: slice(input.compactBufferTokens),
|
|
41
|
+
free: slice(free),
|
|
42
|
+
capturedAt: input.capturedAt,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=context-report.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-graph resolution + validation helpers, shared by the Runner (run()/resume()
|
|
3
|
+
* boundary checks, conversation-head resolution) and the toolset's spawner
|
|
4
|
+
* (resolveInGraph). Pure functions over the `Agent` graph — no runtime state.
|
|
5
|
+
*/
|
|
6
|
+
import { Agent } from "./agent.ts";
|
|
7
|
+
/**
|
|
8
|
+
* Fail a malformed graph at the run()/resume() boundary — before any turn executes or records
|
|
9
|
+
* commit — rather than mid-conversation when the offending agent finally becomes active. Walks
|
|
10
|
+
* by object identity, not name: distinct same-named agents in different corners of the graph are
|
|
11
|
+
* legal, and each one still gets validated.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertGraphUnambiguous<TContext>(root: Agent<TContext>): void;
|
|
14
|
+
/**
|
|
15
|
+
* An agent's edges are addressed by name at two seams — tool names the model calls
|
|
16
|
+
* (`transfer_to_<x>`, `agent_<slug>`) and durable handoff records resolved on resume — so within
|
|
17
|
+
* one agent each name must map to a single target. Not checked in the Agent constructor: cyclic
|
|
18
|
+
* graphs are built by pushing into `handoffs` after both agents exist, so the constructor never
|
|
19
|
+
* sees the final lists. Runs only at the run()/resume() boundary (via `assertGraphUnambiguous`);
|
|
20
|
+
* agents that enter the graph later — provider-loaded subagents, post-run() edge mutation — are
|
|
21
|
+
* the caller's responsibility (name clashes with static subagents already dedupe, static wins).
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertUnambiguousEdges<TContext>(agent: Agent<TContext>): void;
|
|
24
|
+
/** Durable state (conversation head, interruption frames) stores agent NAMES, so resume-time
|
|
25
|
+
* resolution is by name — and a graph with two distinct same-named agents (legal, see
|
|
26
|
+
* {@link assertGraphUnambiguous}) cannot be resolved safely that way. Thrown instead of
|
|
27
|
+
* guessing: binding whichever BFS found first would silently hand the conversation to the
|
|
28
|
+
* wrong agent. */
|
|
29
|
+
export declare class AmbiguousAgentNameError extends Error {
|
|
30
|
+
readonly agentName: string;
|
|
31
|
+
constructor(name: string, count: number);
|
|
32
|
+
}
|
|
33
|
+
/** Names shared by ≥2 distinct agent objects in the graph. Such a graph builds and runs
|
|
34
|
+
* live fine (edges resolve by object), but durable name-keyed resolution (resume,
|
|
35
|
+
* interruption frames) fails closed on those names — surfaced as a run-boundary warning
|
|
36
|
+
* so users hear about it before an {@link AmbiguousAgentNameError} interrupts a resume. */
|
|
37
|
+
export declare function duplicateAgentNames<TContext>(root: Agent<TContext>): string[];
|
|
38
|
+
/** Every distinct agent OBJECT in the graph named `name`. Visits by object identity — a
|
|
39
|
+
* name-keyed visited set would prune the subtree behind a same-named duplicate, hiding
|
|
40
|
+
* agents reachable only through it. */
|
|
41
|
+
export declare function findAgentsByName<TContext>(root: Agent<TContext>, name: string): Agent<TContext>[];
|
|
42
|
+
/** Resolve `name` to THE agent it denotes: `undefined` when absent, the agent when unique,
|
|
43
|
+
* and a thrown {@link AmbiguousAgentNameError} when several distinct agents share the name
|
|
44
|
+
* (fail-closed — see the error's doc). Callers that can resolve ambiguity another way
|
|
45
|
+
* (the Runner's cold head walk resolves along committed handoff edges) should catch it or
|
|
46
|
+
* use {@link findAgentsByName} directly. */
|
|
47
|
+
export declare function findAgentByName<TContext>(root: Agent<TContext>, name: string): Agent<TContext> | undefined;
|
|
48
|
+
//# sourceMappingURL=graph.d.ts.map
|