@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.2

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 (101) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +237 -9
  3. package/dist/aim-CTp-kJW2.d.ts +139 -0
  4. package/dist/aim.d.ts +1 -116
  5. package/dist/alias-dhhr08Ei.d.ts +88 -0
  6. package/dist/alias.d.ts +2 -73
  7. package/dist/api-miiso81x.d.ts +77 -0
  8. package/dist/api.d.ts +1 -62
  9. package/dist/auth-2-jfgiHn.d.ts +34 -0
  10. package/dist/auth.d.ts +1 -26
  11. package/dist/cli-DgOEOsPB.d.ts +450 -0
  12. package/dist/cli.d.ts +5 -309
  13. package/dist/cli.js +190 -62
  14. package/dist/config-BUY7_W2n.d.ts +103 -0
  15. package/dist/config.d.ts +1 -97
  16. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  17. package/dist/errcorrect.d.ts +1 -37
  18. package/dist/id/index.d.ts +2 -83
  19. package/dist/index--C7Mtsmm.d.ts +328 -0
  20. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  21. package/dist/index-MLrRDvEG.d.ts +1073 -0
  22. package/dist/index-QSffbLnj.d.ts +94 -0
  23. package/dist/index.d.ts +26 -0
  24. package/dist/index.js +5863 -0
  25. package/dist/llm-B5XUWH8T.d.ts +231 -0
  26. package/dist/llm.d.ts +1 -188
  27. package/dist/mcp/index.d.ts +2 -0
  28. package/dist/mcp/index.js +1453 -0
  29. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  30. package/dist/netpolicy.d.ts +1 -0
  31. package/dist/netpolicy.js +118 -0
  32. package/dist/output-VFFLqor9.d.ts +521 -0
  33. package/dist/output.d.ts +2 -213
  34. package/dist/output.js +554 -43
  35. package/dist/progress-CAzyxeWl.d.ts +38 -0
  36. package/dist/progress.d.ts +1 -30
  37. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  38. package/dist/provenance.d.ts +1 -24
  39. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  40. package/dist/routellm.d.ts +2 -64
  41. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  42. package/dist/rpc.d.ts +2 -25
  43. package/dist/safety-CUaYEjZc.d.ts +30 -0
  44. package/dist/safety.d.ts +1 -24
  45. package/dist/scope-BrhYB4ij.d.ts +141 -0
  46. package/dist/scope.d.ts +1 -121
  47. package/dist/stream-CrjeCp0M.d.ts +44 -0
  48. package/dist/stream.d.ts +1 -35
  49. package/dist/telemetry/index.d.ts +1 -315
  50. package/dist/telemetry/index.js +12 -1
  51. package/dist/tui/index.d.ts +4 -298
  52. package/dist/tui/index.js +1 -9
  53. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  54. package/dist/upgrade.d.ts +1 -95
  55. package/dist/xdg-DB7Shoib.d.ts +179 -0
  56. package/dist/xdg.d.ts +1 -169
  57. package/package.json +21 -3
  58. package/src/cli.offline.test.ts +93 -0
  59. package/src/cli.parity.test.ts +192 -0
  60. package/src/cli.ts +112 -12
  61. package/src/index.test.ts +58 -0
  62. package/src/index.ts +36 -0
  63. package/src/log.parity.test.ts +105 -0
  64. package/src/log.ts +64 -13
  65. package/src/mcp/bridge.test.ts +150 -0
  66. package/src/mcp/bridge.ts +246 -0
  67. package/src/mcp/conformance.test.ts +336 -0
  68. package/src/mcp/dispatch.ts +313 -0
  69. package/src/mcp/index.ts +138 -0
  70. package/src/mcp/legacy.ts +314 -0
  71. package/src/mcp/mcp.test.ts +697 -0
  72. package/src/mcp/modern-confirm.test.ts +520 -0
  73. package/src/mcp/modern-confirm.ts +452 -0
  74. package/src/mcp/modern.ts +723 -0
  75. package/src/mcp/tasks.ts +82 -0
  76. package/src/mcp/testtree.ts +250 -0
  77. package/src/mcp/types.ts +504 -0
  78. package/src/netpolicy.test.ts +202 -0
  79. package/src/netpolicy.ts +231 -0
  80. package/src/output/dispatch.ts +10 -2
  81. package/src/output/error.ts +293 -0
  82. package/src/output/formatter.ts +29 -5
  83. package/src/output/formatters/csv.ts +48 -12
  84. package/src/output/formatters/json.ts +4 -25
  85. package/src/output/formatters/project.ts +34 -0
  86. package/src/output/formatters/table.ts +8 -6
  87. package/src/output/formatters/text.ts +7 -3
  88. package/src/output/formatters/yaml.ts +5 -22
  89. package/src/output/projection.test.ts +298 -0
  90. package/src/output/projection.ts +33 -59
  91. package/src/output/template.ts +11 -21
  92. package/src/output.surface.test.ts +41 -0
  93. package/src/output.ts +39 -3
  94. package/src/telemetry/client.test.ts +31 -0
  95. package/src/telemetry/client.ts +7 -1
  96. package/src/telemetry/offline.test.ts +64 -0
  97. package/src/tui/parity.test.ts +120 -31
  98. package/src/tui/parity.ts +58 -7
  99. package/test/output/csv.test.ts +164 -0
  100. package/test/output/error.test.ts +241 -0
  101. package/src/tui/parity.json +0 -74
