@hop-top/kit 0.5.0-alpha.6 → 0.5.0-alpha.8

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE-cobra.txt +174 -0
  3. package/NOTICE +15 -0
  4. package/README.md +3 -3
  5. package/dist/alias-D9_qFlyP.d.ts +174 -0
  6. package/dist/alias.d.ts +1 -1
  7. package/dist/alias.js +10 -2
  8. package/dist/chunk-263IZ6Z6.js +915 -0
  9. package/dist/{chunk-S45UHXQF.js → chunk-BLS2OBIQ.js} +106 -25
  10. package/dist/{chunk-7FDIN5KE.js → chunk-GHPJJV5L.js} +8 -4
  11. package/dist/chunk-JKMQSAJP.js +174 -0
  12. package/dist/chunk-JZ22ZUFA.js +1131 -0
  13. package/dist/{chunk-GAZPYCQD.js → chunk-NLMS7HGP.js} +93 -35
  14. package/dist/chunk-QQQYCWSC.js +240 -0
  15. package/dist/chunk-XJTRY453.js +868 -0
  16. package/dist/cli.js +6 -4
  17. package/dist/completion-csVun6SP.d.ts +112 -0
  18. package/dist/completion-values-By-mnjNt.d.ts +142 -0
  19. package/dist/completion-values.d.ts +1 -0
  20. package/dist/completion-values.js +29 -0
  21. package/dist/completion.d.ts +2 -1
  22. package/dist/completion.js +23 -2
  23. package/dist/compliance-AxFf-uMy.d.ts +60 -0
  24. package/dist/compliance.d.ts +1 -0
  25. package/dist/compliance.js +17 -0
  26. package/dist/config-CaK60ByQ.d.ts +241 -0
  27. package/dist/config.d.ts +1 -1
  28. package/dist/config.js +4 -2
  29. package/dist/index.d.ts +7 -5
  30. package/dist/index.js +26 -18
  31. package/dist/log-CkaxMX3U.d.ts +115 -0
  32. package/dist/log.d.ts +1 -1
  33. package/dist/log.js +2 -2
  34. package/dist/toolspec-UrWnoJ3Y.d.ts +336 -0
  35. package/dist/toolspec.d.ts +2 -1
  36. package/dist/toolspec.js +27 -2
  37. package/package.json +19 -3
  38. package/src/alias.conformance.test.ts +250 -0
  39. package/src/alias.test.ts +206 -2
  40. package/src/alias.ts +196 -21
  41. package/src/cli.ts +5 -0
  42. package/src/completion-scripts.ts +16 -0
  43. package/src/completion-values.test.ts +70 -10
  44. package/src/completion-values.ts +170 -66
  45. package/src/completion.conformance.test.ts +297 -0
  46. package/src/completion.test.ts +256 -145
  47. package/src/completion.ts +767 -121
  48. package/src/config-merge.test.ts +425 -0
  49. package/src/config.test.ts +41 -0
  50. package/src/config.ts +265 -18
  51. package/src/index.test.ts +2 -1
  52. package/src/index.ts +5 -1
  53. package/src/log.test.ts +270 -1
  54. package/src/log.ts +172 -44
  55. package/src/published-types.test.ts +18 -0
  56. package/src/toolspec-internal.ts +197 -0
  57. package/src/toolspec-manifest.test.ts +82 -0
  58. package/src/toolspec-manifest.ts +404 -0
  59. package/src/toolspec-spec-schemas.ts +12 -0
  60. package/src/toolspec-spec.test.ts +273 -0
  61. package/src/toolspec-spec.ts +458 -0
  62. package/src/toolspec.from-command.test.ts +216 -0
  63. package/src/toolspec.ts +159 -0
  64. package/test/toolspec/fixture.ts +73 -0
  65. package/dist/alias-BOj0-VAr.d.ts +0 -88
  66. package/dist/chunk-6RFRV4VP.js +0 -128
  67. package/dist/chunk-IQXEISMC.js +0 -142
  68. package/dist/chunk-W7ERKNSQ.js +0 -171
  69. package/dist/completion-CVnPcWMZ.d.ts +0 -32
  70. package/dist/config-Bm9fBXch.d.ts +0 -134
  71. package/dist/log-uKjHsK-c.d.ts +0 -62
  72. package/dist/toolspec-DPBr18Ub.d.ts +0 -106
