@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
package/README.md CHANGED
@@ -24,7 +24,7 @@ Install globally via `npm`:
24
24
  npm install -g @darkrymit/crunes-cli
25
25
  ```
26
26
 
27
- *Requires Node.js ≥ 20.*
27
+ *Requires Node.js ≥ 22.*
28
28
 
29
29
  ---
30
30
 
@@ -54,7 +54,7 @@ crunes run fetch-status
54
54
  crunes init # Create .crunes/config.json in current project
55
55
  crunes create [key] # Scaffold a new rune and register it in config
56
56
  crunes run <key> [args...] # Run a rune (use -b for batch execution)
57
- crunes check <key> # Execute a rune and validate its return schema
57
+ crunes repl <key> [args...] # Run a rune in interactive REPL mode
58
58
  crunes bench <key> # Profile execution time (fast/ok/slow)
59
59
  crunes list # List all registered local and plugin runes
60
60
 
@@ -81,9 +81,10 @@ crunes marketplace add <url> # Register a marketplace source
81
81
 
82
82
  Crunes features a fully dynamic documentation engine built directly into the CLI. Rather than keeping static, outdated markdown guides, you can compile up-to-date workspace handbooks containing precise types, active schemas, and active permissions:
83
83
 
84
- ### 1. Compile the Ecosystem & Workspace Handbook
85
- Generates a comprehensive `INTRO.md` containing sandboxed ESM recipes, permission tokens, active workspace settings, and current plugins:
84
+ ### 1. Compile the Ecosystem Handbook
85
+ Generates a comprehensive document covering anatomy, CLI conventions, configuration, API reference, and sandbox utilities:
86
86
  ```bash
87
+ crunes docs intro
87
88
  crunes docs intro --out INTRO.md
