@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +275 -0
- package/LICENSE +1 -1
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +55 -259
- package/dist/aim-DZHwwiIc.d.ts +139 -0
- package/dist/aim.d.ts +1 -116
- package/dist/aim.js +13 -414
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +2 -73
- package/dist/alias.js +27 -207
- package/dist/api-DAexsu2H.d.ts +77 -0
- package/dist/api.d.ts +1 -62
- package/dist/api.js +10 -164
- package/dist/auth-2-jfgiHn.d.ts +34 -0
- package/dist/auth.d.ts +1 -26
- package/dist/auth.js +6 -40
- package/dist/chunk-3FIKGFKI.js +54 -0
- package/dist/chunk-4FMALWYB.js +669 -0
- package/dist/chunk-4GPCWBBA.js +143 -0
- package/dist/chunk-4UE5TCMQ.js +104 -0
- package/dist/chunk-65VPWMPV.js +1134 -0
- package/dist/chunk-6HFAEZ52.js +29 -0
- package/dist/chunk-6SVOHNIC.js +17 -0
- package/dist/chunk-BDNNPRX6.js +41 -0
- package/dist/chunk-BRNEKPWX.js +37 -0
- package/dist/chunk-BXJ2J27B.js +219 -0
- package/dist/chunk-CSJWB6D3.js +151 -0
- package/dist/chunk-CXBZTONY.js +65 -0
- package/dist/chunk-EE4M2UOF.js +818 -0
- package/dist/chunk-GFRAYYRD.js +817 -0
- package/dist/chunk-IVQHLI56.js +1890 -0
- package/dist/chunk-IZ6Q4SE3.js +178 -0
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-K7E34Q3A.js +1445 -0
- package/dist/chunk-KVG7YCTS.js +115 -0
- package/dist/chunk-L23O2FFE.js +51 -0
- package/dist/chunk-MFVUENZR.js +1549 -0
- package/dist/chunk-ML7D5DWY.js +263 -0
- package/dist/chunk-MQXYDYRD.js +968 -0
- package/dist/chunk-POR5L2DG.js +247 -0
- package/dist/chunk-QJVSKKRQ.js +369 -0
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RYKLVOVK.js +309 -0
- package/dist/chunk-SNVGDYX7.js +187 -0
- package/dist/chunk-T6OZMPPV.js +68 -0
- package/dist/chunk-UKZIAQA7.js +26 -0
- package/dist/chunk-VGOA5Y7S.js +251 -0
- package/dist/chunk-VWGP4NVJ.js +513 -0
- package/dist/chunk-WBVO43HU.js +355 -0
- package/dist/chunk-WUOAQVOA.js +86 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/chunk-YOBAUCVN.js +583 -0
- package/dist/cli-RSRk1M36.d.ts +707 -0
- package/dist/cli.d.ts +7 -309
- package/dist/cli.js +125 -945
- package/dist/completion-csVun6SP.d.ts +112 -0
- package/dist/completion-values-By-mnjNt.d.ts +142 -0
- package/dist/completion-values.d.ts +1 -0
- package/dist/completion-values.js +29 -0
- package/dist/completion.d.ts +3 -0
- package/dist/completion.js +34 -0
- package/dist/compliance-AxFf-uMy.d.ts +60 -0
- package/dist/compliance.d.ts +1 -0
- package/dist/compliance.js +17 -0
- package/dist/config-CaK60ByQ.d.ts +241 -0
- package/dist/config.d.ts +1 -97
- package/dist/config.js +8 -78
- package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
- package/dist/errcorrect.d.ts +1 -37
- package/dist/errcorrect.js +8 -68
- package/dist/error-Do8Qji43.d.ts +231 -0
- package/dist/id/index.d.ts +2 -83
- package/dist/id/index.js +14 -65
- package/dist/index-BKJZClJx.d.ts +1486 -0
- package/dist/index-C3Zw4wDJ.d.ts +359 -0
- package/dist/index-CGE5yLBj.d.ts +328 -0
- package/dist/index-VLDcI5NF.d.ts +95 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +132 -0
- package/dist/llm-DYuR7_uX.d.ts +1069 -0
- package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
- package/dist/llm-anthropic.d.ts +2 -0
- package/dist/llm-anthropic.js +13 -0
- package/dist/llm-openai-DyFrucmV.d.ts +87 -0
- package/dist/llm-openai.d.ts +2 -0
- package/dist/llm-openai.js +19 -0
- package/dist/llm.d.ts +1 -188
- package/dist/llm.js +101 -356
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +2 -0
- package/dist/log.js +14 -0
- package/dist/mcp/index.d.ts +4 -0
- package/dist/mcp/index.js +185 -0
- package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
- package/dist/netpolicy.d.ts +1 -0
- package/dist/netpolicy.js +25 -0
- package/dist/output-CjZWmL8s.d.ts +420 -0
- package/dist/output.d.ts +3 -213
- package/dist/output.js +135 -447
- package/dist/parity-CvMuYcVI.d.ts +61 -0
- package/dist/progress-CAzyxeWl.d.ts +38 -0
- package/dist/progress.d.ts +1 -30
- package/dist/progress.js +6 -55
- package/dist/provenance-SMFHm5gx.d.ts +30 -0
- package/dist/provenance.d.ts +1 -24
- package/dist/provenance.js +6 -31
- package/dist/routellm-B0nv59mH.d.ts +111 -0
- package/dist/routellm.d.ts +2 -64
- package/dist/routellm.js +13 -255
- package/dist/rpc-D31Lg0Kc.d.ts +32 -0
- package/dist/rpc.d.ts +2 -25
- package/dist/rpc.js +4 -98
- package/dist/safety-CUaYEjZc.d.ts +30 -0
- package/dist/safety.d.ts +1 -24
- package/dist/safety.js +6 -43
- package/dist/scope-BrhYB4ij.d.ts +141 -0
- package/dist/scope.d.ts +1 -121
- package/dist/scope.js +20 -377
- package/dist/serve-D8yWMrTc.d.ts +646 -0
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +75 -0
- package/dist/sqlstore.js +6 -39
- package/dist/stream-CrjeCp0M.d.ts +44 -0
- package/dist/stream.d.ts +1 -35
- package/dist/stream.js +8 -51
- package/dist/telemetry/index.d.ts +1 -315
- package/dist/telemetry/index.js +26 -599
- package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
- package/dist/toolspec.d.ts +2 -0
- package/dist/toolspec.js +37 -0
- package/dist/tui/index.d.ts +6 -298
- package/dist/tui/index.js +17 -381
- package/dist/upgrade-C3RWGwRi.d.ts +125 -0
- package/dist/upgrade.d.ts +1 -95
- package/dist/upgrade.js +6 -114
- package/dist/xdg-DB7Shoib.d.ts +179 -0
- package/dist/xdg.d.ts +1 -169
- package/dist/xdg.js +14 -128
- package/package.json +192 -24
- package/src/README.md +15 -0
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +206 -2
- package/src/alias.ts +196 -21
- package/src/cli.help-command.test.ts +105 -0
- package/src/cli.offline.test.ts +93 -0
- package/src/cli.parity.test.ts +192 -0
- package/src/cli.root.conformance.test.ts +166 -0
- package/src/cli.test.ts +95 -1
- package/src/cli.ts +234 -25
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +76 -16
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +298 -0
- package/src/completion.test.ts +268 -145
- package/src/completion.ts +772 -121
- package/src/compliance.test.ts +196 -2
- package/src/compliance.ts +440 -20
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +228 -1
- package/src/config.ts +429 -16
- package/src/delegation.test.ts +299 -0
- package/src/delegation.ts +807 -0
- package/src/gen/crud_pb.ts +7 -7
- package/src/id/README.md +38 -0
- package/src/id/contract.test.ts +1 -1
- package/src/id/index.test.ts +1 -1
- package/src/id/index.ts +3 -2
- package/src/index.test.ts +71 -0
- package/src/index.ts +46 -0
- package/src/llm-anthropic.conformance.test.ts +1135 -0
- package/src/llm-anthropic.test.ts +152 -0
- package/src/llm-anthropic.ts +940 -0
- package/src/llm-choice-hermetic.test.ts +335 -0
- package/src/llm-config.test.ts +232 -0
- package/src/llm-config.ts +106 -0
- package/src/llm-endpoint.ts +254 -0
- package/src/llm-error.ts +17 -0
- package/src/llm-errors.ts +152 -0
- package/src/llm-file.ts +126 -0
- package/src/llm-http.ts +317 -0
- package/src/llm-keys.ts +167 -0
- package/src/llm-media.conformance.test.ts +87 -0
- package/src/llm-media.test.ts +279 -0
- package/src/llm-media.ts +322 -0
- package/src/llm-openai.conformance.test.ts +407 -0
- package/src/llm-openai.test.ts +510 -0
- package/src/llm-openai.ts +708 -0
- package/src/llm-payload.ts +155 -0
- package/src/llm-quote.ts +46 -0
- package/src/llm-routellm.conformance.test.ts +44 -0
- package/src/llm-toolnames.conformance.test.ts +112 -0
- package/src/llm-toolnames.test.ts +132 -0
- package/src/llm-toolnames.ts +298 -0
- package/src/llm-uri.ts +99 -0
- package/src/llm.test.ts +43 -15
- package/src/llm.toolcall.test.ts +175 -0
- package/src/llm.ts +602 -190
- package/src/log.parity.test.ts +105 -0
- package/src/log.test.ts +270 -1
- package/src/log.ts +228 -49
- package/src/mcp/README.md +63 -0
- package/src/mcp/args-separator.test.ts +164 -0
- package/src/mcp/args.test.ts +223 -0
- package/src/mcp/args.ts +160 -0
- package/src/mcp/audit.test.ts +520 -0
- package/src/mcp/audit.ts +70 -0
- package/src/mcp/bridge.test.ts +250 -0
- package/src/mcp/bridge.ts +286 -0
- package/src/mcp/conformance.test.ts +357 -0
- package/src/mcp/dispatch.ts +359 -0
- package/src/mcp/identity.test.ts +166 -0
- package/src/mcp/identity.ts +72 -0
- package/src/mcp/index.ts +176 -0
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +367 -0
- package/src/mcp/mcp.test.ts +707 -0
- package/src/mcp/modern-confirm.test.ts +520 -0
- package/src/mcp/modern-confirm.ts +484 -0
- package/src/mcp/modern.ts +788 -0
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/tasks.ts +82 -0
- package/src/mcp/testtree.ts +250 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +689 -0
- package/src/netpolicy.test.ts +280 -0
- package/src/netpolicy.ts +256 -0
- package/src/output/README.md +46 -0
- package/src/output/builtins.ts +5 -5
- package/src/output/dispatch.ts +10 -2
- package/src/output/error.ts +459 -0
- package/src/output/formatter.ts +29 -5
- package/src/output/formatters/README.md +50 -0
- package/src/output/formatters/csv.ts +48 -12
- package/src/output/formatters/json.ts +4 -25
- package/src/output/formatters/project.ts +34 -0
- package/src/output/formatters/table.ts +8 -6
- package/src/output/formatters/text.ts +7 -3
- package/src/output/formatters/yaml.ts +5 -22
- package/src/output/projection.test.ts +298 -0
- package/src/output/projection.ts +33 -59
- package/src/output/template.ts +11 -21
- package/src/output.surface.test.ts +41 -0
- package/src/output.ts +64 -3
- package/src/plan.ts +89 -0
- package/src/policy.ts +472 -0
- package/src/published-types.test.ts +133 -0
- package/src/routellm.test.ts +209 -28
- package/src/routellm.toolcall.test.ts +521 -0
- package/src/routellm.ts +213 -177
- package/src/router/README.md +44 -0
- package/src/router/server.test.ts +41 -0
- package/src/router/server.ts +11 -0
- package/src/safety.test.ts +19 -9
- package/src/scope-defaults.json +29 -29
- package/src/serve.test.ts +1257 -0
- package/src/serve.ts +1665 -0
- package/src/sideeffect.ts +105 -0
- package/src/telemetry/README.md +48 -0
- package/src/telemetry/client.test.ts +31 -0
- package/src/telemetry/client.ts +12 -6
- package/src/telemetry/offline.test.ts +64 -0
- package/src/toolspec-internal.ts +279 -0
- package/src/toolspec-manifest.test.ts +167 -0
- package/src/toolspec-manifest.ts +415 -0
- package/src/toolspec-spec-schemas.ts +12 -0
- package/src/toolspec-spec.test.ts +273 -0
- package/src/toolspec-spec.ts +458 -0
- package/src/toolspec.from-command.test.ts +350 -0
- package/src/toolspec.test.ts +2 -2
- package/src/toolspec.ts +222 -0
- package/src/triton/README.md +34 -0
- package/src/tui/README.md +42 -0
- package/src/tui/parity.test.ts +120 -31
- package/src/tui/parity.ts +58 -7
- package/src/upgrade.test.ts +291 -0
- package/src/upgrade.ts +116 -7
- package/src/wizard.test.ts +7 -7
- package/test/llm/conformance-helpers.ts +100 -0
- package/test/output/csv.test.ts +164 -0
- package/test/output/dispatch.test.ts +1 -2
- package/test/output/error.test.ts +277 -0
- package/test/output/smoke-capture.ts +2 -2
- package/test/output/smoke.test.ts +2 -2
- package/test/output/taxonomy-contract.test.ts +148 -0
- package/test/setup-env.ts +16 -0
- package/test/toolspec/fixture.ts +79 -0
- package/tsconfig.json +3 -1
- package/tsconfig.test.json +10 -0
- package/vitest.config.ts +9 -0
- package/src/tui/parity.json +0 -74
package/dist/xdg.js
CHANGED
|
@@ -1,129 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function platform(override) {
|
|
44
|
-
return override ?? process.platform;
|
|
45
|
-
}
|
|
46
|
-
function configDir(tool, plt) {
|
|
47
|
-
const xdg = process.env["XDG_CONFIG_HOME"];
|
|
48
|
-
if (xdg) return path.join(xdg, tool);
|
|
49
|
-
const p = platform(plt);
|
|
50
|
-
const home = os.homedir();
|
|
51
|
-
switch (p) {
|
|
52
|
-
case "darwin":
|
|
53
|
-
return path.join(home, "Library", "Preferences", tool);
|
|
54
|
-
case "win32": {
|
|
55
|
-
const appdata = process.env["APPDATA"];
|
|
56
|
-
if (!appdata) throw new Error("%APPDATA% is not set");
|
|
57
|
-
return path.join(appdata, tool);
|
|
58
|
-
}
|
|
59
|
-
default:
|
|
60
|
-
return path.join(home, ".config", tool);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function dataDir(tool, plt) {
|
|
64
|
-
const xdg = process.env["XDG_DATA_HOME"];
|
|
65
|
-
if (xdg) return path.join(xdg, tool);
|
|
66
|
-
const p = platform(plt);
|
|
67
|
-
const home = os.homedir();
|
|
68
|
-
switch (p) {
|
|
69
|
-
case "darwin":
|
|
70
|
-
return path.join(home, "Library", "Application Support", tool);
|
|
71
|
-
case "win32": {
|
|
72
|
-
const local = process.env["LocalAppData"];
|
|
73
|
-
if (!local) throw new Error("%LocalAppData% is not set");
|
|
74
|
-
return path.win32.join(local, tool);
|
|
75
|
-
}
|
|
76
|
-
default:
|
|
77
|
-
return path.join(home, ".local", "share", tool);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function cacheDir(tool, plt) {
|
|
81
|
-
const xdg = process.env["XDG_CACHE_HOME"];
|
|
82
|
-
if (xdg) return path.join(xdg, tool);
|
|
83
|
-
const p = platform(plt);
|
|
84
|
-
const home = os.homedir();
|
|
85
|
-
switch (p) {
|
|
86
|
-
case "darwin":
|
|
87
|
-
return path.join(home, "Library", "Caches", tool);
|
|
88
|
-
case "win32": {
|
|
89
|
-
const local = process.env["LocalAppData"];
|
|
90
|
-
if (!local) throw new Error("%LocalAppData% is not set");
|
|
91
|
-
return path.win32.join(local, tool, "cache");
|
|
92
|
-
}
|
|
93
|
-
default:
|
|
94
|
-
return path.join(home, ".cache", tool);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function stateDir(tool, plt) {
|
|
98
|
-
const xdg = process.env["XDG_STATE_HOME"];
|
|
99
|
-
if (xdg) return path.join(xdg, tool);
|
|
100
|
-
const p = platform(plt);
|
|
101
|
-
const home = os.homedir();
|
|
102
|
-
switch (p) {
|
|
103
|
-
case "darwin":
|
|
104
|
-
return path.join(home, "Library", "Application Support", tool, "state");
|
|
105
|
-
case "win32": {
|
|
106
|
-
const local = process.env["LocalAppData"];
|
|
107
|
-
if (!local) throw new Error("%LocalAppData% is not set");
|
|
108
|
-
return path.win32.join(local, tool, "state");
|
|
109
|
-
}
|
|
110
|
-
default:
|
|
111
|
-
return path.join(home, ".local", "state", tool);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function mustEnsure(dir) {
|
|
115
|
-
fs.mkdirSync(dir, { recursive: true, mode: 488 });
|
|
116
|
-
const stat = fs.statSync(dir);
|
|
117
|
-
if (!stat.isDirectory()) {
|
|
118
|
-
throw new Error(`mustEnsure: path exists but is not a directory: ${dir}`);
|
|
119
|
-
}
|
|
120
|
-
return dir;
|
|
121
|
-
}
|
|
122
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
-
0 && (module.exports = {
|
|
124
|
-
cacheDir,
|
|
125
|
-
configDir,
|
|
126
|
-
dataDir,
|
|
127
|
-
mustEnsure,
|
|
128
|
-
stateDir
|
|
129
|
-
});
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunk4UE5TCMQjs = require('./chunk-4UE5TCMQ.js');
|
|
8
|
+
require('./chunk-R5U7XKVJ.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.cacheDir = _chunk4UE5TCMQjs.cacheDir; exports.configDir = _chunk4UE5TCMQjs.configDir; exports.dataDir = _chunk4UE5TCMQjs.dataDir; exports.mustEnsure = _chunk4UE5TCMQjs.mustEnsure; exports.stateDir = _chunk4UE5TCMQjs.stateDir;
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hop-top/kit",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.11",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/hop-top/poly-kit.git",
|
|
7
|
+
"directory": "sdk/ts"
|
|
8
|
+
},
|
|
4
9
|
"description": "Shared CLI utilities for hop-top tools — TypeScript/CJS edition",
|
|
5
10
|
"type": "commonjs",
|
|
6
11
|
"main": "./dist/index.js",
|
|
@@ -8,7 +13,8 @@
|
|
|
8
13
|
"exports": {
|
|
9
14
|
".": {
|
|
10
15
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"require": "./dist/index.js"
|
|
16
|
+
"require": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
12
18
|
},
|
|
13
19
|
"./cli": {
|
|
14
20
|
"types": "./dist/cli.d.ts",
|
|
@@ -45,6 +51,16 @@
|
|
|
45
51
|
"require": "./dist/llm.js",
|
|
46
52
|
"default": "./dist/llm.js"
|
|
47
53
|
},
|
|
54
|
+
"./anthropic": {
|
|
55
|
+
"types": "./dist/llm-anthropic.d.ts",
|
|
56
|
+
"require": "./dist/llm-anthropic.js",
|
|
57
|
+
"default": "./dist/llm-anthropic.js"
|
|
58
|
+
},
|
|
59
|
+
"./openai": {
|
|
60
|
+
"types": "./dist/llm-openai.d.ts",
|
|
61
|
+
"require": "./dist/llm-openai.js",
|
|
62
|
+
"default": "./dist/llm-openai.js"
|
|
63
|
+
},
|
|
48
64
|
"./routellm": {
|
|
49
65
|
"types": "./dist/routellm.d.ts",
|
|
50
66
|
"require": "./dist/routellm.js",
|
|
@@ -105,11 +121,21 @@
|
|
|
105
121
|
"require": "./dist/aim.js",
|
|
106
122
|
"default": "./dist/aim.js"
|
|
107
123
|
},
|
|
124
|
+
"./netpolicy": {
|
|
125
|
+
"types": "./dist/netpolicy.d.ts",
|
|
126
|
+
"require": "./dist/netpolicy.js",
|
|
127
|
+
"default": "./dist/netpolicy.js"
|
|
128
|
+
},
|
|
108
129
|
"./scope": {
|
|
109
130
|
"types": "./dist/scope.d.ts",
|
|
110
131
|
"require": "./dist/scope.js",
|
|
111
132
|
"default": "./dist/scope.js"
|
|
112
133
|
},
|
|
134
|
+
"./serve": {
|
|
135
|
+
"types": "./dist/serve.d.ts",
|
|
136
|
+
"require": "./dist/serve.js",
|
|
137
|
+
"default": "./dist/serve.js"
|
|
138
|
+
},
|
|
113
139
|
"./telemetry": {
|
|
114
140
|
"types": "./dist/telemetry/index.d.ts",
|
|
115
141
|
"require": "./dist/telemetry/index.js",
|
|
@@ -119,47 +145,189 @@
|
|
|
119
145
|
"types": "./dist/id/index.d.ts",
|
|
120
146
|
"require": "./dist/id/index.js",
|
|
121
147
|
"default": "./dist/id/index.js"
|
|
148
|
+
},
|
|
149
|
+
"./mcp": {
|
|
150
|
+
"types": "./dist/mcp/index.d.ts",
|
|
151
|
+
"require": "./dist/mcp/index.js",
|
|
152
|
+
"default": "./dist/mcp/index.js"
|
|
153
|
+
},
|
|
154
|
+
"./log": {
|
|
155
|
+
"types": "./dist/log.d.ts",
|
|
156
|
+
"require": "./dist/log.js",
|
|
157
|
+
"default": "./dist/log.js"
|
|
158
|
+
},
|
|
159
|
+
"./completion": {
|
|
160
|
+
"types": "./dist/completion.d.ts",
|
|
161
|
+
"require": "./dist/completion.js",
|
|
162
|
+
"default": "./dist/completion.js"
|
|
163
|
+
},
|
|
164
|
+
"./toolspec": {
|
|
165
|
+
"types": "./dist/toolspec.d.ts",
|
|
166
|
+
"require": "./dist/toolspec.js",
|
|
167
|
+
"default": "./dist/toolspec.js"
|
|
168
|
+
},
|
|
169
|
+
"./completion-values": {
|
|
170
|
+
"types": "./dist/completion-values.d.ts",
|
|
171
|
+
"require": "./dist/completion-values.js",
|
|
172
|
+
"default": "./dist/completion-values.js"
|
|
173
|
+
},
|
|
174
|
+
"./compliance": {
|
|
175
|
+
"types": "./dist/compliance.d.ts",
|
|
176
|
+
"require": "./dist/compliance.js",
|
|
177
|
+
"default": "./dist/compliance.js"
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
"typesVersions": {
|
|
181
|
+
"*": {
|
|
182
|
+
"cli": [
|
|
183
|
+
"./dist/cli.d.ts"
|
|
184
|
+
],
|
|
185
|
+
"output": [
|
|
186
|
+
"./dist/output.d.ts"
|
|
187
|
+
],
|
|
188
|
+
"xdg": [
|
|
189
|
+
"./dist/xdg.d.ts"
|
|
190
|
+
],
|
|
191
|
+
"config": [
|
|
192
|
+
"./dist/config.d.ts"
|
|
193
|
+
],
|
|
194
|
+
"sqlstore": [
|
|
195
|
+
"./dist/sqlstore.d.ts"
|
|
196
|
+
],
|
|
197
|
+
"upgrade": [
|
|
198
|
+
"./dist/upgrade.d.ts"
|
|
199
|
+
],
|
|
200
|
+
"llm": [
|
|
201
|
+
"./dist/llm.d.ts"
|
|
202
|
+
],
|
|
203
|
+
"anthropic": [
|
|
204
|
+
"./dist/llm-anthropic.d.ts"
|
|
205
|
+
],
|
|
206
|
+
"openai": [
|
|
207
|
+
"./dist/llm-openai.d.ts"
|
|
208
|
+
],
|
|
209
|
+
"routellm": [
|
|
210
|
+
"./dist/routellm.d.ts"
|
|
211
|
+
],
|
|
212
|
+
"alias": [
|
|
213
|
+
"./dist/alias.d.ts"
|
|
214
|
+
],
|
|
215
|
+
"tui": [
|
|
216
|
+
"./dist/tui/index.d.ts"
|
|
217
|
+
],
|
|
218
|
+
"errcorrect": [
|
|
219
|
+
"./dist/errcorrect.d.ts"
|
|
220
|
+
],
|
|
221
|
+
"safety": [
|
|
222
|
+
"./dist/safety.d.ts"
|
|
223
|
+
],
|
|
224
|
+
"provenance": [
|
|
225
|
+
"./dist/provenance.d.ts"
|
|
226
|
+
],
|
|
227
|
+
"stream": [
|
|
228
|
+
"./dist/stream.d.ts"
|
|
229
|
+
],
|
|
230
|
+
"progress": [
|
|
231
|
+
"./dist/progress.d.ts"
|
|
232
|
+
],
|
|
233
|
+
"auth": [
|
|
234
|
+
"./dist/auth.d.ts"
|
|
235
|
+
],
|
|
236
|
+
"api": [
|
|
237
|
+
"./dist/api.d.ts"
|
|
238
|
+
],
|
|
239
|
+
"rpc": [
|
|
240
|
+
"./dist/rpc.d.ts"
|
|
241
|
+
],
|
|
242
|
+
"aim": [
|
|
243
|
+
"./dist/aim.d.ts"
|
|
244
|
+
],
|
|
245
|
+
"netpolicy": [
|
|
246
|
+
"./dist/netpolicy.d.ts"
|
|
247
|
+
],
|
|
248
|
+
"scope": [
|
|
249
|
+
"./dist/scope.d.ts"
|
|
250
|
+
],
|
|
251
|
+
"serve": [
|
|
252
|
+
"./dist/serve.d.ts"
|
|
253
|
+
],
|
|
254
|
+
"telemetry": [
|
|
255
|
+
"./dist/telemetry/index.d.ts"
|
|
256
|
+
],
|
|
257
|
+
"id": [
|
|
258
|
+
"./dist/id/index.d.ts"
|
|
259
|
+
],
|
|
260
|
+
"mcp": [
|
|
261
|
+
"./dist/mcp/index.d.ts"
|
|
262
|
+
],
|
|
263
|
+
"log": [
|
|
264
|
+
"./dist/log.d.ts"
|
|
265
|
+
],
|
|
266
|
+
"completion": [
|
|
267
|
+
"./dist/completion.d.ts"
|
|
268
|
+
],
|
|
269
|
+
"toolspec": [
|
|
270
|
+
"./dist/toolspec.d.ts"
|
|
271
|
+
],
|
|
272
|
+
"completion-values": [
|
|
273
|
+
"./dist/completion-values.d.ts"
|
|
274
|
+
],
|
|
275
|
+
"compliance": [
|
|
276
|
+
"./dist/compliance.d.ts"
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
"peerDependencies": {
|
|
281
|
+
"@types/better-sqlite3": "^7.6.13"
|
|
282
|
+
},
|
|
283
|
+
"peerDependenciesMeta": {
|
|
284
|
+
"@types/better-sqlite3": {
|
|
285
|
+
"optional": true
|
|
122
286
|
}
|
|
123
287
|
},
|
|
124
288
|
"dependencies": {
|
|
125
|
-
"@bufbuild/protobuf": "^2.
|
|
126
|
-
"@clack/prompts": "^1.
|
|
127
|
-
"@connectrpc/connect": "^2.
|
|
128
|
-
"@connectrpc/connect-web": "^2.
|
|
129
|
-
"@hop-top/cite": "^0.1.
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
"
|
|
289
|
+
"@bufbuild/protobuf": "^2.16.0",
|
|
290
|
+
"@clack/prompts": "^1.8.1",
|
|
291
|
+
"@connectrpc/connect": "^2.2.0",
|
|
292
|
+
"@connectrpc/connect-web": "^2.2.0",
|
|
293
|
+
"@hop-top/cite": "^0.1.2",
|
|
294
|
+
"@modelcontextprotocol/core": "2.3.1",
|
|
295
|
+
"@modelcontextprotocol/server": "2.3.1",
|
|
296
|
+
"better-sqlite3": "^12.11.1",
|
|
297
|
+
"commander": "15.0.0",
|
|
298
|
+
"csv-stringify": "^6.9.0",
|
|
133
299
|
"eta": "^4.6.0",
|
|
134
|
-
"hono": "^4.
|
|
135
|
-
"js-yaml": "^4.
|
|
136
|
-
"picomatch": "^4.0.
|
|
137
|
-
"pino": "^10.
|
|
138
|
-
"semver": "^7.
|
|
300
|
+
"hono": "^4.13.13",
|
|
301
|
+
"js-yaml": "^4.3.2",
|
|
302
|
+
"picomatch": "^4.0.7",
|
|
303
|
+
"pino": "^10.4.0",
|
|
304
|
+
"semver": "^7.8.5",
|
|
139
305
|
"typeid-js": "^1.2.0",
|
|
140
|
-
"zod": "^4.
|
|
306
|
+
"zod": "^4.6.7"
|
|
141
307
|
},
|
|
142
308
|
"devDependencies": {
|
|
143
309
|
"@types/better-sqlite3": "^7.6.13",
|
|
144
310
|
"@types/js-yaml": "^4.0.9",
|
|
145
|
-
"@types/node": "^
|
|
311
|
+
"@types/node": "^24",
|
|
146
312
|
"@types/picomatch": "^4.0.3",
|
|
147
|
-
"@types/semver": "^7.
|
|
148
|
-
"esbuild": "^0.
|
|
149
|
-
"eslint": "^10.
|
|
313
|
+
"@types/semver": "^7.8.0",
|
|
314
|
+
"esbuild": "^0.28.2",
|
|
315
|
+
"eslint": "^10.12.0",
|
|
150
316
|
"tsup": "^8",
|
|
151
317
|
"typescript": "^5",
|
|
152
|
-
"typescript-eslint": "^8.
|
|
153
|
-
"
|
|
318
|
+
"typescript-eslint": "^8.71.2",
|
|
319
|
+
"vite": "^8.3.4",
|
|
320
|
+
"vitest": "^5.0.4"
|
|
154
321
|
},
|
|
155
322
|
"engines": {
|
|
156
|
-
"node": ">=
|
|
323
|
+
"node": ">=22.12"
|
|
157
324
|
},
|
|
158
325
|
"license": "MIT",
|
|
159
326
|
"scripts": {
|
|
160
|
-
"build": "tsup src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/scope.ts src/telemetry/index.ts src/id/index.ts --format cjs --dts",
|
|
327
|
+
"build": "tsup src/index.ts src/alias.ts src/cli.ts src/output.ts src/xdg.ts src/config.ts src/sqlstore.ts src/upgrade.ts src/llm.ts src/llm-anthropic.ts src/llm-openai.ts src/routellm.ts src/tui/index.ts src/errcorrect.ts src/safety.ts src/provenance.ts src/stream.ts src/progress.ts src/auth.ts src/api.ts src/rpc.ts src/aim.ts src/netpolicy.ts src/scope.ts src/serve.ts src/telemetry/index.ts src/id/index.ts src/mcp/index.ts src/log.ts src/completion.ts src/toolspec.ts src/completion-values.ts src/compliance.ts --format cjs --splitting --dts",
|
|
161
328
|
"lint": "eslint src/",
|
|
162
329
|
"lint:fix": "eslint src/ --fix",
|
|
330
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc -p tsconfig.test.json",
|
|
163
331
|
"test": "vitest run"
|
|
164
332
|
}
|
|
165
333
|
}
|
package/src/README.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
# src
|
|
2
2
|
|
|
3
3
|
TypeScript implementation source files.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
| Path | What it is | Start here when |
|
|
8
|
+
|------|------------|-----------------|
|
|
9
|
+
| [`id/`](id/README.md) | TypeID primitive, cross-language wire form | you mint or parse entity ids |
|
|
10
|
+
| [`mcp/`](mcp/README.md) | dual-spec MCP surface, framework-free handler | you serve a Commander tree to MCP clients |
|
|
11
|
+
| [`output/`](output/README.md) | formatter registry, output flag suite, error envelope | a command renders structured data |
|
|
12
|
+
| [`output/formatters/`](output/formatters/README.md) | built-in json, yaml, table, csv, text | you need one formatter or add one |
|
|
13
|
+
| [`router/`](router/README.md) | RouteLLM scorers, `Controller`, Hono handler (not exported) | you route prompts between strong and weak models |
|
|
14
|
+
| [`telemetry/`](telemetry/README.md) | mode gate, install id, consent, redactor, `Client` | you emit usage telemetry |
|
|
15
|
+
| [`triton/`](triton/README.md) | KServe v2 HTTP client (not exported) | you call a Triton-hosted model |
|
|
16
|
+
| [`tui/`](tui/README.md) | status, badge, spinner, progress, prompts | a TTY needs styled widgets |
|
|
17
|
+
| `gen/` | generated Connect stubs, do not edit | never; regenerate instead |
|
|
18
|
+
| top-level modules (`cli.ts`, `serve.ts`, `scope.ts`, ...) | single-file ports, one per package export | see [`../README.md`](../README.md), section "Other modules" |
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Runs the shared alias corpus in contracts/alias-v1. The vectors are
|
|
2
|
+
// the source of truth: a failure means this port drifted from the
|
|
3
|
+
// contract, not that a vector should be edited to fit.
|
|
4
|
+
//
|
|
5
|
+
// Strict: unknown fields fail, `version` must be `v1` and every JSON
|
|
6
|
+
// file in the corpus must have a runner here.
|
|
7
|
+
|
|
8
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
import { Command, CommanderError } from 'commander';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
AliasNameError, type AliasMap, type BridgeOptions,
|
|
15
|
+
bridgeAliases, detectCycles, findCommand, validateAliasName,
|
|
16
|
+
} from './alias';
|
|
17
|
+
import { completeRequest } from './completion';
|
|
18
|
+
|
|
19
|
+
const PORT = 'ts';
|
|
20
|
+
const CORPUS = join(__dirname, '..', '..', '..', 'contracts', 'alias-v1');
|
|
21
|
+
const FILES = ['bridge.json', 'cycles.json', 'validate.json'];
|
|
22
|
+
|
|
23
|
+
function strictKeys(o: object, allowed: string[], where: string): void {
|
|
24
|
+
for (const k of Object.keys(o)) {
|
|
25
|
+
if (!allowed.includes(k)) throw new Error(`${where}: unknown field ${k}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function load<T>(name: string, top: string[]): T {
|
|
30
|
+
for (const n of readdirSync(CORPUS)) {
|
|
31
|
+
if (n.endsWith('.json') && !FILES.includes(n)) {
|
|
32
|
+
throw new Error(`${n} has no runner`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const f = JSON.parse(readFileSync(join(CORPUS, name), 'utf8'));
|
|
36
|
+
strictKeys(f, ['version', 'description', 'cases', ...top], name);
|
|
37
|
+
if (f.version !== 'v1') throw new Error(`${name}: version ${f.version}`);
|
|
38
|
+
if (!Array.isArray(f.cases) || f.cases.length === 0) {
|
|
39
|
+
throw new Error(`${name}: cases section is empty`);
|
|
40
|
+
}
|
|
41
|
+
return f as T;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ── validate.json ───────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
interface ValidateCase {
|
|
47
|
+
name: string; alias: string; builtins?: string[];
|
|
48
|
+
existing?: AliasMap; expect: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe('alias-v1 validate', () => {
|
|
52
|
+
const f = load<{ cases: ValidateCase[] }>('validate.json', []);
|
|
53
|
+
for (const c of f.cases) {
|
|
54
|
+
it(c.name, () => {
|
|
55
|
+
strictKeys(c, ['name', 'alias', 'builtins', 'existing', 'expect'], c.name);
|
|
56
|
+
let got = 'ok';
|
|
57
|
+
try {
|
|
58
|
+
validateAliasName(c.alias, { builtins: c.builtins, existing: c.existing });
|
|
59
|
+
} catch (e) {
|
|
60
|
+
expect(e).toBeInstanceOf(AliasNameError);
|
|
61
|
+
got = (e as AliasNameError).kind;
|
|
62
|
+
}
|
|
63
|
+
expect(got).toBe(c.expect);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// ── cycles.json ─────────────────────────────────────────────
|
|
69
|
+
|
|
70
|
+
describe('alias-v1 cycles', () => {
|
|
71
|
+
const f = load<{ cases: { name: string; aliases: AliasMap; cycles: string[][] }[] }>(
|
|
72
|
+
'cycles.json', [],
|
|
73
|
+
);
|
|
74
|
+
for (const c of f.cases) {
|
|
75
|
+
it(c.name, () => {
|
|
76
|
+
strictKeys(c, ['name', 'aliases', 'cycles'], c.name);
|
|
77
|
+
expect(detectCycles(c.aliases)).toEqual(c.cycles);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// ── bridge.json ─────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
interface Node {
|
|
85
|
+
name: string; description: string;
|
|
86
|
+
flags?: { name: string; default: string }[];
|
|
87
|
+
commands?: Node[];
|
|
88
|
+
}
|
|
89
|
+
interface Entry { kind: string; hidden?: boolean; description?: string }
|
|
90
|
+
interface Run {
|
|
91
|
+
ran: string; path?: string; env?: string | null; args?: string[];
|
|
92
|
+
name?: string; target?: string;
|
|
93
|
+
}
|
|
94
|
+
interface Check {
|
|
95
|
+
alias?: string; argv?: string[]; entry?: Entry; run?: Run; help?: string;
|
|
96
|
+
complete?: string[]; candidates?: string[];
|
|
97
|
+
by_port?: Record<string, Partial<Check>>;
|
|
98
|
+
}
|
|
99
|
+
interface BridgeCase {
|
|
100
|
+
name: string; aliases: AliasMap;
|
|
101
|
+
options?: { hidden?: boolean; describe?: boolean; help?: string; dispatch?: string };
|
|
102
|
+
skip?: Record<string, string>;
|
|
103
|
+
proxy_flags?: { name: string; short: string }[];
|
|
104
|
+
checks: Check[];
|
|
105
|
+
}
|
|
106
|
+
interface BridgeFile {
|
|
107
|
+
tree: Node; describe_template: string; cases: BridgeCase[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// What a target or handler saw.
|
|
111
|
+
interface Seen {
|
|
112
|
+
ran: string; path?: string; env?: string | null; args?: string[];
|
|
113
|
+
name?: string; target?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function build(
|
|
117
|
+
parent: Command, nodes: Node[], prefix: string, rec: { r: Seen },
|
|
118
|
+
descs: Map<string, string>,
|
|
119
|
+
): void {
|
|
120
|
+
for (const n of nodes) {
|
|
121
|
+
strictKeys(n, ['name', 'description', 'flags', 'commands'], n.name);
|
|
122
|
+
const path = `${prefix} ${n.name}`.trim();
|
|
123
|
+
descs.set(path, n.description);
|
|
124
|
+
const c = parent.command(n.name).description(n.description);
|
|
125
|
+
const hasEnv = (n.flags ?? []).some(fl => fl.name === 'env');
|
|
126
|
+
for (const fl of n.flags ?? []) c.option(`--${fl.name} <v>`, '', fl.default);
|
|
127
|
+
if (!n.commands?.length) {
|
|
128
|
+
c.argument('[args...]').action((args: string[], opts: Record<string, string>) => {
|
|
129
|
+
rec.r = { ran: 'target', path, env: hasEnv ? opts.env : null, args };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
build(c, n.commands ?? [], path, rec, descs);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function bridgeOptions(f: BridgeFile, c: BridgeCase, rec: { r: Seen }): BridgeOptions | undefined {
|
|
137
|
+
const o = c.options;
|
|
138
|
+
if (!o) return undefined;
|
|
139
|
+
strictKeys(o, ['hidden', 'describe', 'help', 'dispatch'], c.name);
|
|
140
|
+
const opts: BridgeOptions = {};
|
|
141
|
+
if (o.hidden !== undefined) opts.hidden = o.hidden;
|
|
142
|
+
if (o.describe) {
|
|
143
|
+
opts.describe = (name, target) =>
|
|
144
|
+
f.describe_template.replace('{name}', name).replace('{target}', target);
|
|
145
|
+
}
|
|
146
|
+
if (o.help === 'own') opts.helpOption = true;
|
|
147
|
+
else if (o.help === 'passthrough') opts.helpOption = false;
|
|
148
|
+
else if (o.help !== undefined) throw new Error(`unknown help ${o.help}`);
|
|
149
|
+
if (o.dispatch === 'handler') {
|
|
150
|
+
opts.dispatch = (name, target, cmd) => {
|
|
151
|
+
rec.r = { ran: 'handler', name, target, args: [...cmd.args] };
|
|
152
|
+
};
|
|
153
|
+
} else if (o.dispatch === 'register-only') {
|
|
154
|
+
opts.dispatch = false;
|
|
155
|
+
} else if (o.dispatch !== undefined) {
|
|
156
|
+
throw new Error(`unknown dispatch ${o.dispatch}`);
|
|
157
|
+
}
|
|
158
|
+
return opts;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
describe('alias-v1 bridge', () => {
|
|
162
|
+
const f = load<BridgeFile>('bridge.json', ['tree', 'describe_template']);
|
|
163
|
+
|
|
164
|
+
function setup(c: BridgeCase) {
|
|
165
|
+
const rec: { r: Seen } = { r: { ran: 'none' } };
|
|
166
|
+
const descs = new Map<string, string>();
|
|
167
|
+
let out = '';
|
|
168
|
+
const program = new Command(f.tree.name)
|
|
169
|
+
.exitOverride()
|
|
170
|
+
.configureOutput({ writeOut: s => { out += s; }, writeErr: s => { out += s; } });
|
|
171
|
+
build(program, f.tree.commands ?? [], '', rec, descs);
|
|
172
|
+
const sorted = Object.fromEntries(Object.entries(c.aliases).sort(([a], [b]) => (a < b ? -1 : 1)));
|
|
173
|
+
bridgeAliases(program, sorted, bridgeOptions(f, c, rec));
|
|
174
|
+
for (const fl of c.proxy_flags ?? []) {
|
|
175
|
+
strictKeys(fl, ['name', 'short'], c.name);
|
|
176
|
+
for (const alias of Object.keys(c.aliases)) {
|
|
177
|
+
const proxy = program.commands.find(x => x.name() === alias);
|
|
178
|
+
if (!proxy) throw new Error(`${c.name}: ${alias} has no proxy`);
|
|
179
|
+
proxy.option(`-${fl.short}, --${fl.name} <v>`, fl.name);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return { program, rec, descs, output: () => out };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
for (const c of f.cases) {
|
|
186
|
+
const skip = c.skip?.[PORT];
|
|
187
|
+
(skip ? it.skip : it)(skip ? `${c.name} (${skip})` : c.name, async () => {
|
|
188
|
+
strictKeys(c, ['name', 'aliases', 'options', 'skip', 'proxy_flags', 'checks'], c.name);
|
|
189
|
+
for (const raw of c.checks) {
|
|
190
|
+
strictKeys(
|
|
191
|
+
raw, ['alias', 'argv', 'entry', 'run', 'help', 'complete', 'candidates', 'by_port'], c.name,
|
|
192
|
+
);
|
|
193
|
+
const chk: Check = { ...raw, ...(raw.by_port?.[PORT] ?? {}) };
|
|
194
|
+
const { program, rec, descs, output } = setup(c);
|
|
195
|
+
|
|
196
|
+
if (chk.entry) {
|
|
197
|
+
const alias = chk.alias!;
|
|
198
|
+
const proxy = program.commands.find(x => x.name() === alias);
|
|
199
|
+
if (proxy) {
|
|
200
|
+
expect(chk.entry.kind, alias).toBe('proxy');
|
|
201
|
+
if (chk.entry.hidden !== undefined) {
|
|
202
|
+
expect((proxy as unknown as { _hidden: boolean })._hidden, alias)
|
|
203
|
+
.toBe(chk.entry.hidden);
|
|
204
|
+
}
|
|
205
|
+
if (chk.entry.description !== undefined) {
|
|
206
|
+
expect(proxy.description(), alias).toBe(chk.entry.description);
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
const target = findCommand(program, c.aliases[alias]);
|
|
210
|
+
expect(target?.aliases().includes(alias) ? 'native' : 'missing', alias)
|
|
211
|
+
.toBe(chk.entry.kind);
|
|
212
|
+
}
|
|
213
|
+
} else if (chk.run) {
|
|
214
|
+
await program.parseAsync(chk.argv!, { from: 'user' });
|
|
215
|
+
const r = rec.r;
|
|
216
|
+
expect(r.ran, chk.argv!.join(' ')).toBe(chk.run.ran);
|
|
217
|
+
if (chk.run.ran === 'target') {
|
|
218
|
+
expect({ path: r.path, env: r.env, args: r.args })
|
|
219
|
+
.toEqual({ path: chk.run.path, env: chk.run.env, args: chk.run.args });
|
|
220
|
+
} else if (chk.run.ran === 'handler') {
|
|
221
|
+
expect({ name: r.name, target: r.target, args: r.args })
|
|
222
|
+
.toEqual({ name: chk.run.name, target: chk.run.target, args: chk.run.args });
|
|
223
|
+
}
|
|
224
|
+
} else if (chk.help) {
|
|
225
|
+
const err = await program.parseAsync(chk.argv!, { from: 'user' })
|
|
226
|
+
.then(() => undefined, (e: unknown) => e);
|
|
227
|
+
expect(err, chk.argv!.join(' ')).toBeInstanceOf(CommanderError);
|
|
228
|
+
expect((err as CommanderError).code).toBe('commander.helpDisplayed');
|
|
229
|
+
const alias = chk.argv![0];
|
|
230
|
+
const text = output();
|
|
231
|
+
const proxy = program.commands.find(x => x.name() === alias);
|
|
232
|
+
let got = 'unknown';
|
|
233
|
+
if (text.includes(descs.get(c.aliases[alias])!)) got = 'target';
|
|
234
|
+
else if (proxy && text.includes(proxy.description())) got = 'alias';
|
|
235
|
+
expect(got, text).toBe(chk.help);
|
|
236
|
+
expect(rec.r.ran).toBe('none');
|
|
237
|
+
} else if (chk.complete) {
|
|
238
|
+
let out = '';
|
|
239
|
+
await completeRequest(program, chk.complete, true, {
|
|
240
|
+
out: s => { out += s; }, err: () => {},
|
|
241
|
+
});
|
|
242
|
+
const got = out.split('\n').filter(l => l !== '' && !l.startsWith(':')).sort();
|
|
243
|
+
expect(got, chk.complete.join(' ')).toEqual([...chk.candidates!].sort());
|
|
244
|
+
} else {
|
|
245
|
+
throw new Error(`${c.name}: check has no observable`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|