@darkrymit/crunes-cli 0.9.0 → 0.10.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/dist/chunks/add-2OM5KGN5.js +67 -0
- package/dist/chunks/{apply-YY7MIM64.js → apply-GBUQQ4XF.js} +21 -9
- package/dist/chunks/{benchmark-BQNMULOO.js → benchmark-QWGVX3BX.js} +21 -15
- package/dist/chunks/chunk-2DNYVKBF.js +109 -0
- package/dist/chunks/chunk-2HM5Q52B.js +131 -0
- package/dist/chunks/chunk-3KKRNQQU.js +275 -0
- package/dist/chunks/chunk-55GTJG5I.js +1154 -0
- package/dist/chunks/chunk-7KYCYDAS.js +325 -0
- package/dist/chunks/{chunk-SNC7AOT7.js → chunk-AL37NFWR.js} +45 -94
- package/dist/chunks/chunk-ARIFLX5E.js +9525 -0
- package/dist/chunks/{chunk-X7PZN73N.js → chunk-E7CZPAM2.js} +1 -1
- package/dist/chunks/chunk-EO3CSXWK.js +70 -0
- package/dist/chunks/chunk-FIAFVIAN.js +79 -0
- package/dist/chunks/{chunk-MRNZFUXZ.js → chunk-KQMTTEJV.js} +22 -7
- package/dist/chunks/chunk-KX6QEHM5.js +578 -0
- package/dist/chunks/{chunk-VST6HAB6.js → chunk-MTJ2KW3V.js} +2 -0
- package/dist/chunks/chunk-MUWDZJN2.js +71 -0
- package/dist/chunks/{chunk-CY6C6ADU.js → chunk-MVCBPI4J.js} +45 -478
- package/dist/chunks/{chunk-34F4ZURL.js → chunk-NJVPLN5D.js} +29 -12
- package/dist/chunks/chunk-UBCAZGLE.js +15 -0
- package/dist/chunks/chunk-VP7YLCQP.js +244 -0
- package/dist/chunks/chunk-VSMAZISQ.js +303 -0
- package/dist/chunks/chunk-WE4HDHFU.js +37 -0
- package/dist/chunks/{create-ET6DT5ZE.js → create-2CQZF53Z.js} +5 -2
- package/dist/chunks/{create-LM7U3CJS.js → create-36F6V4WP.js} +99 -6
- package/dist/chunks/{create-TLPM7HJE.js → create-DXW4YYLJ.js} +5 -5
- package/dist/chunks/{disable-TNTEIAKO.js → disable-FB64CSYV.js} +5 -2
- package/dist/chunks/doctor-PVO4JLYN.js +208 -0
- package/dist/chunks/{enable-GUQCB4CU.js → enable-UVXHTKCJ.js} +6 -3
- package/dist/chunks/{init-PJSCFOC6.js → init-GPNC7TR5.js} +5 -2
- package/dist/chunks/{install-4YP7FALO.js → install-3G7U5ZIO.js} +10 -5
- package/dist/chunks/{intro-SA7MWV3Z.js → intro-YI5HUZCF.js} +45 -19
- package/dist/chunks/{list-WKNPZZOV.js → list-J2UCBYAY.js} +9 -6
- package/dist/chunks/list-JB4447YK.js +62 -0
- package/dist/chunks/{list-7R6NASFI.js → list-W4JAYPAA.js} +19 -19
- package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
- package/dist/chunks/{registry-K5DV5NAK.js → registry-IWP7JMNI.js} +1 -1
- package/dist/chunks/{repl-ZB3DIJ4K.js → repl-MWFEZ65P.js} +30 -20
- package/dist/chunks/resolver-URPQMOIV.js +36 -0
- package/dist/chunks/{run-22B65ZWZ.js → run-3VKWSRLO.js} +17 -11
- package/dist/chunks/rune-L5EP645W.js +283 -0
- package/dist/chunks/runner-VPTLUQJE.js +34 -0
- package/dist/chunks/{shell-explain-QLITLHW7.js → shell-explain-LKBBP2BG.js} +5 -2
- package/dist/chunks/trust-LXXYSF6W.js +109 -0
- package/dist/chunks/{uninstall-4WR5IHLC.js → uninstall-J7JUYETA.js} +10 -5
- package/dist/chunks/{update-ACLDK6E6.js → update-ZJRLDCUT.js} +10 -5
- package/dist/chunks/{version-EULYWNXN.js → version-ZULO6CV3.js} +2 -2
- package/dist/cli.js +47 -34
- package/package.json +2 -2
- package/dist/chunks/chunk-G3U4V32O.js +0 -46
- package/dist/chunks/chunk-QYRF3R35.js +0 -154
- package/dist/chunks/chunk-YXCHIMLW.js +0 -75308
- package/dist/chunks/doctor-VXAQYMTR.js +0 -101
- package/dist/chunks/list-OMMZAQ23.js +0 -28
- package/dist/chunks/resolver-QIYYFIDX.js +0 -34
- package/dist/chunks/rune-SYK4N642.js +0 -425
- package/dist/chunks/{delete-5R3WBLVD.js → delete-2EXPFBFC.js} +4 -4
- 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
|
+
};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isVerbose,
|
|
3
|
+
output
|
|
4
|
+
} from "./chunk-MIKWIFYR.js";
|
|
1
5
|
import {
|
|
2
6
|
describeConfigLayers,
|
|
3
7
|
runRune
|
|
4
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-VSMAZISQ.js";
|
|
5
9
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./chunk-CY6C6ADU.js";
|
|
10
|
+
renderSection
|
|
11
|
+
} from "./chunk-KX6QEHM5.js";
|
|
9
12
|
import {
|
|
10
13
|
loadConfig
|
|
11
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-3KKRNQQU.js";
|
|
12
15
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
isGlobMatch,
|
|
17
|
+
isWildcardMatch
|
|
18
|
+
} from "./chunk-MVCBPI4J.js";
|
|
16
19
|
import {
|
|
17
20
|
init_require_shim
|
|
18
21
|
} from "./chunk-TPK5AGRA.js";
|
|
@@ -58,56 +61,6 @@ function permissionHint(message, { key, lifecycle = "run", configLayers }) {
|
|
|
58
61
|
return lines.join("\n");
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
// src/shared/render.js
|
|
62
|
-
init_require_shim();
|
|
63
|
-
function render(data) {
|
|
64
|
-
if (!data) return null;
|
|
65
|
-
if (data.type === "tree") return renderTree(data.root);
|
|
66
|
-
if (data.type === "markdown") return data.content ?? null;
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
function renderSection(section) {
|
|
70
|
-
const parts = [];
|
|
71
|
-
if (section.title) {
|
|
72
|
-
parts.push(`## ${section.title}`);
|
|
73
|
-
} else if (section.name) {
|
|
74
|
-
parts.push(`## ${section.name}`);
|
|
75
|
-
} else {
|
|
76
|
-
parts.push("## (no title)");
|
|
77
|
-
}
|
|
78
|
-
if (section.attrs && Object.keys(section.attrs).length > 0) {
|
|
79
|
-
const attrStr = Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ");
|
|
80
|
-
parts.push(attrStr);
|
|
81
|
-
}
|
|
82
|
-
const content = render(section.data);
|
|
83
|
-
if (content) {
|
|
84
|
-
parts.push(content);
|
|
85
|
-
}
|
|
86
|
-
return parts.filter(Boolean).join("\n") || null;
|
|
87
|
-
}
|
|
88
|
-
function formatSection(section, rune) {
|
|
89
|
-
const nameStr = section.title ?? section.name ?? "(no title)";
|
|
90
|
-
const attrsStr = section.attrs && Object.keys(section.attrs).length > 0 ? " " + Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ") : "";
|
|
91
|
-
const content = render(section.data);
|
|
92
|
-
return `[${rune}:section] ${nameStr}${attrsStr}${content ? "\n" + content : ""}`;
|
|
93
|
-
}
|
|
94
|
-
function renderTree(root) {
|
|
95
|
-
if (!root) return null;
|
|
96
|
-
const lines = [`${root.name.padEnd(12)}${root.description}`];
|
|
97
|
-
appendChildren(root.children ?? [], "", lines);
|
|
98
|
-
return lines.join("\n");
|
|
99
|
-
}
|
|
100
|
-
function appendChildren(children, prefix, lines) {
|
|
101
|
-
for (let i = 0; i < children.length; i++) {
|
|
102
|
-
const child = children[i];
|
|
103
|
-
const isLast = i === children.length - 1;
|
|
104
|
-
const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
105
|
-
const childPrefix = prefix + (isLast ? " " : "\u2502 ");
|
|
106
|
-
lines.push(`${prefix}${connector}${child.name.padEnd(12)}${child.description}`);
|
|
107
|
-
appendChildren(child.children ?? [], childPrefix, lines);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
64
|
// src/rune/commands/batch-permission.js
|
|
112
65
|
init_require_shim();
|
|
113
66
|
function buildMatchString(key, args) {
|
|
@@ -221,6 +174,25 @@ function parseRunArgs(argv) {
|
|
|
221
174
|
const segments = rawSegments.map(parseSegment);
|
|
222
175
|
return { segments, format, failFast, isBatch: allowBatch };
|
|
223
176
|
}
|
|
177
|
+
function framedSection(prefix, section) {
|
|
178
|
+
const rendered = renderSection(section);
|
|
179
|
+
if (!rendered) return null;
|
|
180
|
+
const lines = rendered.split("\n");
|
|
181
|
+
let contentStartIndex = 1;
|
|
182
|
+
let attrs = "";
|
|
183
|
+
if (lines[1] && lines[1].startsWith("[")) {
|
|
184
|
+
attrs = " " + lines[1];
|
|
185
|
+
contentStartIndex = 2;
|
|
186
|
+
}
|
|
187
|
+
return `${prefix} ${section.name}${attrs}
|
|
188
|
+
${lines.slice(contentStartIndex).join("\n")}
|
|
189
|
+
|
|
190
|
+
`;
|
|
191
|
+
}
|
|
192
|
+
function writeSection(direct, prefix, section) {
|
|
193
|
+
const text = direct ? (renderSection(section) ?? "") + "\n\n" : framedSection(prefix, section);
|
|
194
|
+
if (text) process.stdout.write(text);
|
|
195
|
+
}
|
|
224
196
|
async function handler({
|
|
225
197
|
segments,
|
|
226
198
|
format = "text",
|
|
@@ -244,8 +216,8 @@ async function handler({
|
|
|
244
216
|
process.exit(1);
|
|
245
217
|
}
|
|
246
218
|
if (isBatch) {
|
|
247
|
-
const { resolvePluginRune } = await import("./resolver-
|
|
248
|
-
const { loadPluginJson } = await import("./manifest-
|
|
219
|
+
const { resolvePluginRune } = await import("./resolver-URPQMOIV.js");
|
|
220
|
+
const { loadPluginJson } = await import("./manifest-76MIEL2F.js");
|
|
249
221
|
for (const seg of segments) {
|
|
250
222
|
let entry = config.runes?.[seg.key] ?? {};
|
|
251
223
|
if (!entry.batch && seg.key.includes(":")) {
|
|
@@ -266,7 +238,7 @@ async function handler({
|
|
|
266
238
|
const spaceIdx = matchString.indexOf(" ");
|
|
267
239
|
const subject = spaceIdx === -1 ? matchString : matchString.slice(spaceIdx + 1);
|
|
268
240
|
const lines = [`Batch not permitted for "${matchString}" \u2014 ${result.reason}.`, ""];
|
|
269
|
-
lines.push(` "batch" is a
|
|
241
|
+
lines.push(` "batch" is a field of the rune entry, beside "run" \u2014 not inside a block:`);
|
|
270
242
|
lines.push("");
|
|
271
243
|
lines.push(` "runes": { "${seg.key}": { "batch": { "allow": ["${subject}"] } } }`);
|
|
272
244
|
lines.push("");
|
|
@@ -279,6 +251,7 @@ async function handler({
|
|
|
279
251
|
}
|
|
280
252
|
}
|
|
281
253
|
let anyFailed = false;
|
|
254
|
+
const direct = !isBatch && format === "text" && segments.length === 1;
|
|
282
255
|
for (let i = 0; i < segments.length; i++) {
|
|
283
256
|
const printedSections = /* @__PURE__ */ new Set();
|
|
284
257
|
const { key, sections: sectionFilter, runeArgs } = segments[i];
|
|
@@ -289,6 +262,8 @@ async function handler({
|
|
|
289
262
|
sections: sectionFilter,
|
|
290
263
|
configDir: configRoot,
|
|
291
264
|
instanceId: String(i + 1),
|
|
265
|
+
direct,
|
|
266
|
+
stdin: isBatch ? "ignore" : "inherit",
|
|
292
267
|
onEvent(event) {
|
|
293
268
|
const { type, level, message, meta, section, instanceId: instanceId2, rune } = event;
|
|
294
269
|
const prefix = level ? `[${instanceId2}:${rune}:${type}:${level}]` : `[${instanceId2}:${rune}:${type}]`;
|
|
@@ -311,30 +286,21 @@ async function handler({
|
|
|
311
286
|
} else {
|
|
312
287
|
if (type === "section") {
|
|
313
288
|
if (!sectionFilter || isGlobMatch(section.name, sectionFilter)) {
|
|
314
|
-
|
|
315
|
-
const lines = rendered ? rendered.split("\n") : [];
|
|
316
|
-
let contentStartIndex = 1;
|
|
317
|
-
let attrs = "";
|
|
318
|
-
if (lines[1] && lines[1].startsWith("[")) {
|
|
319
|
-
attrs = " " + lines[1];
|
|
320
|
-
contentStartIndex = 2;
|
|
321
|
-
}
|
|
322
|
-
const content = lines.slice(contentStartIndex).join("\n");
|
|
323
|
-
process.stdout.write(`${prefix} ${section.name}${attrs}
|
|
324
|
-
${content}
|
|
325
|
-
|
|
326
|
-
`);
|
|
289
|
+
writeSection(direct, prefix, section);
|
|
327
290
|
printedSections.add(section);
|
|
328
291
|
}
|
|
329
292
|
} else {
|
|
330
293
|
const attrsStr = meta && Object.keys(meta).length > 0 ? " " + Object.entries(meta).map(([k, v]) => `[${k}: ${v}]`).join(" ") : "";
|
|
331
|
-
if (
|
|
332
|
-
process.
|
|
294
|
+
if (direct) {
|
|
295
|
+
process.stderr.write(`${message ?? ""}${attrsStr}
|
|
296
|
+
`);
|
|
297
|
+
} else if (message && message.includes("\n")) {
|
|
298
|
+
process.stderr.write(`${prefix}${attrsStr}
|
|
333
299
|
${message}
|
|
334
300
|
|
|
335
301
|
`);
|
|
336
302
|
} else {
|
|
337
|
-
process.
|
|
303
|
+
process.stderr.write(`${prefix} ${message ?? ""}${attrsStr}
|
|
338
304
|
`);
|
|
339
305
|
}
|
|
340
306
|
}
|
|
@@ -355,6 +321,7 @@ ${msg}${hint ?? ""}`);
|
|
|
355
321
|
if (failFast) process.exit(1);
|
|
356
322
|
continue;
|
|
357
323
|
}
|
|
324
|
+
if (sections?.directExitCode !== void 0) return process.exit(sections.directExitCode);
|
|
358
325
|
if (!sections) {
|
|
359
326
|
const available = Object.keys(config.runes ?? {}).join(", ") || "(none)";
|
|
360
327
|
output.error(`Unknown key: "${key}". Available: ${available}. Looked in: ${describeConfigLayers(configRoot ?? projectRoot)}.`);
|
|
@@ -375,22 +342,7 @@ ${msg}${hint ?? ""}`);
|
|
|
375
342
|
section: sect
|
|
376
343
|
}) + "\n");
|
|
377
344
|
} else {
|
|
378
|
-
|
|
379
|
-
if (rendered) {
|
|
380
|
-
const prefix = `[${instanceId}:${key}:section]`;
|
|
381
|
-
const lines = rendered.split("\n");
|
|
382
|
-
let contentStartIndex = 1;
|
|
383
|
-
let attrs = "";
|
|
384
|
-
if (lines[1] && lines[1].startsWith("[")) {
|
|
385
|
-
attrs = " " + lines[1];
|
|
386
|
-
contentStartIndex = 2;
|
|
387
|
-
}
|
|
388
|
-
const content = lines.slice(contentStartIndex).join("\n");
|
|
389
|
-
process.stdout.write(`${prefix} ${sect.name}${attrs}
|
|
390
|
-
${content}
|
|
391
|
-
|
|
392
|
-
`);
|
|
393
|
-
}
|
|
345
|
+
writeSection(direct, `[${instanceId}:${key}:section]`, sect);
|
|
394
346
|
}
|
|
395
347
|
printedSections.add(sect);
|
|
396
348
|
}
|
|
@@ -401,7 +353,6 @@ ${content}
|
|
|
401
353
|
|
|
402
354
|
export {
|
|
403
355
|
permissionHint,
|
|
404
|
-
formatSection,
|
|
405
356
|
parseBracketKey,
|
|
406
357
|
joinBracketTokens,
|
|
407
358
|
parseSegment,
|