@hop-top/kit 0.4.0-alpha.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 (174) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/LICENSE +25 -0
  3. package/README.md +189 -0
  4. package/dist/aim.d.ts +116 -0
  5. package/dist/aim.js +417 -0
  6. package/dist/alias.d.ts +73 -0
  7. package/dist/alias.js +207 -0
  8. package/dist/api.d.ts +62 -0
  9. package/dist/api.js +165 -0
  10. package/dist/auth.d.ts +26 -0
  11. package/dist/auth.js +41 -0
  12. package/dist/cli.d.ts +309 -0
  13. package/dist/cli.js +885 -0
  14. package/dist/config.d.ts +97 -0
  15. package/dist/config.js +79 -0
  16. package/dist/errcorrect.d.ts +37 -0
  17. package/dist/errcorrect.js +69 -0
  18. package/dist/llm.d.ts +188 -0
  19. package/dist/llm.js +356 -0
  20. package/dist/output.d.ts +213 -0
  21. package/dist/output.js +447 -0
  22. package/dist/progress.d.ts +30 -0
  23. package/dist/progress.js +56 -0
  24. package/dist/provenance.d.ts +24 -0
  25. package/dist/provenance.js +32 -0
  26. package/dist/routellm.d.ts +64 -0
  27. package/dist/routellm.js +258 -0
  28. package/dist/rpc.d.ts +25 -0
  29. package/dist/rpc.js +101 -0
  30. package/dist/safety.d.ts +24 -0
  31. package/dist/safety.js +44 -0
  32. package/dist/scope.d.ts +121 -0
  33. package/dist/scope.js +380 -0
  34. package/dist/sqlstore.d.ts +84 -0
  35. package/dist/sqlstore.js +85 -0
  36. package/dist/stream.d.ts +35 -0
  37. package/dist/stream.js +52 -0
  38. package/dist/tui/index.d.ts +300 -0
  39. package/dist/tui/index.js +332 -0
  40. package/dist/upgrade.d.ts +95 -0
  41. package/dist/upgrade.js +115 -0
  42. package/dist/xdg.d.ts +169 -0
  43. package/dist/xdg.js +129 -0
  44. package/eslint.config.mjs +17 -0
  45. package/package.json +133 -0
  46. package/src/README.md +3 -0
  47. package/src/aim.test.ts +331 -0
  48. package/src/aim.ts +388 -0
  49. package/src/alias.test.ts +423 -0
  50. package/src/alias.ts +256 -0
  51. package/src/api.test.ts +190 -0
  52. package/src/api.ts +214 -0
  53. package/src/auth.test.ts +24 -0
  54. package/src/auth.ts +37 -0
  55. package/src/bus.test.ts +178 -0
  56. package/src/bus.ts +114 -0
  57. package/src/cli.test.ts +690 -0
  58. package/src/cli.ts +741 -0
  59. package/src/completion-values.test.ts +202 -0
  60. package/src/completion-values.ts +173 -0
  61. package/src/completion.test.ts +212 -0
  62. package/src/completion.ts +158 -0
  63. package/src/compliance.test.ts +134 -0
  64. package/src/compliance.ts +669 -0
  65. package/src/config.test.ts +110 -0
  66. package/src/config.ts +164 -0
  67. package/src/errcorrect.test.ts +134 -0
  68. package/src/errcorrect.ts +84 -0
  69. package/src/flagregister.test.ts +103 -0
  70. package/src/flagregister.ts +78 -0
  71. package/src/gen/crud_connect.ts +76 -0
  72. package/src/gen/crud_pb.ts +269 -0
  73. package/src/hint.test.ts +315 -0
  74. package/src/hint.ts +178 -0
  75. package/src/llm.test.ts +612 -0
  76. package/src/llm.ts +577 -0
  77. package/src/log.test.ts +145 -0
  78. package/src/log.ts +155 -0
  79. package/src/output/builtins.ts +34 -0
  80. package/src/output/dispatch.ts +195 -0
  81. package/src/output/flags.ts +151 -0
  82. package/src/output/format_help.ts +80 -0
  83. package/src/output/formatter.ts +167 -0
  84. package/src/output/formatters/csv.ts +72 -0
  85. package/src/output/formatters/json.ts +44 -0
  86. package/src/output/formatters/table.ts +44 -0
  87. package/src/output/formatters/text.ts +109 -0
  88. package/src/output/formatters/yaml.ts +47 -0
  89. package/src/output/projection.ts +126 -0
  90. package/src/output/registry.ts +88 -0
  91. package/src/output/template.ts +63 -0
  92. package/src/output.test.ts +117 -0
  93. package/src/output.ts +90 -0
  94. package/src/progress.test.ts +93 -0
  95. package/src/progress.ts +58 -0
  96. package/src/provenance.test.ts +59 -0
  97. package/src/provenance.ts +26 -0
  98. package/src/routellm.test.ts +179 -0
  99. package/src/routellm.ts +365 -0
  100. package/src/router/bert.test.ts +180 -0
  101. package/src/router/bert.ts +145 -0
  102. package/src/router/controller.test.ts +183 -0
  103. package/src/router/controller.ts +165 -0
  104. package/src/router/integration.test.ts +309 -0
  105. package/src/router/intent.test.ts +187 -0
  106. package/src/router/intent.ts +208 -0
  107. package/src/router/mf.test.ts +66 -0
  108. package/src/router/mf.ts +52 -0
  109. package/src/router/random.test.ts +23 -0
  110. package/src/router/random.ts +13 -0
  111. package/src/router/router.test.ts +31 -0
  112. package/src/router/router.ts +62 -0
  113. package/src/router/server.test.ts +193 -0
  114. package/src/router/server.ts +134 -0
  115. package/src/router/sw.test.ts +199 -0
  116. package/src/router/sw.ts +232 -0
  117. package/src/rpc.test.ts +47 -0
  118. package/src/rpc.ts +91 -0
  119. package/src/safety.test.ts +53 -0
  120. package/src/safety.ts +42 -0
  121. package/src/scope-defaults.json +72 -0
  122. package/src/scope.test.ts +177 -0
  123. package/src/scope.ts +382 -0
  124. package/src/setflag.test.ts +110 -0
  125. package/src/setflag.ts +102 -0
  126. package/src/sqlstore.test.ts +110 -0
  127. package/src/sqlstore.ts +144 -0
  128. package/src/stream.test.ts +69 -0
  129. package/src/stream.ts +47 -0
  130. package/src/textflag.test.ts +105 -0
  131. package/src/textflag.ts +68 -0
  132. package/src/toolspec.test.ts +187 -0
  133. package/src/toolspec.ts +279 -0
  134. package/src/triton/client.test.ts +205 -0
  135. package/src/triton/client.ts +261 -0
  136. package/src/tui/anim.test.ts +146 -0
  137. package/src/tui/anim.ts +134 -0
  138. package/src/tui/badge.test.ts +41 -0
  139. package/src/tui/badge.ts +55 -0
  140. package/src/tui/confirm.test.ts +68 -0
  141. package/src/tui/confirm.ts +49 -0
  142. package/src/tui/index.ts +29 -0
  143. package/src/tui/list.test.ts +84 -0
  144. package/src/tui/list.ts +72 -0
  145. package/src/tui/parity.ts +41 -0
  146. package/src/tui/pills.test.ts +40 -0
  147. package/src/tui/pills.ts +43 -0
  148. package/src/tui/progress.test.ts +164 -0
  149. package/src/tui/progress.ts +120 -0
  150. package/src/tui/spinner.test.ts +111 -0
  151. package/src/tui/spinner.ts +96 -0
  152. package/src/tui/status.test.ts +68 -0
  153. package/src/tui/status.ts +66 -0
  154. package/src/upgrade.test.ts +298 -0
  155. package/src/upgrade.ts +205 -0
  156. package/src/uri.ts +199 -0
  157. package/src/wizard.test.ts +441 -0
  158. package/src/wizard.ts +662 -0
  159. package/src/xdg.test.ts +202 -0
  160. package/src/xdg.ts +280 -0
  161. package/test/output/cols.test.ts +148 -0
  162. package/test/output/csv.test.ts +129 -0
  163. package/test/output/dispatch.test.ts +194 -0
  164. package/test/output/format_help.test.ts +131 -0
  165. package/test/output/formatter.test.ts +137 -0
  166. package/test/output/output_flag.test.ts +124 -0
  167. package/test/output/registry.test.ts +127 -0
  168. package/test/output/smoke-capture.ts +83 -0
  169. package/test/output/smoke.test.ts +142 -0
  170. package/test/output/template.test.ts +95 -0
  171. package/test/output/text.test.ts +75 -0
  172. package/test/testdata/api-fixture.json +115 -0
  173. package/test/testdata/query-vectors.json +187 -0
  174. package/tsconfig.json +12 -0
