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,40 @@
|
|
|
1
|
+
import { CLASSIFIER_BASE_PROMPT, CLASSIFIER_PERMISSIONS_TEMPLATE } from "./prompts-data.js";
|
|
2
|
+
export { CLASSIFIER_BASE_PROMPT, CLASSIFIER_PERMISSIONS_TEMPLATE };
|
|
3
|
+
// Stage-2 XML output instructions that replace the tool-use line from the base prompt. The
|
|
4
|
+
// classifier emits `<block>yes|no</block>` (plus an optional `<reason>`), which the parser
|
|
5
|
+
// reads back — this avoids depending on forced tool-calls / tool_choice, which the model
|
|
6
|
+
// abstraction does not expose.
|
|
7
|
+
const XML_OUTPUT_FORMAT = [
|
|
8
|
+
"## Output Format",
|
|
9
|
+
"",
|
|
10
|
+
"If the action should be blocked:",
|
|
11
|
+
"<block>yes</block><reason>one short sentence</reason>",
|
|
12
|
+
"",
|
|
13
|
+
"If the action should be allowed:",
|
|
14
|
+
"<block>no</block>",
|
|
15
|
+
"",
|
|
16
|
+
"Do NOT include a <reason> tag when the action is allowed.",
|
|
17
|
+
"Your ENTIRE response MUST begin with <block>. Do NOT output any analysis, reasoning, or commentary before <block>. No \"Looking at...\" or similar preamble.",
|
|
18
|
+
].join("\n");
|
|
19
|
+
const TOOL_USE_LINE = "Use the classify_result tool to report your classification.";
|
|
20
|
+
function replaceTaggedSection(prompt, tag, values) {
|
|
21
|
+
const re = new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`);
|
|
22
|
+
// No user values → keep the template's own defaults (the tag's existing contents).
|
|
23
|
+
if (values === undefined || values.length === 0)
|
|
24
|
+
return prompt.replace(re, (_m, defaults) => defaults);
|
|
25
|
+
const rendered = values.map((v) => `- ${v}`).join("\n");
|
|
26
|
+
return prompt.replace(re, () => rendered);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Assemble the full classifier system prompt: base prompt + permissions template, with the
|
|
30
|
+
* three user sections substituted (user values replace the template defaults), and the
|
|
31
|
+
* trailing tool-use line swapped for XML output.
|
|
32
|
+
*/
|
|
33
|
+
export function buildClassifierSystemPrompt(rules = {}) {
|
|
34
|
+
let prompt = CLASSIFIER_BASE_PROMPT.replace("<permissions_template>", () => CLASSIFIER_PERMISSIONS_TEMPLATE);
|
|
35
|
+
prompt = replaceTaggedSection(prompt, "user_allow_rules_to_replace", rules.allow);
|
|
36
|
+
prompt = replaceTaggedSection(prompt, "user_deny_rules_to_replace", rules.deny);
|
|
37
|
+
prompt = replaceTaggedSection(prompt, "user_environment_to_replace", rules.environment);
|
|
38
|
+
return prompt.replace(TOOL_USE_LINE, XML_OUTPUT_FORMAT);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Message } from "../../protocol/index.ts";
|
|
2
|
+
import type { Tool } from "../../tool/types.ts";
|
|
3
|
+
export type ToolLookup = ReadonlyMap<string, Tool>;
|
|
4
|
+
export declare function buildToolLookup(tools: readonly Tool[] | undefined): ToolLookup;
|
|
5
|
+
/**
|
|
6
|
+
* Project a tool call to its compact, security-relevant form. Uses the tool's
|
|
7
|
+
* `toAutoApprovalInput` when available; on a throw (history args may be malformed) or when the
|
|
8
|
+
* tool is unknown, falls back to the raw arguments object. Returns `""` when the tool declares
|
|
9
|
+
* no security relevance (caller skips the block / allows the action).
|
|
10
|
+
*/
|
|
11
|
+
export declare function projectToolCall(name: string, args: unknown, tool: Tool | undefined, lookup: ToolLookup): unknown;
|
|
12
|
+
/** One JSONL transcript line: `{"<name>": <projection>}` for a call, or `""` to skip. */
|
|
13
|
+
export declare function serializeToolCall(name: string, args: unknown, tool: Tool | undefined, lookup: ToolLookup): string;
|
|
14
|
+
/**
|
|
15
|
+
* Build the compact transcript string the classifier reads as context: user text plus the
|
|
16
|
+
* agent's prior tool calls (projected), one JSONL line each. Assistant prose and tool results
|
|
17
|
+
* are deliberately excluded — model-authored text could be crafted to steer the judge, and the
|
|
18
|
+
* threat model only needs what the agent *did*, not what it said. `excludeToolCallId` drops the
|
|
19
|
+
* action under review so it isn't duplicated (the caller appends it as the final action block).
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildTranscriptText(messages: readonly Message[], lookup: ToolLookup, excludeToolCallId?: string): string;
|
|
22
|
+
//# sourceMappingURL=transcript.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export function buildToolLookup(tools) {
|
|
2
|
+
const map = new Map();
|
|
3
|
+
for (const tool of tools ?? [])
|
|
4
|
+
map.set(tool.schema.name, tool);
|
|
5
|
+
return map;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Project a tool call to its compact, security-relevant form. Uses the tool's
|
|
9
|
+
* `toAutoApprovalInput` when available; on a throw (history args may be malformed) or when the
|
|
10
|
+
* tool is unknown, falls back to the raw arguments object. Returns `""` when the tool declares
|
|
11
|
+
* no security relevance (caller skips the block / allows the action).
|
|
12
|
+
*/
|
|
13
|
+
export function projectToolCall(name, args, tool, lookup) {
|
|
14
|
+
const resolved = tool ?? lookup.get(name);
|
|
15
|
+
const project = resolved?.toAutoApprovalInput?.bind(resolved);
|
|
16
|
+
if (project === undefined)
|
|
17
|
+
return args ?? {};
|
|
18
|
+
try {
|
|
19
|
+
const out = project(args ?? {});
|
|
20
|
+
return out ?? args ?? {};
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return args ?? {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** One JSONL transcript line: `{"<name>": <projection>}` for a call, or `""` to skip. */
|
|
27
|
+
export function serializeToolCall(name, args, tool, lookup) {
|
|
28
|
+
const projected = projectToolCall(name, args, tool, lookup);
|
|
29
|
+
if (projected === "")
|
|
30
|
+
return "";
|
|
31
|
+
// JSON-encode so hostile content can't break out of its string context to forge a
|
|
32
|
+
// `{"user": ...}` line — newlines become `\n` inside the value.
|
|
33
|
+
return `${JSON.stringify({ [name]: projected })}\n`;
|
|
34
|
+
}
|
|
35
|
+
function userText(message) {
|
|
36
|
+
if (message.role !== "user")
|
|
37
|
+
return "";
|
|
38
|
+
const content = message.content;
|
|
39
|
+
if (typeof content === "string")
|
|
40
|
+
return content;
|
|
41
|
+
return content
|
|
42
|
+
.filter((c) => c.type === "text")
|
|
43
|
+
.map((c) => c.text)
|
|
44
|
+
.join("\n");
|
|
45
|
+
}
|
|
46
|
+
function toolCalls(message) {
|
|
47
|
+
return message.content.filter((c) => c.type === "toolCall");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build the compact transcript string the classifier reads as context: user text plus the
|
|
51
|
+
* agent's prior tool calls (projected), one JSONL line each. Assistant prose and tool results
|
|
52
|
+
* are deliberately excluded — model-authored text could be crafted to steer the judge, and the
|
|
53
|
+
* threat model only needs what the agent *did*, not what it said. `excludeToolCallId` drops the
|
|
54
|
+
* action under review so it isn't duplicated (the caller appends it as the final action block).
|
|
55
|
+
*/
|
|
56
|
+
export function buildTranscriptText(messages, lookup, excludeToolCallId) {
|
|
57
|
+
let out = "";
|
|
58
|
+
for (const message of messages) {
|
|
59
|
+
if (message.role === "user") {
|
|
60
|
+
const text = userText(message);
|
|
61
|
+
if (text.length > 0)
|
|
62
|
+
out += `${JSON.stringify({ user: text })}\n`;
|
|
63
|
+
}
|
|
64
|
+
else if (message.role === "assistant") {
|
|
65
|
+
for (const call of toolCalls(message)) {
|
|
66
|
+
if (call.id === excludeToolCallId)
|
|
67
|
+
continue;
|
|
68
|
+
out += serializeToolCall(call.name, call.arguments, undefined, lookup);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// toolResult messages are intentionally skipped.
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** `true` = should block, `false` = allow, `null` = unparseable (caller fails closed). */
|
|
2
|
+
export declare function parseXmlBlock(text: string): boolean | null;
|
|
3
|
+
export declare function parseXmlReason(text: string): string | null;
|
|
4
|
+
export declare function parseXmlThinking(text: string): string | null;
|
|
5
|
+
//# sourceMappingURL=xml.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// XML response parsing for the two-stage classifier.
|
|
2
|
+
// The classifier emits `<block>yes|no</block>` plus an optional `<reason>`; stage 2 may also
|
|
3
|
+
// emit `<thinking>`. Thinking content is stripped first so tags inside the model's reasoning
|
|
4
|
+
// aren't mistaken for the verdict.
|
|
5
|
+
function stripThinking(text) {
|
|
6
|
+
return text.replace(/<thinking>[\s\S]*?<\/thinking>/g, "").replace(/<thinking>[\s\S]*$/, "");
|
|
7
|
+
}
|
|
8
|
+
/** `true` = should block, `false` = allow, `null` = unparseable (caller fails closed). */
|
|
9
|
+
export function parseXmlBlock(text) {
|
|
10
|
+
const matches = [...stripThinking(text).matchAll(/<block>(yes|no)\b(<\/block>)?/gi)];
|
|
11
|
+
if (matches.length === 0)
|
|
12
|
+
return null;
|
|
13
|
+
return matches[0][1].toLowerCase() === "yes";
|
|
14
|
+
}
|
|
15
|
+
export function parseXmlReason(text) {
|
|
16
|
+
const matches = [...stripThinking(text).matchAll(/<reason>([\s\S]*?)<\/reason>/g)];
|
|
17
|
+
if (matches.length === 0)
|
|
18
|
+
return null;
|
|
19
|
+
return matches[0][1].trim();
|
|
20
|
+
}
|
|
21
|
+
export function parseXmlThinking(text) {
|
|
22
|
+
const match = /<thinking>([\s\S]*?)<\/thinking>/.exec(text);
|
|
23
|
+
return match ? match[1].trim() : null;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=xml.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { PermissionMode, PermissionRule, PermissionRuleDecision, PermissionRuleScope, PermissionPolicy, PermissionPolicyContext, PermissionPolicyResult, ApprovalRequest, ApprovalRequestOptions, ApprovalResponse, QuestionOption, QuestionItem, QuestionRequest, QuestionAnswerValue, QuestionAnswers, QuestionAnswerMethod, QuestionResponse, QuestionResult, Responder, AutoApprover, AutoApprovalInput, AutoApprovalVerdict, } from "./types.ts";
|
|
2
|
+
export { PermissionManager } from "./manager.ts";
|
|
3
|
+
export type { AuthorizeProviders, PermissionManagerOptions } from "./manager.ts";
|
|
4
|
+
export { parsePattern, matchPermissionRule, permissionPatternError } from "./matches-rule.ts";
|
|
5
|
+
export { createPolicies } from "./policies.ts";
|
|
6
|
+
export { LlmAutoApprover, buildClassifierSystemPrompt, CLASSIFIER_BASE_PROMPT, CLASSIFIER_PERMISSIONS_TEMPLATE, type AutoApprovalOutcome, type AutoApprovalReport, type ClassifierRules, type LlmAutoApproverOptions, type TwoStageMode, } from "./auto-approver/index.ts";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PermissionManager } from "./manager.js";
|
|
2
|
+
export { parsePattern, matchPermissionRule, permissionPatternError } from "./matches-rule.js";
|
|
3
|
+
export { createPolicies } from "./policies.js";
|
|
4
|
+
export { LlmAutoApprover, buildClassifierSystemPrompt, CLASSIFIER_BASE_PROMPT, CLASSIFIER_PERMISSIONS_TEMPLATE, } from "./auto-approver/index.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { AuthorizeToolExecutionResult, ResolvedToolExecutionHookContext } from "../loop/types.ts";
|
|
2
|
+
import type { Message } from "../protocol/index.ts";
|
|
3
|
+
import type { PathClass } from "../tool/policies/path-access.ts";
|
|
4
|
+
import type { Tool } from "../tool/types.ts";
|
|
5
|
+
import type { GitWorkTreeMachine } from "../tool/support/git-worktree.ts";
|
|
6
|
+
import type { Logger } from "../logging/index.ts";
|
|
7
|
+
import type { AutoApprover, PermissionMode, PermissionPolicy, PermissionRule, Responder } from "./types.ts";
|
|
8
|
+
export interface PermissionManagerOptions {
|
|
9
|
+
readonly mode?: PermissionMode;
|
|
10
|
+
readonly rules?: readonly PermissionRule[];
|
|
11
|
+
readonly responder?: Responder;
|
|
12
|
+
readonly cwd?: string;
|
|
13
|
+
readonly pathClass?: PathClass;
|
|
14
|
+
readonly machine?: GitWorkTreeMachine;
|
|
15
|
+
readonly policyOverrides?: ReadonlyMap<string, PermissionPolicy>;
|
|
16
|
+
/** The `auto`-mode judge. Consulted for would-prompt actions when `mode === "auto"`. */
|
|
17
|
+
readonly autoApprover?: AutoApprover;
|
|
18
|
+
/** Supplies the live conversation to the judge (the authorize ctx carries no transcript).
|
|
19
|
+
* Standalone default; a frame-scoped authorizer (`authorizerFor`) overrides it. */
|
|
20
|
+
readonly getTranscript?: () => readonly Message[];
|
|
21
|
+
/** Supplies the tool registry to the judge so it can project prior tool calls faithfully.
|
|
22
|
+
* Standalone default; a frame-scoped authorizer (`authorizerFor`) overrides it. */
|
|
23
|
+
readonly getTools?: () => readonly Tool[];
|
|
24
|
+
/** Optional diagnostics sink: load-time warnings (a malformed rule pattern silently never
|
|
25
|
+
* matches — fail-open for `deny` — so such rules are flagged as they enter the manager)
|
|
26
|
+
* and `auto`-mode judge outcomes (verdict/reason/duration per consult, judge errors). */
|
|
27
|
+
readonly logger?: Logger;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Frame-scoped context for the `auto`-mode judge. The manager is a session-level
|
|
31
|
+
* singleton (shared mode / rules / approval memory), but the transcript and tool registry
|
|
32
|
+
* belong to ONE runtime frame — concurrent sub-agent frames each have their own. They are
|
|
33
|
+
* therefore never stored on the manager: each frame binds its own via `authorizerFor`.
|
|
34
|
+
*/
|
|
35
|
+
export interface AuthorizeProviders {
|
|
36
|
+
readonly getTranscript?: () => readonly Message[];
|
|
37
|
+
readonly getTools?: () => readonly Tool[];
|
|
38
|
+
}
|
|
39
|
+
export declare class PermissionManager {
|
|
40
|
+
private currentMode;
|
|
41
|
+
private readonly ruleList;
|
|
42
|
+
private readonly sessionPatterns;
|
|
43
|
+
private readonly responder;
|
|
44
|
+
private readonly cwd;
|
|
45
|
+
private readonly pathClass;
|
|
46
|
+
private readonly machine;
|
|
47
|
+
private readonly policies;
|
|
48
|
+
private readonly autoApprover;
|
|
49
|
+
private readonly getTranscript;
|
|
50
|
+
private readonly getTools;
|
|
51
|
+
private readonly logger;
|
|
52
|
+
constructor(options?: PermissionManagerOptions);
|
|
53
|
+
get mode(): PermissionMode;
|
|
54
|
+
setMode(mode: PermissionMode): void;
|
|
55
|
+
addRule(rule: PermissionRule): void;
|
|
56
|
+
/** A malformed pattern makes the rule silently never match — fail-open for `deny`. Surface
|
|
57
|
+
* it once, when the rule enters the manager, rather than swallowing it on every match. */
|
|
58
|
+
private warnIfMalformed;
|
|
59
|
+
/**
|
|
60
|
+
* Bind frame-scoped judge context (this frame's live transcript + tool registry) to an
|
|
61
|
+
* authorizer. Shared session state (mode/rules/approval memory) stays on the manager;
|
|
62
|
+
* the providers live only in the returned closure, so concurrent frames can't overwrite
|
|
63
|
+
* each other's.
|
|
64
|
+
*/
|
|
65
|
+
authorizerFor(providers: AuthorizeProviders): (ctx: ResolvedToolExecutionHookContext) => Promise<AuthorizeToolExecutionResult | undefined>;
|
|
66
|
+
/** Standalone authorize: judge context falls back to the constructor-supplied providers. */
|
|
67
|
+
readonly authorize: (ctx: ResolvedToolExecutionHookContext) => Promise<AuthorizeToolExecutionResult | undefined>;
|
|
68
|
+
private authorizeWith;
|
|
69
|
+
applyApproval(approvalRule: string, response: {
|
|
70
|
+
decision: "approved" | "rejected" | "cancelled";
|
|
71
|
+
scope?: "session";
|
|
72
|
+
}): boolean;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createPolicies } from "./policies.js";
|
|
2
|
+
import { permissionPatternError } from "./matches-rule.js";
|
|
3
|
+
export class PermissionManager {
|
|
4
|
+
currentMode;
|
|
5
|
+
ruleList;
|
|
6
|
+
sessionPatterns = new Set();
|
|
7
|
+
responder;
|
|
8
|
+
cwd;
|
|
9
|
+
pathClass;
|
|
10
|
+
machine;
|
|
11
|
+
policies;
|
|
12
|
+
autoApprover;
|
|
13
|
+
getTranscript;
|
|
14
|
+
getTools;
|
|
15
|
+
logger;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.currentMode = options.mode ?? "manual";
|
|
18
|
+
this.ruleList = [...(options.rules ?? [])];
|
|
19
|
+
this.responder = options.responder;
|
|
20
|
+
this.cwd = options.cwd ?? "";
|
|
21
|
+
this.pathClass = options.pathClass ?? "posix";
|
|
22
|
+
this.machine = options.machine;
|
|
23
|
+
this.autoApprover = options.autoApprover;
|
|
24
|
+
this.getTranscript = options.getTranscript;
|
|
25
|
+
this.getTools = options.getTools;
|
|
26
|
+
this.logger = options.logger;
|
|
27
|
+
for (const rule of this.ruleList)
|
|
28
|
+
this.warnIfMalformed(rule);
|
|
29
|
+
const state = {
|
|
30
|
+
mode: () => this.currentMode,
|
|
31
|
+
rules: () => this.ruleList,
|
|
32
|
+
sessionApprovalRulePatterns: () => [...this.sessionPatterns],
|
|
33
|
+
cwd: () => this.cwd,
|
|
34
|
+
pathClass: () => this.pathClass,
|
|
35
|
+
machine: () => this.machine,
|
|
36
|
+
};
|
|
37
|
+
this.policies = createPolicies(state, options.policyOverrides);
|
|
38
|
+
}
|
|
39
|
+
get mode() {
|
|
40
|
+
return this.currentMode;
|
|
41
|
+
}
|
|
42
|
+
setMode(mode) {
|
|
43
|
+
this.currentMode = mode;
|
|
44
|
+
}
|
|
45
|
+
addRule(rule) {
|
|
46
|
+
this.warnIfMalformed(rule);
|
|
47
|
+
this.ruleList.push(rule);
|
|
48
|
+
}
|
|
49
|
+
/** A malformed pattern makes the rule silently never match — fail-open for `deny`. Surface
|
|
50
|
+
* it once, when the rule enters the manager, rather than swallowing it on every match. */
|
|
51
|
+
warnIfMalformed(rule) {
|
|
52
|
+
const error = permissionPatternError(rule.pattern);
|
|
53
|
+
if (error === undefined)
|
|
54
|
+
return;
|
|
55
|
+
this.logger?.log("warn", `Permission rule with malformed pattern ${JSON.stringify(rule.pattern)} (decision "${rule.decision}") will never match — for a deny rule this fails open. ${error}`, { pattern: rule.pattern, decision: rule.decision });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Bind frame-scoped judge context (this frame's live transcript + tool registry) to an
|
|
59
|
+
* authorizer. Shared session state (mode/rules/approval memory) stays on the manager;
|
|
60
|
+
* the providers live only in the returned closure, so concurrent frames can't overwrite
|
|
61
|
+
* each other's.
|
|
62
|
+
*/
|
|
63
|
+
authorizerFor(providers) {
|
|
64
|
+
return (ctx) => this.authorizeWith(ctx, providers);
|
|
65
|
+
}
|
|
66
|
+
/** Standalone authorize: judge context falls back to the constructor-supplied providers. */
|
|
67
|
+
authorize = async (ctx) => this.authorizeWith(ctx, undefined);
|
|
68
|
+
async authorizeWith(ctx, providers) {
|
|
69
|
+
let result;
|
|
70
|
+
let policyName;
|
|
71
|
+
for (const policy of this.policies) {
|
|
72
|
+
result = await policy.evaluate(ctx);
|
|
73
|
+
if (result) {
|
|
74
|
+
policyName = policy.name;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!result || result.kind === "approve")
|
|
79
|
+
return undefined; // proceed
|
|
80
|
+
if (result.kind === "deny") {
|
|
81
|
+
return { block: true, reason: result.message ?? "Denied by permission policy." };
|
|
82
|
+
}
|
|
83
|
+
// `auto` mode: hand this would-prompt action to the model judge instead of a human.
|
|
84
|
+
// The static chain already short-circuited approve/deny above, so the judge only ever
|
|
85
|
+
// sees genuine asks — including the safety floor (sensitive file / .git / cwd-outside),
|
|
86
|
+
// which is what keeps the judge honest. `classifierApprovable === false` (e.g. an
|
|
87
|
+
// explicit user ask rule) stays human-only. Fail-closed: a thrown judge escalates.
|
|
88
|
+
if (this.currentMode === "auto" && this.autoApprover && result.classifierApprovable !== false) {
|
|
89
|
+
let allow = false;
|
|
90
|
+
const startedAt = Date.now();
|
|
91
|
+
try {
|
|
92
|
+
const verdict = await this.autoApprover.classify({
|
|
93
|
+
ctx,
|
|
94
|
+
transcript: (providers?.getTranscript ?? this.getTranscript)?.() ?? [],
|
|
95
|
+
approvalRule: ctx.plan.approvalRule,
|
|
96
|
+
tools: (providers?.getTools ?? this.getTools)?.(),
|
|
97
|
+
});
|
|
98
|
+
allow = verdict.decision === "allow";
|
|
99
|
+
// Without this trail, a mis-tuned or dead judge is indistinguishable from "auto
|
|
100
|
+
// mode just always asks" — every escalation looks like a normal approval prompt.
|
|
101
|
+
this.logger?.log(allow ? "debug" : "info", `auto-approval judge: ${verdict.decision}`, {
|
|
102
|
+
toolName: ctx.toolCall.name,
|
|
103
|
+
approvalRule: ctx.plan.approvalRule,
|
|
104
|
+
durationMs: Date.now() - startedAt,
|
|
105
|
+
...(verdict.reason !== undefined ? { reason: verdict.reason } : {}),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
allow = false; // judge unavailable → escalate to the human path below
|
|
110
|
+
this.logger?.log("warn", "auto-approval judge threw; escalating to approval", {
|
|
111
|
+
toolName: ctx.toolCall.name,
|
|
112
|
+
approvalRule: ctx.plan.approvalRule,
|
|
113
|
+
durationMs: Date.now() - startedAt,
|
|
114
|
+
error: error instanceof Error ? error.message : String(error),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (allow)
|
|
118
|
+
return undefined; // judge cleared it → proceed, no prompt
|
|
119
|
+
// escalate → fall through to the responder / interrupt handling below
|
|
120
|
+
}
|
|
121
|
+
// • no Responder injected here (the Runner-driven / durable path) → reify + bubble
|
|
122
|
+
// `interrupt`; the loop suspends and the Runner's onInterrupt decides live/durable.
|
|
123
|
+
// • a Responder IS injected (standalone / live use) → answer in place.
|
|
124
|
+
if (this.responder === undefined) {
|
|
125
|
+
return {
|
|
126
|
+
interrupt: {
|
|
127
|
+
kind: "approval",
|
|
128
|
+
toolCallId: ctx.toolCall.id,
|
|
129
|
+
toolName: ctx.toolCall.name,
|
|
130
|
+
approvalRule: ctx.plan.approvalRule,
|
|
131
|
+
policyName,
|
|
132
|
+
display: ctx.plan.display,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const response = await this.responder.requestApproval({
|
|
137
|
+
toolCallId: ctx.toolCall.id,
|
|
138
|
+
toolName: ctx.toolCall.name,
|
|
139
|
+
approvalRule: ctx.plan.approvalRule,
|
|
140
|
+
display: ctx.plan.display,
|
|
141
|
+
}, { signal: ctx.signal });
|
|
142
|
+
const resolved = result.resolveApproval?.(response);
|
|
143
|
+
if (resolved?.kind === "deny") {
|
|
144
|
+
return { block: true, reason: resolved.message ?? "Denied." };
|
|
145
|
+
}
|
|
146
|
+
if (response.decision === "approved") {
|
|
147
|
+
if (response.scope === "session")
|
|
148
|
+
this.sessionPatterns.add(ctx.plan.approvalRule);
|
|
149
|
+
return undefined; // proceed
|
|
150
|
+
}
|
|
151
|
+
return { block: true, reason: response.feedback ?? `Tool ${ctx.toolCall.name} was ${response.decision} by the user.` };
|
|
152
|
+
}
|
|
153
|
+
applyApproval(approvalRule, response) {
|
|
154
|
+
if (response.decision === "approved") {
|
|
155
|
+
if (response.scope === "session")
|
|
156
|
+
this.sessionPatterns.add(approvalRule);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ToolPlan } from "../tool/types.ts";
|
|
2
|
+
import type { PermissionRule } from "./types.ts";
|
|
3
|
+
export interface ParsedPattern {
|
|
4
|
+
readonly toolName: string;
|
|
5
|
+
readonly argPattern?: string;
|
|
6
|
+
}
|
|
7
|
+
export type PermissionRuleMatchStrategy = "tool_name_only" | "matches_rule";
|
|
8
|
+
export interface PermissionRuleMatch {
|
|
9
|
+
readonly rule: PermissionRule;
|
|
10
|
+
readonly strategy: PermissionRuleMatchStrategy;
|
|
11
|
+
readonly hasRuleArgs: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface PermissionRuleMatchInput {
|
|
14
|
+
readonly rule: PermissionRule;
|
|
15
|
+
readonly toolName: string;
|
|
16
|
+
readonly execution: Pick<ToolPlan, "matchesRule">;
|
|
17
|
+
}
|
|
18
|
+
export declare function parsePattern(pattern: string): ParsedPattern;
|
|
19
|
+
/**
|
|
20
|
+
* Validate a rule pattern without matching. Returns an error message if malformed, else
|
|
21
|
+
* undefined. A malformed pattern makes {@link matchPermissionRule} silently return "no match"
|
|
22
|
+
* — for a `deny` rule that is fail-open — so callers should surface this at rule-load time
|
|
23
|
+
* (the match path stays silent to avoid re-logging on every tool call).
|
|
24
|
+
*/
|
|
25
|
+
export declare function permissionPatternError(pattern: string): string | undefined;
|
|
26
|
+
export declare function matchPermissionRule({ rule, toolName, execution }: PermissionRuleMatchInput): PermissionRuleMatch | undefined;
|
|
27
|
+
//# sourceMappingURL=matches-rule.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { globMatch } from "../tool/support/path-glob-match.js";
|
|
2
|
+
export function parsePattern(pattern) {
|
|
3
|
+
const trimmed = pattern.trim();
|
|
4
|
+
if (trimmed.length === 0)
|
|
5
|
+
throw new Error("permission pattern: empty string");
|
|
6
|
+
const openIdx = trimmed.indexOf("(");
|
|
7
|
+
if (openIdx === -1)
|
|
8
|
+
return { toolName: trimmed };
|
|
9
|
+
if (!trimmed.endsWith(")")) {
|
|
10
|
+
throw new Error(`permission pattern: missing closing paren in "${pattern}"`);
|
|
11
|
+
}
|
|
12
|
+
const toolName = trimmed.slice(0, openIdx);
|
|
13
|
+
const argPattern = trimmed.slice(openIdx + 1, -1);
|
|
14
|
+
if (toolName.length === 0)
|
|
15
|
+
throw new Error(`permission pattern: empty tool name in "${pattern}"`);
|
|
16
|
+
// `Tool()` stays tool-name-only so tools without a `matchesRule` still match.
|
|
17
|
+
if (argPattern.length === 0)
|
|
18
|
+
return { toolName };
|
|
19
|
+
return { toolName, argPattern };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validate a rule pattern without matching. Returns an error message if malformed, else
|
|
23
|
+
* undefined. A malformed pattern makes {@link matchPermissionRule} silently return "no match"
|
|
24
|
+
* — for a `deny` rule that is fail-open — so callers should surface this at rule-load time
|
|
25
|
+
* (the match path stays silent to avoid re-logging on every tool call).
|
|
26
|
+
*/
|
|
27
|
+
export function permissionPatternError(pattern) {
|
|
28
|
+
try {
|
|
29
|
+
parsePattern(pattern);
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return error instanceof Error ? error.message : String(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function matchPermissionRule({ rule, toolName, execution }) {
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = parsePattern(rule.pattern);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
if (parsed.toolName !== "*" && !globMatch(toolName, parsed.toolName)) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (parsed.argPattern === undefined) {
|
|
48
|
+
return { rule, strategy: "tool_name_only", hasRuleArgs: false };
|
|
49
|
+
}
|
|
50
|
+
return execution.matchesRule?.(parsed.argPattern) === true
|
|
51
|
+
? { rule, strategy: "matches_rule", hasRuleArgs: true }
|
|
52
|
+
: undefined;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=matches-rule.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PathClass } from "../tool/policies/path-access.ts";
|
|
2
|
+
import { type GitWorkTreeMachine } from "../tool/support/git-worktree.ts";
|
|
3
|
+
import type { PermissionMode, PermissionPolicy, PermissionRule } from "./types.ts";
|
|
4
|
+
export interface PermissionState {
|
|
5
|
+
mode(): PermissionMode;
|
|
6
|
+
rules(): readonly PermissionRule[];
|
|
7
|
+
sessionApprovalRulePatterns(): readonly string[];
|
|
8
|
+
cwd(): string;
|
|
9
|
+
pathClass(): PathClass;
|
|
10
|
+
machine?(): GitWorkTreeMachine | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare const STAGED_POLICY_SLOTS: ReadonlySet<string>;
|
|
13
|
+
export declare function createPolicies(state: PermissionState, overrides?: ReadonlyMap<string, PermissionPolicy>): PermissionPolicy[];
|
|
14
|
+
//# sourceMappingURL=policies.d.ts.map
|