@darkrymit/crunes-cli 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +5 -4
  2. package/dist/chunks/{add-OWYVF3IE.js → add-CBHWFGCA.js} +2 -2
  3. package/dist/chunks/{apply-OMEVXCHC.js → apply-YC6JEPUN.js} +6 -5
  4. package/dist/chunks/args-repl-TX3YWUOO.js +81 -0
  5. package/dist/chunks/banner-repl-DD22Z33A.js +52 -0
  6. package/dist/chunks/benchmark-BJEAAFWG.js +234 -0
  7. package/dist/chunks/{browse-COH6IJEX.js → browse-JZFU52ET.js} +2 -2
  8. package/dist/chunks/{chunk-2Q24YPGL.js → chunk-2PBPDTRD.js} +2 -2
  9. package/dist/chunks/chunk-63H5VXZY.js +101 -0
  10. package/dist/chunks/{chunk-GHQOK4L7.js → chunk-65J65MAP.js} +1 -1
  11. package/dist/chunks/{chunk-HMU2J25D.js → chunk-6MRZXASS.js} +3 -3
  12. package/dist/chunks/{chunk-BEVULQIG.js → chunk-ASZKAC24.js} +2 -1
  13. package/dist/chunks/{chunk-AIEWOUXT.js → chunk-DZJRYFOP.js} +104 -41
  14. package/dist/chunks/{chunk-QMWGQXEZ.js → chunk-G4ZAUHHA.js} +2 -4
  15. package/dist/chunks/{chunk-67I2J474.js → chunk-J3GZ3DXD.js} +14 -55
  16. package/dist/chunks/{chunk-XIXND2M4.js → chunk-JOAL437H.js} +5 -1
  17. package/dist/chunks/{chunk-6I7RHSAA.js → chunk-JU6FKUBY.js} +30394 -26055
  18. package/dist/chunks/{chunk-5RGDIMK6.js → chunk-NAEVMRNA.js} +22031 -13353
  19. package/dist/chunks/{chunk-NXSDVVTW.js → chunk-NDEYEYSU.js} +22 -69
  20. package/dist/chunks/{chunk-L72BG6DS.js → chunk-NYLRTAAA.js} +1 -1
  21. package/dist/chunks/{chunk-UGN3FFEF.js → chunk-V35LVVNV.js} +5113 -2117
  22. package/dist/chunks/chunk-ZJDKCC2Y.js +105 -0
  23. package/dist/chunks/{clear-Y5POLIMF.js → clear-YBDIPEEH.js} +5 -9
  24. package/dist/chunks/commands-repl-IPLJ4M7X.js +65 -0
  25. package/dist/chunks/complete-input-repl-IDSCMRYL.js +71 -0
  26. package/dist/chunks/{create-I6BNYZ5Q.js → create-ZFFV3Z2P.js} +2 -1
  27. package/dist/chunks/{delete-UB5SXO5I.js → delete-C4UJ7X5K.js} +5 -9
  28. package/dist/chunks/delete-E4TEBRPX.js +27 -0
  29. package/dist/chunks/{delete-7CQFYIXS.js → delete-LNOYM5KG.js} +5 -9
  30. package/dist/chunks/{disable-FCBW7WVG.js → disable-TMG2K3BF.js} +6 -6
  31. package/dist/chunks/{doctor-DS57HDLJ.js → doctor-N43QEMAH.js} +2 -2
  32. package/dist/chunks/{enable-IXRVUXJM.js → enable-327OMBPC.js} +6 -6
  33. package/dist/chunks/{globals-YCJ2DGWC.js → globals-H2WF344Y.js} +2 -2
  34. package/dist/chunks/{init-WGKQVAZE.js → init-HU5OMHEH.js} +1 -1
  35. package/dist/chunks/input-repl-ZBH6FVPV.js +87 -0
  36. package/dist/chunks/{install-BCTBOPBS.js → install-RRLUOYFO.js} +6 -6
  37. package/dist/chunks/intro-4CICBP2J.js +2727 -0
  38. package/dist/chunks/{kill-LWRXZVM5.js → kill-2UG7PHUV.js} +4 -10
  39. package/dist/chunks/list-4X3JFQGS.js +41 -0
  40. package/dist/chunks/{list-ZBYPMUID.js → list-7VHJIUDX.js} +2 -2
  41. package/dist/chunks/list-A5WVDBWF.js +53 -0
  42. package/dist/chunks/{list-NGOCMJXE.js → list-CK5X2YN3.js} +5 -4
  43. package/dist/chunks/{list-TTKLNJKI.js → list-FLAYJQKN.js} +2 -2
  44. package/dist/chunks/list-PTAWQYWG.js +35 -0
  45. package/dist/chunks/list-U7PAYNAH.js +47 -0
  46. package/dist/chunks/{list-OTOMCFLA.js → list-WH7KESMV.js} +12 -11
  47. package/dist/chunks/{query-NY4SCO77.js → query-AW7WYILM.js} +5 -9
  48. package/dist/chunks/{registry-W5XFI5T6.js → registry-3QIL5SVL.js} +2 -2
  49. package/dist/chunks/{remove-WEAZFZCO.js → remove-QUH2D3S5.js} +2 -2
  50. package/dist/chunks/repl-STBZC4P2.js +180 -0
  51. package/dist/chunks/repl-VGC5FUJG.js +378 -0
  52. package/dist/chunks/resolver-QMIY33FM.js +26 -0
  53. package/dist/chunks/run-T33CMCFZ.js +26 -0
  54. package/dist/chunks/{run-J2A5YTTY.js → run-Y4TG3EM3.js} +22 -3
  55. package/dist/chunks/rune-UBRVWG5A.js +139 -0
  56. package/dist/chunks/{search-XENXL3GC.js → search-MSSDGJTF.js} +2 -2
  57. package/dist/chunks/{uninstall-MX5PLGDI.js → uninstall-55YTHZRH.js} +5 -5
  58. package/dist/chunks/unset-YASSMSE5.js +24 -0
  59. package/dist/chunks/{update-7XDTVFZ3.js → update-EWWDROKW.js} +2 -2
  60. package/dist/chunks/{update-IEE54GPY.js → update-G6XO4RIM.js} +6 -6
  61. package/dist/chunks/{utils-JKGIWZTS.js → utils-XOWJQWNR.js} +2 -2
  62. package/dist/chunks/{version-OPTLR63W.js → version-I442SSH7.js} +10 -5
  63. package/dist/cli.js +114 -81
  64. package/package.json +9 -4
  65. package/dist/chunks/benchmark-ATSRQIDC.js +0 -164
  66. package/dist/chunks/check-G72VZKIP.js +0 -144
  67. package/dist/chunks/chunk-3TM6B4E5.js +0 -70
  68. package/dist/chunks/chunk-XXUNHQIB.js +0 -129
  69. package/dist/chunks/intro-QVSLNH4R.js +0 -1510
  70. package/dist/chunks/list-5DVVP7HX.js +0 -50
  71. package/dist/chunks/list-6WL5LGIZ.js +0 -80
  72. package/dist/chunks/list-YPI7YDKK.js +0 -80
  73. package/dist/chunks/run-AUAGELWL.js +0 -23
  74. package/dist/chunks/rune-ZYEVEYID.js +0 -87
  75. package/dist/chunks/unset-KQOZYVTE.js +0 -28
