@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.2
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 +87 -0
- package/README.md +237 -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-DgOEOsPB.d.ts +450 -0
- package/dist/cli.d.ts +5 -309
- package/dist/cli.js +190 -62
- 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/id/index.d.ts +2 -83
- package/dist/index--C7Mtsmm.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 +26 -0
- package/dist/index.js +5863 -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-VFFLqor9.d.ts +521 -0
- package/dist/output.d.ts +2 -213
- package/dist/output.js +554 -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/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 +4 -298
- package/dist/tui/index.js +1 -9
- 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 +21 -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 +36 -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 +293 -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 +39 -3
- 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 +241 -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,14 +117,6 @@ 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
121
|
"scope-defaults.json"
|
|
119
122
|
]
|
|
@@ -240,6 +243,109 @@ function collectCols(value, prev) {
|
|
|
240
243
|
return [...prev, ...value.split(",")];
|
|
241
244
|
}
|
|
242
245
|
|
|
246
|
+
// src/netpolicy.ts
|
|
247
|
+
var import_node_async_hooks = require("async_hooks");
|
|
248
|
+
var ErrOffline = "OfflineError";
|
|
249
|
+
var OfflineError = class extends Error {
|
|
250
|
+
constructor(method, url) {
|
|
251
|
+
super(`${method} ${url}: network disabled by --offline`);
|
|
252
|
+
this.name = ErrOffline;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
function isOfflineError(err) {
|
|
256
|
+
return err instanceof Error && err.name === ErrOffline;
|
|
257
|
+
}
|
|
258
|
+
var store = new import_node_async_hooks.AsyncLocalStorage();
|
|
259
|
+
var processOffline = false;
|
|
260
|
+
function withOffline(offline, fn) {
|
|
261
|
+
if (!offline) return fn();
|
|
262
|
+
return store.run(true, fn);
|
|
263
|
+
}
|
|
264
|
+
function setProcessOffline(offline) {
|
|
265
|
+
processOffline = offline;
|
|
266
|
+
}
|
|
267
|
+
function isOffline() {
|
|
268
|
+
return processOffline || store.getStore() === true;
|
|
269
|
+
}
|
|
270
|
+
function isLoopback(hostname) {
|
|
271
|
+
const h = hostname.replace(/^\[|\]$/g, "");
|
|
272
|
+
if (h === "localhost") return true;
|
|
273
|
+
if (h === "::1") return true;
|
|
274
|
+
const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(h);
|
|
275
|
+
if (v4) {
|
|
276
|
+
return v4.slice(1).every((o) => Number(o) <= 255) && Number(v4[1]) === 127;
|
|
277
|
+
}
|
|
278
|
+
const mapped = /^::ffff:(.+)$/i.exec(h);
|
|
279
|
+
if (mapped) {
|
|
280
|
+
const inner = mapped[1] ?? "";
|
|
281
|
+
if (/^7f00:1$/i.test(inner)) return true;
|
|
282
|
+
return isLoopback(inner);
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
function target(input, init) {
|
|
287
|
+
if (typeof Request !== "undefined" && input instanceof Request) {
|
|
288
|
+
return { method: init?.method ?? input.method, url: input.url };
|
|
289
|
+
}
|
|
290
|
+
return { method: init?.method ?? "GET", url: String(input) };
|
|
291
|
+
}
|
|
292
|
+
var guarded = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.guarded");
|
|
293
|
+
var unguardedBase = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.unguardedBase");
|
|
294
|
+
function guardFetch(base) {
|
|
295
|
+
if (base[guarded]) return base;
|
|
296
|
+
const wrapper = async (input, init) => {
|
|
297
|
+
if (isOffline()) {
|
|
298
|
+
const { method, url } = target(input, init);
|
|
299
|
+
let loopback = false;
|
|
300
|
+
try {
|
|
301
|
+
loopback = isLoopback(new URL(url).hostname);
|
|
302
|
+
} catch {
|
|
303
|
+
loopback = false;
|
|
304
|
+
}
|
|
305
|
+
if (!loopback) throw new OfflineError(method, url);
|
|
306
|
+
}
|
|
307
|
+
return base(input, init);
|
|
308
|
+
};
|
|
309
|
+
wrapper[guarded] = true;
|
|
310
|
+
wrapper[unguardedBase] = base;
|
|
311
|
+
return wrapper;
|
|
312
|
+
}
|
|
313
|
+
function install() {
|
|
314
|
+
globalThis.fetch = guardFetch(globalThis.fetch);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/output/projection.ts
|
|
318
|
+
function deriveHeaders(rows, columns) {
|
|
319
|
+
if (columns && columns.length > 0) {
|
|
320
|
+
return columns.map((c) => c.header);
|
|
321
|
+
}
|
|
322
|
+
if (rows.length === 0) return [];
|
|
323
|
+
const first = rows[0];
|
|
324
|
+
if (first === null || typeof first !== "object") return [];
|
|
325
|
+
return Object.keys(first);
|
|
326
|
+
}
|
|
327
|
+
function projectRows(rows, cols) {
|
|
328
|
+
return rows.map((row) => {
|
|
329
|
+
const r = row ?? {};
|
|
330
|
+
if (cols.length === 0) return r;
|
|
331
|
+
const out = {};
|
|
332
|
+
for (const name of cols) out[name] = r[name];
|
|
333
|
+
return out;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/output/formatters/project.ts
|
|
338
|
+
function projectForEncoding(data, cols) {
|
|
339
|
+
if (cols.length === 0) return data;
|
|
340
|
+
if (Array.isArray(data)) {
|
|
341
|
+
const rows = data;
|
|
342
|
+
if (rows.some((r) => r === null || typeof r !== "object")) return data;
|
|
343
|
+
return projectRows(rows, cols);
|
|
344
|
+
}
|
|
345
|
+
if (data === null || typeof data !== "object") return data;
|
|
346
|
+
return projectRows([data], cols)[0];
|
|
347
|
+
}
|
|
348
|
+
|
|
243
349
|
// src/output/formatters/json.ts
|
|
244
350
|
var jsonFormatter = {
|
|
245
351
|
key: "json",
|
|
@@ -249,24 +355,10 @@ var jsonFormatter = {
|
|
|
249
355
|
],
|
|
250
356
|
render(out, data, opts, cols) {
|
|
251
357
|
const indent = opts["indent"] ?? 2;
|
|
252
|
-
const value =
|
|
358
|
+
const value = projectForEncoding(data, cols);
|
|
253
359
|
out.write(JSON.stringify(value, null, indent) + "\n");
|
|
254
360
|
}
|
|
255
361
|
};
|
|
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
362
|
|
|
271
363
|
// src/output/formatters/yaml.ts
|
|
272
364
|
var yaml = __toESM(require("js-yaml"));
|
|
@@ -283,24 +375,10 @@ var yamlFormatter = {
|
|
|
283
375
|
],
|
|
284
376
|
render(out, data, opts, cols) {
|
|
285
377
|
const flowLevel = opts["flow-level"] ?? -1;
|
|
286
|
-
const value =
|
|
378
|
+
const value = projectForEncoding(data, cols);
|
|
287
379
|
out.write(yaml.dump(value, { flowLevel }));
|
|
288
380
|
}
|
|
289
381
|
};
|
|
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
382
|
|
|
305
383
|
// src/output/formatters/table.ts
|
|
306
384
|
var tableFormatter = {
|
|
@@ -310,8 +388,7 @@ var tableFormatter = {
|
|
|
310
388
|
render(out, data, _opts, cols) {
|
|
311
389
|
const rows = normalise(data);
|
|
312
390
|
if (rows.length === 0) return;
|
|
313
|
-
const
|
|
314
|
-
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
391
|
+
const headers = cols.length > 0 ? cols : deriveHeaders(rows);
|
|
315
392
|
if (headers.length === 0) return;
|
|
316
393
|
const cells = rows.map(
|
|
317
394
|
(row) => headers.map((h) => String(row[h] ?? ""))
|
|
@@ -333,7 +410,6 @@ function normalise(v) {
|
|
|
333
410
|
}
|
|
334
411
|
|
|
335
412
|
// src/output/formatters/csv.ts
|
|
336
|
-
var import_sync = require("csv-stringify/sync");
|
|
337
413
|
var csvFormatter = {
|
|
338
414
|
key: "csv",
|
|
339
415
|
extensions: [".csv"],
|
|
@@ -368,17 +444,26 @@ var csvFormatter = {
|
|
|
368
444
|
}
|
|
369
445
|
const records = rows.map((r) => headers.map((h) => stringify_cell(r[h])));
|
|
370
446
|
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
|
-
});
|
|
447
|
+
const eol = crlf ? "\r\n" : "\n";
|
|
448
|
+
let text = "";
|
|
449
|
+
for (const cells of csvRows) {
|
|
450
|
+
text += cells.map((c) => encodeField(c, delimiter, quoteAll)).join(delimiter) + eol;
|
|
451
|
+
}
|
|
379
452
|
out.write(text);
|
|
380
453
|
}
|
|
381
454
|
};
|
|
455
|
+
function needsQuotes(field, delim) {
|
|
456
|
+
if (field === "") return false;
|
|
457
|
+
if (field === "\\.") return true;
|
|
458
|
+
if (field.includes(delim) || field.includes('"') || field.includes("\n") || field.includes("\r")) {
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
return /^\s/u.test(field);
|
|
462
|
+
}
|
|
463
|
+
function encodeField(field, delim, quoteAll) {
|
|
464
|
+
if (!quoteAll && !needsQuotes(field, delim)) return field;
|
|
465
|
+
return `"${field.replace(/"/g, '""')}"`;
|
|
466
|
+
}
|
|
382
467
|
function normalise2(v) {
|
|
383
468
|
if (Array.isArray(v)) return v;
|
|
384
469
|
return [v];
|
|
@@ -413,8 +498,7 @@ var textFormatter = {
|
|
|
413
498
|
render(out, data, opts, cols) {
|
|
414
499
|
const rows = normalise3(data);
|
|
415
500
|
if (rows.length === 0) return;
|
|
416
|
-
const
|
|
417
|
-
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
501
|
+
const headers = cols.length > 0 ? cols : deriveHeaders(rows);
|
|
418
502
|
if (headers.length === 0) return;
|
|
419
503
|
const style = opts["style"] || STYLE_KV;
|
|
420
504
|
const sep = opts["separator"] || "=";
|
|
@@ -542,6 +626,13 @@ function registerVersionHints(hints, binary, updateAvail) {
|
|
|
542
626
|
|
|
543
627
|
// src/cli.ts
|
|
544
628
|
var verboseCountMap = /* @__PURE__ */ new WeakMap();
|
|
629
|
+
function verbosityShorthand(d) {
|
|
630
|
+
const s = (d.verbosity?.flag ?? "").replace(/^-+/, "");
|
|
631
|
+
return s.length === 1 ? s : "V";
|
|
632
|
+
}
|
|
633
|
+
function verbosityFlagSpec(d) {
|
|
634
|
+
return `-${verbosityShorthand(d)}, --verbose`;
|
|
635
|
+
}
|
|
545
636
|
function verboseCount(cmd) {
|
|
546
637
|
let c = cmd;
|
|
547
638
|
while (c) {
|
|
@@ -552,13 +643,24 @@ function verboseCount(cmd) {
|
|
|
552
643
|
return 0;
|
|
553
644
|
}
|
|
554
645
|
var streamDefsMap = /* @__PURE__ */ new WeakMap();
|
|
646
|
+
function streamFlagName(d) {
|
|
647
|
+
const name = (d.streams?.flag ?? "").replace(/^-+/, "");
|
|
648
|
+
return name === "" ? "stream" : name;
|
|
649
|
+
}
|
|
650
|
+
function streamLabel(d, name) {
|
|
651
|
+
const format = d.streams?.label_format || "[{name}]";
|
|
652
|
+
return format.split("{name}").join(name) + " ";
|
|
653
|
+
}
|
|
654
|
+
function streamOutput(d) {
|
|
655
|
+
return d.streams?.output === "stdout" ? process.stdout : process.stderr;
|
|
656
|
+
}
|
|
555
657
|
function registerStream(cmd, name, description) {
|
|
556
658
|
let defs = streamDefsMap.get(cmd);
|
|
557
659
|
if (!defs) {
|
|
558
660
|
defs = [];
|
|
559
661
|
streamDefsMap.set(cmd, defs);
|
|
560
662
|
cmd.option(
|
|
561
|
-
|
|
663
|
+
`--${streamFlagName(parity)} <names>`,
|
|
562
664
|
"Enable diagnostic streams (comma-separated)"
|
|
563
665
|
);
|
|
564
666
|
}
|
|
@@ -570,15 +672,21 @@ function getStreamDefs(cmd) {
|
|
|
570
672
|
var noopWriter = { write(_s) {
|
|
571
673
|
return true;
|
|
572
674
|
} };
|
|
675
|
+
function optionKey(flagName) {
|
|
676
|
+
return flagName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
677
|
+
}
|
|
573
678
|
function channel(cmd, name) {
|
|
574
679
|
const opts = cmd.opts();
|
|
575
|
-
const
|
|
680
|
+
const raw = opts[optionKey(streamFlagName(parity))];
|
|
681
|
+
const enabled = typeof raw === "string" ? raw.split(",").map((s) => s.trim()).includes(name) : false;
|
|
576
682
|
if (!enabled) return noopWriter;
|
|
683
|
+
const prefix = streamLabel(parity, name);
|
|
684
|
+
const w = streamOutput(parity);
|
|
577
685
|
return {
|
|
578
686
|
write(s) {
|
|
579
687
|
const lines = s.split("\n");
|
|
580
688
|
for (const line of lines) {
|
|
581
|
-
if (line)
|
|
689
|
+
if (line) w.write(`${prefix}${line}
|
|
582
690
|
`);
|
|
583
691
|
}
|
|
584
692
|
return true;
|
|
@@ -858,8 +966,17 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
858
966
|
if (!cfg.disable?.hints) {
|
|
859
967
|
program.option("--no-hints", "Suppress next-step hints after command output", false);
|
|
860
968
|
}
|
|
969
|
+
if (!cfg.disable?.offline) {
|
|
970
|
+
program.option("--offline", "Disable network access", false);
|
|
971
|
+
install();
|
|
972
|
+
const stamp = (thisCmd) => {
|
|
973
|
+
setProcessOffline(thisCmd.opts()["offline"] === true);
|
|
974
|
+
};
|
|
975
|
+
program.hook("preSubcommand", (thisCmd) => stamp(thisCmd));
|
|
976
|
+
program.hook("preAction", (thisCmd) => stamp(thisCmd));
|
|
977
|
+
}
|
|
861
978
|
program.option(
|
|
862
|
-
|
|
979
|
+
verbosityFlagSpec(parity),
|
|
863
980
|
"Increase verbosity",
|
|
864
981
|
(_, prev) => prev + 1,
|
|
865
982
|
0
|
|
@@ -926,8 +1043,10 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
926
1043
|
// Annotate the CommonJS export names for ESM import in node:
|
|
927
1044
|
0 && (module.exports = {
|
|
928
1045
|
Dark,
|
|
1046
|
+
ErrOffline,
|
|
929
1047
|
HintSet,
|
|
930
1048
|
Neon,
|
|
1049
|
+
OfflineError,
|
|
931
1050
|
active,
|
|
932
1051
|
applyHelpTheme,
|
|
933
1052
|
buildTheme,
|
|
@@ -935,11 +1054,20 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
935
1054
|
createCLI,
|
|
936
1055
|
getCommandGroup,
|
|
937
1056
|
getStreamDefs,
|
|
1057
|
+
guardFetch,
|
|
938
1058
|
hintsEnabled,
|
|
1059
|
+
isOffline,
|
|
1060
|
+
isOfflineError,
|
|
939
1061
|
registerStream,
|
|
940
1062
|
registerUpgradeHints,
|
|
941
1063
|
registerVersionHints,
|
|
942
1064
|
renderHints,
|
|
943
1065
|
setCommandGroup,
|
|
944
|
-
|
|
1066
|
+
streamFlagName,
|
|
1067
|
+
streamLabel,
|
|
1068
|
+
streamOutput,
|
|
1069
|
+
verboseCount,
|
|
1070
|
+
verbosityFlagSpec,
|
|
1071
|
+
verbosityShorthand,
|
|
1072
|
+
withOffline
|
|
945
1073
|
});
|
|
@@ -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 };
|