@darkrymit/crunes-cli 0.8.4 → 0.9.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 (72) hide show
  1. package/dist/chunks/{add-CBHWFGCA.js → add-IT3IHBPO.js} +2 -2
  2. package/dist/chunks/{apply-YC6JEPUN.js → apply-YY7MIM64.js} +13 -12
  3. package/dist/chunks/{benchmark-BJEAAFWG.js → benchmark-BQNMULOO.js} +17 -14
  4. package/dist/chunks/{browse-JZFU52ET.js → browse-PHMBDREQ.js} +2 -2
  5. package/dist/chunks/{chunk-6MRZXASS.js → chunk-2Q3KLBE6.js} +16 -0
  6. package/dist/chunks/{chunk-2PBPDTRD.js → chunk-34F4ZURL.js} +40 -37
  7. package/dist/chunks/{chunk-ZJDKCC2Y.js → chunk-4GJMCFR6.js} +6 -3
  8. package/dist/chunks/chunk-CY6C6ADU.js +2787 -0
  9. package/dist/chunks/{chunk-J3GZ3DXD.js → chunk-GVMT55GH.js} +3 -2
  10. package/dist/chunks/{chunk-JOAL437H.js → chunk-I6MHDUCW.js} +16 -1
  11. package/dist/chunks/{chunk-6XLT25GS.js → chunk-MIKWIFYR.js} +47 -0
  12. package/dist/chunks/chunk-MRNZFUXZ.js +70 -0
  13. package/dist/chunks/{chunk-NAEVMRNA.js → chunk-PBGUKXT6.js} +2940 -1847
  14. package/dist/chunks/chunk-QYRF3R35.js +154 -0
  15. package/dist/chunks/{chunk-DZJRYFOP.js → chunk-SNC7AOT7.js} +78 -12
  16. package/dist/chunks/{chunk-63H5VXZY.js → chunk-UEUUOAJY.js} +4 -1
  17. package/dist/chunks/{chunk-65J65MAP.js → chunk-VST6HAB6.js} +16 -2
  18. package/dist/chunks/{chunk-NDEYEYSU.js → chunk-WJII3LZK.js} +4 -3
  19. package/dist/chunks/chunk-X7PZN73N.js +44 -0
  20. package/dist/chunks/{chunk-NYLRTAAA.js → chunk-YVN3VDRE.js} +1 -1
  21. package/dist/chunks/{chunk-JU6FKUBY.js → chunk-YXCHIMLW.js} +995 -3097
  22. package/dist/chunks/{clear-YBDIPEEH.js → clear-AT7HNUV4.js} +2 -2
  23. package/dist/chunks/{create-GPDE2YKL.js → create-ET6DT5ZE.js} +22 -18
  24. package/dist/chunks/{create-OZACMPEU.js → create-LM7U3CJS.js} +28 -20
  25. package/dist/chunks/{create-ZFFV3Z2P.js → create-TLPM7HJE.js} +5 -5
  26. package/dist/chunks/{delete-LNOYM5KG.js → delete-5R3WBLVD.js} +5 -5
  27. package/dist/chunks/{delete-E4TEBRPX.js → delete-GKYA2W5Z.js} +4 -2
  28. package/dist/chunks/{delete-C4UJ7X5K.js → delete-U4STA2QZ.js} +5 -5
  29. package/dist/chunks/disable-TNTEIAKO.js +39 -0
  30. package/dist/chunks/doctor-VXAQYMTR.js +101 -0
  31. package/dist/chunks/enable-GUQCB4CU.js +31 -0
  32. package/dist/chunks/{globals-H2WF344Y.js → globals-SNQFCHMP.js} +1 -1
  33. package/dist/chunks/{init-HU5OMHEH.js → init-PJSCFOC6.js} +14 -8
  34. package/dist/chunks/{install-RRLUOYFO.js → install-4YP7FALO.js} +18 -16
  35. package/dist/chunks/{intro-4CICBP2J.js → intro-SA7MWV3Z.js} +113 -43
  36. package/dist/chunks/{kill-2UG7PHUV.js → kill-TX3PC73P.js} +2 -1
  37. package/dist/chunks/list-7R6NASFI.js +92 -0
  38. package/dist/chunks/{list-4X3JFQGS.js → list-EHREZR6M.js} +2 -1
  39. package/dist/chunks/{list-U7PAYNAH.js → list-LC6HB3H3.js} +2 -2
  40. package/dist/chunks/{list-FLAYJQKN.js → list-OMMZAQ23.js} +2 -2
  41. package/dist/chunks/{list-7VHJIUDX.js → list-U4EMHQZT.js} +2 -2
  42. package/dist/chunks/{list-PTAWQYWG.js → list-V7VVD5AG.js} +2 -1
  43. package/dist/chunks/{list-A5WVDBWF.js → list-VA73WPK6.js} +2 -2
  44. package/dist/chunks/{list-CK5X2YN3.js → list-WKNPZZOV.js} +5 -4
  45. package/dist/chunks/{output-RJ6JSNY7.js → output-QN5CVJ62.js} +4 -1
  46. package/dist/chunks/{query-AW7WYILM.js → query-2US3CPYT.js} +2 -2
  47. package/dist/chunks/{registry-3QIL5SVL.js → registry-K5DV5NAK.js} +4 -2
  48. package/dist/chunks/{remove-QUH2D3S5.js → remove-BCFTF23J.js} +2 -2
  49. package/dist/chunks/{repl-STBZC4P2.js → repl-2YWTHUWT.js} +4 -0
  50. package/dist/chunks/{repl-VGC5FUJG.js → repl-ZB3DIJ4K.js} +84 -26
  51. package/dist/chunks/resolver-QIYYFIDX.js +34 -0
  52. package/dist/chunks/run-22B65ZWZ.js +29 -0
  53. package/dist/chunks/rune-SYK4N642.js +425 -0
  54. package/dist/chunks/{search-MSSDGJTF.js → search-B7IM7JRJ.js} +2 -2
  55. package/dist/chunks/shell-explain-QLITLHW7.js +74 -0
  56. package/dist/chunks/{uninstall-55YTHZRH.js → uninstall-4WR5IHLC.js} +15 -11
  57. package/dist/chunks/{unset-YASSMSE5.js → unset-P6IUF7SS.js} +2 -2
  58. package/dist/chunks/{update-G6XO4RIM.js → update-ACLDK6E6.js} +19 -18
  59. package/dist/chunks/{update-EWWDROKW.js → update-WXT7CHYA.js} +2 -2
  60. package/dist/chunks/{utils-XOWJQWNR.js → utils-B2QULX5J.js} +8 -4
  61. package/dist/chunks/{version-PW7MHDFH.js → version-EULYWNXN.js} +3 -2
  62. package/dist/cli.js +93 -71
  63. package/package.json +2 -1
  64. package/dist/chunks/chunk-ASZKAC24.js +0 -103
  65. package/dist/chunks/chunk-H3BVJCIL.js +0 -105
  66. package/dist/chunks/disable-TMG2K3BF.js +0 -47
  67. package/dist/chunks/doctor-N43QEMAH.js +0 -53
  68. package/dist/chunks/enable-327OMBPC.js +0 -47
  69. package/dist/chunks/list-WH7KESMV.js +0 -111
  70. package/dist/chunks/resolver-QMIY33FM.js +0 -26
  71. package/dist/chunks/run-T33CMCFZ.js +0 -26
  72. package/dist/chunks/rune-UBRVWG5A.js +0 -139
