@agentic-kit/permissions 0.0.0-stage → 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/LICENSE +23 -0
- package/README.md +279 -2
- package/bash/analyze.d.ts +133 -0
- package/bash/analyze.js +442 -0
- package/bash/args.d.ts +45 -0
- package/bash/args.js +145 -0
- package/bash/braces.d.ts +6 -0
- package/bash/braces.js +72 -0
- package/bash/commands.d.ts +14 -0
- package/bash/commands.js +361 -0
- package/bash/file-commands.d.ts +22 -0
- package/bash/file-commands.js +278 -0
- package/bash/flows.d.ts +67 -0
- package/bash/flows.js +208 -0
- package/bash/git.d.ts +7 -0
- package/bash/git.js +163 -0
- package/bash/network.d.ts +24 -0
- package/bash/network.js +295 -0
- package/bash/quoting.d.ts +16 -0
- package/bash/quoting.js +164 -0
- package/bash/system.d.ts +16 -0
- package/bash/system.js +122 -0
- package/bash/tokenize.d.ts +67 -0
- package/bash/tokenize.js +440 -0
- package/bash/words.d.ts +9 -0
- package/bash/words.js +30 -0
- package/bash/wrappers.d.ts +32 -0
- package/bash/wrappers.js +237 -0
- package/classify.d.ts +22 -0
- package/classify.js +259 -0
- package/engine.d.ts +109 -0
- package/engine.js +144 -0
- package/env.d.ts +13 -0
- package/env.js +37 -0
- package/esm/bash/analyze.d.ts +133 -0
- package/esm/bash/analyze.js +405 -0
- package/esm/bash/args.d.ts +45 -0
- package/esm/bash/args.js +135 -0
- package/esm/bash/braces.d.ts +6 -0
- package/esm/bash/braces.js +69 -0
- package/esm/bash/commands.d.ts +14 -0
- package/esm/bash/commands.js +324 -0
- package/esm/bash/file-commands.d.ts +22 -0
- package/esm/bash/file-commands.js +233 -0
- package/esm/bash/flows.d.ts +67 -0
- package/esm/bash/flows.js +203 -0
- package/esm/bash/git.d.ts +7 -0
- package/esm/bash/git.js +127 -0
- package/esm/bash/network.d.ts +24 -0
- package/esm/bash/network.js +282 -0
- package/esm/bash/quoting.d.ts +16 -0
- package/esm/bash/quoting.js +153 -0
- package/esm/bash/system.d.ts +16 -0
- package/esm/bash/system.js +82 -0
- package/esm/bash/tokenize.d.ts +67 -0
- package/esm/bash/tokenize.js +437 -0
- package/esm/bash/words.d.ts +9 -0
- package/esm/bash/words.js +24 -0
- package/esm/bash/wrappers.d.ts +32 -0
- package/esm/bash/wrappers.js +200 -0
- package/esm/classify.d.ts +22 -0
- package/esm/classify.js +223 -0
- package/esm/engine.d.ts +109 -0
- package/esm/engine.js +108 -0
- package/esm/env.d.ts +13 -0
- package/esm/env.js +34 -0
- package/esm/findings.d.ts +7 -0
- package/esm/findings.js +9 -0
- package/esm/glob.d.ts +15 -0
- package/esm/glob.js +69 -0
- package/esm/grants.d.ts +36 -0
- package/esm/grants.js +99 -0
- package/esm/index.d.ts +19 -0
- package/esm/index.js +18 -0
- package/esm/node-fs.d.ts +6 -0
- package/esm/node-fs.js +34 -0
- package/esm/paths.d.ts +43 -0
- package/esm/paths.js +121 -0
- package/esm/policy.d.ts +21 -0
- package/esm/policy.js +85 -0
- package/esm/prompt.d.ts +14 -0
- package/esm/prompt.js +79 -0
- package/esm/roots.d.ts +75 -0
- package/esm/roots.js +148 -0
- package/esm/secret-files.d.ts +16 -0
- package/esm/secret-files.js +84 -0
- package/esm/secrets/collect.d.ts +19 -0
- package/esm/secrets/collect.js +60 -0
- package/esm/secrets/index.d.ts +5 -0
- package/esm/secrets/index.js +5 -0
- package/esm/secrets/parse.d.ts +19 -0
- package/esm/secrets/parse.js +140 -0
- package/esm/secrets/redact-result.d.ts +8 -0
- package/esm/secrets/redact-result.js +67 -0
- package/esm/secrets/rules.d.ts +34 -0
- package/esm/secrets/rules.js +101 -0
- package/esm/secrets/vault.d.ts +48 -0
- package/esm/secrets/vault.js +158 -0
- package/esm/signals.d.ts +14 -0
- package/esm/signals.js +26 -0
- package/esm/tool-input.d.ts +13 -0
- package/esm/tool-input.js +40 -0
- package/esm/types.d.ts +146 -0
- package/esm/types.js +20 -0
- package/findings.d.ts +7 -0
- package/findings.js +13 -0
- package/glob.d.ts +15 -0
- package/glob.js +73 -0
- package/grants.d.ts +36 -0
- package/grants.js +110 -0
- package/index.d.ts +19 -0
- package/index.js +52 -0
- package/node-fs.d.ts +6 -0
- package/node-fs.js +37 -0
- package/package.json +35 -3
- package/paths.d.ts +43 -0
- package/paths.js +164 -0
- package/policy.d.ts +21 -0
- package/policy.js +88 -0
- package/prompt.d.ts +14 -0
- package/prompt.js +83 -0
- package/roots.d.ts +75 -0
- package/roots.js +192 -0
- package/secret-files.d.ts +16 -0
- package/secret-files.js +124 -0
- package/secrets/collect.d.ts +19 -0
- package/secrets/collect.js +96 -0
- package/secrets/index.d.ts +5 -0
- package/secrets/index.js +21 -0
- package/secrets/parse.d.ts +19 -0
- package/secrets/parse.js +145 -0
- package/secrets/redact-result.d.ts +8 -0
- package/secrets/redact-result.js +70 -0
- package/secrets/rules.d.ts +34 -0
- package/secrets/rules.js +107 -0
- package/secrets/vault.d.ts +48 -0
- package/secrets/vault.js +163 -0
- package/signals.d.ts +14 -0
- package/signals.js +29 -0
- package/tool-input.d.ts +13 -0
- package/tool-input.js +46 -0
- package/types.d.ts +146 -0
- package/types.js +24 -0
package/secrets/vault.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The secret vault: the values the model must never see, and the placeholders
|
|
4
|
+
* it sees instead.
|
|
5
|
+
*
|
|
6
|
+
* A value is replaced by `«secret:NAME#h4»`, where `h4` is the first 4 hex
|
|
7
|
+
* chars of HMAC-SHA256(key, value). The key is per install (or per engine), so
|
|
8
|
+
* a placeholder says which secret it stands for without revealing anything
|
|
9
|
+
* about the value. Restoring maps a placeholder back to its value; the engine
|
|
10
|
+
* only does that where it is safe (writes to secret files, approved commands).
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.SecretVault = exports.UNNAMED_TOKEN = exports.PLACEHOLDER_PATTERN = void 0;
|
|
14
|
+
exports.findPlaceholders = findPlaceholders;
|
|
15
|
+
const node_crypto_1 = require("node:crypto");
|
|
16
|
+
const rules_1 = require("./rules");
|
|
17
|
+
exports.PLACEHOLDER_PATTERN = /«secret:([A-Za-z0-9_]+)#([0-9a-f]{4,64})»/g;
|
|
18
|
+
/** The name used for a token-shaped value found in text with no name of its own. */
|
|
19
|
+
exports.UNNAMED_TOKEN = 'TOKEN';
|
|
20
|
+
function sanitizeName(name) {
|
|
21
|
+
return name.replace(/[^A-Za-z0-9_]+/g, '_').replace(/^_+|_+$/g, '') || 'SECRET';
|
|
22
|
+
}
|
|
23
|
+
class SecretVault {
|
|
24
|
+
key;
|
|
25
|
+
byValue = new Map();
|
|
26
|
+
byPlaceholder = new Map();
|
|
27
|
+
origin = new Map();
|
|
28
|
+
sorted = null;
|
|
29
|
+
constructor(key) {
|
|
30
|
+
this.key = key;
|
|
31
|
+
}
|
|
32
|
+
get size() {
|
|
33
|
+
return this.byValue.size;
|
|
34
|
+
}
|
|
35
|
+
/** Register a value. The first name a value gets is the one it keeps. */
|
|
36
|
+
add(name, value, origin = 'host') {
|
|
37
|
+
const existing = this.byValue.get(value);
|
|
38
|
+
if (existing) {
|
|
39
|
+
if (origin === 'host')
|
|
40
|
+
this.origin.set(value, 'host');
|
|
41
|
+
return existing.placeholder;
|
|
42
|
+
}
|
|
43
|
+
const safe = sanitizeName(name);
|
|
44
|
+
const digest = (0, node_crypto_1.createHmac)('sha256', this.key).update(value).digest('hex');
|
|
45
|
+
let placeholder = '';
|
|
46
|
+
for (let len = 4; len <= digest.length; len += 4) {
|
|
47
|
+
placeholder = `«secret:${safe}#${digest.slice(0, len)}»`;
|
|
48
|
+
if (!this.byPlaceholder.has(placeholder))
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
const entry = { name: safe, value, placeholder };
|
|
52
|
+
this.byValue.set(value, entry);
|
|
53
|
+
this.byPlaceholder.set(placeholder, entry);
|
|
54
|
+
this.origin.set(value, origin);
|
|
55
|
+
this.sorted = null;
|
|
56
|
+
return placeholder;
|
|
57
|
+
}
|
|
58
|
+
/** Drop the values from one origin (before re-reading the files). */
|
|
59
|
+
clear(origin) {
|
|
60
|
+
for (const [value, o] of this.origin) {
|
|
61
|
+
if (o !== origin)
|
|
62
|
+
continue;
|
|
63
|
+
const entry = this.byValue.get(value);
|
|
64
|
+
this.byValue.delete(value);
|
|
65
|
+
this.byPlaceholder.delete(entry.placeholder);
|
|
66
|
+
this.origin.delete(value);
|
|
67
|
+
}
|
|
68
|
+
this.sorted = null;
|
|
69
|
+
}
|
|
70
|
+
entries() {
|
|
71
|
+
this.sorted ??= [...this.byValue.values()].sort((a, b) => b.value.length - a.value.length);
|
|
72
|
+
return this.sorted;
|
|
73
|
+
}
|
|
74
|
+
/** Learn token-shaped values in `text` that no source named. */
|
|
75
|
+
discover(text) {
|
|
76
|
+
const lower = text.toLowerCase();
|
|
77
|
+
for (const shape of rules_1.TOKEN_SHAPE_SCANNERS) {
|
|
78
|
+
if (!shape.hints.some((hint) => lower.includes(hint)))
|
|
79
|
+
continue;
|
|
80
|
+
for (const m of text.matchAll(shape.re)) {
|
|
81
|
+
const value = m[1] ?? m[0];
|
|
82
|
+
if (shape.name === 'UrlPassword' && ((0, rules_1.isTrivial)(value) || /[${}]/.test(value)))
|
|
83
|
+
continue;
|
|
84
|
+
if (value.length >= rules_1.MIN_SECRET_LENGTH && !this.byValue.has(value))
|
|
85
|
+
this.add(exports.UNNAMED_TOKEN, value, 'token');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Replace every known value, longest first, with its placeholder. */
|
|
90
|
+
redact(text) {
|
|
91
|
+
if (!text)
|
|
92
|
+
return { text, changed: false };
|
|
93
|
+
this.discover(text);
|
|
94
|
+
const claimed = new Uint8Array(text.length);
|
|
95
|
+
const hits = [];
|
|
96
|
+
for (const entry of this.entries()) {
|
|
97
|
+
const len = entry.value.length;
|
|
98
|
+
for (let at = text.indexOf(entry.value); at >= 0; at = text.indexOf(entry.value, at + 1)) {
|
|
99
|
+
let free = true;
|
|
100
|
+
for (let k = at; k < at + len; k++) {
|
|
101
|
+
if (claimed[k]) {
|
|
102
|
+
free = false;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!free)
|
|
107
|
+
continue;
|
|
108
|
+
claimed.fill(1, at, at + len);
|
|
109
|
+
hits.push({ start: at, end: at + len, placeholder: entry.placeholder });
|
|
110
|
+
at += len - 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (hits.length === 0)
|
|
114
|
+
return { text, changed: false };
|
|
115
|
+
hits.sort((a, b) => a.start - b.start);
|
|
116
|
+
let out = '';
|
|
117
|
+
let last = 0;
|
|
118
|
+
for (const hit of hits) {
|
|
119
|
+
out += text.slice(last, hit.start) + hit.placeholder;
|
|
120
|
+
last = hit.end;
|
|
121
|
+
}
|
|
122
|
+
return { text: out + text.slice(last), changed: true };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A known value runs across the boundary between two of `parts` (adjacent
|
|
126
|
+
* text blocks), so redacting each part alone would leave both halves.
|
|
127
|
+
*/
|
|
128
|
+
crossesBoundary(parts) {
|
|
129
|
+
const joined = parts.join('');
|
|
130
|
+
this.discover(joined);
|
|
131
|
+
const bounds = [];
|
|
132
|
+
let offset = 0;
|
|
133
|
+
for (const part of parts.slice(0, -1))
|
|
134
|
+
bounds.push((offset += part.length));
|
|
135
|
+
for (const entry of this.entries()) {
|
|
136
|
+
for (let at = joined.indexOf(entry.value); at >= 0; at = joined.indexOf(entry.value, at + 1)) {
|
|
137
|
+
const end = at + entry.value.length;
|
|
138
|
+
if (bounds.some((b) => b > at && b < end))
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
/** Put real values back for known placeholders. Unknown placeholders stay. */
|
|
145
|
+
restore(text) {
|
|
146
|
+
return text.replace(exports.PLACEHOLDER_PATTERN, (m) => this.byPlaceholder.get(m)?.value ?? m);
|
|
147
|
+
}
|
|
148
|
+
/** The secret a text carries: a known value or a placeholder. */
|
|
149
|
+
findSecret(text) {
|
|
150
|
+
const placeholder = findPlaceholders(text)[0];
|
|
151
|
+
if (placeholder)
|
|
152
|
+
return { name: /«secret:([A-Za-z0-9_]+)#/.exec(placeholder)[1], kind: 'placeholder' };
|
|
153
|
+
for (const entry of this.entries()) {
|
|
154
|
+
if (text.includes(entry.value))
|
|
155
|
+
return { name: entry.name, kind: 'value' };
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.SecretVault = SecretVault;
|
|
161
|
+
function findPlaceholders(text) {
|
|
162
|
+
return [...text.matchAll(exports.PLACEHOLDER_PATTERN)].map((m) => m[0]);
|
|
163
|
+
}
|
package/signals.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How each signal moves a decision, in one table so a new signal cannot be
|
|
3
|
+
* left out: when it makes a call ask, and whether a grant may cover it. A
|
|
4
|
+
* hard-deny or protected-write target is denied by its zone before this applies.
|
|
5
|
+
*/
|
|
6
|
+
import type { Signal } from './types';
|
|
7
|
+
interface SignalRule {
|
|
8
|
+
/** `always`: in every mode, Full included. `unless-full`: in Ask and Workspace mode. `never`: it only informs the card. */
|
|
9
|
+
asks: 'always' | 'unless-full' | 'never';
|
|
10
|
+
/** A grant may cover a call that raised it; otherwise each such call needs its own yes. */
|
|
11
|
+
grantable: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const SIGNAL_RULES: Readonly<Record<Signal, SignalRule>>;
|
|
14
|
+
export {};
|
package/signals.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* How each signal moves a decision, in one table so a new signal cannot be
|
|
4
|
+
* left out: when it makes a call ask, and whether a grant may cover it. A
|
|
5
|
+
* hard-deny or protected-write target is denied by its zone before this applies.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.SIGNAL_RULES = void 0;
|
|
9
|
+
const ASKS = { asks: 'unless-full', grantable: true };
|
|
10
|
+
exports.SIGNAL_RULES = {
|
|
11
|
+
'secret-file': { asks: 'never', grantable: true },
|
|
12
|
+
'outside-workspace': ASKS,
|
|
13
|
+
'hard-deny': { asks: 'never', grantable: false },
|
|
14
|
+
'protected-write': { asks: 'never', grantable: false },
|
|
15
|
+
'ask-write': ASKS,
|
|
16
|
+
'shell-dynamic': ASKS,
|
|
17
|
+
sudo: ASKS,
|
|
18
|
+
upload: ASKS,
|
|
19
|
+
destructive: ASKS,
|
|
20
|
+
'placeholder-in-command': { asks: 'always', grantable: false },
|
|
21
|
+
'secret-into-plain-file': { asks: 'unless-full', grantable: false },
|
|
22
|
+
'unresolvable-path': { asks: 'always', grantable: false },
|
|
23
|
+
'stdin-operands': ASKS,
|
|
24
|
+
persistence: ASKS,
|
|
25
|
+
'network-exposure': ASKS,
|
|
26
|
+
clipboard: ASKS,
|
|
27
|
+
'secret-transform': ASKS,
|
|
28
|
+
'secret-env-expansion': ASKS
|
|
29
|
+
};
|
package/tool-input.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape of pi's built-in tool inputs, in one place: `path`, `command` and
|
|
3
|
+
* `glob` strings, a write's `content`, and an edit's `edits[]` of
|
|
4
|
+
* `{ oldText, newText }` (older callers send `oldText`/`newText` at the top).
|
|
5
|
+
*/
|
|
6
|
+
import type { BuiltinTool } from './types';
|
|
7
|
+
export declare function stringField(input: Record<string, unknown>, key: string): string | undefined;
|
|
8
|
+
/** The new text a write or edit puts in the file. */
|
|
9
|
+
export declare function newTexts(toolName: BuiltinTool, input: Record<string, unknown>): string[];
|
|
10
|
+
/** Rewrite, in place, every text field of a write or edit input. */
|
|
11
|
+
export declare function mapWriteTexts(input: Record<string, unknown>, fn: (text: string) => string): void;
|
|
12
|
+
/** Rewrite, in place, a bash input's command. */
|
|
13
|
+
export declare function mapCommand(input: Record<string, unknown>, fn: (text: string) => string): void;
|
package/tool-input.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The shape of pi's built-in tool inputs, in one place: `path`, `command` and
|
|
4
|
+
* `glob` strings, a write's `content`, and an edit's `edits[]` of
|
|
5
|
+
* `{ oldText, newText }` (older callers send `oldText`/`newText` at the top).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.stringField = stringField;
|
|
9
|
+
exports.newTexts = newTexts;
|
|
10
|
+
exports.mapWriteTexts = mapWriteTexts;
|
|
11
|
+
exports.mapCommand = mapCommand;
|
|
12
|
+
function stringField(input, key) {
|
|
13
|
+
const v = input[key];
|
|
14
|
+
return typeof v === 'string' ? v : undefined;
|
|
15
|
+
}
|
|
16
|
+
function editsOf(input) {
|
|
17
|
+
const edits = Array.isArray(input.edits) ? input.edits : [];
|
|
18
|
+
return edits.filter((e) => Boolean(e) && typeof e === 'object');
|
|
19
|
+
}
|
|
20
|
+
/** The new text a write or edit puts in the file. */
|
|
21
|
+
function newTexts(toolName, input) {
|
|
22
|
+
if (toolName === 'write')
|
|
23
|
+
return [stringField(input, 'content') ?? ''];
|
|
24
|
+
const texts = editsOf(input)
|
|
25
|
+
.map((e) => e.newText)
|
|
26
|
+
.filter((t) => typeof t === 'string');
|
|
27
|
+
const legacy = stringField(input, 'newText');
|
|
28
|
+
return legacy === undefined ? texts : [...texts, legacy];
|
|
29
|
+
}
|
|
30
|
+
function mapFields(target, keys, fn) {
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
const value = target[key];
|
|
33
|
+
if (typeof value === 'string')
|
|
34
|
+
target[key] = fn(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Rewrite, in place, every text field of a write or edit input. */
|
|
38
|
+
function mapWriteTexts(input, fn) {
|
|
39
|
+
mapFields(input, ['content', 'oldText', 'newText'], fn);
|
|
40
|
+
for (const edit of editsOf(input))
|
|
41
|
+
mapFields(edit, ['oldText', 'newText'], fn);
|
|
42
|
+
}
|
|
43
|
+
/** Rewrite, in place, a bash input's command. */
|
|
44
|
+
function mapCommand(input, fn) {
|
|
45
|
+
mapFields(input, ['command'], fn);
|
|
46
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared vocabulary of the permissions layer. Everything here is plain data
|
|
3
|
+
* so a host can store it, show it, and assert on it in a test.
|
|
4
|
+
*/
|
|
5
|
+
/** How much the agent may do without asking. The hard-deny list, redaction and
|
|
6
|
+
* self-protection apply in every mode; the mode only moves the defaults. */
|
|
7
|
+
export type PermissionMode = 'ask' | 'workspace' | 'full';
|
|
8
|
+
export declare const PERMISSION_MODES: readonly PermissionMode[];
|
|
9
|
+
export declare const DEFAULT_PERMISSION_MODE: PermissionMode;
|
|
10
|
+
/** The pi built-in tools this layer owns. Every other tool belongs to another
|
|
11
|
+
* gate (the DB gate) or to trusted host code, and the layer abstains on it. */
|
|
12
|
+
export type BuiltinTool = 'read' | 'write' | 'edit' | 'bash' | 'grep' | 'find' | 'ls';
|
|
13
|
+
export type Access = 'read' | 'write' | 'exec';
|
|
14
|
+
export type RequestKind = 'read' | 'write' | 'exec';
|
|
15
|
+
/** What each built-in does: the request kind it makes. */
|
|
16
|
+
export declare const TOOL_KIND: Readonly<Record<BuiltinTool, RequestKind>>;
|
|
17
|
+
export declare const BUILTIN_TOOLS: ReadonlySet<string>;
|
|
18
|
+
export declare function isBuiltinTool(name: string): name is BuiltinTool;
|
|
19
|
+
/**
|
|
20
|
+
* Where a canonical path sits. Computed from the roots, most specific first:
|
|
21
|
+
* `hard-deny` and `protected` win over `workspace`, so `.pi/` inside the
|
|
22
|
+
* workspace is `protected`, and a credential file under a temp dir is `hard-deny`.
|
|
23
|
+
*/
|
|
24
|
+
export type Zone = 'workspace' | 'trusted' | 'temp' | 'outside' | 'hard-deny' | 'protected' | 'ask-write' | 'unresolvable';
|
|
25
|
+
export interface Target {
|
|
26
|
+
/** The path as the agent wrote it. */
|
|
27
|
+
raw: string;
|
|
28
|
+
/** Absolute and canonical (realpath of the deepest existing ancestor). */
|
|
29
|
+
path: string;
|
|
30
|
+
access: Access;
|
|
31
|
+
zone: Zone;
|
|
32
|
+
/** The file name matches a secret-file pattern (`.env`, `*.pem`, …). */
|
|
33
|
+
secretFile: boolean;
|
|
34
|
+
/** What the zone's root is, in words: "SSH keys", "git hook", "project". */
|
|
35
|
+
label: string;
|
|
36
|
+
/** The path holds an unexpanded glob (`~/.ss?/*`): no path grant covers it outside the project. */
|
|
37
|
+
glob?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export type Signal = 'secret-file' | 'outside-workspace' | 'hard-deny' | 'protected-write' | 'ask-write' | 'shell-dynamic' | 'sudo' | 'upload' | 'destructive' | 'placeholder-in-command' | 'secret-into-plain-file' | 'unresolvable-path'
|
|
40
|
+
/** `xargs` or an archiver takes file names from stdin that the analyzer cannot see. */
|
|
41
|
+
| 'stdin-operands'
|
|
42
|
+
/** `crontab`, `at`, `launchctl load`, `defaults write`: a change that outlasts the session. */
|
|
43
|
+
| 'persistence'
|
|
44
|
+
/** A dev server on a public interface, or a tunnel (`ngrok`, `ssh -R`). */
|
|
45
|
+
| 'network-exposure'
|
|
46
|
+
/** `pbcopy`, `pbpaste`, `xclip`, … */
|
|
47
|
+
| 'clipboard'
|
|
48
|
+
/** A secret file read by a program that may change its text, so redaction cannot match it. */
|
|
49
|
+
| 'secret-transform'
|
|
50
|
+
/** The command expands a variable whose name looks secret, or that the host marked secret. */
|
|
51
|
+
| 'secret-env-expansion';
|
|
52
|
+
/** One tool call, classified. */
|
|
53
|
+
export interface PermissionRequest {
|
|
54
|
+
toolCallId: string;
|
|
55
|
+
toolName: BuiltinTool;
|
|
56
|
+
kind: RequestKind;
|
|
57
|
+
targets: Target[];
|
|
58
|
+
/** bash only: the command with whitespace collapsed (the grant key). */
|
|
59
|
+
command?: string;
|
|
60
|
+
signals: Signal[];
|
|
61
|
+
/** One specific sentence for each signal ("it uploads data: curl -d @.env sends a file's contents"). */
|
|
62
|
+
signalReasons: Partial<Record<Signal, string>>;
|
|
63
|
+
}
|
|
64
|
+
export type PermissionVerdict = 'allow' | 'ask' | 'deny';
|
|
65
|
+
/** What a grant matches. Never a tool name alone. */
|
|
66
|
+
export type GrantMatch = {
|
|
67
|
+
type: 'path';
|
|
68
|
+
access: Access;
|
|
69
|
+
pathPrefix: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: 'command';
|
|
72
|
+
command: string;
|
|
73
|
+
};
|
|
74
|
+
export type GrantScope = 'chat' | 'project';
|
|
75
|
+
export interface Grant {
|
|
76
|
+
scope: GrantScope;
|
|
77
|
+
match: GrantMatch;
|
|
78
|
+
createdAt: string;
|
|
79
|
+
}
|
|
80
|
+
/** A scope the user can pick on an ASK, with the exact pattern it would save. */
|
|
81
|
+
export interface GrantOption {
|
|
82
|
+
scope: GrantScope;
|
|
83
|
+
/** "Allow in this chat", "Always: reads in ~/work/lib/". */
|
|
84
|
+
label: string;
|
|
85
|
+
/** The human-readable pattern ("~/work/lib/", "pnpm dlx shadcn add button"). */
|
|
86
|
+
pattern: string;
|
|
87
|
+
match: GrantMatch;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The decision for one call. It is self-contained: an `ask` carries the card
|
|
91
|
+
* to show and the scopes the user may grant, so a host needs nothing else
|
|
92
|
+
* from the engine to put the question in front of a person.
|
|
93
|
+
*/
|
|
94
|
+
export type PermissionDecision = {
|
|
95
|
+
decision: 'allow';
|
|
96
|
+
reason: string;
|
|
97
|
+
request: PermissionRequest;
|
|
98
|
+
} | {
|
|
99
|
+
decision: 'deny';
|
|
100
|
+
reason: string;
|
|
101
|
+
request: PermissionRequest;
|
|
102
|
+
} | {
|
|
103
|
+
decision: 'ask';
|
|
104
|
+
reason: string;
|
|
105
|
+
request: PermissionRequest;
|
|
106
|
+
prompt: PermissionPrompt;
|
|
107
|
+
/** The scopes the user may grant. Empty when a grant is not allowed. */
|
|
108
|
+
grantOptions: GrantOption[];
|
|
109
|
+
};
|
|
110
|
+
/** What a host puts in front of the user for one ASK (`ApprovalRequest.permission` in `@agentic-kit/harness`). */
|
|
111
|
+
export interface PermissionPrompt {
|
|
112
|
+
title: string;
|
|
113
|
+
summary: string;
|
|
114
|
+
toolName: string;
|
|
115
|
+
kind: RequestKind;
|
|
116
|
+
command?: string;
|
|
117
|
+
targets: {
|
|
118
|
+
path: string;
|
|
119
|
+
access: Access;
|
|
120
|
+
zone: Zone;
|
|
121
|
+
}[];
|
|
122
|
+
signals: Signal[];
|
|
123
|
+
/** One plain sentence per signal, in order. */
|
|
124
|
+
reasons: string[];
|
|
125
|
+
grantOptions: {
|
|
126
|
+
scope: GrantScope;
|
|
127
|
+
label: string;
|
|
128
|
+
pattern: string;
|
|
129
|
+
}[];
|
|
130
|
+
}
|
|
131
|
+
/** The filesystem the engine needs. Injected so the pure modules stay testable. */
|
|
132
|
+
export interface FsProbe {
|
|
133
|
+
/** Resolve symlinks; reject when the path does not exist. */
|
|
134
|
+
realpath(path: string): Promise<string>;
|
|
135
|
+
/** `true` when an entry exists at the path itself (a dangling link included). */
|
|
136
|
+
lexists(path: string): Promise<boolean>;
|
|
137
|
+
readFile(path: string): Promise<string>;
|
|
138
|
+
/** The entries of a directory. */
|
|
139
|
+
readDir(path: string): Promise<DirEntry[]>;
|
|
140
|
+
/** File size in bytes, so large files are skipped before they are read. */
|
|
141
|
+
size(path: string): Promise<number>;
|
|
142
|
+
}
|
|
143
|
+
export interface DirEntry {
|
|
144
|
+
name: string;
|
|
145
|
+
kind: 'file' | 'dir' | 'symlink' | 'other';
|
|
146
|
+
}
|
package/types.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The shared vocabulary of the permissions layer. Everything here is plain data
|
|
4
|
+
* so a host can store it, show it, and assert on it in a test.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.BUILTIN_TOOLS = exports.TOOL_KIND = exports.DEFAULT_PERMISSION_MODE = exports.PERMISSION_MODES = void 0;
|
|
8
|
+
exports.isBuiltinTool = isBuiltinTool;
|
|
9
|
+
exports.PERMISSION_MODES = ['ask', 'workspace', 'full'];
|
|
10
|
+
exports.DEFAULT_PERMISSION_MODE = 'workspace';
|
|
11
|
+
/** What each built-in does: the request kind it makes. */
|
|
12
|
+
exports.TOOL_KIND = {
|
|
13
|
+
read: 'read',
|
|
14
|
+
write: 'write',
|
|
15
|
+
edit: 'write',
|
|
16
|
+
bash: 'exec',
|
|
17
|
+
grep: 'read',
|
|
18
|
+
find: 'read',
|
|
19
|
+
ls: 'read'
|
|
20
|
+
};
|
|
21
|
+
exports.BUILTIN_TOOLS = new Set(Object.keys(exports.TOOL_KIND));
|
|
22
|
+
function isBuiltinTool(name) {
|
|
23
|
+
return exports.BUILTIN_TOOLS.has(name);
|
|
24
|
+
}
|