@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.
Files changed (107) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +333 -9
  3. package/dist/aim-CTp-kJW2.d.ts +139 -0
  4. package/dist/aim.d.ts +1 -116
  5. package/dist/alias-dhhr08Ei.d.ts +88 -0
  6. package/dist/alias.d.ts +2 -73
  7. package/dist/api-miiso81x.d.ts +77 -0
  8. package/dist/api.d.ts +1 -62
  9. package/dist/auth-2-jfgiHn.d.ts +34 -0
  10. package/dist/auth.d.ts +1 -26
  11. package/dist/cli-DLygZLi9.d.ts +450 -0
  12. package/dist/cli.d.ts +6 -309
  13. package/dist/cli.js +192 -63
  14. package/dist/config-BUY7_W2n.d.ts +103 -0
  15. package/dist/config.d.ts +1 -97
  16. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  17. package/dist/errcorrect.d.ts +1 -37
  18. package/dist/error-DISJKeDu.d.ts +144 -0
  19. package/dist/id/index.d.ts +2 -83
  20. package/dist/index-Bc5c7Ty5.d.ts +328 -0
  21. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  22. package/dist/index-MLrRDvEG.d.ts +1073 -0
  23. package/dist/index-QSffbLnj.d.ts +94 -0
  24. package/dist/index.d.ts +28 -0
  25. package/dist/index.js +6794 -0
  26. package/dist/llm-B5XUWH8T.d.ts +231 -0
  27. package/dist/llm.d.ts +1 -188
  28. package/dist/mcp/index.d.ts +2 -0
  29. package/dist/mcp/index.js +1453 -0
  30. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  31. package/dist/netpolicy.d.ts +1 -0
  32. package/dist/netpolicy.js +118 -0
  33. package/dist/output-4aXs91GY.d.ts +396 -0
  34. package/dist/output.d.ts +3 -213
  35. package/dist/output.js +567 -43
  36. package/dist/progress-CAzyxeWl.d.ts +38 -0
  37. package/dist/progress.d.ts +1 -30
  38. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  39. package/dist/provenance.d.ts +1 -24
  40. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  41. package/dist/routellm.d.ts +2 -64
  42. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  43. package/dist/rpc.d.ts +2 -25
  44. package/dist/safety-CUaYEjZc.d.ts +30 -0
  45. package/dist/safety.d.ts +1 -24
  46. package/dist/scope-BrhYB4ij.d.ts +141 -0
  47. package/dist/scope.d.ts +1 -121
  48. package/dist/serve-DE-jscpb.d.ts +646 -0
  49. package/dist/serve.d.ts +3 -0
  50. package/dist/serve.js +1019 -0
  51. package/dist/stream-CrjeCp0M.d.ts +44 -0
  52. package/dist/stream.d.ts +1 -35
  53. package/dist/telemetry/index.d.ts +1 -315
  54. package/dist/telemetry/index.js +12 -1
  55. package/dist/tui/index.d.ts +5 -298
  56. package/dist/tui/index.js +3 -10
  57. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  58. package/dist/upgrade.d.ts +1 -95
  59. package/dist/xdg-DB7Shoib.d.ts +179 -0
  60. package/dist/xdg.d.ts +1 -169
  61. package/package.json +26 -3
  62. package/src/cli.offline.test.ts +93 -0
  63. package/src/cli.parity.test.ts +192 -0
  64. package/src/cli.ts +112 -12
  65. package/src/index.test.ts +58 -0
  66. package/src/index.ts +37 -0
  67. package/src/log.parity.test.ts +105 -0
  68. package/src/log.ts +64 -13
  69. package/src/mcp/bridge.test.ts +150 -0
  70. package/src/mcp/bridge.ts +246 -0
  71. package/src/mcp/conformance.test.ts +336 -0
  72. package/src/mcp/dispatch.ts +313 -0
  73. package/src/mcp/index.ts +138 -0
  74. package/src/mcp/legacy.ts +314 -0
  75. package/src/mcp/mcp.test.ts +697 -0
  76. package/src/mcp/modern-confirm.test.ts +520 -0
  77. package/src/mcp/modern-confirm.ts +452 -0
  78. package/src/mcp/modern.ts +723 -0
  79. package/src/mcp/tasks.ts +82 -0
  80. package/src/mcp/testtree.ts +250 -0
  81. package/src/mcp/types.ts +504 -0
  82. package/src/netpolicy.test.ts +202 -0
  83. package/src/netpolicy.ts +231 -0
  84. package/src/output/dispatch.ts +10 -2
  85. package/src/output/error.ts +316 -0
  86. package/src/output/formatter.ts +29 -5
  87. package/src/output/formatters/csv.ts +48 -12
  88. package/src/output/formatters/json.ts +4 -25
  89. package/src/output/formatters/project.ts +34 -0
  90. package/src/output/formatters/table.ts +8 -6
  91. package/src/output/formatters/text.ts +7 -3
  92. package/src/output/formatters/yaml.ts +5 -22
  93. package/src/output/projection.test.ts +298 -0
  94. package/src/output/projection.ts +33 -59
  95. package/src/output/template.ts +11 -21
  96. package/src/output.surface.test.ts +41 -0
  97. package/src/output.ts +41 -3
  98. package/src/serve.test.ts +1257 -0
  99. package/src/serve.ts +1665 -0
  100. package/src/telemetry/client.test.ts +31 -0
  101. package/src/telemetry/client.ts +7 -1
  102. package/src/telemetry/offline.test.ts +64 -0
  103. package/src/tui/parity.test.ts +120 -31
  104. package/src/tui/parity.ts +58 -7
  105. package/test/output/csv.test.ts +164 -0
  106. package/test/output/error.test.ts +246 -0
  107. package/src/tui/parity.json +0 -74