@@ -1,28 +1,32 @@
1
1
  import {
2
2
  formatSection,
3
- parseSegment
4
- } from "./chunk-DZJRYFOP.js";
3
+ parseSegment,
4
+ permissionHint
5
+ } from "./chunk-SNC7AOT7.js";
5
6
  import {
6
- loadConfig
7
- } from "./chunk-H3BVJCIL.js";
8
- import {
9
- isGlobMatch,
7
+ describeConfigLayers,
10
8
  parseArgs,
11
9
  tailStdin
12
- } from "./chunk-JU6FKUBY.js";
13
- import "./chunk-J3GZ3DXD.js";
14
- import "./chunk-ZJDKCC2Y.js";
15
- import "./chunk-NDEYEYSU.js";
10
+ } from "./chunk-YXCHIMLW.js";
11
+ import "./chunk-UEUUOAJY.js";
12
+ import "./chunk-4GJMCFR6.js";
13
+ import {
14
+ isGlobMatch
15
+ } from "./chunk-CY6C6ADU.js";
16
+ import "./chunk-GVMT55GH.js";
17
+ import "./chunk-WJII3LZK.js";
16
18
  import "./chunk-G4ZAUHHA.js";
17
- import "./chunk-63H5VXZY.js";
18
- import "./chunk-ASZKAC24.js";
19
+ import {
20
+ loadConfig
21
+ } from "./chunk-QYRF3R35.js";
19
22
  import {
20
23
  isVerbose,
21
24
  output
22
- } from "./chunk-6XLT25GS.js";
25
+ } from "./chunk-MIKWIFYR.js";
26
+ import "./chunk-CGZL5SSH.js";
23
27
  import "./chunk-WCODTMDN.js";
24
- import "./chunk-65J65MAP.js";
25
- import "./chunk-6MRZXASS.js";
28
+ import "./chunk-VST6HAB6.js";
29
+ import "./chunk-2Q3KLBE6.js";
26
30
  import "./chunk-G3U4V32O.js";
