@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/engine.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The permission engine: classify a tool call, decide it against the mode,
|
|
4
|
+
* the grants and the fixed lists, and keep secrets out of what the model sees.
|
|
5
|
+
*
|
|
6
|
+
* Harness-neutral. A harness adapter (the pi lane in `@agentic-kit/pi`) owns the
|
|
7
|
+
* glue: call `evaluate` on a tool call and show `decision.prompt` on an ask,
|
|
8
|
+
* call `restoreInput` with the decision before the tool runs, and
|
|
9
|
+
* `redactResult` on every result. The engine holds no state about one call
|
|
10
|
+
* between those steps: the decision carries all of it.
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.createPermissionEngine = createPermissionEngine;
|
|
47
|
+
const node_crypto_1 = require("node:crypto");
|
|
48
|
+
const path = __importStar(require("node:path"));
|
|
49
|
+
const classify_1 = require("./classify");
|
|
50
|
+
const node_fs_1 = require("./node-fs");
|
|
51
|
+
const policy_1 = require("./policy");
|
|
52
|
+
const roots_1 = require("./roots");
|
|
53
|
+
const secret_files_1 = require("./secret-files");
|
|
54
|
+
const secrets_1 = require("./secrets");
|
|
55
|
+
const tool_input_1 = require("./tool-input");
|
|
56
|
+
const types_1 = require("./types");
|
|
57
|
+
const MIN_HOST_SECRET = 4;
|
|
58
|
+
/**
|
|
59
|
+
* A write or edit to a secret file, by the file it really lands in: a link
|
|
60
|
+
* named `.env` that points at a plain file gets no real values, and a plainly
|
|
61
|
+
* named link to `.env` gets them back, as the values came from there.
|
|
62
|
+
*/
|
|
63
|
+
function writesSecretFile(request) {
|
|
64
|
+
if (request.toolName !== 'write' && request.toolName !== 'edit')
|
|
65
|
+
return false;
|
|
66
|
+
const target = request.targets[0];
|
|
67
|
+
return Boolean(target) && target.zone !== 'unresolvable' && (0, secret_files_1.isSecretFile)(target.path);
|
|
68
|
+
}
|
|
69
|
+
function createPermissionEngine(options) {
|
|
70
|
+
const fs = options.fs ?? node_fs_1.nodeFsProbe;
|
|
71
|
+
const cwd = path.resolve(options.cwd);
|
|
72
|
+
const homeDir = path.resolve(options.homeDir);
|
|
73
|
+
const vault = new secrets_1.SecretVault(options.placeholderKey ?? (0, node_crypto_1.randomBytes)(32).toString('hex'));
|
|
74
|
+
const report = (error, where) => options.onError?.(error, where);
|
|
75
|
+
let rootsReady;
|
|
76
|
+
const getRoots = () => (rootsReady ??= (0, roots_1.buildRoots)({ cwd, homeDir, ...options.roots }, fs));
|
|
77
|
+
const decisionRoots = async () => {
|
|
78
|
+
const roots = await getRoots();
|
|
79
|
+
if (!options.liveHardDeny)
|
|
80
|
+
return roots;
|
|
81
|
+
const live = await (0, roots_1.buildHostHardDeny)(await options.liveHardDeny(), fs);
|
|
82
|
+
return { ...roots, hardDeny: [...roots.hardDeny, ...live] };
|
|
83
|
+
};
|
|
84
|
+
let hostEnv = {};
|
|
85
|
+
/** The env names whose values are secret: `$NAME` in a command asks. */
|
|
86
|
+
const secretEnvNames = new Set();
|
|
87
|
+
const addHostSecret = (name, value) => {
|
|
88
|
+
if (value && value.length >= MIN_HOST_SECRET)
|
|
89
|
+
vault.add(name, value, 'host');
|
|
90
|
+
};
|
|
91
|
+
const refresh = async (extra) => {
|
|
92
|
+
for (const [name, value] of Object.entries(extra?.values ?? {}))
|
|
93
|
+
addHostSecret(name, value);
|
|
94
|
+
if (extra?.env)
|
|
95
|
+
hostEnv = { ...hostEnv, ...extra.env };
|
|
96
|
+
for (const [name, value] of Object.entries(hostEnv)) {
|
|
97
|
+
if (!value || !(0, secrets_1.isSecretEntry)(name, value))
|
|
98
|
+
continue;
|
|
99
|
+
vault.add(name, value, 'host');
|
|
100
|
+
secretEnvNames.add(name);
|
|
101
|
+
}
|
|
102
|
+
const roots = await getRoots();
|
|
103
|
+
const collected = await (0, secrets_1.collectWorkspaceSecrets)(roots.workspace.map((w) => w.path), fs);
|
|
104
|
+
for (const { file, error } of collected.errors)
|
|
105
|
+
report(error, `secrets: ${file}`);
|
|
106
|
+
vault.clear('file');
|
|
107
|
+
for (const { name, value } of collected.values)
|
|
108
|
+
vault.add(name, value, 'file');
|
|
109
|
+
};
|
|
110
|
+
// The first read of the workspace secrets happens lazily, once; every later
|
|
111
|
+
// refresh replaces it.
|
|
112
|
+
let vaultReady;
|
|
113
|
+
const refreshReported = (extra) => (vaultReady = refresh(extra).catch((error) => report(error, 'secrets')));
|
|
114
|
+
const ensureVault = () => vaultReady ?? refreshReported();
|
|
115
|
+
const restore = (text) => vault.restore(text);
|
|
116
|
+
return {
|
|
117
|
+
async evaluate(call, context) {
|
|
118
|
+
const { toolName } = call;
|
|
119
|
+
if (!(0, types_1.isBuiltinTool)(toolName))
|
|
120
|
+
return null;
|
|
121
|
+
const [roots] = await Promise.all([decisionRoots(), ensureVault()]);
|
|
122
|
+
const request = await (0, classify_1.classify)({ toolCallId: call.toolCallId, toolName, input: call.input ?? {} }, { cwd, homeDir, roots, fs, vault, secretEnvNames });
|
|
123
|
+
return (0, policy_1.decide)(request, { ...context, workspace: roots.workspace[0]?.path, homeDir });
|
|
124
|
+
},
|
|
125
|
+
restoreInput(decision, input, restoreOptions) {
|
|
126
|
+
if (decision.request.toolName === 'bash') {
|
|
127
|
+
if (restoreOptions?.approved)
|
|
128
|
+
(0, tool_input_1.mapCommand)(input, restore);
|
|
129
|
+
}
|
|
130
|
+
else if (writesSecretFile(decision.request)) {
|
|
131
|
+
(0, tool_input_1.mapWriteTexts)(input, restore);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
async redactResult(result) {
|
|
135
|
+
// A built-in that only reads cannot change a file, so the vault needs no refresh after it.
|
|
136
|
+
const readOnly = (0, types_1.isBuiltinTool)(result.toolName) && types_1.TOOL_KIND[result.toolName] === 'read';
|
|
137
|
+
if (!readOnly)
|
|
138
|
+
await refreshReported();
|
|
139
|
+
return (0, secrets_1.redactToolResult)(vault, result.content, result.details);
|
|
140
|
+
},
|
|
141
|
+
refreshSecrets: (extra) => refreshReported(extra),
|
|
142
|
+
addSecret: addHostSecret
|
|
143
|
+
};
|
|
144
|
+
}
|
package/env.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The environment a shell command gets. A host process inherits the user's
|
|
3
|
+
* shell environment, with provider keys and tokens in it; a command that
|
|
4
|
+
* expands one can send it out without the model ever seeing the value. The
|
|
5
|
+
* host passes the environment of each command through `scrubEnv`.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A copy of `env` without the variables that hold a secret: a name that looks
|
|
9
|
+
* secret (the vault's key rule), whatever the value's length, unless the value
|
|
10
|
+
* is a path; or a value with a token shape, a URL password included. The
|
|
11
|
+
* shell startup variables go too.
|
|
12
|
+
*/
|
|
13
|
+
export declare function scrubEnv(env: Readonly<Record<string, string | undefined>>): Record<string, string>;
|
package/env.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The environment a shell command gets. A host process inherits the user's
|
|
4
|
+
* shell environment, with provider keys and tokens in it; a command that
|
|
5
|
+
* expands one can send it out without the model ever seeing the value. The
|
|
6
|
+
* host passes the environment of each command through `scrubEnv`.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.scrubEnv = scrubEnv;
|
|
10
|
+
const secrets_1 = require("./secrets");
|
|
11
|
+
/** A path is an address, not a secret (`SSH_AUTH_SOCK`, `*_KEY_FILE`). */
|
|
12
|
+
const isPath = (value) => value.startsWith('/') && !/\s/.test(value);
|
|
13
|
+
/**
|
|
14
|
+
* Variables that change how the shell itself behaves before the command runs:
|
|
15
|
+
* a startup script it loads, or a search path that sends a relative `cd`
|
|
16
|
+
* somewhere the analyzer cannot see.
|
|
17
|
+
*/
|
|
18
|
+
const SHELL_STARTUP = new Set(['BASH_ENV', 'ENV', 'CDPATH']);
|
|
19
|
+
/**
|
|
20
|
+
* A copy of `env` without the variables that hold a secret: a name that looks
|
|
21
|
+
* secret (the vault's key rule), whatever the value's length, unless the value
|
|
22
|
+
* is a path; or a value with a token shape, a URL password included. The
|
|
23
|
+
* shell startup variables go too.
|
|
24
|
+
*/
|
|
25
|
+
function scrubEnv(env) {
|
|
26
|
+
const kept = {};
|
|
27
|
+
for (const [name, value] of Object.entries(env)) {
|
|
28
|
+
if (value === undefined || SHELL_STARTUP.has(name))
|
|
29
|
+
continue;
|
|
30
|
+
if (secrets_1.SECRET_KEY_PATTERN.test(name) && !isPath(value))
|
|
31
|
+
continue;
|
|
32
|
+
if (secrets_1.TOKEN_SHAPE_RES.some(({ re }) => re.test(value)))
|
|
33
|
+
continue;
|
|
34
|
+
kept[name] = value;
|
|
35
|
+
}
|
|
36
|
+
return kept;
|
|
37
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static risk analysis of a bash command. It finds the paths a command touches
|
|
3
|
+
* and the signals that make it risky, and it fails toward asking: anything it
|
|
4
|
+
* cannot see through (substitution, `eval`, `sh -c`, a variable it cannot
|
|
5
|
+
* resolve, a lexer error) raises `shell-dynamic`.
|
|
6
|
+
*
|
|
7
|
+
* This is best effort and is not a security boundary. A program the agent
|
|
8
|
+
* wrote can still do anything the user can; only an OS sandbox stops that.
|
|
9
|
+
*/
|
|
10
|
+
import type { Findings } from '../findings';
|
|
11
|
+
import type { Access, Signal } from '../types';
|
|
12
|
+
import { type ContentFlow, FlowTracker, type Stdin } from './flows';
|
|
13
|
+
import { type SimpleCommand, type Word } from './tokenize';
|
|
14
|
+
/** One argument after the expansions the analyzer can do. */
|
|
15
|
+
export interface Arg {
|
|
16
|
+
text: string;
|
|
17
|
+
raw: string;
|
|
18
|
+
/** Part of the value is not known statically (`$VAR`, `$(…)`). */
|
|
19
|
+
unknown: boolean;
|
|
20
|
+
/** Has an unquoted `*`, `?` or `[`. */
|
|
21
|
+
glob: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface BashPath {
|
|
24
|
+
raw: string;
|
|
25
|
+
/** Absolute, not normalized: `..` is resolved physically when canonicalized. */
|
|
26
|
+
abs: string;
|
|
27
|
+
access: Access;
|
|
28
|
+
/**
|
|
29
|
+
* A real path operand (has `/`, starts with `.` or `~`, a redirection, or a
|
|
30
|
+
* file operand of a known command). A soft one is a bare word that may or may
|
|
31
|
+
* not be a file; it only becomes a target when it leaves the workspace.
|
|
32
|
+
*/
|
|
33
|
+
hard: boolean;
|
|
34
|
+
/** Has an unexpanded glob (`*`, `?`, `[…]`): matched as a pattern against the restrictive roots. */
|
|
35
|
+
glob: boolean;
|
|
36
|
+
/** The program loads the file without printing it (`--env-file`). */
|
|
37
|
+
quiet: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface DestructiveCheck {
|
|
40
|
+
raw: string;
|
|
41
|
+
/** `null` when the target is not known until the command runs. */
|
|
42
|
+
abs: string | null;
|
|
43
|
+
what: string;
|
|
44
|
+
/** Also destructive on a workspace or temp root itself (`rm -rf .`), not only outside. */
|
|
45
|
+
rootCounts: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** What the analysis found besides its signals, which go straight into the caller's findings. */
|
|
48
|
+
export interface BashAnalysis {
|
|
49
|
+
paths: BashPath[];
|
|
50
|
+
/** Targets that make the command destructive when they sit outside the workspace or are a root. */
|
|
51
|
+
destructiveChecks: DestructiveCheck[];
|
|
52
|
+
/** Where file contents go: copies, the clipboard, transforms. */
|
|
53
|
+
flows: ContentFlow[];
|
|
54
|
+
/** Variables the command expands that it did not set itself. */
|
|
55
|
+
envRefs: string[];
|
|
56
|
+
/** The command may turn on globs that match dotfiles (`shopt -s dotglob`). */
|
|
57
|
+
dotglob: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface AnalyzeContext {
|
|
60
|
+
cwd: string;
|
|
61
|
+
homeDir: string;
|
|
62
|
+
}
|
|
63
|
+
/** The program a simple command runs, and its operands after the wrappers came off. */
|
|
64
|
+
export interface Run {
|
|
65
|
+
name: string;
|
|
66
|
+
rest: Arg[];
|
|
67
|
+
}
|
|
68
|
+
export declare function normalizeCommand(command: string): string;
|
|
69
|
+
declare class Analyzer {
|
|
70
|
+
readonly ctx: AnalyzeContext;
|
|
71
|
+
private readonly findings;
|
|
72
|
+
readonly paths: BashPath[];
|
|
73
|
+
readonly checks: DestructiveCheck[];
|
|
74
|
+
readonly tracker: FlowTracker;
|
|
75
|
+
/** Variables expanded but never set in the command: they come from the environment. */
|
|
76
|
+
readonly envRefs: Set<string>;
|
|
77
|
+
/** git remotes the command adds or points elsewhere (`git remote add`, `set-url`, `-c remote.x.url=`). */
|
|
78
|
+
readonly gitRemotes: Set<string>;
|
|
79
|
+
/** What the command being analyzed reads on stdin. */
|
|
80
|
+
stdin: Stdin;
|
|
81
|
+
/** Shell variables set earlier in the command. `null` = set to something unknown. */
|
|
82
|
+
vars: Map<string, string>;
|
|
83
|
+
/** The shell's working dir at this point. `null` after a `cd` we cannot follow. */
|
|
84
|
+
base: string | null;
|
|
85
|
+
/** How many shell strings (`sh -c`, `eval`, …) deep the analysis is. */
|
|
86
|
+
private depth;
|
|
87
|
+
constructor(ctx: AnalyzeContext, findings: Findings);
|
|
88
|
+
flag(signal: Signal, reason: string): void;
|
|
89
|
+
dynamic(reason: string): void;
|
|
90
|
+
/** A path the analyzer cannot place: it asks in every mode, so no mode lets it reach a denied root. */
|
|
91
|
+
unresolvable(reason: string): void;
|
|
92
|
+
/** `cd dir` looks `dir` up in `CDPATH` when the command set it and `dir` is not `/…`, `./…` or `../…`. */
|
|
93
|
+
searchesCdPath(dir: string): boolean;
|
|
94
|
+
analyzeString(command: string): void;
|
|
95
|
+
/** A shell string run by `sh -c`, `eval`, `watch`, …: analyze it in its own scope. */
|
|
96
|
+
nested(text: string, why: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* `NAME=value`, inline or through `export`, `declare` or `readonly`.
|
|
99
|
+
* `value` is `null` when it is not known statically.
|
|
100
|
+
*/
|
|
101
|
+
assign(name: string, value: string | null): void;
|
|
102
|
+
/** A variable the command expands: an env ref unless the command set it. */
|
|
103
|
+
noteRef(name: string): void;
|
|
104
|
+
lookup(name: string): string | null;
|
|
105
|
+
/**
|
|
106
|
+
* `$NAME`, or `${NAME:-fallback}`. The fallback counts only when this
|
|
107
|
+
* command set the variable to empty: one from outside may hold anything, and
|
|
108
|
+
* a fallback with its own expansion or a `~` is not known either.
|
|
109
|
+
*/
|
|
110
|
+
private valueOf;
|
|
111
|
+
resolveWord(word: Word): Arg[];
|
|
112
|
+
/** The absolute location of an argument, or `null` when it is unknown. */
|
|
113
|
+
toAbs(text: string, base?: string | null): string | null;
|
|
114
|
+
/** Record a path the command touches. `quiet`: the program loads it without printing it. */
|
|
115
|
+
addPath(arg: Arg, access: Access, hard: boolean, quiet?: boolean): void;
|
|
116
|
+
destroy(arg: Arg | null, what: string, rootCounts?: boolean): void;
|
|
117
|
+
analyzeCommand(cmd: SimpleCommand): void;
|
|
118
|
+
/**
|
|
119
|
+
* Take assignments, keywords and wrappers off, then apply the command's
|
|
120
|
+
* rules. Returns the program and its operands, or `null` when there is none.
|
|
121
|
+
* A wrapper's working dir (`env -C`) holds for this command only.
|
|
122
|
+
*/
|
|
123
|
+
runArgs(args: Arg[], stdinFed: boolean): Run | null;
|
|
124
|
+
private run;
|
|
125
|
+
/** A bare operand: a hard path when it looks like one, a soft one otherwise. URLs are skipped. */
|
|
126
|
+
operand(arg: Arg, access?: Access): void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Analyze a bash command, flagging its signals into `findings`. Pure: no fs
|
|
130
|
+
* access; paths are canonicalized by the caller.
|
|
131
|
+
*/
|
|
132
|
+
export declare function analyzeBash(command: string, ctx: AnalyzeContext, findings: Findings): BashAnalysis;
|
|
133
|
+
export type { Analyzer };
|