@@ -0,0 +1,138 @@
1
+ /**
2
+ * @module netpolicy
3
+ * @package @hop-top/kit
4
+ *
5
+ * Owns the process-wide network policy marker and the `fetch` wrapper that
6
+ * enforces it.
7
+ *
8
+ * The `--offline` global (cli-parity-guide, "Global Flags") promises that
9
+ * network access is disabled. Marking a scope alone cannot keep that
10
+ * promise: it is advisory, so any caller that forgets to consult it still
11
+ * reaches the wire. {@link guardFetch} closes that gap by refusing the
12
+ * request inside the fetch implementation, beneath every caller, where no
13
+ * naive leaf can route around it.
14
+ *
15
+ * The marker lives in its own module rather than in `cli` so library code
16
+ * can enforce the policy without importing the CLI factory back.
17
+ *
18
+ * Loopback is deliberately exempt. `--offline` means "do not talk to the
19
+ * network", not "do not talk to myself": a local `kit serve` peer, a dev
20
+ * backend on 127.0.0.1 and unix sockets stay reachable so offline
21
+ * workflows remain usable.
22
+ *
23
+ * ## Scope
24
+ *
25
+ * {@link install} wraps `globalThis.fetch`, so it covers HTTP and HTTPS
26
+ * through the fetch API — which is every network client in kit today
27
+ * (`api`, `aim`, `upgrade`, `routellm`, `triton`, `telemetry`, and the
28
+ * ConnectRPC transport, which resolves `globalThis.fetch` lazily per
29
+ * call). undici's `setGlobalDispatcher` is not used: undici is not a
30
+ * dependency of this package, so the dispatcher hook is unavailable
31
+ * without adding one, and it would not cover callers that inject their
32
+ * own `fetch` anyway.
33
+ *
34
+ * It does NOT cover code that opens a socket directly: `node:net`,
35
+ * `node:http`/`node:https` (`http.request`), `node:dgram`, database
36
+ * drivers, or raw TLS. Nor does it cover a caller that captured a
37
+ * reference to the unguarded `fetch` before {@link install} ran, or one
38
+ * that injects its own transport (`APIClient({ fetch })`). For those,
39
+ * `--offline` remains advisory and the call site must consult
40
+ * {@link isOffline} itself, or wrap its own transport with
41
+ * {@link guardFetch}. Closing that gap needs a guarded dialer threaded
42
+ * through each such client; it is deliberately not attempted here.
43
+ */
44
+ /**
45
+ * Name carried by the error {@link guardFetch} rejects with when a request
46
+ * is attempted in an offline-marked scope. JavaScript has no `errors.Is`,
47
+ * so the name is the matchable analogue of Go's sentinel `ErrOffline`;
48
+ * prefer {@link isOfflineError} over comparing it by hand.
49
+ */
50
+ declare const ErrOffline = "OfflineError";
51
+ /** Error rejected by {@link guardFetch}. Matchable via {@link isOfflineError}. */
52
+ declare class OfflineError extends Error {
53
+ readonly name = "OfflineError";
54
+ constructor(method: string, url: string);
55
+ }
56
+ /**
57
+ * Report whether err is the refusal raised by the offline guard. Matches on
58
+ * the error name rather than `instanceof` so a copy of this module loaded
59
+ * through a different resolution path (bundled adopter, dual dist/src
60
+ * graph) still matches — the JS analogue of `errors.Is`.
61
+ */
62
+ declare function isOfflineError(err: unknown): boolean;
63
+ /**
64
+ * Run fn in a scope marked offline. Passing false runs fn unchanged so an
65
+ * unmarked scope stays clean, mirroring Go's `WithOffline(ctx, false)`.
66
+ */
67
+ declare function withOffline<T>(offline: boolean, fn: () => T): T;
68
+ /**
69
+ * Mark the whole process offline. The CLI uses this rather than
70
+ * {@link withOffline} because commander dispatches an action handler
71
+ * without giving the framework a scope to wrap around it, and because a
72
+ * detached callback (a timer, an unawaited promise) must stay refused.
73
+ * Mirrors the process-global reach of Go's `netpolicy.Install`.
74
+ */
75
+ declare function setProcessOffline(offline: boolean): void;
76
+ /**
77
+ * Report whether the caller is running under the offline marker — either
78
+ * an enclosing {@link withOffline} scope or a process-wide
79
+ * {@link setProcessOffline}.
80
+ */
81
+ declare function isOffline(): boolean;
82
+ /**
83
+ * Wrap base so requests made in an offline-marked scope reject with an
84
+ * {@link OfflineError} instead of reaching the network. Wrapping is
85
+ * idempotent: guarding an already guarded fetch returns it unchanged.
86
+ *
87
+ * A URL that does not parse is refused when offline: an unparseable target
88
+ * cannot be shown to be loopback, and the policy fails closed.
89
+ */
90
+ declare function guardFetch(base: typeof globalThis.fetch): typeof globalThis.fetch;
91
+ /**
92
+ * Wrap `globalThis.fetch` with {@link guardFetch}, so every caller that
93
+ * does not inject its own transport — the common case across kit and
94
+ * adopter code — enforces the policy without a per-site change.
95
+ *
96
+ * Idempotent and safe to call more than once. Call it once during process
97
+ * start-up (`createCLI` does this) and never concurrently with in-flight
98
+ * requests: it mutates a process-global.
99
+ *
100
+ * Callers that DO inject their own fetch must wrap it themselves with
101
+ * {@link guardFetch}; install cannot reach them.
102
+ */
103
+ declare function install(): void;
104
+ /**
105
+ * Fetch for logging-class egress — telemetry, and any future
106
+ * remote-logging or crash-reporting sink.
107
+ *
108
+ * `--offline` means "do not talk to the network on the user's behalf". It
109
+ * does not silence diagnostics, the same way a remote syslog target is
110
+ * not muted by an offline flag. Consent and the telemetry mode already
111
+ * govern whether those sinks emit at all; `--offline` is not a second
112
+ * consent gate.
113
+ *
114
+ * Resolved lazily, per call: it reads the *current* `globalThis.fetch`
115
+ * and unwraps the guard if {@link install} has wrapped it. Capturing a
116
+ * reference at module load instead would freeze out later stubbing —
117
+ * breaking both test fakes and adopters who swap the global transport.
118
+ *
119
+ * Never use this for anything the user asked for — that is exactly the
120
+ * traffic `--offline` exists to stop.
121
+ */
122
+ declare function observabilityFetch(): typeof globalThis.fetch;
123
+
124
+ declare const netpolicy_ErrOffline: typeof ErrOffline;
125
+ type netpolicy_OfflineError = OfflineError;
126
+ declare const netpolicy_OfflineError: typeof OfflineError;
127
+ declare const netpolicy_guardFetch: typeof guardFetch;
128
+ declare const netpolicy_install: typeof install;
129
+ declare const netpolicy_isOffline: typeof isOffline;
130
+ declare const netpolicy_isOfflineError: typeof isOfflineError;
131
+ declare const netpolicy_observabilityFetch: typeof observabilityFetch;
132
+ declare const netpolicy_setProcessOffline: typeof setProcessOffline;
133
+ declare const netpolicy_withOffline: typeof withOffline;
134
+ declare namespace netpolicy {
135
+ export { netpolicy_ErrOffline as ErrOffline, netpolicy_OfflineError as OfflineError, netpolicy_guardFetch as guardFetch, netpolicy_install as install, netpolicy_isOffline as isOffline, netpolicy_isOfflineError as isOfflineError, netpolicy_observabilityFetch as observabilityFetch, netpolicy_setProcessOffline as setProcessOffline, netpolicy_withOffline as withOffline };
136
+ }
137
+
138
+ export { ErrOffline as E, OfflineError as O, isOffline as a, isOfflineError as b, guardFetch as g, install as i, netpolicy as n, observabilityFetch as o, setProcessOffline as s, withOffline as w };
@@ -0,0 +1 @@
1
+ export { E as ErrOffline, O as OfflineError, g as guardFetch, i as install, a as isOffline, b as isOfflineError, o as observabilityFetch, s as setProcessOffline, w as withOffline } from './netpolicy-asvCfwi8.js';
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target2, all) => {
7
+ for (var name in all)
8
+ __defProp(target2, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/netpolicy.ts
21
+ var netpolicy_exports = {};
22
+ __export(netpolicy_exports, {
23
+ ErrOffline: () => ErrOffline,
24
+ OfflineError: () => OfflineError,
25
+ guardFetch: () => guardFetch,
26
+ install: () => install,
27
+ isOffline: () => isOffline,
28
+ isOfflineError: () => isOfflineError,
29
+ observabilityFetch: () => observabilityFetch,
30
+ setProcessOffline: () => setProcessOffline,
31
+ withOffline: () => withOffline
32
+ });
33
+ module.exports = __toCommonJS(netpolicy_exports);
34
+ var import_node_async_hooks = require("async_hooks");
35
+ var ErrOffline = "OfflineError";
36
+ var OfflineError = class extends Error {
37
+ constructor(method, url) {
38
+ super(`${method} ${url}: network disabled by --offline`);
39
+ this.name = ErrOffline;
40
+ }
41
+ };
42
+ function isOfflineError(err) {
43
+ return err instanceof Error && err.name === ErrOffline;
44
+ }
45
+ var store = new import_node_async_hooks.AsyncLocalStorage();
46
+ var processOffline = false;
47
+ function withOffline(offline, fn) {
48
+ if (!offline) return fn();
49
+ return store.run(true, fn);
50
+ }
51
+ function setProcessOffline(offline) {
52
+ processOffline = offline;
53
+ }
54
+ function isOffline() {
55
+ return processOffline || store.getStore() === true;
56
+ }
57
+ function isLoopback(hostname) {
58
+ const h = hostname.replace(/^\[|\]$/g, "");
59
+ if (h === "localhost") return true;
60
+ if (h === "::1") return true;
61
+ const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(h);
62
+ if (v4) {
63
+ return v4.slice(1).every((o) => Number(o) <= 255) && Number(v4[1]) === 127;
64
+ }
65
+ const mapped = /^::ffff:(.+)$/i.exec(h);
66
+ if (mapped) {
67
+ const inner = mapped[1] ?? "";
68
+ if (/^7f00:1$/i.test(inner)) return true;
69
+ return isLoopback(inner);
70
+ }
71
+ return false;
72
+ }
73
+ function target(input, init) {
74
+ if (typeof Request !== "undefined" && input instanceof Request) {
75
+ return { method: init?.method ?? input.method, url: input.url };
76
+ }
77
+ return { method: init?.method ?? "GET", url: String(input) };
78
+ }
79
+ var guarded = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.guarded");
80
+ var unguardedBase = /* @__PURE__ */ Symbol.for("hop.top/kit/netpolicy.unguardedBase");
81
+ function guardFetch(base) {
82
+ if (base[guarded]) return base;
83
+ const wrapper = async (input, init) => {
84
+ if (isOffline()) {
85
+ const { method, url } = target(input, init);
86
+ let loopback = false;
87
+ try {
88
+ loopback = isLoopback(new URL(url).hostname);
89
+ } catch {
90
+ loopback = false;
91
+ }
92
+ if (!loopback) throw new OfflineError(method, url);
93
+ }
94
+ return base(input, init);
95
+ };
96
+ wrapper[guarded] = true;
97
+ wrapper[unguardedBase] = base;
98
+ return wrapper;
99
+ }
100
+ function install() {
101
+ globalThis.fetch = guardFetch(globalThis.fetch);
102
+ }
103
+ function observabilityFetch() {
104
+ const current = globalThis.fetch;
105
+ return current?.[unguardedBase] ?? globalThis.fetch;
106
+ }
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ ErrOffline,
110
+ OfflineError,
111
+ guardFetch,
112
+ install,
113
+ isOffline,
114
+ isOfflineError,
115
+ observabilityFetch,
116
+ setProcessOffline,
117
+ withOffline
118
+ });
@@ -0,0 +1,396 @@
1
+ import { Command } from 'commander';
2
+ import { C as CODE_CONFLICT, a as CODE_GENERIC, b as CODE_NOT_FOUND, c as CODE_OK, d as CODE_PROVENANCE_MISSING, e as CODE_RATE_LIMITED, f as CODE_TRANSIENT, g as CODE_UNAUTHORIZED, h as CODE_USAGE, i as CliError, E as EXIT_GENERIC, j as EXIT_PROVENANCE_MISSING, k as EXIT_RATE_LIMITED, l as EXIT_TRANSIENT, T as TRANSIENCE_PERMANENT, m as TRANSIENCE_TRANSIENT, n as TRANSIENCE_UNKNOWN, o as conflictError, p as genericError, q as notFoundError, r as provenanceMissingError, s as rateLimitedError, t as renderError, u as transienceForCode, v as transientError, w as unauthorizedError, x as unwrapError, y as usageError, z as withTransience, A as wrapError } from './error-DISJKeDu.js';
3
+
4
+ /**
5
+ * @module output/formatter
6
+ *
7
+ * Core Formatter interface + Options/OptionSpec/ColumnSpec types and
8
+ * parseOptions helper. Mirrors Go's go/console/output Formatter interface.
9
+ */
10
+ /** Kinds of values an OptionSpec accepts. */
11
+ type OptionType = 'string' | 'int' | 'bool' | 'enum';
12
+ /** Describes one option accepted by a Formatter via --format-opt key=value. */
13
+ interface OptionSpec {
14
+ readonly name: string;
15
+ readonly type: OptionType;
16
+ readonly default?: string | number | boolean;
17
+ readonly usage: string;
18
+ readonly enum?: readonly string[];
19
+ }
20
+ /**
21
+ * Validated map of option values produced by parseOptions. Keys are
22
+ * OptionSpec.name; values are coerced to the spec's declared type.
23
+ */
24
+ type Options = Readonly<Record<string, string | number | boolean>>;
25
+ /**
26
+ * Column metadata used by every built-in formatter and by --cols validation.
27
+ *
28
+ * - `header` is the user-visible label, the name matched against --cols, AND
29
+ * the property read off the row object: header == key, universally. Go
30
+ * cannot express a header/key split through `table:""` struct tags, so no
31
+ * SDK offers one.
32
+ * - `key` is retained for source compatibility and must equal `header`;
33
+ * `columnName` reports the single effective name.
34
+ * - `priority` is accepted and stored but ignored — hide-on-overflow is a
35
+ * Go-only feature today.
36
+ */
37
+ interface ColumnSpec {
38
+ readonly header: string;
39
+ readonly key: string;
40
+ readonly priority?: number;
41
+ }
42
+ /**
43
+ * Returns a ColumnSpec's effective column name, rejecting a header/key split.
44
+ *
45
+ * Validating at read time keeps drift impossible while `key` still exists as
46
+ * a field.
47
+ */
48
+ declare function columnName(c: ColumnSpec): string;
49
+ /**
50
+ * A Formatter encodes structured data to a writable stream.
51
+ *
52
+ * Implementations declare their key, file extensions, and the option keys
53
+ * they accept. The dispatch helper validates --format-opt input against
54
+ * options() before invoking render(), so render() may trust opts to only
55
+ * contain declared keys with values coerced to declared types.
56
+ */
57
+ interface Formatter<T = unknown> {
58
+ /** Unique format identifier exposed via --format <key>. */
59
+ readonly key: string;
60
+ /**
61
+ * File extensions (with leading dot, e.g. ".csv") that map to this
62
+ * formatter for --output extension inference. May be empty.
63
+ */
64
+ readonly extensions: readonly string[];
65
+ /** Option specs accepted by this formatter via --format-opt key=value. */
66
+ readonly options: readonly OptionSpec[];
67
+ /**
68
+ * Renders data to out.
69
+ *
70
+ * @param out Destination writable stream.
71
+ * @param data Single row or readonly array of rows.
72
+ * @param opts Validated options; only declared keys with coerced values.
73
+ * @param cols Effective column list, already resolved by dispatch: the
74
+ * user's `--cols` when supplied, else the caller's ColumnSpec headers in
75
+ * list order, else empty meaning "fall back to payload key order".
76
+ * Render columns in exactly this order — it is both the labels and, since
77
+ * header == key, the lookup names on each row.
78
+ */
79
+ render(out: NodeJS.WritableStream, data: T | readonly T[], opts: Options, cols: readonly string[]): Promise<void> | void;
80
+ }
81
+ /**
82
+ * Validates raw `key=value` pairs against specs and returns a coerced
83
+ * Options map. Unknown keys, type errors, and out-of-enum values throw an
84
+ * Error listing the offending key and the valid set.
85
+ *
86
+ * A pair without `=` (e.g. `"no-header"`) is treated as bool true; only
87
+ * valid when the matching spec has type `'bool'`.
88
+ *
89
+ * Defaults from specs fill in any keys not present in pairs.
90
+ */
91
+ declare function parseOptions(pairs: readonly string[], specs: readonly OptionSpec[]): Options;
92
+ /** Pretty-print an OptionType. */
93
+ declare function optionTypeName(t: OptionType): string;
94
+
95
+ /**
96
+ * @module output/projection
97
+ *
98
+ * Helpers for projecting structured data through ColumnSpec lists. Mirrors
99
+ * Go's projection.go (projectToMaps / TableHeaders).
100
+ *
101
+ * Unlike Go (which uses `table:""` struct tags), TS callers pass an explicit
102
+ * ColumnSpec[] list. When no columns are provided, callers fall back to
103
+ * deriving headers from the first row's own enumerable keys.
104
+ *
105
+ * A ColumnSpec's `header` and `key` are the same name: validation and value
106
+ * lookup are one operation, matching what Go's `table:""` tag can express.
107
+ * `--cols` reorders as well as selects, so the user's order wins over the
108
+ * ColumnSpec list's.
109
+ */
110
+
111
+ /** Returns the list of headers for a row source given an optional ColumnSpec list. */
112
+ declare function deriveHeaders(rows: readonly unknown[], columns?: readonly ColumnSpec[]): readonly string[];
113
+ /**
114
+ * Resolves the effective column list a formatter should render.
115
+ *
116
+ * Precedence, per the settled ordering contract:
117
+ * - `cols` non-empty → the user's `--cols`, verbatim and in user order
118
+ * (rule 2: --cols reorders as well as selects).
119
+ * - else a ColumnSpec list → its headers, in list order (rule 1).
120
+ * - else → empty, meaning "fall back to payload key order".
121
+ *
122
+ * Because header == key (rule 3), an ordered array of names carries
123
+ * everything a formatter needs: the labels and the row lookup keys are the
124
+ * same strings. Resolving here keeps precedence in one place and leaves the
125
+ * public Formatter signature untouched.
126
+ */
127
+ declare function resolveEffectiveCols(cols: readonly string[], columns: readonly ColumnSpec[] | undefined): readonly string[];
128
+ /**
129
+ * Projects rows to plain objects keyed by column name, in `cols` order.
130
+ * An empty `cols` passes rows through untouched, so JSON/YAML keep whatever
131
+ * shape the caller handed in.
132
+ */
133
+ declare function projectRows(rows: readonly unknown[], cols: readonly string[]): readonly Record<string, unknown>[];
134
+
135
+ /**
136
+ * @module output/registry
137
+ *
138
+ * Registry holds Formatter implementations keyed by Formatter.key. Mirrors
139
+ * Go's *Registry. Built-in formatters register against `defaultRegistry` at
140
+ * module-load time.
141
+ */
142
+
143
+ /**
144
+ * Registry holds Formatter implementations.
145
+ *
146
+ * - `register` throws on duplicate keys (init-time fail-loud).
147
+ * - `override` quietly replaces — use when intentionally swapping a built-in.
148
+ * - `lookup` returns the formatter for a key, or undefined.
149
+ * - `keys` returns sorted format identifiers.
150
+ * - `formatters` returns sorted formatters.
151
+ * - `extensionMap` returns ext→key (e.g. ".csv" → "csv"); later
152
+ * registrations win on collision (alphabetical key order is the tie-break).
153
+ */
154
+ declare class Registry {
155
+ private readonly byKey;
156
+ /**
157
+ * Adds f to the registry. Throws Error on duplicate key or empty key.
158
+ * Use `override` to intentionally replace.
159
+ */
160
+ register<T>(f: Formatter<T>): void;
161
+ /** Replaces (or registers) the formatter for f.key. */
162
+ override<T>(f: Formatter<T>): void;
163
+ /** Returns the formatter registered under key, if any. */
164
+ lookup(key: string): Formatter | undefined;
165
+ /** Returns all registered format keys, sorted alphabetically. */
166
+ keys(): readonly string[];
167
+ /** Returns all registered formatters in key order. */
168
+ formatters(): readonly Formatter[];
169
+ /**
170
+ * Returns extension→key mappings (e.g. ".csv" → "csv") across all
171
+ * registered formatters. Later registrations win on collision; iteration
172
+ * is in sorted-key order so resolution is deterministic.
173
+ */
174
+ extensionMap(): ReadonlyMap<string, string>;
175
+ }
176
+ /** Module-level Registry. Built-ins register here at module-load time. */
177
+ declare const defaultRegistry: Registry;
178
+ /** Returns a new, empty Registry — no built-ins registered. */
179
+ declare function newRegistry(): Registry;
180
+
181
+ /**
182
+ * @module output/formatters/json
183
+ *
184
+ * Built-in JSON formatter. Honors `indent` option (default 2) + trailing
185
+ * newline. Emitted key order follows the ColumnSpec list, narrowed and
186
+ * reordered by `cols`; without either, the payload passes through untouched.
187
+ */
188
+
189
+ declare const jsonFormatter: Formatter;
190
+
191
+ /**
192
+ * @module output/formatters/yaml
193
+ *
194
+ * Built-in YAML formatter. Honors `flow-level` option (default -1, mapping
195
+ * to js-yaml's default block style). Emitted key order follows the ColumnSpec
196
+ * list, narrowed and reordered by `cols`; without either, the payload passes
197
+ * through untouched.
198
+ */
199
+
200
+ declare const yamlFormatter: Formatter;
201
+
202
+ /**
203
+ * @module output/formatters/table
204
+ *
205
+ * Built-in table formatter. Hand-rolled aligner (matches the original
206
+ * output.ts behaviour). Column order comes from the ColumnSpec list, or the
207
+ * first row's key order when none was supplied; `cols` narrows and reorders.
208
+ */
209
+
210
+ declare const tableFormatter: Formatter;
211
+
212
+ /**
213
+ * @module output/flags
214
+ *
215
+ * Commander integration: registerOutputFlags adds the standard output
216
+ * flag suite (--format, --format-opt, --format-help, --cols, --template,
217
+ * --output|-o) to a Commander program. Mirrors Go's RegisterFlagsWith.
218
+ */
219
+
220
+ /** Returns the Registry attached to cmd (walks parents) or defaultRegistry. */
221
+ declare function registryFor(cmd: Command): Registry;
222
+ /** Options for registerOutputFlags. */
223
+ interface RegisterOutputFlagsOptions {
224
+ /** Custom registry (default: defaultRegistry). */
225
+ registry?: Registry;
226
+ /** Per-flag opt-out. */
227
+ disable?: {
228
+ format?: boolean;
229
+ formatOpt?: boolean;
230
+ formatHelp?: boolean;
231
+ cols?: boolean;
232
+ template?: boolean;
233
+ output?: boolean;
234
+ };
235
+ }
236
+ /**
237
+ * Adds the output flag suite to a Commander program. Each flag is opt-out
238
+ * via `opts.disable.<flag>`. The active registry can be swapped via
239
+ * `opts.registry`; tests + multi-CLI binaries use this for isolated sets.
240
+ */
241
+ declare function registerOutputFlags(program: Command, opts?: RegisterOutputFlagsOptions): void;
242
+ /**
243
+ * Merges --cols + --columns from a Commander opts object into a single
244
+ * ordered, deduped string[]. Trims whitespace, drops empty entries.
245
+ */
246
+ declare function resolveCols(opts: Record<string, unknown>): string[];
247
+
248
+ /** Optional inputs to dispatch. */
249
+ interface DispatchOptions<T = unknown> {
250
+ /** ColumnSpec list for projection + --cols validation. */
251
+ columns?: readonly ColumnSpec[];
252
+ /** Override registry (default: registry stashed on cmd, else defaultRegistry). */
253
+ registry?: Registry;
254
+ /** Default format when --format isn't explicit (default: "table"). */
255
+ defaultFormat?: string;
256
+ _phantom?: T;
257
+ }
258
+ /**
259
+ * Renders `data` through the active formatter resolved from cmd's flags.
260
+ *
261
+ * Resolution order:
262
+ * 1. Resolve writer: empty/'-' → cmd.stdout (process.stdout), else file.
263
+ * 2. --format-help short-circuit: list registry or show one formatter.
264
+ * 3. Resolve format: explicit --format wins; else infer from --output ext.
265
+ * 4. Mismatch detection: explicit --format + ext mapping to different
266
+ * formatter is a hard error.
267
+ * 5. --template: build {items, cols} input, run eta, return.
268
+ * 6. Else: parseOptions, validateCols, formatter.render.
269
+ */
270
+ declare function dispatch<T>(cmd: Command, data: T | readonly T[], options?: DispatchOptions<T>): Promise<void>;
271
+
272
+ /**
273
+ * @module output
274
+ * @package @hop-top/kit
275
+ *
276
+ * Output rendering — writes structured values to a writable stream in one of
277
+ * the registered formats: table, JSON, YAML, CSV, text, etc.
278
+ *
279
+ * ## Quick start
280
+ *
281
+ * ```ts
282
+ * import { render, TABLE_FORMAT, JSON_FORMAT, YAML_FORMAT } from '@hop-top/kit/output';
283
+ *
284
+ * // Write a table to stdout
285
+ * render(process.stdout, TABLE_FORMAT, [{ id: '1', name: 'Alice' }]);
286
+ *
287
+ * // Write indented JSON
288
+ * render(process.stdout, JSON_FORMAT, { ok: true });
289
+ *
290
+ * // Write YAML
291
+ * render(process.stdout, YAML_FORMAT, { version: 1 });
292
+ * ```
293
+ *
294
+ * ## Programmatic Formatter API
295
+ *
296
+ * For typed flag wiring + custom formatters use the Formatter / Registry
297
+ * surface from `output/formatter` and `output/registry`. The `render()`
298
+ * helper exported here is a thin shim over `defaultRegistry`.
299
+ *
300
+ * ## Backward compatibility
301
+ *
302
+ * `render(w, format, v)` keeps its original signature and renders every
303
+ * column in payload key order. New per-format options and column ordering
304
+ * (ColumnSpec lists, `--cols`) are accessed via `dispatch()`.
305
+ */
306
+
307
+ /**
308
+ * Supported output formats. Includes the original three for backward-compat
309
+ * + new built-ins (csv, text) registered on the default registry.
310
+ */
311
+ type Format = string;
312
+ /** Constant for the JSON output format. */
313
+ declare const JSON_FORMAT: "json";
314
+ /** Constant for the YAML output format. */
315
+ declare const YAML_FORMAT: "yaml";
316
+ /** Constant for the table output format. */
317
+ declare const TABLE_FORMAT: "table";
318
+ /** Constant for the CSV output format. */
319
+ declare const CSV_FORMAT: "csv";
320
+ /** Constant for the text output format. */
321
+ declare const TEXT_FORMAT: "text";
322
+ /**
323
+ * Renders `v` to `w` in the requested `format`.
324
+ *
325
+ * Backward-compatible thin shim over `defaultRegistry.lookup(format).render`.
326
+ *
327
+ * @throws {Error} For unknown format strings.
328
+ */
329
+ declare function render(w: NodeJS.WritableStream, format: Format, v: unknown): void;
330
+
331
+ declare const output_CODE_CONFLICT: typeof CODE_CONFLICT;
332
+ declare const output_CODE_GENERIC: typeof CODE_GENERIC;
333
+ declare const output_CODE_NOT_FOUND: typeof CODE_NOT_FOUND;
334
+ declare const output_CODE_OK: typeof CODE_OK;
335
+ declare const output_CODE_PROVENANCE_MISSING: typeof CODE_PROVENANCE_MISSING;
336
+ declare const output_CODE_RATE_LIMITED: typeof CODE_RATE_LIMITED;
337
+ declare const output_CODE_TRANSIENT: typeof CODE_TRANSIENT;
338
+ declare const output_CODE_UNAUTHORIZED: typeof CODE_UNAUTHORIZED;
339
+ declare const output_CODE_USAGE: typeof CODE_USAGE;
340
+ declare const output_CSV_FORMAT: typeof CSV_FORMAT;
341
+ declare const output_CliError: typeof CliError;
342
+ type output_ColumnSpec = ColumnSpec;
343
+ type output_DispatchOptions<T = unknown> = DispatchOptions<T>;
344
+ declare const output_EXIT_GENERIC: typeof EXIT_GENERIC;
345
+ declare const output_EXIT_PROVENANCE_MISSING: typeof EXIT_PROVENANCE_MISSING;
346
+ declare const output_EXIT_RATE_LIMITED: typeof EXIT_RATE_LIMITED;
347
+ declare const output_EXIT_TRANSIENT: typeof EXIT_TRANSIENT;
348
+ type output_Format = Format;
349
+ type output_Formatter<T = unknown> = Formatter<T>;
350
+ declare const output_JSON_FORMAT: typeof JSON_FORMAT;
351
+ type output_OptionSpec = OptionSpec;
352
+ type output_OptionType = OptionType;
353
+ type output_Options = Options;
354
+ type output_RegisterOutputFlagsOptions = RegisterOutputFlagsOptions;
355
+ type output_Registry = Registry;
356
+ declare const output_Registry: typeof Registry;
357
+ declare const output_TABLE_FORMAT: typeof TABLE_FORMAT;
358
+ declare const output_TEXT_FORMAT: typeof TEXT_FORMAT;
359
+ declare const output_TRANSIENCE_PERMANENT: typeof TRANSIENCE_PERMANENT;
360
+ declare const output_TRANSIENCE_TRANSIENT: typeof TRANSIENCE_TRANSIENT;
361
+ declare const output_TRANSIENCE_UNKNOWN: typeof TRANSIENCE_UNKNOWN;
362
+ declare const output_YAML_FORMAT: typeof YAML_FORMAT;
363
+ declare const output_columnName: typeof columnName;
364
+ declare const output_conflictError: typeof conflictError;
365
+ declare const output_defaultRegistry: typeof defaultRegistry;
366
+ declare const output_deriveHeaders: typeof deriveHeaders;
367
+ declare const output_dispatch: typeof dispatch;
368
+ declare const output_genericError: typeof genericError;
369
+ declare const output_jsonFormatter: typeof jsonFormatter;
370
+ declare const output_newRegistry: typeof newRegistry;
371
+ declare const output_notFoundError: typeof notFoundError;
372
+ declare const output_optionTypeName: typeof optionTypeName;
373
+ declare const output_parseOptions: typeof parseOptions;
374
+ declare const output_projectRows: typeof projectRows;
375
+ declare const output_provenanceMissingError: typeof provenanceMissingError;
376
+ declare const output_rateLimitedError: typeof rateLimitedError;
377
+ declare const output_registerOutputFlags: typeof registerOutputFlags;
378
+ declare const output_registryFor: typeof registryFor;
379
+ declare const output_render: typeof render;
380
+ declare const output_renderError: typeof renderError;
381
+ declare const output_resolveCols: typeof resolveCols;
382
+ declare const output_resolveEffectiveCols: typeof resolveEffectiveCols;
383
+ declare const output_tableFormatter: typeof tableFormatter;
384
+ declare const output_transienceForCode: typeof transienceForCode;
385
+ declare const output_transientError: typeof transientError;
386
+ declare const output_unauthorizedError: typeof unauthorizedError;
387
+ declare const output_unwrapError: typeof unwrapError;
388
+ declare const output_usageError: typeof usageError;
389
+ declare const output_withTransience: typeof withTransience;
390
+ declare const output_wrapError: typeof wrapError;
391
+ declare const output_yamlFormatter: typeof yamlFormatter;
392
+ declare namespace output {
393
+ export { output_CODE_CONFLICT as CODE_CONFLICT, output_CODE_GENERIC as CODE_GENERIC, output_CODE_NOT_FOUND as CODE_NOT_FOUND, output_CODE_OK as CODE_OK, output_CODE_PROVENANCE_MISSING as CODE_PROVENANCE_MISSING, output_CODE_RATE_LIMITED as CODE_RATE_LIMITED, output_CODE_TRANSIENT as CODE_TRANSIENT, output_CODE_UNAUTHORIZED as CODE_UNAUTHORIZED, output_CODE_USAGE as CODE_USAGE, output_CSV_FORMAT as CSV_FORMAT, output_CliError as CliError, type output_ColumnSpec as ColumnSpec, type output_DispatchOptions as DispatchOptions, output_EXIT_GENERIC as EXIT_GENERIC, output_EXIT_PROVENANCE_MISSING as EXIT_PROVENANCE_MISSING, output_EXIT_RATE_LIMITED as EXIT_RATE_LIMITED, output_EXIT_TRANSIENT as EXIT_TRANSIENT, type output_Format as Format, type output_Formatter as Formatter, output_JSON_FORMAT as JSON_FORMAT, type output_OptionSpec as OptionSpec, type output_OptionType as OptionType, type output_Options as Options, type output_RegisterOutputFlagsOptions as RegisterOutputFlagsOptions, output_Registry as Registry, output_TABLE_FORMAT as TABLE_FORMAT, output_TEXT_FORMAT as TEXT_FORMAT, output_TRANSIENCE_PERMANENT as TRANSIENCE_PERMANENT, output_TRANSIENCE_TRANSIENT as TRANSIENCE_TRANSIENT, output_TRANSIENCE_UNKNOWN as TRANSIENCE_UNKNOWN, output_YAML_FORMAT as YAML_FORMAT, output_columnName as columnName, output_conflictError as conflictError, output_defaultRegistry as defaultRegistry, output_deriveHeaders as deriveHeaders, output_dispatch as dispatch, output_genericError as genericError, output_jsonFormatter as jsonFormatter, output_newRegistry as newRegistry, output_notFoundError as notFoundError, output_optionTypeName as optionTypeName, output_parseOptions as parseOptions, output_projectRows as projectRows, output_provenanceMissingError as provenanceMissingError, output_rateLimitedError as rateLimitedError, output_registerOutputFlags as registerOutputFlags, output_registryFor as registryFor, output_render as render, output_renderError as renderError, output_resolveCols as resolveCols, output_resolveEffectiveCols as resolveEffectiveCols, output_tableFormatter as tableFormatter, output_transienceForCode as transienceForCode, output_transientError as transientError, output_unauthorizedError as unauthorizedError, output_unwrapError as unwrapError, output_usageError as usageError, output_withTransience as withTransience, output_wrapError as wrapError, output_yamlFormatter as yamlFormatter };
394
+ }
395
+
396
+ export { CSV_FORMAT as C, type DispatchOptions as D, type Format as F, JSON_FORMAT as J, type OptionSpec as O, type RegisterOutputFlagsOptions as R, TABLE_FORMAT as T, YAML_FORMAT as Y, type ColumnSpec as a, type Formatter as b, type OptionType as c, type Options as d, Registry as e, TEXT_FORMAT as f, columnName as g, defaultRegistry as h, deriveHeaders as i, dispatch as j, jsonFormatter as k, output as l, projectRows as m, newRegistry as n, optionTypeName as o, parseOptions as p, registryFor as q, registerOutputFlags as r, render as s, resolveCols as t, resolveEffectiveCols as u, tableFormatter as v, yamlFormatter as y };