@darkrymit/crunes-cli 0.9.0 → 0.10.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 (59) hide show
  1. package/dist/chunks/add-MSX6XSU3.js +68 -0
  2. package/dist/chunks/{apply-YY7MIM64.js → apply-LOIJIPLR.js} +18 -9
  3. package/dist/chunks/{benchmark-BQNMULOO.js → benchmark-3IHFP3V2.js} +21 -15
  4. package/dist/chunks/chunk-2DNYVKBF.js +109 -0
  5. package/dist/chunks/chunk-2FI6KN3C.js +283 -0
  6. package/dist/chunks/chunk-2HM5Q52B.js +131 -0
  7. package/dist/chunks/chunk-55GTJG5I.js +1154 -0
  8. package/dist/chunks/chunk-6IC6ZJ74.js +9525 -0
  9. package/dist/chunks/chunk-7KYCYDAS.js +325 -0
  10. package/dist/chunks/chunk-DTOYFY3Z.js +578 -0
  11. package/dist/chunks/chunk-EO3CSXWK.js +70 -0
  12. package/dist/chunks/chunk-FIAFVIAN.js +79 -0
  13. package/dist/chunks/chunk-H2OT7D6N.js +303 -0
  14. package/dist/chunks/{chunk-MRNZFUXZ.js → chunk-KSQDFE5N.js} +22 -7
  15. package/dist/chunks/{chunk-SNC7AOT7.js → chunk-KUEMDPNG.js} +45 -94
  16. package/dist/chunks/{chunk-VST6HAB6.js → chunk-MTJ2KW3V.js} +2 -0
  17. package/dist/chunks/{chunk-CY6C6ADU.js → chunk-MVCBPI4J.js} +45 -478
  18. package/dist/chunks/{chunk-34F4ZURL.js → chunk-RVBAAXRY.js} +29 -12
  19. package/dist/chunks/{chunk-X7PZN73N.js → chunk-SUCYDYMU.js} +1 -1
  20. package/dist/chunks/chunk-UBCAZGLE.js +15 -0
  21. package/dist/chunks/chunk-VP7YLCQP.js +244 -0
  22. package/dist/chunks/chunk-XDMMSZIL.js +71 -0
  23. package/dist/chunks/chunk-YKIKJHYO.js +94 -0
  24. package/dist/chunks/{create-TLPM7HJE.js → create-DXW4YYLJ.js} +5 -5
  25. package/dist/chunks/{create-LM7U3CJS.js → create-LPLNCOW4.js} +100 -6
  26. package/dist/chunks/{create-ET6DT5ZE.js → create-Y4LHLWGL.js} +6 -2
  27. package/dist/chunks/{disable-TNTEIAKO.js → disable-TITOSMXB.js} +6 -2
  28. package/dist/chunks/doctor-R2Y6UAY4.js +208 -0
  29. package/dist/chunks/{enable-GUQCB4CU.js → enable-LGTPDWPV.js} +7 -3
  30. package/dist/chunks/{init-PJSCFOC6.js → init-KO2HLED5.js} +6 -2
  31. package/dist/chunks/{install-4YP7FALO.js → install-7IRUAGSF.js} +10 -5
  32. package/dist/chunks/{intro-SA7MWV3Z.js → intro-JNJ6A75J.js} +44 -18
  33. package/dist/chunks/{list-WKNPZZOV.js → list-BCCM3TLP.js} +10 -6
  34. package/dist/chunks/{list-7R6NASFI.js → list-MLKZE36K.js} +19 -19
  35. package/dist/chunks/list-QVZKR3IE.js +62 -0
  36. package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
  37. package/dist/chunks/migrate-Y3EKMVP5.js +87 -0
  38. package/dist/chunks/{registry-K5DV5NAK.js → registry-IWP7JMNI.js} +1 -1
  39. package/dist/chunks/{repl-ZB3DIJ4K.js → repl-5GDN3RAO.js} +30 -20
  40. package/dist/chunks/resolver-CA2A32AC.js +36 -0
  41. package/dist/chunks/{run-22B65ZWZ.js → run-WL3IZBXF.js} +17 -11
  42. package/dist/chunks/rune-YA4TFHTB.js +283 -0
  43. package/dist/chunks/runner-QNZMBHQY.js +34 -0
  44. package/dist/chunks/{shell-explain-QLITLHW7.js → shell-explain-LKBBP2BG.js} +5 -2
  45. package/dist/chunks/trust-BFIDANXD.js +109 -0
  46. package/dist/chunks/{uninstall-4WR5IHLC.js → uninstall-3MWZIZVA.js} +10 -5
  47. package/dist/chunks/{update-ACLDK6E6.js → update-W4MJUTTW.js} +10 -5
  48. package/dist/chunks/{version-EULYWNXN.js → version-FLHI5KFS.js} +2 -2
  49. package/dist/cli.js +51 -34
  50. package/package.json +2 -2
  51. package/dist/chunks/chunk-G3U4V32O.js +0 -46
  52. package/dist/chunks/chunk-QYRF3R35.js +0 -154
  53. package/dist/chunks/chunk-YXCHIMLW.js +0 -75308
  54. package/dist/chunks/doctor-VXAQYMTR.js +0 -101
  55. package/dist/chunks/list-OMMZAQ23.js +0 -28
  56. package/dist/chunks/resolver-QIYYFIDX.js +0 -34
  57. package/dist/chunks/rune-SYK4N642.js +0 -425
  58. package/dist/chunks/{delete-5R3WBLVD.js → delete-2EXPFBFC.js} +4 -4
  59. package/dist/chunks/{delete-U4STA2QZ.js → delete-MJAECXXV.js} +4 -4
