@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
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,44 @@ All notable changes to `@hop-top/kit` are documented in this file.
|
|
|
4
4
|
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
|
|
5
5
|
versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.5.0-alpha.9](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.8...kit-ts/v0.5.0-alpha.9) (2026-10-30)
|
|
8
|
+
|
|
9
|
+
The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.9. This release includes new features and bug fixes.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **mcp:** toolNameSeparator mount option in ts sdk ([0d0111c](https://github.com/hop-top/poly-kit/commit/0d0111c4600f7ac6be7fe013f96f757230f90467))
|
|
15
|
+
* **ts/mcp:** audit mount hook for refusals ([1f63a5f](https://github.com/hop-top/poly-kit/commit/1f63a5f89cd7ba8c25345ed9478a4a753f5bef28))
|
|
16
|
+
* **ts/mcp:** serveStdio transport ([7ab69a6](https://github.com/hop-top/poly-kit/commit/7ab69a622cc1f3c07b7fb6e51234235a5a992b2f))
|
|
17
|
+
* **ts/toolspec:** skip builtins, includeHidden in toolSpecFromCommand ([2962a7c](https://github.com/hop-top/poly-kit/commit/2962a7cfac4244d5c3bcdc40bceba24dac92f694))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **mcp:** no reply to notifications; ping returns {} ([f24c097](https://github.com/hop-top/poly-kit/commit/f24c09796642894a2329a6170a160283a15c38af))
|
|
23
|
+
* **ts/mcp:** negated, repeatable option types and default/enum in bridge schema ([863a448](https://github.com/hop-top/poly-kit/commit/863a448e899fc8e6d66f675604fc9427ce6d9b80))
|
|
24
|
+
* **ts/mcp:** publish positional args as the Go "args" array ([c47db88](https://github.com/hop-top/poly-kit/commit/c47db88b6f3e7e2594ee103cd87375d19f518e13))
|
|
25
|
+
* **ts/toolspec:** negatable flags typed bool ([79cfeb4](https://github.com/hop-top/poly-kit/commit/79cfeb4cc0b31d449b2b23487949dffce518f63d))
|
|
26
|
+
|
|
27
|
+
Full diff: [kit-ts/v0.5.0-alpha.8...kit-ts/v0.5.0-alpha.9](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.8...kit-ts/v0.5.0-alpha.9)
|
|
28
|
+
|
|
29
|
+
## [0.5.0-alpha.8](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.7...kit-ts/v0.5.0-alpha.8) (2026-10-29)
|
|
30
|
+
|
|
31
|
+
The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.8. This release includes new features and bug fixes.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* **ts/alias:** bridgeAliases options, validateAliasName, detectCycles ([a7c279f](https://github.com/hop-top/poly-kit/commit/a7c279f3abc08ac97dc1f69ce750e0a0e12c88fc))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* **ts/alias:** skip root-alias completion for real-command proxies ([0dc2251](https://github.com/hop-top/poly-kit/commit/0dc225176ed2a1a94fdb8beb4063b56da23ce05c))
|
|
42
|
+
|
|
43
|
+
Full diff: [kit-ts/v0.5.0-alpha.7...kit-ts/v0.5.0-alpha.8](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.7...kit-ts/v0.5.0-alpha.8)
|
|
44
|
+
|
|
7
45
|
## [0.5.0-alpha.7](https://github.com/hop-top/poly-kit/compare/kit-ts/v0.5.0-alpha.6...kit-ts/v0.5.0-alpha.7) (2026-10-29)
|
|
8
46
|
|
|
9
47
|
The hop-top team is happy to announce Kit's TS SDK 0.5.0-alpha.7. This release includes new features and bug fixes.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* alias.ts — YAML-file-based command alias expansion.
|
|
5
|
+
*
|
|
6
|
+
* Port of Go's cli/alias package. Aliases live in per-tool YAML
|
|
7
|
+
* config files with three-tier priority: seeded < global < local.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
type AliasMap = Record<string, string>;
|
|
11
|
+
interface ExpanderConfig {
|
|
12
|
+
globalPath: string;
|
|
13
|
+
localPath: string;
|
|
14
|
+
seededAliases?: AliasMap;
|
|
15
|
+
builtins?: Set<string>;
|
|
16
|
+
}
|
|
17
|
+
/** Read aliases from a single YAML config file. */
|
|
18
|
+
declare function loadFrom(filePath: string): AliasMap;
|
|
19
|
+
/** Write aliases into a YAML config file, preserving other keys. */
|
|
20
|
+
declare function saveTo(filePath: string, aliases: AliasMap): void;
|
|
21
|
+
/**
|
|
22
|
+
* Find the first non-flag element in a slice.
|
|
23
|
+
* Returns [index, value]. Flags with `=` are self-contained;
|
|
24
|
+
* short flags without `=` consume the next element as their value.
|
|
25
|
+
*/
|
|
26
|
+
declare function findFirstNonFlag(slice: string[]): [number, string];
|
|
27
|
+
/**
|
|
28
|
+
* Simple single-file alias store with load/save, set/get/remove,
|
|
29
|
+
* and first-arg expansion.
|
|
30
|
+
*/
|
|
31
|
+
declare class AliasStore {
|
|
32
|
+
private filePath;
|
|
33
|
+
private aliases;
|
|
34
|
+
constructor(filePath: string);
|
|
35
|
+
load(): void;
|
|
36
|
+
save(): void;
|
|
37
|
+
set(name: string, target: string): void;
|
|
38
|
+
remove(name: string): void;
|
|
39
|
+
get(name: string): string | undefined;
|
|
40
|
+
/** Returns a shallow copy. */
|
|
41
|
+
all(): AliasMap;
|
|
42
|
+
/** Expand first arg if it matches an alias. */
|
|
43
|
+
expand(args: string[]): string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Three-tier alias expander matching Go's Expander.
|
|
47
|
+
* Priority: seeded < global < local.
|
|
48
|
+
*/
|
|
49
|
+
declare class Expander {
|
|
50
|
+
private cfg;
|
|
51
|
+
constructor(cfg: ExpanderConfig);
|
|
52
|
+
/** Merged alias map (seeded < global < local). */
|
|
53
|
+
load(): AliasMap;
|
|
54
|
+
/**
|
|
55
|
+
* Rewrite args if args[1] (or first non-flag arg) matches
|
|
56
|
+
* an alias. Returns [rewrittenArgs, wasExpanded].
|
|
57
|
+
*/
|
|
58
|
+
expand(args: string[]): [string[], boolean];
|
|
59
|
+
/**
|
|
60
|
+
* Reject names that shadow builtins or contain whitespace; see
|
|
61
|
+
* {@link validateAliasName}, which needs no config files.
|
|
62
|
+
*/
|
|
63
|
+
validateName(name: string): void;
|
|
64
|
+
}
|
|
65
|
+
/** The rule an alias name failed; see {@link validateAliasName}. */
|
|
66
|
+
type AliasNameErrorKind = 'empty' | 'whitespace' | 'builtin' | 'duplicate';
|
|
67
|
+
/** An alias name {@link validateAliasName} refused. */
|
|
68
|
+
declare class AliasNameError extends Error {
|
|
69
|
+
readonly kind: AliasNameErrorKind;
|
|
70
|
+
readonly alias: string;
|
|
71
|
+
/** The existing alias's target, for `duplicate`. */
|
|
72
|
+
readonly target?: string;
|
|
73
|
+
constructor(kind: AliasNameErrorKind, alias: string, target?: string);
|
|
74
|
+
}
|
|
75
|
+
/** What {@link validateAliasName} checks a name against. */
|
|
76
|
+
interface AliasNameRules {
|
|
77
|
+
/** Names an alias must not take: the tool's commands and reserved words. */
|
|
78
|
+
builtins?: Iterable<string>;
|
|
79
|
+
/** The alias map the name would join. */
|
|
80
|
+
existing?: AliasMap;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check an alias name without a store, config file or command tree.
|
|
84
|
+
* Rules run in order and the first failure throws an
|
|
85
|
+
* {@link AliasNameError}: empty, whitespace (any Unicode White_Space
|
|
86
|
+
* character), builtin, duplicate.
|
|
87
|
+
*/
|
|
88
|
+
declare function validateAliasName(name: string, rules?: AliasNameRules): void;
|
|
89
|
+
/**
|
|
90
|
+
* Report alias cycles in `aliases` (name -> target). An alias points at
|
|
91
|
+
* another when the first word of its target is a key of the map. Each
|
|
92
|
+
* cycle is a path starting at its smallest name and ending with it
|
|
93
|
+
* again (`['a', 'b', 'a']`); cycles are sorted by first name. An alias
|
|
94
|
+
* that only leads into a cycle is not part of one.
|
|
95
|
+
*/
|
|
96
|
+
declare function detectCycles(aliases: AliasMap): string[][];
|
|
97
|
+
/** Walk the Commander program tree to find a command by space-delimited path. */
|
|
98
|
+
declare function findCommand(program: Command, cmdPath: string): Command | undefined;
|
|
99
|
+
/** Runs an alias proxy in place of its target; `cmd.args` holds every argument after the alias, unparsed. */
|
|
100
|
+
type AliasDispatch = (name: string, target: string, cmd: Command) => void | Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Options for {@link bridgeAliases}. Setting any of them registers every
|
|
103
|
+
* alias as a proxy, a root command named after the alias, even for a
|
|
104
|
+
* single-word target that would otherwise take a Commander alias.
|
|
105
|
+
*/
|
|
106
|
+
interface BridgeOptions {
|
|
107
|
+
/** Hide proxies from help. Default true. */
|
|
108
|
+
hidden?: boolean;
|
|
109
|
+
/** A proxy's description, in place of `Alias for <target>`. */
|
|
110
|
+
describe?: (name: string, target: string) => string;
|
|
111
|
+
/**
|
|
112
|
+
* true: the proxy owns -h/--help and shows its own help. false (the
|
|
113
|
+
* default): --help reaches the target, or the dispatch handler.
|
|
114
|
+
*/
|
|
115
|
+
helpOption?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* A handler run instead of the target, or false to register proxies
|
|
118
|
+
* that run nothing (register-only). Default: dispatch the target
|
|
119
|
+
* through the program, like a native subcommand.
|
|
120
|
+
*/
|
|
121
|
+
dispatch?: AliasDispatch | false;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Register loaded aliases with Commander's native .alias() API.
|
|
125
|
+
*
|
|
126
|
+
* Simple single-command aliases use Commander's built-in .alias(),
|
|
127
|
+
* giving free completion and help display. Multi-word or unresolved
|
|
128
|
+
* targets get a hidden proxy command that dispatches the expanded
|
|
129
|
+
* args from the program, like a native subcommand. With any
|
|
130
|
+
* {@link BridgeOptions} set, every alias gets a proxy shaped by them.
|
|
131
|
+
*
|
|
132
|
+
* Completion offers each alias at most once. A native alias, or a hidden
|
|
133
|
+
* proxy that dispatches its target or runs nothing, is a stand-in:
|
|
134
|
+
* completion lists it as `alias for <target>` and offers a proxy only
|
|
135
|
+
* its help flag. A visible proxy, or one with a dispatch handler, is a
|
|
136
|
+
* real command and completes like any subcommand, with its own flags,
|
|
137
|
+
* including any added after bridging; a hidden one is not listed.
|
|
138
|
+
*
|
|
139
|
+
* `source` is an {@link AliasStore} or a plain alias map, so aliases
|
|
140
|
+
* can come from any storage.
|
|
141
|
+
*
|
|
142
|
+
* Dispatch reuses Commander's own subcommand dispatch rather than
|
|
143
|
+
* calling parse()/parseAsync() again: re-parsing resets program
|
|
144
|
+
* option values mid-parse and fixes the sync/async mode, whereas
|
|
145
|
+
* dispatch returns the target's result as-is. parseAsync() callers
|
|
146
|
+
* thus await async targets (rejections propagate), and parse()
|
|
147
|
+
* callers keep synchronous throws.
|
|
148
|
+
*/
|
|
149
|
+
declare function bridgeAliases(program: Command, source: AliasStore | AliasMap, opts?: BridgeOptions): void;
|
|
150
|
+
|
|
151
|
+
type alias_AliasDispatch = AliasDispatch;
|
|
152
|
+
type alias_AliasMap = AliasMap;
|
|
153
|
+
type alias_AliasNameError = AliasNameError;
|
|
154
|
+
declare const alias_AliasNameError: typeof AliasNameError;
|
|
155
|
+
type alias_AliasNameErrorKind = AliasNameErrorKind;
|
|
156
|
+
type alias_AliasNameRules = AliasNameRules;
|
|
157
|
+
type alias_AliasStore = AliasStore;
|
|
158
|
+
declare const alias_AliasStore: typeof AliasStore;
|
|
159
|
+
type alias_BridgeOptions = BridgeOptions;
|
|
160
|
+
type alias_Expander = Expander;
|
|
161
|
+
declare const alias_Expander: typeof Expander;
|
|
162
|
+
type alias_ExpanderConfig = ExpanderConfig;
|
|
163
|
+
declare const alias_bridgeAliases: typeof bridgeAliases;
|
|
164
|
+
declare const alias_detectCycles: typeof detectCycles;
|
|
165
|
+
declare const alias_findCommand: typeof findCommand;
|
|
166
|
+
declare const alias_findFirstNonFlag: typeof findFirstNonFlag;
|
|
167
|
+
declare const alias_loadFrom: typeof loadFrom;
|
|
168
|
+
declare const alias_saveTo: typeof saveTo;
|
|
169
|
+
declare const alias_validateAliasName: typeof validateAliasName;
|
|
170
|
+
declare namespace alias {
|
|
171
|
+
export { type alias_AliasDispatch as AliasDispatch, type alias_AliasMap as AliasMap, alias_AliasNameError as AliasNameError, type alias_AliasNameErrorKind as AliasNameErrorKind, type alias_AliasNameRules as AliasNameRules, alias_AliasStore as AliasStore, type alias_BridgeOptions as BridgeOptions, alias_Expander as Expander, type alias_ExpanderConfig as ExpanderConfig, alias_bridgeAliases as bridgeAliases, alias_detectCycles as detectCycles, alias_findCommand as findCommand, alias_findFirstNonFlag as findFirstNonFlag, alias_loadFrom as loadFrom, alias_saveTo as saveTo, alias_validateAliasName as validateAliasName };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { type AliasDispatch as A, type BridgeOptions as B, Expander as E, alias as a, type AliasMap as b, AliasNameError as c, type AliasNameErrorKind as d, type AliasNameRules as e, AliasStore as f, type ExpanderConfig as g, bridgeAliases as h, detectCycles as i, findCommand as j, findFirstNonFlag as k, loadFrom as l, saveTo as s, validateAliasName as v };
|
package/dist/alias.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import 'commander';
|
|
2
|
-
export { A as
|
|
2
|
+
export { A as AliasDispatch, b as AliasMap, c as AliasNameError, d as AliasNameErrorKind, e as AliasNameRules, f as AliasStore, B as BridgeOptions, E as Expander, g as ExpanderConfig, h as bridgeAliases, i as detectCycles, j as findCommand, k as findFirstNonFlag, l as loadFrom, s as saveTo, v as validateAliasName } from './alias-D9_qFlyP.js';
|
package/dist/alias.js
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkBLS2OBIQjs = require('./chunk-BLS2OBIQ.js');
|
|
10
13
|
require('./chunk-JZ22ZUFA.js');
|
|
11
14
|
require('./chunk-JKMQSAJP.js');
|
|
12
15
|
require('./chunk-R5U7XKVJ.js');
|
|
@@ -18,4 +21,7 @@ require('./chunk-R5U7XKVJ.js');
|
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
exports.AliasNameError = _chunkBLS2OBIQjs.AliasNameError; exports.AliasStore = _chunkBLS2OBIQjs.AliasStore; exports.Expander = _chunkBLS2OBIQjs.Expander; exports.bridgeAliases = _chunkBLS2OBIQjs.bridgeAliases; exports.detectCycles = _chunkBLS2OBIQjs.detectCycles; exports.findCommand = _chunkBLS2OBIQjs.findCommand; exports.findFirstNonFlag = _chunkBLS2OBIQjs.findFirstNonFlag; exports.loadFrom = _chunkBLS2OBIQjs.loadFrom; exports.saveTo = _chunkBLS2OBIQjs.saveTo; exports.validateAliasName = _chunkBLS2OBIQjs.validateAliasName;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
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
2
|
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkUZ65A27Pjs = require('./chunk-UZ65A27P.js');
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
var _chunkIXVQ62NZjs = require('./chunk-IXVQ62NZ.js');
|
|
4
17
|
|
|
5
18
|
|
|
@@ -30,132 +43,6 @@ _chunkR5U7XKVJjs.__export.call(void 0, toolspec_exports, {
|
|
|
30
43
|
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
31
44
|
var _jsyaml = require('js-yaml'); var yaml2 = _interopRequireWildcard(_jsyaml); var yaml = _interopRequireWildcard(_jsyaml);
|
|
32
45
|
|
|
33
|
-
// src/toolspec-internal.ts
|
|
34
|
-
function annotationsOf(cmd) {
|
|
35
|
-
return _nullishCoalesce(cmd.annotations, () => ( {}));
|
|
36
|
-
}
|
|
37
|
-
function splitCSV(s) {
|
|
38
|
-
if (!s) return void 0;
|
|
39
|
-
const out = s.split(",").map((p) => p.trim()).filter((p) => p !== "");
|
|
40
|
-
return out.length > 0 ? out : void 0;
|
|
41
|
-
}
|
|
42
|
-
function isRunnable(cmd) {
|
|
43
|
-
return cmd._actionHandler != null;
|
|
44
|
-
}
|
|
45
|
-
function isHidden(cmd, parent) {
|
|
46
|
-
return !parent.createHelp().visibleCommands(parent).includes(cmd);
|
|
47
|
-
}
|
|
48
|
-
var BUILTIN_NAMES = /* @__PURE__ */ new Set([
|
|
49
|
-
"help",
|
|
50
|
-
"completion",
|
|
51
|
-
"man",
|
|
52
|
-
"__complete",
|
|
53
|
-
"__completeNoDesc"
|
|
54
|
-
]);
|
|
55
|
-
function isBuiltin(cmd, parent) {
|
|
56
|
-
return BUILTIN_NAMES.has(cmd.name()) || parent.name() === "completion";
|
|
57
|
-
}
|
|
58
|
-
function byName(a, b) {
|
|
59
|
-
const x = a.name();
|
|
60
|
-
const y = b.name();
|
|
61
|
-
return x < y ? -1 : x > y ? 1 : 0;
|
|
62
|
-
}
|
|
63
|
-
function goQuote(s) {
|
|
64
|
-
return JSON.stringify(s).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
65
|
-
}
|
|
66
|
-
function reindentRaw(raw, depth) {
|
|
67
|
-
JSON.parse(raw);
|
|
68
|
-
let out = "";
|
|
69
|
-
let level = depth;
|
|
70
|
-
let needIndent = false;
|
|
71
|
-
const nl = (lvl) => "\n" + " ".repeat(lvl);
|
|
72
|
-
for (let i = 0; i < raw.length; i++) {
|
|
73
|
-
const c = raw[i];
|
|
74
|
-
if (c === " " || c === " " || c === "\n" || c === "\r") continue;
|
|
75
|
-
if (needIndent && c !== "]" && c !== "}") {
|
|
76
|
-
out += nl(level);
|
|
77
|
-
needIndent = false;
|
|
78
|
-
}
|
|
79
|
-
if (c === '"') {
|
|
80
|
-
let j = i + 1;
|
|
81
|
-
while (raw[j] !== '"') j += raw[j] === "\\" ? 2 : 1;
|
|
82
|
-
out += goQuote(JSON.parse(raw.slice(i, j + 1)));
|
|
83
|
-
i = j;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
switch (c) {
|
|
87
|
-
case "{":
|
|
88
|
-
case "[":
|
|
89
|
-
out += c;
|
|
90
|
-
level++;
|
|
91
|
-
needIndent = true;
|
|
92
|
-
break;
|
|
93
|
-
case "}":
|
|
94
|
-
case "]":
|
|
95
|
-
level--;
|
|
96
|
-
if (needIndent) needIndent = false;
|
|
97
|
-
else out += nl(level);
|
|
98
|
-
out += c;
|
|
99
|
-
break;
|
|
100
|
-
case ",":
|
|
101
|
-
out += c + nl(level);
|
|
102
|
-
break;
|
|
103
|
-
case ":":
|
|
104
|
-
out += ": ";
|
|
105
|
-
break;
|
|
106
|
-
default:
|
|
107
|
-
out += c;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return out;
|
|
111
|
-
}
|
|
112
|
-
function encodeGoJSON(v, depth, rawKeys, key) {
|
|
113
|
-
if (key !== void 0 && rawKeys.has(key) && typeof v === "string") {
|
|
114
|
-
return reindentRaw(v, depth);
|
|
115
|
-
}
|
|
116
|
-
if (typeof v === "string") return goQuote(v);
|
|
117
|
-
if (typeof v === "boolean" || typeof v === "number") return JSON.stringify(v);
|
|
118
|
-
if (Array.isArray(v)) {
|
|
119
|
-
if (v.length === 0) return "[]";
|
|
120
|
-
const pad = " ".repeat(depth + 1);
|
|
121
|
-
const items = v.map((x) => pad + encodeGoJSON(x, depth + 1, rawKeys));
|
|
122
|
-
return "[\n" + items.join(",\n") + "\n" + " ".repeat(depth) + "]";
|
|
123
|
-
}
|
|
124
|
-
if (v && typeof v === "object") {
|
|
125
|
-
const entries = Object.entries(v).filter(([, x]) => x !== void 0);
|
|
126
|
-
if (entries.length === 0) return "{}";
|
|
127
|
-
const pad = " ".repeat(depth + 1);
|
|
128
|
-
const items = entries.map(
|
|
129
|
-
([k, x]) => pad + goQuote(k) + ": " + encodeGoJSON(x, depth + 1, rawKeys, k)
|
|
130
|
-
);
|
|
131
|
-
return "{\n" + items.join(",\n") + "\n" + " ".repeat(depth) + "}";
|
|
132
|
-
}
|
|
133
|
-
return "null";
|
|
134
|
-
}
|
|
135
|
-
function walkCommands(program, reserved, visit) {
|
|
136
|
-
const reservedSet = new Set(_nullishCoalesce(reserved, () => ( [])));
|
|
137
|
-
const walk = (cmd, parent, path, depthOne, reservedTree) => {
|
|
138
|
-
const inReserved = reservedTree || annotationsOf(cmd)["kit/reserved"] === "true";
|
|
139
|
-
visit(cmd, parent, path, inReserved || reservedSet.has(depthOne));
|
|
140
|
-
for (const child of [...cmd.commands].sort(byName)) {
|
|
141
|
-
if (child.name() === "") continue;
|
|
142
|
-
walk(child, cmd, [...path, child.name()], depthOne, inReserved);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
for (const child of [...program.commands].sort(byName)) {
|
|
146
|
-
if (child.name() === "") continue;
|
|
147
|
-
walk(child, program, [program.name(), child.name()], child.name(), false);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
var pflagTypes = /* @__PURE__ */ new WeakMap();
|
|
151
|
-
function goFormat0(x) {
|
|
152
|
-
const floor = Math.floor(x);
|
|
153
|
-
const diff = x - floor;
|
|
154
|
-
let r = diff > 0.5 ? floor + 1 : diff < 0.5 ? floor : floor % 2 === 0 ? floor : floor + 1;
|
|
155
|
-
if (Object.is(r, -0)) r = 0;
|
|
156
|
-
return String(r);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
46
|
// src/toolspec-manifest.ts
|
|
160
47
|
var SCHEMA_VERSION_ENV = "KIT_TOOLSPEC_SCHEMA";
|
|
161
48
|
var LATEST_SCHEMA_VERSION = "1.1";
|
|
@@ -260,13 +147,14 @@ function dryRunSupported(ann) {
|
|
|
260
147
|
}
|
|
261
148
|
function flagTypeAndDefault(opt) {
|
|
262
149
|
const def = opt.defaultValue;
|
|
263
|
-
const declared = pflagTypes.get(opt);
|
|
150
|
+
const declared = _chunkUZ65A27Pjs.pflagTypes.get(opt);
|
|
264
151
|
if (declared) return [declared, def === void 0 ? "" : String(def)];
|
|
265
|
-
if (opt.isBoolean()) return ["bool", def === void 0 ? "false" : String(def)];
|
|
266
152
|
if (opt.variadic) {
|
|
267
153
|
const items = def === void 0 ? [] : Array.isArray(def) ? def : [def];
|
|
268
154
|
return ["stringSlice", `[${items.map(String).join(",")}]`];
|
|
269
155
|
}
|
|
156
|
+
if (opt.negate) return ["bool", "false"];
|
|
157
|
+
if (_chunkUZ65A27Pjs.takesNoValue.call(void 0, opt)) return ["bool", def === void 0 ? "false" : String(def)];
|
|
270
158
|
return ["string", def === void 0 ? "" : String(def)];
|
|
271
159
|
}
|
|
272
160
|
function manifestFlags(cmd, ann, withHelp) {
|
|
@@ -298,7 +186,7 @@ function manifestFlags(cmd, ann, withHelp) {
|
|
|
298
186
|
return flags.length > 0 ? flags : void 0;
|
|
299
187
|
}
|
|
300
188
|
function manifestArgs(cmd, ann) {
|
|
301
|
-
const declared = splitCSV(ann["kit/args"]);
|
|
189
|
+
const declared = _chunkUZ65A27Pjs.splitCSV.call(void 0, ann["kit/args"]);
|
|
302
190
|
const args = declared ? declared.map(
|
|
303
191
|
(n) => n.endsWith("?") ? { name: n.slice(0, -1) } : { name: n, required: true }
|
|
304
192
|
) : cmd.registeredArguments.map(
|
|
@@ -307,7 +195,7 @@ function manifestArgs(cmd, ann) {
|
|
|
307
195
|
return args.length > 0 ? args : void 0;
|
|
308
196
|
}
|
|
309
197
|
function manifestCommand(cmd, path, hidden, reserved, invoked) {
|
|
310
|
-
const ann = annotationsOf(cmd);
|
|
198
|
+
const ann = _chunkUZ65A27Pjs.annotationsOf.call(void 0, cmd);
|
|
311
199
|
const summary = cmd.summary();
|
|
312
200
|
const short = summary || cmd.description();
|
|
313
201
|
const long = summary ? cmd.description() : "";
|
|
@@ -321,7 +209,7 @@ function manifestCommand(cmd, path, hidden, reserved, invoked) {
|
|
|
321
209
|
if (args) out.args = args;
|
|
322
210
|
const flags = manifestFlags(cmd, ann, invoked);
|
|
323
211
|
if (flags) out.flags = flags;
|
|
324
|
-
const exitCodes = splitCSV(ann["kit/exit-codes"]);
|
|
212
|
+
const exitCodes = _chunkUZ65A27Pjs.splitCSV.call(void 0, ann["kit/exit-codes"]);
|
|
325
213
|
if (exitCodes) out.exit_codes = exitCodes;
|
|
326
214
|
const deprecatedSince = _nullishCoalesce(ann["kit/deprecated-since"], () => ( ""));
|
|
327
215
|
const removalTarget = _nullishCoalesce(ann["kit/removal-target"], () => ( ""));
|
|
@@ -368,19 +256,19 @@ function buildManifest(program, schemaVersion, opts = {}) {
|
|
|
368
256
|
schema_version: schemaVersion,
|
|
369
257
|
commands: []
|
|
370
258
|
};
|
|
371
|
-
walkCommands(program, opts.reserved, (cmd, parent, path, reserved) => {
|
|
372
|
-
const ann = annotationsOf(cmd);
|
|
259
|
+
_chunkUZ65A27Pjs.walkCommands.call(void 0, program, opts.reserved, (cmd, parent, path, reserved) => {
|
|
260
|
+
const ann = _chunkUZ65A27Pjs.annotationsOf.call(void 0, cmd);
|
|
373
261
|
const deprecated = !!(ann["kit/deprecated-since"] || ann["kit/removal-target"]);
|
|
374
|
-
if (!isRunnable(cmd) || isBuiltin(cmd, parent)) return;
|
|
262
|
+
if (!_chunkUZ65A27Pjs.isRunnable.call(void 0, cmd) || _chunkUZ65A27Pjs.isBuiltin.call(void 0, cmd, parent)) return;
|
|
375
263
|
if (deprecated && !opts.includeDeprecated) return;
|
|
376
264
|
m.commands.push(
|
|
377
|
-
manifestCommand(cmd, path, isHidden(cmd, parent), reserved, cmd === opts.invokedCommand)
|
|
265
|
+
manifestCommand(cmd, path, _chunkUZ65A27Pjs.isHidden.call(void 0, cmd, parent), reserved, cmd === opts.invokedCommand)
|
|
378
266
|
);
|
|
379
267
|
});
|
|
380
268
|
return m;
|
|
381
269
|
}
|
|
382
270
|
function renderManifestJSON(m) {
|
|
383
|
-
return encodeGoJSON(m, 0, /* @__PURE__ */ new Set(["output_schema"])) + "\n";
|
|
271
|
+
return _chunkUZ65A27Pjs.encodeGoJSON.call(void 0, m, 0, /* @__PURE__ */ new Set(["output_schema"])) + "\n";
|
|
384
272
|
}
|
|
385
273
|
|
|
386
274
|
// src/toolspec-spec.ts
|
|
@@ -456,7 +344,7 @@ function registerSpecCommand(program, schemaVersion, opts = {}) {
|
|
|
456
344
|
if (local.version || versionForwarded) {
|
|
457
345
|
const vf = format === "" ? "json" : format;
|
|
458
346
|
if (vf === "json") {
|
|
459
|
-
out(encodeGoJSON({ schema_version: resolved }, 0, /* @__PURE__ */ new Set()) + "\n");
|
|
347
|
+
out(_chunkUZ65A27Pjs.encodeGoJSON.call(void 0, { schema_version: resolved }, 0, /* @__PURE__ */ new Set()) + "\n");
|
|
460
348
|
} else if (vf === "yaml") {
|
|
461
349
|
out(toYAML({ schema_version: resolved }));
|
|
462
350
|
} else {
|
|
@@ -578,9 +466,9 @@ function coverageOf(program, opts = {}) {
|
|
|
578
466
|
};
|
|
579
467
|
const unannotated = [];
|
|
580
468
|
const malformed = [];
|
|
581
|
-
walkCommands(program, opts.reserved, (cmd, parent, path, reserved) => {
|
|
582
|
-
const ann = annotationsOf(cmd);
|
|
583
|
-
if (!isRunnable(cmd) || isBuiltin(cmd, parent) || reserved) return;
|
|
469
|
+
_chunkUZ65A27Pjs.walkCommands.call(void 0, program, opts.reserved, (cmd, parent, path, reserved) => {
|
|
470
|
+
const ann = _chunkUZ65A27Pjs.annotationsOf.call(void 0, cmd);
|
|
471
|
+
if (!_chunkUZ65A27Pjs.isRunnable.call(void 0, cmd) || _chunkUZ65A27Pjs.isBuiltin.call(void 0, cmd, parent) || reserved) return;
|
|
584
472
|
if (ann[SPEC_COMMAND_ANNOTATION] === "true") return;
|
|
585
473
|
rep.total++;
|
|
586
474
|
const p = path.join(" ");
|
|
@@ -635,7 +523,7 @@ function registerCoverageCommand(spec, program, reserved) {
|
|
|
635
523
|
}
|
|
636
524
|
return n;
|
|
637
525
|
}).default(0);
|
|
638
|
-
pflagTypes.set(min, "float64");
|
|
526
|
+
_chunkUZ65A27Pjs.pflagTypes.set(min, "float64");
|
|
639
527
|
const cmd = new (0, _commander.Command)("coverage").summary("Report kit/side-effect annotation coverage").description(
|
|
640
528
|
"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."
|
|
641
529
|
).addOption(min);
|
|
@@ -655,11 +543,11 @@ function registerCoverageCommand(spec, program, reserved) {
|
|
|
655
543
|
const rep = coverageOf(program, { reserved });
|
|
656
544
|
const [given, changed] = formatFlag(this);
|
|
657
545
|
const format = changed && given !== "" ? given : "json";
|
|
658
|
-
const text = format === "json" ? encodeGoJSON(rep, 0, /* @__PURE__ */ new Set()) + "\n" : captureRender(format, rep);
|
|
546
|
+
const text = format === "json" ? _chunkUZ65A27Pjs.encodeGoJSON.call(void 0, rep, 0, /* @__PURE__ */ new Set()) + "\n" : captureRender(format, rep);
|
|
659
547
|
this.configureOutput().writeOut(text);
|
|
660
548
|
const threshold = this.opts().min;
|
|
661
549
|
if (coverageMeets(rep, threshold)) return;
|
|
662
|
-
const message = !rep.measurable ? `annotation coverage unmeasurable: no reflectable commands in ${JSON.stringify(rep.tool)} (--min ${goFormat0(threshold)}% cannot be evaluated)` : `annotation coverage ${goFormat0(coveragePercent(rep))}% (${rep.annotated}/${rep.total}) is below --min ${goFormat0(threshold)}%; unannotated: ` + (_nullishCoalesce(rep.unannotated_paths, () => ( []))).join(", ");
|
|
550
|
+
const message = !rep.measurable ? `annotation coverage unmeasurable: no reflectable commands in ${JSON.stringify(rep.tool)} (--min ${_chunkUZ65A27Pjs.goFormat0.call(void 0, threshold)}% cannot be evaluated)` : `annotation coverage ${_chunkUZ65A27Pjs.goFormat0.call(void 0, coveragePercent(rep))}% (${rep.annotated}/${rep.total}) is below --min ${_chunkUZ65A27Pjs.goFormat0.call(void 0, threshold)}%; unannotated: ` + (_nullishCoalesce(rep.unannotated_paths, () => ( []))).join(", ");
|
|
663
551
|
this.error(message, { exitCode: _chunkPOR5L2DGjs.EXIT_CONFLICT, code: "kit.spec.coverageBelowMin" });
|
|
664
552
|
});
|
|
665
553
|
spec.addCommand(cmd);
|
|
@@ -829,21 +717,24 @@ function findCommand(spec, name) {
|
|
|
829
717
|
return void 0;
|
|
830
718
|
}
|
|
831
719
|
function toolSpecFromCommand(program, opts = {}) {
|
|
832
|
-
const
|
|
720
|
+
const ctx = {
|
|
721
|
+
annotations: _nullishCoalesce(opts.annotations, () => ( {})),
|
|
722
|
+
includeHidden: _nullishCoalesce(opts.includeHidden, () => ( false))
|
|
723
|
+
};
|
|
833
724
|
const spec = {
|
|
834
725
|
name: program.name(),
|
|
835
726
|
schemaVersion: _nullishCoalesce(opts.schemaVersion, () => ( "1")),
|
|
836
|
-
commands: projectChildren(program, [],
|
|
727
|
+
commands: projectChildren(program, [], ctx)
|
|
837
728
|
};
|
|
838
729
|
const flags = projectFlags(program);
|
|
839
730
|
if (flags) spec.flags = flags;
|
|
840
731
|
return spec;
|
|
841
732
|
}
|
|
842
|
-
function projectChildren(cmd, path,
|
|
733
|
+
function projectChildren(cmd, path, ctx) {
|
|
843
734
|
const visible = cmd.createHelp().visibleCommands(cmd);
|
|
844
|
-
return
|
|
735
|
+
return cmd.commands.filter((c) => c.name() !== "").filter((c) => ctx.includeHidden || visible.includes(c)).filter((c) => !_chunkUZ65A27Pjs.isBuiltin.call(void 0, c, cmd)).filter((c) => kitAnnotations(c)["kit/spec-command"] !== "true").map((c) => projectCommand(c, [...path, c.name()], ctx));
|
|
845
736
|
}
|
|
846
|
-
function projectCommand(cmd, path,
|
|
737
|
+
function projectCommand(cmd, path, ctx) {
|
|
847
738
|
const out = { name: cmd.name() };
|
|
848
739
|
const short = cmd.summary() || cmd.description();
|
|
849
740
|
if (short) out.short = short;
|
|
@@ -851,15 +742,13 @@ function projectCommand(cmd, path, annotations) {
|
|
|
851
742
|
if (aliases.length > 0) out.aliases = [...aliases];
|
|
852
743
|
const flags = projectFlags(cmd);
|
|
853
744
|
if (flags) out.flags = flags;
|
|
854
|
-
const args =
|
|
855
|
-
(a) => a.required ? { name: a.name(), required: true } : { name: a.name() }
|
|
856
|
-
);
|
|
745
|
+
const args = _chunkUZ65A27Pjs.declaredArgs.call(void 0, cmd);
|
|
857
746
|
if (args.length > 0) out.args = args;
|
|
858
747
|
const exitCodes = splitCSV2(kitAnnotations(cmd)["kit/exit-codes"]);
|
|
859
748
|
if (exitCodes) out.exitCodes = exitCodes;
|
|
860
|
-
const children = projectChildren(cmd, path,
|
|
749
|
+
const children = projectChildren(cmd, path, ctx);
|
|
861
750
|
if (children.length > 0) out.children = children;
|
|
862
|
-
const ann = annotations[path.join(" ")];
|
|
751
|
+
const ann = ctx.annotations[path.join(" ")];
|
|
863
752
|
if (ann) {
|
|
864
753
|
for (const [k, v] of Object.entries(ann)) {
|
|
865
754
|
if (v !== void 0) out[k] = v;
|
|
@@ -891,8 +780,8 @@ function projectFlags(cmd) {
|
|
|
891
780
|
return out.length > 0 ? out : void 0;
|
|
892
781
|
}
|
|
893
782
|
function flagType(opt) {
|
|
894
|
-
if (opt.isBoolean()) return "bool";
|
|
895
783
|
if (opt.variadic) return "stringSlice";
|
|
784
|
+
if (_chunkUZ65A27Pjs.takesNoValue.call(void 0, opt)) return "bool";
|
|
896
785
|
return "string";
|
|
897
786
|
}
|
|
898
787
|
|