27
31
  import {
28
32
  init_require_shim
@@ -57,15 +61,54 @@ function parseJsonlInputLine(text) {
57
61
  if (!parsed || !VALID_INPUT_TYPES.has(parsed.type)) return null;
58
62
  return parsed;
59
63
  }
60
- function parseSlashCommand(line) {
64
+ function parseSlashCommand(line, requireSlash = true) {
61
65
  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 (requireSlash && !trimmed.startsWith("/")) return null;
67
+ const raw = trimmed.startsWith("/") ? trimmed.slice(1) : trimmed;
68
+ const spaceIdx = raw.indexOf(" ");
69
+ const name = spaceIdx === -1 ? raw : raw.slice(0, spaceIdx);
70
+ const rest = spaceIdx === -1 ? "" : raw.slice(spaceIdx + 1).trim();
66
71
  if (!name) return null;
67
72
  return { name, rest };
68
73
  }
74
+ function resolveCommandEvent(event, commandsSchema) {
75
+ if (event.type !== "command") return event;
76
+ if (event.args && typeof event.args === "object") {
77
+ const args = { ...event.args };
78
+ if (event.name && !args.$command) args.$command = event.name;
79
+ if (!args.$command) args.$command = "";
80
+ if (!args.$commands) args.$commands = args.$command ? [args.$command] : [];
81
+ return { type: "command", args };
82
+ }
83
+ if (typeof event.text === "string") {
84
+ const slash = parseSlashCommand(event.text, false);
85
+ if (!slash) return { type: "command", args: { $command: "", $commands: [], _: [], $rest: [], $raw: [] } };
86
+ if (slash.name === "exit") return { type: "eof", text: "" };
87
+ if (commandsSchema?.commands?.some((c) => c.name === slash.name)) {
88
+ const cmdSchema = {
89
+ commands: commandsSchema.commands,
90
+ options: [],
91
+ positionals: [],
92
+ examples: []
93
+ };
94
+ const cmdTokens2 = slash.rest ? [slash.name, ...slash.rest.split(/\s+/)] : [slash.name];
95
+ const parsedCmdArgs2 = parseArgs(cmdTokens2, cmdSchema);
96
+ return { type: "command", args: parsedCmdArgs2 };
97
+ }
98
+ const cmdTokens = slash.rest ? [slash.name, ...slash.rest.split(/\s+/)] : [slash.name];
99
+ const parsedCmdArgs = parseArgs(cmdTokens, null);
100
+ parsedCmdArgs.$command = slash.name;
101
+ parsedCmdArgs.$commands = [slash.name];
102
+ return { type: "command", args: parsedCmdArgs };
103
+ }
104
+ if (typeof event.name === "string") {
105
+ return {
106
+ type: "command",
107
+ args: { $command: event.name, $commands: [event.name], _: [], $rest: [], $raw: [event.name] }
108
+ };
109
+ }
110
+ return event;
111
+ }
69
112
  function parseReplArgs(argv) {
70
113
  let format = "text";
71
114
  let i = 0;
@@ -104,7 +147,7 @@ async function handler({
104
147
  output.info("Run `crunes init` to create a config file.");
105
148
  process.exit(1);
106
149
  }
107
- const { resolveRuneEntry } = await import("./resolver-QMIY33FM.js");
150
+ const { resolveRuneEntry } = await import("./resolver-QIYYFIDX.js");
108
151
  let runeEntry;
109
152
  try {
110
153
  runeEntry = await resolveRuneEntry(projectRoot, config, key, configRoot);
@@ -141,7 +184,12 @@ async function handler({
141
184
  session = await runeEntry.createReplSession(runeArgs, { onEvent, instanceId });
142
185
  } catch (err) {
143
186
  const msg = isVerbose ? err.stack || err.message : err.message;
144
- output.error(`Failed to start REPL for "${key}": ${msg}`);
187
+ const hint = permissionHint(err.message, {
188
+ key,
189
+ lifecycle: "repl",
190
+ configLayers: describeConfigLayers(configRoot)
191
+ });
192
+ output.error(`Failed to start REPL for "${key}": ${msg}${hint ?? ""}`);
145
193
  process.exit(1);
146
194
  }
147
195
  if (format === "jsonl") {
@@ -182,7 +230,12 @@ async function handler({
182
230
  if (format === "jsonl") {
183
231
  process.stdout.write(JSON.stringify({ type: "error", rune: key, instance: instanceId, message: msg }) + "\n");
184
232
  } else {
185
- process.stderr.write(`Error: ${msg}
233
+ const hint = permissionHint(err.message, {
234
+ key,
235
+ lifecycle: "repl",
236
+ configLayers: describeConfigLayers(configRoot)
237
+ });
238
+ process.stderr.write(`Error: ${msg}${hint ?? ""}
186
239
  `);
187
240
  }
188
241
  prompt();
@@ -216,7 +269,10 @@ async function handler({
216
269
  if (sessionEnded) return;
217
270
  if (jsonlInput) {
218
271
  const event = parseJsonlInputLine(line);
219
- if (event) await handleInputEvent(event);
272
+ if (event) {
273
+ const resolved = resolveCommandEvent(event, session.commandsSchema);
274
+ await handleInputEvent(resolved);
275
+ }
220
276
  } else {
221
277
  await handleInputEvent({ type: "line", text: line });
222
278
  }
@@ -321,7 +377,8 @@ async function handler({
321
377
  process.stdout.write(JSON.stringify({ type: "error", rune: key, instance: instanceId, message: `Invalid JSONL input: ${text}` }) + "\n");
322
378
  return;
323
379
  }
324
- await handleInputEvent(event);
380
+ const resolved = resolveCommandEvent(event, session.commandsSchema);
381
+ await handleInputEvent(resolved);
325
382
  return;
326
383
  }
327
384
  const slash = parseSlashCommand(text);
@@ -374,5 +431,6 @@ export {
374
431
  parseJsonlInputLine,
375
432
  parseReplArgs,
376
433
  parseReplReturn,
377
- parseSlashCommand
434
+ parseSlashCommand,
435
+ resolveCommandEvent
378
436
  };
@@ -0,0 +1,34 @@
1
+ import {
2
+ describeConfigLayers,
3
+ getRune,
4
+ normaliseRune,
5
+ resolvePluginRune,
6
+ resolveRuneEntry,
7
+ resolveRuneFilePath,
8
+ resolveRuneFromPlugins,
9
+ runRune
10
+ } from "./chunk-YXCHIMLW.js";
11
+ import "./chunk-UEUUOAJY.js";
12
+ import "./chunk-4GJMCFR6.js";
13
+ import "./chunk-CY6C6ADU.js";
14
+ import "./chunk-GVMT55GH.js";
15
+ import "./chunk-WJII3LZK.js";
16
+ import "./chunk-G4ZAUHHA.js";
17
+ import "./chunk-QYRF3R35.js";
18
+ import "./chunk-MIKWIFYR.js";
19
+ import "./chunk-CGZL5SSH.js";
20
+ import "./chunk-WCODTMDN.js";
21
+ import "./chunk-VST6HAB6.js";
22
+ import "./chunk-2Q3KLBE6.js";
23
+ import "./chunk-G3U4V32O.js";
24
+ import "./chunk-TPK5AGRA.js";
25
+ export {
26
+ describeConfigLayers,
27
+ getRune,
28
+ normaliseRune,
29
+ resolvePluginRune,
30
+ resolveRuneEntry,
31
+ resolveRuneFilePath,
32
+ resolveRuneFromPlugins,
33
+ runRune
34
+ };
@@ -0,0 +1,29 @@
1
+ import {
2
+ handler,
3
+ joinBracketTokens,
4
+ parseBracketKey,
5
+ parseRunArgs,
6
+ parseSegment
7
+ } from "./chunk-SNC7AOT7.js";
8
+ import "./chunk-YXCHIMLW.js";
9
+ import "./chunk-UEUUOAJY.js";
10
+ import "./chunk-4GJMCFR6.js";
11
+ import "./chunk-CY6C6ADU.js";
12
+ import "./chunk-GVMT55GH.js";
13
+ import "./chunk-WJII3LZK.js";
14
+ import "./chunk-G4ZAUHHA.js";
15
+ import "./chunk-QYRF3R35.js";
16
+ import "./chunk-MIKWIFYR.js";
17
+ import "./chunk-CGZL5SSH.js";
18
+ import "./chunk-WCODTMDN.js";
19
+ import "./chunk-VST6HAB6.js";
20
+ import "./chunk-2Q3KLBE6.js";
21
+ import "./chunk-G3U4V32O.js";
22
+ import "./chunk-TPK5AGRA.js";
23
+ export {
24
+ handler,
25
+ joinBracketTokens,
26
+ parseBracketKey,
27
+ parseRunArgs,
28
+ parseSegment
29
+ };
@@ -0,0 +1,425 @@
1
+ import {
2
+ enumerateRunes
3
+ } from "./chunk-MRNZFUXZ.js";
4
+ import {
5
+ getArgsSchema,
6
+ getPluginRunePath,
7
+ getReplSchema,
8
+ getRune,
9
+ resolvePluginRune,
10
+ resolveRuneFilePath,
11
+ resolveRuneFromPlugins
12
+ } from "./chunk-YXCHIMLW.js";
13
+ import "./chunk-UEUUOAJY.js";
14
+ import "./chunk-4GJMCFR6.js";
15
+ import {
16
+ computeEffectivePermissions
17
+ } from "./chunk-CY6C6ADU.js";
18
+ import "./chunk-GVMT55GH.js";
19
+ import "./chunk-WJII3LZK.js";
20
+ import "./chunk-G4ZAUHHA.js";
21
+ import {
22
+ loadConfig
23
+ } from "./chunk-QYRF3R35.js";
24
+ import {
25
+ output
26
+ } from "./chunk-MIKWIFYR.js";
27
+ import "./chunk-CGZL5SSH.js";
28
+ import "./chunk-WCODTMDN.js";
29
+ import "./chunk-VST6HAB6.js";
30
+ import "./chunk-2Q3KLBE6.js";
31
+ import {
32
+ loadPluginJson
33
+ } from "./chunk-G3U4V32O.js";
34
+ import {
35
+ init_require_shim
36
+ } from "./chunk-TPK5AGRA.js";
37
+
38
+ // src/docs/commands/rune.js
39
+ init_require_shim();
40
+ import { relative } from "node:path";
41
+
42
+ // src/docs/help-render.js
43
+ init_require_shim();
44
+ var PAD = 24;
45
+ function row(label, description, indent = " ") {
46
+ const padded = label.length >= PAD ? label + " " : label.padEnd(PAD);
47
+ return `${indent}${padded} ${description ?? ""}`.trimEnd();
48
+ }
49
+ function positionalSpecs(node) {
50
+ return (node?.positionals ?? []).map((p) => p.spec).join(" ");
51
+ }
52
+ function flattenCommands(commands, prefix = "") {
53
+ const rows = [];
54
+ for (const cmd of commands ?? []) {
55
+ const path = prefix ? `${prefix} ${cmd.name}` : cmd.name;
56
+ const specs = positionalSpecs(cmd);
57
+ rows.push({
58
+ path,
59
+ label: specs ? `${path} ${specs}` : path,
60
+ description: cmd.description ?? "",
61
+ node: cmd
62
+ });
63
+ rows.push(...flattenCommands(cmd.commands ?? [], path));
64
+ }
65
+ return rows;
66
+ }
67
+ function selectNode(schema, segments) {
68
+ let node = schema;
69
+ const matched = [];
70
+ for (const seg of segments ?? []) {
71
+ const children = node?.commands ?? [];
72
+ const next = children.find((c) => c.name === seg);
73
+ if (!next) {
74
+ return {
75
+ node: null,
76
+ matchedPath: matched.join(" "),
77
+ failedAt: seg,
78
+ candidates: children.map((c) => c.name)
79
+ };
80
+ }
81
+ node = next;
82
+ matched.push(seg);
83
+ }
84
+ return {
85
+ node,
86
+ matchedPath: matched.join(" "),
87
+ failedAt: null,
88
+ candidates: (node?.commands ?? []).map((c) => c.name)
89
+ };
90
+ }
91
+ function verb(lifecycle) {
92
+ return lifecycle === "repl" ? "repl" : "run";
93
+ }
94
+ function optionRows(options, indent = " ") {
95
+ return (options ?? []).map((opt) => {
96
+ const def = opt.def !== void 0 ? ` [default: ${JSON.stringify(opt.def)}]` : "";
97
+ return row(opt.flags, `${opt.description ?? ""}${def}`, indent);
98
+ });
99
+ }
100
+ function exampleLines(examples, indent = " ") {
101
+ const lines = [];
102
+ for (const ex of examples ?? []) {
103
+ lines.push(`${indent}${ex.usage}`);
104
+ if (ex.description) lines.push(`${indent} ${ex.description}`);
105
+ }
106
+ return lines;
107
+ }
108
+ function formatCommandPage(node, meta) {
109
+ const key = meta?.key ?? "rune";
110
+ const path = meta?.path ?? "";
111
+ const specs = positionalSpecs(node);
112
+ const children = node?.commands ?? [];
113
+ const usage = [`Usage: crunes ${verb(meta?.lifecycle)} ${key}`];
114
+ if (path) usage.push(path);
115
+ if (specs) usage.push(specs);
116
+ else if (children.length > 0) usage.push("<command>");
117
+ usage.push("[options]");
118
+ const lines = [usage.join(" ")];
119
+ if (node?.description) {
120
+ lines.push("");
121
+ lines.push(` ${node.description}`);
122
+ }
123
+ const positionals = node?.positionals ?? [];
124
+ if (positionals.length > 0) {
125
+ lines.push("");
126
+ lines.push("Positionals:");
127
+ for (const p of positionals) lines.push(row(p.spec ?? "", p.description));
128
+ }
129
+ const options = node?.options ?? [];
130
+ if (options.length > 0) {
131
+ lines.push("");
132
+ lines.push("Options:");
133
+ lines.push(...optionRows(options));
134
+ }
135
+ if (children.length > 0) {
136
+ lines.push("");
137
+ lines.push("Commands:");
138
+ for (const child of children) {
139
+ const childPath = path ? `${path} ${child.name}` : child.name;
140
+ const childSpecs = positionalSpecs(child);
141
+ lines.push(row(childSpecs ? `${childPath} ${childSpecs}` : childPath, child.description));
142
+ }
143
+ }
144
+ const examples = node?.examples ?? [];
145
+ if (examples.length > 0) {
146
+ lines.push("");
147
+ lines.push("Examples:");
148
+ lines.push(...exampleLines(examples));
149
+ }
150
+ return lines.join("\n");
151
+ }
152
+ function formatRuneIndex(schema, meta) {
153
+ const key = meta?.key ?? "rune";
154
+ const label = meta?.description ?? meta?.name ?? null;
155
+ const commands = schema?.commands ?? [];
156
+ const specs = positionalSpecs(schema);
157
+ const lines = [`Rune: ${key}${label ? ` \u2014 ${label}` : ""}`];
158
+ if (meta?.relativePath) lines.push(`File (project-relative): ${meta.relativePath}`);
159
+ const usage = [`Usage: crunes ${verb(meta?.lifecycle)} ${key}`];
160
+ if (specs) usage.push(specs);
161
+ else if (commands.length > 0) usage.push("<command>");
162
+ usage.push("[options]");
163
+ lines.push("");
164
+ lines.push(usage.join(" "));
165
+ const positionals = schema?.positionals ?? [];
166
+ if (positionals.length > 0) {
167
+ lines.push("");
168
+ lines.push("Positionals:");
169
+ for (const p of positionals) lines.push(row(p.spec ?? "", p.description));
170
+ }
171
+ const options = schema?.options ?? [];
172
+ if (options.length > 0) {
173
+ lines.push("");
174
+ lines.push("Options:");
175
+ lines.push(...optionRows(options));
176
+ }
177
+ if (commands.length > 0) {
178
+ lines.push("");
179
+ lines.push("Commands:");
180
+ for (const r of flattenCommands(commands)) lines.push(row(r.label, r.description));
181
+ }
182
+ const rootExamples = schema?.examples ?? [];
183
+ if (commands.length === 0 && rootExamples.length > 0) {
184
+ lines.push("");
185
+ lines.push("Examples:");
186
+ lines.push(...exampleLines(rootExamples));
187
+ }
188
+ const replCommands = meta?.repl?.commands ?? [];
189
+ if (replCommands.length > 0) {
190
+ lines.push("");
191
+ lines.push("REPL commands:");
192
+ for (const c of replCommands) lines.push(row(`/${c.name}`, c.description));
193
+ }
194
+ if (meta?.includeBatch === true) {
195
+ lines.push("");
196
+ lines.push("Batch:");
197
+ if (!meta.batch) {
198
+ lines.push(" (no batch block declared \u2014 this rune cannot appear in a -b batch)");
199
+ } else {
200
+ const allow = meta.batch.allow ?? [];
201
+ const deny = meta.batch.deny ?? [];
202
+ lines.push(` allow: ${allow.length ? allow.join(", ") : "(none)"}`);
203
+ if (deny.length) lines.push(` deny: ${deny.join(", ")}`);
204
+ }
205
+ }
206
+ if (commands.length > 0) {
207
+ lines.push("");
208
+ lines.push(`Drill down: crunes docs rune ${key} <command>`);
209
+ }
210
+ return lines.join("\n");
211
+ }
212
+ var GLOBAL_PAD = 50;
213
+ function formatGlobalIndex(entries) {
214
+ if (!entries || entries.length === 0) {
215
+ return "No runes configured. Run `crunes create <key>` to add one.";
216
+ }
217
+ const lines = ["Runes:", ""];
218
+ for (const e of entries) {
219
+ if (e.error) {
220
+ lines.push(`\u26A0 ${e.key} \u2014 could not build args schema: ${e.error}`);
221
+ lines.push("");
222
+ continue;
223
+ }
224
+ const label = e.description ?? e.name ?? "";
225
+ const head = `${e.key}${label ? ` \u2014 ${label}` : ""}`;
226
+ const padded = head.length >= GLOBAL_PAD ? head + " " : head.padEnd(GLOBAL_PAD);
227
+ lines.push(`${padded}${e.source ?? ""}`.trimEnd());
228
+ for (const r of flattenCommands(e.schema?.commands ?? [])) {
229
+ lines.push(row(r.label, r.description));
230
+ }
231
+ lines.push("");
232
+ }
233
+ lines.push("Drill down: crunes docs rune <key> [command path...]");
234
+ return lines.join("\n");
235
+ }
236
+
237
+ // src/docs/commands/rune.js
238
+ var SUGGESTIONS = {
239
+ run: "crunes docs run",
240
+ args: "crunes docs args",
241
+ intro: "crunes docs intro",
242
+ utils: "crunes docs utils",
243
+ globals: "crunes docs globals"
244
+ };
245
+ async function resolveRuneDocs(config, key, projectRoot, configRoot) {
246
+ const pluginMatch = await resolvePluginRune(config, key);
247
+ const localEntry = pluginMatch ? null : getRune(config, key);
248
+ let autoMatch = null;
249
+ if (!pluginMatch && !localEntry) {
250
+ autoMatch = await resolveRuneFromPlugins(config, key);
251
+ }
252
+ const resolved = pluginMatch ?? autoMatch;
253
+ if (!localEntry && !resolved) return null;
254
+ let runeFile, relativePath, basePerms, vars, displayName, displayDescription, batch;
255
+ if (resolved) {
256
+ const { runeKey, pluginDir } = resolved;
257
+ const pluginJson = await loadPluginJson(pluginDir);
258
+ const runeDef = pluginJson.runes[runeKey] ?? {};
259
+ runeFile = getPluginRunePath(pluginDir, runeKey, pluginJson);
260
+ relativePath = void 0;
261
+ basePerms = runeDef.permissions ?? { allow: [], deny: [] };
262
+ vars = runeDef.vars ?? {};
263
+ displayName = runeDef.name ?? runeKey;
264
+ displayDescription = runeDef.description ?? null;
265
+ batch = runeDef.batch != null ? { allow: runeDef.batch.allow ?? [], deny: runeDef.batch.deny ?? [] } : null;
266
+ } else {
267
+ runeFile = resolveRuneFilePath(localEntry, key, configRoot);
268
+ relativePath = relative(projectRoot, runeFile).replace(/\\/g, "/");
269
+ basePerms = localEntry.permissions ?? { allow: [], deny: [] };
270
+ vars = localEntry.vars ?? {};
271
+ displayName = localEntry.name ?? key;
272
+ displayDescription = localEntry.description ?? null;
273
+ batch = localEntry.batch != null ? { allow: localEntry.batch.allow ?? [], deny: localEntry.batch.deny ?? [] } : null;
274
+ }
275
+ const runEffective = computeEffectivePermissions(basePerms, void 0, "run");
276
+ const replEffective = computeEffectivePermissions(basePerms, void 0, "repl");
277
+ let schema = null;
278
+ let schemaError = null;
279
+ try {
280
+ schema = await getArgsSchema(runeFile, runEffective, projectRoot, { vars, runeKey: key });
281
+ } catch (err) {
282
+ schemaError = err.message;
283
+ output.warn(`Could not load args schema for "${key}": ${err.message}`);
284
+ }
285
+ let repl = null;
286
+ try {
287
+ const { argsSchema, commandsSchema } = await getReplSchema(runeFile, replEffective, [], projectRoot, { vars, runeKey: key });
288
+ if (argsSchema !== null || commandsSchema !== null) repl = { argsSchema, commandsSchema };
289
+ } catch (err) {
290
+ output.warn(`Could not load REPL schema for "${key}": ${err.message}`);
291
+ }
292
+ return { key, name: displayName, description: displayDescription, relativePath, schema, schemaError, repl, batch };
293
+ }
294
+ function commandRows(commands) {
295
+ return flattenCommands(commands ?? []).map((r) => ({ path: r.path, description: r.description }));
296
+ }
297
+ function directChildRows(node, path) {
298
+ return (node?.commands ?? []).map((c) => ({
299
+ path: path ? `${path} ${c.name}` : c.name,
300
+ description: c.description ?? ""
301
+ }));
302
+ }
303
+ async function handler({ key, path = [], format = "text", projectRoot = process.cwd(), configRoot = projectRoot }) {
304
+ let config;
305
+ try {
306
+ config = loadConfig(configRoot);
307
+ } catch (err) {
308
+ output.error(`Config unreadable: ${err.message}`);
309
+ process.exit(1);
310
+ return;
311
+ }
312
+ if (key == null) {
313
+ const listed = await enumerateRunes(config);
314
+ const entries = [];
315
+ let anyFailed = false;
316
+ for (const e of listed) {
317
+ let docsEntry = null;
318
+ let error = null;
319
+ try {
320
+ docsEntry = await resolveRuneDocs(config, e.key, projectRoot, configRoot);
321
+ if (!docsEntry) error = "rune could not be resolved";
322
+ else if (docsEntry.schemaError) error = docsEntry.schemaError;
323
+ } catch (err) {
324
+ error = err.message;
325
+ }
326
+ if (error) {
327
+ anyFailed = true;
328
+ entries.push({ ...e, error });
329
+ } else {
330
+ entries.push({ ...e, schema: docsEntry.schema });
331
+ }
332
+ }
333
+ if (format === "json") {
334
+ process.stdout.write(JSON.stringify(entries.map((e) => ({
335
+ key: e.key,
336
+ name: e.name,
337
+ description: e.description,
338
+ source: e.source,
339
+ error: e.error ?? null,
340
+ commands: e.error ? [] : commandRows(e.schema?.commands)
341
+ })), null, 2) + "\n");
342
+ } else {
343
+ process.stdout.write(formatGlobalIndex(entries) + "\n");
344
+ }
345
+ if (anyFailed) process.exit(1);
346
+ return;
347
+ }
348
+ let docs;
349
+ try {
350
+ docs = await resolveRuneDocs(config, key, projectRoot, configRoot);
351
+ } catch (err) {
352
+ output.warn(err.message);
353
+ process.exit(1);
354
+ return;
355
+ }
356
+ if (!docs) {
357
+ if (SUGGESTIONS[key]) {
358
+ output.warn(`Unknown rune: "${key}". (Tip: Did you mean "${SUGGESTIONS[key]}"?)`);
359
+ } else {
360
+ output.warn(`Unknown rune: "${key}"`);
361
+ }
362
+ process.exit(1);
363
+ return;
364
+ }
365
+ const segments = path ?? [];
366
+ if (segments.length === 0) {
367
+ if (format === "json") {
368
+ process.stdout.write(JSON.stringify({
369
+ key: docs.key,
370
+ name: docs.name,
371
+ description: docs.description,
372
+ relativePath: docs.relativePath,
373
+ options: docs.schema?.options ?? [],
374
+ positionals: docs.schema?.positionals ?? [],
375
+ // Mirrors the text index: withheld while there are commands to drill into.
376
+ examples: (docs.schema?.commands ?? []).length === 0 ? docs.schema?.examples ?? [] : [],
377
+ commands: commandRows(docs.schema?.commands),
378
+ repl: docs.repl ? { commands: docs.repl.commandsSchema?.commands ?? [] } : null,
379
+ batch: docs.batch
380
+ }, null, 2) + "\n");
381
+ } else {
382
+ process.stdout.write(formatRuneIndex(docs.schema, {
383
+ key: docs.key,
384
+ name: docs.name,
385
+ description: docs.description,
386
+ relativePath: docs.relativePath,
387
+ repl: docs.repl ? { commands: docs.repl.commandsSchema?.commands ?? [] } : null,
388
+ batch: docs.batch,
389
+ includeBatch: true
390
+ }) + "\n");
391
+ }
392
+ return;
393
+ }
394
+ const sel = selectNode(docs.schema, segments);
395
+ if (!sel.node) {
396
+ const lines = [`"${sel.failedAt}" is not a command of rune "${docs.key}"${sel.matchedPath ? ` at path "${sel.matchedPath}"` : ""}.`];
397
+ lines.push("");
398
+ lines.push(` Available commands: ${sel.candidates.length ? sel.candidates.join(", ") : "(none)"}`);
399
+ const isKnownRune = await resolveRuneDocs(config, sel.failedAt, projectRoot, configRoot).catch(() => null);
400
+ if (isKnownRune) {
401
+ lines.push("");
402
+ lines.push(` "${sel.failedAt}" is a known rune. Multi-rune lookup was removed \u2014 run`);
403
+ lines.push(" `crunes docs rune` for an index of all runes, or `crunes docs rune " + sel.failedAt + "`.");
404
+ }
405
+ output.error(lines.join("\n"));
406
+ process.exit(1);
407
+ return;
408
+ }
409
+ if (format === "json") {
410
+ process.stdout.write(JSON.stringify({
411
+ path: sel.matchedPath,
412
+ description: sel.node.description ?? null,
413
+ positionals: sel.node.positionals ?? [],
414
+ options: sel.node.options ?? [],
415
+ examples: sel.node.examples ?? [],
416
+ commands: directChildRows(sel.node, sel.matchedPath)
417
+ }, null, 2) + "\n");
418
+ } else {
419
+ process.stdout.write(formatCommandPage(sel.node, { key: docs.key, path: sel.matchedPath }) + "\n");
420
+ }
421
+ }
422
+ export {
423
+ handler,
424
+ resolveRuneDocs
425
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  searchMarketplaces
3
- } from "./chunk-NYLRTAAA.js";
4
- import "./chunk-6MRZXASS.js";
3
+ } from "./chunk-YVN3VDRE.js";
4
+ import "./chunk-2Q3KLBE6.js";
5
5
  import {
6
6
  init_require_shim
7
7
  } from "./chunk-TPK5AGRA.js";