@hop-top/kit 0.5.0-alpha.3 → 0.5.0-alpha.5

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 (188) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +1 -1
  3. package/README.md +47 -575
  4. package/dist/{aim-CTp-kJW2.d.ts → aim-DZHwwiIc.d.ts} +1 -1
  5. package/dist/aim.d.ts +1 -1
  6. package/dist/aim.js +13 -414
  7. package/dist/{alias-dhhr08Ei.d.ts → alias-BOj0-VAr.d.ts} +1 -1
  8. package/dist/alias.d.ts +1 -1
  9. package/dist/alias.js +18 -206
  10. package/dist/{api-miiso81x.d.ts → api-DAexsu2H.d.ts} +1 -1
  11. package/dist/api.d.ts +1 -1
  12. package/dist/api.js +10 -164
  13. package/dist/auth.js +6 -40
  14. package/dist/chunk-3FIKGFKI.js +54 -0
  15. package/dist/chunk-4UE5TCMQ.js +104 -0
  16. package/dist/chunk-6HFAEZ52.js +29 -0
  17. package/dist/chunk-6SVOHNIC.js +17 -0
  18. package/dist/chunk-72XZWQX7.js +504 -0
  19. package/dist/chunk-ABQSE7AI.js +513 -0
  20. package/dist/chunk-BDNNPRX6.js +41 -0
  21. package/dist/chunk-BRNEKPWX.js +37 -0
  22. package/dist/chunk-CSJWB6D3.js +151 -0
  23. package/dist/chunk-GGWJRWWA.js +309 -0
  24. package/dist/chunk-IQXEISMC.js +142 -0
  25. package/dist/chunk-IXVQ62NZ.js +334 -0
  26. package/dist/chunk-JTMPNXVQ.js +1491 -0
  27. package/dist/chunk-KVG7YCTS.js +115 -0
  28. package/dist/chunk-L23O2FFE.js +51 -0
  29. package/dist/chunk-MQXYDYRD.js +968 -0
  30. package/dist/chunk-MUIQVU6E.js +251 -0
  31. package/dist/chunk-POR5L2DG.js +247 -0
  32. package/dist/chunk-PSFYJGDG.js +1445 -0
  33. package/dist/chunk-QJVSKKRQ.js +369 -0
  34. package/dist/chunk-QPUCXQXT.js +67 -0
  35. package/dist/chunk-R5U7XKVJ.js +16 -0
  36. package/dist/chunk-S45UHXQF.js +182 -0
  37. package/dist/chunk-T46YPHKN.js +669 -0
  38. package/dist/chunk-UKZIAQA7.js +26 -0
  39. package/dist/chunk-WBVO43HU.js +355 -0
  40. package/dist/chunk-WUOAQVOA.js +86 -0
  41. package/dist/chunk-WWUKGJB5.js +90 -0
  42. package/dist/chunk-YGYQUFGY.js +219 -0
  43. package/dist/chunk-YOBAUCVN.js +583 -0
  44. package/dist/chunk-ZC5TZYZJ.js +609 -0
  45. package/dist/{cli-DLygZLi9.d.ts → cli-8rfITnv4.d.ts} +13 -4
  46. package/dist/cli.d.ts +4 -4
  47. package/dist/cli.js +51 -1057
  48. package/dist/{config-BUY7_W2n.d.ts → config-Bm9fBXch.d.ts} +35 -4
  49. package/dist/config.d.ts +1 -1
  50. package/dist/config.js +6 -78
  51. package/dist/errcorrect.js +8 -68
  52. package/dist/{error-DISJKeDu.d.ts → error-Do8Qji43.d.ts} +88 -1
  53. package/dist/id/index.d.ts +1 -1
  54. package/dist/id/index.js +14 -65
  55. package/dist/{index-MLrRDvEG.d.ts → index-B-pqGHhU.d.ts} +113 -19
  56. package/dist/{index-Bc5c7Ty5.d.ts → index-DEyjGoo2.d.ts} +1 -1
  57. package/dist/{index-QSffbLnj.d.ts → index-VLDcI5NF.d.ts} +3 -2
  58. package/dist/index.d.ts +18 -15
  59. package/dist/index.js +39 -6722
  60. package/dist/llm-DYuR7_uX.d.ts +1069 -0
  61. package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
  62. package/dist/llm-anthropic.d.ts +2 -0
  63. package/dist/llm-anthropic.js +13 -0
  64. package/dist/llm-openai-DyFrucmV.d.ts +87 -0
  65. package/dist/llm-openai.d.ts +2 -0
  66. package/dist/llm-openai.js +19 -0
  67. package/dist/llm.d.ts +1 -1
  68. package/dist/llm.js +101 -356
  69. package/dist/mcp/index.d.ts +2 -1
  70. package/dist/mcp/index.js +155 -1453
  71. package/dist/{netpolicy-asvCfwi8.d.ts → netpolicy-Brx5XZUB.d.ts} +16 -3
  72. package/dist/netpolicy.d.ts +1 -1
  73. package/dist/netpolicy.js +25 -118
  74. package/dist/{output-4aXs91GY.d.ts → output-CjZWmL8s.d.ts} +28 -4
  75. package/dist/output.d.ts +2 -2
  76. package/dist/output.js +137 -971
  77. package/dist/progress.js +6 -55
  78. package/dist/provenance.js +6 -31
  79. package/dist/routellm-B0nv59mH.d.ts +111 -0
  80. package/dist/routellm.d.ts +2 -2
  81. package/dist/routellm.js +13 -255
  82. package/dist/{rpc-D5xLEf8V.d.ts → rpc-D31Lg0Kc.d.ts} +1 -1
  83. package/dist/rpc.d.ts +2 -2
  84. package/dist/rpc.js +4 -98
  85. package/dist/safety.js +6 -43
  86. package/dist/scope.js +20 -377
  87. package/dist/{serve-DE-jscpb.d.ts → serve-D8yWMrTc.d.ts} +2 -2
  88. package/dist/serve.d.ts +2 -2
  89. package/dist/serve.js +75 -1019
  90. package/dist/sqlstore.js +6 -39
  91. package/dist/stream.js +8 -51
  92. package/dist/telemetry/index.js +24 -608
  93. package/dist/tui/index.d.ts +5 -5
  94. package/dist/tui/index.js +17 -374
  95. package/dist/upgrade.js +6 -114
  96. package/dist/xdg.js +14 -128
  97. package/package.json +130 -25
  98. package/src/README.md +15 -0
  99. package/src/cli.help-command.test.ts +105 -0
  100. package/src/cli.test.ts +95 -1
  101. package/src/cli.ts +78 -13
  102. package/src/completion-values.test.ts +10 -10
  103. package/src/compliance.test.ts +196 -2
  104. package/src/compliance.ts +440 -20
  105. package/src/config.test.ts +187 -1
  106. package/src/config.ts +173 -7
  107. package/src/gen/crud_pb.ts +7 -7
  108. package/src/id/README.md +38 -0
  109. package/src/id/contract.test.ts +1 -1
  110. package/src/id/index.test.ts +1 -1
  111. package/src/id/index.ts +3 -2
  112. package/src/index.test.ts +12 -0
  113. package/src/index.ts +2 -0
  114. package/src/llm-anthropic.conformance.test.ts +1135 -0
  115. package/src/llm-anthropic.test.ts +152 -0
  116. package/src/llm-anthropic.ts +940 -0
  117. package/src/llm-choice-hermetic.test.ts +335 -0
  118. package/src/llm-config.test.ts +232 -0
  119. package/src/llm-config.ts +106 -0
  120. package/src/llm-endpoint.ts +254 -0
  121. package/src/llm-error.ts +17 -0
  122. package/src/llm-errors.ts +152 -0
  123. package/src/llm-file.ts +126 -0
  124. package/src/llm-http.ts +317 -0
  125. package/src/llm-keys.ts +167 -0
  126. package/src/llm-media.conformance.test.ts +87 -0
  127. package/src/llm-media.test.ts +279 -0
  128. package/src/llm-media.ts +322 -0
  129. package/src/llm-openai.conformance.test.ts +407 -0
  130. package/src/llm-openai.test.ts +510 -0
  131. package/src/llm-openai.ts +708 -0
  132. package/src/llm-payload.ts +155 -0
  133. package/src/llm-quote.ts +46 -0
  134. package/src/llm-routellm.conformance.test.ts +44 -0
  135. package/src/llm-toolnames.conformance.test.ts +112 -0
  136. package/src/llm-toolnames.test.ts +132 -0
  137. package/src/llm-toolnames.ts +298 -0
  138. package/src/llm-uri.ts +99 -0
  139. package/src/llm.test.ts +43 -15
  140. package/src/llm.toolcall.test.ts +175 -0
  141. package/src/llm.ts +602 -190
  142. package/src/mcp/README.md +57 -0
  143. package/src/mcp/conformance.test.ts +24 -3
  144. package/src/mcp/dispatch.ts +4 -4
  145. package/src/mcp/identity.test.ts +166 -0
  146. package/src/mcp/identity.ts +72 -0
  147. package/src/mcp/index.ts +6 -0
  148. package/src/mcp/legacy.ts +21 -8
  149. package/src/mcp/mcp.test.ts +14 -4
  150. package/src/mcp/modern-confirm.ts +1 -1
  151. package/src/mcp/modern.ts +12 -11
  152. package/src/mcp/tasks.ts +1 -1
  153. package/src/mcp/types.ts +80 -8
  154. package/src/netpolicy.test.ts +78 -0
  155. package/src/netpolicy.ts +28 -3
  156. package/src/output/README.md +46 -0
  157. package/src/output/builtins.ts +5 -5
  158. package/src/output/error.ts +144 -1
  159. package/src/output/formatters/README.md +50 -0
  160. package/src/output.ts +24 -1
  161. package/src/published-types.test.ts +115 -0
  162. package/src/routellm.test.ts +209 -28
  163. package/src/routellm.toolcall.test.ts +521 -0
  164. package/src/routellm.ts +213 -177
  165. package/src/router/README.md +44 -0
  166. package/src/router/server.test.ts +41 -0
  167. package/src/router/server.ts +11 -0
  168. package/src/safety.test.ts +19 -9
  169. package/src/scope-defaults.json +29 -29
  170. package/src/serve.ts +1 -1
  171. package/src/telemetry/README.md +48 -0
  172. package/src/telemetry/client.ts +5 -5
  173. package/src/toolspec.test.ts +2 -2
  174. package/src/triton/README.md +34 -0
  175. package/src/tui/README.md +42 -0
  176. package/src/wizard.test.ts +7 -7
  177. package/test/llm/conformance-helpers.ts +100 -0
  178. package/test/output/dispatch.test.ts +1 -2
  179. package/test/output/error.test.ts +33 -2
  180. package/test/output/smoke-capture.ts +2 -2
  181. package/test/output/smoke.test.ts +2 -2
  182. package/test/output/taxonomy-contract.test.ts +148 -0
  183. package/test/setup-env.ts +16 -0
  184. package/tsconfig.json +3 -1
  185. package/tsconfig.test.json +10 -0
  186. package/vitest.config.ts +9 -0
  187. package/dist/llm-B5XUWH8T.d.ts +0 -231
  188. package/dist/routellm-PGSt2D1y.d.ts +0 -75
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hop-top/kit",
3
- "version": "0.5.0-alpha.3",
3
+ "version": "0.5.0-alpha.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hop-top/poly-kit.git",
@@ -51,6 +51,16 @@
51
51
  "require": "./dist/llm.js",
