@darkrymit/crunes-cli 0.8.5 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/chunks/{add-CBHWFGCA.js → add-IT3IHBPO.js} +2 -2
  2. package/dist/chunks/add-MSX6XSU3.js +68 -0
  3. package/dist/chunks/{apply-J4YICV6H.js → apply-LOIJIPLR.js} +21 -12
  4. package/dist/chunks/{benchmark-AKKV7G32.js → benchmark-3IHFP3V2.js} +27 -18
  5. package/dist/chunks/{browse-JZFU52ET.js → browse-PHMBDREQ.js} +2 -2
  6. package/dist/chunks/chunk-2DNYVKBF.js +109 -0
  7. package/dist/chunks/chunk-2FI6KN3C.js +283 -0
  8. package/dist/chunks/chunk-2HM5Q52B.js +131 -0
  9. package/dist/chunks/{chunk-6MRZXASS.js → chunk-2Q3KLBE6.js} +16 -0
  10. package/dist/chunks/{chunk-ZJDKCC2Y.js → chunk-4GJMCFR6.js} +6 -3
  11. package/dist/chunks/chunk-55GTJG5I.js +1154 -0
  12. package/dist/chunks/chunk-6IC6ZJ74.js +9525 -0
  13. package/dist/chunks/chunk-7KYCYDAS.js +325 -0
  14. package/dist/chunks/chunk-DTOYFY3Z.js +578 -0
  15. package/dist/chunks/chunk-EO3CSXWK.js +70 -0
  16. package/dist/chunks/chunk-FIAFVIAN.js +79 -0
  17. package/dist/chunks/{chunk-J3GZ3DXD.js → chunk-GVMT55GH.js} +3 -2
  18. package/dist/chunks/chunk-H2OT7D6N.js +303 -0
  19. package/dist/chunks/{chunk-JOAL437H.js → chunk-I6MHDUCW.js} +16 -1
  20. package/dist/chunks/chunk-KSQDFE5N.js +85 -0
  21. package/dist/chunks/{chunk-BTIPUR5S.js → chunk-KUEMDPNG.js} +108 -91
  22. package/dist/chunks/{chunk-6XLT25GS.js → chunk-MIKWIFYR.js} +47 -0
  23. package/dist/chunks/{chunk-GTCPZ22N.js → chunk-MTJ2KW3V.js} +3 -1
  24. package/dist/chunks/chunk-MVCBPI4J.js +2354 -0
  25. package/dist/chunks/{chunk-T53L5CJW.js → chunk-PBGUKXT6.js} +2887 -1874
  26. package/dist/chunks/{chunk-KII6KW5Z.js → chunk-RVBAAXRY.js} +64 -44
  27. package/dist/chunks/chunk-SUCYDYMU.js +44 -0
  28. package/dist/chunks/chunk-UBCAZGLE.js +15 -0
  29. package/dist/chunks/{chunk-63H5VXZY.js → chunk-UEUUOAJY.js} +4 -1
  30. package/dist/chunks/chunk-VP7YLCQP.js +244 -0
  31. package/dist/chunks/{chunk-NDEYEYSU.js → chunk-WJII3LZK.js} +4 -3
  32. package/dist/chunks/chunk-XDMMSZIL.js +71 -0
  33. package/dist/chunks/chunk-YKIKJHYO.js +94 -0
  34. package/dist/chunks/{chunk-NYLRTAAA.js → chunk-YVN3VDRE.js} +1 -1
  35. package/dist/chunks/{clear-YBDIPEEH.js → clear-AT7HNUV4.js} +2 -2
  36. package/dist/chunks/{create-L6DJN4ME.js → create-DXW4YYLJ.js} +8 -8
  37. package/dist/chunks/create-LPLNCOW4.js +268 -0
  38. package/dist/chunks/{create-GPDE2YKL.js → create-Y4LHLWGL.js} +26 -18
  39. package/dist/chunks/{delete-LNOYM5KG.js → delete-2EXPFBFC.js} +2 -2
  40. package/dist/chunks/{delete-E4TEBRPX.js → delete-GKYA2W5Z.js} +4 -2
  41. package/dist/chunks/{delete-C4UJ7X5K.js → delete-MJAECXXV.js} +2 -2
  42. package/dist/chunks/disable-TITOSMXB.js +43 -0
  43. package/dist/chunks/doctor-R2Y6UAY4.js +208 -0
  44. package/dist/chunks/enable-LGTPDWPV.js +35 -0
  45. package/dist/chunks/{globals-H2WF344Y.js → globals-SNQFCHMP.js} +1 -1
  46. package/dist/chunks/{init-HU5OMHEH.js → init-KO2HLED5.js} +18 -8
  47. package/dist/chunks/install-7IRUAGSF.js +64 -0
  48. package/dist/chunks/{intro-36OLGNYN.js → intro-JNJ6A75J.js} +89 -21
  49. package/dist/chunks/{kill-2UG7PHUV.js → kill-TX3PC73P.js} +2 -1
  50. package/dist/chunks/{list-2JYMBMZC.js → list-BCCM3TLP.js} +12 -7
  51. package/dist/chunks/{list-4X3JFQGS.js → list-EHREZR6M.js} +2 -1
  52. package/dist/chunks/{list-U7PAYNAH.js → list-LC6HB3H3.js} +2 -2
  53. package/dist/chunks/list-MLKZE36K.js +92 -0
  54. package/dist/chunks/list-QVZKR3IE.js +62 -0
  55. package/dist/chunks/{list-7VHJIUDX.js → list-U4EMHQZT.js} +2 -2
  56. package/dist/chunks/{list-PTAWQYWG.js → list-V7VVD5AG.js} +2 -1
  57. package/dist/chunks/{list-A5WVDBWF.js → list-VA73WPK6.js} +2 -2
  58. package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
  59. package/dist/chunks/migrate-Y3EKMVP5.js +87 -0
  60. package/dist/chunks/{output-RJ6JSNY7.js → output-QN5CVJ62.js} +4 -1
  61. package/dist/chunks/{query-AW7WYILM.js → query-2US3CPYT.js} +2 -2
  62. package/dist/chunks/{registry-RG34DPD7.js → registry-IWP7JMNI.js} +2 -2
  63. package/dist/chunks/{remove-QUH2D3S5.js → remove-BCFTF23J.js} +2 -2
  64. package/dist/chunks/{repl-STBZC4P2.js → repl-2YWTHUWT.js} +4 -0
  65. package/dist/chunks/{repl-BPEWARN7.js → repl-5GDN3RAO.js} +99 -31
  66. package/dist/chunks/resolver-CA2A32AC.js +36 -0
  67. package/dist/chunks/run-WL3IZBXF.js +35 -0
  68. package/dist/chunks/rune-YA4TFHTB.js +283 -0
  69. package/dist/chunks/runner-QNZMBHQY.js +34 -0
  70. package/dist/chunks/{search-MSSDGJTF.js → search-B7IM7JRJ.js} +2 -2
  71. package/dist/chunks/shell-explain-LKBBP2BG.js +77 -0
  72. package/dist/chunks/trust-BFIDANXD.js +109 -0
  73. package/dist/chunks/uninstall-3MWZIZVA.js +58 -0
  74. package/dist/chunks/{unset-YASSMSE5.js → unset-P6IUF7SS.js} +2 -2
  75. package/dist/chunks/{update-KSC6VRMU.js → update-W4MJUTTW.js} +25 -19
  76. package/dist/chunks/{update-EWWDROKW.js → update-WXT7CHYA.js} +2 -2
  77. package/dist/chunks/{utils-3SJFSUSV.js → utils-B2QULX5J.js} +8 -4
  78. package/dist/chunks/{version-YG2M7HER.js → version-FLHI5KFS.js} +3 -3
  79. package/dist/cli.js +115 -70
  80. package/package.json +2 -2
  81. package/dist/chunks/chunk-ASZKAC24.js +0 -103
  82. package/dist/chunks/chunk-G3U4V32O.js +0 -46
  83. package/dist/chunks/chunk-GSA432UC.js +0 -90
  84. package/dist/chunks/chunk-WJRZN7BR.js +0 -77492
  85. package/dist/chunks/create-VYZRWRGQ.js +0 -170
  86. package/dist/chunks/disable-FGJ7VMPO.js +0 -47
  87. package/dist/chunks/doctor-7NWBJAH7.js +0 -53
  88. package/dist/chunks/enable-ZL6QOC2I.js +0 -47
  89. package/dist/chunks/install-FIYRMVLR.js +0 -57
  90. package/dist/chunks/list-AIYNOPNZ.js +0 -28
  91. package/dist/chunks/list-NZ5DHXJF.js +0 -111
  92. package/dist/chunks/resolver-36V72VKR.js +0 -28
  93. package/dist/chunks/run-IVL23SMW.js +0 -26
  94. package/dist/chunks/rune-XRREUL56.js +0 -186
  95. package/dist/chunks/uninstall-G56DZRFG.js +0 -49