package/src/toolspec.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import * as fs from "fs";
2
2
  import * as yaml from "js-yaml";
3
+ import type {
4
+ Command as CommanderCommand,
5
+ Option as CommanderOption,
6
+ } from "commander";
3
7
 
4
8
  // --- Types ---
5
9
 
@@ -47,14 +51,31 @@ export interface Flag {
47
51
  short?: string;
48
52
  type?: string;
49
53
  description?: string;
54
+ /** Flag must be supplied (commander `makeOptionMandatory`). */
55
+ required?: boolean;
50
56
  deprecated?: boolean;
51
57
  replacedBy?: string;
52
58
  }
53
59
 
60
+ /** A declared positional argument (mirrors Go toolspec.Arg). */
61
+ export interface Arg {
62
+ name: string;
63
+ /** False/absent for an optional argument. */
64
+ required?: boolean;
65
+ }
66
+
54
67
  export interface Command {
55
68
  name: string;
69
+ /** One-line summary of the command. */
70
+ short?: string;
56
71
  aliases?: string[];
57
72
  flags?: Flag[];
73
+ /** Declared positional arguments, in order. */
74
+ args?: Arg[];
75
+ /** Command takes positional arguments it does not declare. */
76
+ undeclaredArgs?: boolean;
77
+ /** Exit-code symbols the command may produce (kit/exit-codes). */
78
+ exitCodes?: string[];
58
79
  children?: Command[];
59
80
  contract?: Contract;
60
81
  safety?: Safety;
@@ -103,11 +124,16 @@ function mapFlag(raw: any): Flag {
103
124
  short: raw.short,
104
125
  type: raw.type,
105
126
  description: raw.description,
127
+ required: raw.required,
106
128
  deprecated: raw.deprecated,
107
129
  replacedBy: raw.replaced_by,
108
130
  };
109
131
  }
110
132
 