52
52
  "default": "./dist/llm.js"
53
53
  },
54
+ "./anthropic": {
55
+ "types": "./dist/llm-anthropic.d.ts",
56
+ "require": "./dist/llm-anthropic.js",
57
+ "default": "./dist/llm-anthropic.js"
58
+ },
59
+ "./openai": {
60
+ "types": "./dist/llm-openai.d.ts",
61
+ "require": "./dist/llm-openai.js",
62
+ "default": "./dist/llm-openai.js"
63
+ },
54
64
  "./routellm": {
55
65
  "types": "./dist/routellm.d.ts",
56
66
  "require": "./dist/routellm.js",
@@ -142,47 +152,142 @@
142
152
  "default": "./dist/mcp/index.js"
143
153
  }
144
154
  },
155
+ "typesVersions": {
156
+ "*": {
157
+ "cli": [
158
+ "./dist/cli.d.ts"
159
+ ],
160
+ "output": [
161
+ "./dist/output.d.ts"
162
+ ],
163
+ "xdg": [
164
+ "./dist/xdg.d.ts"
165
+ ],
166
+ "config": [
167
+ "./dist/config.d.ts"
168
+ ],
169
+ "sqlstore": [
170
+ "./dist/sqlstore.d.ts"
171
+ ],
172
+ "upgrade": [
173
+ "./dist/upgrade.d.ts"
174
+ ],
175
+ "llm": [
176
+ "./dist/llm.d.ts"
177
+ ],
178
+ "anthropic": [
179
+ "./dist/llm-anthropic.d.ts"
180
+ ],
181
+ "openai": [
182
+ "./dist/llm-openai.d.ts"
183
+ ],
184
+ "routellm": [
185
+ "./dist/routellm.d.ts"
186
+ ],
187
+ "alias": [
188
+ "./dist/alias.d.ts"
189
+ ],
190
+ "tui": [
191
+ "./dist/tui/index.d.ts"
192
+ ],
193
+ "errcorrect": [
194
+ "./dist/errcorrect.d.ts"
195
+ ],
196
+ "safety": [
197
+ "./dist/safety.d.ts"
198
+ ],
199
+ "provenance": [
200
+ "./dist/provenance.d.ts"
201
+ ],
202
+ "stream": [
203
+ "./dist/stream.d.ts"
204
+ ],
205
+ "progress": [
206
+ "./dist/progress.d.ts"
207
+ ],
208
+ "auth": [
209
+ "./dist/auth.d.ts"
210
+ ],
211
+ "api": [
212
+ "./dist/api.d.ts"
213
+ ],
214
+ "rpc": [
215
+ "./dist/rpc.d.ts"
216
+ ],
217
+ "aim": [
218
+ "./dist/aim.d.ts"
219
+ ],
220
+ "netpolicy": [
221
+ "./dist/netpolicy.d.ts"
222
+ ],
223
+ "scope": [
224
+ "./dist/scope.d.ts"
225
+ ],
226
+ "serve": [
227
+ "./dist/serve.d.ts"
228
+ ],
229
+ "telemetry": [
230
+ "./dist/telemetry/index.d.ts"
231
+ ],
232
+ "id": [
233
+ "./dist/id/index.d.ts"
234
+ ],
235
+ "mcp": [
236
+ "./dist/mcp/index.d.ts"
237
+ ]
238
+ }
239
+ },
240
+ "peerDependencies": {
241
+ "@types/better-sqlite3": "^7.6.13"
242
+ },
243
+ "peerDependenciesMeta": {
244
+ "@types/better-sqlite3": {
245
+ "optional": true
246
+ }
247
+ },
145
248
  "dependencies": {
146
- "@bufbuild/protobuf": "^2.11.0",
147
- "@clack/prompts": "^1.2.0",
148
- "@connectrpc/connect": "^2.1.1",
149
- "@connectrpc/connect-web": "^2.1.1",
150
- "@hop-top/cite": "^0.1.0",
151
- "@modelcontextprotocol/core": "2.0.0",
152
- "@modelcontextprotocol/server": "2.0.0",
153
- "better-sqlite3": "^12.8.0",
154
- "commander": "^14.0.3",
155
- "csv-stringify": "^6.7.0",
249
+ "@bufbuild/protobuf": "^2.16.0",
250
+ "@clack/prompts": "^1.8.1",
251
+ "@connectrpc/connect": "^2.2.0",
252
+ "@connectrpc/connect-web": "^2.2.0",
253
+ "@hop-top/cite": "^0.1.2",
254
+ "@modelcontextprotocol/core": "2.3.1",
255
+ "@modelcontextprotocol/server": "2.3.1",
256
+ "better-sqlite3": "^12.11.1",
257
+ "commander": "^15.0.0",
258
+ "csv-stringify": "^6.9.0",
156
259
  "eta": "^4.6.0",
157
- "hono": "^4.12.10",
158
- "js-yaml": "^4.1.1",
159
- "picomatch": "^4.0.4",
160
- "pino": "^10.3.1",
161
- "semver": "^7.7.4",
260
+ "hono": "^4.13.13",
261
+ "js-yaml": "^4.3.2",
262
+ "picomatch": "^4.0.7",
263
+ "pino": "^10.4.0",
264
+ "semver": "^7.8.5",
162
265
  "typeid-js": "^1.2.0",
163
- "zod": "^4.4.3"
266
+ "zod": "^4.6.7"
164
267
  },
