@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
@@ -3,10 +3,7 @@ import {
3
3
  readRawConfig,
4
4
  setPluginEnabled,
5
5
  writeRawConfig
6
- } from "./chunk-X7PZN73N.js";
7
- import {
8
- coercePlugins
9
- } from "./chunk-QYRF3R35.js";
6
+ } from "./chunk-SUCYDYMU.js";
10
7
  import {
11
8
  output
12
9
  } from "./chunk-MIKWIFYR.js";
@@ -14,19 +11,29 @@ import {
14
11
  R,
15
12
  le
16
13
  } from "./chunk-CGZL5SSH.js";
14
+ import {
15
+ isNativeRune
16
+ } from "./chunk-XDMMSZIL.js";
17
+ import {
18
+ coercePlugins
19
+ } from "./chunk-2FI6KN3C.js";
17
20
  import {
18
21
  loadRegistry,
19
22
  registerPlugin,
20
23
  removePlugin
21
- } from "./chunk-VST6HAB6.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";
22
32
  import {
23
33
  ensureStoreDirs,
24
34
  getPluginCacheDir,
25
35
  getPnpmStorePath
26
36
  } from "./chunk-2Q3KLBE6.js";
27
- import {
28
- loadPluginJson
29
- } from "./chunk-G3U4V32O.js";
30
37
  import {
31
38
  init_require_shim
32
39
  } from "./chunk-TPK5AGRA.js";
@@ -141,14 +148,24 @@ function formatConsentScreen(pluginName, pluginJson) {
141
148
  const lines = [`${pluginName} requests the following permissions:
142
149
  `];
143
150
  for (const [runeKey, rune] of Object.entries(pluginJson.runes)) {
144
- const allow = collectAllow(rune.permissions);
151
+ const allow = collectAllow(scopedPermissions(rune));
145
152
  if (allow.length === 0) continue;
146
153
  lines.push(` ${runeKey}`);
147
154
  for (const perm of allow) {
148
- 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
+ }
149
160
  }
150
161
  lines.push("");
151
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
+ }
152
169
  return lines.join("\n");
153
170
  }
