prae-cli 0.9.2 → 0.10.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/lib/bin.js +2 -6
- package/lib/{checkpoint-C_q_Rpa5.js → checkpoint-BLOGdWFu.js} +1 -1
- package/lib/cli-BlWTUnGJ.js +6 -0
- package/lib/{cli-B_B6-bUZ.js → cli-C_6dosaw.js} +629 -534
- package/lib/docs/pilot-claude-code.md +192 -0
- package/lib/hook-DxLgNtc4.js +693 -0
- package/lib/index.js +4 -4
- package/lib/init-BPlBJvA-.js +272 -0
- package/lib/{instructions-ya0LVnZy.js → instructions-fCJ4j7ce.js} +2 -1
- package/lib/{mcp-BCXbpqu4.js → mcp-DdEDvTvR.js} +1 -1
- package/lib/playground.js +717 -109
- package/lib/prae-baseline.prae.json +144 -1
- package/lib/{receipt-check-DQK_gVPc.js → receipt-check-2F4zLEW5.js} +1 -1
- package/lib/src-2iJy5MZc.js +3 -0
- package/lib/src-CZYvvEn5.js +1691 -0
- package/lib/{src-LA7NdLKb.js → src-CuiWC80o.js} +104 -25
- package/lib/{test-run-CCDgJ0Dp.js → test-run-BGsK-inZ.js} +1 -1
- package/lib/views-C7DD-Oif.js +1396 -0
- package/package.json +6 -6
- package/lib/evaluate-BqLxhYiP.js +0 -499
- package/lib/src-7X6dO7gC.js +0 -3
- package/lib/views-D4UEfbzt.js +0 -1505
- /package/lib/{ocsf-DhVGbBUw.js → ocsf-BwWyM7hc.js} +0 -0
- /package/lib/{src-CBGZVvt7.js → src-BoBCmiwj.js} +0 -0
- /package/lib/{src-d4c_n6wd.js → src-XukJfuml.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prae-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Operator policy for agent harnesses: validate packs, explain a decision, test a pack against security invariants, verify a decision log, and provision a governed DSH profile.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh-plugin",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"node": ">=20"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
35
35
|
"capmark": "^0.3.1",
|
|
36
36
|
"dsh-overlay-check": "^0.4.0",
|
|
37
37
|
"yaml": "^2.8.3"
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"typescript": "^5.9.2",
|
|
43
43
|
"vitest": "^3.2.4",
|
|
44
44
|
"@prae/controls": "0.1.0",
|
|
45
|
-
"@prae/inspect": "0.1.0",
|
|
46
45
|
"@prae/extract": "0.1.0",
|
|
47
|
-
"@prae/instructions": "0.1.0",
|
|
48
|
-
"@prae/ledger": "0.1.0",
|
|
49
46
|
"@prae/kernel": "0.1.0",
|
|
50
|
-
"@prae/
|
|
47
|
+
"@prae/ledger": "0.1.0",
|
|
48
|
+
"@prae/tokens": "0.1.0",
|
|
49
|
+
"@prae/instructions": "0.1.0",
|
|
50
|
+
"@prae/inspect": "0.1.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"test": "vitest run",
|
package/lib/evaluate-BqLxhYiP.js
DELETED
|
@@ -1,499 +0,0 @@
|
|
|
1
|
-
//#region ../kernel/src/command.ts
|
|
2
|
-
/** Wrappers whose first operand is the program actually being run. */
|
|
3
|
-
const WRAPPERS = new Set([
|
|
4
|
-
"sudo",
|
|
5
|
-
"command",
|
|
6
|
-
"env",
|
|
7
|
-
"nohup",
|
|
8
|
-
"time",
|
|
9
|
-
"xargs"
|
|
10
|
-
]);
|
|
11
|
-
/** Wrapper options that consume the next token, so it is not the program. */
|
|
12
|
-
const OPTION_WITH_VALUE = new Set([
|
|
13
|
-
"-u",
|
|
14
|
-
"-g",
|
|
15
|
-
"-p",
|
|
16
|
-
"-h",
|
|
17
|
-
"-C",
|
|
18
|
-
"-r",
|
|
19
|
-
"-t",
|
|
20
|
-
"-U",
|
|
21
|
-
"-I",
|
|
22
|
-
"-n",
|
|
23
|
-
"-P",
|
|
24
|
-
"-L",
|
|
25
|
-
"-s"
|
|
26
|
-
]);
|
|
27
|
-
const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
28
|
-
/**
|
|
29
|
-
* Split a line into pipeline segments of words, one scan, quote-aware.
|
|
30
|
-
*
|
|
31
|
-
* Splitting on `|` before parsing quotes is the classic mistake — it turns
|
|
32
|
-
* `echo "a | b"` into two segments — so quoting and separators are read
|
|
33
|
-
* together.
|
|
34
|
-
*/
|
|
35
|
-
function scan(command) {
|
|
36
|
-
const parts = [];
|
|
37
|
-
let tokens = [];
|
|
38
|
-
let current = "";
|
|
39
|
-
let quote;
|
|
40
|
-
const endToken = () => {
|
|
41
|
-
if (current !== "") tokens.push(current);
|
|
42
|
-
current = "";
|
|
43
|
-
};
|
|
44
|
-
const endSegment = () => {
|
|
45
|
-
endToken();
|
|
46
|
-
if (tokens.length > 0) parts.push(tokens);
|
|
47
|
-
tokens = [];
|
|
48
|
-
};
|
|
49
|
-
for (let at = 0; at < command.length; at += 1) {
|
|
50
|
-
const ch = command[at];
|
|
51
|
-
if (quote !== void 0) {
|
|
52
|
-
if (ch === quote) quote = void 0;
|
|
53
|
-
else current += ch;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (ch === "'" || ch === "\"") {
|
|
57
|
-
quote = ch;
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (ch === ";") {
|
|
61
|
-
endSegment();
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (ch === "|" || ch === "&") {
|
|
65
|
-
endSegment();
|
|
66
|
-
if (command[at + 1] === ch) at += 1;
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (/\s/.test(ch)) {
|
|
70
|
-
endToken();
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
current += ch;
|
|
74
|
-
}
|
|
75
|
-
endSegment();
|
|
76
|
-
return parts;
|
|
77
|
-
}
|
|
78
|
-
/** Decompose a command line into pipeline segments. */
|
|
79
|
-
function segments(command) {
|
|
80
|
-
const found = [];
|
|
81
|
-
for (const tokens of scan(command)) {
|
|
82
|
-
let at = 0;
|
|
83
|
-
const wrappers = [];
|
|
84
|
-
while (at < tokens.length) {
|
|
85
|
-
const token = tokens[at];
|
|
86
|
-
if (ASSIGNMENT.test(token)) {
|
|
87
|
-
at += 1;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
const word = (token.split("/").pop() ?? token).toLowerCase();
|
|
91
|
-
if (WRAPPERS.has(word)) {
|
|
92
|
-
wrappers.push(word);
|
|
93
|
-
at += 1;
|
|
94
|
-
while (at < tokens.length) {
|
|
95
|
-
const option = tokens[at];
|
|
96
|
-
if (!option.startsWith("-")) break;
|
|
97
|
-
at += OPTION_WITH_VALUE.has(option) ? 2 : 1;
|
|
98
|
-
}
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
const name = tokens[at];
|
|
104
|
-
if (name === void 0) {
|
|
105
|
-
const last = wrappers.at(-1);
|
|
106
|
-
if (last !== void 0) found.push({
|
|
107
|
-
name: last,
|
|
108
|
-
tokens: [],
|
|
109
|
-
wrappers
|
|
110
|
-
});
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
found.push({
|
|
114
|
-
name: (name.split("/").pop() ?? name).toLowerCase(),
|
|
115
|
-
tokens: tokens.slice(at + 1),
|
|
116
|
-
wrappers
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return found;
|
|
120
|
-
}
|
|
121
|
-
/** `git*` matches `git`, `github`; bare strings match exactly. */
|
|
122
|
-
function matches$1(pattern, value) {
|
|
123
|
-
if (pattern.endsWith("*")) return value.startsWith(pattern.slice(0, -1));
|
|
124
|
-
return value === pattern;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* A glob with `*` anywhere, for pipeline signatures: `curl*|*sh` is the
|
|
128
|
-
* shape of download-and-execute however the two ends are spelled.
|
|
129
|
-
*/
|
|
130
|
-
function globMatches(pattern, value) {
|
|
131
|
-
const source = pattern.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*");
|
|
132
|
-
return (/* @__PURE__ */ new RegExp(`^${source}$`)).test(value);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Every wanted token holds in a segment: a plain pattern must match some
|
|
136
|
-
* token, a `!pattern` must match none. `["-rf", "!--dry-run"]` is a real
|
|
137
|
-
* force-delete, not a rehearsal of one.
|
|
138
|
-
*/
|
|
139
|
-
function tokensHold(wanted, tokens) {
|
|
140
|
-
return wanted.every((pattern) => pattern.startsWith("!") ? !tokens.some((token) => matches$1(pattern.slice(1), token)) : tokens.some((token) => matches$1(pattern, token)));
|
|
141
|
-
}
|
|
142
|
-
const list = (v) => v === void 0 ? [] : typeof v === "string" ? [v] : v;
|
|
143
|
-
/**
|
|
144
|
-
* Judge one command line against one matcher. Every present field must hold.
|
|
145
|
-
*/
|
|
146
|
-
function commandMatches(match, command) {
|
|
147
|
-
const parts = segments(command);
|
|
148
|
-
if (parts.length === 0) return false;
|
|
149
|
-
const names = list(match.name);
|
|
150
|
-
const args = list(match.token);
|
|
151
|
-
const anyArgs = list(match.anyToken);
|
|
152
|
-
const pipes = list(match.pipedTo);
|
|
153
|
-
const shapes = list(match.pipeline);
|
|
154
|
-
const argsHold = (segment) => tokensHold(args, segment.tokens) && (anyArgs.length === 0 || anyArgs.some((wanted) => segment.tokens.some((token) => matches$1(wanted, token))));
|
|
155
|
-
if (names.length > 0) {
|
|
156
|
-
const hit = parts.filter((segment) => names.some((pattern) => matches$1(pattern, segment.name) || segment.wrappers.some((wrapper) => matches$1(pattern, wrapper))));
|
|
157
|
-
if (hit.length === 0) return false;
|
|
158
|
-
if ((args.length > 0 || anyArgs.length > 0) && !hit.some(argsHold)) return false;
|
|
159
|
-
} else if (args.length > 0 || anyArgs.length > 0) {
|
|
160
|
-
if (!parts.some(argsHold)) return false;
|
|
161
|
-
}
|
|
162
|
-
if (pipes.length > 0) {
|
|
163
|
-
if (!parts.slice(1).some((segment) => pipes.some((pattern) => matches$1(pattern, segment.name)))) return false;
|
|
164
|
-
}
|
|
165
|
-
if (shapes.length > 0) {
|
|
166
|
-
const signature = parts.map((segment) => segment.name).join("|");
|
|
167
|
-
if (!shapes.some((pattern) => globMatches(pattern, signature))) return false;
|
|
168
|
-
}
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region ../kernel/src/path.ts
|
|
174
|
-
/**
|
|
175
|
-
* Path normalization and glob containment, with no filesystem access.
|
|
176
|
-
*
|
|
177
|
-
* The contract, stated here because getting it wrong is how path policies
|
|
178
|
-
* become theatre: **this module compares strings.** It resolves `.` and `..`
|
|
179
|
-
* lexically so that `./src/../../etc/passwd` cannot pose as a workspace path,
|
|
180
|
-
* but it cannot see a symlink. A link inside an allowed directory pointing out
|
|
181
|
-
* of it will pass every check here.
|
|
182
|
-
*
|
|
183
|
-
* That is not a gap to paper over in the matcher — it is a gap the caller
|
|
184
|
-
* closes by resolving before it asks. `dsh-overlay-check` learned this the
|
|
185
|
-
* hard way during the plugin-store gate review: lexical containment accepted a
|
|
186
|
-
* symlink escape cleanly, and the fix was to resolve both the path and its
|
|
187
|
-
* nearest existing ancestor before deciding. Adapters that can touch the
|
|
188
|
-
* filesystem must resolve first and pass the resolved path in.
|
|
189
|
-
*/
|
|
190
|
-
/** Split a path into segments, resolving `.` and `..` lexically. */
|
|
191
|
-
function normalize(path) {
|
|
192
|
-
const absolute = path.startsWith("/");
|
|
193
|
-
const out = [];
|
|
194
|
-
let escaped = false;
|
|
195
|
-
for (const raw of path.split(/[/\\]+/)) {
|
|
196
|
-
if (raw === "" || raw === ".") continue;
|
|
197
|
-
if (raw === "..") {
|
|
198
|
-
if (out.length > 0) out.pop();
|
|
199
|
-
else escaped = true;
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
out.push(raw);
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
segments: out,
|
|
206
|
-
absolute,
|
|
207
|
-
escaped
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
/** Turn one glob segment into an anchored regular expression. */
|
|
211
|
-
function segmentPattern(segment) {
|
|
212
|
-
const body = segment.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*");
|
|
213
|
-
return /* @__PURE__ */ new RegExp(`^${body}$`);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Wildcard segment matching, where `**` spans zero or more segments.
|
|
217
|
-
*
|
|
218
|
-
* Two-pointer with backtracking rather than a recursive walk: the pattern
|
|
219
|
-
* comes from a policy pack and the path from a tool call, and a catastrophic
|
|
220
|
-
* backtrack in the hot path of every call would be a denial of service handed
|
|
221
|
-
* to whoever writes the pack.
|
|
222
|
-
*/
|
|
223
|
-
function matchSegments(path, pattern) {
|
|
224
|
-
let i = 0;
|
|
225
|
-
let j = 0;
|
|
226
|
-
let starPattern = -1;
|
|
227
|
-
let starPath = 0;
|
|
228
|
-
while (i < path.length) {
|
|
229
|
-
const segment = j < pattern.length ? pattern[j] : void 0;
|
|
230
|
-
const here = path[i];
|
|
231
|
-
if (segment === "**") {
|
|
232
|
-
starPattern = j;
|
|
233
|
-
starPath = i;
|
|
234
|
-
j += 1;
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
if (segment !== void 0 && here !== void 0 && segmentPattern(segment).test(here)) {
|
|
238
|
-
i += 1;
|
|
239
|
-
j += 1;
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
if (starPattern >= 0) {
|
|
243
|
-
starPath += 1;
|
|
244
|
-
i = starPath;
|
|
245
|
-
j = starPattern + 1;
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
while (j < pattern.length && pattern[j] === "**") j += 1;
|
|
251
|
-
return j === pattern.length;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Is `path` contained by `glob`?
|
|
255
|
-
*
|
|
256
|
-
* A glob naming a directory contains everything under it: `./src` and
|
|
257
|
-
* `./src/**` both match `src/app/main.ts`. Writing the shorter form is the
|
|
258
|
-
* common intent, and treating it as "this exact directory entry only" is a
|
|
259
|
-
* trap that silently grants the whole subtree past the rule.
|
|
260
|
-
*/
|
|
261
|
-
function within(path, glob) {
|
|
262
|
-
const target = normalize(path);
|
|
263
|
-
if (target.escaped) return false;
|
|
264
|
-
const trimmed = glob.trim();
|
|
265
|
-
if (!(trimmed === "**" || trimmed.startsWith("**/")) && target.absolute !== trimmed.startsWith("/")) return false;
|
|
266
|
-
const pattern = normalize(glob);
|
|
267
|
-
if (matchSegments(target.segments, pattern.segments)) return true;
|
|
268
|
-
return matchSegments(target.segments, [...pattern.segments, "**"]);
|
|
269
|
-
}
|
|
270
|
-
/** Is `path` inside any of these globs? */
|
|
271
|
-
function withinAny(path, globs) {
|
|
272
|
-
return globs.some((glob) => within(path, glob));
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* The host of a URL, or undefined when it is not a URL we can read.
|
|
276
|
-
*
|
|
277
|
-
* Unparseable input returns undefined, and callers treat that as "no host" —
|
|
278
|
-
* which for a `notIn` rule means the rule matches. Failing toward the rule is
|
|
279
|
-
* the only safe direction: a string we cannot parse is exactly the shape an
|
|
280
|
-
* evasion attempt takes.
|
|
281
|
-
*/
|
|
282
|
-
function hostOf(url) {
|
|
283
|
-
try {
|
|
284
|
-
return new URL(url).hostname.toLowerCase();
|
|
285
|
-
} catch {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Host list membership, where a leading dot means "this domain or below".
|
|
291
|
-
*
|
|
292
|
-
* `example.com` matches only that host. `.example.com` also matches
|
|
293
|
-
* `api.example.com`, and deliberately still matches `example.com` itself —
|
|
294
|
-
* an operator writing the suffix form means the organisation, not a rule that
|
|
295
|
-
* covers every subdomain except the one they first thought of.
|
|
296
|
-
*/
|
|
297
|
-
function hostIn(host, list$1) {
|
|
298
|
-
return list$1.some((entry) => {
|
|
299
|
-
const want = entry.toLowerCase();
|
|
300
|
-
if (want.startsWith(".")) return host === want.slice(1) || host.endsWith(want);
|
|
301
|
-
return host === want;
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Argument names that conventionally carry a filesystem path, in the order
|
|
306
|
-
* they are tried when a path rule names none.
|
|
307
|
-
*
|
|
308
|
-
* A path rule used to default to the single argument spelled `path`. DeepSeek
|
|
309
|
-
* Harness's own `read`, `write` and `edit` tools pass `file_path`, so every
|
|
310
|
-
* shipped path rule without an explicit `arg` — including the baseline's
|
|
311
|
-
* "deny read ./.env" — matched nothing on the very harness it was written
|
|
312
|
-
* for, while the ledger dutifully recorded every allowed read. A rule that
|
|
313
|
-
* silently never fires is the worst way for policy to be wrong; defaulting
|
|
314
|
-
* to the conventional set is the same call the dsh adapter already made for
|
|
315
|
-
* path resolution, now made once, here, for matching too.
|
|
316
|
-
*/
|
|
317
|
-
const PATH_ARGS = [
|
|
318
|
-
"path",
|
|
319
|
-
"file_path",
|
|
320
|
-
"filePath",
|
|
321
|
-
"target",
|
|
322
|
-
"directory",
|
|
323
|
-
"cwd",
|
|
324
|
-
"file",
|
|
325
|
-
"dest",
|
|
326
|
-
"destination",
|
|
327
|
-
"source"
|
|
328
|
-
];
|
|
329
|
-
/** The first conventional path argument present, as a string, or undefined. */
|
|
330
|
-
function pathArgOf(args, explicit) {
|
|
331
|
-
if (explicit !== void 0) {
|
|
332
|
-
const v = args[explicit];
|
|
333
|
-
return typeof v === "string" ? v : void 0;
|
|
334
|
-
}
|
|
335
|
-
for (const key of PATH_ARGS) {
|
|
336
|
-
const v = args[key];
|
|
337
|
-
if (typeof v === "string") return v;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
//#endregion
|
|
342
|
-
//#region ../kernel/src/rule.ts
|
|
343
|
-
/**
|
|
344
|
-
* Strength ordering, used when several rules match one call.
|
|
345
|
-
*
|
|
346
|
-
* Higher wins. This is the property that makes a pack safe to extend: adding a
|
|
347
|
-
* rule can raise the strength of a decision and never lower it, so an operator
|
|
348
|
-
* appending to a pack can never accidentally widen what an agent may do.
|
|
349
|
-
*/
|
|
350
|
-
const STRENGTH = {
|
|
351
|
-
allow: 0,
|
|
352
|
-
warn: 1,
|
|
353
|
-
correct: 2,
|
|
354
|
-
ask: 3,
|
|
355
|
-
deny: 4
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
//#endregion
|
|
359
|
-
//#region ../kernel/src/evaluate.ts
|
|
360
|
-
function listed(value, want) {
|
|
361
|
-
if (want === void 0) return true;
|
|
362
|
-
if (value === void 0) return false;
|
|
363
|
-
return typeof want === "string" ? value === want : want.includes(value);
|
|
364
|
-
}
|
|
365
|
-
function argMatches(match, args) {
|
|
366
|
-
const has = Object.hasOwn(args, match.name);
|
|
367
|
-
if (match.present !== void 0 && match.present !== has) return false;
|
|
368
|
-
if (!has) return match.above === void 0 && match.below === void 0 && match.equals === void 0 && match.oneOf === void 0;
|
|
369
|
-
const value = args[match.name];
|
|
370
|
-
if (match.above !== void 0) {
|
|
371
|
-
if (typeof value !== "number" || !(value > match.above)) return false;
|
|
372
|
-
}
|
|
373
|
-
if (match.below !== void 0) {
|
|
374
|
-
if (typeof value !== "number" || !(value < match.below)) return false;
|
|
375
|
-
}
|
|
376
|
-
if (match.equals !== void 0 && value !== match.equals) return false;
|
|
377
|
-
if (match.oneOf !== void 0) {
|
|
378
|
-
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return false;
|
|
379
|
-
if (!match.oneOf.includes(value)) return false;
|
|
380
|
-
}
|
|
381
|
-
return true;
|
|
382
|
-
}
|
|
383
|
-
function matches(when, facts) {
|
|
384
|
-
if (!listed(facts.tool, when.tool)) return false;
|
|
385
|
-
if (!listed(facts.capability, when.capability)) return false;
|
|
386
|
-
if (!listed(facts.plugin, when.plugin)) return false;
|
|
387
|
-
if (!listed(facts.agent, when.agent)) return false;
|
|
388
|
-
if (when.command !== void 0) {
|
|
389
|
-
const raw = facts.args.command ?? facts.args.cmd ?? facts.args.script;
|
|
390
|
-
if (typeof raw !== "string") return false;
|
|
391
|
-
if (!commandMatches(when.command, raw)) return false;
|
|
392
|
-
}
|
|
393
|
-
if (when.path !== void 0) {
|
|
394
|
-
const raw = pathArgOf(facts.args, when.path.arg);
|
|
395
|
-
if (typeof raw !== "string") return false;
|
|
396
|
-
if (when.path.inside !== void 0 && !withinAny(raw, when.path.inside)) return false;
|
|
397
|
-
if (when.path.outside !== void 0 && withinAny(raw, when.path.outside)) return false;
|
|
398
|
-
}
|
|
399
|
-
if (when.host !== void 0) {
|
|
400
|
-
const raw = facts.args[when.host.arg ?? "url"];
|
|
401
|
-
if (typeof raw !== "string") return false;
|
|
402
|
-
const host = hostOf(raw);
|
|
403
|
-
if (host === void 0) return when.host.notIn !== void 0;
|
|
404
|
-
if (when.host.in !== void 0 && !hostIn(host, when.host.in)) return false;
|
|
405
|
-
if (when.host.notIn !== void 0 && hostIn(host, when.host.notIn)) return false;
|
|
406
|
-
}
|
|
407
|
-
if (when.arg !== void 0) {
|
|
408
|
-
for (const one of when.arg) if (!argMatches(one, facts.args)) return false;
|
|
409
|
-
}
|
|
410
|
-
if (when.count !== void 0) {
|
|
411
|
-
const key = facts.capability;
|
|
412
|
-
if (key === void 0) return false;
|
|
413
|
-
if (!((facts.counts?.[key] ?? 0) > when.count.above)) return false;
|
|
414
|
-
}
|
|
415
|
-
if (when.secrets !== void 0) {
|
|
416
|
-
const floor = when.secrets.minConfidence ?? 0;
|
|
417
|
-
const wanted = when.secrets.types;
|
|
418
|
-
if ((facts.secrets ?? []).filter((finding) => finding.confidence >= floor && (wanted === void 0 || wanted.includes(finding.type))).length < (when.secrets.atLeast ?? 1)) return false;
|
|
419
|
-
}
|
|
420
|
-
return true;
|
|
421
|
-
}
|
|
422
|
-
function step(rule, effect) {
|
|
423
|
-
return {
|
|
424
|
-
rule: rule.id,
|
|
425
|
-
...rule.title === void 0 ? {} : { title: rule.title },
|
|
426
|
-
effect: effect.kind,
|
|
427
|
-
because: effect.because
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Decide one call against one pack.
|
|
432
|
-
*
|
|
433
|
-
* Every matching rule lands in the trace; the strongest effect decides. Ties
|
|
434
|
-
* go to the first rule in pack order, so a pack reads top-down the way its
|
|
435
|
-
* author wrote it.
|
|
436
|
-
*
|
|
437
|
-
* `correct` is the effect the rest of this ecosystem does not have. A rival
|
|
438
|
-
* guardrail can allow a call or refuse it; a rule here can also rewrite an
|
|
439
|
-
* argument and let it through, recording what it changed. Refusing is not
|
|
440
|
-
* always the safe option — an agent denied mid-task retries, and the retry is
|
|
441
|
-
* rarely safer than the clamp would have been.
|
|
442
|
-
*/
|
|
443
|
-
function evaluate(pack, facts) {
|
|
444
|
-
const hits = [];
|
|
445
|
-
for (const rule of pack.rules) if (matches(rule.when, facts)) hits.push({
|
|
446
|
-
rule,
|
|
447
|
-
effect: rule.effect
|
|
448
|
-
});
|
|
449
|
-
if (hits.length === 0) return {
|
|
450
|
-
kind: "allow",
|
|
451
|
-
trace: [],
|
|
452
|
-
evaluated: pack.rules.length
|
|
453
|
-
};
|
|
454
|
-
hits.sort((a, b) => STRENGTH[b.effect.kind] - STRENGTH[a.effect.kind]);
|
|
455
|
-
const trace = hits.map((hit) => step(hit.rule, hit.effect));
|
|
456
|
-
const evaluated = pack.rules.length;
|
|
457
|
-
const strongest = hits[0];
|
|
458
|
-
if (strongest === void 0) return {
|
|
459
|
-
kind: "allow",
|
|
460
|
-
trace: [],
|
|
461
|
-
evaluated
|
|
462
|
-
};
|
|
463
|
-
const winner = strongest.effect.kind;
|
|
464
|
-
if (winner === "deny" || winner === "ask") return {
|
|
465
|
-
kind: winner,
|
|
466
|
-
rule: strongest.rule.id,
|
|
467
|
-
reason: strongest.effect.because,
|
|
468
|
-
trace,
|
|
469
|
-
evaluated
|
|
470
|
-
};
|
|
471
|
-
if (winner === "correct") {
|
|
472
|
-
const args = { ...facts.args };
|
|
473
|
-
for (const hit of hits) if (hit.effect.kind === "correct") Object.assign(args, hit.effect.set);
|
|
474
|
-
return {
|
|
475
|
-
kind: "correct",
|
|
476
|
-
rule: strongest.rule.id,
|
|
477
|
-
reason: strongest.effect.because,
|
|
478
|
-
args,
|
|
479
|
-
trace,
|
|
480
|
-
evaluated
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
const allowed = hits.find((hit) => hit.effect.kind === "allow");
|
|
484
|
-
if (allowed !== void 0) return {
|
|
485
|
-
kind: "allow",
|
|
486
|
-
rule: allowed.rule.id,
|
|
487
|
-
reason: allowed.effect.because,
|
|
488
|
-
trace,
|
|
489
|
-
evaluated
|
|
490
|
-
};
|
|
491
|
-
return {
|
|
492
|
-
kind: "allow",
|
|
493
|
-
trace,
|
|
494
|
-
evaluated
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
//#endregion
|
|
499
|
-
export { hostOf as n, withinAny as r, evaluate as t };
|
package/lib/src-7X6dO7gC.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { _ as hashEntry, a as signBytes, c as fingerprint, d as signEntry, f as verifyReceipt, g as chain, h as canonical, i as sealedKeypair, l as generateKeypair, m as GENESIS, n as readEntries, o as unsealPrivateKey, p as verifySignature, r as verifyEntries, s as verifyBytes, t as Ledger, u as makeReceipt, v as seal } from "./src-LA7NdLKb.js";
|
|
2
|
-
|
|
3
|
-
export { GENESIS, Ledger, canonical, chain, fingerprint, generateKeypair, hashEntry, makeReceipt, readEntries, seal, sealedKeypair, signBytes, signEntry, unsealPrivateKey, verifyBytes, verifyEntries, verifyReceipt, verifySignature };
|