@operad-io/access-match 0.1.0 → 0.2.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/access-grants.schema.json +54 -0
- package/package.json +3 -2
- package/src/command.ts +100 -0
- package/src/index.ts +446 -24
- package/src/outward.ts +302 -0
- package/src/readonly.ts +71 -9
- package/src/summary.ts +176 -1
- package/src/target-grants.ts +258 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://operad.io/schemas/access-grants.schema.json",
|
|
4
|
+
"title": "operad access target grants",
|
|
5
|
+
"description": "The outward targets a background run may write to without asking, in $OPERAD_HOME/access-grants.json (ADR 0025 D12). Each grant is bound to one flow definition identity and one target. The flows list keeps the definition digest last seen and its generated identity, so an edit gives a new identity even when it is later reverted.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"flows": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"description": "The flow definition identities last seen.",
|
|
12
|
+
"items": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"additionalProperties": false,
|
|
15
|
+
"properties": {
|
|
16
|
+
"flow": { "type": "string", "minLength": 1, "description": "The flow's name." },
|
|
17
|
+
"digest": { "type": "string", "minLength": 1, "description": "The digest of the definition last seen." },
|
|
18
|
+
"id": { "type": "string", "minLength": 1, "description": "The generated identity of that definition; a change makes a new one." }
|
|
19
|
+
},
|
|
20
|
+
"required": ["flow", "digest", "id"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"grants": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"description": "The targets a person allowed for one flow definition.",
|
|
26
|
+
"items": {
|
|
27
|
+
"type": "object",
|
|
28
|
+
"additionalProperties": false,
|
|
29
|
+
"properties": {
|
|
30
|
+
"flow": { "type": "string", "minLength": 1, "description": "The flow the grant belongs to." },
|
|
31
|
+
"definition": { "type": "string", "minLength": 1, "description": "The definition identity the person answered for." },
|
|
32
|
+
"kind": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"enum": ["channel", "mail", "post", "repository", "service", "command"],
|
|
35
|
+
"description": "What kind of outward write the target takes."
|
|
36
|
+
},
|
|
37
|
+
"target": { "type": "string", "minLength": 1, "description": "The exact target, as the question names it." },
|
|
38
|
+
"by": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"additionalProperties": false,
|
|
41
|
+
"properties": {
|
|
42
|
+
"via": { "type": "string", "minLength": 1, "description": "The client the person answered from." },
|
|
43
|
+
"id": { "type": "string", "minLength": 1, "description": "Who answered, as the client names them." }
|
|
44
|
+
},
|
|
45
|
+
"required": ["via", "id"]
|
|
46
|
+
},
|
|
47
|
+
"at": { "type": "number", "description": "When the person answered, in epoch milliseconds." }
|
|
48
|
+
},
|
|
49
|
+
"required": ["flow", "definition", "kind", "target", "by", "at"]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"required": ["flows", "grants"]
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/access-match",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@operad-io/engine": "0.
|
|
9
|
+
"@operad-io/engine": "0.2.0"
|
|
10
10
|
},
|
|
11
11
|
"description": "operad: access profiles matched against agent tool calls",
|
|
12
12
|
"repository": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"files": [
|
|
19
19
|
"src",
|
|
20
|
+
"access-grants.schema.json",
|
|
20
21
|
"README.md",
|
|
21
22
|
"LICENSE"
|
|
22
23
|
]
|
package/src/command.ts
CHANGED
|
@@ -227,6 +227,106 @@ export function inlineFormOf(part: Part): string | undefined {
|
|
|
227
227
|
return undefined;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
/** The argument of the first option whose single-dash letters include `letter`. */
|
|
231
|
+
function optionArgument(args: readonly string[], letter: string): string | undefined {
|
|
232
|
+
const at = args.findIndex((arg) => CLUSTER.test(arg) && arg.slice(1).includes(letter));
|
|
233
|
+
return at === -1 ? undefined : args[at + 1];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The index of the `)` that closes the `(` at `open`, or -1. */
|
|
237
|
+
function closingParen(text: string, open: number): number {
|
|
238
|
+
let depth = 0;
|
|
239
|
+
let i = open;
|
|
240
|
+
while (i < text.length) {
|
|
241
|
+
const c = text.charAt(i);
|
|
242
|
+
if (c === "'") {
|
|
243
|
+
const close = text.indexOf("'", i + 1);
|
|
244
|
+
if (close === -1) return -1;
|
|
245
|
+
i = close + 1;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (c === '"') {
|
|
249
|
+
i += 1;
|
|
250
|
+
while (i < text.length && text.charAt(i) !== '"') i += text.charAt(i) === "\\" ? 2 : 1;
|
|
251
|
+
i += 1;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (c === "\\") {
|
|
255
|
+
i += 2;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (c === "(") depth += 1;
|
|
259
|
+
if (c === ")" && --depth === 0) return i;
|
|
260
|
+
i += 1;
|
|
261
|
+
}
|
|
262
|
+
return -1;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The text inside each command, process or backtick substitution, outside single quotes. */
|
|
266
|
+
function substitutionContents(command: string): string[] {
|
|
267
|
+
const found: string[] = [];
|
|
268
|
+
let i = 0;
|
|
269
|
+
while (i < command.length) {
|
|
270
|
+
const c = command.charAt(i);
|
|
271
|
+
const next = command.charAt(i + 1);
|
|
272
|
+
if (c === "'") {
|
|
273
|
+
const close = command.indexOf("'", i + 1);
|
|
274
|
+
if (close === -1) return found;
|
|
275
|
+
i = close + 1;
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (c === "\\") {
|
|
279
|
+
i += 2;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (c === "`") {
|
|
283
|
+
const close = command.indexOf("`", i + 1);
|
|
284
|
+
if (close === -1) return found;
|
|
285
|
+
found.push(command.slice(i + 1, close));
|
|
286
|
+
i = close + 1;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if ((c === "$" || c === "<" || c === ">") && next === "(") {
|
|
290
|
+
const close = closingParen(command, i + 1);
|
|
291
|
+
if (close === -1) return found;
|
|
292
|
+
found.push(command.slice(i + 2, close));
|
|
293
|
+
i = close + 1;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
i += 1;
|
|
297
|
+
}
|
|
298
|
+
return found;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* What a command's inline code or shell substitutions plainly contain, for a
|
|
303
|
+
* deny check where the matcher lets their effect through (ADR 0025 D8, D9).
|
|
304
|
+
*/
|
|
305
|
+
export function unreadableContentsOf(command: string, parts: readonly Part[]): string[] {
|
|
306
|
+
const found: string[] = [];
|
|
307
|
+
const add = (text: string | undefined): void => {
|
|
308
|
+
if (text !== undefined && text.trim().length > 0 && !found.includes(text)) found.push(text);
|
|
309
|
+
};
|
|
310
|
+
for (const part of parts) {
|
|
311
|
+
for (const level of levels(part.words)) {
|
|
312
|
+
const name = baseName(level.at(0) ?? "");
|
|
313
|
+
const args = level.slice(1);
|
|
314
|
+
if ((SHELLS.has(name) || /^python[0-9.]*$/.test(name)) && letters(args).has("c")) {
|
|
315
|
+
add(optionArgument(args, "c"));
|
|
316
|
+
} else if (INLINE_E.has(name) && letters(args).has("e")) {
|
|
317
|
+
add(optionArgument(args, "e"));
|
|
318
|
+
} else if (name === "find") {
|
|
319
|
+
const at = args.findIndex((arg) => FIND_EXEC.has(arg));
|
|
320
|
+
if (at !== -1) add(args.slice(at + 1).join(" "));
|
|
321
|
+
} else if (name === "xargs" || name === "eval") {
|
|
322
|
+
add(args.join(" "));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
for (const content of substitutionContents(command)) add(content);
|
|
327
|
+
return found;
|
|
328
|
+
}
|
|
329
|
+
|
|
230
330
|
function glob(pattern: string): RegExp {
|
|
231
331
|
const source = pattern
|
|
232
332
|
.split("*")
|