@hop-top/kit 0.5.0-alpha.7 → 0.5.0-alpha.9
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 +38 -0
- package/dist/alias-D9_qFlyP.d.ts +174 -0
- package/dist/alias.d.ts +1 -1
- package/dist/alias.js +8 -2
- package/dist/{chunk-263IZ6Z6.js → chunk-B4ULGCCN.js} +43 -154
- package/dist/{chunk-DIDN4X5C.js → chunk-BLS2OBIQ.js} +99 -20
- package/dist/{chunk-JTMPNXVQ.js → chunk-P6GRX4RV.js} +486 -83
- package/dist/chunk-UZ65A27P.js +147 -0
- package/dist/{completion-sDKVXPUL.d.ts → completion-csVun6SP.d.ts} +4 -1
- package/dist/completion.d.ts +1 -1
- package/dist/{index-B-pqGHhU.d.ts → index-CaOXdl38.d.ts} +337 -24
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -4
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +31 -2
- package/dist/{toolspec-UrWnoJ3Y.d.ts → toolspec-96rkLfsh.d.ts} +7 -2
- package/dist/toolspec.d.ts +1 -1
- package/dist/toolspec.js +3 -2
- package/package.json +1 -1
- package/src/alias.conformance.test.ts +250 -0
- package/src/alias.test.ts +96 -1
- package/src/alias.ts +179 -19
- package/src/completion.ts +4 -1
- package/src/mcp/README.md +6 -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 +72 -0
- package/src/mcp/bridge.ts +50 -5
- package/src/mcp/conformance.test.ts +1 -1
- package/src/mcp/dispatch.ts +48 -2
- package/src/mcp/index.ts +33 -1
- package/src/mcp/legacy-notify.test.ts +59 -0
- package/src/mcp/legacy.ts +55 -15
- package/src/mcp/modern-confirm.ts +42 -10
- package/src/mcp/modern.ts +99 -35
- package/src/mcp/stdio.test.ts +313 -0
- package/src/mcp/stdio.ts +254 -0
- package/src/mcp/toolname.test.ts +147 -0
- package/src/mcp/types.ts +125 -18
- package/src/toolspec-internal.ts +24 -0
- package/src/toolspec-manifest.test.ts +25 -0
- package/src/toolspec-manifest.ts +5 -1
- package/src/toolspec.from-command.test.ts +51 -0
- package/src/toolspec.ts +29 -15
- package/dist/alias-BsJ2jGqQ.d.ts +0 -96
|
@@ -8,13 +8,16 @@ var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
|
|
|
8
8
|
// src/alias.ts
|
|
9
9
|
var alias_exports = {};
|
|
10
10
|
_chunkR5U7XKVJjs.__export.call(void 0, alias_exports, {
|
|
11
|
+
AliasNameError: () => AliasNameError,
|
|
11
12
|
AliasStore: () => AliasStore,
|
|
12
13
|
Expander: () => Expander,
|
|
13
14
|
bridgeAliases: () => bridgeAliases,
|
|
15
|
+
detectCycles: () => detectCycles,
|
|
14
16
|
findCommand: () => findCommand,
|
|
15
17
|
findFirstNonFlag: () => findFirstNonFlag,
|
|
16
18
|
loadFrom: () => loadFrom,
|
|
17
|
-
saveTo: () => saveTo
|
|
19
|
+
saveTo: () => saveTo,
|
|
20
|
+
validateAliasName: () => validateAliasName
|
|
18
21
|
});
|
|
19
22
|
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
20
23
|
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
@@ -125,50 +128,123 @@ var Expander = class {
|
|
|
125
128
|
const result = [args[0], ...prefix, ...parts, ...suffix];
|
|
126
129
|
return [result, true];
|
|
127
130
|
}
|
|
128
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Reject names that shadow builtins or contain whitespace; see
|
|
133
|
+
* {@link validateAliasName}, which needs no config files.
|
|
134
|
+
*/
|
|
129
135
|
validateName(name) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
validateAliasName(name, { builtins: this.cfg.builtins });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var AliasNameError = class extends Error {
|
|
140
|
+
constructor(kind, alias, target) {
|
|
141
|
+
super(aliasNameMessage(kind, alias, target));
|
|
142
|
+
this.name = "AliasNameError";
|
|
143
|
+
this.kind = kind;
|
|
144
|
+
this.alias = alias;
|
|
145
|
+
this.target = target;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
function aliasNameMessage(kind, alias, target) {
|
|
149
|
+
switch (kind) {
|
|
150
|
+
case "empty":
|
|
151
|
+
return "alias name must not be empty";
|
|
152
|
+
case "whitespace":
|
|
153
|
+
return "alias name must not contain whitespace";
|
|
154
|
+
case "builtin":
|
|
155
|
+
return `alias "${alias}" conflicts with a built-in command`;
|
|
156
|
+
case "duplicate":
|
|
157
|
+
return `alias "${alias}" is already registered for "${_nullishCoalesce(target, () => ( ""))}"`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
var WHITE_SPACE = /\p{White_Space}/u;
|
|
161
|
+
function validateAliasName(name, rules = {}) {
|
|
162
|
+
if (name === "") throw new AliasNameError("empty", name);
|
|
163
|
+
if (WHITE_SPACE.test(name)) throw new AliasNameError("whitespace", name);
|
|
164
|
+
if (rules.builtins) {
|
|
165
|
+
for (const b of rules.builtins) {
|
|
166
|
+
if (b === name) throw new AliasNameError("builtin", name);
|
|
135
167
|
}
|
|
136
|
-
|
|
137
|
-
|
|
168
|
+
}
|
|
169
|
+
const existing = rules.existing;
|
|
170
|
+
if (existing && Object.prototype.hasOwnProperty.call(existing, name)) {
|
|
171
|
+
throw new AliasNameError("duplicate", name, existing[name]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function detectCycles(aliases) {
|
|
175
|
+
const has = (n) => Object.prototype.hasOwnProperty.call(aliases, n);
|
|
176
|
+
const next = (n) => {
|
|
177
|
+
const first = aliases[n].trim().split(/\s+/)[0];
|
|
178
|
+
return first !== "" && has(first) ? first : void 0;
|
|
179
|
+
};
|
|
180
|
+
const cmp = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
181
|
+
const done = /* @__PURE__ */ new Set();
|
|
182
|
+
const cycles = [];
|
|
183
|
+
for (const start of Object.keys(aliases).sort(cmp)) {
|
|
184
|
+
if (done.has(start)) continue;
|
|
185
|
+
const pos = /* @__PURE__ */ new Map();
|
|
186
|
+
const walk = [];
|
|
187
|
+
let cur = start;
|
|
188
|
+
while (cur !== void 0 && !done.has(cur)) {
|
|
189
|
+
const at = pos.get(cur);
|
|
190
|
+
if (at !== void 0) {
|
|
191
|
+
const members = walk.slice(at);
|
|
192
|
+
let min = 0;
|
|
193
|
+
members.forEach((m, i) => {
|
|
194
|
+
if (m < members[min]) min = i;
|
|
195
|
+
});
|
|
196
|
+
const path2 = [...members.slice(min), ...members.slice(0, min)];
|
|
197
|
+
cycles.push([...path2, path2[0]]);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
pos.set(cur, walk.length);
|
|
201
|
+
walk.push(cur);
|
|
202
|
+
cur = next(cur);
|
|
138
203
|
}
|
|
204
|
+
for (const n of walk) done.add(n);
|
|
139
205
|
}
|
|
140
|
-
|
|
206
|
+
return cycles.sort((a, b) => cmp(a[0], b[0]));
|
|
207
|
+
}
|
|
141
208
|
function findCommand(program, cmdPath) {
|
|
142
209
|
const parts = cmdPath.split(" ");
|
|
143
210
|
let cmd = program;
|
|
144
211
|
for (const part of parts) {
|
|
145
|
-
cmd = _optionalChain([cmd, 'optionalAccess',
|
|
212
|
+
cmd = _optionalChain([cmd, 'optionalAccess', _ => _.commands, 'access', _2 => _2.find, 'call', _3 => _3((c) => c.name() === part)]);
|
|
146
213
|
if (!cmd) return void 0;
|
|
147
214
|
}
|
|
148
215
|
return cmd;
|
|
149
216
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
217
|
+
function hasBridgeOptions(opts) {
|
|
218
|
+
return opts !== void 0 && Object.values(opts).some((v) => v !== void 0);
|
|
219
|
+
}
|
|
220
|
+
function bridgeAliases(program, source, opts) {
|
|
221
|
+
const all = typeof source.all === "function" ? source.all() : { ...source };
|
|
222
|
+
const proxyAll = hasBridgeOptions(opts);
|
|
223
|
+
const realProxy = proxyAll && (opts.hidden === false || typeof opts.dispatch === "function");
|
|
152
224
|
for (const [name, target] of Object.entries(all)) {
|
|
153
|
-
_chunkJZ22ZUFAjs.registerRootAlias.call(void 0, program, name, target);
|
|
225
|
+
if (!realProxy) _chunkJZ22ZUFAjs.registerRootAlias.call(void 0, program, name, target);
|
|
154
226
|
const parts = target.split(/\s+/);
|
|
155
|
-
if (parts.length === 1) {
|
|
227
|
+
if (!proxyAll && parts.length === 1) {
|
|
156
228
|
const targetCmd = findCommand(program, target);
|
|
157
229
|
if (targetCmd) {
|
|
158
230
|
targetCmd.alias(name);
|
|
159
231
|
continue;
|
|
160
232
|
}
|
|
161
233
|
}
|
|
162
|
-
const
|
|
234
|
+
const dispatch = _optionalChain([opts, 'optionalAccess', _4 => _4.dispatch]);
|
|
235
|
+
const proxy = new (0, _commander.Command)(name);
|
|
236
|
+
if (proxyAll) proxy.copyInheritedSettings(program);
|
|
237
|
+
proxy.description(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _5 => _5.describe, 'optionalCall', _6 => _6(name, target)]), () => ( `Alias for ${target}`))).allowUnknownOption(true).allowExcessArguments(true).action(function() {
|
|
238
|
+
if (dispatch === false) return void 0;
|
|
239
|
+
if (dispatch) return dispatch(name, target, this);
|
|
163
240
|
const expanded = target.split(/\s+/);
|
|
164
241
|
return program._parseCommand(
|
|
165
242
|
[],
|
|
166
243
|
[...expanded, ...this.args]
|
|
167
244
|
);
|
|
168
245
|
});
|
|
169
|
-
proxy.helpOption(false);
|
|
170
|
-
proxy.
|
|
171
|
-
program.addCommand(proxy);
|
|
246
|
+
if (_optionalChain([opts, 'optionalAccess', _7 => _7.helpOption]) !== true) proxy.helpOption(false);
|
|
247
|
+
program.addCommand(proxy, { hidden: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _8 => _8.hidden]), () => ( true)) });
|
|
172
248
|
}
|
|
173
249
|
}
|
|
174
250
|
|
|
@@ -181,4 +257,7 @@ function bridgeAliases(program, store) {
|
|
|
181
257
|
|
|
182
258
|
|
|
183
259
|
|
|
184
|
-
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
exports.loadFrom = loadFrom; exports.saveTo = saveTo; exports.findFirstNonFlag = findFirstNonFlag; exports.AliasStore = AliasStore; exports.Expander = Expander; exports.AliasNameError = AliasNameError; exports.validateAliasName = validateAliasName; exports.detectCycles = detectCycles; exports.findCommand = findCommand; exports.bridgeAliases = bridgeAliases; exports.alias_exports = alias_exports;
|