@hop-top/kit 0.4.0-alpha.1

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 (174) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/LICENSE +25 -0
  3. package/README.md +189 -0
  4. package/dist/aim.d.ts +116 -0
  5. package/dist/aim.js +417 -0
  6. package/dist/alias.d.ts +73 -0
  7. package/dist/alias.js +207 -0
  8. package/dist/api.d.ts +62 -0
  9. package/dist/api.js +165 -0
  10. package/dist/auth.d.ts +26 -0
  11. package/dist/auth.js +41 -0
  12. package/dist/cli.d.ts +309 -0
  13. package/dist/cli.js +885 -0
  14. package/dist/config.d.ts +97 -0
  15. package/dist/config.js +79 -0
  16. package/dist/errcorrect.d.ts +37 -0
  17. package/dist/errcorrect.js +69 -0
  18. package/dist/llm.d.ts +188 -0
  19. package/dist/llm.js +356 -0
  20. package/dist/output.d.ts +213 -0
  21. package/dist/output.js +447 -0
  22. package/dist/progress.d.ts +30 -0
  23. package/dist/progress.js +56 -0
  24. package/dist/provenance.d.ts +24 -0
  25. package/dist/provenance.js +32 -0
  26. package/dist/routellm.d.ts +64 -0
  27. package/dist/routellm.js +258 -0
  28. package/dist/rpc.d.ts +25 -0
  29. package/dist/rpc.js +101 -0
  30. package/dist/safety.d.ts +24 -0
  31. package/dist/safety.js +44 -0
  32. package/dist/scope.d.ts +121 -0
  33. package/dist/scope.js +380 -0
  34. package/dist/sqlstore.d.ts +84 -0
  35. package/dist/sqlstore.js +85 -0
  36. package/dist/stream.d.ts +35 -0
  37. package/dist/stream.js +52 -0
  38. package/dist/tui/index.d.ts +300 -0
  39. package/dist/tui/index.js +332 -0
  40. package/dist/upgrade.d.ts +95 -0
  41. package/dist/upgrade.js +115 -0
  42. package/dist/xdg.d.ts +169 -0
  43. package/dist/xdg.js +129 -0
  44. package/eslint.config.mjs +17 -0
  45. package/package.json +133 -0
  46. package/src/README.md +3 -0
  47. package/src/aim.test.ts +331 -0
  48. package/src/aim.ts +388 -0
  49. package/src/alias.test.ts +423 -0
  50. package/src/alias.ts +256 -0
  51. package/src/api.test.ts +190 -0
  52. package/src/api.ts +214 -0
  53. package/src/auth.test.ts +24 -0
  54. package/src/auth.ts +37 -0
  55. package/src/bus.test.ts +178 -0
  56. package/src/bus.ts +114 -0
  57. package/src/cli.test.ts +690 -0
  58. package/src/cli.ts +741 -0
  59. package/src/completion-values.test.ts +202 -0
  60. package/src/completion-values.ts +173 -0
  61. package/src/completion.test.ts +212 -0
  62. package/src/completion.ts +158 -0
  63. package/src/compliance.test.ts +134 -0
  64. package/src/compliance.ts +669 -0
  65. package/src/config.test.ts +110 -0
  66. package/src/config.ts +164 -0
  67. package/src/errcorrect.test.ts +134 -0
  68. package/src/errcorrect.ts +84 -0
  69. package/src/flagregister.test.ts +103 -0
  70. package/src/flagregister.ts +78 -0
  71. package/src/gen/crud_connect.ts +76 -0
  72. package/src/gen/crud_pb.ts +269 -0
  73. package/src/hint.test.ts +315 -0
  74. package/src/hint.ts +178 -0
  75. package/src/llm.test.ts +612 -0
  76. package/src/llm.ts +577 -0
  77. package/src/log.test.ts +145 -0
  78. package/src/log.ts +155 -0
  79. package/src/output/builtins.ts +34 -0
  80. package/src/output/dispatch.ts +195 -0
  81. package/src/output/flags.ts +151 -0
  82. package/src/output/format_help.ts +80 -0
  83. package/src/output/formatter.ts +167 -0
  84. package/src/output/formatters/csv.ts +72 -0
  85. package/src/output/formatters/json.ts +44 -0
  86. package/src/output/formatters/table.ts +44 -0
  87. package/src/output/formatters/text.ts +109 -0
  88. package/src/output/formatters/yaml.ts +47 -0
  89. package/src/output/projection.ts +126 -0
  90. package/src/output/registry.ts +88 -0
  91. package/src/output/template.ts +63 -0
  92. package/src/output.test.ts +117 -0
  93. package/src/output.ts +90 -0
  94. package/src/progress.test.ts +93 -0
  95. package/src/progress.ts +58 -0
  96. package/src/provenance.test.ts +59 -0
  97. package/src/provenance.ts +26 -0
  98. package/src/routellm.test.ts +179 -0
  99. package/src/routellm.ts +365 -0
  100. package/src/router/bert.test.ts +180 -0
  101. package/src/router/bert.ts +145 -0
  102. package/src/router/controller.test.ts +183 -0
  103. package/src/router/controller.ts +165 -0
  104. package/src/router/integration.test.ts +309 -0
  105. package/src/router/intent.test.ts +187 -0
  106. package/src/router/intent.ts +208 -0
  107. package/src/router/mf.test.ts +66 -0
  108. package/src/router/mf.ts +52 -0
  109. package/src/router/random.test.ts +23 -0
  110. package/src/router/random.ts +13 -0
  111. package/src/router/router.test.ts +31 -0
  112. package/src/router/router.ts +62 -0
  113. package/src/router/server.test.ts +193 -0
  114. package/src/router/server.ts +134 -0
  115. package/src/router/sw.test.ts +199 -0
  116. package/src/router/sw.ts +232 -0
  117. package/src/rpc.test.ts +47 -0
  118. package/src/rpc.ts +91 -0
  119. package/src/safety.test.ts +53 -0
  120. package/src/safety.ts +42 -0
  121. package/src/scope-defaults.json +72 -0
  122. package/src/scope.test.ts +177 -0
  123. package/src/scope.ts +382 -0
  124. package/src/setflag.test.ts +110 -0
  125. package/src/setflag.ts +102 -0
  126. package/src/sqlstore.test.ts +110 -0
  127. package/src/sqlstore.ts +144 -0
  128. package/src/stream.test.ts +69 -0
  129. package/src/stream.ts +47 -0
  130. package/src/textflag.test.ts +105 -0
  131. package/src/textflag.ts +68 -0
  132. package/src/toolspec.test.ts +187 -0
  133. package/src/toolspec.ts +279 -0
  134. package/src/triton/client.test.ts +205 -0
  135. package/src/triton/client.ts +261 -0
  136. package/src/tui/anim.test.ts +146 -0
  137. package/src/tui/anim.ts +134 -0
  138. package/src/tui/badge.test.ts +41 -0
  139. package/src/tui/badge.ts +55 -0
  140. package/src/tui/confirm.test.ts +68 -0
  141. package/src/tui/confirm.ts +49 -0
  142. package/src/tui/index.ts +29 -0
  143. package/src/tui/list.test.ts +84 -0
  144. package/src/tui/list.ts +72 -0
  145. package/src/tui/parity.ts +41 -0
  146. package/src/tui/pills.test.ts +40 -0
  147. package/src/tui/pills.ts +43 -0
  148. package/src/tui/progress.test.ts +164 -0
  149. package/src/tui/progress.ts +120 -0
  150. package/src/tui/spinner.test.ts +111 -0
  151. package/src/tui/spinner.ts +96 -0
  152. package/src/tui/status.test.ts +68 -0
  153. package/src/tui/status.ts +66 -0
  154. package/src/upgrade.test.ts +298 -0
  155. package/src/upgrade.ts +205 -0
  156. package/src/uri.ts +199 -0
  157. package/src/wizard.test.ts +441 -0
  158. package/src/wizard.ts +662 -0
  159. package/src/xdg.test.ts +202 -0
  160. package/src/xdg.ts +280 -0
  161. package/test/output/cols.test.ts +148 -0
  162. package/test/output/csv.test.ts +129 -0
  163. package/test/output/dispatch.test.ts +194 -0
  164. package/test/output/format_help.test.ts +131 -0
  165. package/test/output/formatter.test.ts +137 -0
  166. package/test/output/output_flag.test.ts +124 -0
  167. package/test/output/registry.test.ts +127 -0
  168. package/test/output/smoke-capture.ts +83 -0
  169. package/test/output/smoke.test.ts +142 -0
  170. package/test/output/template.test.ts +95 -0
  171. package/test/output/text.test.ts +75 -0
  172. package/test/testdata/api-fixture.json +115 -0
  173. package/test/testdata/query-vectors.json +187 -0
  174. package/tsconfig.json +12 -0
