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,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort extraction of the file paths a shell command touches, so Bash can declare
|
|
3
|
+
* `ToolPlan.accesses` like every other tool and the existing permission policies
|
|
4
|
+
* (sensitive-file / git-control-path / write-outside-cwd) apply to it too. Without this,
|
|
5
|
+
* Bash declares nothing and all three silently skip it.
|
|
6
|
+
*
|
|
7
|
+
* EXPLICITLY INCOMPLETE, and safe because of how it fails. `eval "$CMD"`, `bash -c "$(curl …)"`
|
|
8
|
+
* and variable-built paths cannot be resolved from source text, and no amount of parsing fixes
|
|
9
|
+
* that. Every unresolvable case yields NO access entry, which lands exactly on today's
|
|
10
|
+
* behaviour — the policies skip what they cannot see, and the permission chain's fallback ask
|
|
11
|
+
* still stands behind them. So this raises the cost of an accidental out-of-workspace write; it
|
|
12
|
+
* is not a boundary. The boundary is the Machine (sandbox / SSH), which bounds what the command
|
|
13
|
+
* can reach no matter how the path was spelled.
|
|
14
|
+
*
|
|
15
|
+
* Over-declaring is the failure mode worth avoiding: a bogus path means a permission prompt for
|
|
16
|
+
* a command that never touched it, and needless serialization against sibling calls. Hence only
|
|
17
|
+
* literal words of well-understood commands are reported, and anything ambiguous is dropped.
|
|
18
|
+
*/
|
|
19
|
+
import { scanShellCommand } from "./bash-rule-match.js";
|
|
20
|
+
/** Wrappers that run the REST of the words as a command; the real verb is what follows. */
|
|
21
|
+
const COMMAND_PREFIXES = new Set(["sudo", "env", "nohup", "time", "command", "builtin", "exec", "nice", "ionice"]);
|
|
22
|
+
/** Every non-option argument is a write target. */
|
|
23
|
+
const WRITES_ALL_ARGS = new Set(["rm", "rmdir", "touch", "mkdir", "unlink", "shred", "truncate", "tee"]);
|
|
24
|
+
/** Last non-option argument is the destination; the earlier ones are sources. */
|
|
25
|
+
const WRITES_LAST_ARG = new Set(["cp", "mv", "ln", "install", "rsync"]);
|
|
26
|
+
/** First non-option argument is a mode/owner, the rest are targets. */
|
|
27
|
+
const WRITES_ARGS_AFTER_FIRST = new Set(["chmod", "chown", "chgrp"]);
|
|
28
|
+
/** Take a script operand before their filenames, and write in place with `-i`. */
|
|
29
|
+
const SCRIPT_COMMANDS = new Set(["sed", "gsed", "perl", "awk", "gawk"]);
|
|
30
|
+
/** Every non-option argument is read. */
|
|
31
|
+
const READS_ALL_ARGS = new Set([
|
|
32
|
+
"cat", "head", "tail", "less", "more", "wc", "file", "stat", "nl", "od", "xxd", "strings",
|
|
33
|
+
"base64", "md5sum", "sha1sum", "sha256sum", "shasum", "cmp", "diff", "sort", "readlink",
|
|
34
|
+
]);
|
|
35
|
+
/**
|
|
36
|
+
* Split one simple command into words, tracking whether each is a knowable literal.
|
|
37
|
+
*
|
|
38
|
+
* A double-quoted word containing `$` or a backtick is NOT literal — its value depends on the
|
|
39
|
+
* environment. An unquoted word with a glob character is not literal either: it names a set,
|
|
40
|
+
* and reporting the pattern as if it were a path would be a fabricated access.
|
|
41
|
+
*/
|
|
42
|
+
function splitWords(text) {
|
|
43
|
+
const words = [];
|
|
44
|
+
let current = "";
|
|
45
|
+
let started = false;
|
|
46
|
+
let literal = true;
|
|
47
|
+
let inSingle = false;
|
|
48
|
+
let inDouble = false;
|
|
49
|
+
const push = () => {
|
|
50
|
+
if (started)
|
|
51
|
+
words.push({ text: current, literal });
|
|
52
|
+
current = "";
|
|
53
|
+
started = false;
|
|
54
|
+
literal = true;
|
|
55
|
+
};
|
|
56
|
+
for (let i = 0; i < text.length; i++) {
|
|
57
|
+
const ch = text[i];
|
|
58
|
+
if (inSingle) {
|
|
59
|
+
if (ch === "'")
|
|
60
|
+
inSingle = false;
|
|
61
|
+
else
|
|
62
|
+
current += ch;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (ch === "\\" && i + 1 < text.length) {
|
|
66
|
+
current += text[i + 1];
|
|
67
|
+
started = true;
|
|
68
|
+
i++;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (ch === "'" && !inDouble) {
|
|
72
|
+
inSingle = true;
|
|
73
|
+
started = true;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (ch === '"') {
|
|
77
|
+
inDouble = !inDouble;
|
|
78
|
+
started = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!inDouble && /\s/.test(ch)) {
|
|
82
|
+
push();
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (inDouble && (ch === "$" || ch === "`"))
|
|
86
|
+
literal = false;
|
|
87
|
+
// Unquoted expansions and globs: the word is a pattern or a variable, not a path.
|
|
88
|
+
if (!inDouble && (ch === "$" || ch === "*" || ch === "?" || ch === "["))
|
|
89
|
+
literal = false;
|
|
90
|
+
current += ch;
|
|
91
|
+
started = true;
|
|
92
|
+
}
|
|
93
|
+
push();
|
|
94
|
+
return words;
|
|
95
|
+
}
|
|
96
|
+
/** `>`, `>>`, `2>`, `&>`, `>|` … — everything that names a file to be written. */
|
|
97
|
+
const WRITE_REDIRECT = /^(?:\d*&?>{1,2}\|?|&>{1,2})$/;
|
|
98
|
+
const READ_REDIRECT = /^\d*<$/;
|
|
99
|
+
/**
|
|
100
|
+
* Pull redirection targets out and return the remaining words.
|
|
101
|
+
*
|
|
102
|
+
* `2>&1` and friends duplicate a descriptor rather than name a file, so a target starting with
|
|
103
|
+
* `&` is dropped. A redirect written without a space (`>out.log`) is handled by splitting the
|
|
104
|
+
* operator off the front of the word.
|
|
105
|
+
*/
|
|
106
|
+
function takeRedirects(words, out) {
|
|
107
|
+
const rest = [];
|
|
108
|
+
for (let i = 0; i < words.length; i++) {
|
|
109
|
+
const word = words[i];
|
|
110
|
+
// A word that is ENTIRELY an operator takes the next word as its target. This must be
|
|
111
|
+
// tested before the glued form below: `>>` also matches that pattern, with the regex
|
|
112
|
+
// backtracking so the second `>` reads as a one-character filename.
|
|
113
|
+
const isWrite = WRITE_REDIRECT.test(word.text);
|
|
114
|
+
if (isWrite || READ_REDIRECT.test(word.text)) {
|
|
115
|
+
const target = words[i + 1];
|
|
116
|
+
i++; // the target belongs to the redirect either way, never to the command
|
|
117
|
+
if (target !== undefined && target.literal && !target.text.startsWith("&")) {
|
|
118
|
+
out.push({ operation: isWrite ? "write" : "read", path: target.text });
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
// Operator and target written together: `>out.log`.
|
|
123
|
+
const glued = /^(\d*&?>{1,2}\|?|&>{1,2}|\d*<)(.+)$/.exec(word.text);
|
|
124
|
+
if (glued !== null && (WRITE_REDIRECT.test(glued[1]) || READ_REDIRECT.test(glued[1]))) {
|
|
125
|
+
const target = glued[2];
|
|
126
|
+
if (word.literal && !target.startsWith("&")) {
|
|
127
|
+
out.push({ operation: WRITE_REDIRECT.test(glued[1]) ? "write" : "read", path: target });
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
rest.push(word);
|
|
132
|
+
}
|
|
133
|
+
return rest;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* `sed`/`perl` edit files in place, so their operands are writes — but only with `-i`, and
|
|
137
|
+
* only after the SCRIPT operand is told apart from the filenames. Two details make a plain
|
|
138
|
+
* operand scan wrong here:
|
|
139
|
+
*
|
|
140
|
+
* - Without `-e`/`-f`, the first operand is the script (`sed 's/a/b/' notes.txt`). Treating it
|
|
141
|
+
* as a path would declare a write to a file named `s/a/b/`.
|
|
142
|
+
* - BSD `sed` requires a backup suffix for `-i`, usually written as an empty word
|
|
143
|
+
* (`sed -i '' 's/a/b/' notes.txt`), which shifts every operand one place along.
|
|
144
|
+
*
|
|
145
|
+
* Without `-i` the same command only reads, which is still worth declaring — `sed 's/x/y/' .env`
|
|
146
|
+
* should meet the sensitive-file policy just like `cat .env` does.
|
|
147
|
+
*/
|
|
148
|
+
function scriptCommandFiles(name, rawArgs) {
|
|
149
|
+
let inPlace = false;
|
|
150
|
+
let scriptIsAnOption = false;
|
|
151
|
+
const operandWords = [];
|
|
152
|
+
let optionsEnded = false;
|
|
153
|
+
for (let i = 0; i < rawArgs.length; i++) {
|
|
154
|
+
const word = rawArgs[i];
|
|
155
|
+
if (!optionsEnded && word.text === "--") {
|
|
156
|
+
optionsEnded = true;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1) {
|
|
160
|
+
// `--silent` contains an "i", so sed's in-place flag has to be matched at the front;
|
|
161
|
+
// perl's comes bundled into short clusters like `-pi`.
|
|
162
|
+
if (name === "sed" || name === "gsed") {
|
|
163
|
+
if (/^-i/.test(word.text) || word.text === "--in-place" || word.text.startsWith("--in-place="))
|
|
164
|
+
inPlace = true;
|
|
165
|
+
}
|
|
166
|
+
else if (/^-[^-]*i/.test(word.text)) {
|
|
167
|
+
inPlace = true;
|
|
168
|
+
}
|
|
169
|
+
if (word.text === "-e" || word.text === "-f" || word.text === "--expression" || word.text === "--file") {
|
|
170
|
+
scriptIsAnOption = true;
|
|
171
|
+
i++; // the script/scriptfile is this option's argument, never a path
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (/^--(expression|file)=/.test(word.text))
|
|
175
|
+
scriptIsAnOption = true;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
operandWords.push(word);
|
|
179
|
+
}
|
|
180
|
+
const nonEmpty = operandWords.filter((word) => word.text.length > 0);
|
|
181
|
+
return { inPlace, files: scriptIsAnOption ? nonEmpty : nonEmpty.slice(1) };
|
|
182
|
+
}
|
|
183
|
+
/** Drop option flags, and stop treating anything as an option after a bare `--`. */
|
|
184
|
+
function operands(words) {
|
|
185
|
+
const result = [];
|
|
186
|
+
let optionsEnded = false;
|
|
187
|
+
for (const word of words) {
|
|
188
|
+
if (!optionsEnded && word.text === "--") {
|
|
189
|
+
optionsEnded = true;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1)
|
|
193
|
+
continue;
|
|
194
|
+
result.push(word);
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
function pushLiteral(words, operation, out) {
|
|
199
|
+
for (const word of words) {
|
|
200
|
+
if (word.literal && word.text.length > 0)
|
|
201
|
+
out.push({ operation, path: word.text });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
export function extractBashPaths(command) {
|
|
205
|
+
// A command with an eval, a substitution or an unbalanced quote can execute anything; the
|
|
206
|
+
// scan reports it as risky and hands back no subcommands, and we claim nothing about it.
|
|
207
|
+
const scan = scanShellCommand(command);
|
|
208
|
+
if (scan.risky)
|
|
209
|
+
return [];
|
|
210
|
+
const out = [];
|
|
211
|
+
for (const subcommand of scan.subcommands) {
|
|
212
|
+
const afterRedirects = takeRedirects(splitWords(subcommand), out);
|
|
213
|
+
let words = afterRedirects;
|
|
214
|
+
// Skip wrappers (`sudo rm x`) and inline `VAR=value` assignments to find the real verb.
|
|
215
|
+
while (words.length > 0 && (COMMAND_PREFIXES.has(words[0].text) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[0].text))) {
|
|
216
|
+
words = words.slice(1);
|
|
217
|
+
}
|
|
218
|
+
const verb = words[0];
|
|
219
|
+
if (verb === undefined || !verb.literal)
|
|
220
|
+
continue;
|
|
221
|
+
const rawArgs = words.slice(1);
|
|
222
|
+
const args = operands(rawArgs);
|
|
223
|
+
const name = verb.text.replace(/^.*\//, ""); // /bin/rm → rm
|
|
224
|
+
if (SCRIPT_COMMANDS.has(name)) {
|
|
225
|
+
const { inPlace, files } = scriptCommandFiles(name, rawArgs);
|
|
226
|
+
pushLiteral(files, inPlace ? "write" : "read", out);
|
|
227
|
+
}
|
|
228
|
+
else if (WRITES_ALL_ARGS.has(name)) {
|
|
229
|
+
pushLiteral(args, "write", out);
|
|
230
|
+
}
|
|
231
|
+
else if (WRITES_LAST_ARG.has(name)) {
|
|
232
|
+
// Only the destination is a write; a single argument is too ambiguous to classify.
|
|
233
|
+
if (args.length >= 2) {
|
|
234
|
+
pushLiteral(args.slice(0, -1), "read", out);
|
|
235
|
+
pushLiteral(args.slice(-1), "write", out);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else if (WRITES_ARGS_AFTER_FIRST.has(name)) {
|
|
239
|
+
pushLiteral(args.slice(1), "write", out);
|
|
240
|
+
}
|
|
241
|
+
else if (READS_ALL_ARGS.has(name)) {
|
|
242
|
+
pushLiteral(args, "read", out);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return out;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=bash-paths.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True only when every part of the command is recognized as read-only.
|
|
3
|
+
*
|
|
4
|
+
* Everything unrecognized answers false, which costs a judge call. That asymmetry is the whole
|
|
5
|
+
* design: a false negative is a round trip, a false positive is an unreviewed write.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isReadOnlyBashCommand(command: string): boolean;
|
|
8
|
+
//# sourceMappingURL=bash-read-only.d.ts.map
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recognizes shell commands that cannot change anything, so the permission chain can approve
|
|
3
|
+
* them without paying for a model judge.
|
|
4
|
+
*
|
|
5
|
+
* `git status`, `ls`, `cat`, `which` are most of what an agent runs while orienting itself. In
|
|
6
|
+
* `auto` mode each of those otherwise reaches the LLM auto-approver — a round trip and tokens
|
|
7
|
+
* spent re-deciding a question with one answer. This is the small deterministic table that
|
|
8
|
+
* covers the common cases; anything it does not recognize falls through to the judge exactly as
|
|
9
|
+
* before, so the table's coverage is a cost question, never a safety one.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately kept small rather than growing into exhaustive per-tool subcommand tables and
|
|
12
|
+
* flag validators. Every entry is a maintenance burden and a chance to
|
|
13
|
+
* be wrong, and being wrong here means silently approving a write. The cheap 90% is worth
|
|
14
|
+
* having; the long tail belongs to the judge, which does not need updating when a tool adds a
|
|
15
|
+
* subcommand.
|
|
16
|
+
*/
|
|
17
|
+
import { scanShellCommand } from "./bash-rule-match.js";
|
|
18
|
+
/** Commands that only ever read, whatever their arguments. */
|
|
19
|
+
const ALWAYS_READ_ONLY = new Set([
|
|
20
|
+
"ls", "pwd", "cat", "head", "tail", "wc", "file", "stat", "du", "df", "tree", "basename",
|
|
21
|
+
"dirname", "realpath", "readlink", "which", "type", "whoami", "id", "hostname", "uname",
|
|
22
|
+
"date", "echo", "printf", "env", "printenv", "uptime", "ps", "grep", "egrep", "fgrep", "rg",
|
|
23
|
+
"find", "diff", "cmp", "sort", "uniq", "cut", "tr", "nl", "od", "xxd", "strings", "base64",
|
|
24
|
+
"md5sum", "sha1sum", "sha256sum", "shasum", "jq", "yq", "column", "less", "more", "man",
|
|
25
|
+
"true", "false", "sleep", "seq", "expr", "test",
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* Subcommand allow-lists for tools whose read/write split is the subcommand, not the binary.
|
|
29
|
+
* Anything not listed is treated as a write — `git gc` and `gh repo delete` must not reach
|
|
30
|
+
* this table's approval by being unrecognized.
|
|
31
|
+
*/
|
|
32
|
+
const SUBCOMMAND_READ_ONLY = new Map([
|
|
33
|
+
["git", new Set(["status", "log", "diff", "show", "branch", "tag", "remote", "config", "blame",
|
|
34
|
+
"describe", "rev-parse", "ls-files", "ls-remote", "ls-tree", "shortlog", "reflog", "cat-file",
|
|
35
|
+
"symbolic-ref", "whatchanged", "grep", "count-objects", "check-ignore", "var", "help"])],
|
|
36
|
+
["gh", new Set(["pr", "issue", "repo", "run", "release", "api", "auth", "browse", "search", "status"])],
|
|
37
|
+
["docker", new Set(["ps", "images", "logs", "inspect", "version", "info", "port", "top", "stats", "diff", "history"])],
|
|
38
|
+
["kubectl", new Set(["get", "describe", "logs", "explain", "version", "api-resources", "top", "config"])],
|
|
39
|
+
["npm", new Set(["ls", "list", "view", "info", "outdated", "why", "ping", "whoami", "root", "prefix", "bin"])],
|
|
40
|
+
["pnpm", new Set(["ls", "list", "why", "outdated", "root", "bin", "licenses"])],
|
|
41
|
+
["yarn", new Set(["list", "info", "why", "versions"])],
|
|
42
|
+
["cargo", new Set(["tree", "metadata", "search", "version"])],
|
|
43
|
+
["go", new Set(["version", "env", "list", "doc", "vet"])],
|
|
44
|
+
]);
|
|
45
|
+
/**
|
|
46
|
+
* Interpreters, which are only ever read-only when asked for their version. `node -e` and
|
|
47
|
+
* `python -c` take arbitrary code, so nothing else about them can be cleared here.
|
|
48
|
+
*/
|
|
49
|
+
const INTERPRETERS = new Set(["node", "python", "python3", "ruby", "perl", "php", "deno", "bun", "java"]);
|
|
50
|
+
const VERSION_FLAGS = new Set(["--version", "-v", "-V"]);
|
|
51
|
+
/**
|
|
52
|
+
* Subcommands above that become writes under a flag. `gh pr list` reads; `gh pr create` does
|
|
53
|
+
* not, and `git config --global x y` writes despite `config` being on the list.
|
|
54
|
+
*/
|
|
55
|
+
const WRITE_SUBCOMMAND_WORDS = new Set([
|
|
56
|
+
"create", "delete", "edit", "close", "merge", "reopen", "comment", "review", "rename",
|
|
57
|
+
"add", "set", "unset", "remove", "rm", "install", "uninstall", "publish", "push", "apply",
|
|
58
|
+
"clone", "fork", "sync", "update", "upgrade", "prune", "gc", "checkout", "restore", "reset",
|
|
59
|
+
]);
|
|
60
|
+
/** Anything that changes the shell's own state or hands execution to another program. */
|
|
61
|
+
const NEVER_READ_ONLY = new Set(["cd", "export", "unset", "alias", "eval", "source", ".", "exec", "sudo", "xargs", "sh", "bash", "zsh"]);
|
|
62
|
+
/**
|
|
63
|
+
* Flags that turn a reading command into a writing one. Being on a read-only list is about the
|
|
64
|
+
* binary; these are about what it was ASKED to do, and skipping them was a hole big enough to
|
|
65
|
+
* drive `find . -name '*.ts' -delete` through.
|
|
66
|
+
*
|
|
67
|
+
* Kept per-command on purpose. The same spelling means opposite things elsewhere — `-o` writes
|
|
68
|
+
* a file for `sort` but selects long format for `ls`, `-i` edits in place for `yq` but means
|
|
69
|
+
* ignore-case for `grep`. A single global list would either miss the dangerous ones or reject
|
|
70
|
+
* half the harmless reads.
|
|
71
|
+
*/
|
|
72
|
+
const WRITE_CAPABLE_FLAGS = new Map([
|
|
73
|
+
// -exec/-ok run arbitrary commands; -delete and the -f* family write directly.
|
|
74
|
+
["find", new Set(["-delete", "-exec", "-execdir", "-ok", "-okdir", "-fprint", "-fprint0", "-fprintf", "-fls"])],
|
|
75
|
+
["sort", new Set(["-o", "--output"])],
|
|
76
|
+
["yq", new Set(["-i", "--inplace", "--in-place"])],
|
|
77
|
+
["jq", new Set(["-i", "--in-place"])],
|
|
78
|
+
["git", new Set(["--output", "-o"])], // `git log/diff/show --output=FILE`
|
|
79
|
+
["docker", new Set(["--output", "-o"])],
|
|
80
|
+
["kubectl", new Set(["--output-file"])],
|
|
81
|
+
["gh", new Set(["--output"])],
|
|
82
|
+
]);
|
|
83
|
+
/** Long flags that name an output file in essentially every tool that accepts them. */
|
|
84
|
+
const UNIVERSAL_WRITE_FLAGS = new Set(["--output", "--output-file", "--out-file", "--write-out"]);
|
|
85
|
+
/** True when any argument is a flag that would make this command write. */
|
|
86
|
+
function hasWriteCapableFlag(name, args) {
|
|
87
|
+
const perCommand = WRITE_CAPABLE_FLAGS.get(name);
|
|
88
|
+
for (const arg of args) {
|
|
89
|
+
if (!arg.startsWith("-"))
|
|
90
|
+
continue;
|
|
91
|
+
// `--output=FILE` and `--output FILE` are the same flag.
|
|
92
|
+
const flag = arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg;
|
|
93
|
+
if (UNIVERSAL_WRITE_FLAGS.has(flag))
|
|
94
|
+
return true;
|
|
95
|
+
if (perCommand?.has(flag) === true)
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function subcommandIsReadOnly(name, args, allowed) {
|
|
101
|
+
const words = args.filter((word) => !word.startsWith("-"));
|
|
102
|
+
// A bare `git` or `docker` just prints usage. (Interpreters never reach here — they are
|
|
103
|
+
// handled separately, since a bare one waits on stdin.)
|
|
104
|
+
const subcommand = words[0];
|
|
105
|
+
if (subcommand === undefined)
|
|
106
|
+
return true;
|
|
107
|
+
if (!allowed.has(subcommand))
|
|
108
|
+
return false;
|
|
109
|
+
// `git config --global user.name x` writes: a value operand past the setting name.
|
|
110
|
+
if (name === "git" && subcommand === "config" && words.length > 2)
|
|
111
|
+
return false;
|
|
112
|
+
return !words.some((word) => WRITE_SUBCOMMAND_WORDS.has(word));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* True only when every part of the command is recognized as read-only.
|
|
116
|
+
*
|
|
117
|
+
* Everything unrecognized answers false, which costs a judge call. That asymmetry is the whole
|
|
118
|
+
* design: a false negative is a round trip, a false positive is an unreviewed write.
|
|
119
|
+
*/
|
|
120
|
+
export function isReadOnlyBashCommand(command) {
|
|
121
|
+
// Substitutions, eval and unbalanced quotes can run anything; the scan reports them and
|
|
122
|
+
// hands back no subcommands to inspect.
|
|
123
|
+
const scan = scanShellCommand(command);
|
|
124
|
+
if (scan.risky || scan.subcommands.length === 0)
|
|
125
|
+
return false;
|
|
126
|
+
// Any redirection can create or truncate a file, whatever the command in front of it is.
|
|
127
|
+
// `<` alone would be safe, but `<<` heredocs and `>` share too much syntax to split hairs.
|
|
128
|
+
if (/(^|[^<>\d&])>|>>/.test(command))
|
|
129
|
+
return false;
|
|
130
|
+
for (const subcommand of scan.subcommands) {
|
|
131
|
+
const words = subcommand.split(/\s+/).filter((word) => word.length > 0);
|
|
132
|
+
let index = 0;
|
|
133
|
+
// Inline `VAR=value` prefixes do not change what the command does to the filesystem.
|
|
134
|
+
while (index < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[index]))
|
|
135
|
+
index++;
|
|
136
|
+
const verb = words[index];
|
|
137
|
+
if (verb === undefined)
|
|
138
|
+
return false;
|
|
139
|
+
const name = verb.replace(/^.*\//, "");
|
|
140
|
+
if (NEVER_READ_ONLY.has(name))
|
|
141
|
+
return false;
|
|
142
|
+
const args = words.slice(index + 1);
|
|
143
|
+
// Checked before the name lookups: a write-capable flag disqualifies the command no matter
|
|
144
|
+
// how read-only the binary is on its own.
|
|
145
|
+
if (hasWriteCapableFlag(name, args))
|
|
146
|
+
return false;
|
|
147
|
+
if (INTERPRETERS.has(name)) {
|
|
148
|
+
// Only `node --version` and friends; a bare interpreter waits on stdin and any other
|
|
149
|
+
// argument is a script.
|
|
150
|
+
if (args.length === 0 || !args.every((word) => VERSION_FLAGS.has(word)))
|
|
151
|
+
return false;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const allowed = SUBCOMMAND_READ_ONLY.get(name);
|
|
155
|
+
if (allowed !== undefined) {
|
|
156
|
+
if (!subcommandIsReadOnly(name, args, allowed))
|
|
157
|
+
return false;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!ALWAYS_READ_ONLY.has(name))
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=bash-read-only.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bash permission rule matching.
|
|
3
|
+
*
|
|
4
|
+
* Quote-aware splitting
|
|
5
|
+
* of compound commands plus conservative rejection of shell constructs that can
|
|
6
|
+
* execute hidden subcommands. A risky command is covered by no parameterized
|
|
7
|
+
* rule and falls through to the permission chain's fallback ask.
|
|
8
|
+
*/
|
|
9
|
+
export interface ShellScanResult {
|
|
10
|
+
readonly subcommands: readonly string[];
|
|
11
|
+
readonly risky: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function scanShellCommand(command: string): ShellScanResult;
|
|
14
|
+
export declare function permissionRuleExtractPrefix(permissionRule: string): string | null;
|
|
15
|
+
export declare function hasWildcards(pattern: string): boolean;
|
|
16
|
+
export declare function matchWildcardPattern(pattern: string, command: string): boolean;
|
|
17
|
+
export declare function stripSafeEnvPrefix(subcommand: string): string;
|
|
18
|
+
export declare function singleCommandMatchesRule(pattern: string, subcommand: string): boolean;
|
|
19
|
+
export declare function matchesBashRule(ruleArgs: string, command: string): boolean;
|
|
20
|
+
//# sourceMappingURL=bash-rule-match.d.ts.map
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bash permission rule matching.
|
|
3
|
+
*
|
|
4
|
+
* Quote-aware splitting
|
|
5
|
+
* of compound commands plus conservative rejection of shell constructs that can
|
|
6
|
+
* execute hidden subcommands. A risky command is covered by no parameterized
|
|
7
|
+
* rule and falls through to the permission chain's fallback ask.
|
|
8
|
+
*/
|
|
9
|
+
const RISKY_COMMAND_WORDS = new Set(["eval", "source", "."]);
|
|
10
|
+
export function scanShellCommand(command) {
|
|
11
|
+
const subcommands = [];
|
|
12
|
+
let current = "";
|
|
13
|
+
let inSingle = false;
|
|
14
|
+
let inDouble = false;
|
|
15
|
+
let risky = false;
|
|
16
|
+
const pushCurrent = () => {
|
|
17
|
+
const trimmed = current.trim();
|
|
18
|
+
if (trimmed !== "")
|
|
19
|
+
subcommands.push(trimmed);
|
|
20
|
+
current = "";
|
|
21
|
+
};
|
|
22
|
+
for (let i = 0; i < command.length; i++) {
|
|
23
|
+
const ch = command[i];
|
|
24
|
+
const next = command[i + 1];
|
|
25
|
+
if (inSingle) {
|
|
26
|
+
if (ch === "'")
|
|
27
|
+
inSingle = false;
|
|
28
|
+
current += ch;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (ch === "\\" && next !== undefined) {
|
|
32
|
+
current += ch + next;
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (ch === "'" && !inDouble) {
|
|
37
|
+
inSingle = true;
|
|
38
|
+
current += ch;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (ch === '"') {
|
|
42
|
+
inDouble = !inDouble;
|
|
43
|
+
current += ch;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (ch === "`" || (ch === "$" && next === "(")) {
|
|
47
|
+
risky = true;
|
|
48
|
+
current += ch;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!inDouble) {
|
|
52
|
+
if ((ch === "<" || ch === ">") && next === "(") {
|
|
53
|
+
risky = true;
|
|
54
|
+
current += ch;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (ch === "&" && next === "&") {
|
|
58
|
+
pushCurrent();
|
|
59
|
+
i++;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (ch === "|" && next === "|") {
|
|
63
|
+
pushCurrent();
|
|
64
|
+
i++;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (ch === "|" || ch === "&" || ch === ";" || ch === "\n") {
|
|
68
|
+
pushCurrent();
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
current += ch;
|
|
73
|
+
}
|
|
74
|
+
if (inSingle || inDouble)
|
|
75
|
+
risky = true;
|
|
76
|
+
pushCurrent();
|
|
77
|
+
if (!risky) {
|
|
78
|
+
for (const sub of subcommands) {
|
|
79
|
+
const firstWord = sub.split(/\s+/, 1)[0] ?? "";
|
|
80
|
+
if (RISKY_COMMAND_WORDS.has(firstWord)) {
|
|
81
|
+
risky = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return risky ? { subcommands: [], risky: true } : { subcommands, risky: false };
|
|
87
|
+
}
|
|
88
|
+
export function permissionRuleExtractPrefix(permissionRule) {
|
|
89
|
+
const match = /^(.+):\*$/.exec(permissionRule);
|
|
90
|
+
return match?.[1] ?? null;
|
|
91
|
+
}
|
|
92
|
+
export function hasWildcards(pattern) {
|
|
93
|
+
if (pattern.endsWith(":*"))
|
|
94
|
+
return false;
|
|
95
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
96
|
+
if (pattern[i] === "*") {
|
|
97
|
+
let backslashCount = 0;
|
|
98
|
+
let j = i - 1;
|
|
99
|
+
while (j >= 0 && pattern[j] === "\\") {
|
|
100
|
+
backslashCount++;
|
|
101
|
+
j--;
|
|
102
|
+
}
|
|
103
|
+
if (backslashCount % 2 === 0)
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
const ESCAPED_STAR_PLACEHOLDER = "\0ESCAPED_STAR\0";
|
|
110
|
+
const ESCAPED_BACKSLASH_PLACEHOLDER = "\0ESCAPED_BACKSLASH\0";
|
|
111
|
+
export function matchWildcardPattern(pattern, command) {
|
|
112
|
+
const trimmedPattern = pattern.trim();
|
|
113
|
+
let processed = "";
|
|
114
|
+
let i = 0;
|
|
115
|
+
while (i < trimmedPattern.length) {
|
|
116
|
+
const char = trimmedPattern[i];
|
|
117
|
+
if (char === "\\" && i + 1 < trimmedPattern.length) {
|
|
118
|
+
const nextChar = trimmedPattern[i + 1];
|
|
119
|
+
if (nextChar === "*") {
|
|
120
|
+
processed += ESCAPED_STAR_PLACEHOLDER;
|
|
121
|
+
i += 2;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (nextChar === "\\") {
|
|
125
|
+
processed += ESCAPED_BACKSLASH_PLACEHOLDER;
|
|
126
|
+
i += 2;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
processed += char;
|
|
131
|
+
i++;
|
|
132
|
+
}
|
|
133
|
+
const escaped = processed.replace(/[.+?^${}()|[\]\\'"]/g, "\\$&");
|
|
134
|
+
const withWildcards = escaped.replace(/\*/g, ".*");
|
|
135
|
+
let regexPattern = withWildcards
|
|
136
|
+
.replaceAll(ESCAPED_STAR_PLACEHOLDER, "\\*")
|
|
137
|
+
.replaceAll(ESCAPED_BACKSLASH_PLACEHOLDER, "\\\\");
|
|
138
|
+
const unescapedStarCount = (processed.match(/\*/g) ?? []).length;
|
|
139
|
+
if (regexPattern.endsWith(" .*") && unescapedStarCount === 1) {
|
|
140
|
+
regexPattern = `${regexPattern.slice(0, -3)}( .*)?`;
|
|
141
|
+
}
|
|
142
|
+
return new RegExp(`^${regexPattern}$`, "s").test(command);
|
|
143
|
+
}
|
|
144
|
+
const SAFE_ENV_VARS = new Set([
|
|
145
|
+
"GOEXPERIMENT", "GOOS", "GOARCH", "CGO_ENABLED", "GO111MODULE",
|
|
146
|
+
"RUST_BACKTRACE", "RUST_LOG",
|
|
147
|
+
"NODE_ENV",
|
|
148
|
+
"PYTHONUNBUFFERED", "PYTHONDONTWRITEBYTECODE",
|
|
149
|
+
"PYTEST_DISABLE_PLUGIN_AUTOLOAD", "PYTEST_DEBUG",
|
|
150
|
+
"ANTHROPIC_API_KEY",
|
|
151
|
+
"LANG", "LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_TIME", "CHARSET",
|
|
152
|
+
"TERM", "COLORTERM", "NO_COLOR", "FORCE_COLOR", "TZ",
|
|
153
|
+
"LS_COLORS", "LSCOLORS", "GREP_COLOR", "GREP_COLORS", "GCC_COLORS",
|
|
154
|
+
"TIME_STYLE", "BLOCK_SIZE", "BLOCKSIZE",
|
|
155
|
+
]);
|
|
156
|
+
const ENV_ASSIGNMENT_RE = /^([A-Za-z_][A-Za-z0-9_]*)=/;
|
|
157
|
+
export function stripSafeEnvPrefix(subcommand) {
|
|
158
|
+
const tokens = subcommand.split(/\s+/);
|
|
159
|
+
let i = 0;
|
|
160
|
+
while (i < tokens.length) {
|
|
161
|
+
const match = ENV_ASSIGNMENT_RE.exec(tokens[i]);
|
|
162
|
+
if (!match || !SAFE_ENV_VARS.has(match[1]))
|
|
163
|
+
break;
|
|
164
|
+
i++;
|
|
165
|
+
}
|
|
166
|
+
return tokens.slice(i).join(" ");
|
|
167
|
+
}
|
|
168
|
+
export function singleCommandMatchesRule(pattern, subcommand) {
|
|
169
|
+
const trimmedPattern = pattern.trim();
|
|
170
|
+
const prefix = permissionRuleExtractPrefix(trimmedPattern);
|
|
171
|
+
if (prefix !== null)
|
|
172
|
+
return subcommand.startsWith(prefix);
|
|
173
|
+
if (hasWildcards(trimmedPattern))
|
|
174
|
+
return matchWildcardPattern(trimmedPattern, subcommand);
|
|
175
|
+
return subcommand === trimmedPattern;
|
|
176
|
+
}
|
|
177
|
+
export function matchesBashRule(ruleArgs, command) {
|
|
178
|
+
if (ruleArgs.length === 0)
|
|
179
|
+
return true;
|
|
180
|
+
const negated = ruleArgs.startsWith("!");
|
|
181
|
+
const pattern = negated ? ruleArgs.slice(1) : ruleArgs;
|
|
182
|
+
const hit = commandCoveredByRule(pattern, command);
|
|
183
|
+
return negated ? !hit : hit;
|
|
184
|
+
}
|
|
185
|
+
function commandCoveredByRule(pattern, command) {
|
|
186
|
+
const scan = scanShellCommand(command.trim());
|
|
187
|
+
if (scan.risky || scan.subcommands.length === 0)
|
|
188
|
+
return false;
|
|
189
|
+
return scan.subcommands.every((sub) => singleCommandMatchesRule(pattern, stripSafeEnvPrefix(sub)));
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=bash-rule-match.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const MEDIA_SNIFF_BYTES = 512;
|
|
2
|
+
export interface FileType {
|
|
3
|
+
readonly kind: "text" | "image" | "unknown";
|
|
4
|
+
readonly mimeType: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const IMAGE_MIME_BY_SUFFIX: Readonly<Record<string, string>>;
|
|
7
|
+
export declare const NON_TEXT_SUFFIXES: ReadonlySet<string>;
|
|
8
|
+
export declare function sniffMediaFromMagic(data: Buffer | Uint8Array): FileType | null;
|
|
9
|
+
export declare function detectFileType(path: string, header?: Buffer | Uint8Array): FileType;
|
|
10
|
+
//# sourceMappingURL=file-type.d.ts.map
|