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

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 (293) hide show
  1. package/CHANGELOG.md +275 -0
  2. package/LICENSE +1 -1
  3. package/LICENSE-cobra.txt +174 -0
  4. package/NOTICE +15 -0
  5. package/README.md +55 -259
  6. package/dist/aim-DZHwwiIc.d.ts +139 -0
  7. package/dist/aim.d.ts +1 -116
  8. package/dist/aim.js +13 -414
  9. package/dist/alias-D9_qFlyP.d.ts +174 -0
  10. package/dist/alias.d.ts +2 -73
  11. package/dist/alias.js +27 -207
  12. package/dist/api-DAexsu2H.d.ts +77 -0
  13. package/dist/api.d.ts +1 -62
  14. package/dist/api.js +10 -164
  15. package/dist/auth-2-jfgiHn.d.ts +34 -0
  16. package/dist/auth.d.ts +1 -26
  17. package/dist/auth.js +6 -40
  18. package/dist/chunk-3FIKGFKI.js +54 -0
  19. package/dist/chunk-4FMALWYB.js +669 -0
  20. package/dist/chunk-4GPCWBBA.js +143 -0
  21. package/dist/chunk-4UE5TCMQ.js +104 -0
  22. package/dist/chunk-65VPWMPV.js +1134 -0
  23. package/dist/chunk-6HFAEZ52.js +29 -0
  24. package/dist/chunk-6SVOHNIC.js +17 -0
  25. package/dist/chunk-BDNNPRX6.js +41 -0
  26. package/dist/chunk-BRNEKPWX.js +37 -0
  27. package/dist/chunk-BXJ2J27B.js +219 -0
  28. package/dist/chunk-CSJWB6D3.js +151 -0
  29. package/dist/chunk-CXBZTONY.js +65 -0
  30. package/dist/chunk-EE4M2UOF.js +818 -0
  31. package/dist/chunk-GFRAYYRD.js +817 -0
  32. package/dist/chunk-IVQHLI56.js +1890 -0
  33. package/dist/chunk-IZ6Q4SE3.js +178 -0
  34. package/dist/chunk-JKMQSAJP.js +174 -0
  35. package/dist/chunk-K7E34Q3A.js +1445 -0
  36. package/dist/chunk-KVG7YCTS.js +115 -0
  37. package/dist/chunk-L23O2FFE.js +51 -0
  38. package/dist/chunk-MFVUENZR.js +1549 -0
  39. package/dist/chunk-ML7D5DWY.js +263 -0
  40. package/dist/chunk-MQXYDYRD.js +968 -0
  41. package/dist/chunk-POR5L2DG.js +247 -0
  42. package/dist/chunk-QJVSKKRQ.js +369 -0
  43. package/dist/chunk-QQQYCWSC.js +240 -0
  44. package/dist/chunk-R5U7XKVJ.js +16 -0
  45. package/dist/chunk-RYKLVOVK.js +309 -0
  46. package/dist/chunk-SNVGDYX7.js +187 -0
  47. package/dist/chunk-T6OZMPPV.js +68 -0
  48. package/dist/chunk-UKZIAQA7.js +26 -0
  49. package/dist/chunk-VGOA5Y7S.js +251 -0
  50. package/dist/chunk-VWGP4NVJ.js +513 -0
  51. package/dist/chunk-WBVO43HU.js +355 -0
  52. package/dist/chunk-WUOAQVOA.js +86 -0
  53. package/dist/chunk-XJTRY453.js +868 -0
  54. package/dist/chunk-YOBAUCVN.js +583 -0
  55. package/dist/cli-RSRk1M36.d.ts +707 -0
  56. package/dist/cli.d.ts +7 -309
  57. package/dist/cli.js +125 -945
  58. package/dist/completion-csVun6SP.d.ts +112 -0
  59. package/dist/completion-values-By-mnjNt.d.ts +142 -0
  60. package/dist/completion-values.d.ts +1 -0
  61. package/dist/completion-values.js +29 -0
  62. package/dist/completion.d.ts +3 -0
  63. package/dist/completion.js +34 -0
  64. package/dist/compliance-AxFf-uMy.d.ts +60 -0
  65. package/dist/compliance.d.ts +1 -0
  66. package/dist/compliance.js +17 -0
  67. package/dist/config-CaK60ByQ.d.ts +241 -0
  68. package/dist/config.d.ts +1 -97
  69. package/dist/config.js +8 -78
  70. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  71. package/dist/errcorrect.d.ts +1 -37
  72. package/dist/errcorrect.js +8 -68
  73. package/dist/error-Do8Qji43.d.ts +231 -0
  74. package/dist/id/index.d.ts +2 -83
  75. package/dist/id/index.js +14 -65
  76. package/dist/index-BKJZClJx.d.ts +1486 -0
  77. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  78. package/dist/index-CGE5yLBj.d.ts +328 -0
  79. package/dist/index-VLDcI5NF.d.ts +95 -0
  80. package/dist/index.d.ts +37 -0
  81. package/dist/index.js +132 -0
  82. package/dist/llm-DYuR7_uX.d.ts +1069 -0
  83. package/dist/llm-anthropic-Cd_I2xXB.d.ts +67 -0
  84. package/dist/llm-anthropic.d.ts +2 -0
  85. package/dist/llm-anthropic.js +13 -0
  86. package/dist/llm-openai-DyFrucmV.d.ts +87 -0
  87. package/dist/llm-openai.d.ts +2 -0
  88. package/dist/llm-openai.js +19 -0
  89. package/dist/llm.d.ts +1 -188
  90. package/dist/llm.js +101 -356
  91. package/dist/log-CkaxMX3U.d.ts +115 -0
  92. package/dist/log.d.ts +2 -0
  93. package/dist/log.js +14 -0
  94. package/dist/mcp/index.d.ts +4 -0
  95. package/dist/mcp/index.js +185 -0
  96. package/dist/netpolicy-Brx5XZUB.d.ts +151 -0
  97. package/dist/netpolicy.d.ts +1 -0
  98. package/dist/netpolicy.js +25 -0
  99. package/dist/output-CjZWmL8s.d.ts +420 -0
  100. package/dist/output.d.ts +3 -213
  101. package/dist/output.js +135 -447
  102. package/dist/parity-CvMuYcVI.d.ts +61 -0
  103. package/dist/progress-CAzyxeWl.d.ts +38 -0
  104. package/dist/progress.d.ts +1 -30
  105. package/dist/progress.js +6 -55
  106. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  107. package/dist/provenance.d.ts +1 -24
  108. package/dist/provenance.js +6 -31
  109. package/dist/routellm-B0nv59mH.d.ts +111 -0
  110. package/dist/routellm.d.ts +2 -64
  111. package/dist/routellm.js +13 -255
  112. package/dist/rpc-D31Lg0Kc.d.ts +32 -0
  113. package/dist/rpc.d.ts +2 -25
  114. package/dist/rpc.js +4 -98
  115. package/dist/safety-CUaYEjZc.d.ts +30 -0
  116. package/dist/safety.d.ts +1 -24
  117. package/dist/safety.js +6 -43
  118. package/dist/scope-BrhYB4ij.d.ts +141 -0
  119. package/dist/scope.d.ts +1 -121
  120. package/dist/scope.js +20 -377
  121. package/dist/serve-D8yWMrTc.d.ts +646 -0
  122. package/dist/serve.d.ts +3 -0
  123. package/dist/serve.js +75 -0
  124. package/dist/sqlstore.js +6 -39
  125. package/dist/stream-CrjeCp0M.d.ts +44 -0
  126. package/dist/stream.d.ts +1 -35
  127. package/dist/stream.js +8 -51
  128. package/dist/telemetry/index.d.ts +1 -315
  129. package/dist/telemetry/index.js +26 -599
  130. package/dist/toolspec-DcPwwoAZ.d.ts +368 -0
  131. package/dist/toolspec.d.ts +2 -0
  132. package/dist/toolspec.js +37 -0
  133. package/dist/tui/index.d.ts +6 -298
  134. package/dist/tui/index.js +17 -381
  135. package/dist/upgrade-C3RWGwRi.d.ts +125 -0
  136. package/dist/upgrade.d.ts +1 -95
  137. package/dist/upgrade.js +6 -114
  138. package/dist/xdg-DB7Shoib.d.ts +179 -0
  139. package/dist/xdg.d.ts +1 -169
  140. package/dist/xdg.js +14 -128
  141. package/package.json +192 -24
  142. package/src/README.md +15 -0
  143. package/src/alias.conformance.test.ts +250 -0
  144. package/src/alias.test.ts +206 -2
  145. package/src/alias.ts +196 -21
  146. package/src/cli.help-command.test.ts +105 -0
  147. package/src/cli.offline.test.ts +93 -0
  148. package/src/cli.parity.test.ts +192 -0
  149. package/src/cli.root.conformance.test.ts +166 -0
  150. package/src/cli.test.ts +95 -1
  151. package/src/cli.ts +234 -25
  152. package/src/completion-scripts.ts +16 -0
  153. package/src/completion-values.test.ts +76 -16
  154. package/src/completion-values.ts +170 -66
  155. package/src/completion.conformance.test.ts +298 -0
  156. package/src/completion.test.ts +268 -145
  157. package/src/completion.ts +772 -121
  158. package/src/compliance.test.ts +196 -2
  159. package/src/compliance.ts +440 -20
  160. package/src/config-merge.test.ts +425 -0
  161. package/src/config.test.ts +228 -1
  162. package/src/config.ts +429 -16
  163. package/src/delegation.test.ts +299 -0
  164. package/src/delegation.ts +807 -0
  165. package/src/gen/crud_pb.ts +7 -7
  166. package/src/id/README.md +38 -0
  167. package/src/id/contract.test.ts +1 -1
  168. package/src/id/index.test.ts +1 -1
  169. package/src/id/index.ts +3 -2
  170. package/src/index.test.ts +71 -0
  171. package/src/index.ts +46 -0
  172. package/src/llm-anthropic.conformance.test.ts +1135 -0
  173. package/src/llm-anthropic.test.ts +152 -0
  174. package/src/llm-anthropic.ts +940 -0
  175. package/src/llm-choice-hermetic.test.ts +335 -0
  176. package/src/llm-config.test.ts +232 -0
  177. package/src/llm-config.ts +106 -0
  178. package/src/llm-endpoint.ts +254 -0
  179. package/src/llm-error.ts +17 -0
  180. package/src/llm-errors.ts +152 -0
  181. package/src/llm-file.ts +126 -0
  182. package/src/llm-http.ts +317 -0
  183. package/src/llm-keys.ts +167 -0
  184. package/src/llm-media.conformance.test.ts +87 -0
  185. package/src/llm-media.test.ts +279 -0
  186. package/src/llm-media.ts +322 -0
  187. package/src/llm-openai.conformance.test.ts +407 -0
  188. package/src/llm-openai.test.ts +510 -0
  189. package/src/llm-openai.ts +708 -0
  190. package/src/llm-payload.ts +155 -0
  191. package/src/llm-quote.ts +46 -0
  192. package/src/llm-routellm.conformance.test.ts +44 -0
  193. package/src/llm-toolnames.conformance.test.ts +112 -0
  194. package/src/llm-toolnames.test.ts +132 -0
  195. package/src/llm-toolnames.ts +298 -0
  196. package/src/llm-uri.ts +99 -0
  197. package/src/llm.test.ts +43 -15
  198. package/src/llm.toolcall.test.ts +175 -0
  199. package/src/llm.ts +602 -190
  200. package/src/log.parity.test.ts +105 -0
  201. package/src/log.test.ts +270 -1
  202. package/src/log.ts +228 -49
  203. package/src/mcp/README.md +63 -0
  204. package/src/mcp/args-separator.test.ts +164 -0
  205. package/src/mcp/args.test.ts +223 -0
  206. package/src/mcp/args.ts +160 -0
  207. package/src/mcp/audit.test.ts +520 -0
  208. package/src/mcp/audit.ts +70 -0
  209. package/src/mcp/bridge.test.ts +250 -0
  210. package/src/mcp/bridge.ts +286 -0
  211. package/src/mcp/conformance.test.ts +357 -0
  212. package/src/mcp/dispatch.ts +359 -0
  213. package/src/mcp/identity.test.ts +166 -0
  214. package/src/mcp/identity.ts +72 -0
  215. package/src/mcp/index.ts +176 -0
  216. package/src/mcp/legacy-notify.test.ts +59 -0
  217. package/src/mcp/legacy.ts +367 -0
  218. package/src/mcp/mcp.test.ts +707 -0
  219. package/src/mcp/modern-confirm.test.ts +520 -0
  220. package/src/mcp/modern-confirm.ts +484 -0
  221. package/src/mcp/modern.ts +788 -0
  222. package/src/mcp/stdio.test.ts +313 -0
  223. package/src/mcp/stdio.ts +254 -0
  224. package/src/mcp/tasks.ts +82 -0
  225. package/src/mcp/testtree.ts +250 -0
  226. package/src/mcp/toolname.test.ts +147 -0
  227. package/src/mcp/types.ts +689 -0
  228. package/src/netpolicy.test.ts +280 -0
  229. package/src/netpolicy.ts +256 -0
  230. package/src/output/README.md +46 -0
  231. package/src/output/builtins.ts +5 -5
  232. package/src/output/dispatch.ts +10 -2
  233. package/src/output/error.ts +459 -0
  234. package/src/output/formatter.ts +29 -5
  235. package/src/output/formatters/README.md +50 -0
  236. package/src/output/formatters/csv.ts +48 -12
  237. package/src/output/formatters/json.ts +4 -25
  238. package/src/output/formatters/project.ts +34 -0
  239. package/src/output/formatters/table.ts +8 -6
  240. package/src/output/formatters/text.ts +7 -3
  241. package/src/output/formatters/yaml.ts +5 -22
  242. package/src/output/projection.test.ts +298 -0
  243. package/src/output/projection.ts +33 -59
  244. package/src/output/template.ts +11 -21
  245. package/src/output.surface.test.ts +41 -0
  246. package/src/output.ts +64 -3
  247. package/src/plan.ts +89 -0
  248. package/src/policy.ts +472 -0
  249. package/src/published-types.test.ts +133 -0
  250. package/src/routellm.test.ts +209 -28
  251. package/src/routellm.toolcall.test.ts +521 -0
  252. package/src/routellm.ts +213 -177
  253. package/src/router/README.md +44 -0
  254. package/src/router/server.test.ts +41 -0
  255. package/src/router/server.ts +11 -0
  256. package/src/safety.test.ts +19 -9
  257. package/src/scope-defaults.json +29 -29
  258. package/src/serve.test.ts +1257 -0
  259. package/src/serve.ts +1665 -0
  260. package/src/sideeffect.ts +105 -0
  261. package/src/telemetry/README.md +48 -0
  262. package/src/telemetry/client.test.ts +31 -0
  263. package/src/telemetry/client.ts +12 -6
  264. package/src/telemetry/offline.test.ts +64 -0
  265. package/src/toolspec-internal.ts +279 -0
  266. package/src/toolspec-manifest.test.ts +167 -0
  267. package/src/toolspec-manifest.ts +415 -0
  268. package/src/toolspec-spec-schemas.ts +12 -0
  269. package/src/toolspec-spec.test.ts +273 -0
  270. package/src/toolspec-spec.ts +458 -0
  271. package/src/toolspec.from-command.test.ts +350 -0
  272. package/src/toolspec.test.ts +2 -2
  273. package/src/toolspec.ts +222 -0
  274. package/src/triton/README.md +34 -0
  275. package/src/tui/README.md +42 -0
  276. package/src/tui/parity.test.ts +120 -31
  277. package/src/tui/parity.ts +58 -7
  278. package/src/upgrade.test.ts +291 -0
  279. package/src/upgrade.ts +116 -7
  280. package/src/wizard.test.ts +7 -7
  281. package/test/llm/conformance-helpers.ts +100 -0
  282. package/test/output/csv.test.ts +164 -0
  283. package/test/output/dispatch.test.ts +1 -2
  284. package/test/output/error.test.ts +277 -0
  285. package/test/output/smoke-capture.ts +2 -2
  286. package/test/output/smoke.test.ts +2 -2
  287. package/test/output/taxonomy-contract.test.ts +148 -0
  288. package/test/setup-env.ts +16 -0
  289. package/test/toolspec/fixture.ts +79 -0
  290. package/tsconfig.json +3 -1
  291. package/tsconfig.test.json +10 -0
  292. package/vitest.config.ts +9 -0
  293. package/src/tui/parity.json +0 -74
