Permissions¶
asksh checks layered TOML rules in permissions.toml and runs a Bash AST preflight analyzer before executing tool calls or runbook steps.
File lookup order¶
asksh searches for permission files from deepest directory to shallowest:
<cwd>/.asksh/permissions.toml- Each parent directory's
.asksh/permissions.tomlwalking up to/ - Global
~/.config/asksh/permissions.toml(or$ASKSH_CONFIG_DIR/permissions.toml)
The first file containing a matching rule decides the outcome.
Rule precedence¶
Each file can define [permissions] and optional [targets.<env>] sections:
[permissions]
allow = [
"ShellHistory",
"CommandHelp(git*)",
"Read(**/*.md)",
"Shell(git status)",
"Shell(git diff *)",
"MCP(greendale/*)",
]
deny = [
"Read(.env)",
"Shell(rm)",
"MCP(greendale/drop_table)",
]
[targets.prod]
ask = ["Shell(*)"]
deny = ["Write(*)"]
- When
--target ...?env=<env>or/target ...?env=<env>is active,[targets.<env>]is evaluated before[permissions]in the same file. - Within a section, precedence is
ask > deny > allow. - If no rule matches in any file, the default is
Ask(except staticLoadSkillcalls without dynamic embedded commands, which default toAllow).
Rule syntax¶
Rules follow <ToolKind> or <ToolKind>(<scope>):
| Rule kind | Governed tools | Scope matching |
|---|---|---|
Read / Read(<glob-or-path>) |
read_file, grep_files, glob_files |
Doublestar globs, basename, relative-to-CWD, ~/$VAR expansion, and symlink resolution |
Write / Write(<glob-or-path>) |
edit_file, write_file |
Same file matching as Read; any Write rule also grants Read for matching paths |
Shell / Shell(<pattern>) |
execute_shell_command, runbook steps |
Parsed via Bash AST into subcommands and redirections (see below) |
ShellHistory |
shell_history |
Unscoped |
CommandHelp / CommandHelp(<glob>) |
command_help |
Glob matched against normalized command tokens (for example CommandHelp(git *)) |
LoadSkill |
load_skill |
Unscoped |
MCP / MCP(<server>) / MCP(<server>/<tool>) |
mcp__<server>__<tool> |
Supports * wildcards on <server> and <tool> |
There are no separate Grep, Glob, or Edit rule kinds; use Read and Write.
How Shell rules match¶
asksh parses shell commands using mvdan.cc/sh/v3 into subcommands and redirections:
allowrules: every subcommand in a pipeline or list must be covered. Opaque or dynamic constructs (such aseval, dynamic command names or redirections, or parse failures) are never allowed unless you specify bareShellorShell(*). Patterns without*require an exact word match (Shell(git status)matchesgit statusonly); a trailing*matches by word prefix (Shell(git *)matchesgitandgit status, notgitk).denyandaskrules: match if any subcommand matches. Patterns without*match as a word prefix, soShell(rm)matchesrm fooas well asrm.
AST preflight risk assessment¶
asksh inspects shell commands with permissions.AnalyzeCommand (internal/permissions/preflight.go) before suggesting or executing them. The analyzer unwraps wrappers (sudo, env, command, nohup, nice, time, xargs), recurses into sh -c / bash -lc up to depth 4, inspects $(...) and <(...), and expands globs for rm, mv, chmod, and chown (up to 50 paths).
Detected risk findings raise the command's risk level:
- High risk:
eval,mkfs/mkfs.*, downloader (curl,wget,fetch,xh,http,https) piped or process-substituted into a shell,rm -rf,rm -r,rm/rm -fon critical paths (/,/*,~,$HOME,*,.,.., system directories, or critical dotfiles),dd of=/dev/..., recursivechmod 777orchmod 777on critical paths,git reset --hard,git cleanwith-fand-d/-x/-X,git push -f/--force/+ref,kubectl delete(unless--dry-run),docker system prune,docker rm -f, and redirection overwrites to system paths or critical dotfiles (.bashrc,.zshrc,.profile,.env,.netrc,.gitconfig,.ssh,.gnupg,.aws,.kube,.asksh, and related shell rc files). - Medium risk:
sudo, opaque or unparseable commands, non-downloader pipe to shell,rm -foutside/tmp/and/var/tmp/,ddwriting to a non-device path, non-criticalchmod 777,git clean -f,git push --force-with-lease, and redirection overwrites to non-critical dotfiles.