@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
@@ -2,20 +2,15 @@ import {
2
2
  deleteJob,
3
3
  listJobs,
4
4
  resolveJobId
5
- } from "./chunk-XXUNHQIB.js";
6
- import {
7
- ensureProjectIdentity
8
- } from "./chunk-3TM6B4E5.js";
9
- import "./chunk-HMU2J25D.js";
5
+ } from "./chunk-ZJDKCC2Y.js";
10
6
  import {
11
7
  init_require_shim
12
8
  } from "./chunk-TPK5AGRA.js";
13
9
 
14
10
  // src/job/commands/kill.js
15
11
  init_require_shim();
16
- async function handler({ id, projectDir, global: isGlobal }) {
17
- const key = isGlobal ? void 0 : (await ensureProjectIdentity(projectDir)).id;
18
- const jobs = await listJobs(key);
12
+ async function handler({ id, projectDir }) {
13
+ const jobs = await listJobs(projectDir);
19
14
  let resolvedId;
20
15
  try {
21
16
  resolvedId = resolveJobId(id, jobs);
@@ -24,12 +19,11 @@ async function handler({ id, projectDir, global: isGlobal }) {
24
19
  process.exit(1);
25
20
  }
26
21
  const record = jobs.find((j) => j.id === resolvedId);
27
- const recordKey = key ?? record.projectKey;
28
22
  try {
29
23
  process.kill(record.pid, "SIGTERM");
30
24
  } catch {
31
25
  }
32
- await deleteJob(recordKey, record.id);
26
+ await deleteJob(projectDir, record.id);
33
27
  console.log(`Sent SIGTERM to job ${record.id.slice(0, 8)} (${record.runeKey ?? "unknown"})`);
34
28
  }
35
29
  export {
@@ -0,0 +1,41 @@
1
+ import {
2
+ cleanJobs,
3
+ isAlive,
4
+ listJobs
5
+ } from "./chunk-ZJDKCC2Y.js";
6
+ import {
7
+ init_require_shim
8
+ } from "./chunk-TPK5AGRA.js";
9
+
10
+ // src/job/commands/list.js
11
+ init_require_shim();
12
+ function pad(str, len) {
13
+ return String(str ?? "-").padEnd(len);
14
+ }
15
+ async function handler({ projectDir }) {
16
+ await cleanJobs(projectDir);
17
+ const jobs = await listJobs(projectDir);
18
+ if (jobs.length === 0) {
19
+ console.log("No background jobs.");
20
+ return;
21
+ }
22
+ const header = ["ID", "RUNE", "SPAWNED BY", "STATUS", "STARTED"];
23
+ const rows = jobs.map((r) => [
24
+ r.id.slice(0, 8),
25
+ r.runeKey ?? "-",
26
+ r.spawnedBy ?? "-",
27
+ isAlive(r.pid) ? "alive" : "dead",
28
+ new Date(r.startedAt).toLocaleString()
29
+ ]);
30
+ const widths = header.map(
31
+ (h, i) => Math.max(h.length, ...rows.map((r) => String(r[i] ?? "").length))
32
+ );
33
+ console.log(header.map((h, i) => pad(h, widths[i])).join(" "));
34
+ console.log(widths.map((w) => "-".repeat(w)).join(" "));
35
+ for (const row of rows) {
36
+ console.log(row.map((cell, i) => pad(cell, widths[i])).join(" "));
37
+ }
38
+ }
39
+ export {
40
+ handler
41
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  listMarketplaces
3
- } from "./chunk-L72BG6DS.js";
4
- import "./chunk-HMU2J25D.js";
3
+ } from "./chunk-NYLRTAAA.js";
4
+ import "./chunk-6MRZXASS.js";
5
5
  import {
6
6
  init_require_shim
7
7
  } from "./chunk-TPK5AGRA.js";
@@ -0,0 +1,53 @@
1
+ import {
2
+ listCacheBuckets,
3
+ listLocalCacheBuckets
4
+ } from "./chunk-NDEYEYSU.js";
5
+ import "./chunk-G4ZAUHHA.js";
6
+ import "./chunk-6MRZXASS.js";
7
+ import {
8
+ init_require_shim
9
+ } from "./chunk-TPK5AGRA.js";
10
+
11
+ // src/cache/commands/list.js
12
+ init_require_shim();
13
+ function pad(s, n) {
14
+ return String(s ?? "-").padEnd(n);
15
+ }
16
+ function applyPluginFilter(buckets, plugin) {
17
+ if (plugin === void 0) return buckets;
18
+ const pluginScopes = /* @__PURE__ */ new Set(["global-plugin", "local-plugin"]);
19
+ if (plugin === true) return buckets.filter((b) => pluginScopes.has(b.scope));
20
+ return buckets.filter((b) => pluginScopes.has(b.scope) && b.pluginId === plugin);
21
+ }
22
+ async function handler({ projectDir, plugin }) {
23
+ const [local, global] = await Promise.all([
24
+ listLocalCacheBuckets(projectDir),
25
+ listCacheBuckets()
26
+ ]);
27
+ let buckets = applyPluginFilter([...local, ...global], plugin);
28
+ if (buckets.length === 0) {
29
+ console.log("No cache buckets.");
30
+ return;
31
+ }
32
+ function pluginLabel(entry) {
33
+ if (entry.scope === "global-plugin" || entry.scope === "local-plugin") return entry.pluginId ?? "-";
34
+ return "-";
35
+ }
36
+ const cols = ["KEY", "NAME", "SCOPE", "PLUGIN", "FIRST SEEN"];
37
+ const rows = buckets.map((b) => [
38
+ b.key,
39
+ b.name,
40
+ b.scope,
41
+ pluginLabel(b),
42
+ b.firstSeenAt ? new Date(b.firstSeenAt).toLocaleString() : "-"
43
+ ]);
44
+ const widths = cols.map((c, i) => Math.max(c.length, ...rows.map((r) => String(r[i] ?? "").length)));
45
+ console.log(cols.map((c, i) => pad(c, widths[i])).join(" "));
46
+ console.log(widths.map((w) => "-".repeat(w)).join(" "));
47
+ for (const row of rows) {
48
+ console.log(row.map((cell, i) => pad(cell, widths[i])).join(" "));
49
+ }
50
+ }
51
+ export {
52
+ handler
53
+ };
@@ -10,8 +10,8 @@ import {
10
10
  import "./chunk-WCODTMDN.js";
11
11
  import {
12
12
  loadRegistry
13
- } from "./chunk-GHQOK4L7.js";
14
- import "./chunk-HMU2J25D.js";
13
+ } from "./chunk-65J65MAP.js";
14
+ import "./chunk-6MRZXASS.js";
15
15
  import {
16
16
  loadPluginJson
17
17
  } from "./chunk-G3U4V32O.js";
@@ -27,13 +27,14 @@ async function handler({
27
27
  source,
28
28
  format = "md",
29
29
  plain = false,
30
- projectRoot = process.cwd()
30
+ projectRoot = process.cwd(),
31
+ configRoot
31
32
  } = {}) {
32
33
  const results = [];
33
34
  if (!source || source === "project") {
34
35
  let config = { templates: {} };
35
36
  try {
36
- config = loadConfig(projectRoot);
37
+ config = loadConfig(configRoot ?? projectRoot);
37
38
  } catch {
38
39
  }
39
40
  const templates = config.templates ?? {};
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  loadRegistry
3
- } from "./chunk-GHQOK4L7.js";
4
- import "./chunk-HMU2J25D.js";
3
+ } from "./chunk-65J65MAP.js";
4
+ import "./chunk-6MRZXASS.js";
5
5
  import {
6
6
  init_require_shim
7
7
  } from "./chunk-TPK5AGRA.js";
@@ -0,0 +1,35 @@
1
+ import {
2
+ listSchemaCaches
3
+ } from "./chunk-63H5VXZY.js";
4
+ import {
5
+ init_require_shim
6
+ } from "./chunk-TPK5AGRA.js";
7
+
8
+ // src/rune/commands/schema/list.js
9
+ init_require_shim();
10
+ function pad(s, n) {
11
+ return String(s ?? "-").padEnd(n);
12
+ }
13
+ async function handler({ projectDir }) {
14
+ const entries = await listSchemaCaches(projectDir);
15
+ if (entries.length === 0) {
16
+ console.log("No schema cache entries.");
17
+ return;
18
+ }
19
+ const cols = ["RUNE KEY", "TYPE", "CACHED AT", "HASH"];
20
+ const rows = entries.map((e) => [
21
+ e.runeKey,
22
+ e.type,
23
+ new Date(e.cachedAt).toLocaleString(),
24
+ e.hash.slice(0, 12) + "..."
25
+ ]);
26
+ const widths = cols.map((c, i) => Math.max(c.length, ...rows.map((r) => String(r[i] ?? "").length)));
27
+ console.log(cols.map((c, i) => pad(c, widths[i])).join(" "));
28
+ console.log(widths.map((w) => "-".repeat(w)).join(" "));
29
+ for (const row of rows) {
30
+ console.log(row.map((cell, i) => pad(cell, widths[i])).join(" "));
31
+ }
32
+ }
33
+ export {
34
+ handler
35
+ };
@@ -0,0 +1,47 @@
1
+ import {
2
+ listLocalSqliteDbs,
3
+ listSqliteDbs
4
+ } from "./chunk-J3GZ3DXD.js";
5
+ import "./chunk-G4ZAUHHA.js";
6
+ import "./chunk-6MRZXASS.js";
7
+ import {
8
+ init_require_shim
9
+ } from "./chunk-TPK5AGRA.js";
10
+
11
+ // src/sqlite/commands/list.js
12
+ init_require_shim();
13
+ function pad(s, n) {
14
+ return String(s ?? "-").padEnd(n);
15
+ }
16
+ function applyPluginFilter(dbs, plugin) {
17
+ if (plugin === void 0) return dbs;
18
+ const pluginScopes = /* @__PURE__ */ new Set(["global-plugin", "local-plugin"]);
19
+ if (plugin === true) return dbs.filter((d) => pluginScopes.has(d.scope));
20
+ return dbs.filter((d) => pluginScopes.has(d.scope) && d.pluginId === plugin);
21
+ }
22
+ async function handler({ projectDir, plugin }) {
23
+ const [local, global] = await Promise.all([
24
+ listLocalSqliteDbs(projectDir),
25
+ listSqliteDbs()
26
+ ]);
27
+ let dbs = applyPluginFilter([...local, ...global], plugin);
28
+ if (dbs.length === 0) {
29
+ console.log("No SQLite databases.");
30
+ return;
31
+ }
32
+ function pluginLabel(entry) {
33
+ if (entry.scope === "global-plugin" || entry.scope === "local-plugin") return entry.pluginId ?? "-";
34
+ return "-";
35
+ }
36
+ const cols = ["KEY", "NAME", "SCOPE", "PLUGIN", "FIRST SEEN"];
37
+ const rows = dbs.map((d) => [d.key, d.name, d.scope, pluginLabel(d), d.firstSeenAt ? new Date(d.firstSeenAt).toLocaleString() : "-"]);
38
+ const widths = cols.map((c, i) => Math.max(c.length, ...rows.map((r) => String(r[i] ?? "").length)));
39
+ console.log(cols.map((c, i) => pad(c, widths[i])).join(" "));
40
+ console.log(widths.map((w) => "-".repeat(w)).join(" "));
41
+ for (const row of rows) {
42
+ console.log(row.map((cell, i) => pad(cell, widths[i])).join(" "));
43
+ }
44
+ }
45
+ export {
46
+ handler
47
+ };
@@ -1,23 +1,24 @@
1
1
  import {
2
2
  require_cli_table3
3
3
  } from "./chunk-DMMC4X27.js";
4
- import {
5
- getRune
6
- } from "./chunk-6I7RHSAA.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
4
  import {
13
5
  loadConfig
14
6
  } from "./chunk-H3BVJCIL.js";
7
+ import {
8
+ getRune
9
+ } from "./chunk-JU6FKUBY.js";
10
+ import "./chunk-J3GZ3DXD.js";
11
+ import "./chunk-ZJDKCC2Y.js";
12
+ import "./chunk-NDEYEYSU.js";
13
+ import "./chunk-G4ZAUHHA.js";
14
+ import "./chunk-63H5VXZY.js";
15
+ import "./chunk-ASZKAC24.js";
15
16
  import {
16
17
  output
17
18
  } from "./chunk-6XLT25GS.js";
18
19
  import "./chunk-WCODTMDN.js";
19
- import "./chunk-GHQOK4L7.js";
20
- import "./chunk-HMU2J25D.js";
20
+ import "./chunk-65J65MAP.js";
21
+ import "./chunk-6MRZXASS.js";
21
22
  import "./chunk-G3U4V32O.js";
22
23
  import {
23
24
  __toESM,
@@ -52,7 +53,7 @@ async function handler({
52
53
  const enabledPlugins = config.plugins ?? [];
53
54
  if (enabledPlugins.length > 0) {
54
55
  try {
55
- const { loadRegistry } = await import("./registry-W5XFI5T6.js");
56
+ const { loadRegistry } = await import("./registry-3QIL5SVL.js");
56
57
  const { loadPluginJson } = await import("./manifest-7RVNKBOH.js");
57
58
  const registry = await loadRegistry();
58
59
  for (const pluginKey of enabledPlugins) {
@@ -1,11 +1,8 @@
1
1
  import {
2
2
  querySqliteDb
3
- } from "./chunk-67I2J474.js";
4
- import "./chunk-QMWGQXEZ.js";
5
- import {
6
- ensureProjectIdentity
7
- } from "./chunk-3TM6B4E5.js";
8
- import "./chunk-HMU2J25D.js";
3
+ } from "./chunk-J3GZ3DXD.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";
@@ -15,11 +12,10 @@ init_require_shim();
15
12
  function pad(s, n) {
16
13
  return String(s ?? "").padEnd(n);
17
14
  }
18
- async function handler({ id, sql, projectDir, global: isGlobal }) {
19
- const key = isGlobal ? void 0 : (await ensureProjectIdentity(projectDir)).id;
15
+ async function handler({ id, sql, projectDir }) {
20
16
  let rows;
21
17
  try {
22
- rows = await querySqliteDb(id, sql, key);
18
+ rows = await querySqliteDb(id, sql);
23
19
  } catch (err) {
24
20
  console.error(`Error: ${err.message}`);
25
21
  process.exit(1);
@@ -4,8 +4,8 @@ import {
4
4
  removePlugin,
5
5
  resolvePluginKey,
6
6
  saveRegistry
7
- } from "./chunk-GHQOK4L7.js";
8
- import "./chunk-HMU2J25D.js";
7
+ } from "./chunk-65J65MAP.js";
8
+ import "./chunk-6MRZXASS.js";
9
9
  import "./chunk-TPK5AGRA.js";
10
10
  export {
11
11
  loadRegistry,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  removeMarketplace
3
- } from "./chunk-L72BG6DS.js";
4
- import "./chunk-HMU2J25D.js";
3
+ } from "./chunk-NYLRTAAA.js";
4
+ import "./chunk-6MRZXASS.js";
5
5
  import {
6
6
  init_require_shim
7
7
  } from "./chunk-TPK5AGRA.js";
@@ -0,0 +1,180 @@
1
+ import {
2
+ init_require_shim
3
+ } from "./chunk-TPK5AGRA.js";
4
+
5
+ // src/docs/commands/repl.js
6
+ init_require_shim();
7
+ async function handler() {
8
+ process.stdout.write(`# Docs: The REPL Lifecycle Exports
9
+
10
+ The REPL lifecycle is a family of six named exports. At minimum, export \`repl\` or \`inputRepl\` (or both).
11
+
12
+ ## Lifecycle Export Family
13
+
14
+ | Export | Role | Called | Returns |
15
+ |---|---|---|---|
16
+ | \`argsRepl(builder)\` | Session option schema | Once, before start | schema |
17
+ | \`repl(args)\` | Session initializer | Once at session start | \`string | void\` \u2014 initial prompt |
18
+ | \`bannerRepl(args)\` | Welcome banner | Once after \`repl\` | \`string | void\` \u2014 banner text |
19
+ | \`commandsRepl(builder)\` | Slash command schema | Once, before start | schema |
20
+ | \`inputRepl(input)\` | Per-input dispatch | Once per \`InputEvent\` | \`ReplSignal | string | void\` |
21
+ | \`completeInputRepl(tokens)\` | Tab completion | On Tab key | \`string[]\` |
22
+
23
+ ## 1. repl(args) \u2014 Session Initializer
24
+
25
+ Called once at session start. Open connections, validate config, set up module-level state. Returns the initial prompt string, or void for the default \`"> "\`.
26
+
27
+ \`\`\`js
28
+ export async function repl(args) {
29
+ replDb = await sqlite.open(args.db, 'books')
30
+ return 'sqlite> '
31
+ }
32
+ \`\`\`
33
+
34
+ ## 2. bannerRepl(args) \u2014 Welcome Banner
35
+
36
+ Called once after \`repl\` resolves. Printed to stderr before the first prompt. Can use module-level state set up by \`repl\`.
37
+
38
+ \`\`\`js
39
+ export function bannerRepl(args) {
40
+ return \`Connected to \${args.db}/books.db \u2014 /help for commands\`
41
+ }
42
+ \`\`\`
43
+
44
+ ## 3. commandsRepl(builder) \u2014 Slash Command Schema
45
+
46
+ Declares rune slash commands. Only \`.command()\` at root level is used. Matched commands arrive in \`inputRepl\` as \`{ type: 'command', args }\` where \`args.$command\` is the command name.
47
+
48
+ \`\`\`js
49
+ export function commandsRepl(b) {
50
+ return b
51
+ .command('tables', 'List all tables')
52
+ .command('schema', 'Show table schema', sub => sub.positional('<table>', 'Table name'))
53
+ }
54
+ \`\`\`
55
+
56
+ ## 4. inputRepl(input) \u2014 Per-Input Dispatch
57
+
58
+ Called once per \`InputEvent\`. All session logic lives here.
59
+
60
+ ### InputEvent type
61
+
62
+ | type | text | When |
63
+ |---|---|---|
64
+ | \`'line'\` | raw input string | Normal user input |
65
+ | \`'interrupt'\` | \`''\` | Ctrl+C on empty prompt |
66
+ | \`'eof'\` | \`''\` | Ctrl+D or stdin closed |
67
+ | \`'command'\` | \u2014 | Matched slash command (use \`input.args.$command\`) |
68
+
69
+ \`\`\`js
70
+ export async function inputRepl(input) {
71
+ if (input.type === 'eof' || input.type === 'interrupt') {
72
+ await replDb.close(); replDb = null
73
+ return { type: 'done', message: 'Disconnected.' }
74
+ }
75
+ if (input.type === 'command') {
76
+ if (input.args.$command === 'tables') { /* ... */ }
77
+ return undefined
78
+ }
79
+ const trimmed = input.text.trim()
80
+ if (!trimmed) return undefined
81
+ const result = await execQuery(replDb, trimmed)
82
+ section.emit(result)
83
+ return 'sqlite> '
84
+ }
85
+ \`\`\`
86
+
87
+ ### Return values
88
+
89
+ | Return value | Effect |
90
+ |---|---|
91
+ | \`undefined\` or \`null\` | Continue \u2014 re-prompt |
92
+ | \`"string"\` | Continue \u2014 update prompt |
93
+ | \`{ type: 'prompt', value? }\` | Continue \u2014 optionally update prompt |
94
+ | \`{ type: 'done', message? }\` | End session |
95
+
96
+ ## 5. completeInputRepl(tokens) \u2014 Tab Completion
97
+
98
+ Called on Tab. Last token is the partial word being typed \u2014 same convention as the CLI completions system.
99
+
100
+ \`\`\`js
101
+ export async function completeInputRepl(tokens) {
102
+ const partial = tokens[tokens.length - 1] ?? ''
103
+ return ['SELECT', 'FROM', 'WHERE', 'INSERT', 'UPDATE', 'DELETE']
104
+ .filter(k => k.startsWith(partial.toUpperCase()))
105
+ }
106
+ \`\`\`
107
+
108
+ ## 6. Permissions
109
+
110
+ \`repl\` uses a **separate permission namespace** from \`run\`. Declare a \`"repl"\` block in \`config.json\`:
111
+
112
+ \`\`\`json
113
+ {
114
+ "runes": {
115
+ "my-shell": {
116
+ "permissions": {
117
+ "run": { "allow": ["sqlite.read:./state::db"] },
118
+ "repl": { "allow": ["sqlite.read:./state::db", "sqlite.write:./state::db"] }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ \`\`\`
124
+
125
+ ## 7. Built-in Slash Commands
126
+
127
+ These are always available regardless of \`commandsRepl\`:
128
+
129
+ | Command | Action |
130
+ |---|---|
131
+ | \`/help\` | Show available commands |
132
+ | \`/clear\` | Clear the screen (TTY only) |
133
+ | \`/exit\` | End the session |
134
+
135
+ ## 8. Input History
136
+
137
+ Arrow keys (\u2191/\u2193) navigate input history within the session. No persistence across sessions.
138
+
139
+ ## 9. Multiline Input (Ctrl+Enter)
140
+
141
+ In TTY mode, press **Ctrl+Enter** to add a soft newline without dispatching the input. The prompt indents to match the current prompt width. Press **Enter** to flush the entire buffer as a single \`line\` event \u2014 \`input.text\` contains the full multi-line string.
142
+
143
+ \`\`\`
144
+ sqlite> SELECT *
145
+ FROM books
146
+ WHERE genre = 'Sci-Fi';
147
+ \`\`\`
148
+
149
+ No new exports required. \`inputRepl()\` always receives the complete accumulated text.
150
+
151
+ ## 10. disposeRepl() \u2014 Guaranteed Teardown
152
+
153
+ Export an optional \`disposeRepl()\` function to run cleanup logic when the session ends, regardless of how it ends (normal exit, Ctrl+D, process signal). Errors thrown here are swallowed.
154
+
155
+ \`\`\`js
156
+ export async function disposeRepl() {
157
+ if (replDb) { await replDb.close(); replDb = null }
158
+ }
159
+ \`\`\`
160
+
161
+ This is called automatically before the isolate tears down. It removes the need to close resources inside \`inputRepl()\`'s \`eof\`/\`interrupt\` branches \u2014 though doing so there as well is harmless.
162
+
163
+ ## 11. JSONL Input Mode
164
+
165
+ When \`--format jsonl\` is active and stdin is not a TTY, each stdin line is parsed as a JSON \`InputEvent\` object and dispatched directly:
166
+
167
+ \`\`\`jsonl
168
+ {"type":"line","text":"SELECT 1"}
169
+ {"type":"line","text":"SELECT *\\nFROM books\\nWHERE genre = 'Sci-Fi'"}
170
+ {"type":"interrupt"}
171
+ {"type":"eof"}
172
+ \`\`\`
173
+
174
+ Multi-line text is encoded as \`\\n\` in the JSON string \u2014 no Ctrl+Enter needed. Invalid JSON or unrecognised \`type\` values emit a \`{ type: "error" }\` JSONL output line and are skipped; the session continues.
175
+
176
+ `);
177
+ }
178
+ export {
179
+ handler
180
+ };