@@ -0,0 +1,277 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as yaml from 'js-yaml';
3
+ import {
4
+ CODE_CONFLICT,
5
+ CODE_CONSENT_REFUSED,
6
+ CODE_GENERIC,
7
+ CODE_NOT_FOUND,
8
+ CODE_PREREQUISITE,
9
+ CODE_PROVENANCE_MISSING,
10
+ CODE_RATE_LIMITED,
11
+ CODE_TRANSIENT,
12
+ CODE_UNAUTHORIZED,
13
+ CODE_USAGE,
14
+ EXIT_CONSENT_REFUSED,
15
+ EXIT_GENERIC,
16
+ EXIT_PREREQUISITE,
17
+ EXIT_PROVENANCE_MISSING,
18
+ EXIT_RATE_LIMITED,
19
+ EXIT_TRANSIENT,
20
+ TRANSIENCE_PERMANENT,
21
+ TRANSIENCE_TRANSIENT,
22
+ TRANSIENCE_UNKNOWN,
23
+ conflictError,
24
+ consentRefusedError,
25
+ genericError,
26
+ notFoundError,
27
+ prerequisiteError,
28
+ provenanceMissingError,
29
+ rateLimitedError,
30
+ renderError,
31
+ transienceForCode,
32
+ transientError,
33
+ unauthorizedError,
34
+ unwrapError,
35
+ usageError,
36
+ withTransience,
37
+ wrapError,
38
+ } from '../../src/output/error';
39
+ import type { CliError } from '../../src/output/error';
40
+
41
+ /** Collects renderError output into a string. */
42
+ function capture(): { write(chunk: string): void; text(): string } {
43
+ let buf = '';
44
+ return {
45
+ write(chunk: string) {
46
+ buf += chunk;
47
+ },
48
+ text: () => buf,
49
+ };
50
+ }
51
+
52
+ describe('constructors — code/exit/transience', () => {
53
+ const cases: Array<[string, CliError, string, number, string]> = [
54
+ ['Generic', genericError('boom'), CODE_GENERIC, 1, TRANSIENCE_PERMANENT],
55
+ ['NotFound', notFoundError('nope'), CODE_NOT_FOUND, 3, TRANSIENCE_PERMANENT],
56
+ ['Conflict', conflictError('dup'), CODE_CONFLICT, 4, TRANSIENCE_PERMANENT],
57
+ [
58
+ 'Unauthorized',
59
+ unauthorizedError('nope'),
60
+ CODE_UNAUTHORIZED,
61
+ 5,
62
+ TRANSIENCE_PERMANENT,
63
+ ],
64
+ ['Usage', usageError('bad flag'), CODE_USAGE, 2, TRANSIENCE_PERMANENT],
65
+ [
66
+ 'RateLimited',
67
+ rateLimitedError('budget'),
68
+ CODE_RATE_LIMITED,
69
+ 64,
70
+ TRANSIENCE_TRANSIENT,
71
+ ],
72
+ [
73
+ 'Transient',
74
+ transientError('upstream timeout'),
75
+ CODE_TRANSIENT,
76
+ 6,
77
+ TRANSIENCE_TRANSIENT,
78
+ ],
79
+ [
80
+ 'ProvenanceMissing',
81
+ provenanceMissingError('/email'),
82
+ CODE_PROVENANCE_MISSING,
83
+ 65,
84
+ TRANSIENCE_PERMANENT,
85
+ ],
86
+ [
87
+ 'ConsentRefused',
88
+ consentRefusedError('declined'),
89
+ CODE_CONSENT_REFUSED,
90
+ 7,
91
+ TRANSIENCE_TRANSIENT,
92
+ ],
93
+ [
94
+ 'Prerequisite',
95
+ prerequisiteError('no listener'),
96
+ CODE_PREREQUISITE,
97
+ 70,
98
+ TRANSIENCE_TRANSIENT,
99
+ ],
100
+ ];
101
+ it.each(cases)('%s', (_name, got, wantCode, wantExit, wantTransience) => {
102
+ expect(got.code).toBe(wantCode);
103
+ expect(got.exit_code).toBe(wantExit);
104
+ expect(got.transience).toBe(wantTransience);
105
+ });
106
+
107
+ // Mirrors Go's envelope exit-code table: the 0-6 core taxonomy plus
108
+ // CONSENT_REFUSED 7 and the kit extension band 64/65/70. Uniqueness
109
+ // pins the taxonomy; the per-number assertions pin which class owns
110
+ // which slot, so a port that adds a class at a number Go already
111
+ // spent fails here rather than on a user's machine.
112
+ it('exit-code table is unique and every slot is owned by its Go class', () => {
113
+ const exits = new Map(cases.map(([, e]) => [e.exit_code, e.code]));
114
+ expect(exits.size).toBe(10);
115
+ expect(EXIT_GENERIC).toBe(1);
116
+ expect(EXIT_TRANSIENT).toBe(6);
117
+ expect(EXIT_CONSENT_REFUSED).toBe(7);
118
+ expect(EXIT_RATE_LIMITED).toBe(64);
119
+ expect(EXIT_PROVENANCE_MISSING).toBe(65);
120
+ expect(EXIT_PREREQUISITE).toBe(70);
121
+ expect(exits.get(1)).toBe(CODE_GENERIC);
122
+ expect(exits.get(6)).toBe(CODE_TRANSIENT);
123
+ expect(exits.get(7)).toBe(CODE_CONSENT_REFUSED);
124
+ expect(exits.get(65)).toBe(CODE_PROVENANCE_MISSING);
125
+ expect(exits.get(70)).toBe(CODE_PREREQUISITE);
126
+ });
127
+ });
128
+
129
+ describe('transienceForCode', () => {
130
+ it.each([
131
+ [CODE_USAGE, TRANSIENCE_PERMANENT],
132
+ [CODE_NOT_FOUND, TRANSIENCE_PERMANENT],
133
+ [CODE_CONFLICT, TRANSIENCE_PERMANENT],
134
+ [CODE_UNAUTHORIZED, TRANSIENCE_PERMANENT],
135
+ [CODE_PROVENANCE_MISSING, TRANSIENCE_PERMANENT],
136
+ [CODE_RATE_LIMITED, TRANSIENCE_TRANSIENT],
137
+ [CODE_TRANSIENT, TRANSIENCE_TRANSIENT],
138
+ [CODE_CONSENT_REFUSED, TRANSIENCE_TRANSIENT],
139
+ [CODE_PREREQUISITE, TRANSIENCE_TRANSIENT],
140
+ [CODE_GENERIC, TRANSIENCE_UNKNOWN],
141
+ ['ADOPTER_SPECIFIC', TRANSIENCE_UNKNOWN],
142
+ ['', TRANSIENCE_UNKNOWN],
143
+ ])('%s -> %s', (code, want) => {
144
+ expect(transienceForCode(code)).toBe(want);
145
+ });
146
+ });
147
+
148
+ describe('wrapError', () => {
149
+ it('defaults transience from code', () => {
150
+ const base = new Error('boom');
151
+ expect(wrapError(base, CODE_CONFLICT, 4)?.transience).toBe(
152
+ TRANSIENCE_PERMANENT,
153
+ );
154
+ expect(wrapError(base, CODE_RATE_LIMITED, 64)?.transience).toBe(
155
+ TRANSIENCE_TRANSIENT,
156
+ );
157
+ expect(wrapError(base, CODE_GENERIC, 1)?.transience).toBe(
158
+ TRANSIENCE_UNKNOWN,
159
+ );
160
+ });
161
+
162
+ it('retains the source error and passes null through', () => {
163
+ const base = new Error('boom');
164
+ const e = wrapError(base, CODE_CONFLICT, 4);
165
+ expect(e?.message).toBe('boom');
166
+ expect(unwrapError(e as CliError)).toBe(base);
167
+ expect(wrapError(null, CODE_GENERIC, 1)).toBeNull();
168
+ });
169
+ });
170
+
171
+ describe('withTransience', () => {
172
+ it('copies and sets, never mutates the shared envelope', () => {
173
+ const orig: CliError = { code: 'SHARED', message: 'm', exit_code: 9 };
174
+ const got = withTransience(orig, TRANSIENCE_TRANSIENT);
175
+ expect(got).not.toBe(orig);
176
+ expect(got.transience).toBe(TRANSIENCE_TRANSIENT);
177
+ expect(orig.transience).toBeUndefined();
178
+ expect(got.code).toBe(orig.code);
179
+ expect(got.message).toBe(orig.message);
180
+ expect(got.exit_code).toBe(orig.exit_code);
181
+ });
182
+
183
+ it('carries the retained source error to the copy', () => {
184
+ const base = new Error('boom');
185
+ const e = wrapError(base, CODE_GENERIC, 1) as CliError;
186
+ expect(unwrapError(withTransience(e, TRANSIENCE_PERMANENT))).toBe(base);
187
+ });
188
+ });
189
+
190
+ describe('renderError — structured always carries transience', () => {
191
+ it('normalizes unset transience to unknown in JSON', () => {
192
+ const w = capture();
193
+ renderError(w, 'json', { code: 'ADOPTER_SPECIFIC', message: 'm', exit_code: 9 });
194
+ expect(JSON.parse(w.text()).transience).toBe(TRANSIENCE_UNKNOWN);
195
+ });
196
+
197
+ it('normalizes unset transience to unknown in YAML', () => {
198
+ const w = capture();
199
+ renderError(w, 'yaml', { code: 'ADOPTER_SPECIFIC', message: 'm', exit_code: 9 });
200
+ expect(w.text()).toContain('transience: unknown');
201
+ });
202
+
203
+ it('renders an explicit class untouched', () => {
204
+ const w = capture();
205
+ renderError(w, 'json', rateLimitedError('budget'));
206
+ expect(JSON.parse(w.text()).transience).toBe(TRANSIENCE_TRANSIENT);
207
+ });
208
+
209
+ it('does not mutate the input envelope', () => {
210
+ const e: CliError = { code: 'ADOPTER_SPECIFIC', message: 'm', exit_code: 9 };
211
+ renderError(capture(), 'json', e);
212
+ expect(e.transience).toBeUndefined();
213
+ });
214
+ });
215
+
216
+ describe('renderError — wire round-trip', () => {
217
+ it('JSON: full envelope, empty optionals off the wire', () => {
218
+ let w = capture();
219
+ renderError(w, 'json', provenanceMissingError('/email'));
220
+ const full = JSON.parse(w.text());
221
+ expect(full.code).toBe(CODE_PROVENANCE_MISSING);
222
+ expect(full.cause).toBe('/email');
223
+ expect(full.exit_code).toBe(65);
224
+ expect(full.transience).toBe(TRANSIENCE_PERMANENT);
225
+
226
+ w = capture();
227
+ renderError(w, 'json', transientError('upstream timeout'));
228
+ const bare = JSON.parse(w.text());
229
+ expect(Object.keys(bare).sort()).toEqual([
230
+ 'code',
231
+ 'exit_code',
232
+ 'message',
233
+ 'transience',
234
+ ]);
235
+ expect(bare.exit_code).toBe(6);
236
+ });
237
+
238
+ it('YAML: parses back to the wire shape', () => {
239
+ const w = capture();
240
+ renderError(w, 'yaml', transientError('upstream timeout'));
241
+ expect(yaml.load(w.text())).toEqual({
242
+ code: CODE_TRANSIENT,
243
+ message: 'upstream timeout',
244
+ exit_code: 6,
245
+ transience: TRANSIENCE_TRANSIENT,
246
+ });
247
+ });
248
+ });
249
+
250
+ describe('renderError — plain text + null', () => {
251
+ it('renders each populated field on its own line', () => {
252
+ const w = capture();
253
+ renderError(w, 'table', {
254
+ code: 'NOT_FOUND',
255
+ message: 'missing thing',
256
+ cause: 'root',
257
+ suggested_fix: 'try --all',
258
+ alternatives: ['other'],
259
+ exit_code: 3,
260
+ });
261
+ expect(w.text()).toBe(
262
+ 'NOT_FOUND: missing thing\nCause: root\nFix: try --all\nAlternative: other\n',
263
+ );
264
+ });
265
+
266
+ it('renders bare message without code prefix', () => {
267
+ const w = capture();
268
+ renderError(w, '', { code: '', message: 'just text', exit_code: 1 });
269
+ expect(w.text()).toBe('just text\n');
270
+ });
271
+
272
+ it('null renders nothing', () => {
273
+ const w = capture();
274
+ renderError(w, 'json', null);
275
+ expect(w.text()).toBe('');
276
+ });
277
+ });
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Captures verbatim output for each smoke command listed in T-1011 so the
3
- * track report can include real-world output samples. Run with:
2
+ * Captures verbatim output for each smoke command so a report can
3
+ * include real-world output samples. Run with:
4
4
  *
