@darkrymit/crunes-cli 0.8.5 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{add-CBHWFGCA.js → add-IT3IHBPO.js} +2 -2
- package/dist/chunks/add-MSX6XSU3.js +68 -0
- package/dist/chunks/{apply-J4YICV6H.js → apply-LOIJIPLR.js} +21 -12
- package/dist/chunks/{benchmark-AKKV7G32.js → benchmark-3IHFP3V2.js} +27 -18
- package/dist/chunks/{browse-JZFU52ET.js → browse-PHMBDREQ.js} +2 -2
- 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-6MRZXASS.js → chunk-2Q3KLBE6.js} +16 -0
- package/dist/chunks/{chunk-ZJDKCC2Y.js → chunk-4GJMCFR6.js} +6 -3
- 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-J3GZ3DXD.js → chunk-GVMT55GH.js} +3 -2
- package/dist/chunks/chunk-H2OT7D6N.js +303 -0
- package/dist/chunks/{chunk-JOAL437H.js → chunk-I6MHDUCW.js} +16 -1
- package/dist/chunks/chunk-KSQDFE5N.js +85 -0
- package/dist/chunks/{chunk-BTIPUR5S.js → chunk-KUEMDPNG.js} +108 -91
- package/dist/chunks/{chunk-6XLT25GS.js → chunk-MIKWIFYR.js} +47 -0
- package/dist/chunks/{chunk-GTCPZ22N.js → chunk-MTJ2KW3V.js} +3 -1
- package/dist/chunks/chunk-MVCBPI4J.js +2354 -0
- package/dist/chunks/{chunk-T53L5CJW.js → chunk-PBGUKXT6.js} +2887 -1874
- package/dist/chunks/{chunk-KII6KW5Z.js → chunk-RVBAAXRY.js} +64 -44
- package/dist/chunks/chunk-SUCYDYMU.js +44 -0
- package/dist/chunks/chunk-UBCAZGLE.js +15 -0
- package/dist/chunks/{chunk-63H5VXZY.js → chunk-UEUUOAJY.js} +4 -1
- package/dist/chunks/chunk-VP7YLCQP.js +244 -0
- package/dist/chunks/{chunk-NDEYEYSU.js → chunk-WJII3LZK.js} +4 -3
- package/dist/chunks/chunk-XDMMSZIL.js +71 -0
- package/dist/chunks/chunk-YKIKJHYO.js +94 -0
- package/dist/chunks/{chunk-NYLRTAAA.js → chunk-YVN3VDRE.js} +1 -1
- package/dist/chunks/{clear-YBDIPEEH.js → clear-AT7HNUV4.js} +2 -2
- package/dist/chunks/{create-L6DJN4ME.js → create-DXW4YYLJ.js} +8 -8
- package/dist/chunks/create-LPLNCOW4.js +268 -0
- package/dist/chunks/{create-GPDE2YKL.js → create-Y4LHLWGL.js} +26 -18
- package/dist/chunks/{delete-LNOYM5KG.js → delete-2EXPFBFC.js} +2 -2
- package/dist/chunks/{delete-E4TEBRPX.js → delete-GKYA2W5Z.js} +4 -2
- package/dist/chunks/{delete-C4UJ7X5K.js → delete-MJAECXXV.js} +2 -2
- package/dist/chunks/disable-TITOSMXB.js +43 -0
- package/dist/chunks/doctor-R2Y6UAY4.js +208 -0
- package/dist/chunks/enable-LGTPDWPV.js +35 -0
- package/dist/chunks/{globals-H2WF344Y.js → globals-SNQFCHMP.js} +1 -1
- package/dist/chunks/{init-HU5OMHEH.js → init-KO2HLED5.js} +18 -8
- package/dist/chunks/install-7IRUAGSF.js +64 -0
- package/dist/chunks/{intro-36OLGNYN.js → intro-JNJ6A75J.js} +89 -21
- package/dist/chunks/{kill-2UG7PHUV.js → kill-TX3PC73P.js} +2 -1
- package/dist/chunks/{list-2JYMBMZC.js → list-BCCM3TLP.js} +12 -7
- package/dist/chunks/{list-4X3JFQGS.js → list-EHREZR6M.js} +2 -1
- package/dist/chunks/{list-U7PAYNAH.js → list-LC6HB3H3.js} +2 -2
- package/dist/chunks/list-MLKZE36K.js +92 -0
- package/dist/chunks/list-QVZKR3IE.js +62 -0
- package/dist/chunks/{list-7VHJIUDX.js → list-U4EMHQZT.js} +2 -2
- package/dist/chunks/{list-PTAWQYWG.js → list-V7VVD5AG.js} +2 -1
- package/dist/chunks/{list-A5WVDBWF.js → list-VA73WPK6.js} +2 -2
- package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
- package/dist/chunks/migrate-Y3EKMVP5.js +87 -0
- package/dist/chunks/{output-RJ6JSNY7.js → output-QN5CVJ62.js} +4 -1
- package/dist/chunks/{query-AW7WYILM.js → query-2US3CPYT.js} +2 -2
- package/dist/chunks/{registry-RG34DPD7.js → registry-IWP7JMNI.js} +2 -2
- package/dist/chunks/{remove-QUH2D3S5.js → remove-BCFTF23J.js} +2 -2
- package/dist/chunks/{repl-STBZC4P2.js → repl-2YWTHUWT.js} +4 -0
- package/dist/chunks/{repl-BPEWARN7.js → repl-5GDN3RAO.js} +99 -31
- package/dist/chunks/resolver-CA2A32AC.js +36 -0
- package/dist/chunks/run-WL3IZBXF.js +35 -0
- package/dist/chunks/rune-YA4TFHTB.js +283 -0
- package/dist/chunks/runner-QNZMBHQY.js +34 -0
- package/dist/chunks/{search-MSSDGJTF.js → search-B7IM7JRJ.js} +2 -2
- package/dist/chunks/shell-explain-LKBBP2BG.js +77 -0
- package/dist/chunks/trust-BFIDANXD.js +109 -0
- package/dist/chunks/uninstall-3MWZIZVA.js +58 -0
- package/dist/chunks/{unset-YASSMSE5.js → unset-P6IUF7SS.js} +2 -2
- package/dist/chunks/{update-KSC6VRMU.js → update-W4MJUTTW.js} +25 -19
- package/dist/chunks/{update-EWWDROKW.js → update-WXT7CHYA.js} +2 -2
- package/dist/chunks/{utils-3SJFSUSV.js → utils-B2QULX5J.js} +8 -4
- package/dist/chunks/{version-YG2M7HER.js → version-FLHI5KFS.js} +3 -3
- package/dist/cli.js +115 -70
- package/package.json +2 -2
- package/dist/chunks/chunk-ASZKAC24.js +0 -103
- package/dist/chunks/chunk-G3U4V32O.js +0 -46
- package/dist/chunks/chunk-GSA432UC.js +0 -90
- package/dist/chunks/chunk-WJRZN7BR.js +0 -77492
- package/dist/chunks/create-VYZRWRGQ.js +0 -170
- package/dist/chunks/disable-FGJ7VMPO.js +0 -47
- package/dist/chunks/doctor-7NWBJAH7.js +0 -53
- package/dist/chunks/enable-ZL6QOC2I.js +0 -47
- package/dist/chunks/install-FIYRMVLR.js +0 -57
- package/dist/chunks/list-AIYNOPNZ.js +0 -28
- package/dist/chunks/list-NZ5DHXJF.js +0 -111
- package/dist/chunks/resolver-36V72VKR.js +0 -28
- package/dist/chunks/run-IVL23SMW.js +0 -26
- package/dist/chunks/rune-XRREUL56.js +0 -186
- package/dist/chunks/uninstall-G56DZRFG.js +0 -49
|
@@ -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
|
+
};
|
|
@@ -2,9 +2,10 @@ import {
|
|
|
2
2
|
storageKey
|
|
3
3
|
} from "./chunk-G4ZAUHHA.js";
|
|
4
4
|
import {
|
|
5
|
+
getLocalBase,
|
|
5
6
|
getSqliteBasePath,
|
|
6
7
|
getSqliteJsonPath
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2Q3KLBE6.js";
|
|
8
9
|
import {
|
|
9
10
|
init_require_shim
|
|
10
11
|
} from "./chunk-TPK5AGRA.js";
|
|
@@ -40,7 +41,7 @@ async function listSqliteDbs() {
|
|
|
40
41
|
}
|
|
41
42
|
async function listLocalSqliteDbs(projectDir) {
|
|
42
43
|
const results = [];
|
|
43
|
-
const localSqliteDir = path.join(projectDir, "
|
|
44
|
+
const localSqliteDir = path.join(getLocalBase(projectDir), "sqlite");
|
|
44
45
|
async function scanScope(scopeDir, scope, pluginId = null) {
|
|
45
46
|
let entries;
|
|
46
47
|
try {
|
|
@@ -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
|
+
};
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
init_require_shim();
|
|
7
7
|
var KIND_MODULE = 2;
|
|
8
8
|
var KIND_NAMESPACE = 4;
|
|
9
|
+
var KIND_VARIABLE = 32;
|
|
9
10
|
var KIND_FUNCTION = 64;
|
|
10
11
|
var KIND_CLASS = 128;
|
|
11
12
|
var KIND_INTERFACE = 256;
|
|
@@ -146,6 +147,13 @@ function walkChildren(children) {
|
|
|
146
147
|
returnsDescription: returnsComment(sig.comment) || void 0
|
|
147
148
|
});
|
|
148
149
|
}
|
|
150
|
+
} else if (child.kind === KIND_VARIABLE) {
|
|
151
|
+
members.push({
|
|
152
|
+
kind: "variable",
|
|
153
|
+
name: child.name,
|
|
154
|
+
type: typeStr(child.type),
|
|
155
|
+
description: commentText(child.comment) || void 0
|
|
156
|
+
});
|
|
149
157
|
} else if (child.kind === KIND_CLASS) {
|
|
150
158
|
members.push({ kind: "class", ...walkClassOrInterface(child) });
|
|
151
159
|
} else if (child.kind === KIND_INTERFACE) {
|
|
@@ -218,6 +226,11 @@ function renderFunction(node, indent) {
|
|
|
218
226
|
lines.push(...renderFunctionBody(node, indent));
|
|
219
227
|
return lines.join("\n");
|
|
220
228
|
}
|
|
229
|
+
function renderVariable(node, indent) {
|
|
230
|
+
const lines = [`${indent}${node.name}: ${node.type}`];
|
|
231
|
+
if (node.description) lines.push(`${indent} ${indentDesc(node.description, indent + " ")}`);
|
|
232
|
+
return lines.join("\n");
|
|
233
|
+
}
|
|
221
234
|
function renderProperty(p, indent) {
|
|
222
235
|
const ro = p.readonly ? "readonly " : "";
|
|
223
236
|
const opt = p.optional ? "?" : "";
|
|
@@ -278,6 +291,8 @@ function formatNode(node, { prefix = "", indent = "" } = {}) {
|
|
|
278
291
|
return renderNamespace(node, { prefix, indent });
|
|
279
292
|
case "function":
|
|
280
293
|
return renderFunction(node, indent);
|
|
294
|
+
case "variable":
|
|
295
|
+
return renderVariable(node, indent);
|
|
281
296
|
case "class":
|
|
282
297
|
case "interface":
|
|
283
298
|
return renderClassOrInterface(node, indent);
|
|
@@ -287,7 +302,7 @@ function formatNode(node, { prefix = "", indent = "" } = {}) {
|
|
|
287
302
|
}
|
|
288
303
|
function formatMembers(members, { prefix = "", indent = "" } = {}) {
|
|
289
304
|
const sorted = [...members ?? []].sort((a, b) => {
|
|
290
|
-
const rank = (k) => k === "namespace" ? 0 : k === "
|
|
305
|
+
const rank = (k) => k === "namespace" ? 0 : k === "variable" ? 1 : k === "function" ? 2 : 3;
|
|
291
306
|
return rank(a.kind) - rank(b.kind);
|
|
292
307
|
});
|
|
293
308
|
return sorted.map((m) => formatNode(m, { prefix, indent })).filter(Boolean).join("\n\n");
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runtimeOf
|
|
3
|
+
} from "./chunk-2DNYVKBF.js";
|
|
4
|
+
import {
|
|
5
|
+
isNativeRune
|
|
6
|
+
} from "./chunk-XDMMSZIL.js";
|
|
7
|
+
import {
|
|
8
|
+
enabledPluginKeys,
|
|
9
|
+
getRune
|
|
10
|
+
} from "./chunk-2FI6KN3C.js";
|
|
11
|
+
import {
|
|
12
|
+
blockOf
|
|
13
|
+
} from "./chunk-YKIKJHYO.js";
|
|
14
|
+
import {
|
|
15
|
+
init_require_shim
|
|
16
|
+
} from "./chunk-TPK5AGRA.js";
|
|
17
|
+
|
|
18
|
+
// src/rune/enumerate.js
|
|
19
|
+
init_require_shim();
|
|
20
|
+
async function enumerateRunes(config) {
|
|
21
|
+
const runes = config?.runes ?? {};
|
|
22
|
+
const entries = [];
|
|
23
|
+
const overrideKeys = [];
|
|
24
|
+
for (const key of Object.keys(runes)) {
|
|
25
|
+
if (/@[^:]+:/.test(key)) {
|
|
26
|
+
overrideKeys.push(key);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const entry = getRune(config, key);
|
|
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}` : "";
|
|
38
|
+
entries.push({ key, source, name: entry.name ?? null, description: entry.description ?? null });
|
|
39
|
+
}
|
|
40
|
+
const enabledPlugins = enabledPluginKeys(config);
|
|
41
|
+
if (enabledPlugins.length > 0) {
|
|
42
|
+
try {
|
|
43
|
+
const { loadRegistry } = await import("./registry-IWP7JMNI.js");
|
|
44
|
+
const { loadPluginJson } = await import("./manifest-76MIEL2F.js");
|
|
45
|
+
const registry = await loadRegistry();
|
|
46
|
+
for (const pluginKey of enabledPlugins) {
|
|
47
|
+
const entry = registry.plugins?.[pluginKey];
|
|
48
|
+
if (!entry) continue;
|
|
49
|
+
let pluginJson;
|
|
50
|
+
try {
|
|
51
|
+
pluginJson = await loadPluginJson(entry.path);
|
|
52
|
+
} catch {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
for (const [runeKey, runeEntry] of Object.entries(pluginJson.runes ?? {})) {
|
|
56
|
+
const idx = pluginKey.indexOf("@");
|
|
57
|
+
const shortName = idx !== -1 ? pluginKey.slice(idx + 1) : pluginKey;
|
|
58
|
+
const displayKey = `${shortName}:${runeKey}`;
|
|
59
|
+
if (!entries.some((e) => e.key === displayKey)) {
|
|
60
|
+
entries.push({
|
|
61
|
+
key: displayKey,
|
|
62
|
+
source: `plugin: ${pluginKey}`,
|
|
63
|
+
...isNativeRune(runeEntry) && { runtime: runtimeOf(blockOf(runeEntry, "run").command) },
|
|
64
|
+
name: runeEntry.name ?? null,
|
|
65
|
+
description: runeEntry.description ?? null
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const key of overrideKeys) {
|
|
74
|
+
const runeKey = key.slice(key.lastIndexOf(":") + 1);
|
|
75
|
+
const shortName = key.slice(key.indexOf("@") + 1, key.lastIndexOf(":"));
|
|
76
|
+
if (entries.some((e) => e.key === `${shortName}:${runeKey}`)) continue;
|
|
77
|
+
const entry = getRune(config, key);
|
|
78
|
+
entries.push({ key, source: "", name: entry.name ?? null, description: entry.description ?? null });
|
|
79
|
+
}
|
|
80
|
+
return entries;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
enumerateRunes
|
|
85
|
+
};
|