@agent-corpus/policy-manager 0.1.0 → 0.2.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/README.md +29 -0
- package/dist/audit.d.ts +1 -0
- package/dist/audit.js +5 -2
- package/dist/cli.js +47 -3
- package/dist/evidence.d.ts +7 -0
- package/dist/evidence.js +33 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/merged.d.ts +14 -0
- package/dist/merged.js +96 -0
- package/dist/permissive.d.ts +23 -0
- package/dist/permissive.js +491 -0
- package/dist/policy.d.ts +5 -2
- package/dist/policy.js +22 -9
- package/dist/profile.d.ts +24 -0
- package/dist/profile.js +113 -0
- package/dist/replay.d.ts +18 -0
- package/dist/replay.js +81 -0
- package/dist/service.d.ts +7 -0
- package/dist/service.js +42 -3
- package/dist/session.d.ts +3 -1
- package/dist/session.js +6 -3
- package/dist/shell.d.ts +13 -0
- package/dist/shell.js +201 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,6 +82,35 @@ Categories are `code-read`, `worktree-write`, `cloud-read`, `git-read`, `impactf
|
|
|
82
82
|
|
|
83
83
|
These are approval recommendations, not a sandbox. Trusted local executables and their configuration remain part of the host's trust boundary. Hooks cannot observe every hosted tool or prevent arbitrary same-user processes from changing files. Recheck path evidence on every request; filesystem races still require host enforcement.
|
|
84
84
|
|
|
85
|
+
## Policy profiles
|
|
86
|
+
|
|
87
|
+
Without a profile the engine is strict (everything above). An organization can install one profile file that widens automatic approval without changing the checks themselves:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"version": 1,
|
|
92
|
+
"mode": "permissive",
|
|
93
|
+
"cloudWrites": "human",
|
|
94
|
+
"humanPatterns": ["^npm install"],
|
|
95
|
+
"scratchRoots": ["/tmp"]
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
policy-manager profile validate policy.json
|
|
101
|
+
policy-manager profile install policy.json # writes ~/.config/agent-corpus/policy-manager/policy.json
|
|
102
|
+
```
|
|
103
|
+
|
|
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
|
+
|
|
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, expansions and subshells, writes outside linked feature worktrees and `scratchRoots`, and protected or credential paths. `humanPatterns` adds organization-specific expressions. `cloudWrites: "allow"` also approves non-destructive cloud changes.
|
|
107
|
+
|
|
108
|
+
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
|
+
|
|
110
|
+
Protected names (`.claude`, `.agent-config`, `AGENTS.md`, ...) are judged relative to the repository root, so a linked worktree under `<repo>/.claude/worktrees/<name>` is ordinary code while `<worktree>/.claude/settings.json` stays protected. `git config` is limited to a short allowlist of local, non-executable keys; hooks, aliases, credential helpers, URLs and `--global` always need a human. Read-only cloud verbs (`list`, `show`, `describe`, `get-*`) are approved beyond the exact catalog unless the arguments name credentials or override the endpoint.
|
|
111
|
+
|
|
112
|
+
Deleting a branch is automatic only when it is already merged into `origin/main` (or `master`): reachable from it, or patch-equivalent to a squash or rebase merge. Remote deletion also needs `origin` and a `git ls-remote` tip that matches the fetched tracking ref, so unfetched commits block it. Evidence uses the locally fetched default branch; fetch first for very recent merges.
|
|
113
|
+
|
|
85
114
|
## Service, cache, and logs
|
|
86
115
|
|
|
87
116
|
The service uses a Unix socket on macOS/Linux and a named pipe on Windows. A random session token authenticates local requests. Files use owner-only modes on Unix. On Windows, the operating system's temporary-directory ACL is the access boundary; Unix modes do not establish Windows ACL isolation. Other processes running as the same user are outside this boundary.
|
package/dist/audit.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Request } from "./types.js";
|
|
2
|
+
export declare function sessionDirectoryPath(harness: string, sessionId: string): string;
|
|
2
3
|
export declare function sessionDirectory(harness: string, sessionId: string): string;
|
|
3
4
|
export declare function sessionToken(directory: string): string;
|
|
4
5
|
export declare function audit(directory: string, event: Record<string, unknown>): void;
|
package/dist/audit.js
CHANGED
|
@@ -6,10 +6,13 @@ import { AuditLog } from "@agent-corpus/audit-log";
|
|
|
6
6
|
import { hash, words } from "./policy.js";
|
|
7
7
|
const vocabulary = new Set("git az aws gcloud cat rm terraform resource group network monitor servicebus queue topic storage blob webapp appservice containerapp vm disk ec2 rds s3api cloudformation logs cloudwatch sqs sns ecs eks compute instances projects container run sql pubsub logging monitoring log-analytics workspace boards work-item account list show query create update delete destroy purge status diff log fetch origin branch worktree add describe-instances describe-volumes describe-stacks".split(" "));
|
|
8
8
|
const tools = new Set("Read Write Edit view create edit Bash bash powershell exec_command apply_patch shell read_file write_file".split(" "));
|
|
9
|
-
export function
|
|
9
|
+
export function sessionDirectoryPath(harness, sessionId) {
|
|
10
10
|
if (!sessionId || !["claude", "codex", "copilot"].includes(harness))
|
|
11
11
|
throw new Error("A harness and session ID are required");
|
|
12
|
-
|
|
12
|
+
return join(tmpdir(), `acp-${process.getuid?.() ?? "user"}-${hash([harness, sessionId]).slice(0, 24)}`);
|
|
13
|
+
}
|
|
14
|
+
export function sessionDirectory(harness, sessionId) {
|
|
15
|
+
const path = sessionDirectoryPath(harness, sessionId);
|
|
13
16
|
try {
|
|
14
17
|
mkdirSync(path, { mode: 0o700 });
|
|
15
18
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { parseArgs } from "node:util";
|
|
5
6
|
import { executionReport, hookResponse, normalize } from "./adapters.js";
|
|
6
7
|
import { hookConfig } from "./config.js";
|
|
7
|
-
import {
|
|
8
|
+
import { defaultProfilePath, loadProfile, parseProfile } from "./profile.js";
|
|
9
|
+
import { replayTranscripts } from "./replay.js";
|
|
10
|
+
import { send, serve, start, stop } from "./service.js";
|
|
8
11
|
import { SetupError, setupHook } from "./setup.js";
|
|
9
12
|
const usage = `policy-manager usage [--json]
|
|
10
13
|
policy-manager hook <claude|codex|copilot> <SessionStart|PreToolUse|PermissionRequest|PostToolUse|PostToolUseFailure|SessionEnd>
|
|
@@ -14,6 +17,9 @@ policy-manager record <claude|codex|copilot> <session-id> # host-reported huma
|
|
|
14
17
|
policy-manager setup-hook <claude|codex|copilot> [--dry-run] [--config-dir <harness-config-directory>]
|
|
15
18
|
policy-manager setup-hook-claude|setup-hook-codex|setup-hook-copilot [--dry-run] [--config-dir <directory>]
|
|
16
19
|
policy-manager config <claude|codex|copilot> <absolute-installed-cli-path>
|
|
20
|
+
policy-manager profile validate <file> # check a policy profile without installing it
|
|
21
|
+
policy-manager profile install <file> # install it to the user config directory outside Git
|
|
22
|
+
policy-manager replay <transcript-dir-or-file...> [--profile <file>] [--files <n>] # approval rate over recorded Bash commands; nothing is executed
|
|
17
23
|
policy-manager stop <claude|codex|copilot> <session-id>
|
|
18
24
|
A per-session background service checks policy and writes private temporary audit.jsonl logs.
|
|
19
25
|
AI classification comes from the session's policy-manager agent, never an external API.
|
|
@@ -52,6 +58,44 @@ try {
|
|
|
52
58
|
}
|
|
53
59
|
else if (action === "config")
|
|
54
60
|
console.log(JSON.stringify(hookConfig(harness, phase ?? ""), null, 2));
|
|
61
|
+
else if (action === "profile" &&
|
|
62
|
+
(harnessArg === "validate" || harnessArg === "install") &&
|
|
63
|
+
phase) {
|
|
64
|
+
const profile = parseProfile(readFileSync(phase, "utf8"));
|
|
65
|
+
const summary = {
|
|
66
|
+
mode: profile.mode,
|
|
67
|
+
cloudWrites: profile.cloudWrites,
|
|
68
|
+
digest: profile.digest,
|
|
69
|
+
};
|
|
70
|
+
if (harnessArg === "install") {
|
|
71
|
+
const target = defaultProfilePath();
|
|
72
|
+
mkdirSync(dirname(target), { recursive: true, mode: 0o700 });
|
|
73
|
+
const temporary = `${target}.${process.pid}.tmp`;
|
|
74
|
+
writeFileSync(temporary, readFileSync(phase, "utf8"), { mode: 0o600 });
|
|
75
|
+
renameSync(temporary, target);
|
|
76
|
+
console.log(JSON.stringify({ installed: target, ...summary }));
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
console.log(JSON.stringify({ valid: true, ...summary }));
|
|
80
|
+
}
|
|
81
|
+
else if (action === "replay") {
|
|
82
|
+
const { values, positionals } = parseArgs({
|
|
83
|
+
args: args.slice(1),
|
|
84
|
+
options: { profile: { type: "string" }, files: { type: "string" } },
|
|
85
|
+
allowPositionals: true,
|
|
86
|
+
});
|
|
87
|
+
const profile = values.profile
|
|
88
|
+
? parseProfile(readFileSync(values.profile, "utf8"))
|
|
89
|
+
: loadProfile();
|
|
90
|
+
const report = replayTranscripts(positionals, profile, Number(values.files ?? 50));
|
|
91
|
+
const pct = (n) => `${((100 * n) / Math.max(report.commands, 1)).toFixed(1)}%`;
|
|
92
|
+
console.log(`${report.commands} unique commands; approved ${pct(report.approved)} (strict ${pct(report.strictApproved)})`);
|
|
93
|
+
for (const row of report.reasons.slice(0, 15)) {
|
|
94
|
+
console.log(`${row.count}\t${row.reason}`);
|
|
95
|
+
for (const example of row.examples)
|
|
96
|
+
console.log(`\t ${example}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
55
99
|
else if (action === "serve")
|
|
56
100
|
await serve(harness, phase ?? "");
|
|
57
101
|
else if (action === "stop")
|
|
@@ -70,7 +114,7 @@ try {
|
|
|
70
114
|
const payload = await stdin();
|
|
71
115
|
const request = normalize(harness, payload);
|
|
72
116
|
if (phase === "SessionEnd") {
|
|
73
|
-
await
|
|
117
|
+
await stop(harness, request.sessionId);
|
|
74
118
|
console.log("{}");
|
|
75
119
|
}
|
|
76
120
|
else {
|
package/dist/evidence.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ export declare function canonical(path: string): string;
|
|
|
3
3
|
export declare function inside(root: string, path: string): boolean;
|
|
4
4
|
export declare function sensitive(path: string): boolean;
|
|
5
5
|
export declare function protectedPath(path: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Protected names (.claude, .agent-config, AGENTS.md ...) guard a repository's own configuration,
|
|
8
|
+
* so they are judged relative to the Git top level. A linked worktree that lives under
|
|
9
|
+
* `<repo>/.claude/worktrees/<name>` is ordinary code, while `<worktree>/.claude/settings.json`
|
|
10
|
+
* stays protected.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isProtectedPath(path: string): boolean;
|
|
6
13
|
export declare function pathEvidence(cwd: string, input: string, write: boolean): {
|
|
7
14
|
allowed: boolean;
|
|
8
15
|
category: "code-read" | "worktree-write" | "sensitive";
|
package/dist/evidence.js
CHANGED
|
@@ -11,8 +11,10 @@ export function git(cwd, args) {
|
|
|
11
11
|
}).trim();
|
|
12
12
|
}
|
|
13
13
|
export function canonical(path) {
|
|
14
|
+
// Native resolution expands Windows 8.3 aliases as well as symlinks, so
|
|
15
|
+
// paths supplied by Node and Git describe the same repository boundaries.
|
|
14
16
|
if (existsSync(path))
|
|
15
|
-
return realpathSync(path);
|
|
17
|
+
return realpathSync.native(path);
|
|
16
18
|
const parent = dirname(path);
|
|
17
19
|
if (parent === path)
|
|
18
20
|
throw new Error("Cannot resolve path");
|
|
@@ -32,13 +34,42 @@ export function protectedPath(path) {
|
|
|
32
34
|
.split(/[\\/]/)
|
|
33
35
|
.some((part) => /^(?:\.agent-config|\.local|\.codex|\.claude|\.agents|AGENTS\.md|CLAUDE\.md|\.github)$/i.test(part));
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Protected names (.claude, .agent-config, AGENTS.md ...) guard a repository's own configuration,
|
|
39
|
+
* so they are judged relative to the Git top level. A linked worktree that lives under
|
|
40
|
+
* `<repo>/.claude/worktrees/<name>` is ordinary code, while `<worktree>/.claude/settings.json`
|
|
41
|
+
* stays protected.
|
|
42
|
+
*/
|
|
43
|
+
export function isProtectedPath(path) {
|
|
44
|
+
try {
|
|
45
|
+
let parent = existsSync(path) && statSync(path).isDirectory() ? path : dirname(path);
|
|
46
|
+
while (!existsSync(parent))
|
|
47
|
+
parent = dirname(parent);
|
|
48
|
+
const root = canonical(git(parent, ["rev-parse", "--show-toplevel"]));
|
|
49
|
+
if (protectedPath(relative(root, canonical(path))))
|
|
50
|
+
return true;
|
|
51
|
+
// A protected name that is a symlink (`.claude -> config`) vanishes once the path is resolved,
|
|
52
|
+
// so also judge the path as written, relative to the checkout it lives in.
|
|
53
|
+
const written = resolve(path);
|
|
54
|
+
let ancestor = dirname(written);
|
|
55
|
+
while (ancestor !== dirname(ancestor)) {
|
|
56
|
+
if (existsSync(ancestor) && canonical(ancestor) === root)
|
|
57
|
+
return protectedPath(relative(ancestor, written));
|
|
58
|
+
ancestor = dirname(ancestor);
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return protectedPath(path);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
35
66
|
export function pathEvidence(cwd, input, write) {
|
|
36
67
|
try {
|
|
37
68
|
const lexical = resolve(cwd, input);
|
|
38
69
|
const path = canonical(lexical);
|
|
39
70
|
if (sensitive(path) ||
|
|
40
71
|
sensitive(lexical) ||
|
|
41
|
-
(write && (
|
|
72
|
+
(write && (isProtectedPath(path) || isProtectedPath(lexical))))
|
|
42
73
|
return {
|
|
43
74
|
allowed: false,
|
|
44
75
|
category: "sensitive",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
export { executionReport, hookResponse, normalize } from "./adapters.js";
|
|
2
2
|
export { branchEvidence, pathEvidence } from "./evidence.js";
|
|
3
|
+
export { mergedEvidence } from "./merged.js";
|
|
3
4
|
export { evaluate, hash, words } from "./policy.js";
|
|
5
|
+
export type { Profile } from "./profile.js";
|
|
6
|
+
export { defaultProfilePath, loadProfile, ProfileError, parseProfile, strictProfile, } from "./profile.js";
|
|
7
|
+
export type { ReplayReport } from "./replay.js";
|
|
8
|
+
export { replayTranscripts } from "./replay.js";
|
|
4
9
|
export { PolicySession } from "./session.js";
|
|
5
10
|
export type { SetupOptions, SetupResult } from "./setup.js";
|
|
6
11
|
export { SetupError, setupHook } from "./setup.js";
|
|
12
|
+
export { parseShell } from "./shell.js";
|
|
7
13
|
export type { Category, Classification, Decision, OutcomeReport, Request } from "./types.js";
|
|
8
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { executionReport, hookResponse, normalize } from "./adapters.js";
|
|
2
2
|
export { branchEvidence, pathEvidence } from "./evidence.js";
|
|
3
|
+
export { mergedEvidence } from "./merged.js";
|
|
3
4
|
export { evaluate, hash, words } from "./policy.js";
|
|
5
|
+
export { defaultProfilePath, loadProfile, ProfileError, parseProfile, strictProfile, } from "./profile.js";
|
|
6
|
+
export { replayTranscripts } from "./replay.js";
|
|
4
7
|
export { PolicySession } from "./session.js";
|
|
5
8
|
export { SetupError, setupHook } from "./setup.js";
|
|
9
|
+
export { parseShell } from "./shell.js";
|
|
6
10
|
//# sourceMappingURL=index.js.map
|
package/dist/merged.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface MergedEvidence {
|
|
2
|
+
merged: boolean;
|
|
3
|
+
how: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Decides whether every change on `ref` already reached origin's default branch, either by
|
|
7
|
+
* ancestry (merge or fast-forward) or by squash/rebase merge (patch-equivalence of the whole
|
|
8
|
+
* branch). Evidence uses the locally fetched origin/main, so stale fetches can only make the
|
|
9
|
+
* answer more conservative for new work and less accurate for very recent merges.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergedEvidence(cwd: string, ref: string): MergedEvidence;
|
|
12
|
+
/** The remote tip must match the fetched tracking ref, or a delete could discard unseen commits. */
|
|
13
|
+
export declare function remoteTipMatches(cwd: string, branch: string): boolean;
|
|
14
|
+
//# sourceMappingURL=merged.d.ts.map
|
package/dist/merged.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { git } from "./evidence.js";
|
|
3
|
+
const BRANCH_NAME = /^[a-zA-Z0-9][a-zA-Z0-9/_.-]*$/;
|
|
4
|
+
function target(cwd) {
|
|
5
|
+
for (const name of ["main", "master"]) {
|
|
6
|
+
try {
|
|
7
|
+
git(cwd, ["rev-parse", "--verify", "--quiet", `refs/remotes/origin/${name}^{commit}`]);
|
|
8
|
+
return `refs/remotes/origin/${name}`;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
/* try the next default branch */
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decides whether every change on `ref` already reached origin's default branch, either by
|
|
18
|
+
* ancestry (merge or fast-forward) or by squash/rebase merge (patch-equivalence of the whole
|
|
19
|
+
* branch). Evidence uses the locally fetched origin/main, so stale fetches can only make the
|
|
20
|
+
* answer more conservative for new work and less accurate for very recent merges.
|
|
21
|
+
*/
|
|
22
|
+
export function mergedEvidence(cwd, ref) {
|
|
23
|
+
const branch = ref.replace(/^refs\/(?:heads|remotes\/origin)\//, "");
|
|
24
|
+
if (!BRANCH_NAME.test(branch) || /^(?:main|master|HEAD)$/.test(branch))
|
|
25
|
+
return { merged: false, how: "protected or unverifiable branch name" };
|
|
26
|
+
const into = target(cwd);
|
|
27
|
+
if (!into)
|
|
28
|
+
return { merged: false, how: "origin default branch is not fetched" };
|
|
29
|
+
try {
|
|
30
|
+
const tip = git(cwd, ["rev-parse", "--verify", `${ref}^{commit}`]);
|
|
31
|
+
try {
|
|
32
|
+
git(cwd, ["merge-base", "--is-ancestor", tip, into]);
|
|
33
|
+
return { merged: true, how: "reachable from origin default branch" };
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* not an ancestor; test for a squash or rebase merge */
|
|
37
|
+
}
|
|
38
|
+
const base = git(cwd, ["merge-base", tip, into]);
|
|
39
|
+
const tree = git(cwd, ["rev-parse", `${tip}^{tree}`]);
|
|
40
|
+
// commit-tree writes one unreachable object; it never touches refs, the index or the worktree.
|
|
41
|
+
const synthetic = execFileSync("git", [
|
|
42
|
+
"-c",
|
|
43
|
+
"core.fsmonitor=false",
|
|
44
|
+
"-C",
|
|
45
|
+
cwd,
|
|
46
|
+
"commit-tree",
|
|
47
|
+
tree,
|
|
48
|
+
"-p",
|
|
49
|
+
base,
|
|
50
|
+
"-m",
|
|
51
|
+
"squash probe",
|
|
52
|
+
], {
|
|
53
|
+
encoding: "utf8",
|
|
54
|
+
timeout: 3000,
|
|
55
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
56
|
+
env: {
|
|
57
|
+
...Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith("GIT_"))),
|
|
58
|
+
GIT_AUTHOR_NAME: "policy-manager",
|
|
59
|
+
GIT_AUTHOR_EMAIL: "policy-manager@localhost",
|
|
60
|
+
GIT_COMMITTER_NAME: "policy-manager",
|
|
61
|
+
GIT_COMMITTER_EMAIL: "policy-manager@localhost",
|
|
62
|
+
},
|
|
63
|
+
}).trim();
|
|
64
|
+
const cherry = git(cwd, ["cherry", into, synthetic]);
|
|
65
|
+
if (cherry && cherry.split("\n").every((line) => line.startsWith("-")))
|
|
66
|
+
return {
|
|
67
|
+
merged: true,
|
|
68
|
+
how: "patch-equivalent to a squash or rebase merge into origin default",
|
|
69
|
+
};
|
|
70
|
+
return { merged: false, how: "branch has changes absent from origin default branch" };
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return { merged: false, how: "merge state could not be verified" };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The remote tip must match the fetched tracking ref, or a delete could discard unseen commits. */
|
|
77
|
+
export function remoteTipMatches(cwd, branch) {
|
|
78
|
+
try {
|
|
79
|
+
const local = git(cwd, ["rev-parse", "--verify", `refs/remotes/origin/${branch}^{commit}`]);
|
|
80
|
+
const remote = execFileSync("git", [
|
|
81
|
+
"-c",
|
|
82
|
+
"core.fsmonitor=false",
|
|
83
|
+
"-C",
|
|
84
|
+
cwd,
|
|
85
|
+
"ls-remote",
|
|
86
|
+
"--heads",
|
|
87
|
+
"origin",
|
|
88
|
+
`refs/heads/${branch}`,
|
|
89
|
+
], { encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
90
|
+
return remote.split(/\s+/)[0] === local;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=merged.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Profile } from "./profile.js";
|
|
2
|
+
import type { Decision, Request } from "./types.js";
|
|
3
|
+
export declare function permissiveRead(cwd: string, input: string): {
|
|
4
|
+
allowed: boolean;
|
|
5
|
+
category: "sensitive";
|
|
6
|
+
reason: string;
|
|
7
|
+
} | {
|
|
8
|
+
allowed: boolean;
|
|
9
|
+
category: "code-read";
|
|
10
|
+
reason: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function permissiveWrite(cwd: string, input: string, profile: Profile): {
|
|
13
|
+
allowed: boolean;
|
|
14
|
+
category: "code-read" | "worktree-write" | "sensitive";
|
|
15
|
+
reason: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Evaluates a compound command. `cd <literal>` is tracked: every later command is judged in each
|
|
19
|
+
* directory it could run in (before and after the `cd`, since `cd x || ...` may fail), so a command
|
|
20
|
+
* that only looks safe relative to the starting directory cannot hide behind a `cd`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function commandDecision(request: Request, command: string, profile: Profile, depth?: number, start?: string[]): Decision;
|
|
23
|
+
//# sourceMappingURL=permissive.d.ts.map
|