@darkrymit/crunes-cli 0.5.10 → 0.7.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 (70) hide show
  1. package/README.md +5 -5
  2. package/dist/chunks/add-OWYVF3IE.js +22 -0
  3. package/dist/chunks/apply-OMEVXCHC.js +183 -0
  4. package/dist/chunks/args-32BVYW77.js +42 -0
  5. package/dist/chunks/benchmark-CLUBISCR.js +164 -0
  6. package/dist/chunks/browse-COH6IJEX.js +34 -0
  7. package/dist/chunks/check-BS6TZGRR.js +144 -0
  8. package/dist/chunks/chunk-2Q24YPGL.js +369 -0
  9. package/dist/chunks/chunk-3TM6B4E5.js +70 -0
  10. package/dist/chunks/chunk-67I2J474.js +153 -0
  11. package/dist/chunks/chunk-6XLT25GS.js +50 -0
  12. package/dist/chunks/chunk-BVY5LN7X.js +25091 -0
  13. package/dist/chunks/chunk-CGZL5SSH.js +926 -0
  14. package/dist/chunks/chunk-DMMC4X27.js +1836 -0
  15. package/dist/chunks/chunk-G3U4V32O.js +46 -0
  16. package/dist/chunks/chunk-GHQOK4L7.js +59 -0
  17. package/dist/chunks/chunk-H3BVJCIL.js +105 -0
  18. package/dist/chunks/chunk-HMU2J25D.js +63 -0
  19. package/dist/chunks/chunk-HOH7WZX4.js +95 -0
  20. package/dist/chunks/chunk-L72BG6DS.js +225 -0
  21. package/dist/chunks/chunk-NXSDVVTW.js +181 -0
  22. package/dist/chunks/chunk-QLDB3FO2.js +73059 -0
  23. package/dist/chunks/chunk-QMWGQXEZ.js +26 -0
  24. package/dist/chunks/chunk-TPK5AGRA.js +54 -0
  25. package/dist/chunks/chunk-UGN3FFEF.js +8379 -0
  26. package/dist/chunks/chunk-WCODTMDN.js +508 -0
  27. package/dist/chunks/chunk-XIXND2M4.js +296 -0
  28. package/dist/chunks/chunk-XXUNHQIB.js +129 -0
  29. package/dist/chunks/chunk-ZXIP4Z5V.js +281 -0
  30. package/dist/chunks/clear-Y5POLIMF.js +32 -0
  31. package/dist/chunks/completions-2MSEWWTG.js +232 -0
  32. package/dist/chunks/create-5FXQYCGM.js +165 -0
  33. package/dist/chunks/create-I6BNYZ5Q.js +247 -0
  34. package/dist/chunks/create-O3HMODSL.js +130 -0
  35. package/dist/chunks/delete-7CQFYIXS.js +40 -0
  36. package/dist/chunks/delete-UB5SXO5I.js +40 -0
  37. package/dist/chunks/disable-FCBW7WVG.js +47 -0
  38. package/dist/chunks/doctor-DS57HDLJ.js +53 -0
  39. package/dist/chunks/enable-IXRVUXJM.js +47 -0
  40. package/dist/chunks/esm-7MEWZCHY.js +5162 -0
  41. package/dist/chunks/globals-YCJ2DGWC.js +60 -0
  42. package/dist/chunks/init-WGKQVAZE.js +59 -0
  43. package/dist/chunks/install-BCTBOPBS.js +57 -0
  44. package/dist/chunks/intro-2UDWF6D4.js +1482 -0
  45. package/dist/chunks/kill-LWRXZVM5.js +37 -0
  46. package/dist/chunks/list-5DVVP7HX.js +50 -0
  47. package/dist/chunks/list-6WL5LGIZ.js +80 -0
  48. package/dist/chunks/list-NGOCMJXE.js +104 -0
  49. package/dist/chunks/list-TTKLNJKI.js +28 -0
  50. package/dist/chunks/list-WUAOSO3M.js +110 -0
  51. package/dist/chunks/list-YPI7YDKK.js +80 -0
  52. package/dist/chunks/list-ZBYPMUID.js +23 -0
  53. package/dist/chunks/manifest-7RVNKBOH.js +9 -0
  54. package/dist/chunks/output-RJ6JSNY7.js +12 -0
  55. package/dist/chunks/promise-DUSIQMA2.js +19400 -0
  56. package/dist/chunks/query-NY4SCO77.js +41 -0
  57. package/dist/chunks/registry-W5XFI5T6.js +16 -0
  58. package/dist/chunks/remove-WEAZFZCO.js +22 -0
  59. package/dist/chunks/run-I6TZX347.js +23 -0
  60. package/dist/chunks/run-MVIZQVJ6.js +36 -0
  61. package/dist/chunks/rune-TAX26NH2.js +76 -0
  62. package/dist/chunks/search-XENXL3GC.js +25 -0
  63. package/dist/chunks/uninstall-MX5PLGDI.js +49 -0
  64. package/dist/chunks/unset-KQOZYVTE.js +28 -0
  65. package/dist/chunks/update-7XDTVFZ3.js +39 -0
  66. package/dist/chunks/update-IEE54GPY.js +79 -0
  67. package/dist/chunks/utils-PO3ZK53L.js +50 -0
  68. package/dist/chunks/version-DIEA5FVV.js +145 -0
  69. package/dist/cli.js +3360 -125840
  70. package/package.json +23 -15
