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,388 @@
|
|
|
1
|
+
import { StringDecoder } from "node:string_decoder";
|
|
2
|
+
import { posix, win32 } from "node:path";
|
|
3
|
+
import { FileExistsError, StaleFileError, } from "./machine.js";
|
|
4
|
+
import { fileVersionFromInfo, fileVersionsMatch, normalizeForCompare } from "./support/machine-ops.js";
|
|
5
|
+
/** Deadline for the `readlink -f` realpath fallback (see BaseMachine.realpath). */
|
|
6
|
+
const REALPATH_TIMEOUT_MS = 10_000;
|
|
7
|
+
function codedError(message, code) {
|
|
8
|
+
const error = new Error(message);
|
|
9
|
+
error.code = code;
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
/** Join with the TARGET machine's path flavour, not the host's — a local process may be
|
|
13
|
+
* driving a posix machine (SSH / sandbox) or vice versa. */
|
|
14
|
+
function joinPath(pathClass, dir, name) {
|
|
15
|
+
return (pathClass === "win32" ? win32 : posix).join(dir, name);
|
|
16
|
+
}
|
|
17
|
+
function sleep(ms) {
|
|
18
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
|
+
}
|
|
20
|
+
/** Single-quote for a POSIX shell; only used by the subshell `cwd` fallback. */
|
|
21
|
+
function shellQuoteArg(value) {
|
|
22
|
+
if (/^[A-Za-z0-9_/@%+=:,.-]+$/.test(value))
|
|
23
|
+
return value;
|
|
24
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Read a stream, stopping accumulation at `maxBytes`. Chunks are handed to `onData` as they
|
|
28
|
+
* arrive (that is what makes `RunCommandOptions.onOutput` incremental on streaming backends), and
|
|
29
|
+
* accumulation stops at the cap while the stream is still drained, so the writer never
|
|
30
|
+
* blocks on a full pipe.
|
|
31
|
+
*/
|
|
32
|
+
async function readCapped(stream, maxBytes, onData) {
|
|
33
|
+
const chunks = [];
|
|
34
|
+
let total = 0;
|
|
35
|
+
let truncated = false;
|
|
36
|
+
// Incremental delivery decodes through a StringDecoder: a multi-byte character split across
|
|
37
|
+
// two chunks would otherwise reach the caller as mojibake. The accumulated `text` below is
|
|
38
|
+
// immune (it concatenates buffers first), so only this path needs it.
|
|
39
|
+
const decoder = onData === undefined ? undefined : new StringDecoder("utf8");
|
|
40
|
+
try {
|
|
41
|
+
for await (const chunk of stream) {
|
|
42
|
+
const buf = typeof chunk === "string" ? Buffer.from(chunk, "utf8") : chunk;
|
|
43
|
+
if (onData !== undefined && decoder !== undefined && !truncated) {
|
|
44
|
+
const decoded = decoder.write(buf);
|
|
45
|
+
if (decoded.length > 0)
|
|
46
|
+
onData(decoded);
|
|
47
|
+
}
|
|
48
|
+
if (truncated)
|
|
49
|
+
continue;
|
|
50
|
+
if (total + buf.length > maxBytes) {
|
|
51
|
+
const room = maxBytes - total;
|
|
52
|
+
if (room > 0)
|
|
53
|
+
chunks.push(buf.subarray(0, room));
|
|
54
|
+
total = maxBytes;
|
|
55
|
+
truncated = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
chunks.push(buf);
|
|
59
|
+
total += buf.length;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// The stream died mid-read — most often because `run` destroyed it deliberately to stop a
|
|
64
|
+
// process that survived being killed. Whatever arrived before that is still the honest
|
|
65
|
+
// output; the caller learns how the command ended from exitCode/timedOut/terminated.
|
|
66
|
+
}
|
|
67
|
+
if (decoder !== undefined && onData !== undefined && !truncated) {
|
|
68
|
+
// Flush whatever bytes were left mid-character; replacement chars only if truly malformed.
|
|
69
|
+
const tail = decoder.end();
|
|
70
|
+
if (tail.length > 0)
|
|
71
|
+
onData(tail);
|
|
72
|
+
}
|
|
73
|
+
return { text: Buffer.concat(chunks).toString("utf8"), truncated };
|
|
74
|
+
}
|
|
75
|
+
function isFileMissingError(error) {
|
|
76
|
+
if (typeof error !== "object" || error === null)
|
|
77
|
+
return false;
|
|
78
|
+
const code = error["code"];
|
|
79
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
80
|
+
}
|
|
81
|
+
async function collectStream(stream) {
|
|
82
|
+
const chunks = [];
|
|
83
|
+
for await (const chunk of stream) {
|
|
84
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
85
|
+
}
|
|
86
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
87
|
+
}
|
|
88
|
+
export class BaseMachine {
|
|
89
|
+
/** Extra workspace roots (see Machine.additionalDirs). Default: cwd only. */
|
|
90
|
+
additionalDirs() {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The write half of the compare-and-swap in `writeTextIfUnchanged`. Default: the same raw
|
|
95
|
+
* write as anywhere else — correct, but a reader racing it can observe a half-written file,
|
|
96
|
+
* and a crash mid-write leaves one behind.
|
|
97
|
+
*
|
|
98
|
+
* Backends that can swap a complete file into place in one indivisible step (write to a
|
|
99
|
+
* sibling temp path, then rename over the target on the same filesystem) override this. It
|
|
100
|
+
* is separate from `writeBytesRaw` because the extra round trip only earns its cost where
|
|
101
|
+
* torn state is observable — which is the CAS path, not every write.
|
|
102
|
+
*/
|
|
103
|
+
async writeBytesSwap(path, data) {
|
|
104
|
+
await this.writeBytesRaw(path, data);
|
|
105
|
+
}
|
|
106
|
+
/** Decode with the shared contract: strict UTF-8 throws on invalid bytes (binary detection). */
|
|
107
|
+
decodeText(data, options) {
|
|
108
|
+
const encoding = options?.encoding ?? "utf8";
|
|
109
|
+
const errors = options?.errors ?? "strict";
|
|
110
|
+
if ((encoding === "utf8" || encoding === "utf-8") && errors === "strict") {
|
|
111
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(data);
|
|
112
|
+
}
|
|
113
|
+
return data.toString(encoding);
|
|
114
|
+
}
|
|
115
|
+
// ---- Derived high-level operations (override when the backend can do better) ----
|
|
116
|
+
/**
|
|
117
|
+
* `listDir` helper for backends whose native listing hands back bare names: stat each
|
|
118
|
+
* entry, but in PARALLEL — the serial stat-per-entry walk is exactly what putting `kind`
|
|
119
|
+
* in the listing contract exists to prevent. `lstat` semantics (`followSymlinks: false`)
|
|
120
|
+
* to match `DirEntry`, so a symlink stays a symlink as it would in a native readdir.
|
|
121
|
+
*
|
|
122
|
+
* Backends whose readdir already reports kinds (local opendir, SFTP readdir) never call
|
|
123
|
+
* this — they answer in one round trip.
|
|
124
|
+
*/
|
|
125
|
+
async entriesByStatting(path, names) {
|
|
126
|
+
return Promise.all(names.map(async (name) => {
|
|
127
|
+
const info = await this.fileInfo(joinPath(this.pathClass(), path, name), { followSymlinks: false })
|
|
128
|
+
// An entry that vanished between readdir and stat is reported as "other" rather
|
|
129
|
+
// than failing the whole listing — callers filter by kind anyway.
|
|
130
|
+
.catch(() => undefined);
|
|
131
|
+
return { name, kind: info?.kind ?? "other" };
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* `run` derived from the process-spawning SPI: spawn, cap both streams while reading, and
|
|
136
|
+
* on timeout/abort escalate SIGTERM → SIGKILL. This is the logic that used to live in the
|
|
137
|
+
* Grep/Glob and Bash tool layers — it belongs here, where "kill the process" is something
|
|
138
|
+
* the backend actually knows how to do (and where a backend that CANNOT do it reports
|
|
139
|
+
* `terminated: false` instead of the tool pretending it worked).
|
|
140
|
+
*
|
|
141
|
+
* Backends without a process handle override this wholesale; the throw below is the
|
|
142
|
+
* contract's other half made loud rather than silent.
|
|
143
|
+
*/
|
|
144
|
+
async run(argv, options = {}) {
|
|
145
|
+
const { timeoutMs, maxOutputBytes = Number.POSITIVE_INFINITY, signal, onOutput } = options;
|
|
146
|
+
if (signal?.aborted) {
|
|
147
|
+
return { stdout: "", stderr: "", exitCode: undefined, timedOut: false, truncated: false, terminated: true };
|
|
148
|
+
}
|
|
149
|
+
if (this.spawn === undefined) {
|
|
150
|
+
throw new Error(`${this.name}: a backend with no process SPI must override run().`);
|
|
151
|
+
}
|
|
152
|
+
const proc = await this.spawn(this.withCwdArgv(argv, options.cwd), options.env);
|
|
153
|
+
if (options.stdin !== undefined)
|
|
154
|
+
proc.stdin.write(options.stdin);
|
|
155
|
+
try {
|
|
156
|
+
proc.stdin.end();
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
/* already closed */
|
|
160
|
+
}
|
|
161
|
+
let timedOut = false;
|
|
162
|
+
let terminated = false;
|
|
163
|
+
let killing;
|
|
164
|
+
// Resolves only when the kill escalation ran out of options — the process is still alive,
|
|
165
|
+
// so neither its pipes nor its exit status will ever arrive on their own. Without this
|
|
166
|
+
// escape hatch a timeout or an abort would hang forever on a process that ignores signals.
|
|
167
|
+
let abandonHung;
|
|
168
|
+
const abandoned = new Promise((resolve) => {
|
|
169
|
+
abandonHung = resolve;
|
|
170
|
+
});
|
|
171
|
+
const stop = () => (killing ??= this.escalatingKill(proc).then((ok) => {
|
|
172
|
+
terminated = ok;
|
|
173
|
+
if (!ok) {
|
|
174
|
+
proc.stdout.destroy(); // ends the reads below (readCapped treats this as EOF)
|
|
175
|
+
proc.stderr.destroy();
|
|
176
|
+
abandonHung();
|
|
177
|
+
}
|
|
178
|
+
}));
|
|
179
|
+
const onAbort = () => void stop();
|
|
180
|
+
signal?.addEventListener("abort", onAbort);
|
|
181
|
+
const timer = timeoutMs === undefined ? undefined : setTimeout(() => {
|
|
182
|
+
timedOut = true;
|
|
183
|
+
void stop();
|
|
184
|
+
}, timeoutMs);
|
|
185
|
+
try {
|
|
186
|
+
const [out, err, code] = await Promise.all([
|
|
187
|
+
readCapped(proc.stdout, maxOutputBytes, onOutput && ((data) => onOutput({ stream: "stdout", data }))),
|
|
188
|
+
readCapped(proc.stderr, maxOutputBytes, onOutput && ((data) => onOutput({ stream: "stderr", data }))),
|
|
189
|
+
Promise.race([proc.wait().catch(() => undefined), abandoned.then(() => undefined)]),
|
|
190
|
+
]);
|
|
191
|
+
// A cap hit means we stop reading, but the process may still be writing — stop it so
|
|
192
|
+
// it cannot keep producing output nobody will read.
|
|
193
|
+
if ((out.truncated || err.truncated) && proc.exitCode === null)
|
|
194
|
+
await stop();
|
|
195
|
+
// A kill makes wait() settle immediately, so without joining the in-flight kill here we
|
|
196
|
+
// would read `terminated` before it resolved and under-report every termination.
|
|
197
|
+
await killing;
|
|
198
|
+
return {
|
|
199
|
+
stdout: out.text,
|
|
200
|
+
stderr: err.text,
|
|
201
|
+
exitCode: timedOut ? undefined : code,
|
|
202
|
+
timedOut,
|
|
203
|
+
truncated: out.truncated || err.truncated,
|
|
204
|
+
terminated,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
if (timer !== undefined)
|
|
209
|
+
clearTimeout(timer);
|
|
210
|
+
signal?.removeEventListener("abort", onAbort);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** SIGTERM, then SIGKILL if it does not exit. Returns whether the process actually stopped. */
|
|
214
|
+
/** How long SIGTERM gets before SIGKILL, and SIGKILL before we give up. Overridable so a
|
|
215
|
+
* backend (or a test) can tighten it; the default matches the shell's own convention. */
|
|
216
|
+
sigtermGraceMs = 5_000;
|
|
217
|
+
async escalatingKill(proc, graceMs = this.sigtermGraceMs) {
|
|
218
|
+
try {
|
|
219
|
+
await proc.kill("SIGTERM");
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
/* already gone */
|
|
223
|
+
}
|
|
224
|
+
const exited = proc.wait().then(() => true, () => true);
|
|
225
|
+
const inTime = await Promise.race([exited, sleep(graceMs).then(() => false)]);
|
|
226
|
+
if (inTime)
|
|
227
|
+
return true;
|
|
228
|
+
try {
|
|
229
|
+
await proc.kill("SIGKILL");
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return proc.exitCode !== null;
|
|
233
|
+
}
|
|
234
|
+
return await Promise.race([exited, sleep(graceMs).then(() => false)]);
|
|
235
|
+
}
|
|
236
|
+
/** `spawn` has no cwd parameter; a backend without a native one runs through a subshell. */
|
|
237
|
+
withCwdArgv(argv, cwd) {
|
|
238
|
+
if (cwd === undefined)
|
|
239
|
+
return [...argv];
|
|
240
|
+
const quoted = argv.map(shellQuoteArg).join(" ");
|
|
241
|
+
return ["sh", "-c", `cd ${shellQuoteArg(cwd)} && ${quoted}`];
|
|
242
|
+
}
|
|
243
|
+
async writeText(path, data, options = {}) {
|
|
244
|
+
const payload = options.lineEndings === "CRLF" ? data.replaceAll("\n", "\r\n") : data;
|
|
245
|
+
const buf = Buffer.from(payload, options.encoding ?? "utf8");
|
|
246
|
+
await this.writeBytesRaw(path, buf);
|
|
247
|
+
return { bytesWritten: buf.byteLength };
|
|
248
|
+
}
|
|
249
|
+
/** Exact bytes through the same primitive `writeText` uses — no encoding, no CRLF rewrite. */
|
|
250
|
+
async writeBytes(path, data) {
|
|
251
|
+
await this.writeBytesRaw(path, data);
|
|
252
|
+
}
|
|
253
|
+
// ── Per-path write serialization ──
|
|
254
|
+
// The same-process floor of the writeTextIfUnchanged contract: compare, write and
|
|
255
|
+
// version stamp happen under the file's lock, so two in-process writers cannot
|
|
256
|
+
// interleave. Clones sharing a backend (withCwd) must share this map — backends
|
|
257
|
+
// assign `clone.pathLocks = this.pathLocks` when cloning.
|
|
258
|
+
pathLocks = new Map();
|
|
259
|
+
/** Key identifying "the same file" for the write lock. Backends with real path
|
|
260
|
+
* resolution override so relative and absolute spellings share one lock. */
|
|
261
|
+
lockKeyFor(path) {
|
|
262
|
+
return this.normpath(path);
|
|
263
|
+
}
|
|
264
|
+
async withPathLock(path, body) {
|
|
265
|
+
const key = this.lockKeyFor(path);
|
|
266
|
+
const prev = this.pathLocks.get(key) ?? Promise.resolve();
|
|
267
|
+
let release;
|
|
268
|
+
const gate = new Promise((resolve) => (release = resolve));
|
|
269
|
+
this.pathLocks.set(key, gate);
|
|
270
|
+
await prev;
|
|
271
|
+
try {
|
|
272
|
+
return await body();
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
release();
|
|
276
|
+
// Drop the entry once no later writer has queued behind us (bounds the map).
|
|
277
|
+
if (this.pathLocks.get(key) === gate)
|
|
278
|
+
this.pathLocks.delete(key);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The compare half of writeTextIfUnchanged: throws unless the file still matches
|
|
283
|
+
* `options.expected`. Shared by the base composition and by backend overrides
|
|
284
|
+
* that re-check right before an atomic swap (SshMachine).
|
|
285
|
+
*/
|
|
286
|
+
async assertUnchanged(path, options, encoding) {
|
|
287
|
+
let info;
|
|
288
|
+
try {
|
|
289
|
+
info = await this.fileInfo(path);
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
if (!isFileMissingError(error))
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
if (options.expected === "must-not-exist") {
|
|
296
|
+
if (info !== undefined)
|
|
297
|
+
throw new FileExistsError();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (info === undefined) {
|
|
301
|
+
throw new StaleFileError("File no longer exists. Read it again before attempting to write it.");
|
|
302
|
+
}
|
|
303
|
+
if (fileVersionsMatch(options.expected, fileVersionFromInfo(info)))
|
|
304
|
+
return;
|
|
305
|
+
// mtime moved or is unavailable — review against the prior content (the
|
|
306
|
+
// Windows false-positive fallback, also the only check on mtime-less
|
|
307
|
+
// sandbox backends).
|
|
308
|
+
if (options.expectedContent !== undefined) {
|
|
309
|
+
let confirmedUnchanged = false;
|
|
310
|
+
try {
|
|
311
|
+
const text = this.decodeText(await this.readBytes(path), { encoding, errors: "strict" });
|
|
312
|
+
confirmedUnchanged = normalizeForCompare(text) === options.expectedContent;
|
|
313
|
+
}
|
|
314
|
+
catch {
|
|
315
|
+
confirmedUnchanged = false;
|
|
316
|
+
}
|
|
317
|
+
if (!confirmedUnchanged)
|
|
318
|
+
throw new StaleFileError();
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
// The mtime moved, or one side never had one, and there is no content to review
|
|
322
|
+
// against. Either way the file cannot be established as unchanged — refuse.
|
|
323
|
+
throw new StaleFileError();
|
|
324
|
+
}
|
|
325
|
+
async writeTextIfUnchanged(path, data, options) {
|
|
326
|
+
return await this.withPathLock(path, async () => {
|
|
327
|
+
const encoding = options.encoding ?? "utf8";
|
|
328
|
+
await this.assertUnchanged(path, options, encoding);
|
|
329
|
+
const payload = options.lineEndings === "CRLF" ? data.replaceAll("\n", "\r\n") : data;
|
|
330
|
+
const buf = Buffer.from(payload, encoding);
|
|
331
|
+
await this.writeBytesSwap(path, buf);
|
|
332
|
+
// Still inside the lock: the returned version must be THIS write's, not a
|
|
333
|
+
// concurrent sibling's that landed after ours.
|
|
334
|
+
const after = await this.fileInfo(path);
|
|
335
|
+
return { bytesWritten: buf.byteLength, version: fileVersionFromInfo(after) };
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/** Deadline for the readlink fallback; a test/backend subclass may shorten it. */
|
|
339
|
+
realpathTimeoutMs = REALPATH_TIMEOUT_MS;
|
|
340
|
+
/**
|
|
341
|
+
* Exec-derived fallback (`readlink -f`). A readlink that is missing/unsupported or
|
|
342
|
+
* exits nonzero degrades to `normpath` (best effort for backends without a native
|
|
343
|
+
* resolver), but a HANG throws after {@link REALPATH_TIMEOUT_MS}: path-access relies
|
|
344
|
+
* on realpath for its symlink guard, and a timeout silently degrading to string
|
|
345
|
+
* matching would fail open. Hosts with a native resolver override this for exactness.
|
|
346
|
+
*/
|
|
347
|
+
async realpath(path) {
|
|
348
|
+
if (this.pathClass() === "win32")
|
|
349
|
+
return this.normpath(path);
|
|
350
|
+
// The deadline is raced OUTSIDE `run` rather than passed in as `timeoutMs`: a timeout
|
|
351
|
+
// inside `run` resolves only after the kill escalation finishes, and this caller cannot
|
|
352
|
+
// wait that long — path-access blocks on it. So we abort the run and reject immediately,
|
|
353
|
+
// leaving the backend to finish stopping on its own.
|
|
354
|
+
const controller = new AbortController();
|
|
355
|
+
let timer;
|
|
356
|
+
const running = this.run(["readlink", "-f", "--", path], { signal: controller.signal });
|
|
357
|
+
running.catch(() => undefined); // a post-deadline rejection must not surface as unhandled
|
|
358
|
+
try {
|
|
359
|
+
const result = await Promise.race([
|
|
360
|
+
running,
|
|
361
|
+
new Promise((_resolve, reject) => {
|
|
362
|
+
// Deliberately NOT unref'd: this timer is what unblocks the awaiting caller when the
|
|
363
|
+
// command hangs — an unref'd timer would let an otherwise-idle process exit mid-await.
|
|
364
|
+
timer = setTimeout(() => {
|
|
365
|
+
controller.abort();
|
|
366
|
+
reject(codedError(`realpath: readlink -f timed out after ${this.realpathTimeoutMs}ms for '${path}'`, "ETIMEDOUT"));
|
|
367
|
+
}, this.realpathTimeoutMs);
|
|
368
|
+
}),
|
|
369
|
+
]);
|
|
370
|
+
const resolved = result.stdout.trim();
|
|
371
|
+
if (result.exitCode === 0 && resolved.length > 0)
|
|
372
|
+
return resolved;
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
// A HANG is an infrastructure failure, not a resolution failure — surface it. Degrading
|
|
376
|
+
// to string matching here would fail OPEN for path-access's symlink guard.
|
|
377
|
+
if (error.code === "ETIMEDOUT")
|
|
378
|
+
throw error;
|
|
379
|
+
/* anything else (no such command, backend refused) falls through to normpath */
|
|
380
|
+
}
|
|
381
|
+
finally {
|
|
382
|
+
if (timer !== undefined)
|
|
383
|
+
clearTimeout(timer);
|
|
384
|
+
}
|
|
385
|
+
return this.normpath(path);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
//# sourceMappingURL=machine-base.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type DirEntry, type Environment, type ByteRange, type Machine, type FileInfo, type WriteFileResult, type WriteTextIfUnchangedOptions } from "./machine.ts";
|
|
2
|
+
import { BaseMachine, type SpawnedProcess } from "./machine-base.ts";
|
|
3
|
+
export declare function detectEnvironment(env?: NodeJS.ProcessEnv): Environment;
|
|
4
|
+
export declare class LocalMachine extends BaseMachine {
|
|
5
|
+
readonly name = "local";
|
|
6
|
+
readonly osEnv: Environment;
|
|
7
|
+
private cwd;
|
|
8
|
+
private readonly extraDirs;
|
|
9
|
+
constructor(cwdOrOptions?: string | {
|
|
10
|
+
cwd?: string;
|
|
11
|
+
additionalDirs?: readonly string[];
|
|
12
|
+
});
|
|
13
|
+
pathClass(): "posix" | "win32";
|
|
14
|
+
normpath(path: string): string;
|
|
15
|
+
gethome(): string;
|
|
16
|
+
getcwd(): string;
|
|
17
|
+
withCwd(cwd: string): Machine;
|
|
18
|
+
additionalDirs(): readonly string[];
|
|
19
|
+
private abs;
|
|
20
|
+
fileInfo(path: string, options?: {
|
|
21
|
+
followSymlinks?: boolean;
|
|
22
|
+
}): Promise<FileInfo>;
|
|
23
|
+
/** opendir already carries the dirent type — no stat per entry (lstat semantics). */
|
|
24
|
+
listDir(path: string): Promise<readonly DirEntry[]>;
|
|
25
|
+
readBytes(path: string, range?: ByteRange): Promise<Buffer>;
|
|
26
|
+
protected writeBytesRaw(path: string, data: Buffer): Promise<void>;
|
|
27
|
+
mkdir(path: string, options?: {
|
|
28
|
+
parents?: boolean;
|
|
29
|
+
existOk?: boolean;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
realpath(path: string): Promise<string>;
|
|
32
|
+
writeTextIfUnchanged(path: string, data: string, options: WriteTextIfUnchangedOptions): Promise<WriteFileResult>;
|
|
33
|
+
protected spawn(argv: readonly string[], env?: Record<string, string>): Promise<SpawnedProcess>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=machine-local.d.ts.map
|