attocode 0.2.4 → 0.2.5
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/CHANGELOG.md +56 -1
- package/dist/src/adapters.d.ts +2 -1
- package/dist/src/adapters.d.ts.map +1 -1
- package/dist/src/adapters.js +60 -2
- package/dist/src/adapters.js.map +1 -1
- package/dist/src/agent/agent-builder.d.ts +117 -0
- package/dist/src/agent/agent-builder.d.ts.map +1 -0
- package/dist/src/agent/agent-builder.js +204 -0
- package/dist/src/agent/agent-builder.js.map +1 -0
- package/dist/src/agent/feature-initializer.d.ts +80 -0
- package/dist/src/agent/feature-initializer.d.ts.map +1 -0
- package/dist/src/agent/feature-initializer.js +677 -0
- package/dist/src/agent/feature-initializer.js.map +1 -0
- package/dist/src/agent/index.d.ts +13 -0
- package/dist/src/agent/index.d.ts.map +1 -0
- package/dist/src/agent/index.js +13 -0
- package/dist/src/agent/index.js.map +1 -0
- package/dist/src/agent/message-builder.d.ts +50 -0
- package/dist/src/agent/message-builder.d.ts.map +1 -0
- package/dist/src/agent/message-builder.js +173 -0
- package/dist/src/agent/message-builder.js.map +1 -0
- package/dist/src/agent/session-api.d.ts +94 -0
- package/dist/src/agent/session-api.d.ts.map +1 -0
- package/dist/src/agent/session-api.js +262 -0
- package/dist/src/agent/session-api.js.map +1 -0
- package/dist/src/agent-tools/lsp-file-tools.d.ts +1 -1
- package/dist/src/agent-tools/lsp-file-tools.d.ts.map +1 -1
- package/dist/src/agent.d.ts +14 -115
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +36 -1177
- package/dist/src/agent.js.map +1 -1
- package/dist/src/cli.js +1 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/handler.d.ts.map +1 -1
- package/dist/src/commands/handler.js +8 -7
- package/dist/src/commands/handler.js.map +1 -1
- package/dist/src/commands/init.js +1 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/config/schema.d.ts +6 -6
- package/dist/src/core/execution-loop.d.ts.map +1 -1
- package/dist/src/core/execution-loop.js +155 -16
- package/dist/src/core/execution-loop.js.map +1 -1
- package/dist/src/core/response-handler.d.ts.map +1 -1
- package/dist/src/core/response-handler.js +3 -2
- package/dist/src/core/response-handler.js.map +1 -1
- package/dist/src/core/subagent-spawner.d.ts.map +1 -1
- package/dist/src/core/subagent-spawner.js +13 -6
- package/dist/src/core/subagent-spawner.js.map +1 -1
- package/dist/src/core/tool-executor.d.ts.map +1 -1
- package/dist/src/core/tool-executor.js +7 -2
- package/dist/src/core/tool-executor.js.map +1 -1
- package/dist/src/core/types.d.ts +1 -0
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/integrations/agents/agent-registry.d.ts +262 -0
- package/dist/src/integrations/agents/agent-registry.d.ts.map +1 -0
- package/dist/src/integrations/agents/agent-registry.js +686 -0
- package/dist/src/integrations/agents/agent-registry.js.map +1 -0
- package/dist/src/integrations/agents/async-subagent.d.ts +135 -0
- package/dist/src/integrations/agents/async-subagent.d.ts.map +1 -0
- package/dist/src/integrations/agents/async-subagent.js +213 -0
- package/dist/src/integrations/agents/async-subagent.js.map +1 -0
- package/dist/src/integrations/agents/complexity-classifier.d.ts +86 -0
- package/dist/src/integrations/agents/complexity-classifier.d.ts.map +1 -0
- package/dist/src/integrations/agents/complexity-classifier.js +233 -0
- package/dist/src/integrations/agents/complexity-classifier.js.map +1 -0
- package/dist/src/integrations/agents/delegation-protocol.d.ts +86 -0
- package/dist/src/integrations/agents/delegation-protocol.d.ts.map +1 -0
- package/dist/src/integrations/agents/delegation-protocol.js +127 -0
- package/dist/src/integrations/agents/delegation-protocol.js.map +1 -0
- package/dist/src/integrations/agents/multi-agent.d.ts +150 -0
- package/dist/src/integrations/agents/multi-agent.d.ts.map +1 -0
- package/dist/src/integrations/agents/multi-agent.js +306 -0
- package/dist/src/integrations/agents/multi-agent.js.map +1 -0
- package/dist/src/integrations/agents/result-synthesizer.d.ts +389 -0
- package/dist/src/integrations/agents/result-synthesizer.d.ts.map +1 -0
- package/dist/src/integrations/agents/result-synthesizer.js +951 -0
- package/dist/src/integrations/agents/result-synthesizer.js.map +1 -0
- package/dist/src/integrations/agents/shared-blackboard.d.ts +406 -0
- package/dist/src/integrations/agents/shared-blackboard.d.ts.map +1 -0
- package/dist/src/integrations/agents/shared-blackboard.js +757 -0
- package/dist/src/integrations/agents/shared-blackboard.js.map +1 -0
- package/dist/src/integrations/agents/subagent-output-store.d.ts +91 -0
- package/dist/src/integrations/agents/subagent-output-store.d.ts.map +1 -0
- package/dist/src/integrations/agents/subagent-output-store.js +257 -0
- package/dist/src/integrations/agents/subagent-output-store.js.map +1 -0
- package/dist/src/integrations/budget/budget-pool.d.ts +115 -0
- package/dist/src/integrations/budget/budget-pool.d.ts.map +1 -0
- package/dist/src/integrations/budget/budget-pool.js +205 -0
- package/dist/src/integrations/budget/budget-pool.js.map +1 -0
- package/dist/src/integrations/budget/cancellation.d.ts +229 -0
- package/dist/src/integrations/budget/cancellation.d.ts.map +1 -0
- package/dist/src/integrations/budget/cancellation.js +520 -0
- package/dist/src/integrations/budget/cancellation.js.map +1 -0
- package/dist/src/integrations/budget/dynamic-budget.d.ts +81 -0
- package/dist/src/integrations/budget/dynamic-budget.d.ts.map +1 -0
- package/dist/src/integrations/budget/dynamic-budget.js +151 -0
- package/dist/src/integrations/budget/dynamic-budget.js.map +1 -0
- package/dist/src/integrations/budget/economics.d.ts +435 -0
- package/dist/src/integrations/budget/economics.d.ts.map +1 -0
- package/dist/src/integrations/budget/economics.js +1007 -0
- package/dist/src/integrations/budget/economics.js.map +1 -0
- package/dist/src/integrations/budget/injection-budget.d.ts +71 -0
- package/dist/src/integrations/budget/injection-budget.d.ts.map +1 -0
- package/dist/src/integrations/budget/injection-budget.js +137 -0
- package/dist/src/integrations/budget/injection-budget.js.map +1 -0
- package/dist/src/integrations/budget/loop-detector.d.ts +105 -0
- package/dist/src/integrations/budget/loop-detector.d.ts.map +1 -0
- package/dist/src/integrations/budget/loop-detector.js +287 -0
- package/dist/src/integrations/budget/loop-detector.js.map +1 -0
- package/dist/src/integrations/budget/phase-tracker.d.ts +114 -0
- package/dist/src/integrations/budget/phase-tracker.d.ts.map +1 -0
- package/dist/src/integrations/budget/phase-tracker.js +262 -0
- package/dist/src/integrations/budget/phase-tracker.js.map +1 -0
- package/dist/src/integrations/budget/resources.d.ts +182 -0
- package/dist/src/integrations/budget/resources.d.ts.map +1 -0
- package/dist/src/integrations/budget/resources.js +318 -0
- package/dist/src/integrations/budget/resources.js.map +1 -0
- package/dist/src/integrations/context/auto-compaction.d.ts +210 -0
- package/dist/src/integrations/context/auto-compaction.d.ts.map +1 -0
- package/dist/src/integrations/context/auto-compaction.js +477 -0
- package/dist/src/integrations/context/auto-compaction.js.map +1 -0
- package/dist/src/integrations/context/code-analyzer.d.ts +71 -0
- package/dist/src/integrations/context/code-analyzer.d.ts.map +1 -0
- package/dist/src/integrations/context/code-analyzer.js +448 -0
- package/dist/src/integrations/context/code-analyzer.js.map +1 -0
- package/dist/src/integrations/context/code-selector.d.ts +78 -0
- package/dist/src/integrations/context/code-selector.d.ts.map +1 -0
- package/dist/src/integrations/context/code-selector.js +649 -0
- package/dist/src/integrations/context/code-selector.js.map +1 -0
- package/dist/src/integrations/context/codebase-ast.d.ts +138 -0
- package/dist/src/integrations/context/codebase-ast.d.ts.map +1 -0
- package/dist/src/integrations/context/codebase-ast.js +818 -0
- package/dist/src/integrations/context/codebase-ast.js.map +1 -0
- package/dist/src/integrations/context/codebase-context.d.ts +473 -0
- package/dist/src/integrations/context/codebase-context.d.ts.map +1 -0
- package/dist/src/integrations/context/codebase-context.js +685 -0
- package/dist/src/integrations/context/codebase-context.js.map +1 -0
- package/dist/src/integrations/context/compaction.d.ts +191 -0
- package/dist/src/integrations/context/compaction.d.ts.map +1 -0
- package/dist/src/integrations/context/compaction.js +384 -0
- package/dist/src/integrations/context/compaction.js.map +1 -0
- package/dist/src/integrations/context/context-engineering.d.ts +274 -0
- package/dist/src/integrations/context/context-engineering.d.ts.map +1 -0
- package/dist/src/integrations/context/context-engineering.js +437 -0
- package/dist/src/integrations/context/context-engineering.js.map +1 -0
- package/dist/src/integrations/context/file-cache.d.ts +97 -0
- package/dist/src/integrations/context/file-cache.d.ts.map +1 -0
- package/dist/src/integrations/context/file-cache.js +218 -0
- package/dist/src/integrations/context/file-cache.js.map +1 -0
- package/dist/src/integrations/context/semantic-cache.d.ts +178 -0
- package/dist/src/integrations/context/semantic-cache.d.ts.map +1 -0
- package/dist/src/integrations/context/semantic-cache.js +372 -0
- package/dist/src/integrations/context/semantic-cache.js.map +1 -0
- package/dist/src/integrations/index.d.ts +72 -68
- package/dist/src/integrations/index.d.ts.map +1 -1
- package/dist/src/integrations/index.js +76 -68
- package/dist/src/integrations/index.js.map +1 -1
- package/dist/src/integrations/lsp/lsp.d.ts +196 -0
- package/dist/src/integrations/lsp/lsp.d.ts.map +1 -0
- package/dist/src/integrations/lsp/lsp.js +583 -0
- package/dist/src/integrations/lsp/lsp.js.map +1 -0
- package/dist/src/integrations/mcp/mcp-client.d.ts +279 -0
- package/dist/src/integrations/mcp/mcp-client.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-client.js +755 -0
- package/dist/src/integrations/mcp/mcp-client.js.map +1 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.d.ts +102 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.js +232 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.js.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-search.d.ts +77 -0
- package/dist/src/integrations/mcp/mcp-tool-search.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-search.js +220 -0
- package/dist/src/integrations/mcp/mcp-tool-search.js.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.d.ts +60 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.js +141 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.js.map +1 -0
- package/dist/src/integrations/persistence/codebase-repository.d.ts +45 -0
- package/dist/src/integrations/persistence/codebase-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/codebase-repository.js +81 -0
- package/dist/src/integrations/persistence/codebase-repository.js.map +1 -0
- package/dist/src/integrations/persistence/goal-repository.d.ts +71 -0
- package/dist/src/integrations/persistence/goal-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/goal-repository.js +184 -0
- package/dist/src/integrations/persistence/goal-repository.js.map +1 -0
- package/dist/src/integrations/persistence/history.d.ts +72 -0
- package/dist/src/integrations/persistence/history.d.ts.map +1 -0
- package/dist/src/integrations/persistence/history.js +165 -0
- package/dist/src/integrations/persistence/history.js.map +1 -0
- package/dist/src/integrations/persistence/persistence.d.ts +49 -0
- package/dist/src/integrations/persistence/persistence.d.ts.map +1 -0
- package/dist/src/integrations/persistence/persistence.js +197 -0
- package/dist/src/integrations/persistence/persistence.js.map +1 -0
- package/dist/src/integrations/persistence/session-repository.d.ts +212 -0
- package/dist/src/integrations/persistence/session-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/session-repository.js +770 -0
- package/dist/src/integrations/persistence/session-repository.js.map +1 -0
- package/dist/src/integrations/persistence/session-store.d.ts +184 -0
- package/dist/src/integrations/persistence/session-store.d.ts.map +1 -0
- package/dist/src/integrations/persistence/session-store.js +346 -0
- package/dist/src/integrations/persistence/session-store.js.map +1 -0
- package/dist/src/integrations/persistence/sqlite-store.d.ts +453 -0
- package/dist/src/integrations/persistence/sqlite-store.d.ts.map +1 -0
- package/dist/src/integrations/persistence/sqlite-store.js +676 -0
- package/dist/src/integrations/persistence/sqlite-store.js.map +1 -0
- package/dist/src/integrations/persistence/worker-repository.d.ts +65 -0
- package/dist/src/integrations/persistence/worker-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/worker-repository.js +183 -0
- package/dist/src/integrations/persistence/worker-repository.js.map +1 -0
- package/dist/src/integrations/quality/auto-checkpoint.d.ts +98 -0
- package/dist/src/integrations/quality/auto-checkpoint.d.ts.map +1 -0
- package/dist/src/integrations/quality/auto-checkpoint.js +252 -0
- package/dist/src/integrations/quality/auto-checkpoint.js.map +1 -0
- package/dist/src/integrations/quality/dead-letter-queue.d.ts +233 -0
- package/dist/src/integrations/quality/dead-letter-queue.d.ts.map +1 -0
- package/dist/src/integrations/quality/dead-letter-queue.js +543 -0
- package/dist/src/integrations/quality/dead-letter-queue.js.map +1 -0
- package/dist/src/integrations/quality/health-check.d.ts +218 -0
- package/dist/src/integrations/quality/health-check.d.ts.map +1 -0
- package/dist/src/integrations/quality/health-check.js +415 -0
- package/dist/src/integrations/quality/health-check.js.map +1 -0
- package/dist/src/integrations/quality/learning-store.d.ts +291 -0
- package/dist/src/integrations/quality/learning-store.d.ts.map +1 -0
- package/dist/src/integrations/quality/learning-store.js +646 -0
- package/dist/src/integrations/quality/learning-store.js.map +1 -0
- package/dist/src/integrations/quality/self-improvement.d.ts +90 -0
- package/dist/src/integrations/quality/self-improvement.d.ts.map +1 -0
- package/dist/src/integrations/quality/self-improvement.js +229 -0
- package/dist/src/integrations/quality/self-improvement.js.map +1 -0
- package/dist/src/integrations/quality/tool-recommendation.d.ts +61 -0
- package/dist/src/integrations/quality/tool-recommendation.d.ts.map +1 -0
- package/dist/src/integrations/quality/tool-recommendation.js +268 -0
- package/dist/src/integrations/quality/tool-recommendation.js.map +1 -0
- package/dist/src/integrations/safety/bash-policy.d.ts +33 -0
- package/dist/src/integrations/safety/bash-policy.d.ts.map +1 -0
- package/dist/src/integrations/safety/bash-policy.js +144 -0
- package/dist/src/integrations/safety/bash-policy.js.map +1 -0
- package/dist/src/integrations/safety/edit-validator.d.ts +30 -0
- package/dist/src/integrations/safety/edit-validator.d.ts.map +1 -0
- package/dist/src/integrations/safety/edit-validator.js +87 -0
- package/dist/src/integrations/safety/edit-validator.js.map +1 -0
- package/dist/src/integrations/safety/execution-policy.d.ts +189 -0
- package/dist/src/integrations/safety/execution-policy.d.ts.map +1 -0
- package/dist/src/integrations/safety/execution-policy.js +352 -0
- package/dist/src/integrations/safety/execution-policy.js.map +1 -0
- package/dist/src/integrations/safety/policy-engine.d.ts +55 -0
- package/dist/src/integrations/safety/policy-engine.d.ts.map +1 -0
- package/dist/src/integrations/safety/policy-engine.js +247 -0
- package/dist/src/integrations/safety/policy-engine.js.map +1 -0
- package/dist/src/integrations/safety/safety.d.ts +174 -0
- package/dist/src/integrations/safety/safety.d.ts.map +1 -0
- package/dist/src/integrations/safety/safety.js +470 -0
- package/dist/src/integrations/safety/safety.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/basic.d.ts +81 -0
- package/dist/src/integrations/safety/sandbox/basic.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/basic.js +335 -0
- package/dist/src/integrations/safety/sandbox/basic.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/docker.d.ts +94 -0
- package/dist/src/integrations/safety/sandbox/docker.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/docker.js +294 -0
- package/dist/src/integrations/safety/sandbox/docker.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/index.d.ts +188 -0
- package/dist/src/integrations/safety/sandbox/index.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/index.js +386 -0
- package/dist/src/integrations/safety/sandbox/index.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/landlock.d.ts +59 -0
- package/dist/src/integrations/safety/sandbox/landlock.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/landlock.js +329 -0
- package/dist/src/integrations/safety/sandbox/landlock.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.d.ts +68 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.js +298 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.js.map +1 -0
- package/dist/src/integrations/safety/type-checker.d.ts +53 -0
- package/dist/src/integrations/safety/type-checker.d.ts.map +1 -0
- package/dist/src/integrations/safety/type-checker.js +142 -0
- package/dist/src/integrations/safety/type-checker.js.map +1 -0
- package/dist/src/integrations/skills/skill-executor.d.ts +113 -0
- package/dist/src/integrations/skills/skill-executor.d.ts.map +1 -0
- package/dist/src/integrations/skills/skill-executor.js +270 -0
- package/dist/src/integrations/skills/skill-executor.js.map +1 -0
- package/dist/src/integrations/skills/skills.d.ts +262 -0
- package/dist/src/integrations/skills/skills.d.ts.map +1 -0
- package/dist/src/integrations/skills/skills.js +602 -0
- package/dist/src/integrations/skills/skills.js.map +1 -0
- package/dist/src/integrations/streaming/pty-shell.d.ts +169 -0
- package/dist/src/integrations/streaming/pty-shell.d.ts.map +1 -0
- package/dist/src/integrations/streaming/pty-shell.js +367 -0
- package/dist/src/integrations/streaming/pty-shell.js.map +1 -0
- package/dist/src/integrations/streaming/streaming.d.ts +102 -0
- package/dist/src/integrations/streaming/streaming.d.ts.map +1 -0
- package/dist/src/integrations/streaming/streaming.js +362 -0
- package/dist/src/integrations/streaming/streaming.js.map +1 -0
- package/dist/src/integrations/swarm/index.d.ts +2 -1
- package/dist/src/integrations/swarm/index.d.ts.map +1 -1
- package/dist/src/integrations/swarm/index.js +2 -0
- package/dist/src/integrations/swarm/index.js.map +1 -1
- package/dist/src/integrations/swarm/model-selector.js +1 -1
- package/dist/src/integrations/swarm/model-selector.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-budget.d.ts +1 -1
- package/dist/src/integrations/swarm/swarm-budget.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-budget.js +1 -1
- package/dist/src/integrations/swarm/swarm-budget.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-config-loader.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-config-loader.js +7 -0
- package/dist/src/integrations/swarm/swarm-config-loader.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-events.d.ts +1 -1
- package/dist/src/integrations/swarm/swarm-events.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-execution.d.ts +27 -0
- package/dist/src/integrations/swarm/swarm-execution.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-execution.js +1021 -0
- package/dist/src/integrations/swarm/swarm-execution.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-helpers.d.ts +26 -0
- package/dist/src/integrations/swarm/swarm-helpers.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-helpers.js +95 -0
- package/dist/src/integrations/swarm/swarm-helpers.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.d.ts +100 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.js +922 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-orchestrator.d.ts +84 -203
- package/dist/src/integrations/swarm/swarm-orchestrator.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-orchestrator.js +251 -2870
- package/dist/src/integrations/swarm/swarm-orchestrator.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-quality-gate.js +1 -1
- package/dist/src/integrations/swarm/swarm-quality-gate.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-recovery.d.ts +75 -0
- package/dist/src/integrations/swarm/swarm-recovery.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-recovery.js +550 -0
- package/dist/src/integrations/swarm/swarm-recovery.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-state-store.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-state-store.js +6 -0
- package/dist/src/integrations/swarm/swarm-state-store.js.map +1 -1
- package/dist/src/integrations/swarm/task-queue.d.ts +1 -1
- package/dist/src/integrations/swarm/task-queue.d.ts.map +1 -1
- package/dist/src/integrations/swarm/task-queue.js +28 -1
- package/dist/src/integrations/swarm/task-queue.js.map +1 -1
- package/dist/src/integrations/swarm/types.d.ts +17 -5
- package/dist/src/integrations/swarm/types.d.ts.map +1 -1
- package/dist/src/integrations/swarm/types.js.map +1 -1
- package/dist/src/integrations/swarm/worker-pool.d.ts +1 -1
- package/dist/src/integrations/swarm/worker-pool.d.ts.map +1 -1
- package/dist/src/integrations/swarm/worker-pool.js +13 -9
- package/dist/src/integrations/swarm/worker-pool.js.map +1 -1
- package/dist/src/integrations/tasks/dependency-analyzer.d.ts +34 -0
- package/dist/src/integrations/tasks/dependency-analyzer.d.ts.map +1 -0
- package/dist/src/integrations/tasks/dependency-analyzer.js +232 -0
- package/dist/src/integrations/tasks/dependency-analyzer.js.map +1 -0
- package/dist/src/integrations/tasks/interactive-planning.d.ts +322 -0
- package/dist/src/integrations/tasks/interactive-planning.d.ts.map +1 -0
- package/dist/src/integrations/tasks/interactive-planning.js +655 -0
- package/dist/src/integrations/tasks/interactive-planning.js.map +1 -0
- package/dist/src/integrations/tasks/pending-plan.d.ts +196 -0
- package/dist/src/integrations/tasks/pending-plan.d.ts.map +1 -0
- package/dist/src/integrations/tasks/pending-plan.js +431 -0
- package/dist/src/integrations/tasks/pending-plan.js.map +1 -0
- package/dist/src/integrations/tasks/planning.d.ts +115 -0
- package/dist/src/integrations/tasks/planning.d.ts.map +1 -0
- package/dist/src/integrations/tasks/planning.js +413 -0
- package/dist/src/integrations/tasks/planning.js.map +1 -0
- package/dist/src/integrations/tasks/smart-decomposer.d.ts +316 -0
- package/dist/src/integrations/tasks/smart-decomposer.d.ts.map +1 -0
- package/dist/src/integrations/tasks/smart-decomposer.js +661 -0
- package/dist/src/integrations/tasks/smart-decomposer.js.map +1 -0
- package/dist/src/integrations/tasks/task-manager.d.ts +164 -0
- package/dist/src/integrations/tasks/task-manager.d.ts.map +1 -0
- package/dist/src/integrations/tasks/task-manager.js +383 -0
- package/dist/src/integrations/tasks/task-manager.js.map +1 -0
- package/dist/src/integrations/tasks/task-splitter.d.ts +56 -0
- package/dist/src/integrations/tasks/task-splitter.d.ts.map +1 -0
- package/dist/src/integrations/tasks/task-splitter.js +537 -0
- package/dist/src/integrations/tasks/task-splitter.js.map +1 -0
- package/dist/src/integrations/tasks/verification-gate.d.ts +103 -0
- package/dist/src/integrations/tasks/verification-gate.d.ts.map +1 -0
- package/dist/src/integrations/tasks/verification-gate.js +193 -0
- package/dist/src/integrations/tasks/verification-gate.js.map +1 -0
- package/dist/src/integrations/tasks/work-log.d.ts +87 -0
- package/dist/src/integrations/tasks/work-log.d.ts.map +1 -0
- package/dist/src/integrations/tasks/work-log.js +275 -0
- package/dist/src/integrations/tasks/work-log.js.map +1 -0
- package/dist/src/integrations/utilities/capabilities.d.ts +160 -0
- package/dist/src/integrations/utilities/capabilities.d.ts.map +1 -0
- package/dist/src/integrations/utilities/capabilities.js +426 -0
- package/dist/src/integrations/utilities/capabilities.js.map +1 -0
- package/dist/src/integrations/utilities/diff-utils.d.ts +105 -0
- package/dist/src/integrations/utilities/diff-utils.d.ts.map +1 -0
- package/dist/src/integrations/utilities/diff-utils.js +497 -0
- package/dist/src/integrations/utilities/diff-utils.js.map +1 -0
- package/dist/src/integrations/utilities/environment-facts.d.ts +52 -0
- package/dist/src/integrations/utilities/environment-facts.d.ts.map +1 -0
- package/dist/src/integrations/utilities/environment-facts.js +84 -0
- package/dist/src/integrations/utilities/environment-facts.js.map +1 -0
- package/dist/src/integrations/utilities/file-change-tracker.d.ts +162 -0
- package/dist/src/integrations/utilities/file-change-tracker.d.ts.map +1 -0
- package/dist/src/integrations/utilities/file-change-tracker.js +538 -0
- package/dist/src/integrations/utilities/file-change-tracker.js.map +1 -0
- package/dist/src/integrations/utilities/graph-visualization.d.ts +72 -0
- package/dist/src/integrations/utilities/graph-visualization.d.ts.map +1 -0
- package/dist/src/integrations/utilities/graph-visualization.js +383 -0
- package/dist/src/integrations/utilities/graph-visualization.js.map +1 -0
- package/dist/src/integrations/utilities/hierarchical-config.d.ts +215 -0
- package/dist/src/integrations/utilities/hierarchical-config.d.ts.map +1 -0
- package/dist/src/integrations/utilities/hierarchical-config.js +504 -0
- package/dist/src/integrations/utilities/hierarchical-config.js.map +1 -0
- package/dist/src/integrations/utilities/hooks.d.ts +116 -0
- package/dist/src/integrations/utilities/hooks.d.ts.map +1 -0
- package/dist/src/integrations/utilities/hooks.js +410 -0
- package/dist/src/integrations/utilities/hooks.js.map +1 -0
- package/dist/src/integrations/utilities/ignore.d.ts +143 -0
- package/dist/src/integrations/utilities/ignore.d.ts.map +1 -0
- package/dist/src/integrations/utilities/ignore.js +417 -0
- package/dist/src/integrations/utilities/ignore.js.map +1 -0
- package/dist/src/integrations/utilities/image-renderer.d.ts +119 -0
- package/dist/src/integrations/utilities/image-renderer.d.ts.map +1 -0
- package/dist/src/integrations/utilities/image-renderer.js +306 -0
- package/dist/src/integrations/utilities/image-renderer.js.map +1 -0
- package/dist/src/integrations/utilities/logger.d.ts +104 -0
- package/dist/src/integrations/utilities/logger.d.ts.map +1 -0
- package/dist/src/integrations/utilities/logger.js +219 -0
- package/dist/src/integrations/utilities/logger.js.map +1 -0
- package/dist/src/integrations/utilities/memory.d.ts +116 -0
- package/dist/src/integrations/utilities/memory.d.ts.map +1 -0
- package/dist/src/integrations/utilities/memory.js +311 -0
- package/dist/src/integrations/utilities/memory.js.map +1 -0
- package/dist/src/integrations/utilities/observability.d.ts +162 -0
- package/dist/src/integrations/utilities/observability.d.ts.map +1 -0
- package/dist/src/integrations/utilities/observability.js +407 -0
- package/dist/src/integrations/utilities/observability.js.map +1 -0
- package/dist/src/integrations/utilities/openrouter-pricing.d.ts +67 -0
- package/dist/src/integrations/utilities/openrouter-pricing.d.ts.map +1 -0
- package/dist/src/integrations/utilities/openrouter-pricing.js +166 -0
- package/dist/src/integrations/utilities/openrouter-pricing.js.map +1 -0
- package/dist/src/integrations/utilities/react.d.ts +139 -0
- package/dist/src/integrations/utilities/react.d.ts.map +1 -0
- package/dist/src/integrations/utilities/react.js +273 -0
- package/dist/src/integrations/utilities/react.js.map +1 -0
- package/dist/src/integrations/utilities/retry.d.ts +132 -0
- package/dist/src/integrations/utilities/retry.d.ts.map +1 -0
- package/dist/src/integrations/utilities/retry.js +233 -0
- package/dist/src/integrations/utilities/retry.js.map +1 -0
- package/dist/src/integrations/utilities/routing.d.ts +118 -0
- package/dist/src/integrations/utilities/routing.d.ts.map +1 -0
- package/dist/src/integrations/utilities/routing.js +348 -0
- package/dist/src/integrations/utilities/routing.js.map +1 -0
- package/dist/src/integrations/utilities/rules.d.ts +131 -0
- package/dist/src/integrations/utilities/rules.d.ts.map +1 -0
- package/dist/src/integrations/utilities/rules.js +284 -0
- package/dist/src/integrations/utilities/rules.js.map +1 -0
- package/dist/src/integrations/utilities/sourcegraph.d.ts +169 -0
- package/dist/src/integrations/utilities/sourcegraph.d.ts.map +1 -0
- package/dist/src/integrations/utilities/sourcegraph.js +379 -0
- package/dist/src/integrations/utilities/sourcegraph.js.map +1 -0
- package/dist/src/integrations/utilities/thinking-strategy.d.ts +52 -0
- package/dist/src/integrations/utilities/thinking-strategy.d.ts.map +1 -0
- package/dist/src/integrations/utilities/thinking-strategy.js +129 -0
- package/dist/src/integrations/utilities/thinking-strategy.js.map +1 -0
- package/dist/src/integrations/utilities/thread-manager.d.ts +199 -0
- package/dist/src/integrations/utilities/thread-manager.d.ts.map +1 -0
- package/dist/src/integrations/utilities/thread-manager.js +357 -0
- package/dist/src/integrations/utilities/thread-manager.js.map +1 -0
- package/dist/src/integrations/utilities/token-estimate.d.ts +11 -0
- package/dist/src/integrations/utilities/token-estimate.d.ts.map +1 -0
- package/dist/src/integrations/utilities/token-estimate.js +14 -0
- package/dist/src/integrations/utilities/token-estimate.js.map +1 -0
- package/dist/src/main.js +10 -4
- package/dist/src/main.js.map +1 -1
- package/dist/src/modes/repl.d.ts.map +1 -1
- package/dist/src/modes/repl.js +22 -5
- package/dist/src/modes/repl.js.map +1 -1
- package/dist/src/modes/tui.d.ts.map +1 -1
- package/dist/src/modes/tui.js +23 -6
- package/dist/src/modes/tui.js.map +1 -1
- package/dist/src/modes.js +1 -1
- package/dist/src/modes.js.map +1 -1
- package/dist/src/observability/tracer.js +1 -1
- package/dist/src/observability/tracer.js.map +1 -1
- package/dist/src/persistence/schema.d.ts +2 -0
- package/dist/src/persistence/schema.d.ts.map +1 -1
- package/dist/src/persistence/schema.js +31 -0
- package/dist/src/persistence/schema.js.map +1 -1
- package/dist/src/providers/adapters/anthropic.d.ts +6 -0
- package/dist/src/providers/adapters/anthropic.d.ts.map +1 -1
- package/dist/src/providers/adapters/anthropic.js +99 -15
- package/dist/src/providers/adapters/anthropic.js.map +1 -1
- package/dist/src/providers/adapters/azure.d.ts +74 -0
- package/dist/src/providers/adapters/azure.d.ts.map +1 -0
- package/dist/src/providers/adapters/azure.js +354 -0
- package/dist/src/providers/adapters/azure.js.map +1 -0
- package/dist/src/providers/adapters/mock.d.ts +16 -2
- package/dist/src/providers/adapters/mock.d.ts.map +1 -1
- package/dist/src/providers/adapters/mock.js +44 -3
- package/dist/src/providers/adapters/mock.js.map +1 -1
- package/dist/src/providers/adapters/openai.d.ts +6 -1
- package/dist/src/providers/adapters/openai.d.ts.map +1 -1
- package/dist/src/providers/adapters/openai.js +39 -8
- package/dist/src/providers/adapters/openai.js.map +1 -1
- package/dist/src/providers/adapters/openrouter.d.ts +6 -0
- package/dist/src/providers/adapters/openrouter.d.ts.map +1 -1
- package/dist/src/providers/adapters/openrouter.js +73 -3
- package/dist/src/providers/adapters/openrouter.js.map +1 -1
- package/dist/src/providers/provider.js +1 -1
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/providers/resilient-provider.js +1 -1
- package/dist/src/providers/resilient-provider.js.map +1 -1
- package/dist/src/providers/types.d.ts +23 -2
- package/dist/src/providers/types.d.ts.map +1 -1
- package/dist/src/session-picker.d.ts +1 -1
- package/dist/src/session-picker.d.ts.map +1 -1
- package/dist/src/session-picker.js +1 -1
- package/dist/src/session-picker.js.map +1 -1
- package/dist/src/shared/budget-tracker.js +1 -1
- package/dist/src/shared/budget-tracker.js.map +1 -1
- package/dist/src/tools/agent.d.ts +1 -1
- package/dist/src/tools/agent.d.ts.map +1 -1
- package/dist/src/tools/bash.js +1 -1
- package/dist/src/tools/bash.js.map +1 -1
- package/dist/src/tools/file.js +1 -1
- package/dist/src/tools/file.js.map +1 -1
- package/dist/src/tools/permission.js +2 -2
- package/dist/src/tools/permission.js.map +1 -1
- package/dist/src/tools/registry.d.ts +1 -1
- package/dist/src/tools/registry.d.ts.map +1 -1
- package/dist/src/tools/registry.js +1 -1
- package/dist/src/tools/registry.js.map +1 -1
- package/dist/src/tools/tasks.d.ts +1 -1
- package/dist/src/tools/tasks.d.ts.map +1 -1
- package/dist/src/tools/undo.d.ts +1 -1
- package/dist/src/tools/undo.d.ts.map +1 -1
- package/dist/src/tracing/cache-boundary-tracker.d.ts.map +1 -1
- package/dist/src/tracing/cache-boundary-tracker.js +2 -2
- package/dist/src/tracing/cache-boundary-tracker.js.map +1 -1
- package/dist/src/tracing/trace-collector.d.ts +22 -0
- package/dist/src/tracing/trace-collector.d.ts.map +1 -1
- package/dist/src/tracing/trace-collector.js +27 -3
- package/dist/src/tracing/trace-collector.js.map +1 -1
- package/dist/src/tracing/types.d.ts +17 -1
- package/dist/src/tracing/types.d.ts.map +1 -1
- package/dist/src/tracing/types.js.map +1 -1
- package/dist/src/tricks/failure-evidence.js +1 -1
- package/dist/src/tricks/failure-evidence.js.map +1 -1
- package/dist/src/tricks/recitation.d.ts.map +1 -1
- package/dist/src/tricks/recitation.js +2 -1
- package/dist/src/tricks/recitation.js.map +1 -1
- package/dist/src/tricks/recursive-context.d.ts.map +1 -1
- package/dist/src/tricks/recursive-context.js +2 -2
- package/dist/src/tricks/recursive-context.js.map +1 -1
- package/dist/src/tricks/reversible-compaction.d.ts.map +1 -1
- package/dist/src/tricks/reversible-compaction.js +6 -2
- package/dist/src/tricks/reversible-compaction.js.map +1 -1
- package/dist/src/tui/app.d.ts +3 -3
- package/dist/src/tui/app.d.ts.map +1 -1
- package/dist/src/tui/app.js +86 -14
- package/dist/src/tui/app.js.map +1 -1
- package/dist/src/tui/components/CollapsibleDiffView.d.ts +1 -1
- package/dist/src/tui/components/CollapsibleDiffView.d.ts.map +1 -1
- package/dist/src/tui/components/DiagnosticsPanel.d.ts +24 -0
- package/dist/src/tui/components/DiagnosticsPanel.d.ts.map +1 -0
- package/dist/src/tui/components/DiagnosticsPanel.js +47 -0
- package/dist/src/tui/components/DiagnosticsPanel.js.map +1 -0
- package/dist/src/tui/components/DiffView.d.ts +1 -1
- package/dist/src/tui/components/DiffView.d.ts.map +1 -1
- package/dist/src/tui/components/ErrorBoundary.js +1 -1
- package/dist/src/tui/components/ErrorBoundary.js.map +1 -1
- package/dist/src/tui/components/TasksPanel.d.ts +1 -1
- package/dist/src/tui/components/TasksPanel.d.ts.map +1 -1
- package/dist/src/tui/event-display.js +1 -1
- package/dist/src/tui/event-display.js.map +1 -1
- package/dist/src/tui/index.js +1 -1
- package/dist/src/tui/index.js.map +1 -1
- package/dist/src/tui/transparency-aggregator.d.ts +13 -0
- package/dist/src/tui/transparency-aggregator.d.ts.map +1 -1
- package/dist/src/tui/transparency-aggregator.js +21 -0
- package/dist/src/tui/transparency-aggregator.js.map +1 -1
- package/dist/src/types.d.ts +27 -2
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-engine.js","sourceRoot":"","sources":["../../../../src/integrations/safety/policy-engine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,CAAC,MAAM,uBAAuB,GAAkC;IACpE,eAAe,EAAE;QACf,cAAc,EAAE,WAAW;QAC3B,YAAY,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,E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AU,CAAC,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC;YAClG,CAAC,CAAC,WAAW;YACb,CAAC,CAAC,UAAU,CAAC;IACjB,CAAC;IAED,MAAM,QAAQ,GAAG,kBAAkB,CACjC,OAAO,EACP,IAAI,EACJ,OAAO,CAAC,mBAAmB,IAAI,KAAK,CACrC,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,KAIC,EACD,OAAsB;IAMtB,OAAO;QACL,WAAW,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACnG,aAAa,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,IAAI,EAAE,CAAC,EAAE;QAC7F,eAAe,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;KAChH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lesson 23: Safety Integration
|
|
3
|
+
*
|
|
4
|
+
* Integrates sandboxing (Lesson 20) and human-in-the-loop (Lesson 21)
|
|
5
|
+
* into the production agent. Provides execution safety and approval workflows.
|
|
6
|
+
*/
|
|
7
|
+
import type { SandboxConfig, PolicyEngineConfig, HumanInLoopConfig, ToolCall } from '../../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Manages sandboxed execution of tools.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SandboxManager {
|
|
12
|
+
private config;
|
|
13
|
+
private policyEngineConfig?;
|
|
14
|
+
constructor(config: SandboxConfig, policyEngineConfig?: PolicyEngineConfig | false);
|
|
15
|
+
/**
|
|
16
|
+
* Check if a command is allowed.
|
|
17
|
+
*/
|
|
18
|
+
isCommandAllowed(command: string): {
|
|
19
|
+
allowed: boolean;
|
|
20
|
+
reason?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Check if a path is allowed.
|
|
24
|
+
* Resolves relative paths against cwd before comparison.
|
|
25
|
+
* Uses realpath to resolve symlinks and prevent symlink escape attacks.
|
|
26
|
+
*/
|
|
27
|
+
isPathAllowed(path: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Get resource limits.
|
|
30
|
+
*/
|
|
31
|
+
getResourceLimits(): NonNullable<SandboxConfig['resourceLimits']>;
|
|
32
|
+
/**
|
|
33
|
+
* Wrap execution with resource limits.
|
|
34
|
+
*/
|
|
35
|
+
executeWithLimits<T>(fn: () => Promise<T>, timeout?: number): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Validate tool call against sandbox rules.
|
|
38
|
+
*/
|
|
39
|
+
validateToolCall(toolCall: ToolCall): {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
reason?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Manages human approval workflows.
|
|
46
|
+
*/
|
|
47
|
+
export declare class HumanInLoopManager {
|
|
48
|
+
private config;
|
|
49
|
+
private auditLog;
|
|
50
|
+
private pendingApprovals;
|
|
51
|
+
private approvalScope;
|
|
52
|
+
private readonly maxAuditEntries;
|
|
53
|
+
private readonly auditTrimSize;
|
|
54
|
+
constructor(config: HumanInLoopConfig);
|
|
55
|
+
/**
|
|
56
|
+
* Set an approval scope for pre-approved operations.
|
|
57
|
+
* Used by subagents to reduce approval interruptions.
|
|
58
|
+
*/
|
|
59
|
+
setApprovalScope(scope: ApprovalScope): void;
|
|
60
|
+
/**
|
|
61
|
+
* Check if a tool call is pre-approved by the current scope.
|
|
62
|
+
*/
|
|
63
|
+
private isPreApproved;
|
|
64
|
+
/**
|
|
65
|
+
* Determine risk level of an action.
|
|
66
|
+
*/
|
|
67
|
+
assessRisk(toolCall: ToolCall): RiskLevel;
|
|
68
|
+
/**
|
|
69
|
+
* Check if action needs approval.
|
|
70
|
+
*/
|
|
71
|
+
needsApproval(toolCall: ToolCall): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Request approval for an action.
|
|
74
|
+
*/
|
|
75
|
+
requestApproval(toolCall: ToolCall, context: string): Promise<ApprovalResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Console-based approval (for demos).
|
|
78
|
+
*/
|
|
79
|
+
private consoleApproval;
|
|
80
|
+
/**
|
|
81
|
+
* Execute with timeout.
|
|
82
|
+
*/
|
|
83
|
+
private executeWithTimeout;
|
|
84
|
+
/**
|
|
85
|
+
* Log an action to audit trail.
|
|
86
|
+
* Trims the log when it exceeds maxAuditEntries to prevent unbounded growth.
|
|
87
|
+
*/
|
|
88
|
+
private logAction;
|
|
89
|
+
/**
|
|
90
|
+
* Get audit log.
|
|
91
|
+
*/
|
|
92
|
+
getAuditLog(): AuditEntry[];
|
|
93
|
+
/**
|
|
94
|
+
* Get audit summary.
|
|
95
|
+
*/
|
|
96
|
+
getAuditSummary(): AuditSummary;
|
|
97
|
+
/**
|
|
98
|
+
* Clear audit log.
|
|
99
|
+
*/
|
|
100
|
+
clearAuditLog(): void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Combined safety manager for the production agent.
|
|
104
|
+
*/
|
|
105
|
+
export declare class SafetyManager {
|
|
106
|
+
sandbox: SandboxManager | null;
|
|
107
|
+
humanInLoop: HumanInLoopManager | null;
|
|
108
|
+
constructor(sandboxConfig: SandboxConfig | false, hilConfig: HumanInLoopConfig | false, policyEngineConfig?: PolicyEngineConfig | false);
|
|
109
|
+
/**
|
|
110
|
+
* Validate a tool call against all safety rules.
|
|
111
|
+
*/
|
|
112
|
+
validateAndApprove(toolCall: ToolCall, context: string, options?: {
|
|
113
|
+
skipHumanApproval?: boolean;
|
|
114
|
+
}): Promise<{
|
|
115
|
+
allowed: boolean;
|
|
116
|
+
reason?: string;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Execute a tool call with safety wrapping.
|
|
120
|
+
*/
|
|
121
|
+
executeWithSafety<T>(fn: () => Promise<T>, toolCall: ToolCall, context: string): Promise<T>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Approval scope for subagent pre-approval.
|
|
125
|
+
* Allows specifying which tools and paths are pre-approved,
|
|
126
|
+
* reducing interruptions during multi-agent workflows.
|
|
127
|
+
*/
|
|
128
|
+
export interface ApprovalScope {
|
|
129
|
+
/** Tools that are always auto-approved (e.g., read_file, glob, grep) */
|
|
130
|
+
autoApprove?: string[];
|
|
131
|
+
/** Tools approved within specific path scopes */
|
|
132
|
+
scopedApprove?: Record<string, {
|
|
133
|
+
paths: string[];
|
|
134
|
+
}>;
|
|
135
|
+
/** Tools that always require approval regardless of scope */
|
|
136
|
+
requireApproval?: string[];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Risk levels for safety assessment.
|
|
140
|
+
* Matches the risk property in ApprovalRequest from types.ts.
|
|
141
|
+
*/
|
|
142
|
+
type RiskLevel = 'low' | 'moderate' | 'high' | 'critical';
|
|
143
|
+
/**
|
|
144
|
+
* Result of an approval request.
|
|
145
|
+
* Extends ApprovalResponse with additional tracking info.
|
|
146
|
+
*/
|
|
147
|
+
interface ApprovalResult {
|
|
148
|
+
approved: boolean;
|
|
149
|
+
reason?: string;
|
|
150
|
+
modifiedArgs?: Record<string, unknown>;
|
|
151
|
+
/** Who approved the action (for audit trail) */
|
|
152
|
+
approver?: string;
|
|
153
|
+
}
|
|
154
|
+
interface AuditEntry {
|
|
155
|
+
timestamp: Date;
|
|
156
|
+
action: string;
|
|
157
|
+
args: unknown;
|
|
158
|
+
approved: boolean;
|
|
159
|
+
approver: string;
|
|
160
|
+
risk: RiskLevel;
|
|
161
|
+
}
|
|
162
|
+
interface AuditSummary {
|
|
163
|
+
total: number;
|
|
164
|
+
approved: number;
|
|
165
|
+
denied: number;
|
|
166
|
+
byRisk: {
|
|
167
|
+
low: number;
|
|
168
|
+
medium: number;
|
|
169
|
+
high: number;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export declare function createSafetyManager(sandboxConfig: SandboxConfig | false, hilConfig: HumanInLoopConfig | false, policyEngineConfig?: PolicyEngineConfig | false): SafetyManager;
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=safety.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safety.d.ts","sourceRoot":"","sources":["../../../../src/integrations/safety/safety.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,QAAQ,EAGT,MAAM,gBAAgB,CAAC;AAaxB;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,kBAAkB,CAAC,CAAqB;gBAEpC,MAAM,EAAE,aAAa,EAAE,kBAAkB,CAAC,EAAE,kBAAkB,GAAG,KAAK;IAKlF;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAkCxE;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAyDpC;;OAEG;IACH,iBAAiB,IAAI,WAAW,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IASjE;;OAEG;IACG,iBAAiB,CAAC,CAAC,EACvB,EAAE,EAAE,MAAM,OAAO,CAA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CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,UAAU,YAAY;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAMD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,aAAa,GAAG,KAAK,EACpC,SAAS,EAAE,iBAAiB,GAAG,KAAK,EACpC,kBAAkB,CAAC,EAAE,kBAAkB,GAAG,KAAK,GAC9C,aAAa,CAEf"}
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lesson 23: Safety Integration
|
|
3
|
+
*
|
|
4
|
+
* Integrates sandboxing (Lesson 20) and human-in-the-loop (Lesson 21)
|
|
5
|
+
* into the production agent. Provides execution safety and approval workflows.
|
|
6
|
+
*/
|
|
7
|
+
import { resolve, isAbsolute, dirname } from 'node:path';
|
|
8
|
+
import { realpathSync, existsSync, lstatSync } from 'node:fs';
|
|
9
|
+
import { evaluateBashCommandByProfile, isToolAllowedByProfile, resolvePolicyProfile, } from './policy-engine.js';
|
|
10
|
+
import { stripCdPrefix } from './bash-policy.js';
|
|
11
|
+
import { logger } from '../utilities/logger.js';
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// SANDBOX MANAGER
|
|
14
|
+
// =============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Manages sandboxed execution of tools.
|
|
17
|
+
*/
|
|
18
|
+
export class SandboxManager {
|
|
19
|
+
config;
|
|
20
|
+
policyEngineConfig;
|
|
21
|
+
constructor(config, policyEngineConfig) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.policyEngineConfig = policyEngineConfig || undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if a command is allowed.
|
|
27
|
+
*/
|
|
28
|
+
isCommandAllowed(command) {
|
|
29
|
+
const { profile } = resolvePolicyProfile({
|
|
30
|
+
policyEngine: this.policyEngineConfig,
|
|
31
|
+
sandboxConfig: this.config,
|
|
32
|
+
});
|
|
33
|
+
const policyDecision = evaluateBashCommandByProfile(command, profile);
|
|
34
|
+
if (!policyDecision.allowed) {
|
|
35
|
+
return { allowed: false, reason: policyDecision.reason };
|
|
36
|
+
}
|
|
37
|
+
// Check blocked patterns first
|
|
38
|
+
for (const blocked of this.config.blockedCommands || []) {
|
|
39
|
+
if (command.includes(blocked)) {
|
|
40
|
+
return { allowed: false, reason: `Blocked pattern: ${blocked}` };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check allowed commands
|
|
44
|
+
const allowedCommands = this.config.allowedCommands || [];
|
|
45
|
+
const effective = stripCdPrefix(command);
|
|
46
|
+
const commandBase = effective.split(' ')[0];
|
|
47
|
+
if (allowedCommands.length > 0 && !allowedCommands.includes(commandBase)) {
|
|
48
|
+
const suggestions = allowedCommands.slice(0, 10).join(', ');
|
|
49
|
+
return {
|
|
50
|
+
allowed: false,
|
|
51
|
+
reason: `Command '${commandBase}' is not in the sandbox allowlist. Use built-in tools (read_file, write_file, edit_file, glob, grep) instead, or use bash with an allowed command: ${suggestions}...`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return { allowed: true };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if a path is allowed.
|
|
58
|
+
* Resolves relative paths against cwd before comparison.
|
|
59
|
+
* Uses realpath to resolve symlinks and prevent symlink escape attacks.
|
|
60
|
+
*/
|
|
61
|
+
isPathAllowed(path) {
|
|
62
|
+
const allowedPaths = this.config.allowedPaths || ['.'];
|
|
63
|
+
// Resolve the path, handling symlinks for security
|
|
64
|
+
let resolvedPath;
|
|
65
|
+
try {
|
|
66
|
+
const absolutePath = isAbsolute(path) ? path : resolve(process.cwd(), path);
|
|
67
|
+
// If path exists, use realpath to resolve symlinks
|
|
68
|
+
if (existsSync(absolutePath)) {
|
|
69
|
+
resolvedPath = realpathSync(absolutePath);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Special case: broken symlink exists as a link entry but target is missing.
|
|
73
|
+
// Deny to fail closed and avoid symlink-escape bypasses.
|
|
74
|
+
try {
|
|
75
|
+
const stat = lstatSync(absolutePath);
|
|
76
|
+
if (stat.isSymbolicLink()) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// No direct entry - continue with parent-directory check.
|
|
82
|
+
}
|
|
83
|
+
// Path doesn't exist yet - recursively check that parent is allowed
|
|
84
|
+
const parentDir = dirname(absolutePath);
|
|
85
|
+
if (parentDir === absolutePath) {
|
|
86
|
+
return false; // Root reached without match
|
|
87
|
+
}
|
|
88
|
+
return this.isPathAllowed(parentDir);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// realpath failed (broken symlink, permission denied, etc.)
|
|
93
|
+
// Fail closed - deny access
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
for (const allowed of allowedPaths) {
|
|
97
|
+
let resolvedAllowed;
|
|
98
|
+
try {
|
|
99
|
+
const absoluteAllowed = isAbsolute(allowed) ? allowed : resolve(process.cwd(), allowed);
|
|
100
|
+
// Use realpath if allowed path exists, otherwise just the absolute path
|
|
101
|
+
resolvedAllowed = existsSync(absoluteAllowed)
|
|
102
|
+
? realpathSync(absoluteAllowed)
|
|
103
|
+
: absoluteAllowed;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
continue; // Skip invalid allowed paths
|
|
107
|
+
}
|
|
108
|
+
// Check if resolved target is within resolved allowed path
|
|
109
|
+
if (resolvedPath === resolvedAllowed || resolvedPath.startsWith(resolvedAllowed + '/')) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get resource limits.
|
|
117
|
+
*/
|
|
118
|
+
getResourceLimits() {
|
|
119
|
+
return this.config.resourceLimits || {
|
|
120
|
+
maxCpuSeconds: 30,
|
|
121
|
+
maxMemoryMB: 512,
|
|
122
|
+
maxOutputBytes: 1024 * 1024,
|
|
123
|
+
timeout: 60000,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Wrap execution with resource limits.
|
|
128
|
+
*/
|
|
129
|
+
async executeWithLimits(fn, timeout) {
|
|
130
|
+
const limits = this.getResourceLimits();
|
|
131
|
+
const timeoutMs = timeout || limits.timeout;
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const timer = setTimeout(() => {
|
|
134
|
+
reject(new Error(`Execution timeout: ${timeoutMs}ms`));
|
|
135
|
+
}, timeoutMs);
|
|
136
|
+
fn()
|
|
137
|
+
.then((result) => {
|
|
138
|
+
clearTimeout(timer);
|
|
139
|
+
resolve(result);
|
|
140
|
+
})
|
|
141
|
+
.catch((err) => {
|
|
142
|
+
clearTimeout(timer);
|
|
143
|
+
reject(err);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Validate tool call against sandbox rules.
|
|
149
|
+
*/
|
|
150
|
+
validateToolCall(toolCall) {
|
|
151
|
+
const args = toolCall.arguments;
|
|
152
|
+
const { profile } = resolvePolicyProfile({
|
|
153
|
+
policyEngine: this.policyEngineConfig,
|
|
154
|
+
sandboxConfig: this.config,
|
|
155
|
+
});
|
|
156
|
+
const toolDecision = isToolAllowedByProfile(toolCall.name, profile);
|
|
157
|
+
if (!toolDecision.allowed) {
|
|
158
|
+
return { valid: false, reason: toolDecision.reason };
|
|
159
|
+
}
|
|
160
|
+
// Check for command execution tools
|
|
161
|
+
if (toolCall.name === 'bash' || toolCall.name === 'shell' || toolCall.name === 'execute') {
|
|
162
|
+
const command = String(args.command || args.cmd || '');
|
|
163
|
+
const result = this.isCommandAllowed(command);
|
|
164
|
+
return { valid: result.allowed, reason: result.reason };
|
|
165
|
+
}
|
|
166
|
+
// Check for file operation tools
|
|
167
|
+
if (toolCall.name === 'read_file' || toolCall.name === 'write_file' || toolCall.name === 'edit_file') {
|
|
168
|
+
const path = String(args.path || args.file || args.file_path || '');
|
|
169
|
+
if (!this.isPathAllowed(path)) {
|
|
170
|
+
return { valid: false, reason: `Path not allowed: ${path}` };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return { valid: true };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// =============================================================================
|
|
177
|
+
// HUMAN-IN-LOOP MANAGER
|
|
178
|
+
// =============================================================================
|
|
179
|
+
/**
|
|
180
|
+
* Manages human approval workflows.
|
|
181
|
+
*/
|
|
182
|
+
export class HumanInLoopManager {
|
|
183
|
+
config;
|
|
184
|
+
auditLog = [];
|
|
185
|
+
pendingApprovals = new Map();
|
|
186
|
+
approvalScope = null;
|
|
187
|
+
// Audit log limits to prevent unbounded memory growth
|
|
188
|
+
maxAuditEntries = 10000;
|
|
189
|
+
auditTrimSize = 5000; // Keep this many when trimming
|
|
190
|
+
constructor(config) {
|
|
191
|
+
this.config = config;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Set an approval scope for pre-approved operations.
|
|
195
|
+
* Used by subagents to reduce approval interruptions.
|
|
196
|
+
*/
|
|
197
|
+
setApprovalScope(scope) {
|
|
198
|
+
this.approvalScope = scope;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Check if a tool call is pre-approved by the current scope.
|
|
202
|
+
*/
|
|
203
|
+
isPreApproved(toolCall) {
|
|
204
|
+
if (!this.approvalScope)
|
|
205
|
+
return false;
|
|
206
|
+
const toolName = toolCall.name.toLowerCase();
|
|
207
|
+
// Check require-approval list first (highest priority) — exact match only
|
|
208
|
+
if (this.approvalScope.requireApproval?.some(t => toolName === t.toLowerCase())) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
// Check auto-approve list — exact match only
|
|
212
|
+
if (this.approvalScope.autoApprove?.some(t => toolName === t.toLowerCase())) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
// Check scoped approval (tool + path match)
|
|
216
|
+
if (this.approvalScope.scopedApprove?.[toolCall.name]) {
|
|
217
|
+
const scope = this.approvalScope.scopedApprove[toolCall.name];
|
|
218
|
+
const args = toolCall.arguments;
|
|
219
|
+
const filePath = String(args.path || args.file_path || '');
|
|
220
|
+
if (filePath && scope.paths.some(p => {
|
|
221
|
+
// Directory-aware path matching
|
|
222
|
+
const dir = p.endsWith('/**') ? p.slice(0, -3) : p;
|
|
223
|
+
// Ensure directory boundary: "src/" matches "src/foo.ts" but not "src-backup/foo.ts"
|
|
224
|
+
// If dir already ends with '/', use as-is; otherwise check exact match or '/' boundary
|
|
225
|
+
if (dir.endsWith('/')) {
|
|
226
|
+
return filePath.startsWith(dir);
|
|
227
|
+
}
|
|
228
|
+
return filePath === dir || filePath.startsWith(dir + '/');
|
|
229
|
+
})) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Determine risk level of an action.
|
|
237
|
+
*/
|
|
238
|
+
assessRisk(toolCall) {
|
|
239
|
+
const toolName = toolCall.name.toLowerCase();
|
|
240
|
+
const args = toolCall.arguments;
|
|
241
|
+
// Check always-approve list (high risk)
|
|
242
|
+
for (const pattern of this.config.alwaysApprove || []) {
|
|
243
|
+
if (toolName.includes(pattern.toLowerCase())) {
|
|
244
|
+
return 'high';
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Check never-approve list (low risk, auto-approve)
|
|
248
|
+
for (const pattern of this.config.neverApprove || []) {
|
|
249
|
+
if (toolName.includes(pattern.toLowerCase())) {
|
|
250
|
+
return 'low';
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Internal bookkeeping tools are always low risk regardless of name patterns
|
|
254
|
+
const internalTools = ['task_create', 'task_update', 'task_get', 'task_list'];
|
|
255
|
+
if (internalTools.includes(toolName)) {
|
|
256
|
+
return 'low';
|
|
257
|
+
}
|
|
258
|
+
// Heuristic risk assessment
|
|
259
|
+
const highRiskPatterns = ['delete', 'remove', 'drop', 'truncate', 'wipe', 'destroy'];
|
|
260
|
+
for (const pattern of highRiskPatterns) {
|
|
261
|
+
if (toolName.includes(pattern)) {
|
|
262
|
+
return 'high';
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const moderateRiskPatterns = ['write', 'modify', 'update'];
|
|
266
|
+
for (const pattern of moderateRiskPatterns) {
|
|
267
|
+
if (toolName.includes(pattern)) {
|
|
268
|
+
return 'moderate';
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// Check for destructive arguments
|
|
272
|
+
const argsStr = JSON.stringify(args).toLowerCase();
|
|
273
|
+
if (argsStr.includes('--force') || argsStr.includes('-rf') || argsStr.includes('--hard')) {
|
|
274
|
+
return 'moderate';
|
|
275
|
+
}
|
|
276
|
+
return 'low';
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Check if action needs approval.
|
|
280
|
+
*/
|
|
281
|
+
needsApproval(toolCall) {
|
|
282
|
+
// Check pre-approval scope first (for subagent batched approvals)
|
|
283
|
+
if (this.isPreApproved(toolCall)) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
const risk = this.assessRisk(toolCall);
|
|
287
|
+
const threshold = this.config.riskThreshold || 'high';
|
|
288
|
+
const riskLevels = ['low', 'moderate', 'high'];
|
|
289
|
+
const riskIndex = riskLevels.indexOf(risk);
|
|
290
|
+
const thresholdIndex = riskLevels.indexOf(threshold);
|
|
291
|
+
return riskIndex >= thresholdIndex;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Request approval for an action.
|
|
295
|
+
*/
|
|
296
|
+
async requestApproval(toolCall, context) {
|
|
297
|
+
const risk = this.assessRisk(toolCall);
|
|
298
|
+
// Auto-approve low risk if below threshold
|
|
299
|
+
if (!this.needsApproval(toolCall)) {
|
|
300
|
+
this.logAction(toolCall, true, 'auto', risk);
|
|
301
|
+
return { approved: true, approver: 'auto' };
|
|
302
|
+
}
|
|
303
|
+
// Use custom handler if provided
|
|
304
|
+
if (this.config.approvalHandler) {
|
|
305
|
+
const approvalRequest = {
|
|
306
|
+
id: `approval-${Date.now()}`,
|
|
307
|
+
action: toolCall.name,
|
|
308
|
+
tool: toolCall.name,
|
|
309
|
+
args: toolCall.arguments,
|
|
310
|
+
risk,
|
|
311
|
+
context,
|
|
312
|
+
};
|
|
313
|
+
const response = await this.executeWithTimeout(() => this.config.approvalHandler(approvalRequest), this.config.approvalTimeout || 300000);
|
|
314
|
+
// Convert ApprovalResponse to ApprovalResult
|
|
315
|
+
const result = {
|
|
316
|
+
approved: response.approved,
|
|
317
|
+
reason: response.reason,
|
|
318
|
+
modifiedArgs: response.modifiedArgs,
|
|
319
|
+
approver: 'handler',
|
|
320
|
+
};
|
|
321
|
+
this.logAction(toolCall, result.approved, result.approver || 'handler', risk);
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
// Default: console-based approval
|
|
325
|
+
return this.consoleApproval(toolCall, context, risk);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Console-based approval (for demos).
|
|
329
|
+
*/
|
|
330
|
+
async consoleApproval(toolCall, context, risk) {
|
|
331
|
+
logger.info('Approval required', {
|
|
332
|
+
tool: toolCall.name,
|
|
333
|
+
risk: risk.toUpperCase(),
|
|
334
|
+
arguments: JSON.stringify(toolCall.arguments).slice(0, 47),
|
|
335
|
+
context: context.slice(0, 47),
|
|
336
|
+
});
|
|
337
|
+
// In non-interactive mode, auto-approve for demo
|
|
338
|
+
logger.debug('Demo mode: Auto-approving');
|
|
339
|
+
this.logAction(toolCall, true, 'demo', risk);
|
|
340
|
+
return { approved: true, approver: 'demo' };
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Execute with timeout.
|
|
344
|
+
*/
|
|
345
|
+
async executeWithTimeout(fn, timeout) {
|
|
346
|
+
return new Promise((resolve, reject) => {
|
|
347
|
+
const timer = setTimeout(() => {
|
|
348
|
+
reject(new Error('Approval timeout'));
|
|
349
|
+
}, timeout);
|
|
350
|
+
fn()
|
|
351
|
+
.then((result) => {
|
|
352
|
+
clearTimeout(timer);
|
|
353
|
+
resolve(result);
|
|
354
|
+
})
|
|
355
|
+
.catch((err) => {
|
|
356
|
+
clearTimeout(timer);
|
|
357
|
+
reject(err);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Log an action to audit trail.
|
|
363
|
+
* Trims the log when it exceeds maxAuditEntries to prevent unbounded growth.
|
|
364
|
+
*/
|
|
365
|
+
logAction(toolCall, approved, approver, risk) {
|
|
366
|
+
if (!this.config.auditLog)
|
|
367
|
+
return;
|
|
368
|
+
const entry = {
|
|
369
|
+
timestamp: new Date(),
|
|
370
|
+
action: toolCall.name,
|
|
371
|
+
args: toolCall.arguments,
|
|
372
|
+
approved,
|
|
373
|
+
approver,
|
|
374
|
+
risk,
|
|
375
|
+
};
|
|
376
|
+
this.auditLog.push(entry);
|
|
377
|
+
// Trim if exceeded max size - keep most recent entries
|
|
378
|
+
if (this.auditLog.length > this.maxAuditEntries) {
|
|
379
|
+
this.auditLog = this.auditLog.slice(-this.auditTrimSize);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get audit log.
|
|
384
|
+
*/
|
|
385
|
+
getAuditLog() {
|
|
386
|
+
return [...this.auditLog];
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Get audit summary.
|
|
390
|
+
*/
|
|
391
|
+
getAuditSummary() {
|
|
392
|
+
const total = this.auditLog.length;
|
|
393
|
+
const approved = this.auditLog.filter((e) => e.approved).length;
|
|
394
|
+
const denied = total - approved;
|
|
395
|
+
const byRisk = {
|
|
396
|
+
low: this.auditLog.filter((e) => e.risk === 'low').length,
|
|
397
|
+
medium: this.auditLog.filter((e) => e.risk === 'moderate').length,
|
|
398
|
+
high: this.auditLog.filter((e) => e.risk === 'high').length,
|
|
399
|
+
};
|
|
400
|
+
return { total, approved, denied, byRisk };
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Clear audit log.
|
|
404
|
+
*/
|
|
405
|
+
clearAuditLog() {
|
|
406
|
+
this.auditLog = [];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// =============================================================================
|
|
410
|
+
// COMBINED SAFETY MANAGER
|
|
411
|
+
// =============================================================================
|
|
412
|
+
/**
|
|
413
|
+
* Combined safety manager for the production agent.
|
|
414
|
+
*/
|
|
415
|
+
export class SafetyManager {
|
|
416
|
+
sandbox = null;
|
|
417
|
+
humanInLoop = null;
|
|
418
|
+
constructor(sandboxConfig, hilConfig, policyEngineConfig) {
|
|
419
|
+
if (sandboxConfig && sandboxConfig.enabled !== false) {
|
|
420
|
+
this.sandbox = new SandboxManager(sandboxConfig, policyEngineConfig);
|
|
421
|
+
}
|
|
422
|
+
if (hilConfig && hilConfig.enabled !== false) {
|
|
423
|
+
this.humanInLoop = new HumanInLoopManager(hilConfig);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Validate a tool call against all safety rules.
|
|
428
|
+
*/
|
|
429
|
+
async validateAndApprove(toolCall, context, options) {
|
|
430
|
+
// Sandbox validation
|
|
431
|
+
if (this.sandbox) {
|
|
432
|
+
const validation = this.sandbox.validateToolCall(toolCall);
|
|
433
|
+
if (!validation.valid) {
|
|
434
|
+
return { allowed: false, reason: validation.reason };
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
// Human-in-loop approval
|
|
438
|
+
if (this.humanInLoop) {
|
|
439
|
+
if (!options?.skipHumanApproval && this.humanInLoop.needsApproval(toolCall)) {
|
|
440
|
+
const result = await this.humanInLoop.requestApproval(toolCall, context);
|
|
441
|
+
if (!result.approved) {
|
|
442
|
+
return { allowed: false, reason: `Denied by ${result.approver}` };
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return { allowed: true };
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Execute a tool call with safety wrapping.
|
|
450
|
+
*/
|
|
451
|
+
async executeWithSafety(fn, toolCall, context) {
|
|
452
|
+
// Validate first
|
|
453
|
+
const validation = await this.validateAndApprove(toolCall, context);
|
|
454
|
+
if (!validation.allowed) {
|
|
455
|
+
throw new Error(`Tool call blocked: ${validation.reason}`);
|
|
456
|
+
}
|
|
457
|
+
// Execute with sandbox limits if enabled
|
|
458
|
+
if (this.sandbox) {
|
|
459
|
+
return this.sandbox.executeWithLimits(fn);
|
|
460
|
+
}
|
|
461
|
+
return fn();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
// =============================================================================
|
|
465
|
+
// FACTORY
|
|
466
|
+
// =============================================================================
|
|
467
|
+
export function createSafetyManager(sandboxConfig, hilConfig, policyEngineConfig) {
|
|
468
|
+
return new SafetyManager(sandboxConfig, hilConfig, policyEngineConfig);
|
|
469
|
+
}
|
|
470
|
+
//# sourceMappingURL=safety.js.map
|