165
268
  "devDependencies": {
166
269
  "@types/better-sqlite3": "^7.6.13",
167
270
  "@types/js-yaml": "^4.0.9",
168
- "@types/node": "^20",
271
+ "@types/node": "^24",
169
272
  "@types/picomatch": "^4.0.3",
170
- "@types/semver": "^7.7.1",
171
- "esbuild": "^0.25.12",
172
- "eslint": "^10.2.0",
273
+ "@types/semver": "^7.8.0",
274
+ "esbuild": "^0.28.2",
275
+ "eslint": "^10.12.0",
173
276
  "tsup": "^8",
174
277
  "typescript": "^5",
175
- "typescript-eslint": "^8.58.0",
176
- "vitest": "^1"
278
+ "typescript-eslint": "^8.71.2",
279
+ "vite": "^8.3.4",
280
+ "vitest": "^5.0.4"
177
281
  },
178
282
  "engines": {
179
- "node": ">=20"
283
+ "node": ">=22.12"
180
284
  },
181
285
  "license": "MIT",
182
286
  "scripts": {
183
- "build": "tsup src/index.ts src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/netpolicy.ts src/scope.ts src/serve.ts src/telemetry/index.ts src/id/index.ts src/mcp/index.ts --format cjs --dts",
287
+ "build": "tsup src/index.ts src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/llm-anthropic.ts src/llm-openai.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/netpolicy.ts src/scope.ts src/serve.ts src/telemetry/index.ts src/id/index.ts src/mcp/index.ts --format cjs --splitting --dts",
184
288
  "lint": "eslint src/",
185
289
  "lint:fix": "eslint src/ --fix",
290
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc -p tsconfig.test.json",
186
291
  "test": "vitest run"
187
292
  }
