@hop-top/kit 0.5.0-alpha.6 → 0.5.0-alpha.7
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 +36 -0
- package/LICENSE-cobra.txt +174 -0
- package/NOTICE +15 -0
- package/README.md +3 -3
- package/dist/{alias-BOj0-VAr.d.ts → alias-BsJ2jGqQ.d.ts} +9 -1
- package/dist/alias.d.ts +1 -1
- package/dist/alias.js +4 -2
- package/dist/chunk-263IZ6Z6.js +915 -0
- package/dist/{chunk-S45UHXQF.js → chunk-DIDN4X5C.js} +8 -6
- package/dist/{chunk-7FDIN5KE.js → chunk-GHPJJV5L.js} +8 -4
- package/dist/chunk-JKMQSAJP.js +174 -0
- package/dist/chunk-JZ22ZUFA.js +1131 -0
- package/dist/{chunk-GAZPYCQD.js → chunk-NLMS7HGP.js} +93 -35
- package/dist/chunk-QQQYCWSC.js +240 -0
- package/dist/chunk-XJTRY453.js +868 -0
- package/dist/cli.js +6 -4
- package/dist/completion-sDKVXPUL.d.ts +109 -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 +2 -1
- package/dist/completion.js +23 -2
- 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 -1
- package/dist/config.js +4 -2
- package/dist/index.d.ts +7 -5
- package/dist/index.js +26 -18
- package/dist/log-CkaxMX3U.d.ts +115 -0
- package/dist/log.d.ts +1 -1
- package/dist/log.js +2 -2
- package/dist/toolspec-UrWnoJ3Y.d.ts +336 -0
- package/dist/toolspec.d.ts +2 -1
- package/dist/toolspec.js +27 -2
- package/package.json +19 -3
- package/src/alias.test.ts +110 -1
- package/src/alias.ts +19 -4
- package/src/cli.ts +5 -0
- package/src/completion-scripts.ts +16 -0
- package/src/completion-values.test.ts +70 -10
- package/src/completion-values.ts +170 -66
- package/src/completion.conformance.test.ts +297 -0
- package/src/completion.test.ts +256 -145
- package/src/completion.ts +764 -121
- package/src/config-merge.test.ts +425 -0
- package/src/config.test.ts +41 -0
- package/src/config.ts +265 -18
- package/src/index.test.ts +2 -1
- package/src/index.ts +5 -1
- package/src/log.test.ts +270 -1
- package/src/log.ts +172 -44
- package/src/published-types.test.ts +18 -0
- package/src/toolspec-internal.ts +197 -0
- package/src/toolspec-manifest.test.ts +82 -0
- package/src/toolspec-manifest.ts +404 -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 +216 -0
- package/src/toolspec.ts +159 -0
- package/test/toolspec/fixture.ts +73 -0
- package/dist/chunk-6RFRV4VP.js +0 -128
- package/dist/chunk-IQXEISMC.js +0 -142
- package/dist/chunk-W7ERKNSQ.js +0 -171
- package/dist/completion-CVnPcWMZ.d.ts +0 -32
- package/dist/config-Bm9fBXch.d.ts +0 -134
- package/dist/log-uKjHsK-c.d.ts +0 -62
- package/dist/toolspec-DPBr18Ub.d.ts +0 -106
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { Command as Command$1 } from 'commander';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Port of Go's `toolspec.Manifest` and `BuildManifest`
|
|
5
|
+
* (go/ai/toolspec/spec.go, go/ai/toolspec/cli/spec_command.go): the
|
|
6
|
+
* flat, snake_case capability manifest a `<tool> spec` command emits,
|
|
7
|
+
* projected from a commander tree carrying kit/* annotations.
|
|
8
|
+
*
|
|
9
|
+
* Byte parity with Go is pinned by
|
|
10
|
+
* sdk/tests/cross-lang/fixtures/toolspec-manifest*.json.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Env var a harness sets to request a manifest schema version. */
|
|
14
|
+
declare const SCHEMA_VERSION_ENV = "KIT_TOOLSPEC_SCHEMA";
|
|
15
|
+
/** Newest manifest schema version kit emits. */
|
|
16
|
+
declare const LATEST_SCHEMA_VERSION = "1.1";
|
|
17
|
+
/** Value side_effect / idempotent carry when nothing was declared. */
|
|
18
|
+
declare const SIDE_EFFECT_UNKNOWN = "unknown";
|
|
19
|
+
declare const IDEMPOTENT_UNKNOWN = "unknown";
|
|
20
|
+
interface ManifestArg {
|
|
21
|
+
name: string;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface ManifestFlag {
|
|
25
|
+
name: string;
|
|
26
|
+
short?: string;
|
|
27
|
+
type?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
default?: string;
|
|
30
|
+
since_version?: string;
|
|
31
|
+
}
|
|
32
|
+
interface ManifestExample {
|
|
33
|
+
title: string;
|
|
34
|
+
command: string;
|
|
35
|
+
output?: string;
|
|
36
|
+
}
|
|
37
|
+
interface ManifestNextStep {
|
|
38
|
+
when?: string;
|
|
39
|
+
suggest: string;
|
|
40
|
+
reason?: string;
|
|
41
|
+
}
|
|
42
|
+
/** One invocable command. Field order is the Go struct order. */
|
|
43
|
+
interface ManifestCommand {
|
|
44
|
+
path: string[];
|
|
45
|
+
short: string;
|
|
46
|
+
side_effect: string;
|
|
47
|
+
idempotent: string;
|
|
48
|
+
args?: ManifestArg[];
|
|
49
|
+
flags?: ManifestFlag[];
|
|
50
|
+
exit_codes?: string[];
|
|
51
|
+
deprecated?: boolean;
|
|
52
|
+
deprecated_since?: string;
|
|
53
|
+
removal_target?: string;
|
|
54
|
+
since_version?: string;
|
|
55
|
+
long?: string;
|
|
56
|
+
retryable: boolean;
|
|
57
|
+
/** Raw JSON Schema text, embedded verbatim (Go RawJSON). */
|
|
58
|
+
output_schema?: string;
|
|
59
|
+
output_schema_version?: string;
|
|
60
|
+
examples?: ManifestExample[];
|
|
61
|
+
next_steps?: ManifestNextStep[];
|
|
62
|
+
top_level_verb?: boolean;
|
|
63
|
+
hierarchical?: boolean;
|
|
64
|
+
passthrough?: boolean;
|
|
65
|
+
destructive_token_required?: boolean;
|
|
66
|
+
dry_run_supported: boolean;
|
|
67
|
+
dry_run_rationale?: string;
|
|
68
|
+
reserved?: boolean;
|
|
69
|
+
hidden?: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface Manifest {
|
|
72
|
+
tool: string;
|
|
73
|
+
version: string;
|
|
74
|
+
schema_version: string;
|
|
75
|
+
commands: ManifestCommand[];
|
|
76
|
+
}
|
|
77
|
+
interface BuildManifestOptions {
|
|
78
|
+
/** Include deprecated commands (Go --include-deprecated). */
|
|
79
|
+
includeDeprecated?: boolean;
|
|
80
|
+
/** Depth-1 verbs the tool reserves (Go Root.IsReserved). */
|
|
81
|
+
reserved?: Iterable<string>;
|
|
82
|
+
/**
|
|
83
|
+
* The command being executed, if any. It gets the -h/--help flag
|
|
84
|
+
* cobra adds to the executing command, as a live Go run lists.
|
|
85
|
+
*/
|
|
86
|
+
invokedCommand?: Command$1;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolve the emitted schema_version (Go NegotiateSchemaVersion):
|
|
90
|
+
* declared is a floor; a well-formed request raises it to the highest
|
|
91
|
+
* known version not above the request; nothing is ever refused.
|
|
92
|
+
*/
|
|
93
|
+
declare function negotiateSchemaVersion(declared: string, requested: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Project a commander tree into the Go-shaped Manifest (Go
|
|
96
|
+
* BuildManifest). Lists every runnable command except framework
|
|
97
|
+
* builtins (help, completion, man) and, unless includeDeprecated,
|
|
98
|
+
* deprecated ones; hidden and reserved commands stay listed and say
|
|
99
|
+
* so. Children are visited in name order and flags sorted by name,
|
|
100
|
+
* as cobra and pflag do by default.
|
|
101
|
+
*/
|
|
102
|
+
declare function buildManifest(program: Command$1, schemaVersion: string, opts?: BuildManifestOptions): Manifest;
|
|
103
|
+
/**
|
|
104
|
+
* Render a Manifest exactly as Go's `output.Render(w, "json", m)`:
|
|
105
|
+
* two-space indent, HTML-escaped strings, trailing newline, fields
|
|
106
|
+
* in Go struct order with omitempty applied.
|
|
107
|
+
*/
|
|
108
|
+
declare function renderManifestJSON(m: Manifest): string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Port of Go's `<tool> spec` subcommand and `spec coverage`
|
|
112
|
+
* (go/ai/toolspec/cli/spec_command.go, coverage.go,
|
|
113
|
+
* coverage_command.go). Output bytes for json / kit-manifest are
|
|
114
|
+
* pinned against Go by sdk/tests/cross-lang/fixtures/toolspec-spec*.json.
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/** Annotation marking kit's spec subcommands (Go specCommandAnnotation). */
|
|
118
|
+
declare const SPEC_COMMAND_ANNOTATION = "kit/spec-command";
|
|
119
|
+
interface RegisterSpecOptions {
|
|
120
|
+
/** Depth-1 verbs the tool reserves; "spec" is always added. */
|
|
121
|
+
reserved?: Iterable<string>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Attach a `spec` subcommand emitting the tool's capability manifest
|
|
125
|
+
* (Go RegisterSpecCommand). Call once after registering every
|
|
126
|
+
* command.
|
|
127
|
+
*
|
|
128
|
+
* - `--format`: `kit-manifest` (default; aliases `kit`, `manifest`)
|
|
129
|
+
* and `json` emit Go-identical JSON; `yaml` emits the same document
|
|
130
|
+
* as YAML; `table`/`csv`/`text` emit nothing, as Go does today.
|
|
131
|
+
* The program's global `--format` is used when it has one,
|
|
132
|
+
* otherwise spec adds its own.
|
|
133
|
+
* - `--version`: print only the schema version.
|
|
134
|
+
* - `--include-deprecated`: list deprecated commands too.
|
|
135
|
+
*
|
|
136
|
+
* schemaVersion is a floor: each run resolves the emitted version
|
|
137
|
+
* against KIT_TOOLSPEC_SCHEMA (negotiateSchemaVersion).
|
|
138
|
+
*
|
|
139
|
+
* commander parses a program's own options anywhere on the line, so
|
|
140
|
+
* a program-level `--version` (commander `.version()`, which
|
|
141
|
+
* createCLI sets) would answer `spec --version` with the tool
|
|
142
|
+
* version. The program's version listener is wrapped so a literal
|
|
143
|
+
* `--version` is forwarded to spec when spec is the command being
|
|
144
|
+
* executed; `tool --version`, `-v`, and `--version` on any other
|
|
145
|
+
* command keep commander's behaviour. See forwardVersionToSpec.
|
|
146
|
+
*/
|
|
147
|
+
declare function registerSpecCommand(program: Command$1, schemaVersion: string, opts?: RegisterSpecOptions): Command$1;
|
|
148
|
+
/** Go CoverageReport: annotation coverage over a command tree. */
|
|
149
|
+
interface CoverageReport {
|
|
150
|
+
tool: string;
|
|
151
|
+
total: number;
|
|
152
|
+
annotated: number;
|
|
153
|
+
unannotated: number;
|
|
154
|
+
inferred: number;
|
|
155
|
+
malformed: number;
|
|
156
|
+
unannotated_paths?: string[];
|
|
157
|
+
malformed_paths?: string[];
|
|
158
|
+
measurable: boolean;
|
|
159
|
+
}
|
|
160
|
+
interface CoverageOptions {
|
|
161
|
+
/** Depth-1 verbs the tool reserves (not measured). */
|
|
162
|
+
reserved?: Iterable<string>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Measure kit/side-effect annotation coverage (Go CoverageOf):
|
|
166
|
+
* runnable commands, excluding framework builtins, reserved verbs and
|
|
167
|
+
* kit's spec commands. Deprecated and hidden commands count.
|
|
168
|
+
*/
|
|
169
|
+
declare function coverageOf(program: Command$1, opts?: CoverageOptions): CoverageReport;
|
|
170
|
+
|
|
171
|
+
type SafetyLevel = "safe" | "caution" | "dangerous";
|
|
172
|
+
interface Contract {
|
|
173
|
+
idempotent: boolean;
|
|
174
|
+
sideEffects?: string[];
|
|
175
|
+
retryable: boolean;
|
|
176
|
+
preConditions?: string[];
|
|
177
|
+
}
|
|
178
|
+
interface Safety {
|
|
179
|
+
level: SafetyLevel;
|
|
180
|
+
requiresConfirmation?: boolean;
|
|
181
|
+
permissions?: string[];
|
|
182
|
+
}
|
|
183
|
+
interface OutputSchema {
|
|
184
|
+
format?: string;
|
|
185
|
+
fields?: string[];
|
|
186
|
+
example?: string;
|
|
187
|
+
}
|
|
188
|
+
interface StateIntrospection {
|
|
189
|
+
configCommands?: string[];
|
|
190
|
+
envVars?: string[];
|
|
191
|
+
authCommands?: string[];
|
|
192
|
+
}
|
|
193
|
+
interface Provenance {
|
|
194
|
+
source?: string;
|
|
195
|
+
retrievedAt?: string;
|
|
196
|
+
confidence?: number;
|
|
197
|
+
}
|
|
198
|
+
interface Intent {
|
|
199
|
+
domain?: string;
|
|
200
|
+
category?: string;
|
|
201
|
+
tags?: string[];
|
|
202
|
+
}
|
|
203
|
+
interface Flag {
|
|
204
|
+
name: string;
|
|
205
|
+
short?: string;
|
|
206
|
+
type?: string;
|
|
207
|
+
description?: string;
|
|
208
|
+
/** Flag must be supplied (commander `makeOptionMandatory`). */
|
|
209
|
+
required?: boolean;
|
|
210
|
+
deprecated?: boolean;
|
|
211
|
+
replacedBy?: string;
|
|
212
|
+
}
|
|
213
|
+
/** A declared positional argument (mirrors Go toolspec.Arg). */
|
|
214
|
+
interface Arg {
|
|
215
|
+
name: string;
|
|
216
|
+
/** False/absent for an optional argument. */
|
|
217
|
+
required?: boolean;
|
|
218
|
+
}
|
|
219
|
+
interface Command {
|
|
220
|
+
name: string;
|
|
221
|
+
/** One-line summary of the command. */
|
|
222
|
+
short?: string;
|
|
223
|
+
aliases?: string[];
|
|
224
|
+
flags?: Flag[];
|
|
225
|
+
/** Declared positional arguments, in order. */
|
|
226
|
+
args?: Arg[];
|
|
227
|
+
/** Command takes positional arguments it does not declare. */
|
|
228
|
+
undeclaredArgs?: boolean;
|
|
229
|
+
/** Exit-code symbols the command may produce (kit/exit-codes). */
|
|
230
|
+
exitCodes?: string[];
|
|
231
|
+
children?: Command[];
|
|
232
|
+
contract?: Contract;
|
|
233
|
+
safety?: Safety;
|
|
234
|
+
previewModes?: string[];
|
|
235
|
+
outputSchema?: OutputSchema;
|
|
236
|
+
deprecated?: boolean;
|
|
237
|
+
deprecatedSince?: string;
|
|
238
|
+
replacedBy?: string;
|
|
239
|
+
intent?: Intent;
|
|
240
|
+
suggestedNext?: string[];
|
|
241
|
+
}
|
|
242
|
+
interface ErrorPattern {
|
|
243
|
+
pattern: string;
|
|
244
|
+
fix: string;
|
|
245
|
+
source?: string;
|
|
246
|
+
cause?: string;
|
|
247
|
+
fixes?: string[];
|
|
248
|
+
confidence?: number;
|
|
249
|
+
provenance?: Provenance;
|
|
250
|
+
}
|
|
251
|
+
interface Workflow {
|
|
252
|
+
name: string;
|
|
253
|
+
steps: string[];
|
|
254
|
+
after?: Record<string, string[]>;
|
|
255
|
+
provenance?: Provenance;
|
|
256
|
+
}
|
|
257
|
+
interface ToolSpec {
|
|
258
|
+
name: string;
|
|
259
|
+
schemaVersion: string;
|
|
260
|
+
commands: Command[];
|
|
261
|
+
flags?: Flag[];
|
|
262
|
+
errorPatterns?: ErrorPattern[];
|
|
263
|
+
workflows?: Workflow[];
|
|
264
|
+
stateIntrospection?: StateIntrospection;
|
|
265
|
+
}
|
|
266
|
+
/** Parse a YAML toolspec file into a ToolSpec object. */
|
|
267
|
+
declare function loadToolSpec(yamlPath: string): ToolSpec;
|
|
268
|
+
/** Validate a ToolSpec, returning a list of error strings. */
|
|
269
|
+
declare function validateToolSpec(spec: ToolSpec): string[];
|
|
270
|
+
/** BFS search for a command by name (mirrors Go FindCommand). */
|
|
271
|
+
declare function findCommand(spec: ToolSpec, name: string): Command | undefined;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Per-command fields merged over what the commander tree yields.
|
|
275
|
+
* Structural fields (name, aliases, flags, args, children) always
|
|
276
|
+
* come from the tree.
|
|
277
|
+
*/
|
|
278
|
+
type CommandAnnotation = Omit<Partial<Command>, "name" | "aliases" | "flags" | "args" | "children">;
|
|
279
|
+
interface FromCommandOptions {
|
|
280
|
+
/** Annotations keyed by space-joined path below the root, e.g. "mission list". */
|
|
281
|
+
annotations?: Record<string, CommandAnnotation>;
|
|
282
|
+
/** Defaults to "1", the version the YAML toolspecs declare. */
|
|
283
|
+
schemaVersion?: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Build a ToolSpec from a constructed commander tree, so CLIs with
|
|
287
|
+
* dynamically registered subcommands need no hand-synced YAML.
|
|
288
|
+
* Mirrors Go's WalkCobra projection: hidden commands and options are
|
|
289
|
+
* omitted, flag names are undashed, root options become spec.flags.
|
|
290
|
+
*/
|
|
291
|
+
declare function toolSpecFromCommand(program: Command$1, opts?: FromCommandOptions): ToolSpec;
|
|
292
|
+
|
|
293
|
+
type toolspec_Arg = Arg;
|
|
294
|
+
type toolspec_BuildManifestOptions = BuildManifestOptions;
|
|
295
|
+
type toolspec_Command = Command;
|
|
296
|
+
type toolspec_CommandAnnotation = CommandAnnotation;
|
|
297
|
+
type toolspec_Contract = Contract;
|
|
298
|
+
type toolspec_CoverageOptions = CoverageOptions;
|
|
299
|
+
type toolspec_CoverageReport = CoverageReport;
|
|
300
|
+
type toolspec_ErrorPattern = ErrorPattern;
|
|
301
|
+
type toolspec_Flag = Flag;
|
|
302
|
+
type toolspec_FromCommandOptions = FromCommandOptions;
|
|
303
|
+
declare const toolspec_IDEMPOTENT_UNKNOWN: typeof IDEMPOTENT_UNKNOWN;
|
|
304
|
+
type toolspec_Intent = Intent;
|
|
305
|
+
declare const toolspec_LATEST_SCHEMA_VERSION: typeof LATEST_SCHEMA_VERSION;
|
|
306
|
+
type toolspec_Manifest = Manifest;
|
|
307
|
+
type toolspec_ManifestArg = ManifestArg;
|
|
308
|
+
type toolspec_ManifestCommand = ManifestCommand;
|
|
309
|
+
type toolspec_ManifestExample = ManifestExample;
|
|
310
|
+
type toolspec_ManifestFlag = ManifestFlag;
|
|
311
|
+
type toolspec_ManifestNextStep = ManifestNextStep;
|
|
312
|
+
type toolspec_OutputSchema = OutputSchema;
|
|
313
|
+
type toolspec_Provenance = Provenance;
|
|
314
|
+
type toolspec_RegisterSpecOptions = RegisterSpecOptions;
|
|
315
|
+
declare const toolspec_SCHEMA_VERSION_ENV: typeof SCHEMA_VERSION_ENV;
|
|
316
|
+
declare const toolspec_SIDE_EFFECT_UNKNOWN: typeof SIDE_EFFECT_UNKNOWN;
|
|
317
|
+
declare const toolspec_SPEC_COMMAND_ANNOTATION: typeof SPEC_COMMAND_ANNOTATION;
|
|
318
|
+
type toolspec_Safety = Safety;
|
|
319
|
+
type toolspec_SafetyLevel = SafetyLevel;
|
|
320
|
+
type toolspec_StateIntrospection = StateIntrospection;
|
|
321
|
+
type toolspec_ToolSpec = ToolSpec;
|
|
322
|
+
type toolspec_Workflow = Workflow;
|
|
323
|
+
declare const toolspec_buildManifest: typeof buildManifest;
|
|
324
|
+
declare const toolspec_coverageOf: typeof coverageOf;
|
|
325
|
+
declare const toolspec_findCommand: typeof findCommand;
|
|
326
|
+
declare const toolspec_loadToolSpec: typeof loadToolSpec;
|
|
327
|
+
declare const toolspec_negotiateSchemaVersion: typeof negotiateSchemaVersion;
|
|
328
|
+
declare const toolspec_registerSpecCommand: typeof registerSpecCommand;
|
|
329
|
+
declare const toolspec_renderManifestJSON: typeof renderManifestJSON;
|
|
330
|
+
declare const toolspec_toolSpecFromCommand: typeof toolSpecFromCommand;
|
|
331
|
+
declare const toolspec_validateToolSpec: typeof validateToolSpec;
|
|
332
|
+
declare namespace toolspec {
|
|
333
|
+
export { type toolspec_Arg as Arg, type toolspec_BuildManifestOptions as BuildManifestOptions, type toolspec_Command as Command, type toolspec_CommandAnnotation as CommandAnnotation, type toolspec_Contract as Contract, type toolspec_CoverageOptions as CoverageOptions, type toolspec_CoverageReport as CoverageReport, type toolspec_ErrorPattern as ErrorPattern, type toolspec_Flag as Flag, type toolspec_FromCommandOptions as FromCommandOptions, toolspec_IDEMPOTENT_UNKNOWN as IDEMPOTENT_UNKNOWN, type toolspec_Intent as Intent, toolspec_LATEST_SCHEMA_VERSION as LATEST_SCHEMA_VERSION, type toolspec_Manifest as Manifest, type toolspec_ManifestArg as ManifestArg, type toolspec_ManifestCommand as ManifestCommand, type toolspec_ManifestExample as ManifestExample, type toolspec_ManifestFlag as ManifestFlag, type toolspec_ManifestNextStep as ManifestNextStep, type toolspec_OutputSchema as OutputSchema, type toolspec_Provenance as Provenance, type toolspec_RegisterSpecOptions as RegisterSpecOptions, toolspec_SCHEMA_VERSION_ENV as SCHEMA_VERSION_ENV, toolspec_SIDE_EFFECT_UNKNOWN as SIDE_EFFECT_UNKNOWN, toolspec_SPEC_COMMAND_ANNOTATION as SPEC_COMMAND_ANNOTATION, type toolspec_Safety as Safety, type toolspec_SafetyLevel as SafetyLevel, type toolspec_StateIntrospection as StateIntrospection, type toolspec_ToolSpec as ToolSpec, type toolspec_Workflow as Workflow, toolspec_buildManifest as buildManifest, toolspec_coverageOf as coverageOf, toolspec_findCommand as findCommand, toolspec_loadToolSpec as loadToolSpec, toolspec_negotiateSchemaVersion as negotiateSchemaVersion, toolspec_registerSpecCommand as registerSpecCommand, toolspec_renderManifestJSON as renderManifestJSON, toolspec_toolSpecFromCommand as toolSpecFromCommand, toolspec_validateToolSpec as validateToolSpec };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export { type Arg as A, type BuildManifestOptions as B, type Command as C, type ErrorPattern as E, type Flag as F, IDEMPOTENT_UNKNOWN as I, LATEST_SCHEMA_VERSION as L, type Manifest as M, type OutputSchema as O, type Provenance as P, type RegisterSpecOptions as R, SCHEMA_VERSION_ENV as S, type ToolSpec as T, type Workflow as W, type CommandAnnotation as a, type Contract as b, type CoverageOptions as c, type CoverageReport as d, type FromCommandOptions as e, type Intent as f, type ManifestArg as g, type ManifestCommand as h, type ManifestExample as i, type ManifestFlag as j, type ManifestNextStep as k, SIDE_EFFECT_UNKNOWN as l, SPEC_COMMAND_ANNOTATION as m, type Safety as n, type SafetyLevel as o, type StateIntrospection as p, buildManifest as q, coverageOf as r, findCommand as s, toolspec as t, loadToolSpec as u, negotiateSchemaVersion as v, registerSpecCommand as w, renderManifestJSON as x, toolSpecFromCommand as y, validateToolSpec as z };
|
package/dist/toolspec.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import 'commander';
|
|
2
|
+
export { A as Arg, B as BuildManifestOptions, C as Command, a as CommandAnnotation, b as Contract, c as CoverageOptions, d as CoverageReport, E as ErrorPattern, F as Flag, e as FromCommandOptions, I as IDEMPOTENT_UNKNOWN, f as Intent, L as LATEST_SCHEMA_VERSION, M as Manifest, g as ManifestArg, h as ManifestCommand, i as ManifestExample, j as ManifestFlag, k as ManifestNextStep, O as OutputSchema, P as Provenance, R as RegisterSpecOptions, S as SCHEMA_VERSION_ENV, l as SIDE_EFFECT_UNKNOWN, m as SPEC_COMMAND_ANNOTATION, n as Safety, o as SafetyLevel, p as StateIntrospection, T as ToolSpec, W as Workflow, q as buildManifest, r as coverageOf, s as findCommand, u as loadToolSpec, v as negotiateSchemaVersion, w as registerSpecCommand, x as renderManifestJSON, y as toolSpecFromCommand, z as validateToolSpec } from './toolspec-UrWnoJ3Y.js';
|
package/dist/toolspec.js
CHANGED
|
@@ -2,10 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunk263IZ6Z6js = require('./chunk-263IZ6Z6.js');
|
|
17
|
+
require('./chunk-IXVQ62NZ.js');
|
|
18
|
+
require('./chunk-72XZWQX7.js');
|
|
19
|
+
require('./chunk-POR5L2DG.js');
|
|
6
20
|
require('./chunk-R5U7XKVJ.js');
|
|
7
21
|
|
|
8
22
|
|
|
9
23
|
|
|
10
24
|
|
|
11
|
-
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
exports.IDEMPOTENT_UNKNOWN = _chunk263IZ6Z6js.IDEMPOTENT_UNKNOWN; exports.LATEST_SCHEMA_VERSION = _chunk263IZ6Z6js.LATEST_SCHEMA_VERSION; exports.SCHEMA_VERSION_ENV = _chunk263IZ6Z6js.SCHEMA_VERSION_ENV; exports.SIDE_EFFECT_UNKNOWN = _chunk263IZ6Z6js.SIDE_EFFECT_UNKNOWN; exports.SPEC_COMMAND_ANNOTATION = _chunk263IZ6Z6js.SPEC_COMMAND_ANNOTATION; exports.buildManifest = _chunk263IZ6Z6js.buildManifest; exports.coverageOf = _chunk263IZ6Z6js.coverageOf; exports.findCommand = _chunk263IZ6Z6js.findCommand; exports.loadToolSpec = _chunk263IZ6Z6js.loadToolSpec; exports.negotiateSchemaVersion = _chunk263IZ6Z6js.negotiateSchemaVersion; exports.registerSpecCommand = _chunk263IZ6Z6js.registerSpecCommand; exports.renderManifestJSON = _chunk263IZ6Z6js.renderManifestJSON; exports.toolSpecFromCommand = _chunk263IZ6Z6js.toolSpecFromCommand; exports.validateToolSpec = _chunk263IZ6Z6js.validateToolSpec;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hop-top/kit",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/hop-top/poly-kit.git",
|
|
@@ -165,6 +165,16 @@
|
|
|
165
165
|
"types": "./dist/toolspec.d.ts",
|
|
166
166
|
"require": "./dist/toolspec.js",
|
|
167
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"
|
|
168
178
|
}
|
|
169
179
|
},
|
|
170
180
|
"typesVersions": {
|
|
@@ -258,6 +268,12 @@
|
|
|
258
268
|
],
|
|
259
269
|
"toolspec": [
|
|
260
270
|
"./dist/toolspec.d.ts"
|
|
271
|
+
],
|
|
272
|
+
"completion-values": [
|
|
273
|
+
"./dist/completion-values.d.ts"
|
|
274
|
+
],
|
|
275
|
+
"compliance": [
|
|
276
|
+
"./dist/compliance.d.ts"
|
|
261
277
|
]
|
|
262
278
|
}
|
|
263
279
|
},
|
|
@@ -278,7 +294,7 @@
|
|
|
278
294
|
"@modelcontextprotocol/core": "2.3.1",
|
|
279
295
|
"@modelcontextprotocol/server": "2.3.1",
|
|
280
296
|
"better-sqlite3": "^12.11.1",
|
|
281
|
-
"commander": "
|
|
297
|
+
"commander": "15.0.0",
|
|
282
298
|
"csv-stringify": "^6.9.0",
|
|
283
299
|
"eta": "^4.6.0",
|
|
284
300
|
"hono": "^4.13.13",
|
|
@@ -308,7 +324,7 @@
|
|
|
308
324
|
},
|
|
309
325
|
"license": "MIT",
|
|
310
326
|
"scripts": {
|
|
311
|
-
"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 --format cjs --splitting --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",
|
|
312
328
|
"lint": "eslint src/",
|
|
313
329
|
"lint:fix": "eslint src/ --fix",
|
|
314
330
|
"typecheck": "tsc --noEmit -p tsconfig.json && tsc -p tsconfig.test.json",
|
package/src/alias.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
AliasStore, loadFrom, saveTo, findFirstNonFlag, Expander,
|
|
7
7
|
bridgeAliases, findCommand,
|
|
8
8
|
} from './alias';
|
|
9
|
-
import { Command } from 'commander';
|
|
9
|
+
import { Command, CommanderError } from 'commander';
|
|
10
10
|
|
|
11
11
|
let tmpDir: string;
|
|
12
12
|
|
|
@@ -421,3 +421,112 @@ describe('bridgeAliases', () => {
|
|
|
421
421
|
expect(deploy?.aliases()).toEqual([]);
|
|
422
422
|
});
|
|
423
423
|
});
|
|
424
|
+
|
|
425
|
+
// ── bridgeAliases proxy dispatch ────────────────────────────
|
|
426
|
+
|
|
427
|
+
describe('bridgeAliases proxy dispatch', () => {
|
|
428
|
+
type Seen = { pos?: string; size?: string; verbose?: boolean };
|
|
429
|
+
|
|
430
|
+
function setup(
|
|
431
|
+
action: (
|
|
432
|
+
pos: string | undefined, opts: { size?: string },
|
|
433
|
+
) => void | Promise<void>,
|
|
434
|
+
): Command {
|
|
435
|
+
const program = new Command('x')
|
|
436
|
+
.exitOverride()
|
|
437
|
+
.option('-v, --verbose')
|
|
438
|
+
.configureOutput({ writeErr: () => {}, writeOut: () => {} });
|
|
439
|
+
program
|
|
440
|
+
.command('react')
|
|
441
|
+
.command('components')
|
|
442
|
+
.option('--size <n>')
|
|
443
|
+
.argument('[pos]')
|
|
444
|
+
.action(action);
|
|
445
|
+
const store = new AliasStore('/dev/null');
|
|
446
|
+
store.set('comp', 'react components');
|
|
447
|
+
store.set('compsz', 'react components --size 9');
|
|
448
|
+
bridgeAliases(program, store);
|
|
449
|
+
return program;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const tick = () => new Promise(r => setTimeout(r, 5));
|
|
453
|
+
let unhandled: unknown[];
|
|
454
|
+
const onUnhandled = (e: unknown) => { unhandled.push(e); };
|
|
455
|
+
|
|
456
|
+
beforeEach(() => {
|
|
457
|
+
unhandled = [];
|
|
458
|
+
process.on('unhandledRejection', onUnhandled);
|
|
459
|
+
});
|
|
460
|
+
afterEach(() => {
|
|
461
|
+
process.off('unhandledRejection', onUnhandled);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it('parseAsync awaits an async target action', async () => {
|
|
465
|
+
let done = false;
|
|
466
|
+
const program = setup(async () => { await tick(); done = true; });
|
|
467
|
+
await program.parseAsync(['node', 'x', 'comp']);
|
|
468
|
+
expect(done).toBe(true);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('parseAsync rejects with the async target error', async () => {
|
|
472
|
+
const program = setup(async () => {
|
|
473
|
+
await tick();
|
|
474
|
+
throw new CommanderError(3, 'x.boom', 'boom');
|
|
475
|
+
});
|
|
476
|
+
const err = await program
|
|
477
|
+
.parseAsync(['node', 'x', 'comp'])
|
|
478
|
+
.catch((e: unknown) => e);
|
|
479
|
+
expect(err).toBeInstanceOf(CommanderError);
|
|
480
|
+
expect((err as CommanderError).exitCode).toBe(3);
|
|
481
|
+
await tick();
|
|
482
|
+
expect(unhandled).toEqual([]);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it('passes args and options through to the target', async () => {
|
|
486
|
+
let seen: Seen = {};
|
|
487
|
+
const program = setup((pos, o) => { seen = { pos, size: o.size }; });
|
|
488
|
+
await program.parseAsync(['node', 'x', 'comp', '--size', '3', 'p1']);
|
|
489
|
+
expect(seen).toEqual({ pos: 'p1', size: '3' });
|
|
490
|
+
|
|
491
|
+
await program.parseAsync(['node', 'x', 'compsz', 'p2']);
|
|
492
|
+
expect(seen).toEqual({ pos: 'p2', size: '9' });
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('keeps program-level options given around the alias', async () => {
|
|
496
|
+
let verbose: unknown;
|
|
497
|
+
const program = setup(() => { verbose = program.opts().verbose; });
|
|
498
|
+
await program.parseAsync(['node', 'x', '-v', 'comp']);
|
|
499
|
+
expect(verbose).toBe(true);
|
|
500
|
+
|
|
501
|
+
verbose = undefined;
|
|
502
|
+
await program.parseAsync(['node', 'x', 'comp', 'p1', '-v']);
|
|
503
|
+
expect(verbose).toBe(true);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it('sync parse runs a sync target and rethrows its errors', async () => {
|
|
507
|
+
let seen: string | undefined;
|
|
508
|
+
const ok = setup(pos => { seen = pos; });
|
|
509
|
+
ok.parse(['node', 'x', 'comp', 'p1']);
|
|
510
|
+
expect(seen).toBe('p1');
|
|
511
|
+
|
|
512
|
+
const bad = setup(() => { throw new Error('syncboom'); });
|
|
513
|
+
expect(() => bad.parse(['node', 'x', 'comp'])).toThrow('syncboom');
|
|
514
|
+
|
|
515
|
+
expect(() => ok.parse(['node', 'x', 'comp', '--bogus']))
|
|
516
|
+
.toThrow(CommanderError);
|
|
517
|
+
await tick();
|
|
518
|
+
expect(unhandled).toEqual([]);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it('unknown target still reports unknown command', async () => {
|
|
522
|
+
const program = new Command('x')
|
|
523
|
+
.exitOverride()
|
|
524
|
+
.configureOutput({ writeErr: () => {}, writeOut: () => {} });
|
|
525
|
+
program.command('real').action(() => {});
|
|
526
|
+
const store = new AliasStore('/dev/null');
|
|
527
|
+
store.set('nope', 'nonexistent');
|
|
528
|
+
bridgeAliases(program, store);
|
|
529
|
+
await expect(program.parseAsync(['node', 'x', 'nope']))
|
|
530
|
+
.rejects.toMatchObject({ code: 'commander.unknownCommand' });
|
|
531
|
+
});
|
|
532
|
+
});
|
package/src/alias.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as fs from 'fs';
|
|
|
9
9
|
import * as path from 'path';
|
|
10
10
|
import * as yaml from 'js-yaml';
|
|
11
11
|
import { Command } from 'commander';
|
|
12
|
+
import { registerRootAlias } from './completion';
|
|
12
13
|
|
|
13
14
|
export type AliasMap = Record<string, string>;
|
|
14
15
|
|
|
@@ -215,12 +216,25 @@ export function findCommand(
|
|
|
215
216
|
return cmd;
|
|
216
217
|
}
|
|
217
218
|
|
|
219
|
+
/** Commander internal used for subcommand dispatch (promise-or-value). */
|
|
220
|
+
type Dispatcher = {
|
|
221
|
+
_parseCommand(operands: string[], unknown: string[]): void | Promise<void>;
|
|
222
|
+
};
|
|
223
|
+
|
|
218
224
|
/**
|
|
219
225
|
* Register loaded aliases with Commander's native .alias() API.
|
|
220
226
|
*
|
|
221
227
|
* Simple single-command aliases use Commander's built-in .alias(),
|
|
222
228
|
* giving free completion and help display. Multi-word or unresolved
|
|
223
|
-
* targets get a hidden proxy command that
|
|
229
|
+
* targets get a hidden proxy command that dispatches the expanded
|
|
230
|
+
* args from the program, like a native subcommand.
|
|
231
|
+
*
|
|
232
|
+
* Dispatch reuses Commander's own subcommand dispatch rather than
|
|
233
|
+
* calling parse()/parseAsync() again: re-parsing resets program
|
|
234
|
+
* option values mid-parse and fixes the sync/async mode, whereas
|
|
235
|
+
* dispatch returns the target's result as-is. parseAsync() callers
|
|
236
|
+
* thus await async targets (rejections propagate), and parse()
|
|
237
|
+
* callers keep synchronous throws.
|
|
224
238
|
*/
|
|
225
239
|
export function bridgeAliases(
|
|
226
240
|
program: Command,
|
|
@@ -228,6 +242,7 @@ export function bridgeAliases(
|
|
|
228
242
|
): void {
|
|
229
243
|
const all = store.all();
|
|
230
244
|
for (const [name, target] of Object.entries(all)) {
|
|
245
|
+
registerRootAlias(program, name, target);
|
|
231
246
|
const parts = target.split(/\s+/);
|
|
232
247
|
// simple alias: single word target that exists as a direct subcommand
|
|
233
248
|
if (parts.length === 1) {
|
|
@@ -245,9 +260,9 @@ export function bridgeAliases(
|
|
|
245
260
|
.allowExcessArguments(true)
|
|
246
261
|
.action(function (this: Command) {
|
|
247
262
|
const expanded = target.split(/\s+/);
|
|
248
|
-
program.
|
|
249
|
-
|
|
250
|
-
|
|
263
|
+
return (program as unknown as Dispatcher)._parseCommand(
|
|
264
|
+
[], [...expanded, ...this.args],
|
|
265
|
+
);
|
|
251
266
|
});
|
|
252
267
|
proxy.helpOption(false);
|
|
253
268
|
(proxy as any)._hidden = true;
|
package/src/cli.ts
CHANGED
|
@@ -30,6 +30,7 @@ import { parity, type ParityData } from './tui/parity.js';
|
|
|
30
30
|
import { registerOutputFlags } from './output/flags.js';
|
|
31
31
|
import { EXIT_USAGE } from './output/error.js';
|
|
32
32
|
import { install as installNetPolicy, setProcessOffline } from './netpolicy.js';
|
|
33
|
+
import { installCompletionRequest } from './completion.js';
|
|
33
34
|
import './output/builtins.js';
|
|
34
35
|
export { ErrOffline, OfflineError, guardFetch, isOffline, isOfflineError,
|
|
35
36
|
withOffline } from './netpolicy.js';
|
|
@@ -881,6 +882,10 @@ export function createCLI(cfg: CLIConfig): CLIResult {
|
|
|
881
882
|
program.option(flag, g.usage, g.default ?? '');
|
|
882
883
|
}
|
|
883
884
|
|
|
885
|
+
// Shell completion scripts call back into `<name> __complete`; answer
|
|
886
|
+
// it ahead of commander's parse so no hook or action runs on tab.
|
|
887
|
+
installCompletionRequest(program);
|
|
888
|
+
|
|
884
889
|
// Apply brand color scheme + section order to --help output.
|
|
885
890
|
// noColor is read lazily at render time inside applyHelpTheme.
|
|
886
891
|
applyHelpTheme(program, theme, false, cfg.help?.sectionOrder,
|