@draht/coding-agent 2026.7.11 → 2026.7.12-1
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 +28 -0
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/register-bedrock.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
- package/dist/bun/restore-sandbox-env.js.map +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/attach-mode.d.ts.map +1 -1
- package/dist/cli/attach-mode.js.map +1 -1
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/initial-message.d.ts +1 -1
- package/dist/cli/initial-message.d.ts.map +1 -1
- package/dist/cli/initial-message.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/list-sessions.d.ts.map +1 -1
- package/dist/cli/list-sessions.js.map +1 -1
- package/dist/cli/project-trust.d.ts.map +1 -1
- package/dist/cli/project-trust.js.map +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +0 -8
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +2 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +28 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +94 -123
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/auth-storage.d.ts +4 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +4 -7
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/builtins/index.d.ts +11 -0
- package/dist/core/builtins/index.d.ts.map +1 -0
- package/dist/core/builtins/index.js +11 -0
- package/dist/core/builtins/index.js.map +1 -0
- package/dist/core/builtins/subagent.d.ts +88 -1
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +263 -27
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js.map +1 -1
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/experimental.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +21 -28
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +17 -18
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +0 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +6 -8
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/multi-agent/fsm.d.ts +60 -0
- package/dist/core/multi-agent/fsm.d.ts.map +1 -0
- package/dist/core/multi-agent/fsm.js +90 -0
- package/dist/core/multi-agent/fsm.js.map +1 -0
- package/dist/core/multi-agent/index.d.ts +21 -0
- package/dist/core/multi-agent/index.d.ts.map +1 -0
- package/dist/core/multi-agent/index.js +21 -0
- package/dist/core/multi-agent/index.js.map +1 -0
- package/dist/core/multi-agent/mailbox.d.ts +56 -0
- package/dist/core/multi-agent/mailbox.d.ts.map +1 -0
- package/dist/core/multi-agent/mailbox.js +112 -0
- package/dist/core/multi-agent/mailbox.js.map +1 -0
- package/dist/core/multi-agent/permission-gate.d.ts +140 -0
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -0
- package/dist/core/multi-agent/permission-gate.js +669 -0
- package/dist/core/multi-agent/permission-gate.js.map +1 -0
- package/dist/core/multi-agent/task-board.d.ts +100 -0
- package/dist/core/multi-agent/task-board.d.ts.map +1 -0
- package/dist/core/multi-agent/task-board.js +141 -0
- package/dist/core/multi-agent/task-board.js.map +1 -0
- package/dist/core/multi-agent/worktree.d.ts +50 -0
- package/dist/core/multi-agent/worktree.d.ts.map +1 -0
- package/dist/core/multi-agent/worktree.js +148 -0
- package/dist/core/multi-agent/worktree.js.map +1 -0
- package/dist/core/output-guard.d.ts.map +1 -1
- package/dist/core/output-guard.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +0 -6
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-attribution.d.ts.map +1 -1
- package/dist/core/provider-attribution.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +0 -41
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +7 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js +0 -1
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +7 -11
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +7 -17
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/socket-server/discovery.d.ts.map +1 -1
- package/dist/core/socket-server/discovery.js.map +1 -1
- package/dist/core/socket-server/index.d.ts.map +1 -1
- package/dist/core/socket-server/session-integration.d.ts.map +1 -1
- package/dist/core/socket-server/session-integration.js.map +1 -1
- package/dist/core/socket-server/socket-client.d.ts.map +1 -1
- package/dist/core/socket-server/socket-client.js.map +1 -1
- package/dist/core/socket-server/socket-server.d.ts.map +1 -1
- package/dist/core/socket-server/socket-server.js.map +1 -1
- package/dist/core/socket-server/types.d.ts.map +1 -1
- package/dist/core/source-info.d.ts.map +1 -1
- package/dist/core/source-info.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/telemetry.d.ts.map +1 -1
- package/dist/core/telemetry.js.map +1 -1
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +8 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +12 -18
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/path-utils.d.ts.map +1 -1
- package/dist/core/tools/path-utils.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +0 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +0 -1
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/gsd/domain-validator.d.ts.map +1 -1
- package/dist/gsd/domain-validator.js.map +1 -1
- package/dist/gsd/domain.d.ts.map +1 -1
- package/dist/gsd/domain.js.map +1 -1
- package/dist/gsd/git.d.ts.map +1 -1
- package/dist/gsd/git.js.map +1 -1
- package/dist/gsd/hook-utils.d.ts.map +1 -1
- package/dist/gsd/hook-utils.js.map +1 -1
- package/dist/gsd/index.d.ts.map +1 -1
- package/dist/gsd/index.js.map +1 -1
- package/dist/gsd/planning.d.ts.map +1 -1
- package/dist/gsd/planning.js.map +1 -1
- package/dist/hooks/gsd/draht-post-task.js +1 -1
- package/dist/hooks/gsd/draht-quality-gate.js +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.d.ts.map +1 -1
- package/dist/modes/interactive/components/armin.js +6 -10
- package/dist/modes/interactive/components/armin.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +1 -7
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +4 -9
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js +0 -3
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +1 -3
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +1 -3
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +5 -22
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
- package/dist/modes/interactive/components/countdown-timer.js +0 -5
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +1 -8
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +1 -4
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -6
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
- package/dist/modes/interactive/components/daxnuts.js +6 -8
- package/dist/modes/interactive/components/daxnuts.js.map +1 -1
- package/dist/modes/interactive/components/diff.d.ts.map +1 -1
- package/dist/modes/interactive/components/diff.js.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +0 -1
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +1 -7
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +2 -8
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-selector.js +1 -9
- package/dist/modes/interactive/components/extension-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +2 -4
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -3
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +3 -9
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +8 -20
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +3 -13
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +9 -13
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +33 -57
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +0 -14
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js +0 -1
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +1 -3
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +0 -2
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.js +0 -2
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +0 -1
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +9 -24
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +18 -32
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/trust-selector.js +0 -6
- package/dist/modes/interactive/components/trust-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +3 -6
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +0 -3
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +11 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +65 -96
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/model-search.d.ts.map +1 -1
- package/dist/modes/interactive/model-search.js.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +2 -7
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +2 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +0 -6
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/jsonl.d.ts.map +1 -1
- package/dist/modes/rpc/jsonl.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +7 -8
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/prompts/commands/execute-phase.md +10 -0
- package/dist/rlm-cli.d.ts +92 -0
- package/dist/rlm-cli.d.ts.map +1 -0
- package/dist/rlm-cli.js +379 -0
- package/dist/rlm-cli.js.map +1 -0
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/rpc-entry.js.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/deprecation.d.ts.map +1 -1
- package/dist/utils/deprecation.js.map +1 -1
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/fs-watch.d.ts.map +1 -1
- package/dist/utils/fs-watch.js.map +1 -1
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/html.d.ts.map +1 -1
- package/dist/utils/html.js.map +1 -1
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-process.d.ts.map +1 -1
- package/dist/utils/image-process.js.map +1 -1
- package/dist/utils/image-resize-core.d.ts.map +1 -1
- package/dist/utils/image-resize-core.js.map +1 -1
- package/dist/utils/image-resize-worker.d.ts.map +1 -1
- package/dist/utils/image-resize-worker.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/mime.d.ts.map +1 -1
- package/dist/utils/mime.js.map +1 -1
- package/dist/utils/notify.d.ts +3 -1
- package/dist/utils/notify.d.ts.map +1 -1
- package/dist/utils/notify.js +11 -4
- package/dist/utils/notify.js.map +1 -1
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/photon.d.ts.map +1 -1
- package/dist/utils/photon.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js.map +1 -1
- package/dist/utils/windows-self-update.d.ts.map +1 -1
- package/dist/utils/windows-self-update.js.map +1 -1
- package/hooks/gsd/draht-post-task.js +1 -1
- package/hooks/gsd/draht-quality-gate.js +1 -1
- package/package.json +10 -8
- package/prompts/commands/execute-phase.md +10 -0
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission gate: a three-tier permission system that decides whether a
|
|
3
|
+
* tool call may proceed automatically, must be blocked, or must be confirmed
|
|
4
|
+
* by the user before it runs.
|
|
5
|
+
*
|
|
6
|
+
* SECURITY-CRITICAL: this module gates real bash/write tool calls. Prefer
|
|
7
|
+
* fail-safe (approve/deny) over fail-open (allow) whenever a decision is
|
|
8
|
+
* ambiguous.
|
|
9
|
+
*
|
|
10
|
+
* Configuration is read from `.draht/permissions.yml` (project) and
|
|
11
|
+
* `~/.draht/agent/permissions.yml` (global), e.g.:
|
|
12
|
+
*
|
|
13
|
+
* ```yaml
|
|
14
|
+
* rules:
|
|
15
|
+
* - tool: bash
|
|
16
|
+
* pattern: "rm -rf *"
|
|
17
|
+
* action: deny
|
|
18
|
+
* - tool: bash
|
|
19
|
+
* pattern: "git push *"
|
|
20
|
+
* action: approve
|
|
21
|
+
* - tool: read
|
|
22
|
+
* action: allow
|
|
23
|
+
* - tool: write
|
|
24
|
+
* paths: ["src/**"]
|
|
25
|
+
* action: allow
|
|
26
|
+
* - tool: write
|
|
27
|
+
* action: approve
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Rules are evaluated top-to-bottom; the first matching rule wins.
|
|
31
|
+
*
|
|
32
|
+
* On top of the rules sits a session-level `PermissionMode` (`default` /
|
|
33
|
+
* `auto` / `yolo`, see the type doc) that relaxes how unmatched calls and
|
|
34
|
+
* `approve` outcomes are handled — `deny` rules are never relaxed.
|
|
35
|
+
*
|
|
36
|
+
* `pattern` matching against bash commands is textual (no real shell
|
|
37
|
+
* parser), so `deny` and `allow`/`approve` patterns are matched with
|
|
38
|
+
* deliberately asymmetric strategies to stay fail-safe: `deny` scans every
|
|
39
|
+
* chained/wrapped/unwrapped piece of the command it can find (paranoid,
|
|
40
|
+
* over-matching is safe), while `allow`/`approve` require an exact
|
|
41
|
+
* chain-shape match and reject anything containing `$(...)`, backticks, or
|
|
42
|
+
* redirection (strict, under-matching just falls through to the default
|
|
43
|
+
* decision instead of silently authorizing more than intended). See the
|
|
44
|
+
* doc comment on `matchCommandPattern` below for details and known limits —
|
|
45
|
+
* in particular, `pattern` can never guarantee real path containment; use
|
|
46
|
+
* `paths` for that.
|
|
47
|
+
*/
|
|
48
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
49
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
50
|
+
import { minimatch } from "minimatch";
|
|
51
|
+
import { parse } from "yaml";
|
|
52
|
+
import { CONFIG_DIR_NAME, getAgentDir } from "../../config.js";
|
|
53
|
+
export const PERMISSION_MODES = ["default", "auto", "yolo"];
|
|
54
|
+
export function isPermissionMode(value) {
|
|
55
|
+
return typeof value === "string" && PERMISSION_MODES.includes(value);
|
|
56
|
+
}
|
|
57
|
+
const VALID_ACTIONS = ["deny", "allow", "approve"];
|
|
58
|
+
const RULES_FILE_NAME = "permissions.yml";
|
|
59
|
+
const PATH_SCOPED_TOOLS = new Set(["read", "write", "edit"]);
|
|
60
|
+
/** Read-only tools whose optional `path` arg defaults to the cwd when omitted. */
|
|
61
|
+
const READ_ONLY_PATH_TOOLS = new Set(["grep", "find", "ls"]);
|
|
62
|
+
/**
|
|
63
|
+
* Tools that are safe to run without confirmation because the call itself
|
|
64
|
+
* touches nothing: `subagent` only delegates — the spawned child process runs
|
|
65
|
+
* this same gate over every tool call it actually makes. Explicit rules can
|
|
66
|
+
* still `deny`/`approve` these.
|
|
67
|
+
*/
|
|
68
|
+
const DEFAULT_ALLOWED_TOOLS = new Set(["subagent"]);
|
|
69
|
+
function isPermissionAction(value) {
|
|
70
|
+
return typeof value === "string" && VALID_ACTIONS.includes(value);
|
|
71
|
+
}
|
|
72
|
+
function validateRule(raw, index) {
|
|
73
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
74
|
+
throw new Error(`permissions.yml: rule at index ${index} must be an object`);
|
|
75
|
+
}
|
|
76
|
+
const record = raw;
|
|
77
|
+
if (typeof record.tool !== "string" || record.tool.length === 0) {
|
|
78
|
+
throw new Error(`permissions.yml: rule at index ${index} is missing a valid "tool" field`);
|
|
79
|
+
}
|
|
80
|
+
if (!isPermissionAction(record.action)) {
|
|
81
|
+
throw new Error(`permissions.yml: rule at index ${index} has an invalid "action" (must be one of ${VALID_ACTIONS.join(", ")})`);
|
|
82
|
+
}
|
|
83
|
+
const rule = { tool: record.tool, action: record.action };
|
|
84
|
+
if (record.pattern !== undefined) {
|
|
85
|
+
if (typeof record.pattern !== "string") {
|
|
86
|
+
throw new Error(`permissions.yml: rule at index ${index} has a non-string "pattern"`);
|
|
87
|
+
}
|
|
88
|
+
rule.pattern = record.pattern;
|
|
89
|
+
}
|
|
90
|
+
if (record.paths !== undefined) {
|
|
91
|
+
if (!Array.isArray(record.paths) || !record.paths.every((entry) => typeof entry === "string")) {
|
|
92
|
+
throw new Error(`permissions.yml: rule at index ${index} has an invalid "paths" (must be a string array)`);
|
|
93
|
+
}
|
|
94
|
+
rule.paths = record.paths;
|
|
95
|
+
}
|
|
96
|
+
return rule;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parse a `permissions.yml` document (as a string) into an ordered list of
|
|
100
|
+
* rules. Returns an empty array for empty documents or documents without a
|
|
101
|
+
* `rules` key. Throws on malformed rule entries so misconfiguration fails
|
|
102
|
+
* loudly rather than silently degrading the gate.
|
|
103
|
+
*/
|
|
104
|
+
export function parseRules(yamlText) {
|
|
105
|
+
const parsed = parse(yamlText);
|
|
106
|
+
if (parsed === null || parsed === undefined)
|
|
107
|
+
return [];
|
|
108
|
+
if (parsed.rules === undefined)
|
|
109
|
+
return [];
|
|
110
|
+
if (!Array.isArray(parsed.rules)) {
|
|
111
|
+
throw new Error('permissions.yml: "rules" must be an array');
|
|
112
|
+
}
|
|
113
|
+
return parsed.rules.map((raw, index) => validateRule(raw, index));
|
|
114
|
+
}
|
|
115
|
+
function readRulesFile(filePath) {
|
|
116
|
+
if (!existsSync(filePath))
|
|
117
|
+
return [];
|
|
118
|
+
return parseRules(readFileSync(filePath, "utf-8"));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Load and merge permission rules from the global (`~/.draht/agent/permissions.yml`)
|
|
122
|
+
* and project (`<projectDir>/.draht/permissions.yml`) config files.
|
|
123
|
+
*
|
|
124
|
+
* Loading order: global is read first, project is read after (so a project
|
|
125
|
+
* can be authored as a delta on top of the global defaults). Merge order is
|
|
126
|
+
* reversed relative to load order: project rules are placed *before* global
|
|
127
|
+
* rules in the returned array, so that under first-match-wins evaluation the
|
|
128
|
+
* project's rules take precedence over — i.e. "override" — the global ones.
|
|
129
|
+
*/
|
|
130
|
+
export function loadRules(projectDir, globalDir) {
|
|
131
|
+
const globalRulesPath = join(globalDir ?? getAgentDir(), RULES_FILE_NAME);
|
|
132
|
+
const projectRulesPath = join(projectDir ?? process.cwd(), CONFIG_DIR_NAME, RULES_FILE_NAME);
|
|
133
|
+
const globalRules = readRulesFile(globalRulesPath);
|
|
134
|
+
const projectRules = readRulesFile(projectRulesPath);
|
|
135
|
+
return [...projectRules, ...globalRules];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Bash `pattern` matching against the raw command string can never be more
|
|
139
|
+
* than textual — it has no real shell parser behind it. A previous
|
|
140
|
+
* implementation matched the whole command string against the pattern with
|
|
141
|
+
* minimatch after stripping every "/" (to stop "*" from being blocked by
|
|
142
|
+
* minimatch's path-segment semantics). That was trivially bypassed: any
|
|
143
|
+
* prefix at all (a leading space, `sudo`, `/bin/`, `env`, chaining with `;`
|
|
144
|
+
* or `&&`, wrapping in `bash -c "..."`, double spaces, reordered combined
|
|
145
|
+
* flags like `-fr` vs `-rf`, or different case) defeated the anchored match,
|
|
146
|
+
* and — separately — a trailing-wildcard *allow* rule like
|
|
147
|
+
* `{ pattern: "npm test*", action: "allow" }` matched anything appended
|
|
148
|
+
* after it via `;`, `&&`, `|`, backticks, or `$(...)`, silently
|
|
149
|
+
* auto-approving injected commands.
|
|
150
|
+
*
|
|
151
|
+
* To stay fail-safe rather than fail-open, `deny` and `allow`/`approve` are
|
|
152
|
+
* matched with deliberately different, asymmetric strategies:
|
|
153
|
+
*
|
|
154
|
+
* - `deny` is matched *paranoidly*. The command is decomposed into every
|
|
155
|
+
* independently-executed piece we can find — split on chaining operators
|
|
156
|
+
* (`;`, `&&`, `||`, `|`, `&`, newlines); unwrapped from passthrough
|
|
157
|
+
* prefixes (`sudo`, `env`, `nice`, ...) and leading `VAR=val`
|
|
158
|
+
* assignments; unwrapped from `bash -c "..."` / `sh -c '...'` / `eval
|
|
159
|
+
* "..."`; unwrapped from `$(...)`/backtick substitutions; resolved from
|
|
160
|
+
* an absolute/relative path to a bare command name — recursively, up to
|
|
161
|
+
* a bounded depth/count. The pattern matches if *any* resulting
|
|
162
|
+
* candidate matches, after collapsing whitespace and canonicalizing
|
|
163
|
+
* combined short flags (so `-rf`/`-fr` compare equal), case-insensitively.
|
|
164
|
+
* Over-matching here is the safe failure mode.
|
|
165
|
+
* - `allow`/`approve` are matched *strictly*: the command is rejected
|
|
166
|
+
* outright if it contains any dynamic/opaque construct (`$(...)`,
|
|
167
|
+
* backticks, redirection `<`/`>`), and otherwise must have the exact same
|
|
168
|
+
* chain shape (same number of segments joined by the same operators) as
|
|
169
|
+
* the pattern, with each segment matched independently. A rule authored
|
|
170
|
+
* for `npm test*` therefore can never also authorize
|
|
171
|
+
* `npm test; rm -rf /` — the extra chained segment has no counterpart in
|
|
172
|
+
* the pattern, so the rule simply doesn't match (falling through to the
|
|
173
|
+
* default decision) instead of silently allowing it.
|
|
174
|
+
*
|
|
175
|
+
* KNOWN LIMITATION (not fixable with text matching alone): interpreter
|
|
176
|
+
* escape hatches. Once a command hands control to a language runtime, the
|
|
177
|
+
* payload is no longer shell and no shell-shaped pattern — `deny` rules
|
|
178
|
+
* included — can see into it: `python -c "os.system('rm -rf /')"` never
|
|
179
|
+
* surfaces `rm -rf /` as a match candidate, `python script.py` hides the
|
|
180
|
+
* danger in file contents the gate never reads, and
|
|
181
|
+
* `python -c "shutil.rmtree('/')"` involves no shell command at all. The
|
|
182
|
+
* built-in danger filter flags *inline eval* invocations (`python -c`,
|
|
183
|
+
* `node -e`, ...) so auto mode prompts on them, but script files and
|
|
184
|
+
* in-language equivalents are out of reach by construction. The gate is a
|
|
185
|
+
* guard against a confused agent, not a confinement boundary for a
|
|
186
|
+
* malicious one — a hard boundary needs OS-level sandboxing of the bash
|
|
187
|
+
* tool itself (Seatbelt/Landlock-style), not better string matching.
|
|
188
|
+
*
|
|
189
|
+
* KNOWN LIMITATION (not fixable with text matching alone): `pattern` cannot
|
|
190
|
+
* enforce real directory containment. A rule like
|
|
191
|
+
* `{ pattern: "cat /safe/dir/*", action: "allow" }` will still match
|
|
192
|
+
* `cat /safe/dir/../../../etc/passwd`, because from a glob's point of view
|
|
193
|
+
* `..` is just more characters absorbed by the trailing `*` — there is no
|
|
194
|
+
* shell/path awareness in a plain string pattern. Use the `paths` mechanism
|
|
195
|
+
* (which resolves real paths via `resolve`/`relative`, see `toMatchablePath`
|
|
196
|
+
* below) instead of `pattern` whenever a rule needs to be scoped to a
|
|
197
|
+
* directory; don't rely on `pattern` for path containment.
|
|
198
|
+
*/
|
|
199
|
+
/** Command names that merely forward to another command without changing what ultimately runs. */
|
|
200
|
+
const PASSTHROUGH_PREFIXES = new Set([
|
|
201
|
+
"sudo",
|
|
202
|
+
"doas",
|
|
203
|
+
"command",
|
|
204
|
+
"exec",
|
|
205
|
+
"nice",
|
|
206
|
+
"nohup",
|
|
207
|
+
"env",
|
|
208
|
+
"time",
|
|
209
|
+
"stdbuf",
|
|
210
|
+
"ionice",
|
|
211
|
+
"chrt",
|
|
212
|
+
"setsid",
|
|
213
|
+
"xargs",
|
|
214
|
+
]);
|
|
215
|
+
/** Shells whose `-c <command>` argument is itself a full command line to unwrap and re-check. */
|
|
216
|
+
const SHELL_C_WRAPPERS = new Set(["bash", "sh", "zsh", "ksh", "dash"]);
|
|
217
|
+
/** Constructs that make a command dynamic/opaque enough that allow/approve patterns must never match it. */
|
|
218
|
+
const DANGEROUS_CONSTRUCT_RE = /\$\(|`|<|>/;
|
|
219
|
+
/** Quote-aware split of a command string on top-level chain operators (`;`, `&&`, `||`, `|`, `&`, newlines). */
|
|
220
|
+
function splitChain(command) {
|
|
221
|
+
const segments = [];
|
|
222
|
+
let current = "";
|
|
223
|
+
let quote;
|
|
224
|
+
let operator;
|
|
225
|
+
let i = 0;
|
|
226
|
+
while (i < command.length) {
|
|
227
|
+
const ch = command[i];
|
|
228
|
+
if (quote) {
|
|
229
|
+
current += ch;
|
|
230
|
+
if (ch === quote)
|
|
231
|
+
quote = undefined;
|
|
232
|
+
i++;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (ch === '"' || ch === "'") {
|
|
236
|
+
quote = ch;
|
|
237
|
+
current += ch;
|
|
238
|
+
i++;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (ch === "\\" && i + 1 < command.length) {
|
|
242
|
+
current += ch + command[i + 1];
|
|
243
|
+
i += 2;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const two = command.slice(i, i + 2);
|
|
247
|
+
if (two === "&&" || two === "||") {
|
|
248
|
+
segments.push({ text: current, operator });
|
|
249
|
+
current = "";
|
|
250
|
+
operator = two;
|
|
251
|
+
i += 2;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (ch === ";" || ch === "|" || ch === "&" || ch === "\n") {
|
|
255
|
+
segments.push({ text: current, operator });
|
|
256
|
+
current = "";
|
|
257
|
+
operator = ch === "\n" ? ";" : ch;
|
|
258
|
+
i += 1;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
current += ch;
|
|
262
|
+
i++;
|
|
263
|
+
}
|
|
264
|
+
segments.push({ text: current, operator });
|
|
265
|
+
return segments;
|
|
266
|
+
}
|
|
267
|
+
function collapseWhitespace(text) {
|
|
268
|
+
return text.trim().replace(/\s+/g, " ");
|
|
269
|
+
}
|
|
270
|
+
/** Canonicalizes combined single-dash short-flag clusters (`-rf` / `-fr`) by sorting their letters. */
|
|
271
|
+
function normalizeFlagClusters(text) {
|
|
272
|
+
return text.replace(/(^|\s)-([A-Za-z]{2,})(?=\s|$)/g, (_match, pre, letters) => {
|
|
273
|
+
return `${pre}-${letters.split("").sort().join("")}`;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function normalizeForMatch(text) {
|
|
277
|
+
return normalizeFlagClusters(collapseWhitespace(text));
|
|
278
|
+
}
|
|
279
|
+
/** Resolves a leading `/some/path/cmd` (or `./cmd`, `../cmd`) first token down to its bare basename. */
|
|
280
|
+
function resolveBasenameOfFirstToken(text) {
|
|
281
|
+
const leadingWs = text.slice(0, text.length - text.trimStart().length);
|
|
282
|
+
const trimmed = text.trimStart();
|
|
283
|
+
const match = trimmed.match(/^(\S+)([\s\S]*)$/);
|
|
284
|
+
if (!match)
|
|
285
|
+
return text;
|
|
286
|
+
const [, firstToken, rest] = match;
|
|
287
|
+
if (!firstToken.includes("/"))
|
|
288
|
+
return text;
|
|
289
|
+
const basename = firstToken.slice(firstToken.lastIndexOf("/") + 1);
|
|
290
|
+
return leadingWs + basename + rest;
|
|
291
|
+
}
|
|
292
|
+
function stripLeadingBackslashEscape(text) {
|
|
293
|
+
return text.replace(/^(\s*)\\(?=[A-Za-z])/, "$1");
|
|
294
|
+
}
|
|
295
|
+
function stripEnvAssignments(text) {
|
|
296
|
+
return text.replace(/^\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)+/, "");
|
|
297
|
+
}
|
|
298
|
+
/** Strips one leading passthrough-wrapper command (e.g. `sudo`, `env FOO=1`) and its own flags, if present. */
|
|
299
|
+
function stripPassthroughPrefix(text) {
|
|
300
|
+
const trimmed = text.replace(/^\s+/, "");
|
|
301
|
+
const match = trimmed.match(/^(\S+)((?:\s+-\S+)*)\s+/);
|
|
302
|
+
if (!match)
|
|
303
|
+
return { stripped: text, changed: false };
|
|
304
|
+
const token = match[1];
|
|
305
|
+
const basename = token.includes("/") ? token.slice(token.lastIndexOf("/") + 1) : token;
|
|
306
|
+
if (!PASSTHROUGH_PREFIXES.has(basename.toLowerCase()))
|
|
307
|
+
return { stripped: text, changed: false };
|
|
308
|
+
return { stripped: trimmed.slice(match[0].length), changed: true };
|
|
309
|
+
}
|
|
310
|
+
/** Extracts the inner command line from a `bash -c "..."` / `sh -c '...'` style wrapper, if present. */
|
|
311
|
+
function extractShellDashC(text) {
|
|
312
|
+
const trimmed = text.trim();
|
|
313
|
+
const match = trimmed.match(/^(\S+)(?:\s+-\S+)*\s+-c\s+(['"])([\s\S]*)\2\s*$/);
|
|
314
|
+
if (!match)
|
|
315
|
+
return undefined;
|
|
316
|
+
const token = match[1];
|
|
317
|
+
const basename = token.includes("/") ? token.slice(token.lastIndexOf("/") + 1) : token;
|
|
318
|
+
if (!SHELL_C_WRAPPERS.has(basename.toLowerCase()))
|
|
319
|
+
return undefined;
|
|
320
|
+
return match[3];
|
|
321
|
+
}
|
|
322
|
+
/** Extracts the inner command line from an `eval "..."` / `eval '...'` wrapper, if present. */
|
|
323
|
+
function extractEvalArg(text) {
|
|
324
|
+
const match = text.trim().match(/^eval\s+(['"])([\s\S]*)\1\s*$/i);
|
|
325
|
+
return match ? match[2] : undefined;
|
|
326
|
+
}
|
|
327
|
+
/** Extracts the contents of every `$(...)` and `` `...` `` command substitution found anywhere in `text`. */
|
|
328
|
+
function extractSubstitutions(text) {
|
|
329
|
+
const results = [];
|
|
330
|
+
let i = 0;
|
|
331
|
+
while (i < text.length) {
|
|
332
|
+
if (text[i] === "$" && text[i + 1] === "(") {
|
|
333
|
+
let depth = 1;
|
|
334
|
+
let j = i + 2;
|
|
335
|
+
while (j < text.length && depth > 0) {
|
|
336
|
+
if (text[j] === "(")
|
|
337
|
+
depth++;
|
|
338
|
+
else if (text[j] === ")")
|
|
339
|
+
depth--;
|
|
340
|
+
j++;
|
|
341
|
+
}
|
|
342
|
+
results.push(text.slice(i + 2, depth === 0 ? j - 1 : j));
|
|
343
|
+
i = j;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
i++;
|
|
347
|
+
}
|
|
348
|
+
const backtickMatches = text.match(/`([^`]*)`/g);
|
|
349
|
+
if (backtickMatches) {
|
|
350
|
+
for (const m of backtickMatches)
|
|
351
|
+
results.push(m.slice(1, -1));
|
|
352
|
+
}
|
|
353
|
+
return results;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Returns the literal output of a simple `echo ...` command. This covers a
|
|
357
|
+
* substitution used as a command position, such as `$(echo rm -rf /)`, where
|
|
358
|
+
* the output is subsequently executed by the outer shell.
|
|
359
|
+
*/
|
|
360
|
+
function extractSimpleEchoOutput(text) {
|
|
361
|
+
const match = text.match(/^\s*echo\s+([^$`]+?)\s*$/i);
|
|
362
|
+
return match?.[1];
|
|
363
|
+
}
|
|
364
|
+
const MAX_DENY_CANDIDATES = 50;
|
|
365
|
+
const MAX_DENY_DEPTH = 4;
|
|
366
|
+
/**
|
|
367
|
+
* Paranoidly enumerates every independently-executed "piece" of `command` a
|
|
368
|
+
* `deny` rule should be checked against: the raw command, each chained
|
|
369
|
+
* segment, prefix/wrapper-stripped variants of each segment, and the bodies
|
|
370
|
+
* of any `bash -c` / `eval` / `$(...)` / backtick constructs — recursively,
|
|
371
|
+
* bounded so adversarial input can't cause unbounded work.
|
|
372
|
+
*/
|
|
373
|
+
function collectDenyCandidates(command) {
|
|
374
|
+
const seen = new Set();
|
|
375
|
+
const queue = [{ text: command, depth: 0 }];
|
|
376
|
+
while (queue.length > 0 && seen.size < MAX_DENY_CANDIDATES) {
|
|
377
|
+
const next = queue.shift();
|
|
378
|
+
if (!next)
|
|
379
|
+
break;
|
|
380
|
+
const { text, depth } = next;
|
|
381
|
+
if (seen.has(text))
|
|
382
|
+
continue;
|
|
383
|
+
seen.add(text);
|
|
384
|
+
if (depth >= MAX_DENY_DEPTH)
|
|
385
|
+
continue;
|
|
386
|
+
const enqueue = (candidate) => {
|
|
387
|
+
if (!seen.has(candidate) && seen.size + queue.length < MAX_DENY_CANDIDATES) {
|
|
388
|
+
queue.push({ text: candidate, depth: depth + 1 });
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const segments = splitChain(text).map((s) => s.text);
|
|
392
|
+
const pieces = segments.length > 1 ? segments : [text];
|
|
393
|
+
for (const seg of segments)
|
|
394
|
+
enqueue(seg);
|
|
395
|
+
for (const piece of pieces) {
|
|
396
|
+
let working = stripLeadingBackslashEscape(piece);
|
|
397
|
+
working = stripEnvAssignments(working);
|
|
398
|
+
for (let guard = 0; guard < 5; guard++) {
|
|
399
|
+
const { stripped, changed } = stripPassthroughPrefix(working);
|
|
400
|
+
if (!changed)
|
|
401
|
+
break;
|
|
402
|
+
working = stripped;
|
|
403
|
+
}
|
|
404
|
+
enqueue(working);
|
|
405
|
+
const basenameResolved = resolveBasenameOfFirstToken(working);
|
|
406
|
+
enqueue(basenameResolved);
|
|
407
|
+
const shellC = extractShellDashC(working) ?? extractShellDashC(basenameResolved);
|
|
408
|
+
if (shellC !== undefined)
|
|
409
|
+
enqueue(shellC);
|
|
410
|
+
const evalArg = extractEvalArg(working) ?? extractEvalArg(basenameResolved);
|
|
411
|
+
if (evalArg !== undefined)
|
|
412
|
+
enqueue(evalArg);
|
|
413
|
+
for (const sub of extractSubstitutions(piece)) {
|
|
414
|
+
enqueue(sub);
|
|
415
|
+
const echoOutput = extractSimpleEchoOutput(sub);
|
|
416
|
+
if (echoOutput !== undefined)
|
|
417
|
+
enqueue(echoOutput);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return [...seen];
|
|
422
|
+
}
|
|
423
|
+
function globToRegExp(pattern) {
|
|
424
|
+
let source = "";
|
|
425
|
+
for (const ch of pattern) {
|
|
426
|
+
if (ch === "*")
|
|
427
|
+
source += ".*";
|
|
428
|
+
else if (ch === "?")
|
|
429
|
+
source += ".";
|
|
430
|
+
else
|
|
431
|
+
source += ch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
432
|
+
}
|
|
433
|
+
return new RegExp(`^${source}$`, "is");
|
|
434
|
+
}
|
|
435
|
+
function matchDenyPattern(command, pattern) {
|
|
436
|
+
const regex = globToRegExp(normalizeForMatch(pattern));
|
|
437
|
+
return collectDenyCandidates(command).some((candidate) => regex.test(normalizeForMatch(candidate)));
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Strictly matches `command` against an `allow`/`approve` `pattern`: any
|
|
441
|
+
* dynamic/opaque construct disqualifies the match outright, and the command
|
|
442
|
+
* must have the same chain shape (segment count and operators) as the
|
|
443
|
+
* pattern, with every segment matching independently. This is what stops a
|
|
444
|
+
* rule like `{ pattern: "npm test*", action: "allow" }` from also
|
|
445
|
+
* authorizing `npm test; rm -rf /` or `` npm test `rm -rf /` ``.
|
|
446
|
+
*/
|
|
447
|
+
function matchAllowPattern(command, pattern) {
|
|
448
|
+
if (DANGEROUS_CONSTRUCT_RE.test(command))
|
|
449
|
+
return false;
|
|
450
|
+
const commandSegments = splitChain(command);
|
|
451
|
+
const patternSegments = splitChain(pattern);
|
|
452
|
+
if (commandSegments.length !== patternSegments.length)
|
|
453
|
+
return false;
|
|
454
|
+
for (let i = 0; i < commandSegments.length; i++) {
|
|
455
|
+
if (commandSegments[i].operator !== patternSegments[i].operator)
|
|
456
|
+
return false;
|
|
457
|
+
const cmdText = normalizeForMatch(commandSegments[i].text);
|
|
458
|
+
const cmdResolved = normalizeForMatch(resolveBasenameOfFirstToken(commandSegments[i].text));
|
|
459
|
+
const regex = globToRegExp(normalizeForMatch(patternSegments[i].text));
|
|
460
|
+
if (!regex.test(cmdText) && !regex.test(cmdResolved))
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
function matchCommandPattern(command, pattern, action) {
|
|
466
|
+
return action === "deny" ? matchDenyPattern(command, pattern) : matchAllowPattern(command, pattern);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Built-in danger filter backing `auto` mode. These are matched with the
|
|
470
|
+
* same paranoid strategy as `deny` rules (chain splitting, wrapper
|
|
471
|
+
* unwrapping, substitution extraction), so `echo hi && rm -rf /` or
|
|
472
|
+
* `bash -c "sudo dd ..."` still trip the filter.
|
|
473
|
+
*
|
|
474
|
+
* This is a *prompt* heuristic, not a security boundary: it decides which
|
|
475
|
+
* unmatched commands fall back to approval instead of auto-allow. It can
|
|
476
|
+
* never enumerate every destructive command — anything that must be hard
|
|
477
|
+
* blocked belongs in a `deny` rule in `permissions.yml`.
|
|
478
|
+
*/
|
|
479
|
+
export const DANGEROUS_COMMAND_PATTERNS = [
|
|
480
|
+
// recursive/forced deletion (flag clusters normalize to sorted letters,
|
|
481
|
+
// so `-rf`/`-fr` become `-fr` and are caught by the `-f*` prefix; bare
|
|
482
|
+
// `-r`/`-R` by the `-r*` prefix via case-insensitive matching)
|
|
483
|
+
"rm -r*",
|
|
484
|
+
"rm -f*",
|
|
485
|
+
// privilege escalation
|
|
486
|
+
"sudo *",
|
|
487
|
+
"doas *",
|
|
488
|
+
"su *",
|
|
489
|
+
// raw disk / filesystem surgery
|
|
490
|
+
"dd *",
|
|
491
|
+
"mkfs*",
|
|
492
|
+
// system state
|
|
493
|
+
"shutdown*",
|
|
494
|
+
"reboot*",
|
|
495
|
+
"halt*",
|
|
496
|
+
"poweroff*",
|
|
497
|
+
// blanket permission changes
|
|
498
|
+
"chmod 777 *",
|
|
499
|
+
"chmod -R *",
|
|
500
|
+
"chown -R *",
|
|
501
|
+
// outward-facing / history-rewriting git and publishing
|
|
502
|
+
"git push*",
|
|
503
|
+
"git reset --hard*",
|
|
504
|
+
"git clean*",
|
|
505
|
+
"npm publish*",
|
|
506
|
+
"yarn publish*",
|
|
507
|
+
"pnpm publish*",
|
|
508
|
+
// pipe-to-shell installers
|
|
509
|
+
"curl * | *",
|
|
510
|
+
"wget * | *",
|
|
511
|
+
// inline interpreter eval — the code payload is another language the gate
|
|
512
|
+
// cannot parse, so `python -c "os.system('rm -rf /')"` would otherwise
|
|
513
|
+
// sail through as "not shell-dangerous". Running a script *file*
|
|
514
|
+
// (`python script.py`) is deliberately NOT flagged: it is everyday dev
|
|
515
|
+
// work, and the gate cannot see file contents anyway (see the module doc
|
|
516
|
+
// on interpreter escape hatches).
|
|
517
|
+
"python* -c*",
|
|
518
|
+
"node -e*",
|
|
519
|
+
"node --eval*",
|
|
520
|
+
"node -p*",
|
|
521
|
+
"bun -e*",
|
|
522
|
+
"bun --eval*",
|
|
523
|
+
"deno eval*",
|
|
524
|
+
"ruby -e*",
|
|
525
|
+
"perl -e*",
|
|
526
|
+
"php -r*",
|
|
527
|
+
];
|
|
528
|
+
/**
|
|
529
|
+
* Returns the first built-in dangerous pattern the command matches, or
|
|
530
|
+
* `undefined` if the command passes the filter.
|
|
531
|
+
*/
|
|
532
|
+
export function findDangerousPattern(command) {
|
|
533
|
+
return DANGEROUS_COMMAND_PATTERNS.find((pattern) => matchDenyPattern(command, pattern));
|
|
534
|
+
}
|
|
535
|
+
/** Normalize a (possibly relative or absolute) path into a forward-slash path relative to `cwd`, for glob matching. */
|
|
536
|
+
function toMatchablePath(filePath, cwd) {
|
|
537
|
+
const resolved = isAbsolute(filePath) ? filePath : resolve(cwd, filePath);
|
|
538
|
+
const rel = relative(cwd, resolved);
|
|
539
|
+
return rel.split(sep).join("/");
|
|
540
|
+
}
|
|
541
|
+
/** Whether `filePath` (relative or absolute) resolves to a location inside `cwd`. */
|
|
542
|
+
function isWithinProject(filePath, cwd) {
|
|
543
|
+
const resolved = isAbsolute(filePath) ? filePath : resolve(cwd, filePath);
|
|
544
|
+
const rel = relative(cwd, resolved);
|
|
545
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* NOTE: this assumes the tool-call args carry a `command` string under the
|
|
549
|
+
* exact key `command`. If/when this gate is wired into actual tool
|
|
550
|
+
* dispatch, verify every gated tool's argument shape matches these
|
|
551
|
+
* hardcoded key names — a mismatch doesn't error, it just silently fails to
|
|
552
|
+
* match any `pattern`/`paths` rule and falls through to the (fail-safe)
|
|
553
|
+
* default decision. Not currently exploitable: nothing outside this module
|
|
554
|
+
* and its test calls `PermissionGate`/`loadRules` yet.
|
|
555
|
+
*/
|
|
556
|
+
function getCommandArg(args) {
|
|
557
|
+
return typeof args.command === "string" ? args.command : undefined;
|
|
558
|
+
}
|
|
559
|
+
/** Prefers `file_path` over `path` when both are present; see the note on `getCommandArg` above. */
|
|
560
|
+
function getPathArg(args) {
|
|
561
|
+
if (typeof args.file_path === "string")
|
|
562
|
+
return args.file_path;
|
|
563
|
+
if (typeof args.path === "string")
|
|
564
|
+
return args.path;
|
|
565
|
+
return undefined;
|
|
566
|
+
}
|
|
567
|
+
function describeMatch(rule) {
|
|
568
|
+
const parts = [`tool=${rule.tool}`];
|
|
569
|
+
if (rule.pattern !== undefined)
|
|
570
|
+
parts.push(`pattern=${JSON.stringify(rule.pattern)}`);
|
|
571
|
+
if (rule.paths !== undefined)
|
|
572
|
+
parts.push(`paths=${JSON.stringify(rule.paths)}`);
|
|
573
|
+
return `matched rule (${parts.join(", ")}) -> ${rule.action}`;
|
|
574
|
+
}
|
|
575
|
+
function ruleMatches(rule, toolName, args, cwd) {
|
|
576
|
+
if (rule.tool !== "*" && rule.tool.toLowerCase() !== toolName)
|
|
577
|
+
return false;
|
|
578
|
+
if (rule.pattern !== undefined) {
|
|
579
|
+
const command = getCommandArg(args);
|
|
580
|
+
if (command === undefined || !matchCommandPattern(command, rule.pattern, rule.action))
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
if (rule.paths !== undefined) {
|
|
584
|
+
const filePath = getPathArg(args);
|
|
585
|
+
if (filePath === undefined)
|
|
586
|
+
return false;
|
|
587
|
+
const matchable = toMatchablePath(filePath, cwd);
|
|
588
|
+
if (!rule.paths.some((pattern) => minimatch(matchable, pattern, { dot: true })))
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Evaluates tool calls against an ordered list of permission rules,
|
|
595
|
+
* returning a `deny` / `allow` / `approve` decision.
|
|
596
|
+
*/
|
|
597
|
+
export class PermissionGate {
|
|
598
|
+
constructor(rules = [], options = {}) {
|
|
599
|
+
this.rules = rules;
|
|
600
|
+
this.cwd = options.cwd ?? process.cwd();
|
|
601
|
+
this.mode = options.mode ?? "default";
|
|
602
|
+
}
|
|
603
|
+
/** Evaluate a tool call. `args` should carry `command` for bash, or `path`/`file_path` for read/write/edit. */
|
|
604
|
+
evaluate(toolName, args = {}) {
|
|
605
|
+
const normalizedTool = toolName.toLowerCase();
|
|
606
|
+
for (const rule of this.rules) {
|
|
607
|
+
if (ruleMatches(rule, normalizedTool, args, this.cwd)) {
|
|
608
|
+
return this.applyMode({ action: rule.action, reason: describeMatch(rule) });
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return this.applyMode(this.defaultDecision(normalizedTool, args));
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Applies the session mode to a decision. `deny` is never relaxed by any
|
|
615
|
+
* mode; `yolo` downgrades every `approve` to `allow`.
|
|
616
|
+
*/
|
|
617
|
+
applyMode(decision) {
|
|
618
|
+
if (this.mode === "yolo" && decision.action === "approve") {
|
|
619
|
+
return { action: "allow", reason: `yolo mode: auto-allowed (${decision.reason})` };
|
|
620
|
+
}
|
|
621
|
+
return decision;
|
|
622
|
+
}
|
|
623
|
+
defaultDecision(toolName, args) {
|
|
624
|
+
if (DEFAULT_ALLOWED_TOOLS.has(toolName)) {
|
|
625
|
+
return { action: "allow", reason: `no rule matched; "${toolName}" is allowed by default` };
|
|
626
|
+
}
|
|
627
|
+
if (toolName === "bash") {
|
|
628
|
+
if (this.mode === "auto") {
|
|
629
|
+
const command = getCommandArg(args);
|
|
630
|
+
if (command === undefined) {
|
|
631
|
+
return { action: "approve", reason: "auto mode: bash call without a command string requires approval" };
|
|
632
|
+
}
|
|
633
|
+
const dangerous = findDangerousPattern(command);
|
|
634
|
+
if (dangerous !== undefined) {
|
|
635
|
+
return {
|
|
636
|
+
action: "approve",
|
|
637
|
+
reason: `auto mode: command matched dangerous pattern ${JSON.stringify(dangerous)}, requires approval`,
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
return { action: "allow", reason: "auto mode: no rule matched and command passed the danger filter" };
|
|
641
|
+
}
|
|
642
|
+
return { action: "approve", reason: "no rule matched; bash commands require approval by default" };
|
|
643
|
+
}
|
|
644
|
+
if (PATH_SCOPED_TOOLS.has(toolName)) {
|
|
645
|
+
const filePath = getPathArg(args);
|
|
646
|
+
if (filePath !== undefined && isWithinProject(filePath, this.cwd)) {
|
|
647
|
+
return { action: "allow", reason: "no rule matched; allowed by default within the project" };
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
action: "approve",
|
|
651
|
+
reason: "no rule matched; path is outside the project (or missing), requires approval",
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
if (READ_ONLY_PATH_TOOLS.has(toolName)) {
|
|
655
|
+
// Unlike read/write/edit, these tools treat a missing `path` as the
|
|
656
|
+
// cwd, so an absent path arg is within the project by definition.
|
|
657
|
+
const filePath = getPathArg(args) ?? ".";
|
|
658
|
+
if (isWithinProject(filePath, this.cwd)) {
|
|
659
|
+
return { action: "allow", reason: "no rule matched; read-only tool allowed by default within the project" };
|
|
660
|
+
}
|
|
661
|
+
return {
|
|
662
|
+
action: "approve",
|
|
663
|
+
reason: "no rule matched; path is outside the project, requires approval",
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
return { action: "approve", reason: `no rule matched for tool "${toolName}"; defaults to approve` };
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
//# sourceMappingURL=permission-gate.js.map
|