88
89
  ```
89
90
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  addMarketplace
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";
@@ -14,8 +14,8 @@ import "./chunk-WCODTMDN.js";
14
14
  import {
15
15
  loadRegistry,
16
16
  resolvePluginKey
17
- } from "./chunk-GHQOK4L7.js";
18
- import "./chunk-HMU2J25D.js";
17
+ } from "./chunk-65J65MAP.js";
18
+ import "./chunk-6MRZXASS.js";
19
19
  import {
20
20
  loadPluginJson
21
21
  } from "./chunk-G3U4V32O.js";
@@ -81,7 +81,8 @@ async function handler({
81
81
  name,
82
82
  description,
83
83
  yes = false,
84
- projectRoot = process.cwd()
84
+ projectRoot = process.cwd(),
85
+ configRoot
85
86
  } = {}) {
86
87
  const isNonInteractive = yes || !process.stdout.isTTY;
87
88
  let sourceName = null;
@@ -91,7 +92,7 @@ async function handler({
91
92
  sourceName = ref.slice(0, colonIdx);
92
93
  templateName = ref.slice(colonIdx + 1);
93
94
  }
94
- const resolved = await resolveTemplate(sourceName, templateName, projectRoot);
95
+ const resolved = await resolveTemplate(sourceName, templateName, configRoot ?? projectRoot);
95
96
  if (!resolved) {
96
97
  output.error(`Template "${templateName}" not found. Run: crunes template list`);
97
98
  process.exit(1);
@@ -151,7 +152,7 @@ async function handler({
151
152
  await fs.copyFile(srcPath, runeAbsPath);
152
153
  templateMeta = resolved.templateMeta;
153
154
  }
154
- const configPath = path.join(projectRoot, ".crunes", "config.json");
155
+ const configPath = path.join(configRoot ?? projectRoot, ".crunes", "config.json");
155
156
  let config = { runes: {} };
156
157
  try {
157
158
  config = JSON.parse(await fs.readFile(configPath, "utf8"));
@@ -0,0 +1,81 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/docs/commands/args-repl.js
6
+ init_require_shim();
7
+ async function handler() {
8
+ process.stdout.write(`# Docs: The argsRepl(builder) Export
9
+
10
+ Runes declare REPL-specific options using \`export function argsRepl(builder)\`. This schema is parsed **once at session start** and the result is passed as \`args\` to every \`repl(args)\` call.
11
+
12
+ ## 1. Independence from \`args()\`
13
+
14
+ \`argsRepl()\` is **completely independent** from \`args()\`. It does NOT fall back to \`args()\` if absent. The two lifecycles have separate schemas:
15
+
16
+ \`\`\`js
17
+ export function args(b) {
18
+ // Schema for: crunes run my-shell "SELECT * FROM t"
19
+ return b
20
+ .option('--db <path>', 'Database path', './state')
21
+ .positional('<query>', 'SQL query to execute')
22
+ .build()
23
+ }
24
+
25
+ export function argsRepl(b) {
26
+ // Schema for: crunes repl my-shell --db ./other
27
+ // No <query> positional \u2014 input arrives line-by-line via repl
28
+ return b
29
+ .option('--db <path>', 'Database path', './state')
30
+ .build()
31
+ }
32
+ \`\`\`
33
+
34
+ If \`argsRepl()\` is absent, \`repl(args)\` receives \`args = {}\`.
35
+
36
+ ## 2. Builder Methods Reference
37
+
38
+ Same API as \`args()\` \u2014 see \`crunes docs args\` for the full reference:
39
+
40
+ - **\`.option(flags, description, defaultValue?)\`** \u2014 declares a named flag
41
+ - **\`.positional(spec, description)\`** \u2014 declares a positional argument
42
+ - **\`.example(usage, description)\`** \u2014 adds a usage example
43
+ - **\`.command(name, description, callback?)\`** \u2014 declares a nested subcommand
44
+ - **\`.build()\`** \u2014 finalizes the schema (called implicitly if you return the builder)
45
+
46
+ ## 3. When to Use \`argsRepl()\`
47
+
48
+ Use it when your REPL session needs startup configuration \u2014 a path, a target, a mode \u2014 that is provided once when the session starts and then available on every \`repl(args)\` call:
49
+
50
+ \`\`\`js
51
+ export function argsRepl(b) {
52
+ return b
53
+ .option('--db <path>', 'SQLite database directory', './state')
54
+ .option('--read-only', 'Open in read-only mode', false)
55
+ .example('crunes repl my-shell --db ./prod', 'Open prod database interactively')
56
+ .build()
57
+ }
58
+
59
+ let db = null
60
+
61
+ export async function repl(args) {
62
+ db = await sqlite.open(args.db, 'main')
63
+ // args.readOnly is available for the session
64
+ }
65
+ \`\`\`
66
+
67
+ ## 4. Sandbox Extraction & Implicit Build
68
+
69
+ Same behavior as \`args()\` \u2014 the builder runs inside a V8 isolate and \`.build()\` is called automatically. Returning the builder chain directly works:
70
+
71
+ \`\`\`js
72
+ export function argsRepl(b) {
73
+ return b.option('--db <path>', 'Database path', './state') // implicitly built
74
+ }
75
+ \`\`\`
76
+
77
+ `);
78
+ }
79
+ export {
80
+ handler
81
+ };
@@ -0,0 +1,52 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/docs/commands/banner-repl.js
6
+ init_require_shim();
7
+ async function handler() {
8
+ process.stdout.write(`# Docs: The bannerRepl(args) Export
9
+
10
+ \`export function bannerRepl(args)\` prints a welcome message before the first prompt. It is called once after \`repl()\` resolves, so it can reference module-level state set up during initialization.
11
+
12
+ ## 1. When It Is Called
13
+
14
+ Lifecycle order at session start:
15
+
16
+ 1. \`argsRepl(builder)\` \u2014 schema extracted (once, before startup)
17
+ 2. \`repl(args)\` \u2014 session initializer (open connections, set state)
18
+ 3. \`bannerRepl(args)\` \u2014 banner captured and printed to stderr
19
+ 4. First prompt shown
20
+
21
+ ## 2. Return Value
22
+
23
+ Return a \`string\` to print it. Return \`undefined\` or \`void\` to show no banner.
24
+
25
+ In text mode the string is written to **stderr** (so it doesn't pollute stdout section output).
26
+ In JSONL mode it is emitted as \`{ type: "banner", message: "..." }\`.
27
+
28
+ ## 3. Example
29
+
30
+ \`\`\`js
31
+ let replDb = null
32
+
33
+ export async function repl(args) {
34
+ replDb = await sqlite.open(args.db, 'books')
35
+ return 'sqlite> '
36
+ }
37
+
38
+ export function bannerRepl(args) {
39
+ // replDb is already open \u2014 can reference module-level state
40
+ return \`Connected to \${args.db}/books.db \u2014 /help for commands, Ctrl+D to quit\`
41
+ }
42
+ \`\`\`
43
+
44
+ ## 4. Absence
45
+
46
+ If \`bannerRepl\` is not exported, no banner is shown and no error is raised.
47
+
48
+ `);
49
+ }
50
+ export {
51
+ handler
52
+ };
@@ -0,0 +1,234 @@
1
+ import {
2
+ parseBracketKey
3
+ } from "./chunk-DZJRYFOP.js";
4
+ import {
5
+ loadConfig
6
+ } from "./chunk-H3BVJCIL.js";
7
+ import {
8
+ runRune
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 "./chunk-ASZKAC24.js";
16
+ import {
17
+ output
18
+ } from "./chunk-6XLT25GS.js";
19
+ import {
20
+ source_default
21
+ } from "./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/rune/commands/benchmark.js
30
+ init_require_shim();
31
+ import { performance } from "node:perf_hooks";
32
+ var FAST_MS = 200;
33
+ var SLOW_MS = 1e3;
34
+ var BAR_WIDTH = 10;
35
+ function label(ms) {
36
+ if (ms >= SLOW_MS) return "slow";
37
+ if (ms >= FAST_MS) return "ok";
38
+ return "fast";
39
+ }
40
+ function bar(ms, plain) {
41
+ const ratio = Math.min(ms / SLOW_MS, 1);
42
+ const filled = Math.round(ratio * BAR_WIDTH);
43
+ const empty = BAR_WIDTH - filled;
44
+ const fill = "\u2588".repeat(filled) + "\u2591".repeat(empty);
45
+ if (plain) return fill;
46
+ if (ms >= SLOW_MS) return source_default.red(fill);
47
+ if (ms >= FAST_MS) return source_default.yellow(fill);
48
+ return source_default.green(fill);
49
+ }
50
+ function labelColour(l, plain) {
51
+ if (plain) return l;
52
+ if (l === "slow") return source_default.red(l);
53
+ if (l === "ok") return source_default.yellow(l);
54
+ return source_default.green(l);
55
+ }
56
+ function parseBenchArgs(argv) {
57
+ let globalRuns = 1;
58
+ let globalWarmup = false;
59
+ let allowBatch = false;
60
+ let failFast = false;
61
+ let format = "text";
62
+ let i = 0;
63
+ while (i < argv.length) {
64
+ const tok = argv[i];
65
+ if (tok === "--runs" && i + 1 < argv.length) {
66
+ globalRuns = parseInt(argv[i + 1], 10);
67
+ i += 2;
68
+ } else if (tok.startsWith("--runs=")) {
69
+ globalRuns = parseInt(tok.slice(7), 10);
70
+ i++;
71
+ } else if (tok === "--warmup") {
72
+ globalWarmup = true;
73
+ i++;
74
+ } else if (tok === "-b" || tok === "--batch") {
75
+ allowBatch = true;
76
+ i++;
77
+ } else if (tok === "--fail-fast") {
78
+ failFast = true;
79
+ i++;
80
+ } else if (tok === "--format" && i + 1 < argv.length) {
81
+ format = argv[i + 1];
82
+ i += 2;
83
+ } else if (tok.startsWith("--format=")) {
84
+ format = tok.slice(9);
85
+ i++;
86
+ } else {
87
+ break;
88
+ }
89
+ }
90
+ const rawSegments = [];
91
+ let current = [];
92
+ for (const tok of argv.slice(i)) {
93
+ if (allowBatch && tok === "+") {
94
+ rawSegments.push(current);
95
+ current = [];
96
+ } else {
97
+ current.push(tok);
98
+ }
99
+ }
100
+ rawSegments.push(current);
101
+ const segments = rawSegments.map((seg) => {
102
+ const { key, bracketArgs } = parseBracketKey(seg[0] ?? "");
103
+ let runs = globalRuns;
104
+ let warmup = globalWarmup;
105
+ let sections = null;
106
+ let j = 0;
107
+ while (j < bracketArgs.length) {
108
+ const tok = bracketArgs[j];
109
+ if (tok === "--runs" && j + 1 < bracketArgs.length) {
110
+ runs = parseInt(bracketArgs[j + 1], 10);
111
+ j += 2;
112
+ } else if (tok.startsWith("--runs=")) {
113
+ runs = parseInt(tok.slice(7), 10);
114
+ j++;
115
+ } else if (tok === "--warmup") {
116
+ warmup = true;
117
+ j++;
118
+ } else if ((tok === "--section" || tok === "-s") && j + 1 < bracketArgs.length) {
119
+ sections = bracketArgs[j + 1].split(",").map((s) => s.trim()).filter(Boolean);
120
+ j += 2;
121
+ } else if (tok.startsWith("--section=")) {
122
+ sections = tok.slice(10).split(",").map((s) => s.trim()).filter(Boolean);
123
+ j++;
124
+ } else if (tok.startsWith("-s=")) {
125
+ sections = tok.slice(3).split(",").map((s) => s.trim()).filter(Boolean);
126
+ j++;
127
+ } else {
128
+ j++;
129
+ }
130
+ }
131
+ return { key: key || null, runs, warmup, sections, runeArgs: seg.slice(1) };
132
+ });
133
+ return { segments, format, failFast, isBatch: allowBatch, globalRuns, globalWarmup };
134
+ }
135
+ async function handler({
136
+ segments,
137
+ key,
138
+ runeArgs = [],
139
+ runs: legacyRuns,
140
+ warmup: legacyWarmup,
141
+ format: _format = "text",
142
+ failFast = false,
143
+ isBatch: _isBatch = false,
144
+ plain = false,
145
+ projectRoot = process.cwd(),
146
+ configRoot = projectRoot
147
+ } = {}) {
148
+ const resolvedSegments = segments ?? [{ key, runeArgs, runs: legacyRuns ?? 1, warmup: legacyWarmup ?? false, sections: null }];
149
+ const firstKey = resolvedSegments[0]?.key;
150
+ if (!firstKey) {
151
+ output.error("Missing required argument: <rune>");
152
+ process.exit(1);
153
+ }
154
+ for (const seg of resolvedSegments) {
155
+ if (!Number.isInteger(seg.runs) || seg.runs < 1) {
156
+ output.error("Invalid option: --runs must be a positive integer >= 1");
157
+ process.exit(1);
158
+ }
159
+ }
160
+ let config;
161
+ try {
162
+ config = loadConfig(configRoot);
163
+ } catch (err) {
164
+ output.error(`Config unreadable: ${err.message}`);
165
+ output.info("Run `crunes init` to create a config file.");
166
+ process.exit(1);
167
+ }
168
+ if (!plain) {
169
+ console.log(source_default.dim("\u2500".repeat(40)));
170
+ console.log(source_default.bold("crunes benchmark"));
171
+ console.log();
172
+ }
173
+ const maxKeyLen = Math.max(...resolvedSegments.map((s) => (s.key ?? "").length));
174
+ let total = 0;
175
+ let slowCount = 0;
176
+ for (const seg of resolvedSegments) {
177
+ const { key: segKey, runeArgs: segArgs, runs, warmup } = seg;
178
+ const times = [];
179
+ let err = null;
180
+ if (warmup) {
181
+ try {
182
+ await runRune(projectRoot, config, segKey, segArgs, { configDir: configRoot });
183
+ } catch {
184
+ }
185
+ }
186
+ for (let i = 0; i < runs; i++) {
187
+ const t0 = performance.now();
188
+ try {
189
+ await runRune(projectRoot, config, segKey, segArgs, { configDir: configRoot });
190
+ } catch (e) {
191
+ err = e;
192
+ break;
193
+ }
194
+ times.push(performance.now() - t0);
195
+ }
196
+ if (err) {
197
+ if (plain) {
198
+ process.stdout.write(`${segKey} error ${err.message}
199
+ `);
200
+ } else {
201
+ console.log(` ${source_default.dim(segKey.padEnd(maxKeyLen))} ${source_default.red("error")} ${source_default.dim(err.message)}`);
202
+ }
203
+ if (failFast) process.exit(1);
204
+ } else {
205
+ const avg = Math.round(times.reduce((a, b) => a + b, 0) / times.length);
206
+ const l = label(avg);
207
+ if (l === "slow") slowCount++;
208
+ total += avg;
209
+ if (plain) {
210
+ process.stdout.write(`${segKey} ${avg} ${l}
211
+ `);
212
+ } else {
213
+ const k = segKey.padEnd(maxKeyLen);
214
+ const warn = l === "slow" ? ` ${source_default.yellow("\u26A0")}` : "";
215
+ console.log(` ${source_default.cyan(k)} ${String(avg).padStart(6)}ms ${bar(avg, plain)} ${labelColour(l, plain)}${warn}`);
216
+ }
217
+ }
218
+ }
219
+ if (plain) {
220
+ process.stdout.write(`total ${total}
221
+ slow-count ${slowCount}
222
+ `);
223
+ } else {
224
+ console.log();
225
+ const slowMsg = slowCount > 0 ? ` ${source_default.yellow("\u26A0")} ${slowCount} slow rune${slowCount > 1 ? "s" : ""} (> ${SLOW_MS}ms)` : ` ${source_default.green("\u2713")} All runes within acceptable range`;
226
+ console.log(` ${source_default.dim("Total:")} ${total}ms`);
227
+ console.log(slowMsg);
228
+ console.log();
229
+ }
230
+ }
231
+ export {
232
+ handler,
233
+ parseBenchArgs
234
+ };
@@ -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";
@@ -7,12 +7,12 @@ import {
7
7
  loadRegistry,
8
8
  registerPlugin,
9
9
  removePlugin
10
- } from "./chunk-GHQOK4L7.js";
10
+ } from "./chunk-65J65MAP.js";
11
11
  import {
12
12
  ensureStoreDirs,
13
13
  getPluginCacheDir,
14
14
  getPnpmStorePath
15
- } from "./chunk-HMU2J25D.js";
15
+ } from "./chunk-6MRZXASS.js";
16
16
  import {
17
17
  loadPluginJson
18
18
  } from "./chunk-G3U4V32O.js";
