@agentic-kit/permissions 0.0.0-stage → 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.
Files changed (143) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +278 -2
  3. package/bash/analyze.d.ts +133 -0
  4. package/bash/analyze.js +442 -0
  5. package/bash/args.d.ts +45 -0
  6. package/bash/args.js +145 -0
  7. package/bash/braces.d.ts +6 -0
  8. package/bash/braces.js +72 -0
  9. package/bash/commands.d.ts +14 -0
  10. package/bash/commands.js +361 -0
  11. package/bash/file-commands.d.ts +22 -0
  12. package/bash/file-commands.js +278 -0
  13. package/bash/flows.d.ts +67 -0
  14. package/bash/flows.js +208 -0
  15. package/bash/git.d.ts +7 -0
  16. package/bash/git.js +163 -0
  17. package/bash/network.d.ts +24 -0
  18. package/bash/network.js +295 -0
  19. package/bash/quoting.d.ts +16 -0
  20. package/bash/quoting.js +164 -0
  21. package/bash/system.d.ts +16 -0
  22. package/bash/system.js +122 -0
  23. package/bash/tokenize.d.ts +67 -0
  24. package/bash/tokenize.js +440 -0
  25. package/bash/words.d.ts +9 -0
  26. package/bash/words.js +30 -0
  27. package/bash/wrappers.d.ts +32 -0
  28. package/bash/wrappers.js +237 -0
  29. package/classify.d.ts +22 -0
  30. package/classify.js +259 -0
  31. package/engine.d.ts +109 -0
  32. package/engine.js +144 -0
  33. package/env.d.ts +13 -0
  34. package/env.js +37 -0
  35. package/esm/bash/analyze.d.ts +133 -0
  36. package/esm/bash/analyze.js +405 -0
  37. package/esm/bash/args.d.ts +45 -0
  38. package/esm/bash/args.js +135 -0
  39. package/esm/bash/braces.d.ts +6 -0
  40. package/esm/bash/braces.js +69 -0
  41. package/esm/bash/commands.d.ts +14 -0
  42. package/esm/bash/commands.js +324 -0
  43. package/esm/bash/file-commands.d.ts +22 -0
  44. package/esm/bash/file-commands.js +233 -0
  45. package/esm/bash/flows.d.ts +67 -0
  46. package/esm/bash/flows.js +203 -0
  47. package/esm/bash/git.d.ts +7 -0
  48. package/esm/bash/git.js +127 -0
  49. package/esm/bash/network.d.ts +24 -0
  50. package/esm/bash/network.js +282 -0
  51. package/esm/bash/quoting.d.ts +16 -0
  52. package/esm/bash/quoting.js +153 -0
  53. package/esm/bash/system.d.ts +16 -0
  54. package/esm/bash/system.js +82 -0
  55. package/esm/bash/tokenize.d.ts +67 -0
  56. package/esm/bash/tokenize.js +437 -0
  57. package/esm/bash/words.d.ts +9 -0
  58. package/esm/bash/words.js +24 -0
  59. package/esm/bash/wrappers.d.ts +32 -0
  60. package/esm/bash/wrappers.js +200 -0
  61. package/esm/classify.d.ts +22 -0
  62. package/esm/classify.js +223 -0
  63. package/esm/engine.d.ts +109 -0
  64. package/esm/engine.js +108 -0
  65. package/esm/env.d.ts +13 -0
  66. package/esm/env.js +34 -0
  67. package/esm/findings.d.ts +7 -0
  68. package/esm/findings.js +9 -0
  69. package/esm/glob.d.ts +15 -0
  70. package/esm/glob.js +69 -0
  71. package/esm/grants.d.ts +36 -0
  72. package/esm/grants.js +99 -0
  73. package/esm/index.d.ts +19 -0
  74. package/esm/index.js +18 -0
  75. package/esm/node-fs.d.ts +6 -0
  76. package/esm/node-fs.js +34 -0
  77. package/esm/paths.d.ts +43 -0
  78. package/esm/paths.js +121 -0
  79. package/esm/policy.d.ts +21 -0
  80. package/esm/policy.js +85 -0
  81. package/esm/prompt.d.ts +14 -0
  82. package/esm/prompt.js +79 -0
  83. package/esm/roots.d.ts +75 -0
  84. package/esm/roots.js +148 -0
  85. package/esm/secret-files.d.ts +16 -0
  86. package/esm/secret-files.js +84 -0
  87. package/esm/secrets/collect.d.ts +19 -0
  88. package/esm/secrets/collect.js +60 -0
  89. package/esm/secrets/index.d.ts +5 -0
  90. package/esm/secrets/index.js +5 -0
  91. package/esm/secrets/parse.d.ts +19 -0
  92. package/esm/secrets/parse.js +140 -0
  93. package/esm/secrets/redact-result.d.ts +8 -0
  94. package/esm/secrets/redact-result.js +67 -0
  95. package/esm/secrets/rules.d.ts +34 -0
  96. package/esm/secrets/rules.js +101 -0
  97. package/esm/secrets/vault.d.ts +48 -0
  98. package/esm/secrets/vault.js +158 -0
  99. package/esm/signals.d.ts +14 -0
  100. package/esm/signals.js +26 -0
  101. package/esm/tool-input.d.ts +13 -0
  102. package/esm/tool-input.js +40 -0
  103. package/esm/types.d.ts +146 -0
  104. package/esm/types.js +20 -0
  105. package/findings.d.ts +7 -0
  106. package/findings.js +13 -0
  107. package/glob.d.ts +15 -0
  108. package/glob.js +73 -0
  109. package/grants.d.ts +36 -0
  110. package/grants.js +110 -0
  111. package/index.d.ts +19 -0
  112. package/index.js +52 -0
  113. package/node-fs.d.ts +6 -0
  114. package/node-fs.js +37 -0
  115. package/package.json +38 -4
  116. package/paths.d.ts +43 -0
  117. package/paths.js +164 -0
  118. package/policy.d.ts +21 -0
  119. package/policy.js +88 -0
  120. package/prompt.d.ts +14 -0
  121. package/prompt.js +83 -0
  122. package/roots.d.ts +75 -0
  123. package/roots.js +192 -0
  124. package/secret-files.d.ts +16 -0
  125. package/secret-files.js +124 -0
  126. package/secrets/collect.d.ts +19 -0
  127. package/secrets/collect.js +96 -0
  128. package/secrets/index.d.ts +5 -0
  129. package/secrets/index.js +21 -0
  130. package/secrets/parse.d.ts +19 -0
  131. package/secrets/parse.js +145 -0
  132. package/secrets/redact-result.d.ts +8 -0
  133. package/secrets/redact-result.js +70 -0
  134. package/secrets/rules.d.ts +34 -0
  135. package/secrets/rules.js +107 -0
  136. package/secrets/vault.d.ts +48 -0
  137. package/secrets/vault.js +163 -0
  138. package/signals.d.ts +14 -0
  139. package/signals.js +29 -0
  140. package/tool-input.d.ts +13 -0
  141. package/tool-input.js +46 -0
  142. package/types.d.ts +146 -0
  143. package/types.js +24 -0