@@ -1,21 +1,39 @@
1
1
  import {
2
- Ce,
2
+ getConfigPath,
3
+ readRawConfig,
4
+ setPluginEnabled,
5
+ writeRawConfig
6
+ } from "./chunk-SUCYDYMU.js";
7
+ import {
8
+ output
9
+ } from "./chunk-MIKWIFYR.js";
10
+ import {
3
11
  R,
4
12
  le
5
13
  } from "./chunk-CGZL5SSH.js";
14
+ import {
15
+ isNativeRune
16
+ } from "./chunk-XDMMSZIL.js";
17
+ import {
18
+ coercePlugins
19
+ } from "./chunk-2FI6KN3C.js";
6
20
  import {
7
21
  loadRegistry,
8
22
  registerPlugin,
9
23
  removePlugin
10
- } from "./chunk-GTCPZ22N.js";
24
+ } from "./chunk-MTJ2KW3V.js";
25
+ import {
26
+ loadPluginJson
27
+ } from "./chunk-FIAFVIAN.js";
28
+ import {
29
+ blockOf,
30
+ scopedPermissions
31
+ } from "./chunk-YKIKJHYO.js";
11
32
  import {
12
33
  ensureStoreDirs,
13
34
  getPluginCacheDir,
14
35
  getPnpmStorePath
15
- } from "./chunk-6MRZXASS.js";
16
- import {
17
- loadPluginJson
18
- } from "./chunk-G3U4V32O.js";
36
+ } from "./chunk-2Q3KLBE6.js";
19
37
  import {
20
38
  init_require_shim
21
39
  } from "./chunk-TPK5AGRA.js";