@@ -0,0 +1,325 @@
1
+ import {
2
+ PermissionError
3
+ } from "./chunk-MVCBPI4J.js";
4
+ import {
5
+ init_require_shim
6
+ } from "./chunk-TPK5AGRA.js";
7
+
8
+ // src/rune/permissions/shell-scan.js
9
+ init_require_shim();
10
+ var ScanRefusal = class extends Error {
11
+ constructor(construct, offset) {
12
+ super(`Cannot scan command: ${construct} at offset ${offset} is not supported.`);
13
+ this.name = "ScanRefusal";
14
+ this.construct = construct;
15
+ this.offset = offset;
16
+ }
17
+ };
18
+ var ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/;
19
+ var CONTROL_KEYWORDS = /* @__PURE__ */ new Set([
20
+ "if",
21
+ "then",
22
+ "else",
23
+ "elif",
24
+ "fi",
25
+ "while",
26
+ "until",
27
+ "do",
28
+ "done",
29
+ "for",
30
+ "select",
31
+ "case",
32
+ "esac",
33
+ "function"
34
+ ]);
35
+ var NESTED_INTERPRETERS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh"]);
36
+ var CMD_METACHARACTERS = /[&|<>^%()]/;
37
+ function guardCmdMode(cmd) {
38
+ const m = CMD_METACHARACTERS.exec(cmd);
39
+ if (m) throw new ScanRefusal("cmd metacharacter", m.index);
40
+ }
41
+ function matchDelimiter(src, from, open, close) {
42
+ let depth = 1;
43
+ let i = from;
44
+ while (i < src.length) {
45
+ const ch = src[i];
46
+ if (ch === "\\") {
47
+ i += 2;
48
+ continue;
49
+ }
50
+ if (ch === "'") {
51
+ const e = src.indexOf("'", i + 1);
52
+ if (e === -1) return -1;
53
+ i = e + 1;
54
+ continue;
55
+ }
56
+ if (ch === '"') {
57
+ const e = src.indexOf('"', i + 1);
58
+ if (e === -1) return -1;
59
+ i = e + 1;
60
+ continue;
61
+ }
62
+ if (ch === open) depth++;
63
+ else if (ch === close) {
64
+ depth--;
65
+ if (depth === 0) return i;
66
+ }
67
+ i++;
68
+ }
69
+ return -1;
70
+ }
71
+ function isOperatorStart(ch) {
72
+ return ch === "|" || ch === "&" || ch === ";" || ch === "\n";
73
+ }
74
+ function tokenize(src, baseOffset) {
75
+ const tokens = [];
76
+ let i = 0;
77
+ let buf = "";
78
+ let bufStart = -1;
79
+ let hadWord = false;
80
+ const flush = () => {
81
+ if (!hadWord) return;
82
+ tokens.push({ type: "word", value: buf, offset: baseOffset + bufStart });
83
+ buf = "";
84
+ bufStart = -1;
85
+ hadWord = false;
86
+ };
87
+ const begin = (at) => {
88
+ if (!hadWord) {
89
+ hadWord = true;
90
+ bufStart = at;
91
+ }
92
+ };
93
+ while (i < src.length) {
94
+ const ch = src[i];
95
+ if (ch === " " || ch === " ") {
96
+ flush();
97
+ i++;
98
+ continue;
99
+ }
100
+ if (ch === "'") {
101
+ const end = src.indexOf("'", i + 1);
102
+ if (end === -1) throw new ScanRefusal("unterminated single quote", baseOffset + i);
103
+ begin(i);
104
+ buf += src.slice(i + 1, end);
105
+ i = end + 1;
106
+ continue;
107
+ }
108
+ if (ch === '"') {
109
+ begin(i);
110
+ let j = i + 1;
111
+ let inner = "";
112
+ let closed = false;
113
+ while (j < src.length) {
114
+ if (src[j] === "\\" && j + 1 < src.length) {
115
+ inner += src[j + 1];
116
+ j += 2;
117
+ continue;
118
+ }
119
+ if (src[j] === '"') {
120
+ closed = true;
121
+ break;
122
+ }
123
+ inner += src[j];
124
+ j++;
125
+ }
126
+ if (!closed) throw new ScanRefusal("unterminated double quote", baseOffset + i);
127
+ if (inner.includes("$(") || inner.includes("`")) {
128
+ const nested = tokenize(inner, baseOffset + i + 1);
129
+ for (const t of nested) {
130
+ if (t.type === "subst") tokens.push({ ...t, inCommandPosition: false });
131
+ }
132
+ buf += inner.replace(/\$\([^)]*\)|`[^`]*`/g, "");
133
+ } else {
134
+ buf += inner;
135
+ }
136
+ i = j + 1;
137
+ continue;
138
+ }
139
+ if (ch === "\\" && i + 1 < src.length) {
140
+ begin(i);
141
+ buf += src[i + 1];
142
+ i += 2;
143
+ continue;
144
+ }
145
+ if (ch === "$" && src[i + 1] === "(" && src[i + 2] === "(") {
146
+ throw new ScanRefusal("arithmetic expansion", baseOffset + i);
147
+ }
148
+ if (ch === "<" && src[i + 1] === "<") {
149
+ throw new ScanRefusal("heredoc", baseOffset + i);
150
+ }
151
+ if ((ch === "<" || ch === ">") && src[i + 1] === "(") {
152
+ throw new ScanRefusal("process substitution", baseOffset + i);
153
+ }
154
+ if (ch === "$" && src[i + 1] === "(") {
155
+ const end = matchDelimiter(src, i + 2, "(", ")");
156
+ if (end === -1) throw new ScanRefusal("unterminated command substitution", baseOffset + i);
157
+ const wasInCommandPosition = !hadWord;
158
+ flush();
159
+ tokens.push({ type: "subst", src: src.slice(i + 2, end), offset: baseOffset + i + 2, inCommandPosition: wasInCommandPosition });
160
+ i = end + 1;
161
+ continue;
162
+ }
163
+ if (ch === "`") {
164
+ const end = src.indexOf("`", i + 1);
165
+ if (end === -1) throw new ScanRefusal("unterminated command substitution", baseOffset + i);
166
+ const wasInCommandPosition = !hadWord;
167
+ flush();
168
+ tokens.push({ type: "subst", src: src.slice(i + 1, end), offset: baseOffset + i + 1, inCommandPosition: wasInCommandPosition });
169
+ i = end + 1;
170
+ continue;
171
+ }
172
+ if (ch === "(" && !hadWord) {
173
+ const end = matchDelimiter(src, i + 1, "(", ")");
174
+ if (end === -1) throw new ScanRefusal("unterminated subshell", baseOffset + i);
175
+ flush();
176
+ tokens.push({ type: "group", src: src.slice(i + 1, end), offset: baseOffset + i + 1 });
177
+ i = end + 1;
178
+ continue;
179
+ }
180
+ if (ch === ">" || ch === "<" || ch === "&" && src[i + 1] === ">") {
181
+ let opLen = 1;
182
+ let mode = ch === "<" ? "read" : "write";
183
+ if (ch === "&") {
184
+ opLen = 2;
185
+ mode = "write";
186
+ } else if (src[i + 1] === ">" || src[i + 1] === "|") opLen = 2;
187
+ if (hadWord && /^\d+$/.test(buf) && (ch === ">" || ch === "<")) {
188
+ buf = "";
189
+ hadWord = false;
190
+ bufStart = -1;
191
+ } else {
192
+ flush();
193
+ }
194
+ tokens.push({ type: "redirect", mode, offset: baseOffset + i });
195
+ i += opLen;
196
+ continue;
197
+ }
198
+ if (isOperatorStart(ch)) {
199
+ flush();
200
+ let op = ch;
201
+ if (ch === "|" && src[i + 1] === "|" || ch === "&" && src[i + 1] === "&") op = ch + ch;
202
+ tokens.push({ type: "op", value: op, offset: baseOffset + i });
203
+ i += op.length;
204
+ continue;
205
+ }
206
+ begin(i);
207
+ buf += ch;
208
+ i++;
209
+ }
210
+ flush();
211
+ return tokens;
212
+ }
213
+ function splitSegments(tokens) {
214
+ const segments = [];
215
+ let current = [];
216
+ for (const t of tokens) {
217
+ if (t.type === "op") {
218
+ segments.push(current);
219
+ current = [];
220
+ continue;
221
+ }
222
+ current.push(t);
223
+ }
224
+ segments.push(current);
225
+ return segments.filter((s) => s.length > 0);
226
+ }
227
+ function stripAssignments(words) {
228
+ let k = 0;
229
+ while (k < words.length && ASSIGNMENT_RE.test(words[k].value)) k++;
230
+ return words.slice(k);
231
+ }
232
+ function scanCommand(cmd, shellKind = "bash") {
233
+ if (shellKind === "cmd") guardCmdMode(cmd);
234
+ const commands = [];
235
+ const redirects = [];
236
+ collect(tokenize(cmd, 0), commands, redirects);
237
+ return { commands, redirects };
238
+ }
239
+ function collect(tokens, commands, redirects) {
240
+ for (const segment of splitSegments(tokens)) {
241
+ const words = [];
242
+ for (let k = 0; k < segment.length; k++) {
243
+ const t = segment[k];
244
+ if (t.type === "subst" || t.type === "group") {
245
+ if (t.type === "subst" && t.inCommandPosition && words.length === 0) {
246
+ throw new ScanRefusal("substitution in command position", t.offset);
247
+ }
248
+ collect(tokenize(t.src, t.offset), commands, redirects);
249
+ continue;
250
+ }
251
+ if (t.type === "redirect") {
252
+ const target = segment[k + 1];
253
+ if (!target || target.type !== "word") throw new ScanRefusal("redirect without target", t.offset);
254
+ if (target.value.startsWith("$")) throw new ScanRefusal("variable redirect target", target.offset);
255
+ redirects.push({ mode: t.mode, target: target.value, offset: target.offset });
256
+ k++;
257
+ continue;
258
+ }
259
+ words.push(t);
260
+ }
261
+ const real = stripAssignments(words);
262
+ if (real.length === 0) continue;
263
+ const program = real[0].value;
264
+ const args = real.slice(1).map((w) => w.value);
265
+ if (program.startsWith("$")) throw new ScanRefusal("variable in command position", real[0].offset);
266
+ if (CONTROL_KEYWORDS.has(program)) throw new ScanRefusal("control structure", real[0].offset);
267
+ if (program === "eval") throw new ScanRefusal("eval", real[0].offset);
268
+ if (program === "xargs") throw new ScanRefusal("xargs", real[0].offset);
269
+ if (NESTED_INTERPRETERS.has(program) && args.includes("-c")) {
270
+ throw new ScanRefusal("nested interpreter", real[0].offset);
271
+ }
272
+ if (program === "find" && args.some((a) => a === "-exec" || a === "-execdir" || a === "-ok")) {
273
+ throw new ScanRefusal("find -exec", real[0].offset);
274
+ }
275
+ commands.push({ program, args, segment: [program, ...args].join(" "), offset: real[0].offset });
276
+ }
277
+ }
278
+
279
+ // src/rune/permissions/shell-check.js
280
+ init_require_shim();
281
+ var BUILTIN_ALLOWLIST = /* @__PURE__ */ new Set([
282
+ "cd",
283
+ "echo",
284
+ "printf",
285
+ "test",
286
+ "[",
287
+ "pwd",
288
+ "true",
289
+ "false",
290
+ "export",
291
+ "set",
292
+ "unset",
293
+ "shift",
294
+ "read",
295
+ ":"
296
+ ]);
297
+ function checkShellCommand(cmd, shellKind, checkPermission) {
298
+ if (!checkPermission) return;
299
+ let scanned;
300
+ try {
301
+ scanned = scanCommand(cmd, shellKind);
302
+ } catch (e) {
303
+ if (e instanceof ScanRefusal) {
304
+ throw new PermissionError("shell.run", cmd, "unscannable", {
305
+ construct: e.construct,
306
+ offset: e.offset
307
+ });
308
+ }
309
+ throw e;
310
+ }
311
+ for (const command of scanned.commands) {
312
+ if (BUILTIN_ALLOWLIST.has(command.program)) continue;
313
+ checkPermission("shell.run", command.segment);
314
+ }
315
+ for (const redirect of scanned.redirects) {
316
+ checkPermission(redirect.mode === "write" ? "fs.write" : "fs.read", redirect.target);
317
+ }
318
+ }
319
+
320
+ export {
321
+ ScanRefusal,
322
+ scanCommand,
323
+ BUILTIN_ALLOWLIST,
324
+ checkShellCommand
325
+ };