@hop-top/kit 0.5.0-alpha.0 → 0.5.0-alpha.10
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 +262 -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-2JV3A7OP.js +1894 -0
- 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-BLS2OBIQ.js +263 -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-GHPJJV5L.js +613 -0
- package/dist/chunk-IXVQ62NZ.js +334 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-JZ22ZUFA.js +1131 -0
- package/dist/chunk-K7VCKJ27.js +814 -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-NLMS7HGP.js +178 -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-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T46YPHKN.js +669 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-WWUKGJB5.js +90 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YGYQUFGY.js +219 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-C5B5tnpA.d.ts +400 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +70 -885
- 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-DCe1boBz.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 +184 -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 +137 -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 +18 -322
- package/dist/upgrade-p_zh3pvV.d.ts +102 -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 +236 -46
- 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.test.ts +95 -1
- package/src/cli.ts +195 -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 +297 -0
- package/src/completion.test.ts +256 -145
- package/src/completion.ts +767 -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/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 +222 -0
- package/src/mcp/bridge.ts +291 -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/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/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 +410 -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 +142 -0
- package/src/tui/parity.ts +59 -13
- 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
|
@@ -0,0 +1,868 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
4
|
+
|
|
5
|
+
// src/compliance.ts
|
|
6
|
+
var compliance_exports = {};
|
|
7
|
+
_chunkR5U7XKVJjs.__export.call(void 0, compliance_exports, {
|
|
8
|
+
Factor: () => Factor,
|
|
9
|
+
factorName: () => factorName,
|
|
10
|
+
formatReport: () => formatReport,
|
|
11
|
+
run: () => run,
|
|
12
|
+
runRuntime: () => runRuntime,
|
|
13
|
+
runStatic: () => runStatic
|
|
14
|
+
});
|
|
15
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
16
|
+
var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml);
|
|
17
|
+
var _child_process = require('child_process');
|
|
18
|
+
var Factor = /* @__PURE__ */ ((Factor2) => {
|
|
19
|
+
Factor2[Factor2["SelfDescribing"] = 1] = "SelfDescribing";
|
|
20
|
+
Factor2[Factor2["StructuredIO"] = 2] = "StructuredIO";
|
|
21
|
+
Factor2[Factor2["StreamDiscipline"] = 3] = "StreamDiscipline";
|
|
22
|
+
Factor2[Factor2["ContractsErrors"] = 4] = "ContractsErrors";
|
|
23
|
+
Factor2[Factor2["Preview"] = 5] = "Preview";
|
|
24
|
+
Factor2[Factor2["Idempotency"] = 6] = "Idempotency";
|
|
25
|
+
Factor2[Factor2["StateTransparency"] = 7] = "StateTransparency";
|
|
26
|
+
Factor2[Factor2["SafeDelegation"] = 8] = "SafeDelegation";
|
|
27
|
+
Factor2[Factor2["ObservableOps"] = 9] = "ObservableOps";
|
|
28
|
+
Factor2[Factor2["Provenance"] = 10] = "Provenance";
|
|
29
|
+
Factor2[Factor2["Evolution"] = 11] = "Evolution";
|
|
30
|
+
Factor2[Factor2["AuthLifecycle"] = 12] = "AuthLifecycle";
|
|
31
|
+
Factor2[Factor2["ConsentingTelemetry"] = 13] = "ConsentingTelemetry";
|
|
32
|
+
return Factor2;
|
|
33
|
+
})(Factor || {});
|
|
34
|
+
var factorNames = {
|
|
35
|
+
[1 /* SelfDescribing */]: "Self-Describing",
|
|
36
|
+
[2 /* StructuredIO */]: "Structured I/O",
|
|
37
|
+
[3 /* StreamDiscipline */]: "Stream Discipline",
|
|
38
|
+
[4 /* ContractsErrors */]: "Contracts & Errors",
|
|
39
|
+
[5 /* Preview */]: "Preview",
|
|
40
|
+
[6 /* Idempotency */]: "Idempotency",
|
|
41
|
+
[7 /* StateTransparency */]: "State Transparency",
|
|
42
|
+
[8 /* SafeDelegation */]: "Safe Delegation",
|
|
43
|
+
[9 /* ObservableOps */]: "Observable Ops",
|
|
44
|
+
[10 /* Provenance */]: "Provenance",
|
|
45
|
+
[11 /* Evolution */]: "Evolution",
|
|
46
|
+
[12 /* AuthLifecycle */]: "Auth Lifecycle",
|
|
47
|
+
[13 /* ConsentingTelemetry */]: "Consenting Telemetry"
|
|
48
|
+
};
|
|
49
|
+
function factorName(f) {
|
|
50
|
+
return _nullishCoalesce(factorNames[f], () => ( `Factor(${f})`));
|
|
51
|
+
}
|
|
52
|
+
function loadSpec(path) {
|
|
53
|
+
const raw = fs.readFileSync(path, "utf-8");
|
|
54
|
+
return yaml.load(raw);
|
|
55
|
+
}
|
|
56
|
+
function allCommands(cmds) {
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const c of cmds) {
|
|
59
|
+
out.push(c);
|
|
60
|
+
if (c.children) out.push(...allCommands(c.children));
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
function mutatingCommands(cmds) {
|
|
65
|
+
return allCommands(cmds).filter(
|
|
66
|
+
(c) => _optionalChain([c, 'access', _ => _.contract, 'optionalAccess', _2 => _2.side_effects]) && c.contract.side_effects.length > 0
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
function dangerousCommands(cmds) {
|
|
70
|
+
return allCommands(cmds).filter(
|
|
71
|
+
(c) => _optionalChain([c, 'access', _3 => _3.safety, 'optionalAccess', _4 => _4.level]) === "dangerous"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function telemetryOptedIn(spec) {
|
|
75
|
+
return _optionalChain([spec, 'optionalAccess', _5 => _5.telemetry, 'optionalAccess', _6 => _6.enabled]) === true;
|
|
76
|
+
}
|
|
77
|
+
var telemetryConsentSubcommandsCanonical = [
|
|
78
|
+
"disable",
|
|
79
|
+
"enable",
|
|
80
|
+
"inspect",
|
|
81
|
+
"reset",
|
|
82
|
+
"status"
|
|
83
|
+
];
|
|
84
|
+
var telemetryModeEnvShape = /^[A-Z][A-Z0-9_]*_TELEMETRY_MODE$/;
|
|
85
|
+
function hasTelemetryModeEnv(envs) {
|
|
86
|
+
return envs.some((e) => telemetryModeEnvShape.test(e));
|
|
87
|
+
}
|
|
88
|
+
function commandPathExists(cmds, path) {
|
|
89
|
+
if (path.length === 0) return false;
|
|
90
|
+
for (const c of cmds) {
|
|
91
|
+
if (c.name !== path[0]) continue;
|
|
92
|
+
if (path.length === 1) return true;
|
|
93
|
+
return commandPathExists(_nullishCoalesce(c.children, () => ( [])), path.slice(1));
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
function pass(f, details) {
|
|
98
|
+
return {
|
|
99
|
+
factor: f,
|
|
100
|
+
name: factorName(f),
|
|
101
|
+
status: "pass",
|
|
102
|
+
details
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function fail(f, details, suggestion) {
|
|
106
|
+
return {
|
|
107
|
+
factor: f,
|
|
108
|
+
name: factorName(f),
|
|
109
|
+
status: "fail",
|
|
110
|
+
details,
|
|
111
|
+
suggestion
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function skip(f, details) {
|
|
115
|
+
return {
|
|
116
|
+
factor: f,
|
|
117
|
+
name: factorName(f),
|
|
118
|
+
status: "skip",
|
|
119
|
+
details
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function warn(f, details, suggestion) {
|
|
123
|
+
return {
|
|
124
|
+
factor: f,
|
|
125
|
+
name: factorName(f),
|
|
126
|
+
status: "warn",
|
|
127
|
+
details,
|
|
128
|
+
suggestion
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function checkSelfDescribing(spec) {
|
|
132
|
+
const f = 1 /* SelfDescribing */;
|
|
133
|
+
if (!spec.commands || spec.commands.length === 0) {
|
|
134
|
+
return fail(
|
|
135
|
+
f,
|
|
136
|
+
"no commands defined",
|
|
137
|
+
"Add a commands array with at least one named command"
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
for (const c of spec.commands) {
|
|
141
|
+
if (!c.name) {
|
|
142
|
+
return fail(
|
|
143
|
+
f,
|
|
144
|
+
"command missing name",
|
|
145
|
+
"Every command must have a name field"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return pass(f, "commands array non-empty, all named");
|
|
150
|
+
}
|
|
151
|
+
function checkStructuredIO(spec) {
|
|
152
|
+
const f = 2 /* StructuredIO */;
|
|
153
|
+
for (const c of allCommands(_nullishCoalesce(spec.commands, () => ( [])))) {
|
|
154
|
+
if (c.output_schema) {
|
|
155
|
+
return pass(f, `output_schema found on ${c.name}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return fail(
|
|
159
|
+
f,
|
|
160
|
+
"no command has output_schema",
|
|
161
|
+
"Add output_schema to at least one command"
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
function checkContractsErrors(spec) {
|
|
165
|
+
const f = 4 /* ContractsErrors */;
|
|
166
|
+
const mut = mutatingCommands(_nullishCoalesce(spec.commands, () => ( [])));
|
|
167
|
+
if (mut.length === 0) {
|
|
168
|
+
for (const c of allCommands(_nullishCoalesce(spec.commands, () => ( [])))) {
|
|
169
|
+
if (c.contract) return pass(f, "contracts found");
|
|
170
|
+
}
|
|
171
|
+
return fail(
|
|
172
|
+
f,
|
|
173
|
+
"no contracts declared",
|
|
174
|
+
"Add contract fields to commands"
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
for (const c of mut) {
|
|
178
|
+
if (!c.contract) {
|
|
179
|
+
return fail(
|
|
180
|
+
f,
|
|
181
|
+
`${c.name} has side_effects but no contract`,
|
|
182
|
+
"Add contract fields to mutating commands"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return pass(f, "all mutating commands have contracts");
|
|
187
|
+
}
|
|
188
|
+
function checkPreview(spec) {
|
|
189
|
+
const f = 5 /* Preview */;
|
|
190
|
+
const mut = mutatingCommands(_nullishCoalesce(spec.commands, () => ( [])));
|
|
191
|
+
if (mut.length === 0) {
|
|
192
|
+
return pass(f, "no mutating commands to preview");
|
|
193
|
+
}
|
|
194
|
+
let withPreview = 0;
|
|
195
|
+
for (const c of mut) {
|
|
196
|
+
if (c.preview_modes && c.preview_modes.length > 0) {
|
|
197
|
+
withPreview++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (withPreview === 0) {
|
|
201
|
+
return fail(
|
|
202
|
+
f,
|
|
203
|
+
"no mutating command has preview_modes",
|
|
204
|
+
"Add preview_modes (e.g. --dry-run) to mutating commands"
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return pass(
|
|
208
|
+
f,
|
|
209
|
+
`${withPreview}/${mut.length} mutating commands have preview_modes`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
function checkIdempotency(spec) {
|
|
213
|
+
const f = 6 /* Idempotency */;
|
|
214
|
+
const all = allCommands(_nullishCoalesce(spec.commands, () => ( [])));
|
|
215
|
+
if (all.length === 0) {
|
|
216
|
+
return fail(f, "no commands", "Add commands");
|
|
217
|
+
}
|
|
218
|
+
let declared = 0;
|
|
219
|
+
for (const c of all) {
|
|
220
|
+
if (c.contract && c.contract.idempotent !== void 0) {
|
|
221
|
+
declared++;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (declared === 0) {
|
|
225
|
+
return fail(
|
|
226
|
+
f,
|
|
227
|
+
"no command declares idempotent",
|
|
228
|
+
"Add contract.idempotent to each command"
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
return pass(f, "idempotency declared on commands");
|
|
232
|
+
}
|
|
233
|
+
function checkStateTransparency(spec) {
|
|
234
|
+
const f = 7 /* StateTransparency */;
|
|
235
|
+
const si = spec.state_introspection;
|
|
236
|
+
if (!_optionalChain([si, 'optionalAccess', _7 => _7.config_commands]) || si.config_commands.length === 0) {
|
|
237
|
+
return fail(
|
|
238
|
+
f,
|
|
239
|
+
"no config_commands in state_introspection",
|
|
240
|
+
"Add state_introspection.config_commands"
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return pass(f, "config_commands present");
|
|
244
|
+
}
|
|
245
|
+
function checkSafeDelegation(spec) {
|
|
246
|
+
const f = 8 /* SafeDelegation */;
|
|
247
|
+
const dangerous = dangerousCommands(_nullishCoalesce(spec.commands, () => ( [])));
|
|
248
|
+
if (dangerous.length === 0) {
|
|
249
|
+
return pass(f, "no dangerous commands");
|
|
250
|
+
}
|
|
251
|
+
for (const c of dangerous) {
|
|
252
|
+
if (!c.safety) {
|
|
253
|
+
return fail(
|
|
254
|
+
f,
|
|
255
|
+
`${c.name} is dangerous but has no safety block`,
|
|
256
|
+
"Add safety with requires_confirmation"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return pass(f, "all dangerous commands have safety metadata");
|
|
261
|
+
}
|
|
262
|
+
function checkEvolution(spec) {
|
|
263
|
+
const f = 11 /* Evolution */;
|
|
264
|
+
if (!spec.schema_version) {
|
|
265
|
+
return fail(
|
|
266
|
+
f,
|
|
267
|
+
"schema_version not set",
|
|
268
|
+
"Set schema_version in the toolspec"
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return pass(f, `schema_version: ${spec.schema_version}`);
|
|
272
|
+
}
|
|
273
|
+
function checkAuthLifecycle(spec) {
|
|
274
|
+
const f = 12 /* AuthLifecycle */;
|
|
275
|
+
const si = spec.state_introspection;
|
|
276
|
+
if (!_optionalChain([si, 'optionalAccess', _8 => _8.auth_commands]) || si.auth_commands.length === 0) {
|
|
277
|
+
return skip(
|
|
278
|
+
f,
|
|
279
|
+
"no auth_commands \u2014 skipped (tool may not need auth)"
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
return pass(f, "auth_commands present");
|
|
283
|
+
}
|
|
284
|
+
function checkConsentingTelemetry(spec) {
|
|
285
|
+
const f = 13 /* ConsentingTelemetry */;
|
|
286
|
+
if (!telemetryOptedIn(spec)) {
|
|
287
|
+
return skip(f, "binary does not opt into telemetry");
|
|
288
|
+
}
|
|
289
|
+
const t = _nullishCoalesce(spec.telemetry, () => ( {}));
|
|
290
|
+
const failures = [];
|
|
291
|
+
if (!t.categories || t.categories.length === 0) {
|
|
292
|
+
failures.push("telemetry.categories is empty");
|
|
293
|
+
}
|
|
294
|
+
const subs = _nullishCoalesce(t.consent_subcommands, () => ( []));
|
|
295
|
+
const missingSubs = telemetryConsentSubcommandsCanonical.filter(
|
|
296
|
+
(req) => !subs.includes(req)
|
|
297
|
+
);
|
|
298
|
+
if (missingSubs.length > 0) {
|
|
299
|
+
failures.push(
|
|
300
|
+
"telemetry.consent_subcommands missing required entries: " + missingSubs.join(", ")
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
const envs = _nullishCoalesce(t.kill_switch_envs, () => ( []));
|
|
304
|
+
if (!envs.includes("DO_NOT_TRACK")) {
|
|
305
|
+
failures.push(
|
|
306
|
+
"telemetry.kill_switch_envs missing DO_NOT_TRACK"
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
if (!hasTelemetryModeEnv(envs)) {
|
|
310
|
+
failures.push(
|
|
311
|
+
"telemetry.kill_switch_envs missing a <APP>_TELEMETRY_MODE entry (e.g. KIT_TELEMETRY_MODE or SPACED_TELEMETRY_MODE)"
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (!(_nullishCoalesce(t.prompt_version, () => ( ""))).trim()) {
|
|
315
|
+
failures.push(
|
|
316
|
+
"telemetry.prompt_version is empty (canonical field name is `prompt_version`; aliases like `consent_version` are not accepted)"
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
if (!(_nullishCoalesce(t.redact_rules, () => ( ""))).trim()) {
|
|
320
|
+
failures.push("telemetry.redact_rules is empty");
|
|
321
|
+
}
|
|
322
|
+
const consentTokens = (_nullishCoalesce(t.consent_command, () => ( ""))).split(/\s+/).filter((tok) => tok.length > 0);
|
|
323
|
+
const consentPath = consentTokens.length > 1 ? consentTokens.slice(1) : ["telemetry"];
|
|
324
|
+
const unmappedSubs = [];
|
|
325
|
+
for (const sub of subs) {
|
|
326
|
+
const full = [...consentPath, sub];
|
|
327
|
+
if (!commandPathExists(_nullishCoalesce(spec.commands, () => ( [])), full)) {
|
|
328
|
+
unmappedSubs.push(full.join(" "));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (unmappedSubs.length > 0) {
|
|
332
|
+
failures.push(
|
|
333
|
+
"telemetry.consent_subcommands declared but not in commands tree: " + unmappedSubs.join(", ")
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
if (failures.length === 0) {
|
|
337
|
+
return pass(
|
|
338
|
+
f,
|
|
339
|
+
"telemetry block well-formed; all consent subcommands declared"
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
return fail(
|
|
343
|
+
f,
|
|
344
|
+
failures.join("; "),
|
|
345
|
+
"Fix the telemetry block: ensure categories, consent_subcommands {disable, enable, inspect, reset, status}, kill_switch_envs [DO_NOT_TRACK, <APP>_TELEMETRY_MODE], prompt_version, redact_rules are set, and that each consent_subcommand maps to a command in the commands tree."
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
function runStaticChecks(spec) {
|
|
349
|
+
return [
|
|
350
|
+
checkSelfDescribing(spec),
|
|
351
|
+
checkStructuredIO(spec),
|
|
352
|
+
skip(3 /* StreamDiscipline */, "runtime check only"),
|
|
353
|
+
checkContractsErrors(spec),
|
|
354
|
+
checkPreview(spec),
|
|
355
|
+
checkIdempotency(spec),
|
|
356
|
+
checkStateTransparency(spec),
|
|
357
|
+
checkSafeDelegation(spec),
|
|
358
|
+
skip(9 /* ObservableOps */, "runtime check only"),
|
|
359
|
+
skip(10 /* Provenance */, "runtime check only"),
|
|
360
|
+
checkEvolution(spec),
|
|
361
|
+
checkAuthLifecycle(spec)
|
|
362
|
+
];
|
|
363
|
+
}
|
|
364
|
+
function execBin(bin, args) {
|
|
365
|
+
try {
|
|
366
|
+
const stdout = _child_process.execFileSync.call(void 0, bin, args, {
|
|
367
|
+
timeout: 1e4,
|
|
368
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
369
|
+
}).toString();
|
|
370
|
+
return { stdout, stderr: "", code: 0 };
|
|
371
|
+
} catch (e) {
|
|
372
|
+
return {
|
|
373
|
+
stdout: _nullishCoalesce(_optionalChain([e, 'access', _9 => _9.stdout, 'optionalAccess', _10 => _10.toString, 'call', _11 => _11()]), () => ( "")),
|
|
374
|
+
stderr: _nullishCoalesce(_optionalChain([e, 'access', _12 => _12.stderr, 'optionalAccess', _13 => _13.toString, 'call', _14 => _14()]), () => ( "")),
|
|
375
|
+
code: _nullishCoalesce(e.status, () => ( 1))
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function execBinEnv(bin, args, env) {
|
|
380
|
+
try {
|
|
381
|
+
const stdout = _child_process.execFileSync.call(void 0, bin, args, {
|
|
382
|
+
timeout: 1e4,
|
|
383
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
384
|
+
env: { ...process.env, ...env }
|
|
385
|
+
}).toString();
|
|
386
|
+
return { stdout, stderr: "", code: 0 };
|
|
387
|
+
} catch (e) {
|
|
388
|
+
return {
|
|
389
|
+
stdout: _nullishCoalesce(_optionalChain([e, 'access', _15 => _15.stdout, 'optionalAccess', _16 => _16.toString, 'call', _17 => _17()]), () => ( "")),
|
|
390
|
+
stderr: _nullishCoalesce(_optionalChain([e, 'access', _18 => _18.stderr, 'optionalAccess', _19 => _19.toString, 'call', _20 => _20()]), () => ( "")),
|
|
391
|
+
code: _nullishCoalesce(e.status, () => ( 1))
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function findReadCommand(spec) {
|
|
396
|
+
for (const c of allCommands(_nullishCoalesce(spec.commands, () => ( [])))) {
|
|
397
|
+
if (c.output_schema && _optionalChain([c, 'access', _21 => _21.contract, 'optionalAccess', _22 => _22.idempotent]) === true) {
|
|
398
|
+
return c.name;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return void 0;
|
|
402
|
+
}
|
|
403
|
+
var autocorrectEnvVar = "KIT_AUTOCORRECT";
|
|
404
|
+
var correctedFromField = "corrected_from";
|
|
405
|
+
function contractsErrorsEnvelope(bin) {
|
|
406
|
+
const f = 4 /* ContractsErrors */;
|
|
407
|
+
const r = execBin(bin, ["--format", "json", "--bogus-arg-xyzzy"]);
|
|
408
|
+
if (r.code === 0) {
|
|
409
|
+
return fail(
|
|
410
|
+
f,
|
|
411
|
+
"bogus arg didn't cause error exit",
|
|
412
|
+
"Unknown flags should cause non-zero exit"
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
if (isValidJSON(r.stderr)) {
|
|
416
|
+
let obj;
|
|
417
|
+
try {
|
|
418
|
+
obj = JSON.parse(r.stderr.trim());
|
|
419
|
+
} catch (e2) {
|
|
420
|
+
obj = void 0;
|
|
421
|
+
}
|
|
422
|
+
if (obj && typeof obj === "object" && "code" in obj) {
|
|
423
|
+
if (errorCarriesFix(obj)) {
|
|
424
|
+
return pass(f, "structured error with code field and recovery guidance");
|
|
425
|
+
}
|
|
426
|
+
return warn(
|
|
427
|
+
f,
|
|
428
|
+
"structured error carries no recovery guidance",
|
|
429
|
+
"Populate suggested_fix (or alternatives) with a concrete correction so the caller does not need a --help round trip"
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return warn(
|
|
434
|
+
f,
|
|
435
|
+
"error output is not structured JSON",
|
|
436
|
+
"Return JSON errors with a 'code' field on stderr"
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
function contractsErrorsAutocorrect(bin, spec) {
|
|
440
|
+
const f = 4 /* ContractsErrors */;
|
|
441
|
+
const nearMiss = "--formt=json";
|
|
442
|
+
const readCmd = findReadCommand(spec);
|
|
443
|
+
if (!readCmd) {
|
|
444
|
+
return skip(f, "no read command found to probe autocorrect on");
|
|
445
|
+
}
|
|
446
|
+
if (execBin(bin, [readCmd, nearMiss]).code === 0) {
|
|
447
|
+
return fail(
|
|
448
|
+
f,
|
|
449
|
+
"a mistyped flag exited 0 with no autocorrect policy set",
|
|
450
|
+
"Keep autocorrect off by default: a bad flag must exit non-zero unless the caller opted in"
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
if (execBinEnv(
|
|
454
|
+
bin,
|
|
455
|
+
[readCmd, nearMiss],
|
|
456
|
+
{ [autocorrectEnvVar]: "off" }
|
|
457
|
+
).code === 0) {
|
|
458
|
+
return fail(
|
|
459
|
+
f,
|
|
460
|
+
"a mistyped flag exited 0 under an explicit off policy",
|
|
461
|
+
"Honor the off value: it must not be read as unset"
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
const r = execBinEnv(
|
|
465
|
+
bin,
|
|
466
|
+
[readCmd, "--format", "json", nearMiss],
|
|
467
|
+
{ [autocorrectEnvVar]: "read" }
|
|
468
|
+
);
|
|
469
|
+
if (r.code !== 0) {
|
|
470
|
+
return skip(f, "binary does not apply flag corrections under " + autocorrectEnvVar + "=read");
|
|
471
|
+
}
|
|
472
|
+
if (correctionDeclared(r.stderr) || correctionDeclared(r.stdout)) {
|
|
473
|
+
return pass(f, "applied flag correction declares " + correctedFromField);
|
|
474
|
+
}
|
|
475
|
+
return fail(
|
|
476
|
+
f,
|
|
477
|
+
"a flag correction was applied but no " + correctedFromField + " was reported",
|
|
478
|
+
"Emit " + correctedFromField + " in the structured envelope naming the token the caller typed, so an agent and an audit log can both see that the command that ran is not the command that was asked for"
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
function correctionDeclared(s) {
|
|
482
|
+
for (const line of s.split("\n")) {
|
|
483
|
+
const t = line.trim();
|
|
484
|
+
if (!t.startsWith("{")) continue;
|
|
485
|
+
try {
|
|
486
|
+
const obj = JSON.parse(t);
|
|
487
|
+
if (obj && typeof obj === "object") {
|
|
488
|
+
const v = obj[correctedFromField];
|
|
489
|
+
if (typeof v === "string" && v.trim() !== "") return true;
|
|
490
|
+
}
|
|
491
|
+
} catch (e3) {
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (/"corrected_from"\s*:\s*"[^"\s]/.test(s)) return true;
|
|
495
|
+
return s.includes(correctedFromField + ":") || s.includes("Corrected from:");
|
|
496
|
+
}
|
|
497
|
+
function aggregateContractsErrors(...rs) {
|
|
498
|
+
const f = 4 /* ContractsErrors */;
|
|
499
|
+
const failed = [];
|
|
500
|
+
const skipped = [];
|
|
501
|
+
let firstWarn;
|
|
502
|
+
for (const r of rs) {
|
|
503
|
+
if (r.status === "fail") failed.push(_nullishCoalesce(r.details, () => ( "")));
|
|
504
|
+
else if (r.status === "skip") skipped.push(_nullishCoalesce(r.details, () => ( "")));
|
|
505
|
+
else if (r.status === "warn" && !firstWarn) firstWarn = r;
|
|
506
|
+
}
|
|
507
|
+
if (failed.length > 0) {
|
|
508
|
+
return fail(
|
|
509
|
+
f,
|
|
510
|
+
failed.join("; "),
|
|
511
|
+
"Address each failing sub-condition (structured error envelope; autocorrect mode semantics)"
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
if (firstWarn) return firstWarn;
|
|
515
|
+
if (skipped.length === rs.length) {
|
|
516
|
+
return skip(f, [...new Set(skipped)].join("; "));
|
|
517
|
+
}
|
|
518
|
+
return pass(f, "structured error with recovery guidance; autocorrect mode semantics honored");
|
|
519
|
+
}
|
|
520
|
+
function errorCarriesFix(obj) {
|
|
521
|
+
const fix = obj["suggested_fix"];
|
|
522
|
+
if (typeof fix === "string" && isConcreteFix(fix)) return true;
|
|
523
|
+
const alts = obj["alternatives"];
|
|
524
|
+
if (!Array.isArray(alts)) return false;
|
|
525
|
+
return alts.some((a) => typeof a === "string" && isConcreteFix(a));
|
|
526
|
+
}
|
|
527
|
+
var HELP_FRAMING = /* @__PURE__ */ new Set([
|
|
528
|
+
"--help",
|
|
529
|
+
"-h",
|
|
530
|
+
"help",
|
|
531
|
+
"run",
|
|
532
|
+
"see",
|
|
533
|
+
"try",
|
|
534
|
+
"use",
|
|
535
|
+
"for",
|
|
536
|
+
"usage",
|
|
537
|
+
"the",
|
|
538
|
+
"a",
|
|
539
|
+
"an",
|
|
540
|
+
"to",
|
|
541
|
+
"and",
|
|
542
|
+
"or",
|
|
543
|
+
"then",
|
|
544
|
+
"check",
|
|
545
|
+
"consult",
|
|
546
|
+
"with"
|
|
547
|
+
]);
|
|
548
|
+
function isConcreteFix(s) {
|
|
549
|
+
const words = s.toLowerCase().split(/[\s'"`,.;:()]+/).filter(Boolean);
|
|
550
|
+
for (const w of words) {
|
|
551
|
+
if (HELP_FRAMING.has(w)) continue;
|
|
552
|
+
if (w.startsWith("-") || /[=<>[\]{}/|@]/.test(w)) return true;
|
|
553
|
+
}
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
function isValidJSON(s) {
|
|
557
|
+
try {
|
|
558
|
+
JSON.parse(s.trim());
|
|
559
|
+
return true;
|
|
560
|
+
} catch (e4) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
function runRuntimeChecks(bin, spec) {
|
|
565
|
+
const results = [];
|
|
566
|
+
{
|
|
567
|
+
const f = 1 /* SelfDescribing */;
|
|
568
|
+
const r = execBin(bin, ["--help"]);
|
|
569
|
+
if (r.code !== 0) {
|
|
570
|
+
results.push(fail(
|
|
571
|
+
f,
|
|
572
|
+
`--help exited ${r.code}`,
|
|
573
|
+
"Ensure --help exits 0"
|
|
574
|
+
));
|
|
575
|
+
} else {
|
|
576
|
+
const upper = r.stdout.toUpperCase();
|
|
577
|
+
if (!upper.includes("COMMANDS") && !upper.includes("USAGE")) {
|
|
578
|
+
results.push(fail(
|
|
579
|
+
f,
|
|
580
|
+
"--help lacks COMMANDS/USAGE",
|
|
581
|
+
"Help should list available commands"
|
|
582
|
+
));
|
|
583
|
+
} else {
|
|
584
|
+
results.push(pass(
|
|
585
|
+
f,
|
|
586
|
+
"--help exits 0, contains command listing"
|
|
587
|
+
));
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
{
|
|
592
|
+
const f = 2 /* StructuredIO */;
|
|
593
|
+
const readCmd = findReadCommand(spec);
|
|
594
|
+
if (!readCmd) {
|
|
595
|
+
results.push(skip(f, "no read command found"));
|
|
596
|
+
} else {
|
|
597
|
+
const r = execBin(bin, [readCmd, "--format", "json"]);
|
|
598
|
+
if (r.code !== 0) {
|
|
599
|
+
results.push(
|
|
600
|
+
fail(
|
|
601
|
+
f,
|
|
602
|
+
`${readCmd} --format json exited ${r.code}`,
|
|
603
|
+
"Read commands should support --format json"
|
|
604
|
+
)
|
|
605
|
+
);
|
|
606
|
+
} else if (!isValidJSON(r.stdout)) {
|
|
607
|
+
results.push(fail(
|
|
608
|
+
f,
|
|
609
|
+
"output is not valid JSON",
|
|
610
|
+
"--format json should produce valid JSON"
|
|
611
|
+
));
|
|
612
|
+
} else {
|
|
613
|
+
results.push(
|
|
614
|
+
pass(f, `${readCmd} --format json returns valid JSON`)
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
{
|
|
620
|
+
const f = 3 /* StreamDiscipline */;
|
|
621
|
+
const readCmd = findReadCommand(spec);
|
|
622
|
+
if (!readCmd) {
|
|
623
|
+
results.push(skip(f, "no read command found"));
|
|
624
|
+
} else {
|
|
625
|
+
const r = execBin(bin, [readCmd, "--format", "json"]);
|
|
626
|
+
if (!r.stdout.trim()) {
|
|
627
|
+
results.push(fail(
|
|
628
|
+
f,
|
|
629
|
+
"stdout is empty",
|
|
630
|
+
"Data should go to stdout"
|
|
631
|
+
));
|
|
632
|
+
} else if (isValidJSON(r.stderr) && r.stderr.trim().length > 2) {
|
|
633
|
+
results.push(fail(
|
|
634
|
+
f,
|
|
635
|
+
"stderr contains JSON",
|
|
636
|
+
"Keep structured data on stdout, logs on stderr"
|
|
637
|
+
));
|
|
638
|
+
} else {
|
|
639
|
+
results.push(pass(f, "stdout has data, stderr clean"));
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
results.push(aggregateContractsErrors(
|
|
644
|
+
contractsErrorsEnvelope(bin),
|
|
645
|
+
contractsErrorsAutocorrect(bin, spec)
|
|
646
|
+
));
|
|
647
|
+
{
|
|
648
|
+
const f = 5 /* Preview */;
|
|
649
|
+
const mut = mutatingCommands(_nullishCoalesce(spec.commands, () => ( [])));
|
|
650
|
+
if (mut.length === 0) {
|
|
651
|
+
results.push(skip(f, "no mutating commands"));
|
|
652
|
+
} else {
|
|
653
|
+
let found = false;
|
|
654
|
+
for (const c of mut) {
|
|
655
|
+
for (const mode of _nullishCoalesce(c.preview_modes, () => ( []))) {
|
|
656
|
+
const r = execBin(bin, [c.name, mode]);
|
|
657
|
+
if (r.code === 0) {
|
|
658
|
+
results.push(
|
|
659
|
+
pass(f, `${c.name} ${mode} exits 0`)
|
|
660
|
+
);
|
|
661
|
+
found = true;
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (found) break;
|
|
666
|
+
}
|
|
667
|
+
if (!found) {
|
|
668
|
+
results.push(fail(
|
|
669
|
+
f,
|
|
670
|
+
"no mutating command succeeds with preview mode",
|
|
671
|
+
"Ensure --dry-run exits 0"
|
|
672
|
+
));
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
{
|
|
677
|
+
const f = 7 /* StateTransparency */;
|
|
678
|
+
let r = execBin(bin, ["config", "show"]);
|
|
679
|
+
if (r.code === 0) {
|
|
680
|
+
results.push(pass(f, "config show exits 0"));
|
|
681
|
+
} else {
|
|
682
|
+
r = execBin(bin, ["config"]);
|
|
683
|
+
if (r.code === 0) {
|
|
684
|
+
results.push(pass(f, "config exits 0"));
|
|
685
|
+
} else {
|
|
686
|
+
results.push(fail(
|
|
687
|
+
f,
|
|
688
|
+
"config command failed",
|
|
689
|
+
"Add a config/config show command"
|
|
690
|
+
));
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
{
|
|
695
|
+
const f = 8 /* SafeDelegation */;
|
|
696
|
+
const dangerous = dangerousCommands(_nullishCoalesce(spec.commands, () => ( [])));
|
|
697
|
+
if (dangerous.length === 0) {
|
|
698
|
+
results.push(skip(f, "no dangerous commands"));
|
|
699
|
+
} else {
|
|
700
|
+
results.push(pass(
|
|
701
|
+
f,
|
|
702
|
+
"dangerous commands have safety metadata"
|
|
703
|
+
));
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
{
|
|
707
|
+
const f = 10 /* Provenance */;
|
|
708
|
+
const readCmd = findReadCommand(spec);
|
|
709
|
+
if (!readCmd) {
|
|
710
|
+
results.push(skip(f, "no read command found"));
|
|
711
|
+
} else {
|
|
712
|
+
const r = execBin(bin, [readCmd, "--format", "json"]);
|
|
713
|
+
if (r.code !== 0) {
|
|
714
|
+
results.push(skip(f, `${readCmd} failed`));
|
|
715
|
+
} else {
|
|
716
|
+
try {
|
|
717
|
+
const obj = JSON.parse(r.stdout.trim());
|
|
718
|
+
if (obj._meta) {
|
|
719
|
+
results.push(pass(f, "_meta field present"));
|
|
720
|
+
} else {
|
|
721
|
+
results.push(fail(
|
|
722
|
+
f,
|
|
723
|
+
"no _meta field in JSON output",
|
|
724
|
+
"Add _meta with provenance info"
|
|
725
|
+
));
|
|
726
|
+
}
|
|
727
|
+
} catch (e5) {
|
|
728
|
+
results.push(skip(f, "output not JSON object"));
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
{
|
|
734
|
+
const f = 11 /* Evolution */;
|
|
735
|
+
const r = execBin(bin, ["--version"]);
|
|
736
|
+
if (r.code !== 0) {
|
|
737
|
+
results.push(
|
|
738
|
+
fail(
|
|
739
|
+
f,
|
|
740
|
+
`--version exited ${r.code}`,
|
|
741
|
+
"Ensure --version exits 0"
|
|
742
|
+
)
|
|
743
|
+
);
|
|
744
|
+
} else {
|
|
745
|
+
results.push(pass(f, "--version exits 0"));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
{
|
|
749
|
+
const f = 12 /* AuthLifecycle */;
|
|
750
|
+
const si = spec.state_introspection;
|
|
751
|
+
if (!_optionalChain([si, 'optionalAccess', _23 => _23.auth_commands]) || si.auth_commands.length === 0) {
|
|
752
|
+
results.push(skip(f, "no auth_commands declared"));
|
|
753
|
+
} else {
|
|
754
|
+
const r = execBin(bin, ["auth", "status"]);
|
|
755
|
+
if (r.code === 0) {
|
|
756
|
+
results.push(pass(f, "auth status exits 0"));
|
|
757
|
+
} else {
|
|
758
|
+
const r2 = execBin(bin, ["auth"]);
|
|
759
|
+
if (r2.code === 0) {
|
|
760
|
+
results.push(pass(f, "auth exits 0"));
|
|
761
|
+
} else {
|
|
762
|
+
results.push(fail(
|
|
763
|
+
f,
|
|
764
|
+
"auth command failed",
|
|
765
|
+
"Implement auth status/auth commands"
|
|
766
|
+
));
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return results;
|
|
772
|
+
}
|
|
773
|
+
function runStatic(toolspecPath) {
|
|
774
|
+
const spec = loadSpec(toolspecPath);
|
|
775
|
+
return runStaticChecks(spec);
|
|
776
|
+
}
|
|
777
|
+
function runRuntime(binaryPath, toolspecPath) {
|
|
778
|
+
const spec = loadSpec(toolspecPath);
|
|
779
|
+
return runRuntimeChecks(binaryPath, spec);
|
|
780
|
+
}
|
|
781
|
+
function run(binaryPath, toolspecPath) {
|
|
782
|
+
const spec = loadSpec(toolspecPath);
|
|
783
|
+
let results = runStaticChecks(spec);
|
|
784
|
+
results.push(checkConsentingTelemetry(spec));
|
|
785
|
+
if (binaryPath) {
|
|
786
|
+
const rtResults = runRuntimeChecks(binaryPath, spec);
|
|
787
|
+
results = mergeResults(results, rtResults);
|
|
788
|
+
}
|
|
789
|
+
const total = telemetryOptedIn(spec) ? 13 : 12;
|
|
790
|
+
const score = results.filter((r) => r.status === "pass").length;
|
|
791
|
+
return {
|
|
792
|
+
binary: binaryPath,
|
|
793
|
+
toolspec: toolspecPath,
|
|
794
|
+
results,
|
|
795
|
+
score,
|
|
796
|
+
total
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
function mergeResults(staticR, runtime) {
|
|
800
|
+
const byFactor = /* @__PURE__ */ new Map();
|
|
801
|
+
for (const r of staticR) byFactor.set(r.factor, r);
|
|
802
|
+
for (const r of runtime) {
|
|
803
|
+
const existing = byFactor.get(r.factor);
|
|
804
|
+
if (!existing || existing.status === "skip") {
|
|
805
|
+
byFactor.set(r.factor, r);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
const out = [];
|
|
809
|
+
for (let f = 1 /* SelfDescribing */; f <= 13 /* ConsentingTelemetry */; f++) {
|
|
810
|
+
const r = byFactor.get(f);
|
|
811
|
+
if (r) out.push(r);
|
|
812
|
+
}
|
|
813
|
+
return out;
|
|
814
|
+
}
|
|
815
|
+
function formatReport(r, format = "text") {
|
|
816
|
+
if (format === "json") {
|
|
817
|
+
return JSON.stringify(r, null, 2) + "\n";
|
|
818
|
+
}
|
|
819
|
+
return formatText(r);
|
|
820
|
+
}
|
|
821
|
+
function statusIcon(s) {
|
|
822
|
+
switch (s) {
|
|
823
|
+
case "pass":
|
|
824
|
+
return "PASS";
|
|
825
|
+
case "fail":
|
|
826
|
+
return "FAIL";
|
|
827
|
+
case "warn":
|
|
828
|
+
return "WARN";
|
|
829
|
+
case "skip":
|
|
830
|
+
return "SKIP";
|
|
831
|
+
default:
|
|
832
|
+
return "????";
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
function formatText(r) {
|
|
836
|
+
const lines = [
|
|
837
|
+
"",
|
|
838
|
+
" 12-Factor AI CLI Compliance Report",
|
|
839
|
+
" \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"
|
|
840
|
+
];
|
|
841
|
+
if (r.binary) lines.push(` Binary : ${r.binary}`);
|
|
842
|
+
if (r.toolspec) lines.push(` Toolspec : ${r.toolspec}`);
|
|
843
|
+
lines.push("");
|
|
844
|
+
for (const cr of r.results) {
|
|
845
|
+
const icon = statusIcon(cr.status);
|
|
846
|
+
const fNum = String(cr.factor).padStart(2, " ");
|
|
847
|
+
lines.push(
|
|
848
|
+
` ${icon} F${fNum} ${cr.name.padEnd(20)} ${_nullishCoalesce(cr.details, () => ( ""))}`
|
|
849
|
+
);
|
|
850
|
+
if (cr.suggestion) {
|
|
851
|
+
lines.push(` \u2514\u2500 ${cr.suggestion}`);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
lines.push("");
|
|
855
|
+
lines.push(` Score: ${r.score}/${r.total} factors passing`);
|
|
856
|
+
lines.push("");
|
|
857
|
+
return lines.join("\n");
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
exports.Factor = Factor; exports.factorName = factorName; exports.runStatic = runStatic; exports.runRuntime = runRuntime; exports.run = run; exports.formatReport = formatReport; exports.compliance_exports = compliance_exports;
|