@@ -130,20 +148,30 @@ function formatConsentScreen(pluginName, pluginJson) {
130
148
  const lines = [`${pluginName} requests the following permissions:
131
149
  `];
132
150
  for (const [runeKey, rune] of Object.entries(pluginJson.runes)) {
133
- const allow = collectAllow(rune.permissions);
151
+ const allow = collectAllow(scopedPermissions(rune));
134
152
  if (allow.length === 0) continue;
135
153
  lines.push(` ${runeKey}`);
136
154
  for (const perm of allow) {
137
- lines.push(` ${perm}`);
155
+ if (perm === "*" || perm === "*:*") {
156
+ lines.push(` * (UNRESTRICTED: allows all filesystem, shell, network, and environment operations)`);
157
+ } else {
158
+ lines.push(` ${perm}`);
159
+ }
138
160
  }
139
161
  lines.push("");
140
162
  }
163
+ const natives = Object.entries(pluginJson.runes).filter(([, rune]) => isNativeRune(rune));
164
+ if (natives.length) {
165
+ lines.push("Native runes \u2014 these run outside the sandbox, with your full access:\n");
166
+ for (const [runeKey, rune] of natives) lines.push(` ${runeKey} runs ${blockOf(rune, "run").command}`);
167
+ lines.push("", `They will not run until you review and trust them: crunes plugin trust ${pluginName}`, "");
168
+ }
141
169
  return lines.join("\n");
142
170
  }