188
293
  }
package/src/README.md CHANGED
@@ -1,3 +1,18 @@
1
1
  # src
2
2
 
3
3
  TypeScript implementation source files.
4
+
5
+ ## Contents
6
+
7
+ | Path | What it is | Start here when |
8
+ |------|------------|-----------------|
9
+ | [`id/`](id/README.md) | TypeID primitive, cross-language wire form | you mint or parse entity ids |
10
+ | [`mcp/`](mcp/README.md) | dual-spec MCP surface, framework-free handler | you serve a Commander tree to MCP clients |
11
+ | [`output/`](output/README.md) | formatter registry, output flag suite, error envelope | a command renders structured data |
12
+ | [`output/formatters/`](output/formatters/README.md) | built-in json, yaml, table, csv, text | you need one formatter or add one |
13
+ | [`router/`](router/README.md) | RouteLLM scorers, `Controller`, Hono handler (not exported) | you route prompts between strong and weak models |
14
+ | [`telemetry/`](telemetry/README.md) | mode gate, install id, consent, redactor, `Client` | you emit usage telemetry |
15
+ | [`triton/`](triton/README.md) | KServe v2 HTTP client (not exported) | you call a Triton-hosted model |
16
+ | [`tui/`](tui/README.md) | status, badge, spinner, progress, prompts | a TTY needs styled widgets |
17
+ | `gen/` | generated Connect stubs, do not edit | never; regenerate instead |
18
+ | top-level modules (`cli.ts`, `serve.ts`, `scope.ts`, ...) | single-file ports, one per package export | see [`../README.md`](../README.md), section "Other modules" |
@@ -0,0 +1,105 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { CommanderError } from 'commander';
3
+ import { createCLI, setCommandGroup } from './cli';
4
+
5
+ // "help <operand...>" resolution, matching the Go root's order:
6
+ // "all", then a fully-resolved command path, then a group ID, else a
7
+ // usage error (exit 2). A command wins over a group of the same name.
8
+
9
+ const ANSI = /\x1b\[[0-9;]*m/g;
10
+
11
+ interface Run { out: string; err: string; code: number }
12
+
13
+ function makeCLI() {
14
+ const { program } = createCLI({
15
+ name: 'prog', version: '1.0.0', description: 'root desc',
16
+ groups: [
17
+ { id: 'management', title: 'MANAGEMENT', hidden: true },
18
+ { id: 'extras', title: 'EXTRAS' },
19
+ ],
20
+ });
21
+ let out = '';
22
+ let err = '';
23
+ program.exitOverride();
24
+ program.configureOutput({
25
+ writeOut: (s: string) => { out += s; },
26
+ writeErr: (s: string) => { err += s; },
27
+ });
28
+ program.command('map').alias('mp').description('Map things')
29
+ .option('--deep', 'Map recursively');
30
+ const remote = program.command('remote').description('Manage remotes');
31
+ remote.command('add').description('Add a remote')
32
+ .option('--fetch', 'Fetch after adding');
33
+ setCommandGroup(program.command('config').description('Manage config'), 'management');
34
+ // Command sharing its name with a group ID.
35
+ program.command('extras').description('Extras command');
36
+ return {
37
+ program,
38
+ run(args: string[]): Run {
39
+ let code = -1;
40
+ // Group help is signalled through process.argv; keep it local.
41
+ const argv = process.argv;
42
+ process.argv = [...argv];
43
+ try {
44
+ program.parse(args, { from: 'user' });
45
+ code = 0;
46
+ } catch (e) {
47
+ if (!(e instanceof CommanderError)) throw e;
48
+ code = e.exitCode;
49
+ } finally {
50
+ process.argv = argv;
51
+ }
52
+ return { out: out.replace(ANSI, ''), err: err.replace(ANSI, ''), code };
53
+ },
54
+ };
55
+ }
56
+
57
+ describe('help <command> subcommand', () => {
58
+ it('help <command> prints that command\'s help, not root help', () => {
59
+ const r = makeCLI().run(['help', 'map']);
60
+ expect(r.code).toBe(0);
61
+ expect(r.out).toContain('Usage: prog map');
62
+ expect(r.out).toContain('--deep');
63
+ expect(r.out).not.toContain('COMMANDS:');
64
+ });
65
+
66
+ it('help <alias> resolves to the aliased command', () => {
67
+ const r = makeCLI().run(['help', 'mp']);
68
+ expect(r.code).toBe(0);
69
+ expect(r.out).toContain('Usage: prog map');
70
+ });
71
+
72
+ it('help <a> <b> prints nested command help', () => {
73
+ const r = makeCLI().run(['help', 'remote', 'add']);
74
+ expect(r.code).toBe(0);
75
+ expect(r.out).toContain('Usage: prog remote add');
76
+ expect(r.out).toContain('--fetch');
77
+ });
78
+
79
+ it('help <group> still prints group help', () => {
80
+ const r = makeCLI().run(['help', 'management']);
81
+ expect(r.code).toBe(0);
82
+ expect(r.out).toContain('MANAGEMENT:');
83
+ expect(r.out).toContain('config');
84
+ });
85
+
86
+ it('command wins over a group of the same name', () => {
87
+ const r = makeCLI().run(['help', 'extras']);
88
+ expect(r.code).toBe(0);
89
+ expect(r.out).toContain('Usage: prog extras');
90
+ expect(r.out).not.toContain('EXTRAS:');
91
+ });
92
+
93
+ it('unknown topic is a usage error (exit 2)', () => {
94
+ const r = makeCLI().run(['help', 'nosuch']);
95
+ expect(r.code).toBe(2);
96
+ expect(r.err).toContain('unknown help topic \'nosuch\'');
97
+ expect(r.out).not.toContain('Usage: prog');
98
+ });
99
+
100
+ it('partial path is a usage error, not parent help', () => {
101
+ const r = makeCLI().run(['help', 'remote', 'nosuch']);
102
+ expect(r.code).toBe(2);
103
+ expect(r.err).toContain('unknown help topic \'remote nosuch\'');
104
+ });
105
+ });
package/src/cli.test.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, afterEach } from 'vitest';
2
2
  import { createCLI, buildTheme, applyHelpTheme, Neon, Dark,
3
- setCommandGroup, verboseCount, registerStream,
3
+ setCommandGroup, verboseCount, isQuiet, registerStream,
4
4
  channel, getStreamDefs } from './cli';