@@ -0,0 +1,105 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/job/registry.js
6
+ init_require_shim();
7
+ import { readFile, writeFile, mkdir, readdir, rm } from "node:fs/promises";
8
+ import { join } from "node:path";
9
+ import { randomUUID } from "node:crypto";
10
+ function jobDir(projectDir, id) {
11
+ return join(projectDir, ".crunes", "jobs", id);
12
+ }
13
+ function jobStdoutPath(projectDir, id) {
14
+ return join(jobDir(projectDir, id), "stdout.log");
15
+ }
16
+ function jobStderrPath(projectDir, id) {
17
+ return join(jobDir(projectDir, id), "stderr.log");
18
+ }
19
+ function jobStdinPath(projectDir, id) {
20
+ return join(jobDir(projectDir, id), "stdin.log");
21
+ }
22
+ async function updateJobPid(projectDir, id, pid) {
23
+ const record = await getJob(projectDir, id);
24
+ if (!record) return;
25
+ record.pid = pid;
26
+ await writeFile(join(jobDir(projectDir, id), "job.json"), JSON.stringify(record, null, 2), "utf8");
27
+ }
28
+ async function createJob(pid, { type = "rune", spawnedBy, runeKey, projectDir, args = [] } = {}) {
29
+ const id = randomUUID();
30
+ const record = { id, type, pid, startedAt: (/* @__PURE__ */ new Date()).toISOString(), projectDir, spawnedBy, runeKey, args };
31
+ const dir = jobDir(projectDir, id);
32
+ await mkdir(dir, { recursive: true });
33
+ await writeFile(join(dir, "job.json"), JSON.stringify(record, null, 2), "utf8");
34
+ return { id };
35
+ }
36
+ async function getJob(projectDir, id) {
37
+ try {
38
+ const raw = await readFile(join(jobDir(projectDir, id), "job.json"), "utf8");
39
+ return JSON.parse(raw);
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+ async function listJobs(projectDir) {
45
+ const base = join(projectDir, ".crunes", "jobs");
46
+ let entries;
47
+ try {
48
+ entries = await readdir(base, { withFileTypes: true });
49
+ } catch {
50
+ return [];
51
+ }
52
+ const records = await Promise.all(
53
+ entries.filter((e) => e.isDirectory()).map((e) => getJob(projectDir, e.name))
54
+ );
55
+ return records.filter(Boolean);
56
+ }
57
+ async function deleteJob(projectDir, id) {
58
+ await rm(jobDir(projectDir, id), { recursive: true, force: true });
59
+ }
60
+ async function cleanJobs(projectDir) {
61
+ const base = join(projectDir, ".crunes", "jobs");
62
+ let entries;
63
+ try {
64
+ entries = await readdir(base, { withFileTypes: true });
65
+ } catch {
66
+ return;
67
+ }
68
+ await Promise.all(
69
+ entries.filter((e) => e.isDirectory()).map(async (e) => {
70
+ const record = await getJob(projectDir, e.name);
71
+ if (!record) return;
72
+ if (!isAlive(record.pid)) await rm(jobDir(projectDir, e.name), { recursive: true, force: true });
73
+ })
74
+ );
75
+ }
76
+ function resolveJobId(id, jobs) {
77
+ const exact = jobs.find((j) => j.id === id);
78
+ if (exact) return exact.id;
79
+ const matches = jobs.filter((j) => j.id.startsWith(id));
80
+ if (matches.length === 1) return matches[0].id;
81
+ if (matches.length === 0) throw new Error(`No job matching "${id}".`);
82
+ throw new Error(`Ambiguous id "${id}" \u2014 matches: ${matches.map((j) => j.id).join(", ")}.`);
83
+ }
84
+ function isAlive(pid) {
85
+ try {
86
+ process.kill(pid, 0);
87
+ return true;
88
+ } catch {
89
+ return false;
90
+ }
91
+ }
92
+
93
+ export {
94
+ jobStdoutPath,
95
+ jobStderrPath,
96
+ jobStdinPath,
97
+ updateJobPid,
98
+ createJob,
99
+ getJob,
100
+ listJobs,
101
+ deleteJob,
102
+ cleanJobs,
103
+ resolveJobId,
104
+ isAlive
105
+ };
@@ -1,22 +1,18 @@
1
1
  import {
2
2
  clearCacheBucket
3
- } from "./chunk-NXSDVVTW.js";
4
- import "./chunk-QMWGQXEZ.js";
5
- import {
6
- ensureProjectIdentity
7
- } from "./chunk-3TM6B4E5.js";
8
- import "./chunk-HMU2J25D.js";
3
+ } from "./chunk-NDEYEYSU.js";
4
+ import "./chunk-G4ZAUHHA.js";
5
+ import "./chunk-6MRZXASS.js";
9
6
  import {
10
7
  init_require_shim
11
8
  } from "./chunk-TPK5AGRA.js";
12
9
 
13
10
  // src/cache/commands/clear.js
14
11
  init_require_shim();
15
- async function handler({ id, projectDir, global: isGlobal }) {
16
- const key = isGlobal ? void 0 : (await ensureProjectIdentity(projectDir)).id;
12
+ async function handler({ id, projectDir }) {
17
13
  let result;
18
14
  try {
19
- result = await clearCacheBucket(id, key);
15
+ result = await clearCacheBucket(id);
20
16
  } catch (err) {
21
17
  console.error(`Error: ${err.message}`);
22
18
  process.exit(1);
@@ -0,0 +1,65 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/docs/commands/commands-repl.js
6
+ init_require_shim();
7
+ async function handler() {
8
+ process.stdout.write(`# Docs: The commandsRepl(builder) Export
9
+
10
+ \`export function commandsRepl(builder)\` declares the slash commands available in a REPL session. Only \`.command()\` at the **root level** is meaningful \u2014 \`.option()\` and \`.positional()\` at root are silently ignored. Sub-commands may use the full builder API.
11
+
12
+ ## 1. Declaration
13
+
14
+ \`\`\`js
15
+ export function commandsRepl(b) {
16
+ return b
17
+ .command('tables', 'List all tables in the database')
18
+ .command('schema', 'Show schema for a table', sub =>
19
+ sub.positional('<table>', 'Table name')
20
+ )
21
+ .command('exit', 'Disconnect and quit')
22
+ }
23
+ \`\`\`
24
+
25
+ ## 2. Dispatch to inputRepl
26
+
27
+ When the user types \`/tables\` the host intercepts it, parses it against the declared schema, and dispatches to \`inputRepl\` as a \`command\` event:
28
+
29
+ \`\`\`js
30
+ export async function inputRepl(input) {
31
+ if (input.type === 'command') {
32
+ // input.args.$command === 'tables'
33
+ // input.args.$command === 'schema', input.args.table === 'books'
34
+ switch (input.args.$command) {
35
+ case 'tables': { /* list tables */ return undefined }
36
+ case 'schema': { /* show schema for input.args.table */ return undefined }
37
+ case 'exit': { await replDb.close(); return { type: 'done' } }
38
+ }
39
+ }
40
+ }
41
+ \`\`\`
42
+
43
+ ## 3. Built-in Host Commands
44
+
45
+ These are always available regardless of \`commandsRepl\`:
46
+
47
+ | Command | Action |
48
+ |---|---|
49
+ | \`/help\` | Show all available commands (built-in + rune-declared) |
50
+ | \`/clear\` | Clear the screen (TTY only) |
51
+ | \`/exit\` | End the session (queues an \`eof\` event into \`inputRepl\`) |
52
+
53
+ ## 4. Unrecognised Slash Input
54
+
55
+ Input starting with \`/\` that does not match any declared or built-in command is passed through to \`inputRepl\` as a normal \`{ type: 'line', text: '/foo' }\` event \u2014 the rune can handle it or ignore it.
56
+
57
+ ## 5. Absence
58
+
59
+ If \`commandsRepl\` is not exported, no rune-declared slash commands are available. Built-in host commands still work.
60
+
61
+ `);
62
+ }
63
+ export {
64
+ handler
65
+ };
@@ -0,0 +1,71 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/docs/commands/complete-input-repl.js
6
+ init_require_shim();
7
+ async function handler() {
8
+ process.stdout.write(`# Docs: The completeInputRepl(tokens) Export
9
+
10
+ \`export async function completeInputRepl(tokens)\` provides tab completion for the REPL session. Called on the Tab key.
11
+
12
+ ## 1. The \`tokens\` Parameter
13
+
14
+ \`tokens\` is the current input line split on whitespace, where the **last element is the partial word being typed**. This is the same convention as \`resolveCompletions(tokens, program)\` in the crunes CLI completions system.
15
+
16
+ Examples:
17
+
18
+ | User has typed | \`tokens\` received |
19
+ |---|---|
20
+ | \`SEL\` (Tab) | \`['SEL']\` |
21
+ | \`SELECT \` (Tab) | \`['SELECT', '']\` |
22
+ | \`SELECT * FR\` (Tab) | \`['SELECT', '*', 'FR']\` |
23
+
24
+ ## 2. Return Value
25
+
26
+ Return \`string[]\` of completion candidates. The host filters by the partial word (prefix match) and passes the result to readline's completer. Return \`[]\` for no completions.
27
+
28
+ ## 3. Example
29
+
30
+ \`\`\`js
31
+ export async function completeInputRepl(tokens) {
32
+ const partial = tokens[tokens.length - 1] ?? ''
33
+ const keywords = [
34
+ 'SELECT', 'FROM', 'WHERE', 'INSERT', 'INTO', 'UPDATE', 'SET',
35
+ 'DELETE', 'CREATE', 'DROP', 'TABLE', 'PRAGMA', 'WITH',
36
+ 'ORDER', 'BY', 'GROUP', 'HAVING', 'LIMIT', 'OFFSET',
37
+ 'JOIN', 'LEFT', 'INNER', 'ON',
38
+ ]
39
+ return keywords.filter(k => k.startsWith(partial.toUpperCase()))
40
+ }
41
+ \`\`\`
42
+
43
+ ## 4. Dynamic Completions
44
+
45
+ You can use module-level session state (set up in \`repl()\`) to return context-aware completions \u2014 for example, table names from the active database:
46
+
47
+ \`\`\`js
48
+ let tableNames = []
49
+
50
+ export async function repl(args) {
51
+ const db = await sqlite.open(args.db, 'main')
52
+ const rows = await db.query("SELECT name FROM sqlite_master WHERE type='table'")
53
+ tableNames = rows.map(r => r.name)
54
+ return 'db> '
55
+ }
56
+
57
+ export async function completeInputRepl(tokens) {
58
+ const partial = tokens[tokens.length - 1] ?? ''
59
+ return tableNames.filter(t => t.startsWith(partial))
60
+ }
61
+ \`\`\`
62
+
63
+ ## 5. Absence
64
+
65
+ If \`completeInputRepl\` is not exported, Tab does nothing \u2014 no readline completer is registered.
66
+
67
+ `);
68
+ }
69
+ export {
70
+ handler
71
+ };
@@ -26,7 +26,7 @@ function pluginJson({ name, description, author, license }) {
26
26
  name: "Example Rune",
27
27
  description: "Replace with your rune description",
28
28
  permissions: {
29
- use: {
29
+ run: {
30
30
  allow: [],
31
31
  deny: []
32
32
  }
@@ -79,6 +79,7 @@ export async function run(args) {
79
79
  // args._ \u2014 data positionals (command tokens stripped)
80
80
  // args.verbose \u2014 named flag (if args export is defined above)
81
81
  // utils.fs.cwd() \u2014 absolute path to the user's project root
82
+ // To handle --help: check args.$raw.includes('--help') and return a help section
82
83
 
83
84
  return section.create('example', {
84
85
  type: 'markdown',
@@ -5,19 +5,16 @@ import {
5
5
  } from "./chunk-CGZL5SSH.js";
6
6
  import {
7
7
  deleteSqliteDb
8
- } from "./chunk-67I2J474.js";
9
- import "./chunk-QMWGQXEZ.js";
10
- import {
11
- ensureProjectIdentity
12
- } from "./chunk-3TM6B4E5.js";
13
- import "./chunk-HMU2J25D.js";
8
+ } from "./chunk-J3GZ3DXD.js";
9
+ import "./chunk-G4ZAUHHA.js";
10
+ import "./chunk-6MRZXASS.js";
14
11
  import {
15
12
  init_require_shim
16
13
  } from "./chunk-TPK5AGRA.js";
17
14
 
18
15
  // src/sqlite/commands/delete.js
19
16
  init_require_shim();
20
- async function handler({ id, yes, projectDir, global: isGlobal }) {
17
+ async function handler({ id, yes, projectDir }) {
21
18
  if (!yes) {
22
19
  const confirm = await le({ message: `Delete SQLite database matching "${id}"?` });
23
20
  if (R(confirm) || !confirm) {
@@ -25,10 +22,9 @@ async function handler({ id, yes, projectDir, global: isGlobal }) {
25
22
  process.exit(0);
26
23
  }
27
24
  }
28
- const key = isGlobal ? void 0 : (await ensureProjectIdentity(projectDir)).id;
29
25
  let result;
30
26
  try {
31
- result = await deleteSqliteDb(id, key);
27
+ result = await deleteSqliteDb(id);
32
28
  } catch (err) {
33
29
  console.error(`Error: ${err.message}`);
34
30
  process.exit(1);
@@ -0,0 +1,27 @@
1
+ import {
2
+ deleteSchemaCache,
3
+ listSchemaCaches
4
+ } from "./chunk-63H5VXZY.js";
5
+ import {
6
+ output
7
+ } from "./chunk-6XLT25GS.js";
8
+ import "./chunk-WCODTMDN.js";
9
+ import {
10
+ init_require_shim
11
+ } from "./chunk-TPK5AGRA.js";
12
+
13
+ // src/rune/commands/schema/delete.js
14
+ init_require_shim();
15
+ async function handler({ runeKey, projectDir }) {
16
+ const before = await listSchemaCaches(projectDir);
17
+ const matching = before.filter((e) => e.runeKey === runeKey);
18
+ if (matching.length === 0) {
19
+ output.warn(`No schema cache entries found for "${runeKey}".`);
20
+ return;
21
+ }
22
+ await deleteSchemaCache(runeKey, projectDir);
23
+ console.log(`Deleted ${matching.length} schema cache file(s) for "${runeKey}".`);
24
+ }
25
+ export {
26
+ handler
27
+ };
@@ -5,19 +5,16 @@ import {
5
5
  } from "./chunk-CGZL5SSH.js";
6
6
  import {
7
7
  deleteCacheBucket
8
- } from "./chunk-NXSDVVTW.js";
9
- import "./chunk-QMWGQXEZ.js";
10
- import {
11
- ensureProjectIdentity
12
- } from "./chunk-3TM6B4E5.js";
13
- import "./chunk-HMU2J25D.js";
8
+ } from "./chunk-NDEYEYSU.js";
9
+ import "./chunk-G4ZAUHHA.js";
10
+ import "./chunk-6MRZXASS.js";
14
11
  import {
15
12
  init_require_shim
16
13
  } from "./chunk-TPK5AGRA.js";
17
14
 
18
15
  // src/cache/commands/delete.js
19
16
  init_require_shim();
20
- async function handler({ id, yes, projectDir, global: isGlobal }) {
17
+ async function handler({ id, yes, projectDir }) {
21
18
  if (!yes) {
22
19
  const confirm = await le({ message: `Delete cache bucket matching "${id}"?` });
23
20
  if (R(confirm) || !confirm) {
@@ -25,10 +22,9 @@ async function handler({ id, yes, projectDir, global: isGlobal }) {
25
22
  process.exit(0);
26
23
  }
27
24
  }
28
- const key = isGlobal ? void 0 : (await ensureProjectIdentity(projectDir)).id;
29
25
  let result;
30
26
  try {
31
- result = await deleteCacheBucket(id, key);
27
+ result = await deleteCacheBucket(id);
32
28
  } catch (err) {
33
29
  console.error(`Error: ${err.message}`);
34
30
  process.exit(1);
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  loadRegistry,
3
3
  resolvePluginKey
4
- } from "./chunk-GHQOK4L7.js";
5
- import "./chunk-HMU2J25D.js";
4
+ } from "./chunk-65J65MAP.js";
5
+ import "./chunk-6MRZXASS.js";
6
6
  import {
7
7
  init_require_shim
8
8
  } from "./chunk-TPK5AGRA.js";
@@ -11,20 +11,20 @@ import {
11
11
  init_require_shim();
12
12
  import fs from "node:fs/promises";
13
13
  import path from "node:path";
14
- async function handler({ name, projectRoot }) {
14
+ async function handler({ name, projectRoot, configRoot }) {
15
15
  try {
16
16
  const registry = await loadRegistry();
17
17
  const pluginKey = resolvePluginKey(name, registry);
18
18
  if (!pluginKey) throw new Error(`Plugin "${name}" is not installed. Run: crunes plugin list`);
19
- await setProjectPluginEnabled(projectRoot, pluginKey, false);
19
+ await setProjectPluginEnabled(configRoot ?? projectRoot, pluginKey, false);
20
20
  console.log(`Plugin "${pluginKey}" disabled.`);
21
21
  } catch (err) {
22
22
  console.error(`Error: ${err.message}`);
23
23
  process.exit(1);
24
24
  }
25
25
  }
26
- async function setProjectPluginEnabled(projectRoot, pluginKey, enabled) {
27
- const configPath = path.join(projectRoot, ".crunes", "config.json");
26
+ async function setProjectPluginEnabled(configRoot, pluginKey, enabled) {
27
+ const configPath = path.join(configRoot, ".crunes", "config.json");
28
28
  let config;
29
29
  try {
30
30
  config = JSON.parse(await fs.readFile(configPath, "utf8"));
@@ -16,10 +16,10 @@ var KNOWN_FORMATS = /* @__PURE__ */ new Set(["1"]);
16
16
  async function handler({ projectRoot = process.cwd() } = {}) {
17
17
  let anyFailed = false;
18
18
  const major = parseInt(process.versions.node.split(".")[0], 10);
19
- if (major >= 20) {
19
+ if (major >= 22) {
20
20
  output.success(`Node.js v${process.versions.node}`);
21
21
  } else {
22
- output.error(`Node.js v${process.versions.node} \u2014 requires >= 20`);
22
+ output.error(`Node.js v${process.versions.node} \u2014 requires >= 22`);
23
23
  anyFailed = true;
24
24
  }
25
25
  const versionResult = spawnSync("crunes", ["--version"], { encoding: "utf8", shell: true });
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  loadRegistry,
3
3
  resolvePluginKey
4
- } from "./chunk-GHQOK4L7.js";
5
- import "./chunk-HMU2J25D.js";
4
+ } from "./chunk-65J65MAP.js";
5
+ import "./chunk-6MRZXASS.js";
6
6
  import {
7
7
  init_require_shim
8
8
  } from "./chunk-TPK5AGRA.js";
@@ -11,20 +11,20 @@ import {
11
11
  init_require_shim();
12
12
  import fs from "node:fs/promises";
13
13
  import path from "node:path";
14
- async function handler({ name, projectRoot }) {
14
+ async function handler({ name, projectRoot, configRoot }) {
15
15
  try {
16
16
  const registry = await loadRegistry();
17
17
  const pluginKey = resolvePluginKey(name, registry);
18
18
  if (!pluginKey) throw new Error(`Plugin "${name}" is not installed. Run: crunes plugin list`);
19
- await setProjectPluginEnabled(projectRoot, pluginKey, true);
19
+ await setProjectPluginEnabled(configRoot ?? projectRoot, pluginKey, true);
20
20
  console.log(`Plugin "${pluginKey}" enabled.`);
21
21
  } catch (err) {
22
22
  console.error(`Error: ${err.message}`);
23
23
  process.exit(1);
24
24
  }
25
25
  }
26
- async function setProjectPluginEnabled(projectRoot, pluginKey, enabled) {
27
- const configPath = path.join(projectRoot, ".crunes", "config.json");
26
+ async function setProjectPluginEnabled(configRoot, pluginKey, enabled) {
27
+ const configPath = path.join(configRoot, ".crunes", "config.json");
28
28
  let config;
29
29
  try {
30
30
  config = JSON.parse(await fs.readFile(configPath, "utf8"));
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  globals_api_default
3
- } from "./chunk-UGN3FFEF.js";
3
+ } from "./chunk-V35LVVNV.js";
4
4
  import {
5
5
  formatMembers,
6
6
  walk
7
- } from "./chunk-XIXND2M4.js";
7
+ } from "./chunk-JOAL437H.js";
8
8
  import {
9
9
  init_require_shim
10
10
  } from "./chunk-TPK5AGRA.js";
@@ -17,7 +17,7 @@ init_require_shim();
17
17
  import { mkdirSync, writeFileSync, existsSync } from "node:fs";
18
18
  import { join } from "node:path";
19
19
  var EMPTY_CONFIG = JSON.stringify({ runes: {} }, null, 2) + "\n";
20
- var GITIGNORE_CONTENT = "# local overrides (machine-specific, never commit)\nconfig.local.json\nproject.local.json\n\n# run logs\nlogs/\n\n# local caches and databases (gitignored by default)\ncaches/\nsqlite/\n";
20
+ var GITIGNORE_CONTENT = "# local overrides (machine-specific, never commit)\nconfig.local.json\nproject.local.json\n\n# run logs\nlogs/\n\n# local caches, databases, schema cache and job logs (gitignored by default)\ncaches/\nschemas/\nsqlite/\njobs/\n";
21
21
  async function handler({
22
22
  yes = false,
23
23
  projectRoot = process.cwd()
@@ -0,0 +1,87 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/docs/commands/input-repl.js
6
+ init_require_shim();
7
+ async function handler() {
8
+ process.stdout.write(`# Docs: The inputRepl(input) Export
9
+
10
+ \`export async function inputRepl(input)\` is the per-input dispatch handler. It is called once per \`InputEvent\` for the entire session. All session logic \u2014 query execution, command handling, exit \u2014 lives here.
11
+
12
+ ## 1. InputEvent Types
13
+
14
+ | \`type\` | \`text\` | \`args\` | When |
15
+ |---|---|---|---|
16
+ | \`'line'\` | raw input string (untrimmed) | \u2014 | Normal user input |
17
+ | \`'interrupt'\` | \`''\` | \u2014 | Ctrl+C on an empty prompt |
18
+ | \`'eof'\` | \`''\` | \u2014 | Ctrl+D or stdin closed |
19
+ | \`'command'\` | \u2014 | \`ParsedArgs\` | Matched slash command (use \`args.$command\`) |
20
+
21
+ ## 2. Return Values
22
+
23
+ | Return value | Effect |
24
+ |---|---|
25
+ | \`undefined\` or \`null\` | Continue \u2014 re-prompt with current prompt string |
26
+ | \`"string"\` | Continue \u2014 update prompt to this string |
27
+ | \`{ type: 'prompt', value?: string }\` | Continue \u2014 optionally update prompt |
28
+ | \`{ type: 'done', message?: string }\` | End session \u2014 optional goodbye message |
29
+
30
+ ## 3. Example
31
+
32
+ \`\`\`js
33
+ import { sqlite, section, md } from '@utils'
34
+
35
+ let replDb = null
36
+
37
+ export async function repl(args) {
38
+ replDb = await sqlite.open(args.db, 'books')
39
+ return 'sqlite> '
40
+ }
41
+
42
+ export async function inputRepl(input) {
43
+ // Clean up and exit on Ctrl+C (empty prompt) or Ctrl+D
44
+ if (input.type === 'eof' || input.type === 'interrupt') {
45
+ await replDb.close()
46
+ replDb = null
47
+ return { type: 'done', message: 'Disconnected.' }
48
+ }
49
+
50
+ // Handle slash commands declared in commandsRepl()
51
+ if (input.type === 'command') {
52
+ if (input.args.$command === 'exit') {
53
+ await replDb.close()
54
+ replDb = null
55
+ return { type: 'done' }
56
+ }
57
+ return undefined
58
+ }
59
+
60
+ // Normal input line
61
+ const trimmed = input.text.trim()
62
+ if (!trimmed) return undefined // empty line \u2014 re-prompt
63
+
64
+ const rows = await replDb.query(trimmed)
65
+ section.emit(section.create('result', {
66
+ type: 'markdown',
67
+ content: md.table(Object.keys(rows[0] ?? {}), rows.map(r => Object.values(r).map(String))),
68
+ }))
69
+ return \`[\${rows.length} rows]> \`
70
+ }
71
+ \`\`\`
72
+
73
+ ## 4. Output
74
+
75
+ Use \`section.emit()\` to stream sections to the consumer in real time before the function returns. Also accepts an array: \`section.emit([s1, s2])\`.
76
+
77
+ Use \`console.log()\` for log lines \u2014 written to stderr in text mode, emitted as \`log\` events in JSONL mode.
78
+
79
+ ## 5. Session State
80
+
81
+ The isolate stays alive across all calls. JS module-level variables are the state store \u2014 assign to them in \`repl()\` and read them in \`inputRepl()\`.
82
+
83
+ `);
84
+ }
85
+ export {
86
+ handler
87
+ };
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  resolveFromMarketplace
3
- } from "./chunk-L72BG6DS.js";
3
+ } from "./chunk-NYLRTAAA.js";
4
4
  import {
5
5
  installPlugin
6
- } from "./chunk-2Q24YPGL.js";
6
+ } from "./chunk-2PBPDTRD.js";
7
7
  import {
8
8
  fe,
9
9
  ge,
10
10
  ye
11
11
  } from "./chunk-CGZL5SSH.js";
12
- import "./chunk-GHQOK4L7.js";
13
- import "./chunk-HMU2J25D.js";
12
+ import "./chunk-65J65MAP.js";
13
+ import "./chunk-6MRZXASS.js";
14
14
  import "./chunk-G3U4V32O.js";
15
15
  import {
16
16
  init_require_shim
@@ -23,7 +23,7 @@ function parseInstallArg(arg) {
23
23
  if (idx === -1) return null;
24
24
  return [arg.slice(0, idx), arg.slice(idx + 1)];
25
25
  }
26
- async function handler({ source, projectRoot, yes }) {
26
+ async function handler({ source, projectRoot, configRoot, yes }) {
27
27
  const parts = parseInstallArg(source);
28
28
  if (!parts) {
29
29
  ge("Use <marketplace>@<plugin> format (e.g. hello-world@hello-world)");
@@ -41,7 +41,7 @@ async function handler({ source, projectRoot, yes }) {
41
41
  }
42
42
  let result;
43
43
  try {
44
- result = await installPlugin(resolvedSource, projectRoot, provenance, { yes });
44
+ result = await installPlugin(resolvedSource, configRoot ?? projectRoot, provenance, { yes });
45
45
  } catch (err) {
46
46
  ge(`Installation failed: ${err.message}`);
47
47
  process.exit(1);