@justfortytwo/gate 0.1.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/.claude-plugin/plugin.json +5 -0
- package/LICENSE +21 -0
- package/README.md +196 -0
- package/dist/approval-store.d.ts +84 -0
- package/dist/approval-store.js +172 -0
- package/dist/approval-store.js.map +1 -0
- package/dist/bash-allowlist.d.ts +28 -0
- package/dist/bash-allowlist.js +98 -0
- package/dist/bash-allowlist.js.map +1 -0
- package/dist/cli-bin.d.ts +2 -0
- package/dist/cli-bin.js +21 -0
- package/dist/cli-bin.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +60 -0
- package/dist/cli.js.map +1 -0
- package/dist/gate-hook.d.ts +2 -0
- package/dist/gate-hook.js +73 -0
- package/dist/gate-hook.js.map +1 -0
- package/dist/gate.d.ts +47 -0
- package/dist/gate.js +279 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/policy.d.ts +76 -0
- package/dist/policy.js +253 -0
- package/dist/policy.js.map +1 -0
- package/examples/bash-allowlist.jsonl +30 -0
- package/examples/capabilities.toml +70 -0
- package/hooks/hooks.json +15 -0
- package/package.json +65 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// gate CLI: clear deferred approvals from the durable store, standalone — so the
|
|
2
|
+
// gate can complete its own approve->allow loop without a host. Pure and testable:
|
|
3
|
+
// the store + output sinks are injected; the bin shim (cli-bin.ts) wires them.
|
|
4
|
+
//
|
|
5
|
+
// list list staged approvals
|
|
6
|
+
// approve <tool_use_id> approve a deferred call (consumed once on re-fire)
|
|
7
|
+
// deny <tool_use_id> deny a deferred call
|
|
8
|
+
const USAGE = `usage: fortytwo-gate <command>
|
|
9
|
+
list list staged approvals
|
|
10
|
+
approve <tool_use_id> approve a deferred call (one-shot)
|
|
11
|
+
deny <tool_use_id> deny a deferred call`;
|
|
12
|
+
function fmt(r) {
|
|
13
|
+
return `${r.status.padEnd(8)} ${r.tier.padEnd(12)} ${r.tool_use_id} ${r.tool} -> ${r.target}`;
|
|
14
|
+
}
|
|
15
|
+
export async function runCli(argv, opts) {
|
|
16
|
+
const out = opts.out ?? ((s) => process.stdout.write(`${s}\n`));
|
|
17
|
+
const err = opts.err ?? ((s) => process.stderr.write(`${s}\n`));
|
|
18
|
+
const [cmd, id] = argv;
|
|
19
|
+
// Validate the command/args before touching the store (no I/O on bad usage).
|
|
20
|
+
if (!cmd) {
|
|
21
|
+
err(USAGE);
|
|
22
|
+
return 2;
|
|
23
|
+
}
|
|
24
|
+
if (cmd === 'approve' || cmd === 'deny') {
|
|
25
|
+
if (!id) {
|
|
26
|
+
err(`${cmd}: missing <tool_use_id>`);
|
|
27
|
+
return 2;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (cmd !== 'list') {
|
|
31
|
+
err(`unknown command: ${cmd}\n${USAGE}`);
|
|
32
|
+
return 2;
|
|
33
|
+
}
|
|
34
|
+
// Store access is fail-closed: any error reports non-zero, never silent success.
|
|
35
|
+
try {
|
|
36
|
+
if (cmd === 'list') {
|
|
37
|
+
if (opts.storeLabel)
|
|
38
|
+
out(`store: ${opts.storeLabel}`);
|
|
39
|
+
const rows = await opts.store.list();
|
|
40
|
+
if (rows.length === 0)
|
|
41
|
+
out('(no staged approvals)');
|
|
42
|
+
for (const r of rows)
|
|
43
|
+
out(fmt(r));
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
const status = cmd === 'approve' ? 'approved' : 'denied';
|
|
47
|
+
const ok = await opts.store.setDecisionByToolUseId(id, status, 'cli');
|
|
48
|
+
if (!ok) {
|
|
49
|
+
err(`${cmd}: no staged (pending) approval for ${id}`);
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
out(`${id} ${status}`);
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
err(`gate error (fail-closed): ${e instanceof Error ? e.message : String(e)}`);
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,mFAAmF;AACnF,+EAA+E;AAC/E,EAAE;AACF,kDAAkD;AAClD,+EAA+E;AAC/E,iDAAiD;AAYjD,MAAM,KAAK,GAAG;;;+CAGiC,CAAC;AAEhD,SAAS,GAAG,CAAC,CAAkB;IAC7B,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;AACjG,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAc,EAAE,IAAgB;IAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;IAEvB,6EAA6E;IAC7E,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,CAAC,KAAK,CAAC,CAAC;QACX,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,GAAG,KAAK,SAAS,I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BAA6B,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC/E,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PreToolUse hook entry for the standalone safety gate. Claude Code pipes the tool
|
|
3
|
+
// event as JSON on stdin; we emit a permissionDecision on stdout. Fail-closed: any
|
|
4
|
+
// internal error denies the call (a broken gate stops the agent, never leaks).
|
|
5
|
+
//
|
|
6
|
+
// Wired as a Claude Code plugin hook (hooks/hooks.json): PreToolUse matcher "*" ->
|
|
7
|
+
// this command. It can also be wired directly from .claude/settings.json.
|
|
8
|
+
//
|
|
9
|
+
// Configuration (all optional, resolved relative to the project root = cwd):
|
|
10
|
+
// GATE_MANIFEST path to the capability manifest TOML
|
|
11
|
+
// (default: .claude/policy/capabilities.toml)
|
|
12
|
+
// GATE_BASH_ALLOWLIST path to the bash allowlist JSONL
|
|
13
|
+
// (default: rules/bash-allowlist.jsonl)
|
|
14
|
+
// GATE_APPROVALS path to the durable one-shot approval store JSONL
|
|
15
|
+
// (default: .gate/approvals.jsonl)
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { resolve } from 'node:path';
|
|
18
|
+
import { loadManifest, decide } from './gate.js';
|
|
19
|
+
import { JsonlApprovalStore } from './approval-store.js';
|
|
20
|
+
function emit(permission, reason) {
|
|
21
|
+
process.stdout.write(JSON.stringify({
|
|
22
|
+
hookSpecificOutput: {
|
|
23
|
+
hookEventName: 'PreToolUse',
|
|
24
|
+
permissionDecision: permission,
|
|
25
|
+
permissionDecisionReason: reason,
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
async function main() {
|
|
30
|
+
// Empty/garbage stdin (e.g. a non-gating event) -> allow.
|
|
31
|
+
let evt = null;
|
|
32
|
+
try {
|
|
33
|
+
const raw = readFileSync(0, 'utf8');
|
|
34
|
+
if (raw.trim())
|
|
35
|
+
evt = JSON.parse(raw);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
emit('allow', 'gate: no/invalid stdin event');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (!evt || evt.hook_event_name !== 'PreToolUse') {
|
|
42
|
+
emit('allow', 'gate: not a PreToolUse event');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const root = resolve(evt.cwd ?? process.cwd());
|
|
47
|
+
const manifestPath = process.env.GATE_MANIFEST
|
|
48
|
+
? resolve(root, process.env.GATE_MANIFEST)
|
|
49
|
+
: resolve(root, '.claude', 'policy', 'capabilities.toml');
|
|
50
|
+
const approvalsPath = process.env.GATE_APPROVALS
|
|
51
|
+
? resolve(root, process.env.GATE_APPROVALS)
|
|
52
|
+
: resolve(root, '.gate', 'approvals.jsonl');
|
|
53
|
+
const bashAllowlistPath = process.env.GATE_BASH_ALLOWLIST
|
|
54
|
+
? resolve(root, process.env.GATE_BASH_ALLOWLIST)
|
|
55
|
+
: undefined; // undefined -> gate uses its default (<root>/rules/bash-allowlist.jsonl)
|
|
56
|
+
const m = loadManifest(manifestPath);
|
|
57
|
+
const store = new JsonlApprovalStore(approvalsPath);
|
|
58
|
+
const d = await decide(m, {
|
|
59
|
+
toolName: evt.tool_name,
|
|
60
|
+
toolInput: evt.tool_input ?? {},
|
|
61
|
+
toolUseId: evt.tool_use_id,
|
|
62
|
+
sessionId: evt.session_id,
|
|
63
|
+
cwd: root,
|
|
64
|
+
bashAllowlistPath,
|
|
65
|
+
}, { store });
|
|
66
|
+
emit(d.permission, d.reason);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
emit('deny', `gate error (fail-closed): ${e?.message ?? String(e)}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
main();
|
|
73
|
+
//# sourceMapping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AAE,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,EAAE,6BAA6B,CAAC,EAAE,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/gate.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type ApprovalStore, type AuditLogger, InMemoryApprovalStore, NullAuditLogger } from './approval-store.js';
|
|
2
|
+
export type Tier = 'read' | 'internal' | 'draft' | 'external' | 'irreversible';
|
|
3
|
+
export interface Manifest {
|
|
4
|
+
defaultTier: Tier;
|
|
5
|
+
tiers: Map<string, Tier>;
|
|
6
|
+
prefixes: Array<{
|
|
7
|
+
prefix: string;
|
|
8
|
+
tier: Tier;
|
|
9
|
+
}>;
|
|
10
|
+
bash: Array<{
|
|
11
|
+
re: RegExp;
|
|
12
|
+
tier: Tier;
|
|
13
|
+
}>;
|
|
14
|
+
guardFiles: Set<string>;
|
|
15
|
+
}
|
|
16
|
+
export interface GateContext {
|
|
17
|
+
toolName: string;
|
|
18
|
+
toolInput: Record<string, unknown>;
|
|
19
|
+
toolUseId?: string;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
cwd?: string;
|
|
22
|
+
bashAllowlistPath?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface Decision {
|
|
25
|
+
permission: 'allow' | 'defer' | 'deny';
|
|
26
|
+
tier: Tier;
|
|
27
|
+
reason: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function parseToml(src: string): Record<string, unknown>;
|
|
30
|
+
export declare function parseManifest(src: string): Manifest;
|
|
31
|
+
export declare function loadManifest(path: string): Manifest;
|
|
32
|
+
export declare function classify(m: Manifest, toolName: string, toolInput: Record<string, unknown>, cwd?: string): Tier;
|
|
33
|
+
export interface DecideOptions {
|
|
34
|
+
/** Durable one-shot approval record store. Defaults to a process-local store. */
|
|
35
|
+
store?: ApprovalStore;
|
|
36
|
+
/** Optional audit trail. Defaults to a no-op logger. */
|
|
37
|
+
audit?: AuditLogger;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The defer/allow/deny state machine. Auto tiers pass. External/irreversible:
|
|
41
|
+
* the first call defers + stages a pending approval; a re-fire after the approval
|
|
42
|
+
* is recorded consumes the one-shot and allows; denied/already-executed calls are
|
|
43
|
+
* denied.
|
|
44
|
+
*/
|
|
45
|
+
export declare function decide(m: Manifest, ctx: GateContext, opts?: DecideOptions): Promise<Decision>;
|
|
46
|
+
export { InMemoryApprovalStore, NullAuditLogger };
|
|
47
|
+
export type { ApprovalStore, AuditLogger };
|
package/dist/gate.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// The safety gate: a pure capability classifier plus a defer/allow/deny state
|
|
2
|
+
// machine. Auto tiers (read/internal/draft) pass; external/irreversible calls are
|
|
3
|
+
// deferred on first sight, staged as a one-shot approval, and only run after an
|
|
4
|
+
// out-of-band approval is recorded. It is agent-agnostic: it talks to a pluggable
|
|
5
|
+
// ApprovalStore for the durable one-shot record and an optional AuditLogger for
|
|
6
|
+
// the trail, so it carries no database or host-specific code itself.
|
|
7
|
+
//
|
|
8
|
+
// TODO(wire): the original host backed ApprovalStore/AuditLogger with its own
|
|
9
|
+
// transactional store (a memory/DB package). That binding belongs to a host
|
|
10
|
+
// integration package — @justfortytwo/memory exports an ApprovalStore
|
|
11
|
+
// implementation (see its gate-approval-store.ts) and wires it in. The gate
|
|
12
|
+
// ships only the in-memory + JSONL stores below so it stands alone.
|
|
13
|
+
import { readFileSync } from 'node:fs';
|
|
14
|
+
import { resolve, relative, isAbsolute } from 'node:path';
|
|
15
|
+
import { bashAllowlistPath, findBashAllowlistMatch } from './bash-allowlist.js';
|
|
16
|
+
import { InMemoryApprovalStore, NullAuditLogger, } from './approval-store.js';
|
|
17
|
+
const AUTO = new Set(['read', 'internal', 'draft']);
|
|
18
|
+
const RANK = { read: 0, internal: 1, draft: 2, external: 3, irreversible: 4 };
|
|
19
|
+
const ACTOR = process.env.GATE_ACTOR ?? 'agent';
|
|
20
|
+
// --- minimal TOML parser (schema: default_tier, [tiers], [bash], [guard].files) ---
|
|
21
|
+
function findUnquotedHash(line) {
|
|
22
|
+
let inS = null;
|
|
23
|
+
for (let i = 0; i < line.length; i++) {
|
|
24
|
+
const c = line[i];
|
|
25
|
+
if (inS) {
|
|
26
|
+
if (c === inS)
|
|
27
|
+
inS = null;
|
|
28
|
+
}
|
|
29
|
+
else if (c === '"' || c === "'")
|
|
30
|
+
inS = c;
|
|
31
|
+
else if (c === '#')
|
|
32
|
+
return i;
|
|
33
|
+
}
|
|
34
|
+
return -1;
|
|
35
|
+
}
|
|
36
|
+
function stripQuotes(s) {
|
|
37
|
+
if (s.length >= 2 && ((s[0] === '"' && s[s.length - 1] === '"') || (s[0] === "'" && s[s.length - 1] === "'"))) {
|
|
38
|
+
return s.slice(1, -1);
|
|
39
|
+
}
|
|
40
|
+
return s;
|
|
41
|
+
}
|
|
42
|
+
function parseValue(v) {
|
|
43
|
+
v = v.trim();
|
|
44
|
+
if (v.startsWith('[') && v.endsWith(']')) {
|
|
45
|
+
const inner = v.slice(1, -1).trim();
|
|
46
|
+
if (!inner)
|
|
47
|
+
return [];
|
|
48
|
+
return inner.split(',').map((s) => stripQuotes(s.trim()));
|
|
49
|
+
}
|
|
50
|
+
return stripQuotes(v);
|
|
51
|
+
}
|
|
52
|
+
function startsCollection(v) {
|
|
53
|
+
return v.startsWith('[') || v.startsWith('{');
|
|
54
|
+
}
|
|
55
|
+
/** Brackets/braces balanced (ignoring quoted regions)? Drives multi-line arrays. */
|
|
56
|
+
function balanced(v) {
|
|
57
|
+
let depth = 0;
|
|
58
|
+
let inS = null;
|
|
59
|
+
for (const c of v) {
|
|
60
|
+
if (inS) {
|
|
61
|
+
if (c === inS)
|
|
62
|
+
inS = null;
|
|
63
|
+
}
|
|
64
|
+
else if (c === '"' || c === "'")
|
|
65
|
+
inS = c;
|
|
66
|
+
else if (c === '[' || c === '{')
|
|
67
|
+
depth++;
|
|
68
|
+
else if (c === ']' || c === '}')
|
|
69
|
+
depth--;
|
|
70
|
+
}
|
|
71
|
+
return depth <= 0 && inS === null;
|
|
72
|
+
}
|
|
73
|
+
export function parseToml(src) {
|
|
74
|
+
const out = {};
|
|
75
|
+
let cur = out;
|
|
76
|
+
let pendingKey = null;
|
|
77
|
+
let pendingVal = '';
|
|
78
|
+
for (const raw of src.split('\n')) {
|
|
79
|
+
let line = raw;
|
|
80
|
+
const h = findUnquotedHash(line);
|
|
81
|
+
if (h >= 0)
|
|
82
|
+
line = line.slice(0, h);
|
|
83
|
+
line = line.trim();
|
|
84
|
+
if (!line)
|
|
85
|
+
continue;
|
|
86
|
+
// Continue a multi-line array/table value until brackets balance.
|
|
87
|
+
if (pendingKey !== null) {
|
|
88
|
+
pendingVal += ' ' + line;
|
|
89
|
+
if (balanced(pendingVal)) {
|
|
90
|
+
cur[pendingKey] = parseValue(pendingVal.trim());
|
|
91
|
+
pendingKey = null;
|
|
92
|
+
pendingVal = '';
|
|
93
|
+
}
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (line.startsWith('[') && line.endsWith(']')) {
|
|
97
|
+
const sec = line.slice(1, -1).trim();
|
|
98
|
+
cur = out[sec] ??= {};
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const eq = line.indexOf('=');
|
|
102
|
+
if (eq < 0)
|
|
103
|
+
continue;
|
|
104
|
+
const key = stripQuotes(line.slice(0, eq).trim());
|
|
105
|
+
const val = line.slice(eq + 1).trim();
|
|
106
|
+
if (startsCollection(val) && !balanced(val)) {
|
|
107
|
+
pendingKey = key;
|
|
108
|
+
pendingVal = val;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
cur[key] = parseValue(val);
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
const VALID = ['read', 'internal', 'draft', 'external', 'irreversible'];
|
|
116
|
+
function asTier(v, fallback) {
|
|
117
|
+
return typeof v === 'string' && VALID.includes(v) ? v : fallback;
|
|
118
|
+
}
|
|
119
|
+
export function parseManifest(src) {
|
|
120
|
+
const o = parseToml(src);
|
|
121
|
+
const defaultTier = asTier(o['default_tier'], 'internal');
|
|
122
|
+
const tiers = new Map();
|
|
123
|
+
const prefixes = [];
|
|
124
|
+
const tiersSection = (o['tiers'] ?? {});
|
|
125
|
+
for (const [k, v] of Object.entries(tiersSection)) {
|
|
126
|
+
const tier = asTier(v, defaultTier);
|
|
127
|
+
if (k.endsWith('*'))
|
|
128
|
+
prefixes.push({ prefix: k.slice(0, -1), tier });
|
|
129
|
+
else
|
|
130
|
+
tiers.set(k, tier);
|
|
131
|
+
}
|
|
132
|
+
const bashSection = (o['bash'] ?? {});
|
|
133
|
+
const bash = Object.entries(bashSection).map(([k, v]) => ({ re: new RegExp(k), tier: asTier(v, 'external') }));
|
|
134
|
+
const guardSection = (o['guard'] ?? {});
|
|
135
|
+
const files = Array.isArray(guardSection['files']) ? guardSection['files'] : [];
|
|
136
|
+
return { defaultTier, tiers, prefixes, bash, guardFiles: new Set(files) };
|
|
137
|
+
}
|
|
138
|
+
export function loadManifest(path) {
|
|
139
|
+
return parseManifest(readFileSync(path, 'utf8'));
|
|
140
|
+
}
|
|
141
|
+
// --- classification ---
|
|
142
|
+
const EDIT_TOOLS = new Set(['Write', 'Edit', 'NotebookEdit']);
|
|
143
|
+
/** Normalize an arbitrary file_path to project-relative against cwd. */
|
|
144
|
+
function repoRel(file_path, cwd) {
|
|
145
|
+
const base = cwd ?? '.';
|
|
146
|
+
const abs = isAbsolute(file_path) ? file_path : resolve(base, file_path);
|
|
147
|
+
let rel = relative(resolve(base), abs);
|
|
148
|
+
if (rel.startsWith('..'))
|
|
149
|
+
rel = file_path; // outside project — compare as-is
|
|
150
|
+
return rel.replace(/^\.\//, '');
|
|
151
|
+
}
|
|
152
|
+
export function classify(m, toolName, toolInput, cwd) {
|
|
153
|
+
// 1. Protect the guard: editing a guarded file is irreversible.
|
|
154
|
+
if (EDIT_TOOLS.has(toolName) && typeof toolInput['file_path'] === 'string') {
|
|
155
|
+
const rel = repoRel(toolInput['file_path'], cwd);
|
|
156
|
+
if (m.guardFiles.has(rel))
|
|
157
|
+
return 'irreversible';
|
|
158
|
+
}
|
|
159
|
+
// 2. Bash: the base tier is the FLOOR; [bash] patterns only ever elevate.
|
|
160
|
+
// Bash fails closed — an unmatched command stays at the base tier (external,
|
|
161
|
+
// deferred) rather than auto-running, and a benign segment can never
|
|
162
|
+
// de-escalate a chained command (`git commit && node -e "..."`). Known-safe
|
|
163
|
+
// commands are permitted via the allowlist in decide(), not by lowering here.
|
|
164
|
+
if (toolName === 'Bash' && typeof toolInput['command'] === 'string') {
|
|
165
|
+
let bashTier = m.tiers.get('Bash') ?? m.defaultTier;
|
|
166
|
+
for (const { re, tier } of m.bash) {
|
|
167
|
+
if (re.test(toolInput['command']) && RANK[tier] > RANK[bashTier])
|
|
168
|
+
bashTier = tier;
|
|
169
|
+
}
|
|
170
|
+
return bashTier;
|
|
171
|
+
}
|
|
172
|
+
// 3. Exact tool tier.
|
|
173
|
+
const exact = m.tiers.get(toolName);
|
|
174
|
+
if (exact)
|
|
175
|
+
return exact;
|
|
176
|
+
// 4. Prefix glob (e.g. mcp__messaging__*).
|
|
177
|
+
for (const { prefix, tier } of m.prefixes)
|
|
178
|
+
if (toolName.startsWith(prefix))
|
|
179
|
+
return tier;
|
|
180
|
+
// 5. Default.
|
|
181
|
+
return m.defaultTier;
|
|
182
|
+
}
|
|
183
|
+
function describeTarget(toolInput) {
|
|
184
|
+
for (const k of ['target', 'to', 'chat_id', 'email', 'url']) {
|
|
185
|
+
const v = toolInput[k];
|
|
186
|
+
if (typeof v === 'string' && v.length)
|
|
187
|
+
return `${k}=${v.slice(0, 80)}`;
|
|
188
|
+
}
|
|
189
|
+
if (typeof toolInput['command'] === 'string')
|
|
190
|
+
return `cmd=${toolInput['command'].slice(0, 80)}`;
|
|
191
|
+
return JSON.stringify(toolInput).slice(0, 80);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The defer/allow/deny state machine. Auto tiers pass. External/irreversible:
|
|
195
|
+
* the first call defers + stages a pending approval; a re-fire after the approval
|
|
196
|
+
* is recorded consumes the one-shot and allows; denied/already-executed calls are
|
|
197
|
+
* denied.
|
|
198
|
+
*/
|
|
199
|
+
export async function decide(m, ctx, opts = {}) {
|
|
200
|
+
const store = opts.store ?? defaultStore;
|
|
201
|
+
const audit = opts.audit ?? new NullAuditLogger();
|
|
202
|
+
const tier = classify(m, ctx.toolName, ctx.toolInput, ctx.cwd);
|
|
203
|
+
const target = describeTarget(ctx.toolInput);
|
|
204
|
+
if (AUTO.has(tier)) {
|
|
205
|
+
return { permission: 'allow', tier, reason: `[${tier}] auto` };
|
|
206
|
+
}
|
|
207
|
+
// Existing deferred calls are authoritative: consume explicit approvals before
|
|
208
|
+
// consulting durable allowlists, so a pending/denied one-shot cannot be bypassed.
|
|
209
|
+
let existing;
|
|
210
|
+
if (ctx.toolUseId)
|
|
211
|
+
existing = await store.getByToolUseId(ctx.toolUseId);
|
|
212
|
+
if (existing) {
|
|
213
|
+
if (existing.status === 'pending') {
|
|
214
|
+
return { permission: 'defer', tier, reason: `[${tier}] Still awaiting approval #${existing.id}.` };
|
|
215
|
+
}
|
|
216
|
+
if (existing.status === 'approved') {
|
|
217
|
+
const consumed = await store.markExecutedByToolUseId(ctx.toolUseId);
|
|
218
|
+
if (consumed) {
|
|
219
|
+
await audit.log({
|
|
220
|
+
actor: ACTOR, kind: 'approval_decision',
|
|
221
|
+
content: `${ctx.toolName} -> ${target} (executed one-shot)`, approval_status: 'executed',
|
|
222
|
+
meta: { pending_id: existing.id, tier },
|
|
223
|
+
});
|
|
224
|
+
return { permission: 'allow', tier, reason: `[${tier}] One-shot approval consumed for #${existing.id}.` };
|
|
225
|
+
}
|
|
226
|
+
return { permission: 'deny', tier, reason: `[${tier}] Approval #${existing.id} already consumed.` };
|
|
227
|
+
}
|
|
228
|
+
// denied | executed | expired
|
|
229
|
+
return {
|
|
230
|
+
permission: 'deny', tier,
|
|
231
|
+
reason: `[${tier}] ${ctx.toolName} -> ${target} is ${existing.status} (#${existing.id}). Re-request approval if still needed.`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
// Deny-always-wins: a command flagged by ANY [bash] elevation pattern (external
|
|
235
|
+
// exfil like `curl --data`, `git push`, OR irreversible like `rm -rf`) can never
|
|
236
|
+
// be satisfied by the allowlist — a broad glob (`git *`) must not launder
|
|
237
|
+
// `git push` past the gate. The allowlist only fast-paths commands sitting at
|
|
238
|
+
// the neutral base tier; flagged commands always need explicit one-shot approval.
|
|
239
|
+
const flaggedBash = ctx.toolName === 'Bash' && typeof ctx.toolInput['command'] === 'string'
|
|
240
|
+
&& m.bash.some(({ re }) => re.test(ctx.toolInput['command']));
|
|
241
|
+
if (ctx.toolName === 'Bash' && !flaggedBash && typeof ctx.toolInput['command'] === 'string') {
|
|
242
|
+
const cwd = ctx.cwd ? resolve(ctx.cwd) : resolve('.');
|
|
243
|
+
const allowPath = ctx.bashAllowlistPath ?? bashAllowlistPath(cwd);
|
|
244
|
+
const match = findBashAllowlistMatch(allowPath, ctx.toolInput['command'], cwd);
|
|
245
|
+
if (match) {
|
|
246
|
+
await audit.log({
|
|
247
|
+
actor: ACTOR, kind: 'approval_decision',
|
|
248
|
+
content: `Bash allowlist matched: ${ctx.toolInput['command']}`,
|
|
249
|
+
approval_status: 'approved',
|
|
250
|
+
meta: { tier, command_glob: match.command_glob, cwd_glob: match.cwd_glob, expires_at: match.expires_at ?? null },
|
|
251
|
+
});
|
|
252
|
+
return { permission: 'allow', tier, reason: `[${tier}] Bash allowlist matched ${match.command_glob}` };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// No prior record -> stage the approval and defer.
|
|
256
|
+
if (!ctx.toolUseId) {
|
|
257
|
+
// Cannot key a one-shot without a tool_use_id; fail closed.
|
|
258
|
+
return { permission: 'deny', tier, reason: `[${tier}] ${ctx.toolName} requires approval but no tool_use_id was provided.` };
|
|
259
|
+
}
|
|
260
|
+
const id = await store.addPending({
|
|
261
|
+
tool: ctx.toolName, target, payload: ctx.toolInput,
|
|
262
|
+
tier, tool_use_id: ctx.toolUseId, session_id: ctx.sessionId ?? null,
|
|
263
|
+
});
|
|
264
|
+
await audit.log({
|
|
265
|
+
actor: ACTOR, kind: 'approval_request',
|
|
266
|
+
content: `${ctx.toolName} -> ${target}`, approval_status: 'pending',
|
|
267
|
+
meta: { pending_id: id, tier },
|
|
268
|
+
});
|
|
269
|
+
return {
|
|
270
|
+
permission: 'defer', tier,
|
|
271
|
+
reason: `APPROVAL - [${tier}]\n${ctx.toolName} -> ${target}\nApprove once, allow by policy, or deny. Pending #${id}.`,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
// The default durable store for standalone use. The hook persists one-shot
|
|
275
|
+
// approvals to a JSONL file (see ./approval-store.ts); this in-memory default is a
|
|
276
|
+
// safe library fallback when no store is supplied to decide().
|
|
277
|
+
const defaultStore = new InMemoryApprovalStore();
|
|
278
|
+
export { InMemoryApprovalStore, NullAuditLogger };
|
|
279
|
+
//# sourceMappingURL=gate.js.map
|
package/dist/gate.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gate.js","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,kFAAkF;AAClF,gFAAgF;AAChF,kFAAkF;AAClF,gFAAgF;AAChF,qEAAqE;AACrE,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAC9E,sEAAsE;AAEtE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC1D,O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AE,IAAI,IAAI,KAAK,GAAG,CAAC,QAAQ,qDAAqD,EAAE,CAAC;IAC9H,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC;QAChC,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,SAAS;QAClD,IAAI,EAAE,WAAW,EAAE,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,SAAS,IAAI,IAAI;KACpE,CAAC,CAAC;IACH,MAAM,KAAK,CAAC,GAAG,CAAC;QACd,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,kBAAkB;QACtC,OAAO,EAAE,GAAG,GAAG,CAAC,QAAQ,OAAO,MAAM,EAAE,EAAE,eAAe,EAAE,SAAS;QACnE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE;KAC/B,CAAC,CAAC;IACH,OAAO;QACL,UAAU,EAAE,OAAO,EAAE,IAAI;QACzB,MAAM,EAAE,eAAe,IAAI,MAAM,GAAG,CAAC,QAAQ,OAAO,MAAM,sDAAsD,EAAE,GAAG;KACtH,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,mFAAmF;AACnF,+DAA+D;AAC/D,MAAM,YAAY,GAAkB,IAAI,qBAAqB,EAAE,CAAC;AAEhE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const POLICY_SCHEMA_VERSION = 1;
|
|
2
|
+
export { decide, classify, loadManifest, parseManifest, parseToml, InMemoryApprovalStore, NullAuditLogger, } from './gate.js';
|
|
3
|
+
export type { Tier, Manifest, GateContext, Decision, DecideOptions, } from './gate.js';
|
|
4
|
+
export { runCli } from './cli.js';
|
|
5
|
+
export type { CliOptions } from './cli.js';
|
|
6
|
+
export { JsonlApprovalStore, } from './approval-store.js';
|
|
7
|
+
export type { ApprovalStore, AuditLogger, AuditEntry, ApprovalStatus, PendingApproval, AddPendingInput, } from './approval-store.js';
|
|
8
|
+
export { readBashAllowlist, findBashAllowlistMatch, bashAllowlistPath, appendExactBashAllowlistEntry, escapeGlobLiteral, globToRegExp, DEFAULT_BASH_ALLOW_TTL_HOURS, } from './bash-allowlist.js';
|
|
9
|
+
export type { BashAllowlistEntry } from './bash-allowlist.js';
|
|
10
|
+
export { decidePolicy, classifyAuthority, canUseAsInstruction, createSourceEnvelope, defaultMemoryClassForSource, recallPriorityForMemoryClass, rankRecall, renderContextPack, } from './policy.js';
|
|
11
|
+
export type { SourceKind, Authority, MemoryClass, RequestedOperation, PolicyInput, PolicyDecision, SourceEnvelope, SourceEnvelopeInput, ContextPackItem, RecallItem, RankedRecallItem, } from './policy.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @justfortytwo/gate — a standalone, agent-agnostic PreToolUse safety gate.
|
|
2
|
+
//
|
|
3
|
+
// Public API:
|
|
4
|
+
// - the capability manifest + classifier + defer/allow/deny engine (./gate)
|
|
5
|
+
// - the fail-closed bash allowlist (./bash-allowlist)
|
|
6
|
+
// - the durable one-shot approval store contract + stock impls (./approval-store)
|
|
7
|
+
// - the content-trust policy engine (./policy)
|
|
8
|
+
//
|
|
9
|
+
// CONTRACT: POLICY_SCHEMA_VERSION is the version of the `policySchema` contract —
|
|
10
|
+
// the shape and meaning of the Authority / MemoryClass / SourceKind types and the
|
|
11
|
+
// decidePolicy() outcomes in ./policy, together with the Tier model in ./gate.
|
|
12
|
+
// Downstream @justfortytwo/* packages pin a caret range on this package; any change
|
|
13
|
+
// to that contract's meaning is a breaking change and must bump this number (and
|
|
14
|
+
// the package major version).
|
|
15
|
+
export const POLICY_SCHEMA_VERSION = 1;
|
|
16
|
+
// --- capability gate (autonomy tiers + defer/allow/deny state machine) ---
|
|
17
|
+
export { decide, classify, loadManifest, parseManifest, parseToml, InMemoryApprovalStore, NullAuditLogger, } from './gate.js';
|
|
18
|
+
// --- approval-clearing CLI (standalone approve/deny/list) ---
|
|
19
|
+
export { runCli } from './cli.js';
|
|
20
|
+
// --- durable one-shot approval store (the host-integration seam) ---
|
|
21
|
+
export { JsonlApprovalStore, } from './approval-store.js';
|
|
22
|
+
// --- bash allowlist ---
|
|
23
|
+
export { readBashAllowlist, findBashAllowlistMatch, bashAllowlistPath, appendExactBashAllowlistEntry, escapeGlobLiteral, globToRegExp, DEFAULT_BASH_ALLOW_TTL_HOURS, } from './bash-allowlist.js';
|
|
24
|
+
// --- content-trust policy engine (the policySchema contract surface) ---
|
|
25
|
+
export { decidePolicy, classifyAuthority, canUseAsInstruction, createSourceEnvelope, defaultMemoryClassForSource, recallPriorityForMemoryClass, rankRecall, renderContextPack, } from './policy.js';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,cAAc;AACd,+EAA+E;AAC/E,0FAA0F;AAC1F,0FAA0F;AAC1F,kFAAkF;AAClF,EAAE;AACF,kFAAkF;AAClF,kFAAkF;AAClF,+EAA+E;AAC/E,oFAAoF;AACpF,iFAAiF;AACjF,8BAA8B;AAC9B,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC,4EAA4E;AAC5E,OAAO,EACL,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,eAAe,GAChB,MAAM,WAAW,CAAC;AASnB,+DAA+D;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,sEAAsE;AACtE,OAAO,EACL,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAU7B,yBAAyB;AACzB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,EACZ,4BAA4B,GAC7B,MAAM,qBAAqB,CAAC;AAG7B,0EAA0E;AAC1E,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export type SourceKind = 'repo_policy' | 'repo_document' | 'approved_rule' | 'installed_skill' | 'owner_direct' | 'approval_record' | 'assistant_message' | 'guide_doc' | 'chat_message' | 'chat_photo' | 'chat_document' | 'quoted_text' | 'document' | 'web_page' | 'email' | 'tool_output' | 'mcp_output' | 'plugin_output' | 'memory_recall';
|
|
2
|
+
export type Authority = 'trusted_policy' | 'trusted_user' | 'trusted_approval' | 'trusted_procedure' | 'evidence' | 'untrusted_content';
|
|
3
|
+
export type MemoryClass = 'journal_fact' | 'working_note' | 'pending_decision' | 'preference' | 'canonical_rule' | 'inferred_trait' | 'secret' | 'untrusted_claim';
|
|
4
|
+
export type RequestedOperation = 'summarize' | 'extract_fact' | 'store_journal' | 'store_working_note' | 'store_preference' | 'promote_to_canonical_rule' | 'store_inferred_trait' | 'store_secret' | 'execute_tool' | 'approve_action' | 'use_as_instruction';
|
|
5
|
+
export interface PolicyInput {
|
|
6
|
+
source: SourceKind | string;
|
|
7
|
+
requested_operation: RequestedOperation;
|
|
8
|
+
content?: string;
|
|
9
|
+
memory_class?: MemoryClass;
|
|
10
|
+
provenance?: string;
|
|
11
|
+
direct_user_statement?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface PolicyDecision {
|
|
14
|
+
authority: Authority;
|
|
15
|
+
memory_class: MemoryClass;
|
|
16
|
+
allowed: boolean;
|
|
17
|
+
must_propose: boolean;
|
|
18
|
+
approval_required: boolean;
|
|
19
|
+
provenance_required: boolean;
|
|
20
|
+
recall_priority: number;
|
|
21
|
+
can_use_as_instruction: boolean;
|
|
22
|
+
reason: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SourceEnvelopeInput {
|
|
25
|
+
source_kind: SourceKind | string;
|
|
26
|
+
content: string;
|
|
27
|
+
source_id?: string;
|
|
28
|
+
authority?: Authority | string;
|
|
29
|
+
memory_class?: MemoryClass;
|
|
30
|
+
actor?: string;
|
|
31
|
+
channel?: string;
|
|
32
|
+
parent_source_id?: string | null;
|
|
33
|
+
created_at?: string;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface SourceEnvelope {
|
|
37
|
+
source_id: string;
|
|
38
|
+
source_kind: string;
|
|
39
|
+
authority: Authority;
|
|
40
|
+
memory_class: MemoryClass;
|
|
41
|
+
actor?: string;
|
|
42
|
+
channel?: string;
|
|
43
|
+
content_hash: string;
|
|
44
|
+
parent_source_id?: string | null;
|
|
45
|
+
created_at: string;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
export interface ContextPackItem {
|
|
49
|
+
id: string | number;
|
|
50
|
+
source_kind?: string;
|
|
51
|
+
source?: SourceKind | string;
|
|
52
|
+
authority: Authority;
|
|
53
|
+
memory_class: MemoryClass;
|
|
54
|
+
recall_priority: number;
|
|
55
|
+
can_use_as_instruction: boolean;
|
|
56
|
+
content: string;
|
|
57
|
+
}
|
|
58
|
+
export declare function classifyAuthority(source: SourceKind | string): Authority;
|
|
59
|
+
export declare function defaultMemoryClassForSource(source: SourceKind | string): MemoryClass;
|
|
60
|
+
export declare function recallPriorityForMemoryClass(memoryClass: MemoryClass): number;
|
|
61
|
+
export declare function createSourceEnvelope(input: SourceEnvelopeInput): SourceEnvelope;
|
|
62
|
+
export declare function canUseAsInstruction(sourceOrAuthority: SourceKind | Authority | string): boolean;
|
|
63
|
+
export declare function decidePolicy(input: PolicyInput): PolicyDecision;
|
|
64
|
+
export interface RecallItem {
|
|
65
|
+
id: string;
|
|
66
|
+
memory_class: MemoryClass;
|
|
67
|
+
source: SourceKind | string;
|
|
68
|
+
content: string;
|
|
69
|
+
}
|
|
70
|
+
export interface RankedRecallItem extends RecallItem {
|
|
71
|
+
authority: Authority;
|
|
72
|
+
recall_priority: number;
|
|
73
|
+
can_use_as_instruction: boolean;
|
|
74
|
+
}
|
|
75
|
+
export declare function rankRecall(items: RecallItem[]): RankedRecallItem[];
|
|
76
|
+
export declare function renderContextPack(items: ContextPackItem[]): string;
|