@darkrymit/crunes-cli 0.9.0 → 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 (59) hide show
  1. package/dist/chunks/add-MSX6XSU3.js +68 -0
  2. package/dist/chunks/{apply-YY7MIM64.js → apply-LOIJIPLR.js} +18 -9
  3. package/dist/chunks/{benchmark-BQNMULOO.js → benchmark-3IHFP3V2.js} +21 -15
  4. package/dist/chunks/chunk-2DNYVKBF.js +109 -0
  5. package/dist/chunks/chunk-2FI6KN3C.js +283 -0
  6. package/dist/chunks/chunk-2HM5Q52B.js +131 -0
  7. package/dist/chunks/chunk-55GTJG5I.js +1154 -0
  8. package/dist/chunks/chunk-6IC6ZJ74.js +9525 -0
  9. package/dist/chunks/chunk-7KYCYDAS.js +325 -0
  10. package/dist/chunks/chunk-DTOYFY3Z.js +578 -0
  11. package/dist/chunks/chunk-EO3CSXWK.js +70 -0
  12. package/dist/chunks/chunk-FIAFVIAN.js +79 -0
  13. package/dist/chunks/chunk-H2OT7D6N.js +303 -0
  14. package/dist/chunks/{chunk-MRNZFUXZ.js → chunk-KSQDFE5N.js} +22 -7
  15. package/dist/chunks/{chunk-SNC7AOT7.js → chunk-KUEMDPNG.js} +45 -94
  16. package/dist/chunks/{chunk-VST6HAB6.js → chunk-MTJ2KW3V.js} +2 -0
  17. package/dist/chunks/{chunk-CY6C6ADU.js → chunk-MVCBPI4J.js} +45 -478
  18. package/dist/chunks/{chunk-34F4ZURL.js → chunk-RVBAAXRY.js} +29 -12
  19. package/dist/chunks/{chunk-X7PZN73N.js → chunk-SUCYDYMU.js} +1 -1
  20. package/dist/chunks/chunk-UBCAZGLE.js +15 -0
  21. package/dist/chunks/chunk-VP7YLCQP.js +244 -0
  22. package/dist/chunks/chunk-XDMMSZIL.js +71 -0
  23. package/dist/chunks/chunk-YKIKJHYO.js +94 -0
  24. package/dist/chunks/{create-TLPM7HJE.js → create-DXW4YYLJ.js} +5 -5
  25. package/dist/chunks/{create-LM7U3CJS.js → create-LPLNCOW4.js} +100 -6
  26. package/dist/chunks/{create-ET6DT5ZE.js → create-Y4LHLWGL.js} +6 -2
  27. package/dist/chunks/{disable-TNTEIAKO.js → disable-TITOSMXB.js} +6 -2
  28. package/dist/chunks/doctor-R2Y6UAY4.js +208 -0
  29. package/dist/chunks/{enable-GUQCB4CU.js → enable-LGTPDWPV.js} +7 -3
  30. package/dist/chunks/{init-PJSCFOC6.js → init-KO2HLED5.js} +6 -2
  31. package/dist/chunks/{install-4YP7FALO.js → install-7IRUAGSF.js} +10 -5
  32. package/dist/chunks/{intro-SA7MWV3Z.js → intro-JNJ6A75J.js} +44 -18
  33. package/dist/chunks/{list-WKNPZZOV.js → list-BCCM3TLP.js} +10 -6
  34. package/dist/chunks/{list-7R6NASFI.js → list-MLKZE36K.js} +19 -19
  35. package/dist/chunks/list-QVZKR3IE.js +62 -0
  36. package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
  37. package/dist/chunks/migrate-Y3EKMVP5.js +87 -0
  38. package/dist/chunks/{registry-K5DV5NAK.js → registry-IWP7JMNI.js} +1 -1
  39. package/dist/chunks/{repl-ZB3DIJ4K.js → repl-5GDN3RAO.js} +30 -20
  40. package/dist/chunks/resolver-CA2A32AC.js +36 -0
  41. package/dist/chunks/{run-22B65ZWZ.js → run-WL3IZBXF.js} +17 -11
  42. package/dist/chunks/rune-YA4TFHTB.js +283 -0
  43. package/dist/chunks/runner-QNZMBHQY.js +34 -0
  44. package/dist/chunks/{shell-explain-QLITLHW7.js → shell-explain-LKBBP2BG.js} +5 -2
  45. package/dist/chunks/trust-BFIDANXD.js +109 -0
  46. package/dist/chunks/{uninstall-4WR5IHLC.js → uninstall-3MWZIZVA.js} +10 -5
  47. package/dist/chunks/{update-ACLDK6E6.js → update-W4MJUTTW.js} +10 -5
  48. package/dist/chunks/{version-EULYWNXN.js → version-FLHI5KFS.js} +2 -2
  49. package/dist/cli.js +51 -34
  50. package/package.json +2 -2
  51. package/dist/chunks/chunk-G3U4V32O.js +0 -46
  52. package/dist/chunks/chunk-QYRF3R35.js +0 -154
  53. package/dist/chunks/chunk-YXCHIMLW.js +0 -75308
  54. package/dist/chunks/doctor-VXAQYMTR.js +0 -101
  55. package/dist/chunks/list-OMMZAQ23.js +0 -28
  56. package/dist/chunks/resolver-QIYYFIDX.js +0 -34
  57. package/dist/chunks/rune-SYK4N642.js +0 -425
  58. package/dist/chunks/{delete-5R3WBLVD.js → delete-2EXPFBFC.js} +4 -4
  59. package/dist/chunks/{delete-U4STA2QZ.js → delete-MJAECXXV.js} +4 -4