@@ -0,0 +1,101 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/rune/schema-cache.js
6
+ init_require_shim();
7
+ import { readFile, writeFile, mkdir, readdir, rm, rename } from "node:fs/promises";
8
+ import { createHash, randomBytes } from "node:crypto";
9
+ import { join } from "node:path";
10
+ var TYPES = ["args", "argsRepl", "commandsRepl"];
11
+ function safeKey(runeKey) {
12
+ return runeKey.replace(/:/g, "__");
13
+ }
14
+ function schemasDir(projectDir) {
15
+ return join(projectDir, ".crunes", "schemas");
16
+ }
17
+ function cacheFilePath(runeKey, type, projectDir) {
18
+ return join(schemasDir(projectDir), `${safeKey(runeKey)}-${type}.json`);
19
+ }
20
+ async function computeHash(runeFile, vars) {
21
+ const content = await readFile(runeFile, "utf8");
22
+ const sortedVars = Object.fromEntries(Object.entries(vars).sort(([a], [b]) => a.localeCompare(b)));
23
+ const contentHash = createHash("sha256").update(content).digest("hex");
24
+ const varsHash = createHash("sha256").update(JSON.stringify(sortedVars)).digest("hex");
25
+ return `${contentHash}:${varsHash}`;
26
+ }
27
+ async function readSchemaCache(runeKey, type, runeFile, vars, projectDir) {
28
+ const filePath = cacheFilePath(runeKey, type, projectDir);
29
+ let raw;
30
+ try {
31
+ raw = await readFile(filePath, "utf8");
32
+ } catch {
33
+ return void 0;
34
+ }
35
+ let entry;
36
+ try {
37
+ entry = JSON.parse(raw);
38
+ } catch {
39
+ return void 0;
40
+ }
41
+ const hash = await computeHash(runeFile, vars);
42
+ if (entry.hash !== hash) return void 0;
43
+ return entry.schema;
44
+ }
45
+ async function writeSchemaCache(runeKey, type, runeFile, vars, schema, projectDir) {
46
+ const dir = schemasDir(projectDir);
47
+ await mkdir(dir, { recursive: true });
48
+ const hash = await computeHash(runeFile, vars);
49
+ const entry = {
50
+ runeKey,
51
+ hash,
52
+ cachedAt: (/* @__PURE__ */ new Date()).toISOString(),
53
+ schema
54
+ };
55
+ const filePath = cacheFilePath(runeKey, type, projectDir);
56
+ const tmp = join(dir, `.tmp-${randomBytes(6).toString("hex")}.json`);
57
+ await writeFile(tmp, JSON.stringify(entry, null, 2), "utf8");
58
+ await rename(tmp, filePath);
59
+ }
60
+ async function listSchemaCaches(projectDir) {
61
+ const dir = schemasDir(projectDir);
62
+ let files;
63
+ try {
64
+ files = await readdir(dir);
65
+ } catch {
66
+ return [];
67
+ }
68
+ const results = [];
69
+ for (const file of files) {
70
+ if (!file.endsWith(".json") || file.startsWith(".tmp-")) continue;
71
+ const filePath = join(dir, file);
72
+ try {
73
+ const entry = JSON.parse(await readFile(filePath, "utf8"));
74
+ const match = file.match(/^(.+)-(args|argsRepl|commandsRepl)\.json$/);
75
+ if (!match) continue;
76
+ results.push({
77
+ runeKey: entry.runeKey ?? match[1].replace(/__/g, ":"),
78
+ type: match[2],
79
+ hash: entry.hash,
80
+ cachedAt: entry.cachedAt,
81
+ filePath
82
+ });
83
+ } catch {
84
+ }
85
+ }
86
+ return results;
87
+ }
88
+ async function deleteSchemaCache(runeKey, projectDir) {
89
+ await Promise.all(
90
+ TYPES.map(
91
+ (type) => rm(cacheFilePath(runeKey, type, projectDir), { force: true })
92
+ )
93
+ );
94
+ }
95
+
96
+ export {
97
+ readSchemaCache,
98
+ writeSchemaCache,
99
+ listSchemaCaches,
100
+ deleteSchemaCache
101
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getPluginsJsonPath
3
- } from "./chunk-HMU2J25D.js";
3
+ } from "./chunk-6MRZXASS.js";
4
4
  import {
5
5
  init_require_shim
6
6
  } from "./chunk-TPK5AGRA.js";
