@agent-corpus/policy-manager 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/evidence.js +5 -3
- package/dist/flow.d.ts +9 -0
- package/dist/flow.js +698 -0
- package/dist/merged.js +1 -1
- package/dist/permissive.d.ts +15 -6
- package/dist/permissive.js +247 -63
- package/dist/script.d.ts +101 -0
- package/dist/script.js +912 -0
- package/dist/shell.d.ts +7 -0
- package/dist/shell.js +82 -191
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,7 +103,17 @@ policy-manager profile install policy.json # writes ~/.config/agent-corpus/pol
|
|
|
103
103
|
|
|
104
104
|
The service reads the profile only from that user directory (`$XDG_CONFIG_HOME` honored). It must be a regular, non-symlink file owned by the user, not group/world writable, and outside every Git checkout, so an agent cannot rewrite its own rules from a worktree. On Windows, POSIX owner and mode bits do not exist, so only the regular-file, non-symlink and outside-Git checks apply and the user-profile ACL is the trust boundary. `cd <literal>` is tracked, and each later command is judged in every directory it could run in. Git long-option abbreviations are treated as the full option. An invalid or untrusted profile logs `profile ... invalid-using-strict` and the session stays strict. Each session records the profile mode and SHA-256 digest in `audit.jsonl`.
|
|
105
105
|
|
|
106
|
-
`permissive` approves compound commands (`;`, `&&`, `||`, `|`, quotes, redirects, `VAR=x` prefixes) when every simple command is acceptable, and approves unknown executables and interpreters with inline code. It still sends these to a human: deletion (`rm`, `find -delete`, `xargs rm`), `sudo`, `git reset --hard`, `git clean`, forced or mirror pushes, discarding checkouts and restores, stash and reflog destruction, `gh` deletions and security endpoints, cloud deletion and credential retrieval, infrastructure destroy, `npm publish`, destructive HTTP verbs, piping into a shell,
|
|
106
|
+
`permissive` approves compound commands (`;`, `&&`, `||`, `|`, quotes, redirects, `VAR=x` prefixes) when every simple command is acceptable, and approves unknown executables and interpreters with inline code. It still sends these to a human: deletion (`rm`, `find -delete`, `xargs rm`), `sudo`, `git reset --hard`, `git clean`, forced or mirror pushes, discarding checkouts and restores, stash and reflog destruction, `gh` deletions and security endpoints, cloud deletion and credential retrieval, infrastructure destroy, `npm publish`, destructive HTTP verbs, piping into a shell, ssh and database clients, builtins that run a string later (`eval`, `source`, `trap`, `alias`), printing the environment, writes outside linked feature worktrees and `scratchRoots`, and protected or credential paths. `humanPatterns` adds organization-specific expressions.
|
|
107
|
+
|
|
108
|
+
#### Shell syntax in permissive mode
|
|
109
|
+
|
|
110
|
+
Every command that could run is judged, not only the first. Understood: `;`, newlines, `&&`, `||`, `|`, `&`, comments, quoting and escapes, line continuation, redirections (including `&>`, `|&`, here-strings and quoted-delimiter heredocs), `( ... )`, `{ ...; }`, `for`, `while`, `until`, `if`, `case`, `$(...)`, backticks and `<(...)`.
|
|
111
|
+
|
|
112
|
+
- **Variables.** `NAME=value`, `export NAME=value` and `for NAME in a b c` give a variable a known value; the command is then judged with the value substituted, in every directory and for every value it could take. A variable assigned in only some branches, in a loop, or from a command, glob or `read` has an unknown value, as does any environment variable the script did not assign. An unknown value is accepted only as an argument to `echo`, `printf` with string conversions, `test`/`[` without numeric tests, `true`, `false`, `basename` and `dirname`, and as the value of a commit or PR message option (`git commit -m "$(...)"`, `gh pr create --body "$(...)"`). It is never a program, option, path, `cd` target or redirection target. Environment variables other than a short list (`PWD`, `USER`, `TMPDIR`, ...) need a human, because they can hold credentials.
|
|
113
|
+
- **Command substitution** and process substitution run first: the inner command is judged with the same rules.
|
|
114
|
+
- **Heredocs.** A quoted delimiter (`<<'EOF'`) is literal text. An unquoted delimiter is accepted only when the body has no `$`, backtick or backslash. A shell fed by a heredoc (`bash <<'EOF'`) has its body judged as a script. An interpreter fed by a heredoc or `-c` is treated like inline code: the code is scanned for file deletion, process creation, string evaluation and protected paths, and anything flagged goes to a human; code piped in from elsewhere always does.
|
|
115
|
+
- **Compound commands.** Branches are judged on copies of the state and merged; a loop's assigned variables are unknown inside it and afterwards, and a `cd` inside a loop or pipeline needs a human.
|
|
116
|
+
- **Still sent to a human:** brace expansion, arithmetic (`$((`, `$[`, `(( ))`), `${X:-y}` and other parameter forms, `$'...'`, function definitions, unquoted heredocs whose body expands, and scripts that expand to more than a few hundred commands. `cloudWrites: "allow"` also approves non-destructive cloud changes.
|
|
107
117
|
|
|
108
118
|
Measure a profile against real usage with `policy-manager replay ~/.claude/projects --profile policy.json`: it replays the Bash commands recorded in Claude Code transcripts through the evaluator (nothing is executed) and prints the approval rate with and without the profile, plus the most common reasons that still need a human. Reports include short command excerpts, so keep them local.
|
|
109
119
|
|
package/dist/evidence.js
CHANGED
|
@@ -24,10 +24,12 @@ export function inside(root, path) {
|
|
|
24
24
|
const rel = relative(root, path);
|
|
25
25
|
return rel === "" || (!isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`));
|
|
26
26
|
}
|
|
27
|
+
const CREDENTIAL_CONFIG_DIRS = /(?:^|[\\/])\.config[\\/](?:gh|gcloud|op|hub)(?:[\\/]|$)/i;
|
|
27
28
|
export function sensitive(path) {
|
|
28
|
-
return path
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
return (CREDENTIAL_CONFIG_DIRS.test(path) ||
|
|
30
|
+
path
|
|
31
|
+
.split(/[\\/]/)
|
|
32
|
+
.some((part) => /^(?:\.git|\.env(?:\..*)?|\.ssh|\.aws|\.azure|\.gcloud|\.docker|\.gnupg|\.password-store|\.git-credentials|\.vault-token|\.pgpass|\.my\.cnf|\.pypirc|\.npmrc|\.netrc|\.kube|credentials?|secrets?|id_rsa|id_ed25519|id_ecdsa|kubeconfig|terraform\.tfstate(?:\..*)?|.*\.(?:pem|key|pfx|p12))$/i.test(part)));
|
|
31
33
|
}
|
|
32
34
|
export function protectedPath(path) {
|
|
33
35
|
return path
|
package/dist/flow.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Profile } from "./profile.js";
|
|
2
|
+
import type { Decision, Request } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Evaluates a compound command. `cd <literal>` is tracked: every later command is judged in each
|
|
5
|
+
* directory it could run in (before and after the `cd`, since `cd x || ...` may fail), so a command
|
|
6
|
+
* that only looks safe relative to the starting directory cannot hide behind a `cd`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function commandDecision(request: Request, command: string, profile: Profile, depth?: number, start?: string[]): Decision;
|
|
9
|
+
//# sourceMappingURL=flow.d.ts.map
|