@@ -2,8 +2,7 @@ import {
2
2
  getConfigPath,
3
3
  readRawConfig,
4
4
  writeRawConfig
5
- } from "./chunk-X7PZN73N.js";
6
- import "./chunk-QYRF3R35.js";
5
+ } from "./chunk-SUCYDYMU.js";
7
6
  import {
8
7
  output
9
8
  } from "./chunk-MIKWIFYR.js";
@@ -15,9 +14,14 @@ import {
15
14
  ye
16
15
  } from "./chunk-CGZL5SSH.js";
17
16
  import "./chunk-WCODTMDN.js";
17
+ import "./chunk-2FI6KN3C.js";
18
+ import "./chunk-UBCAZGLE.js";
19
+ import "./chunk-VP7YLCQP.js";
20
+ import "./chunk-YKIKJHYO.js";
18
21
  import {
19
22
  getStorePath
20
23
  } from "./chunk-2Q3KLBE6.js";
24
+ import "./chunk-55GTJG5I.js";
21
25
  import {
22
26
  init_require_shim
23
27
  } from "./chunk-TPK5AGRA.js";
@@ -27,6 +31,86 @@ init_require_shim();
27
31
  import { mkdir, writeFile } from "node:fs/promises";
28
32
  import { join, dirname } from "node:path";
29
33
  var VALID_FORMATS = ["tree", "markdown"];