143
171
  async function promptConsent(pluginName, pluginJson, { yes = false } = {}) {
144
172
  const isYes = yes || !process.stdout.isTTY;
145
173
  if (isYes) return true;
146
- Ce(formatConsentScreen(pluginName, pluginJson), "Permissions requested");
174
+ output.note(formatConsentScreen(pluginName, pluginJson), "Permissions requested");
147
175
  const answer = await le({ message: "Allow these permissions?" });
148
176
  if (R(answer)) return false;
149
177
  return answer === true;
@@ -151,7 +179,7 @@ async function promptConsent(pluginName, pluginJson, { yes = false } = {}) {
151
179
  function diffPermissions(oldConsented, newPluginJson) {
152
180
  const added = {};
153
181
  for (const [runeKey, rune] of Object.entries(newPluginJson.runes)) {
154
- const newPerms = collectAllow(rune.permissions);
182
+ const newPerms = collectAllow(scopedPermissions(rune));
155
183
  const oldPerms = oldConsented[runeKey] ?? [];
156
184
  const newOnes = newPerms.filter((perm) => !oldPerms.includes(perm));
157
185
  if (newOnes.length > 0) added[runeKey] = newOnes;
@@ -170,7 +198,7 @@ async function promptReConsent(pluginName, diff, { yes = false } = {}) {
170
198
  }
171
199
  lines.push("");
172
200
  }
173
- Ce(lines.join("\n"), "New permissions");
201
+ output.note(lines.join("\n"), "New permissions");
174
202
  const answer = await le({ message: "Allow these new permissions?" });
175
203
  if (R(answer)) return false;
176
204
  return answer === true;
@@ -180,7 +208,7 @@ async function promptReConsent(pluginName, diff, { yes = false } = {}) {
180
208
  var execFileAsync2 = promisify2(execFile2);
181
209
  function collectAllowFromRune(rune) {
182
210
  const all = [];
183
- for (const lifecycle of Object.values(rune.permissions ?? {})) {
211
+ for (const lifecycle of Object.values(scopedPermissions(rune) ?? {})) {
184
212
  for (const perm of lifecycle?.allow ?? []) {
185
213
  if (!all.includes(perm)) all.push(perm);
186
214
  }
@@ -228,7 +256,7 @@ async function downloadNpm(packageName, destDir) {
228
256
  }
229
257
  }
230
258
  async function installPlugin(source, projectDir, provenance = {}, options = {}) {
231
- const { yes = false } = options;
259
+ const { yes = false, global = false } = options;
232
260
  if (!provenance.marketplaceName) {
233
261
  throw new Error("Direct installs are not allowed. Use: crunes plugin install <marketplace>@<plugin>");
234
262
  }
@@ -255,7 +283,7 @@ async function installPlugin(source, projectDir, provenance = {}, options = {})
255
283
  const registry = await loadRegistry();
256
284
  const existing = registry.plugins?.[pluginKey];
257
285
  if (existing) {
258
- return await updatePlugin(pluginKey, stagingDir, pluginJson, projectDir, type === "local", provenance, { yes });
286
+ return await updatePlugin(pluginKey, stagingDir, pluginJson, projectDir, type === "local", provenance, { yes, global });
259
287
  }
260
288
  const isLocal = type === "local";
261
289
  const cacheDir = getPluginCacheDir(name, version, provenance.marketplaceName);
@@ -275,7 +303,7 @@ async function installPlugin(source, projectDir, provenance = {}, options = {})
275
303
  consentedPermissions[key] = collectAllowFromRune(rune);
276
304
  }
277
305
  await registerPlugin({ name, version, path: isLocal ? stagingDir : cacheDir, cacheDir, local: isLocal, consentedPermissions, ...provenance });
278
- await addPluginToProjectConfig(projectDir, pluginKey);
306
+ await setEnabled(projectDir, pluginKey, true, global);
279
307
  return { installed: true, name: pluginKey, version };
280
308
  } finally {
281
309
  if (type !== "local") {
@@ -285,7 +313,7 @@ async function installPlugin(source, projectDir, provenance = {}, options = {})
285
313
  }
286
314
  }
287
315
  async function updatePlugin(pluginKey, newPluginDir, newPluginJson, projectDir, isLocal, provenance = {}, options = {}) {
288
- const { yes = false } = options;
316
+ const { yes = false, global = false } = options;
289
317
  const registry = await loadRegistry();
290
318
  const existing = registry.plugins[pluginKey];
291
319
  if (!existing) throw new Error(`Plugin "${pluginKey}" is not installed.`);
@@ -311,26 +339,31 @@ async function updatePlugin(pluginKey, newPluginDir, newPluginJson, projectDir,
311
339
  consentedPermissions[key] = collectAllowFromRune(rune);
312
340
  }
313
341
  await registerPlugin({ name, version, path: isLocal ? newPluginDir : cacheDir, cacheDir, local: isLocal, consentedPermissions, ...provenance });
314
- await addPluginToProjectConfig(projectDir, pluginKey);
342
+ await setEnabled(projectDir, pluginKey, true, global);
315
343
  return { installed: true, name: pluginKey, version, updated: true };
316
344
  }
317
- async function addPluginToProjectConfig(projectDir, pluginName) {
318
- if (!projectDir) return;
319
- const configPath = path2.join(projectDir, ".crunes", "config.json");
345
+ async function setEnabled(projectDir, pluginKey, enabled, global) {
346
+ if (!projectDir && !global) return;
320
347
  try {
321
- const raw = await fs2.readFile(configPath, "utf8");
322
- const config = JSON.parse(raw);
323
- const plugins = config.plugins ?? [];
324
- if (!plugins.includes(pluginName)) {
325
- config.plugins = [...plugins, pluginName];
326
- const tmp = configPath + "." + Date.now() + Math.random().toString(36).slice(2) + ".tmp";
327
- await fs2.writeFile(tmp, JSON.stringify(config, null, 2), "utf8");
328
- await fs2.rename(tmp, configPath);
329
- }
348
+ await setPluginEnabled(getConfigPath({ configRoot: projectDir, global }), pluginKey, enabled);
330
349
  } catch {
331
350
  }
332
351
  }
333
- async function uninstallPlugin(pluginKey, projectDir) {
352
+ async function removeEnabled(projectDir, pluginKey, global) {
353
+ if (!projectDir && !global) return;
354
+ try {
355
+ const configPath = getConfigPath({ configRoot: projectDir, global });
356
+ const config = readRawConfig(configPath);
357
+ if (!config) return;
358
+ const plugins = coercePlugins(config.plugins);
359
+ if (!(pluginKey in plugins)) return;
360
+ delete plugins[pluginKey];
361
+ config.plugins = plugins;
362
+ await writeRawConfig(configPath, config);
363
+ } catch {
364
+ }
365
+ }
366
+ async function uninstallPlugin(pluginKey, projectDir, { global = false } = {}) {
334
367
  const registry = await loadRegistry();
335
368
  const entry = registry.plugins?.[pluginKey];
336
369
  if (!entry) throw new Error(`Plugin "${pluginKey}" is not installed.`);
@@ -347,20 +380,7 @@ async function uninstallPlugin(pluginKey, projectDir) {
347
380
  } catch {
348
381
  }
349
382
  await removePlugin(pluginKey);
350
- await removePluginFromProjectConfig(projectDir, pluginKey);
351
- }
352
- async function removePluginFromProjectConfig(projectDir, pluginName) {
353
- if (!projectDir) return;
354
- const configPath = path2.join(projectDir, ".crunes", "config.json");
355
- try {
356
- const raw = await fs2.readFile(configPath, "utf8");
357
- const config = JSON.parse(raw);
358
- config.plugins = (config.plugins ?? []).filter((p) => p !== pluginName);
359
- const tmp = configPath + "." + Date.now() + Math.random().toString(36).slice(2) + ".tmp";
360
- await fs2.writeFile(tmp, JSON.stringify(config, null, 2), "utf8");
361
- await fs2.rename(tmp, configPath);
362
- } catch {
363
- }
383
+ await removeEnabled(projectDir, pluginKey, global);
364
384
  }
365
385
 
366
386
  export {
@@ -0,0 +1,44 @@
1
+ import {
2
+ coercePlugins
3
+ } from "./chunk-2FI6KN3C.js";
4
+ import {
5
+ getStorePath
6
+ } from "./chunk-2Q3KLBE6.js";
7
+ import {
8
+ init_require_shim
9
+ } from "./chunk-TPK5AGRA.js";
10
+
11
+ // src/core/config-writer.js
12
+ init_require_shim();
13
+ import fs from "node:fs/promises";
14
+ import { readFileSync, existsSync } from "node:fs";
15
+ import path from "node:path";
16
+ function getConfigPath({ configRoot, global = false } = {}) {
17
+ if (global) return path.join(getStorePath(), "config.json");
18
+ return path.join(configRoot, ".crunes", "config.json");
19
+ }
20
+ function readRawConfig(configPath) {
21
+ if (!existsSync(configPath)) return null;
22
+ return JSON.parse(readFileSync(configPath, "utf8"));
23
+ }
24
+ async function writeRawConfig(configPath, config) {
25
+ await fs.mkdir(path.dirname(configPath), { recursive: true });
26
+ const tmp = `${configPath}.${Date.now()}${Math.random().toString(36).slice(2)}.tmp`;
27
+ await fs.writeFile(tmp, JSON.stringify(config, null, 2) + "\n", "utf8");
28
+ await fs.rename(tmp, configPath);
29
+ }
30
+ async function setPluginEnabled(configPath, pluginKey, enabled) {
31
+ const config = readRawConfig(configPath);
32
+ if (config === null) {
33
+ throw new Error(`No config found at ${configPath}. Run: crunes init (or crunes init -g for the global config)`);
34
+ }
35
+ config.plugins = { ...coercePlugins(config.plugins), [pluginKey]: enabled };
36
+ await writeRawConfig(configPath, config);
37
+ }
38
+
39
+ export {
40
+ getConfigPath,
41
+ readRawConfig,
42
+ writeRawConfig,
43
+ setPluginEnabled
44
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/shared/command.js
6
+ init_require_shim();
7
+ import path from "node:path";
8
+ var ISOLATE_MODULE = /\.rune\.m?js$/i;
9
+ function isPathCommand(command) {
10
+ return command.includes("/") || command.includes("\\") || command.startsWith(".") || path.isAbsolute(command) || ISOLATE_MODULE.test(command);
11
+ }
12
+
13
+ export {
14
+ isPathCommand
15
+ };
@@ -1,3 +1,6 @@
1
+ import {
2
+ getLocalBase
3
+ } from "./chunk-2Q3KLBE6.js";
1
4
  import {
2
5
  init_require_shim
3
6
  } from "./chunk-TPK5AGRA.js";
@@ -12,7 +15,7 @@ function safeKey(runeKey) {
12
15
  return runeKey.replace(/:/g, "__");
13
16
  }
14
17
  function schemasDir(projectDir) {
15
- return join(projectDir, ".crunes", "schemas");
18
+ return join(getLocalBase(projectDir), "schemas");
16
19
  }
17
20
  function cacheFilePath(runeKey, type, projectDir) {
18
21
  return join(schemasDir(projectDir), `${safeKey(runeKey)}-${type}.json`);
@@ -0,0 +1,244 @@
1
+ import {
2
+ parseFlags
3
+ } from "./chunk-55GTJG5I.js";
4
+ import {
5
+ init_require_shim
6
+ } from "./chunk-TPK5AGRA.js";
7
+
8
+ // src/rune/native/schema.js
9
+ init_require_shim();
10
+ import { readFileSync } from "node:fs";
11
+ var SCHEMA_KEYS = ["positionals", "options", "examples", "commands"];
12
+ var NODE_KEYS = {
13
+ root: SCHEMA_KEYS,
14
+ command: ["name", "description", "to", ...SCHEMA_KEYS],
15
+ positional: ["spec", "description", "type", "choices", "to"],
16
+ option: ["flags", "description", "type", "default", "required", "choices", "to"],
17
+ example: ["usage", "description"]
18
+ };
19
+ var POSITIONAL_SPEC = /^[<[]([a-zA-Z0-9_-]+)(\.\.\.)?[>\]]$/;
20
+ var VALUE_TYPES = ["string", "number", "integer"];
21
+ function isInlineSchema(block) {
22
+ return block != null && typeof block === "object" && !Array.isArray(block) && Object.keys(block).some((k) => SCHEMA_KEYS.includes(k));
23
+ }
24
+ function fail(where, message) {
25
+ throw new Error(`${where}: ${message}`);
26
+ }
27
+ function checkKeys(where, node, kind) {
28
+ if (node == null || typeof node !== "object" || Array.isArray(node)) fail(where, "must be an object");
29
+ const unknown = Object.keys(node).filter((k) => !NODE_KEYS[kind].includes(k));
30
+ if (unknown.length) fail(where, `unknown field${unknown.length > 1 ? "s" : ""} ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 allowed: ${NODE_KEYS[kind].join(", ")}`);
31
+ }
32
+ function checkChoices(where, choices) {
33
+ if (choices !== void 0 && (!Array.isArray(choices) || choices.length === 0 || choices.some((c) => typeof c !== "string" && typeof c !== "number"))) {
34
+ fail(where, '"choices" must be a non-empty array of strings or numbers');
35
+ }
36
+ }
37
+ function checkTo(where, to) {
38
+ if (to !== void 0 && typeof to !== "string" && !(Array.isArray(to) && to.every((t) => typeof t === "string"))) {
39
+ fail(where, '"to" must be a string or an array of strings \u2014 the program arguments this one becomes, with {value} for its value');
40
+ }
41
+ }
42
+ function list(where, node, field) {
43
+ const value = node[field];
44
+ if (value === void 0) return [];
45
+ if (!Array.isArray(value)) fail(where, `"${field}" must be an array`);
46
+ return value;
47
+ }
48
+ function normaliseJsonSchema(schema, where = "args") {
49
+ return normaliseNode(schema, where, "root");
50
+ }
51
+ function normaliseNode(node, where, kind) {
52
+ checkKeys(where, node, kind);
53
+ const out = {};
54
+ if (kind === "command") {
55
+ if (typeof node.name !== "string" || !node.name) fail(where, '"name" must be a non-empty string');
56
+ out.name = node.name;
57
+ out.description = node.description ?? "";
58
+ checkTo(where, node.to);
59
+ if (node.to !== void 0) out.to = node.to;
60
+ }
61
+ out.positionals = list(where, node, "positionals").map((p, i) => {
62
+ const at = `${where}.positionals[${i}]`;
63
+ checkKeys(at, p, "positional");
64
+ if (typeof p.spec !== "string" || !POSITIONAL_SPEC.test(p.spec)) fail(at, `"spec" must look like <name>, [name] or <names...>`);
65
+ if (p.type !== void 0 && !VALUE_TYPES.includes(p.type)) fail(at, `"type" must be one of ${VALUE_TYPES.join(", ")}`);
66
+ checkChoices(at, p.choices);
67
+ checkTo(at, p.to);
68
+ return { spec: p.spec, description: p.description ?? "", ...p.type && { type: p.type }, ...p.choices && { choices: p.choices }, ...p.to !== void 0 && { to: p.to } };
69
+ });
70
+ out.options = list(where, node, "options").map((o, i) => {
71
+ const at = `${where}.options[${i}]`;
72
+ checkKeys(at, o, "option");
73
+ if (typeof o.flags !== "string") fail(at, '"flags" must be a string such as "--min <percent>"');
74
+ let flag;
75
+ try {
76
+ flag = parseFlags(o.flags);
77
+ } catch (err) {
78
+ fail(at, err.message);
79
+ }
80
+ if (o.type !== void 0) {
81
+ const takesValue = flag.type !== "boolean";
82
+ if (takesValue ? !VALUE_TYPES.includes(o.type) : o.type !== "boolean") {
83
+ fail(at, `"type" must be ${takesValue ? `one of ${VALUE_TYPES.join(", ")} for an option that takes a value` : '"boolean" for a flag that takes no value'}`);
84
+ }
85
+ }
86
+ if (o.required !== void 0 && typeof o.required !== "boolean") fail(at, '"required" must be true or false');
87
+ checkChoices(at, o.choices);
88
+ checkTo(at, o.to);
89
+ return {
90
+ flags: o.flags,
91
+ description: o.description ?? "",
92
+ ...o.type && o.type !== "boolean" && { type: o.type },
93
+ ...o.default !== void 0 && { def: o.default },
94
+ ...o.required && { required: true },
95
+ ...o.choices && { choices: o.choices },
96
+ ...o.to !== void 0 && { to: o.to }
97
+ };
98
+ });
99
+ out.examples = list(where, node, "examples").map((e, i) => {
100
+ const at = `${where}.examples[${i}]`;
101
+ checkKeys(at, e, "example");
102
+ if (typeof e.usage !== "string") fail(at, '"usage" must be a string');
103
+ return { usage: e.usage, description: e.description ?? "" };
104
+ });
105
+ out.commands = list(where, node, "commands").map((c, i) => normaliseNode(c, `${where}.commands[${i}]`, "command"));
106
+ return out;
107
+ }
108
+ function loadJsonSchema(file, shownAs = file) {
109
+ let parsed;
110
+ try {
111
+ parsed = JSON.parse(readFileSync(file, "utf8"));
112
+ } catch (err) {
113
+ throw new Error(`${shownAs}: ${err.code === "ENOENT" ? "file not found" : `invalid JSON \u2014 ${err.message}`}`);
114
+ }
115
+ return normaliseJsonSchema(parsed, shownAs);
116
+ }
117
+ function nodeFor(schema, commands) {
118
+ let node = schema;
119
+ const options = [...schema.options ?? []];
120
+ for (const name of commands) {
121
+ node = (node.commands ?? []).find((c) => c.name === name) ?? node;
122
+ options.push(...node.options ?? []);
123
+ }
124
+ return { node, options };
125
+ }
126
+ var shown = (value) => JSON.stringify(value);
127
+ function typeProblem(type, value) {
128
+ if (type === "number" && !Number.isFinite(value)) return "must be a number";
129
+ if (type === "integer" && !Number.isInteger(value)) return "must be an integer";
130
+ return null;
131
+ }
132
+ function validateParsed(schema, parsed, key) {
133
+ const { node, options } = nodeFor(schema, parsed.$commands ?? []);
134
+ const usage = `Run \`crunes run ${key}${parsed.$command ? ` ${parsed.$command}` : ""} --help\` for usage.`;
135
+ const problems = [];
136
+ for (const p of node.positionals ?? []) {
137
+ const [, name, variadic] = p.spec.match(POSITIONAL_SPEC);
138
+ const required = p.spec.startsWith("<");
139
+ const value = parsed[name];
140
+ const values = variadic ? value ?? [] : value === void 0 ? [] : [value];
141
+ if (required && values.length === 0) problems.push(`missing required ${p.spec}`);
142
+ for (const v of values) {
143
+ const problem = typeProblem(p.type, v);
144
+ if (problem) problems.push(`${p.spec} ${problem} \u2014 got ${shown(String(v))}`);
145
+ }
146
+ if (p.choices) {
147
+ for (const v of values) {
148
+ if (!p.choices.map(String).includes(String(v))) problems.push(`${p.spec} must be one of ${p.choices.map(shown).join(", ")} \u2014 got ${shown(String(v))}`);
149
+ }
150
+ }
151
+ }
152
+ for (const o of options) {
153
+ const { key: optKey } = parseFlags(o.flags);
154
+ const value = parsed[optKey];
155
+ if (o.required && value === void 0) problems.push(`missing required option ${o.flags}`);
156
+ if (value !== void 0) {
157
+ for (const v of Array.isArray(value) ? value : [value]) {
158
+ const problem = typeProblem(o.type, v);
159
+ if (problem) problems.push(`${o.flags} ${problem}${Number.isNaN(v) ? "" : ` \u2014 got ${shown(String(v))}`}`);
160
+ }
161
+ }
162
+ if (o.choices && value !== void 0) {
163
+ const values = Array.isArray(value) ? value : [value];
164
+ for (const v of values) {
165
+ if (!o.choices.map(String).includes(String(v))) problems.push(`${o.flags} must be one of ${o.choices.map(shown).join(", ")} \u2014 got ${shown(String(v))}`);
166
+ }
167
+ }
168
+ }
169
+ if (problems.length) throw new Error(`Invalid arguments for "${key}":
170
+ ${problems.join("\n ")}
171
+ ${usage}`);
172
+ }
173
+ function expand(to, value) {
174
+ return (Array.isArray(to) ? to : [to]).map((t) => value === void 0 ? t : t.replaceAll("{value}", String(value)));
175
+ }
176
+ function flagToken(option, key) {
177
+ return /--/.test(option.flags) ? `--${key}` : `-${key}`;
178
+ }
179
+ function mapToArgv(schema, parsed) {
180
+ const tokens = [];
181
+ let node = schema;
182
+ for (const name of parsed.$commands ?? []) {
183
+ node = (node.commands ?? []).find((c) => c.name === name) ?? node;
184
+ tokens.push(...expand(node.to ?? name));
185
+ }
186
+ for (const o of nodeFor(schema, parsed.$commands ?? []).options) {
187
+ const { key, type } = parseFlags(o.flags);
188
+ const value = parsed[key];
189
+ if (value === void 0 || value === false) continue;
190
+ if (type === "boolean" && !o.type) {
191
+ if (value === true) tokens.push(...o.to !== void 0 ? expand(o.to) : [flagToken(o, key)]);
192
+ continue;
193
+ }
194
+ for (const v of Array.isArray(value) ? value : [value]) {
195
+ tokens.push(...o.to !== void 0 ? expand(o.to, v) : [flagToken(o, key), String(v)]);
196
+ }
197
+ }
198
+ for (const p of node.positionals ?? []) {
199
+ const [, name] = p.spec.match(POSITIONAL_SPEC);
200
+ const value = parsed[name];
201
+ if (value === void 0) continue;
202
+ for (const v of Array.isArray(value) ? value : [value]) tokens.push(...p.to !== void 0 ? expand(p.to, v) : [String(v)]);
203
+ }
204
+ return tokens;
205
+ }
206
+ function undeclaredArgs(schema, parsed, raw) {
207
+ const { options } = nodeFor(schema, parsed.$commands ?? []);
208
+ const long = /* @__PURE__ */ new Set(["help"]);
209
+ const short = /* @__PURE__ */ new Map([["h", false]]);
210
+ for (const o of options) {
211
+ const { key, alias, type } = parseFlags(o.flags);
212
+ if (/--/.test(o.flags)) long.add(key);
213
+ else short.set(key, type !== "boolean");
214
+ if (alias) short.set(alias, type !== "boolean");
215
+ if (type === "boolean") long.add(`no-${key}`);
216
+ }
217
+ const problems = [];
218
+ for (const token of raw) {
219
+ if (token === "--") break;
220
+ const longMatch = token.match(/^--([^=]+)/);
221
+ if (longMatch) {
222
+ if (!long.has(longMatch[1])) problems.push(`unknown option --${longMatch[1]}`);
223
+ } else if (/^-[^-\d]/.test(token)) {
224
+ for (const c of token.slice(1).split("=")[0]) {
225
+ if (!short.has(c)) {
226
+ problems.push(`unknown option -${c}`);
227
+ break;
228
+ }
229
+ if (short.get(c)) break;
230
+ }
231
+ }
232
+ }
233
+ if (parsed.$rest?.length) problems.push(`unexpected argument${parsed.$rest.length > 1 ? "s" : ""} ${parsed.$rest.map((v) => JSON.stringify(String(v))).join(" ")}`);
234
+ return problems;
235
+ }
236
+
237
+ export {
238
+ isInlineSchema,
239
+ normaliseJsonSchema,
240
+ loadJsonSchema,
241
+ validateParsed,
242
+ mapToArgv,
243
+ undeclaredArgs
244
+ };
@@ -3,8 +3,9 @@ import {
3
3
  } from "./chunk-G4ZAUHHA.js";
4
4
  import {
5
5
  getCacheBasePath,
6
- getCacheJsonPath
7
- } from "./chunk-6MRZXASS.js";
6
+ getCacheJsonPath,
7
+ getLocalBase
8
+ } from "./chunk-2Q3KLBE6.js";
8
9
  import {
9
10
  init_require_shim
10
11
  } from "./chunk-TPK5AGRA.js";
@@ -30,7 +31,7 @@ async function listCacheBuckets() {
30
31
  }
31
32
  async function listLocalCacheBuckets(projectDir) {
32
33
  const results = [];
33
- const localCacheDir = path.join(projectDir, ".crunes", "caches");
34
+ const localCacheDir = path.join(getLocalBase(projectDir), "caches");
34
35
  async function scanScope(scopeDir, scope, pluginId = null) {
35
36
  let entries;
36
37
  try {
@@ -0,0 +1,71 @@
1
+ import {
2
+ isPathCommand
3
+ } from "./chunk-UBCAZGLE.js";
4
+ import {
5
+ loadRegistry,
6
+ saveRegistry
7
+ } from "./chunk-MTJ2KW3V.js";
8
+ import {
9
+ blockOf
10
+ } from "./chunk-YKIKJHYO.js";
11
+ import {
12
+ init_require_shim
13
+ } from "./chunk-TPK5AGRA.js";
14
+
15
+ // src/plugin/native.js
16
+ init_require_shim();
17
+ import { createHash } from "node:crypto";
18
+ import { readFileSync } from "node:fs";
19
+ import { join, isAbsolute } from "node:path";
20
+ var ISOLATE_MODULE = /\.rune\.m?js$/i;
21
+ function isNativeRune(rune) {
22
+ const command = blockOf(rune, "run")?.command;
23
+ return typeof command === "string" && !ISOLATE_MODULE.test(command);
24
+ }
25
+ function nativeRuneFile(pluginDir, rune) {
26
+ const { command } = blockOf(rune, "run");
27
+ if (!isPathCommand(command)) return null;
28
+ return isAbsolute(command) ? command : join(pluginDir, command);
29
+ }
30
+ function trustDigest(pluginDir, rune) {
31
+ const hash = createHash("sha256");
32
+ hash.update(JSON.stringify({ run: blockOf(rune, "run"), args: rune.args ?? null }));
33
+ const file = nativeRuneFile(pluginDir, rune);
34
+ if (file) {
35
+ try {
36
+ hash.update(readFileSync(file));
37
+ } catch {
38
+ hash.update("missing");
39
+ }
40
+ }
41
+ return hash.digest("hex");
42
+ }
43
+ function trustState(registryEntry, runeKey, digest) {
44
+ const trusted = registryEntry?.trustedNative?.[runeKey];
45
+ if (!trusted) return "untrusted";
46
+ return trusted.digest === digest ? "trusted" : "changed";
47
+ }
48
+ async function recordTrust(pluginKey, runeKey, digest) {
49
+ const registry = await loadRegistry();
50
+ const entry = registry.plugins?.[pluginKey];
51
+ if (!entry) throw new Error(`Plugin "${pluginKey}" is not installed`);
52
+ entry.trustedNative = { ...entry.trustedNative ?? {}, [runeKey]: { digest, at: (/* @__PURE__ */ new Date()).toISOString() } };
53
+ await saveRegistry(registry);
54
+ }
55
+ function untrustedError(pluginKey, runeKey, state) {
56
+ const shortName = pluginKey.slice(pluginKey.indexOf("@") + 1);
57
+ const why = state === "changed" ? `has changed since it was trusted \u2014 its script, command or schema is not what was reviewed` : `runs natively, outside the sandbox, with your full access, and has not been trusted`;
58
+ return new Error(
59
+ `Plugin rune "${pluginKey}:${runeKey}" ${why}.
60
+ Review what it runs and trust it with: crunes plugin trust ${shortName} ${runeKey}`
61
+ );
62
+ }
63
+
64
+ export {
65
+ isNativeRune,
66
+ nativeRuneFile,
67
+ trustDigest,
68
+ trustState,
69
+ recordTrust,
70
+ untrustedError
71
+ };