@darkrymit/crunes-cli 0.7.1 → 0.8.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 (75) hide show
  1. package/README.md +5 -4
  2. package/dist/chunks/{add-OWYVF3IE.js → add-CBHWFGCA.js} +2 -2
  3. package/dist/chunks/{apply-OMEVXCHC.js → apply-YC6JEPUN.js} +6 -5
  4. package/dist/chunks/args-repl-TX3YWUOO.js +81 -0
  5. package/dist/chunks/banner-repl-DD22Z33A.js +52 -0
  6. package/dist/chunks/benchmark-BJEAAFWG.js +234 -0
  7. package/dist/chunks/{browse-COH6IJEX.js → browse-JZFU52ET.js} +2 -2
  8. package/dist/chunks/{chunk-2Q24YPGL.js → chunk-2PBPDTRD.js} +2 -2
  9. package/dist/chunks/chunk-63H5VXZY.js +101 -0
  10. package/dist/chunks/{chunk-GHQOK4L7.js → chunk-65J65MAP.js} +1 -1
  11. package/dist/chunks/{chunk-HMU2J25D.js → chunk-6MRZXASS.js} +3 -3
  12. package/dist/chunks/{chunk-HOH7WZX4.js → chunk-ASZKAC24.js} +9 -1
  13. package/dist/chunks/{chunk-AIEWOUXT.js → chunk-DZJRYFOP.js} +104 -41
  14. package/dist/chunks/{chunk-QMWGQXEZ.js → chunk-G4ZAUHHA.js} +2 -4
  15. package/dist/chunks/{chunk-67I2J474.js → chunk-J3GZ3DXD.js} +14 -55
  16. package/dist/chunks/{chunk-XIXND2M4.js → chunk-JOAL437H.js} +5 -1
  17. package/dist/chunks/{chunk-6I7RHSAA.js → chunk-JU6FKUBY.js} +30394 -26055
  18. package/dist/chunks/{chunk-BVY5LN7X.js → chunk-NAEVMRNA.js} +22031 -13350
  19. package/dist/chunks/{chunk-NXSDVVTW.js → chunk-NDEYEYSU.js} +22 -69
  20. package/dist/chunks/{chunk-L72BG6DS.js → chunk-NYLRTAAA.js} +1 -1
  21. package/dist/chunks/{chunk-UGN3FFEF.js → chunk-V35LVVNV.js} +5113 -2117
  22. package/dist/chunks/chunk-ZJDKCC2Y.js +105 -0
  23. package/dist/chunks/{clear-Y5POLIMF.js → clear-YBDIPEEH.js} +5 -9
  24. package/dist/chunks/commands-repl-IPLJ4M7X.js +65 -0
  25. package/dist/chunks/complete-input-repl-IDSCMRYL.js +71 -0
  26. package/dist/chunks/{create-I6BNYZ5Q.js → create-ZFFV3Z2P.js} +2 -1
  27. package/dist/chunks/{delete-UB5SXO5I.js → delete-C4UJ7X5K.js} +5 -9
  28. package/dist/chunks/delete-E4TEBRPX.js +27 -0
  29. package/dist/chunks/{delete-7CQFYIXS.js → delete-LNOYM5KG.js} +5 -9
  30. package/dist/chunks/{disable-FCBW7WVG.js → disable-TMG2K3BF.js} +6 -6
  31. package/dist/chunks/{doctor-DS57HDLJ.js → doctor-N43QEMAH.js} +2 -2
  32. package/dist/chunks/{enable-IXRVUXJM.js → enable-327OMBPC.js} +6 -6
  33. package/dist/chunks/{globals-YCJ2DGWC.js → globals-H2WF344Y.js} +2 -2
  34. package/dist/chunks/{init-WGKQVAZE.js → init-HU5OMHEH.js} +1 -1
  35. package/dist/chunks/input-repl-ZBH6FVPV.js +87 -0
  36. package/dist/chunks/{install-BCTBOPBS.js → install-RRLUOYFO.js} +6 -6
  37. package/dist/chunks/intro-4CICBP2J.js +2727 -0
  38. package/dist/chunks/{kill-LWRXZVM5.js → kill-2UG7PHUV.js} +4 -10
  39. package/dist/chunks/list-4X3JFQGS.js +41 -0
  40. package/dist/chunks/{list-ZBYPMUID.js → list-7VHJIUDX.js} +2 -2
  41. package/dist/chunks/list-A5WVDBWF.js +53 -0
  42. package/dist/chunks/{list-NGOCMJXE.js → list-CK5X2YN3.js} +5 -4
  43. package/dist/chunks/{list-TTKLNJKI.js → list-FLAYJQKN.js} +2 -2
  44. package/dist/chunks/list-PTAWQYWG.js +35 -0
  45. package/dist/chunks/list-U7PAYNAH.js +47 -0
  46. package/dist/chunks/{list-OTOMCFLA.js → list-WH7KESMV.js} +12 -11
  47. package/dist/chunks/{query-NY4SCO77.js → query-AW7WYILM.js} +5 -9
  48. package/dist/chunks/{registry-W5XFI5T6.js → registry-3QIL5SVL.js} +2 -2
  49. package/dist/chunks/{remove-WEAZFZCO.js → remove-QUH2D3S5.js} +2 -2
  50. package/dist/chunks/repl-STBZC4P2.js +180 -0
  51. package/dist/chunks/repl-VGC5FUJG.js +378 -0
  52. package/dist/chunks/resolver-QMIY33FM.js +26 -0
  53. package/dist/chunks/run-T33CMCFZ.js +26 -0
  54. package/dist/chunks/{run-J2A5YTTY.js → run-Y4TG3EM3.js} +22 -3
  55. package/dist/chunks/rune-UBRVWG5A.js +139 -0
  56. package/dist/chunks/{search-XENXL3GC.js → search-MSSDGJTF.js} +2 -2
  57. package/dist/chunks/{uninstall-MX5PLGDI.js → uninstall-55YTHZRH.js} +5 -5
  58. package/dist/chunks/unset-YASSMSE5.js +24 -0
  59. package/dist/chunks/{update-7XDTVFZ3.js → update-EWWDROKW.js} +2 -2
  60. package/dist/chunks/{update-IEE54GPY.js → update-G6XO4RIM.js} +6 -6
  61. package/dist/chunks/{utils-PO3ZK53L.js → utils-XOWJQWNR.js} +2 -2
  62. package/dist/chunks/{version-V67W66HQ.js → version-I442SSH7.js} +10 -5
  63. package/dist/cli.js +114 -81
  64. package/package.json +9 -4
  65. package/dist/chunks/benchmark-ATSRQIDC.js +0 -164
  66. package/dist/chunks/check-G72VZKIP.js +0 -144
  67. package/dist/chunks/chunk-3TM6B4E5.js +0 -70
  68. package/dist/chunks/chunk-XXUNHQIB.js +0 -129
  69. package/dist/chunks/intro-RFWW5HIO.js +0 -1510
  70. package/dist/chunks/list-5DVVP7HX.js +0 -50
  71. package/dist/chunks/list-6WL5LGIZ.js +0 -80
  72. package/dist/chunks/list-YPI7YDKK.js +0 -80
  73. package/dist/chunks/run-AUAGELWL.js +0 -23
  74. package/dist/chunks/rune-D2FL547U.js +0 -87
  75. package/dist/chunks/unset-KQOZYVTE.js +0 -28