34
+ var SCRIPT_LANGS = {
35
+ python: {
36
+ ext: "py",
37
+ body: (key) => [
38
+ `import json`,
39
+ `import os`,
40
+ `import sys`,
41
+ ``,
42
+ `# A script rune: crunes runs this with the project's Python and passes`,
43
+ `# sys.argv[1:] the caller's arguments, unchanged`,
44
+ `# CRUNES_ARGS the parsed arguments as JSON, when the rune has an args schema`,
45
+ `# CRUNES_VARS the rune's configured vars as JSON`,
46
+ `# Whatever it prints is the rune's output.`,
47
+ ``,
48
+ `args = json.loads(os.environ.get("CRUNES_ARGS", "null"))`,
49
+ `rune_vars = json.loads(os.environ.get("CRUNES_VARS", "{}"))`,
50
+ ``,
51
+ `print("${key}:", sys.argv[1:])`,
52
+ ``
53
+ ].join("\n")
54
+ },
55
+ bash: {
56
+ ext: "sh",
57
+ body: (key) => [
58
+ `# A script rune: crunes runs this with bash and passes`,
59
+ `# "$@" the caller's arguments, unchanged`,
60
+ `# CRUNES_ARGS the parsed arguments as JSON, when the rune has an args schema`,
61
+ `# CRUNES_VARS the rune's configured vars as JSON`,
62
+ `# Whatever it prints is the rune's output; its exit code is crunes's.`,
63
+ ``,
64
+ `echo "${key}: $*"`,
65
+ ``
66
+ ].join("\n")
67
+ },
68
+ node: {
69
+ ext: "js",
70
+ body: (key) => [
71
+ `// A script rune: crunes runs this with Node, outside the sandbox, and passes`,
72
+ `// process.argv.slice(2) the caller's arguments, unchanged`,
73
+ `// CRUNES_ARGS the parsed arguments as JSON, when the rune has an args schema`,
74
+ `// CRUNES_VARS the rune's configured vars as JSON`,
75
+ `// Whatever it prints is the rune's output. To run in the sandbox instead, use a *.rune.js file.`,
76
+ ``,
77
+ `const args = JSON.parse(process.env.CRUNES_ARGS ?? 'null')`,
78
+ `const vars = JSON.parse(process.env.CRUNES_VARS ?? '{}')`,
79
+ ``,
80
+ `console.log('${key}:', process.argv.slice(2))`,
81
+ ``
82
+ ].join("\n")
83
+ }
84
+ };
85
+ var VALID_LANGS = Object.keys(SCRIPT_LANGS);
86
+ async function createScriptRune({ key, lang, runeRelPath, name, description, configRoot, global }) {
87
+ const spec = SCRIPT_LANGS[lang];
88
+ if (!spec) {
89
+ output.error(`Invalid --lang. Must be one of: ${VALID_LANGS.join(", ")}`);
90
+ process.exit(1);
91
+ }
92
+ if (!key) {
93
+ output.error("Missing required argument: <key>");
94
+ process.exit(1);
95
+ }
96
+ runeRelPath = runeRelPath ?? (global ? `runes/${key}.${spec.ext}` : `.crunes/runes/${key}.${spec.ext}`);
97
+ const runeAbsPath = join(global ? getStorePath() : configRoot, runeRelPath);
98
+ const configPath = getConfigPath({ configRoot, global });
99
+ const config = readRawConfig(configPath) ?? { runes: {} };
100
+ if (config.runes?.[key] != null) {
101
+ output.error(`Rune "${key}" already exists in ${configPath}.`);
102
+ process.exit(1);
103
+ }
104
+ await mkdir(dirname(runeAbsPath), { recursive: true });
105
+ await writeFile(runeAbsPath, spec.body(key));
106
+ config.runes = {
107
+ ...config.runes ?? {},
108
+ [key]: { ...name && { name }, ...description && { description }, run: runeRelPath }
109
+ };
110
+ await writeRawConfig(configPath, config);
111
+ output.success(`Created ${runeRelPath} (${lang}, native)`);
112
+ output.info(`Run: crunes run ${key}`);
113
+ }
30
114
  function template(key, format) {
31
115
  const imports = format === "tree" ? `import { md, section, tree } from '@utils'` : `import { md, section } from '@utils'`;
32
116
  const header = [
@@ -74,6 +158,7 @@ function template(key, format) {
74
158
  async function handler({
75
159
  key,
76
160
  format,
161
+ lang,
77
162
  path: runeRelPath,
78
163
  name,
79
164
  description,
@@ -82,6 +167,10 @@ async function handler({
82
167
  configRoot = projectRoot,
83
168
  global = false
84
169
  } = {}) {
170
+ if (lang) {
171
+ await createScriptRune({ key, lang, runeRelPath, name, description, configRoot, global });
172
+ return;
173
+ }
85
174
  const isNonInteractive = yes || !process.stdout.isTTY;
86
175
  if (isNonInteractive) {
87
176
  if (!key) {
@@ -121,7 +210,7 @@ async function handler({
121
210
  format = result;
122
211
  }
123
212
  if (!runeRelPath) {
124
- const defaultPath = global ? `runes/${key}.js` : `.crunes/runes/${key}.js`;
213
+ const defaultPath = global ? `runes/${key}.rune.js` : `.crunes/runes/${key}.rune.js`;
125
214
  const result = await Re({ message: "File path?", initialValue: defaultPath });
126
215
  if (result === /* @__PURE__ */ Symbol.for("clack:cancel")) {
127
216
  ge("Cancelled.");
@@ -146,7 +235,11 @@ async function handler({
146
235
  description = result || void 0;
147
236
  }
148
237
  }
149
- runeRelPath = runeRelPath ?? (global ? `runes/${key}.js` : `.crunes/runes/${key}.js`);
238
+ runeRelPath = runeRelPath ?? (global ? `runes/${key}.rune.js` : `.crunes/runes/${key}.rune.js`);
239
+ if (!/\.rune\.m?js$/i.test(runeRelPath)) {
240
+ output.error(`${runeRelPath}: a sandboxed rune's file must be named *.rune.js \u2014 the name is what runs it in the isolate.`);
241
+ process.exit(1);
242
+ }
150
243
  const baseRoot = global ? getStorePath() : configRoot;
151
244
  const runeAbsPath = join(baseRoot, runeRelPath);
152
245
  await mkdir(dirname(runeAbsPath), { recursive: true });
@@ -154,9 +247,9 @@ async function handler({
154
247
  const configPath = getConfigPath({ configRoot, global });
155
248
  const config = readRawConfig(configPath) ?? { runes: {} };
156
249
  const entry = {
157
- path: runeRelPath,
158
250
  ...name && { name },
159
- ...description && { description }
251
+ ...description && { description },
252
+ run: runeRelPath
160
253
  };
161
254
  config.runes = { ...config.runes ?? {}, [key]: entry };
162
255
  await writeRawConfig(configPath, config);
@@ -169,6 +262,7 @@ Run: crunes run ${key}`);
169
262
  }
170
263
  }
171
264
  export {
265
+ VALID_LANGS,
172
266
  handler,
173
267
  template
174
268
  };
@@ -2,8 +2,7 @@ import {
2
2
  getConfigPath,
3
3
  readRawConfig,
4
4
  writeRawConfig
5
- } from "./chunk-X7PZN73N.js";
6
- import "./chunk-QYRF3R35.js";
5
+ } from "./chunk-SUCYDYMU.js";
7
6
  import {
8
7
  output
9
8
  } from "./chunk-MIKWIFYR.js";
@@ -14,9 +13,14 @@ import {
14
13
  ye
15
14
  } from "./chunk-CGZL5SSH.js";
16
15
  import "./chunk-WCODTMDN.js";
16
+ import "./chunk-2FI6KN3C.js";
17
+ import "./chunk-UBCAZGLE.js";
18
+ import "./chunk-VP7YLCQP.js";
19
+ import "./chunk-YKIKJHYO.js";
17
20
  import {
18
21
  getStorePath
19
22
  } from "./chunk-2Q3KLBE6.js";
23
+ import "./chunk-55GTJG5I.js";
20
24
  import {
21
25
  init_require_shim
22
26
  } from "./chunk-TPK5AGRA.js";
@@ -1,12 +1,16 @@
1
1
  import {
2
2
  getConfigPath,
3
3
  setPluginEnabled
4
- } from "./chunk-X7PZN73N.js";
4
+ } from "./chunk-SUCYDYMU.js";
5
5
  import {
6
6
  enabledPluginKeys,
7
7
  loadConfig
8
- } from "./chunk-QYRF3R35.js";
8
+ } from "./chunk-2FI6KN3C.js";
9
+ import "./chunk-UBCAZGLE.js";
10
+ import "./chunk-VP7YLCQP.js";
11
+ import "./chunk-YKIKJHYO.js";
9
12
  import "./chunk-2Q3KLBE6.js";
13
+ import "./chunk-55GTJG5I.js";
10
14
  import {
11
15
  init_require_shim
12
16
  } from "./chunk-TPK5AGRA.js";
@@ -0,0 +1,208 @@
1
+ import {
2
+ getConfigPath,
3
+ readRawConfig
4
+ } from "./chunk-SUCYDYMU.js";
5
+ import {
6
+ output
7
+ } from "./chunk-MIKWIFYR.js";
8
+ import "./chunk-CGZL5SSH.js";
9
+ import "./chunk-WCODTMDN.js";
10
+ import {
11
+ describeRunBlock
12
+ } from "./chunk-DTOYFY3Z.js";
13
+ import {
14
+ assertNotMissedRename,
15
+ onPath,
16
+ resolveInterpreter
17
+ } from "./chunk-2DNYVKBF.js";
18
+ import {
19
+ isNativeRune,
20
+ trustDigest,
21
+ trustState
22
+ } from "./chunk-XDMMSZIL.js";
23
+ import {
24
+ coercePlugins,
25
+ loadConfig
26
+ } from "./chunk-2FI6KN3C.js";
27
+ import "./chunk-UBCAZGLE.js";
28
+ import {
29
+ loadRegistry
30
+ } from "./chunk-MTJ2KW3V.js";
31
+ import {
32
+ loadPluginJson
33
+ } from "./chunk-FIAFVIAN.js";
34
+ import {
35
+ loadJsonSchema
36
+ } from "./chunk-VP7YLCQP.js";
37
+ import "./chunk-YKIKJHYO.js";
38
+ import "./chunk-MVCBPI4J.js";
39
+ import "./chunk-GVMT55GH.js";
40
+ import "./chunk-2HM5Q52B.js";
41
+ import "./chunk-WJII3LZK.js";
42
+ import "./chunk-G4ZAUHHA.js";
43
+ import "./chunk-2Q3KLBE6.js";
44
+ import "./chunk-55GTJG5I.js";
45
+ import {
46
+ init_require_shim
47
+ } from "./chunk-TPK5AGRA.js";
48
+
49
+ // src/cli/commands/doctor.js
50
+ init_require_shim();
51
+ import { spawnSync } from "node:child_process";
52
+ import { existsSync } from "node:fs";
53
+ import { relative } from "node:path";
54
+ async function checkPluginNativeTrust(config) {
55
+ const results = [];
56
+ let registry;
57
+ try {
58
+ registry = await loadRegistry();
59
+ } catch {
60
+ return results;
61
+ }
62
+ const enabled = new Set(Object.entries(config?.plugins ?? {}).filter(([, v]) => v).map(([k]) => k));
63
+ for (const [pluginKey, regEntry] of Object.entries(registry.plugins ?? {})) {
64
+ if (!enabled.has(pluginKey) || !regEntry?.path) continue;
65
+ try {
66
+ const pj = await loadPluginJson(regEntry.path);
67
+ for (const [runeKey, runeDef] of Object.entries(pj.runes ?? {})) {
68
+ if (!isNativeRune(runeDef)) continue;
69
+ const digest = trustDigest(regEntry.path, runeDef);
70
+ const state = trustState(regEntry, runeKey, digest);
71
+ if (state === "trusted") {
72
+ results.push({ ok: true, message: `plugin ${pluginKey}:${runeKey} native script trusted` });
73
+ } else if (state === "changed") {
74
+ results.push({ ok: false, message: `plugin ${pluginKey}:${runeKey} changed since trusted (run: crunes plugin trust ${pluginKey} ${runeKey})` });
75
+ } else {
76
+ results.push({ ok: false, message: `plugin ${pluginKey}:${runeKey} runs natively outside sandbox and is not yet trusted (run: crunes plugin trust ${pluginKey} ${runeKey})` });
77
+ }
78
+ }
79
+ } catch {
80
+ }
81
+ }
82
+ return results;
83
+ }
84
+ function checkRunBlockRunes(config, projectRoot) {
85
+ const results = [];
86
+ for (const [key, entry] of Object.entries(config?.runes ?? {})) {
87
+ if (entry?.run == null) continue;
88
+ const run = typeof entry.run === "string" ? { command: entry.run } : entry.run;
89
+ if (!run?.command) continue;
90
+ const desc = describeRunBlock(entry, projectRoot);
91
+ if (desc.runtime === "isolate") {
92
+ results.push({ ok: true, message: `${key} \u2192 isolate` });
93
+ continue;
94
+ }
95
+ try {
96
+ if (desc.runtime === "program") {
97
+ if (!onPath(desc.command)) throw new Error(`"${desc.command}" is not on PATH`);
98
+ } else if (!existsSync(desc.command)) {
99
+ throw new Error(`${relative(projectRoot, desc.command).replace(/\\/g, "/")} does not exist`);
100
+ }
101
+ assertNotMissedRename(desc.command, desc.runtime, projectRoot);
102
+ if (desc.argsModule && /\.json$/i.test(desc.argsModule)) {
103
+ loadJsonSchema(desc.argsModule, relative(projectRoot, desc.argsModule).replace(/\\/g, "/"));
104
+ }
105
+ const found = resolveInterpreter(desc.runtime, projectRoot);
106
+ const how = found ? `${desc.runtime}: ${[found.command, ...found.args].join(" ")}` : desc.runtime === "program" ? `program: ${onPath(desc.command)}` : `${desc.runtime}: run directly`;
107
+ results.push({ ok: true, message: `${key} \u2192 ${how} (native)` });
108
+ } catch (err) {
109
+ results.push({ ok: false, message: `${key}: ${err.message}` });
110
+ }
111
+ }
112
+ return results;
113
+ }
114
+ var KNOWN_FORMATS = /* @__PURE__ */ new Set(["1"]);
115
+ function collectLayerWarnings({ global = {}, project = {} } = {}) {
116
+ const warnings = [];
117
+ for (const key of Object.keys(project.runes ?? {})) {
118
+ if (global.runes?.[key]) {
119
+ warnings.push(`rune "${key}" shadows the global rune of the same name`);
120
+ }
121
+ }
122
+ const globalPlugins = coercePlugins(global.plugins);
123
+ const projectPlugins = coercePlugins(project.plugins);
124
+ for (const [key, enabled] of Object.entries(projectPlugins)) {
125
+ if (globalPlugins[key] === true && enabled === false) {
126
+ warnings.push(`plugin "${key}" is enabled globally but disabled in this project`);
127
+ }
128
+ }
129
+ return warnings;
130
+ }
131
+ async function handler({ projectRoot = process.cwd() } = {}) {
132
+ let anyFailed = false;
133
+ const major = parseInt(process.versions.node.split(".")[0], 10);
134
+ if (major >= 22) {
135
+ output.success(`Node.js v${process.versions.node}`);
136
+ } else {
137
+ output.error(`Node.js v${process.versions.node} \u2014 requires >= 22`);
138
+ anyFailed = true;
139
+ }
140
+ const versionResult = spawnSync("crunes", ["--version"], { encoding: "utf8", shell: true });
141
+ if (versionResult.status === 0) {
142
+ output.success(`crunes ${versionResult.stdout.trim()} in PATH`);
143
+ } else {
144
+ output.warn("crunes not found globally in PATH (you can still run it locally or via npx)");
145
+ }
146
+ let config;
147
+ try {
148
+ config = loadConfig(projectRoot);
149
+ } catch (err) {
150
+ output.error(`Config: ${err.message}`);
151
+ anyFailed = true;
152
+ }
153
+ if (config) {
154
+ const runeCount = Object.keys(config.runes ?? {}).length;
155
+ if (config.format !== void 0 && !KNOWN_FORMATS.has(String(config.format))) {
156
+ output.error(`Config format "${config.format}" not recognised by this CLI version`);
157
+ anyFailed = true;
158
+ } else {
159
+ output.success(`Config valid \u2014 ${runeCount} rune${runeCount === 1 ? "" : "s"} registered`);
160
+ }
161
+ for (const { ok, message } of checkRunBlockRunes(config, projectRoot)) {
162
+ if (ok) output.success(message);
163
+ else {
164
+ output.error(message);
165
+ anyFailed = true;
166
+ }
167
+ }
168
+ for (const { ok, message } of await checkPluginNativeTrust(config)) {
169
+ if (ok) output.success(message);
170
+ else {
171
+ output.info(message);
172
+ }
173
+ }
174
+ }
175
+ const globalPath = getConfigPath({ global: true });
176
+ let globalRaw = null;
177
+ try {
178
+ globalRaw = readRawConfig(globalPath);
179
+ } catch {
180
+ }
181
+ if (process.env.CRUNES_NO_GLOBAL === "1") {
182
+ output.warn("Global config skipped (CRUNES_NO_GLOBAL=1)");
183
+ } else if (globalRaw) {
184
+ output.success(`Global config found at ${globalPath}`);
185
+ } else {
186
+ output.info(`No global config at ${globalPath}`);
187
+ }
188
+ let projectRaw = null;
189
+ try {
190
+ projectRaw = readRawConfig(getConfigPath({ configRoot: projectRoot }));
191
+ } catch {
192
+ }
193
+ if (!projectRaw) {
194
+ output.info("No project config \u2014 crunes runs rootless here, writing no local state");
195
+ }
196
+ for (const warning of collectLayerWarnings({ global: globalRaw ?? {}, project: projectRaw ?? {} })) {
197
+ output.warn(warning);
198
+ }
199
+ if (anyFailed) {
200
+ process.exit(1);
201
+ }
202
+ }
203
+ export {
204
+ checkPluginNativeTrust,
205
+ checkRunBlockRunes,
206
+ collectLayerWarnings,
207
+ handler
208
+ };
@@ -1,13 +1,17 @@
1
1
  import {
2
2
  getConfigPath,
3
3
  setPluginEnabled
4
- } from "./chunk-X7PZN73N.js";
5
- import "./chunk-QYRF3R35.js";
4
+ } from "./chunk-SUCYDYMU.js";
5
+ import "./chunk-2FI6KN3C.js";
6
+ import "./chunk-UBCAZGLE.js";
6
7
  import {
7
8
  loadRegistry,
8
9
  resolvePluginKey
9
- } from "./chunk-VST6HAB6.js";
10
+ } from "./chunk-MTJ2KW3V.js";
11
+ import "./chunk-VP7YLCQP.js";
12
+ import "./chunk-YKIKJHYO.js";
10
13
  import "./chunk-2Q3KLBE6.js";
14
+ import "./chunk-55GTJG5I.js";
11
15
  import {
12
16
  init_require_shim
13
17
  } from "./chunk-TPK5AGRA.js";
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  getConfigPath
3
- } from "./chunk-X7PZN73N.js";
4
- import "./chunk-QYRF3R35.js";
3
+ } from "./chunk-SUCYDYMU.js";
5
4
  import {
6
5
  output
7
6
  } from "./chunk-MIKWIFYR.js";
@@ -12,7 +11,12 @@ import {
12
11
  ye
13
12
  } from "./chunk-CGZL5SSH.js";
14
13
  import "./chunk-WCODTMDN.js";
14
+ import "./chunk-2FI6KN3C.js";
15
+ import "./chunk-UBCAZGLE.js";
16
+ import "./chunk-VP7YLCQP.js";
17
+ import "./chunk-YKIKJHYO.js";
15
18
  import "./chunk-2Q3KLBE6.js";
19
+ import "./chunk-55GTJG5I.js";
16
20
  import {
17
21
  init_require_shim
18
22
  } from "./chunk-TPK5AGRA.js";
@@ -3,17 +3,22 @@ import {
3
3
  } from "./chunk-YVN3VDRE.js";
4
4
  import {
5
5
  installPlugin
6
- } from "./chunk-34F4ZURL.js";
7
- import "./chunk-X7PZN73N.js";
8
- import "./chunk-QYRF3R35.js";
6
+ } from "./chunk-RVBAAXRY.js";
7
+ import "./chunk-SUCYDYMU.js";
9
8
  import {
10
9
  output
11
10
  } from "./chunk-MIKWIFYR.js";
12
11
  import "./chunk-CGZL5SSH.js";
13
12
  import "./chunk-WCODTMDN.js";
14
- import "./chunk-VST6HAB6.js";
13
+ import "./chunk-XDMMSZIL.js";
14
+ import "./chunk-2FI6KN3C.js";
15
+ import "./chunk-UBCAZGLE.js";
16
+ import "./chunk-MTJ2KW3V.js";
17
+ import "./chunk-FIAFVIAN.js";
18
+ import "./chunk-VP7YLCQP.js";
19
+ import "./chunk-YKIKJHYO.js";
15
20
  import "./chunk-2Q3KLBE6.js";
16
- import "./chunk-G3U4V32O.js";
21
+ import "./chunk-55GTJG5I.js";
17
22
  import {
18
23
  init_require_shim
19
24
  } from "./chunk-TPK5AGRA.js";
@@ -2519,12 +2519,12 @@ async function compileIntro() {
2519
2519
  lines.push("");
2520
2520
  lines.push("Crunes execute inside an isolated sandbox (`isolated-vm`). Runes are ESM modules with two primary execution modes: **run** (one-shot) and **repl** (interactive session).");
2521
2521
  lines.push("");
2522
- lines.push("Scaffold a new rune with `crunes create`. In non-interactive/agent sessions `--format` is required (no default); `--path` defaults to `.crunes/runes/<key>.js` if omitted. `-y`/`--yes` is a global flag, so it goes **before** the subcommand:");
2522
+ lines.push("Scaffold a new rune with `crunes create`. In non-interactive/agent sessions `--format` is required (no default); `--path` defaults to `.crunes/runes/<key>.rune.js` if omitted \u2014 the `.rune.js` suffix is what runs a file in the isolate. `-y`/`--yes` is a global flag, so it goes **before** the subcommand:");
2523
2523
  lines.push("```bash");
2524
2524
  lines.push("crunes -y create my-rune --format markdown");
2525
2525
  lines.push("```");
2526
2526
  lines.push("");
2527
- lines.push("`crunes create` does not write a `permissions` block. Grants live in `.crunes/config.json` under `runes.<key>.permissions.<lifecycle>.allow` \u2014 not in the rune file \u2014 so add them there once you know what the rune touches (section 3).");
2527
+ lines.push("`crunes create` does not write a `permissions` block. Grants live in `.crunes/config.json` under `runes.<key>.run.permissions.allow` \u2014 not in the rune file \u2014 so add them there once you know what the rune touches (section 3).");
2528
2528
  lines.push("");
2529
2529
  lines.push('**Run mode** \u2014 export `args` to declare a schema and `run` to execute. `--help`/`-h` is NOT intercepted by `crunes run` \u2014 declare it yourself and check it at the top of `run(args)`, as shown below. This example also shows `args(builder)` reading `vars` at schema-build time to compute a dynamic option (`--profile`), a common pattern for anything with a "profile"/"environment" concept:');
2530
2530
  lines.push("");
@@ -2633,39 +2633,38 @@ async function compileIntro() {
2633
2633
  lines.push("");
2634
2634
  lines.push("Configuration properties in `.crunes/config.json` control permissions, default variables, mappings, and plugin registration.");
2635
2635
  lines.push("");
2636
- lines.push("`crunes init` also scaffolds a `.crunes/.gitignore` covering local-only files (`config.local.json`, `project.local.json`) and generated directories (`logs/`, `caches/`, `schemas/`, `sqlite/`, `jobs/`) \u2014 only `config.json` and your rune `.js` files need to be committed.");
2636
+ lines.push("`crunes init` also scaffolds a `.crunes/.gitignore` covering local-only files (`config.local.json`, `project.local.json`) and generated directories (`logs/`, `caches/`, `schemas/`, `sqlite/`, `jobs/`) \u2014 only `config.json` and your rune `.rune.js` files need to be committed.");
2637
2637
  lines.push("");
2638
2638
  lines.push("### Sandbox Security & Permissions");
2639
- lines.push("Runes do not have direct access to Node.js APIs. They declare specific lifecycle-scoped permission scopes nested inside their own entry in `.crunes/config.json`:");
2639
+ lines.push("Runes do not have direct access to Node.js APIs. A rune entry names its module in a `run` block, and the grants for it inside that block in `.crunes/config.json`. Nothing is found by convention: a rune runs only the module its entry names.");
2640
2640
  lines.push("```json");
2641
2641
  lines.push("{");
2642
2642
  lines.push(' "runes": {');
2643
2643
  lines.push(' "my-rune": {');
2644
2644
  lines.push(' "name": "My Rune",');
2645
2645
  lines.push(' "description": "Does something useful",');
2646
- lines.push(' "path": ".crunes/runes/my-rune.js",');
2647
2646
  lines.push(' "vars": { "api_url": "https://example.com" },');
2648
- lines.push(' "permissions": {');
2649
- lines.push(' "run": { "allow": ["fs.read:src/**", "fs.write:dist/**", "shell.run:git *"] }');
2647
+ lines.push(' "run": {');
2648
+ lines.push(' "command": ".crunes/runes/my-rune.rune.js",');
2649
+ lines.push(' "permissions": { "allow": ["fs.read:src/**", "fs.write:dist/**", "shell.run:git *"] }');
2650
2650
  lines.push(" }");
2651
2651
  lines.push(" }");
2652
2652
  lines.push(" }");
2653
2653
  lines.push("}");
2654
2654
  lines.push("```");
2655
2655
  lines.push("");
2656
- lines.push("For runes that use both `run` and `repl`, declare both permission namespaces separately \u2014 `repl` does not inherit from `run`:");
2656
+ lines.push("A rune has a REPL only when its entry declares a `repl` block, with its own grants \u2014 `repl` does not inherit from `run`:");
2657
2657
  lines.push("```json");
2658
2658
  lines.push("{");
2659
2659
  lines.push(' "runes": {');
2660
2660
  lines.push(' "my-shell": {');
2661
- lines.push(' "permissions": {');
2662
- lines.push(' "run": { "allow": ["sqlite.read:./state::db"] },');
2663
- lines.push(' "repl": { "allow": ["sqlite.read:./state::db", "sqlite.write:./state::db"] }');
2664
- lines.push(" }");
2661
+ lines.push(' "run": { "command": ".crunes/runes/my-shell.rune.js", "permissions": { "allow": ["sqlite.read:./state::db"] } },');
2662
+ lines.push(' "repl": { "command": ".crunes/runes/my-shell.rune.js", "permissions": { "allow": ["sqlite.read:./state::db", "sqlite.write:./state::db"] } }');
2665
2663
  lines.push(" }");
2666
2664
  lines.push(" }");
2667
2665
  lines.push("}");
2668
2666
  lines.push("```");
2667
+ lines.push('A block written as a string is shorthand for `{ "command": \u2026 }`. An entry in the old shape \u2014 `path`, `permissions.run`, or none at all relying on `.crunes/runes/<key>.js` \u2014 is refused; `crunes migrate` rewrites every entry and renames the modules.');
2669
2668
  lines.push("");
2670
2669
  lines.push('To grant a **plugin** rune extra permissions or vars from the project side (plugin runes have no `runes.<key>` entry of their own), add an entry keyed by the fully-qualified `"marketplace@plugin:runeKey"` string \u2014 **this must always be the full form, never the bare plugin name**, since two enabled plugins could share a bare name and a bare-form key can never resolve to anything (config loading rejects a bare-form key outright).');
2671
2670
  lines.push("```json");
@@ -2674,8 +2673,8 @@ async function compileIntro() {
2674
2673
  lines.push(' "runes": {');
2675
2674
  lines.push(' "my-market@my-plugin:deploy": {');
2676
2675
  lines.push(' "vars": { "region": "us-east-1" },');
2677
- lines.push(' "permissions": {');
2678
- lines.push(' "run": { "allow": ["fs.read:src/**"] }');
2676
+ lines.push(' "run": {');
2677
+ lines.push(' "permissions": { "allow": ["fs.read:src/**"] }');
2679
2678
  lines.push(" }");
2680
2679
  lines.push(" }");
2681
2680
  lines.push(" }");
@@ -2695,8 +2694,35 @@ async function compileIntro() {
2695
2694
  lines.push("```");
2696
2695
  lines.push("Now `crunes run git` always resolves to that specific plugin rune, with no ambiguity, regardless of what else is enabled.");
2697
2696
  lines.push("");
2697
+ lines.push("### Script Runes");
2698
+ lines.push("A rune can also be a Node, Python or bash script, or a program on `PATH`. Its `run` block names the script instead of a `*.rune.js` module \u2014 `crunes add <key> <command>` writes one:");
2699
+ lines.push("```json");
2700
+ lines.push("{");
2701
+ lines.push(' "runes": {');
2702
+ lines.push(' "coverage": { "description": "Coverage per module", "run": "tools/coverage.py", "args": ".crunes/runes/coverage.args.rune.js" },');
2703
+ lines.push(' "log": { "description": "Recent commits", "run": { "command": "git", "argv": ["log", "--oneline", "-n", "20"] } },');
2704
+ lines.push(' "api": { "run": { "command": ".crunes/runes/api.rune.js", "permissions": { "allow": ["fs.read:src/**"] } } }');
2705
+ lines.push(" }");
2706
+ lines.push("}");
2707
+ lines.push("```");
2708
+ lines.push("- **`run.command`** is resolved like a shell resolves a command: a value with a path separator, a leading `.`, or an absolute path is a file relative to the config layer; a bare name is a program on `PATH`. A file name selects the runtime: `*.rune.js` runs in the isolate, `.js`/`.mjs`/`.cjs` with Node, `.py` with Python (`CRUNES_PYTHON`, the active virtualenv, a project `.venv/` or `venv/`, then `python3`/`python`), `.sh` with bash; anything else is executed directly. `run.argv` is placed before the caller's arguments.");
2709
+ lines.push("- **Script runes run natively, with full access** \u2014 `run.permissions` is only accepted for a `*.rune.js` module. `crunes list` marks them `native`; `crunes doctor` reports the interpreter each one resolves to.");
2710
+ lines.push("- **A plugin may ship script runes too**, with the same `run` and `args` blocks in its `plugin.json`. Installing the plugin does not make them runnable: each is refused until you review it with `crunes plugin trust <plugin> [rune]`, which shows the command and the script itself and records your trust against exactly that content. A plugin update that changes a script, its command or its schema needs trusting again. Every run of a plugin script says on standard error that it runs natively; the script receives `CRUNES_PLUGIN_ROOT` beside the usual variables.");
2711
+ lines.push("- **`args`** documents and parses a script's arguments: crunes answers `--help`, `crunes docs rune` shows the schema, and the script receives the parsed result as JSON in `CRUNES_ARGS` alongside the raw arguments. It is a JSON schema \u2014 written inline, or in a `.json` file \u2014 or a `*.rune.js` module whose `args(builder)` export builds one. In a JSON schema, an option takes `default`, `required` and `choices`, a positional takes `choices`, and either takes `type` (`string`, `number` or `integer`; values are strings unless declared otherwise); crunes refuses a call that is missing a required argument, uses a value outside its choices, or is not of the declared type, before the script starts. Without an `args` block, arguments pass through unchanged.");
2712
+ lines.push("- **`run.timeout`** \u2014 seconds a rune may run. A script still running is stopped (SIGTERM, then SIGKILL five seconds later, with the processes it started) and ends with status 124 when run on its own, or fails the rune when captured; an isolate module's timeout replaces the default 30 seconds. A script has no timeout unless its entry declares one.");
2713
+ lines.push('- **`run.pass: "mapped"`** makes the schema the rune\'s whole surface: a call with an option or argument the schema does not declare is refused, and the parsed call is rewritten into the program\'s own arguments instead of being passed raw. Each positional, option or command may declare `to` \u2014 the program tokens it becomes, with `{value}` for its value, e.g. `{ "flags": "--limit <n>", "type": "integer", "to": ["-n", "{value}"] }`; without `to`, an option is passed as its own flag. The order is `run.argv`, the matched command path, the options as declared, then the positionals.');
2714
+ lines.push("```json");
2715
+ lines.push('"args": {');
2716
+ lines.push(' "positionals": [{ "spec": "<module>", "description": "Module to report on", "choices": ["auth", "billing"] }],');
2717
+ lines.push(' "options": [{ "flags": "--min <percent>", "description": "Fail below this", "default": "0" }]');
2718
+ lines.push("}");
2719
+ lines.push("```");
2720
+ lines.push('- **`run.output: "sections"`** lets a script print named sections: each standard-output line shaped like a `--format jsonl` section event \u2014 `{"type":"section","section":{"name":"summary","data":{"type":"markdown","content":"\u2026"}}}` \u2014 becomes a section as soon as it is printed, filterable with `-s`; any other line is plain text. Run on its own, a script\'s sections print as markdown; in a batch or JSONL they are labelled like any rune\'s.');
2721
+ lines.push("- **`crunes create --lang python|bash|node <key>`** scaffolds a script rune; `crunes add <key> <command>` registers one that already exists.");
2722
+ lines.push("- **Run on its own, a script rune gets the caller's terminal and standard streams and returns its own exit code.** In a batch, `--format jsonl` or `rune.exec`, its standard output is captured as an `output` section and a non-zero exit fails it. Every script also receives `CRUNES_PROJECT_ROOT`, `CRUNES_RUNE_KEY`, `CRUNES_LIFECYCLE`, and `CRUNES_VARS` \u2014 the rune's configured `vars` as a JSON object.");
2723
+ lines.push("");
2698
2724
  lines.push("### Config File Fields Reference");
2699
- lines.push('- **`runes`**: Definition of project-registered runes, keyed by rune key (or the fully-qualified `"marketplace@plugin:runeKey"` string for a plugin-rune override \u2014 never a bare plugin name). Each entry may declare `path`, `name`, `description`, `vars` (key-value settings read via `utils.vars.read(key)`), `permissions` (lifecycle-scoped allow/deny lists), or `plugin` (an alias to a specific plugin rune, see above).');
2725
+ lines.push('- **`runes`**: Definition of project-registered runes, keyed by rune key (or the fully-qualified `"marketplace@plugin:runeKey"` string for a plugin-rune override \u2014 never a bare plugin name). Each entry declares a `run` block (and optionally `args` \u2014 see Script Runes \u2014 and `repl`), `name`, `description` and `vars` (key-value settings read via `utils.vars.read(key)`); or `plugin` (an alias to a specific plugin rune, see above). Grants live inside the `run` and `repl` blocks as `{ "allow": [...], "deny": [...] }`; a plugin alias or `marketplace@plugin:rune` override may carry blocks with only `permissions`.');
2700
2726
  lines.push('- **`plugins`**: Map of plugin key to a boolean, e.g. `{"my-market@my-plugin": true}`. A legacy array of keys is still read and is converted to map form on the next write. `false` is meaningful: it turns a plugin off in this layer even though a lower layer enabled it.');
2701
2727
  lines.push("- **`templates`**: Definition of registered templates, keyed by template name, merged across layers exactly like `runes`.");
2702
2728
  lines.push("");
@@ -2707,10 +2733,10 @@ async function compileIntro() {
2707
2733
  lines.push("2. <project>/.crunes/config.json");
2708
2734
  lines.push("3. <project>/.crunes/config.local.json");
2709
2735
  lines.push("```");
2710
- lines.push("`~/.crunes` **is** the global config directory, so global paths carry no `.crunes/` segment: a global rune lives at `~/.crunes/runes/<key>.js`, not `~/.crunes/.crunes/runes/<key>.js`. Each layer resolves its own paths before merging, so a project can override one field of a global rune and still load the global file:");
2736
+ lines.push("`~/.crunes` **is** the global config directory, so global paths carry no `.crunes/` segment: a global rune's module is written `runes/<key>.rune.js` and lives at `~/.crunes/runes/<key>.rune.js`. Each layer resolves its own files before merging, so a project can override one field of a global rune and still load the global file:");
2711
2737
  lines.push("```json");
2712
2738
  lines.push("// ~/.crunes/config.json");
2713
- lines.push('{ "runes": { "serve": { "path": "runes/serve.js", "vars": { "port": 3000 } } } }');
2739
+ lines.push('{ "runes": { "serve": { "run": "runes/serve.rune.js", "vars": { "port": 3000 } } } }');
2714
2740
  lines.push("");
2715
2741
  lines.push("// <project>/.crunes/config.json \u2014 same rune, different port");
2716
2742
  lines.push('{ "runes": { "serve": { "vars": { "port": 4000 } } } }');
@@ -2730,7 +2756,7 @@ async function compileIntro() {
2730
2756
  lines.push("`-g` / `--global` targets the global config instead of the project:");
2731
2757
  lines.push("```bash");
2732
2758
  lines.push("crunes init -g # create ~/.crunes/config.json");
2733
- lines.push("crunes create -g serve # write ~/.crunes/runes/serve.js and register it");
2759
+ lines.push("crunes create -g serve # write ~/.crunes/runes/serve.rune.js and register it");
2734
2760
  lines.push("crunes plugin install -g mkt@plug # install and enable everywhere");
2735
2761
  lines.push("crunes plugin enable -g plug");
2736
2762
  lines.push("crunes plugin disable plug # opt this project out of a global enable");