@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/policy.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The decision for a classified request. First match wins:
|
|
4
|
+
*
|
|
5
|
+
* 1. a hard-deny or protected-write target: DENY (no grant changes this)
|
|
6
|
+
* 2. a user deny rule: DENY (reserved; no rule UI in v1)
|
|
7
|
+
* 3. a chat grant, then a project grant, that covers the request: ALLOW
|
|
8
|
+
* 4. a user allow rule: ALLOW (reserved)
|
|
9
|
+
* 5. the mode default (see `modeDefault`)
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.decide = decide;
|
|
13
|
+
const grants_1 = require("./grants");
|
|
14
|
+
const paths_1 = require("./paths");
|
|
15
|
+
const prompt_1 = require("./prompt");
|
|
16
|
+
const signals_1 = require("./signals");
|
|
17
|
+
const ING = { read: 'reading', write: 'writing', exec: 'running' };
|
|
18
|
+
/** The classifier's sentence for a signal. */
|
|
19
|
+
function reasonFor(signal, request) {
|
|
20
|
+
return request.signalReasons[signal] ?? signal;
|
|
21
|
+
}
|
|
22
|
+
function blockedTarget(request) {
|
|
23
|
+
return request.targets.find((t) => t.zone === 'hard-deny' || (t.zone === 'protected' && t.access === 'write'));
|
|
24
|
+
}
|
|
25
|
+
function denyReason(request, target, ctx) {
|
|
26
|
+
const shown = (0, paths_1.showPath)(target.path, ctx.workspace, ctx.homeDir);
|
|
27
|
+
const bash = request.toolName === 'bash';
|
|
28
|
+
if (target.zone === 'hard-deny') {
|
|
29
|
+
const what = bash ? `this command ${grants_1.ACCESS_VERB[target.access]} ${shown}, which` : `${ING[target.access]} ${shown}`;
|
|
30
|
+
return `permissions: ${what} is not allowed (${target.label}; blocked in every mode)`;
|
|
31
|
+
}
|
|
32
|
+
const what = bash ? `this command writes ${shown}, which` : `writing ${shown}`;
|
|
33
|
+
return `permissions: ${what} is not allowed (${target.label}; protected in every mode)`;
|
|
34
|
+
}
|
|
35
|
+
/** What the request is, for a reason: "reading /etc/hosts", "this command". */
|
|
36
|
+
function describe(request, ctx) {
|
|
37
|
+
if (request.toolName === 'bash')
|
|
38
|
+
return 'this command';
|
|
39
|
+
const shown = request.targets.map((t) => (0, paths_1.showPath)(t.path, ctx.workspace, ctx.homeDir)).join(', ');
|
|
40
|
+
const verb = request.toolName === 'edit' ? 'editing' : ING[request.targets[0]?.access ?? 'read'];
|
|
41
|
+
return `${verb} ${shown}`;
|
|
42
|
+
}
|
|
43
|
+
/** The mode default (step 5): the sentences that make it ask; empty means allow. */
|
|
44
|
+
function modeDefault(request, mode) {
|
|
45
|
+
const asks = (s) => {
|
|
46
|
+
const rule = signals_1.SIGNAL_RULES[s].asks;
|
|
47
|
+
return rule === 'always' || (rule === 'unless-full' && mode !== 'full');
|
|
48
|
+
};
|
|
49
|
+
const reasons = request.signals.filter(asks).map((s) => reasonFor(s, request));
|
|
50
|
+
if (mode === 'ask') {
|
|
51
|
+
if (request.kind === 'write')
|
|
52
|
+
reasons.push('Ask mode asks before every file change');
|
|
53
|
+
if (request.kind === 'exec')
|
|
54
|
+
reasons.push('Ask mode asks before every command');
|
|
55
|
+
}
|
|
56
|
+
return reasons;
|
|
57
|
+
}
|
|
58
|
+
function decide(request, ctx) {
|
|
59
|
+
const allow = (reason) => ({ decision: 'allow', reason, request });
|
|
60
|
+
const deny = (reason) => ({ decision: 'deny', reason, request });
|
|
61
|
+
const blocked = blockedTarget(request);
|
|
62
|
+
if (blocked)
|
|
63
|
+
return deny(denyReason(request, blocked, ctx));
|
|
64
|
+
if (ctx.rules?.deny?.some((m) => (0, grants_1.matchCovers)(m, request))) {
|
|
65
|
+
return deny(`permissions: ${describe(request, ctx)} is blocked by a deny rule`);
|
|
66
|
+
}
|
|
67
|
+
const grant = (0, grants_1.findGrant)(ctx.grants, request);
|
|
68
|
+
if (grant)
|
|
69
|
+
return allow(`permissions: allowed by a ${grant.scope} grant`);
|
|
70
|
+
if (ctx.rules?.allow?.some((m) => (0, grants_1.matchCovers)(m, request)) && !request.signals.includes('unresolvable-path')) {
|
|
71
|
+
return allow('permissions: allowed by an allow rule');
|
|
72
|
+
}
|
|
73
|
+
const asks = modeDefault(request, ctx.mode);
|
|
74
|
+
if (asks.length === 0)
|
|
75
|
+
return allow(`permissions: allowed in ${ctx.mode} mode`);
|
|
76
|
+
// The card leads with why it asks, then adds what else the user should know
|
|
77
|
+
// (a secret file's values reach the model only as placeholders).
|
|
78
|
+
const explained = request.signals.map((s) => reasonFor(s, request));
|
|
79
|
+
const reasons = [...new Set([...asks, ...explained])];
|
|
80
|
+
const grantOptions = (0, grants_1.grantOptionsFor)(request, ctx.homeDir);
|
|
81
|
+
return {
|
|
82
|
+
decision: 'ask',
|
|
83
|
+
reason: `permissions: ${describe(request, ctx)} needs approval: ${asks.join('; ')}`,
|
|
84
|
+
request,
|
|
85
|
+
grantOptions,
|
|
86
|
+
prompt: (0, prompt_1.buildPrompt)(request, reasons, grantOptions, ctx)
|
|
87
|
+
};
|
|
88
|
+
}
|
package/prompt.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The approval card for an ASK: a title, what it touches, and why it asks. */
|
|
2
|
+
import type { GrantOption, PermissionPrompt, PermissionRequest } from './types';
|
|
3
|
+
/** The most specific title, by signal priority. */
|
|
4
|
+
export declare function promptTitle(request: PermissionRequest): string;
|
|
5
|
+
export interface PromptDisplay {
|
|
6
|
+
workspace: string | undefined;
|
|
7
|
+
homeDir: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The card for an ASK. `reasons` are the sentences the policy asked for, in
|
|
11
|
+
* order. With one target and no command, the card shows the path in its own
|
|
12
|
+
* row, so a reason that opens with that path says "it" instead.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildPrompt(request: PermissionRequest, reasons: readonly string[], grantOptions: readonly GrantOption[], display: PromptDisplay): PermissionPrompt;
|
package/prompt.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** The approval card for an ASK: a title, what it touches, and why it asks. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.promptTitle = promptTitle;
|
|
5
|
+
exports.buildPrompt = buildPrompt;
|
|
6
|
+
const paths_1 = require("./paths");
|
|
7
|
+
/** The title of a write to a file that runs code later, by the label of its root. */
|
|
8
|
+
const ASK_WRITE_TITLES = {
|
|
9
|
+
'git hook': 'Write to a git hook',
|
|
10
|
+
'git config': 'Change the git config',
|
|
11
|
+
'direnv script': 'Change the direnv script',
|
|
12
|
+
'editor task config': 'Change the editor task config'
|
|
13
|
+
};
|
|
14
|
+
/** The most specific title, by signal priority. */
|
|
15
|
+
function promptTitle(request) {
|
|
16
|
+
const has = (s) => request.signals.includes(s);
|
|
17
|
+
const bash = request.toolName === 'bash';
|
|
18
|
+
if (has('placeholder-in-command'))
|
|
19
|
+
return 'Run a command that uses a secret';
|
|
20
|
+
if (has('upload'))
|
|
21
|
+
return 'Run a command that uploads data';
|
|
22
|
+
if (has('destructive'))
|
|
23
|
+
return 'Run a destructive command';
|
|
24
|
+
if (has('sudo'))
|
|
25
|
+
return 'Run a command as root';
|
|
26
|
+
if (has('persistence'))
|
|
27
|
+
return 'Make a change that outlasts this session';
|
|
28
|
+
if (has('network-exposure'))
|
|
29
|
+
return 'Expose this machine to the network';
|
|
30
|
+
if (has('secret-env-expansion'))
|
|
31
|
+
return 'Run a command that uses a secret variable';
|
|
32
|
+
if (has('secret-transform'))
|
|
33
|
+
return 'Run a command that transforms a secret file';
|
|
34
|
+
if (has('shell-dynamic'))
|
|
35
|
+
return 'Run a command with dynamic shell code';
|
|
36
|
+
if (has('secret-into-plain-file'))
|
|
37
|
+
return 'Write a secret into a regular file';
|
|
38
|
+
if (has('clipboard'))
|
|
39
|
+
return 'Use the clipboard';
|
|
40
|
+
if (has('stdin-operands'))
|
|
41
|
+
return 'Run a command on file names from its input';
|
|
42
|
+
if (has('ask-write')) {
|
|
43
|
+
const label = request.targets.find((t) => t.zone === 'ask-write')?.label ?? '';
|
|
44
|
+
return ASK_WRITE_TITLES[label] ?? 'Write to a file that runs code';
|
|
45
|
+
}
|
|
46
|
+
if (has('unresolvable-path'))
|
|
47
|
+
return 'Use a path that cannot be resolved';
|
|
48
|
+
if (has('outside-workspace')) {
|
|
49
|
+
if (bash)
|
|
50
|
+
return 'Run a command that touches files outside the project';
|
|
51
|
+
if (request.kind === 'write')
|
|
52
|
+
return 'Write a file outside the project';
|
|
53
|
+
return 'Read a file outside the project';
|
|
54
|
+
}
|
|
55
|
+
if (bash)
|
|
56
|
+
return 'Run a command';
|
|
57
|
+
if (request.toolName === 'edit')
|
|
58
|
+
return 'Edit a file';
|
|
59
|
+
if (request.kind === 'write')
|
|
60
|
+
return 'Write a file';
|
|
61
|
+
return 'Read a file';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The card for an ASK. `reasons` are the sentences the policy asked for, in
|
|
65
|
+
* order. With one target and no command, the card shows the path in its own
|
|
66
|
+
* row, so a reason that opens with that path says "it" instead.
|
|
67
|
+
*/
|
|
68
|
+
function buildPrompt(request, reasons, grantOptions, display) {
|
|
69
|
+
const shown = request.targets.map((t) => (0, paths_1.showPath)(t.path, display.workspace, display.homeDir));
|
|
70
|
+
const only = request.command === undefined && shown.length === 1 ? `${shown[0]} ` : null;
|
|
71
|
+
const cardReasons = reasons.map((r) => (only && r.startsWith(only) ? `it ${r.slice(only.length)}` : r));
|
|
72
|
+
return {
|
|
73
|
+
title: promptTitle(request),
|
|
74
|
+
summary: request.command ?? shown.join('\n'),
|
|
75
|
+
toolName: request.toolName,
|
|
76
|
+
kind: request.kind,
|
|
77
|
+
...(request.command === undefined ? {} : { command: request.command }),
|
|
78
|
+
targets: request.targets.map((t, i) => ({ path: shown[i], access: t.access, zone: t.zone })),
|
|
79
|
+
signals: request.signals,
|
|
80
|
+
reasons: cardReasons,
|
|
81
|
+
grantOptions: grantOptions.map(({ scope, label, pattern }) => ({ scope, label, pattern }))
|
|
82
|
+
};
|
|
83
|
+
}
|
package/roots.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fixed places the engine knows about, and the zone a path falls in.
|
|
3
|
+
*
|
|
4
|
+
* Roots are canonicalized once per engine, so `/tmp/x` and `/private/tmp/x`
|
|
5
|
+
* (macOS) compare equal. Each root keeps its lexical spelling too, so a list
|
|
6
|
+
* entry still matches when the root itself is a symlink or does not exist yet.
|
|
7
|
+
*/
|
|
8
|
+
import type { Access, FsProbe, Zone } from './types';
|
|
9
|
+
/** One fixed place, relative to the home dir or a workspace, and what it is in words. */
|
|
10
|
+
export interface KnownPath {
|
|
11
|
+
rel: string;
|
|
12
|
+
label: string;
|
|
13
|
+
}
|
|
14
|
+
/** The macOS keychain dir. The bash analyzer counts a `security` read as a read of it. */
|
|
15
|
+
export declare const KEYCHAIN_DIR = "Library/Keychains";
|
|
16
|
+
/** Credential stores under the home dir. Read, write and run there are DENY in every mode. */
|
|
17
|
+
export declare const HOME_HARD_DENY: readonly KnownPath[];
|
|
18
|
+
export declare function defaultHardDeny(homeDir: string): string[];
|
|
19
|
+
/** Scratch dirs the agent may read and write without a prompt. */
|
|
20
|
+
export declare function defaultTempDirs(): string[];
|
|
21
|
+
/** Inside each workspace: writes are DENY in every mode (pi loads extensions from here). */
|
|
22
|
+
export declare const WORKSPACE_PROTECTED_WRITE: readonly KnownPath[];
|
|
23
|
+
/** Inside each workspace: writes run code later, so they ask outside Full mode. */
|
|
24
|
+
export declare const WORKSPACE_ASK_WRITE: readonly KnownPath[];
|
|
25
|
+
/** One root: the canonical path plus the lexical spelling, and what it is for. */
|
|
26
|
+
export interface Root {
|
|
27
|
+
path: string;
|
|
28
|
+
lexical: string;
|
|
29
|
+
label: string;
|
|
30
|
+
}
|
|
31
|
+
export interface Roots {
|
|
32
|
+
workspace: Root[];
|
|
33
|
+
trustedRead: Root[];
|
|
34
|
+
trustedExec: Root[];
|
|
35
|
+
temp: Root[];
|
|
36
|
+
hardDeny: Root[];
|
|
37
|
+
/** Writes are DENY: the trusted roots, `<ws>/.pi`, and host entries. */
|
|
38
|
+
protectedWrite: Root[];
|
|
39
|
+
/** Writes ask outside Full mode. */
|
|
40
|
+
askWrite: Root[];
|
|
41
|
+
}
|
|
42
|
+
export interface RootsSpec {
|
|
43
|
+
cwd: string;
|
|
44
|
+
homeDir: string;
|
|
45
|
+
workspace?: string[];
|
|
46
|
+
trustedRead?: string[];
|
|
47
|
+
trustedExec?: string[];
|
|
48
|
+
temp?: string[];
|
|
49
|
+
hardDeny?: string[];
|
|
50
|
+
protectedWrite?: string[];
|
|
51
|
+
askWrite?: string[];
|
|
52
|
+
}
|
|
53
|
+
/** Host hard-deny paths listed at decision time (a folder made during the session). */
|
|
54
|
+
export declare function buildHostHardDeny(paths: readonly string[], fs: FsProbe): Promise<Root[]>;
|
|
55
|
+
/** Canonicalize every root once. */
|
|
56
|
+
export declare function buildRoots(spec: RootsSpec, fs: FsProbe): Promise<Roots>;
|
|
57
|
+
/** The first root that holds `p`, matching either spelling. */
|
|
58
|
+
export declare function findRoot(roots: readonly Root[], p: string, caseInsensitive?: boolean): Root | undefined;
|
|
59
|
+
export interface ZoneHit {
|
|
60
|
+
zone: Zone;
|
|
61
|
+
root?: Root;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Where a canonical path sits for one access, most specific first:
|
|
65
|
+
* hard-deny > protected (writes) > ask-write (writes) > trusted > workspace > temp > outside.
|
|
66
|
+
* The restrictive lists match case-insensitively on macOS and Windows.
|
|
67
|
+
*/
|
|
68
|
+
export declare function zoneOf(p: string, access: Access, roots: Roots): ZoneHit;
|
|
69
|
+
/**
|
|
70
|
+
* The strictest restrictive zone a glob path could expand into: hard-deny,
|
|
71
|
+
* then (writes) protected and ask-write. `undefined` when it reaches none.
|
|
72
|
+
*/
|
|
73
|
+
export declare function globZoneOf(pattern: string, access: Access, roots: Roots, dot: boolean): ZoneHit | undefined;
|
|
74
|
+
/** `p` is exactly one of the roots (a workspace or temp root itself). */
|
|
75
|
+
export declare function isRootItself(roots: readonly Root[], p: string): boolean;
|
package/roots.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The fixed places the engine knows about, and the zone a path falls in.
|
|
4
|
+
*
|
|
5
|
+
* Roots are canonicalized once per engine, so `/tmp/x` and `/private/tmp/x`
|
|
6
|
+
* (macOS) compare equal. Each root keeps its lexical spelling too, so a list
|
|
7
|
+
* entry still matches when the root itself is a symlink or does not exist yet.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.WORKSPACE_ASK_WRITE = exports.WORKSPACE_PROTECTED_WRITE = exports.HOME_HARD_DENY = exports.KEYCHAIN_DIR = void 0;
|
|
44
|
+
exports.defaultHardDeny = defaultHardDeny;
|
|
45
|
+
exports.defaultTempDirs = defaultTempDirs;
|
|
46
|
+
exports.buildHostHardDeny = buildHostHardDeny;
|
|
47
|
+
exports.buildRoots = buildRoots;
|
|
48
|
+
exports.findRoot = findRoot;
|
|
49
|
+
exports.zoneOf = zoneOf;
|
|
50
|
+
exports.globZoneOf = globZoneOf;
|
|
51
|
+
exports.isRootItself = isRootItself;
|
|
52
|
+
const os = __importStar(require("node:os"));
|
|
53
|
+
const path = __importStar(require("node:path"));
|
|
54
|
+
const glob_1 = require("./glob");
|
|
55
|
+
const paths_1 = require("./paths");
|
|
56
|
+
/** The macOS keychain dir. The bash analyzer counts a `security` read as a read of it. */
|
|
57
|
+
exports.KEYCHAIN_DIR = 'Library/Keychains';
|
|
58
|
+
/** Credential stores under the home dir. Read, write and run there are DENY in every mode. */
|
|
59
|
+
exports.HOME_HARD_DENY = [
|
|
60
|
+
{ rel: '.ssh', label: 'SSH keys' },
|
|
61
|
+
{ rel: '.aws', label: 'AWS credentials' },
|
|
62
|
+
{ rel: '.gnupg', label: 'GPG keys' },
|
|
63
|
+
{ rel: '.config/gh', label: 'GitHub CLI credentials' },
|
|
64
|
+
{ rel: '.config/gcloud', label: 'Google Cloud credentials' },
|
|
65
|
+
{ rel: '.azure', label: 'Azure credentials' },
|
|
66
|
+
{ rel: '.kube', label: 'Kubernetes credentials' },
|
|
67
|
+
{ rel: '.docker/config.json', label: 'Docker credentials' },
|
|
68
|
+
{ rel: '.netrc', label: 'network credentials' },
|
|
69
|
+
{ rel: '.npmrc', label: 'npm credentials' },
|
|
70
|
+
{ rel: '.pypirc', label: 'PyPI credentials' },
|
|
71
|
+
{ rel: '.git-credentials', label: 'git credentials' },
|
|
72
|
+
{ rel: '.pgpass', label: 'Postgres passwords' },
|
|
73
|
+
{ rel: exports.KEYCHAIN_DIR, label: 'macOS keychain' },
|
|
74
|
+
{ rel: 'Library/Application Support/Google/Chrome', label: 'browser profile' },
|
|
75
|
+
{ rel: 'Library/Application Support/Firefox', label: 'browser profile' },
|
|
76
|
+
{ rel: 'Library/Application Support/BraveSoftware', label: 'browser profile' },
|
|
77
|
+
{ rel: 'Library/Application Support/Arc', label: 'browser profile' }
|
|
78
|
+
];
|
|
79
|
+
function defaultHardDeny(homeDir) {
|
|
80
|
+
return exports.HOME_HARD_DENY.map(({ rel }) => path.join(path.resolve(homeDir), rel));
|
|
81
|
+
}
|
|
82
|
+
/** Scratch dirs the agent may read and write without a prompt. */
|
|
83
|
+
function defaultTempDirs() {
|
|
84
|
+
const dirs = [os.tmpdir(), '/tmp', '/private/tmp'];
|
|
85
|
+
if (process.platform === 'darwin')
|
|
86
|
+
dirs.push('/private/var/folders');
|
|
87
|
+
return [...new Set(dirs.map((d) => path.resolve(d)))];
|
|
88
|
+
}
|
|
89
|
+
/** Inside each workspace: writes are DENY in every mode (pi loads extensions from here). */
|
|
90
|
+
exports.WORKSPACE_PROTECTED_WRITE = [{ rel: '.pi', label: 'agent extension dir' }];
|
|
91
|
+
/** Inside each workspace: writes run code later, so they ask outside Full mode. */
|
|
92
|
+
exports.WORKSPACE_ASK_WRITE = [
|
|
93
|
+
{ rel: '.git/hooks', label: 'git hook' },
|
|
94
|
+
{ rel: '.git/config', label: 'git config' },
|
|
95
|
+
{ rel: '.husky', label: 'git hook' },
|
|
96
|
+
{ rel: '.envrc', label: 'direnv script' },
|
|
97
|
+
{ rel: '.vscode/tasks.json', label: 'editor task config' }
|
|
98
|
+
];
|
|
99
|
+
async function makeRoot(p, label, fs) {
|
|
100
|
+
const lexical = path.resolve(p);
|
|
101
|
+
const canonical = await (0, paths_1.canonicalize)(lexical, fs);
|
|
102
|
+
return { path: canonical ?? lexical, lexical, label };
|
|
103
|
+
}
|
|
104
|
+
const HOST_HARD_DENY_LABEL = 'app data the agent may not touch';
|
|
105
|
+
/** Host hard-deny paths listed at decision time (a folder made during the session). */
|
|
106
|
+
function buildHostHardDeny(paths, fs) {
|
|
107
|
+
return Promise.all(paths.map((p) => makeRoot(p, HOST_HARD_DENY_LABEL, fs)));
|
|
108
|
+
}
|
|
109
|
+
/** Canonicalize every root once. */
|
|
110
|
+
async function buildRoots(spec, fs) {
|
|
111
|
+
const labelled = (list, label) => (list ?? []).map((p) => ({ p, label }));
|
|
112
|
+
const known = (base, list) => list.map(({ rel, label }) => ({ p: path.join(base, rel), label }));
|
|
113
|
+
const build = (entries) => Promise.all(entries.map(({ p, label }) => makeRoot(p, label, fs)));
|
|
114
|
+
const workspaceDirs = spec.workspace?.length ? spec.workspace : [spec.cwd];
|
|
115
|
+
const trustedRead = labelled(spec.trustedRead, 'trusted harness files');
|
|
116
|
+
const trustedExec = labelled(spec.trustedExec, 'trusted harness scripts');
|
|
117
|
+
const [workspace, tRead, tExec, temp, hardDeny, protectedWrite, askWrite] = await Promise.all([
|
|
118
|
+
build(labelled(workspaceDirs, 'project')),
|
|
119
|
+
build(trustedRead),
|
|
120
|
+
build(trustedExec),
|
|
121
|
+
build(labelled(spec.temp ?? defaultTempDirs(), 'temp dir')),
|
|
122
|
+
build([...known(path.resolve(spec.homeDir), exports.HOME_HARD_DENY), ...labelled(spec.hardDeny, HOST_HARD_DENY_LABEL)]),
|
|
123
|
+
build([
|
|
124
|
+
...trustedRead,
|
|
125
|
+
...trustedExec,
|
|
126
|
+
...workspaceDirs.flatMap((ws) => known(ws, exports.WORKSPACE_PROTECTED_WRITE)),
|
|
127
|
+
...labelled(spec.protectedWrite, 'protected by the host')
|
|
128
|
+
]),
|
|
129
|
+
build([...workspaceDirs.flatMap((ws) => known(ws, exports.WORKSPACE_ASK_WRITE)), ...labelled(spec.askWrite, 'file that can run code')])
|
|
130
|
+
]);
|
|
131
|
+
return { workspace, trustedRead: tRead, trustedExec: tExec, temp, hardDeny, protectedWrite, askWrite };
|
|
132
|
+
}
|
|
133
|
+
/** The first root that holds `p`, matching either spelling. */
|
|
134
|
+
function findRoot(roots, p, caseInsensitive = false) {
|
|
135
|
+
return roots.find((r) => (0, paths_1.contains)(r.path, p, caseInsensitive) || (0, paths_1.contains)(r.lexical, p, caseInsensitive));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Where a canonical path sits for one access, most specific first:
|
|
139
|
+
* hard-deny > protected (writes) > ask-write (writes) > trusted > workspace > temp > outside.
|
|
140
|
+
* The restrictive lists match case-insensitively on macOS and Windows.
|
|
141
|
+
*/
|
|
142
|
+
function zoneOf(p, access, roots) {
|
|
143
|
+
const ci = paths_1.CASE_INSENSITIVE_FS;
|
|
144
|
+
let root = findRoot(roots.hardDeny, p, ci);
|
|
145
|
+
if (root)
|
|
146
|
+
return { zone: 'hard-deny', root };
|
|
147
|
+
if (access === 'write') {
|
|
148
|
+
root = findRoot(roots.protectedWrite, p, ci);
|
|
149
|
+
if (root)
|
|
150
|
+
return { zone: 'protected', root };
|
|
151
|
+
root = findRoot(roots.askWrite, p, ci);
|
|
152
|
+
if (root)
|
|
153
|
+
return { zone: 'ask-write', root };
|
|
154
|
+
}
|
|
155
|
+
if (access !== 'exec') {
|
|
156
|
+
root = findRoot(roots.trustedRead, p);
|
|
157
|
+
if (root)
|
|
158
|
+
return { zone: 'trusted', root };
|
|
159
|
+
}
|
|
160
|
+
root = findRoot(roots.trustedExec, p);
|
|
161
|
+
if (root)
|
|
162
|
+
return { zone: 'trusted', root };
|
|
163
|
+
root = findRoot(roots.workspace, p);
|
|
164
|
+
if (root)
|
|
165
|
+
return { zone: 'workspace', root };
|
|
166
|
+
root = findRoot(roots.temp, p);
|
|
167
|
+
if (root)
|
|
168
|
+
return { zone: 'temp', root };
|
|
169
|
+
return { zone: 'outside' };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The strictest restrictive zone a glob path could expand into: hard-deny,
|
|
173
|
+
* then (writes) protected and ask-write. `undefined` when it reaches none.
|
|
174
|
+
*/
|
|
175
|
+
function globZoneOf(pattern, access, roots, dot) {
|
|
176
|
+
const opts = { dot, caseInsensitive: paths_1.CASE_INSENSITIVE_FS };
|
|
177
|
+
const reached = (list) => list.find((r) => (0, glob_1.globReaches)(pattern, r.path, opts) || (0, glob_1.globReaches)(pattern, r.lexical, opts));
|
|
178
|
+
let root = reached(roots.hardDeny);
|
|
179
|
+
if (root)
|
|
180
|
+
return { zone: 'hard-deny', root };
|
|
181
|
+
if (access !== 'write')
|
|
182
|
+
return undefined;
|
|
183
|
+
root = reached(roots.protectedWrite);
|
|
184
|
+
if (root)
|
|
185
|
+
return { zone: 'protected', root };
|
|
186
|
+
root = reached(roots.askWrite);
|
|
187
|
+
return root ? { zone: 'ask-write', root } : undefined;
|
|
188
|
+
}
|
|
189
|
+
/** `p` is exactly one of the roots (a workspace or temp root itself). */
|
|
190
|
+
function isRootItself(roots, p) {
|
|
191
|
+
return roots.some((r) => r.path === p || r.lexical === p);
|
|
192
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Files that hold credentials, by name (from the oh-my-pi jfind list). Reading
|
|
3
|
+
* one is allowed, because the output is redacted; writing one gets the real
|
|
4
|
+
* values restored; and their values feed the secret vault.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SECRET_FILE_NAMES: readonly string[];
|
|
7
|
+
/** Committed `.env` templates: not secret. */
|
|
8
|
+
export declare const ENV_TEMPLATE_NAMES: readonly string[];
|
|
9
|
+
export declare const SECRET_FILE_EXTENSIONS: readonly string[];
|
|
10
|
+
/** The base name is a secret file. Case-insensitive (`.ENV` opens `.env` on macOS). */
|
|
11
|
+
export declare function isSecretFileName(name: string): boolean;
|
|
12
|
+
export declare function isSecretFile(p: string): boolean;
|
|
13
|
+
/** `.env`, `.env.*` (not a template) or `.envrc`: parsed as dotenv for the vault. */
|
|
14
|
+
export declare function isEnvFileName(name: string): boolean;
|
|
15
|
+
/** A glob (grep `glob`, find `pattern`) that names secret files: `.env*`, `*.pem`. */
|
|
16
|
+
export declare function globNamesSecretFiles(glob: string): boolean;
|
package/secret-files.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Files that hold credentials, by name (from the oh-my-pi jfind list). Reading
|
|
4
|
+
* one is allowed, because the output is redacted; writing one gets the real
|
|
5
|
+
* values restored; and their values feed the secret vault.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.SECRET_FILE_EXTENSIONS = exports.ENV_TEMPLATE_NAMES = exports.SECRET_FILE_NAMES = void 0;
|
|
42
|
+
exports.isSecretFileName = isSecretFileName;
|
|
43
|
+
exports.isSecretFile = isSecretFile;
|
|
44
|
+
exports.isEnvFileName = isEnvFileName;
|
|
45
|
+
exports.globNamesSecretFiles = globNamesSecretFiles;
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
exports.SECRET_FILE_NAMES = [
|
|
48
|
+
'.env',
|
|
49
|
+
'.envrc',
|
|
50
|
+
'.netrc',
|
|
51
|
+
'.npmrc',
|
|
52
|
+
'.pypirc',
|
|
53
|
+
'.pgpass',
|
|
54
|
+
'.boto',
|
|
55
|
+
'.s3cfg',
|
|
56
|
+
'.dockercfg',
|
|
57
|
+
'.git-credentials',
|
|
58
|
+
'.htpasswd',
|
|
59
|
+
'credentials',
|
|
60
|
+
'credentials.json',
|
|
61
|
+
'client_secret.json',
|
|
62
|
+
'service-account.json',
|
|
63
|
+
'id_rsa',
|
|
64
|
+
'id_dsa',
|
|
65
|
+
'id_ecdsa',
|
|
66
|
+
'id_ed25519'
|
|
67
|
+
];
|
|
68
|
+
/** Committed `.env` templates: not secret. */
|
|
69
|
+
exports.ENV_TEMPLATE_NAMES = ['.env.example', '.env.sample', '.env.template', '.env.dist'];
|
|
70
|
+
exports.SECRET_FILE_EXTENSIONS = [
|
|
71
|
+
'pem',
|
|
72
|
+
'key',
|
|
73
|
+
'p12',
|
|
74
|
+
'pfx',
|
|
75
|
+
'jks',
|
|
76
|
+
'keystore',
|
|
77
|
+
'bks',
|
|
78
|
+
'ppk',
|
|
79
|
+
'kdbx',
|
|
80
|
+
'gpg',
|
|
81
|
+
'pgp',
|
|
82
|
+
'asc',
|
|
83
|
+
'tfvars',
|
|
84
|
+
'tfvars.json',
|
|
85
|
+
'tfstate',
|
|
86
|
+
'tfstate.backup'
|
|
87
|
+
];
|
|
88
|
+
const NAMES = new Set(exports.SECRET_FILE_NAMES);
|
|
89
|
+
const TEMPLATES = new Set(exports.ENV_TEMPLATE_NAMES);
|
|
90
|
+
/** The base name is a secret file. Case-insensitive (`.ENV` opens `.env` on macOS). */
|
|
91
|
+
function isSecretFileName(name) {
|
|
92
|
+
const lower = name.toLowerCase();
|
|
93
|
+
if (NAMES.has(lower))
|
|
94
|
+
return true;
|
|
95
|
+
if (lower.startsWith('.env.'))
|
|
96
|
+
return !TEMPLATES.has(lower);
|
|
97
|
+
return exports.SECRET_FILE_EXTENSIONS.some((ext) => lower.length > ext.length + 1 && lower.endsWith(`.${ext}`));
|
|
98
|
+
}
|
|
99
|
+
function isSecretFile(p) {
|
|
100
|
+
return isSecretFileName(path.basename(p));
|
|
101
|
+
}
|
|
102
|
+
/** `.env`, `.env.*` (not a template) or `.envrc`: parsed as dotenv for the vault. */
|
|
103
|
+
function isEnvFileName(name) {
|
|
104
|
+
const lower = name.toLowerCase();
|
|
105
|
+
if (lower === '.env' || lower === '.envrc')
|
|
106
|
+
return true;
|
|
107
|
+
return lower.startsWith('.env.') && !TEMPLATES.has(lower);
|
|
108
|
+
}
|
|
109
|
+
/** A glob (grep `glob`, find `pattern`) that names secret files: `.env*`, `*.pem`. */
|
|
110
|
+
function globNamesSecretFiles(glob) {
|
|
111
|
+
const names = glob
|
|
112
|
+
.split(/[{},/]/)
|
|
113
|
+
.map((part) => part.trim())
|
|
114
|
+
.filter(Boolean);
|
|
115
|
+
return names.some((name) => {
|
|
116
|
+
const lower = name.toLowerCase();
|
|
117
|
+
if (lower === '*' || lower === '**')
|
|
118
|
+
return false;
|
|
119
|
+
if (/^\.env(\*|\..*)?$/.test(lower) && !TEMPLATES.has(lower))
|
|
120
|
+
return true;
|
|
121
|
+
const literal = lower.replace(/\*/g, 'x');
|
|
122
|
+
return isSecretFileName(literal);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Read the secret values out of the secret files in the workspace. */
|
|
2
|
+
import type { FsProbe } from '../types';
|
|
3
|
+
export interface CollectedSecrets {
|
|
4
|
+
values: {
|
|
5
|
+
name: string;
|
|
6
|
+
value: string;
|
|
7
|
+
file: string;
|
|
8
|
+
}[];
|
|
9
|
+
errors: {
|
|
10
|
+
file: string;
|
|
11
|
+
error: unknown;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Read the secret files in the workspace dirs (the root and nested, to depth 4,
|
|
16
|
+
* skipping dependencies and build output, files up to 256 KB). Sibling dirs are
|
|
17
|
+
* walked in parallel, since a refresh runs after every tool that can write.
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectWorkspaceSecrets(dirs: readonly string[], fs: FsProbe): Promise<CollectedSecrets>;
|