@@ -0,0 +1,378 @@
1
+ import {
2
+ formatSection,
3
+ parseSegment
4
+ } from "./chunk-DZJRYFOP.js";
5
+ import {
6
+ loadConfig
7
+ } from "./chunk-H3BVJCIL.js";
8
+ import {
9
+ isGlobMatch,
10
+ parseArgs,
11
+ tailStdin
12
+ } from "./chunk-JU6FKUBY.js";
13
+ import "./chunk-J3GZ3DXD.js";
14
+ import "./chunk-ZJDKCC2Y.js";
15
+ import "./chunk-NDEYEYSU.js";
16
+ import "./chunk-G4ZAUHHA.js";
17
+ import "./chunk-63H5VXZY.js";
18
+ import "./chunk-ASZKAC24.js";
19
+ import {
20
+ isVerbose,
21
+ output
22
+ } from "./chunk-6XLT25GS.js";
23
+ import "./chunk-WCODTMDN.js";
24
+ import "./chunk-65J65MAP.js";
25
+ import "./chunk-6MRZXASS.js";
26
+ import "./chunk-G3U4V32O.js";
27
+ import {
28
+ init_require_shim
29
+ } from "./chunk-TPK5AGRA.js";
30
+
31
+ // src/rune/commands/repl.js
32
+ init_require_shim();
33
+ import readline from "node:readline";
34
+ function parseReplReturn(value) {
35
+ if (value === void 0 || value === null) return { type: "continue", prompt: null };
36
+ if (typeof value === "string") return { type: "continue", prompt: value };
37
+ if (value && typeof value === "object") {
38
+ if (value.type === "done") return { type: "done", message: value.message ?? null };
39
+ if (value.type === "prompt") return { type: "continue", prompt: value.value ?? null };
40
+ }
41
+ return { type: "continue", prompt: null };
42
+ }
43
+ var BUILTIN_SLASH_COMMANDS = [
44
+ { name: "help", description: "Show available commands" },
45
+ { name: "clear", description: "Clear the screen" },
46
+ { name: "exit", description: "End the session" }
47
+ ];
48
+ var VALID_INPUT_TYPES = /* @__PURE__ */ new Set(["line", "interrupt", "eof", "command"]);
49
+ function parseJsonlInputLine(text) {
50
+ if (!text) return null;
51
+ let parsed;
52
+ try {
53
+ parsed = JSON.parse(text);
54
+ } catch {
55
+ return null;
56
+ }
57
+ if (!parsed || !VALID_INPUT_TYPES.has(parsed.type)) return null;
58
+ return parsed;
59
+ }
60
+ function parseSlashCommand(line) {
61
+ const trimmed = line.trim();
62
+ if (!trimmed.startsWith("/")) return null;
63
+ const spaceIdx = trimmed.indexOf(" ");
64
+ const name = spaceIdx === -1 ? trimmed.slice(1) : trimmed.slice(1, spaceIdx);
65
+ const rest = spaceIdx === -1 ? "" : trimmed.slice(spaceIdx + 1).trim();
66
+ if (!name) return null;
67
+ return { name, rest };
68
+ }
69
+ function parseReplArgs(argv) {
70
+ let format = "text";
71
+ let i = 0;
72
+ while (i < argv.length) {
73
+ const tok = argv[i];
74
+ if (tok === "--format" && i + 1 < argv.length) {
75
+ format = argv[i + 1];
76
+ i += 2;
77
+ } else if (tok.startsWith("--format=")) {
78
+ format = tok.slice(9);
79
+ i++;
80
+ } else {
81
+ break;
82
+ }
83
+ }
84
+ const { key, sections, runeArgs } = parseSegment(argv.slice(i));
85
+ return { key, sections, runeArgs, format };
86
+ }
87
+ async function handler({
88
+ key,
89
+ runeArgs = [],
90
+ sections: sectionFilter = null,
91
+ format = "text",
92
+ projectRoot = process.cwd(),
93
+ configRoot = projectRoot
94
+ }) {
95
+ if (!key) {
96
+ output.error("Missing required argument: <rune>");
97
+ process.exit(1);
98
+ }
99
+ let config;
100
+ try {
101
+ config = loadConfig(configRoot);
102
+ } catch (err) {
103
+ output.error(`Config unreadable: ${err.message}`);
104
+ output.info("Run `crunes init` to create a config file.");
105
+ process.exit(1);
106
+ }
107
+ const { resolveRuneEntry } = await import("./resolver-QMIY33FM.js");
108
+ let runeEntry;
109
+ try {
110
+ runeEntry = await resolveRuneEntry(projectRoot, config, key, configRoot);
111
+ } catch (err) {
112
+ output.error(`Rune "${key}" not found: ${err.message}`);
113
+ process.exit(1);
114
+ }
115
+ const instanceId = "1";
116
+ const jsonlInput = format === "jsonl" && !process.stdin.isTTY;
117
+ function onEvent(event) {
118
+ const { type, message, section, rune, instanceId: iid, level, meta } = event;
119
+ if (format === "jsonl") {
120
+ process.stdout.write(JSON.stringify({
121
+ type,
122
+ rune,
123
+ instance: iid,
124
+ ...message != null ? { message } : {},
125
+ ...section != null ? { section } : {},
126
+ ...level != null ? { level } : {},
127
+ ...meta != null ? { meta } : {}
128
+ }) + "\n");
129
+ } else {
130
+ if (type === "section") {
131
+ if (!sectionFilter || isGlobMatch(section.name, sectionFilter)) {
132
+ process.stdout.write(formatSection(section, rune) + "\n");
133
+ }
134
+ } else if (type === "log") {
135
+ process.stderr.write(message + "\n");
136
+ }
137
+ }
138
+ }
139
+ let session;
140
+ try {
141
+ session = await runeEntry.createReplSession(runeArgs, { onEvent, instanceId });
142
+ } catch (err) {
143
+ const msg = isVerbose ? err.stack || err.message : err.message;
144
+ output.error(`Failed to start REPL for "${key}": ${msg}`);
145
+ process.exit(1);
146
+ }
147
+ if (format === "jsonl") {
148
+ process.stdout.write(JSON.stringify({ type: "session-start", rune: key, instance: instanceId }) + "\n");
149
+ }
150
+ if (session.banner) {
151
+ if (format === "jsonl") {
152
+ process.stdout.write(JSON.stringify({ type: "banner", rune: key, instance: instanceId, message: session.banner }) + "\n");
153
+ } else {
154
+ process.stderr.write(session.banner + "\n");
155
+ }
156
+ }
157
+ let currentPrompt = session.initialPrompt ?? "> ";
158
+ let lineBuffer = [];
159
+ let sessionEnded = false;
160
+ let eofResolve = null;
161
+ const eofPromise = new Promise((resolve) => {
162
+ eofResolve = resolve;
163
+ });
164
+ let rl = null;
165
+ function prompt() {
166
+ if (!rl) return;
167
+ if (process.stdin.isTTY) rl.setPrompt(currentPrompt);
168
+ rl.prompt();
169
+ }
170
+ let queue = Promise.resolve();
171
+ function enqueue(fn) {
172
+ queue = queue.then(fn);
173
+ }
174
+ async function handleInputEvent(event) {
175
+ if (sessionEnded) return;
176
+ let result;
177
+ try {
178
+ result = await session.step(event);
179
+ } catch (err) {
180
+ if (sessionEnded) return;
181
+ const msg = isVerbose ? err.stack || err.message : err.message;
182
+ if (format === "jsonl") {
183
+ process.stdout.write(JSON.stringify({ type: "error", rune: key, instance: instanceId, message: msg }) + "\n");
184
+ } else {
185
+ process.stderr.write(`Error: ${msg}
186
+ `);
187
+ }
188
+ prompt();
189
+ return;
190
+ }
191
+ const signal = parseReplReturn(result);
192
+ if (signal.type === "done") {
193
+ await endSession(signal.message);
194
+ eofResolve();
195
+ return;
196
+ }
197
+ if (signal.prompt !== null) currentPrompt = signal.prompt;
198
+ prompt();
199
+ }
200
+ const completerFn = session.complete ? (line, cb) => {
201
+ const tokens = line.length === 0 ? [""] : line.trimStart().split(/\s+/);
202
+ if (line.length > 0 && line[line.length - 1] === " ") tokens.push("");
203
+ Promise.resolve(session.complete(tokens)).then((candidates) => {
204
+ const partial = tokens[tokens.length - 1] ?? "";
205
+ const matches = candidates.filter((c) => c.startsWith(partial));
206
+ cb(null, [matches, partial]);
207
+ }).catch(() => cb(null, [[], ""]));
208
+ } : void 0;
209
+ const stdinLogPath = process.env.CRUNES_STDIN_LOG;
210
+ if (stdinLogPath) {
211
+ const keepAlive = setInterval(() => {
212
+ }, 1e4);
213
+ const tail = tailStdin(stdinLogPath, {
214
+ onLine: (line) => {
215
+ enqueue(async () => {
216
+ if (sessionEnded) return;
217
+ if (jsonlInput) {
218
+ const event = parseJsonlInputLine(line);
219
+ if (event) await handleInputEvent(event);
220
+ } else {
221
+ await handleInputEvent({ type: "line", text: line });
222
+ }
223
+ });
224
+ },
225
+ onEof: () => {
226
+ enqueue(async () => {
227
+ if (!sessionEnded) await handleInputEvent({ type: "eof", text: "" });
228
+ eofResolve();
229
+ });
230
+ }
231
+ });
232
+ eofPromise.then(() => {
233
+ tail.stop();
234
+ clearInterval(keepAlive);
235
+ });
236
+ await eofPromise;
237
+ await queue;
238
+ return;
239
+ }
240
+ rl = readline.createInterface({
241
+ input: process.stdin,
242
+ output: process.stderr,
243
+ terminal: process.stdin.isTTY,
244
+ historySize: process.stdin.isTTY ? 100 : 0,
245
+ ...completerFn ? { completer: completerFn } : {}
246
+ });
247
+ if (process.stdin.isTTY && !jsonlInput) {
248
+ readline.emitKeypressEvents(process.stdin, rl);
249
+ process.stdin.setRawMode(true);
250
+ process.stdin.on("keypress", (ch, key2) => {
251
+ if (!key2) return;
252
+ if (key2.ctrl && key2.name === "return") {
253
+ const currentLine = rl.line;
254
+ lineBuffer.push(currentLine);
255
+ rl.write(null, { ctrl: true, name: "u" });
256
+ process.stderr.write("\n");
257
+ rl.setPrompt(" ".repeat(currentPrompt.length));
258
+ rl.prompt();
259
+ }
260
+ });
261
+ }
262
+ async function endSession(message) {
263
+ if (sessionEnded) return;
264
+ sessionEnded = true;
265
+ if (message) {
266
+ if (format === "jsonl") {
267
+ process.stdout.write(JSON.stringify({ type: "session-end", rune: key, instance: instanceId, message }) + "\n");
268
+ } else {
269
+ process.stderr.write(message + "\n");
270
+ }
271
+ } else if (format === "jsonl") {
272
+ process.stdout.write(JSON.stringify({ type: "session-end", rune: key, instance: instanceId }) + "\n");
273
+ }
274
+ if (process.stdin.isTTY && !jsonlInput) process.stdin.setRawMode(false);
275
+ rl?.close();
276
+ await session.dispose();
277
+ }
278
+ function buildHelpText() {
279
+ const lines = ["Built-in commands:"];
280
+ for (const cmd of BUILTIN_SLASH_COMMANDS) {
281
+ lines.push(` /${cmd.name.padEnd(8)} ${cmd.description}`);
282
+ }
283
+ if (session.commandsSchema?.commands?.length) {
284
+ lines.push("Rune commands:");
285
+ for (const cmd of session.commandsSchema.commands) {
286
+ lines.push(` /${cmd.name.padEnd(8)} ${cmd.description ?? ""}`);
287
+ }
288
+ }
289
+ lines.push('Press Ctrl+D or return { type: "done" } from inputRepl() to exit.');
290
+ return lines.join("\n");
291
+ }
292
+ rl.on("SIGINT", () => {
293
+ if (lineBuffer.length > 0) {
294
+ lineBuffer = [];
295
+ process.stderr.write("\n");
296
+ rl.setPrompt(currentPrompt);
297
+ prompt();
298
+ return;
299
+ }
300
+ if (rl.line && rl.line.length > 0) {
301
+ process.stderr.write("\n");
302
+ prompt();
303
+ return;
304
+ }
305
+ enqueue(() => handleInputEvent({ type: "interrupt", text: "" }));
306
+ });
307
+ rl.on("line", (text) => {
308
+ enqueue(async () => {
309
+ if (sessionEnded) return;
310
+ if (lineBuffer.length > 0) {
311
+ lineBuffer.push(text);
312
+ const fullText = lineBuffer.join("\n");
313
+ lineBuffer = [];
314
+ rl.setPrompt(currentPrompt);
315
+ await handleInputEvent({ type: "line", text: fullText });
316
+ return;
317
+ }
318
+ if (jsonlInput) {
319
+ const event = parseJsonlInputLine(text);
320
+ if (!event) {
321
+ process.stdout.write(JSON.stringify({ type: "error", rune: key, instance: instanceId, message: `Invalid JSONL input: ${text}` }) + "\n");
322
+ return;
323
+ }
324
+ await handleInputEvent(event);
325
+ return;
326
+ }
327
+ const slash = parseSlashCommand(text);
328
+ if (slash) {
329
+ if (slash.name === "exit") {
330
+ enqueue(() => handleInputEvent({ type: "eof", text: "" }));
331
+ return;
332
+ }
333
+ if (slash.name === "clear") {
334
+ if (process.stdin.isTTY) process.stderr.write("\x1Bc");
335
+ prompt();
336
+ return;
337
+ }
338
+ if (slash.name === "help") {
339
+ process.stderr.write(buildHelpText() + "\n");
340
+ prompt();
341
+ return;
342
+ }
343
+ if (session.commandsSchema?.commands?.some((c) => c.name === slash.name)) {
344
+ const cmdSchema = {
345
+ commands: session.commandsSchema.commands,
346
+ options: [],
347
+ positionals: [],
348
+ examples: []
349
+ };
350
+ const cmdTokens = slash.rest ? [slash.name, ...slash.rest.split(/\s+/)] : [slash.name];
351
+ const parsedCmdArgs = parseArgs(cmdTokens, cmdSchema);
352
+ await handleInputEvent({ type: "command", args: parsedCmdArgs });
353
+ return;
354
+ }
355
+ }
356
+ await handleInputEvent({ type: "line", text });
357
+ });
358
+ });
359
+ rl.on("close", () => {
360
+ queue.then(async () => {
361
+ if (!sessionEnded) {
362
+ await handleInputEvent({ type: "eof", text: "" });
363
+ }
364
+ eofResolve();
365
+ });
366
+ });
367
+ prompt();
368
+ await eofPromise;
369
+ await queue;
370
+ }
371
+ export {
372
+ BUILTIN_SLASH_COMMANDS,
373
+ handler,
374
+ parseJsonlInputLine,
375
+ parseReplArgs,
376
+ parseReplReturn,
377
+ parseSlashCommand
378
+ };
@@ -0,0 +1,26 @@
1
+ import {
2
+ getRune,
3
+ normaliseRune,
4
+ resolvePluginRune,
5
+ resolveRuneEntry,
6
+ runRune
7
+ } from "./chunk-JU6FKUBY.js";
8
+ import "./chunk-J3GZ3DXD.js";
9
+ import "./chunk-ZJDKCC2Y.js";
10
+ import "./chunk-NDEYEYSU.js";
11
+ import "./chunk-G4ZAUHHA.js";
12
+ import "./chunk-63H5VXZY.js";
13
+ import "./chunk-ASZKAC24.js";
14
+ import "./chunk-6XLT25GS.js";
15
+ import "./chunk-WCODTMDN.js";
16
+ import "./chunk-65J65MAP.js";
17
+ import "./chunk-6MRZXASS.js";
18
+ import "./chunk-G3U4V32O.js";
19
+ import "./chunk-TPK5AGRA.js";
20
+ export {
21
+ getRune,
22
+ normaliseRune,
23
+ resolvePluginRune,
24
+ resolveRuneEntry,
25
+ runRune
26
+ };
@@ -0,0 +1,26 @@
1
+ import {
2
+ handler,
3
+ parseBracketKey,
4
+ parseRunArgs,
5
+ parseSegment
6
+ } from "./chunk-DZJRYFOP.js";
7
+ import "./chunk-H3BVJCIL.js";
8
+ import "./chunk-JU6FKUBY.js";
9
+ import "./chunk-J3GZ3DXD.js";
10
+ import "./chunk-ZJDKCC2Y.js";
11
+ import "./chunk-NDEYEYSU.js";
12
+ import "./chunk-G4ZAUHHA.js";
13
+ import "./chunk-63H5VXZY.js";
14
+ import "./chunk-ASZKAC24.js";
15
+ import "./chunk-6XLT25GS.js";
16
+ import "./chunk-WCODTMDN.js";
17
+ import "./chunk-65J65MAP.js";
18
+ import "./chunk-6MRZXASS.js";
19
+ import "./chunk-G3U4V32O.js";
20
+ import "./chunk-TPK5AGRA.js";
21
+ export {
22
+ handler,
23
+ parseBracketKey,
24
+ parseRunArgs,
25
+ parseSegment
26
+ };
@@ -12,8 +12,8 @@ The entrypoint \`export async function run(args)\` executes the rune's main scri
12
12
  ## 1. Parsed Arguments Structure
13
13
 
14
14
  Inside \`run(args)\`, the \`args\` parameter contains:
15
- - **\`args.$command\`** *(string)*: The space-separated matched command path (e.g. \`"remote add"\` or \`""\` for the root).
16
- - **\`args.$commands\`** *(string[])*: The array of matched command levels (e.g. \`["remote", "add"]\` or \`[]\` for the root).
15
+ - **\`args.$command\`** *(string)*: The space-separated matched command path (e.g. \`"remote add"\`). Always present \u2014 \`""\` at the root level.
16
+ - **\`args.$commands\`** *(string[])*: The array of matched command levels (e.g. \`["remote", "add"]\`). Always present \u2014 \`[]\` at the root level.
17
17
  - **\`args._\`** *(string[])*: All data positionals (command tokens are stripped, so \`args._[0]\` is always the first positional argument after the matched command path).
18
18
  - **\`args.$rest\`** *(string[])*: Unmapped positional arguments that were not bound to named positionals.
19
19
  - **\`args.$raw\`** *(string[])*: The exact raw string array before parsing.
@@ -55,7 +55,7 @@ import { section } from '@utils'
55
55
 
56
56
  export async function run(args) {
57
57
  // 1. Root level command logic
58
- if (args.$command === '') {
58
+ if (!args.$command) {
59
59
  return section.create('root', { type: 'markdown', content: 'Root command' })
60
60
  }
61
61
 
@@ -86,6 +86,25 @@ export async function run(args) {
86
86
  3. **Rune Arguments**: Scoped after the rune key (e.g. \`myrune remote add origin --verbose\`).
87
87
  Placing global or command flags after the rune key will cause them to be passed as raw rune arguments!
88
88
 
89
+ ## 5. dispose() \u2014 Guaranteed Teardown
90
+
91
+ Export an optional \`dispose()\` function to run cleanup logic after \`run()\` completes or throws, before the isolate tears down. Errors thrown by \`dispose()\` are swallowed.
92
+
93
+ \`\`\`js
94
+ let db = null
95
+
96
+ export async function run(args) {
97
+ db = await sqlite.open(args.db, 'books')
98
+ return await execQuery(db, args.query)
99
+ }
100
+
101
+ export async function dispose() {
102
+ if (db) { await db.close(); db = null }
103
+ }
104
+ \`\`\`
105
+
106
+ This is equivalent to wrapping your entire \`run()\` body in a \`try/finally\` \u2014 but cleaner. The \`try/finally\` pattern still works if you prefer it.
107
+
89
108
  `);