@@ -28,8 +28,8 @@ function getMarketplacesJsonPath() {
28
28
  function getMarketplaceCacheDir(name) {
29
29
  return path.join(getStorePath(), "marketplaces", name);
30
30
  }
31
- function getCachesBasePath() {
32
- return path.join(getStorePath(), "caches");
31
+ function getCacheBasePath() {
32
+ return path.join(getStorePath(), "cache");
33
33
  }
34
34
  function getSqliteBasePath() {
35
35
  return path.join(getStorePath(), "sqlite");
@@ -55,7 +55,7 @@ export {
55
55
  getPnpmStorePath,
56
56
  getMarketplacesJsonPath,
57
57
  getMarketplaceCacheDir,
58
- getCachesBasePath,
58
+ getCacheBasePath,
59
59
  getSqliteBasePath,
60
60
  getCacheJsonPath,
61
61
  getSqliteJsonPath,
@@ -13,6 +13,13 @@ function formatCommands(commands, depth = 0) {
13
13
  const posSpecs = (cmd.positionals ?? []).map((p) => p.spec).join(" ");
14
14
  const cmdStr = `${cmd.name}${posSpecs ? " " + posSpecs : ""}`;
15
15
  lines.push(`${indent}${cmdStr.padEnd(30 - depth * 2)} ${cmd.description ?? ""}`.trimEnd());
16
+ const cmdPos = cmd.positionals ?? [];
17
+ if (cmdPos.length > 0) {
18
+ lines.push(`${childIndent}Positionals:`);
19
+ for (const p of cmdPos) {
20
+ lines.push(`${detailIndent}${p.spec.padEnd(26)} ${p.description ?? ""}`.trimEnd());
21
+ }
22
+ }
16
23
  const cmdOpts = cmd.options ?? [];
17
24
  if (cmdOpts.length > 0) {
18
25
  lines.push(`${childIndent}Options:`);
@@ -47,7 +54,8 @@ function formatHelp(schema, runeMeta) {
47
54
  lines.push("");
48
55
  }
49
56
  const hasCommands = (schema?.commands ?? []).length > 0;
50
- lines.push(`Usage: crunes run ${key} ${hasCommands ? "<command> " : ""}[options]`);
57
+ const cmd = runeMeta?.lifecycle === "repl" ? "repl" : "run";
58
+ lines.push(`Usage: crunes ${cmd} ${key} ${hasCommands ? "<command> " : ""}[options]`);
51
59
  if (desc) {
52
60
  lines.push("");
53
61
  lines.push(` ${desc}`);