@@ -0,0 +1,241 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as yaml from 'js-yaml';
3
+ import {
4
+ CODE_CONFLICT,
5
+ CODE_GENERIC,
6
+ CODE_NOT_FOUND,
7
+ CODE_PROVENANCE_MISSING,
8
+ CODE_RATE_LIMITED,
9
+ CODE_TRANSIENT,
10
+ CODE_UNAUTHORIZED,
11
+ CODE_USAGE,
12
+ EXIT_PROVENANCE_MISSING,
13
+ EXIT_RATE_LIMITED,
14
+ EXIT_TRANSIENT,
15
+ TRANSIENCE_PERMANENT,
16
+ TRANSIENCE_TRANSIENT,
17
+ TRANSIENCE_UNKNOWN,
18
+ conflictError,
19
+ notFoundError,
20
+ provenanceMissingError,
21
+ rateLimitedError,
22
+ renderError,
23
+ transienceForCode,
24
+ transientError,
25
+ unauthorizedError,
26
+ unwrapError,
27
+ usageError,
28
+ withTransience,
29
+ wrapError,
30
+ } from '../../src/output/error';
31
+ import type { CliError } from '../../src/output/error';
32
+
33
+ /** Collects renderError output into a string. */
34
+ function capture(): { write(chunk: string): void; text(): string } {
35
+ let buf = '';
36
+ return {
37
+ write(chunk: string) {
38
+ buf += chunk;
39
+ },
40
+ text: () => buf,
41
+ };
42
+ }
43
+
44
+ describe('constructors — code/exit/transience', () => {
45
+ const cases: Array<[string, CliError, string, number, string]> = [
46
+ ['NotFound', notFoundError('nope'), CODE_NOT_FOUND, 3, TRANSIENCE_PERMANENT],
47
+ ['Conflict', conflictError('dup'), CODE_CONFLICT, 4, TRANSIENCE_PERMANENT],
48
+ [
49
+ 'Unauthorized',
50
+ unauthorizedError('nope'),
51
+ CODE_UNAUTHORIZED,
52
+ 5,
53
+ TRANSIENCE_PERMANENT,
54
+ ],
55
+ ['Usage', usageError('bad flag'), CODE_USAGE, 2, TRANSIENCE_PERMANENT],
56
+ [
57
+ 'RateLimited',
58
+ rateLimitedError('budget'),
59
+ CODE_RATE_LIMITED,
60
+ 64,
61
+ TRANSIENCE_TRANSIENT,
62
+ ],
63
+ [
64
+ 'Transient',
65
+ transientError('upstream timeout'),
66
+ CODE_TRANSIENT,
67
+ 6,
68
+ TRANSIENCE_TRANSIENT,
69
+ ],
70
+ [
71
+ 'ProvenanceMissing',
72
+ provenanceMissingError('/email'),
73
+ CODE_PROVENANCE_MISSING,
74
+ 65,
75
+ TRANSIENCE_PERMANENT,
76
+ ],
77
+ ];
78
+ it.each(cases)('%s', (_name, got, wantCode, wantExit, wantTransience) => {
79
+ expect(got.code).toBe(wantCode);
80
+ expect(got.exit_code).toBe(wantExit);
81
+ expect(got.transience).toBe(wantTransience);
82
+ });
83
+
84
+ it('exit-code table is unique, 6 transient / 65 provenance', () => {
85
+ const exits = new Map(cases.map(([, e]) => [e.exit_code, e.code]));
86
+ expect(exits.size).toBe(7);
87
+ expect(EXIT_TRANSIENT).toBe(6);
88
+ expect(EXIT_RATE_LIMITED).toBe(64);
89
+ expect(EXIT_PROVENANCE_MISSING).toBe(65);
90
+ expect(exits.get(6)).toBe(CODE_TRANSIENT);
91
+ expect(exits.get(65)).toBe(CODE_PROVENANCE_MISSING);
92
+ });
93
+ });
94
+
95
+ describe('transienceForCode', () => {
96
+ it.each([
97
+ [CODE_USAGE, TRANSIENCE_PERMANENT],
98
+ [CODE_NOT_FOUND, TRANSIENCE_PERMANENT],
99
+ [CODE_CONFLICT, TRANSIENCE_PERMANENT],
100
+ [CODE_UNAUTHORIZED, TRANSIENCE_PERMANENT],
101
+ [CODE_PROVENANCE_MISSING, TRANSIENCE_PERMANENT],
102
+ [CODE_RATE_LIMITED, TRANSIENCE_TRANSIENT],
103
+ [CODE_TRANSIENT, TRANSIENCE_TRANSIENT],
104
+ [CODE_GENERIC, TRANSIENCE_UNKNOWN],
105
+ ['ADOPTER_SPECIFIC', TRANSIENCE_UNKNOWN],
106
+ ['', TRANSIENCE_UNKNOWN],
107
+ ])('%s -> %s', (code, want) => {
108
+ expect(transienceForCode(code)).toBe(want);
109
+ });
110
+ });
111
+
112
+ describe('wrapError', () => {
113
+ it('defaults transience from code', () => {
114
+ const base = new Error('boom');
115
+ expect(wrapError(base, CODE_CONFLICT, 4)?.transience).toBe(
116
+ TRANSIENCE_PERMANENT,
117
+ );
118
+ expect(wrapError(base, CODE_RATE_LIMITED, 64)?.transience).toBe(
119
+ TRANSIENCE_TRANSIENT,
120
+ );
121
+ expect(wrapError(base, CODE_GENERIC, 1)?.transience).toBe(
122
+ TRANSIENCE_UNKNOWN,
123
+ );
124
+ });
125
+
126
+ it('retains the source error and passes null through', () => {
127
+ const base = new Error('boom');
128
+ const e = wrapError(base, CODE_CONFLICT, 4);
129
+ expect(e?.message).toBe('boom');
130
+ expect(unwrapError(e as CliError)).toBe(base);
131
+ expect(wrapError(null, CODE_GENERIC, 1)).toBeNull();
132
+ });
133
+ });
134
+
135
+ describe('withTransience', () => {
136
+ it('copies and sets, never mutates the shared envelope', () => {
137
+ const orig: CliError = { code: 'SHARED', message: 'm', exit_code: 9 };
138
+ const got = withTransience(orig, TRANSIENCE_TRANSIENT);
139
+ expect(got).not.toBe(orig);
140
+ expect(got.transience).toBe(TRANSIENCE_TRANSIENT);
141
+ expect(orig.transience).toBeUndefined();
142
+ expect(got.code).toBe(orig.code);
143
+ expect(got.message).toBe(orig.message);
144
+ expect(got.exit_code).toBe(orig.exit_code);
145
+ });
146
+
147
+ it('carries the retained source error to the copy', () => {
148
+ const base = new Error('boom');
149
+ const e = wrapError(base, CODE_GENERIC, 1) as CliError;
150
+ expect(unwrapError(withTransience(e, TRANSIENCE_PERMANENT))).toBe(base);
151
+ });
152
+ });
153
+
154
+ describe('renderError — structured always carries transience', () => {
155
+ it('normalizes unset transience to unknown in JSON', () => {
156
+ const w = capture();
157
+ renderError(w, 'json', { code: 'ADOPTER_SPECIFIC', message: 'm', exit_code: 9 });
158
+ expect(JSON.parse(w.text()).transience).toBe(TRANSIENCE_UNKNOWN);
159
+ });
160
+
161
+ it('normalizes unset transience to unknown in YAML', () => {
162
+ const w = capture();
163
+ renderError(w, 'yaml', { code: 'ADOPTER_SPECIFIC', message: 'm', exit_code: 9 });
164
+ expect(w.text()).toContain('transience: unknown');
165
+ });
166
+
167
+ it('renders an explicit class untouched', () => {
168
+ const w = capture();
169
+ renderError(w, 'json', rateLimitedError('budget'));
170
+ expect(JSON.parse(w.text()).transience).toBe(TRANSIENCE_TRANSIENT);
171
+ });
172
+
173
+ it('does not mutate the input envelope', () => {
174
+ const e: CliError = { code: 'ADOPTER_SPECIFIC', message: 'm', exit_code: 9 };
175
+ renderError(capture(), 'json', e);
176
+ expect(e.transience).toBeUndefined();
177
+ });
178
+ });
179
+
180
+ describe('renderError — wire round-trip', () => {
181
+ it('JSON: full envelope, empty optionals off the wire', () => {
182
+ let w = capture();
183
+ renderError(w, 'json', provenanceMissingError('/email'));
184
+ const full = JSON.parse(w.text());
185
+ expect(full.code).toBe(CODE_PROVENANCE_MISSING);
186
+ expect(full.cause).toBe('/email');
187
+ expect(full.exit_code).toBe(65);
188
+ expect(full.transience).toBe(TRANSIENCE_PERMANENT);
189
+
190
+ w = capture();
191
+ renderError(w, 'json', transientError('upstream timeout'));
192
+ const bare = JSON.parse(w.text());
193
+ expect(Object.keys(bare).sort()).toEqual([
194
+ 'code',
195
+ 'exit_code',
196
+ 'message',
197
+ 'transience',
198
+ ]);
199
+ expect(bare.exit_code).toBe(6);
200
+ });
201
+
202
+ it('YAML: parses back to the wire shape', () => {
203
+ const w = capture();
204
+ renderError(w, 'yaml', transientError('upstream timeout'));
205
+ expect(yaml.load(w.text())).toEqual({
206
+ code: CODE_TRANSIENT,
207
+ message: 'upstream timeout',
208
+ exit_code: 6,
209
+ transience: TRANSIENCE_TRANSIENT,
210
+ });
211
+ });
212
+ });
213
+
214
+ describe('renderError — plain text + null', () => {
215
+ it('renders each populated field on its own line', () => {
216
+ const w = capture();
217
+ renderError(w, 'table', {
218
+ code: 'NOT_FOUND',
219
+ message: 'missing thing',
220
+ cause: 'root',
221
+ suggested_fix: 'try --all',
222
+ alternatives: ['other'],
223
+ exit_code: 3,
224
+ });
225
+ expect(w.text()).toBe(
226
+ 'NOT_FOUND: missing thing\nCause: root\nFix: try --all\nAlternative: other\n',
227
+ );
228
+ });
229
+
230
+ it('renders bare message without code prefix', () => {
231
+ const w = capture();
232
+ renderError(w, '', { code: '', message: 'just text', exit_code: 1 });
233
+ expect(w.text()).toBe('just text\n');
234
+ });
235
+
236
+ it('null renders nothing', () => {
237
+ const w = capture();
238
+ renderError(w, 'json', null);
239
+ expect(w.text()).toBe('');
240
+ });
241
+ });
@@ -1,74 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://hop.top/kit/go/console/tui/parity.json",
4
- "description": "Cross-language TUI parity constants. All language implementations MUST load values from here.",
5
-
6
- "status": {
7
- "description": "Prefix symbols for status lines. Mirrors Go's InfoType constants in tui/status.go.",
8
- "symbols": {
9
- "info": "ℹ",
10
- "success": "✓",
11
- "error": "●",
12
- "warn": "▲"
13
- }
14
- },
15
-
16
- "spinner": {
17
- "description": "Braille dot spinner frames and timing.",
18
- "frames": ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
19
- "interval_ms": 80
20
- },
21
-
22
- "anim": {
23
- "description": "Gradient character-scramble animation constants.",
24
- "runes": "0123456789abcdefABCDEF~!@#$%^&*()+=_",
25
- "interval_ms": 100,
26
- "default_width": 10
27
- },
28
-
29
- "help": {
30
- "description": "Root --help layout contract. Fang is canonical; TS and Python mirror it.",
31
- "section_order": ["commands", "flags"],
32
- "sections": {
33
- "usage": { "title": "USAGE" },
34
- "commands": { "title": "COMMANDS" },
35
- "flags": { "title": "FLAGS" },
36
- "global flags": { "title": "GLOBAL FLAGS" },
37
- "arguments": { "title": "ARGUMENTS" },
38
- "aliases": { "title": "ALIASES" },
39
- "examples": { "title": "EXAMPLES" },
40
- "streams": { "title": "STREAMS" }
41
- }
42
- },
43
-
44
- "verbosity": {
45
- "description": "Stackable -V flag maps count to log level. --quiet overrides to warn.",
46
- "flag": "-V",
47
- "levels": {
48
- "0": "info",
49
- "1": "debug",
50
- "2": "trace"
51
- },
52
- "quiet_override": "warn"
53
- },
54
-
55
- "streams": {
56
- "description": "Per-command named output streams toggled via --stream flag.",
57
- "flag": "--stream",
58
- "label_format": "[{name}]",
59
- "output": "stderr"
60
- },
61
-
62
- "table": {
63
- "description": "Styled-table contract for the output package. Plain tabwriter is the default; callers opt in to the lipgloss-backed renderer via WithTableStyle. The styled path is gated on writer-is-TTY so non-TTY writers (pipes, files, tests) always emit ANSI-free, diff-friendly output.",
64
- "render_option": "WithTableStyle",
65
- "tty_only": true,
66
- "row_emphasis_kinds": ["none", "primary", "secondary", "muted"],
67
- "row_emphasis_option": "RowEmphasis",
68
- "border_default": "normal"
69
- },
70
-
71
- "extends": [
72
- "scope-defaults.json"
73
- ]
74
- }