90
109
  }
91
110
  export {
@@ -0,0 +1,139 @@
1
+ import {
2
+ loadConfig
3
+ } from "./chunk-H3BVJCIL.js";
4
+ import {
5
+ computeEffectivePermissions,
6
+ getArgsSchema,
7
+ getReplSchema,
8
+ getRune
9
+ } from "./chunk-JU6FKUBY.js";
10
+ import "./chunk-J3GZ3DXD.js";
11
+ import "./chunk-ZJDKCC2Y.js";
12
+ import "./chunk-NDEYEYSU.js";
13
+ import "./chunk-G4ZAUHHA.js";
14
+ import "./chunk-63H5VXZY.js";
15
+ import {
16
+ formatHelp
17
+ } from "./chunk-ASZKAC24.js";
18
+ import {
19
+ output
20
+ } from "./chunk-6XLT25GS.js";
21
+ import "./chunk-WCODTMDN.js";
22
+ import "./chunk-65J65MAP.js";
23
+ import "./chunk-6MRZXASS.js";
24
+ import "./chunk-G3U4V32O.js";
25
+ import {
26
+ init_require_shim
27
+ } from "./chunk-TPK5AGRA.js";
28
+
29
+ // src/docs/commands/rune.js
30
+ init_require_shim();
31
+ import { join, relative } from "node:path";
32
+ var SUGGESTIONS = {
33
+ run: "crunes docs run",
34
+ args: "crunes docs args",
35
+ intro: "crunes docs intro",
36
+ utils: "crunes docs utils",
37
+ globals: "crunes docs globals"
38
+ };
39
+ function formatSlashCommands(commands, indent = "") {
40
+ const lines = [`${indent}REPL Slash Commands:`];
41
+ for (const cmd of commands) {
42
+ lines.push(`${indent} /${cmd.name.padEnd(12)} ${cmd.description ?? ""}`);
43
+ for (const pos of cmd.positionals ?? []) {
44
+ lines.push(`${indent} ${pos.spec.padEnd(14)} ${pos.description ?? ""}`);
45
+ }
46
+ for (const opt of cmd.options ?? []) {
47
+ lines.push(`${indent} ${opt.flags.padEnd(14)} ${opt.description ?? ""}`);
48
+ }
49
+ }
50
+ return lines.join("\n");
51
+ }
52
+ function formatBatch(batch) {
53
+ const lines = ["Batch:"];
54
+ if (!batch) {
55
+ lines.push(" (not permitted \u2014 no batch block declared)");
56
+ return lines.join("\n");
57
+ }
58
+ const allow = batch.allow ?? [];
59
+ const deny = batch.deny ?? [];
60
+ lines.push(` allow: ${allow.length ? allow.join(", ") : "(none)"}`);
61
+ if (deny.length) lines.push(` deny: ${deny.join(", ")}`);
62
+ return lines.join("\n");
63
+ }
64
+ async function handler({ keys, format = "text", projectRoot = process.cwd(), configRoot = projectRoot }) {
65
+ let config;
66
+ try {
67
+ config = loadConfig(configRoot);
68
+ } catch (err) {
69
+ output.error(`Config unreadable: ${err.message}`);
70
+ process.exit(1);
71
+ }
72
+ const results = [];
73
+ let anyFailed = false;
74
+ for (const key of keys) {
75
+ const entry = getRune(config, key);
76
+ if (!entry) {
77
+ if (SUGGESTIONS[key]) {
78
+ output.warn(`Unknown rune: "${key}". (Tip: Did you mean "${SUGGESTIONS[key]}"?)`);
79
+ } else {
80
+ output.warn(`Unknown rune: "${key}"`);
81
+ }
82
+ anyFailed = true;
83
+ continue;
84
+ }
85
+ const runeFile = join(configRoot, entry.path ?? `.crunes/runes/${key}.js`);
86
+ const relativePath = relative(projectRoot, runeFile).replace(/\\/g, "/");
87
+ const basePerms = entry.permissions ?? { allow: [], deny: [] };
88
+ const vars = entry.vars ?? {};
89
+ const runEffective = computeEffectivePermissions(basePerms, config.permissions?.[key], "run");
90
+ const replEffective = computeEffectivePermissions(basePerms, config.permissions?.[key], "repl");
91
+ let schema = null;
92
+ try {
93
+ schema = await getArgsSchema(runeFile, runEffective, projectRoot, { vars, runeKey: key });
94
+ } catch (err) {
95
+ output.warn(`Could not load args schema for "${key}": ${err.message}`);
96
+ }
97
+ let repl = null;
98
+ try {
99
+ const { argsSchema, commandsSchema } = await getReplSchema(runeFile, replEffective, [], projectRoot, { vars, runeKey: key });
100
+ if (argsSchema !== null || commandsSchema !== null) {
101
+ repl = { argsSchema, commandsSchema };
102
+ }
103
+ } catch (err) {
104
+ output.warn(`Could not load REPL schema for "${key}": ${err.message}`);
105
+ }
106
+ const batch = entry.batch != null ? { allow: entry.batch.allow ?? [], deny: entry.batch.deny ?? [] } : null;
107
+ results.push({
108
+ key,
109
+ name: entry.name ?? key,
110
+ description: entry.description ?? null,
111
+ relativePath,
112
+ schema,
113
+ repl,
114
+ batch
115
+ });
116
+ }
117
+ if (format === "json") {
118
+ process.stdout.write(JSON.stringify(results, null, 2) + "\n");
119
+ } else {
120
+ const blocks = [];
121
+ for (const r of results) {
122
+ const parts = [];
123
+ parts.push(formatHelp(r.schema, { key: r.key, name: r.name, description: r.description, relativePath: r.relativePath }));
124
+ if (r.repl?.argsSchema) {
125
+ parts.push(formatHelp(r.repl.argsSchema, { key: r.key, name: r.name, description: r.description, relativePath: r.relativePath, lifecycle: "repl" }));
126
+ }
127
+ if (r.repl?.commandsSchema?.commands?.length) {
128
+ parts.push(formatSlashCommands(r.repl.commandsSchema.commands));
129
+ }
130
+ parts.push(formatBatch(r.batch));
131
+ blocks.push(parts.join("\n\n"));
132
+ }
133
+ if (blocks.length > 0) process.stdout.write(blocks.join("\n\n") + "\n");
134
+ }
135
+ if (anyFailed) process.exit(1);
136
+ }
137
+ export {
138
+ handler
139
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  searchMarketplaces
3
- } from "./chunk-L72BG6DS.js";
4
- import "./chunk-HMU2J25D.js";
3
+ } from "./chunk-NYLRTAAA.js";
4
+ import "./chunk-6MRZXASS.js";
5
5
  import {
6
6
  init_require_shim
7
7
  } from "./chunk-TPK5AGRA.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  uninstallPlugin
