import { tmpdir } from "node:os"; import type { AllowedPath } from "../../core/paths/path"; import type { ResolvedConfig } from "./types"; const builtinTempDirectories = [ ...new Set([tmpdir(), ...(process.platform === "win32" ? [] : ["/tmp"])]), ].map((path): AllowedPath => ({ kind: "directory", path })); export const DEFAULT_CONFIG: ResolvedConfig = { enabled: true, applyBuiltinDefaults: true, features: { policies: true, permissionGate: true, pathAccess: false, workspaceRoots: true, }, pathAccess: { mode: "ask", allowedPaths: [ { kind: "file", path: "/dev/null" }, ...builtinTempDirectories, ], }, workspaceRoots: { roots: [], }, audit: { enabled: true, path: "~/.pi/agent/guardrails-audit.jsonl", }, policies: { rules: [ { id: "secret-files", description: "Files containing secrets", patterns: [ { pattern: ".env" }, { pattern: ".env.local" }, { pattern: ".env.production" }, { pattern: ".env.prod" }, { pattern: ".dev.vars" }, ], allowedPatterns: [ { pattern: "*.example.env" }, { pattern: "*.sample.env" }, { pattern: "*.test.env" }, { pattern: ".env.example" }, { pattern: ".env.sample" }, { pattern: ".env.test" }, ], protection: "noAccess", onlyIfExists: true, allowSourcing: true, blockMessage: "Accessing {file} is not allowed. This file contains secrets. " + "You may load it with `source {file}` when a command needs its environment variables. " + "Explain to the user why you want to access this file, and if changes are needed ask the user to make them.", }, { id: "home-ssh", description: "SSH directory and keys", patterns: [ { pattern: "~/.ssh/**" }, { pattern: "~/.ssh/*_rsa" }, { pattern: "~/.ssh/*_ed25519" }, { pattern: "~/.ssh/*.pem" }, ], allowedPatterns: [{ pattern: "~/.ssh/*.pub" }], protection: "noAccess", onlyIfExists: true, blockMessage: "Accessing {file} is not allowed. This file is part of your SSH configuration and may contain private keys or sensitive host information.", }, { id: "home-config", description: "Sensitive user configuration directories", enabled: false, patterns: [ { pattern: "~/.config/gh/**" }, { pattern: "~/.config/gcloud/**" }, { pattern: "~/.config/op/**" }, { pattern: "~/.config/sops/**" }, ], protection: "noAccess", onlyIfExists: true, blockMessage: "Accessing {file} is not allowed. This file is in a sensitive user configuration directory and may contain credentials or tokens.", }, { id: "home-gpg", description: "GPG keys and configuration", enabled: false, patterns: [ { pattern: "~/.gnupg/**" }, { pattern: "~/*.gpg" }, { pattern: "~/.gpg-agent.conf" }, ], protection: "noAccess", onlyIfExists: true, blockMessage: "Accessing {file} is not allowed. This file is part of your GPG configuration and may contain private keys or trust settings.", }, { id: "pi-config", description: "Pi and Guardrails configuration (self-protection)", patterns: [ { pattern: "~/.pi/agent/settings.json" }, { pattern: "~/.pi/agent/extensions/**" }, { pattern: ".pi/settings.json" }, { pattern: ".pi/extensions/**" }, ], protection: "readOnly", onlyIfExists: true, blockMessage: "Writing to {file} is not allowed. Pi and Guardrails configuration is protected from agent modification. " + "Ask the user to change settings, e.g. via /guardrails:settings.", }, { id: "pi-credentials", description: "Pi provider credentials", patterns: [{ pattern: "~/.pi/agent/auth.json" }], protection: "noAccess", onlyIfExists: true, blockMessage: "Accessing {file} is not allowed. This file contains provider API keys.", }, { id: "git-hooks", description: "Git hooks (persistence vector)", patterns: [{ pattern: ".git/hooks/**" }], protection: "readOnly", onlyIfExists: true, blockMessage: "Writing to {file} is not allowed. Git hooks execute on every git operation; ask the user to change them.", }, { id: "shell-rc", description: "Shell startup files (persistence vector)", patterns: [ { pattern: "~/.zshrc" }, { pattern: "~/.zprofile" }, { pattern: "~/.zshenv" }, { pattern: "~/.bashrc" }, { pattern: "~/.bash_profile" }, { pattern: "~/.profile" }, { pattern: "~/.config/fish/**" }, ], protection: "readOnly", onlyIfExists: true, blockMessage: "Writing to {file} is not allowed. Shell startup files run in every new terminal; ask the user to make changes.", }, ], }, permissionGate: { patterns: [ { pattern: "rm -rf", description: "recursive force delete" }, { pattern: "sudo", description: "superuser command" }, { pattern: "dd of=", description: "disk write operation" }, { pattern: "mkfs.", description: "filesystem format" }, { pattern: "chmod -R 777", description: "insecure recursive permissions", }, { pattern: "chown -R", description: "recursive ownership change" }, { pattern: "doas", description: "privileged command execution" }, { pattern: "pkexec", description: "privileged command execution" }, { pattern: "shred", description: "secure file overwrite" }, { pattern: "wipefs", description: "filesystem signature wipe" }, { pattern: "blkdiscard", description: "block device discard" }, { pattern: "fdisk", description: "disk partitioning" }, { pattern: "parted", description: "disk partitioning" }, { pattern: "docker run --privileged", description: "container with privileged mode", }, { pattern: "git push --force", description: "force push rewrites remote history", }, { pattern: "git reset --hard", description: "hard reset discards uncommitted changes", }, { pattern: "git clean -f", description: "removes untracked files" }, { pattern: "git filter-branch", description: "rewrites git history" }, { pattern: "git branch -D", description: "force branch deletion" }, { pattern: "git checkout", description: "checkout may overwrite uncommitted changes", }, { pattern: "git restore", description: "restore discards working tree changes", }, { pattern: "git stash drop", description: "deletes stashed changes" }, { pattern: "crontab", description: "modifies scheduled tasks" }, { pattern: "launchctl load", description: "registers a persistent launch job", }, { pattern: "systemctl enable", description: "enables a persistent service", }, { pattern: "npx --yes", description: "runs a remote package without confirmation", }, { pattern: "pip install http", description: "installs a package from a URL", }, { pattern: "uv add", description: "adds a project dependency" }, { pattern: "scp", description: "copies files to a remote host" }, { pattern: "gh gist create", description: "publishes a gist" }, ], useBuiltinMatchers: true, requireConfirmation: true, allowedPatterns: [], autoDenyPatterns: [], }, };