@hop-top/kit 0.5.0-alpha.0 → 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 +98 -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 +250 -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 +61 -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 +65 -25
- 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 +142 -0
- package/src/tui/parity.ts +59 -13
- package/test/output/csv.test.ts +164 -0
- package/test/output/error.test.ts +241 -0
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,27 +42,88 @@ __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
|
|
|
65
|
+
// ../../contracts/parity/parity.json
|
|
66
|
+
var parity_default = {
|
|
67
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
68
|
+
$id: "https://hop.top/kit/go/console/tui/parity.json",
|
|
69
|
+
description: "Cross-language TUI parity constants. All language implementations MUST load values from here.",
|
|
70
|
+
status: {
|
|
71
|
+
description: "Prefix symbols for status lines. Mirrors Go's InfoType constants in tui/status.go.",
|
|
72
|
+
symbols: {
|
|
73
|
+
info: "\u2139",
|
|
74
|
+
success: "\u2713",
|
|
75
|
+
error: "\u25CF",
|
|
76
|
+
warn: "\u25B2"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
spinner: {
|
|
80
|
+
description: "Braille dot spinner frames and timing.",
|
|
81
|
+
frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"],
|
|
82
|
+
interval_ms: 80
|
|
83
|
+
},
|
|
84
|
+
anim: {
|
|
85
|
+
description: "Gradient character-scramble animation constants.",
|
|
86
|
+
runes: "0123456789abcdefABCDEF~!@#$%^&*()+=_",
|
|
87
|
+
interval_ms: 100,
|
|
88
|
+
default_width: 10
|
|
89
|
+
},
|
|
90
|
+
help: {
|
|
91
|
+
description: "Root --help layout contract. Fang is canonical; TS and Python mirror it.",
|
|
92
|
+
section_order: ["commands", "flags"],
|
|
93
|
+
sections: {
|
|
94
|
+
usage: { title: "USAGE" },
|
|
95
|
+
commands: { title: "COMMANDS" },
|
|
96
|
+
flags: { title: "FLAGS" },
|
|
97
|
+
"global flags": { title: "GLOBAL FLAGS" },
|
|
98
|
+
arguments: { title: "ARGUMENTS" },
|
|
99
|
+
aliases: { title: "ALIASES" },
|
|
100
|
+
examples: { title: "EXAMPLES" },
|
|
101
|
+
streams: { title: "STREAMS" }
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
verbosity: {
|
|
105
|
+
description: "Stackable -V flag maps count to log level. --quiet overrides to warn.",
|
|
106
|
+
flag: "-V",
|
|
107
|
+
levels: {
|
|
108
|
+
"0": "info",
|
|
109
|
+
"1": "debug",
|
|
110
|
+
"2": "trace"
|
|
111
|
+
},
|
|
112
|
+
quiet_override: "warn"
|
|
113
|
+
},
|
|
114
|
+
streams: {
|
|
115
|
+
description: "Per-command named output streams toggled via --stream flag.",
|
|
116
|
+
flag: "--stream",
|
|
117
|
+
label_format: "[{name}]",
|
|
118
|
+
output: "stderr"
|
|
119
|
+
},
|
|
120
|
+
extends: [
|
|
121
|
+
"scope-defaults.json"
|
|
122
|
+
]
|
|
123
|
+
};
|
|
124
|
+
|
|
54
125
|
// src/tui/parity.ts
|
|
55
|
-
var
|
|
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"));
|
|
126
|
+
var parity = parity_default;
|
|
64
127
|
|
|
65
128
|
// src/output/registry.ts
|
|
66
129
|
var Registry = class {
|
|
@@ -180,6 +243,109 @@ function collectCols(value, prev) {
|
|
|
180
243
|
return [...prev, ...value.split(",")];
|
|
181
244
|
}
|
|
182
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
|
+
|
|
183
349
|
// src/output/formatters/json.ts
|
|
184
350
|
var jsonFormatter = {
|
|
185
351
|
key: "json",
|
|
@@ -189,24 +355,10 @@ var jsonFormatter = {
|
|
|
189
355
|
],
|
|
190
356
|
render(out, data, opts, cols) {
|
|
191
357
|
const indent = opts["indent"] ?? 2;
|
|
192
|
-
const value =
|
|
358
|
+
const value = projectForEncoding(data, cols);
|
|
193
359
|
out.write(JSON.stringify(value, null, indent) + "\n");
|
|
194
360
|
}
|
|
195
361
|
};
|
|
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
362
|
|
|
211
363
|
// src/output/formatters/yaml.ts
|
|
212
364
|
var yaml = __toESM(require("js-yaml"));
|
|
@@ -223,24 +375,10 @@ var yamlFormatter = {
|
|
|
223
375
|
],
|
|
224
376
|
render(out, data, opts, cols) {
|
|
225
377
|
const flowLevel = opts["flow-level"] ?? -1;
|
|
226
|
-
const value =
|
|
378
|
+
const value = projectForEncoding(data, cols);
|
|
227
379
|
out.write(yaml.dump(value, { flowLevel }));
|
|
228
380
|
}
|
|
229
381
|
};
|
|
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
382
|
|
|
245
383
|
// src/output/formatters/table.ts
|
|
246
384
|
var tableFormatter = {
|
|
@@ -250,8 +388,7 @@ var tableFormatter = {
|
|
|
250
388
|
render(out, data, _opts, cols) {
|
|
251
389
|
const rows = normalise(data);
|
|
252
390
|
if (rows.length === 0) return;
|
|
253
|
-
const
|
|
254
|
-
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
391
|
+
const headers = cols.length > 0 ? cols : deriveHeaders(rows);
|
|
255
392
|
if (headers.length === 0) return;
|
|
256
393
|
const cells = rows.map(
|
|
257
394
|
(row) => headers.map((h) => String(row[h] ?? ""))
|
|
@@ -273,7 +410,6 @@ function normalise(v) {
|
|
|
273
410
|
}
|
|
274
411
|
|
|
275
412
|
// src/output/formatters/csv.ts
|
|
276
|
-
var import_sync = require("csv-stringify/sync");
|
|
277
413
|
var csvFormatter = {
|
|
278
414
|
key: "csv",
|
|
279
415
|
extensions: [".csv"],
|
|
@@ -308,17 +444,26 @@ var csvFormatter = {
|
|
|
308
444
|
}
|
|
309
445
|
const records = rows.map((r) => headers.map((h) => stringify_cell(r[h])));
|
|
310
446
|
const csvRows = noHeader ? records : [headers, ...records];
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// row layout uniform with csv format and to make `no-header` toggle
|
|
317
|
-
// a single decision point.
|
|
318
|
-
});
|
|
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
|
+
}
|
|
319
452
|
out.write(text);
|
|
320
453
|
}
|
|
321
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
|
+
}
|
|
322
467
|
function normalise2(v) {
|
|
323
468
|
if (Array.isArray(v)) return v;
|
|
324
469
|
return [v];
|
|
@@ -353,8 +498,7 @@ var textFormatter = {
|
|
|
353
498
|
render(out, data, opts, cols) {
|
|
354
499
|
const rows = normalise3(data);
|
|
355
500
|
if (rows.length === 0) return;
|
|
356
|
-
const
|
|
357
|
-
const headers = cols.length > 0 ? cols.filter((c) => allHeaders.includes(c)) : allHeaders;
|
|
501
|
+
const headers = cols.length > 0 ? cols : deriveHeaders(rows);
|
|
358
502
|
if (headers.length === 0) return;
|
|
359
503
|
const style = opts["style"] || STYLE_KV;
|
|
360
504
|
const sep = opts["separator"] || "=";
|
|
@@ -482,6 +626,13 @@ function registerVersionHints(hints, binary, updateAvail) {
|
|
|
482
626
|
|
|
483
627
|
// src/cli.ts
|
|
484
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
|
+
}
|
|
485
636
|
function verboseCount(cmd) {
|
|
486
637
|
let c = cmd;
|
|
487
638
|
while (c) {
|
|
@@ -492,13 +643,24 @@ function verboseCount(cmd) {
|
|
|
492
643
|
return 0;
|
|
493
644
|
}
|
|
494
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
|
+
}
|
|
495
657
|
function registerStream(cmd, name, description) {
|
|
496
658
|
let defs = streamDefsMap.get(cmd);
|
|
497
659
|
if (!defs) {
|
|
498
660
|
defs = [];
|
|
499
661
|
streamDefsMap.set(cmd, defs);
|
|
500
662
|
cmd.option(
|
|
501
|
-
|
|
663
|
+
`--${streamFlagName(parity)} <names>`,
|
|
502
664
|
"Enable diagnostic streams (comma-separated)"
|
|
503
665
|
);
|
|
504
666
|
}
|
|
@@ -510,15 +672,21 @@ function getStreamDefs(cmd) {
|
|
|
510
672
|
var noopWriter = { write(_s) {
|
|
511
673
|
return true;
|
|
512
674
|
} };
|
|
675
|
+
function optionKey(flagName) {
|
|
676
|
+
return flagName.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
677
|
+
}
|
|
513
678
|
function channel(cmd, name) {
|
|
514
679
|
const opts = cmd.opts();
|
|
515
|
-
const
|
|
680
|
+
const raw = opts[optionKey(streamFlagName(parity))];
|
|
681
|
+
const enabled = typeof raw === "string" ? raw.split(",").map((s) => s.trim()).includes(name) : false;
|
|
516
682
|
if (!enabled) return noopWriter;
|
|
683
|
+
const prefix = streamLabel(parity, name);
|
|
684
|
+
const w = streamOutput(parity);
|
|
517
685
|
return {
|
|
518
686
|
write(s) {
|
|
519
687
|
const lines = s.split("\n");
|
|
520
688
|
for (const line of lines) {
|
|
521
|
-
if (line)
|
|
689
|
+
if (line) w.write(`${prefix}${line}
|
|
522
690
|
`);
|
|
523
691
|
}
|
|
524
692
|
return true;
|
|
@@ -798,8 +966,17 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
798
966
|
if (!cfg.disable?.hints) {
|
|
799
967
|
program.option("--no-hints", "Suppress next-step hints after command output", false);
|
|
800
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
|
+
}
|
|
801
978
|
program.option(
|
|
802
|
-
|
|
979
|
+
verbosityFlagSpec(parity),
|
|
803
980
|
"Increase verbosity",
|
|
804
981
|
(_, prev) => prev + 1,
|
|
805
982
|
0
|
|
@@ -866,8 +1043,10 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
866
1043
|
// Annotate the CommonJS export names for ESM import in node:
|
|
867
1044
|
0 && (module.exports = {
|
|
868
1045
|
Dark,
|
|
1046
|
+
ErrOffline,
|
|
869
1047
|
HintSet,
|
|
870
1048
|
Neon,
|
|
1049
|
+
OfflineError,
|
|
871
1050
|
active,
|
|
872
1051
|
applyHelpTheme,
|
|
873
1052
|
buildTheme,
|
|
@@ -875,11 +1054,20 @@ ${cfg.help.disclaimer}` : cfg.description;
|
|
|
875
1054
|
createCLI,
|
|
876
1055
|
getCommandGroup,
|
|
877
1056
|
getStreamDefs,
|
|
1057
|
+
guardFetch,
|
|
878
1058
|
hintsEnabled,
|
|
1059
|
+
isOffline,
|
|
1060
|
+
isOfflineError,
|
|
879
1061
|
registerStream,
|
|
880
1062
|
registerUpgradeHints,
|
|
881
1063
|
registerVersionHints,
|
|
882
1064
|
renderHints,
|
|
883
1065
|
setCommandGroup,
|
|
884
|
-
|
|
1066
|
+
streamFlagName,
|
|
1067
|
+
streamLabel,
|
|
1068
|
+
streamOutput,
|
|
1069
|
+
verboseCount,
|
|
1070
|
+
verbosityFlagSpec,
|
|
1071
|
+
verbosityShorthand,
|
|
1072
|
+
withOffline
|
|
885
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';
|