@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.3
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/CHANGELOG.md +107 -0
- package/README.md +333 -9
- package/dist/aim-CTp-kJW2.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/alias-dhhr08Ei.d.ts +88 -0
- package/dist/alias.d.ts +2 -73
- package/dist/api-miiso81x.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/cli-DLygZLi9.d.ts +450 -0
- package/dist/cli.d.ts +6 -309
- package/dist/cli.js +192 -63
- package/dist/config-BUY7_W2n.d.ts +103 -0
- package/dist/config.d.ts +1 -97
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/error-DISJKeDu.d.ts +144 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/index-Bc5c7Ty5.d.ts +328 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-MLrRDvEG.d.ts +1073 -0
- package/dist/index-QSffbLnj.d.ts +94 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +6794 -0
- package/dist/llm-B5XUWH8T.d.ts +231 -0
- package/dist/llm.d.ts +1 -188
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +1453 -0
- package/dist/netpolicy-asvCfwi8.d.ts +138 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +118 -0
- package/dist/output-4aXs91GY.d.ts +396 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +567 -43
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/routellm-PGSt2D1y.d.ts +75 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/rpc-D5xLEf8V.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/serve-DE-jscpb.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +1019 -0
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +12 -1
- package/dist/tui/index.d.ts +5 -298
- package/dist/tui/index.js +3 -10
- package/dist/upgrade-p_zh3pvV.d.ts +102 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/package.json +26 -3
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.ts +112 -12
- package/src/index.test.ts +58 -0
- package/src/index.ts +37 -0
- package/src/log.parity.test.ts +105 -0
- package/src/log.ts +64 -13
- package/src/mcp/bridge.test.ts +150 -0
- package/src/mcp/bridge.ts +246 -0
- package/src/mcp/conformance.test.ts +336 -0
- package/src/mcp/dispatch.ts +313 -0
- package/src/mcp/index.ts +138 -0
- package/src/mcp/legacy.ts +314 -0
- package/src/mcp/mcp.test.ts +697 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +452 -0
- package/src/mcp/modern.ts +723 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/types.ts +504 -0
- package/src/netpolicy.test.ts +202 -0
- package/src/netpolicy.ts +231 -0
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +316 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +41 -3
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +7 -1
- package/src/telemetry/offline.test.ts +64 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/test/output/csv.test.ts +164 -0
- package/test/output/error.test.ts +246 -0
- package/src/tui/parity.json +0 -74
package/dist/cli.js
CHANGED
|
@@ -5,9 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (
|
|
8
|
+
var __export = (target2, all) => {
|
|
9
9
|
for (var name in all)
|
|
10
|
-
__defProp(
|
|
10
|
+
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -17,12 +17,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode,
|
|
20
|
+
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
21
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
22
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
23
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
24
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
@@ -31,8 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var cli_exports = {};
|
|
32
32
|
__export(cli_exports, {
|
|
33
33
|
Dark: () => Dark,
|
|
34
|
+
ErrOffline: () => ErrOffline,
|
|
34
35
|
HintSet: () => HintSet,
|
|
35
36
|
Neon: () => Neon,
|
|
37
|
+
OfflineError: () => OfflineError,
|
|
36
38
|
active: () => active,
|
|
37
39
|
applyHelpTheme: () => applyHelpTheme,
|
|
38
40
|
buildTheme: () => buildTheme,
|
|
@@ -40,18 +42,27 @@ __export(cli_exports, {
|
|
|
40
42
|
createCLI: () => createCLI,
|
|
41
43
|
getCommandGroup: () => getCommandGroup,
|
|
42
44
|
getStreamDefs: () => getStreamDefs,
|
|
45
|
+
guardFetch: () => guardFetch,
|
|
43
46
|
hintsEnabled: () => hintsEnabled,
|
|
47
|
+
isOffline: () => isOffline,
|
|
48
|
+
isOfflineError: () => isOfflineError,
|
|
44
49
|
registerStream: () => registerStream,
|
|
45
50
|
registerUpgradeHints: () => registerUpgradeHints,
|
|
46
51
|
registerVersionHints: () => registerVersionHints,
|
|
47
52
|
renderHints: () => renderHints,
|
|
48
53
|
setCommandGroup: () => setCommandGroup,
|
|
49
|
-
|
|
54
|
+
streamFlagName: () => streamFlagName,
|
|
55
|
+
streamLabel: () => streamLabel,
|
|
56
|
+
streamOutput: () => streamOutput,
|
|
57
|
+
verboseCount: () => verboseCount,
|
|
58
|
+
verbosityFlagSpec: () => verbosityFlagSpec,
|
|
59
|
+
verbosityShorthand: () => verbosityShorthand,
|
|
60
|
+
withOffline: () => withOffline
|
|
50
61
|
});
|
|
51
62
|
module.exports = __toCommonJS(cli_exports);
|
|
52
63
|
var import_commander = require("commander");
|
|
53
64
|
|
|
54
|
-
//
|
|
65
|
+
// ../../contracts/parity/parity.json
|
|
55
66
|
var parity_default = {
|
|
56
67
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
57
68
|
$id: "https://hop.top/kit/go/console/tui/parity.json",
|
|
@@ -106,16 +117,9 @@ var parity_default = {
|
|
|
106
117
|
label_format: "[{name}]",
|
|
107
118
|
output: "stderr"
|
|
108
119
|
},
|
|
109
|
-
table: {
|
|
110
|
-
description: "Styled-table contract for the output package. Plain tabwriter is the default; callers opt in to the lipgloss-backed renderer via WithTableStyle. The styled path is gated on writer-is-TTY so non-TTY writers (pipes, files, tests) always emit ANSI-free, diff-friendly output.",
|
|
111
|
-
render_option: "WithTableStyle",
|
|
112
|
-
tty_only: true,
|
|
113
|
-
row_emphasis_kinds: ["none", "primary", "secondary", "muted"],
|
|
114
|
-
row_emphasis_option: "RowEmphasis",
|
|
115
|
-
border_default: "normal"
|
|
116
|
-
},
|
|
117
120
|
extends: [
|
|
118
|
-
"scope-defaults.json"
|
|
121
|
+
"scope-defaults.json",
|
|
122
|
+
"serve.json"
|
|
119
123
|
]
|
|
120
124
|
};
|
|
121
125
|
|
|
@@ -240,6 +244,109 @@ function collectCols(value, prev) {
|
|
|
240
244
|
return [...prev, ...value.split(",")];
|
|
241
245
|
}
|
|
242
246
|
|
|
247
|
+
// src/netpolicy.ts
|
|
248
|
+
var import_node_async_hooks = require("async_hooks");
|
|
249
|
+
var ErrOffline = "OfflineError";
|
|
250
|
+
var OfflineError = class extends Error {
|
|
251
|
+
constructor(method, url) {
|
|
252
|
+
super(`${method} ${url}: network disabled by --offline`);
|
|
253
|
+
this.name = ErrOffline;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
function isOfflineError(err) {
|
|
257
|
+
return err instanceof Error && err.name === ErrOffline;
|
|
258
|
+
}
|
|
259
|
+
var store = new import_node_async_hooks.AsyncLocalStorage();
|
|
260
|
+
var processOffline = false;
|
|
261
|
+
function withOffline(offline, fn) {
|
|
262
|
+
if (!offline) return fn();
|
|
263
|
+
return store.run(true, fn);
|
|
264
|
+
}
|
|
265
|
+
function setProcessOffline(offline) {
|
|
266
|
+
processOffline = offline;
|
|
267
|
+
}
|
|
268
|
+
function isOffline() {
|
|
269
|
+
return processOffline || store.getStore() === true;
|
|
270
|
+
}
|
|
271
|
+
function isLoopback(hostname) {
|
|
272
|
+
const h = hostname.replace(/^\[|\]$/g, "");
|
|
273
|
+
if (h === "localhost") return true;
|
|
274
|
+
if (h === "::1") return true;
|
|
275
|
+
const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(h);
|
|
276
|
+
if (v4) {
|
|
277
|
+
return v4.slice(1).every((o) => Number(o) <= 255) && Number(v4[1]) === 127;
|
|
278
|
+
}
|
|
279
|
+
const mapped = /^::ffff:(.+)$/i.exec(h);
|
|
280
|
+
if (mapped) {
|
|
281
|
+
const inner = mapped[1] ?? "";
|
|
282
|
+
if (/^7f00:1$/i.test(inner)) return true;
|
|
283
|
+
return isLoopback(inner);
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
function target(input, init) {
|
|
288
|
+
if (typeof Request !== "undefined" && input instanceof Request) {
|
|
289
|
+
return { method: init?.method ?? input.method, url: input.url };
|
|
290
|
+
}
|
|
291
|
+
return { method: init?.method ?? "GET", url: String(input) };
|
|
292
|
+
}
|
|
293
|
+
var guarded = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.guarded");
|
|
294
|
+
var unguardedBase = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.unguardedBase");
|
|
295
|
+
function guardFetch(base) {
|
|
296
|
+
if (base[guarded]) return base;
|
|
297
|
+
const wrapper = async (input, init) => {
|
|
298
|
+
if (isOffline()) {
|
|
299
|
+
const { method, url } = target(input, init);
|
|
300
|
+
let loopback = false;
|
|
301
|
+
try {
|
|
302
|
+
loopback = isLoopback(new URL(url).hostname);
|
|
303
|
+
} catch {
|
|
304
|
+
loopback = false;
|
|
305
|
+
}
|
|
306
|
+
if (!loopback) throw new OfflineError(method, url);
|
|
307
|
+
}
|
|
308
|
+
return base(input, init);
|
|
309
|
+
};
|
|
310
|
+
wrapper[guarded] = true;
|
|
311
|
+
wrapper[unguardedBase] = base;
|
|
312
|
+
return wrapper;
|
|
313
|
+
}
|
|
314
|
+
function install() {
|
|
315
|
+
globalThis.fetch = guardFetch(globalThis.fetch);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/output/projection.ts
|
|
319
|
+
function deriveHeaders(rows, columns) {
|
|
320
|
+
if (columns && columns.length > 0) {
|
|
321
|
+
return columns.map((c) => c.header);
|
|
322
|
+
}
|
|
323
|
+
if (rows.length === 0) return [];
|
|
324
|
+
const first = rows[0];
|
|
325
|
+
if (first === null || typeof first !== "object") return [];
|
|
326
|
+
return Object.keys(first);
|
|
327
|
+
}
|
|
328
|
+
function projectRows(rows, cols) {
|
|
329
|
+
return rows.map((row) => {
|
|
330
|
+
const r = row ?? {};
|
|
331
|
+
if (cols.length === 0) return r;
|
|
332
|
+
const out = {};
|
|
333
|
+
for (const name of cols) out[name] = r[name];
|
|
334
|
+
return out;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/output/formatters/project.ts
|
|
339
|
+
function projectForEncoding(data, cols) {
|
|
340
|
+
if (cols.length === 0) return data;
|
|
341
|
+
if (Array.isArray(data)) {
|
|
342
|
+
const rows = data;
|
|
343
|
+
if (rows.some((r) => r === null || typeof r !== "object")) return data;
|
|
344
|
+
return projectRows(rows, cols);
|
|
345
|
+
}
|
|
346
|
+
if (data === null || typeof data !== "object") return data;
|
|
347
|
+
return projectRows([data], cols)[0];
|
|
348
|
+
}
|
|
349
|
+
|
|
243
350
|
// src/output/formatters/json.ts
|
|
244
351
|
var jsonFormatter = {
|
|
245
352
|
key: "json",
|
|
@@ -249,24 +356,10 @@ var jsonFormatter = {
|
|
|
249
356
|
],
|
|
250
357
|
render(out, data, opts, cols) {
|
|
251
358
|
const indent = opts["indent"] ?? 2;
|
|
252
|
-
const value =
|
|
359
|
+
const value = projectForEncoding(data, cols);
|
|
253
360
|
out.write(JSON.stringify(value, null, indent) + "\n");
|
|
254
361
|
}
|
|
255
362
|
};
|
|
256
|
-
function projectForJson(data, cols) {
|
|
257
|
-
if (cols.length === 0) return data;
|
|
258
|
-
if (Array.isArray(data)) {
|
|
259
|
-
return data.map((row) => projectRow(row, cols));
|
|
260
|
-
}
|
|
261
|
-
return projectRow(data, cols);
|
|
262
|
-
}
|
|
263
|
-
function projectRow(row, cols) {
|
|
264
|
-
if (row === null || typeof row !== "object") return row;
|
|
265
|
-
const r = row;
|
|
266
|
-
const out = {};
|
|
267
|
-
for (const c of cols) out[c] = r[c];
|
|
268
|
-
return out;
|
|
269
|
-
}
|
|
270
363
|
|
|
271
364
|
// src/output/formatters/yaml.ts
|
|
272
365
|
var yaml = __toESM(require("js-yaml"));
|
|
@@ -283,24 +376,10 @@ var yamlFormatter = {
|
|
|
283
376
|
],
|
|
284
377
|
render(out, data, opts, cols) {
|
|
285
378
|
const flowLevel = opts["flow-level"] ?? -1;
|
|
286
|
-
const value =
|
|
379
|
+
const value = projectForEncoding(data, cols);
|
|
287
380
|
out.write(yaml.dump(value, { flowLevel }));
|
|
288
381
|
}
|
|
289
382
|
};
|
|
290
|
-
function projectForYaml(data, cols) {
|
|
291
|
-
if (cols.length === 0) return data;
|
|
292
|
-
if (Array.isArray(data)) {
|
|
293
|
-
return data.map((row) => projectRow2(row, cols));
|
|
294
|
-
}
|
|
295
|
-
return projectRow2(data, cols);
|
|
296
|
-
}
|
|
297
|
-
function projectRow2(row, cols) {
|
|
298
|
-
if (row === null || typeof row !== "object") return row;
|
|
299
|
-
const r = row;
|
|
300
|
-
const out = {};
|
|
301
|
-
for (const c of cols) out[c] = r[c];
|
|
302
|
-
return out;
|
|
303
|
-
}
|
|
304
383
|
|
|
305
384
|
// src/output/formatters/table.ts
|
|
306
385
|
var tableFormatter = {
|
|
@@ -310,8 +389,7 @@ var tableFormatter = {
|
|
|
310
389
|
render(out, data, _opts, cols) {
|
|
311
390
|
const rows = normalise(data);
|
|
312
391
|
if (rows.length === 0) return;
|
|
313
|
-
const
|
|
314
|
-
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
392
|
+
const headers = cols.length > 0 ? cols : deriveHeaders(rows);
|
|
315
393
|
if (headers.length === 0) return;
|
|
316
394
|
const cells = rows.map(
|
|
317
395
|
(row) => headers.map((h) => String(row[h] ?? ""))
|
|
@@ -333,7 +411,6 @@ function normalise(v) {
|
|
|
333
411
|
}
|
|
334
412
|
|
|
335
413
|
// src/output/formatters/csv.ts
|
|
336
|
-
var import_sync = require("csv-stringify/sync");
|
|
337
414
|
var csvFormatter = {
|
|
338
415
|
key: "csv",
|
|
339
416
|
extensions: [".csv"],
|
|
@@ -368,17 +445,26 @@ var csvFormatter = {
|
|
|
368
445
|
}
|
|
369
446
|
const records = rows.map((r) => headers.map((h) => stringify_cell(r[h])));
|
|
370
447
|
const csvRows = noHeader ? records : [headers, ...records];
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// row layout uniform with csv format and to make `no-header` toggle
|
|
377
|
-
// a single decision point.
|
|
378
|
-
});
|
|
448
|
+
const eol = crlf ? "\r\n" : "\n";
|
|
449
|
+
let text = "";
|
|
450
|
+
for (const cells of csvRows) {
|
|
451
|
+
text += cells.map((c) => encodeField(c, delimiter, quoteAll)).join(delimiter) + eol;
|
|
452
|
+
}
|
|
379
453
|
out.write(text);
|
|
380
454
|
}
|
|
381
455
|
};
|
|
456
|
+
function needsQuotes(field, delim) {
|
|
457
|
+
if (field === "") return false;
|
|
458
|
+
if (field === "\\.") return true;
|
|
459
|
+
if (field.includes(delim) || field.includes('"') || field.includes("\n") || field.includes("\r")) {
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
return /^\s/u.test(field);
|
|
463
|
+
}
|
|
464
|
+
function encodeField(field, delim, quoteAll) {
|
|
465
|
+
if (!quoteAll && !needsQuotes(field, delim)) return field;
|
|
466
|
+
return `"${field.replace(/"/g, '""')}"`;
|
|
467
|
+
}
|
|
382
468
|
function normalise2(v) {
|
|
383
469
|
if (Array.isArray(v)) return v;
|
|
384
470
|
return [v];
|
|
@@ -413,8 +499,7 @@ var textFormatter = {
|
|
|
413
499
|
render(out, data, opts, cols) {
|
|
414
500
|
const rows = normalise3(data);
|
|
415
501
|
if (rows.length === 0) return;
|
|
416
|
-
const
|
|
417
|
-
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
502
|
+
const headers = cols.length > 0 ? cols : deriveHeaders(rows);
|
|
418
503
|
if (headers.length === 0) return;
|
|
419
504
|
const style = opts["style"] || STYLE_KV;
|
|
420
505
|
const sep = opts["separator"] || "=";
|
|
@@ -542,6 +627,13 @@ function registerVersionHints(hints, binary, updateAvail) {
|
|
|
542
627
|
|
|
543
628
|
// src/cli.ts
|
|
544
629
|
var verboseCountMap = /* @__PURE__ */ new WeakMap();
|
|
630
|
+
function verbosityShorthand(d) {
|
|
631
|
+
const s = (d.verbosity?.flag ?? "").replace(/^-+/, "");
|
|
632
|
+
return s.length === 1 ? s : "V";
|
|
633
|
+
}
|
|
634
|
+
function verbosityFlagSpec(d) {
|
|
635
|
+
return `-${verbosityShorthand(d)}, --verbose`;
|
|
636
|
+
}
|
|
545
637
|
function verboseCount(cmd) {
|
|
546
638
|
let c = cmd;
|
|
547
639
|
while (c) {
|
|
@@ -552,13 +644,24 @@ function verboseCount(cmd) {
|
|
|
552
644
|
return 0;
|
|
553
645
|
}
|
|
554
646
|
var streamDefsMap = /* @__PURE__ */ new WeakMap();
|
|
647
|
+
function streamFlagName(d) {
|
|
648
|
+
const name = (d.streams?.flag ?? "").replace(/^-+/, "");
|
|
649
|
+
return name === "" ? "stream" : name;
|
|
650
|
+
}
|
|
651
|
+
function streamLabel(d, name) {
|
|
652
|
+
const format = d.streams?.label_format || "[{name}]";
|
|
653
|
+
return format.split("{name}").join(name) + " ";
|
|
654
|
+
}
|
|
655
|
+
function streamOutput(d) {
|
|
656
|
+
return d.streams?.output === "stdout" ? process.stdout : process.stderr;
|
|
657
|
+
}
|
|
555
658
|
function registerStream(cmd, name, description) {
|
|
556
659
|
let defs = streamDefsMap.get(cmd);
|
|
557
660
|
if (!defs) {
|
|
558
661
|
defs = [];
|
|
559
662
|
streamDefsMap.set(cmd, defs);
|
|
560
663
|
cmd.option(
|
|
561
|
-
|
|
664
|
+
`--${streamFlagName(parity)} <names>`,
|
|
562
665
|
"Enable diagnostic streams (comma-separated)"
|
|
563
666
|
);
|
|
564
667
|
}
|
|
@@ -570,15 +673,21 @@ function getStreamDefs(cmd) {
|
|
|
570
673
|
var noopWriter = { write(_s) {
|
|
571
674
|
return true;
|
|
572
675
|
} };
|
|
676
|
+
function optionKey(flagName) {
|
|
677
|
+
return flagName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
678
|
+
}
|
|
573
679
|
function channel(cmd, name) {
|
|
574
680
|
const opts = cmd.opts();
|
|
575
|
-
const
|
|
681
|
+
const raw = opts[optionKey(streamFlagName(parity))];
|
|
682
|
+
const enabled = typeof raw === "string" ? raw.split(",").map((s) => s.trim()).includes(name) : false;
|
|
576
683
|
if (!enabled) return noopWriter;
|
|
684
|
+
const prefix = streamLabel(parity, name);
|
|
685
|
+
const w = streamOutput(parity);
|
|
577
686
|
return {
|
|
578
687
|
write(s) {
|
|
579
688
|
const lines = s.split("\n");
|
|
580
689
|
for (const line of lines) {
|
|
581
|
-
if (line)
|
|
690
|
+
if (line) w.write(`${prefix}${line}
|
|
582
691
|
`);
|
|
583
692
|
}
|
|
584
693
|
return true;
|
|
@@ -858,8 +967,17 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
858
967
|
if (!cfg.disable?.hints) {
|
|
859
968
|
program.option("--no-hints", "Suppress next-step hints after command output", false);
|
|
860
969
|
}
|
|
970
|
+
if (!cfg.disable?.offline) {
|
|
971
|
+
program.option("--offline", "Disable network access", false);
|
|
972
|
+
install();
|
|
973
|
+
const stamp = (thisCmd) => {
|
|
974
|
+
setProcessOffline(thisCmd.opts()["offline"] === true);
|
|
975
|
+
};
|
|
976
|
+
program.hook("preSubcommand", (thisCmd) => stamp(thisCmd));
|
|
977
|
+
program.hook("preAction", (thisCmd) => stamp(thisCmd));
|
|
978
|
+
}
|
|
861
979
|
program.option(
|
|
862
|
-
|
|
980
|
+
verbosityFlagSpec(parity),
|
|
863
981
|
"Increase verbosity",
|
|
864
982
|
(_, prev) => prev + 1,
|
|
865
983
|
0
|
|
@@ -926,8 +1044,10 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
926
1044
|
// Annotate the CommonJS export names for ESM import in node:
|
|
927
1045
|
0 && (module.exports = {
|
|
928
1046
|
Dark,
|
|
1047
|
+
ErrOffline,
|
|
929
1048
|
HintSet,
|
|
930
1049
|
Neon,
|
|
1050
|
+
OfflineError,
|
|
931
1051
|
active,
|
|
932
1052
|
applyHelpTheme,
|
|
933
1053
|
buildTheme,
|
|
@@ -935,11 +1055,20 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
935
1055
|
createCLI,
|
|
936
1056
|
getCommandGroup,
|
|
937
1057
|
getStreamDefs,
|
|
1058
|
+
guardFetch,
|
|
938
1059
|
hintsEnabled,
|
|
1060
|
+
isOffline,
|
|
1061
|
+
isOfflineError,
|
|
939
1062
|
registerStream,
|
|
940
1063
|
registerUpgradeHints,
|
|
941
1064
|
registerVersionHints,
|
|
942
1065
|
renderHints,
|
|
943
1066
|
setCommandGroup,
|
|
944
|
-
|
|
1067
|
+
streamFlagName,
|
|
1068
|
+
streamLabel,
|
|
1069
|
+
streamOutput,
|
|
1070
|
+
verboseCount,
|
|
1071
|
+
verbosityFlagSpec,
|
|
1072
|
+
verbosityShorthand,
|
|
1073
|
+
withOffline
|
|
945
1074
|
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* Layered YAML configuration loader — TypeScript port of hop.top/kit/config.
|
|
5
|
+
*
|
|
6
|
+
* Merges configuration from up to three file layers in priority order:
|
|
7
|
+
* system → user → project → envOverride
|
|
8
|
+
*
|
|
9
|
+
* Each later layer's values overwrite earlier ones via {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign | Object.assign}.
|
|
10
|
+
* Missing files are silently skipped. A file that exists but contains invalid
|
|
11
|
+
* YAML causes {@link load} to throw.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { load } from "@hop-top/kit/config";
|
|
16
|
+
*
|
|
17
|
+
* interface AppConfig {
|
|
18
|
+
* host: string;
|
|
19
|
+
* port: number;
|
|
20
|
+
* debug: boolean;
|
|
21
|
+
* token: string;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* const cfg: AppConfig = { host: "localhost", port: 3000, debug: false, token: "" };
|
|
25
|
+
*
|
|
26
|
+
* load(cfg, {
|
|
27
|
+
* systemConfigPath: "/etc/mytool/config.yaml",
|
|
28
|
+
* userConfigPath: `${process.env.HOME}/.config/mytool/config.yaml`,
|
|
29
|
+
* projectConfigPath: ".mytool.yaml",
|
|
30
|
+
* envOverride(c) {
|
|
31
|
+
* if (process.env.HOST) c.host = process.env.HOST;
|
|
32
|
+
* if (process.env.PORT) c.port = Number(process.env.PORT);
|
|
33
|
+
* if (process.env.TOKEN) c.token = process.env.TOKEN;
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Configuration sources for {@link load}.
|
|
40
|
+
*
|
|
41
|
+
* All path fields are optional; an empty or omitted path is silently skipped.
|
|
42
|
+
* {@link Options.envOverride} is called last, after all file layers, so it can
|
|
43
|
+
* apply environment-variable overrides on top of file values.
|
|
44
|
+
*/
|
|
45
|
+
interface Options<T extends object = object> {
|
|
46
|
+
/**
|
|
47
|
+
* Path to the system-wide config file, e.g. `/etc/mytool/config.yaml`.
|
|
48
|
+
* Applied first (lowest priority).
|
|
49
|
+
*/
|
|
50
|
+
systemConfigPath?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Path to the per-user config file, e.g. `~/.config/mytool/config.yaml`.
|
|
53
|
+
* Applied second; overwrites system values for shared keys.
|
|
54
|
+
*/
|
|
55
|
+
userConfigPath?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Path to the project-level config file, e.g. `.mytool.yaml`.
|
|
58
|
+
* Applied third; overwrites system and user values for shared keys.
|
|
59
|
+
*/
|
|
60
|
+
projectConfigPath?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Optional callback invoked after all file layers have been merged.
|
|
63
|
+
* Receives the fully-merged `dst` object so the caller can apply
|
|
64
|
+
* environment-variable overrides last (highest priority).
|
|
65
|
+
*
|
|
66
|
+
* @param cfg - The merged config object (same reference as `dst`).
|
|
67
|
+
*/
|
|
68
|
+
envOverride?: (cfg: T) => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Merges layered YAML configuration into `dst` and returns it.
|
|
72
|
+
*
|
|
73
|
+
* Merge order: `systemConfigPath` → `userConfigPath` → `projectConfigPath` →
|
|
74
|
+
* `envOverride`.
|
|
75
|
+
*
|
|
76
|
+
* - Missing files (ENOENT) are silently skipped.
|
|
77
|
+
* - A file that exists but is not valid YAML causes this function to throw
|
|
78
|
+
* a descriptive error wrapping the parse failure.
|
|
79
|
+
* - `envOverride`, when provided, is called last with the merged `dst`.
|
|
80
|
+
* - Returns `dst` (the same object reference passed in).
|
|
81
|
+
*
|
|
82
|
+
* @param dst - Destination object to merge config into. Must be a non-null
|
|
83
|
+
* object; mutated in place.
|
|
84
|
+
* @param opts - Config sources. All fields are optional.
|
|
85
|
+
* @returns The mutated `dst` object.
|
|
86
|
+
* @throws {Error} When a file exists but cannot be parsed as YAML.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const cfg = { host: "localhost", port: 8080 };
|
|
91
|
+
* load(cfg, { projectConfigPath: ".tool.yaml" });
|
|
92
|
+
* console.log(cfg.host); // value from .tool.yaml, or "localhost" if file missing
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function load<T extends object>(dst: T, opts?: Options<T>): T;
|
|
96
|
+
|
|
97
|
+
type config_Options<T extends object = object> = Options<T>;
|
|
98
|
+
declare const config_load: typeof load;
|
|
99
|
+
declare namespace config {
|
|
100
|
+
export { type config_Options as Options, config_load as load };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { type Options as O, config as c, load as l };
|
package/dist/config.d.ts
CHANGED
|
@@ -1,97 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* Layered YAML configuration loader — TypeScript port of hop.top/kit/config.
|
|
5
|
-
*
|
|
6
|
-
* Merges configuration from up to three file layers in priority order:
|
|
7
|
-
* system → user → project → envOverride
|
|
8
|
-
*
|
|
9
|
-
* Each later layer's values overwrite earlier ones via {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign | Object.assign}.
|
|
10
|
-
* Missing files are silently skipped. A file that exists but contains invalid
|
|
11
|
-
* YAML causes {@link load} to throw.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { load } from "@hop-top/kit/config";
|
|
16
|
-
*
|
|
17
|
-
* interface AppConfig {
|
|
18
|
-
* host: string;
|
|
19
|
-
* port: number;
|
|
20
|
-
* debug: boolean;
|
|
21
|
-
* token: string;
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* const cfg: AppConfig = { host: "localhost", port: 3000, debug: false, token: "" };
|
|
25
|
-
*
|
|
26
|
-
* load(cfg, {
|
|
27
|
-
* systemConfigPath: "/etc/mytool/config.yaml",
|
|
28
|
-
* userConfigPath: `${process.env.HOME}/.config/mytool/config.yaml`,
|
|
29
|
-
* projectConfigPath: ".mytool.yaml",
|
|
30
|
-
* envOverride(c) {
|
|
31
|
-
* if (process.env.HOST) c.host = process.env.HOST;
|
|
32
|
-
* if (process.env.PORT) c.port = Number(process.env.PORT);
|
|
33
|
-
* if (process.env.TOKEN) c.token = process.env.TOKEN;
|
|
34
|
-
* },
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
/**
|
|
39
|
-
* Configuration sources for {@link load}.
|
|
40
|
-
*
|
|
41
|
-
* All path fields are optional; an empty or omitted path is silently skipped.
|
|
42
|
-
* {@link Options.envOverride} is called last, after all file layers, so it can
|
|
43
|
-
* apply environment-variable overrides on top of file values.
|
|
44
|
-
*/
|
|
45
|
-
interface Options<T extends object = object> {
|
|
46
|
-
/**
|
|
47
|
-
* Path to the system-wide config file, e.g. `/etc/mytool/config.yaml`.
|
|
48
|
-
* Applied first (lowest priority).
|
|
49
|
-
*/
|
|
50
|
-
systemConfigPath?: string;
|
|
51
|
-
/**
|
|
52
|
-
* Path to the per-user config file, e.g. `~/.config/mytool/config.yaml`.
|
|
53
|
-
* Applied second; overwrites system values for shared keys.
|
|
54
|
-
*/
|
|
55
|
-
userConfigPath?: string;
|
|
56
|
-
/**
|
|
57
|
-
* Path to the project-level config file, e.g. `.mytool.yaml`.
|
|
58
|
-
* Applied third; overwrites system and user values for shared keys.
|
|
59
|
-
*/
|
|
60
|
-
projectConfigPath?: string;
|
|
61
|
-
/**
|
|
62
|
-
* Optional callback invoked after all file layers have been merged.
|
|
63
|
-
* Receives the fully-merged `dst` object so the caller can apply
|
|
64
|
-
* environment-variable overrides last (highest priority).
|
|
65
|
-
*
|
|
66
|
-
* @param cfg - The merged config object (same reference as `dst`).
|
|
67
|
-
*/
|
|
68
|
-
envOverride?: (cfg: T) => void;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Merges layered YAML configuration into `dst` and returns it.
|
|
72
|
-
*
|
|
73
|
-
* Merge order: `systemConfigPath` → `userConfigPath` → `projectConfigPath` →
|
|
74
|
-
* `envOverride`.
|
|
75
|
-
*
|
|
76
|
-
* - Missing files (ENOENT) are silently skipped.
|
|
77
|
-
* - A file that exists but is not valid YAML causes this function to throw
|
|
78
|
-
* a descriptive error wrapping the parse failure.
|
|
79
|
-
* - `envOverride`, when provided, is called last with the merged `dst`.
|
|
80
|
-
* - Returns `dst` (the same object reference passed in).
|
|
81
|
-
*
|
|
82
|
-
* @param dst - Destination object to merge config into. Must be a non-null
|
|
83
|
-
* object; mutated in place.
|
|
84
|
-
* @param opts - Config sources. All fields are optional.
|
|
85
|
-
* @returns The mutated `dst` object.
|
|
86
|
-
* @throws {Error} When a file exists but cannot be parsed as YAML.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* const cfg = { host: "localhost", port: 8080 };
|
|
91
|
-
* load(cfg, { projectConfigPath: ".tool.yaml" });
|
|
92
|
-
* console.log(cfg.host); // value from .tool.yaml, or "localhost" if file missing
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
declare function load<T extends object>(dst: T, opts?: Options<T>): T;
|
|
96
|
-
|
|
97
|
-
export { type Options, load };
|
|
1
|
+
export { O as Options, l as load } from './config-BUY7_W2n.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module errcorrect
|
|
3
|
+
* @package @hop-top/kit
|
|
4
|
+
*
|
|
5
|
+
* Factor 4 — Corrective Error Model.
|
|
6
|
+
*
|
|
7
|
+
* Structured errors with machine-readable code, human-readable message,
|
|
8
|
+
* likely cause, suggested fix, and alternative commands.
|
|
9
|
+
*/
|
|
10
|
+
interface CorrectedError {
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
cause?: string;
|
|
14
|
+
fix?: string;
|
|
15
|
+
alternatives?: string[];
|
|
16
|
+
retryable?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates an Error instance augmented with CorrectedError fields.
|
|
20
|
+
* Serializes cleanly to JSON (only defined fields).
|
|
21
|
+
*/
|
|
22
|
+
declare function createCorrectedError(opts: CorrectedError): Error & CorrectedError;
|
|
23
|
+
/**
|
|
24
|
+
* Formats a CorrectedError for terminal display.
|
|
25
|
+
*
|
|
26
|
+
* ```
|
|
27
|
+
* ERROR mission not found
|
|
28
|
+
* Cause: no mission matches "bogux"
|
|
29
|
+
* Fix: spaced mission list
|
|
30
|
+
* Try: spaced mission search bogux
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function formatError(err: CorrectedError, opts?: {
|
|
34
|
+
noColor?: boolean;
|
|
35
|
+
}): string;
|
|
36
|
+
|
|
37
|
+
type errcorrect_CorrectedError = CorrectedError;
|
|
38
|
+
declare const errcorrect_createCorrectedError: typeof createCorrectedError;
|
|
39
|
+
declare const errcorrect_formatError: typeof formatError;
|
|
40
|
+
declare namespace errcorrect {
|
|
41
|
+
export { type errcorrect_CorrectedError as CorrectedError, errcorrect_createCorrectedError as createCorrectedError, errcorrect_formatError as formatError };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { type CorrectedError as C, createCorrectedError as c, errcorrect as e, formatError as f };
|