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,576 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { PassThrough } from "node:stream";
|
|
4
|
+
import { posix } from "node:path";
|
|
5
|
+
import * as ssh2 from "ssh2";
|
|
6
|
+
import { FileExistsError, } from "./machine.js";
|
|
7
|
+
import { BaseMachine } from "./machine-base.js";
|
|
8
|
+
import { fileVersionFromInfo } from "./support/machine-ops.js";
|
|
9
|
+
import { proxyEnv } from "./shell-env.js";
|
|
10
|
+
const FALLBACK_SFTP_STATUS = {
|
|
11
|
+
NO_SUCH_FILE: 2,
|
|
12
|
+
PERMISSION_DENIED: 3,
|
|
13
|
+
NO_CONNECTION: 6,
|
|
14
|
+
CONNECTION_LOST: 7,
|
|
15
|
+
};
|
|
16
|
+
function codedError(message, code) {
|
|
17
|
+
const error = new Error(message);
|
|
18
|
+
error.code = code;
|
|
19
|
+
return error;
|
|
20
|
+
}
|
|
21
|
+
function sftpStatusCode() {
|
|
22
|
+
return { ...FALLBACK_SFTP_STATUS, ...ssh2.utils?.sftp?.STATUS_CODE };
|
|
23
|
+
}
|
|
24
|
+
function mapSftpError(operation, error) {
|
|
25
|
+
const raw = typeof error === "object" && error !== null ? error.code : undefined;
|
|
26
|
+
const code = typeof raw === "number" ? raw : undefined;
|
|
27
|
+
const message = `${operation} failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
28
|
+
const status = sftpStatusCode();
|
|
29
|
+
if (code === status.NO_SUCH_FILE)
|
|
30
|
+
return codedError(message, "ENOENT");
|
|
31
|
+
if (code === status.PERMISSION_DENIED)
|
|
32
|
+
return codedError(message, "EACCES");
|
|
33
|
+
if (code === status.NO_CONNECTION || code === status.CONNECTION_LOST)
|
|
34
|
+
return codedError(message, "ECONNRESET");
|
|
35
|
+
return codedError(message, "EIO");
|
|
36
|
+
}
|
|
37
|
+
export function sshShellQuote(arg) {
|
|
38
|
+
if (arg === "")
|
|
39
|
+
return "''";
|
|
40
|
+
if (/^[A-Za-z0-9_./:=@%^,+-]+$/.test(arg))
|
|
41
|
+
return arg;
|
|
42
|
+
return "'" + arg.replaceAll("'", "'\"'\"'") + "'";
|
|
43
|
+
}
|
|
44
|
+
export function buildSshExecCommand(args, cwd, env) {
|
|
45
|
+
let command = args.map((arg) => sshShellQuote(arg)).join(" ");
|
|
46
|
+
if (env !== undefined) {
|
|
47
|
+
const assignments = [];
|
|
48
|
+
for (const [key, value] of Object.entries(env)) {
|
|
49
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
|
|
50
|
+
throw new Error(`SshMachine: invalid env variable name ${JSON.stringify(key)}`);
|
|
51
|
+
}
|
|
52
|
+
assignments.push(`${key}=${sshShellQuote(value)}`);
|
|
53
|
+
}
|
|
54
|
+
if (assignments.length > 0)
|
|
55
|
+
command = `${assignments.join(" ")} ${command}`;
|
|
56
|
+
}
|
|
57
|
+
if (cwd !== "")
|
|
58
|
+
command = `cd ${sshShellQuote(cwd)} && ${command}`;
|
|
59
|
+
return command;
|
|
60
|
+
}
|
|
61
|
+
function fileKindFromSftpStats(attrs) {
|
|
62
|
+
if (attrs.isFile())
|
|
63
|
+
return "file";
|
|
64
|
+
if (attrs.isDirectory())
|
|
65
|
+
return "dir";
|
|
66
|
+
if (attrs.isSymbolicLink())
|
|
67
|
+
return "symlink";
|
|
68
|
+
return "other";
|
|
69
|
+
}
|
|
70
|
+
export class SshProcess {
|
|
71
|
+
stdin;
|
|
72
|
+
stdout;
|
|
73
|
+
stderr;
|
|
74
|
+
_exitCode = null;
|
|
75
|
+
_exit;
|
|
76
|
+
channel;
|
|
77
|
+
constructor(channel) {
|
|
78
|
+
this.channel = channel;
|
|
79
|
+
this.stdin = channel;
|
|
80
|
+
// Buffer through PassThroughs so output emitted before a consumer attaches isn't dropped.
|
|
81
|
+
const out = new PassThrough();
|
|
82
|
+
const err = new PassThrough();
|
|
83
|
+
channel.pipe(out);
|
|
84
|
+
channel.stderr.pipe(err);
|
|
85
|
+
this.stdout = out;
|
|
86
|
+
this.stderr = err;
|
|
87
|
+
this._exit = new Promise((resolve) => {
|
|
88
|
+
// Resolve on 'close' (all buffered output flushed); 'exit' carries the code on some backends.
|
|
89
|
+
channel.on("exit", (code) => {
|
|
90
|
+
this._exitCode = code ?? 1;
|
|
91
|
+
});
|
|
92
|
+
channel.on("close", (code) => {
|
|
93
|
+
this._exitCode ??= code ?? 1;
|
|
94
|
+
resolve(this._exitCode);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
get exitCode() {
|
|
99
|
+
return this._exitCode;
|
|
100
|
+
}
|
|
101
|
+
wait() {
|
|
102
|
+
return this._exit;
|
|
103
|
+
}
|
|
104
|
+
kill(signal = "SIGTERM") {
|
|
105
|
+
const sshSignal = signal.startsWith("SIG") ? signal.slice(3) : signal;
|
|
106
|
+
this.channel.signal(sshSignal);
|
|
107
|
+
return Promise.resolve();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function connectClient(config) {
|
|
111
|
+
const client = new ssh2.Client();
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
client.on("ready", () => resolve(client));
|
|
114
|
+
client.on("error", (err) => reject(err));
|
|
115
|
+
client.connect(config);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function getSftp(client) {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
client.sftp((err, sftp) => (err ? reject(err) : resolve(sftp)));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function clientExec(client, command) {
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
client.exec(command, (err, channel) => (err ? reject(err) : resolve(channel)));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function sftpRealpath(sftp, path) {
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
sftp.realpath(path, (err, abs) => (err ? reject(mapSftpError("realpath", err)) : resolve(abs)));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function sftpStat(sftp, path) {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
sftp.stat(path, (err, stats) => (err ? reject(mapSftpError("stat", err)) : resolve(stats)));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function sftpLstat(sftp, path) {
|
|
139
|
+
return new Promise((resolve, reject) => {
|
|
140
|
+
sftp.lstat(path, (err, stats) => (err ? reject(mapSftpError("lstat", err)) : resolve(stats)));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function sftpReaddir(sftp, path) {
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
sftp.readdir(path, (err, list) => (err ? reject(mapSftpError("readdir", err)) : resolve(list)));
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function sftpMkdir(sftp, path) {
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
|
+
sftp.mkdir(path, (err) => (err ? reject(mapSftpError("mkdir", err)) : resolve()));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function sftpExists(sftp, path) {
|
|
154
|
+
return new Promise((resolve) => sftp.exists(path, (exists) => resolve(exists)));
|
|
155
|
+
}
|
|
156
|
+
/** Occupant kind probe for mkdir: `exists` alone can't tell a file from a directory, and
|
|
157
|
+
* mkdir's `existOk`/`parents` semantics only tolerate DIRECTORY occupants. */
|
|
158
|
+
async function sftpKindOf(sftp, path) {
|
|
159
|
+
try {
|
|
160
|
+
const attrs = await sftpStat(sftp, path);
|
|
161
|
+
return attrs.isDirectory() ? "dir" : "other";
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return undefined; // missing (or unstat-able — the subsequent mkdir surfaces the real error)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function sftpReadFile(sftp, path) {
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
sftp.readFile(path, (err, data) => (err ? reject(mapSftpError("readFile", err)) : resolve(data)));
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function sftpWriteFile(sftp, path, data) {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
sftp.writeFile(path, data, (err) => (err ? reject(mapSftpError("writeFile", err)) : resolve()));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function sftpOpen(sftp, path, flags) {
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
|
+
sftp.open(path, flags, (err, handle) => (err ? reject(mapSftpError("open", err)) : resolve(handle)));
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** Reads at most `length` bytes starting at `offset` — a genuine windowed read, not a
|
|
183
|
+
* whole-file transfer that gets sliced afterwards. */
|
|
184
|
+
function sftpReadHandle(sftp, handle, offset, length) {
|
|
185
|
+
return new Promise((resolve, reject) => {
|
|
186
|
+
const buf = Buffer.alloc(length);
|
|
187
|
+
sftp.read(handle, buf, 0, length, offset, (err, bytesRead) => {
|
|
188
|
+
// EOF before `length` bytes arrives as an error on some servers; an empty read is
|
|
189
|
+
// the honest answer there, not a failure.
|
|
190
|
+
if (err)
|
|
191
|
+
return bytesRead ? resolve(buf.subarray(0, bytesRead)) : resolve(Buffer.alloc(0));
|
|
192
|
+
resolve(buf.subarray(0, bytesRead));
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function sftpClose(sftp, handle) {
|
|
197
|
+
return new Promise((resolve) => sftp.close(handle, () => resolve()));
|
|
198
|
+
}
|
|
199
|
+
function sftpWriteHandle(sftp, handle, data) {
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
// ssh2 chunks writes beyond the server's max packet size internally.
|
|
202
|
+
sftp.write(handle, data, 0, data.byteLength, 0, (err) => (err ? reject(mapSftpError("write", err)) : resolve()));
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function sftpCloseHandle(sftp, handle) {
|
|
206
|
+
return new Promise((resolve, reject) => {
|
|
207
|
+
sftp.close(handle, (err) => (err ? reject(mapSftpError("close", err)) : resolve()));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function sftpUnlink(sftp, path) {
|
|
211
|
+
return new Promise((resolve, reject) => {
|
|
212
|
+
sftp.unlink(path, (err) => (err ? reject(mapSftpError("unlink", err)) : resolve()));
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function sftpRename(sftp, src, dst) {
|
|
216
|
+
return new Promise((resolve, reject) => {
|
|
217
|
+
sftp.rename(src, dst, (err) => (err ? reject(mapSftpError("rename", err)) : resolve()));
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function sftpSetstat(sftp, path, attrs) {
|
|
221
|
+
return new Promise((resolve, reject) => {
|
|
222
|
+
sftp.setstat(path, attrs, (err) => (err ? reject(mapSftpError("setstat", err)) : resolve()));
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Atomic overwriting rename: posix-rename@openssh.com when the server offers it.
|
|
227
|
+
* ONLY the unsupported-extension error falls back to unlink+rename (which has a tiny
|
|
228
|
+
* no-file window between the two calls) — any real failure propagates untouched,
|
|
229
|
+
* because unlinking the destination after e.g. a permission error would delete the
|
|
230
|
+
* target with no replacement guaranteed.
|
|
231
|
+
*/
|
|
232
|
+
async function sftpAtomicRename(sftp, src, dst) {
|
|
233
|
+
try {
|
|
234
|
+
await new Promise((resolve, reject) => {
|
|
235
|
+
// ssh2 throws synchronously when the server lacks the extension; the
|
|
236
|
+
// executor converts that throw into a rejection.
|
|
237
|
+
sftp.ext_openssh_rename(src, dst, (err) => (err ? reject(mapSftpError("rename", err)) : resolve()));
|
|
238
|
+
});
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
const unsupported = error instanceof Error && /does not support this extended request/i.test(error.message);
|
|
243
|
+
if (!unsupported)
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
await sftpUnlink(sftp, dst);
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
if (error.code !== "ENOENT")
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
await sftpRename(sftp, src, dst); // SFTP v3 rename refuses to overwrite — dst is gone by now
|
|
254
|
+
}
|
|
255
|
+
function buildAuthHandler(username, privateKeys, password) {
|
|
256
|
+
const queue = privateKeys.map((key) => ({ key, type: "publickey", username }));
|
|
257
|
+
if (password !== undefined)
|
|
258
|
+
queue.push({ password, type: "password", username });
|
|
259
|
+
let index = 0;
|
|
260
|
+
return (_authsLeft, _partialSuccess, next) => {
|
|
261
|
+
const nextAuth = queue[index];
|
|
262
|
+
index += 1;
|
|
263
|
+
next(nextAuth ?? false);
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/** Deadline for the env probe: the probe is best-effort (failure already falls back to
|
|
267
|
+
* defaults), but a server that never closes the exec channel — a restricted shell, an
|
|
268
|
+
* unclean close — must not hang `SshMachine.create()` forever. */
|
|
269
|
+
const PROBE_TIMEOUT_MS = 10_000;
|
|
270
|
+
async function probeRemoteEnvironment(client) {
|
|
271
|
+
let raw = "";
|
|
272
|
+
try {
|
|
273
|
+
raw = await new Promise((resolve, reject) => {
|
|
274
|
+
// Timeout resolves to "" — the same defaults path a failed probe takes. NOT unref'd:
|
|
275
|
+
// this timer is what unblocks create() when the channel never closes.
|
|
276
|
+
const timer = setTimeout(() => resolve(""), PROBE_TIMEOUT_MS);
|
|
277
|
+
clientExec(client, 'uname -s; uname -m; uname -r; printf "%s" "${SHELL:-/bin/sh}"').then((channel) => {
|
|
278
|
+
const chunks = [];
|
|
279
|
+
channel.on("data", (d) => chunks.push(Buffer.isBuffer(d) ? d : Buffer.from(String(d))));
|
|
280
|
+
channel.on("close", () => {
|
|
281
|
+
clearTimeout(timer);
|
|
282
|
+
resolve(Buffer.concat(chunks).toString("utf-8"));
|
|
283
|
+
});
|
|
284
|
+
}, (error) => {
|
|
285
|
+
clearTimeout(timer);
|
|
286
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
/* fall through to defaults */
|
|
292
|
+
}
|
|
293
|
+
const [sysname = "", machine = "", osVersion = "", shell = ""] = raw.split("\n").map((line) => line.trim());
|
|
294
|
+
const osKind = /^linux/i.test(sysname)
|
|
295
|
+
? "Linux"
|
|
296
|
+
: /^darwin/i.test(sysname)
|
|
297
|
+
? "Darwin"
|
|
298
|
+
: /mingw|msys|cygwin|windows/i.test(sysname)
|
|
299
|
+
? "Windows"
|
|
300
|
+
: sysname.length > 0
|
|
301
|
+
? sysname
|
|
302
|
+
: "Linux";
|
|
303
|
+
const shellPath = shell.length > 0 ? shell : "/bin/sh";
|
|
304
|
+
const shellName = posix.basename(shellPath);
|
|
305
|
+
return { osKind, osArch: machine || "unknown", osVersion: osVersion || "unknown", shellName, shellPath };
|
|
306
|
+
}
|
|
307
|
+
export class SshMachine extends BaseMachine {
|
|
308
|
+
name;
|
|
309
|
+
osEnv;
|
|
310
|
+
client;
|
|
311
|
+
sftp;
|
|
312
|
+
home;
|
|
313
|
+
cwd;
|
|
314
|
+
injectedEnv;
|
|
315
|
+
extraDirs;
|
|
316
|
+
constructor(args) {
|
|
317
|
+
super();
|
|
318
|
+
this.client = args.client;
|
|
319
|
+
this.sftp = args.sftp;
|
|
320
|
+
this.home = args.home;
|
|
321
|
+
this.cwd = args.cwd;
|
|
322
|
+
this.osEnv = args.osEnv;
|
|
323
|
+
this.name = args.name;
|
|
324
|
+
this.injectedEnv = args.injectedEnv;
|
|
325
|
+
this.extraDirs = args.additionalDirs;
|
|
326
|
+
}
|
|
327
|
+
static fromConnection(args) {
|
|
328
|
+
return new SshMachine({
|
|
329
|
+
client: args.client,
|
|
330
|
+
sftp: args.sftp,
|
|
331
|
+
home: args.home,
|
|
332
|
+
cwd: args.cwd ?? args.home,
|
|
333
|
+
osEnv: args.osEnv,
|
|
334
|
+
name: args.name ?? "ssh",
|
|
335
|
+
injectedEnv: args.injectedEnv ?? {},
|
|
336
|
+
additionalDirs: args.additionalDirs ?? [],
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
static async create(options) {
|
|
340
|
+
const config = {
|
|
341
|
+
...options.extraOptions,
|
|
342
|
+
host: options.host,
|
|
343
|
+
port: options.port ?? 22,
|
|
344
|
+
username: options.username,
|
|
345
|
+
};
|
|
346
|
+
if (options.password !== undefined)
|
|
347
|
+
config.password = options.password;
|
|
348
|
+
const privateKeys = [...(options.keyContents ?? [])];
|
|
349
|
+
if (options.keyPaths) {
|
|
350
|
+
const loaded = await Promise.all(options.keyPaths.map((p) => readFile(p, "utf-8")));
|
|
351
|
+
privateKeys.push(...loaded);
|
|
352
|
+
}
|
|
353
|
+
if (privateKeys.length > 0) {
|
|
354
|
+
const handler = buildAuthHandler(options.username, privateKeys, options.password);
|
|
355
|
+
if (handler !== undefined)
|
|
356
|
+
config.authHandler = handler;
|
|
357
|
+
}
|
|
358
|
+
config.hostVerifier = options.hostVerifier ?? (() => true);
|
|
359
|
+
const client = await connectClient(config);
|
|
360
|
+
try {
|
|
361
|
+
const sftp = await getSftp(client);
|
|
362
|
+
const home = await sftpRealpath(sftp, ".");
|
|
363
|
+
let cwd = home;
|
|
364
|
+
if (options.cwd !== undefined) {
|
|
365
|
+
cwd = await sftpRealpath(sftp, options.cwd);
|
|
366
|
+
const attrs = await sftpStat(sftp, cwd);
|
|
367
|
+
if (!attrs.isDirectory())
|
|
368
|
+
throw codedError(`${cwd} is not a directory`, "ENOTDIR");
|
|
369
|
+
}
|
|
370
|
+
const osEnv = await probeRemoteEnvironment(client);
|
|
371
|
+
const injectedEnv = options.forwardProxyEnv === false ? {} : proxyEnv();
|
|
372
|
+
return new SshMachine({ client, sftp, home, cwd, osEnv, name: options.name ?? `ssh:${options.host}`, injectedEnv, additionalDirs: options.additionalDirs ?? [] });
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
client.end();
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
pathClass() {
|
|
380
|
+
return "posix";
|
|
381
|
+
}
|
|
382
|
+
normpath(path) {
|
|
383
|
+
return posix.normalize(path);
|
|
384
|
+
}
|
|
385
|
+
gethome() {
|
|
386
|
+
return this.home;
|
|
387
|
+
}
|
|
388
|
+
getcwd() {
|
|
389
|
+
return this.cwd;
|
|
390
|
+
}
|
|
391
|
+
additionalDirs() {
|
|
392
|
+
return this.extraDirs;
|
|
393
|
+
}
|
|
394
|
+
resolvePath(path) {
|
|
395
|
+
return posix.isAbsolute(path) ? path : posix.join(this.cwd, path);
|
|
396
|
+
}
|
|
397
|
+
async fileInfo(path, options) {
|
|
398
|
+
const resolved = this.resolvePath(path);
|
|
399
|
+
const follow = options?.followSymlinks ?? true;
|
|
400
|
+
const st = follow ? await sftpStat(this.sftp, resolved) : await sftpLstat(this.sftp, resolved);
|
|
401
|
+
// SFTP v3 mtime is POSIX seconds; the cross-host contract is milliseconds.
|
|
402
|
+
return {
|
|
403
|
+
kind: fileKindFromSftpStats(st),
|
|
404
|
+
size: st.size,
|
|
405
|
+
...(st.mtime === 0 ? {} : { mtimeMs: st.mtime * 1000 }),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
/** SFTP readdir returns each entry's attrs (lstat semantics) alongside its name, so the
|
|
409
|
+
* whole listing — kinds included — is a single round trip. */
|
|
410
|
+
async listDir(path) {
|
|
411
|
+
const entries = await sftpReaddir(this.sftp, this.resolvePath(path));
|
|
412
|
+
return entries
|
|
413
|
+
.filter((entry) => entry.filename !== "." && entry.filename !== "..")
|
|
414
|
+
.map((entry) => ({ name: entry.filename, kind: fileKindFromSftpStats(entry.attrs) }));
|
|
415
|
+
}
|
|
416
|
+
withCwd(cwd) {
|
|
417
|
+
// Share this connection's client/sftp — only the cwd differs. Never close the
|
|
418
|
+
// clone independently; the connection is owned by whoever opened this machine.
|
|
419
|
+
const clone = SshMachine.fromConnection({
|
|
420
|
+
client: this.client,
|
|
421
|
+
sftp: this.sftp,
|
|
422
|
+
home: this.home,
|
|
423
|
+
cwd: this.resolvePath(cwd),
|
|
424
|
+
osEnv: this.osEnv,
|
|
425
|
+
name: this.name,
|
|
426
|
+
injectedEnv: this.injectedEnv,
|
|
427
|
+
});
|
|
428
|
+
clone.pathLocks = this.pathLocks; // one connection, one file namespace — clones share write locks
|
|
429
|
+
return clone;
|
|
430
|
+
}
|
|
431
|
+
async readBytes(path, range) {
|
|
432
|
+
const resolved = this.resolvePath(path);
|
|
433
|
+
if (range === undefined)
|
|
434
|
+
return await sftpReadFile(this.sftp, resolved);
|
|
435
|
+
// Open + bounded read: only the requested window crosses the wire, which is the whole
|
|
436
|
+
// point of asking for one (a header sniff must not pull a 500 MB file over SFTP).
|
|
437
|
+
const offset = range.offset ?? 0;
|
|
438
|
+
const length = range.length ?? Math.max(0, (await this.fileInfo(path)).size - offset);
|
|
439
|
+
if (length === 0)
|
|
440
|
+
return Buffer.alloc(0);
|
|
441
|
+
const handle = await sftpOpen(this.sftp, resolved, "r");
|
|
442
|
+
try {
|
|
443
|
+
return await sftpReadHandle(this.sftp, handle, offset, length);
|
|
444
|
+
}
|
|
445
|
+
finally {
|
|
446
|
+
await sftpClose(this.sftp, handle);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/** Streamed via SFTP + the shared scanner: bounded memory ("read the last 10 lines"
|
|
450
|
+
* no longer pulls the whole file into a Buffer), same range/byte-cap semantics as
|
|
451
|
+
* LocalMachine's streaming path — replaces the whole-file BaseMachine composition. */
|
|
452
|
+
async writeBytesRaw(path, data) {
|
|
453
|
+
await sftpWriteFile(this.sftp, this.resolvePath(path), data);
|
|
454
|
+
}
|
|
455
|
+
/** Same file → same lock across path spellings: resolve against cwd like every SFTP call does. */
|
|
456
|
+
lockKeyFor(path) {
|
|
457
|
+
return this.resolvePath(path);
|
|
458
|
+
}
|
|
459
|
+
async writeTextIfUnchanged(path, data, options) {
|
|
460
|
+
return await this.withPathLock(path, async () => {
|
|
461
|
+
const encoding = options.encoding ?? "utf8";
|
|
462
|
+
const resolved = this.resolvePath(path);
|
|
463
|
+
const payload = options.lineEndings === "CRLF" ? data.replaceAll("\n", "\r\n") : data;
|
|
464
|
+
const buf = Buffer.from(payload, encoding);
|
|
465
|
+
if (options.expected === "must-not-exist") {
|
|
466
|
+
let handle;
|
|
467
|
+
try {
|
|
468
|
+
handle = await sftpOpen(this.sftp, resolved, "wx");
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
// SFTP v3 has no EEXIST status (servers report a generic FAILURE) — disambiguate by stat.
|
|
472
|
+
if (await sftpExists(this.sftp, resolved))
|
|
473
|
+
throw new FileExistsError();
|
|
474
|
+
throw error;
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
await sftpWriteHandle(this.sftp, handle, buf);
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
// The EXCL open created the file; don't leave a torn one behind.
|
|
481
|
+
await sftpCloseHandle(this.sftp, handle).catch(() => undefined);
|
|
482
|
+
await sftpUnlink(this.sftp, resolved).catch(() => undefined);
|
|
483
|
+
throw error;
|
|
484
|
+
}
|
|
485
|
+
await sftpCloseHandle(this.sftp, handle);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
// Check before the upload — a stale file shouldn't cost the whole transfer.
|
|
489
|
+
await this.assertUnchanged(path, options, encoding);
|
|
490
|
+
const tmp = posix.join(posix.dirname(resolved), `.${posix.basename(resolved)}.tmp-${randomBytes(6).toString("hex")}`);
|
|
491
|
+
try {
|
|
492
|
+
await sftpWriteFile(this.sftp, tmp, buf);
|
|
493
|
+
const target = await sftpStat(this.sftp, resolved).catch(() => undefined);
|
|
494
|
+
if (target !== undefined)
|
|
495
|
+
await sftpSetstat(this.sftp, tmp, { mode: target.mode & 0o7777 });
|
|
496
|
+
await this.assertUnchanged(path, options, encoding); // re-check right before the swap
|
|
497
|
+
await sftpAtomicRename(this.sftp, tmp, resolved);
|
|
498
|
+
}
|
|
499
|
+
catch (error) {
|
|
500
|
+
await sftpUnlink(this.sftp, tmp).catch(() => undefined);
|
|
501
|
+
throw error;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
const after = await this.fileInfo(path); // still inside the lock — the version is THIS write's
|
|
505
|
+
return { bytesWritten: buf.byteLength, version: fileVersionFromInfo(after) };
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
/** SFTP has a native canonicalizer — exact, no readlink dependency. */
|
|
509
|
+
async realpath(path) {
|
|
510
|
+
return await sftpRealpath(this.sftp, this.resolvePath(path));
|
|
511
|
+
}
|
|
512
|
+
async mkdir(path, options) {
|
|
513
|
+
const resolved = this.resolvePath(path);
|
|
514
|
+
const existOk = options?.existOk ?? false;
|
|
515
|
+
if (options?.parents) {
|
|
516
|
+
const parts = resolved.split("/").filter(Boolean);
|
|
517
|
+
let current = resolved.startsWith("/") ? "/" : "";
|
|
518
|
+
for (const part of parts) {
|
|
519
|
+
current = current === "/" || current === "" ? `${current}${part}` : `${current}/${part}`;
|
|
520
|
+
const kind = await sftpKindOf(this.sftp, current);
|
|
521
|
+
if (kind === "dir")
|
|
522
|
+
continue;
|
|
523
|
+
// `mkdir -p` tolerates existing DIRECTORIES only — a file occupant anywhere on
|
|
524
|
+
// the way (final component included) is EEXIST, matching LocalMachine/Node.
|
|
525
|
+
if (kind !== undefined)
|
|
526
|
+
throw codedError(`${current} already exists and is not a directory`, "EEXIST");
|
|
527
|
+
try {
|
|
528
|
+
await sftpMkdir(this.sftp, current);
|
|
529
|
+
}
|
|
530
|
+
catch (error) {
|
|
531
|
+
// Lost a create race — fine only if the winner made a directory.
|
|
532
|
+
if ((await sftpKindOf(this.sftp, current)) !== "dir")
|
|
533
|
+
throw error;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const kind = await sftpKindOf(this.sftp, resolved);
|
|
539
|
+
if (kind !== undefined) {
|
|
540
|
+
// existOk only tolerates a directory occupant; a file at the path is always EEXIST.
|
|
541
|
+
if (existOk && kind === "dir")
|
|
542
|
+
return;
|
|
543
|
+
throw codedError(`${resolved} already exists`, "EEXIST");
|
|
544
|
+
}
|
|
545
|
+
await sftpMkdir(this.sftp, resolved);
|
|
546
|
+
}
|
|
547
|
+
async spawn(argv, env) {
|
|
548
|
+
if (argv.length === 0)
|
|
549
|
+
throw new Error("spawn requires at least one argument");
|
|
550
|
+
// Layer proxy forwarding under the caller's overrides (caller wins on conflict).
|
|
551
|
+
const merged = { ...this.injectedEnv, ...(env ?? {}) };
|
|
552
|
+
const command = buildSshExecCommand(argv, this.cwd, Object.keys(merged).length > 0 ? merged : undefined);
|
|
553
|
+
const channel = await clientExec(this.client, command);
|
|
554
|
+
return new SshProcess(channel);
|
|
555
|
+
}
|
|
556
|
+
close() {
|
|
557
|
+
this.sftp.end();
|
|
558
|
+
return new Promise((resolve) => {
|
|
559
|
+
this.client.once("close", () => resolve());
|
|
560
|
+
this.client.end();
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/*
|
|
565
|
+
* No `sshMachineFactory` here on purpose. Its only job would be closing the connection on
|
|
566
|
+
* session close — the lifecycle management that now belongs to whoever opened it (see
|
|
567
|
+
* `MachineFactory`). A host wires SSH in the same way it wires a sandbox:
|
|
568
|
+
*
|
|
569
|
+
* const machine = await SshMachine.create(options);
|
|
570
|
+
* const harness = new Harness({ machine });
|
|
571
|
+
* // ...and calls machine.close() on its own terms.
|
|
572
|
+
*
|
|
573
|
+
* That also fixes what the factory form got wrong: it opened a NEW connection per session,
|
|
574
|
+
* so several sessions on one host meant several connections, each dying with its own session.
|
|
575
|
+
*/
|
|
576
|
+
//# sourceMappingURL=machine-ssh.js.map
|