@@ -0,0 +1,158 @@
1
+ /**
2
+ * @module completion
3
+ * @package @hop-top/kit
4
+ *
5
+ * Shell completion script generators for Commander-based CLIs.
6
+ * Extracts subcommand names and flag names from the program tree
7
+ * and generates bash/zsh/fish completion scripts.
8
+ */
9
+
10
+ import { Command } from 'commander';
11
+
12
+ /** Collect all visible subcommand names + aliases (non-hidden, excluding help). */
13
+ function collectCommands(cmd: Command): string[] {
14
+ return cmd.commands
15
+ .filter(c => !(c as any)._hidden && c.name() !== 'help')
16
+ .flatMap(c => [c.name(), ...c.aliases()]);
17
+ }
18
+
19
+ /** Collect all option long-names (e.g. --format, --quiet). */
20
+ function collectFlags(cmd: Command): string[] {
21
+ return cmd.options.map(o => o.long).filter(Boolean) as string[];
22
+ }
23
+
24
+ /** Generate a bash completion script for the given program. */
25
+ export function generateBashCompletion(program: Command): string {
26
+ const name = program.name();
27
+ const cmds = collectCommands(program);
28
+ const flags = collectFlags(program);
29
+ const words = [...cmds, ...flags].join(' ');
30
+
31
+ return `# bash completion for ${name}
32
+ # eval "$(${name} completion bash)"
33
+
34
+ _${name}_completions() {
35
+ local cur="\${COMP_WORDS[COMP_CWORD]}"
36
+ local commands="${words}"
37
+
38
+ COMPREPLY=( $(compgen -W "\${commands}" -- "\${cur}") )
39
+ }
40
+
41
+ complete -F _${name}_completions ${name}
42
+ `;
43
+ }
44
+
45
+ /** Generate a zsh completion script for the given program. */
46
+ export function generateZshCompletion(program: Command): string {
47
+ const name = program.name();
48
+ const cmds = collectCommands(program);
49
+ const flags = collectFlags(program);
50
+
51
+ const cmdEntries = cmds
52
+ .map(c => {
53
+ const sub = program.commands.find(
54
+ s => s.name() === c || s.aliases().includes(c),
55
+ );
56
+ const desc = sub?.description() ?? '';
57
+ return ` '${c}:${desc}'`;
58
+ })
59
+ .join('\n');
60
+
61
+ const flagEntries = flags
62
+ .map(f => ` '${f}[${f}]'`)
63
+ .join('\n');
64
+
65
+ return `#compdef ${name}
66
+ # eval "$(${name} completion zsh)"
67
+
68
+ _${name}() {
69
+ local -a commands flags
70
+
71
+ commands=(
72
+ ${cmdEntries}
73
+ )
74
+
75
+ flags=(
76
+ ${flagEntries}
77
+ )
78
+
79
+ _arguments -s \\
80
+ '1:command:->cmds' \\
81
+ '*::flags:->flags'
82
+
83
+ case "$state" in
84
+ cmds)
85
+ _describe -t commands 'commands' commands
86
+ ;;
87
+ flags)
88
+ _describe -t flags 'flags' flags
89
+ ;;
90
+ esac
91
+ }
92
+
93
+ compdef _${name} ${name}
94
+ `;
95
+ }
96
+
97
+ /** Generate a fish completion script for the given program. */
98
+ export function generateFishCompletion(program: Command): string {
99
+ const name = program.name();
100
+ const cmds = collectCommands(program);
101
+ const flags = collectFlags(program);
102
+
103
+ const lines = [
104
+ `# fish completion for ${name}`,
105
+ `# ${name} completion fish | source`,
106
+ '',
107
+ ];
108
+
109
+ for (const c of cmds) {
110
+ const sub = program.commands.find(
111
+ s => s.name() === c || s.aliases().includes(c),
112
+ );
113
+ const desc = sub?.description() ?? '';
114
+ lines.push(
115
+ `complete -c ${name} -n '__fish_use_subcommand' ` +
116
+ `-a '${c}' -d '${desc}'`
117
+ );
118
+ }
119
+
120
+ for (const f of flags) {
121
+ const long = f.replace(/^--/, '');
122
+ lines.push(
123
+ `complete -c ${name} -l '${long}'`
124
+ );
125
+ }
126
+
127
+ lines.push('');
128
+ return lines.join('\n');
129
+ }
130
+
131
+ /**
132
+ * Create a hidden `completion` command with bash/zsh/fish subcommands.
133
+ * Each prints the completion script to stdout.
134
+ */
135
+ export function completionCommand(program: Command): Command {
136
+ const cmd = new Command('completion')
137
+ .description('Generate shell completion scripts');
138
+
139
+ cmd.command('bash')
140
+ .description('Generate bash completion script')
141
+ .action(() => {
142
+ process.stdout.write(generateBashCompletion(program));
143
+ });
144
+
145
+ cmd.command('zsh')
146
+ .description('Generate zsh completion script')
147
+ .action(() => {
148
+ process.stdout.write(generateZshCompletion(program));
149
+ });
150
+
151
+ cmd.command('fish')
152
+ .description('Generate fish completion script')
153
+ .action(() => {
154
+ process.stdout.write(generateFishCompletion(program));
155
+ });
156
+
157
+ return cmd;
158
+ }
@@ -0,0 +1,134 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import * as path from "path";
3
+ import * as fs from "fs";
4
+ import * as os from "os";
5
+ import {
6
+ Factor,
7
+ factorName,
8
+ runStatic,
9
+ run,
10
+ formatReport,
11
+ type CheckResult,
12
+ } from "./compliance";
13
+
14
+ const TOOLSPEC = path.resolve(
15
+ __dirname,
16
+ "../../../examples/spaced/spaced.toolspec.yaml",
17
+ );
18
+
19
+ describe("compliance", () => {
20
+ describe("factorName", () => {
21
+ it("returns name for all 12 factors", () => {
22
+ for (
23
+ let f = Factor.SelfDescribing;
24
+ f <= Factor.AuthLifecycle;
25
+ f++
26
+ ) {
27
+ expect(factorName(f)).not.toBe("");
28
+ expect(factorName(f)).not.toMatch(/^Factor\(/);
29
+ }
30
+ });
31
+ });
32
+
33
+ describe("runStatic", () => {
34
+ it("checks spaced toolspec", () => {
35
+ const results = runStatic(TOOLSPEC);
36
+ expect(results.length).toBe(12);
37
+
38
+ const byFactor = new Map<number, CheckResult>();
39
+ for (const r of results) byFactor.set(r.factor, r);
40
+
41
+ // Passing factors
42
+ expect(byFactor.get(Factor.SelfDescribing)?.status)
43
+ .toBe("pass");
44
+ expect(byFactor.get(Factor.StructuredIO)?.status)
45
+ .toBe("pass");
46
+ expect(byFactor.get(Factor.ContractsErrors)?.status)
47
+ .toBe("pass");
48
+ expect(byFactor.get(Factor.Preview)?.status)
49
+ .toBe("pass");
50
+ expect(byFactor.get(Factor.Idempotency)?.status)
51
+ .toBe("pass");
52
+ expect(byFactor.get(Factor.StateTransparency)?.status)
53
+ .toBe("pass");
54
+ expect(byFactor.get(Factor.SafeDelegation)?.status)
55
+ .toBe("pass");
56
+ expect(byFactor.get(Factor.Evolution)?.status)
57
+ .toBe("pass");
58
+
59
+ // Runtime-only (skipped)
60
+ expect(byFactor.get(Factor.StreamDiscipline)?.status)
61
+ .toBe("skip");
62
+ expect(byFactor.get(Factor.ObservableOps)?.status)
63
+ .toBe("skip");
64
+ expect(byFactor.get(Factor.Provenance)?.status)
65
+ .toBe("skip");
66
+ });
67
+
68
+ it("fails on empty spec", () => {
69
+ const tmp = path.join(
70
+ os.tmpdir(),
71
+ `compliance-test-${Date.now()}.yaml`,
72
+ );
73
+ fs.writeFileSync(tmp, "name: empty\n");
74
+ try {
75
+ const results = runStatic(tmp);
76
+ const failing = results.filter(
77
+ (r) => r.status === "fail",
78
+ );
79
+ expect(failing.length).toBeGreaterThan(0);
80
+ } finally {
81
+ fs.unlinkSync(tmp);
82
+ }
83
+ });
84
+ });
85
+
86
+ describe("run", () => {
87
+ it("returns report with static-only", () => {
88
+ const report = run("", TOOLSPEC);
89
+ expect(report.total).toBe(12);
90
+ expect(report.score).toBeGreaterThanOrEqual(1);
91
+ expect(report.toolspec).toBe(TOOLSPEC);
92
+ });
93
+ });
94
+
95
+ describe("formatReport", () => {
96
+ const report = {
97
+ binary: "test-bin",
98
+ toolspec: "test.yaml",
99
+ total: 12,
100
+ score: 8,
101
+ results: [
102
+ {
103
+ factor: Factor.SelfDescribing,
104
+ name: "Self-Describing",
105
+ status: "pass" as const,
106
+ details: "ok",
107
+ },
108
+ {
109
+ factor: Factor.StructuredIO,
110
+ name: "Structured I/O",
111
+ status: "fail" as const,
112
+ details: "missing",
113
+ suggestion: "Add output_schema",
114
+ },
115
+ ],
116
+ };
117
+
118
+ it("renders text format", () => {
119
+ const out = formatReport(report, "text");
120
+ expect(out).toContain("Self-Describing");
121
+ expect(out).toContain("PASS");
122
+ expect(out).toContain("FAIL");
123
+ expect(out).toContain("8/12");
124
+ });
125
+
126
+ it("renders json format", () => {
127
+ const out = formatReport(report, "json");
128
+ const parsed = JSON.parse(out);
129
+ expect(parsed.score).toBe(8);
130
+ expect(parsed.total).toBe(12);
131
+ expect(parsed.results).toHaveLength(2);
132
+ });
133
+ });
134
+ });