@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.
- package/dist/chunks/add-MSX6XSU3.js +68 -0
- package/dist/chunks/{apply-YY7MIM64.js → apply-LOIJIPLR.js} +18 -9
- package/dist/chunks/{benchmark-BQNMULOO.js → benchmark-3IHFP3V2.js} +21 -15
- package/dist/chunks/chunk-2DNYVKBF.js +109 -0
- package/dist/chunks/chunk-2FI6KN3C.js +283 -0
- package/dist/chunks/chunk-2HM5Q52B.js +131 -0
- package/dist/chunks/chunk-55GTJG5I.js +1154 -0
- package/dist/chunks/chunk-6IC6ZJ74.js +9525 -0
- package/dist/chunks/chunk-7KYCYDAS.js +325 -0
- package/dist/chunks/chunk-DTOYFY3Z.js +578 -0
- package/dist/chunks/chunk-EO3CSXWK.js +70 -0
- package/dist/chunks/chunk-FIAFVIAN.js +79 -0
- package/dist/chunks/chunk-H2OT7D6N.js +303 -0
- package/dist/chunks/{chunk-MRNZFUXZ.js → chunk-KSQDFE5N.js} +22 -7
- package/dist/chunks/{chunk-SNC7AOT7.js → chunk-KUEMDPNG.js} +45 -94
- package/dist/chunks/{chunk-VST6HAB6.js → chunk-MTJ2KW3V.js} +2 -0
- package/dist/chunks/{chunk-CY6C6ADU.js → chunk-MVCBPI4J.js} +45 -478
- package/dist/chunks/{chunk-34F4ZURL.js → chunk-RVBAAXRY.js} +29 -12
- package/dist/chunks/{chunk-X7PZN73N.js → chunk-SUCYDYMU.js} +1 -1
- package/dist/chunks/chunk-UBCAZGLE.js +15 -0
- package/dist/chunks/chunk-VP7YLCQP.js +244 -0
- package/dist/chunks/chunk-XDMMSZIL.js +71 -0
- package/dist/chunks/chunk-YKIKJHYO.js +94 -0
- package/dist/chunks/{create-TLPM7HJE.js → create-DXW4YYLJ.js} +5 -5
- package/dist/chunks/{create-LM7U3CJS.js → create-LPLNCOW4.js} +100 -6
- package/dist/chunks/{create-ET6DT5ZE.js → create-Y4LHLWGL.js} +6 -2
- package/dist/chunks/{disable-TNTEIAKO.js → disable-TITOSMXB.js} +6 -2
- package/dist/chunks/doctor-R2Y6UAY4.js +208 -0
- package/dist/chunks/{enable-GUQCB4CU.js → enable-LGTPDWPV.js} +7 -3
- package/dist/chunks/{init-PJSCFOC6.js → init-KO2HLED5.js} +6 -2
- package/dist/chunks/{install-4YP7FALO.js → install-7IRUAGSF.js} +10 -5
- package/dist/chunks/{intro-SA7MWV3Z.js → intro-JNJ6A75J.js} +44 -18
- package/dist/chunks/{list-WKNPZZOV.js → list-BCCM3TLP.js} +10 -6
- package/dist/chunks/{list-7R6NASFI.js → list-MLKZE36K.js} +19 -19
- package/dist/chunks/list-QVZKR3IE.js +62 -0
- package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
- package/dist/chunks/migrate-Y3EKMVP5.js +87 -0
- package/dist/chunks/{registry-K5DV5NAK.js → registry-IWP7JMNI.js} +1 -1
- package/dist/chunks/{repl-ZB3DIJ4K.js → repl-5GDN3RAO.js} +30 -20
- package/dist/chunks/resolver-CA2A32AC.js +36 -0
- package/dist/chunks/{run-22B65ZWZ.js → run-WL3IZBXF.js} +17 -11
- package/dist/chunks/rune-YA4TFHTB.js +283 -0
- package/dist/chunks/runner-QNZMBHQY.js +34 -0
- package/dist/chunks/{shell-explain-QLITLHW7.js → shell-explain-LKBBP2BG.js} +5 -2
- package/dist/chunks/trust-BFIDANXD.js +109 -0
- package/dist/chunks/{uninstall-4WR5IHLC.js → uninstall-3MWZIZVA.js} +10 -5
- package/dist/chunks/{update-ACLDK6E6.js → update-W4MJUTTW.js} +10 -5
- package/dist/chunks/{version-EULYWNXN.js → version-FLHI5KFS.js} +2 -2
- package/dist/cli.js +51 -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,578 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertNotMissedRename,
|
|
3
|
+
resolveInterpreter,
|
|
4
|
+
runtimeOf
|
|
5
|
+
} from "./chunk-2DNYVKBF.js";
|
|
6
|
+
import {
|
|
7
|
+
isPathCommand
|
|
8
|
+
} from "./chunk-UBCAZGLE.js";
|
|
9
|
+
import {
|
|
10
|
+
isInlineSchema,
|
|
11
|
+
loadJsonSchema,
|
|
12
|
+
mapToArgv,
|
|
13
|
+
normaliseJsonSchema,
|
|
14
|
+
undeclaredArgs,
|
|
15
|
+
validateParsed
|
|
16
|
+
} from "./chunk-VP7YLCQP.js";
|
|
17
|
+
import {
|
|
18
|
+
computeEffectivePermissions,
|
|
19
|
+
isGlobMatch
|
|
20
|
+
} from "./chunk-MVCBPI4J.js";
|
|
21
|
+
import {
|
|
22
|
+
getLocalBase
|
|
23
|
+
} from "./chunk-2Q3KLBE6.js";
|
|
24
|
+
import {
|
|
25
|
+
parseArgs
|
|
26
|
+
} from "./chunk-55GTJG5I.js";
|
|
27
|
+
import {
|
|
28
|
+
init_require_shim
|
|
29
|
+
} from "./chunk-TPK5AGRA.js";
|
|
30
|
+
|
|
31
|
+
// src/docs/help-render.js
|
|
32
|
+
init_require_shim();
|
|
33
|
+
var PAD = 24;
|
|
34
|
+
function row(label, description, indent = " ") {
|
|
35
|
+
const padded = label.length >= PAD ? label + " " : label.padEnd(PAD);
|
|
36
|
+
return `${indent}${padded} ${description ?? ""}`.trimEnd();
|
|
37
|
+
}
|
|
38
|
+
function positionalSpecs(node) {
|
|
39
|
+
return (node?.positionals ?? []).map((p) => p.spec).join(" ");
|
|
40
|
+
}
|
|
41
|
+
function flattenCommands(commands, prefix = "") {
|
|
42
|
+
const rows = [];
|
|
43
|
+
for (const cmd of commands ?? []) {
|
|
44
|
+
const path = prefix ? `${prefix} ${cmd.name}` : cmd.name;
|
|
45
|
+
const specs = positionalSpecs(cmd);
|
|
46
|
+
rows.push({
|
|
47
|
+
path,
|
|
48
|
+
label: specs ? `${path} ${specs}` : path,
|
|
49
|
+
description: cmd.description ?? "",
|
|
50
|
+
node: cmd
|
|
51
|
+
});
|
|
52
|
+
rows.push(...flattenCommands(cmd.commands ?? [], path));
|
|
53
|
+
}
|
|
54
|
+
return rows;
|
|
55
|
+
}
|
|
56
|
+
function selectNode(schema, segments) {
|
|
57
|
+
let node = schema;
|
|
58
|
+
const matched = [];
|
|
59
|
+
for (const seg of segments ?? []) {
|
|
60
|
+
const children = node?.commands ?? [];
|
|
61
|
+
const next = children.find((c) => c.name === seg);
|
|
62
|
+
if (!next) {
|
|
63
|
+
return {
|
|
64
|
+
node: null,
|
|
65
|
+
matchedPath: matched.join(" "),
|
|
66
|
+
failedAt: seg,
|
|
67
|
+
candidates: children.map((c) => c.name)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
node = next;
|
|
71
|
+
matched.push(seg);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
node,
|
|
75
|
+
matchedPath: matched.join(" "),
|
|
76
|
+
failedAt: null,
|
|
77
|
+
candidates: (node?.commands ?? []).map((c) => c.name)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function verb(lifecycle) {
|
|
81
|
+
return lifecycle === "repl" ? "repl" : "run";
|
|
82
|
+
}
|
|
83
|
+
var choicesNote = (choices) => choices ? ` [choices: ${choices.map((c) => JSON.stringify(c)).join(", ")}]` : "";
|
|
84
|
+
var typeNote = (type) => type ? ` [${type}]` : "";
|
|
85
|
+
function optionRows(options, indent = " ") {
|
|
86
|
+
return (options ?? []).map((opt) => {
|
|
87
|
+
const def = opt.def !== void 0 ? ` [default: ${JSON.stringify(opt.def)}]` : "";
|
|
88
|
+
const required = opt.required ? " [required]" : "";
|
|
89
|
+
return row(opt.flags, `${opt.description ?? ""}${typeNote(opt.type)}${def}${required}${choicesNote(opt.choices)}`, indent);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function positionalRow(p, indent) {
|
|
93
|
+
return row(p.spec ?? "", `${p.description ?? ""}${typeNote(p.type)}${choicesNote(p.choices)}`, indent);
|
|
94
|
+
}
|
|
95
|
+
function exampleLines(examples, indent = " ") {
|
|
96
|
+
const lines = [];
|
|
97
|
+
for (const ex of examples ?? []) {
|
|
98
|
+
lines.push(`${indent}${ex.usage}`);
|
|
99
|
+
if (ex.description) lines.push(`${indent} ${ex.description}`);
|
|
100
|
+
}
|
|
101
|
+
return lines;
|
|
102
|
+
}
|
|
103
|
+
function formatCommandPage(node, meta) {
|
|
104
|
+
const key = meta?.key ?? "rune";
|
|
105
|
+
const path = meta?.path ?? "";
|
|
106
|
+
const specs = positionalSpecs(node);
|
|
107
|
+
const children = node?.commands ?? [];
|
|
108
|
+
const usage = [`Usage: crunes ${verb(meta?.lifecycle)} ${key}`];
|
|
109
|
+
if (path) usage.push(path);
|
|
110
|
+
if (specs) usage.push(specs);
|
|
111
|
+
else if (children.length > 0) usage.push("<command>");
|
|
112
|
+
usage.push("[options]");
|
|
113
|
+
const lines = [usage.join(" ")];
|
|
114
|
+
if (node?.description) {
|
|
115
|
+
lines.push("");
|
|
116
|
+
lines.push(` ${node.description}`);
|
|
117
|
+
}
|
|
118
|
+
const positionals = node?.positionals ?? [];
|
|
119
|
+
if (positionals.length > 0) {
|
|
120
|
+
lines.push("");
|
|
121
|
+
lines.push("Positionals:");
|
|
122
|
+
for (const p of positionals) lines.push(positionalRow(p));
|
|
123
|
+
}
|
|
124
|
+
const options = node?.options ?? [];
|
|
125
|
+
if (options.length > 0) {
|
|
126
|
+
lines.push("");
|
|
127
|
+
lines.push("Options:");
|
|
128
|
+
lines.push(...optionRows(options));
|
|
129
|
+
}
|
|
130
|
+
if (children.length > 0) {
|
|
131
|
+
lines.push("");
|
|
132
|
+
lines.push("Commands:");
|
|
133
|
+
for (const child of children) {
|
|
134
|
+
const childPath = path ? `${path} ${child.name}` : child.name;
|
|
135
|
+
const childSpecs = positionalSpecs(child);
|
|
136
|
+
lines.push(row(childSpecs ? `${childPath} ${childSpecs}` : childPath, child.description));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const examples = node?.examples ?? [];
|
|
140
|
+
if (examples.length > 0) {
|
|
141
|
+
lines.push("");
|
|
142
|
+
lines.push("Examples:");
|
|
143
|
+
lines.push(...exampleLines(examples));
|
|
144
|
+
}
|
|
145
|
+
return lines.join("\n");
|
|
146
|
+
}
|
|
147
|
+
function formatRuneIndex(schema, meta) {
|
|
148
|
+
const key = meta?.key ?? "rune";
|
|
149
|
+
const label = meta?.description ?? meta?.name ?? null;
|
|
150
|
+
const commands = schema?.commands ?? [];
|
|
151
|
+
const specs = positionalSpecs(schema);
|
|
152
|
+
const lines = [`Rune: ${key}${label ? ` \u2014 ${label}` : ""}`];
|
|
153
|
+
if (meta?.relativePath) lines.push(`File (project-relative): ${meta.relativePath}`);
|
|
154
|
+
if (meta?.runs) lines.push(`Runs: ${meta.runs}`);
|
|
155
|
+
if (meta?.passThrough) lines.push("No argument schema \u2014 arguments are passed to it unchanged. Add an args block to document and parse them.");
|
|
156
|
+
const usage = [`Usage: crunes ${verb(meta?.lifecycle)} ${key}`];
|
|
157
|
+
if (specs) usage.push(specs);
|
|
158
|
+
else if (commands.length > 0) usage.push("<command>");
|
|
159
|
+
usage.push("[options]");
|
|
160
|
+
lines.push("");
|
|
161
|
+
lines.push(usage.join(" "));
|
|
162
|
+
const positionals = schema?.positionals ?? [];
|
|
163
|
+
if (positionals.length > 0) {
|
|
164
|
+
lines.push("");
|
|
165
|
+
lines.push("Positionals:");
|
|
166
|
+
for (const p of positionals) lines.push(positionalRow(p));
|
|
167
|
+
}
|
|
168
|
+
const options = schema?.options ?? [];
|
|
169
|
+
if (options.length > 0) {
|
|
170
|
+
lines.push("");
|
|
171
|
+
lines.push("Options:");
|
|
172
|
+
lines.push(...optionRows(options));
|
|
173
|
+
}
|
|
174
|
+
if (commands.length > 0) {
|
|
175
|
+
lines.push("");
|
|
176
|
+
lines.push("Commands:");
|
|
177
|
+
for (const r of flattenCommands(commands)) lines.push(row(r.label, r.description));
|
|
178
|
+
}
|
|
179
|
+
const rootExamples = schema?.examples ?? [];
|
|
180
|
+
if (commands.length === 0 && rootExamples.length > 0) {
|
|
181
|
+
lines.push("");
|
|
182
|
+
lines.push("Examples:");
|
|
183
|
+
lines.push(...exampleLines(rootExamples));
|
|
184
|
+
}
|
|
185
|
+
const replCommands = meta?.repl?.commands ?? [];
|
|
186
|
+
if (replCommands.length > 0) {
|
|
187
|
+
lines.push("");
|
|
188
|
+
lines.push("REPL commands:");
|
|
189
|
+
for (const c of replCommands) lines.push(row(`/${c.name}`, c.description));
|
|
190
|
+
}
|
|
191
|
+
if (meta?.includeBatch === true) {
|
|
192
|
+
lines.push("");
|
|
193
|
+
lines.push("Batch:");
|
|
194
|
+
if (!meta.batch) {
|
|
195
|
+
lines.push(" (no batch block declared \u2014 this rune cannot appear in a -b batch)");
|
|
196
|
+
} else {
|
|
197
|
+
const allow = meta.batch.allow ?? [];
|
|
198
|
+
const deny = meta.batch.deny ?? [];
|
|
199
|
+
lines.push(` allow: ${allow.length ? allow.join(", ") : "(none)"}`);
|
|
200
|
+
if (deny.length) lines.push(` deny: ${deny.join(", ")}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (commands.length > 0) {
|
|
204
|
+
lines.push("");
|
|
205
|
+
lines.push(`Drill down: crunes docs rune ${key} <command>`);
|
|
206
|
+
}
|
|
207
|
+
return lines.join("\n");
|
|
208
|
+
}
|
|
209
|
+
var GLOBAL_PAD = 50;
|
|
210
|
+
function formatGlobalIndex(entries) {
|
|
211
|
+
if (!entries || entries.length === 0) {
|
|
212
|
+
return "No runes configured. Run `crunes create <key>` to add one.";
|
|
213
|
+
}
|
|
214
|
+
const lines = ["Runes:", ""];
|
|
215
|
+
for (const e of entries) {
|
|
216
|
+
if (e.error) {
|
|
217
|
+
lines.push(`\u26A0 ${e.key} \u2014 could not build args schema: ${e.error}`);
|
|
218
|
+
lines.push("");
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const label = e.description ?? e.name ?? "";
|
|
222
|
+
const head = `${e.key}${label ? ` \u2014 ${label}` : ""}`;
|
|
223
|
+
const padded = head.length >= GLOBAL_PAD ? head + " " : head.padEnd(GLOBAL_PAD);
|
|
224
|
+
lines.push(`${padded}${e.source ?? ""}`.trimEnd());
|
|
225
|
+
for (const r of flattenCommands(e.schema?.commands ?? [])) {
|
|
226
|
+
lines.push(row(r.label, r.description));
|
|
227
|
+
}
|
|
228
|
+
lines.push("");
|
|
229
|
+
}
|
|
230
|
+
lines.push("Drill down: crunes docs rune <key> [command path...]");
|
|
231
|
+
return lines.join("\n");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/shared/render.js
|
|
235
|
+
init_require_shim();
|
|
236
|
+
function render(data) {
|
|
237
|
+
if (!data) return null;
|
|
238
|
+
if (data.type === "tree") return renderTree(data.root);
|
|
239
|
+
if (data.type === "markdown") return data.content ?? null;
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
function renderSection(section) {
|
|
243
|
+
const parts = [];
|
|
244
|
+
if (section.title) {
|
|
245
|
+
parts.push(`## ${section.title}`);
|
|
246
|
+
} else if (section.name) {
|
|
247
|
+
parts.push(`## ${section.name}`);
|
|
248
|
+
} else {
|
|
249
|
+
parts.push("## (no title)");
|
|
250
|
+
}
|
|
251
|
+
if (section.attrs && Object.keys(section.attrs).length > 0) {
|
|
252
|
+
const attrStr = Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ");
|
|
253
|
+
parts.push(attrStr);
|
|
254
|
+
}
|
|
255
|
+
const content = render(section.data);
|
|
256
|
+
if (content) {
|
|
257
|
+
parts.push(content);
|
|
258
|
+
}
|
|
259
|
+
return parts.filter(Boolean).join("\n") || null;
|
|
260
|
+
}
|
|
261
|
+
function formatSection(section, rune) {
|
|
262
|
+
const nameStr = section.title ?? section.name ?? "(no title)";
|
|
263
|
+
const attrsStr = section.attrs && Object.keys(section.attrs).length > 0 ? " " + Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ") : "";
|
|
264
|
+
const content = render(section.data);
|
|
265
|
+
return `[${rune}:section] ${nameStr}${attrsStr}${content ? "\n" + content : ""}`;
|
|
266
|
+
}
|
|
267
|
+
function renderTree(root) {
|
|
268
|
+
if (!root) return null;
|
|
269
|
+
const lines = [`${root.name.padEnd(12)}${root.description}`];
|
|
270
|
+
appendChildren(root.children ?? [], "", lines);
|
|
271
|
+
return lines.join("\n");
|
|
272
|
+
}
|
|
273
|
+
function appendChildren(children, prefix, lines) {
|
|
274
|
+
for (let i = 0; i < children.length; i++) {
|
|
275
|
+
const child = children[i];
|
|
276
|
+
const isLast = i === children.length - 1;
|
|
277
|
+
const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
278
|
+
const childPrefix = prefix + (isLast ? " " : "\u2502 ");
|
|
279
|
+
lines.push(`${prefix}${connector}${child.name.padEnd(12)}${child.description}`);
|
|
280
|
+
appendChildren(child.children ?? [], childPrefix, lines);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/rune/native/run-block.js
|
|
285
|
+
init_require_shim();
|
|
286
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
287
|
+
|
|
288
|
+
// src/rune/native/spawn.js
|
|
289
|
+
init_require_shim();
|
|
290
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
291
|
+
import { constants } from "node:os";
|
|
292
|
+
var TIMEOUT_STATUS = 124;
|
|
293
|
+
var KILL_GRACE_MS = 5e3;
|
|
294
|
+
function signalStatus(signal) {
|
|
295
|
+
return 128 + (constants.signals[signal] ?? 0);
|
|
296
|
+
}
|
|
297
|
+
function stopTree(child, signal) {
|
|
298
|
+
if (process.platform === "win32") {
|
|
299
|
+
spawnSync("taskkill", ["/pid", String(child.pid), "/T", "/F"], { windowsHide: true });
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const listed = spawnSync("pgrep", ["-P", String(child.pid)], { encoding: "utf8" }).stdout ?? "";
|
|
303
|
+
child.kill(signal);
|
|
304
|
+
for (const pid of listed.split("\n").filter(Boolean)) {
|
|
305
|
+
try {
|
|
306
|
+
process.kill(Number(pid), signal);
|
|
307
|
+
} catch {
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function notFound(key, command, err) {
|
|
312
|
+
if (err.code === "ENOENT") return new Error(`Rune "${key}": cannot run "${command}" \u2014 not found.`);
|
|
313
|
+
if (err.code === "EACCES") return new Error(`Rune "${key}": cannot run "${command}" \u2014 not executable.`);
|
|
314
|
+
return err;
|
|
315
|
+
}
|
|
316
|
+
function spawnNative({ key, file, argv, env, cwd, direct, stdin = "inherit", onLine = null, timeoutMs = null }) {
|
|
317
|
+
const [command, ...args] = argv;
|
|
318
|
+
return new Promise((resolve, reject) => {
|
|
319
|
+
let child;
|
|
320
|
+
try {
|
|
321
|
+
child = spawn(command, args, {
|
|
322
|
+
cwd,
|
|
323
|
+
env,
|
|
324
|
+
stdio: direct ? ["inherit", onLine ? "pipe" : "inherit", "inherit"] : [stdin, "pipe", "inherit"],
|
|
325
|
+
windowsHide: true
|
|
326
|
+
});
|
|
327
|
+
} catch (err) {
|
|
328
|
+
reject(notFound(key, file, err));
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const ignoreInterrupt = () => {
|
|
332
|
+
};
|
|
333
|
+
const forward = (signal) => () => child.kill(signal);
|
|
334
|
+
const forwarders = { SIGTERM: forward("SIGTERM"), SIGHUP: forward("SIGHUP") };
|
|
335
|
+
process.on("SIGINT", ignoreInterrupt);
|
|
336
|
+
for (const [signal, handler] of Object.entries(forwarders)) process.on(signal, handler);
|
|
337
|
+
let timedOut = false;
|
|
338
|
+
let killTimer = null;
|
|
339
|
+
const timer = timeoutMs == null ? null : setTimeout(() => {
|
|
340
|
+
timedOut = true;
|
|
341
|
+
stopTree(child, "SIGTERM");
|
|
342
|
+
killTimer = setTimeout(() => {
|
|
343
|
+
stopTree(child, "SIGKILL");
|
|
344
|
+
child.stdout?.destroy();
|
|
345
|
+
}, KILL_GRACE_MS);
|
|
346
|
+
}, timeoutMs);
|
|
347
|
+
const detach = () => {
|
|
348
|
+
process.off("SIGINT", ignoreInterrupt);
|
|
349
|
+
for (const [signal, handler] of Object.entries(forwarders)) process.off(signal, handler);
|
|
350
|
+
clearTimeout(timer);
|
|
351
|
+
clearTimeout(killTimer);
|
|
352
|
+
};
|
|
353
|
+
let stdout = "";
|
|
354
|
+
let pending = "";
|
|
355
|
+
if (onLine) {
|
|
356
|
+
child.stdout.setEncoding("utf8");
|
|
357
|
+
child.stdout.on("data", (chunk) => {
|
|
358
|
+
pending += chunk;
|
|
359
|
+
let nl;
|
|
360
|
+
while ((nl = pending.indexOf("\n")) !== -1) {
|
|
361
|
+
onLine(pending.slice(0, nl).replace(/\r$/, ""));
|
|
362
|
+
pending = pending.slice(nl + 1);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
} else if (!direct) {
|
|
366
|
+
child.stdout.setEncoding("utf8");
|
|
367
|
+
child.stdout.on("data", (chunk) => {
|
|
368
|
+
stdout += chunk;
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
child.on("exit", () => {
|
|
372
|
+
if (timedOut) child.stdout?.destroy();
|
|
373
|
+
});
|
|
374
|
+
child.on("error", (err) => {
|
|
375
|
+
detach();
|
|
376
|
+
reject(notFound(key, file, err));
|
|
377
|
+
});
|
|
378
|
+
child.on("close", (code, signal) => {
|
|
379
|
+
detach();
|
|
380
|
+
if (onLine && pending) onLine(pending.replace(/\r$/, ""));
|
|
381
|
+
if (timedOut) {
|
|
382
|
+
const message = `Rune "${key}" timed out after ${timeoutMs / 1e3}s and was stopped.`;
|
|
383
|
+
if (!direct) {
|
|
384
|
+
reject(new Error(message));
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
process.stderr.write(`[crunes] ${message}
|
|
388
|
+
`);
|
|
389
|
+
resolve({ exitCode: TIMEOUT_STATUS });
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const status = code ?? signalStatus(signal);
|
|
393
|
+
if (direct) {
|
|
394
|
+
resolve({ exitCode: status });
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (status !== 0) {
|
|
398
|
+
reject(new Error(`Rune "${key}" exited with status ${status}${signal ? ` (${signal})` : ""}.`));
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
resolve({ stdout: stdout.replace(/\r?\n$/, "") });
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/rune/native/run-block.js
|
|
407
|
+
function normaliseBlock(block) {
|
|
408
|
+
if (block == null) return null;
|
|
409
|
+
return typeof block === "string" ? { command: block } : block;
|
|
410
|
+
}
|
|
411
|
+
function resolveCommand(command, configDir) {
|
|
412
|
+
if (!command) return null;
|
|
413
|
+
return isPathCommand(command) && !isAbsolute(command) ? join(configDir, command) : command;
|
|
414
|
+
}
|
|
415
|
+
function blockGrants(block, lifecycle = "run") {
|
|
416
|
+
return computeEffectivePermissions({ [lifecycle]: block?.permissions ?? {} }, void 0, lifecycle);
|
|
417
|
+
}
|
|
418
|
+
function describeRunBlock(entry, configDir) {
|
|
419
|
+
const run = normaliseBlock(entry.run);
|
|
420
|
+
const inline = isInlineSchema(entry.args) ? entry.args : null;
|
|
421
|
+
const args = inline ? null : normaliseBlock(entry.args);
|
|
422
|
+
const command = resolveCommand(run.command, configDir);
|
|
423
|
+
const argsFile = args ? isAbsolute(args.command) ? args.command : join(configDir, args.command) : null;
|
|
424
|
+
return {
|
|
425
|
+
command,
|
|
426
|
+
argv: run.argv ?? [],
|
|
427
|
+
runtime: runtimeOf(command),
|
|
428
|
+
output: run.output ?? "text",
|
|
429
|
+
pass: run.pass ?? "raw",
|
|
430
|
+
timeout: run.timeout ?? null,
|
|
431
|
+
permissions: run.permissions,
|
|
432
|
+
argsInline: inline,
|
|
433
|
+
argsModule: argsFile,
|
|
434
|
+
argsPermissions: args?.permissions
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
async function getRunBlockSchema(desc, projectDir, { vars = {}, runeKey = null } = {}) {
|
|
438
|
+
if (desc.argsInline) return normaliseJsonSchema(desc.argsInline, `runes["${runeKey}"].args`);
|
|
439
|
+
if (!desc.argsModule) return null;
|
|
440
|
+
if (/\.json$/i.test(desc.argsModule)) {
|
|
441
|
+
return loadJsonSchema(desc.argsModule, relative(projectDir, desc.argsModule).replace(/\\/g, "/") || desc.argsModule);
|
|
442
|
+
}
|
|
443
|
+
const { getArgsSchema } = await import("./runner-QNZMBHQY.js");
|
|
444
|
+
return getArgsSchema(desc.argsModule, blockGrants({ permissions: desc.argsPermissions }), projectDir, { vars, runeKey });
|
|
445
|
+
}
|
|
446
|
+
function parseOutputLine(line) {
|
|
447
|
+
if (!line.startsWith("{")) return { text: line };
|
|
448
|
+
let event;
|
|
449
|
+
try {
|
|
450
|
+
event = JSON.parse(line);
|
|
451
|
+
} catch {
|
|
452
|
+
return { text: line };
|
|
453
|
+
}
|
|
454
|
+
const sec = event?.section;
|
|
455
|
+
if (event?.type === "section" && sec && typeof sec.name === "string" && sec.data && typeof sec.data === "object") {
|
|
456
|
+
return { section: { name: sec.name, ...sec.title && { title: sec.title }, attrs: sec.attrs ?? {}, data: sec.data } };
|
|
457
|
+
}
|
|
458
|
+
if (event?.type === "log" && typeof event.message === "string") return { log: event };
|
|
459
|
+
return { text: line };
|
|
460
|
+
}
|
|
461
|
+
function helpText(schema, parsed, key) {
|
|
462
|
+
const commands = parsed.$commands ?? [];
|
|
463
|
+
if (commands.length > 0) {
|
|
464
|
+
const sel = selectNode(schema, commands);
|
|
465
|
+
if (sel.node) return formatCommandPage(sel.node, { key, lifecycle: "run", path: sel.matchedPath });
|
|
466
|
+
}
|
|
467
|
+
return formatRuneIndex(schema, { key, lifecycle: "run", includeBatch: false });
|
|
468
|
+
}
|
|
469
|
+
function wantsHelp(rawArgs) {
|
|
470
|
+
const end = rawArgs.indexOf("--");
|
|
471
|
+
return (end === -1 ? rawArgs : rawArgs.slice(0, end)).includes("--help");
|
|
472
|
+
}
|
|
473
|
+
async function runRunBlock({ dir, key, args, entry, opts = {}, configDir, runeCallback, instanceId, extraEnv = {} }) {
|
|
474
|
+
const desc = describeRunBlock(entry, configDir);
|
|
475
|
+
let callArgs = [...desc.argv, ...args];
|
|
476
|
+
if (desc.runtime === "isolate") {
|
|
477
|
+
const { runRuneInIsolate } = await import("./runner-QNZMBHQY.js");
|
|
478
|
+
return runRuneInIsolate(desc.command, blockGrants(desc), callArgs, dir, {
|
|
479
|
+
runeCallback,
|
|
480
|
+
sections: opts.sections ?? null,
|
|
481
|
+
vars: entry.vars ?? {},
|
|
482
|
+
lifecycle: "run",
|
|
483
|
+
runeKey: key,
|
|
484
|
+
onEvent: opts.onEvent ?? null,
|
|
485
|
+
instanceId,
|
|
486
|
+
nodeModulesDir: join(getLocalBase(configDir), "node_modules"),
|
|
487
|
+
pluginDeps: null,
|
|
488
|
+
...desc.timeout != null && { isolateTimeoutMs: desc.timeout * 1e3 }
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
const direct = opts.direct === true;
|
|
492
|
+
const structured = desc.output === "sections";
|
|
493
|
+
if (direct && opts.sections && !structured) {
|
|
494
|
+
throw new Error(
|
|
495
|
+
`A section filter cannot apply to "${key}": it is a script rune run on its own, so crunes does not capture its output. Run it in a batch (-b) or with --format jsonl to filter its result.`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
assertNotMissedRename(desc.command, desc.runtime, dir);
|
|
499
|
+
const schema = await getRunBlockSchema(desc, dir, { vars: entry.vars ?? {}, runeKey: key });
|
|
500
|
+
let parsed = null;
|
|
501
|
+
if (schema) {
|
|
502
|
+
parsed = parseArgs(args, schema);
|
|
503
|
+
if (wantsHelp(args)) {
|
|
504
|
+
const text2 = helpText(schema, parsed, key);
|
|
505
|
+
if (!direct) return text2;
|
|
506
|
+
process.stdout.write(text2 + "\n");
|
|
507
|
+
return { directExitCode: 0 };
|
|
508
|
+
}
|
|
509
|
+
validateParsed(schema, parsed, key);
|
|
510
|
+
if (desc.pass === "mapped") {
|
|
511
|
+
const undeclared = undeclaredArgs(schema, parsed, args);
|
|
512
|
+
if (undeclared.length) {
|
|
513
|
+
throw new Error(`Invalid arguments for "${key}":
|
|
514
|
+
${undeclared.join("\n ")}
|
|
515
|
+
Run \`crunes run ${key} --help\` for usage.`);
|
|
516
|
+
}
|
|
517
|
+
callArgs = [...desc.argv, ...mapToArgv(schema, parsed)];
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const interpreter = resolveInterpreter(desc.runtime, dir);
|
|
521
|
+
const argv = interpreter ? [interpreter.command, ...interpreter.args, desc.command, ...callArgs] : [desc.command, ...callArgs];
|
|
522
|
+
const env = {
|
|
523
|
+
...process.env,
|
|
524
|
+
CRUNES_PROJECT_ROOT: dir,
|
|
525
|
+
CRUNES_RUNE_KEY: key,
|
|
526
|
+
CRUNES_LIFECYCLE: "run",
|
|
527
|
+
...parsed ? { CRUNES_ARGS: JSON.stringify(parsed) } : {},
|
|
528
|
+
CRUNES_VARS: JSON.stringify(entry.vars ?? {}),
|
|
529
|
+
...extraEnv
|
|
530
|
+
};
|
|
531
|
+
if (!parsed && !("CRUNES_ARGS" in (extraEnv ?? {}))) delete env.CRUNES_ARGS;
|
|
532
|
+
const shown = isPathCommand(desc.command) ? relative(dir, desc.command) || desc.command : desc.command;
|
|
533
|
+
const spawnOpts = { key, file: shown, argv, env, cwd: dir, direct, stdin: opts.stdin ?? "inherit", timeoutMs: desc.timeout != null ? desc.timeout * 1e3 : null };
|
|
534
|
+
if (!structured) {
|
|
535
|
+
const result2 = await spawnNative(spawnOpts);
|
|
536
|
+
return direct ? { directExitCode: result2.exitCode } : result2.stdout;
|
|
537
|
+
}
|
|
538
|
+
const sections = [];
|
|
539
|
+
const text = [];
|
|
540
|
+
const wanted = (sec) => !opts.sections || isGlobMatch(sec.name, opts.sections);
|
|
541
|
+
const onLine = (line) => {
|
|
542
|
+
const parsedLine = parseOutputLine(line);
|
|
543
|
+
if (parsedLine.log) {
|
|
544
|
+
const { level = "log", message, meta } = parsedLine.log;
|
|
545
|
+
if (direct) process.stderr.write(`${message}
|
|
546
|
+
`);
|
|
547
|
+
else opts.onEvent?.({ type: "log", level, message, ...meta && { meta }, instanceId, rune: key });
|
|
548
|
+
} else if (parsedLine.section) {
|
|
549
|
+
if (direct) {
|
|
550
|
+
if (wanted(parsedLine.section)) process.stdout.write(renderSection(parsedLine.section) + "\n\n");
|
|
551
|
+
} else {
|
|
552
|
+
sections.push(parsedLine.section);
|
|
553
|
+
opts.onEvent?.({ type: "section", section: parsedLine.section, instanceId, rune: key });
|
|
554
|
+
}
|
|
555
|
+
} else if (direct) {
|
|
556
|
+
process.stdout.write(parsedLine.text + "\n");
|
|
557
|
+
} else {
|
|
558
|
+
text.push(parsedLine.text);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
const result = await spawnNative({ ...spawnOpts, onLine });
|
|
562
|
+
if (direct) return { directExitCode: result.exitCode };
|
|
563
|
+
const plain = text.join("\n").replace(/\n+$/, "");
|
|
564
|
+
return plain ? [...sections, plain] : sections;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export {
|
|
568
|
+
flattenCommands,
|
|
569
|
+
selectNode,
|
|
570
|
+
formatCommandPage,
|
|
571
|
+
formatRuneIndex,
|
|
572
|
+
formatGlobalIndex,
|
|
573
|
+
renderSection,
|
|
574
|
+
formatSection,
|
|
575
|
+
describeRunBlock,
|
|
576
|
+
getRunBlockSchema,
|
|
577
|
+
runRunBlock
|
|
578
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_require_shim
|
|
3
|
+
} from "./chunk-TPK5AGRA.js";
|
|
4
|
+
|
|
5
|
+
// src/job/stdin-tail.js
|
|
6
|
+
init_require_shim();
|
|
7
|
+
import { readSync, openSync, closeSync, statSync } from "node:fs";
|
|
8
|
+
var EOF_SENTINEL = "__CRUNES_STDIN_EOF__";
|
|
9
|
+
function tailStdin(logPath, { onLine, onEof = () => {
|
|
10
|
+
}, pollMs = 50 } = {}) {
|
|
11
|
+
let offset = 0;
|
|
12
|
+
let stopped = false;
|
|
13
|
+
let timer = null;
|
|
14
|
+
let remainder = "";
|
|
15
|
+
function read() {
|
|
16
|
+
if (stopped) return;
|
|
17
|
+
let fd;
|
|
18
|
+
try {
|
|
19
|
+
fd = openSync(logPath, "r");
|
|
20
|
+
const size = statSync(logPath).size;
|
|
21
|
+
if (size <= offset) {
|
|
22
|
+
schedule();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const buf = Buffer.allocUnsafe(size - offset);
|
|
26
|
+
const bytesRead = readSync(fd, buf, 0, buf.length, offset);
|
|
27
|
+
offset += bytesRead;
|
|
28
|
+
remainder += buf.slice(0, bytesRead).toString("utf8");
|
|
29
|
+
} catch {
|
|
30
|
+
schedule();
|
|
31
|
+
return;
|
|
32
|
+
} finally {
|
|
33
|
+
try {
|
|
34
|
+
if (fd !== void 0) closeSync(fd);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const lines = remainder.split("\n");
|
|
39
|
+
remainder = lines.pop();
|
|
40
|
+
for (const line of lines) {
|
|
41
|
+
if (line === EOF_SENTINEL) {
|
|
42
|
+
stopped = true;
|
|
43
|
+
onEof();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (line.length > 0) onLine(line);
|
|
47
|
+
}
|
|
48
|
+
schedule();
|
|
49
|
+
}
|
|
50
|
+
function schedule() {
|
|
51
|
+
if (!stopped) {
|
|
52
|
+
timer = setTimeout(read, pollMs);
|
|
53
|
+
timer.unref();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function stop() {
|
|
57
|
+
stopped = true;
|
|
58
|
+
if (timer) {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
timer = null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
schedule();
|
|
64
|
+
return { stop };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
EOF_SENTINEL,
|
|
69
|
+
tailStdin
|
|
70
|
+
};
|