@darkrymit/crunes-cli 0.5.10 → 0.7.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/README.md +5 -5
- package/dist/chunks/add-OWYVF3IE.js +22 -0
- package/dist/chunks/apply-OMEVXCHC.js +183 -0
- package/dist/chunks/args-32BVYW77.js +42 -0
- package/dist/chunks/benchmark-CLUBISCR.js +164 -0
- package/dist/chunks/browse-COH6IJEX.js +34 -0
- package/dist/chunks/check-BS6TZGRR.js +144 -0
- package/dist/chunks/chunk-2Q24YPGL.js +369 -0
- package/dist/chunks/chunk-3TM6B4E5.js +70 -0
- package/dist/chunks/chunk-67I2J474.js +153 -0
- package/dist/chunks/chunk-6XLT25GS.js +50 -0
- package/dist/chunks/chunk-BVY5LN7X.js +25091 -0
- package/dist/chunks/chunk-CGZL5SSH.js +926 -0
- package/dist/chunks/chunk-DMMC4X27.js +1836 -0
- package/dist/chunks/chunk-G3U4V32O.js +46 -0
- package/dist/chunks/chunk-GHQOK4L7.js +59 -0
- package/dist/chunks/chunk-H3BVJCIL.js +105 -0
- package/dist/chunks/chunk-HMU2J25D.js +63 -0
- package/dist/chunks/chunk-HOH7WZX4.js +95 -0
- package/dist/chunks/chunk-L72BG6DS.js +225 -0
- package/dist/chunks/chunk-NXSDVVTW.js +181 -0
- package/dist/chunks/chunk-QLDB3FO2.js +73059 -0
- package/dist/chunks/chunk-QMWGQXEZ.js +26 -0
- package/dist/chunks/chunk-TPK5AGRA.js +54 -0
- package/dist/chunks/chunk-UGN3FFEF.js +8379 -0
- package/dist/chunks/chunk-WCODTMDN.js +508 -0
- package/dist/chunks/chunk-XIXND2M4.js +296 -0
- package/dist/chunks/chunk-XXUNHQIB.js +129 -0
- package/dist/chunks/chunk-ZXIP4Z5V.js +281 -0
- package/dist/chunks/clear-Y5POLIMF.js +32 -0
- package/dist/chunks/completions-2MSEWWTG.js +232 -0
- package/dist/chunks/create-5FXQYCGM.js +165 -0
- package/dist/chunks/create-I6BNYZ5Q.js +247 -0
- package/dist/chunks/create-O3HMODSL.js +130 -0
- package/dist/chunks/delete-7CQFYIXS.js +40 -0
- package/dist/chunks/delete-UB5SXO5I.js +40 -0
- package/dist/chunks/disable-FCBW7WVG.js +47 -0
- package/dist/chunks/doctor-DS57HDLJ.js +53 -0
- package/dist/chunks/enable-IXRVUXJM.js +47 -0
- package/dist/chunks/esm-7MEWZCHY.js +5162 -0
- package/dist/chunks/globals-YCJ2DGWC.js +60 -0
- package/dist/chunks/init-WGKQVAZE.js +59 -0
- package/dist/chunks/install-BCTBOPBS.js +57 -0
- package/dist/chunks/intro-2UDWF6D4.js +1482 -0
- package/dist/chunks/kill-LWRXZVM5.js +37 -0
- package/dist/chunks/list-5DVVP7HX.js +50 -0
- package/dist/chunks/list-6WL5LGIZ.js +80 -0
- package/dist/chunks/list-NGOCMJXE.js +104 -0
- package/dist/chunks/list-TTKLNJKI.js +28 -0
- package/dist/chunks/list-WUAOSO3M.js +110 -0
- package/dist/chunks/list-YPI7YDKK.js +80 -0
- package/dist/chunks/list-ZBYPMUID.js +23 -0
- package/dist/chunks/manifest-7RVNKBOH.js +9 -0
- package/dist/chunks/output-RJ6JSNY7.js +12 -0
- package/dist/chunks/promise-DUSIQMA2.js +19400 -0
- package/dist/chunks/query-NY4SCO77.js +41 -0
- package/dist/chunks/registry-W5XFI5T6.js +16 -0
- package/dist/chunks/remove-WEAZFZCO.js +22 -0
- package/dist/chunks/run-I6TZX347.js +23 -0
- package/dist/chunks/run-MVIZQVJ6.js +36 -0
- package/dist/chunks/rune-TAX26NH2.js +76 -0
- package/dist/chunks/search-XENXL3GC.js +25 -0
- package/dist/chunks/uninstall-MX5PLGDI.js +49 -0
- package/dist/chunks/unset-KQOZYVTE.js +28 -0
- package/dist/chunks/update-7XDTVFZ3.js +39 -0
- package/dist/chunks/update-IEE54GPY.js +79 -0
- package/dist/chunks/utils-PO3ZK53L.js +50 -0
- package/dist/chunks/version-DIEA5FVV.js +145 -0
- package/dist/cli.js +3360 -125840
- package/package.json +23 -15
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@ Crunes allows developers and AI coding agents to write and run secure, sandboxed
|
|
|
9
9
|
## Key Features
|
|
10
10
|
|
|
11
11
|
* **V8 Sandbox Isolation:** Runes are evaluated inside secure `isolated-vm` sandboxes with zero direct access to Node.js builtins.
|
|
12
|
-
* **Capability-Based Security:** Fine-grained whitelist and blacklist rules (e.g. `fs.read:src/**`, `http.fetch:GET
|
|
12
|
+
* **Capability-Based Security:** Fine-grained whitelist and blacklist rules (e.g. `fs.read:src/**`, `http.fetch:GET::https://api.github.com/*`) configured at the project level.
|
|
13
13
|
* **Premium Developer Experience:** Modern modular scripting (`import { fs, section } from '@utils'`) with native TypeScript types and autocompletion.
|
|
14
|
-
* **Interactive Tooling:** Shell sessions, background daemon jobs, built-in SQLite/JSON/YAML parsers, and
|
|
14
|
+
* **Interactive Tooling:** Shell sessions, background daemon jobs, built-in SQLite/JSON/YAML parsers, custom templates, and loopback HTTP/WebSocket servers with path-param routing.
|
|
15
15
|
* **AI-First Design:** Outputs cleanly formatted Markdown structures optimised for AI context window ingestion and pipe/CLI pipelines.
|
|
16
16
|
|
|
17
17
|
---
|
|
@@ -42,7 +42,7 @@ crunes init
|
|
|
42
42
|
crunes create fetch-status
|
|
43
43
|
|
|
44
44
|
# Run the rune and output the markdown sections
|
|
45
|
-
crunes
|
|
45
|
+
crunes run fetch-status
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
---
|
|
@@ -53,7 +53,7 @@ crunes use fetch-status
|
|
|
53
53
|
# Core Operations
|
|
54
54
|
crunes init # Create .crunes/config.json in current project
|
|
55
55
|
crunes create [key] # Scaffold a new rune and register it in config
|
|
56
|
-
crunes
|
|
56
|
+
crunes run <key> [args...] # Run a rune (use -b for batch execution)
|
|
57
57
|
crunes check <key> # Execute a rune and validate its return schema
|
|
58
58
|
crunes bench <key> # Profile execution time (fast/ok/slow)
|
|
59
59
|
crunes list # List all registered local and plugin runes
|
|
@@ -69,7 +69,7 @@ crunes job kill <id> # Forcefully terminate a running background
|
|
|
69
69
|
|
|
70
70
|
# Templates, Plugins, and Markets
|
|
71
71
|
crunes template list # List available rune templates
|
|
72
|
-
crunes template
|
|
72
|
+
crunes template apply <name> # Copy a template as a new local rune
|
|
73
73
|
crunes plugin install <pkg> # Install a secure plugin from marketplace
|
|
74
74
|
crunes plugin list # List active marketplace plugins
|
|
75
75
|
crunes marketplace add <url> # Register a marketplace source
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addMarketplace
|
|
3
|
+
} from "./chunk-L72BG6DS.js";
|
|
4
|
+
import "./chunk-HMU2J25D.js";
|
|
5
|
+
import {
|
|
6
|
+
init_require_shim
|
|
7
|
+
} from "./chunk-TPK5AGRA.js";
|
|
8
|
+
|
|
9
|
+
// src/marketplace/commands/add.js
|
|
10
|
+
init_require_shim();
|
|
11
|
+
async function handler({ url }) {
|
|
12
|
+
try {
|
|
13
|
+
await addMarketplace(url);
|
|
14
|
+
console.log(`Marketplace "${url}" added.`);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error(`Error: ${err.message}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
handler
|
|
22
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fe,
|
|
3
|
+
ge,
|
|
4
|
+
le,
|
|
5
|
+
ye
|
|
6
|
+
} from "./chunk-CGZL5SSH.js";
|
|
7
|
+
import {
|
|
8
|
+
loadConfig
|
|
9
|
+
} from "./chunk-H3BVJCIL.js";
|
|
10
|
+
import {
|
|
11
|
+
output
|
|
12
|
+
} from "./chunk-6XLT25GS.js";
|
|
13
|
+
import "./chunk-WCODTMDN.js";
|
|
14
|
+
import {
|
|
15
|
+
loadRegistry,
|
|
16
|
+
resolvePluginKey
|
|
17
|
+
} from "./chunk-GHQOK4L7.js";
|
|
18
|
+
import "./chunk-HMU2J25D.js";
|
|
19
|
+
import {
|
|
20
|
+
loadPluginJson
|
|
21
|
+
} from "./chunk-G3U4V32O.js";
|
|
22
|
+
import {
|
|
23
|
+
init_require_shim
|
|
24
|
+
} from "./chunk-TPK5AGRA.js";
|
|
25
|
+
|
|
26
|
+
// src/template/commands/apply.js
|
|
27
|
+
init_require_shim();
|
|
28
|
+
import fs from "node:fs/promises";
|
|
29
|
+
import path from "node:path";
|
|
30
|
+
async function resolveTemplate(sourceName, templateName, projectRoot) {
|
|
31
|
+
if (!sourceName || sourceName === "project") {
|
|
32
|
+
let config = { templates: {} };
|
|
33
|
+
try {
|
|
34
|
+
config = loadConfig(projectRoot);
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
const templates = config.templates ?? {};
|
|
38
|
+
const entry = templates[templateName];
|
|
39
|
+
if (entry !== void 0) {
|
|
40
|
+
if (typeof entry === "string" || entry.path) {
|
|
41
|
+
return { type: "local", templateName, entry };
|
|
42
|
+
}
|
|
43
|
+
if (entry.plugin) {
|
|
44
|
+
return { type: "shortcut", templateName, entry };
|
|
45
|
+
}
|
|
46
|
+
return { type: "local", templateName, entry: { ...entry, path: `.crunes/templates/${templateName}.js` } };
|
|
47
|
+
}
|
|
48
|
+
if (sourceName === "project") return null;
|
|
49
|
+
}
|
|
50
|
+
const registry = await loadRegistry();
|
|
51
|
+
const matches = [];
|
|
52
|
+
for (const [pluginKey, pluginEntry] of Object.entries(registry.plugins ?? {})) {
|
|
53
|
+
const pluginName = pluginKey.slice(pluginKey.indexOf("@") + 1);
|
|
54
|
+
if (sourceName && sourceName !== pluginName && sourceName !== pluginKey) continue;
|
|
55
|
+
if (!pluginEntry.path) continue;
|
|
56
|
+
let pluginJson;
|
|
57
|
+
try {
|
|
58
|
+
pluginJson = await loadPluginJson(pluginEntry.path);
|
|
59
|
+
} catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const templateMeta = (pluginJson.templates ?? {})[templateName];
|
|
63
|
+
if (templateMeta) {
|
|
64
|
+
matches.push({ pluginName, pluginEntry, pluginJson, templateMeta });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (matches.length > 1) {
|
|
68
|
+
const sources = matches.map((m) => m.pluginName).join(", ");
|
|
69
|
+
output.error(`"${templateName}" matches templates in multiple sources: ${sources}. Use source:${templateName}.`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
if (matches.length === 1) {
|
|
73
|
+
return { type: "plugin", templateName, ...matches[0] };
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
async function handler({
|
|
78
|
+
ref,
|
|
79
|
+
key,
|
|
80
|
+
path: runeRelPath,
|
|
81
|
+
name,
|
|
82
|
+
description,
|
|
83
|
+
yes = false,
|
|
84
|
+
projectRoot = process.cwd()
|
|
85
|
+
} = {}) {
|
|
86
|
+
const isNonInteractive = yes || !process.stdout.isTTY;
|
|
87
|
+
let sourceName = null;
|
|
88
|
+
let templateName = ref;
|
|
89
|
+
if (ref && ref.includes(":")) {
|
|
90
|
+
const colonIdx = ref.indexOf(":");
|
|
91
|
+
sourceName = ref.slice(0, colonIdx);
|
|
92
|
+
templateName = ref.slice(colonIdx + 1);
|
|
93
|
+
}
|
|
94
|
+
const resolved = await resolveTemplate(sourceName, templateName, projectRoot);
|
|
95
|
+
if (!resolved) {
|
|
96
|
+
output.error(`Template "${templateName}" not found. Run: crunes template list`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
const outputKey = key ?? templateName;
|
|
100
|
+
runeRelPath = runeRelPath ?? `.crunes/runes/${outputKey}.js`;
|
|
101
|
+
const runeAbsPath = path.join(projectRoot, runeRelPath);
|
|
102
|
+
if (!isNonInteractive) ye("crunes template apply");
|
|
103
|
+
try {
|
|
104
|
+
await fs.access(runeAbsPath);
|
|
105
|
+
if (!isNonInteractive) {
|
|
106
|
+
const ok = await le({ message: `${runeRelPath} already exists. Overwrite?` });
|
|
107
|
+
if (!ok || ok === /* @__PURE__ */ Symbol.for("clack:cancel")) {
|
|
108
|
+
ge("Cancelled.");
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
await fs.mkdir(path.dirname(runeAbsPath), { recursive: true });
|
|
115
|
+
let templateMeta = {};
|
|
116
|
+
if (resolved.type === "local") {
|
|
117
|
+
const localPath = typeof resolved.entry === "string" ? resolved.entry : resolved.entry.path;
|
|
118
|
+
await fs.copyFile(path.join(projectRoot, localPath), runeAbsPath);
|
|
119
|
+
templateMeta = typeof resolved.entry === "string" ? {} : resolved.entry;
|
|
120
|
+
} else if (resolved.type === "shortcut") {
|
|
121
|
+
const pluginRef = resolved.entry.plugin;
|
|
122
|
+
const colonIdx = pluginRef.indexOf(":");
|
|
123
|
+
const pluginBareName = pluginRef.slice(0, colonIdx);
|
|
124
|
+
const pluginTemplateKey = pluginRef.slice(colonIdx + 1);
|
|
125
|
+
const registry = await loadRegistry();
|
|
126
|
+
const pluginKey = resolvePluginKey(pluginBareName, registry);
|
|
127
|
+
if (!pluginKey) {
|
|
128
|
+
output.error(`Template shortcut "${templateName}" \u2192 "${pluginRef}" is not enabled or installed.`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
const pluginEntry = registry.plugins[pluginKey];
|
|
132
|
+
let pluginJson;
|
|
133
|
+
try {
|
|
134
|
+
pluginJson = await loadPluginJson(pluginEntry.path);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
output.error(`Failed to load plugin "${pluginBareName}": ${e.message}`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
const meta = (pluginJson.templates ?? {})[pluginTemplateKey];
|
|
140
|
+
if (!meta) {
|
|
141
|
+
output.error(`Template shortcut "${templateName}" \u2192 "${pluginRef}" not found in plugin.`);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
const templateRelPath = meta?.path ?? `templates/${pluginTemplateKey}.js`;
|
|
145
|
+
const srcPath = path.join(pluginEntry.path, templateRelPath);
|
|
146
|
+
await fs.copyFile(srcPath, runeAbsPath);
|
|
147
|
+
templateMeta = { ...meta, ...resolved.entry.name && { name: resolved.entry.name }, ...resolved.entry.description && { description: resolved.entry.description } };
|
|
148
|
+
} else if (resolved.type === "plugin") {
|
|
149
|
+
const templateRelPath = resolved.templateMeta?.path ?? `templates/${resolved.templateName}.js`;
|
|
150
|
+
const srcPath = path.join(resolved.pluginEntry.path, templateRelPath);
|
|
151
|
+
await fs.copyFile(srcPath, runeAbsPath);
|
|
152
|
+
templateMeta = resolved.templateMeta;
|
|
153
|
+
}
|
|
154
|
+
const configPath = path.join(projectRoot, ".crunes", "config.json");
|
|
155
|
+
let config = { runes: {} };
|
|
156
|
+
try {
|
|
157
|
+
config = JSON.parse(await fs.readFile(configPath, "utf8"));
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
const resolvedName = name ?? templateMeta.name;
|
|
161
|
+
const resolvedDesc = description ?? templateMeta.description;
|
|
162
|
+
const configEntry = {
|
|
163
|
+
path: runeRelPath,
|
|
164
|
+
...resolvedName && { name: resolvedName },
|
|
165
|
+
...resolvedDesc && { description: resolvedDesc },
|
|
166
|
+
...templateMeta.permissions && { permissions: templateMeta.permissions }
|
|
167
|
+
};
|
|
168
|
+
config.runes = { ...config.runes ?? {}, [outputKey]: configEntry };
|
|
169
|
+
const tmp = configPath + ".tmp";
|
|
170
|
+
await fs.writeFile(tmp, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
171
|
+
await fs.rename(tmp, configPath);
|
|
172
|
+
if (!isNonInteractive) {
|
|
173
|
+
fe(`Created ${runeRelPath}
|
|
174
|
+
Run: crunes run ${outputKey}`);
|
|
175
|
+
} else {
|
|
176
|
+
output.success(`Created ${runeRelPath}`);
|
|
177
|
+
output.info(`Run: crunes run ${outputKey}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export {
|
|
181
|
+
handler,
|
|
182
|
+
resolveTemplate
|
|
183
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_require_shim
|
|
3
|
+
} from "./chunk-TPK5AGRA.js";
|
|
4
|
+
|
|
5
|
+
// src/docs/commands/args.js
|
|
6
|
+
init_require_shim();
|
|
7
|
+
async function handler() {
|
|
8
|
+
process.stdout.write(`# Docs: The args(builder) Export
|
|
9
|
+
|
|
10
|
+
Runes declare options, positionals, examples, and nested commands using \`export function args(builder)\`. This is executed inside a sandboxed V8 isolate context before running the rune or loading help text.
|
|
11
|
+
|
|
12
|
+
## 1. Builder Methods Reference
|
|
13
|
+
|
|
14
|
+
- **\`.option(flags, description, defaultValue?)\`**: Declares a named flag.
|
|
15
|
+
- *Example*: \`b.option('-c, --count <number>', 'Max results', 10)\`
|
|
16
|
+
- **\`.positional(spec, description)\`**: Declares a descriptive positional parameter.
|
|
17
|
+
- *Example*: \`b.positional('<name>', 'Item name')\`
|
|
18
|
+
- **\`.example(usage, description)\`**: Adds a CLI calling example.
|
|
19
|
+
- *Example*: \`b.example('crunes run my-rune hello', 'Basic call')\`
|
|
20
|
+
- **\`.command(name, description, callback?)\`**: Declares a recursively nested command.
|
|
21
|
+
- *Example*:
|
|
22
|
+
\`\`\`javascript
|
|
23
|
+
b.command('remote', 'Manage remotes', remote => {
|
|
24
|
+
remote.command('add', 'Add a remote repository')
|
|
25
|
+
})
|
|
26
|
+
\`\`\`
|
|
27
|
+
|
|
28
|
+
## 2. Sandbox Extraction & Implicit Build Gotcha
|
|
29
|
+
The arguments builder runs inside a strict, secure V8 isolate. Because functions (methods) cannot cross the sandbox-host boundary directly, the host automatically calls \`.build()\` inside the sandbox.
|
|
30
|
+
|
|
31
|
+
Developers can return the builder chain directly without appending \`.build()\`:
|
|
32
|
+
\`\`\`javascript
|
|
33
|
+
export function args(b) {
|
|
34
|
+
return b.positional('<query>', 'Query search') // Implicitly built!
|
|
35
|
+
}
|
|
36
|
+
\`\`\`
|
|
37
|
+
|
|
38
|
+
`);
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
handler
|
|
42
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseSegment
|
|
3
|
+
} from "./chunk-ZXIP4Z5V.js";
|
|
4
|
+
import {
|
|
5
|
+
runRune
|
|
6
|
+
} from "./chunk-QLDB3FO2.js";
|
|
7
|
+
import "./chunk-67I2J474.js";
|
|
8
|
+
import "./chunk-XXUNHQIB.js";
|
|
9
|
+
import "./chunk-NXSDVVTW.js";
|
|
10
|
+
import "./chunk-QMWGQXEZ.js";
|
|
11
|
+
import "./chunk-3TM6B4E5.js";
|
|
12
|
+
import {
|
|
13
|
+
loadConfig
|
|
14
|
+
} from "./chunk-H3BVJCIL.js";
|
|
15
|
+
import {
|
|
16
|
+
output
|
|
17
|
+
} from "./chunk-6XLT25GS.js";
|
|
18
|
+
import {
|
|
19
|
+
source_default
|
|
20
|
+
} from "./chunk-WCODTMDN.js";
|
|
21
|
+
import "./chunk-GHQOK4L7.js";
|
|
22
|
+
import "./chunk-HMU2J25D.js";
|
|
23
|
+
import "./chunk-G3U4V32O.js";
|
|
24
|
+
import {
|
|
25
|
+
init_require_shim
|
|
26
|
+
} from "./chunk-TPK5AGRA.js";
|
|
27
|
+
|
|
28
|
+
// src/rune/commands/benchmark.js
|
|
29
|
+
init_require_shim();
|
|
30
|
+
import { performance } from "node:perf_hooks";
|
|
31
|
+
var FAST_MS = 200;
|
|
32
|
+
var SLOW_MS = 1e3;
|
|
33
|
+
var BAR_WIDTH = 10;
|
|
34
|
+
function label(ms) {
|
|
35
|
+
if (ms >= SLOW_MS) return "slow";
|
|
36
|
+
if (ms >= FAST_MS) return "ok";
|
|
37
|
+
return "fast";
|
|
38
|
+
}
|
|
39
|
+
function bar(ms, plain) {
|
|
40
|
+
const ratio = Math.min(ms / SLOW_MS, 1);
|
|
41
|
+
const filled = Math.round(ratio * BAR_WIDTH);
|
|
42
|
+
const empty = BAR_WIDTH - filled;
|
|
43
|
+
const fill = "\u2588".repeat(filled) + "\u2591".repeat(empty);
|
|
44
|
+
if (plain) return fill;
|
|
45
|
+
if (ms >= SLOW_MS) return source_default.red(fill);
|
|
46
|
+
if (ms >= FAST_MS) return source_default.yellow(fill);
|
|
47
|
+
return source_default.green(fill);
|
|
48
|
+
}
|
|
49
|
+
function labelColour(l, plain) {
|
|
50
|
+
if (plain) return l;
|
|
51
|
+
if (l === "slow") return source_default.red(l);
|
|
52
|
+
if (l === "ok") return source_default.yellow(l);
|
|
53
|
+
return source_default.green(l);
|
|
54
|
+
}
|
|
55
|
+
function parseBenchArgs(argv) {
|
|
56
|
+
let runs = 1;
|
|
57
|
+
let warmup = false;
|
|
58
|
+
let i = 0;
|
|
59
|
+
while (i < argv.length) {
|
|
60
|
+
const tok = argv[i];
|
|
61
|
+
if (tok === "--runs" && i + 1 < argv.length) {
|
|
62
|
+
runs = parseInt(argv[i + 1], 10);
|
|
63
|
+
i += 2;
|
|
64
|
+
} else if (tok.startsWith("--runs=")) {
|
|
65
|
+
runs = parseInt(tok.slice(7), 10);
|
|
66
|
+
i++;
|
|
67
|
+
} else if (tok === "--warmup") {
|
|
68
|
+
warmup = true;
|
|
69
|
+
i++;
|
|
70
|
+
} else {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const { key, sections, runeArgs } = parseSegment(argv.slice(i));
|
|
75
|
+
return { key, sections, runeArgs, runs, warmup };
|
|
76
|
+
}
|
|
77
|
+
async function handler({
|
|
78
|
+
key,
|
|
79
|
+
runeArgs = [],
|
|
80
|
+
runs = 1,
|
|
81
|
+
warmup = false,
|
|
82
|
+
plain = false,
|
|
83
|
+
projectRoot = process.cwd(),
|
|
84
|
+
configRoot = projectRoot
|
|
85
|
+
} = {}) {
|
|
86
|
+
if (!key) {
|
|
87
|
+
output.error("Missing required argument: <rune>");
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
if (!Number.isInteger(runs) || runs < 1) {
|
|
91
|
+
output.error("Invalid option: --runs must be a positive integer >= 1");
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
let config;
|
|
95
|
+
try {
|
|
96
|
+
config = loadConfig(configRoot);
|
|
97
|
+
} catch (err2) {
|
|
98
|
+
output.error(`Config unreadable: ${err2.message}`);
|
|
99
|
+
output.info("Run `crunes init` to create a config file.");
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
if (!plain) {
|
|
103
|
+
console.log(source_default.dim("\u2500".repeat(40)));
|
|
104
|
+
console.log(source_default.bold("crunes benchmark"));
|
|
105
|
+
console.log();
|
|
106
|
+
}
|
|
107
|
+
const times = [];
|
|
108
|
+
let err = null;
|
|
109
|
+
if (warmup) {
|
|
110
|
+
try {
|
|
111
|
+
await runRune(projectRoot, config, key, runeArgs, { configDir: configRoot });
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (let i = 0; i < runs; i++) {
|
|
116
|
+
const t0 = performance.now();
|
|
117
|
+
try {
|
|
118
|
+
await runRune(projectRoot, config, key, runeArgs, { configDir: configRoot });
|
|
119
|
+
} catch (e) {
|
|
120
|
+
err = e;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
times.push(performance.now() - t0);
|
|
124
|
+
}
|
|
125
|
+
const maxKeyLen = key.length;
|
|
126
|
+
let total = 0;
|
|
127
|
+
let slowCount = 0;
|
|
128
|
+
if (err) {
|
|
129
|
+
if (plain) {
|
|
130
|
+
process.stdout.write(`${key} error ${err.message}
|
|
131
|
+
`);
|
|
132
|
+
} else {
|
|
133
|
+
console.log(` ${source_default.dim(key.padEnd(maxKeyLen))} ${source_default.red("error")} ${source_default.dim(err.message)}`);
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
const avg = Math.round(times.reduce((a, b) => a + b, 0) / times.length);
|
|
137
|
+
const l = label(avg);
|
|
138
|
+
if (l === "slow") slowCount++;
|
|
139
|
+
total += avg;
|
|
140
|
+
if (plain) {
|
|
141
|
+
process.stdout.write(`${key} ${avg} ${l}
|
|
142
|
+
`);
|
|
143
|
+
} else {
|
|
144
|
+
const k = key.padEnd(maxKeyLen);
|
|
145
|
+
const warn = l === "slow" ? ` ${source_default.yellow("\u26A0")}` : "";
|
|
146
|
+
console.log(` ${source_default.cyan(k)} ${String(avg).padStart(6)}ms ${bar(avg, plain)} ${labelColour(l, plain)}${warn}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (plain) {
|
|
150
|
+
process.stdout.write(`total ${total}
|
|
151
|
+
slow-count ${slowCount}
|
|
152
|
+
`);
|
|
153
|
+
} else {
|
|
154
|
+
console.log();
|
|
155
|
+
const slowMsg = slowCount > 0 ? ` ${source_default.yellow("\u26A0")} ${slowCount} slow rune${slowCount > 1 ? "s" : ""} (> ${SLOW_MS}ms)` : ` ${source_default.green("\u2713")} All runes within acceptable range`;
|
|
156
|
+
console.log(` ${source_default.dim("Total:")} ${total}ms${runs > 1 ? ` (avg of ${runs} runs)` : ""}`);
|
|
157
|
+
console.log(slowMsg);
|
|
158
|
+
console.log();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export {
|
|
162
|
+
handler,
|
|
163
|
+
parseBenchArgs
|
|
164
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
searchMarketplaces
|
|
3
|
+
} from "./chunk-L72BG6DS.js";
|
|
4
|
+
import "./chunk-HMU2J25D.js";
|
|
5
|
+
import {
|
|
6
|
+
init_require_shim
|
|
7
|
+
} from "./chunk-TPK5AGRA.js";
|
|
8
|
+
|
|
9
|
+
// src/marketplace/commands/browse.js
|
|
10
|
+
init_require_shim();
|
|
11
|
+
async function handler({ format = "md" }) {
|
|
12
|
+
const results = await searchMarketplaces("");
|
|
13
|
+
if (results.length === 0) {
|
|
14
|
+
console.log("No plugins found in configured marketplaces.");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (format === "json") {
|
|
18
|
+
console.log(JSON.stringify(results, null, 2));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let currentMarketplace = null;
|
|
22
|
+
for (const plugin of results) {
|
|
23
|
+
if (plugin._marketplace !== currentMarketplace) {
|
|
24
|
+
currentMarketplace = plugin._marketplace;
|
|
25
|
+
console.log(`
|
|
26
|
+
${currentMarketplace}`);
|
|
27
|
+
}
|
|
28
|
+
const desc = plugin.description ? ` \u2014 ${plugin.description}` : "";
|
|
29
|
+
console.log(` ${plugin.name}${desc}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
handler
|
|
34
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runRune
|
|
3
|
+
} from "./chunk-QLDB3FO2.js";
|
|
4
|
+
import "./chunk-67I2J474.js";
|
|
5
|
+
import "./chunk-XXUNHQIB.js";
|
|
6
|
+
import "./chunk-NXSDVVTW.js";
|
|
7
|
+
import "./chunk-QMWGQXEZ.js";
|
|
8
|
+
import "./chunk-3TM6B4E5.js";
|
|
9
|
+
import {
|
|
10
|
+
loadConfig
|
|
11
|
+
} from "./chunk-H3BVJCIL.js";
|
|
12
|
+
import {
|
|
13
|
+
output
|
|
14
|
+
} from "./chunk-6XLT25GS.js";
|
|
15
|
+
import "./chunk-WCODTMDN.js";
|
|
16
|
+
import "./chunk-GHQOK4L7.js";
|
|
17
|
+
import "./chunk-HMU2J25D.js";
|
|
18
|
+
import "./chunk-G3U4V32O.js";
|
|
19
|
+
import {
|
|
20
|
+
init_require_shim
|
|
21
|
+
} from "./chunk-TPK5AGRA.js";
|
|
22
|
+
|
|
23
|
+
// src/rune/commands/check.js
|
|
24
|
+
init_require_shim();
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
import { join } from "node:path";
|
|
27
|
+
function scanPermissionWarnings(runeSource) {
|
|
28
|
+
const warnings = [];
|
|
29
|
+
const GATED_UTILS = ["utils.fs", "utils.shell", "utils.fetch", "utils.env", "utils.archive", "utils.cache"];
|
|
30
|
+
for (const u of GATED_UTILS) {
|
|
31
|
+
if (runeSource.includes(u)) {
|
|
32
|
+
warnings.push(u);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const importRegex = /import\s*\{\s*([^}]+)\s*\}\s*from\s*['"]@utils['"]/g;
|
|
36
|
+
let match;
|
|
37
|
+
const importedNames = /* @__PURE__ */ new Set();
|
|
38
|
+
while ((match = importRegex.exec(runeSource)) !== null) {
|
|
39
|
+
const names = match[1].split(",").map((n) => n.trim().split(/\s+as\s+/)[0]);
|
|
40
|
+
for (const name of names) {
|
|
41
|
+
if (name) importedNames.add(name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const namespaces = ["fs", "shell", "fetch", "env", "archive", "cache"];
|
|
45
|
+
for (const ns of namespaces) {
|
|
46
|
+
if (importedNames.has(ns)) {
|
|
47
|
+
const warningKey = `utils.${ns}`;
|
|
48
|
+
if (!warnings.includes(warningKey)) {
|
|
49
|
+
warnings.push(warningKey);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return warnings;
|
|
54
|
+
}
|
|
55
|
+
var KEBAB_RE = /^[a-z0-9-]+$/;
|
|
56
|
+
function checkSections(sections) {
|
|
57
|
+
const errors = [];
|
|
58
|
+
if (!Array.isArray(sections)) {
|
|
59
|
+
errors.push({ section: null, message: "use() must return an array" });
|
|
60
|
+
return errors;
|
|
61
|
+
}
|
|
62
|
+
const seen = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const sec of sections) {
|
|
64
|
+
const name = sec?.name;
|
|
65
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
66
|
+
errors.push({ section: null, message: "section is missing a non-empty name" });
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!KEBAB_RE.test(name)) {
|
|
70
|
+
errors.push({ section: name, message: `section "${name}" must be kebab-case (a-z, 0-9, -)` });
|
|
71
|
+
}
|
|
72
|
+
if (seen.has(name)) {
|
|
73
|
+
errors.push({ section: name, message: `duplicate section name "${name}"` });
|
|
74
|
+
}
|
|
75
|
+
seen.add(name);
|
|
76
|
+
if (sec.data == null) {
|
|
77
|
+
errors.push({ section: name, message: `section "${name}" is missing data` });
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const { type } = sec.data;
|
|
81
|
+
if (type !== "markdown" && type !== "tree") {
|
|
82
|
+
errors.push({ section: name, message: `section "${name}" has unknown type "${type ?? "undefined"}"` });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (type === "markdown") {
|
|
86
|
+
if (typeof sec.data.content !== "string" || sec.data.content.length === 0) {
|
|
87
|
+
errors.push({ section: name, message: `section "${name}" markdown content must be a non-empty string` });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (type === "tree") {
|
|
91
|
+
const root = sec.data.root;
|
|
92
|
+
if (!root || typeof root.name === "undefined" || !Array.isArray(root.children)) {
|
|
93
|
+
errors.push({ section: name, message: `section "${name}" tree root must have name and children` });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return errors;
|
|
98
|
+
}
|
|
99
|
+
async function handler({ key, runeArgs = [], sections = null, projectRoot = process.cwd(), configRoot = projectRoot } = {}) {
|
|
100
|
+
let config;
|
|
101
|
+
try {
|
|
102
|
+
config = loadConfig(configRoot);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
output.error(`Config unreadable: ${err.message}`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
const entry = config.runes?.[key];
|
|
108
|
+
if (entry?.path && !entry.permissions?.allow?.length) {
|
|
109
|
+
let src = "";
|
|
110
|
+
try {
|
|
111
|
+
src = readFileSync(join(configRoot, entry.path), "utf8");
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
for (const util of scanPermissionWarnings(src)) {
|
|
115
|
+
output.warn(`${key} \u2014 permissions.allow is empty but rune uses ${util}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
let result;
|
|
119
|
+
try {
|
|
120
|
+
result = await runRune(projectRoot, config, key, runeArgs, { configDir: configRoot });
|
|
121
|
+
} catch (err) {
|
|
122
|
+
output.error(`${key}: ${err.message}`);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
if (!result) {
|
|
126
|
+
output.error(`${key}: rune not found`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
const errors = checkSections(result);
|
|
130
|
+
if (errors.length === 0) {
|
|
131
|
+
output.success(`${key} \u2014 ${result.length} section${result.length === 1 ? "" : "s"}`);
|
|
132
|
+
} else {
|
|
133
|
+
for (const { message } of errors) {
|
|
134
|
+
output.error(`${key} \u2014 ${message}`);
|
|
135
|
+
}
|
|
136
|
+
console.log(`
|
|
137
|
+
${errors.length} problem${errors.length === 1 ? "" : "s"} found.`);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
handler,
|
|
143
|
+
scanPermissionWarnings
|
|
144
|
+
};
|