@darkrymit/crunes-cli 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/add-2OM5KGN5.js +67 -0
- package/dist/chunks/{apply-YY7MIM64.js → apply-GBUQQ4XF.js} +21 -9
- package/dist/chunks/{benchmark-BQNMULOO.js → benchmark-QWGVX3BX.js} +21 -15
- package/dist/chunks/chunk-2DNYVKBF.js +109 -0
- package/dist/chunks/chunk-2HM5Q52B.js +131 -0
- package/dist/chunks/chunk-3KKRNQQU.js +275 -0
- package/dist/chunks/chunk-55GTJG5I.js +1154 -0
- package/dist/chunks/chunk-7KYCYDAS.js +325 -0
- package/dist/chunks/{chunk-SNC7AOT7.js → chunk-AL37NFWR.js} +45 -94
- package/dist/chunks/chunk-ARIFLX5E.js +9525 -0
- package/dist/chunks/{chunk-X7PZN73N.js → chunk-E7CZPAM2.js} +1 -1
- package/dist/chunks/chunk-EO3CSXWK.js +70 -0
- package/dist/chunks/chunk-FIAFVIAN.js +79 -0
- package/dist/chunks/{chunk-MRNZFUXZ.js → chunk-KQMTTEJV.js} +22 -7
- package/dist/chunks/chunk-KX6QEHM5.js +578 -0
- package/dist/chunks/{chunk-VST6HAB6.js → chunk-MTJ2KW3V.js} +2 -0
- package/dist/chunks/chunk-MUWDZJN2.js +71 -0
- package/dist/chunks/{chunk-CY6C6ADU.js → chunk-MVCBPI4J.js} +45 -478
- package/dist/chunks/{chunk-34F4ZURL.js → chunk-NJVPLN5D.js} +29 -12
- package/dist/chunks/chunk-UBCAZGLE.js +15 -0
- package/dist/chunks/chunk-VP7YLCQP.js +244 -0
- package/dist/chunks/chunk-VSMAZISQ.js +303 -0
- package/dist/chunks/chunk-WE4HDHFU.js +37 -0
- package/dist/chunks/{create-ET6DT5ZE.js → create-2CQZF53Z.js} +5 -2
- package/dist/chunks/{create-LM7U3CJS.js → create-36F6V4WP.js} +99 -6
- package/dist/chunks/{create-TLPM7HJE.js → create-DXW4YYLJ.js} +5 -5
- package/dist/chunks/{disable-TNTEIAKO.js → disable-FB64CSYV.js} +5 -2
- package/dist/chunks/doctor-PVO4JLYN.js +208 -0
- package/dist/chunks/{enable-GUQCB4CU.js → enable-UVXHTKCJ.js} +6 -3
- package/dist/chunks/{init-PJSCFOC6.js → init-GPNC7TR5.js} +5 -2
- package/dist/chunks/{install-4YP7FALO.js → install-3G7U5ZIO.js} +10 -5
- package/dist/chunks/{intro-SA7MWV3Z.js → intro-YI5HUZCF.js} +45 -19
- package/dist/chunks/{list-WKNPZZOV.js → list-J2UCBYAY.js} +9 -6
- package/dist/chunks/list-JB4447YK.js +62 -0
- package/dist/chunks/{list-7R6NASFI.js → list-W4JAYPAA.js} +19 -19
- package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
- package/dist/chunks/{registry-K5DV5NAK.js → registry-IWP7JMNI.js} +1 -1
- package/dist/chunks/{repl-ZB3DIJ4K.js → repl-MWFEZ65P.js} +30 -20
- package/dist/chunks/resolver-URPQMOIV.js +36 -0
- package/dist/chunks/{run-22B65ZWZ.js → run-3VKWSRLO.js} +17 -11
- package/dist/chunks/rune-L5EP645W.js +283 -0
- package/dist/chunks/runner-VPTLUQJE.js +34 -0
- package/dist/chunks/{shell-explain-QLITLHW7.js → shell-explain-LKBBP2BG.js} +5 -2
- package/dist/chunks/trust-LXXYSF6W.js +109 -0
- package/dist/chunks/{uninstall-4WR5IHLC.js → uninstall-J7JUYETA.js} +10 -5
- package/dist/chunks/{update-ACLDK6E6.js → update-ZJRLDCUT.js} +10 -5
- package/dist/chunks/{version-EULYWNXN.js → version-ZULO6CV3.js} +2 -2
- package/dist/cli.js +47 -34
- package/package.json +2 -2
- package/dist/chunks/chunk-G3U4V32O.js +0 -46
- package/dist/chunks/chunk-QYRF3R35.js +0 -154
- package/dist/chunks/chunk-YXCHIMLW.js +0 -75308
- package/dist/chunks/doctor-VXAQYMTR.js +0 -101
- package/dist/chunks/list-OMMZAQ23.js +0 -28
- package/dist/chunks/resolver-QIYYFIDX.js +0 -34
- package/dist/chunks/rune-SYK4N642.js +0 -425
- package/dist/chunks/{delete-5R3WBLVD.js → delete-2EXPFBFC.js} +4 -4
- package/dist/chunks/{delete-U4STA2QZ.js → delete-MJAECXXV.js} +4 -4
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPathCommand
|
|
3
|
+
} from "./chunk-UBCAZGLE.js";
|
|
4
|
+
import {
|
|
5
|
+
isInlineSchema,
|
|
6
|
+
normaliseJsonSchema
|
|
7
|
+
} from "./chunk-VP7YLCQP.js";
|
|
8
|
+
import {
|
|
9
|
+
getStorePath
|
|
10
|
+
} from "./chunk-2Q3KLBE6.js";
|
|
11
|
+
import {
|
|
12
|
+
init_require_shim
|
|
13
|
+
} from "./chunk-TPK5AGRA.js";
|
|
14
|
+
|
|
15
|
+
// src/core/config.js
|
|
16
|
+
init_require_shim();
|
|
17
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
18
|
+
import { join, resolve } from "node:path";
|
|
19
|
+
function isObject(item) {
|
|
20
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
21
|
+
}
|
|
22
|
+
var LAYER = /* @__PURE__ */ Symbol.for("crunes.layer");
|
|
23
|
+
var BLOCKS = ["run", "args", "repl"];
|
|
24
|
+
function absolutizeSection(section, kind, baseDir, layer) {
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const [key, entry] of Object.entries(section)) {
|
|
27
|
+
if (!isObject(entry)) {
|
|
28
|
+
out[key] = entry;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const copy = { ...entry, [LAYER]: layer };
|
|
32
|
+
if (kind === "templates") {
|
|
33
|
+
const isPluginRef = Boolean(entry.plugin) || key.includes(":");
|
|
34
|
+
if (entry.path) copy.path = resolve(baseDir, entry.path);
|
|
35
|
+
else if (layer === "global" && !isPluginRef) copy.path = resolve(baseDir, `templates/${key}.js`);
|
|
36
|
+
out[key] = copy;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
for (const block of BLOCKS) {
|
|
40
|
+
if (entry[block] == null || block === "args" && isInlineSchema(entry[block])) continue;
|
|
41
|
+
const b = typeof entry[block] === "string" ? { command: entry[block] } : { ...entry[block] };
|
|
42
|
+
if (typeof b.command === "string" && (block !== "run" || isPathCommand(b.command))) b.command = resolve(baseDir, b.command);
|
|
43
|
+
copy[block] = b;
|
|
44
|
+
}
|
|
45
|
+
out[key] = copy;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
function absolutizeEntryPaths(config, baseDir, layer) {
|
|
50
|
+
const out = { ...config };
|
|
51
|
+
if (isObject(config.runes)) out.runes = absolutizeSection(config.runes, "runes", baseDir, layer);
|
|
52
|
+
if (isObject(config.templates)) out.templates = absolutizeSection(config.templates, "templates", baseDir, layer);
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
function coercePlugins(plugins) {
|
|
56
|
+
return isObject(plugins) ? { ...plugins } : {};
|
|
57
|
+
}
|
|
58
|
+
function enabledPluginKeys(config) {
|
|
59
|
+
return Object.entries(coercePlugins(config?.plugins)).filter(([, enabled]) => enabled === true).map(([key]) => key);
|
|
60
|
+
}
|
|
61
|
+
function mergeConfigs(shared, local) {
|
|
62
|
+
const merged = { ...shared };
|
|
63
|
+
for (const [key, value] of Object.entries(local)) {
|
|
64
|
+
if (key !== "runes" && key !== "templates" && key !== "plugins") {
|
|
65
|
+
merged[key] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (local.runes) {
|
|
69
|
+
merged.runes = { ...shared.runes };
|
|
70
|
+
for (const [key, localEntry] of Object.entries(local.runes)) {
|
|
71
|
+
const sharedEntry = shared.runes?.[key];
|
|
72
|
+
if (sharedEntry && isObject(sharedEntry) && isObject(localEntry)) {
|
|
73
|
+
merged.runes[key] = {
|
|
74
|
+
...sharedEntry,
|
|
75
|
+
...localEntry,
|
|
76
|
+
vars: { ...sharedEntry.vars, ...localEntry.vars }
|
|
77
|
+
};
|
|
78
|
+
for (const block of BLOCKS) {
|
|
79
|
+
if (isObject(sharedEntry[block]) && isObject(localEntry[block]) && !isInlineSchema(sharedEntry[block]) && !isInlineSchema(localEntry[block])) {
|
|
80
|
+
merged.runes[key][block] = { ...sharedEntry[block], ...localEntry[block] };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
merged.runes[key] = localEntry;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (local.templates) {
|
|
89
|
+
merged.templates = { ...shared.templates };
|
|
90
|
+
for (const [key, localEntry] of Object.entries(local.templates)) {
|
|
91
|
+
const sharedEntry = shared.templates?.[key];
|
|
92
|
+
merged.templates[key] = isObject(sharedEntry) && isObject(localEntry) ? { ...sharedEntry, ...localEntry } : localEntry;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (shared.plugins || local.plugins) {
|
|
96
|
+
merged.plugins = { ...coercePlugins(shared.plugins), ...coercePlugins(local.plugins) };
|
|
97
|
+
}
|
|
98
|
+
return merged;
|
|
99
|
+
}
|
|
100
|
+
var ISOLATE_MODULE = /\.rune\.m?js$/i;
|
|
101
|
+
var RUN_BLOCK_KEYS = ["command", "argv", "permissions", "output", "pass", "timeout"];
|
|
102
|
+
var ARGS_FILE = /\.(rune\.m?js|json)$/i;
|
|
103
|
+
var ARGS_BLOCK_KEYS = ["command", "permissions"];
|
|
104
|
+
var REPL_BLOCK_KEYS = ["command", "permissions"];
|
|
105
|
+
function validateBlockShape(where, block, allowedKeys, fileName) {
|
|
106
|
+
if (typeof block === "string") {
|
|
107
|
+
if (block === "") throw new Error(`${fileName}: ${where} must not be empty`);
|
|
108
|
+
return { command: block };
|
|
109
|
+
}
|
|
110
|
+
if (!isObject(block)) throw new Error(`${fileName}: ${where} must be a command string or an object with "command"`);
|
|
111
|
+
const unknown = Object.keys(block).filter((k) => !allowedKeys.includes(k));
|
|
112
|
+
if (unknown.length) {
|
|
113
|
+
throw new Error(`${fileName}: ${where} has unknown field${unknown.length > 1 ? "s" : ""} ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 allowed: ${allowedKeys.join(", ")}`);
|
|
114
|
+
}
|
|
115
|
+
if (block.command !== void 0 && (typeof block.command !== "string" || block.command === "")) {
|
|
116
|
+
throw new Error(`${fileName}: ${where}.command must be a non-empty string`);
|
|
117
|
+
}
|
|
118
|
+
if (block.permissions != null) {
|
|
119
|
+
const p = block.permissions;
|
|
120
|
+
if (!isObject(p) || Object.keys(p).some((k) => k !== "allow" && k !== "deny")) {
|
|
121
|
+
throw new Error(`${fileName}: ${where}.permissions must be { "allow": [...], "deny": [...] } \u2014 grants in a block are not scoped by lifecycle`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return block;
|
|
125
|
+
}
|
|
126
|
+
function isPluginReference(runeKey, entry) {
|
|
127
|
+
const runCommand = typeof entry.run === "string" ? entry.run : entry.run?.command;
|
|
128
|
+
return entry.plugin != null || runeKey.includes(":") && runCommand === void 0;
|
|
129
|
+
}
|
|
130
|
+
function validateEntry(runeKey, entry, fileName, partial) {
|
|
131
|
+
const at = `runes["${runeKey}"]`;
|
|
132
|
+
if (isPluginReference(runeKey, entry)) {
|
|
133
|
+
if (entry.plugin == null) {
|
|
134
|
+
const pluginPart = runeKey.slice(0, runeKey.indexOf(":"));
|
|
135
|
+
if (!pluginPart.includes("@")) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`${fileName}: ${at} is a plugin-rune override \u2014 but "${pluginPart}" is missing the marketplace prefix. Use the full "marketplace@plugin:${runeKey.slice(runeKey.indexOf(":") + 1)}" form.`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const name of ["run", "repl"]) {
|
|
142
|
+
if (entry[name] == null) continue;
|
|
143
|
+
const b = validateBlockShape(`${at}.${name}`, entry[name], ["command", "permissions"], fileName);
|
|
144
|
+
if (b.command !== void 0) throw new Error(`${fileName}: ${at}.${name} \u2014 a plugin rune's handler comes from the plugin; this entry may only grant permissions`);
|
|
145
|
+
}
|
|
146
|
+
if (entry.args != null) throw new Error(`${fileName}: ${at}.args \u2014 a plugin rune's schema comes from the plugin`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const run = entry.run == null ? null : validateBlockShape(`${at}.run`, entry.run, RUN_BLOCK_KEYS, fileName);
|
|
150
|
+
if (!partial && (run == null || run.command === void 0)) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`${fileName}: ${at} has no run block naming its command in any config layer \u2014 a rune runs only what its entry declares.`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (run?.argv != null && (!Array.isArray(run.argv) || run.argv.some((a) => typeof a !== "string"))) {
|
|
156
|
+
throw new Error(`${fileName}: ${at}.run.argv must be an array of strings`);
|
|
157
|
+
}
|
|
158
|
+
const runIsIsolate = run?.command !== void 0 && ISOLATE_MODULE.test(run.command);
|
|
159
|
+
if (run?.permissions != null && run.command !== void 0 && !runIsIsolate) {
|
|
160
|
+
throw new Error(`${fileName}: ${at}.run.permissions \u2014 "${run.command}" runs natively with full access, so grants would not apply to it. Remove the block, or use a *.rune.js module to run in the sandbox`);
|
|
161
|
+
}
|
|
162
|
+
if (run?.output !== void 0) {
|
|
163
|
+
if (run.output !== "text" && run.output !== "sections") throw new Error(`${fileName}: ${at}.run.output must be "text" or "sections"`);
|
|
164
|
+
if (runIsIsolate) throw new Error(`${fileName}: ${at}.run.output \u2014 an isolate module returns sections itself; output applies to native handlers`);
|
|
165
|
+
}
|
|
166
|
+
if (run?.timeout !== void 0 && !(typeof run.timeout === "number" && Number.isFinite(run.timeout) && run.timeout > 0)) {
|
|
167
|
+
throw new Error(`${fileName}: ${at}.run.timeout must be a number of seconds greater than 0`);
|
|
168
|
+
}
|
|
169
|
+
if (run?.pass !== void 0) {
|
|
170
|
+
if (run.pass !== "raw" && run.pass !== "mapped") throw new Error(`${fileName}: ${at}.run.pass must be "raw" or "mapped"`);
|
|
171
|
+
if (runIsIsolate) throw new Error(`${fileName}: ${at}.run.pass \u2014 an isolate module receives parsed arguments itself; pass applies to native handlers`);
|
|
172
|
+
if (run.pass === "mapped" && entry.args == null && !partial) {
|
|
173
|
+
throw new Error(`${fileName}: ${at}.run.pass is "mapped" but the rune has no args block \u2014 mapped arguments are built from the schema`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (entry.args != null && isInlineSchema(entry.args)) {
|
|
177
|
+
try {
|
|
178
|
+
normaliseJsonSchema(entry.args, `${at}.args`);
|
|
179
|
+
} catch (err) {
|
|
180
|
+
throw new Error(`${fileName}: ${err.message}`);
|
|
181
|
+
}
|
|
182
|
+
if (runIsIsolate) {
|
|
183
|
+
throw new Error(`${fileName}: ${at}.args \u2014 an isolate run module declares its schema with its own args export; an args block is for native handlers`);
|
|
184
|
+
}
|
|
185
|
+
} else if (entry.args != null) {
|
|
186
|
+
const args = validateBlockShape(`${at}.args`, entry.args, ARGS_BLOCK_KEYS, fileName);
|
|
187
|
+
if (args.command === void 0 && !partial) throw new Error(`${fileName}: ${at}.args has no command in any config layer`);
|
|
188
|
+
if (args.command !== void 0 && !ARGS_FILE.test(args.command)) {
|
|
189
|
+
throw new Error(`${fileName}: ${at}.args.command must be a *.rune.js module exporting args(builder), or a .json schema`);
|
|
190
|
+
}
|
|
191
|
+
if (runIsIsolate) {
|
|
192
|
+
throw new Error(`${fileName}: ${at}.args \u2014 an isolate run module declares its schema with its own args export; an args block is for native handlers`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (entry.repl != null) {
|
|
196
|
+
const repl = validateBlockShape(`${at}.repl`, entry.repl, REPL_BLOCK_KEYS, fileName);
|
|
197
|
+
if (repl.command === void 0 && !partial) throw new Error(`${fileName}: ${at}.repl has no command in any config layer`);
|
|
198
|
+
if (repl.command !== void 0 && !ISOLATE_MODULE.test(repl.command)) {
|
|
199
|
+
throw new Error(`${fileName}: ${at}.repl.command must be a *.rune.js module \u2014 a REPL runs in the isolate`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function validateMergedRunBlocks(config, label = "config") {
|
|
204
|
+
for (const [runeKey, entry] of Object.entries(config.runes ?? {})) {
|
|
205
|
+
if (isObject(entry)) validateEntry(runeKey, entry, label, false);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function validateConfig(config, fileName = "config.json") {
|
|
209
|
+
if (config.runes && typeof config.runes === "object") {
|
|
210
|
+
for (const [runeKey, entry] of Object.entries(config.runes)) {
|
|
211
|
+
if (!isObject(entry)) continue;
|
|
212
|
+
if (entry.path !== void 0 || entry.permissions !== void 0) {
|
|
213
|
+
throw new Error(`${fileName}: runes["${runeKey}"] uses unsupported legacy fields (path / permissions); declare a run block instead.`);
|
|
214
|
+
}
|
|
215
|
+
validateEntry(runeKey, entry, fileName, true);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (config.plugins && !Array.isArray(config.plugins) && typeof config.plugins === "object") {
|
|
219
|
+
for (const [key, value] of Object.entries(config.plugins)) {
|
|
220
|
+
if (typeof value !== "boolean") {
|
|
221
|
+
throw new Error(`${fileName}: plugins["${key}"] must be true or false, got ${JSON.stringify(value)}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function normaliseRune(entry) {
|
|
227
|
+
return entry;
|
|
228
|
+
}
|
|
229
|
+
function getRune(config, key) {
|
|
230
|
+
const raw = (config.runes ?? {})[key];
|
|
231
|
+
if (raw == null) return null;
|
|
232
|
+
return normaliseRune(raw);
|
|
233
|
+
}
|
|
234
|
+
var ROOTLESS = /* @__PURE__ */ Symbol.for("crunes.rootless");
|
|
235
|
+
function readLayer(filePath, label, base, layer) {
|
|
236
|
+
if (!existsSync(filePath)) return null;
|
|
237
|
+
let parsed;
|
|
238
|
+
try {
|
|
239
|
+
parsed = JSON.parse(readFileSync(filePath, "utf8"));
|
|
240
|
+
} catch (err) {
|
|
241
|
+
throw new Error(`${label} is invalid JSON: ${err.message}`);
|
|
242
|
+
}
|
|
243
|
+
validateConfig(parsed, label, { base, layer });
|
|
244
|
+
return parsed;
|
|
245
|
+
}
|
|
246
|
+
function loadConfig(dir) {
|
|
247
|
+
const layers = [];
|
|
248
|
+
if (process.env.CRUNES_NO_GLOBAL !== "1") {
|
|
249
|
+
const storeRoot = getStorePath();
|
|
250
|
+
const globalPath = join(storeRoot, "config.json");
|
|
251
|
+
const globalRaw = readLayer(globalPath, globalPath, storeRoot, "global");
|
|
252
|
+
if (globalRaw) layers.push(absolutizeEntryPaths(globalRaw, storeRoot, "global"));
|
|
253
|
+
}
|
|
254
|
+
const sharedRaw = readLayer(join(dir, ".crunes", "config.json"), "config.json", dir, "project");
|
|
255
|
+
const rootless = sharedRaw === null;
|
|
256
|
+
if (sharedRaw) {
|
|
257
|
+
layers.push(absolutizeEntryPaths(sharedRaw, dir, "project"));
|
|
258
|
+
const localRaw = readLayer(join(dir, ".crunes", "config.local.json"), "config.local.json", dir, "local");
|
|
259
|
+
if (localRaw) layers.push(absolutizeEntryPaths(localRaw, dir, "local"));
|
|
260
|
+
}
|
|
261
|
+
const merged = layers.reduce((acc, layer) => mergeConfigs(acc, layer), {});
|
|
262
|
+
validateMergedRunBlocks(merged, "config (merged layers)");
|
|
263
|
+
merged[ROOTLESS] = rootless;
|
|
264
|
+
return merged;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export {
|
|
268
|
+
LAYER,
|
|
269
|
+
coercePlugins,
|
|
270
|
+
enabledPluginKeys,
|
|
271
|
+
normaliseRune,
|
|
272
|
+
getRune,
|
|
273
|
+
ROOTLESS,
|
|
274
|
+
loadConfig
|
|
275
|
+
};
|