5
5
  * pnpm exec tsx test/output/smoke-capture.ts
6
6
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Smoke tests mirroring T-1011's manual checklist. Each test exercises a
2
+ * Smoke tests mirroring the manual checklist. Each test exercises a
3
3
  * dispatch path end-to-end against an in-memory writer or temp file so the
4
4
  * suite is hermetic but covers the same surface a real `cli list` invocation
5
5
  * would.
@@ -44,7 +44,7 @@ const rows = [
44
44
  { id: '2', name: 'Bob', status: 'idle' },
45
45
  ];
46
46
 
47
- describe('smoke — T-1011 checklist', () => {
47
+ describe('smoke — checklist', () => {
48
48
  it('cli list (default table)', async () => {
49
49
  const program = makeProgram([]);
50
50
  const cap = captureStdout();
@@ -0,0 +1,148 @@
1
+ // Cross-language exit-taxonomy contract loader.
2
+ //
3
+ // Loads contracts/exit-taxonomy-v1/taxonomy.json — generated from
4
+ // go/console/output/envelope, the single source of truth — and asserts
5
+ // this TS SDK's table agrees with it on every class, every exit number
6
+ // and every transience.
7
+ //
8
+ // A failure here means Go's taxonomy moved and this port did not follow.
9
+ // That is the exact drift this contract exists to catch: when Go gained
10
+ // CONSENT_REFUSED 7 and PREREQUISITE 70, all four SDK ports silently
11
+ // kept the old nine-class table for two releases, and
12
+ // transienceForCode returned 'unknown' where Go returned 'transient' —
13
+ // so four runtimes handed agents wrong retry guidance.
14
+ //
15
+ // Fix by adding the missing class here, not by editing the contract:
16
+ // the contract is regenerated from Go, never hand-edited.
17
+
18
+ import { existsSync, readFileSync } from 'node:fs';
19
+ import { dirname, resolve } from 'node:path';
20
+ import { fileURLToPath } from 'node:url';
21
+
22
+ import { describe, it, expect } from 'vitest';
23
+
24
+ import {
25
+ exitClasses,
26
+ exitCodeForClass,
27
+ transienceForCode,
28
+ } from '../../src/output/error';
29
+
30
+ interface TaxonomyClass {
31
+ readonly class: string;
32
+ readonly exit: number;
33
+ readonly transience: string;
34
+ }
35
+
36
+ interface BandSlot {
37
+ readonly exit: number;
38
+ readonly class: string;
39
+ readonly owner: string;
40
+ }
41
+
42
+ interface TaxonomyContract {
43
+ readonly version: string;
44
+ readonly source: string;
45
+ readonly transiences: ReadonlyArray<string>;
46
+ readonly classes: ReadonlyArray<TaxonomyClass>;
47
+ readonly extension_band: ReadonlyArray<BandSlot>;
48
+ }
49
+
50
+ // Walk up from this test file's directory until we hit a directory
51
+ // holding contracts/exit-taxonomy-v1/taxonomy.json. Robust against both
52
+ // `vitest run` (CWD = sdk/ts) and IDE-driven invocations whose CWD may
53
+ // vary.
54
+ function locateContract(): string {
55
+ const here = dirname(fileURLToPath(import.meta.url));
56
+ let dir = here;
57
+ for (let i = 0; i < 10; i++) {
58
+ const candidate = resolve(
59
+ dir,
60
+ 'contracts',
61
+ 'exit-taxonomy-v1',
62
+ 'taxonomy.json',
63
+ );
64
+ if (existsSync(candidate)) return candidate;
65
+ const parent = dirname(dir);
66
+ if (parent === dir) break;
67
+ dir = parent;
68
+ }
69
+ throw new Error(
70
+ `contracts/exit-taxonomy-v1/taxonomy.json: not found walking up from ${here}`,
71
+ );
72
+ }
73
+
74
+ const CONTRACT: TaxonomyContract = JSON.parse(
75
+ readFileSync(locateContract(), 'utf8'),
76
+ ) as TaxonomyContract;
77
+
78
+ // The slots envelope itself owns. The conformance-tree slots (66-69)
79
+ // are recorded in the contract so a new allocation cannot double-book a
80
+ // number, but no SDK port is expected to export them.
81
+ const ENVELOPE_OWNER = 'hop.top/kit/go/console/output/envelope';
82
+
83
+ describe('exit-taxonomy-v1 contract metadata', () => {
84
+ it('pins version and source', () => {
85
+ expect(CONTRACT.version).toBe('v1');
86
+ expect(CONTRACT.source).toBe(ENVELOPE_OWNER);
87
+ expect(CONTRACT.classes.length).toBeGreaterThan(0);
88
+ });
89
+ });
90
+
91
+ describe('exit-taxonomy-v1: this port matches the contract', () => {
92
+ // Membership in both directions. A port carrying an extra class Go
93
+ // does not define is as much a divergence as a port missing one: an
94
+ // adopter branching on it gets a number no other runtime produces.
95
+ it('declares exactly the contract classes, in contract order', () => {
96
+ expect(exitClasses()).toEqual(CONTRACT.classes.map((c) => c.class));
97
+ });
98
+
99
+ it.each(CONTRACT.classes.map((c) => [c.class, c] as const))(
100
+ '%s resolves to the contract exit and transience',
101
+ (_name, row) => {
102
+ expect(exitCodeForClass(row.class)).toBe(row.exit);
103
+ expect(transienceForCode(row.class)).toBe(row.transience);
104
+ },
105
+ );
106
+
107
+ // The transience vocabulary is itself a contract: an agent branching
108
+ // on a fourth string has no defined behavior.
109
+ it('answers only with the contract transience vocabulary', () => {
110
+ for (const row of CONTRACT.classes) {
111
+ expect(CONTRACT.transiences).toContain(transienceForCode(row.class));
112
+ }
113
+ });
114
+
115
+ // An unknown class must resolve to nothing rather than to a fallback
116
+ // number. A built-in fallback is what turns "kit added a class and
117
+ // this port never copied it" into an assertion against exit 1 that
118
+ // reads as a real failure rather than a stale table.
119
+ it('does not invent a code for an adopter-defined class', () => {
120
+ expect(exitCodeForClass('ADOPTER_SPECIFIC')).toBeUndefined();
121
+ expect(transienceForCode('ADOPTER_SPECIFIC')).toBe('unknown');
122
+ });
123
+ });
124
+
125
+ describe('exit-taxonomy-v1 extension band', () => {
126
+ it('exports every band slot envelope owns', () => {
127
+ const owned = CONTRACT.extension_band.filter(
128
+ (s) => s.owner === ENVELOPE_OWNER,
129
+ );
130
+ expect(owned.length).toBeGreaterThan(0);
131
+ for (const slot of owned) {
132
+ expect(exitCodeForClass(slot.class)).toBe(slot.exit);
133
+ }
134
+ });
135
+
136
+ // Slots owned elsewhere must NOT be claimed here. A port that
137
+ // exported LEAK_DETECTED would be minting a number the conformance
138
+ // tree owns, which is the collision the band record exists to stop.
139
+ it('leaves slots owned by other packages unclaimed', () => {
140
+ const foreign = CONTRACT.extension_band.filter(
141
+ (s) => s.owner !== ENVELOPE_OWNER,
142
+ );
143
+ expect(foreign.length).toBeGreaterThan(0);
144
+ for (const slot of foreign) {
145
+ expect(exitCodeForClass(slot.class)).toBeUndefined();
146
+ }
147
+ });
148
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Vitest setup: points XDG_CONFIG_HOME at an empty temp dir per test
3
+ * file, so a developer's own config (llm.yaml included) never reaches
4
+ * a test. A test that needs a config writes it there or sets its own.
5
+ *
6
+ * @internal
7
+ */
8
+
9
+ import { mkdtempSync, rmSync } from "node:fs";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { afterAll } from "vitest";
13
+
14
+ const dir = mkdtempSync(join(tmpdir(), "kit-ts-xdg-"));
15
+ process.env["XDG_CONFIG_HOME"] = dir;
16
+ afterAll(() => rmSync(dir, { recursive: true, force: true }));
@@ -0,0 +1,79 @@
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
+ /** cobra MarkFlagRequired / commander makeOptionMandatory. */
22
+ required?: boolean;
23
+ /** kit flag enum (cli.FlagEnumAnnotation) / commander .choices(). */
24
+ enum?: string[];
25
+ }
26
+
27
+ interface TreeCommand {
28
+ name: string;
29
+ short?: string;
30
+ long?: string;
31
+ hidden?: boolean;
32
+ run?: boolean;
33
+ annotations?: Record<string, string>;
34
+ flags?: TreeFlag[];
35
+ commands?: TreeCommand[];
36
+ }
37
+
38
+ export interface Tree {
39
+ tool: string;
40
+ version: string;
41
+ reserved: string[];
42
+ commands: TreeCommand[];
43
+ }
44
+
45
+ function addFixtureCommand(parent: Command, tc: TreeCommand): void {
46
+ const cmd = parent.command(tc.name, { hidden: tc.hidden ?? false });
47
+ if (tc.short && tc.long) cmd.summary(tc.short).description(tc.long);
48
+ else if (tc.short) cmd.description(tc.short);
49
+ if (tc.run) cmd.action(() => {});
50
+ if (tc.annotations) {
51
+ (cmd as Command & { annotations?: Record<string, string> }).annotations = {
52
+ ...tc.annotations,
53
+ };
54
+ }
55
+ for (const f of tc.flags ?? []) {
56
+ const short = f.short ? `-${f.short}, ` : "";
57
+ const arg =
58
+ f.type === "bool" ? "" : f.type === "string" ? " <value>" : " <values...>";
59
+ const opt = new Option(`${short}--${f.name}${arg}`, f.description);
60
+ if (f.default !== undefined) opt.default(f.default);
61
+ if (f.hidden) opt.hideHelp();
62
+ if (f.required) opt.makeOptionMandatory();
63
+ if (f.enum) opt.choices(f.enum);
64
+ cmd.addOption(opt);
65
+ }
66
+ for (const child of tc.commands ?? []) addFixtureCommand(cmd, child);
67
+ }
68
+
69
+ /**
70
+ * The fixture program, with createCLI's `-v, --version` on the root.
71
+ */
72
+ export function fixtureProgram(): { program: Command; tree: Tree } {
73
+ const tree = JSON.parse(
74
+ fs.readFileSync(path.join(FIXTURES, "toolspec-manifest.tree.json"), "utf-8"),
75
+ ) as Tree;
76
+ const program = new Command(tree.tool).version(tree.version, "-v, --version");
77
+ for (const c of tree.commands) addFixtureCommand(program, c);
78
+ return { program, tree };
79
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
4
5
  "module": "CommonJS",
5
6
  "declaration": true,
6
7
  "outDir": "./dist",
@@ -8,5 +9,6 @@
8
9
  "esModuleInterop": true,
9
10
  "resolveJsonModule": true
10
11
  },
11
- "include": ["src"]
12
+ "include": ["src"],
13
+ "exclude": ["src/**/*.test.ts"]
12
14
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler"
7
+ },
8
+ "include": ["src", "test"],
9
+ "exclude": []
10
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ // Every test file starts with an empty XDG config home, so no
6
+ // developer's llm.yaml (or other config) reaches a test.
7
+ setupFiles: ["test/setup-env.ts"],
8
+ },
9
+ });
@@ -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
- }