package/dist/cli.js ADDED
@@ -0,0 +1,885 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/cli.ts
31
+ var cli_exports = {};
32
+ __export(cli_exports, {
33
+ Dark: () => Dark,
34
+ HintSet: () => HintSet,
35
+ Neon: () => Neon,
36
+ active: () => active,
37
+ applyHelpTheme: () => applyHelpTheme,
38
+ buildTheme: () => buildTheme,
39
+ channel: () => channel,
40
+ createCLI: () => createCLI,
41
+ getCommandGroup: () => getCommandGroup,
42
+ getStreamDefs: () => getStreamDefs,
43
+ hintsEnabled: () => hintsEnabled,
44
+ registerStream: () => registerStream,
45
+ registerUpgradeHints: () => registerUpgradeHints,
46
+ registerVersionHints: () => registerVersionHints,
47
+ renderHints: () => renderHints,
48
+ setCommandGroup: () => setCommandGroup,
49
+ verboseCount: () => verboseCount
50
+ });
51
+ module.exports = __toCommonJS(cli_exports);
52
+ var import_commander = require("commander");
53
+
54
+ // src/tui/parity.ts
55
+ var import_node_fs = require("fs");
56
+ var import_node_path = require("path");
57
+ var _candidates = [
58
+ (0, import_node_path.resolve)(__dirname, "..", "..", "..", "..", "contracts", "parity", "parity.json"),
59
+ (0, import_node_path.resolve)(__dirname, "..", "..", "..", "..", "..", "contracts", "parity", "parity.json"),
60
+ (0, import_node_path.resolve)(process.cwd(), "contracts", "parity", "parity.json")
61
+ ];
62
+ var _path = _candidates.find((path) => (0, import_node_fs.existsSync)(path)) ?? _candidates[0];
63
+ var parity = JSON.parse((0, import_node_fs.readFileSync)(_path, "utf8"));
64
+
65
+ // src/output/registry.ts
66
+ var Registry = class {
67
+ constructor() {
68
+ this.byKey = /* @__PURE__ */ new Map();
69
+ }
70
+ /**
71
+ * Adds f to the registry. Throws Error on duplicate key or empty key.
72
+ * Use `override` to intentionally replace.
73
+ */
74
+ register(f) {
75
+ if (f.key === "") {
76
+ throw new Error("output: formatter key is empty");
77
+ }
78
+ if (this.byKey.has(f.key)) {
79
+ throw new Error(
80
+ `output: formatter "${f.key}" already registered (use override to replace)`
81
+ );
82
+ }
83
+ this.byKey.set(f.key, f);
84
+ }
85
+ /** Replaces (or registers) the formatter for f.key. */
86
+ override(f) {
87
+ if (f.key === "") {
88
+ throw new Error("output: formatter key is empty");
89
+ }
90
+ this.byKey.set(f.key, f);
91
+ }
92
+ /** Returns the formatter registered under key, if any. */
93
+ lookup(key) {
94
+ return this.byKey.get(key);
95
+ }
96
+ /** Returns all registered format keys, sorted alphabetically. */
97
+ keys() {
98
+ return [...this.byKey.keys()].sort();
99
+ }
100
+ /** Returns all registered formatters in key order. */
101
+ formatters() {
102
+ return this.keys().map((k) => this.byKey.get(k));
103
+ }
104
+ /**
105
+ * Returns extension→key mappings (e.g. ".csv" → "csv") across all
106
+ * registered formatters. Later registrations win on collision; iteration
107
+ * is in sorted-key order so resolution is deterministic.
108
+ */
109
+ extensionMap() {
110
+ const out = /* @__PURE__ */ new Map();
111
+ for (const k of this.keys()) {
112
+ const f = this.byKey.get(k);
113
+ if (!f) continue;
114
+ for (const ext of f.extensions) {
115
+ out.set(ext.toLowerCase(), k);
116
+ }
117
+ }
118
+ return out;
119
+ }
120
+ };
121
+ var defaultRegistry = new Registry();
122
+
123
+ // src/output/flags.ts
124
+ var registryStash = /* @__PURE__ */ new WeakMap();
125
+ function registerOutputFlags(program, opts = {}) {
126
+ const registry = opts.registry ?? defaultRegistry;
127
+ const d = opts.disable ?? {};
128
+ if (registry !== defaultRegistry) {
129
+ registryStash.set(program, registry);
130
+ }
131
+ if (!d.format) {
132
+ program.option(
133
+ "--format <fmt>",
134
+ `Output format (${registry.keys().join(", ")})`,
135
+ "table"
136
+ );
137
+ }
138
+ if (!d.formatOpt) {
139
+ const opt = program.createOption(
140
+ "--format-opt <kv...>",
141
+ "Per-format option as key=value (repeatable; bool keys may omit =value)"
142
+ ).default([]).argParser(collectKv);
143
+ opt.hidden = true;
144
+ program.addOption(opt);
145
+ }
146
+ if (!d.formatHelp) {
147
+ const opt = program.createOption(
148
+ "--format-help [fmt]",
149
+ "Show available formats and their options (use --format-help <key> for one)"
150
+ );
151
+ opt.hidden = true;
152
+ program.addOption(opt);
153
+ }
154
+ if (!d.cols) {
155
+ const colsOpt = program.createOption("--cols <cols...>", "Restrict columns to this comma-separated list (repeatable)").default([]).argParser(collectCols);
156
+ colsOpt.hidden = true;
157
+ program.addOption(colsOpt);
158
+ const columnsOpt = program.createOption("--columns <cols...>", "Alias for --cols").default([]).argParser(collectCols);
159
+ columnsOpt.hidden = true;
160
+ program.addOption(columnsOpt);
161
+ }
162
+ if (!d.template) {
163
+ const opt = program.createOption(
164
+ "--template <tpl>",
165
+ "eta template applied to results (mutually exclusive with --cols)"
166
+ );
167
+ opt.hidden = true;
168
+ program.addOption(opt);
169
+ }
170
+ if (!d.output) {
171
+ const opt = program.createOption("-o, --output <path>", "Write output to path (use - or empty for stdout)").default("");
172
+ opt.hidden = true;
173
+ program.addOption(opt);
174
+ }
175
+ }
176
+ function collectKv(value, prev) {
177
+ return [...prev, value];
178
+ }
179
+ function collectCols(value, prev) {
180
+ return [...prev, ...value.split(",")];
181
+ }
182
+
183
+ // src/output/formatters/json.ts
184
+ var jsonFormatter = {
185
+ key: "json",
186
+ extensions: [".json"],
187
+ options: [
188
+ { name: "indent", type: "int", default: 2, usage: "spaces per indent level" }
189
+ ],
190
+ render(out, data, opts, cols) {
191
+ const indent = opts["indent"] ?? 2;
192
+ const value = projectForJson(data, cols);
193
+ out.write(JSON.stringify(value, null, indent) + "\n");
194
+ }
195
+ };
196
+ function projectForJson(data, cols) {
197
+ if (cols.length === 0) return data;
198
+ if (Array.isArray(data)) {
199
+ return data.map((row) => projectRow(row, cols));
200
+ }
201
+ return projectRow(data, cols);
202
+ }
203
+ function projectRow(row, cols) {
204
+ if (row === null || typeof row !== "object") return row;
205
+ const r = row;
206
+ const out = {};
207
+ for (const c of cols) out[c] = r[c];
208
+ return out;
209
+ }
210
+
211
+ // src/output/formatters/yaml.ts
212
+ var yaml = __toESM(require("js-yaml"));
213
+ var yamlFormatter = {
214
+ key: "yaml",
215
+ extensions: [".yaml", ".yml"],
216
+ options: [
217
+ {
218
+ name: "flow-level",
219
+ type: "int",
220
+ default: -1,
221
+ usage: "level at which to switch from block to flow style"
222
+ }
223
+ ],
224
+ render(out, data, opts, cols) {
225
+ const flowLevel = opts["flow-level"] ?? -1;
226
+ const value = projectForYaml(data, cols);
227
+ out.write(yaml.dump(value, { flowLevel }));
228
+ }
229
+ };
230
+ function projectForYaml(data, cols) {
231
+ if (cols.length === 0) return data;
232
+ if (Array.isArray(data)) {
233
+ return data.map((row) => projectRow2(row, cols));
234
+ }
235
+ return projectRow2(data, cols);
236
+ }
237
+ function projectRow2(row, cols) {
238
+ if (row === null || typeof row !== "object") return row;
239
+ const r = row;
240
+ const out = {};
241
+ for (const c of cols) out[c] = r[c];
242
+ return out;
243
+ }
244
+
245
+ // src/output/formatters/table.ts
246
+ var tableFormatter = {
247
+ key: "table",
248
+ extensions: [],
249
+ options: [],
250
+ render(out, data, _opts, cols) {
251
+ const rows = normalise(data);
252
+ if (rows.length === 0) return;
253
+ const allHeaders = Object.keys(rows[0] ?? {});
254
+ const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
255
+ if (headers.length === 0) return;
256
+ const cells = rows.map(
257
+ (row) => headers.map((h) => String(row[h] ?? ""))
258
+ );
259
+ const widths = headers.map(
260
+ (h, ci) => Math.max(h.length, ...cells.map((r) => r[ci].length))
261
+ );
262
+ const pad = (s, w) => s + " ".repeat(w - s.length);
263
+ const line = (parts) => parts.map((c, i) => pad(c, widths[i])).join(" ");
264
+ out.write(line(headers) + "\n");
265
+ for (const row of cells) {
266
+ out.write(line(row) + "\n");
267
+ }
268
+ }
269
+ };
270
+ function normalise(v) {
271
+ if (Array.isArray(v)) return v;
272
+ return [v];
273
+ }
274
+
275
+ // src/output/formatters/csv.ts
276
+ var import_sync = require("csv-stringify/sync");
277
+ var csvFormatter = {
278
+ key: "csv",
279
+ extensions: [".csv"],
280
+ options: [
281
+ { name: "delimiter", type: "string", default: ",", usage: "field delimiter" },
282
+ { name: "no-header", type: "bool", default: false, usage: "omit header row" },
283
+ {
284
+ name: "quote-all",
285
+ type: "bool",
286
+ default: false,
287
+ usage: "quote every field, not just those needing it"
288
+ },
289
+ {
290
+ name: "crlf",
291
+ type: "bool",
292
+ default: false,
293
+ usage: "use CRLF line endings (default LF)"
294
+ }
295
+ ],
296
+ render(out, data, opts, cols) {
297
+ const rows = normalise2(data);
298
+ if (rows.length === 0) return;
299
+ const allHeaders = Object.keys(rows[0] ?? {});
300
+ const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
301
+ if (headers.length === 0) return;
302
+ const delimiter = opts["delimiter"] ?? ",";
303
+ const noHeader = opts["no-header"] ?? false;
304
+ const quoteAll = opts["quote-all"] ?? false;
305
+ const crlf = opts["crlf"] ?? false;
306
+ if (delimiter.length !== 1) {
307
+ throw new Error(`option "delimiter": delimiter must be exactly one character`);
308
+ }
309
+ const records = rows.map((r) => headers.map((h) => stringify_cell(r[h])));
310
+ const csvRows = noHeader ? records : [headers, ...records];
311
+ const text = (0, import_sync.stringify)(csvRows, {
312
+ delimiter,
313
+ record_delimiter: crlf ? "windows" : "unix",
314
+ quoted: quoteAll
315
+ // No `header: true` — we already prepend headers ourselves to keep
316
+ // row layout uniform with csv format and to make `no-header` toggle
317
+ // a single decision point.
318
+ });
319
+ out.write(text);
320
+ }
321
+ };
322
+ function normalise2(v) {
323
+ if (Array.isArray(v)) return v;
324
+ return [v];
325
+ }
326
+ function stringify_cell(v) {
327
+ if (v === null || v === void 0) return "";
328
+ return String(v);
329
+ }
330
+
331
+ // src/output/formatters/text.ts
332
+ var STYLE_KV = "kv";
333
+ var STYLE_LINES = "lines";
334
+ var STYLE_PARAGRAPH = "paragraph";
335
+ var textFormatter = {
336
+ key: "text",
337
+ extensions: [".txt"],
338
+ options: [
339
+ {
340
+ name: "style",
341
+ type: "enum",
342
+ default: STYLE_KV,
343
+ enum: [STYLE_KV, STYLE_LINES, STYLE_PARAGRAPH],
344
+ usage: "output style"
345
+ },
346
+ {
347
+ name: "separator",
348
+ type: "string",
349
+ default: "=",
350
+ usage: "kv separator (kv style only)"
351
+ }
352
+ ],
353
+ render(out, data, opts, cols) {
354
+ const rows = normalise3(data);
355
+ if (rows.length === 0) return;
356
+ const allHeaders = Object.keys(rows[0] ?? {});
357
+ const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
358
+ if (headers.length === 0) return;
359
+ const style = opts["style"] || STYLE_KV;
360
+ const sep = opts["separator"] || "=";
361
+ switch (style) {
362
+ case STYLE_KV:
363
+ return renderKV(out, rows, headers, sep);
364
+ case STYLE_LINES:
365
+ return renderLines(out, rows, headers);
366
+ case STYLE_PARAGRAPH:
367
+ return renderParagraph(out, rows, headers);
368
+ }
369
+ }
370
+ };
371
+ function normalise3(v) {
372
+ if (Array.isArray(v)) return v;
373
+ return [v];
374
+ }
375
+ function fmt(v) {
376
+ if (v === null || v === void 0) return "";
377
+ return String(v);
378
+ }
379
+ function renderKV(out, rows, headers, sep) {
380
+ rows.forEach((r, i) => {
381
+ if (i > 0) out.write("\n");
382
+ for (const h of headers) {
383
+ out.write(`${h}${sep}${fmt(r[h])}
384
+ `);
385
+ }
386
+ });
387
+ }
388
+ function renderLines(out, rows, headers) {
389
+ for (const r of rows) {
390
+ out.write(headers.map((h) => fmt(r[h])).join(" ") + "\n");
391
+ }
392
+ }
393
+ function renderParagraph(out, rows, headers) {
394
+ rows.forEach((r, i) => {
395
+ if (i > 0) out.write("\n");
396
+ out.write(`Record ${i + 1}:
397
+ `);
398
+ for (const h of headers) {
399
+ out.write(` ${h}: ${fmt(r[h])}
400
+ `);
401
+ }
402
+ });
403
+ }
404
+
405
+ // src/output/builtins.ts
406
+ var registered = false;
407
+ function registerBuiltins() {
408
+ if (registered) return;
409
+ defaultRegistry.register(jsonFormatter);
410
+ defaultRegistry.register(yamlFormatter);
411
+ defaultRegistry.register(tableFormatter);
412
+ defaultRegistry.register(csvFormatter);
413
+ defaultRegistry.register(textFormatter);
414
+ registered = true;
415
+ }
416
+ registerBuiltins();
417
+
418
+ // src/hint.ts
419
+ var HintSet = class {
420
+ constructor() {
421
+ this.m = /* @__PURE__ */ new Map();
422
+ }
423
+ /** Add one or more hints for the given command name. */
424
+ register(cmd, ...hints) {
425
+ const existing = this.m.get(cmd) ?? [];
426
+ this.m.set(cmd, [...existing, ...hints]);
427
+ }
428
+ /**
429
+ * Return a copy of the hints registered for cmd.
430
+ * Returns an empty array when none are registered.
431
+ */
432
+ lookup(cmd) {
433
+ return [...this.m.get(cmd) ?? []];
434
+ }
435
+ };
436
+ function active(hints) {
437
+ return hints.filter((h) => h.condition === void 0 || h.condition());
438
+ }
439
+ function hintsEnabled(opts) {
440
+ if (opts.noHints) return false;
441
+ if (opts.hintsEnabled === false) return false;
442
+ if (opts.quiet) return false;
443
+ const env = process.env["HOP_QUIET_HINTS"];
444
+ if (env === "1" || env === "true" || env === "yes") return false;
445
+ return true;
446
+ }
447
+ function renderHints(w, hints, format, opts, muted) {
448
+ if (format !== "table") return;
449
+ if (!hintsEnabled(opts)) return;
450
+ const isTTY = w.isTTY === true;
451
+ if (!isTTY) return;
452
+ const visible = active(hints);
453
+ if (visible.length === 0) return;
454
+ const noColor = process.env["NO_COLOR"] !== void 0 || process.argv.includes("--no-color");
455
+ w.write("\n");
456
+ for (const h of visible) {
457
+ const text = `\u2192 ${h.message}`;
458
+ if (noColor) {
459
+ w.write(text + "\n");
460
+ } else {
461
+ const hex = muted.replace("#", "");
462
+ const r = parseInt(hex.slice(0, 2), 16);
463
+ const g = parseInt(hex.slice(2, 4), 16);
464
+ const b = parseInt(hex.slice(4, 6), 16);
465
+ w.write(`\x1B[38;2;${r};${g};${b}m${text}\x1B[0m
466
+ `);
467
+ }
468
+ }
469
+ }
470
+ function registerUpgradeHints(hints, binary, upgraded) {
471
+ hints.register("upgrade", {
472
+ message: `Run \`${binary} version\` to verify.`,
473
+ condition: upgraded
474
+ });
475
+ }
476
+ function registerVersionHints(hints, binary, updateAvail) {
477
+ hints.register("version", {
478
+ message: `Run \`${binary} upgrade\` to get latest.`,
479
+ condition: updateAvail
480
+ });
481
+ }
482
+
483
+ // src/cli.ts
484
+ var verboseCountMap = /* @__PURE__ */ new WeakMap();
485
+ function verboseCount(cmd) {
486
+ let c = cmd;
487
+ while (c) {
488
+ const v = verboseCountMap.get(c);
489
+ if (v !== void 0) return v;
490
+ c = c.parent ?? null;
491
+ }
492
+ return 0;
493
+ }
494
+ var streamDefsMap = /* @__PURE__ */ new WeakMap();
495
+ function registerStream(cmd, name, description) {
496
+ let defs = streamDefsMap.get(cmd);
497
+ if (!defs) {
498
+ defs = [];
499
+ streamDefsMap.set(cmd, defs);
500
+ cmd.option(
501
+ "--stream <names>",
502
+ "Enable diagnostic streams (comma-separated)"
503
+ );
504
+ }
505
+ defs.push({ name, description });
506
+ }
507
+ function getStreamDefs(cmd) {
508
+ return streamDefsMap.get(cmd) ?? [];
509
+ }
510
+ var noopWriter = { write(_s) {
511
+ return true;
512
+ } };
513
+ function channel(cmd, name) {
514
+ const opts = cmd.opts();
515
+ const enabled = typeof opts.stream === "string" ? opts.stream.split(",").map((s) => s.trim()).includes(name) : false;
516
+ if (!enabled) return noopWriter;
517
+ return {
518
+ write(s) {
519
+ const lines = s.split("\n");
520
+ for (const line of lines) {
521
+ if (line) process.stderr.write(`[${name}] ${line}
522
+ `);
523
+ }
524
+ return true;
525
+ }
526
+ };
527
+ }
528
+ var Neon = {
529
+ command: "#7ED957",
530
+ // grass green
531
+ flag: "#FF00FF"
532
+ // vivid neon pink
533
+ };
534
+ var Dark = {
535
+ command: "#C1FF72",
536
+ // lime
537
+ flag: "#FF66C4"
538
+ // pink
539
+ };
540
+ function buildTheme(accent) {
541
+ const palette = { ...Neon };
542
+ if (accent) {
543
+ palette.command = accent;
544
+ }
545
+ return {
546
+ palette,
547
+ accent: palette.command,
548
+ secondary: palette.flag,
549
+ muted: "#858183",
550
+ // CharmTone Squid
551
+ error: "#ED4A5E",
552
+ // CharmTone Cherry
553
+ success: "#52CF84",
554
+ // CharmTone Guac
555
+ title: "#FFFFFF",
556
+ // fang ColorScheme.Title
557
+ argument: "#B5E89B",
558
+ // fang ColorScheme.Argument
559
+ dimmedArgument: "#8ABF6E"
560
+ // fang ColorScheme.DimmedArgument
561
+ };
562
+ }
563
+ var commandGroupMap = /* @__PURE__ */ new WeakMap();
564
+ function setCommandGroup(cmd, groupId) {
565
+ commandGroupMap.set(cmd, groupId);
566
+ }
567
+ function getCommandGroup(cmd) {
568
+ return commandGroupMap.get(cmd);
569
+ }
570
+ function hexToRgb(hex) {
571
+ const h = hex.replace("#", "");
572
+ return [
573
+ parseInt(h.slice(0, 2), 16),
574
+ parseInt(h.slice(2, 4), 16),
575
+ parseInt(h.slice(4, 6), 16)
576
+ ];
577
+ }
578
+ function ansi(hex, text) {
579
+ const [r, g, b] = hexToRgb(hex);
580
+ return `\x1B[38;2;${r};${g};${b}m${text}\x1B[0m`;
581
+ }
582
+ function ansiBold(hex, text) {
583
+ const [r, g, b] = hexToRgb(hex);
584
+ return `\x1B[1;38;2;${r};${g};${b}m${text}\x1B[0m`;
585
+ }
586
+ function applyHelpTheme(program, theme, noColor, sectionOrder, showAliases, groups) {
587
+ const isNoColor = () => noColor || process.argv.includes("--no-color") || process.env["NO_COLOR"] !== void 0;
588
+ program.configureOutput({
589
+ ...program._outputConfiguration ?? {},
590
+ getOutHasColors: () => !isNoColor(),
591
+ getErrHasColors: () => !isNoColor()
592
+ });
593
+ program.configureHelp({
594
+ // --- V14 style hooks: delegate coloring here ---
595
+ styleTitle(str) {
596
+ return isNoColor() ? str : ansiBold(theme.title, str);
597
+ },
598
+ styleUsage(str) {
599
+ if (isNoColor()) return str;
600
+ return str.split(" ").map((word) => {
601
+ if (word === "[options]" || word === "[--flags]")
602
+ return ansi(theme.dimmedArgument, word);
603
+ if (word[0] === "[" || word[0] === "<")
604
+ return ansi(theme.argument, word);
605
+ return ansi(theme.accent, word);
606
+ }).join(" ");
607
+ },
608
+ styleCommandText(str) {
609
+ return isNoColor() ? str : ansi(theme.accent, str);
610
+ },
611
+ styleSubcommandText(str) {
612
+ return isNoColor() ? str : ansi(theme.accent, str);
613
+ },
614
+ styleOptionText(str) {
615
+ return isNoColor() ? str : ansi(theme.secondary, str);
616
+ },
617
+ styleArgumentText(str) {
618
+ return isNoColor() ? str : ansi(theme.argument, str);
619
+ },
620
+ styleDescriptionText(str) {
621
+ return isNoColor() ? str : ansi(theme.muted, str);
622
+ },
623
+ // Color each part of option term separately (short, long, arg).
624
+ styleOptionTerm(str) {
625
+ if (isNoColor()) return str;
626
+ return str.split(" ").map((word) => {
627
+ if (word === ",") return word;
628
+ if (word.startsWith("<") || word.startsWith("["))
629
+ return ansi(theme.argument, word);
630
+ if (word.endsWith(","))
631
+ return ansi(theme.secondary, word.slice(0, -1)) + ",";
632
+ return ansi(theme.secondary, word);
633
+ }).join(" ");
634
+ },
635
+ // Color subcommand term parts: name in accent, args dimmed.
636
+ styleSubcommandTerm(str) {
637
+ if (isNoColor()) return str;
638
+ const words = str.split(" ");
639
+ return words.map((word, i) => {
640
+ if (i === 0) return ansi(theme.accent, word);
641
+ if (word.startsWith("<") || word.startsWith("["))
642
+ return ansi(theme.dimmedArgument, word);
643
+ return ansi(theme.accent, word);
644
+ }).join(" ");
645
+ },
646
+ // --- Term overrides ---
647
+ subcommandTerm(cmd) {
648
+ const args = cmd.registeredArguments.map((a) => a.required ? `<${a.name()}>` : `[${a.name()}]`).join(" ");
649
+ const hasSubcmds = cmd.commands.length > 0;
650
+ let term = cmd.name();
651
+ if (args) term += " " + args;
652
+ if (hasSubcmds) term += " [command]";
653
+ else if (cmd.options.length) term += " [--flags]";
654
+ return term;
655
+ },
656
+ // --- Custom formatHelp for group partitioning + section ordering ---
657
+ formatHelp(cmd, helper) {
658
+ const termWidth = helper.padWidth(cmd, helper);
659
+ function callFormatItem(term, description) {
660
+ return helper.formatItem(term, termWidth, description, helper);
661
+ }
662
+ const output = [];
663
+ output.push(
664
+ `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`
665
+ );
666
+ output.push("");
667
+ const desc = helper.commandDescription(cmd);
668
+ if (desc) {
669
+ output.push(helper.styleCommandDescription(desc));
670
+ output.push("");
671
+ }
672
+ const helpSections = [];
673
+ const helpAll = process.argv.includes("--help-all");
674
+ let helpGroupFilter;
675
+ for (const arg of process.argv) {
676
+ const m = arg.match(/^--help-(.+)$/);
677
+ if (m && m[1] !== "all") {
678
+ helpGroupFilter = m[1];
679
+ break;
680
+ }
681
+ }
682
+ const groupDefs = /* @__PURE__ */ new Map();
683
+ for (const g of groups ?? []) {
684
+ groupDefs.set(g.id, { title: g.title, hidden: g.hidden ?? false });
685
+ }
686
+ const allCmds = helper.visibleCommands(cmd).filter((sc) => sc.name() !== "help");
687
+ const defaultCmds = [];
688
+ const groupedCmds = /* @__PURE__ */ new Map();
689
+ for (const sc of allCmds) {
690
+ const gid = getCommandGroup(sc);
691
+ if (gid && groupDefs.has(gid)) {
692
+ let arr = groupedCmds.get(gid);
693
+ if (!arr) {
694
+ arr = [];
695
+ groupedCmds.set(gid, arr);
696
+ }
697
+ arr.push(sc);
698
+ } else {
699
+ defaultCmds.push(sc);
700
+ }
701
+ }
702
+ const buildCmdItems = (cmds) => {
703
+ return cmds.map((sc) => {
704
+ let descr = helper.subcommandDescription(sc);
705
+ if (showAliases && sc.aliases().length > 0) {
706
+ descr += ` (aliases: ${sc.aliases().join(", ")})`;
707
+ }
708
+ return callFormatItem(
709
+ helper.styleSubcommandTerm(helper.subcommandTerm(sc)),
710
+ helper.styleSubcommandDescription(descr)
711
+ );
712
+ });
713
+ };
714
+ if (defaultCmds.length > 0 && !helpGroupFilter) {
715
+ helpSections.push({
716
+ name: "commands",
717
+ items: buildCmdItems(defaultCmds)
718
+ });
719
+ }
720
+ for (const [gid, cmds] of groupedCmds) {
721
+ if (helpGroupFilter && gid !== helpGroupFilter) continue;
722
+ const def = groupDefs.get(gid);
723
+ if (!helpGroupFilter && def.hidden && !helpAll) continue;
724
+ if (cmds.length > 0) {
725
+ helpSections.push({ name: gid, items: buildCmdItems(cmds) });
726
+ }
727
+ }
728
+ const opts = helper.visibleOptions(cmd);
729
+ if (opts.length > 0) {
730
+ const flagItems = opts.map(
731
+ (o) => callFormatItem(
732
+ helper.styleOptionTerm(helper.optionTerm(o)),
733
+ helper.styleOptionDescription(helper.optionDescription(o))
734
+ )
735
+ );
736
+ helpSections.push({ name: "flags", items: flagItems });
737
+ }
738
+ const sectionMap = new Map(helpSections.map((s) => [s.name, s]));
739
+ const effectiveOrder = sectionOrder && sectionOrder.length > 0 ? sectionOrder : parity.help.section_order;
740
+ const sectionTitles = parity.help.sections ?? {};
741
+ const resolveTitle = (name) => {
742
+ const gdef = groupDefs.get(name);
743
+ if (gdef) return gdef.title;
744
+ return sectionTitles[name]?.title ?? name.charAt(0).toUpperCase() + name.slice(1);
745
+ };
746
+ for (const name of effectiveOrder) {
747
+ if (name === "flags") continue;
748
+ const sec = sectionMap.get(name);
749
+ if (!sec) continue;
750
+ output.push(helper.styleTitle(`${resolveTitle(name)}:`));
751
+ output.push(...sec.items);
752
+ output.push("");
753
+ }
754
+ for (const sec of helpSections) {
755
+ if (sec.name === "flags") continue;
756
+ if (effectiveOrder.includes(sec.name)) continue;
757
+ output.push(helper.styleTitle(`${resolveTitle(sec.name)}:`));
758
+ output.push(...sec.items);
759
+ output.push("");
760
+ }
761
+ const flagsSec = sectionMap.get("flags");
762
+ if (flagsSec) {
763
+ output.push(helper.styleTitle(`${resolveTitle("flags")}:`));
764
+ output.push(...flagsSec.items);
765
+ output.push("");
766
+ }
767
+ const defs = getStreamDefs(cmd);
768
+ if (defs.length > 0) {
769
+ const styleTerm = helper.styleOptionTerm?.bind(helper) ?? ((s) => s);
770
+ const styleDesc = helper.styleDescriptionText?.bind(helper) ?? ((s) => s);
771
+ output.push(helper.styleTitle("STREAMS:"));
772
+ for (const d of defs) {
773
+ output.push(callFormatItem(styleTerm(d.name), styleDesc(d.description)));
774
+ }
775
+ output.push("");
776
+ }
777
+ return output.join("\n") + "\n";
778
+ }
779
+ });
780
+ }
781
+ function createCLI(cfg) {
782
+ const theme = buildTheme(cfg.accent);
783
+ const desc = cfg.help?.disclaimer ? `${cfg.description}
784
+
785
+ ${cfg.help.disclaimer}` : cfg.description;
786
+ const normalizedVersion = cfg.version.startsWith("v") ? cfg.version : `v${cfg.version}`;
787
+ const versionOutput = `${cfg.name} ${normalizedVersion}`;
788
+ const program = new import_commander.Command(cfg.name).description(desc).version(versionOutput, "-v, --version", `Print ${cfg.name} version and exit`).helpOption("-h, --help", "Display help").addHelpCommand(false).showHelpAfterError(true);
789
+ if (!cfg.disable?.format) {
790
+ registerOutputFlags(program);
791
+ }
792
+ if (!cfg.disable?.quiet) {
793
+ program.option("--quiet", "Suppress non-essential output", false);
794
+ }
795
+ if (!cfg.disable?.noColor) {
796
+ program.option("--no-color", "Disable ANSI colour", false);
797
+ }
798
+ if (!cfg.disable?.hints) {
799
+ program.option("--no-hints", "Suppress next-step hints after command output", false);
800
+ }
801
+ program.option(
802
+ "-V, --verbose",
803
+ "Increase verbosity",
804
+ (_, prev) => prev + 1,
805
+ 0
806
+ );
807
+ program.hook("preAction", (thisCmd) => {
808
+ const opts = thisCmd.opts();
809
+ const count = opts.quiet ? 0 : opts.verbose ?? 0;
810
+ verboseCountMap.set(thisCmd, count);
811
+ });
812
+ if (cfg.groups?.some((g) => g.hidden)) {
813
+ program.option("--help-all", "Show all commands including hidden groups");
814
+ program.on("option:help-all", () => {
815
+ program.help();
816
+ });
817
+ }
818
+ for (const g of cfg.groups ?? []) {
819
+ program.option(`--help-${g.id}`, `Show ${g.title} commands`);
820
+ program.on(`option:help-${g.id}`, () => {
821
+ program.help();
822
+ });
823
+ }
824
+ if (cfg.groups && cfg.groups.length > 0) {
825
+ const groupIds = cfg.groups.map((g) => g.id);
826
+ const helpCmd = program.command("help [group]").description("Show help for a command group").action((group) => {
827
+ if (group === "all") {
828
+ process.argv.push("--help-all");
829
+ program.help();
830
+ } else if (group && groupIds.includes(group)) {
831
+ process.argv.push(`--help-${group}`);
832
+ program.help();
833
+ } else {
834
+ program.help();
835
+ }
836
+ });
837
+ helpCmd.hideHelp = true;
838
+ helpCmd._hidden = true;
839
+ }
840
+ for (const g of cfg.globals ?? []) {
841
+ const flag = g.short ? `-${g.short}, --${g.name} <value>` : `--${g.name} <value>`;
842
+ program.option(flag, g.usage, g.default ?? "");
843
+ }
844
+ applyHelpTheme(
845
+ program,
846
+ theme,
847
+ false,
848
+ cfg.help?.sectionOrder,
849
+ cfg.help?.showAliases,
850
+ cfg.groups
851
+ );
852
+ const existing = program._outputConfiguration ?? {};
853
+ program.configureOutput({
854
+ ...existing,
855
+ outputError(str, write) {
856
+ const nc = process.argv.includes("--no-color") || process.env["NO_COLOR"] !== void 0;
857
+ if (nc) {
858
+ write(str);
859
+ } else {
860
+ write(ansi(theme.error, str));
861
+ }
862
+ }
863
+ });
864
+ return { program, theme };
865
+ }
866
+ // Annotate the CommonJS export names for ESM import in node:
867
+ 0 && (module.exports = {
868
+ Dark,
869
+ HintSet,
870
+ Neon,
871
+ active,
872
+ applyHelpTheme,
873
+ buildTheme,
874
+ channel,
875
+ createCLI,
876
+ getCommandGroup,
877
+ getStreamDefs,
878
+ hintsEnabled,
879
+ registerStream,
880
+ registerUpgradeHints,
881
+ registerVersionHints,
882
+ renderHints,
883
+ setCommandGroup,
884
+ verboseCount
885
+ });