@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.
Files changed (143) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +279 -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 +35 -3
  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
@@ -0,0 +1,437 @@
1
+ /**
2
+ * A POSIX-shell lexer that is good enough to find what a command touches.
3
+ *
4
+ * It splits a command into simple commands (on `;`, `&&`, `||`, `|`, `&`,
5
+ * newline and subshell parens), keeps quoting so expansion can be judged, and
6
+ * records redirections and heredocs. Command substitution (`$(…)`, backticks,
7
+ * `<(…)`) is lexed recursively, so the commands inside it are analyzed too.
8
+ *
9
+ * It never executes or expands anything that needs the environment. What it
10
+ * cannot know it marks: a word part is `unknown`, and constructs that hide code
11
+ * add a `dynamic` note. Any lexer error (an unterminated quote) is reported as
12
+ * `error`, and the analyzer turns both into `shell-dynamic`.
13
+ */
14
+ import { decodeAnsiC, findAnsiClose, LexError, matchBacktick, matchBrace, matchParen, stripQuotes, unescapeBackticks } from './quoting';
15
+ const MAX_DEPTH = 6;
16
+ const OPERATOR_CHARS = new Set([';', '&', '|', '(', ')', '<', '>']);
17
+ const NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
18
+ const SPECIAL_PARAMS = new Set(['?', '$', '!', '#', '@', '*', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']);
19
+ function newCommand() {
20
+ return { words: [], redirects: [], heredocs: [], pipedIn: false, stdinDoc: false, hereStrings: [] };
21
+ }
22
+ class Lexer {
23
+ s;
24
+ depth;
25
+ commands = [];
26
+ dynamic = [];
27
+ current = newCommand();
28
+ pending = [];
29
+ pipeNext = false;
30
+ upstream = null;
31
+ i = 0;
32
+ constructor(s, depth) {
33
+ this.s = s;
34
+ this.depth = depth;
35
+ }
36
+ run() {
37
+ const { s } = this;
38
+ while (this.i < s.length) {
39
+ const ch = s[this.i];
40
+ if (ch === ' ' || ch === '\t' || ch === '\r') {
41
+ this.i++;
42
+ }
43
+ else if (ch === '\\' && s[this.i + 1] === '\n') {
44
+ this.i += 2;
45
+ }
46
+ else if (ch === '\n') {
47
+ this.i++;
48
+ // A pipe may continue on the next line.
49
+ if (!this.pipeNext || this.current.words.length > 0 || this.current.redirects.length > 0)
50
+ this.endCommand(false);
51
+ this.readHeredocs();
52
+ }
53
+ else if (ch === '#') {
54
+ const nl = s.indexOf('\n', this.i);
55
+ this.i = nl < 0 ? s.length : nl;
56
+ }
57
+ else if (OPERATOR_CHARS.has(ch)) {
58
+ this.operator();
59
+ }
60
+ else {
61
+ const start = this.i;
62
+ const parts = this.readWord();
63
+ if (parts)
64
+ this.current.words.push({ parts, raw: s.slice(start, this.i) });
65
+ }
66
+ }
67
+ if (this.pending.length > 0)
68
+ throw new LexError('unterminated heredoc');
69
+ this.endCommand(false);
70
+ }
71
+ endCommand(pipe) {
72
+ const cmd = this.current;
73
+ if (cmd.words.length > 0 || cmd.redirects.length > 0) {
74
+ cmd.pipedIn = cmd.pipedIn || this.pipeNext;
75
+ if (cmd.pipedIn && this.upstream)
76
+ cmd.upstream = this.upstream;
77
+ this.commands.push(cmd);
78
+ this.pipeNext = pipe;
79
+ this.upstream = pipe ? cmd : null;
80
+ }
81
+ else if (pipe) {
82
+ // `( … ) | x`: the group's output is piped on.
83
+ this.pipeNext = true;
84
+ this.upstream = 'group';
85
+ }
86
+ else {
87
+ this.pipeNext = false;
88
+ this.upstream = null;
89
+ }
90
+ this.current = newCommand();
91
+ }
92
+ operator() {
93
+ const { s } = this;
94
+ const ch = s[this.i];
95
+ const two = s.slice(this.i, this.i + 2);
96
+ if (ch === '<' || ch === '>' || two === '&>') {
97
+ this.redirect(null);
98
+ return;
99
+ }
100
+ if (two === '&&' || two === '||' || two === ';;' || two === ';&') {
101
+ this.i += 2;
102
+ this.endCommand(false);
103
+ }
104
+ else if (two === '|&') {
105
+ this.i += 2;
106
+ this.endCommand(true);
107
+ }
108
+ else if (ch === '|') {
109
+ this.i++;
110
+ this.endCommand(true);
111
+ }
112
+ else {
113
+ // `;`, `&`, `(`, `)`
114
+ if (ch === '(' && s[this.i + 1] === ')') {
115
+ // `name()`: a function definition hides a body that runs later.
116
+ this.dynamic.push('defines a shell function');
117
+ this.i += 2;
118
+ return;
119
+ }
120
+ this.i++;
121
+ this.endCommand(false);
122
+ }
123
+ }
124
+ redirect(fd) {
125
+ const { s } = this;
126
+ const ops = ['&>>', '<<<', '<<-', '&>', '>>', '>|', '>&', '<<', '<>', '<&', '<(', '>(', '<', '>'];
127
+ const op = ops.find((candidate) => s.startsWith(candidate, this.i));
128
+ if (op === '<(' || op === '>(') {
129
+ // Process substitution: a word whose value comes from a command.
130
+ const start = this.i;
131
+ const parts = this.readWord();
132
+ if (parts)
133
+ this.current.words.push({ parts, raw: s.slice(start, this.i) });
134
+ return;
135
+ }
136
+ this.i += op.length;
137
+ while (s[this.i] === ' ' || s[this.i] === '\t')
138
+ this.i++;
139
+ if (this.i >= s.length || s[this.i] === '\n' || OPERATOR_CHARS.has(s[this.i])) {
140
+ throw new LexError(`redirection ${op} has no target`);
141
+ }
142
+ const start = this.i;
143
+ const parts = this.readWord();
144
+ if (!parts)
145
+ throw new LexError(`redirection ${op} has no target`);
146
+ const target = { parts, raw: s.slice(start, this.i) };
147
+ const cmd = this.current;
148
+ if (op === '<<' || op === '<<-') {
149
+ const quoted = parts.some((p) => p.kind === 'lit' && p.quoted);
150
+ const delim = parts.map((p) => (p.kind === 'lit' ? p.text : '')).join('');
151
+ this.pending.push({ delim, quoted, stripTabs: op === '<<-', command: cmd });
152
+ cmd.stdinDoc = true;
153
+ cmd.redirects.push({ op, fd, target: null });
154
+ return;
155
+ }
156
+ if (op === '<<<') {
157
+ cmd.stdinDoc = true;
158
+ cmd.hereStrings.push(target);
159
+ cmd.redirects.push({ op, fd, target: null });
160
+ return;
161
+ }
162
+ if ((op === '>&' || op === '<&') && /^(\d+-?|-)$/.test(target.raw)) {
163
+ cmd.redirects.push({ op, fd, target: null });
164
+ return;
165
+ }
166
+ cmd.redirects.push({ op, fd, target });
167
+ }
168
+ readHeredocs() {
169
+ const { s } = this;
170
+ for (const doc of this.pending) {
171
+ let body = '';
172
+ let found = false;
173
+ while (this.i < s.length) {
174
+ const nl = s.indexOf('\n', this.i);
175
+ const line = s.slice(this.i, nl < 0 ? s.length : nl);
176
+ this.i = nl < 0 ? s.length : nl + 1;
177
+ const check = doc.stripTabs ? line.replace(/^\t+/, '') : line;
178
+ if (check === doc.delim) {
179
+ found = true;
180
+ break;
181
+ }
182
+ body += `${line}\n`;
183
+ }
184
+ if (!found)
185
+ throw new LexError('unterminated heredoc');
186
+ if (!doc.quoted)
187
+ this.scanExpansions(body);
188
+ doc.command.heredocs.push({ quoted: doc.quoted, body });
189
+ }
190
+ this.pending = [];
191
+ }
192
+ /** An unquoted heredoc body expands `$(…)` and backticks: lex them. */
193
+ scanExpansions(body) {
194
+ for (let i = 0; i < body.length; i++) {
195
+ const ch = body[i];
196
+ if (ch === '\\')
197
+ i++;
198
+ else if (ch === '$' && body[i + 1] === '(') {
199
+ const end = matchParen(body, i + 1);
200
+ this.substitute(body.slice(i + 2, end), 'command substitution in a heredoc');
201
+ i = end;
202
+ }
203
+ else if (ch === '`') {
204
+ const end = matchBacktick(body, i);
205
+ this.substitute(unescapeBackticks(body.slice(i + 1, end)), 'backtick substitution in a heredoc');
206
+ i = end;
207
+ }
208
+ }
209
+ }
210
+ substitute(inner, note) {
211
+ this.dynamic.push(note);
212
+ if (this.depth >= MAX_DEPTH)
213
+ throw new LexError('substitutions nested too deep');
214
+ const sub = new Lexer(inner, this.depth + 1);
215
+ sub.run();
216
+ this.commands.push(...sub.commands);
217
+ this.dynamic.push(...sub.dynamic);
218
+ }
219
+ /** Read one word starting at `this.i`, up to unquoted whitespace or an operator. */
220
+ readWord() {
221
+ const { s } = this;
222
+ const parts = [];
223
+ const lit = (text, quoted) => {
224
+ const last = parts[parts.length - 1];
225
+ if (last && last.kind === 'lit' && last.quoted === quoted)
226
+ last.text += text;
227
+ else
228
+ parts.push({ kind: 'lit', text, quoted });
229
+ };
230
+ const wordStart = this.i;
231
+ while (this.i < s.length) {
232
+ const ch = s[this.i];
233
+ if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r')
234
+ break;
235
+ if ((ch === '<' || ch === '>') && s[this.i + 1] === '(') {
236
+ const end = matchParen(s, this.i + 1);
237
+ this.substitute(s.slice(this.i + 2, end), 'process substitution');
238
+ parts.push({ kind: 'unknown' });
239
+ this.i = end + 1;
240
+ continue;
241
+ }
242
+ if (OPERATOR_CHARS.has(ch)) {
243
+ // `2>file`: digits right before a redirection are its fd.
244
+ if ((ch === '<' || ch === '>') && this.i > wordStart) {
245
+ const text = s.slice(wordStart, this.i);
246
+ if (/^\d+$/.test(text)) {
247
+ parts.length = 0;
248
+ this.redirect(Number(text));
249
+ return null;
250
+ }
251
+ }
252
+ break;
253
+ }
254
+ if (ch === '\\') {
255
+ if (s[this.i + 1] === '\n') {
256
+ this.i += 2;
257
+ continue;
258
+ }
259
+ if (this.i + 1 < s.length)
260
+ lit(s[this.i + 1], true);
261
+ this.i += 2;
262
+ continue;
263
+ }
264
+ if (ch === "'") {
265
+ const end = s.indexOf("'", this.i + 1);
266
+ if (end < 0)
267
+ throw new LexError('unterminated single quote');
268
+ lit(s.slice(this.i + 1, end), true);
269
+ this.i = end + 1;
270
+ continue;
271
+ }
272
+ if (ch === '"') {
273
+ this.readDouble(parts, lit);
274
+ continue;
275
+ }
276
+ if (ch === '`') {
277
+ const end = matchBacktick(s, this.i);
278
+ this.substitute(unescapeBackticks(s.slice(this.i + 1, end)), 'backtick substitution');
279
+ parts.push({ kind: 'unknown' });
280
+ this.i = end + 1;
281
+ continue;
282
+ }
283
+ if (ch === '$') {
284
+ this.readDollar(parts, lit, false);
285
+ continue;
286
+ }
287
+ if (ch === '~' && this.atTildePosition(parts)) {
288
+ const rest = s.slice(this.i + 1);
289
+ const user = /^[^/\s;&|()<>:]*/.exec(rest)[0];
290
+ if (user === '') {
291
+ parts.push({ kind: 'tilde' });
292
+ this.i++;
293
+ continue;
294
+ }
295
+ this.dynamic.push(`~${user} expansion`);
296
+ lit(`~${user}`, false);
297
+ this.i += 1 + user.length;
298
+ continue;
299
+ }
300
+ lit(ch, false);
301
+ this.i++;
302
+ }
303
+ return parts;
304
+ }
305
+ /** `~` expands at the start of a word and right after `NAME=` (an assignment). */
306
+ atTildePosition(parts) {
307
+ if (parts.length === 0)
308
+ return true;
309
+ if (parts.length !== 1)
310
+ return false;
311
+ const only = parts[0];
312
+ return only.kind === 'lit' && !only.quoted && /^[A-Za-z_][A-Za-z0-9_]*=$/.test(only.text);
313
+ }
314
+ readDouble(parts, lit) {
315
+ const { s } = this;
316
+ this.i++;
317
+ while (this.i < s.length) {
318
+ const ch = s[this.i];
319
+ if (ch === '"') {
320
+ this.i++;
321
+ if (parts.length === 0)
322
+ lit('', true);
323
+ return;
324
+ }
325
+ if (ch === '\\') {
326
+ const next = s[this.i + 1];
327
+ if (next === '\n') {
328
+ this.i += 2;
329
+ }
330
+ else if (next === '"' || next === '\\' || next === '$' || next === '`') {
331
+ lit(next, true);
332
+ this.i += 2;
333
+ }
334
+ else {
335
+ lit('\\', true);
336
+ this.i++;
337
+ }
338
+ continue;
339
+ }
340
+ if (ch === '`') {
341
+ const end = matchBacktick(s, this.i);
342
+ this.substitute(unescapeBackticks(s.slice(this.i + 1, end)), 'backtick substitution');
343
+ parts.push({ kind: 'unknown' });
344
+ this.i = end + 1;
345
+ continue;
346
+ }
347
+ if (ch === '$') {
348
+ this.readDollar(parts, lit, true);
349
+ continue;
350
+ }
351
+ lit(ch, true);
352
+ this.i++;
353
+ }
354
+ throw new LexError('unterminated double quote');
355
+ }
356
+ readDollar(parts, lit, quoted) {
357
+ const { s } = this;
358
+ const next = s[this.i + 1];
359
+ if (next === '(' && s[this.i + 2] === '(') {
360
+ const end = matchParen(s, this.i + 1);
361
+ const inner = s.slice(this.i + 3, end - 1);
362
+ if (/\$\(|`/.test(inner))
363
+ this.substitute(inner.replace(/^[^$`]*/, ''), 'command substitution in arithmetic');
364
+ parts.push({ kind: 'unknown' });
365
+ this.i = end + 1;
366
+ return;
367
+ }
368
+ if (next === '(') {
369
+ const end = matchParen(s, this.i + 1);
370
+ this.substitute(s.slice(this.i + 2, end), 'command substitution $(…)');
371
+ parts.push({ kind: 'unknown' });
372
+ this.i = end + 1;
373
+ return;
374
+ }
375
+ if (next === '{') {
376
+ const end = matchBrace(s, this.i + 1);
377
+ const inner = s.slice(this.i + 2, end);
378
+ this.i = end + 1;
379
+ if (NAME_RE.test(inner)) {
380
+ parts.push({ kind: 'var', name: inner, quoted });
381
+ return;
382
+ }
383
+ if (SPECIAL_PARAMS.has(inner)) {
384
+ parts.push({ kind: 'unknown' });
385
+ return;
386
+ }
387
+ const ref = /^[#!]?([A-Za-z_][A-Za-z0-9_]*)/.exec(inner)?.[1];
388
+ const withDefault = /^([A-Za-z_][A-Za-z0-9_]*):?[-=](.*)$/s.exec(inner);
389
+ this.dynamic.push(`parameter expansion \${${inner}}`);
390
+ if (/\$\(|`/.test(inner))
391
+ this.scanExpansions(inner);
392
+ if (withDefault) {
393
+ parts.push({ kind: 'var', name: withDefault[1], quoted, fallback: stripQuotes(withDefault[2]) });
394
+ return;
395
+ }
396
+ parts.push(ref ? { kind: 'unknown', ref } : { kind: 'unknown' });
397
+ return;
398
+ }
399
+ if (next === "'" && !quoted) {
400
+ const close = findAnsiClose(s, this.i + 2);
401
+ lit(decodeAnsiC(s.slice(this.i + 2, close)), true);
402
+ this.i = close + 1;
403
+ return;
404
+ }
405
+ if (next === '"' && !quoted) {
406
+ // `$"…"` is a locale string: a double-quoted string.
407
+ this.i++;
408
+ return;
409
+ }
410
+ const name = /^[A-Za-z_][A-Za-z0-9_]*/.exec(s.slice(this.i + 1))?.[0];
411
+ if (name) {
412
+ parts.push({ kind: 'var', name, quoted });
413
+ this.i += 1 + name.length;
414
+ return;
415
+ }
416
+ if (next !== undefined && SPECIAL_PARAMS.has(next)) {
417
+ parts.push({ kind: 'unknown' });
418
+ this.i += 2;
419
+ return;
420
+ }
421
+ lit('$', quoted);
422
+ this.i++;
423
+ }
424
+ }
425
+ /** Lex a command. Never throws: a lexer error comes back in `error`. */
426
+ export function tokenize(command) {
427
+ const lexer = new Lexer(command, 0);
428
+ try {
429
+ lexer.run();
430
+ return { commands: lexer.commands, dynamic: lexer.dynamic };
431
+ }
432
+ catch (error) {
433
+ if (!(error instanceof LexError))
434
+ throw error;
435
+ return { commands: lexer.commands, dynamic: lexer.dynamic, error: error.message };
436
+ }
437
+ }
@@ -0,0 +1,9 @@
1
+ /** Small predicates on argument text, shared by the analyzer and the command rules. */
2
+ /** Has a `/`, or starts with `.` or `~`: the agent meant a path. */
3
+ export declare function isPathLike(text: string): boolean;
4
+ /** A network URL (`https://…`, `ssh://…`). `file://` is a path, not a URL. */
5
+ export declare function isUrl(text: string): boolean;
6
+ /** `host:path`, `user@host:path`, `rsync://…`; not `./a:b` or `/a:b`. */
7
+ export declare function isRemoteSpec(text: string): boolean;
8
+ /** `localhost`, `127.x.x.x`, `::1` and `*.localhost`: reachable only from this machine. */
9
+ export declare function isLoopbackHost(host: string): boolean;
@@ -0,0 +1,24 @@
1
+ /** Small predicates on argument text, shared by the analyzer and the command rules. */
2
+ /** Has a `/`, or starts with `.` or `~`: the agent meant a path. */
3
+ export function isPathLike(text) {
4
+ return text.includes('/') || text.startsWith('.') || text.startsWith('~');
5
+ }
6
+ /** A network URL (`https://…`, `ssh://…`). `file://` is a path, not a URL. */
7
+ export function isUrl(text) {
8
+ return /^[a-z][a-z0-9+.-]*:\/\//i.test(text) && !/^file:\/\//i.test(text);
9
+ }
10
+ /** `host:path`, `user@host:path`, `rsync://…`; not `./a:b` or `/a:b`. */
11
+ export function isRemoteSpec(text) {
12
+ if (/^rsync:\/\//i.test(text))
13
+ return true;
14
+ if (text.startsWith('/') || text.startsWith('.') || text.startsWith('~'))
15
+ return false;
16
+ const colon = text.indexOf(':');
17
+ const slash = text.indexOf('/');
18
+ return colon > 0 && (slash < 0 || colon < slash);
19
+ }
20
+ /** `localhost`, `127.x.x.x`, `::1` and `*.localhost`: reachable only from this machine. */
21
+ export function isLoopbackHost(host) {
22
+ const h = host.toLowerCase().replace(/^\[|\]$/g, '');
23
+ return h === 'localhost' || h === '::1' || /^127\.\d+\.\d+\.\d+$/.test(h) || h.endsWith('.localhost');
24
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Wrappers that run another command (`env`, `sudo`, `timeout`, `xargs`, …).
3
+ * They come off the front of a command before its rules apply, so `/bin/rm`,
4
+ * `command rm` and `env rm` are all `rm`.
5
+ */
6
+ import type { Analyzer, Arg } from './analyze';
7
+ /** How `xargs` feeds the command it runs. */
8
+ export interface XargsInput {
9
+ /** `xargs -I {}`: the string each input line replaces. */
10
+ replace?: string;
11
+ /** `xargs -a file`: the input comes from a file, not stdin. */
12
+ fromFile: boolean;
13
+ }
14
+ /** What the wrappers taken off so far change about the command they run. */
15
+ export interface WrapperScope {
16
+ sudo: boolean;
17
+ /** Set once `xargs` came off: more operands arrive from its input. */
18
+ xargs: XargsInput | null;
19
+ /** `env -C dir` moved the working dir for this one command. */
20
+ chdir: boolean;
21
+ }
22
+ /**
23
+ * The operands of the command `xargs` runs. The words on stdin join them when
24
+ * they are known, and the roots of a file listing stand in for the names it
25
+ * prints. Otherwise the names cannot be seen, which is a signal.
26
+ */
27
+ export declare function xargsOperands(analyzer: Analyzer, name: string, rest: Arg[], input: XargsInput): Arg[];
28
+ /**
29
+ * Take one wrapper off the front of the command. Returns the index of the
30
+ * next word, or `i` when `args[i]` is not a wrapper.
31
+ */
32
+ export declare function stripWrapper(analyzer: Analyzer, args: Arg[], i: number, scope: WrapperScope): number;