154
171
  async function promptConsent(pluginName, pluginJson, { yes = false } = {}) {
@@ -162,7 +179,7 @@ async function promptConsent(pluginName, pluginJson, { yes = false } = {}) {
162
179
  function diffPermissions(oldConsented, newPluginJson) {
163
180
  const added = {};
164
181
  for (const [runeKey, rune] of Object.entries(newPluginJson.runes)) {
165
- const newPerms = collectAllow(rune.permissions);
182
+ const newPerms = collectAllow(scopedPermissions(rune));
166
183
  const oldPerms = oldConsented[runeKey] ?? [];
167
184
  const newOnes = newPerms.filter((perm) => !oldPerms.includes(perm));
168
185
  if (newOnes.length > 0) added[runeKey] = newOnes;
@@ -191,7 +208,7 @@ async function promptReConsent(pluginName, diff, { yes = false } = {}) {
191
208
  var execFileAsync2 = promisify2(execFile2);
192
209
  function collectAllowFromRune(rune) {
193
210
  const all = [];
194
- for (const lifecycle of Object.values(rune.permissions ?? {})) {
211
+ for (const lifecycle of Object.values(scopedPermissions(rune) ?? {})) {
195
212
  for (const perm of lifecycle?.allow ?? []) {
196
213
  if (!all.includes(perm)) all.push(perm);
197
214
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  coercePlugins
3
- } from "./chunk-QYRF3R35.js";
3
+ } from "./chunk-2FI6KN3C.js";
4
4
  import {
5
5
  getStorePath
6
6
  } from "./chunk-2Q3KLBE6.js";
@@ -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
+ };
@@ -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
+ };
@@ -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
+ };
@@ -0,0 +1,94 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/core/rune-entry.js
6
+ init_require_shim();
7
+ import { existsSync, readFileSync } from "node:fs";
8
+ import { join, isAbsolute } from "node:path";
9
+ var ISOLATE_MODULE = /\.rune\.m?js$/i;
10
+ var REPL_EXPORT = /\bexport\s+(?:async\s+)?(?:function\s*\*?\s*|const\s+|let\s+|var\s+)repl\b|\bexport\s*\{[^}]*\brepl\b[^}]*\}/;
11
+ function blockOf(entry, name) {
12
+ const block2 = entry?.[name];
13
+ if (block2 == null) return null;
14
+ return typeof block2 === "string" ? { command: block2 } : block2;
15
+ }
16
+ function scopedPermissions(entry) {
17
+ const out = {};
18
+ for (const mode of ["run", "repl"]) {
19
+ const permissions = blockOf(entry, mode)?.permissions;
20
+ if (permissions) out[mode] = permissions;
21
+ }
22
+ return Object.keys(out).length ? out : void 0;
23
+ }
24
+ function blockModule(entry, mode, base) {
25
+ const command = blockOf(entry, mode)?.command;
26
+ if (!command) return null;
27
+ return isAbsolute(command) ? command : join(base, command);
28
+ }
29
+ function isolateName(file) {
30
+ if (ISOLATE_MODULE.test(file)) return file;
31
+ return file.replace(/\.(m?js)$/i, ".rune.$1");
32
+ }
33
+ function exportsRepl(file) {
34
+ try {
35
+ return REPL_EXPORT.test(readFileSync(file, "utf8"));
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+ function block(command, permissions) {
41
+ return permissions ? { ...command && { command }, permissions } : command;
42
+ }
43
+ function migrateEntry(entry, { base, defaultFile }) {
44
+ if (entry == null || typeof entry !== "object" || Array.isArray(entry)) return null;
45
+ const perms = entry.permissions;
46
+ const isV1 = entry.path !== void 0 || perms !== void 0 || entry.run == null && entry.plugin == null && defaultFile && existsSync(join(base, defaultFile));
47
+ if (!isV1) return null;
48
+ const renames = [];
49
+ const file = entry.path ?? (entry.plugin == null && defaultFile && existsSync(join(base, defaultFile)) ? defaultFile : null);
50
+ const blocks = {};
51
+ if (file) {
52
+ const command = isolateName(file);
53
+ if (command !== file) renames.push({ from: file, to: command });
54
+ const absolute = isAbsolute(file) ? file : join(base, file);
55
+ blocks.run = block(command, perms?.run);
56
+ if (perms?.repl || exportsRepl(absolute)) blocks.repl = block(command, perms?.repl);
57
+ } else {
58
+ if (perms?.run) blocks.run = { permissions: perms.run };
59
+ if (perms?.repl) blocks.repl = { permissions: perms.repl };
60
+ }
61
+ const out = {};
62
+ let placed = false;
63
+ for (const [key, value] of Object.entries(entry)) {
64
+ if (key === "path" || key === "permissions") {
65
+ if (!placed) {
66
+ Object.assign(out, blocks);
67
+ placed = true;
68
+ }
69
+ continue;
70
+ }
71
+ out[key] = value;
72
+ }
73
+ if (!placed) Object.assign(out, blocks);
74
+ return { entry: out, renames };
75
+ }
76
+ function v1EntryError(fileName, where, rewritten) {
77
+ return new Error(
78
+ `${fileName}: ${where} uses the old entry shape (path / permissions.run / an implicit REPL), which is no longer read. Rewritten, it is:
79
+
80
+ ${JSON.stringify(rewritten.entry, null, 2).replace(/^/gm, " ")}
81
+ ` + (rewritten.renames.length ? `
82
+ and the module is renamed: ${rewritten.renames.map((r) => `${r.from} \u2192 ${r.to}`).join(", ")}
83
+ ` : "") + `
84
+ Run \`crunes migrate\` to rewrite every entry and rename the modules.`
85
+ );
86
+ }
87
+
88
+ export {
89
+ blockOf,
90
+ scopedPermissions,
91
+ blockModule,
92
+ migrateEntry,
93
+ v1EntryError
94
+ };
@@ -25,8 +25,9 @@ function pluginJson({ name, description, author, license }) {
25
25
  example: {
26
26
  name: "Example Rune",
27
27
  description: "Replace with your rune description",
28
- permissions: {
29
- run: {
28
+ run: {
29
+ command: "runes/example.rune.js",
30
+ permissions: {
30
31
  allow: [],
31
32
  deny: []
32
33
  }
@@ -62,8 +63,7 @@ function exampleRune() {
62
63
  return `// Ready-to-run rune \u2014 runs directly from the plugin install location.
63
64
  // Users activate it by adding your plugin to their project config.
64
65
  //
65
- // permissions (plugin.json):
66
- // run:
66
+ // permissions (plugin.json, inside this rune's run block):
67
67
  // allow: [] \u2014 add patterns like fs.read:./** if you use utils.fs
68
68
  // deny: []
69
69
 
@@ -216,7 +216,7 @@ async function handler({
216
216
  const files = [
217
217
  [join(outDir, ".crunes-plugin", "plugin.json"), pluginJson(opts)],
218
218
  [join(outDir, ".crunes-plugin", "marketplace.json"), marketplaceJson(opts)],
219
- [join(outDir, "runes", "example.js"), exampleRune()],
219
+ [join(outDir, "runes", "example.rune.js"), exampleRune()],
220
220
  [join(outDir, "templates", "example-template.js"), exampleTemplate()],
221
221
  [join(outDir, "README.md"), readmeMd(opts)],
222
222
  [join(outDir, "CHANGELOG.md"), changelogMd()]