@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.
- package/dist/chunks/add-MSX6XSU3.js +68 -0
- package/dist/chunks/{apply-YY7MIM64.js → apply-LOIJIPLR.js} +18 -9
- package/dist/chunks/{benchmark-BQNMULOO.js → benchmark-3IHFP3V2.js} +21 -15
- package/dist/chunks/chunk-2DNYVKBF.js +109 -0
- package/dist/chunks/chunk-2FI6KN3C.js +283 -0
- package/dist/chunks/chunk-2HM5Q52B.js +131 -0
- package/dist/chunks/chunk-55GTJG5I.js +1154 -0
- package/dist/chunks/chunk-6IC6ZJ74.js +9525 -0
- package/dist/chunks/chunk-7KYCYDAS.js +325 -0
- package/dist/chunks/chunk-DTOYFY3Z.js +578 -0
- package/dist/chunks/chunk-EO3CSXWK.js +70 -0
- package/dist/chunks/chunk-FIAFVIAN.js +79 -0
- package/dist/chunks/chunk-H2OT7D6N.js +303 -0
- package/dist/chunks/{chunk-MRNZFUXZ.js → chunk-KSQDFE5N.js} +22 -7
- package/dist/chunks/{chunk-SNC7AOT7.js → chunk-KUEMDPNG.js} +45 -94
- package/dist/chunks/{chunk-VST6HAB6.js → chunk-MTJ2KW3V.js} +2 -0
- package/dist/chunks/{chunk-CY6C6ADU.js → chunk-MVCBPI4J.js} +45 -478
- package/dist/chunks/{chunk-34F4ZURL.js → chunk-RVBAAXRY.js} +29 -12
- package/dist/chunks/{chunk-X7PZN73N.js → chunk-SUCYDYMU.js} +1 -1
- package/dist/chunks/chunk-UBCAZGLE.js +15 -0
- package/dist/chunks/chunk-VP7YLCQP.js +244 -0
- package/dist/chunks/chunk-XDMMSZIL.js +71 -0
- package/dist/chunks/chunk-YKIKJHYO.js +94 -0
- package/dist/chunks/{create-TLPM7HJE.js → create-DXW4YYLJ.js} +5 -5
- package/dist/chunks/{create-LM7U3CJS.js → create-LPLNCOW4.js} +100 -6
- package/dist/chunks/{create-ET6DT5ZE.js → create-Y4LHLWGL.js} +6 -2
- package/dist/chunks/{disable-TNTEIAKO.js → disable-TITOSMXB.js} +6 -2
- package/dist/chunks/doctor-R2Y6UAY4.js +208 -0
- package/dist/chunks/{enable-GUQCB4CU.js → enable-LGTPDWPV.js} +7 -3
- package/dist/chunks/{init-PJSCFOC6.js → init-KO2HLED5.js} +6 -2
- package/dist/chunks/{install-4YP7FALO.js → install-7IRUAGSF.js} +10 -5
- package/dist/chunks/{intro-SA7MWV3Z.js → intro-JNJ6A75J.js} +44 -18
- package/dist/chunks/{list-WKNPZZOV.js → list-BCCM3TLP.js} +10 -6
- package/dist/chunks/{list-7R6NASFI.js → list-MLKZE36K.js} +19 -19
- package/dist/chunks/list-QVZKR3IE.js +62 -0
- package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
- package/dist/chunks/migrate-Y3EKMVP5.js +87 -0
- package/dist/chunks/{registry-K5DV5NAK.js → registry-IWP7JMNI.js} +1 -1
- package/dist/chunks/{repl-ZB3DIJ4K.js → repl-5GDN3RAO.js} +30 -20
- package/dist/chunks/resolver-CA2A32AC.js +36 -0
- package/dist/chunks/{run-22B65ZWZ.js → run-WL3IZBXF.js} +17 -11
- package/dist/chunks/rune-YA4TFHTB.js +283 -0
- package/dist/chunks/runner-QNZMBHQY.js +34 -0
- package/dist/chunks/{shell-explain-QLITLHW7.js → shell-explain-LKBBP2BG.js} +5 -2
- package/dist/chunks/trust-BFIDANXD.js +109 -0
- package/dist/chunks/{uninstall-4WR5IHLC.js → uninstall-3MWZIZVA.js} +10 -5
- package/dist/chunks/{update-ACLDK6E6.js → update-W4MJUTTW.js} +10 -5
- package/dist/chunks/{version-EULYWNXN.js → version-FLHI5KFS.js} +2 -2
- package/dist/cli.js +51 -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,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isInlineSchema,
|
|
3
|
+
normaliseJsonSchema
|
|
4
|
+
} from "./chunk-VP7YLCQP.js";
|
|
5
|
+
import {
|
|
6
|
+
init_require_shim
|
|
7
|
+
} from "./chunk-TPK5AGRA.js";
|
|
8
|
+
|
|
9
|
+
// src/plugin/manifest.js
|
|
10
|
+
init_require_shim();
|
|
11
|
+
import fs from "node:fs/promises";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
var PLUGIN_JSON_RELATIVE = ".crunes-plugin/plugin.json";
|
|
14
|
+
async function loadPluginJson(pluginDir) {
|
|
15
|
+
const jsonPath = path.join(pluginDir, PLUGIN_JSON_RELATIVE);
|
|
16
|
+
const raw = await fs.readFile(jsonPath, "utf8");
|
|
17
|
+
const json = JSON.parse(raw);
|
|
18
|
+
validatePluginJson(json, pluginDir);
|
|
19
|
+
return json;
|
|
20
|
+
}
|
|
21
|
+
var ISOLATE_MODULE = /\.rune\.m?js$/i;
|
|
22
|
+
var ARGS_FILE = /\.(rune\.m?js|json)$/i;
|
|
23
|
+
var RUNE_BLOCK_KEYS = {
|
|
24
|
+
run: ["command", "argv", "permissions", "output", "pass", "timeout"],
|
|
25
|
+
repl: ["command", "permissions"]
|
|
26
|
+
};
|
|
27
|
+
function validatePluginJson(json, pluginDir = null) {
|
|
28
|
+
if (json.format !== "1") throw new Error(`plugin.json: unsupported format "${json.format}" (expected "1")`);
|
|
29
|
+
if (!json.runes || typeof json.runes !== "object") throw new Error('plugin.json: "runes" must be an object');
|
|
30
|
+
for (const [key, rune] of Object.entries(json.runes)) {
|
|
31
|
+
const at = `plugin.json: rune "${key}"`;
|
|
32
|
+
if (!rune || typeof rune !== "object" || Array.isArray(rune)) throw new Error(`${at} must be an object`);
|
|
33
|
+
for (const old of ["path", "permissions"]) {
|
|
34
|
+
if (rune[old] !== void 0) throw new Error(`${at} has "${old}" \u2014 a plugin manifest names the module and its grants in the run and repl blocks`);
|
|
35
|
+
}
|
|
36
|
+
if (rune.run == null) throw new Error(`${at} has no run block`);
|
|
37
|
+
for (const mode of ["run", "repl"]) {
|
|
38
|
+
if (rune[mode] == null) continue;
|
|
39
|
+
const block = typeof rune[mode] === "string" ? { command: rune[mode] } : rune[mode];
|
|
40
|
+
if (typeof block !== "object" || Array.isArray(block)) throw new Error(`${at}: ${mode} must be a module path or { "command", "permissions" }`);
|
|
41
|
+
const unknown = Object.keys(block).filter((k) => !RUNE_BLOCK_KEYS[mode].includes(k));
|
|
42
|
+
if (unknown.length) throw new Error(`${at}: ${mode} has unknown field ${unknown.map((k) => `"${k}"`).join(", ")}`);
|
|
43
|
+
if (typeof block.command !== "string" || block.command === "") throw new Error(`${at}: ${mode}.command must be a non-empty string`);
|
|
44
|
+
const isolate = ISOLATE_MODULE.test(block.command);
|
|
45
|
+
if (mode === "repl" && !isolate) throw new Error(`${at}: repl.command must be a *.rune.js module in the plugin`);
|
|
46
|
+
const perms = block.permissions;
|
|
47
|
+
if (perms != null && !isolate) {
|
|
48
|
+
throw new Error(`${at}: ${mode}.permissions \u2014 "${block.command}" runs natively with full access, so grants would not apply to it`);
|
|
49
|
+
}
|
|
50
|
+
if (perms != null && (typeof perms !== "object" || Array.isArray(perms) || Object.keys(perms).some((k) => k !== "allow" && k !== "deny"))) {
|
|
51
|
+
throw new Error(`${at}: ${mode}.permissions must be { "allow": [...], "deny": [...] }`);
|
|
52
|
+
}
|
|
53
|
+
if (isolate && ["argv", "output", "pass"].some((k) => block[k] !== void 0)) {
|
|
54
|
+
throw new Error(`${at}: ${mode} \u2014 argv, output and pass apply to a native handler, not an isolate module`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (rune.args != null) {
|
|
58
|
+
const run = typeof rune.run === "string" ? { command: rune.run } : rune.run;
|
|
59
|
+
if (ISOLATE_MODULE.test(run.command)) throw new Error(`${at}: args \u2014 an isolate module declares its schema with its own args export`);
|
|
60
|
+
if (isInlineSchema(rune.args)) {
|
|
61
|
+
try {
|
|
62
|
+
normaliseJsonSchema(rune.args, `rune "${key}" args`);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
throw new Error(`plugin.json: ${err.message}`);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const args = typeof rune.args === "string" ? { command: rune.args } : rune.args;
|
|
68
|
+
if (typeof args.command !== "string" || !ARGS_FILE.test(args.command)) {
|
|
69
|
+
throw new Error(`${at}: args.command must be a *.rune.js module exporting args(builder), or a .json schema`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
loadPluginJson,
|
|
78
|
+
validatePluginJson
|
|
79
|
+
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runRunBlock
|
|
3
|
+
} from "./chunk-DTOYFY3Z.js";
|
|
4
|
+
import {
|
|
5
|
+
isNativeRune,
|
|
6
|
+
trustDigest,
|
|
7
|
+
trustState,
|
|
8
|
+
untrustedError
|
|
9
|
+
} from "./chunk-XDMMSZIL.js";
|
|
10
|
+
import {
|
|
11
|
+
enabledPluginKeys,
|
|
12
|
+
getRune
|
|
13
|
+
} from "./chunk-2FI6KN3C.js";
|
|
14
|
+
import {
|
|
15
|
+
loadRegistry,
|
|
16
|
+
resolvePluginKeyScoped
|
|
17
|
+
} from "./chunk-MTJ2KW3V.js";
|
|
18
|
+
import {
|
|
19
|
+
loadPluginJson
|
|
20
|
+
} from "./chunk-FIAFVIAN.js";
|
|
21
|
+
import {
|
|
22
|
+
blockModule,
|
|
23
|
+
scopedPermissions
|
|
24
|
+
} from "./chunk-YKIKJHYO.js";
|
|
25
|
+
import {
|
|
26
|
+
computeEffectivePermissions
|
|
27
|
+
} from "./chunk-MVCBPI4J.js";
|
|
28
|
+
import {
|
|
29
|
+
getLocalBase,
|
|
30
|
+
getStorePath
|
|
31
|
+
} from "./chunk-2Q3KLBE6.js";
|
|
32
|
+
import {
|
|
33
|
+
init_require_shim
|
|
34
|
+
} from "./chunk-TPK5AGRA.js";
|
|
35
|
+
|
|
36
|
+
// src/rune/resolver.js
|
|
37
|
+
init_require_shim();
|
|
38
|
+
import { join } from "node:path";
|
|
39
|
+
|
|
40
|
+
// src/core/errors.js
|
|
41
|
+
init_require_shim();
|
|
42
|
+
var CircularRuneError = class extends Error {
|
|
43
|
+
constructor(chain) {
|
|
44
|
+
super(`Circular rune call: ${chain.join(" \u2192 ")}`);
|
|
45
|
+
this.name = "CircularRuneError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/rune/resolver.js
|
|
50
|
+
function describeConfigLayers(configDir) {
|
|
51
|
+
return [
|
|
52
|
+
`project config (${configDir})`,
|
|
53
|
+
"enabled plugins",
|
|
54
|
+
process.env.CRUNES_NO_GLOBAL === "1" ? "global config (skipped: CRUNES_NO_GLOBAL=1)" : `global config (${join(getStorePath(), "config.json")})`
|
|
55
|
+
].join(", ");
|
|
56
|
+
}
|
|
57
|
+
async function resolvePluginRune(config, key) {
|
|
58
|
+
const colonIdx = key.indexOf(":");
|
|
59
|
+
if (colonIdx === -1) return null;
|
|
60
|
+
const enabledPlugins = enabledPluginKeys(config);
|
|
61
|
+
if (enabledPlugins.length === 0) return null;
|
|
62
|
+
const pluginPart = key.slice(0, colonIdx);
|
|
63
|
+
const runeKey = key.slice(colonIdx + 1);
|
|
64
|
+
let registry;
|
|
65
|
+
try {
|
|
66
|
+
registry = await loadRegistry();
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const pluginKey = resolvePluginKeyScoped(pluginPart, registry, enabledPlugins);
|
|
71
|
+
if (!pluginKey) return null;
|
|
72
|
+
if (!enabledPlugins.includes(pluginKey)) return null;
|
|
73
|
+
const entry = registry.plugins?.[pluginKey];
|
|
74
|
+
if (!entry) return null;
|
|
75
|
+
return { pluginKey, runeKey, pluginDir: entry.path, pluginCacheDir: entry.cacheDir ?? entry.path };
|
|
76
|
+
}
|
|
77
|
+
async function resolveRuneFromPlugins(config, runeKey) {
|
|
78
|
+
const enabledPlugins = enabledPluginKeys(config);
|
|
79
|
+
if (enabledPlugins.length === 0) return null;
|
|
80
|
+
let registry;
|
|
81
|
+
try {
|
|
82
|
+
registry = await loadRegistry();
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const matches = [];
|
|
87
|
+
for (const pluginKey of enabledPlugins) {
|
|
88
|
+
const entry = registry.plugins?.[pluginKey];
|
|
89
|
+
if (!entry) continue;
|
|
90
|
+
let pluginJson;
|
|
91
|
+
try {
|
|
92
|
+
pluginJson = await loadPluginJson(entry.path);
|
|
93
|
+
} catch {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if ((pluginJson.runes ?? {})[runeKey]) {
|
|
97
|
+
matches.push({ pluginKey, runeKey, pluginDir: entry.path, pluginCacheDir: entry.cacheDir ?? entry.path, pluginJson });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (matches.length > 1) {
|
|
101
|
+
const names = matches.map((m) => m.pluginKey).join(", ");
|
|
102
|
+
const options = matches.map((m) => `${m.pluginKey}:${runeKey}`).join(" or ");
|
|
103
|
+
throw new Error(`"${runeKey}" matches runes in multiple plugins: ${names}. Use ${options} to specify one.`);
|
|
104
|
+
}
|
|
105
|
+
return matches[0] ?? null;
|
|
106
|
+
}
|
|
107
|
+
async function runPluginMatch({ match, pluginJson, projectPerms, projectVars, key, args, dir, config, opts, runeCallback, instanceId }) {
|
|
108
|
+
const { pluginKey, runeKey, pluginDir, pluginCacheDir } = match;
|
|
109
|
+
const rune = pluginJson.runes?.[runeKey];
|
|
110
|
+
if (rune && isNativeRune(rune)) {
|
|
111
|
+
const registry = await loadRegistry();
|
|
112
|
+
const state = trustState(registry.plugins?.[pluginKey], runeKey, trustDigest(pluginDir, rune));
|
|
113
|
+
if (state !== "trusted") throw untrustedError(pluginKey, runeKey, state);
|
|
114
|
+
process.stderr.write(`[crunes] ${pluginKey}:${runeKey} is a plugin script: it runs natively, outside the sandbox, with your full access.
|
|
115
|
+
`);
|
|
116
|
+
const entry = { run: rune.run, args: rune.args, vars: { ...rune.vars ?? {}, ...projectVars } };
|
|
117
|
+
const result2 = await runRunBlock({
|
|
118
|
+
dir,
|
|
119
|
+
key,
|
|
120
|
+
args,
|
|
121
|
+
entry,
|
|
122
|
+
opts,
|
|
123
|
+
configDir: pluginDir,
|
|
124
|
+
runeCallback,
|
|
125
|
+
instanceId,
|
|
126
|
+
extraEnv: { CRUNES_PLUGIN_ROOT: pluginDir }
|
|
127
|
+
});
|
|
128
|
+
return result2?.directExitCode !== void 0 ? result2 : normaliseResult(result2);
|
|
129
|
+
}
|
|
130
|
+
const { executePluginRune } = await import("./runner-QNZMBHQY.js");
|
|
131
|
+
const result = await executePluginRune({
|
|
132
|
+
pluginDir,
|
|
133
|
+
pluginCacheDir,
|
|
134
|
+
runeKey,
|
|
135
|
+
pluginJson,
|
|
136
|
+
projectPerms,
|
|
137
|
+
projectVars,
|
|
138
|
+
args,
|
|
139
|
+
projectDir: dir,
|
|
140
|
+
opts: config,
|
|
141
|
+
runeCallback,
|
|
142
|
+
sections: opts.sections ?? null,
|
|
143
|
+
lifecycle: "run",
|
|
144
|
+
onEvent: opts.onEvent ?? null,
|
|
145
|
+
instanceId
|
|
146
|
+
});
|
|
147
|
+
return normaliseResult(result);
|
|
148
|
+
}
|
|
149
|
+
async function runRune(dir, config, key, args, opts = {}, _callStack = []) {
|
|
150
|
+
const configDir = opts.configDir ?? dir;
|
|
151
|
+
const instanceId = opts.instanceId ?? "1";
|
|
152
|
+
let localOnly = false;
|
|
153
|
+
if (key.startsWith("project:")) {
|
|
154
|
+
key = key.slice(8);
|
|
155
|
+
localOnly = true;
|
|
156
|
+
}
|
|
157
|
+
if (_callStack.includes(key)) {
|
|
158
|
+
throw new CircularRuneError([..._callStack, key]);
|
|
159
|
+
}
|
|
160
|
+
const nextStack = [..._callStack, key];
|
|
161
|
+
let childCounter = 0;
|
|
162
|
+
const runeCallback = (childKey, childArgs) => {
|
|
163
|
+
childCounter++;
|
|
164
|
+
const childInstanceId = `${instanceId}.${childCounter}`;
|
|
165
|
+
return runRune(dir, config, childKey, childArgs, {
|
|
166
|
+
configDir,
|
|
167
|
+
onEvent: opts.onEvent,
|
|
168
|
+
instanceId: childInstanceId
|
|
169
|
+
}, nextStack);
|
|
170
|
+
};
|
|
171
|
+
const pluginMatch = localOnly ? null : await resolvePluginRune(config, key);
|
|
172
|
+
if (pluginMatch) {
|
|
173
|
+
const { pluginKey, runeKey, pluginDir } = pluginMatch;
|
|
174
|
+
const pluginJson = await loadPluginJson(pluginDir);
|
|
175
|
+
const projectPerms = scopedPermissions(config.runes?.[`${pluginKey}:${runeKey}`]);
|
|
176
|
+
const projectVars = config.runes?.[`${pluginKey}:${runeKey}`]?.vars ?? {};
|
|
177
|
+
return runPluginMatch({ match: pluginMatch, pluginJson, projectPerms, projectVars, key, args, dir, config, opts, runeCallback, instanceId });
|
|
178
|
+
}
|
|
179
|
+
const entry = getRune(config, key);
|
|
180
|
+
if (!entry && !localOnly) {
|
|
181
|
+
const autoMatch = await resolveRuneFromPlugins(config, key);
|
|
182
|
+
if (autoMatch) {
|
|
183
|
+
const { pluginKey, runeKey, pluginJson } = autoMatch;
|
|
184
|
+
const projectPerms = scopedPermissions(config.runes?.[`${pluginKey}:${runeKey}`]);
|
|
185
|
+
const projectVars = config.runes?.[`${pluginKey}:${runeKey}`]?.vars ?? {};
|
|
186
|
+
return runPluginMatch({ match: autoMatch, pluginJson, projectPerms, projectVars, key, args, dir, config, opts, runeCallback, instanceId });
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
if (!entry) return null;
|
|
191
|
+
if (entry.plugin) {
|
|
192
|
+
const aliasMatch = await resolvePluginRune(config, entry.plugin);
|
|
193
|
+
if (!aliasMatch) throw new Error(`Plugin alias "${key}" \u2192 "${entry.plugin}" is not enabled or installed.`);
|
|
194
|
+
const { pluginKey, runeKey, pluginDir } = aliasMatch;
|
|
195
|
+
const pluginJson = await loadPluginJson(pluginDir);
|
|
196
|
+
const projectPerms = scopedPermissions(entry) ?? scopedPermissions(config.runes?.[`${pluginKey}:${runeKey}`]);
|
|
197
|
+
const projectVars = entry.vars ?? config.runes?.[`${pluginKey}:${runeKey}`]?.vars ?? {};
|
|
198
|
+
return runPluginMatch({ match: aliasMatch, pluginJson, projectPerms, projectVars, key, args, dir, config, opts, runeCallback, instanceId });
|
|
199
|
+
}
|
|
200
|
+
const result = await runRunBlock({ dir, key, args, entry, opts, configDir, runeCallback, instanceId });
|
|
201
|
+
return result?.directExitCode !== void 0 ? result : normaliseResult(result);
|
|
202
|
+
}
|
|
203
|
+
function normaliseResult(result) {
|
|
204
|
+
if (result == null) return [];
|
|
205
|
+
const items = Array.isArray(result) ? result : [result];
|
|
206
|
+
let strings = 0;
|
|
207
|
+
return items.map((item) => {
|
|
208
|
+
if (typeof item !== "string") return item;
|
|
209
|
+
strings++;
|
|
210
|
+
const name = strings === 1 ? "output" : `output-${strings}`;
|
|
211
|
+
return { name, attrs: {}, data: { type: "markdown", content: item } };
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
async function resolveRuneEntry(projectDir, config, key, configDir = projectDir) {
|
|
215
|
+
const pluginMatch = await resolvePluginRune(config, key);
|
|
216
|
+
if (pluginMatch) {
|
|
217
|
+
const { pluginKey, runeKey, pluginDir, pluginCacheDir } = pluginMatch;
|
|
218
|
+
const pluginJson = await loadPluginJson(pluginDir);
|
|
219
|
+
const projectPerms = scopedPermissions(config.runes?.[`${pluginKey}:${runeKey}`]);
|
|
220
|
+
const effective = computeEffectivePermissions(
|
|
221
|
+
scopedPermissions(pluginJson.runes[runeKey]) ?? {},
|
|
222
|
+
projectPerms ?? {},
|
|
223
|
+
"repl"
|
|
224
|
+
);
|
|
225
|
+
const vars = { ...pluginJson.runes[runeKey]?.vars ?? {}, ...config.runes?.[`${pluginKey}:${runeKey}`]?.vars ?? {} };
|
|
226
|
+
return {
|
|
227
|
+
async createReplSession(args, opts = {}) {
|
|
228
|
+
const { getPluginRunePath, runRuneInRepl } = await import("./runner-QNZMBHQY.js");
|
|
229
|
+
const runeFile = getPluginRunePath(pluginDir, runeKey, pluginJson, "repl");
|
|
230
|
+
const nodeModulesDir = join(pluginCacheDir, "node_modules");
|
|
231
|
+
return runRuneInRepl(runeFile, effective, args, projectDir, {
|
|
232
|
+
nodeModulesDir,
|
|
233
|
+
pluginDeps: pluginJson.dependencies ?? {},
|
|
234
|
+
pluginDir,
|
|
235
|
+
pluginId: `${pluginJson.name}@${pluginJson.version}`,
|
|
236
|
+
vars,
|
|
237
|
+
runeKey,
|
|
238
|
+
onEvent: opts.onEvent ?? null,
|
|
239
|
+
instanceId: opts.instanceId ?? "1"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const entry = getRune(config, key);
|
|
245
|
+
if (entry && !entry.plugin && entry.repl == null) {
|
|
246
|
+
throw new Error(`Rune "${key}" has no repl block \u2014 a rune has a REPL only when its entry declares one.`);
|
|
247
|
+
}
|
|
248
|
+
if (entry && !entry.plugin) {
|
|
249
|
+
const runeFile = blockModule(entry, "repl", configDir);
|
|
250
|
+
const effective = computeEffectivePermissions(scopedPermissions(entry) ?? {}, void 0, "repl");
|
|
251
|
+
const vars = entry.vars ?? {};
|
|
252
|
+
return {
|
|
253
|
+
async createReplSession(args, opts = {}) {
|
|
254
|
+
const { runRuneInRepl } = await import("./runner-QNZMBHQY.js");
|
|
255
|
+
return runRuneInRepl(runeFile, effective, args, projectDir, {
|
|
256
|
+
vars,
|
|
257
|
+
runeKey: key,
|
|
258
|
+
onEvent: opts.onEvent ?? null,
|
|
259
|
+
instanceId: opts.instanceId ?? "1",
|
|
260
|
+
nodeModulesDir: join(getLocalBase(configDir), "node_modules"),
|
|
261
|
+
pluginDeps: null
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
const autoMatch = await resolveRuneFromPlugins(config, key);
|
|
267
|
+
if (autoMatch) {
|
|
268
|
+
const { pluginKey, runeKey, pluginDir, pluginCacheDir, pluginJson } = autoMatch;
|
|
269
|
+
const projectPerms = scopedPermissions(config.runes?.[`${pluginKey}:${runeKey}`]);
|
|
270
|
+
const effective = computeEffectivePermissions(
|
|
271
|
+
scopedPermissions(pluginJson.runes[runeKey]) ?? {},
|
|
272
|
+
projectPerms ?? {},
|
|
273
|
+
"repl"
|
|
274
|
+
);
|
|
275
|
+
const vars = { ...pluginJson.runes[runeKey]?.vars ?? {}, ...config.runes?.[`${pluginKey}:${runeKey}`]?.vars ?? {} };
|
|
276
|
+
return {
|
|
277
|
+
async createReplSession(args, opts = {}) {
|
|
278
|
+
const { getPluginRunePath, runRuneInRepl } = await import("./runner-QNZMBHQY.js");
|
|
279
|
+
const runeFile = getPluginRunePath(pluginDir, runeKey, pluginJson, "repl");
|
|
280
|
+
const nodeModulesDir = join(pluginCacheDir, "node_modules");
|
|
281
|
+
return runRuneInRepl(runeFile, effective, args, projectDir, {
|
|
282
|
+
nodeModulesDir,
|
|
283
|
+
pluginDeps: pluginJson.dependencies ?? {},
|
|
284
|
+
pluginDir,
|
|
285
|
+
pluginId: `${pluginJson.name}@${pluginJson.version}`,
|
|
286
|
+
vars,
|
|
287
|
+
runeKey,
|
|
288
|
+
onEvent: opts.onEvent ?? null,
|
|
289
|
+
instanceId: opts.instanceId ?? "1"
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
throw new Error(`Unknown key: "${key}". Looked in: ${describeConfigLayers(configDir)}.`);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export {
|
|
298
|
+
describeConfigLayers,
|
|
299
|
+
resolvePluginRune,
|
|
300
|
+
resolveRuneFromPlugins,
|
|
301
|
+
runRune,
|
|
302
|
+
resolveRuneEntry
|
|
303
|
+
};
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
+
runtimeOf
|
|
3
|
+
} from "./chunk-2DNYVKBF.js";
|
|
4
|
+
import {
|
|
5
|
+
isNativeRune
|
|
6
|
+
} from "./chunk-XDMMSZIL.js";
|
|
7
|
+
import {
|
|
8
|
+
enabledPluginKeys,
|
|
2
9
|
getRune
|
|
3
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-2FI6KN3C.js";
|
|
4
11
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
12
|
+
blockOf
|
|
13
|
+
} from "./chunk-YKIKJHYO.js";
|
|
7
14
|
import {
|
|
8
15
|
init_require_shim
|
|
9
16
|
} from "./chunk-TPK5AGRA.js";
|
|
@@ -20,14 +27,21 @@ async function enumerateRunes(config) {
|
|
|
20
27
|
continue;
|
|
21
28
|
}
|
|
22
29
|
const entry = getRune(config, key);
|
|
23
|
-
|
|
30
|
+
if (entry.run != null) {
|
|
31
|
+
const run = typeof entry.run === "string" ? { command: entry.run } : entry.run;
|
|
32
|
+
const runtime = runtimeOf(run.command);
|
|
33
|
+
const source2 = [run.command, ...run.argv ?? []].join(" ");
|
|
34
|
+
entries.push({ key, source: source2, runtime, name: entry.name ?? null, description: entry.description ?? null });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const source = entry.plugin ? `\u2192 ${entry.plugin}` : "";
|
|
24
38
|
entries.push({ key, source, name: entry.name ?? null, description: entry.description ?? null });
|
|
25
39
|
}
|
|
26
40
|
const enabledPlugins = enabledPluginKeys(config);
|
|
27
41
|
if (enabledPlugins.length > 0) {
|
|
28
42
|
try {
|
|
29
|
-
const { loadRegistry } = await import("./registry-
|
|
30
|
-
const { loadPluginJson } = await import("./manifest-
|
|
43
|
+
const { loadRegistry } = await import("./registry-IWP7JMNI.js");
|
|
44
|
+
const { loadPluginJson } = await import("./manifest-76MIEL2F.js");
|
|
31
45
|
const registry = await loadRegistry();
|
|
32
46
|
for (const pluginKey of enabledPlugins) {
|
|
33
47
|
const entry = registry.plugins?.[pluginKey];
|
|
@@ -46,6 +60,7 @@ async function enumerateRunes(config) {
|
|
|
46
60
|
entries.push({
|
|
47
61
|
key: displayKey,
|
|
48
62
|
source: `plugin: ${pluginKey}`,
|
|
63
|
+
...isNativeRune(runeEntry) && { runtime: runtimeOf(blockOf(runeEntry, "run").command) },
|
|
49
64
|
name: runeEntry.name ?? null,
|
|
50
65
|
description: runeEntry.description ?? null
|
|
51
66
|
});
|
|
@@ -60,7 +75,7 @@ async function enumerateRunes(config) {
|
|
|
60
75
|
const shortName = key.slice(key.indexOf("@") + 1, key.lastIndexOf(":"));
|
|
61
76
|
if (entries.some((e) => e.key === `${shortName}:${runeKey}`)) continue;
|
|
62
77
|
const entry = getRune(config, key);
|
|
63
|
-
entries.push({ key, source:
|
|
78
|
+
entries.push({ key, source: "", name: entry.name ?? null, description: entry.description ?? null });
|
|
64
79
|
}
|
|
65
80
|
return entries;
|
|
66
81
|
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isVerbose,
|
|
3
|
+
output
|
|
4
|
+
} from "./chunk-MIKWIFYR.js";
|
|
1
5
|
import {
|
|
2
6
|
describeConfigLayers,
|
|
3
7
|
runRune
|
|
4
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-H2OT7D6N.js";
|
|
5
9
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./chunk-CY6C6ADU.js";
|
|
10
|
+
renderSection
|
|
11
|
+
} from "./chunk-DTOYFY3Z.js";
|
|
9
12
|
import {
|
|
10
13
|
loadConfig
|
|
11
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-2FI6KN3C.js";
|
|
12
15
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
isGlobMatch,
|
|
17
|
+
isWildcardMatch
|
|
18
|
+
} from "./chunk-MVCBPI4J.js";
|
|
16
19
|
import {
|
|
17
20
|
init_require_shim
|
|
18
21
|
} from "./chunk-TPK5AGRA.js";
|
|
@@ -58,56 +61,6 @@ function permissionHint(message, { key, lifecycle = "run", configLayers }) {
|
|
|
58
61
|
return lines.join("\n");
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
// src/shared/render.js
|
|
62
|
-
init_require_shim();
|
|
63
|
-
function render(data) {
|
|
64
|
-
if (!data) return null;
|
|
65
|
-
if (data.type === "tree") return renderTree(data.root);
|
|
66
|
-
if (data.type === "markdown") return data.content ?? null;
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
function renderSection(section) {
|
|
70
|
-
const parts = [];
|
|
71
|
-
if (section.title) {
|
|
72
|
-
parts.push(`## ${section.title}`);
|
|
73
|
-
} else if (section.name) {
|
|
74
|
-
parts.push(`## ${section.name}`);
|
|
75
|
-
} else {
|
|
76
|
-
parts.push("## (no title)");
|
|
77
|
-
}
|
|
78
|
-
if (section.attrs && Object.keys(section.attrs).length > 0) {
|
|
79
|
-
const attrStr = Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ");
|
|
80
|
-
parts.push(attrStr);
|
|
81
|
-
}
|
|
82
|
-
const content = render(section.data);
|
|
83
|
-
if (content) {
|
|
84
|
-
parts.push(content);
|
|
85
|
-
}
|
|
86
|
-
return parts.filter(Boolean).join("\n") || null;
|
|
87
|
-
}
|
|
88
|
-
function formatSection(section, rune) {
|
|
89
|
-
const nameStr = section.title ?? section.name ?? "(no title)";
|
|
90
|
-
const attrsStr = section.attrs && Object.keys(section.attrs).length > 0 ? " " + Object.entries(section.attrs).map(([k, v]) => `[${k}: ${v}]`).join(" ") : "";
|
|
91
|
-
const content = render(section.data);
|
|
92
|
-
return `[${rune}:section] ${nameStr}${attrsStr}${content ? "\n" + content : ""}`;
|
|
93
|
-
}
|
|
94
|
-
function renderTree(root) {
|
|
95
|
-
if (!root) return null;
|
|
96
|
-
const lines = [`${root.name.padEnd(12)}${root.description}`];
|
|
97
|
-
appendChildren(root.children ?? [], "", lines);
|
|
98
|
-
return lines.join("\n");
|
|
99
|
-
}
|
|
100
|
-
function appendChildren(children, prefix, lines) {
|
|
101
|
-
for (let i = 0; i < children.length; i++) {
|
|
102
|
-
const child = children[i];
|
|
103
|
-
const isLast = i === children.length - 1;
|
|
104
|
-
const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
105
|
-
const childPrefix = prefix + (isLast ? " " : "\u2502 ");
|
|
106
|
-
lines.push(`${prefix}${connector}${child.name.padEnd(12)}${child.description}`);
|
|
107
|
-
appendChildren(child.children ?? [], childPrefix, lines);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
64
|
// src/rune/commands/batch-permission.js
|
|
112
65
|
init_require_shim();
|
|
113
66
|
function buildMatchString(key, args) {
|
|
@@ -221,6 +174,25 @@ function parseRunArgs(argv) {
|
|
|
221
174
|
const segments = rawSegments.map(parseSegment);
|
|
222
175
|
return { segments, format, failFast, isBatch: allowBatch };
|
|
223
176
|
}
|
|
177
|
+
function framedSection(prefix, section) {
|
|
178
|
+
const rendered = renderSection(section);
|
|
179
|
+
if (!rendered) return null;
|
|
180
|
+
const lines = rendered.split("\n");
|
|
181
|
+
let contentStartIndex = 1;
|
|
182
|
+
let attrs = "";
|
|
183
|
+
if (lines[1] && lines[1].startsWith("[")) {
|
|
184
|
+
attrs = " " + lines[1];
|
|
185
|
+
contentStartIndex = 2;
|
|
186
|
+
}
|
|
187
|
+
return `${prefix} ${section.name}${attrs}
|
|
188
|
+
${lines.slice(contentStartIndex).join("\n")}
|
|
189
|
+
|
|
190
|
+
`;
|
|
191
|
+
}
|
|
192
|
+
function writeSection(direct, prefix, section) {
|
|
193
|
+
const text = direct ? (renderSection(section) ?? "") + "\n\n" : framedSection(prefix, section);
|
|
194
|
+
if (text) process.stdout.write(text);
|
|
195
|
+
}
|
|
224
196
|
async function handler({
|
|
225
197
|
segments,
|
|
226
198
|
format = "text",
|
|
@@ -244,8 +216,8 @@ async function handler({
|
|
|
244
216
|
process.exit(1);
|
|
245
217
|
}
|
|
246
218
|
if (isBatch) {
|
|
247
|
-
const { resolvePluginRune } = await import("./resolver-
|
|
248
|
-
const { loadPluginJson } = await import("./manifest-
|
|
219
|
+
const { resolvePluginRune } = await import("./resolver-CA2A32AC.js");
|
|
220
|
+
const { loadPluginJson } = await import("./manifest-76MIEL2F.js");
|
|
249
221
|
for (const seg of segments) {
|
|
250
222
|
let entry = config.runes?.[seg.key] ?? {};
|
|
251
223
|
if (!entry.batch && seg.key.includes(":")) {
|
|
@@ -266,7 +238,7 @@ async function handler({
|
|
|
266
238
|
const spaceIdx = matchString.indexOf(" ");
|
|
267
239
|
const subject = spaceIdx === -1 ? matchString : matchString.slice(spaceIdx + 1);
|
|
268
240
|
const lines = [`Batch not permitted for "${matchString}" \u2014 ${result.reason}.`, ""];
|
|
269
|
-
lines.push(` "batch" is a
|
|
241
|
+
lines.push(` "batch" is a field of the rune entry, beside "run" \u2014 not inside a block:`);
|
|
270
242
|
lines.push("");
|
|
271
243
|
lines.push(` "runes": { "${seg.key}": { "batch": { "allow": ["${subject}"] } } }`);
|
|
272
244
|
lines.push("");
|
|
@@ -279,6 +251,7 @@ async function handler({
|
|
|
279
251
|
}
|
|
280
252
|
}
|
|
281
253
|
let anyFailed = false;
|
|
254
|
+
const direct = !isBatch && format === "text" && segments.length === 1;
|
|
282
255
|
for (let i = 0; i < segments.length; i++) {
|
|
283
256
|
const printedSections = /* @__PURE__ */ new Set();
|
|
284
257
|
const { key, sections: sectionFilter, runeArgs } = segments[i];
|
|
@@ -289,6 +262,8 @@ async function handler({
|
|
|
289
262
|
sections: sectionFilter,
|
|
290
263
|
configDir: configRoot,
|
|
291
264
|
instanceId: String(i + 1),
|
|
265
|
+
direct,
|
|
266
|
+
stdin: isBatch ? "ignore" : "inherit",
|
|
292
267
|
onEvent(event) {
|
|
293
268
|
const { type, level, message, meta, section, instanceId: instanceId2, rune } = event;
|
|
294
269
|
const prefix = level ? `[${instanceId2}:${rune}:${type}:${level}]` : `[${instanceId2}:${rune}:${type}]`;
|
|
@@ -311,30 +286,21 @@ async function handler({
|
|
|
311
286
|
} else {
|
|
312
287
|
if (type === "section") {
|
|
313
288
|
if (!sectionFilter || isGlobMatch(section.name, sectionFilter)) {
|
|
314
|
-
|
|
315
|
-
const lines = rendered ? rendered.split("\n") : [];
|
|
316
|
-
let contentStartIndex = 1;
|
|
317
|
-
let attrs = "";
|
|
318
|
-
if (lines[1] && lines[1].startsWith("[")) {
|
|
319
|
-
attrs = " " + lines[1];
|
|
320
|
-
contentStartIndex = 2;
|
|
321
|
-
}
|
|
322
|
-
const content = lines.slice(contentStartIndex).join("\n");
|
|
323
|
-
process.stdout.write(`${prefix} ${section.name}${attrs}
|
|
324
|
-
${content}
|
|
325
|
-
|
|
326
|
-
`);
|
|
289
|
+
writeSection(direct, prefix, section);
|
|
327
290
|
printedSections.add(section);
|
|
328
291
|
}
|
|
329
292
|
} else {
|
|
330
293
|
const attrsStr = meta && Object.keys(meta).length > 0 ? " " + Object.entries(meta).map(([k, v]) => `[${k}: ${v}]`).join(" ") : "";
|
|
331
|
-
if (
|
|
332
|
-
process.
|
|
294
|
+
if (direct) {
|
|
295
|
+
process.stderr.write(`${message ?? ""}${attrsStr}
|
|
296
|
+
`);
|
|
297
|
+
} else if (message && message.includes("\n")) {
|
|
298
|
+
process.stderr.write(`${prefix}${attrsStr}
|
|
333
299
|
${message}
|
|
334
300
|
|
|
335
301
|
`);
|
|
336
302
|
} else {
|
|
337
|
-
process.
|
|
303
|
+
process.stderr.write(`${prefix} ${message ?? ""}${attrsStr}
|
|
338
304
|
`);
|
|
339
305
|
}
|
|
340
306
|
}
|
|
@@ -355,6 +321,7 @@ ${msg}${hint ?? ""}`);
|
|
|
355
321
|
if (failFast) process.exit(1);
|
|
356
322
|
continue;
|
|
357
323
|
}
|
|
324
|
+
if (sections?.directExitCode !== void 0) return process.exit(sections.directExitCode);
|
|
358
325
|
if (!sections) {
|
|
359
326
|
const available = Object.keys(config.runes ?? {}).join(", ") || "(none)";
|
|
360
327
|
output.error(`Unknown key: "${key}". Available: ${available}. Looked in: ${describeConfigLayers(configRoot ?? projectRoot)}.`);
|
|
@@ -375,22 +342,7 @@ ${msg}${hint ?? ""}`);
|
|
|
375
342
|
section: sect
|
|
376
343
|
}) + "\n");
|
|
377
344
|
} else {
|
|
378
|
-
|
|
379
|
-
if (rendered) {
|
|
380
|
-
const prefix = `[${instanceId}:${key}:section]`;
|
|
381
|
-
const lines = rendered.split("\n");
|
|
382
|
-
let contentStartIndex = 1;
|
|
383
|
-
let attrs = "";
|
|
384
|
-
if (lines[1] && lines[1].startsWith("[")) {
|
|
385
|
-
attrs = " " + lines[1];
|
|
386
|
-
contentStartIndex = 2;
|
|
387
|
-
}
|
|
388
|
-
const content = lines.slice(contentStartIndex).join("\n");
|
|
389
|
-
process.stdout.write(`${prefix} ${sect.name}${attrs}
|
|
390
|
-
${content}
|
|
391
|
-
|
|
392
|
-
`);
|
|
393
|
-
}
|
|
345
|
+
writeSection(direct, `[${instanceId}:${key}:section]`, sect);
|
|
394
346
|
}
|
|
395
347
|
printedSections.add(sect);
|
|
396
348
|
}
|
|
@@ -401,7 +353,6 @@ ${content}
|
|
|
401
353
|
|
|
402
354
|
export {
|
|
403
355
|
permissionHint,
|
|
404
|
-
formatSection,
|
|
405
356
|
parseBracketKey,
|
|
406
357
|
joinBracketTokens,
|
|
407
358
|
parseSegment,
|
|
@@ -27,7 +27,9 @@ async function saveRegistry(data) {
|
|
|
27
27
|
async function registerPlugin(entry) {
|
|
28
28
|
const registry = await loadRegistry();
|
|
29
29
|
const key = `${entry.marketplaceName}@${entry.name}`;
|
|
30
|
+
const trustedNative = registry.plugins[key]?.trustedNative;
|
|
30
31
|
registry.plugins[key] = {
|
|
32
|
+
...trustedNative && { trustedNative },
|
|
31
33
|
version: entry.version,
|
|
32
34
|
path: entry.path,
|
|
33
35
|
cacheDir: entry.cacheDir ?? entry.path,
|