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,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow runtime — builds the in-script hooks (agent/parallel/pipeline/phase/
|
|
3
|
+
* log/budget/workflow) and runs the compiled script in a hardened VM. `agent()`
|
|
4
|
+
* runs through the host — this framework's subagent runner.
|
|
5
|
+
*
|
|
6
|
+
* Design points worth knowing:
|
|
7
|
+
* - structured output is enforced by the HOST (StructuredOutput tool), so the
|
|
8
|
+
* runtime just trusts hooks.runAgent to return a parsed value when a schema
|
|
9
|
+
* is set — no fragile text-JSON parsing here;
|
|
10
|
+
* - budget is REAL: hooks.runAgent reports output tokens and the host's
|
|
11
|
+
* getTurnSpent() reads live usage, so spent()/remaining() are not stubs;
|
|
12
|
+
* - parallel()/pipeline() enforce the 4096-items-per-call cap.
|
|
13
|
+
*/
|
|
14
|
+
import { compileScriptBody, createSandboxContext, harden, runCompiled } from "./sandbox.js";
|
|
15
|
+
import { Semaphore } from "../concurrency.js";
|
|
16
|
+
import { WORKFLOW_AGENT_CAP, WORKFLOW_MAX_ITEMS_PER_CALL, } from "./types.js";
|
|
17
|
+
export class WorkflowAgentCapError extends Error {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(`Workflow agent() call cap reached (${WORKFLOW_AGENT_CAP}). This usually means a loop using ` +
|
|
20
|
+
"budget.remaining() never terminates because no token budget was set — remaining() returns " +
|
|
21
|
+
"Infinity when budget.total is null. Add a hard iteration cap, or pass a token budget.");
|
|
22
|
+
this.name = "WorkflowAgentCapError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class WorkflowBudgetExceededError extends Error {
|
|
26
|
+
constructor(spent, total) {
|
|
27
|
+
super(`Workflow token budget exceeded (${spent.toLocaleString()} / ${total.toLocaleString()} output tokens). ` +
|
|
28
|
+
"Stopping further agent() calls. In-flight agents will complete; their results are preserved.");
|
|
29
|
+
this.name = "WorkflowBudgetExceededError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown by every hook when the workflow is aborted. There is no external VM
|
|
34
|
+
* teardown here, so abort must unwind the script by throwing
|
|
35
|
+
* rather than by stalling — otherwise a script that continues past a parallel()
|
|
36
|
+
* would hang forever. `name` is "AbortError" so the host's isAbortError() treats a
|
|
37
|
+
* backgrounded run as "killed" instead of "failed".
|
|
38
|
+
*/
|
|
39
|
+
export class WorkflowAbortedError extends Error {
|
|
40
|
+
constructor() {
|
|
41
|
+
super("Workflow aborted.");
|
|
42
|
+
this.name = "AbortError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function runWorkflow(params) {
|
|
46
|
+
const { meta, scriptBody, args, hooks, journal } = params;
|
|
47
|
+
const depth = params.depth ?? 0;
|
|
48
|
+
// Resume chain — created at the root, shared into nested workflows.
|
|
49
|
+
const chain = params.chain ?? { prevKey: "", diverged: false };
|
|
50
|
+
const compiled = compileScriptBody(scriptBody);
|
|
51
|
+
if (!compiled.ok) {
|
|
52
|
+
return { ok: false, error: compiled.error, failures: [], agentCount: 0 };
|
|
53
|
+
}
|
|
54
|
+
const failures = [];
|
|
55
|
+
const semaphore = new Semaphore(Math.max(1, hooks.concurrency));
|
|
56
|
+
let agentCount = 0;
|
|
57
|
+
let localSpent = 0;
|
|
58
|
+
let capExceeded = false;
|
|
59
|
+
let budgetExceeded = false;
|
|
60
|
+
const aborted = () => hooks.abortSignal.aborted;
|
|
61
|
+
const budgetTotal = hooks.budget.total;
|
|
62
|
+
const spent = () => hooks.budget.getTurnSpent() + localSpent;
|
|
63
|
+
const remaining = () => budgetTotal == null ? Number.POSITIVE_INFINITY : Math.max(0, budgetTotal - spent());
|
|
64
|
+
const budgetExhausted = () => budgetTotal != null && budgetTotal > 0 && spent() >= budgetTotal;
|
|
65
|
+
function checkCaps() {
|
|
66
|
+
// Abort is checked first: there is no external VM teardown here, so every hook
|
|
67
|
+
// turns an aborted signal into a thrown AbortError that unwinds the script.
|
|
68
|
+
if (aborted())
|
|
69
|
+
throw new WorkflowAbortedError();
|
|
70
|
+
if (agentCount >= WORKFLOW_AGENT_CAP) {
|
|
71
|
+
capExceeded = true;
|
|
72
|
+
throw new WorkflowAgentCapError();
|
|
73
|
+
}
|
|
74
|
+
if (budgetExhausted()) {
|
|
75
|
+
budgetExceeded = true;
|
|
76
|
+
throw new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function assertItemCount(n, who) {
|
|
80
|
+
if (n > WORKFLOW_MAX_ITEMS_PER_CALL) {
|
|
81
|
+
throw new RangeError(`${who}() accepts at most ${WORKFLOW_MAX_ITEMS_PER_CALL} items per call (got ${n}). ` +
|
|
82
|
+
"Chunk the work, or loop in smaller batches.");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// ---- agent() ----------------------------------------------------------
|
|
86
|
+
const agent = harden(async (promptArg, optsArg) => {
|
|
87
|
+
checkCaps();
|
|
88
|
+
const prompt = String(promptArg);
|
|
89
|
+
const opts = optsArg ?? {};
|
|
90
|
+
const index = ++agentCount;
|
|
91
|
+
const label = (opts.label != null ? String(opts.label) : prompt.slice(0, 60).replace(/\s+/g, " ").trim()) ||
|
|
92
|
+
`agent ${index}`;
|
|
93
|
+
const phase = opts.phase != null ? String(opts.phase) : undefined;
|
|
94
|
+
const recordBase = { index, label, ...(phase !== undefined ? { phase } : {}) };
|
|
95
|
+
// Journal: chained key over (prevKey + prompt + opts), rolling in
|
|
96
|
+
// execution order. `diverged` latches the prefix model — once one call misses,
|
|
97
|
+
// every key after it changes too, so we stop consulting the cache entirely.
|
|
98
|
+
const key = journal.keyFor(chain.prevKey, prompt, opts);
|
|
99
|
+
chain.prevKey = key;
|
|
100
|
+
const cached = chain.diverged ? undefined : journal.getResult(key);
|
|
101
|
+
if (cached !== undefined) {
|
|
102
|
+
// No journal write: a resume reuses the prior run's journal address, so this result is
|
|
103
|
+
// already on record — re-appending it would grow the journal by a full copy per resume.
|
|
104
|
+
hooks.emitProgress({
|
|
105
|
+
type: "agent",
|
|
106
|
+
record: {
|
|
107
|
+
...recordBase,
|
|
108
|
+
...(cached.agentId.length > 0 ? { agentId: cached.agentId } : {}),
|
|
109
|
+
...(cached.address !== undefined ? { address: cached.address } : {}),
|
|
110
|
+
state: "done",
|
|
111
|
+
resultPreview: previewOf(cached.result),
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
return cached.result;
|
|
115
|
+
}
|
|
116
|
+
// First miss → diverge. If this key has a `started` marker but no result, the
|
|
117
|
+
// agent was interrupted on a prior run; we re-run it (respawn) and say so.
|
|
118
|
+
chain.diverged = true;
|
|
119
|
+
if (journal.wasStarted(key)) {
|
|
120
|
+
hooks.emitProgress({ type: "log", message: `↻ respawning interrupted agent [${label}]` });
|
|
121
|
+
void journal.recordLog(`↻ respawning interrupted agent [${label}]`);
|
|
122
|
+
}
|
|
123
|
+
hooks.emitProgress({ type: "agent", record: { ...recordBase, state: "queued" } });
|
|
124
|
+
void journal.recordQueued(key, recordBase);
|
|
125
|
+
return semaphore.run(async () => {
|
|
126
|
+
// Re-check once the slot is free: agents that completed while this one queued
|
|
127
|
+
// have updated spent(), so a real budget ceiling stops further dispatch here
|
|
128
|
+
// (in-flight agents still finish — overshoot is bounded by concurrency).
|
|
129
|
+
if (aborted()) {
|
|
130
|
+
hooks.emitProgress({ type: "agent", record: { ...recordBase, state: "error", error: "Workflow aborted before dispatch." } });
|
|
131
|
+
await journal.recordError(key, "", "Workflow aborted before dispatch.", recordBase);
|
|
132
|
+
throw new WorkflowAbortedError();
|
|
133
|
+
}
|
|
134
|
+
if (budgetExhausted()) {
|
|
135
|
+
budgetExceeded = true;
|
|
136
|
+
hooks.emitProgress({ type: "agent", record: { ...recordBase, state: "error", error: "Token budget exhausted before dispatch." } });
|
|
137
|
+
await journal.recordError(key, "", "Token budget exhausted before dispatch.", recordBase);
|
|
138
|
+
throw new WorkflowBudgetExceededError(spent(), budgetTotal);
|
|
139
|
+
}
|
|
140
|
+
let identity;
|
|
141
|
+
let res;
|
|
142
|
+
try {
|
|
143
|
+
res = await hooks.runAgent({
|
|
144
|
+
index,
|
|
145
|
+
prompt,
|
|
146
|
+
label,
|
|
147
|
+
phase,
|
|
148
|
+
model: opts.model,
|
|
149
|
+
agentType: opts.agentType,
|
|
150
|
+
isolation: opts.isolation,
|
|
151
|
+
schema: opts.schema,
|
|
152
|
+
signal: hooks.abortSignal,
|
|
153
|
+
// Marker written BEFORE the agent runs, so an interruption leaves a
|
|
154
|
+
// `started`-without-`result` trail that the next resume can detect.
|
|
155
|
+
onStart: (started) => {
|
|
156
|
+
identity = started;
|
|
157
|
+
void journal.recordStarted(key, started.agentId, {
|
|
158
|
+
...recordBase,
|
|
159
|
+
address: started.address,
|
|
160
|
+
});
|
|
161
|
+
hooks.emitProgress({
|
|
162
|
+
type: "agent",
|
|
163
|
+
record: { ...recordBase, ...started, state: "running" },
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
170
|
+
hooks.emitProgress({
|
|
171
|
+
type: "agent",
|
|
172
|
+
record: { ...recordBase, ...(identity ?? {}), state: "error", error: msg },
|
|
173
|
+
});
|
|
174
|
+
// Recorded, not just emitted: "which step broke" is the first question asked of a run
|
|
175
|
+
// that came back empty, and progress events do not survive the process.
|
|
176
|
+
await journal.recordError(key, identity?.agentId ?? "", msg, {
|
|
177
|
+
...recordBase,
|
|
178
|
+
...(identity !== undefined ? { address: identity.address } : {}),
|
|
179
|
+
});
|
|
180
|
+
throw new Error(`agent "${label}" failed: ${msg}`);
|
|
181
|
+
}
|
|
182
|
+
localSpent += res.outputTokens;
|
|
183
|
+
await journal.recordResult(key, res.agentId, res.value, { ...recordBase, address: res.address });
|
|
184
|
+
hooks.emitProgress({
|
|
185
|
+
type: "agent",
|
|
186
|
+
record: { ...recordBase, agentId: res.agentId, address: res.address, state: "done", resultPreview: previewOf(res.value) },
|
|
187
|
+
});
|
|
188
|
+
return res.value;
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
// ---- parallel() -------------------------------------------------------
|
|
192
|
+
const parallel = harden(async (thunks) => {
|
|
193
|
+
checkCaps();
|
|
194
|
+
if (!Array.isArray(thunks))
|
|
195
|
+
throw new TypeError("parallel() expects an array of functions");
|
|
196
|
+
if (thunks.length === 0)
|
|
197
|
+
return [];
|
|
198
|
+
assertItemCount(thunks.length, "parallel");
|
|
199
|
+
for (const t of thunks) {
|
|
200
|
+
if (typeof t !== "function") {
|
|
201
|
+
throw new TypeError("parallel() expects an array of functions, not promises. Wrap each call: () => agent(...)");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const settled = await Promise.allSettled(thunks.map((t) => t()));
|
|
205
|
+
// Aborted mid-flight: propagate so the script unwinds instead of continuing
|
|
206
|
+
// past the (now meaningless) results into another agent() that would throw.
|
|
207
|
+
if (aborted())
|
|
208
|
+
throw new WorkflowAbortedError();
|
|
209
|
+
return settled.map((r, i) => {
|
|
210
|
+
if (r.status === "fulfilled")
|
|
211
|
+
return r.value;
|
|
212
|
+
if (r.reason instanceof WorkflowBudgetExceededError)
|
|
213
|
+
return null;
|
|
214
|
+
const msg = `parallel[${i}] failed: ${r.reason instanceof Error ? r.reason.message : String(r.reason)}`;
|
|
215
|
+
failures.push(msg);
|
|
216
|
+
hooks.emitProgress({ type: "log", message: msg });
|
|
217
|
+
void journal.recordLog(msg);
|
|
218
|
+
return null;
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
// ---- pipeline() -------------------------------------------------------
|
|
222
|
+
const pipeline = harden(async (items, ...stages) => {
|
|
223
|
+
checkCaps();
|
|
224
|
+
if (!Array.isArray(items))
|
|
225
|
+
throw new TypeError("pipeline() expects an array as the first argument");
|
|
226
|
+
if (items.length === 0)
|
|
227
|
+
return [];
|
|
228
|
+
assertItemCount(items.length, "pipeline");
|
|
229
|
+
for (const s of stages) {
|
|
230
|
+
if (typeof s !== "function") {
|
|
231
|
+
throw new TypeError("pipeline() stages must be functions: pipeline(items, item => ..., result => ...)");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const stageFns = stages;
|
|
235
|
+
const settled = await Promise.allSettled(items.map(async (item, index) => {
|
|
236
|
+
let value = item;
|
|
237
|
+
for (const stage of stageFns) {
|
|
238
|
+
if (value === null)
|
|
239
|
+
break;
|
|
240
|
+
value = await stage(value, item, index);
|
|
241
|
+
}
|
|
242
|
+
return value;
|
|
243
|
+
}));
|
|
244
|
+
if (aborted())
|
|
245
|
+
throw new WorkflowAbortedError();
|
|
246
|
+
return settled.map((r, i) => {
|
|
247
|
+
if (r.status === "fulfilled")
|
|
248
|
+
return r.value;
|
|
249
|
+
if (r.reason instanceof WorkflowBudgetExceededError)
|
|
250
|
+
return null;
|
|
251
|
+
const msg = `pipeline[${i}] failed: ${r.reason instanceof Error ? r.reason.message : String(r.reason)}`;
|
|
252
|
+
failures.push(msg);
|
|
253
|
+
hooks.emitProgress({ type: "log", message: msg });
|
|
254
|
+
void journal.recordLog(msg);
|
|
255
|
+
return null;
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
// ---- phase() / log() --------------------------------------------------
|
|
259
|
+
let phaseIndex = 0;
|
|
260
|
+
const seenPhases = new Map();
|
|
261
|
+
const resolvePhase = (title, kind = "normal") => {
|
|
262
|
+
let idx = seenPhases.get(title);
|
|
263
|
+
if (idx == null) {
|
|
264
|
+
idx = ++phaseIndex;
|
|
265
|
+
seenPhases.set(title, idx);
|
|
266
|
+
hooks.emitProgress({ type: "phase", index: idx, title, kind });
|
|
267
|
+
void journal.recordPhase(idx, title, kind);
|
|
268
|
+
}
|
|
269
|
+
return idx;
|
|
270
|
+
};
|
|
271
|
+
// Seed declared phases up front.
|
|
272
|
+
for (const p of meta.phases ?? [])
|
|
273
|
+
resolvePhase(p.title);
|
|
274
|
+
const phase = harden((title) => {
|
|
275
|
+
resolvePhase(String(title));
|
|
276
|
+
});
|
|
277
|
+
const log = harden((message) => {
|
|
278
|
+
const text = String(message);
|
|
279
|
+
hooks.emitProgress({ type: "log", message: text });
|
|
280
|
+
void journal.recordLog(text);
|
|
281
|
+
});
|
|
282
|
+
// ---- budget -----------------------------------------------------------
|
|
283
|
+
const budget = {
|
|
284
|
+
total: budgetTotal,
|
|
285
|
+
spent: harden(() => spent()),
|
|
286
|
+
remaining: harden(() => remaining()),
|
|
287
|
+
};
|
|
288
|
+
// ---- workflow() (nested, one level) -----------------------------------
|
|
289
|
+
const workflowHook = harden(async (nameOrRef, childArgs) => {
|
|
290
|
+
checkCaps();
|
|
291
|
+
if (depth >= 1) {
|
|
292
|
+
throw new Error("workflow() cannot be called from within a child workflow — nesting is limited to one level. " +
|
|
293
|
+
"Inline the inner script or call its agents directly.");
|
|
294
|
+
}
|
|
295
|
+
if (typeof nameOrRef !== "string") {
|
|
296
|
+
throw new TypeError("workflow() expects a saved workflow name (string)");
|
|
297
|
+
}
|
|
298
|
+
if (!hooks.resolveWorkflowScript) {
|
|
299
|
+
throw new Error(`workflow('${nameOrRef}'): named workflows are not available in this context`);
|
|
300
|
+
}
|
|
301
|
+
const script = await hooks.resolveWorkflowScript(nameOrRef);
|
|
302
|
+
if (!script)
|
|
303
|
+
throw new Error(`workflow('${nameOrRef}'): no workflow with that name`);
|
|
304
|
+
const { parseWorkflow } = await import("./parse.js");
|
|
305
|
+
const parsed = parseWorkflow(script);
|
|
306
|
+
if ("error" in parsed)
|
|
307
|
+
throw new Error(`workflow('${nameOrRef}'): ${parsed.error}`);
|
|
308
|
+
hooks.emitProgress({ type: "log", message: `▸ running nested workflow ${parsed.meta.name}` });
|
|
309
|
+
void journal.recordLog(`▸ running nested workflow ${parsed.meta.name}`);
|
|
310
|
+
const child = await runWorkflow({
|
|
311
|
+
meta: parsed.meta,
|
|
312
|
+
scriptBody: parsed.scriptBody,
|
|
313
|
+
args: childArgs,
|
|
314
|
+
hooks,
|
|
315
|
+
journal,
|
|
316
|
+
depth: depth + 1,
|
|
317
|
+
// Share the chain: the child continues the parent's key chain,
|
|
318
|
+
// so a nested workflow whose first agent() shares a prompt with the parent's
|
|
319
|
+
// gets a DIFFERENT key (prevKey differs) and can't collide on the journal.
|
|
320
|
+
chain,
|
|
321
|
+
});
|
|
322
|
+
if (!child.ok)
|
|
323
|
+
throw new Error(`workflow('${nameOrRef}'): ${child.error}`);
|
|
324
|
+
return child.result;
|
|
325
|
+
});
|
|
326
|
+
// ---- assemble globals + run ------------------------------------------
|
|
327
|
+
const globals = {
|
|
328
|
+
agent,
|
|
329
|
+
parallel,
|
|
330
|
+
pipeline,
|
|
331
|
+
phase,
|
|
332
|
+
log,
|
|
333
|
+
workflow: workflowHook,
|
|
334
|
+
budget,
|
|
335
|
+
args,
|
|
336
|
+
console: makeConsole(log),
|
|
337
|
+
};
|
|
338
|
+
const context = createSandboxContext(globals);
|
|
339
|
+
try {
|
|
340
|
+
const result = await runCompiled(compiled.vmScript, context);
|
|
341
|
+
return { ok: true, result, failures, agentCount };
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
// Abort: there is no external VM teardown, so propagate (the host folds usage in
|
|
345
|
+
// a finally, and a backgrounded run settles as "killed" via isAbortError).
|
|
346
|
+
if (err instanceof WorkflowAbortedError || aborted())
|
|
347
|
+
throw new WorkflowAbortedError();
|
|
348
|
+
if (capExceeded || budgetExceeded) {
|
|
349
|
+
// Soft stop — return what we have; the error is informational.
|
|
350
|
+
return { ok: true, result: undefined, failures: [...failures, errMsg(err)], agentCount };
|
|
351
|
+
}
|
|
352
|
+
return { ok: false, error: errMsg(err), failures, agentCount };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function makeConsole(log) {
|
|
356
|
+
const fmt = (parts) => parts.map((p) => (typeof p === "string" ? p : safeStringify(p))).join(" ");
|
|
357
|
+
return {
|
|
358
|
+
log: (...a) => log(fmt(a)),
|
|
359
|
+
info: (...a) => log(fmt(a)),
|
|
360
|
+
debug: (...a) => log(fmt(a)),
|
|
361
|
+
warn: (...a) => log(`[warn] ${fmt(a)}`),
|
|
362
|
+
error: (...a) => log(`[error] ${fmt(a)}`),
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function safeStringify(value) {
|
|
366
|
+
try {
|
|
367
|
+
return JSON.stringify(value);
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
return String(value);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function previewOf(value) {
|
|
374
|
+
const s = typeof value === "string" ? value : safeStringify(value);
|
|
375
|
+
return s.length > 400 ? `${s.slice(0, 400)}…` : s;
|
|
376
|
+
}
|
|
377
|
+
function errMsg(err) {
|
|
378
|
+
return err instanceof Error ? err.message : String(err);
|
|
379
|
+
}
|
|
380
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow sandbox — script compilation plus determinism/escape hardening:
|
|
3
|
+
* - the async IIFE runs in `'use strict'`, so `with` is a SyntaxError and
|
|
4
|
+
* silent-failure footguns become throws;
|
|
5
|
+
* - dynamic `import()` is rejected (no importModuleDynamically callback is
|
|
6
|
+
* provided to vm, so any import() throws — we machine a clear message).
|
|
7
|
+
*
|
|
8
|
+
* Node's built-in `vm` is NOT a security sandbox on its own; the hardening here
|
|
9
|
+
* covers the realistic failure modes: strip `constructor`/`prototype` off injected functions,
|
|
10
|
+
* make Date/Math.random throw (so runs are deterministic and journaling/resume
|
|
11
|
+
* is stable), and remove a few escape-prone globals. The script is authored by
|
|
12
|
+
* our own model, so this guards against non-determinism + casual escapes rather
|
|
13
|
+
* than a determined attacker.
|
|
14
|
+
*/
|
|
15
|
+
import vm from "node:vm";
|
|
16
|
+
export type CompileResult = {
|
|
17
|
+
ok: true;
|
|
18
|
+
vmScript: vm.Script;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
/** Wrap the script body in a strict async IIFE, syntax-check it, then compile. */
|
|
24
|
+
export declare function compileScriptBody(body: string): CompileResult;
|
|
25
|
+
/**
|
|
26
|
+
* Strip `constructor`/`prototype` off an injected function and null its
|
|
27
|
+
* prototype, so script code cannot reach the host `Function` constructor
|
|
28
|
+
* via `agent.constructor("...")`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function harden<T extends object>(fn: T): T;
|
|
31
|
+
/** Create a hardened VM context populated with the given globals. */
|
|
32
|
+
export declare function createSandboxContext(globals: Record<string, unknown>): vm.Context;
|
|
33
|
+
/** Run a compiled workflow script in a hardened context. Returns its resolved value. */
|
|
34
|
+
export declare function runCompiled(vmScript: vm.Script, context: vm.Context): Promise<unknown>;
|
|
35
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow sandbox — script compilation plus determinism/escape hardening:
|
|
3
|
+
* - the async IIFE runs in `'use strict'`, so `with` is a SyntaxError and
|
|
4
|
+
* silent-failure footguns become throws;
|
|
5
|
+
* - dynamic `import()` is rejected (no importModuleDynamically callback is
|
|
6
|
+
* provided to vm, so any import() throws — we machine a clear message).
|
|
7
|
+
*
|
|
8
|
+
* Node's built-in `vm` is NOT a security sandbox on its own; the hardening here
|
|
9
|
+
* covers the realistic failure modes: strip `constructor`/`prototype` off injected functions,
|
|
10
|
+
* make Date/Math.random throw (so runs are deterministic and journaling/resume
|
|
11
|
+
* is stable), and remove a few escape-prone globals. The script is authored by
|
|
12
|
+
* our own model, so this guards against non-determinism + casual escapes rather
|
|
13
|
+
* than a determined attacker.
|
|
14
|
+
*/
|
|
15
|
+
import vm from "node:vm";
|
|
16
|
+
import { WORKFLOW_VM_TIMEOUT_MS } from "./types.js";
|
|
17
|
+
/** Wrap the script body in a strict async IIFE, syntax-check it, then compile. */
|
|
18
|
+
export function compileScriptBody(body) {
|
|
19
|
+
const wrapped = `(async () => {'use strict';\n${body}\n})()`;
|
|
20
|
+
try {
|
|
21
|
+
// Parse-only pre-check (does not execute) for a clean SyntaxError message.
|
|
22
|
+
// 'use strict' here too so `with`/duplicate params/etc. are caught the same way.
|
|
23
|
+
// eslint-disable-next-line no-new-func
|
|
24
|
+
new Function(`async function _check() {'use strict';\n${body}\n}`);
|
|
25
|
+
return { ok: true, vmScript: new vm.Script(wrapped, { filename: "workflow.js" }) };
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return { ok: false, error: `SyntaxError: ${err instanceof Error ? err.message : String(err)}` };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const NOW_ERR = "Date.now() / new Date() are unavailable in workflow scripts (breaks resume). " +
|
|
32
|
+
"Stamp results after the workflow returns, or pass timestamps via args.";
|
|
33
|
+
const RANDOM_ERR = "Math.random() is unavailable in workflow scripts (breaks resume). " +
|
|
34
|
+
"For N independent samples, include the index in the agent label or prompt.";
|
|
35
|
+
/** Determinism shim — Date/Math.random throw. */
|
|
36
|
+
const DETERMINISM_SHIM = `(() => {
|
|
37
|
+
const NOW_ERR = ${JSON.stringify(NOW_ERR)};
|
|
38
|
+
const RANDOM_ERR = ${JSON.stringify(RANDOM_ERR)};
|
|
39
|
+
Math.random = function random() { throw new Error(RANDOM_ERR); };
|
|
40
|
+
const RealDate = Date;
|
|
41
|
+
RealDate.now = function now() { throw new Error(NOW_ERR); };
|
|
42
|
+
function ShimDate(...a) {
|
|
43
|
+
if (!new.target) throw new Error(NOW_ERR);
|
|
44
|
+
if (a.length === 0) throw new Error(NOW_ERR);
|
|
45
|
+
return Reflect.construct(RealDate, a, new.target);
|
|
46
|
+
}
|
|
47
|
+
ShimDate.now = RealDate.now;
|
|
48
|
+
ShimDate.parse = RealDate.parse;
|
|
49
|
+
ShimDate.UTC = RealDate.UTC;
|
|
50
|
+
ShimDate.prototype = RealDate.prototype;
|
|
51
|
+
RealDate.prototype.constructor = ShimDate;
|
|
52
|
+
Object.freeze(RealDate);
|
|
53
|
+
globalThis.Date = ShimDate;
|
|
54
|
+
})()`;
|
|
55
|
+
/** Escape hardening — neuter stack-trace backdoor, drop escape-prone globals. */
|
|
56
|
+
const ESCAPE_SHIM = `(() => {
|
|
57
|
+
Object.defineProperty(Error, 'prepareStackTrace', {
|
|
58
|
+
value: (err, sites) => String(err && err.stack ? err.stack : err),
|
|
59
|
+
writable: false, configurable: false,
|
|
60
|
+
});
|
|
61
|
+
try { delete globalThis.ShadowRealm; } catch {}
|
|
62
|
+
try { delete globalThis.WebAssembly; } catch {}
|
|
63
|
+
})()`;
|
|
64
|
+
/**
|
|
65
|
+
* Strip `constructor`/`prototype` off an injected function and null its
|
|
66
|
+
* prototype, so script code cannot reach the host `Function` constructor
|
|
67
|
+
* via `agent.constructor("...")`.
|
|
68
|
+
*/
|
|
69
|
+
export function harden(fn) {
|
|
70
|
+
Object.setPrototypeOf(fn, null);
|
|
71
|
+
const f = fn;
|
|
72
|
+
delete f.constructor;
|
|
73
|
+
delete f.prototype;
|
|
74
|
+
return fn;
|
|
75
|
+
}
|
|
76
|
+
/** Create a hardened VM context populated with the given globals. */
|
|
77
|
+
export function createSandboxContext(globals) {
|
|
78
|
+
const context = vm.createContext(globals);
|
|
79
|
+
vm.runInContext(DETERMINISM_SHIM, context);
|
|
80
|
+
vm.runInContext(ESCAPE_SHIM, context);
|
|
81
|
+
return context;
|
|
82
|
+
}
|
|
83
|
+
/** Run a compiled workflow script in a hardened context. Returns its resolved value. */
|
|
84
|
+
export async function runCompiled(vmScript, context) {
|
|
85
|
+
// The timeout bounds only the SYNCHRONOUS prefix until the first await; long
|
|
86
|
+
// agent() awaits are not killed by it. A purely-synchronous infinite loop is.
|
|
87
|
+
const result = await vmScript.runInContext(context, { timeout: WORKFLOW_VM_TIMEOUT_MS });
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow run discovery types. A BACKGROUND workflow run is a task, so `/workflows` lists
|
|
3
|
+
* runs from the durable task store (see `session.listWorkflows`, which projects task records
|
|
4
|
+
* into `WorkflowSnapshot`). A foreground workflow is a plain `Workflow` tool call — its record
|
|
5
|
+
* is the conversation plus its journal shard. `WorkflowRunDetails` is the structured `details`
|
|
6
|
+
* a Workflow tool result carries as the human/model-facing record.
|
|
7
|
+
*/
|
|
8
|
+
export type WorkflowSnapshotStatus = "running" | "completed" | "failed" | "aborted";
|
|
9
|
+
/** A discovery row for one run — enough to list past runs and pick a runId to resume. */
|
|
10
|
+
export interface WorkflowSnapshot {
|
|
11
|
+
readonly runId: string;
|
|
12
|
+
readonly workflowName: string;
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
readonly status: WorkflowSnapshotStatus;
|
|
15
|
+
readonly background: boolean;
|
|
16
|
+
/** The background task handle from the spawn ack (background runs only). */
|
|
17
|
+
readonly taskId?: string;
|
|
18
|
+
/** ISO timestamps (stamped by the host, not inside the deterministic sandbox). */
|
|
19
|
+
readonly startedAt: string;
|
|
20
|
+
readonly endedAt?: string;
|
|
21
|
+
readonly outputTokens?: number;
|
|
22
|
+
}
|
|
23
|
+
/** The structured `details` every Workflow tool result carries — what the fold reads. */
|
|
24
|
+
export interface WorkflowRunDetails {
|
|
25
|
+
readonly workflow: string;
|
|
26
|
+
readonly runId: string;
|
|
27
|
+
readonly status: WorkflowSnapshotStatus;
|
|
28
|
+
readonly background?: boolean;
|
|
29
|
+
readonly description?: string;
|
|
30
|
+
readonly taskId?: string;
|
|
31
|
+
readonly startedAt?: string;
|
|
32
|
+
readonly endedAt?: string;
|
|
33
|
+
readonly usage?: unknown;
|
|
34
|
+
readonly outputTokens?: number;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow run discovery types. A BACKGROUND workflow run is a task, so `/workflows` lists
|
|
3
|
+
* runs from the durable task store (see `session.listWorkflows`, which projects task records
|
|
4
|
+
* into `WorkflowSnapshot`). A foreground workflow is a plain `Workflow` tool call — its record
|
|
5
|
+
* is the conversation plus its journal shard. `WorkflowRunDetails` is the structured `details`
|
|
6
|
+
* a Workflow tool result carries as the human/model-facing record.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured-output enforcement.
|
|
3
|
+
*
|
|
4
|
+
* Instead of asking the subagent to emit JSON as prose and parsing the text
|
|
5
|
+
* (fragile), we inject a `StructuredOutput` tool whose parameter schema IS the
|
|
6
|
+
* caller's JSON Schema. The subagent is forced to call it; calling it ends the
|
|
7
|
+
* turn (`stopTurn`) and captures the argument. We then validate with Ajv and, on
|
|
8
|
+
* a miss (or no call), nudge in the SAME conversation and retry.
|
|
9
|
+
*/
|
|
10
|
+
import { type ValidateFunction } from "ajv";
|
|
11
|
+
import { Agent } from "../agent.ts";
|
|
12
|
+
import type { Tool } from "../../tool/types.ts";
|
|
13
|
+
/** Compile (and cache) an Ajv validator for a JSON Schema. Throws if invalid. */
|
|
14
|
+
export declare function getValidator(schema: Record<string, unknown>): ValidateFunction;
|
|
15
|
+
export declare function validateValue(schema: Record<string, unknown>, value: unknown): {
|
|
16
|
+
ok: true;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
/** Mutable capture cell shared between the injected tool and the run loop. */
|
|
22
|
+
export interface StructuredCapture {
|
|
23
|
+
called: boolean;
|
|
24
|
+
value: unknown;
|
|
25
|
+
}
|
|
26
|
+
/** Build a StructuredOutput tool whose parameters are the given JSON Schema. */
|
|
27
|
+
export declare function makeStructuredOutputTool(schema: Record<string, unknown>): {
|
|
28
|
+
tool: Tool;
|
|
29
|
+
capture: StructuredCapture;
|
|
30
|
+
};
|
|
31
|
+
/** Clone an agent, appending one extra tool (the StructuredOutput injector). */
|
|
32
|
+
export declare function cloneAgentWithTool<TContext>(sub: Agent<TContext>, extra: Tool): Agent<TContext>;
|
|
33
|
+
/** Instruction appended to the prompt so the subagent knows to call the tool. */
|
|
34
|
+
export declare function structuredInstruction(schema: Record<string, unknown>): string;
|
|
35
|
+
//# sourceMappingURL=structured.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured-output enforcement.
|
|
3
|
+
*
|
|
4
|
+
* Instead of asking the subagent to emit JSON as prose and parsing the text
|
|
5
|
+
* (fragile), we inject a `StructuredOutput` tool whose parameter schema IS the
|
|
6
|
+
* caller's JSON Schema. The subagent is forced to call it; calling it ends the
|
|
7
|
+
* turn (`stopTurn`) and captures the argument. We then validate with Ajv and, on
|
|
8
|
+
* a miss (or no call), nudge in the SAME conversation and retry.
|
|
9
|
+
*/
|
|
10
|
+
import Ajv, {} from "ajv";
|
|
11
|
+
import { Agent } from "../agent.js";
|
|
12
|
+
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
13
|
+
const validators = new Map();
|
|
14
|
+
/** Compile (and cache) an Ajv validator for a JSON Schema. Throws if invalid. */
|
|
15
|
+
export function getValidator(schema) {
|
|
16
|
+
const cacheKey = JSON.stringify(schema);
|
|
17
|
+
const existing = validators.get(cacheKey);
|
|
18
|
+
if (existing)
|
|
19
|
+
return existing;
|
|
20
|
+
const compiled = ajv.compile(schema);
|
|
21
|
+
validators.set(cacheKey, compiled);
|
|
22
|
+
return compiled;
|
|
23
|
+
}
|
|
24
|
+
export function validateValue(schema, value) {
|
|
25
|
+
const validate = getValidator(schema);
|
|
26
|
+
if (validate(value))
|
|
27
|
+
return { ok: true };
|
|
28
|
+
return { ok: false, error: ajv.errorsText(validate.errors, { separator: "; " }) };
|
|
29
|
+
}
|
|
30
|
+
/** Build a StructuredOutput tool whose parameters are the given JSON Schema. */
|
|
31
|
+
export function makeStructuredOutputTool(schema) {
|
|
32
|
+
const capture = { called: false, value: undefined };
|
|
33
|
+
let pending;
|
|
34
|
+
const tool = {
|
|
35
|
+
schema: {
|
|
36
|
+
name: "StructuredOutput",
|
|
37
|
+
description: "Return your final answer as a single object matching the required JSON schema. " +
|
|
38
|
+
"Call this exactly once — its argument IS your answer, and calling it ends your turn. " +
|
|
39
|
+
"Do not put the answer in prose.",
|
|
40
|
+
parameters: schema,
|
|
41
|
+
},
|
|
42
|
+
resolve: (args) => {
|
|
43
|
+
pending = args;
|
|
44
|
+
return {
|
|
45
|
+
approvalRule: "StructuredOutput",
|
|
46
|
+
run: async () => {
|
|
47
|
+
capture.called = true;
|
|
48
|
+
capture.value = pending;
|
|
49
|
+
return { content: [{ type: "text", text: "Structured output recorded." }], stopTurn: true };
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
return { tool, capture };
|
|
55
|
+
}
|
|
56
|
+
/** Clone an agent, appending one extra tool (the StructuredOutput injector). */
|
|
57
|
+
export function cloneAgentWithTool(sub, extra) {
|
|
58
|
+
return new Agent({
|
|
59
|
+
name: sub.name,
|
|
60
|
+
instructions: sub.instructions,
|
|
61
|
+
handoffDescription: sub.handoffDescription,
|
|
62
|
+
model: sub.model,
|
|
63
|
+
modelSettings: sub.modelSettings,
|
|
64
|
+
tools: [...sub.tools, extra],
|
|
65
|
+
handoffs: sub.handoffs,
|
|
66
|
+
subagents: sub.subagents,
|
|
67
|
+
guardrails: sub.guardrails,
|
|
68
|
+
outputType: sub.outputType,
|
|
69
|
+
maxStepsPerTurn: sub.maxStepsPerTurn,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** Instruction appended to the prompt so the subagent knows to call the tool. */
|
|
73
|
+
export function structuredInstruction(schema) {
|
|
74
|
+
return ("\n\nIMPORTANT: When you have your answer, call the StructuredOutput tool exactly once " +
|
|
75
|
+
"with a single argument matching this JSON Schema. The tool argument IS your answer — " +
|
|
76
|
+
"do not also write it as prose.\nSchema:\n" +
|
|
77
|
+
JSON.stringify(schema, null, 2));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=structured.js.map
|