@hop-top/kit 0.4.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/LICENSE +25 -0
  3. package/README.md +189 -0
  4. package/dist/aim.d.ts +116 -0
  5. package/dist/aim.js +417 -0
  6. package/dist/alias.d.ts +73 -0
  7. package/dist/alias.js +207 -0
  8. package/dist/api.d.ts +62 -0
  9. package/dist/api.js +165 -0
  10. package/dist/auth.d.ts +26 -0
  11. package/dist/auth.js +41 -0
  12. package/dist/cli.d.ts +309 -0
  13. package/dist/cli.js +885 -0
  14. package/dist/config.d.ts +97 -0
  15. package/dist/config.js +79 -0
  16. package/dist/errcorrect.d.ts +37 -0
  17. package/dist/errcorrect.js +69 -0
  18. package/dist/llm.d.ts +188 -0
  19. package/dist/llm.js +356 -0
  20. package/dist/output.d.ts +213 -0
  21. package/dist/output.js +447 -0
  22. package/dist/progress.d.ts +30 -0
  23. package/dist/progress.js +56 -0
  24. package/dist/provenance.d.ts +24 -0
  25. package/dist/provenance.js +32 -0
  26. package/dist/routellm.d.ts +64 -0
  27. package/dist/routellm.js +258 -0
  28. package/dist/rpc.d.ts +25 -0
  29. package/dist/rpc.js +101 -0
  30. package/dist/safety.d.ts +24 -0
  31. package/dist/safety.js +44 -0
  32. package/dist/scope.d.ts +121 -0
  33. package/dist/scope.js +380 -0
  34. package/dist/sqlstore.d.ts +84 -0
  35. package/dist/sqlstore.js +85 -0
  36. package/dist/stream.d.ts +35 -0
  37. package/dist/stream.js +52 -0
  38. package/dist/tui/index.d.ts +300 -0
  39. package/dist/tui/index.js +332 -0
  40. package/dist/upgrade.d.ts +95 -0
  41. package/dist/upgrade.js +115 -0
  42. package/dist/xdg.d.ts +169 -0
  43. package/dist/xdg.js +129 -0
  44. package/eslint.config.mjs +17 -0
  45. package/package.json +133 -0
  46. package/src/README.md +3 -0
  47. package/src/aim.test.ts +331 -0
  48. package/src/aim.ts +388 -0
  49. package/src/alias.test.ts +423 -0
  50. package/src/alias.ts +256 -0
  51. package/src/api.test.ts +190 -0
  52. package/src/api.ts +214 -0
  53. package/src/auth.test.ts +24 -0
  54. package/src/auth.ts +37 -0
  55. package/src/bus.test.ts +178 -0
  56. package/src/bus.ts +114 -0
  57. package/src/cli.test.ts +690 -0
  58. package/src/cli.ts +741 -0
  59. package/src/completion-values.test.ts +202 -0
  60. package/src/completion-values.ts +173 -0
  61. package/src/completion.test.ts +212 -0
  62. package/src/completion.ts +158 -0
  63. package/src/compliance.test.ts +134 -0
  64. package/src/compliance.ts +669 -0
  65. package/src/config.test.ts +110 -0
  66. package/src/config.ts +164 -0
  67. package/src/errcorrect.test.ts +134 -0
  68. package/src/errcorrect.ts +84 -0
  69. package/src/flagregister.test.ts +103 -0
  70. package/src/flagregister.ts +78 -0
  71. package/src/gen/crud_connect.ts +76 -0
  72. package/src/gen/crud_pb.ts +269 -0
  73. package/src/hint.test.ts +315 -0
  74. package/src/hint.ts +178 -0
  75. package/src/llm.test.ts +612 -0
  76. package/src/llm.ts +577 -0
  77. package/src/log.test.ts +145 -0
  78. package/src/log.ts +155 -0
  79. package/src/output/builtins.ts +34 -0
  80. package/src/output/dispatch.ts +195 -0
  81. package/src/output/flags.ts +151 -0
  82. package/src/output/format_help.ts +80 -0
  83. package/src/output/formatter.ts +167 -0
  84. package/src/output/formatters/csv.ts +72 -0
  85. package/src/output/formatters/json.ts +44 -0
  86. package/src/output/formatters/table.ts +44 -0
  87. package/src/output/formatters/text.ts +109 -0
  88. package/src/output/formatters/yaml.ts +47 -0
  89. package/src/output/projection.ts +126 -0
  90. package/src/output/registry.ts +88 -0
  91. package/src/output/template.ts +63 -0
  92. package/src/output.test.ts +117 -0
  93. package/src/output.ts +90 -0
  94. package/src/progress.test.ts +93 -0
  95. package/src/progress.ts +58 -0
  96. package/src/provenance.test.ts +59 -0
  97. package/src/provenance.ts +26 -0
  98. package/src/routellm.test.ts +179 -0
  99. package/src/routellm.ts +365 -0
  100. package/src/router/bert.test.ts +180 -0
  101. package/src/router/bert.ts +145 -0
  102. package/src/router/controller.test.ts +183 -0
  103. package/src/router/controller.ts +165 -0
  104. package/src/router/integration.test.ts +309 -0
  105. package/src/router/intent.test.ts +187 -0
  106. package/src/router/intent.ts +208 -0
  107. package/src/router/mf.test.ts +66 -0
  108. package/src/router/mf.ts +52 -0
  109. package/src/router/random.test.ts +23 -0
  110. package/src/router/random.ts +13 -0
  111. package/src/router/router.test.ts +31 -0
  112. package/src/router/router.ts +62 -0
  113. package/src/router/server.test.ts +193 -0
  114. package/src/router/server.ts +134 -0
  115. package/src/router/sw.test.ts +199 -0
  116. package/src/router/sw.ts +232 -0
  117. package/src/rpc.test.ts +47 -0
  118. package/src/rpc.ts +91 -0
  119. package/src/safety.test.ts +53 -0
  120. package/src/safety.ts +42 -0
  121. package/src/scope-defaults.json +72 -0
  122. package/src/scope.test.ts +177 -0
  123. package/src/scope.ts +382 -0
  124. package/src/setflag.test.ts +110 -0
  125. package/src/setflag.ts +102 -0
  126. package/src/sqlstore.test.ts +110 -0
  127. package/src/sqlstore.ts +144 -0
  128. package/src/stream.test.ts +69 -0
  129. package/src/stream.ts +47 -0
  130. package/src/textflag.test.ts +105 -0
  131. package/src/textflag.ts +68 -0
  132. package/src/toolspec.test.ts +187 -0
  133. package/src/toolspec.ts +279 -0
  134. package/src/triton/client.test.ts +205 -0
  135. package/src/triton/client.ts +261 -0
  136. package/src/tui/anim.test.ts +146 -0
  137. package/src/tui/anim.ts +134 -0
  138. package/src/tui/badge.test.ts +41 -0
  139. package/src/tui/badge.ts +55 -0
  140. package/src/tui/confirm.test.ts +68 -0
  141. package/src/tui/confirm.ts +49 -0
  142. package/src/tui/index.ts +29 -0
  143. package/src/tui/list.test.ts +84 -0
  144. package/src/tui/list.ts +72 -0
  145. package/src/tui/parity.ts +41 -0
  146. package/src/tui/pills.test.ts +40 -0
  147. package/src/tui/pills.ts +43 -0
  148. package/src/tui/progress.test.ts +164 -0
  149. package/src/tui/progress.ts +120 -0
  150. package/src/tui/spinner.test.ts +111 -0
  151. package/src/tui/spinner.ts +96 -0
  152. package/src/tui/status.test.ts +68 -0
  153. package/src/tui/status.ts +66 -0
  154. package/src/upgrade.test.ts +298 -0
  155. package/src/upgrade.ts +205 -0
  156. package/src/uri.ts +199 -0
  157. package/src/wizard.test.ts +441 -0
  158. package/src/wizard.ts +662 -0
  159. package/src/xdg.test.ts +202 -0
  160. package/src/xdg.ts +280 -0
  161. package/test/output/cols.test.ts +148 -0
  162. package/test/output/csv.test.ts +129 -0
  163. package/test/output/dispatch.test.ts +194 -0
  164. package/test/output/format_help.test.ts +131 -0
  165. package/test/output/formatter.test.ts +137 -0
  166. package/test/output/output_flag.test.ts +124 -0
  167. package/test/output/registry.test.ts +127 -0
  168. package/test/output/smoke-capture.ts +83 -0
  169. package/test/output/smoke.test.ts +142 -0
  170. package/test/output/template.test.ts +95 -0
  171. package/test/output/text.test.ts +75 -0
  172. package/test/testdata/api-fixture.json +115 -0
  173. package/test/testdata/query-vectors.json +187 -0
  174. package/tsconfig.json +12 -0