package/bash/braces.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /** Brace expansion (`{a,b}`, `{1..3}`) on the unquoted parts of a word. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.expandBraces = expandBraces;
5
+ const MAX_BRACE_RESULTS = 256;
6
+ /** Expand `{a,b}` and `{1..3}` in the unquoted parts of a word. */
7
+ function expandBraces(text, mask, out) {
8
+ if (out.length >= MAX_BRACE_RESULTS)
9
+ return;
10
+ for (let open = 0; open < text.length; open++) {
11
+ if (text[open] !== '{' || !mask[open])
12
+ continue;
13
+ let depth = 0;
14
+ const commas = [];
15
+ let close = -1;
16
+ for (let j = open; j < text.length; j++) {
17
+ if (!mask[j])
18
+ continue;
19
+ if (text[j] === '{')
20
+ depth++;
21
+ else if (text[j] === '}') {
22
+ depth--;
23
+ if (depth === 0) {
24
+ close = j;
25
+ break;
26
+ }
27
+ }
28
+ else if (text[j] === ',' && depth === 1)
29
+ commas.push(j);
30
+ }
31
+ if (close < 0)
32
+ return void out.push({ text, mask });
33
+ const pre = text.slice(0, open);
34
+ const preMask = mask.slice(0, open);
35
+ const post = text.slice(close + 1);
36
+ const postMask = mask.slice(close + 1);
37
+ let alternatives = [];
38
+ if (commas.length > 0) {
39
+ const bounds = [open, ...commas, close];
40
+ for (let k = 0; k < bounds.length - 1; k++) {
41
+ alternatives.push({
42
+ text: text.slice(bounds[k] + 1, bounds[k + 1]),
43
+ mask: mask.slice(bounds[k] + 1, bounds[k + 1])
44
+ });
45
+ }
46
+ }
47
+ else {
48
+ const seq = /^(-?\d+|[A-Za-z])\.\.(-?\d+|[A-Za-z])(?:\.\.(-?\d+))?$/.exec(text.slice(open + 1, close));
49
+ if (!seq)
50
+ continue;
51
+ alternatives = sequence(seq[1], seq[2], seq[3]).map((t) => ({ text: t, mask: [...t].map(() => true) }));
52
+ }
53
+ for (const alt of alternatives) {
54
+ expandBraces(pre + alt.text + post, [...preMask, ...alt.mask, ...postMask], out);
55
+ }
56
+ return;
57
+ }
58
+ out.push({ text, mask });
59
+ }
60
+ function sequence(from, to, step) {
61
+ const numeric = /^-?\d+$/.test(from) && /^-?\d+$/.test(to);
62
+ const a = numeric ? Number(from) : from.charCodeAt(0);
63
+ const b = numeric ? Number(to) : to.charCodeAt(0);
64
+ const inc = Math.max(1, Math.abs(Number(step ?? 1)));
65
+ const out = [];
66
+ for (let v = a; a <= b ? v <= b : v >= b; v += a <= b ? inc : -inc) {
67
+ out.push(numeric ? String(v) : String.fromCharCode(v));
68
+ if (out.length >= MAX_BRACE_RESULTS)
69
+ break;
70
+ }
71
+ return out;
72
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * What known commands do with their arguments: which operands they read or
3
+ * write, and which forms run hidden code, upload data or destroy things.
4
+ * Everything not listed here gets the generic rule: every operand is a read.
5
+ * The rules for files, git, the network and the machine live in their own
6
+ * modules; this one holds the shells and interpreters and the dispatch.
7
+ */
8
+ import type { Arg } from './analyze';
9
+ import { type CommandContext } from './args';
10
+ /** Commands that take no file operands. */
11
+ export declare const NO_OPERANDS: Set<string>;
12
+ /** The test commands: `[` and `[[` are names here, not globs. */
13
+ export declare const TESTS: Set<string>;
14
+ export declare function runCommand(name: string, rest: readonly Arg[], ctx: CommandContext): void;
@@ -0,0 +1,361 @@
1
+ "use strict";
2
+ /**
3
+ * What known commands do with their arguments: which operands they read or
4
+ * write, and which forms run hidden code, upload data or destroy things.
5
+ * Everything not listed here gets the generic rule: every operand is a read.
6
+ * The rules for files, git, the network and the machine live in their own
7
+ * modules; this one holds the shells and interpreters and the dispatch.
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.TESTS = exports.NO_OPERANDS = void 0;
44
+ exports.runCommand = runCommand;
45
+ const path = __importStar(require("node:path"));
46
+ const args_1 = require("./args");
47
+ const file_commands_1 = require("./file-commands");
48
+ const git_1 = require("./git");
49
+ const network_1 = require("./network");
50
+ const system_1 = require("./system");
51
+ const words_1 = require("./words");
52
+ const SHELLS = new Set(['sh', 'bash', 'zsh', 'dash', 'ksh', 'mksh', 'fish', 'ash']);
53
+ const AWKS = new Set(['awk', 'gawk', 'mawk', 'nawk']);
54
+ const GREPS = new Set(['grep', 'egrep', 'fgrep', 'rg', 'ag', 'ack', 'ggrep']);
55
+ const NETWORK_SHELLS = new Set(['nc', 'ncat', 'netcat', 'socat', 'telnet', 'ftp', 'tftp', 'sftp']);
56
+ const DISK_TOOLS = /^(mkfs(\..*)?|fdisk|sfdisk|gdisk|parted|wipefs|cryptsetup|newfs(_.*)?)$/;
57
+ const PERSISTENCE = new Set(['crontab', 'at', 'batch', 'launchctl', 'defaults']);
58
+ /** Commands that take no file operands. */
59
+ exports.NO_OPERANDS = new Set([
60
+ 'echo',
61
+ 'printf',
62
+ 'true',
63
+ 'false',
64
+ ':',
65
+ 'exit',
66
+ 'return',
67
+ 'set',
68
+ 'unset',
69
+ 'shift',
70
+ 'wait',
71
+ 'jobs',
72
+ 'type',
73
+ 'which',
74
+ 'hash',
75
+ 'alias',
76
+ 'unalias',
77
+ 'sleep',
78
+ 'date',
79
+ 'pwd',
80
+ 'whoami',
81
+ 'clear',
82
+ 'kill',
83
+ 'trap',
84
+ 'read',
85
+ 'let'
86
+ ]);
87
+ /**
88
+ * Readers whose every operand is a file, with the options that take a value.
89
+ * An operand built from a variable is then a path, not a word: it asks in
90
+ * every mode, as it may name any file.
91
+ */
92
+ const READERS = new Map([
93
+ ...['cat', 'less', 'more', 'bat', 'wc', 'nl', 'strings', 'file', 'stat', 'cmp', 'diff'].map((n) => [n, new Set()]),
94
+ ['head', new Set(['-n', '-c'])],
95
+ ['tail', new Set(['-n', '-c', '-b'])],
96
+ ['sort', new Set(['-k', '-t', '-o', '-S', '-T'])],
97
+ ['uniq', new Set(['-f', '-s'])],
98
+ ['base64', new Set(['-b', '-i', '-o', '-w'])],
99
+ ['xxd', new Set(['-c', '-g', '-l', '-s', '-o'])],
100
+ ['od', new Set(['-A', '-j', '-N', '-t'])],
101
+ ['hexdump', new Set(['-e', '-f', '-n', '-s'])]
102
+ ]);
103
+ /** The test commands: `[` and `[[` are names here, not globs. */
104
+ exports.TESTS = new Set(['test', '[', '[[']);
105
+ /** `[[`'s arithmetic comparisons evaluate their operands as expressions. */
106
+ const ARITHMETIC_TESTS = new Set(['-eq', '-ne', '-lt', '-le', '-gt', '-ge']);
107
+ /**
108
+ * A test reads the files it names. `-v NAME` (and, in `[[`, an arithmetic
109
+ * comparison) evaluates array subscripts, which can run a substitution even
110
+ * from a quoted word.
111
+ */
112
+ function test(name, ctx, rest) {
113
+ const close = name === '[' ? ']' : name === '[[' ? ']]' : null;
114
+ const operands = close && rest[rest.length - 1]?.text === close ? rest.slice(0, -1) : rest;
115
+ const evaluates = operands.some((a) => a.text === '-v' || (name === '[[' && ARITHMETIC_TESTS.has(a.text)));
116
+ if (evaluates)
117
+ ctx.analyzer.dynamic(`it runs ${name} with an operator that evaluates expressions`);
118
+ (0, args_1.generic)(ctx, operands);
119
+ }
120
+ /** Shell options that take a value; the `*file` ones name a script the shell loads. */
121
+ const SHELL_VALUE_OPTIONS = new Set(['-o', '-O', '--rcfile', '--init-file', '--command', '--init-command']);
122
+ const SHELL_LOADS = new Set(['--rcfile', '--init-file']);
123
+ /** `-c` takes its string from the first operand; fish's long forms carry it. */
124
+ const SHELL_INLINE = new Set(['--command', '--init-command']);
125
+ /** A word in a shell's option list that is not a plain letter cluster (`-ex`, `+o`). */
126
+ const isOddShellOption = (text) => /^[-+][^-]/.test(text) && !/^[-+][a-zA-Z]+$/.test(text);
127
+ function shell(name, ctx, rest) {
128
+ const { analyzer } = ctx;
129
+ // `+x`, `+o name`: the same options, turned off.
130
+ const words = rest.map((a) => (/^\+[a-zA-Z]/.test(a.text) ? { ...a, text: `-${a.text.slice(1)}` } : a));
131
+ const { options, next } = (0, args_1.leadingOptions)(words, SHELL_VALUE_OPTIONS);
132
+ const odd = rest.slice(0, next).find((a) => isOddShellOption(a.text));
133
+ if (odd)
134
+ analyzer.dynamic(`it passes ${name} an option it cannot read: ${odd.raw}`);
135
+ for (const { key, value } of options)
136
+ if (value && SHELL_LOADS.has(key))
137
+ analyzer.operand(value);
138
+ const inline = options.find((o) => SHELL_INLINE.has(o.key));
139
+ const script = inline ? inline.value : options.some((o) => o.key === '-c') ? (rest[next] ?? null) : undefined;
140
+ if (script !== undefined) {
141
+ if (!script || script.unknown)
142
+ analyzer.dynamic(`it runs ${name} -c with a string from a variable`);
143
+ else
144
+ analyzer.nested(script.text, `it runs a shell string with ${name} -c`);
145
+ return;
146
+ }
147
+ const file = rest[next];
148
+ if (file && file.text !== '-') {
149
+ analyzer.addPath(file, 'read', true);
150
+ (0, args_1.generic)(ctx, rest.slice(next + 1));
151
+ }
152
+ else if (ctx.stdinFed) {
153
+ analyzer.dynamic(`it pipes a script into ${name}`);
154
+ }
155
+ }
156
+ const interpreter = (inline, others, extra = {}) => ({
157
+ inline: new Set(inline),
158
+ withValue: new Set([...inline, ...others, ...(extra.loads ?? [])]),
159
+ ...extra
160
+ });
161
+ const NODE = interpreter(['-e', '-p', '--eval', '--print'], ['--input-type', '--conditions', '-C'], {
162
+ loads: new Set(['-r', '--require', '--import', '--loader', '--experimental-loader'])
163
+ });
164
+ const SCRIPT_RUNNER = interpreter(['-e'], ['-l']);
165
+ /** By program name; every `python*` version is `python`. */
166
+ const INTERPRETERS = new Map([
167
+ ['python', interpreter(['-c'], ['-m', '-W', '-X', '-Q'], { module: '-m', stopAfter: new Set(['-c', '-m']), moduleServer: network_1.pythonServer })],
168
+ ['node', NODE],
169
+ ['nodejs', NODE],
170
+ ['perl', interpreter(['-e', '-E'], ['-I', '-M', '-m'])],
171
+ ['ruby', interpreter(['-e'], ['-I', '-C'], { loads: new Set(['-r']), server: network_1.rubyServer })],
172
+ ['php', interpreter(['-r', '-B', '-R', '-E'], ['-c', '-d', '-S', '-t'], { loads: new Set(['-f']), server: network_1.phpServer })],
173
+ ['lua', SCRIPT_RUNNER],
174
+ ['luajit', SCRIPT_RUNNER],
175
+ ['Rscript', SCRIPT_RUNNER],
176
+ ['osascript', SCRIPT_RUNNER]
177
+ ]);
178
+ function interpreterOf(name) {
179
+ return INTERPRETERS.get(/^python[0-9.]*$/.test(name) ? 'python' : name);
180
+ }
181
+ /** The script an interpreter runs is a read; inline code or piped code is dynamic. */
182
+ function interpret(name, spec, ctx, rest) {
183
+ const { analyzer } = ctx;
184
+ spec.server?.(ctx, rest);
185
+ const { options, next } = (0, args_1.leadingOptions)(rest, spec.withValue, spec.stopAfter);
186
+ for (const { key, value } of options) {
187
+ if (spec.inline.has(key))
188
+ return analyzer.dynamic(`it runs inline code with ${name} ${key}`);
189
+ if (value && spec.loads?.has(key))
190
+ analyzer.operand(value);
191
+ if (key === spec.module) {
192
+ if (value && !value.unknown)
193
+ spec.moduleServer?.(ctx, value.text, rest.slice(next));
194
+ return (0, args_1.generic)(ctx, rest.slice(next));
195
+ }
196
+ }
197
+ const script = rest[next];
198
+ if (script && script.text !== '-') {
199
+ analyzer.addPath(script, 'read', true);
200
+ (0, args_1.generic)(ctx, rest.slice(next + 1));
201
+ }
202
+ else if (ctx.stdinFed) {
203
+ analyzer.dynamic(`it pipes code into ${name}`);
204
+ }
205
+ }
206
+ function runCommand(name, rest, ctx) {
207
+ const { analyzer } = ctx;
208
+ (0, network_1.publishes)(name, ctx, rest);
209
+ if (ctx.stdinFed && (0, system_1.namesFromStdin)(name, rest)) {
210
+ const words = analyzer.stdin.words;
211
+ if (words === null)
212
+ analyzer.flag('stdin-operands', `${name} takes file names from its input, which cannot be checked before it runs`);
213
+ else
214
+ for (const w of words)
215
+ analyzer.addPath(w, 'read', true);
216
+ }
217
+ if (SHELLS.has(name))
218
+ return shell(name, ctx, rest);
219
+ const spec = interpreterOf(name);
220
+ if (spec)
221
+ return interpret(name, spec, ctx, rest);
222
+ if (AWKS.has(name))
223
+ return (0, file_commands_1.awk)(name, ctx, rest);
224
+ if (GREPS.has(name))
225
+ return (0, file_commands_1.grep)(ctx, rest);
226
+ if (NETWORK_SHELLS.has(name)) {
227
+ analyzer.flag('upload', `it uploads data: ${name} opens a raw network connection`);
228
+ return (0, args_1.generic)(ctx, rest.filter((a) => (0, words_1.isPathLike)(a.text)));
229
+ }
230
+ if (network_1.TUNNELS.has(name))
231
+ return (0, network_1.tunnel)(name, ctx, rest);
232
+ if (PERSISTENCE.has(name))
233
+ return (0, system_1.persistence)(name, ctx, rest);
234
+ if (system_1.CLIPBOARD.has(name))
235
+ return (0, system_1.clipboard)(name, ctx, rest);
236
+ if (DISK_TOOLS.test(name)) {
237
+ analyzer.flag('destructive', `it runs ${name}, which formats or partitions a disk`);
238
+ return;
239
+ }
240
+ if (exports.TESTS.has(name))
241
+ return test(name, ctx, rest);
242
+ const readerValues = READERS.get(name);
243
+ if (readerValues) {
244
+ for (const v of (0, args_1.parse)(rest, readerValues).positionals)
245
+ if (v.unknown)
246
+ analyzer.addPath(v, 'read', true);
247
+ return (0, args_1.generic)(ctx, rest);
248
+ }
249
+ if (exports.NO_OPERANDS.has(name))
250
+ return;
251
+ switch (name) {
252
+ case 'cd':
253
+ case 'pushd': {
254
+ const target = (0, args_1.parse)(rest).positionals[0];
255
+ if (!target) {
256
+ analyzer.base = path.resolve(analyzer.ctx.homeDir);
257
+ }
258
+ else if (target.unknown || /^[-+]\d*$/.test(target.text) || analyzer.searchesCdPath(target.text)) {
259
+ // `cd -`, `pushd +1` and a `CDPATH` lookup go to a dir the text does not name.
260
+ analyzer.base = null;
261
+ }
262
+ else {
263
+ const abs = analyzer.toAbs(target.text);
264
+ analyzer.addPath(target, 'read', true);
265
+ analyzer.base = abs === null ? null : path.resolve(abs);
266
+ }
267
+ return;
268
+ }
269
+ case 'popd':
270
+ analyzer.base = null;
271
+ return;
272
+ case 'export':
273
+ case 'declare':
274
+ case 'local':
275
+ case 'readonly':
276
+ case 'typeset':
277
+ for (const arg of rest) {
278
+ const m = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s.exec(arg.text);
279
+ if (m)
280
+ analyzer.assign(m[1], arg.unknown ? null : m[2]);
281
+ }
282
+ return;
283
+ case 'eval':
284
+ if (rest.some((a) => a.unknown))
285
+ analyzer.dynamic('it runs eval on a value from a variable');
286
+ else
287
+ analyzer.nested(rest.map((a) => a.text).join(' '), 'it runs a string with eval');
288
+ return;
289
+ case 'source':
290
+ case '.':
291
+ analyzer.dynamic(`it loads a script into the shell with ${name}`);
292
+ if (rest[0])
293
+ analyzer.addPath(rest[0], 'read', true);
294
+ return;
295
+ case 'deno':
296
+ if (rest[0]?.text === 'eval')
297
+ return analyzer.dynamic('it runs inline code with deno eval');
298
+ return (0, args_1.generic)(ctx, rest);
299
+ case 'bun':
300
+ if ((0, args_1.leadingOptions)(rest, NODE.inline).options.some((o) => NODE.inline.has(o.key))) {
301
+ return analyzer.dynamic('it runs inline code with bun -e');
302
+ }
303
+ return (0, args_1.generic)(ctx, rest);
304
+ case 'curl':
305
+ return (0, network_1.curl)(ctx, rest);
306
+ case 'wget':
307
+ return (0, network_1.wget)(ctx, rest);
308
+ case 'scp':
309
+ case 'rsync':
310
+ return (0, network_1.remoteCopy)(name, ctx, rest);
311
+ case 'ssh':
312
+ return (0, network_1.ssh)(ctx, rest);
313
+ case 'security':
314
+ return (0, system_1.security)(ctx, rest);
315
+ case 'busybox':
316
+ if (rest[0]?.text === 'httpd')
317
+ return (0, network_1.busyboxServer)(ctx, rest.slice(1));
318
+ if (rest[0])
319
+ return runCommand(path.basename(rest[0].text), rest.slice(1), ctx);
320
+ return;
321
+ case 'find':
322
+ return (0, file_commands_1.find)(ctx, rest);
323
+ case 'git':
324
+ return (0, git_1.git)(ctx, rest);
325
+ case 'sed':
326
+ case 'gsed':
327
+ return (0, file_commands_1.sed)(ctx, rest);
328
+ case 'rm':
329
+ case 'rmdir':
330
+ case 'unlink':
331
+ case 'shred':
332
+ case 'rimraf':
333
+ case 'srm':
334
+ return (0, file_commands_1.remove)(name, ctx, rest);
335
+ case 'touch':
336
+ case 'mkdir':
337
+ case 'mkfifo':
338
+ case 'truncate':
339
+ return (0, args_1.files)(ctx, (0, args_1.parse)(rest, new Set(['-m', '--mode', '-s', '--size', '-r', '--reference', '-t', '-d'])).positionals, 'write');
340
+ case 'tee':
341
+ return (0, file_commands_1.tee)(ctx, rest);
342
+ case 'cp':
343
+ case 'mv':
344
+ case 'ln':
345
+ case 'install':
346
+ return (0, file_commands_1.copyLike)(name, ctx, rest);
347
+ case 'chmod':
348
+ case 'chown':
349
+ case 'chgrp':
350
+ return (0, file_commands_1.chmodLike)(name, ctx, rest);
351
+ case 'dd':
352
+ return (0, file_commands_1.dd)(ctx, rest);
353
+ case 'diskutil':
354
+ if (rest.some((a) => /^(erase|zero|partition|secureErase|reformat)/i.test(a.text))) {
355
+ analyzer.flag('destructive', 'it runs diskutil to erase or partition a disk');
356
+ }
357
+ return;
358
+ default:
359
+ return (0, args_1.generic)(ctx, rest);
360
+ }
361
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Commands that read, write, copy and delete files: which operands they touch
3
+ * with which access, which forms destroy data, and where a copy puts a file's
4
+ * contents.
5
+ */
6
+ import type { Arg } from './analyze';
7
+ import { type CommandContext } from './args';
8
+ /** `tee file…`: stdin lands in each file. */
9
+ export declare function tee(ctx: CommandContext, rest: readonly Arg[]): void;
10
+ /** The dirs `find` searches (`.` when none is given), and the index of its first expression word. */
11
+ export declare function findRoots(rest: readonly Arg[]): {
12
+ roots: Arg[];
13
+ next: number;
14
+ };
15
+ export declare function find(ctx: CommandContext, rest: readonly Arg[]): void;
16
+ export declare function sed(ctx: CommandContext, rest: readonly Arg[]): void;
17
+ export declare function grep(ctx: CommandContext, rest: readonly Arg[]): void;
18
+ export declare function awk(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
19
+ export declare function remove(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
20
+ export declare function copyLike(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
21
+ export declare function chmodLike(name: string, ctx: CommandContext, rest: readonly Arg[]): void;
22
+ export declare function dd(ctx: CommandContext, rest: readonly Arg[]): void;