@hop-top/kit 0.5.0-alpha.2 → 0.5.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/LICENSE +1 -1
- package/README.md +48 -480
- package/dist/{aim-CTp-kJW2.d.ts → aim-DZHwwiIc.d.ts} +1 -1
- package/dist/aim.d.ts +1 -1
- package/dist/aim.js +13 -414
- package/dist/{alias-dhhr08Ei.d.ts → alias-BOj0-VAr.d.ts} +1 -1
- package/dist/alias.d.ts +1 -1
- package/dist/alias.js +18 -206
- package/dist/{api-miiso81x.d.ts → api-DAexsu2H.d.ts} +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +10 -164
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-72XZWQX7.js +504 -0
- package/dist/chunk-ABQSE7AI.js +513 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-GGWJRWWA.js +309 -0
- package/dist/chunk-IQXEISMC.js +142 -0
- package/dist/chunk-JTMPNXVQ.js +1491 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-MUIQVU6E.js +251 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-PSFYJGDG.js +1445 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QPUCXQXT.js +67 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-S45UHXQF.js +182 -0
- package/dist/chunk-T46YPHKN.js +669 -0
- package/dist/chunk-UIOOOK6M.js +334 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WTYDHXPW.js +574 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-WWUKGJB5.js +90 -0
- package/dist/chunk-YGYQUFGY.js +219 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/{cli-DgOEOsPB.d.ts → cli-8rfITnv4.d.ts} +13 -4
- package/dist/cli.d.ts +4 -3
- package/dist/cli.js +50 -1056
- package/dist/{config-BUY7_W2n.d.ts → config-Bm9fBXch.d.ts} +35 -4
- package/dist/config.d.ts +1 -1
- package/dist/config.js +6 -78
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +1 -1
- package/dist/id/index.js +14 -65
- package/dist/{index-MLrRDvEG.d.ts → index-B-pqGHhU.d.ts} +113 -19
- package/dist/{index--C7Mtsmm.d.ts → index-DEyjGoo2.d.ts} +1 -1
- package/dist/{index-QSffbLnj.d.ts → index-VLDcI5NF.d.ts} +3 -2
- package/dist/index.d.ts +18 -13
- package/dist/index.js +40 -5792
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -1
- package/dist/llm.js +101 -356
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +155 -1453
- package/dist/{netpolicy-asvCfwi8.d.ts → netpolicy-Brx5XZUB.d.ts} +16 -3
- package/dist/netpolicy.d.ts +1 -1
- package/dist/netpolicy.js +25 -118
- package/dist/{output-VFFLqor9.d.ts → output-CjZWmL8s.d.ts} +29 -130
- package/dist/output.d.ts +2 -1
- package/dist/output.js +137 -958
- package/dist/progress.js +6 -55
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -2
- package/dist/routellm.js +13 -255
- package/dist/{rpc-D5xLEf8V.d.ts → rpc-D31Lg0Kc.d.ts} +1 -1
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.js +4 -98
- package/dist/safety.js +6 -43
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.js +24 -608
- package/dist/tui/index.d.ts +5 -4
- package/dist/tui/index.js +17 -373
- package/dist/upgrade.js +6 -114
- package/dist/xdg.js +14 -128
- package/package.json +135 -25
- package/src/README.md +15 -0
- package/src/cli.test.ts +56 -1
- package/src/cli.ts +24 -4
- package/src/completion-values.test.ts +10 -10
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config.test.ts +187 -1
- package/src/config.ts +173 -7
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +12 -0
- package/src/index.ts +3 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/mcp/README.md +57 -0
- package/src/mcp/conformance.test.ts +24 -3
- package/src/mcp/dispatch.ts +4 -4
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +6 -0
- package/src/mcp/legacy.ts +21 -8
- package/src/mcp/mcp.test.ts +14 -4
- package/src/mcp/modern-confirm.ts +1 -1
- package/src/mcp/modern.ts +12 -11
- package/src/mcp/tasks.ts +1 -1
- package/src/mcp/types.ts +80 -8
- package/src/netpolicy.test.ts +78 -0
- package/src/netpolicy.ts +28 -3
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/error.ts +167 -1
- package/src/output/formatters/README.md +50 -0
- package/src/output.ts +26 -1
- package/src/published-types.test.ts +115 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.ts +5 -5
- package/src/toolspec.test.ts +2 -2
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +38 -2
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/dist/llm-B5XUWH8T.d.ts +0 -231
- 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
|
+
"version": "0.5.0-alpha.4",
|
|
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",
|
|
@@ -121,6 +131,11 @@
|
|
|
121
131
|
"require": "./dist/scope.js",
|
|
122
132
|
"default": "./dist/scope.js"
|
|
123
133
|
},
|
|
134
|
+
"./serve": {
|
|
135
|
+
"types": "./dist/serve.d.ts",
|
|
136
|
+
"require": "./dist/serve.js",
|
|
137
|
+
"default": "./dist/serve.js"
|
|
138
|
+
},
|
|
124
139
|
"./telemetry": {
|
|
125
140
|
"types": "./dist/telemetry/index.d.ts",
|
|
126
141
|
"require": "./dist/telemetry/index.js",
|
|
@@ -137,47 +152,142 @@
|
|
|
137
152
|
"default": "./dist/mcp/index.js"
|
|
138
153
|
}
|
|
139
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
|
+
},
|
|
140
248
|
"dependencies": {
|
|
141
|
-
"@bufbuild/protobuf": "^2.
|
|
142
|
-
"@clack/prompts": "^1.
|
|
143
|
-
"@connectrpc/connect": "^2.
|
|
144
|
-
"@connectrpc/connect-web": "^2.
|
|
145
|
-
"@hop-top/cite": "^0.1.
|
|
146
|
-
"@modelcontextprotocol/core": "2.
|
|
147
|
-
"@modelcontextprotocol/server": "2.
|
|
148
|
-
"better-sqlite3": "^12.
|
|
149
|
-
"commander": "^
|
|
150
|
-
"csv-stringify": "^6.
|
|
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",
|
|
151
259
|
"eta": "^4.6.0",
|
|
152
|
-
"hono": "^4.
|
|
153
|
-
"js-yaml": "^4.
|
|
154
|
-
"picomatch": "^4.0.
|
|
155
|
-
"pino": "^10.
|
|
156
|
-
"semver": "^7.
|
|
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",
|
|
157
265
|
"typeid-js": "^1.2.0",
|
|
158
|
-
"zod": "^4.
|
|
266
|
+
"zod": "^4.6.7"
|
|
159
267
|
},
|
|
160
268
|
"devDependencies": {
|
|
161
269
|
"@types/better-sqlite3": "^7.6.13",
|
|
162
270
|
"@types/js-yaml": "^4.0.9",
|
|
163
|
-
"@types/node": "^
|
|
271
|
+
"@types/node": "^24",
|
|
164
272
|
"@types/picomatch": "^4.0.3",
|
|
165
|
-
"@types/semver": "^7.
|
|
166
|
-
"esbuild": "^0.
|
|
167
|
-
"eslint": "^10.
|
|
273
|
+
"@types/semver": "^7.8.0",
|
|
274
|
+
"esbuild": "^0.28.2",
|
|
275
|
+
"eslint": "^10.12.0",
|
|
168
276
|
"tsup": "^8",
|
|
169
277
|
"typescript": "^5",
|
|
170
|
-
"typescript-eslint": "^8.
|
|
171
|
-
"
|
|
278
|
+
"typescript-eslint": "^8.71.2",
|
|
279
|
+
"vite": "^8.3.4",
|
|
280
|
+
"vitest": "^5.0.4"
|
|
172
281
|
},
|
|
173
282
|
"engines": {
|
|
174
|
-
"node": ">=
|
|
283
|
+
"node": ">=22.12"
|
|
175
284
|
},
|
|
176
285
|
"license": "MIT",
|
|
177
286
|
"scripts": {
|
|
178
|
-
"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/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",
|
|
179
288
|
"lint": "eslint src/",
|
|
180
289
|
"lint:fix": "eslint src/ --fix",
|
|
290
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc -p tsconfig.test.json",
|
|
181
291
|
"test": "vitest run"
|
|
182
292
|
}
|
|
183
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" |
|
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', () => {
|
|
@@ -608,6 +608,61 @@ describe('verbose flag', () => {
|
|
|
608
608
|
});
|
|
609
609
|
});
|
|
610
610
|
|
|
611
|
+
// ---------------------------------------------------------------------------
|
|
612
|
+
// Quiet accessor
|
|
613
|
+
// ---------------------------------------------------------------------------
|
|
614
|
+
|
|
615
|
+
describe('isQuiet', () => {
|
|
616
|
+
async function quietOf(argv: string[], disableQuiet = false): Promise<boolean | undefined> {
|
|
617
|
+
const { program } = createCLI({
|
|
618
|
+
name: 't', version: '0.1.0', description: 't',
|
|
619
|
+
disable: { quiet: disableQuiet },
|
|
620
|
+
});
|
|
621
|
+
let quiet: boolean | undefined;
|
|
622
|
+
program.command('run').action(function (this: any) {
|
|
623
|
+
quiet = isQuiet(this);
|
|
624
|
+
});
|
|
625
|
+
await program.parseAsync(['node', 't', ...argv]);
|
|
626
|
+
return quiet;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
it('is false before parsing', () => {
|
|
630
|
+
const { program } = createCLI({ name: 't', version: '0.1.0', description: 't' });
|
|
631
|
+
const run = program.command('run');
|
|
632
|
+
expect(isQuiet(program)).toBe(false);
|
|
633
|
+
expect(isQuiet(run)).toBe(false);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
it('is false when --quiet is absent', async () => {
|
|
637
|
+
expect(await quietOf(['run'])).toBe(false);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
it('reads root --quiet from a subcommand', async () => {
|
|
641
|
+
expect(await quietOf(['--quiet', 'run'])).toBe(true);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it('reads root --quiet given after the subcommand', async () => {
|
|
645
|
+
expect(await quietOf(['run', '--quiet'])).toBe(true);
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
it('is false when the flag is disabled', async () => {
|
|
649
|
+
expect(await quietOf(['run'], true)).toBe(false);
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
it('wins over -V: quiet reported, verbose count 0', async () => {
|
|
653
|
+
const { program } = createCLI({ name: 't', version: '0.1.0', description: 't' });
|
|
654
|
+
let quiet: boolean | undefined;
|
|
655
|
+
let count = -1;
|
|
656
|
+
program.command('run').action(function (this: any) {
|
|
657
|
+
quiet = isQuiet(this);
|
|
658
|
+
count = verboseCount(this);
|
|
659
|
+
});
|
|
660
|
+
await program.parseAsync(['node', 't', '-VV', '--quiet', 'run']);
|
|
661
|
+
expect(quiet).toBe(true);
|
|
662
|
+
expect(count).toBe(0);
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
|
|
611
666
|
// ---------------------------------------------------------------------------
|
|
612
667
|
// Named streams
|
|
613
668
|
// ---------------------------------------------------------------------------
|
package/src/cli.ts
CHANGED
|
@@ -37,10 +37,11 @@ export { HintSet, hintsEnabled, renderHints, active,
|
|
|
37
37
|
export type { Hint, HintOptions } from './hint.js';
|
|
38
38
|
|
|
39
39
|
// ---------------------------------------------------------------------------
|
|
40
|
-
// Verbose count — stacking -V flags
|
|
40
|
+
// Verbose count — stacking -V flags; quiet
|
|
41
41
|
// ---------------------------------------------------------------------------
|
|
42
42
|
|
|
43
43
|
const verboseCountMap = new WeakMap<Command, number>();
|
|
44
|
+
const quietMap = new WeakMap<Command, boolean>();
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
47
|
* Return the single-character shorthand declared by the parity contract's
|
|
@@ -77,6 +78,24 @@ export function verboseCount(cmd: Command): number {
|
|
|
77
78
|
return 0;
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Report whether `--quiet` is in effect for a parsed command tree.
|
|
83
|
+
*
|
|
84
|
+
* `--quiet` wins over `-V`: when set, `verboseCount` reads 0 and the
|
|
85
|
+
* logger level is the contract's `verbosity.quiet_override`. False before
|
|
86
|
+
* parsing and when `disable.quiet` drops the flag.
|
|
87
|
+
*/
|
|
88
|
+
export function isQuiet(cmd: Command): boolean {
|
|
89
|
+
// Walk up to root to find the stored flag.
|
|
90
|
+
let c: Command | null = cmd;
|
|
91
|
+
while (c) {
|
|
92
|
+
const q = quietMap.get(c);
|
|
93
|
+
if (q !== undefined) return q;
|
|
94
|
+
c = c.parent ?? null;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
80
99
|
// ---------------------------------------------------------------------------
|
|
81
100
|
// Named streams — registerStream / channel
|
|
82
101
|
// ---------------------------------------------------------------------------
|
|
@@ -768,11 +787,12 @@ export function createCLI(cfg: CLIConfig): CLIResult {
|
|
|
768
787
|
verbosityFlagSpec(parity), 'Increase verbosity',
|
|
769
788
|
(_: string, prev: number) => prev + 1, 0,
|
|
770
789
|
);
|
|
771
|
-
// Store count after parse; quiet overrides verbose.
|
|
790
|
+
// Store count + quiet after parse; quiet overrides verbose.
|
|
772
791
|
program.hook('preAction', (thisCmd) => {
|
|
773
792
|
const opts = thisCmd.opts();
|
|
774
|
-
const
|
|
775
|
-
|
|
793
|
+
const quiet = opts.quiet === true;
|
|
794
|
+
quietMap.set(thisCmd, quiet);
|
|
795
|
+
verboseCountMap.set(thisCmd, quiet ? 0 : (opts.verbose ?? 0));
|
|
776
796
|
});
|
|
777
797
|
|
|
778
798
|
if (cfg.groups?.some(g => g.hidden)) {
|
|
@@ -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
|
});
|
package/src/compliance.test.ts
CHANGED
|
@@ -18,10 +18,10 @@ const TOOLSPEC = path.resolve(
|
|
|
18
18
|
|
|
19
19
|
describe("compliance", () => {
|
|
20
20
|
describe("factorName", () => {
|
|
21
|
-
it("returns name for all
|
|
21
|
+
it("returns name for all 13 factors", () => {
|
|
22
22
|
for (
|
|
23
23
|
let f = Factor.SelfDescribing;
|
|
24
|
-
f <= Factor.
|
|
24
|
+
f <= Factor.ConsentingTelemetry;
|
|
25
25
|
f++
|
|
26
26
|
) {
|
|
27
27
|
expect(factorName(f)).not.toBe("");
|
|
@@ -131,4 +131,198 @@ describe("compliance", () => {
|
|
|
131
131
|
expect(parsed.results).toHaveLength(2);
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
|
+
|
|
135
|
+
describe("F13 Consenting Telemetry", () => {
|
|
136
|
+
const wellFormed = `name: probe
|
|
137
|
+
schema_version: "1"
|
|
138
|
+
commands:
|
|
139
|
+
- name: ping
|
|
140
|
+
- name: telemetry
|
|
141
|
+
children:
|
|
142
|
+
- name: status
|
|
143
|
+
- name: enable
|
|
144
|
+
- name: disable
|
|
145
|
+
- name: reset
|
|
146
|
+
- name: inspect
|
|
147
|
+
telemetry:
|
|
148
|
+
enabled: true
|
|
149
|
+
categories: [invocation]
|
|
150
|
+
sinks: [bus]
|
|
151
|
+
consent_command: "probe telemetry"
|
|
152
|
+
consent_subcommands: [disable, enable, inspect, reset, status]
|
|
153
|
+
kill_switch_envs: [DO_NOT_TRACK, PROBE_TELEMETRY_MODE]
|
|
154
|
+
prompt_version: "v1"
|
|
155
|
+
redact_rules: kit-default
|
|
156
|
+
`;
|
|
157
|
+
|
|
158
|
+
/** Run a toolspec body and return the whole report — both the F13
|
|
159
|
+
* row and the denominator are asserted per case. */
|
|
160
|
+
function report(body: string) {
|
|
161
|
+
const tmp = path.join(
|
|
162
|
+
os.tmpdir(),
|
|
163
|
+
`compliance-f13-${Date.now()}-${Math.random()
|
|
164
|
+
.toString(36)
|
|
165
|
+
.slice(2)}.yaml`,
|
|
166
|
+
);
|
|
167
|
+
fs.writeFileSync(tmp, body);
|
|
168
|
+
try {
|
|
169
|
+
return run("", tmp);
|
|
170
|
+
} finally {
|
|
171
|
+
fs.unlinkSync(tmp);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function f13(r: ReturnType<typeof report>): CheckResult {
|
|
176
|
+
const row = r.results.find(
|
|
177
|
+
(x) => x.factor === Factor.ConsentingTelemetry,
|
|
178
|
+
);
|
|
179
|
+
expect(row, "F13 row must always be present").toBeDefined();
|
|
180
|
+
return row!;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
it("names the factor", () => {
|
|
184
|
+
expect(factorName(Factor.ConsentingTelemetry))
|
|
185
|
+
.toBe("Consenting Telemetry");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("skips when not opted in", () => {
|
|
189
|
+
const r = report(
|
|
190
|
+
'name: probe\nschema_version: "1"\ncommands:\n - name: ping\n',
|
|
191
|
+
);
|
|
192
|
+
expect(f13(r).status).toBe("skip");
|
|
193
|
+
expect(r.total).toBe(12);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("skips on a null telemetry key", () => {
|
|
197
|
+
// A bare `telemetry:` key parses as null, not an object. It is
|
|
198
|
+
// still not an opt-in, so it must skip rather than throw.
|
|
199
|
+
const r = report(
|
|
200
|
+
'name: probe\nschema_version: "1"\ncommands:\n - name: ping\ntelemetry:\n',
|
|
201
|
+
);
|
|
202
|
+
expect(f13(r).status).toBe("skip");
|
|
203
|
+
expect(r.total).toBe(12);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("runs when opted in", () => {
|
|
207
|
+
const r = report(wellFormed);
|
|
208
|
+
expect(f13(r).status).toBe("pass");
|
|
209
|
+
expect(r.total).toBe(13);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("passes a well-formed block", () => {
|
|
213
|
+
const r = report(wellFormed);
|
|
214
|
+
const row = f13(r);
|
|
215
|
+
expect(row.status).toBe("pass");
|
|
216
|
+
expect(row.details).toContain("well-formed");
|
|
217
|
+
expect(r.total).toBe(13);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("fails on empty categories", () => {
|
|
221
|
+
const r = report(
|
|
222
|
+
wellFormed.replace(
|
|
223
|
+
"categories: [invocation]",
|
|
224
|
+
"categories: []",
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
const row = f13(r);
|
|
228
|
+
expect(row.status).toBe("fail");
|
|
229
|
+
expect(row.details).toContain("categories");
|
|
230
|
+
expect(row.suggestion).toBeTruthy();
|
|
231
|
+
expect(r.total).toBe(13);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("fails on a missing canonical subcommand", () => {
|
|
235
|
+
const r = report(
|
|
236
|
+
wellFormed.replace(
|
|
237
|
+
"consent_subcommands: [disable, enable, inspect, reset, status]",
|
|
238
|
+
"consent_subcommands: [status, enable, disable]",
|
|
239
|
+
),
|
|
240
|
+
);
|
|
241
|
+
const row = f13(r);
|
|
242
|
+
expect(row.status).toBe("fail");
|
|
243
|
+
expect(row.details).toContain("reset");
|
|
244
|
+
expect(row.details).toContain("inspect");
|
|
245
|
+
expect(r.total).toBe(13);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("fails when DO_NOT_TRACK is absent", () => {
|
|
249
|
+
const r = report(
|
|
250
|
+
wellFormed.replace(
|
|
251
|
+
"kill_switch_envs: [DO_NOT_TRACK, PROBE_TELEMETRY_MODE]",
|
|
252
|
+
"kill_switch_envs: [PROBE_TELEMETRY_MODE]",
|
|
253
|
+
),
|
|
254
|
+
);
|
|
255
|
+
const row = f13(r);
|
|
256
|
+
expect(row.status).toBe("fail");
|
|
257
|
+
expect(row.details).toContain("DO_NOT_TRACK");
|
|
258
|
+
expect(r.total).toBe(13);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("fails when no mode env is declared", () => {
|
|
262
|
+
const r = report(
|
|
263
|
+
wellFormed.replace(
|
|
264
|
+
"kill_switch_envs: [DO_NOT_TRACK, PROBE_TELEMETRY_MODE]",
|
|
265
|
+
"kill_switch_envs: [DO_NOT_TRACK]",
|
|
266
|
+
),
|
|
267
|
+
);
|
|
268
|
+
const row = f13(r);
|
|
269
|
+
expect(row.status).toBe("fail");
|
|
270
|
+
expect(row.details).toContain("TELEMETRY_MODE");
|
|
271
|
+
expect(r.total).toBe(13);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("accepts KIT_TELEMETRY_MODE", () => {
|
|
275
|
+
// The regex covers the kit literal without a special-case branch.
|
|
276
|
+
const r = report(
|
|
277
|
+
wellFormed.replace("PROBE_TELEMETRY_MODE", "KIT_TELEMETRY_MODE"),
|
|
278
|
+
);
|
|
279
|
+
expect(f13(r).status).toBe("pass");
|
|
280
|
+
expect(r.total).toBe(13);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("accepts an app-prefixed mode env", () => {
|
|
284
|
+
const r = report(
|
|
285
|
+
wellFormed.replace("PROBE_TELEMETRY_MODE", "SPACED_TELEMETRY_MODE"),
|
|
286
|
+
);
|
|
287
|
+
expect(f13(r).status).toBe("pass");
|
|
288
|
+
expect(r.total).toBe(13);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("fails on an empty prompt_version", () => {
|
|
292
|
+
const r = report(
|
|
293
|
+
wellFormed.replace('prompt_version: "v1"', 'prompt_version: ""'),
|
|
294
|
+
);
|
|
295
|
+
const row = f13(r);
|
|
296
|
+
expect(row.status).toBe("fail");
|
|
297
|
+
expect(row.details).toContain("prompt_version");
|
|
298
|
+
// The field name is locked; the failure names the rejected alias.
|
|
299
|
+
expect(row.details).toContain("consent_version");
|
|
300
|
+
expect(r.total).toBe(13);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("fails on empty redact_rules", () => {
|
|
304
|
+
const r = report(
|
|
305
|
+
wellFormed.replace(
|
|
306
|
+
"redact_rules: kit-default",
|
|
307
|
+
'redact_rules: ""',
|
|
308
|
+
),
|
|
309
|
+
);
|
|
310
|
+
const row = f13(r);
|
|
311
|
+
expect(row.status).toBe("fail");
|
|
312
|
+
expect(row.details).toContain("redact_rules");
|
|
313
|
+
expect(r.total).toBe(13);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("fails when a subcommand is absent from the commands tree", () => {
|
|
317
|
+
// `inspect` is declared but has no node under `telemetry`.
|
|
318
|
+
const r = report(
|
|
319
|
+
wellFormed.replace(" - name: inspect\n", ""),
|
|
320
|
+
);
|
|
321
|
+
const row = f13(r);
|
|
322
|
+
expect(row.status).toBe("fail");
|
|
323
|
+
expect(row.details).toContain("not in commands tree");
|
|
324
|
+
expect(row.details).toContain("telemetry inspect");
|
|
325
|
+
expect(r.total).toBe(13);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
134
328
|
});
|