3
- } from "./chunk-2Q24YPGL.js";
3
+ } from "./chunk-2PBPDTRD.js";
4
4
  import {
5
5
  R,
6
6
  fe,
@@ -10,8 +10,8 @@ import {
10
10
  import {
11
11
  loadRegistry,
12
12
  resolvePluginKey
13
- } from "./chunk-GHQOK4L7.js";
14
- import "./chunk-HMU2J25D.js";
13
+ } from "./chunk-65J65MAP.js";
14
+ import "./chunk-6MRZXASS.js";
15
15
  import "./chunk-G3U4V32O.js";
16
16
  import {
17
17
  init_require_shim
@@ -19,7 +19,7 @@ import {
19
19
 
20
20
  // src/plugin/commands/uninstall.js
21
21
  init_require_shim();
22
- async function handler({ name, yes, projectRoot }) {
22
+ async function handler({ name, yes, projectRoot, configRoot }) {
23
23
  let pluginKey;
24
24
  try {
25
25
  const registry = await loadRegistry();
@@ -37,7 +37,7 @@ async function handler({ name, yes, projectRoot }) {
37
37
  }
38
38
  }
39
39
  try {
40
- await uninstallPlugin(pluginKey, projectRoot);
40
+ await uninstallPlugin(pluginKey, configRoot ?? projectRoot);
41
41
  fe(`Uninstalled ${pluginKey}`);
42
42
  } catch (err) {
43
43
  ge(`Failed: ${err.message}`);
@@ -0,0 +1,24 @@
1
+ import {
2
+ deleteCacheKey
3
+ } from "./chunk-NDEYEYSU.js";
4
+ import "./chunk-G4ZAUHHA.js";
5
+ import "./chunk-6MRZXASS.js";
6
+ import {
7
+ init_require_shim
8
+ } from "./chunk-TPK5AGRA.js";
9
+
10
+ // src/cache/commands/unset.js
11
+ init_require_shim();
12
+ async function handler({ id, key: keyName, projectDir }) {
13
+ let result;
14
+ try {
15
+ result = await deleteCacheKey(id, keyName);
16
+ } catch (err) {
17
+ console.error(`Error: ${err.message}`);
18
+ process.exit(1);
19
+ }
20
+ console.log(`Removed key "${keyName}" from "${result.name}".`);
21
+ }
22
+ export {
23
+ handler
24
+ };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  listMarketplaces,
3
3
  updateMarketplace
4
- } from "./chunk-L72BG6DS.js";
5
- import "./chunk-HMU2J25D.js";
4
+ } from "./chunk-NYLRTAAA.js";
5
+ import "./chunk-6MRZXASS.js";
6
6
  import {
7
7
  init_require_shim
8
8
  } from "./chunk-TPK5AGRA.js";