package/dist/api.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Typed REST API client + WebSocket client for kit services.
3
+ *
4
+ * Mirrors Go-side api.Service[T] (CRUD) and api.WSMessage (pub/sub).
5
+ */
6
+ interface Entity {
7
+ id: string;
8
+ }
9
+ interface Query {
10
+ limit?: number;
11
+ offset?: number;
12
+ sort?: string;
13
+ search?: string;
14
+ }
15
+ interface APIError {
16
+ status: number;
17
+ code: string;
18
+ message: string;
19
+ }
20
+ interface WSMessage {
21
+ type: string;
22
+ topic: string;
23
+ payload: unknown;
24
+ }
25
+ declare class APIRequestError extends Error implements APIError {
26
+ status: number;
27
+ code: string;
28
+ constructor(err: APIError);
29
+ }
30
+ interface APIClientOptions {
31
+ auth?: string;
32
+ fetch?: typeof globalThis.fetch;
33
+ }
34
+ declare class APIClient<T extends Entity> {
35
+ private baseURL;
36
+ private auth?;
37
+ private fetchFn;
38
+ constructor(baseURL: string, opts?: APIClientOptions);
39
+ private headers;
40
+ private request;
41
+ create(entity: Omit<T, "id"> | T): Promise<T>;
42
+ get(id: string): Promise<T>;
43
+ list(q?: Query): Promise<T[]>;
44
+ update(entity: T): Promise<T>;
45
+ delete(id: string): Promise<void>;
46
+ }
47
+ type MessageHandler = (msg: WSMessage) => void;
48
+ declare class WSClient {
49
+ private url;
50
+ private ws?;
51
+ private handlers;
52
+ constructor(url: string);
53
+ private static resolveWS;
54
+ connect(): Promise<void>;
55
+ subscribe(topic: string): void;
56
+ unsubscribe(topic: string): void;
57
+ onMessage(fn: MessageHandler): void;
58
+ close(): void;
59
+ private send;
60
+ }
61
+
62
+ export { APIClient, type APIClientOptions, type APIError, APIRequestError, type Entity, type Query, WSClient, type WSMessage };
package/dist/api.js ADDED
@@ -0,0 +1,165 @@
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 = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, 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/api.ts
21
+ var api_exports = {};
22
+ __export(api_exports, {
23
+ APIClient: () => APIClient,
24
+ APIRequestError: () => APIRequestError,
25
+ WSClient: () => WSClient
26
+ });
27
+ module.exports = __toCommonJS(api_exports);
28
+ var APIRequestError = class extends Error {
29
+ constructor(err) {
30
+ super(err.message);
31
+ this.name = "APIRequestError";
32
+ this.status = err.status;
33
+ this.code = err.code;
34
+ }
35
+ };
36
+ var APIClient = class {
37
+ constructor(baseURL, opts) {
38
+ this.baseURL = baseURL.replace(/\/+$/, "");
39
+ this.auth = opts?.auth;
40
+ this.fetchFn = opts?.fetch ?? globalThis.fetch.bind(globalThis);
41
+ }
42
+ headers() {
43
+ const h = {
44
+ "Content-Type": "application/json"
45
+ };
46
+ if (this.auth) {
47
+ h["Authorization"] = `Bearer ${this.auth}`;
48
+ }
49
+ return h;
50
+ }
51
+ async request(method, path, body) {
52
+ const res = await this.fetchFn(`${this.baseURL}${path}`, {
53
+ method,
54
+ headers: this.headers(),
55
+ body: body !== void 0 ? JSON.stringify(body) : void 0
56
+ });
57
+ if (!res.ok) {
58
+ let err;
59
+ try {
60
+ err = await res.json();
61
+ } catch {
62
+ err = {
63
+ status: res.status,
64
+ code: "unknown",
65
+ message: res.statusText
66
+ };
67
+ }
68
+ throw new APIRequestError(err);
69
+ }
70
+ if (res.status === 204) return void 0;
71
+ return await res.json();
72
+ }
73
+ async create(entity) {
74
+ return this.request("POST", "/", entity);
75
+ }
76
+ async get(id) {
77
+ return this.request("GET", `/${encodeURIComponent(id)}`);
78
+ }
79
+ async list(q) {
80
+ const params = new URLSearchParams();
81
+ if (q?.limit !== void 0) params.set("limit", String(q.limit));
82
+ if (q?.offset !== void 0) params.set("offset", String(q.offset));
83
+ if (q?.sort) params.set("sort", q.sort);
84
+ if (q?.search) params.set("search", q.search);
85
+ const qs = params.toString();
86
+ return this.request("GET", `/${qs ? `?${qs}` : ""}`);
87
+ }
88
+ async update(entity) {
89
+ return this.request(
90
+ "PUT",
91
+ `/${encodeURIComponent(entity.id)}`,
92
+ entity
93
+ );
94
+ }
95
+ async delete(id) {
96
+ return this.request(
97
+ "DELETE",
98
+ `/${encodeURIComponent(id)}`
99
+ );
100
+ }
101
+ };
102
+ var WSClient = class _WSClient {
103
+ constructor(url) {
104
+ this.handlers = [];
105
+ this.url = url;
106
+ }
107
+ static async resolveWS() {
108
+ if (typeof globalThis.WebSocket !== "undefined") {
109
+ return globalThis.WebSocket;
110
+ }
111
+ try {
112
+ return require("ws");
113
+ } catch {
114
+ }
115
+ throw new Error("ws: no WebSocket implementation available");
116
+ }
117
+ async connect() {
118
+ const WS = await _WSClient.resolveWS();
119
+ return new Promise((resolve, reject) => {
120
+ const ws = new WS(this.url);
121
+ ws.onopen = () => {
122
+ this.ws = ws;
123
+ resolve();
124
+ };
125
+ ws.onerror = (e) => {
126
+ reject(e);
127
+ };
128
+ ws.onmessage = (ev) => {
129
+ try {
130
+ const msg = JSON.parse(
131
+ typeof ev.data === "string" ? ev.data : String(ev.data)
132
+ );
133
+ for (const fn of this.handlers) {
134
+ fn(msg);
135
+ }
136
+ } catch {
137
+ }
138
+ };
139
+ });
140
+ }
141
+ subscribe(topic) {
142
+ this.send({ type: "subscribe", topic, payload: null });
143
+ }
144
+ unsubscribe(topic) {
145
+ this.send({ type: "unsubscribe", topic, payload: null });
146
+ }
147
+ onMessage(fn) {
148
+ this.handlers.push(fn);
149
+ }
150
+ close() {
151
+ this.ws?.close();
152
+ this.ws = void 0;
153
+ this.handlers = [];
154
+ }
155
+ send(msg) {
156
+ if (!this.ws) throw new Error("ws: not connected");
157
+ this.ws.send(JSON.stringify(msg));
158
+ }
159
+ };
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ APIClient,
163
+ APIRequestError,
164
+ WSClient
165
+ });
package/dist/auth.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module auth
3
+ * @package @hop-top/kit
4
+ *
5
+ * Factor 12 — Auth and Credential Lifecycle.
6
+ *
7
+ * Provides introspection and refresh for credentials.
8
+ * NoAuth is the zero-value implementation.
9
+ */
10
+ interface Credential {
11
+ source: string;
12
+ identity: string;
13
+ scopes: string[];
14
+ expiresAt?: string;
15
+ renewable: boolean;
16
+ }
17
+ interface AuthIntrospector {
18
+ inspect(): Promise<Credential>;
19
+ refresh(): Promise<void>;
20
+ }
21
+ declare class NoAuth implements AuthIntrospector {
22
+ inspect(): Promise<Credential>;
23
+ refresh(): Promise<void>;
24
+ }
25
+
26
+ export { type AuthIntrospector, type Credential, NoAuth };
package/dist/auth.js ADDED
@@ -0,0 +1,41 @@
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 = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, 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/auth.ts
21
+ var auth_exports = {};
22
+ __export(auth_exports, {
23
+ NoAuth: () => NoAuth
24
+ });
25
+ module.exports = __toCommonJS(auth_exports);
26
+ var NoAuth = class {
27
+ async inspect() {
28
+ return {
29
+ source: "none",
30
+ identity: "anonymous",
31
+ scopes: [],
32
+ renewable: false
33
+ };
34
+ }
35
+ async refresh() {
36
+ }
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ NoAuth
41
+ });
package/dist/cli.d.ts ADDED
@@ -0,0 +1,309 @@
1
+ import { Command } from 'commander';
2
+ import { Writable } from 'node:stream';
3
+ import { Format } from './output.js';
4
+
5
+ /**
6
+ * @module hint
7
+ * @package @hop-top/kit
8
+ *
9
+ * Contextual next-step hints — mirrors Go's output/hint.go contract.
10
+ *
11
+ * Hints guide users (and agents) toward the logical next action without
12
+ * burying them in a wall of text. They are suppressed when output is
13
+ * machine-formatted (JSON/YAML), piped (non-TTY), or explicitly disabled
14
+ * via flag/env.
15
+ */
16
+
17
+ /** A single next-step suggestion attached to a command. */
18
+ interface Hint {
19
+ /** Human-readable hint text (e.g. `"Run \`hop version\` to verify."`). */
20
+ message: string;
21
+ /**
22
+ * When provided, the hint is only rendered if this returns true.
23
+ * Omit (or set to undefined) for hints that always apply.
24
+ */
25
+ condition?: () => boolean;
26
+ }
27
+ /** Options read by {@link hintsEnabled} — subset of parsed CLI opts. */
28
+ interface HintOptions {
29
+ /** Value of --no-hints flag. */
30
+ noHints?: boolean;
31
+ /** Value of --quiet flag. */
32
+ quiet?: boolean;
33
+ /** Value of hints.enabled config key (false = disabled). */
34
+ hintsEnabled?: boolean;
35
+ }
36
+ /**
37
+ * Concurrency-safe registry mapping command names to hints.
38
+ * Mirrors Go's `output.HintSet`.
39
+ */
40
+ declare class HintSet {
41
+ private readonly m;
42
+ /** Add one or more hints for the given command name. */
43
+ register(cmd: string, ...hints: Hint[]): void;
44
+ /**
45
+ * Return a copy of the hints registered for cmd.
46
+ * Returns an empty array when none are registered.
47
+ */
48
+ lookup(cmd: string): Hint[];
49
+ }
50
+ /** Return only the hints whose condition is undefined or returns true. */
51
+ declare function active(hints: Hint[]): Hint[];
52
+ /**
53
+ * Report whether hints should be rendered given the current options.
54
+ * Mirrors Go's `output.HintsEnabled`.
55
+ *
56
+ * Hints are disabled when any of:
57
+ * - `opts.noHints` is true
58
+ * - `opts.hintsEnabled` is explicitly false
59
+ * - `opts.quiet` is true
60
+ * - `HOP_QUIET_HINTS` env var is set to `"1"`, `"true"`, or `"yes"`
61
+ */
62
+ declare function hintsEnabled(opts: HintOptions): boolean;
63
+ /**
64
+ * Write active hints to `w` with dimmed styling.
65
+ * No-op when format is not `"table"`, stdout is not a TTY, or hints disabled.
66
+ * Mirrors Go's `output.RenderHints`.
67
+ *
68
+ * @param w Writable stream (typically `process.stdout`).
69
+ * @param hints Hints to consider (pass `hintSet.lookup(cmdName)`).
70
+ * @param format Current output format.
71
+ * @param opts Parsed CLI options (noHints, quiet, hintsEnabled).
72
+ * @param muted Hex color for the hint prefix/text (e.g. `"#858183"`).
73
+ * Ignored when NO_COLOR env var is set or stdout is not a TTY.
74
+ */
75
+ declare function renderHints(w: Writable, hints: Hint[], format: Format, opts: HintOptions, muted: string): void;
76
+ /**
77
+ * Add a standard upgrade hint: `"Run \`<binary> version\` to verify."`
78
+ * Active only when `upgraded` returns true.
79
+ * Mirrors Go's `output.RegisterUpgradeHints`.
80
+ */
81
+ declare function registerUpgradeHints(hints: HintSet, binary: string, upgraded: () => boolean): void;
82
+ /**
83
+ * Add a standard version hint: `"Run \`<binary> upgrade\` to get latest."`
84
+ * Active only when `updateAvail` returns true.
85
+ * Mirrors Go's `output.RegisterVersionHints`.
86
+ */
87
+ declare function registerVersionHints(hints: HintSet, binary: string, updateAvail: () => boolean): void;
88
+
89
+ /**
90
+ * @module cli
91
+ * @package @hop-top/kit
92
+ *
93
+ * Commander-based CLI factory that enforces the hop-top CLI contract.
94
+ *
95
+ * The hop-top CLI contract:
96
+ * - No `help` subcommand; help is exposed only as -h/--help flag.
97
+ * - `completion` is a management-group command (hidden from default help).
98
+ * - Version is a root-level option (-v/--version), NOT a subcommand.
99
+ * - All hop-top CLIs expose three global options on the root command:
100
+ * --format <fmt> table | json | yaml (default: "table")
101
+ * --quiet suppress non-essential output
102
+ * --no-color disable ANSI colour
103
+ * - Errors are printed to stderr in error color (unless --no-color is set).
104
+ *
105
+ * Requirements: Node >= 20, commander ^14.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * import { createCLI } from '@hop-top/kit/cli';
110
+ * const { program, theme } = createCLI({ name: 'mytool', version: '1.0.0', description: 'My tool' });
111
+ * program.command('run').action(() => { ... });
112
+ * program.parse();
113
+ * ```
114
+ */
115
+
116
+ /** Read the accumulated -V count for a parsed command tree. */
117
+ declare function verboseCount(cmd: Command): number;
118
+ interface StreamDef {
119
+ name: string;
120
+ description: string;
121
+ }
122
+ /**
123
+ * Register a named diagnostic stream on a command.
124
+ * Adds a `--stream <names>` option (comma-separated) on first call.
125
+ *
126
+ * Parity note: Go uses StringSlice (repeatable --stream); TS and Python
127
+ * use a single comma-separated string value.
128
+ */
129
+ declare function registerStream(cmd: Command, name: string, description: string): void;
130
+ /** Return registered stream definitions for a command. */
131
+ declare function getStreamDefs(cmd: Command): StreamDef[];
132
+ /**
133
+ * Return a writer for a named stream. When the stream is enabled via
134
+ * `--stream`, writes go to stderr with a `[name] ` prefix. Otherwise
135
+ * writes are discarded.
136
+ */
137
+ declare function channel(cmd: Command, name: string): {
138
+ write(s: string): boolean;
139
+ };
140
+ /**
141
+ * Brand color pair used across a theme.
142
+ * Hex strings (e.g. `"#7ED957"`).
143
+ */
144
+ interface Palette {
145
+ /** Commands / primary accent. */
146
+ command: string;
147
+ /** Flags / secondary accent. */
148
+ flag: string;
149
+ }
150
+ /**
151
+ * Built-in Neon palette — vivid grass green + neon pink.
152
+ * Mirrors Go's `Neon` palette in `kit/cli/theme.go`.
153
+ */
154
+ declare const Neon: Palette;
155
+ /**
156
+ * Built-in Dark palette — softer lime + pink.
157
+ * Mirrors Go's `Dark` palette in `kit/cli/theme.go`.
158
+ */
159
+ declare const Dark: Palette;
160
+ /**
161
+ * Semantic color theme for CLI output.
162
+ * Mirrors Go's `Theme` struct in `kit/cli/theme.go`.
163
+ */
164
+ interface Theme {
165
+ palette: Palette;
166
+ /** Primary accent — same as `palette.command`. */
167
+ accent: string;
168
+ /** Secondary accent — same as `palette.flag`. */
169
+ secondary: string;
170
+ /** Muted/dim color (CharmTone Squid). */
171
+ muted: string;
172
+ /** Error color (CharmTone Cherry). */
173
+ error: string;
174
+ /** Success color (CharmTone Guac). */
175
+ success: string;
176
+ /** Title/header color — mirrors fang's ColorScheme.Title (#FFFFFF). */
177
+ title: string;
178
+ /** Argument placeholder color — mirrors fang's ColorScheme.Argument (#B5E89B). */
179
+ argument: string;
180
+ /** Dimmed argument color — mirrors fang's ColorScheme.DimmedArgument (#8ABF6E). */
181
+ dimmedArgument: string;
182
+ }
183
+ /**
184
+ * Build a Theme from an optional accent override.
185
+ * When `accent` is provided it replaces `palette.command`; otherwise
186
+ * the Neon palette is used. Mirrors Go's `buildTheme` function.
187
+ */
188
+ declare function buildTheme(accent?: string): Theme;
189
+ /**
190
+ * Configuration passed to {@link createCLI} to identify the program.
191
+ */
192
+ interface CLIConfig {
193
+ /**
194
+ * Binary name as invoked by the user (e.g. `"mytool"`).
195
+ * Used as the Commander program name and in the version string output.
196
+ */
197
+ name: string;
198
+ /**
199
+ * Semver version string (e.g. `"1.2.3"`).
200
+ * Exposed via `-v / --version`; do NOT include a leading `v`.
201
+ */
202
+ version: string;
203
+ /**
204
+ * One-line description shown in help output.
205
+ */
206
+ description: string;
207
+ /**
208
+ * Optional hex color string (e.g. `"#FF0000"`) used as the theme accent.
209
+ * Omit to use the Neon palette default.
210
+ */
211
+ accent?: string;
212
+ /** Opt-out built-in global flags. Zero value = all enabled. */
213
+ disable?: {
214
+ format?: boolean;
215
+ quiet?: boolean;
216
+ noColor?: boolean;
217
+ hints?: boolean;
218
+ };
219
+ /** Command groups for partitioned help (e.g. COMMANDS vs MANAGEMENT). */
220
+ groups?: Array<{
221
+ id: string;
222
+ title: string;
223
+ hidden?: boolean;
224
+ }>;
225
+ /** Extra tool-specific persistent flags on root command. */
226
+ globals?: Array<{
227
+ name: string;
228
+ short?: string;
229
+ usage: string;
230
+ default?: string;
231
+ }>;
232
+ /**
233
+ * Root --help layout overrides.
234
+ * Defaults are loaded from contracts/parity/parity.json.
235
+ */
236
+ help?: {
237
+ /**
238
+ * Appended to `description` as a separate paragraph when non-empty.
239
+ * Empty = no extra block.
240
+ */
241
+ disclaimer?: string;
242
+ /**
243
+ * Section rendering order using fang vocabulary
244
+ * (e.g. `["commands", "flags"]`). Omit to use parity.json default.
245
+ */
246
+ sectionOrder?: string[];
247
+ showAliases?: boolean;
248
+ };
249
+ }
250
+ /**
251
+ * Result of {@link createCLI}.
252
+ */
253
+ interface CLIResult {
254
+ /** Configured Commander root program. */
255
+ program: Command;
256
+ /** Theme derived from the config accent (or Neon default). */
257
+ theme: Theme;
258
+ }
259
+ /** Assign a command to a named group (used in formatHelp partitioning). */
260
+ declare function setCommandGroup(cmd: Command, groupId: string): void;
261
+ /** Retrieve the group ID for a command (undefined = default group). */
262
+ declare function getCommandGroup(cmd: Command): string | undefined;
263
+ /**
264
+ * Apply hop-top brand colors to Commander's help output.
265
+ *
266
+ * Uses Commander's structured Help API (optionTerm, subcommandTerm, etc.)
267
+ * to color each element independently — no regex post-processing on
268
+ * description text.
269
+ *
270
+ * Color mapping (mirrors Go's brandColorScheme):
271
+ * - Section headers: #FFFFFF bold
272
+ * - Flag names: theme.secondary (#FF00FF)
273
+ * - Command names: theme.accent (#7ED957)
274
+ * - Arguments (<angle>): theme.argument (#B5E89B)
275
+ * - Dimmed args ([optional]): theme.dimmedArgument (#8ABF6E)
276
+ * - Descriptions: theme.muted (#858183)
277
+ * - Usage program name: theme.accent
278
+ */
279
+ declare function applyHelpTheme(program: Command, theme: Theme, noColor: boolean, sectionOrder?: string[], showAliases?: boolean, groups?: CLIConfig['groups']): void;
280
+ /**
281
+ * Creates a Commander `Command` (root program) pre-configured to the hop-top CLI contract.
282
+ *
283
+ * Contract enforced by this factory (callers must NOT override these):
284
+ * - No `help` subcommand; -h/--help flag only.
285
+ * - `completion` available as management-group command (hidden by default).
286
+ * - `-v, --version` is a root option (not a subcommand); prints `<name> v<version>` and exits.
287
+ * - Global options added to the returned program:
288
+ * `--format <fmt>` Output format — `"table"` | `"json"` | `"yaml"` (default `"table"`)
289
+ * `--quiet` Suppress non-essential output (boolean, default `false`)
290
+ * `--no-color` Disable ANSI colour (boolean, default `false`)
291
+ * - `showHelpAfterError` is enabled; unknown commands print help to stderr.
292
+ * - Errors are written to stderr in `theme.error` color unless `--no-color` is active.
293
+ *
294
+ * Requires commander ^14. Do not add `-v/--version`, `--format`, `--quiet`, or
295
+ * `--no-color` again on the returned program — they are already registered.
296
+ *
297
+ * @param cfg - Program identity (name, version, description, optional accent). See {@link CLIConfig}.
298
+ * @returns `{ program, theme }` — program ready for sub-commands; theme for TUI components.
299
+ *
300
+ * @example
301
+ * ```ts
302
+ * const { program, theme } = createCLI({ name: 'hop', version: '2.0.0', description: 'hop CLI' });
303
+ * program.command('deploy').action(() => { ... });
304
+ * program.parse();
305
+ * ```
306
+ */
307
+ declare function createCLI(cfg: CLIConfig): CLIResult;
308
+
309
+ export { type CLIConfig, type CLIResult, Dark, type Hint, type HintOptions, HintSet, Neon, type Palette, type Theme, active, applyHelpTheme, buildTheme, channel, createCLI, getCommandGroup, getStreamDefs, hintsEnabled, registerStream, registerUpgradeHints, registerVersionHints, renderHints, setCommandGroup, verboseCount };