@@ -0,0 +1,296 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/docs/ts-walker.js
6
+ init_require_shim();
7
+ var KIND_MODULE = 2;
8
+ var KIND_NAMESPACE = 4;
9
+ var KIND_FUNCTION = 64;
10
+ var KIND_CLASS = 128;
11
+ var KIND_INTERFACE = 256;
12
+ var KIND_PROPERTY = 1024;
13
+ var KIND_METHOD = 2048;
14
+ var KIND_CTOR = 512;
15
+ function commentText(comment) {
16
+ if (!comment?.summary) return "";
17
+ return comment.summary.map((s) => s.text).join("").trim();
18
+ }
19
+ function paramComment(comment, paramName) {
20
+ const tag = comment?.blockTags?.find((t) => t.tag === "@param" && t.name === paramName);
21
+ if (!tag) return "";
22
+ return tag.content.map((c) => c.text).join("").trim();
23
+ }
24
+ function returnsComment(comment) {
25
+ const tag = comment?.blockTags?.find((t) => t.tag === "@returns");
26
+ if (!tag) return "";
27
+ return tag.content.map((c) => c.text).join("").trim();
28
+ }
29
+ function typeStr(typeObj) {
30
+ if (!typeObj) return "unknown";
31
+ if (typeObj.type === "intrinsic") return typeObj.name;
32
+ if (typeObj.type === "literal") return JSON.stringify(typeObj.value);
33
+ if (typeObj.type === "reference") {
34
+ const args = typeObj.typeArguments;
35
+ if (args?.length) return `${typeObj.name}<${args.map(typeStr).join(", ")}>`;
36
+ return typeObj.name;
37
+ }
38
+ if (typeObj.type === "union") return typeObj.types.map(typeStr).join(" | ");
39
+ if (typeObj.type === "intersection") return typeObj.types.map(typeStr).join(" & ");
40
+ if (typeObj.type === "array") return `${typeStr(typeObj.elementType)}[]`;
41
+ if (typeObj.type === "reflection") return reflectionTypeStr(typeObj.declaration);
42
+ return typeObj.type ?? "unknown";
43
+ }
44
+ function reflectionTypeStr(decl) {
45
+ if (!decl) return "object";
46
+ if (decl.signatures?.length) {
47
+ const sig = decl.signatures[0];
48
+ const params = (sig.parameters ?? []).map((p) => {
49
+ const opt = p.flags?.isOptional ? "?" : "";
50
+ return `${p.name}${opt}: ${typeStr(p.type)}`;
51
+ }).join(", ");
52
+ return `(${params}) => ${typeStr(sig.type)}`;
53
+ }
54
+ if (!decl.children?.length) return "object";
55
+ return `{ ${decl.children.map((c) => {
56
+ const opt = c.flags?.isOptional ? "?" : "";
57
+ return `${c.name}${opt}: ${typeStr(c.type)}`;
58
+ }).join("; ")} }`;
59
+ }
60
+ function walkParam(p, sigComment) {
61
+ const desc = paramComment(sigComment, p.name) || commentText(p.comment);
62
+ const optional = p.flags?.isOptional ? true : void 0;
63
+ if (p.type?.type === "reflection" && !p.type.declaration?.signatures?.length) {
64
+ const decl = p.type.declaration;
65
+ const fields = (decl?.children ?? []).map((c) => ({
66
+ name: c.name,
67
+ type: typeStr(c.type),
68
+ description: commentText(c.comment) || void 0,
69
+ ...c.flags?.isOptional ? { optional: true } : {}
70
+ }));
71
+ return {
72
+ name: p.name,
73
+ ...desc ? { description: desc } : {},
74
+ ...optional ? { optional } : {},
75
+ fields
76
+ };
77
+ }
78
+ return {
79
+ name: p.name,
80
+ type: typeStr(p.type),
81
+ ...desc ? { description: desc } : {},
82
+ ...optional ? { optional } : {}
83
+ };
84
+ }
85
+ function walkSignature(sig) {
86
+ return (sig.parameters ?? []).map((p) => walkParam(p, sig.comment));
87
+ }
88
+ function walkProperty(child) {
89
+ const readonly = child.flags?.isReadonly ? true : void 0;
90
+ const optional = child.flags?.isOptional ? true : void 0;
91
+ return {
92
+ name: child.name,
93
+ type: typeStr(child.type),
94
+ description: commentText(child.comment) || void 0,
95
+ ...optional ? { optional } : {},
96
+ ...readonly ? { readonly } : {}
97
+ };
98
+ }
99
+ function walkMethod(child) {
100
+ return (child.signatures ?? []).map((sig) => ({
101
+ name: child.name,
102
+ description: commentText(sig.comment) || void 0,
103
+ params: walkSignature(sig),
104
+ returns: typeStr(sig.type),
105
+ returnsDescription: returnsComment(sig.comment) || void 0
106
+ }));
107
+ }
108
+ function walkClassOrInterface(child) {
109
+ const properties = (child.children ?? []).filter((c) => c.kind === KIND_PROPERTY).map(walkProperty);
110
+ const methods = (child.children ?? []).filter((c) => c.kind === KIND_METHOD).flatMap(walkMethod);
111
+ const base = {
112
+ name: child.name,
113
+ description: commentText(child.comment) || void 0,
114
+ properties,
115
+ methods
116
+ };
117
+ if (child.kind === KIND_CLASS) {
118
+ const ctorChild = (child.children ?? []).find((c) => c.kind === KIND_CTOR);
119
+ const ctorSig = ctorChild?.signatures?.[0];
120
+ base.constructor = ctorSig ? walkSignature(ctorSig) : [];
121
+ }
122
+ if (child.kind === KIND_INTERFACE) {
123
+ const ext = child.extendedTypes?.[0];
124
+ if (ext) base.extends = typeStr(ext);
125
+ }
126
+ return base;
127
+ }
128
+ function walkChildren(children) {
129
+ const members = [];
130
+ for (const child of children ?? []) {
131
+ if (child.kind === KIND_NAMESPACE) {
132
+ members.push({
133
+ kind: "namespace",
134
+ name: child.name,
135
+ description: commentText(child.comment) || void 0,
136
+ members: walkChildren(child.children)
137
+ });
138
+ } else if (child.kind === KIND_FUNCTION) {
139
+ for (const sig of child.signatures ?? []) {
140
+ members.push({
141
+ kind: "function",
142
+ name: child.name,
143
+ description: commentText(sig.comment) || void 0,
144
+ params: walkSignature(sig),
145
+ returns: typeStr(sig.type),
146
+ returnsDescription: returnsComment(sig.comment) || void 0
147
+ });
148
+ }
149
+ } else if (child.kind === KIND_CLASS) {
150
+ members.push({ kind: "class", ...walkClassOrInterface(child) });
151
+ } else if (child.kind === KIND_INTERFACE) {
152
+ members.push({ kind: "interface", ...walkClassOrInterface(child) });
153
+ }
154
+ }
155
+ return members;
156
+ }
157
+ function walk(typedocJson) {
158
+ const top = typedocJson.children ?? [];
159
+ const unwrapped = top.flatMap((c) => c.kind === KIND_MODULE ? c.children ?? [] : [c]);
160
+ return unwrapped.map((c) => ({
161
+ kind: "namespace",
162
+ name: c.name,
163
+ description: commentText(c.comment) || void 0,
164
+ members: walkChildren(c.children)
165
+ }));
166
+ }
167
+
168
+ // src/docs/ts-formatter.js
169
+ init_require_shim();
170
+ function indentDesc(desc, indent) {
171
+ return desc.split("\n").join("\n" + indent);
172
+ }
173
+ function sigLineTyped(name, params, returns) {
174
+ const args = (params ?? []).map((p) => {
175
+ if (p.fields) {
176
+ const opt2 = p.optional ? "?" : "";
177
+ const fields = p.fields.map((f) => `${f.name}${f.optional ? "?" : ""}: ${f.type}`).join("; ");
178
+ return `${p.name}${opt2}: { ${fields} }`;
179
+ }
180
+ const opt = p.optional ? "?" : "";
181
+ return p.type ? `${p.name}${opt}: ${p.type}` : `${p.name}${opt}`;
182
+ }).join(", ");
183
+ const ret = returns && returns !== "void" ? `: ${returns}` : "";
184
+ return `${name}(${args})${ret}`;
185
+ }
186
+ function renderParams(params, indent) {
187
+ const withDesc = (params ?? []).filter((p) => p.description || p.fields?.some((f) => f.description));
188
+ if (!withDesc.length) return [];
189
+ const lines = [`${indent}Parameters:`];
190
+ for (const p of params ?? []) {
191
+ if (!p.description && !p.fields?.some((f) => f.description)) continue;
192
+ if (p.fields) {
193
+ const opt = p.optional ? "?" : "";
194
+ lines.push(`${indent} ${p.name}${opt}${p.description ? " " + indentDesc(p.description, indent + " ") : ""}`);
195
+ for (const f of p.fields) {
196
+ if (!f.description) continue;
197
+ const fopt = f.optional ? "?" : "";
198
+ lines.push(`${indent} ${f.name}${fopt} ${indentDesc(f.description, indent + " ")}`);
199
+ }
200
+ } else {
201
+ const opt = p.optional ? "?" : "";
202
+ lines.push(`${indent} ${p.name}${opt} ${indentDesc(p.description, indent + " ")}`);
203
+ }
204
+ }
205
+ return lines;
206
+ }
207
+ function renderFunctionBody(node, indent) {
208
+ const lines = [];
209
+ if (node.description) lines.push(`${indent} ${indentDesc(node.description, indent + " ")}`);
210
+ const paramLines = renderParams(node.params, `${indent} `);
211
+ if (paramLines.length) lines.push(...paramLines);
212
+ if (node.returnsDescription) lines.push(`${indent} Returns: ${indentDesc(node.returnsDescription, indent + " ")}`);
213
+ return lines;
214
+ }
215
+ function renderFunction(node, indent) {
216
+ const lines = [];
217
+ lines.push(`${indent}${sigLineTyped(node.name, node.params, node.returns)}`);
218
+ lines.push(...renderFunctionBody(node, indent));
219
+ return lines.join("\n");
220
+ }
221
+ function renderProperty(p, indent) {
222
+ const ro = p.readonly ? "readonly " : "";
223
+ const opt = p.optional ? "?" : "";
224
+ return `${indent}${ro}${p.name}${opt} ${p.type}${p.description ? " " + indentDesc(p.description, indent) : ""}`;
225
+ }
226
+ function renderMethods(methods, indent) {
227
+ if (!methods?.length) return [];
228
+ const lines = [];
229
+ let i = 0;
230
+ while (i < methods.length) {
231
+ const m = methods[i];
232
+ const overloads = [m];
233
+ while (i + overloads.length < methods.length && methods[i + overloads.length].name === m.name) {
234
+ overloads.push(methods[i + overloads.length]);
235
+ }
236
+ lines.push("");
237
+ if (overloads.length > 1) {
238
+ for (const o of overloads) {
239
+ lines.push(`${indent}${sigLineTyped(o.name, o.params, o.returns)}`);
240
+ }
241
+ } else {
242
+ lines.push(`${indent}${sigLineTyped(m.name, m.params, m.returns)}`);
243
+ lines.push(...renderFunctionBody(m, indent));
244
+ }
245
+ i += overloads.length;
246
+ }
247
+ return lines;
248
+ }
249
+ function renderClassOrInterface(node, indent) {
250
+ const lines = [];
251
+ const heading = node.kind === "class" ? `${indent}${sigLineTyped(node.name, node.constructor ?? [], void 0)}` : node.extends ? `${indent}${node.name} extends ${node.extends}` : `${indent}${node.name}`;
252
+ lines.push(heading);
253
+ if (node.description) {
254
+ lines.push(`${indent} ${indentDesc(node.description, indent + " ")}`);
255
+ if (node.properties?.length || node.methods?.length) lines.push("");
256
+ }
257
+ const hasProps = (node.properties ?? []).length > 0;
258
+ for (const p of node.properties ?? []) {
259
+ lines.push(renderProperty(p, `${indent} `));
260
+ }
261
+ const methodLines = renderMethods(node.methods ?? [], `${indent} `);
262
+ const skipLeadingBlank = methodLines.length && !hasProps;
263
+ lines.push(...skipLeadingBlank ? methodLines.slice(1) : methodLines);
264
+ return lines.join("\n");
265
+ }
266
+ function renderNamespace(node, { prefix = "", indent = "" } = {}) {
267
+ const heading = prefix ? `${prefix}.${node.name}` : node.name;
268
+ const lines = [];
269
+ lines.push(`${indent}${heading}`);
270
+ if (node.description) lines.push(`${indent} ${indentDesc(node.description, indent + " ")}`);
271
+ lines.push("");
272
+ lines.push(formatMembers(node.members, { prefix: heading, indent: `${indent} ` }));
273
+ return lines.join("\n");
274
+ }
275
+ function formatNode(node, { prefix = "", indent = "" } = {}) {
276
+ switch (node.kind) {
277
+ case "namespace":
278
+ return renderNamespace(node, { prefix, indent });
279
+ case "function":
280
+ return renderFunction(node, indent);
281
+ case "class":
282
+ case "interface":
283
+ return renderClassOrInterface(node, indent);
284
+ default:
285
+ return "";
286
+ }
287
+ }
288
+ function formatMembers(members, { prefix = "", indent = "" } = {}) {
289
+ return (members ?? []).map((m) => formatNode(m, { prefix, indent })).filter(Boolean).join("\n\n");
290
+ }
291
+
292
+ export {
293
+ walk,
294
+ formatNode,
295
+ formatMembers
296
+ };
@@ -0,0 +1,129 @@
1
+ import {
2
+ ensureProjectIdentity,
3
+ upsertProject
4
+ } from "./chunk-3TM6B4E5.js";
5
+ import {
6
+ getStorePath
7
+ } from "./chunk-HMU2J25D.js";
8
+ import {
9
+ init_require_shim
10
+ } from "./chunk-TPK5AGRA.js";
11
+
12
+ // src/job/registry.js
13
+ init_require_shim();
14
+ import { readFile, writeFile, mkdir, readdir, rm } from "node:fs/promises";
15
+ import { join } from "node:path";
16
+ import { randomUUID } from "node:crypto";
17
+ function jobsBase() {
18
+ return join(getStorePath(), "jobs");
19
+ }
20
+ function projectJobsDir(key) {
21
+ return join(jobsBase(), "project", key);
22
+ }
23
+ function jobPath(key, id) {
24
+ return join(projectJobsDir(key), `${id}.json`);
25
+ }
26
+ function jobStdoutPath(key, id) {
27
+ return join(projectJobsDir(key), `${id}.stdout.log`);
28
+ }
29
+ function jobStderrPath(key, id) {
30
+ return join(projectJobsDir(key), `${id}.stderr.log`);
31
+ }
32
+ async function updateJobPid(key, id, pid) {
33
+ const record = await getJob(key, id);
34
+ if (!record) return;
35
+ record.pid = pid;
36
+ await writeFile(jobPath(key, id), JSON.stringify(record, null, 2), "utf8");
37
+ }
38
+ async function createJob(pid, { type = "rune", spawnedBy, runeKey, projectDir, args = [] } = {}) {
39
+ const { id: key } = await ensureProjectIdentity(projectDir);
40
+ const id = randomUUID();
41
+ const record = { id, type, pid, startedAt: (/* @__PURE__ */ new Date()).toISOString(), projectKey: key, projectDir, spawnedBy, runeKey, args };
42
+ await mkdir(projectJobsDir(key), { recursive: true });
43
+ await writeFile(jobPath(key, id), JSON.stringify(record, null, 2), "utf8");
44
+ await upsertProject(key, projectDir);
45
+ return { id, projectKey: key };
46
+ }
47
+ async function getJob(key, id) {
48
+ try {
49
+ const raw = await readFile(jobPath(key, id), "utf8");
50
+ return JSON.parse(raw);
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+ async function listJobs(key) {
56
+ if (key) {
57
+ let files;
58
+ try {
59
+ files = await readdir(projectJobsDir(key));
60
+ } catch {
61
+ return [];
62
+ }
63
+ const records = await Promise.all(
64
+ files.filter((f) => f.endsWith(".json")).map((f) => getJob(key, f.slice(0, -5)))
65
+ );
66
+ return records.filter(Boolean);
67
+ }
68
+ let keys;
69
+ try {
70
+ keys = await readdir(join(jobsBase(), "project"));
71
+ } catch {
72
+ return [];
73
+ }
74
+ const all = await Promise.all(keys.map((k) => listJobs(k)));
75
+ return all.flat();
76
+ }
77
+ async function deleteJob(key, id) {
78
+ await rm(jobPath(key, id), { force: true });
79
+ }
80
+ async function cleanJobs(key) {
81
+ const dir = key ? projectJobsDir(key) : join(jobsBase(), "project");
82
+ let entries;
83
+ try {
84
+ entries = await readdir(dir);
85
+ } catch {
86
+ return;
87
+ }
88
+ if (key) {
89
+ await Promise.all(
90
+ entries.filter((f) => f.endsWith(".json")).map(async (f) => {
91
+ const id = f.slice(0, -5);
92
+ const record = await getJob(key, id);
93
+ if (!record) return;
94
+ if (!isAlive(record.pid)) await rm(jobPath(key, id), { force: true });
95
+ })
96
+ );
97
+ } else {
98
+ await Promise.all(entries.map((k) => cleanJobs(k)));
99
+ }
100
+ }
101
+ function resolveJobId(id, jobs) {
102
+ const exact = jobs.find((j) => j.id === id);
103
+ if (exact) return exact.id;
104
+ const matches = jobs.filter((j) => j.id.startsWith(id));
105
+ if (matches.length === 1) return matches[0].id;
106
+ if (matches.length === 0) throw new Error(`No job matching "${id}".`);
107
+ throw new Error(`Ambiguous id "${id}" \u2014 matches: ${matches.map((j) => j.id).join(", ")}.`);
108
+ }
109
+ function isAlive(pid) {
110
+ try {
111
+ process.kill(pid, 0);
112
+ return true;
113
+ } catch {
114
+ return false;
115
+ }
116
+ }
117
+
118
+ export {
119
+ jobStdoutPath,
120
+ jobStderrPath,
121
+ updateJobPid,
122
+ createJob,
123
+ getJob,
124
+ listJobs,
125
+ deleteJob,
126
+ cleanJobs,
127
+ resolveJobId,
128
+ isAlive
129
+ };
@@ -0,0 +1,281 @@
1
+ import {
2
+ require_micromatch,
3
+ runRune
4
+ } from "./chunk-QLDB3FO2.js";
5
+ import {
6
+ loadConfig
7
+ } from "./chunk-H3BVJCIL.js";
8
+ import {
9
+ isVerbose,
10
+ output
11
+ } from "./chunk-6XLT25GS.js";
12
+ import {
13
+ __toESM,
14
+ init_require_shim
15
+ } from "./chunk-TPK5AGRA.js";
16
+
17
+ // src/rune/commands/run.js
18
+ init_require_shim();
19
+
20
+ // src/shared/render.js
21
+ init_require_shim();
22
+ function render(data) {
23
+ if (!data) return null;
24
+ if (data.type === "tree") return renderTree(data.root);
25
+ if (data.type === "markdown") return data.content ?? null;
26
+ return null;
27
+ }
28
+ function renderSection(section) {
29
+ const parts = [];
30
+ if (section.title) {
31
+ parts.push(`## ${section.title}`);
32
+ } else if (section.name) {
33
+ parts.push(`## ${section.name}`);
34
+ } else {
35
+ parts.push("## (no title)");
36
+ }
37
+ if (section.attrs && Object.keys(section.attrs).length > 0) {
38
+ const attrStr = Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ");
39
+ parts.push(attrStr);
40
+ }
41
+ const content = render(section.data);
42
+ if (content) {
43
+ if (section.data?.type === "markdown") {
44
+ parts.push("```md\n" + content + "\n```");
45
+ } else {
46
+ parts.push(content);
47
+ }
48
+ }
49
+ return parts.filter(Boolean).join("\n") || null;
50
+ }
51
+ function renderTree(root) {
52
+ if (!root) return null;
53
+ const lines = [`${root.name.padEnd(12)}${root.description}`];
54
+ appendChildren(root.children ?? [], "", lines);
55
+ return lines.join("\n");
56
+ }
57
+ function appendChildren(children, prefix, lines) {
58
+ for (let i = 0; i < children.length; i++) {
59
+ const child = children[i];
60
+ const isLast = i === children.length - 1;
61
+ const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
62
+ const childPrefix = prefix + (isLast ? " " : "\u2502 ");
63
+ lines.push(`${prefix}${connector}${child.name.padEnd(12)}${child.description}`);
64
+ appendChildren(child.children ?? [], childPrefix, lines);
65
+ }
66
+ }
67
+
68
+ // src/rune/commands/run.js
69
+ var import_micromatch = __toESM(require_micromatch(), 1);
70
+ function parseSegment(argv) {
71
+ let sections = null;
72
+ let i = 0;
73
+ while (i < argv.length) {
74
+ const tok = argv[i];
75
+ if ((tok === "--section" || tok === "-s") && i + 1 < argv.length) {
76
+ sections = argv[i + 1].split(",").map((s) => s.trim()).filter(Boolean);
77
+ i += 2;
78
+ } else if (tok.startsWith("--section=")) {
79
+ sections = tok.slice(10).split(",").map((s) => s.trim()).filter(Boolean);
80
+ i++;
81
+ } else if (tok.startsWith("-s=")) {
82
+ sections = tok.slice(3).split(",").map((s) => s.trim()).filter(Boolean);
83
+ i++;
84
+ } else {
85
+ break;
86
+ }
87
+ }
88
+ const key = argv[i] ?? null;
89
+ if (key && key.startsWith("-")) {
90
+ output.error(`Unknown option or misplaced flag: "${key}"`);
91
+ output.info(`
92
+ Arguments must follow this strict structure:
93
+ 1. Global Flags (e.g., --cwd, --verbose)
94
+ 2. Command (e.g., use, check, bench)
95
+ 3. Command Flags (e.g., --format, -b)
96
+ 4. Rune Key (e.g., myrune)
97
+ 5. Rune Arguments (e.g., --strict, pos-arg)
98
+
99
+ Example: crunes --cwd ./dir use --format json myrune --strict
100
+ `.trimEnd());
101
+ process.exit(1);
102
+ }
103
+ const runeArgs = key !== null ? argv.slice(i + 1) : [];
104
+ return { key, sections, runeArgs };
105
+ }
106
+ function parseRunArgs(argv) {
107
+ let format = "text";
108
+ let failFast = false;
109
+ let allowBatch = false;
110
+ let i = 0;
111
+ while (i < argv.length) {
112
+ const tok = argv[i];
113
+ if (tok === "--format" && i + 1 < argv.length) {
114
+ format = argv[i + 1];
115
+ i += 2;
116
+ } else if (tok.startsWith("--format=")) {
117
+ format = tok.slice(9);
118
+ i++;
119
+ } else if (tok === "--fail-fast") {
120
+ failFast = true;
121
+ i++;
122
+ } else if (tok === "-b" || tok === "--batch") {
123
+ allowBatch = true;
124
+ i++;
125
+ } else {
126
+ break;
127
+ }
128
+ }
129
+ const rawSegments = [];
130
+ let current = [];
131
+ for (const tok of argv.slice(i)) {
132
+ if (allowBatch && tok === "+") {
133
+ rawSegments.push(current);
134
+ current = [];
135
+ } else {
136
+ current.push(tok);
137
+ }
138
+ }
139
+ rawSegments.push(current);
140
+ const segments = rawSegments.map(parseSegment);
141
+ return { segments, format, failFast };
142
+ }
143
+ async function handler({
144
+ segments,
145
+ format = "text",
146
+ failFast = false,
147
+ projectRoot = process.cwd(),
148
+ configRoot = projectRoot
149
+ }) {
150
+ for (const seg of segments) {
151
+ if (!seg.key) {
152
+ output.error("Missing required argument: <rune>");
153
+ process.exit(1);
154
+ }
155
+ }
156
+ let config;
157
+ try {
158
+ config = loadConfig(configRoot);
159
+ } catch (err) {
160
+ output.error(`Config unreadable: ${err.message}`);
161
+ output.info("Run `crunes init` to create a config file.");
162
+ process.exit(1);
163
+ }
164
+ let anyFailed = false;
165
+ for (let i = 0; i < segments.length; i++) {
166
+ const printedSections = /* @__PURE__ */ new Set();
167
+ const { key, sections: sectionFilter, runeArgs } = segments[i];
168
+ let sections;
169
+ try {
170
+ if (isVerbose) console.error(`[crunes:debug] Loading rune "${key}"`);
171
+ sections = await runRune(projectRoot, config, key, runeArgs, {
172
+ sections: sectionFilter,
173
+ configDir: configRoot,
174
+ instanceId: String(i + 1),
175
+ onEvent(event) {
176
+ const { type, message, section, instanceId: instanceId2, rune } = event;
177
+ const prefix = `[${instanceId2}:${rune}:${type}]`;
178
+ if (format === "jsonl") {
179
+ if (type === "section") {
180
+ if (sectionFilter && !import_micromatch.default.isMatch(section.name, sectionFilter)) {
181
+ return;
182
+ }
183
+ printedSections.add(section);
184
+ }
185
+ process.stdout.write(JSON.stringify({
186
+ type,
187
+ rune,
188
+ instance: instanceId2,
189
+ ...message != null ? { message } : {},
190
+ ...section != null ? { section } : {}
191
+ }) + "\n");
192
+ } else {
193
+ if (type === "section") {
194
+ if (!sectionFilter || import_micromatch.default.isMatch(section.name, sectionFilter)) {
195
+ const rendered = renderSection(section);
196
+ const lines = rendered ? rendered.split("\n") : [];
197
+ let contentStartIndex = 1;
198
+ let attrs = "";
199
+ if (lines[1] && lines[1].startsWith("[")) {
200
+ attrs = " " + lines[1];
201
+ contentStartIndex = 2;
202
+ }
203
+ const content = lines.slice(contentStartIndex).join("\n");
204
+ process.stdout.write(`${prefix} ${section.name}${attrs}
205
+ ${content}
206
+
207
+ `);
208
+ printedSections.add(section);
209
+ }
210
+ } else {
211
+ if (message && message.includes("\n")) {
212
+ process.stdout.write(`${prefix}
213
+ ${message}
214
+
215
+ `);
216
+ } else {
217
+ process.stdout.write(`${prefix} ${message ?? ""}
218
+ `);
219
+ }
220
+ }
221
+ }
222
+ }
223
+ });
224
+ if (isVerbose) console.error(`[crunes:debug] Rune "${key}" completed with ${sections?.length ?? 0} sections`);
225
+ } catch (err) {
226
+ const msg = isVerbose ? err.stack || err.message : err.message;
227
+ output.error(`Rune "${key}" failed:
228
+ ${msg}`);
229
+ anyFailed = true;
230
+ if (failFast) process.exit(1);
231
+ continue;
232
+ }
233
+ if (!sections) {
234
+ const available = Object.keys(config.runes ?? {}).join(", ") || "(none)";
235
+ output.error(`Unknown key: "${key}". Available: ${available}`);
236
+ anyFailed = true;
237
+ if (failFast) process.exit(1);
238
+ continue;
239
+ }
240
+ const filtered = sectionFilter ? sections.filter((s) => import_micromatch.default.isMatch(s.name, sectionFilter)) : sections;
241
+ const instanceId = String(i + 1);
242
+ for (const sect of filtered) {
243
+ const alreadyPrinted = Array.from(printedSections).some((p) => p.name === sect.name);
244
+ if (!alreadyPrinted) {
245
+ if (format === "jsonl") {
246
+ process.stdout.write(JSON.stringify({
247
+ type: "section",
248
+ rune: key,
249
+ instance: instanceId,
250
+ section: sect
251
+ }) + "\n");
252
+ } else {
253
+ const rendered = renderSection(sect);
254
+ if (rendered) {
255
+ const prefix = `[${instanceId}:${key}:section]`;
256
+ const lines = rendered.split("\n");
257
+ let contentStartIndex = 1;
258
+ let attrs = "";
259
+ if (lines[1] && lines[1].startsWith("[")) {
260
+ attrs = " " + lines[1];
261
+ contentStartIndex = 2;
262
+ }
263
+ const content = lines.slice(contentStartIndex).join("\n");
264
+ process.stdout.write(`${prefix} ${sect.name}${attrs}
265
+ ${content}
266
+
267
+ `);
268
+ }
269
+ }
270
+ printedSections.add(sect);
271
+ }
272
+ }
273
+ }
274
+ if (anyFailed) process.exit(1);
275
+ }
276
+
277
+ export {
278
+ parseSegment,
279
+ parseRunArgs,
280
+ handler
281
+ };