133
+ function mapArg(raw: any): Arg {
134
+ return { name: raw.name ?? "", required: raw.required };
135
+ }
136
+
111
137
  function mapProvenance(raw: any): Provenance | undefined {
112
138
  if (!raw) return undefined;
113
139
  return {
@@ -157,8 +183,12 @@ function mapIntent(raw: any): Intent | undefined {
157
183
  function mapCommand(raw: any): Command {
158
184
  return {
159
185
  name: raw.name ?? "",
186
+ short: raw.short,
160
187
  aliases: raw.aliases,
161
188
  flags: raw.flags?.map(mapFlag),
189
+ args: raw.args?.map(mapArg),
190
+ undeclaredArgs: raw.undeclared_args,
191
+ exitCodes: raw.exit_codes,
162
192
  children: raw.children?.map(mapCommand),
163
193
  contract: mapContract(raw.contract),
164
194
  safety: mapSafety(raw.safety),
@@ -250,6 +280,9 @@ export function validateToolSpec(spec: ToolSpec): string[] {
250
280
  ` (must be safe|caution|dangerous)`,
251
281
  );
252
282
  }
283
+ if (cmd.exitCodes?.some((c) => typeof c !== "string" || c.trim() === "")) {
284
+ errors.push(`${path}: exit code symbols must be non-empty strings`);
285
+ }
253
286
  if (cmd.children) {
254
287
  for (const child of cmd.children) {
255
288
  validateCmd(child, `${path}/${child.name || "<unnamed>"}`);
@@ -277,3 +310,129 @@ export function findCommand(
277
310
  }
278
311
  return undefined;
279
312
  }
313
+
314
+ export * from "./toolspec-manifest.js";
315
+ export * from "./toolspec-spec.js";
316
+
317
+ // --- Build from a commander tree ---
318
+
319
+ /**
320
+ * Per-command fields merged over what the commander tree yields.
321
+ * Structural fields (name, aliases, flags, args, children) always
322
+ * come from the tree.
323
+ */
324
+ export type CommandAnnotation = Omit<
325
+ Partial<Command>,
326
+ "name" | "aliases" | "flags" | "args" | "children"
327
+ >;
328
+
329
+ export interface FromCommandOptions {
330
+ /** Annotations keyed by space-joined path below the root, e.g. "mission list". */
331
+ annotations?: Record<string, CommandAnnotation>;
332
+ /** Defaults to "1", the version the YAML toolspecs declare. */
333
+ schemaVersion?: string;
334
+ }
335
+
336
+ /**
337
+ * Build a ToolSpec from a constructed commander tree, so CLIs with
338
+ * dynamically registered subcommands need no hand-synced YAML.
339
+ * Mirrors Go's WalkCobra projection: hidden commands and options are
340
+ * omitted, flag names are undashed, root options become spec.flags.
341
+ */
342
+ export function toolSpecFromCommand(
343
+ program: CommanderCommand,
344
+ opts: FromCommandOptions = {},
345
+ ): ToolSpec {
346
+ const annotations = opts.annotations ?? {};
347
+ const spec: ToolSpec = {
348
+ name: program.name(),
349
+ schemaVersion: opts.schemaVersion ?? "1",
350
+ commands: projectChildren(program, [], annotations),
351
+ };
352
+ const flags = projectFlags(program);
353
+ if (flags) spec.flags = flags;
354
+ return spec;
355
+ }
356
+
357
+ function projectChildren(
358
+ cmd: CommanderCommand,
359
+ path: string[],
360
+ annotations: Record<string, CommandAnnotation>,
361
+ ): Command[] {
362
+ // visibleCommands drops hidden subcommands but appends commander's
363
+ // implicit help placeholder, which is not in cmd.commands.
364
+ const visible = cmd.createHelp().visibleCommands(cmd);
365
+ return visible
366
+ .filter((c) => cmd.commands.includes(c))
367
+ .filter((c) => kitAnnotations(c)["kit/spec-command"] !== "true")
368
+ .map((c) => projectCommand(c, [...path, c.name()], annotations));
369
+ }
370
+
371
+ function projectCommand(
372
+ cmd: CommanderCommand,
373
+ path: string[],
374
+ annotations: Record<string, CommandAnnotation>,
375
+ ): Command {
376
+ const out: Command = { name: cmd.name() };
377
+ const short = cmd.summary() || cmd.description();
378
+ if (short) out.short = short;
379
+ const aliases = cmd.aliases();
380
+ if (aliases.length > 0) out.aliases = [...aliases];
381
+ const flags = projectFlags(cmd);
382
+ if (flags) out.flags = flags;
383
+ const args = cmd.registeredArguments.map((a): Arg =>
384
+ a.required ? { name: a.name(), required: true } : { name: a.name() },
385
+ );
386
+ if (args.length > 0) out.args = args;
387
+ const exitCodes = splitCSV(kitAnnotations(cmd)["kit/exit-codes"]);
388
+ if (exitCodes) out.exitCodes = exitCodes;
389
+ const children = projectChildren(cmd, path, annotations);
390
+ if (children.length > 0) out.children = children;
391
+
392
+ const ann = annotations[path.join(" ")];
393
+ if (ann) {
394
+ for (const [k, v] of Object.entries(ann)) {
395
+ if (v !== undefined) (out as any)[k] = v;
396
+ }
397
+ }
398
+ return out;
399
+ }
400
+
401
+ /**
402
+ * kit/* annotations on a commander command. commander has no
403
+ * annotations concept; they ride an optional `annotations` property,
404
+ * the same convention the MCP bridge reads.
405
+ */
406
+ function kitAnnotations(cmd: CommanderCommand): Record<string, string> {
407
+ return (cmd as { annotations?: Record<string, string> }).annotations ?? {};
408
+ }
409
+
410
+ /** Comma-separated annotation value, trimmed, empties dropped. */
411
+ function splitCSV(s: string | undefined): string[] | undefined {
412
+ if (!s) return undefined;
413
+ const out = s.split(",").map((p) => p.trim()).filter((p) => p !== "");
414
+ return out.length > 0 ? out : undefined;
415
+ }
416
+
417
+ function projectFlags(cmd: CommanderCommand): Flag[] | undefined {
418
+ const out: Flag[] = [];
419
+ for (const opt of cmd.options as readonly CommanderOption[]) {
420
+ if (opt.hidden) continue;
421
+ const name = (opt.long ?? opt.short ?? "").replace(/^-+/, "");
422
+ if (!name) continue;
423
+ const flag: Flag = { name };
424
+ if (opt.long && opt.short) flag.short = opt.short.replace(/^-/, "");
425
+ flag.type = flagType(opt);
426
+ if (opt.description) flag.description = opt.description;
427
+ if (opt.mandatory) flag.required = true;
428
+ out.push(flag);
429
+ }
430
+ return out.length > 0 ? out : undefined;
431
+ }
432
+
433
+ /** pflag-style type names, matching the Go walker's output. */
434
+ function flagType(opt: CommanderOption): string {
435
+ if (opt.isBoolean()) return "bool";
436
+ if (opt.variadic) return "stringSlice";
437
+ return "string";
438
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Builds the shared cross-language toolspec fixture tree
3
+ * (sdk/tests/cross-lang/fixtures/toolspec-manifest.tree.json) as a
4
+ * commander program, mirroring the Go cobra builder in
5
+ * go/ai/toolspec/cli/manifest_crosslang_test.go.
6
+ */
7
+ import * as fs from "fs";
8
+ import * as path from "path";
9
+ import { Command, Option } from "commander";
10
+
11
+ export const FIXTURES = path.resolve(__dirname, "../../../tests/cross-lang/fixtures");
12
+ export const CONTRACTS = path.resolve(__dirname, "../../../../contracts");
13
+
14
+ interface TreeFlag {
15
+ name: string;
16
+ short?: string;
17
+ type: "bool" | "string" | "stringSlice";
18
+ default?: string | string[];
19
+ description?: string;
20
+ hidden?: boolean;
21
+ }
22
+
23
+ interface TreeCommand {
24
+ name: string;
25
+ short?: string;
26
+ long?: string;
27
+ hidden?: boolean;
28
+ run?: boolean;
29
+ annotations?: Record<string, string>;
30
+ flags?: TreeFlag[];
31
+ commands?: TreeCommand[];
32
+ }
33
+
34
+ export interface Tree {
35
+ tool: string;
36
+ version: string;
37
+ reserved: string[];
38
+ commands: TreeCommand[];
39
+ }
40
+
41
+ function addFixtureCommand(parent: Command, tc: TreeCommand): void {
42
+ const cmd = parent.command(tc.name, { hidden: tc.hidden ?? false });
43
+ if (tc.short && tc.long) cmd.summary(tc.short).description(tc.long);
44
+ else if (tc.short) cmd.description(tc.short);
45
+ if (tc.run) cmd.action(() => {});
46
+ if (tc.annotations) {
47
+ (cmd as Command & { annotations?: Record<string, string> }).annotations = {
48
+ ...tc.annotations,
49
+ };
50
+ }
51
+ for (const f of tc.flags ?? []) {
52
+ const short = f.short ? `-${f.short}, ` : "";
53
+ const arg =
54
+ f.type === "bool" ? "" : f.type === "string" ? " <value>" : " <values...>";
55
+ const opt = new Option(`${short}--${f.name}${arg}`, f.description);
56
+ if (f.default !== undefined) opt.default(f.default);
57
+ if (f.hidden) opt.hideHelp();
58
+ cmd.addOption(opt);
59
+ }
60
+ for (const child of tc.commands ?? []) addFixtureCommand(cmd, child);
61
+ }
62
+
63
+ /**
64
+ * The fixture program, with createCLI's `-v, --version` on the root.
65
+ */
66
+ export function fixtureProgram(): { program: Command; tree: Tree } {
67
+ const tree = JSON.parse(
68
+ fs.readFileSync(path.join(FIXTURES, "toolspec-manifest.tree.json"), "utf-8"),
69
+ ) as Tree;
70
+ const program = new Command(tree.tool).version(tree.version, "-v, --version");
71
+ for (const c of tree.commands) addFixtureCommand(program, c);
72
+ return { program, tree };
73
+ }
@@ -1,88 +0,0 @@
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
- /** Reject names that shadow builtins or contain whitespace. */
60
- validateName(name: string): void;
61
- }
62
- /** Walk the Commander program tree to find a command by space-delimited path. */
63
- declare function findCommand(program: Command, cmdPath: string): Command | undefined;
64
- /**
65
- * Register loaded aliases with Commander's native .alias() API.
66
- *
67
- * Simple single-command aliases use Commander's built-in .alias(),
68
- * giving free completion and help display. Multi-word or unresolved
69
- * targets get a hidden proxy command that re-parses with expanded args.
70
- */
71
- declare function bridgeAliases(program: Command, store: AliasStore): void;
72
-
73
- type alias_AliasMap = AliasMap;
74
- type alias_AliasStore = AliasStore;
75
- declare const alias_AliasStore: typeof AliasStore;
76
- type alias_Expander = Expander;
77
- declare const alias_Expander: typeof Expander;
78
- type alias_ExpanderConfig = ExpanderConfig;
79
- declare const alias_bridgeAliases: typeof bridgeAliases;
80
- declare const alias_findCommand: typeof findCommand;
81
- declare const alias_findFirstNonFlag: typeof findFirstNonFlag;
82
- declare const alias_loadFrom: typeof loadFrom;
83
- declare const alias_saveTo: typeof saveTo;
84
- declare namespace alias {
85
- export { type alias_AliasMap as AliasMap, alias_AliasStore as AliasStore, alias_Expander as Expander, type alias_ExpanderConfig as ExpanderConfig, alias_bridgeAliases as bridgeAliases, alias_findCommand as findCommand, alias_findFirstNonFlag as findFirstNonFlag, alias_loadFrom as loadFrom, alias_saveTo as saveTo };
86
- }
87
-
88
- export { type AliasMap as A, Expander as E, alias as a, AliasStore as b, type ExpanderConfig as c, bridgeAliases as d, findFirstNonFlag as e, findCommand as f, loadFrom as l, saveTo as s };
@@ -1,128 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
4
-
5
- // src/completion.ts
6
- var completion_exports = {};
7
- _chunkR5U7XKVJjs.__export.call(void 0, completion_exports, {
8
- completionCommand: () => completionCommand,
9
- generateBashCompletion: () => generateBashCompletion,
10
- generateFishCompletion: () => generateFishCompletion,
11
- generateZshCompletion: () => generateZshCompletion
12
- });
13
- var _commander = require('commander');
14
- function collectCommands(cmd) {
15
- return cmd.commands.filter((c) => !c._hidden && c.name() !== "help").flatMap((c) => [c.name(), ...c.aliases()]);
16
- }
17
- function collectFlags(cmd) {
18
- return cmd.options.map((o) => o.long).filter(Boolean);
19
- }
20
- function generateBashCompletion(program) {
21
- const name = program.name();
22
- const cmds = collectCommands(program);
23
- const flags = collectFlags(program);
24
- const words = [...cmds, ...flags].join(" ");
25
- return `# bash completion for ${name}
26
- # eval "$(${name} completion bash)"
27
-
28
- _${name}_completions() {
29
- local cur="\${COMP_WORDS[COMP_CWORD]}"
30
- local commands="${words}"
31
-
32
- COMPREPLY=( $(compgen -W "\${commands}" -- "\${cur}") )
33
- }
34
-
35
- complete -F _${name}_completions ${name}
36
- `;
37
- }
38
- function generateZshCompletion(program) {
39
- const name = program.name();
40
- const cmds = collectCommands(program);
41
- const flags = collectFlags(program);
42
- const cmdEntries = cmds.map((c) => {
43
- const sub = program.commands.find(
44
- (s) => s.name() === c || s.aliases().includes(c)
45
- );
46
- const desc = _nullishCoalesce(_optionalChain([sub, 'optionalAccess', _ => _.description, 'call', _2 => _2()]), () => ( ""));
47
- return ` '${c}:${desc}'`;
48
- }).join("\n");
49
- const flagEntries = flags.map((f) => ` '${f}[${f}]'`).join("\n");
50
- return `#compdef ${name}
51
- # eval "$(${name} completion zsh)"
52
-
53
- _${name}() {
54
- local -a commands flags
55
-
56
- commands=(
57
- ${cmdEntries}
58
- )
59
-
60
- flags=(
61
- ${flagEntries}
62
- )
63
-
64
- _arguments -s \\
65
- '1:command:->cmds' \\
66
- '*::flags:->flags'
67
-
68
- case "$state" in
69
- cmds)
70
- _describe -t commands 'commands' commands
71
- ;;
72
- flags)
73
- _describe -t flags 'flags' flags
74
- ;;
75
- esac
76
- }
77
-
78
- compdef _${name} ${name}
79
- `;
80
- }
81
- function generateFishCompletion(program) {
82
- const name = program.name();
83
- const cmds = collectCommands(program);
84
- const flags = collectFlags(program);
85
- const lines = [
86
- `# fish completion for ${name}`,
87
- `# ${name} completion fish | source`,
88
- ""
89
- ];
90
- for (const c of cmds) {
91
- const sub = program.commands.find(
92
- (s) => s.name() === c || s.aliases().includes(c)
93
- );
94
- const desc = _nullishCoalesce(_optionalChain([sub, 'optionalAccess', _3 => _3.description, 'call', _4 => _4()]), () => ( ""));
95
- lines.push(
96
- `complete -c ${name} -n '__fish_use_subcommand' -a '${c}' -d '${desc}'`
97
- );
98
- }
99
- for (const f of flags) {
100
- const long = f.replace(/^--/, "");
101
- lines.push(
102
- `complete -c ${name} -l '${long}'`
103
- );
104
- }
105
- lines.push("");
106
- return lines.join("\n");
107
- }
108
- function completionCommand(program) {
109
- const cmd = new (0, _commander.Command)("completion").description("Generate shell completion scripts");
110
- cmd.command("bash").description("Generate bash completion script").action(() => {
111
- process.stdout.write(generateBashCompletion(program));
112
- });
113
- cmd.command("zsh").description("Generate zsh completion script").action(() => {
114
- process.stdout.write(generateZshCompletion(program));
115
- });
116
- cmd.command("fish").description("Generate fish completion script").action(() => {
117
- process.stdout.write(generateFishCompletion(program));
118
- });
119
- return cmd;
120
- }
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
- exports.generateBashCompletion = generateBashCompletion; exports.generateZshCompletion = generateZshCompletion; exports.generateFishCompletion = generateFishCompletion; exports.completionCommand = completionCommand; exports.completion_exports = completion_exports;
@@ -1,142 +0,0 @@
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; } }
2
-
3
- var _chunkR5U7XKVJjs = require('./chunk-R5U7XKVJ.js');
4
-
5
- // src/config.ts
6
- var config_exports = {};
7
- _chunkR5U7XKVJjs.__export.call(void 0, config_exports, {
8
- load: () => load2
9
- });
10
- var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
11
- var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml);
12
- function load2(dst, opts = {}) {
13
- const paths = [
14
- opts.systemConfigPath,
15
- opts.userConfigPath,
16
- opts.projectConfigPath
17
- ];
18
- for (const p of paths) {
19
- if (!p) continue;
20
- mergeFile(dst, p);
21
- }
22
- if (opts.envOverride) {
23
- opts.envOverride(dst);
24
- }
25
- return dst;
26
- }
27
- function mergeFile(dst, filePath) {
28
- let raw;
29
- try {
30
- raw = fs.readFileSync(filePath, "utf8");
31
- } catch (err) {
32
- if (isEnoent(err)) return;
33
- throw err;
34
- }
35
- let parsed;
36
- try {
37
- parsed = yaml.load(raw);
38
- checkBounds(parsed);
39
- } catch (err) {
40
- throw new Error(
41
- `config: failed to parse ${filePath}: ${err instanceof Error ? err.message : String(err)}`
42
- );
43
- }
44
- if (isPlainObject(parsed)) {
45
- mergeInto(dst, parsed);
46
- }
47
- }
48
- var MAX_DEPTH = 100;
49
- var ALIAS_MIN_ALIASES = 100;
50
- var ALIAS_MIN_DECODED = 1e3;
51
- var ALIAS_RATIO_LOW = 4e5;
52
- var ALIAS_RATIO_HIGH = 4e6;
53
- function allowedAliasRatio(decoded) {
54
- if (decoded <= ALIAS_RATIO_LOW) return 0.99;
55
- if (decoded >= ALIAS_RATIO_HIGH) return 0.1;
56
- return 0.99 - 0.89 * ((decoded - ALIAS_RATIO_LOW) / (ALIAS_RATIO_HIGH - ALIAS_RATIO_LOW));
57
- }
58
- function checkBounds(root) {
59
- const seen = /* @__PURE__ */ new WeakSet();
60
- const stack = [[root, 1, false]];
61
- let decoded = 0;
62
- let aliased = 0;
63
- while (stack.length > 0) {
64
- const [node, depth, inAlias] = stack.pop();
65
- let alias = inAlias;
66
- const container = Array.isArray(node) || isPlainObject(node);
67
- if (container) {
68
- if (seen.has(node)) {
69
- decoded++;
70
- alias = true;
71
- } else {
72
- seen.add(node);
73
- }
74
- }
75
- decoded++;
76
- if (alias) aliased++;
77
- if (aliased > ALIAS_MIN_ALIASES && decoded > ALIAS_MIN_DECODED && aliased / decoded > allowedAliasRatio(decoded)) {
78
- throw new Error("document contains excessive aliasing");
79
- }
80
- if (!container) continue;
81
- if (depth > MAX_DEPTH) {
82
- throw new Error(`nesting exceeded maxDepth (${MAX_DEPTH})`);
83
- }
84
- if (Array.isArray(node)) {
85
- for (let i = node.length - 1; i >= 0; i--) stack.push([node[i], depth + 1, alias]);
86
- } else {
87
- const keys = Object.keys(node);
88
- for (let i = keys.length - 1; i >= 0; i--) {
89
- decoded++;
90
- if (alias) aliased++;
91
- stack.push([node[keys[i]], depth + 1, alias]);
92
- }
93
- }
94
- }
95
- }
96
- function mergeInto(dst, src) {
97
- for (const key of Object.keys(src)) {
98
- const next = src[key];
99
- const has = Object.prototype.hasOwnProperty.call(dst, key);
100
- const cur = has ? dst[key] : void 0;
101
- if (next === null) {
102
- if (has && cur !== null && cur !== void 0 && typeof cur !== "object") {
103
- continue;
104
- }
105
- setOwn(dst, key, null);
106
- } else if (isPlainObject(next) && isPlainObject(cur)) {
107
- mergeInto(cur, next);
108
- } else {
109
- setOwn(dst, key, copy(next));
110
- }
111
- }
112
- }
113
- function setOwn(dst, key, value) {
114
- Object.defineProperty(dst, key, {
115
- value,
116
- writable: true,
117
- enumerable: true,
118
- configurable: true
119
- });
120
- }
121
- function copy(v) {
122
- if (Array.isArray(v)) return v.map(copy);
123
- if (isPlainObject(v)) {
124
- const out = {};
125
- for (const k of Object.keys(v)) setOwn(out, k, copy(v[k]));
126
- return out;
127
- }
128
- return v;
129
- }
130
- function isPlainObject(v) {
131
- if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
132
- const proto = Object.getPrototypeOf(v);
133
- return proto === Object.prototype || proto === null;
134
- }
135
- function isEnoent(err) {
136
- return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
137
- }
138
-
139
-
140
-
141
-
142
- exports.load = load2; exports.config_exports = config_exports;