5
5
 
6
6
  describe('createCLI', () => {
@@ -247,6 +247,45 @@ describe('help structure — line-by-line parity', () => {
247
247
  });
248
248
  });
249
249
 
250
+ describe('help ARGUMENTS section', () => {
251
+ /** Plain help lines for a `gen` command with the given arguments. */
252
+ function genHelpLines(withDescriptions: boolean): string[] {
253
+ const { program } = createCLI({ name: 'mytool', version: '1.2.3', description: 'A tool' });
254
+ const gen = program.command('gen').description('Generate');
255
+ if (withDescriptions) {
256
+ gen.argument('<shell>', 'shell to generate for')
257
+ .argument('[out]', 'output path');
258
+ } else {
259
+ gen.argument('<shell>').argument('[out]');
260
+ }
261
+ gen.option('--force', 'overwrite');
262
+ return stripANSI(gen.helpInformation()).split('\n');
263
+ }
264
+
265
+ it('lists described arguments with their descriptions', () => {
266
+ const lines = genHelpLines(true);
267
+ const argIdx = lines.findIndex(l => l.trim() === 'ARGUMENTS:');
268
+ expect(argIdx).toBeGreaterThanOrEqual(0);
269
+ expect(lines[argIdx + 1]).toMatch(/^\s+shell\s+shell to generate for$/);
270
+ expect(lines[argIdx + 2]).toMatch(/^\s+out\s+output path$/);
271
+ });
272
+
273
+ it('ARGUMENTS: appears after the description and before FLAGS:', () => {
274
+ const lines = genHelpLines(true);
275
+ const descIdx = lines.findIndex(l => l.trim() === 'Generate');
276
+ const argIdx = lines.findIndex(l => l.trim() === 'ARGUMENTS:');
277
+ const flagIdx = lines.findIndex(l => l.trim() === 'FLAGS:');
278
+ expect(descIdx).toBeLessThan(argIdx);
279
+ expect(argIdx).toBeLessThan(flagIdx);
280
+ });
281
+
282
+ it('omits ARGUMENTS: when no argument has a description', () => {
283
+ const lines = genHelpLines(false);
284
+ expect(lines.some(l => l.trim() === 'ARGUMENTS:')).toBe(false);
285
+ expect(lines.some(l => l.trim() === 'Arguments:')).toBe(false);
286
+ });
287
+ });
288
+
250
289
  describe('CLIConfig disable', () => {
251
290
  it('disable.format=true → no format key in opts after parse', () => {
252
291
  const { program } = createCLI({
@@ -608,6 +647,61 @@ describe('verbose flag', () => {
608
647
  });
609
648
  });
610
649
 
650
+ // ---------------------------------------------------------------------------
651
+ // Quiet accessor
652
+ // ---------------------------------------------------------------------------
653
+
654
+ describe('isQuiet', () => {
655
+ async function quietOf(argv: string[], disableQuiet = false): Promise<boolean | undefined> {
656
+ const { program } = createCLI({
657
+ name: 't', version: '0.1.0', description: 't',
658
+ disable: { quiet: disableQuiet },
659
+ });
660
+ let quiet: boolean | undefined;
661
+ program.command('run').action(function (this: any) {
662
+ quiet = isQuiet(this);
663
+ });
664
+ await program.parseAsync(['node', 't', ...argv]);
665
+ return quiet;
666
+ }
667
+
668
+ it('is false before parsing', () => {
669
+ const { program } = createCLI({ name: 't', version: '0.1.0', description: 't' });
670
+ const run = program.command('run');
671
+ expect(isQuiet(program)).toBe(false);
672
+ expect(isQuiet(run)).toBe(false);
673
+ });
674
+
675
+ it('is false when --quiet is absent', async () => {
676
+ expect(await quietOf(['run'])).toBe(false);
677
+ });
678
+
679
+ it('reads root --quiet from a subcommand', async () => {
680
+ expect(await quietOf(['--quiet', 'run'])).toBe(true);
681
+ });
682
+
683
+ it('reads root --quiet given after the subcommand', async () => {
684
+ expect(await quietOf(['run', '--quiet'])).toBe(true);
685
+ });
686
+
687
+ it('is false when the flag is disabled', async () => {
688
+ expect(await quietOf(['run'], true)).toBe(false);
689
+ });
690
+
691
+ it('wins over -V: quiet reported, verbose count 0', async () => {
692
+ const { program } = createCLI({ name: 't', version: '0.1.0', description: 't' });
693
+ let quiet: boolean | undefined;
694
+ let count = -1;
695
+ program.command('run').action(function (this: any) {
696
+ quiet = isQuiet(this);
697
+ count = verboseCount(this);
698
+ });
699
+ await program.parseAsync(['node', 't', '-VV', '--quiet', 'run']);
700
+ expect(quiet).toBe(true);
701
+ expect(count).toBe(0);
702
+ });
703
+ });
704
+
611
705
  // ---------------------------------------------------------------------------
612
706
  // Named streams
613
707
  // ---------------------------------------------------------------------------
package/src/cli.ts CHANGED
@@ -28,6 +28,7 @@
28
28
  import { Command, Help } from 'commander';
29
29
  import { parity, type ParityData } from './tui/parity.js';
30
30
  import { registerOutputFlags } from './output/flags.js';
31
+ import { EXIT_USAGE } from './output/error.js';
31
32
  import { install as installNetPolicy, setProcessOffline } from './netpolicy.js';
32
33
  import './output/builtins.js';
33
34
  export { ErrOffline, OfflineError, guardFetch, isOffline, isOfflineError,
@@ -37,10 +38,11 @@ export { HintSet, hintsEnabled, renderHints, active,
37
38
  export type { Hint, HintOptions } from './hint.js';
38
39
 
39
40
  // ---------------------------------------------------------------------------
40
- // Verbose count — stacking -V flags
41
+ // Verbose count — stacking -V flags; quiet
41
42
  // ---------------------------------------------------------------------------
42
43
 
43
44
  const verboseCountMap = new WeakMap<Command, number>();
45
+ const quietMap = new WeakMap<Command, boolean>();
44
46
 
45
47
  /**
46
48
  * Return the single-character shorthand declared by the parity contract's
@@ -77,6 +79,24 @@ export function verboseCount(cmd: Command): number {
77
79
  return 0;
78
80
  }
79
81
 
82
+ /**
83
+ * Report whether `--quiet` is in effect for a parsed command tree.
84
+ *
85
+ * `--quiet` wins over `-V`: when set, `verboseCount` reads 0 and the
86
+ * logger level is the contract's `verbosity.quiet_override`. False before
87
+ * parsing and when `disable.quiet` drops the flag.
88
+ */
89
+ export function isQuiet(cmd: Command): boolean {
90
+ // Walk up to root to find the stored flag.
91
+ let c: Command | null = cmd;
92
+ while (c) {
93
+ const q = quietMap.get(c);
94
+ if (q !== undefined) return q;
95
+ c = c.parent ?? null;
96
+ }
97
+ return false;
98
+ }
99
+
80
100
  // ---------------------------------------------------------------------------
81
101
  // Named streams — registerStream / channel
82
102
  // ---------------------------------------------------------------------------
@@ -537,6 +557,21 @@ export function applyHelpTheme(
537
557
  output.push('');
538
558
  }
539
559
 
560
+ // Arguments — only listed when at least one carries a description
561
+ // (Commander's visibleArguments rule); title from parity.json.
562
+ const argList = helper.visibleArguments(cmd);
563
+ if (argList.length > 0) {
564
+ const title = parity.help.sections?.['arguments']?.title ?? 'ARGUMENTS';
565
+ output.push(helper.styleTitle(`${title}:`));
566
+ for (const a of argList) {
567
+ output.push(callFormatItem(
568
+ helper.styleArgumentTerm(helper.argumentTerm(a)),
569
+ helper.styleArgumentDescription(helper.argumentDescription(a)),
570
+ ));
571
+ }
572
+ output.push('');
573
+ }
574
+
540
575
  // Collect sections in parity order.
541
576
  const helpSections: { name: string; items: string[] }[] = [];
542
577
 
@@ -672,6 +707,22 @@ export function applyHelpTheme(
672
707
  });
673
708
  }
674
709
 
710
+ /**
711
+ * Resolves operands as a command path below root, matching names and
712
+ * aliases. Only a fully-resolved path counts: "remote nosuch" names no
713
+ * command rather than falling back to "remote".
714
+ */
715
+ function findHelpTarget(root: Command, operands: string[]): Command | undefined {
716
+ let cmd: Command | undefined;
717
+ let scope = root;
718
+ for (const word of operands) {
719
+ cmd = scope.commands.find(c => c.name() === word || c.aliases().includes(word));
720
+ if (!cmd) return undefined;
721
+ scope = cmd;
722
+ }
723
+ return cmd;
724
+ }
725
+
675
726
  // ---------------------------------------------------------------------------
676
727
  // Factory
677
728
  // ---------------------------------------------------------------------------
@@ -768,11 +819,12 @@ export function createCLI(cfg: CLIConfig): CLIResult {
768
819
  verbosityFlagSpec(parity), 'Increase verbosity',
769
820
  (_: string, prev: number) => prev + 1, 0,
770
821
  );
771
- // Store count after parse; quiet overrides verbose.
822
+ // Store count + quiet after parse; quiet overrides verbose.
772
823
  program.hook('preAction', (thisCmd) => {
773
824
  const opts = thisCmd.opts();
774
- const count = opts.quiet ? 0 : (opts.verbose ?? 0);
775
- verboseCountMap.set(thisCmd, count);
825
+ const quiet = opts.quiet === true;
826
+ quietMap.set(thisCmd, quiet);
827
+ verboseCountMap.set(thisCmd, quiet ? 0 : (opts.verbose ?? 0));
776
828
  });
777
829
 
778
830
  if (cfg.groups?.some(g => g.hidden)) {
@@ -790,21 +842,34 @@ export function createCLI(cfg: CLIConfig): CLIResult {
790
842
  });
791
843
  }
792
844
 
793
- // help <group> subcommand (hidden from default help).
845
+ // help [command | group] subcommand (hidden from default help).
846
+ // Operands resolve in order: "all", a fully-resolved command path
847
+ // (a command wins over a group of the same name), a group ID; else a
848
+ // usage error (exit 2).
794
849
  if (cfg.groups && cfg.groups.length > 0) {
795
850
  const groupIds = cfg.groups.map(g => g.id);
796
- const helpCmd = program.command('help [group]')
797
- .description('Show help for a command group')
798
- .action((group?: string) => {
799
- if (group === 'all') {
800
- process.argv.push('--help-all');
851
+ const helpCmd = program.command('help [operands...]')
852
+ .description('Show help for a command or command group')
853
+ .action((operands: string[]) => {
854
+ if (operands.length === 0) {
801
855
  program.help();
802
- } else if (group && groupIds.includes(group)) {
803
- process.argv.push(`--help-${group}`);
856
+ }
857
+ if (operands.length === 1 && operands[0] === 'all') {
858
+ process.argv.push('--help-all');
804
859
  program.help();
805
- } else {
860
+ }
861
+ const target = findHelpTarget(program, operands);
862
+ if (target) {
863
+ target.help();
864
+ }
865
+ if (operands.length === 1 && groupIds.includes(operands[0]!)) {
866
+ process.argv.push(`--help-${operands[0]}`);
806
867
  program.help();
807
868
  }
869
+ program.error(
870
+ `error: unknown help topic '${operands.join(' ')}' for '${program.name()}'`,
871
+ { exitCode: EXIT_USAGE, code: 'commander.unknownCommand' },
872
+ );
808
873
  });
809
874
  // Hide from default help output.
810
875
  (helpCmd as any).hideHelp = true;
@@ -112,35 +112,35 @@ describe('prefixedCompleter', () => {
112
112
  });
113
113
 
114
114
  describe('configKeysCompleter', () => {
115
- it('returns top-level keys', () => {
115
+ it('returns top-level keys', async () => {
116
116
  const c = configKeysCompleter({ name: 'x', version: '1', debug: true });
117
- const items = c.complete('');
117
+ const items = await c.complete('');
118
118
  const values = items.map((i: CompletionItem) => i.value);
119
119
  expect(values).toContain('name');
120
120
  expect(values).toContain('version');
121
121
  expect(values).toContain('debug');
122
122
  });
123
123
 
124
- it('returns nested keys with dot notation', () => {
124
+ it('returns nested keys with dot notation', async () => {
125
125
  const c = configKeysCompleter({ db: { host: 'localhost', port: 5432 } });
126
- const items = c.complete('db.');
126
+ const items = await c.complete('db.');
127
127
  const values = items.map((i: CompletionItem) => i.value);
128
128
  expect(values).toContain('db.host');
129
129
  expect(values).toContain('db.port');
130
130
  });
131
131
 
132
- it('filters by prefix', () => {
132
+ it('filters by prefix', async () => {
133
133
  const c = configKeysCompleter({ name: 'x', namespace: 'y', version: '1' });
134
- const items = c.complete('na');
134
+ const items = await c.complete('na');
135
135
  const values = items.map((i: CompletionItem) => i.value);
136
136
  expect(values).toEqual(['name', 'namespace']);
137
137
  });
138
138
  });
139
139
 
140
140
  describe('fileCompleter', () => {
141
- it('returns items with value field', () => {
141
+ it('returns items with value field', async () => {
142
142
  const c = fileCompleter('.ts', '.js');
143
- const items = c.complete('');
143
+ const items = await c.complete('');
144
144
  // file completer returns a marker item for shell-level file completion
145
145
  expect(items.length).toBeGreaterThanOrEqual(1);
146
146
  expect(items[0]).toHaveProperty('value');
@@ -148,9 +148,9 @@ describe('fileCompleter', () => {
148
148
  });
149
149
 
150
150
  describe('dirCompleter', () => {
151
- it('returns items with value field', () => {
151
+ it('returns items with value field', async () => {
152
152
  const c = dirCompleter();
153
- const items = c.complete('');
153
+ const items = await c.complete('');
154
154
  expect(items.length).toBeGreaterThanOrEqual(1);
155
155
  expect(items[0]).toHaveProperty('value');
156
156
  });