@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.11
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 +275 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4FMALWYB.js +669 -0
- package/dist/chunk-4GPCWBBA.js +143 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-65VPWMPV.js +1134 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-BXJ2J27B.js +219 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/chunk-EE4M2UOF.js +818 -0
- package/dist/chunk-GFRAYYRD.js +817 -0
- package/dist/chunk-IVQHLI56.js +1890 -0
- package/dist/chunk-IZ6Q4SE3.js +178 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-K7E34Q3A.js +1445 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/chunk-ML7D5DWY.js +263 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RYKLVOVK.js +309 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T6OZMPPV.js +68 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-VGOA5Y7S.js +251 -0
- package/dist/chunk-VWGP4NVJ.js +513 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +125 -945
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-CGE5yLBj.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- 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 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +185 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +135 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- 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-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +17 -381
- package/dist/upgrade-C3RWGwRi.d.ts +125 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +192 -24
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +234 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +298 -0
- package/src/completion.test.ts +268 -145
- package/src/completion.ts +772 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- 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 +71 -0
- package/src/index.ts +46 -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/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +250 -0
- package/src/mcp/bridge.ts +286 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/published-types.test.ts +133 -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/sideeffect.ts +105 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +415 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/src/upgrade.test.ts +291 -0
- package/src/upgrade.ts +116 -7
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- 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/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/src/tui/parity.json +0 -74
package/src/compliance.ts
CHANGED
|
@@ -24,6 +24,7 @@ export enum Factor {
|
|
|
24
24
|
Provenance = 10,
|
|
25
25
|
Evolution = 11,
|
|
26
26
|
AuthLifecycle = 12,
|
|
27
|
+
ConsentingTelemetry = 13,
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const factorNames: Record<number, string> = {
|
|
@@ -39,6 +40,7 @@ const factorNames: Record<number, string> = {
|
|
|
39
40
|
[Factor.Provenance]: "Provenance",
|
|
40
41
|
[Factor.Evolution]: "Evolution",
|
|
41
42
|
[Factor.AuthLifecycle]: "Auth Lifecycle",
|
|
43
|
+
[Factor.ConsentingTelemetry]: "Consenting Telemetry",
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
export function factorName(f: Factor): string {
|
|
@@ -71,6 +73,19 @@ interface SpecYAML {
|
|
|
71
73
|
config_commands?: string[];
|
|
72
74
|
auth_commands?: string[];
|
|
73
75
|
};
|
|
76
|
+
telemetry?: TelemetryYAML;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The toolspec `telemetry:` block, subject to the F13 check. */
|
|
80
|
+
interface TelemetryYAML {
|
|
81
|
+
enabled?: boolean;
|
|
82
|
+
categories?: string[];
|
|
83
|
+
sinks?: string[];
|
|
84
|
+
consent_command?: string;
|
|
85
|
+
consent_subcommands?: string[];
|
|
86
|
+
kill_switch_envs?: string[];
|
|
87
|
+
prompt_version?: string;
|
|
88
|
+
redact_rules?: string;
|
|
74
89
|
}
|
|
75
90
|
|
|
76
91
|
interface CmdYAML {
|
|
@@ -118,6 +133,46 @@ function dangerousCommands(cmds: CmdYAML[]): CmdYAML[] {
|
|
|
118
133
|
);
|
|
119
134
|
}
|
|
120
135
|
|
|
136
|
+
/** True iff the toolspec declares a telemetry block with
|
|
137
|
+
* enabled: true. Non-opt-in specs skip F13 entirely. */
|
|
138
|
+
function telemetryOptedIn(spec: SpecYAML): boolean {
|
|
139
|
+
return spec?.telemetry?.enabled === true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Subcommands an opt-in binary MUST expose under its consent
|
|
143
|
+
* command (typically `<bin> telemetry`). */
|
|
144
|
+
const telemetryConsentSubcommandsCanonical = [
|
|
145
|
+
"disable",
|
|
146
|
+
"enable",
|
|
147
|
+
"inspect",
|
|
148
|
+
"reset",
|
|
149
|
+
"status",
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
/** Matches `<UPPERCASE_APP>_TELEMETRY_MODE`. The kit literal
|
|
153
|
+
* `KIT_TELEMETRY_MODE` matches by construction, as does any
|
|
154
|
+
* app-prefixed form like `SPACED_TELEMETRY_MODE`. */
|
|
155
|
+
const telemetryModeEnvShape = /^[A-Z][A-Z0-9_]*_TELEMETRY_MODE$/;
|
|
156
|
+
|
|
157
|
+
function hasTelemetryModeEnv(envs: string[]): boolean {
|
|
158
|
+
return envs.some((e) => telemetryModeEnvShape.test(e));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** True when the space-separated path (e.g. "telemetry status")
|
|
162
|
+
* exists in the command tree. */
|
|
163
|
+
function commandPathExists(
|
|
164
|
+
cmds: CmdYAML[],
|
|
165
|
+
path: string[],
|
|
166
|
+
): boolean {
|
|
167
|
+
if (path.length === 0) return false;
|
|
168
|
+
for (const c of cmds) {
|
|
169
|
+
if (c.name !== path[0]) continue;
|
|
170
|
+
if (path.length === 1) return true;
|
|
171
|
+
return commandPathExists(c.children ?? [], path.slice(1));
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
121
176
|
function pass(
|
|
122
177
|
f: Factor,
|
|
123
178
|
details: string,
|
|
@@ -156,6 +211,23 @@ function skip(
|
|
|
156
211
|
};
|
|
157
212
|
}
|
|
158
213
|
|
|
214
|
+
// warn is a partial pass: the obligation is met in shape but not in
|
|
215
|
+
// substance. It carries a suggestion like fail, because the point of a warn
|
|
216
|
+
// is that there is something to do about it.
|
|
217
|
+
function warn(
|
|
218
|
+
f: Factor,
|
|
219
|
+
details: string,
|
|
220
|
+
suggestion: string,
|
|
221
|
+
): CheckResult {
|
|
222
|
+
return {
|
|
223
|
+
factor: f,
|
|
224
|
+
name: factorName(f),
|
|
225
|
+
status: "warn",
|
|
226
|
+
details,
|
|
227
|
+
suggestion,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
159
231
|
// --- Static Checks ---
|
|
160
232
|
|
|
161
233
|
function checkSelfDescribing(spec: SpecYAML): CheckResult {
|
|
@@ -287,6 +359,108 @@ function checkAuthLifecycle(spec: SpecYAML): CheckResult {
|
|
|
287
359
|
return pass(f, "auth_commands present");
|
|
288
360
|
}
|
|
289
361
|
|
|
362
|
+
/**
|
|
363
|
+
* F13 static check. When the toolspec opts into telemetry
|
|
364
|
+
* (`telemetry.enabled: true`), asserts the block is well-formed
|
|
365
|
+
* across seven sub-conditions:
|
|
366
|
+
*
|
|
367
|
+
* 1. categories non-empty
|
|
368
|
+
* 2. consent_subcommands contains the canonical set
|
|
369
|
+
* {disable, enable, inspect, reset, status}
|
|
370
|
+
* 3. kill_switch_envs contains DO_NOT_TRACK
|
|
371
|
+
* 4. kill_switch_envs contains a `<APP>_TELEMETRY_MODE` entry
|
|
372
|
+
* 5. prompt_version non-empty (canonical field name is locked —
|
|
373
|
+
* aliases like `consent_version` are not read)
|
|
374
|
+
* 6. redact_rules non-empty
|
|
375
|
+
* 7. every declared consent_subcommand maps to a real command
|
|
376
|
+
* in the commands tree
|
|
377
|
+
*
|
|
378
|
+
* Failures aggregate into a single result: one row per factor.
|
|
379
|
+
*/
|
|
380
|
+
function checkConsentingTelemetry(spec: SpecYAML): CheckResult {
|
|
381
|
+
const f = Factor.ConsentingTelemetry;
|
|
382
|
+
if (!telemetryOptedIn(spec)) {
|
|
383
|
+
return skip(f, "binary does not opt into telemetry");
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const t = spec.telemetry ?? {};
|
|
387
|
+
const failures: string[] = [];
|
|
388
|
+
|
|
389
|
+
if (!t.categories || t.categories.length === 0) {
|
|
390
|
+
failures.push("telemetry.categories is empty");
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const subs = t.consent_subcommands ?? [];
|
|
394
|
+
const missingSubs = telemetryConsentSubcommandsCanonical.filter(
|
|
395
|
+
(req) => !subs.includes(req),
|
|
396
|
+
);
|
|
397
|
+
if (missingSubs.length > 0) {
|
|
398
|
+
failures.push(
|
|
399
|
+
"telemetry.consent_subcommands missing required entries: " +
|
|
400
|
+
missingSubs.join(", "),
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const envs = t.kill_switch_envs ?? [];
|
|
405
|
+
if (!envs.includes("DO_NOT_TRACK")) {
|
|
406
|
+
failures.push(
|
|
407
|
+
"telemetry.kill_switch_envs missing DO_NOT_TRACK",
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
if (!hasTelemetryModeEnv(envs)) {
|
|
411
|
+
failures.push(
|
|
412
|
+
"telemetry.kill_switch_envs missing a <APP>_TELEMETRY_MODE " +
|
|
413
|
+
"entry (e.g. KIT_TELEMETRY_MODE or SPACED_TELEMETRY_MODE)",
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (!(t.prompt_version ?? "").trim()) {
|
|
418
|
+
failures.push(
|
|
419
|
+
"telemetry.prompt_version is empty (canonical field name " +
|
|
420
|
+
"is `prompt_version`; aliases like `consent_version` " +
|
|
421
|
+
"are not accepted)",
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (!(t.redact_rules ?? "").trim()) {
|
|
426
|
+
failures.push("telemetry.redact_rules is empty");
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// The consent_command schema is `<bin> telemetry [...]`; the
|
|
430
|
+
// leading `<bin>` is the binary name, not a top-level command,
|
|
431
|
+
// so strip it. Fall back to `telemetry <sub>` when the value is
|
|
432
|
+
// empty or a bare binary name.
|
|
433
|
+
const consentTokens = (t.consent_command ?? "").split(/\s+/)
|
|
434
|
+
.filter((tok) => tok.length > 0);
|
|
435
|
+
const consentPath =
|
|
436
|
+
consentTokens.length > 1 ? consentTokens.slice(1) : ["telemetry"];
|
|
437
|
+
const unmappedSubs: string[] = [];
|
|
438
|
+
for (const sub of subs) {
|
|
439
|
+
const full = [...consentPath, sub];
|
|
440
|
+
if (!commandPathExists(spec.commands ?? [], full)) {
|
|
441
|
+
unmappedSubs.push(full.join(" "));
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (unmappedSubs.length > 0) {
|
|
445
|
+
failures.push(
|
|
446
|
+
"telemetry.consent_subcommands declared but not in " +
|
|
447
|
+
"commands tree: " + unmappedSubs.join(", "),
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (failures.length === 0) {
|
|
452
|
+
return pass(f,
|
|
453
|
+
"telemetry block well-formed; all consent subcommands declared");
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return fail(f, failures.join("; "),
|
|
457
|
+
"Fix the telemetry block: ensure categories, " +
|
|
458
|
+
"consent_subcommands {disable, enable, inspect, reset, " +
|
|
459
|
+
"status}, kill_switch_envs [DO_NOT_TRACK, <APP>_TELEMETRY_MODE], " +
|
|
460
|
+
"prompt_version, redact_rules are set, and that each " +
|
|
461
|
+
"consent_subcommand maps to a command in the commands tree.");
|
|
462
|
+
}
|
|
463
|
+
|
|
290
464
|
function runStaticChecks(spec: SpecYAML): CheckResult[] {
|
|
291
465
|
return [
|
|
292
466
|
checkSelfDescribing(spec),
|
|
@@ -325,6 +499,31 @@ function execBin(
|
|
|
325
499
|
}
|
|
326
500
|
}
|
|
327
501
|
|
|
502
|
+
// execBinEnv is execBin with extra environment entries, for probes whose
|
|
503
|
+
// obligation is stated against a policy the tool reads from the environment.
|
|
504
|
+
// The inherited environment is kept: a binary needing PATH or HOME to start
|
|
505
|
+
// at all must still start.
|
|
506
|
+
function execBinEnv(
|
|
507
|
+
bin: string,
|
|
508
|
+
args: string[],
|
|
509
|
+
env: Record<string, string>,
|
|
510
|
+
): { stdout: string; stderr: string; code: number } {
|
|
511
|
+
try {
|
|
512
|
+
const stdout = execFileSync(bin, args, {
|
|
513
|
+
timeout: 10000,
|
|
514
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
515
|
+
env: { ...process.env, ...env },
|
|
516
|
+
}).toString();
|
|
517
|
+
return { stdout, stderr: "", code: 0 };
|
|
518
|
+
} catch (e: any) {
|
|
519
|
+
return {
|
|
520
|
+
stdout: e.stdout?.toString() ?? "",
|
|
521
|
+
stderr: e.stderr?.toString() ?? "",
|
|
522
|
+
code: e.status ?? 1,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
328
527
|
function findReadCommand(spec: SpecYAML): string | undefined {
|
|
329
528
|
for (const c of allCommands(spec.commands ?? [])) {
|
|
330
529
|
if (c.output_schema && c.contract?.idempotent === true) {
|
|
@@ -334,6 +533,216 @@ function findReadCommand(spec: SpecYAML): string | undefined {
|
|
|
334
533
|
return undefined;
|
|
335
534
|
}
|
|
336
535
|
|
|
536
|
+
// autocorrectEnvVar is the environment name kit reads for its opt-in flag
|
|
537
|
+
// autocorrect policy. Set by the probe below to elicit each mode from a tool
|
|
538
|
+
// that supports it; a tool that does not simply ignores it, which is what
|
|
539
|
+
// makes the probe skip rather than fail.
|
|
540
|
+
const autocorrectEnvVar = "KIT_AUTOCORRECT";
|
|
541
|
+
|
|
542
|
+
// correctedFromField is the envelope key a tool MUST populate when it
|
|
543
|
+
// rewrote a flag for the caller.
|
|
544
|
+
const correctedFromField = "corrected_from";
|
|
545
|
+
|
|
546
|
+
// contractsErrorsEnvelope is the original F4 obligation: a bogus flag exits
|
|
547
|
+
// non-zero and comes back as a structured envelope carrying a fix.
|
|
548
|
+
function contractsErrorsEnvelope(bin: string): CheckResult {
|
|
549
|
+
const f = Factor.ContractsErrors;
|
|
550
|
+
const r = execBin(bin, ["--format", "json", "--bogus-arg-xyzzy"]);
|
|
551
|
+
if (r.code === 0) {
|
|
552
|
+
return fail(f, "bogus arg didn't cause error exit",
|
|
553
|
+
"Unknown flags should cause non-zero exit");
|
|
554
|
+
}
|
|
555
|
+
if (isValidJSON(r.stderr)) {
|
|
556
|
+
let obj: unknown;
|
|
557
|
+
try {
|
|
558
|
+
obj = JSON.parse(r.stderr.trim());
|
|
559
|
+
} catch {
|
|
560
|
+
obj = undefined;
|
|
561
|
+
}
|
|
562
|
+
if (obj && typeof obj === "object" && "code" in obj) {
|
|
563
|
+
if (errorCarriesFix(obj as Record<string, unknown>)) {
|
|
564
|
+
return pass(f, "structured error with code field and recovery guidance");
|
|
565
|
+
}
|
|
566
|
+
return warn(f, "structured error carries no recovery guidance",
|
|
567
|
+
"Populate suggested_fix (or alternatives) with a concrete " +
|
|
568
|
+
"correction so the caller does not need a --help round trip");
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return warn(f, "error output is not structured JSON",
|
|
572
|
+
"Return JSON errors with a 'code' field on stderr");
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// contractsErrorsAutocorrect checks the per-mode semantics of an opt-in flag
|
|
576
|
+
// autocorrect, when the tool has one.
|
|
577
|
+
//
|
|
578
|
+
// The obligations differ by mode, and each is the thing that mode's existence
|
|
579
|
+
// puts at risk:
|
|
580
|
+
//
|
|
581
|
+
// - off (and the default, which is off): a mistyped flag exits non-zero.
|
|
582
|
+
// This is the contract every other caller depends on, and a tool that
|
|
583
|
+
// quietly corrects by default has broken it for every script that was
|
|
584
|
+
// relying on the failure.
|
|
585
|
+
// - read: IF a correction was applied — exit 0 on an invocation that should
|
|
586
|
+
// have failed to parse — the envelope MUST carry corrected_from. A run
|
|
587
|
+
// that silently becomes a different run is unauditable, and stderr prose
|
|
588
|
+
// is not something a --format json consumer reads.
|
|
589
|
+
//
|
|
590
|
+
// Aimed at a READ command, not the root, because a correction is only ever
|
|
591
|
+
// legitimate on one: the side-effect gate is per-leaf, and a tool rewriting a
|
|
592
|
+
// flag on an unannotated root would be violating that gate rather than
|
|
593
|
+
// demonstrating the feature.
|
|
594
|
+
//
|
|
595
|
+
// The near-miss token is a one-edit typo of --format. `--formt` rather than
|
|
596
|
+
// `--forma`: the latter is a PREFIX of --format, --format-opt and
|
|
597
|
+
// --format-help, so it is ambiguous by construction and no compliant tool
|
|
598
|
+
// would ever correct it — a probe built on it would skip for every tool and
|
|
599
|
+
// measure nothing.
|
|
600
|
+
function contractsErrorsAutocorrect(bin: string, spec: SpecYAML): CheckResult {
|
|
601
|
+
const f = Factor.ContractsErrors;
|
|
602
|
+
const nearMiss = "--formt=json";
|
|
603
|
+
|
|
604
|
+
const readCmd = findReadCommand(spec);
|
|
605
|
+
if (!readCmd) {
|
|
606
|
+
return skip(f, "no read command found to probe autocorrect on");
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Obligation 1: the default is suggest-only.
|
|
610
|
+
if (execBin(bin, [readCmd, nearMiss]).code === 0) {
|
|
611
|
+
return fail(f,
|
|
612
|
+
"a mistyped flag exited 0 with no autocorrect policy set",
|
|
613
|
+
"Keep autocorrect off by default: a bad flag must exit non-zero " +
|
|
614
|
+
"unless the caller opted in");
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// Obligation 2: explicit off behaves as the default does.
|
|
618
|
+
if (execBinEnv(bin, [readCmd, nearMiss],
|
|
619
|
+
{ [autocorrectEnvVar]: "off" }).code === 0) {
|
|
620
|
+
return fail(f,
|
|
621
|
+
"a mistyped flag exited 0 under an explicit off policy",
|
|
622
|
+
"Honor the off value: it must not be read as unset");
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// Obligation 3: under read, a correction that WAS applied is declared.
|
|
626
|
+
const r = execBinEnv(bin, [readCmd, "--format", "json", nearMiss],
|
|
627
|
+
{ [autocorrectEnvVar]: "read" });
|
|
628
|
+
if (r.code !== 0) {
|
|
629
|
+
return skip(f, "binary does not apply flag corrections under " +
|
|
630
|
+
autocorrectEnvVar + "=read");
|
|
631
|
+
}
|
|
632
|
+
if (correctionDeclared(r.stderr) || correctionDeclared(r.stdout)) {
|
|
633
|
+
return pass(f, "applied flag correction declares " + correctedFromField);
|
|
634
|
+
}
|
|
635
|
+
return fail(f,
|
|
636
|
+
"a flag correction was applied but no " + correctedFromField +
|
|
637
|
+
" was reported",
|
|
638
|
+
"Emit " + correctedFromField + " in the structured envelope naming the " +
|
|
639
|
+
"token the caller typed, so an agent and an audit log can both see " +
|
|
640
|
+
"that the command that ran is not the command that was asked for");
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// correctionDeclared reports whether s carries a corrected_from field.
|
|
644
|
+
//
|
|
645
|
+
// Tolerant of surrounding output on purpose: a tool may write the notice
|
|
646
|
+
// alongside logs, and a probe that demanded the stream be exactly one JSON
|
|
647
|
+
// document would be testing Factor 3's obligation, not this one. Each line
|
|
648
|
+
// is tried as its own document, then the raw text as a fallback for a YAML
|
|
649
|
+
// or plaintext rendering.
|
|
650
|
+
function correctionDeclared(s: string): boolean {
|
|
651
|
+
for (const line of s.split("\n")) {
|
|
652
|
+
const t = line.trim();
|
|
653
|
+
if (!t.startsWith("{")) continue;
|
|
654
|
+
try {
|
|
655
|
+
const obj = JSON.parse(t);
|
|
656
|
+
if (obj && typeof obj === "object") {
|
|
657
|
+
const v = (obj as Record<string, unknown>)[correctedFromField];
|
|
658
|
+
if (typeof v === "string" && v.trim() !== "") return true;
|
|
659
|
+
}
|
|
660
|
+
} catch {
|
|
661
|
+
// Not a standalone document; the raw-text fallback below still
|
|
662
|
+
// catches a pretty-printed one.
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (/"corrected_from"\s*:\s*"[^"\s]/.test(s)) return true;
|
|
666
|
+
return s.includes(correctedFromField + ":") ||
|
|
667
|
+
s.includes("Corrected from:");
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// aggregateContractsErrors folds the two F4 runtime sub-checks into one row,
|
|
671
|
+
// per the "one row per factor" model.
|
|
672
|
+
//
|
|
673
|
+
// Precedence matches the F13 aggregator with one addition it needs and F13
|
|
674
|
+
// does not: a warn survives. The envelope sub-check reports warn for a tool
|
|
675
|
+
// whose error is unstructured or fix-less, and collapsing that to pass
|
|
676
|
+
// because the autocorrect arm skipped would hide the finding on exactly the
|
|
677
|
+
// tools that have not adopted autocorrect — which is most of them.
|
|
678
|
+
function aggregateContractsErrors(...rs: CheckResult[]): CheckResult {
|
|
679
|
+
const f = Factor.ContractsErrors;
|
|
680
|
+
const failed: string[] = [];
|
|
681
|
+
const skipped: string[] = [];
|
|
682
|
+
let firstWarn: CheckResult | undefined;
|
|
683
|
+
for (const r of rs) {
|
|
684
|
+
// details is optional on the wire; a sub-check that set none
|
|
685
|
+
// contributes nothing to the concatenation rather than "undefined".
|
|
686
|
+
if (r.status === "fail") failed.push(r.details ?? "");
|
|
687
|
+
else if (r.status === "skip") skipped.push(r.details ?? "");
|
|
688
|
+
else if (r.status === "warn" && !firstWarn) firstWarn = r;
|
|
689
|
+
}
|
|
690
|
+
if (failed.length > 0) {
|
|
691
|
+
return fail(f, failed.join("; "),
|
|
692
|
+
"Address each failing sub-condition (structured error envelope; " +
|
|
693
|
+
"autocorrect mode semantics)");
|
|
694
|
+
}
|
|
695
|
+
if (firstWarn) return firstWarn;
|
|
696
|
+
if (skipped.length === rs.length) {
|
|
697
|
+
return skip(f, [...new Set(skipped)].join("; "));
|
|
698
|
+
}
|
|
699
|
+
return pass(f, "structured error with recovery guidance; " +
|
|
700
|
+
"autocorrect mode semantics honored");
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// errorCarriesFix reports whether a decoded error envelope offers the caller
|
|
704
|
+
// a way forward.
|
|
705
|
+
//
|
|
706
|
+
// Either field satisfies it. A single unambiguous correction belongs in
|
|
707
|
+
// suggested_fix; an ambiguous one belongs in alternatives, and a tool that
|
|
708
|
+
// declines to guess between candidates is behaving correctly, not
|
|
709
|
+
// incompletely. Empty strings and empty lists do not count — a present but
|
|
710
|
+
// blank field is the same dead end as an absent one.
|
|
711
|
+
//
|
|
712
|
+
// A bare `--help` pointer does not count either, in EITHER field. "Run tool
|
|
713
|
+
// --help for usage" is precisely the round trip this factor exists to
|
|
714
|
+
// eliminate, and accepting it would let a tool pass "with recovery guidance"
|
|
715
|
+
// for offering none. A fix that names --help alongside something concrete
|
|
716
|
+
// still counts — the concrete part is the guidance.
|
|
717
|
+
function errorCarriesFix(obj: Record<string, unknown>): boolean {
|
|
718
|
+
const fix = obj["suggested_fix"];
|
|
719
|
+
if (typeof fix === "string" && isConcreteFix(fix)) return true;
|
|
720
|
+
const alts = obj["alternatives"];
|
|
721
|
+
if (!Array.isArray(alts)) return false;
|
|
722
|
+
return alts.some((a) => typeof a === "string" && isConcreteFix(a));
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// HELP_FRAMING is every word that exists only to frame a help invocation. A
|
|
726
|
+
// fix reduces to nothing once they are removed exactly when it is a pointer
|
|
727
|
+
// back at the help page.
|
|
728
|
+
const HELP_FRAMING = new Set([
|
|
729
|
+
"--help", "-h", "help", "run", "see", "try", "use", "for", "usage",
|
|
730
|
+
"the", "a", "an", "to", "and", "or", "then", "check", "consult", "with",
|
|
731
|
+
]);
|
|
732
|
+
|
|
733
|
+
// isConcreteFix reports whether s is recovery guidance rather than a pointer
|
|
734
|
+
// back at the help page. A bare command-path word ("tool", "sub") counts as
|
|
735
|
+
// framing too: "tool sub --help" names a path, not a fix, so a token must
|
|
736
|
+
// carry a flag dash or punctuation of its own to count as content.
|
|
737
|
+
function isConcreteFix(s: string): boolean {
|
|
738
|
+
const words = s.toLowerCase().split(/[\s'"`,.;:()]+/).filter(Boolean);
|
|
739
|
+
for (const w of words) {
|
|
740
|
+
if (HELP_FRAMING.has(w)) continue;
|
|
741
|
+
if (w.startsWith("-") || /[=<>[\]{}/|@]/.test(w)) return true;
|
|
742
|
+
}
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
|
|
337
746
|
function isValidJSON(s: string): boolean {
|
|
338
747
|
try {
|
|
339
748
|
JSON.parse(s.trim());
|
|
@@ -413,24 +822,27 @@ function runRuntimeChecks(
|
|
|
413
822
|
}
|
|
414
823
|
}
|
|
415
824
|
|
|
416
|
-
// F4: bogus arg
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
825
|
+
// F4: bogus arg returns a structured error carrying a fix
|
|
826
|
+
//
|
|
827
|
+
// Two separate obligations, checked in order of severity:
|
|
828
|
+
//
|
|
829
|
+
// 1. Non-zero exit. A rejected flag that exits 0 is the worst outcome —
|
|
830
|
+
// the caller cannot tell the invocation failed. Hard fail.
|
|
831
|
+
// 2. A structured envelope that carries recovery guidance. An error whose
|
|
832
|
+
// only content is "unknown flag: --x" is a dead end: the caller has to
|
|
833
|
+
// spend a --help round trip to learn what it should have typed. That
|
|
834
|
+
// round trip is the cost this factor exists to eliminate, so a
|
|
835
|
+
// structured error WITHOUT a fix is only a partial pass.
|
|
836
|
+
//
|
|
837
|
+
// Both are stated against the SUGGEST-ONLY behavior, which is what this
|
|
838
|
+
// probe elicits: an argument no real flag is close to, and no autocorrect
|
|
839
|
+
// policy of its own. A tool invoked under an autocorrect policy is a
|
|
840
|
+
// different measurement, made by the second sub-check below and folded
|
|
841
|
+
// into the same row.
|
|
842
|
+
results.push(aggregateContractsErrors(
|
|
843
|
+
contractsErrorsEnvelope(bin),
|
|
844
|
+
contractsErrorsAutocorrect(bin, spec),
|
|
845
|
+
));
|
|
434
846
|
|
|
435
847
|
// F5: preview
|
|
436
848
|
{
|
|
@@ -578,19 +990,27 @@ export function run(
|
|
|
578
990
|
): Report {
|
|
579
991
|
const spec = loadSpec(toolspecPath);
|
|
580
992
|
let results = runStaticChecks(spec);
|
|
993
|
+
results.push(checkConsentingTelemetry(spec));
|
|
581
994
|
|
|
582
995
|
if (binaryPath) {
|
|
583
996
|
const rtResults = runRuntimeChecks(binaryPath, spec);
|
|
584
997
|
results = mergeResults(results, rtResults);
|
|
585
998
|
}
|
|
586
999
|
|
|
1000
|
+
// The denominator counts factors *eligible* to contribute. The 12
|
|
1001
|
+
// pre-F13 factors always are, so a non-opt-in binary still scores
|
|
1002
|
+
// N/12; only an opt-in binary adds F13 and scores N/13. Skips
|
|
1003
|
+
// inside the eligible set (e.g. runtime-only factors on a
|
|
1004
|
+
// static-only run) still count toward the denominator.
|
|
1005
|
+
const total = telemetryOptedIn(spec) ? 13 : 12;
|
|
1006
|
+
|
|
587
1007
|
const score = results.filter((r) => r.status === "pass").length;
|
|
588
1008
|
return {
|
|
589
1009
|
binary: binaryPath,
|
|
590
1010
|
toolspec: toolspecPath,
|
|
591
1011
|
results,
|
|
592
1012
|
score,
|
|
593
|
-
total
|
|
1013
|
+
total,
|
|
594
1014
|
};
|
|
595
1015
|
}
|
|
596
1016
|
|
|
@@ -610,7 +1030,7 @@ function mergeResults(
|
|
|
610
1030
|
const out: CheckResult[] = [];
|
|
611
1031
|
for (
|
|
612
1032
|
let f = Factor.SelfDescribing;
|
|
613
|
-
f <= Factor.
|
|
1033
|
+
f <= Factor.ConsentingTelemetry;
|
|
614
1034
|
f++
|
|
615
1035
|
) {
|
|
616
1036
|
const r = byFactor.get(f);
|