@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
|
@@ -0,0 +1,818 @@
|
|
|
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
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkSNVGDYX7js = require('./chunk-SNVGDYX7.js');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkCXBZTONYjs = require('./chunk-CXBZTONY.js');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var _chunkGFRAYYRDjs = require('./chunk-GFRAYYRD.js');
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _chunkPOR5L2DGjs = require('./chunk-POR5L2DG.js');
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
29
|
+
|
|
30
|
+
// src/toolspec.ts
|
|
31
|
+
var toolspec_exports = {};
|
|
32
|
+
_chunkR5U7XKVJjs.__export.call(void 0, toolspec_exports, {
|
|
33
|
+
IDEMPOTENT_UNKNOWN: () => IDEMPOTENT_UNKNOWN,
|
|
34
|
+
LATEST_SCHEMA_VERSION: () => LATEST_SCHEMA_VERSION,
|
|
35
|
+
SCHEMA_VERSION_ENV: () => SCHEMA_VERSION_ENV,
|
|
36
|
+
SIDE_EFFECT_UNKNOWN: () => SIDE_EFFECT_UNKNOWN,
|
|
37
|
+
SPEC_COMMAND_ANNOTATION: () => SPEC_COMMAND_ANNOTATION,
|
|
38
|
+
buildManifest: () => buildManifest,
|
|
39
|
+
coverageOf: () => coverageOf,
|
|
40
|
+
findCommand: () => findCommand,
|
|
41
|
+
loadToolSpec: () => loadToolSpec,
|
|
42
|
+
negotiateSchemaVersion: () => negotiateSchemaVersion,
|
|
43
|
+
registerSpecCommand: () => registerSpecCommand,
|
|
44
|
+
renderManifestJSON: () => renderManifestJSON,
|
|
45
|
+
toolSpecFromCommand: () => toolSpecFromCommand,
|
|
46
|
+
validateToolSpec: () => validateToolSpec
|
|
47
|
+
});
|
|
48
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
49
|
+
var _jsyaml = require('js-yaml'); var yaml2 = _interopRequireWildcard(_jsyaml); var yaml = _interopRequireWildcard(_jsyaml);
|
|
50
|
+
|
|
51
|
+
// src/toolspec-manifest.ts
|
|
52
|
+
var SCHEMA_VERSION_ENV = "KIT_TOOLSPEC_SCHEMA";
|
|
53
|
+
var LATEST_SCHEMA_VERSION = "1.2";
|
|
54
|
+
var KNOWN_SCHEMA_VERSIONS = ["1.0", "1.1", LATEST_SCHEMA_VERSION];
|
|
55
|
+
var SIDE_EFFECT_UNKNOWN = "unknown";
|
|
56
|
+
var IDEMPOTENT_UNKNOWN = "unknown";
|
|
57
|
+
function parseSchemaVersion(s) {
|
|
58
|
+
const t = s.trim();
|
|
59
|
+
const dot = t.indexOf(".");
|
|
60
|
+
if (dot < 0) return void 0;
|
|
61
|
+
const parts = [t.slice(0, dot), t.slice(dot + 1)];
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const p of parts) {
|
|
64
|
+
if (!/^[0-9]+$/.test(p)) return void 0;
|
|
65
|
+
const n = Number(p);
|
|
66
|
+
if (!Number.isSafeInteger(n)) return void 0;
|
|
67
|
+
out.push(n);
|
|
68
|
+
}
|
|
69
|
+
return [out[0], out[1]];
|
|
70
|
+
}
|
|
71
|
+
function after(a, b) {
|
|
72
|
+
return a[0] !== b[0] ? a[0] > b[0] : a[1] > b[1];
|
|
73
|
+
}
|
|
74
|
+
function negotiateSchemaVersion(declared, requested) {
|
|
75
|
+
const floor = parseSchemaVersion(declared);
|
|
76
|
+
if (!floor) return declared;
|
|
77
|
+
const ceiling = parseSchemaVersion(requested);
|
|
78
|
+
if (!ceiling) return declared;
|
|
79
|
+
let resolved = declared;
|
|
80
|
+
let best = floor;
|
|
81
|
+
for (const v of KNOWN_SCHEMA_VERSIONS) {
|
|
82
|
+
const known = parseSchemaVersion(v);
|
|
83
|
+
if (after(known, best) && !after(known, ceiling)) {
|
|
84
|
+
resolved = v;
|
|
85
|
+
best = known;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return resolved;
|
|
89
|
+
}
|
|
90
|
+
function flagSince(ann) {
|
|
91
|
+
const out = /* @__PURE__ */ new Map();
|
|
92
|
+
for (const entry of (_nullishCoalesce(ann["kit/flag-since"], () => ( ""))).split(",")) {
|
|
93
|
+
const e = entry.trim();
|
|
94
|
+
const eq = e.indexOf("=");
|
|
95
|
+
if (eq < 0) continue;
|
|
96
|
+
out.set(e.slice(0, eq).trim(), e.slice(eq + 1).trim());
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
function fieldOf(rec, name) {
|
|
101
|
+
if (name in rec) return rec[name];
|
|
102
|
+
const k = Object.keys(rec).find((x) => x.toLowerCase() === name);
|
|
103
|
+
return k === void 0 ? void 0 : rec[k];
|
|
104
|
+
}
|
|
105
|
+
function decodeList(raw, fields) {
|
|
106
|
+
if (!raw) return void 0;
|
|
107
|
+
let parsed;
|
|
108
|
+
try {
|
|
109
|
+
parsed = JSON.parse(raw);
|
|
110
|
+
} catch (e2) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
if (parsed === null) return [];
|
|
114
|
+
if (!Array.isArray(parsed)) return void 0;
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const item of parsed) {
|
|
117
|
+
if (item === null) {
|
|
118
|
+
out.push(Object.fromEntries(fields.filter((f) => f.required).map((f) => [f.name, ""])));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (typeof item !== "object" || Array.isArray(item)) return void 0;
|
|
122
|
+
const rec = {};
|
|
123
|
+
for (const f of fields) {
|
|
124
|
+
const v = fieldOf(item, f.name);
|
|
125
|
+
if (v === void 0 || v === null) {
|
|
126
|
+
if (f.required) rec[f.name] = "";
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (typeof v !== "string") return void 0;
|
|
130
|
+
if (v !== "" || f.required) rec[f.name] = v;
|
|
131
|
+
}
|
|
132
|
+
out.push(rec);
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
var DRY_RUN_SIDE_EFFECTS = /* @__PURE__ */ new Set([
|
|
137
|
+
"write",
|
|
138
|
+
"write-local",
|
|
139
|
+
"write-shared",
|
|
140
|
+
"destructive",
|
|
141
|
+
"destructive-local",
|
|
142
|
+
"destructive-shared"
|
|
143
|
+
]);
|
|
144
|
+
function dryRunSupported(name, ann) {
|
|
145
|
+
switch (ann["kit/dry-run"]) {
|
|
146
|
+
case "opted-out":
|
|
147
|
+
return false;
|
|
148
|
+
case "supported":
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if (_chunkCXBZTONYjs.inferredDestructive.call(void 0, name, ann)) return true;
|
|
152
|
+
return DRY_RUN_SIDE_EFFECTS.has(_nullishCoalesce(ann["kit/side-effect"], () => ( "")));
|
|
153
|
+
}
|
|
154
|
+
function manifestFlags(cmd, ann, withHelp) {
|
|
155
|
+
const since = flagSince(ann);
|
|
156
|
+
const visible = cmd.options.filter((o) => !o.hidden);
|
|
157
|
+
const flags = [];
|
|
158
|
+
for (const o of visible) {
|
|
159
|
+
const name = (_nullishCoalesce(_nullishCoalesce(o.long, () => ( o.short)), () => ( ""))).replace(/^-+/, "");
|
|
160
|
+
if (name === "") continue;
|
|
161
|
+
const [type, def] = _chunkSNVGDYX7js.flagTypeAndDefault.call(void 0, o);
|
|
162
|
+
const f = { name };
|
|
163
|
+
if (o.long && o.short) f.short = o.short.replace(/^-/, "");
|
|
164
|
+
f.type = type;
|
|
165
|
+
if (o.description) f.description = o.description;
|
|
166
|
+
if (def !== "") f.default = def;
|
|
167
|
+
const sv = since.get(name);
|
|
168
|
+
if (sv) f.since_version = sv;
|
|
169
|
+
if (o.mandatory) f.required = true;
|
|
170
|
+
const choices = _chunkSNVGDYX7js.flagChoices.call(void 0, o);
|
|
171
|
+
if (choices) f.choices = choices;
|
|
172
|
+
flags.push(f);
|
|
173
|
+
}
|
|
174
|
+
if (withHelp && !flags.some((f) => f.name === "help")) {
|
|
175
|
+
const help = { name: "help" };
|
|
176
|
+
if (!flags.some((f) => f.short === "h")) help.short = "h";
|
|
177
|
+
help.type = "bool";
|
|
178
|
+
help.description = `help for ${cmd.name()}`;
|
|
179
|
+
help.default = "false";
|
|
180
|
+
flags.push(help);
|
|
181
|
+
}
|
|
182
|
+
flags.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
183
|
+
return flags.length > 0 ? flags : void 0;
|
|
184
|
+
}
|
|
185
|
+
function manifestArgs(cmd, ann) {
|
|
186
|
+
const declared = _chunkSNVGDYX7js.parseKitArgs.call(void 0, ann["kit/args"]);
|
|
187
|
+
const args = declared ? declared.map((a) => {
|
|
188
|
+
const out = { name: a.name };
|
|
189
|
+
if (!a.optional) out.required = true;
|
|
190
|
+
if (a.variadic) out.variadic = true;
|
|
191
|
+
return out;
|
|
192
|
+
}) : _chunkSNVGDYX7js.declaredArgs.call(void 0, cmd);
|
|
193
|
+
return args.length > 0 ? args : void 0;
|
|
194
|
+
}
|
|
195
|
+
function manifestCommand(cmd, path, hidden, reserved, invoked) {
|
|
196
|
+
const ann = _chunkSNVGDYX7js.annotationsOf.call(void 0, cmd);
|
|
197
|
+
const summary = cmd.summary();
|
|
198
|
+
const short = summary || cmd.description();
|
|
199
|
+
const long = summary ? cmd.description() : "";
|
|
200
|
+
const out = {
|
|
201
|
+
path,
|
|
202
|
+
short,
|
|
203
|
+
side_effect: ann["kit/side-effect"] || SIDE_EFFECT_UNKNOWN,
|
|
204
|
+
idempotent: ann["kit/idempotent"] || IDEMPOTENT_UNKNOWN
|
|
205
|
+
};
|
|
206
|
+
const args = manifestArgs(cmd, ann);
|
|
207
|
+
if (args) out.args = args;
|
|
208
|
+
const flags = manifestFlags(cmd, ann, invoked);
|
|
209
|
+
if (flags) out.flags = flags;
|
|
210
|
+
const exitCodes = _chunkSNVGDYX7js.splitCSV.call(void 0, ann["kit/exit-codes"]);
|
|
211
|
+
if (exitCodes) out.exit_codes = exitCodes;
|
|
212
|
+
const deprecatedSince = _nullishCoalesce(ann["kit/deprecated-since"], () => ( ""));
|
|
213
|
+
const removalTarget = _nullishCoalesce(ann["kit/removal-target"], () => ( ""));
|
|
214
|
+
if (deprecatedSince || removalTarget) out.deprecated = true;
|
|
215
|
+
if (deprecatedSince) out.deprecated_since = deprecatedSince;
|
|
216
|
+
if (removalTarget) out.removal_target = removalTarget;
|
|
217
|
+
if (ann["kit/since"]) out.since_version = ann["kit/since"];
|
|
218
|
+
if (long) out.long = long;
|
|
219
|
+
out.retryable = ann["kit/retryable"] === "true";
|
|
220
|
+
const schema = ann["kit/output-schema"];
|
|
221
|
+
if (schema) {
|
|
222
|
+
out.output_schema = schema;
|
|
223
|
+
if (ann["kit/output-schema-version"]) {
|
|
224
|
+
out.output_schema_version = ann["kit/output-schema-version"];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const examples = decodeList(ann["kit/examples"], [
|
|
228
|
+
{ name: "title", required: true },
|
|
229
|
+
{ name: "command", required: true },
|
|
230
|
+
{ name: "output", required: false }
|
|
231
|
+
]);
|
|
232
|
+
if (examples && examples.length > 0) out.examples = examples;
|
|
233
|
+
const nextSteps = decodeList(ann["kit/next-steps"], [
|
|
234
|
+
{ name: "when", required: false },
|
|
235
|
+
{ name: "suggest", required: true },
|
|
236
|
+
{ name: "reason", required: false }
|
|
237
|
+
]);
|
|
238
|
+
if (nextSteps && nextSteps.length > 0) out.next_steps = nextSteps;
|
|
239
|
+
if (ann["kit/top-level-verb"] === "true") out.top_level_verb = true;
|
|
240
|
+
if (ann["kit/hierarchical"] === "true") out.hierarchical = true;
|
|
241
|
+
if (ann["kit/passthrough"] === "true") out.passthrough = true;
|
|
242
|
+
const token = ann["kit/destructive-token"];
|
|
243
|
+
if (token === "required" || token === "true") out.destructive_token_required = true;
|
|
244
|
+
out.dry_run_supported = dryRunSupported(cmd.name(), ann);
|
|
245
|
+
if (ann["kit/dry-run-rationale"]) out.dry_run_rationale = ann["kit/dry-run-rationale"];
|
|
246
|
+
if (reserved) out.reserved = true;
|
|
247
|
+
if (hidden) out.hidden = true;
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
function buildManifest(program, schemaVersion, opts = {}) {
|
|
251
|
+
const m = {
|
|
252
|
+
tool: program.name(),
|
|
253
|
+
version: _nullishCoalesce(program.version(), () => ( "")),
|
|
254
|
+
schema_version: schemaVersion,
|
|
255
|
+
commands: []
|
|
256
|
+
};
|
|
257
|
+
_chunkSNVGDYX7js.walkCommands.call(void 0, program, opts.reserved, (cmd, parent, path, reserved) => {
|
|
258
|
+
const ann = _chunkSNVGDYX7js.annotationsOf.call(void 0, cmd);
|
|
259
|
+
const deprecated = !!(ann["kit/deprecated-since"] || ann["kit/removal-target"]);
|
|
260
|
+
if (!_chunkSNVGDYX7js.isRunnable.call(void 0, cmd) || _chunkSNVGDYX7js.isBuiltin.call(void 0, cmd, parent)) return;
|
|
261
|
+
if (deprecated && !opts.includeDeprecated) return;
|
|
262
|
+
m.commands.push(
|
|
263
|
+
manifestCommand(cmd, path, _chunkSNVGDYX7js.isHidden.call(void 0, cmd, parent), reserved, cmd === opts.invokedCommand)
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
return m;
|
|
267
|
+
}
|
|
268
|
+
function renderManifestJSON(m) {
|
|
269
|
+
return _chunkSNVGDYX7js.encodeGoJSON.call(void 0, m, 0, /* @__PURE__ */ new Set(["output_schema"])) + "\n";
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/toolspec-spec.ts
|
|
273
|
+
var _commander = require('commander');
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
// src/toolspec-spec-schemas.ts
|
|
277
|
+
var MANIFEST_OUTPUT_SCHEMA = '{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://hop.top/kit/go/ai/toolspec/manifest","$ref":"#/$defs/Manifest","$defs":{"Manifest":{"properties":{"tool":{"type":"string"},"version":{"type":"string"},"schema_version":{"type":"string"},"commands":{"items":{"$ref":"#/$defs/ManifestCommand"},"type":"array"}},"additionalProperties":false,"type":"object","required":["tool","version","schema_version","commands"]},"ManifestArg":{"properties":{"name":{"type":"string"},"required":{"type":"boolean"},"variadic":{"type":"boolean"}},"additionalProperties":false,"type":"object","required":["name"]},"ManifestCommand":{"properties":{"path":{"items":{"type":"string"},"type":"array"},"short":{"type":"string"},"side_effect":{"type":"string"},"idempotent":{"type":"string"},"args":{"items":{"$ref":"#/$defs/ManifestArg"},"type":"array"},"flags":{"items":{"$ref":"#/$defs/ManifestFlag"},"type":"array"},"exit_codes":{"items":{"type":"string"},"type":"array"},"deprecated":{"type":"boolean"},"deprecated_since":{"type":"string"},"removal_target":{"type":"string"},"since_version":{"type":"string"},"long":{"type":"string"},"retryable":{"type":"boolean"},"output_schema":{"$ref":"#/$defs/RawJSON"},"output_schema_version":{"type":"string"},"examples":{"items":{"$ref":"#/$defs/ManifestExample"},"type":"array"},"next_steps":{"items":{"$ref":"#/$defs/ManifestNextStep"},"type":"array"},"top_level_verb":{"type":"boolean"},"hierarchical":{"type":"boolean"},"passthrough":{"type":"boolean"},"destructive_token_required":{"type":"boolean"},"dry_run_supported":{"type":"boolean"},"dry_run_rationale":{"type":"string"},"reserved":{"type":"boolean"},"hidden":{"type":"boolean"}},"additionalProperties":false,"type":"object","required":["path","short","side_effect","idempotent","retryable","dry_run_supported"]},"ManifestExample":{"properties":{"title":{"type":"string"},"command":{"type":"string"},"output":{"type":"string"}},"additionalProperties":false,"type":"object","required":["title","command"]},"ManifestFlag":{"properties":{"name":{"type":"string"},"short":{"type":"string"},"type":{"type":"string"},"description":{"type":"string"},"default":{"type":"string"},"since_version":{"type":"string"},"required":{"type":"boolean"},"choices":{"items":{"type":"string"},"type":"array"}},"additionalProperties":false,"type":"object","required":["name"]},"ManifestNextStep":{"properties":{"when":{"type":"string"},"suggest":{"type":"string"},"reason":{"type":"string"}},"additionalProperties":false,"type":"object","required":["suggest"]},"RawJSON":{"type":"string","contentEncoding":"base64"}}}';
|
|
278
|
+
var COVERAGE_REPORT_OUTPUT_SCHEMA = '{"$schema":"https://json-schema.org/draft/2020-12/schema","$id":"https://hop.top/kit/go/ai/toolspec/cli/coverage-report","$ref":"#/$defs/CoverageReport","$defs":{"CoverageReport":{"properties":{"tool":{"type":"string"},"total":{"type":"integer"},"annotated":{"type":"integer"},"unannotated":{"type":"integer"},"inferred":{"type":"integer"},"malformed":{"type":"integer"},"unannotated_paths":{"items":{"type":"string"},"type":"array"},"malformed_paths":{"items":{"type":"string"},"type":"array"},"measurable":{"type":"boolean"}},"additionalProperties":false,"type":"object","required":["tool","total","annotated","unannotated","inferred","malformed","measurable"]}}}';
|
|
279
|
+
|
|
280
|
+
// src/toolspec-spec.ts
|
|
281
|
+
var SPEC_COMMAND_ANNOTATION = "kit/spec-command";
|
|
282
|
+
var KIT_MANIFEST = "kit-manifest";
|
|
283
|
+
var KIT_MANIFEST_ALIASES = ["kit", "manifest"];
|
|
284
|
+
var LEGACY_FORMATS = ["json", "yaml", "table", "csv", "text"];
|
|
285
|
+
function formatFlag(cmd) {
|
|
286
|
+
const v = cmd.optsWithGlobals().format;
|
|
287
|
+
const src = cmd.getOptionValueSourceWithGlobals("format");
|
|
288
|
+
return [typeof v === "string" ? v : "", src === "cli"];
|
|
289
|
+
}
|
|
290
|
+
function toYAML(v) {
|
|
291
|
+
return yaml.dump(v, { quotingType: '"', lineWidth: -1 });
|
|
292
|
+
}
|
|
293
|
+
function manifestYAML(m) {
|
|
294
|
+
const projected = {
|
|
295
|
+
...m,
|
|
296
|
+
commands: m.commands.map(
|
|
297
|
+
(c) => c.output_schema === void 0 ? c : { ...c, output_schema: JSON.parse(c.output_schema) }
|
|
298
|
+
)
|
|
299
|
+
};
|
|
300
|
+
return toYAML(projected);
|
|
301
|
+
}
|
|
302
|
+
function registerSpecCommand(program, schemaVersion, opts = {}) {
|
|
303
|
+
const reserved = [..._nullishCoalesce(opts.reserved, () => ( [])), "spec"];
|
|
304
|
+
const tool = program.name();
|
|
305
|
+
const spec = new (0, _commander.Command)("spec").summary("Emit machine-readable capability manifest").description(
|
|
306
|
+
"Emit the tool's full capability manifest as JSON/YAML/table. Agents consume this for capability negotiation and dispatch. --version prints only the schema version."
|
|
307
|
+
).option("--version", "Print the schema version only (capability negotiation)").option(
|
|
308
|
+
"--include-deprecated",
|
|
309
|
+
"Include deprecated commands in the manifest (default: hidden)"
|
|
310
|
+
);
|
|
311
|
+
if (!program.options.some((o) => o.long === "--format")) {
|
|
312
|
+
spec.option("--format <format>", "Output format");
|
|
313
|
+
}
|
|
314
|
+
spec.annotations = {
|
|
315
|
+
"kit/side-effect": "read",
|
|
316
|
+
"kit/idempotent": "yes",
|
|
317
|
+
[SPEC_COMMAND_ANNOTATION]: "true",
|
|
318
|
+
"kit/top-level-verb": "true",
|
|
319
|
+
"kit/output-schema": MANIFEST_OUTPUT_SCHEMA,
|
|
320
|
+
"kit/output-schema-version": schemaVersion,
|
|
321
|
+
"kit/examples": JSON.stringify([
|
|
322
|
+
{ title: "Full capabilities", command: `${tool} spec --format json` },
|
|
323
|
+
{ title: "Schema probe", command: `${tool} spec --version` },
|
|
324
|
+
{ title: "Filter to old clients", command: `${tool} spec --api-version=1.0` }
|
|
325
|
+
])
|
|
326
|
+
};
|
|
327
|
+
let versionForwarded = false;
|
|
328
|
+
forwardVersionToSpec(program, spec, () => {
|
|
329
|
+
versionForwarded = true;
|
|
330
|
+
}, () => {
|
|
331
|
+
versionForwarded = false;
|
|
332
|
+
});
|
|
333
|
+
spec.action(function() {
|
|
334
|
+
const out = (s) => this.configureOutput().writeOut(s);
|
|
335
|
+
const resolved = negotiateSchemaVersion(
|
|
336
|
+
schemaVersion,
|
|
337
|
+
_nullishCoalesce(process.env[SCHEMA_VERSION_ENV], () => ( ""))
|
|
338
|
+
);
|
|
339
|
+
const local = this.opts();
|
|
340
|
+
const [given, changed] = formatFlag(this);
|
|
341
|
+
const format = changed ? given : "";
|
|
342
|
+
if (local.version || versionForwarded) {
|
|
343
|
+
const vf = format === "" ? "json" : format;
|
|
344
|
+
if (vf === "json") {
|
|
345
|
+
out(_chunkSNVGDYX7js.encodeGoJSON.call(void 0, { schema_version: resolved }, 0, /* @__PURE__ */ new Set()) + "\n");
|
|
346
|
+
} else if (vf === "yaml") {
|
|
347
|
+
out(toYAML({ schema_version: resolved }));
|
|
348
|
+
} else {
|
|
349
|
+
out(resolved + "\n");
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
let outputFormat;
|
|
354
|
+
if (format === "" || format === KIT_MANIFEST || KIT_MANIFEST_ALIASES.includes(format)) {
|
|
355
|
+
outputFormat = "json";
|
|
356
|
+
} else if (LEGACY_FORMATS.includes(format)) {
|
|
357
|
+
outputFormat = format;
|
|
358
|
+
} else {
|
|
359
|
+
const valid = [KIT_MANIFEST, ...LEGACY_FORMATS].join(", ");
|
|
360
|
+
this.error(`unknown --format ${JSON.stringify(format)} (valid: ${valid})`, {
|
|
361
|
+
exitCode: _chunkPOR5L2DGjs.EXIT_GENERIC,
|
|
362
|
+
code: "kit.spec.unknownFormat"
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
const manifest = buildManifest(program, resolved, {
|
|
366
|
+
includeDeprecated: local.includeDeprecated === true,
|
|
367
|
+
reserved,
|
|
368
|
+
invokedCommand: this
|
|
369
|
+
});
|
|
370
|
+
if (outputFormat === "json") out(renderManifestJSON(manifest));
|
|
371
|
+
else if (outputFormat === "yaml") out(manifestYAML(manifest));
|
|
372
|
+
});
|
|
373
|
+
registerCoverageCommand(spec, program, reserved);
|
|
374
|
+
program.addCommand(spec);
|
|
375
|
+
return spec;
|
|
376
|
+
}
|
|
377
|
+
var WRAPPED = /* @__PURE__ */ new WeakSet();
|
|
378
|
+
function selectedSubcommand(cmd, args) {
|
|
379
|
+
const options = [cmd, ...ancestors(cmd)].flatMap((c) => c.options);
|
|
380
|
+
const find = (flag) => options.find((o) => o.long === flag || o.short === flag);
|
|
381
|
+
for (let i = 0; i < args.length; i++) {
|
|
382
|
+
const a = args[i];
|
|
383
|
+
if (a === "--") return void 0;
|
|
384
|
+
if (a.length > 1 && a.startsWith("-")) {
|
|
385
|
+
const long = a.startsWith("--");
|
|
386
|
+
const opt = find(long ? a.split("=")[0] : a.slice(0, 2));
|
|
387
|
+
const inline = long ? a.includes("=") : a.length > 2;
|
|
388
|
+
const next = args[i + 1];
|
|
389
|
+
if (opt && !inline && (opt.required || opt.optional && next !== void 0 && !next.startsWith("-"))) {
|
|
390
|
+
i++;
|
|
391
|
+
}
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
const sub = cmd.commands.find((c) => c.name() === a || c.aliases().includes(a));
|
|
395
|
+
return sub ? [sub, args.slice(i + 1)] : void 0;
|
|
396
|
+
}
|
|
397
|
+
return void 0;
|
|
398
|
+
}
|
|
399
|
+
function ancestors(cmd) {
|
|
400
|
+
const out = [];
|
|
401
|
+
for (let c = cmd.parent; c; c = c.parent) out.push(c);
|
|
402
|
+
return out;
|
|
403
|
+
}
|
|
404
|
+
function forwardVersionToSpec(program, spec, forward, reset) {
|
|
405
|
+
let forwarding = false;
|
|
406
|
+
const original = program.parseOptions.bind(program);
|
|
407
|
+
const wrapListeners = () => {
|
|
408
|
+
const versionOpt = program.options.find(
|
|
409
|
+
(o) => o.long === "--version"
|
|
410
|
+
);
|
|
411
|
+
if (!versionOpt) return;
|
|
412
|
+
const event = `option:${versionOpt.name()}`;
|
|
413
|
+
const emitter = program;
|
|
414
|
+
for (const l of emitter.listeners(event)) {
|
|
415
|
+
if (WRAPPED.has(l)) continue;
|
|
416
|
+
const wrapped = function(...a) {
|
|
417
|
+
if (forwarding) {
|
|
418
|
+
forward();
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
l.apply(this, a);
|
|
422
|
+
};
|
|
423
|
+
WRAPPED.add(wrapped);
|
|
424
|
+
emitter.removeListener(event, l);
|
|
425
|
+
emitter.on(event, wrapped);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
program.parseOptions = (args) => {
|
|
429
|
+
reset();
|
|
430
|
+
wrapListeners();
|
|
431
|
+
let executing = program;
|
|
432
|
+
let rest = args;
|
|
433
|
+
for (let sel = selectedSubcommand(executing, rest); sel; sel = selectedSubcommand(executing, rest)) {
|
|
434
|
+
[executing, rest] = sel;
|
|
435
|
+
}
|
|
436
|
+
forwarding = executing === spec && args.includes("--version");
|
|
437
|
+
try {
|
|
438
|
+
return original(args);
|
|
439
|
+
} finally {
|
|
440
|
+
forwarding = false;
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
var KNOWN_SIDE_EFFECTS = /* @__PURE__ */ new Set([
|
|
445
|
+
"read",
|
|
446
|
+
"write",
|
|
447
|
+
"write-local",
|
|
448
|
+
"write-shared",
|
|
449
|
+
"destructive",
|
|
450
|
+
"destructive-local",
|
|
451
|
+
"destructive-shared",
|
|
452
|
+
"interactive"
|
|
453
|
+
]);
|
|
454
|
+
var DESTRUCTIVE_NAMES = /* @__PURE__ */ new Set(["delete", "remove", "rm", "destroy", "purge", "drop"]);
|
|
455
|
+
function coverageOf(program, opts = {}) {
|
|
456
|
+
const rep = {
|
|
457
|
+
tool: program.name(),
|
|
458
|
+
total: 0,
|
|
459
|
+
annotated: 0,
|
|
460
|
+
unannotated: 0,
|
|
461
|
+
inferred: 0,
|
|
462
|
+
malformed: 0,
|
|
463
|
+
measurable: false
|
|
464
|
+
};
|
|
465
|
+
const unannotated = [];
|
|
466
|
+
const malformed = [];
|
|
467
|
+
_chunkSNVGDYX7js.walkCommands.call(void 0, program, opts.reserved, (cmd, parent, path, reserved) => {
|
|
468
|
+
const ann = _chunkSNVGDYX7js.annotationsOf.call(void 0, cmd);
|
|
469
|
+
if (!_chunkSNVGDYX7js.isRunnable.call(void 0, cmd) || _chunkSNVGDYX7js.isBuiltin.call(void 0, cmd, parent) || reserved) return;
|
|
470
|
+
if (ann[SPEC_COMMAND_ANNOTATION] === "true") return;
|
|
471
|
+
rep.total++;
|
|
472
|
+
const p = path.join(" ");
|
|
473
|
+
const raw = _nullishCoalesce(ann["kit/side-effect"], () => ( ""));
|
|
474
|
+
if (raw !== "" && !KNOWN_SIDE_EFFECTS.has(raw)) {
|
|
475
|
+
rep.malformed++;
|
|
476
|
+
malformed.push(`${p}=${JSON.stringify(raw)}`);
|
|
477
|
+
unannotated.push(p);
|
|
478
|
+
} else if (raw === "") {
|
|
479
|
+
if (DESTRUCTIVE_NAMES.has(cmd.name())) rep.inferred++;
|
|
480
|
+
rep.unannotated++;
|
|
481
|
+
unannotated.push(p);
|
|
482
|
+
} else {
|
|
483
|
+
rep.annotated++;
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
rep.unannotated += rep.malformed;
|
|
487
|
+
if (unannotated.length > 0) rep.unannotated_paths = unannotated.sort();
|
|
488
|
+
if (malformed.length > 0) rep.malformed_paths = malformed.sort();
|
|
489
|
+
rep.measurable = rep.total > 0;
|
|
490
|
+
const { measurable, ...rest } = rep;
|
|
491
|
+
return { ...rest, measurable };
|
|
492
|
+
}
|
|
493
|
+
function coveragePercent(r) {
|
|
494
|
+
return r.total === 0 ? 0 : r.annotated / r.total * 100;
|
|
495
|
+
}
|
|
496
|
+
function coverageMeets(r, threshold) {
|
|
497
|
+
if (threshold <= 0) return true;
|
|
498
|
+
if (!r.measurable) return false;
|
|
499
|
+
return coveragePercent(r) >= threshold;
|
|
500
|
+
}
|
|
501
|
+
function captureRender(format, v) {
|
|
502
|
+
let buf = "";
|
|
503
|
+
const sink = {
|
|
504
|
+
write(chunk) {
|
|
505
|
+
buf += String(chunk);
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
_chunkGFRAYYRDjs.render.call(void 0, sink, format, v);
|
|
510
|
+
return buf;
|
|
511
|
+
}
|
|
512
|
+
function registerCoverageCommand(spec, program, reserved) {
|
|
513
|
+
const tool = program.name();
|
|
514
|
+
const min = new (0, _commander.Option)(
|
|
515
|
+
"--min <percent>",
|
|
516
|
+
"Minimum coverage percentage; exit CONFLICT (4) below it (0 disables the gate)"
|
|
517
|
+
).argParser((v) => {
|
|
518
|
+
const n = Number(v);
|
|
519
|
+
if (v.trim() === "" || Number.isNaN(n)) {
|
|
520
|
+
throw new Error(`invalid argument "${v}" for "--min" flag`);
|
|
521
|
+
}
|
|
522
|
+
return n;
|
|
523
|
+
}).default(0);
|
|
524
|
+
_chunkSNVGDYX7js.pflagTypes.set(min, "float64");
|
|
525
|
+
const cmd = new (0, _commander.Command)("coverage").summary("Report kit/side-effect annotation coverage").description(
|
|
526
|
+
"Report how many of this tool's commands declare a kit/side-effect class, list the ones that do not, and exit non-zero when coverage falls below --min.\n\nAn unannotated command is not a read-only command: it is one kit knows nothing about, and every safety gate that consumes the manifest must fail closed on it. This report is how an adopter finds and closes that gap, and how CI keeps it closed."
|
|
527
|
+
).addOption(min);
|
|
528
|
+
cmd.annotations = {
|
|
529
|
+
"kit/side-effect": "read",
|
|
530
|
+
"kit/idempotent": "yes",
|
|
531
|
+
"kit/exit-codes": "OK,CONFLICT",
|
|
532
|
+
[SPEC_COMMAND_ANNOTATION]: "true",
|
|
533
|
+
"kit/output-schema": COVERAGE_REPORT_OUTPUT_SCHEMA,
|
|
534
|
+
"kit/output-schema-version": "1.0",
|
|
535
|
+
"kit/examples": JSON.stringify([
|
|
536
|
+
{ title: "See the gap", command: `${tool} spec coverage --format json` },
|
|
537
|
+
{ title: "Gate in CI", command: `${tool} spec coverage --min 80` }
|
|
538
|
+
])
|
|
539
|
+
};
|
|
540
|
+
cmd.action(function() {
|
|
541
|
+
const rep = coverageOf(program, { reserved });
|
|
542
|
+
const [given, changed] = formatFlag(this);
|
|
543
|
+
const format = changed && given !== "" ? given : "json";
|
|
544
|
+
const text = format === "json" ? _chunkSNVGDYX7js.encodeGoJSON.call(void 0, rep, 0, /* @__PURE__ */ new Set()) + "\n" : captureRender(format, rep);
|
|
545
|
+
this.configureOutput().writeOut(text);
|
|
546
|
+
const threshold = this.opts().min;
|
|
547
|
+
if (coverageMeets(rep, threshold)) return;
|
|
548
|
+
const message = !rep.measurable ? `annotation coverage unmeasurable: no reflectable commands in ${JSON.stringify(rep.tool)} (--min ${_chunkSNVGDYX7js.goFormat0.call(void 0, threshold)}% cannot be evaluated)` : `annotation coverage ${_chunkSNVGDYX7js.goFormat0.call(void 0, coveragePercent(rep))}% (${rep.annotated}/${rep.total}) is below --min ${_chunkSNVGDYX7js.goFormat0.call(void 0, threshold)}%; unannotated: ` + (_nullishCoalesce(rep.unannotated_paths, () => ( []))).join(", ");
|
|
549
|
+
this.error(message, { exitCode: _chunkPOR5L2DGjs.EXIT_CONFLICT, code: "kit.spec.coverageBelowMin" });
|
|
550
|
+
});
|
|
551
|
+
spec.addCommand(cmd);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// src/toolspec.ts
|
|
555
|
+
function mapFlag(raw) {
|
|
556
|
+
return {
|
|
557
|
+
name: _nullishCoalesce(raw.name, () => ( "")),
|
|
558
|
+
short: raw.short,
|
|
559
|
+
type: raw.type,
|
|
560
|
+
description: raw.description,
|
|
561
|
+
required: raw.required,
|
|
562
|
+
deprecated: raw.deprecated,
|
|
563
|
+
replacedBy: raw.replaced_by,
|
|
564
|
+
default: raw.default,
|
|
565
|
+
choices: raw.choices
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
function mapArg(raw) {
|
|
569
|
+
return { name: _nullishCoalesce(raw.name, () => ( "")), required: raw.required, variadic: raw.variadic };
|
|
570
|
+
}
|
|
571
|
+
function mapProvenance(raw) {
|
|
572
|
+
if (!raw) return void 0;
|
|
573
|
+
return {
|
|
574
|
+
source: raw.source,
|
|
575
|
+
retrievedAt: raw.retrieved_at,
|
|
576
|
+
confidence: raw.confidence
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function mapContract(raw) {
|
|
580
|
+
if (!raw) return void 0;
|
|
581
|
+
return {
|
|
582
|
+
idempotent: _nullishCoalesce(raw.idempotent, () => ( false)),
|
|
583
|
+
sideEffects: raw.side_effects,
|
|
584
|
+
retryable: _nullishCoalesce(raw.retryable, () => ( false)),
|
|
585
|
+
preConditions: raw.pre_conditions,
|
|
586
|
+
idempotentClass: raw.idempotent_class
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function mapSafety(raw) {
|
|
590
|
+
if (!raw) return void 0;
|
|
591
|
+
return {
|
|
592
|
+
level: raw.level,
|
|
593
|
+
requiresConfirmation: raw.requires_confirmation,
|
|
594
|
+
permissions: raw.permissions
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function mapOutputSchema(raw) {
|
|
598
|
+
if (!raw) return void 0;
|
|
599
|
+
return {
|
|
600
|
+
format: raw.format,
|
|
601
|
+
fields: raw.fields,
|
|
602
|
+
example: raw.example
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function mapIntent(raw) {
|
|
606
|
+
if (!raw) return void 0;
|
|
607
|
+
return {
|
|
608
|
+
domain: raw.domain,
|
|
609
|
+
category: raw.category,
|
|
610
|
+
tags: raw.tags
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
function mapCommand(raw) {
|
|
614
|
+
return {
|
|
615
|
+
name: _nullishCoalesce(raw.name, () => ( "")),
|
|
616
|
+
short: raw.short,
|
|
617
|
+
aliases: raw.aliases,
|
|
618
|
+
flags: _optionalChain([raw, 'access', _ => _.flags, 'optionalAccess', _2 => _2.map, 'call', _3 => _3(mapFlag)]),
|
|
619
|
+
args: _optionalChain([raw, 'access', _4 => _4.args, 'optionalAccess', _5 => _5.map, 'call', _6 => _6(mapArg)]),
|
|
620
|
+
undeclaredArgs: raw.undeclared_args,
|
|
621
|
+
exitCodes: raw.exit_codes,
|
|
622
|
+
children: _optionalChain([raw, 'access', _7 => _7.children, 'optionalAccess', _8 => _8.map, 'call', _9 => _9(mapCommand)]),
|
|
623
|
+
contract: mapContract(raw.contract),
|
|
624
|
+
safety: mapSafety(raw.safety),
|
|
625
|
+
previewModes: raw.preview_modes,
|
|
626
|
+
outputSchema: mapOutputSchema(raw.output_schema),
|
|
627
|
+
deprecated: raw.deprecated,
|
|
628
|
+
deprecatedSince: raw.deprecated_since,
|
|
629
|
+
replacedBy: raw.replaced_by,
|
|
630
|
+
intent: mapIntent(raw.intent),
|
|
631
|
+
suggestedNext: raw.suggested_next
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function mapStateIntrospection(raw) {
|
|
635
|
+
if (!raw) return void 0;
|
|
636
|
+
return {
|
|
637
|
+
configCommands: raw.config_commands,
|
|
638
|
+
envVars: raw.env_vars,
|
|
639
|
+
authCommands: raw.auth_commands
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
function mapErrorPattern(raw) {
|
|
643
|
+
return {
|
|
644
|
+
pattern: _nullishCoalesce(raw.pattern, () => ( "")),
|
|
645
|
+
fix: _nullishCoalesce(raw.fix, () => ( "")),
|
|
646
|
+
source: raw.source,
|
|
647
|
+
cause: raw.cause,
|
|
648
|
+
fixes: raw.fixes,
|
|
649
|
+
confidence: raw.confidence,
|
|
650
|
+
provenance: mapProvenance(raw.provenance)
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
function mapWorkflow(raw) {
|
|
654
|
+
return {
|
|
655
|
+
name: _nullishCoalesce(raw.name, () => ( "")),
|
|
656
|
+
steps: _nullishCoalesce(raw.steps, () => ( [])),
|
|
657
|
+
after: raw.after,
|
|
658
|
+
provenance: mapProvenance(raw.provenance)
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function loadToolSpec(yamlPath) {
|
|
662
|
+
const content = fs.readFileSync(yamlPath, "utf-8");
|
|
663
|
+
const raw = yaml2.load(content);
|
|
664
|
+
return {
|
|
665
|
+
name: _nullishCoalesce(raw.name, () => ( "")),
|
|
666
|
+
schemaVersion: _nullishCoalesce(raw.schema_version, () => ( "")),
|
|
667
|
+
commands: (_nullishCoalesce(raw.commands, () => ( []))).map(mapCommand),
|
|
668
|
+
flags: _optionalChain([raw, 'access', _10 => _10.flags, 'optionalAccess', _11 => _11.map, 'call', _12 => _12(mapFlag)]),
|
|
669
|
+
errorPatterns: _optionalChain([raw, 'access', _13 => _13.error_patterns, 'optionalAccess', _14 => _14.map, 'call', _15 => _15(mapErrorPattern)]),
|
|
670
|
+
workflows: _optionalChain([raw, 'access', _16 => _16.workflows, 'optionalAccess', _17 => _17.map, 'call', _18 => _18(mapWorkflow)]),
|
|
671
|
+
stateIntrospection: mapStateIntrospection(
|
|
672
|
+
raw.state_introspection
|
|
673
|
+
)
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
var VALID_SAFETY_LEVELS = /* @__PURE__ */ new Set([
|
|
677
|
+
"safe",
|
|
678
|
+
"caution",
|
|
679
|
+
"dangerous"
|
|
680
|
+
]);
|
|
681
|
+
function validateToolSpec(spec) {
|
|
682
|
+
const errors = [];
|
|
683
|
+
if (!spec.name) errors.push("name is required");
|
|
684
|
+
if (!spec.schemaVersion) errors.push("schemaVersion is required");
|
|
685
|
+
if (!spec.commands || spec.commands.length === 0) {
|
|
686
|
+
errors.push("at least one command is required");
|
|
687
|
+
}
|
|
688
|
+
const validateCmd = (cmd, path) => {
|
|
689
|
+
if (!cmd.name) {
|
|
690
|
+
errors.push(`${path}: command name is required`);
|
|
691
|
+
}
|
|
692
|
+
if (cmd.safety && !VALID_SAFETY_LEVELS.has(cmd.safety.level)) {
|
|
693
|
+
errors.push(
|
|
694
|
+
`${path}: invalid safety level "${cmd.safety.level}" (must be safe|caution|dangerous)`
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
if (_optionalChain([cmd, 'access', _19 => _19.exitCodes, 'optionalAccess', _20 => _20.some, 'call', _21 => _21((c) => typeof c !== "string" || c.trim() === "")])) {
|
|
698
|
+
errors.push(`${path}: exit code symbols must be non-empty strings`);
|
|
699
|
+
}
|
|
700
|
+
if (cmd.children) {
|
|
701
|
+
for (const child of cmd.children) {
|
|
702
|
+
validateCmd(child, `${path}/${child.name || "<unnamed>"}`);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
for (const cmd of _nullishCoalesce(spec.commands, () => ( []))) {
|
|
707
|
+
validateCmd(cmd, cmd.name || "<unnamed>");
|
|
708
|
+
}
|
|
709
|
+
return errors;
|
|
710
|
+
}
|
|
711
|
+
function findCommand(spec, name) {
|
|
712
|
+
const queue = [...spec.commands];
|
|
713
|
+
while (queue.length > 0) {
|
|
714
|
+
const c = queue.shift();
|
|
715
|
+
if (c.name === name) return c;
|
|
716
|
+
if (c.children) queue.push(...c.children);
|
|
717
|
+
}
|
|
718
|
+
return void 0;
|
|
719
|
+
}
|
|
720
|
+
function toolSpecFromCommand(program, opts = {}) {
|
|
721
|
+
const ctx = {
|
|
722
|
+
annotations: _nullishCoalesce(opts.annotations, () => ( {})),
|
|
723
|
+
includeHidden: _nullishCoalesce(opts.includeHidden, () => ( false))
|
|
724
|
+
};
|
|
725
|
+
const spec = {
|
|
726
|
+
name: program.name(),
|
|
727
|
+
schemaVersion: _nullishCoalesce(opts.schemaVersion, () => ( "1")),
|
|
728
|
+
commands: projectChildren(program, [], ctx)
|
|
729
|
+
};
|
|
730
|
+
const flags = projectFlags(program);
|
|
731
|
+
if (flags) spec.flags = flags;
|
|
732
|
+
return spec;
|
|
733
|
+
}
|
|
734
|
+
function projectChildren(cmd, path, ctx) {
|
|
735
|
+
const visible = cmd.createHelp().visibleCommands(cmd);
|
|
736
|
+
return cmd.commands.filter((c) => c.name() !== "").filter((c) => ctx.includeHidden || visible.includes(c)).filter((c) => !_chunkSNVGDYX7js.isBuiltin.call(void 0, c, cmd)).filter((c) => kitAnnotations(c)["kit/spec-command"] !== "true").map((c) => projectCommand(c, [...path, c.name()], ctx));
|
|
737
|
+
}
|
|
738
|
+
function projectCommand(cmd, path, ctx) {
|
|
739
|
+
const out = { name: cmd.name() };
|
|
740
|
+
const short = cmd.summary() || cmd.description();
|
|
741
|
+
if (short) out.short = short;
|
|
742
|
+
const aliases = cmd.aliases();
|
|
743
|
+
if (aliases.length > 0) out.aliases = [...aliases];
|
|
744
|
+
const flags = projectFlags(cmd);
|
|
745
|
+
if (flags) out.flags = flags;
|
|
746
|
+
const args = _chunkSNVGDYX7js.declaredArgs.call(void 0, cmd);
|
|
747
|
+
if (args.length > 0) out.args = args;
|
|
748
|
+
const exitCodes = splitCSV2(kitAnnotations(cmd)["kit/exit-codes"]);
|
|
749
|
+
if (exitCodes) out.exitCodes = exitCodes;
|
|
750
|
+
const children = projectChildren(cmd, path, ctx);
|
|
751
|
+
if (children.length > 0) out.children = children;
|
|
752
|
+
const contract = projectContract(kitAnnotations(cmd));
|
|
753
|
+
if (contract) out.contract = contract;
|
|
754
|
+
const ann = ctx.annotations[path.join(" ")];
|
|
755
|
+
if (ann) {
|
|
756
|
+
for (const [k, v] of Object.entries(ann)) {
|
|
757
|
+
if (v !== void 0) out[k] = v;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return out;
|
|
761
|
+
}
|
|
762
|
+
function kitAnnotations(cmd) {
|
|
763
|
+
return _nullishCoalesce(cmd.annotations, () => ( {}));
|
|
764
|
+
}
|
|
765
|
+
function splitCSV2(s) {
|
|
766
|
+
if (!s) return void 0;
|
|
767
|
+
const out = s.split(",").map((p) => p.trim()).filter((p) => p !== "");
|
|
768
|
+
return out.length > 0 ? out : void 0;
|
|
769
|
+
}
|
|
770
|
+
var IDEMPOTENT_CLASSES = /* @__PURE__ */ new Set(["yes", "no", "conditional"]);
|
|
771
|
+
function projectContract(ann) {
|
|
772
|
+
const sideEffect = ann["kit/side-effect"];
|
|
773
|
+
const cls = ann["kit/idempotent"];
|
|
774
|
+
const retryable = ann["kit/retryable"] === "true";
|
|
775
|
+
const hasClass = cls !== void 0 && IDEMPOTENT_CLASSES.has(cls);
|
|
776
|
+
if (!sideEffect && !hasClass && !retryable) return void 0;
|
|
777
|
+
const out = { idempotent: hasClass && cls === "yes", retryable };
|
|
778
|
+
if (sideEffect) out.sideEffects = [sideEffect];
|
|
779
|
+
if (hasClass) out.idempotentClass = cls;
|
|
780
|
+
return out;
|
|
781
|
+
}
|
|
782
|
+
function projectFlags(cmd) {
|
|
783
|
+
const out = [];
|
|
784
|
+
for (const opt of cmd.options) {
|
|
785
|
+
if (opt.hidden) continue;
|
|
786
|
+
const name = (_nullishCoalesce(_nullishCoalesce(opt.long, () => ( opt.short)), () => ( ""))).replace(/^-+/, "");
|
|
787
|
+
if (!name) continue;
|
|
788
|
+
const flag = { name };
|
|
789
|
+
if (opt.long && opt.short) flag.short = opt.short.replace(/^-/, "");
|
|
790
|
+
const [type, def] = _chunkSNVGDYX7js.flagTypeAndDefault.call(void 0, opt);
|
|
791
|
+
flag.type = type;
|
|
792
|
+
if (opt.description) flag.description = opt.description;
|
|
793
|
+
if (opt.mandatory) flag.required = true;
|
|
794
|
+
if (def !== "") flag.default = def;
|
|
795
|
+
const choices = _chunkSNVGDYX7js.flagChoices.call(void 0, opt);
|
|
796
|
+
if (choices) flag.choices = choices;
|
|
797
|
+
out.push(flag);
|
|
798
|
+
}
|
|
799
|
+
return out.length > 0 ? out : void 0;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
exports.SCHEMA_VERSION_ENV = SCHEMA_VERSION_ENV; exports.LATEST_SCHEMA_VERSION = LATEST_SCHEMA_VERSION; exports.SIDE_EFFECT_UNKNOWN = SIDE_EFFECT_UNKNOWN; exports.IDEMPOTENT_UNKNOWN = IDEMPOTENT_UNKNOWN; exports.negotiateSchemaVersion = negotiateSchemaVersion; exports.buildManifest = buildManifest; exports.renderManifestJSON = renderManifestJSON; exports.SPEC_COMMAND_ANNOTATION = SPEC_COMMAND_ANNOTATION; exports.registerSpecCommand = registerSpecCommand; exports.coverageOf = coverageOf; exports.loadToolSpec = loadToolSpec; exports.validateToolSpec = validateToolSpec; exports.findCommand = findCommand; exports.toolSpecFromCommand = toolSpecFromCommand; exports.toolspec_exports = toolspec_exports;
|