@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
@@ -1,605 +1,32 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
29
2
 
30
- // src/telemetry/index.ts
31
- var telemetry_exports = {};
32
- __export(telemetry_exports, {
33
- Client: () => Client,
34
- Mode: () => Mode,
35
- consentPath: () => consentPath,
36
- deniedConsent: () => deniedConsent,
37
- getInstallId: () => getInstallId,
38
- installIdPath: () => installIdPath,
39
- loadConsent: () => loadConsent,
40
- parseMode: () => parseMode,
41
- redact: () => redact,
42
- redactString: () => redactString,
43
- resetForTest: () => resetForTest,
44
- resolveMode: () => resolveMode,
45
- rotate: () => rotate
46
- });
47
- module.exports = __toCommonJS(telemetry_exports);
48
3
 
49
- // src/telemetry/mode.ts
50
- var Mode = {
51
- Off: "off",
52
- Anon: "anon",
53
- Full: "full"
54
- };
55
- function parseMode(s) {
56
- if (s === void 0 || s === null || s === "") {
57
- return [Mode.Off, true];
58
- }
59
- const low = s.trim().toLowerCase();
60
- if (low === "") {
61
- return [Mode.Off, true];
62
- }
63
- for (const m of Object.values(Mode)) {
64
- if (m === low) {
65
- return [m, true];
66
- }
67
- }
68
- return [Mode.Off, false];
69
- }
70
- function resolveAppPrefix(env) {
71
- return (env.KIT_APP_PREFIX ?? "").trim().toUpperCase();
72
- }
73
- function resolveMode(env = process.env) {
74
- const app = resolveAppPrefix(env);
75
- if (app) {
76
- const v2 = (env[`${app}_TELEMETRY_MODE`] ?? "").trim();
77
- if (v2) {
78
- const [m, ok] = parseMode(v2);
79
- if (ok) {
80
- return m;
81
- }
82
- }
83
- }
84
- const v = (env.KIT_TELEMETRY_MODE ?? "").trim();
85
- if (v) {
86
- const [m, ok] = parseMode(v);
87
- if (ok) {
88
- return m;
89
- }
90
- }
91
- return Mode.Off;
92
- }
93
4
 
94
- // src/telemetry/installId.ts
95
- var import_node_fs = require("fs");
96
- var import_node_fs2 = require("fs");
97
- var import_node_crypto = require("crypto");
98
- var import_node_os = require("os");
99
- var path = __toESM(require("path"));
100
- var installIDSize = 32;
101
- var installIDFilePerm = 384;
102
- var installIDDirPerm = 448;
103
- function xdgStateHome() {
104
- return process.env.XDG_STATE_HOME ?? path.join((0, import_node_os.homedir)(), ".local", "state");
105
- }
106
- function installIdPath() {
107
- return path.join(xdgStateHome(), "kit", "telemetry", "installation_id");
108
- }
109
- function sha256Hex(buf) {
110
- return (0, import_node_crypto.createHash)("sha256").update(buf).digest("hex");
111
- }
112
- async function readAndValidate(p) {
113
- const data = await import_node_fs.promises.readFile(p);
114
- if (data.length !== installIDSize) {
115
- throw new Error(
116
- `install_id: file ${p} has wrong size ${data.length} bytes, expected ${installIDSize}`
117
- );
118
- }
119
- return data;
120
- }
121
- async function getInstallId() {
122
- const p = installIdPath();
123
- if ((0, import_node_fs2.existsSync)(p)) {
124
- const data = await readAndValidate(p);
125
- return sha256Hex(data);
126
- }
127
- const parent = path.dirname(p);
128
- await import_node_fs.promises.mkdir(parent, { recursive: true, mode: installIDDirPerm });
129
- try {
130
- await import_node_fs.promises.chmod(parent, installIDDirPerm);
131
- } catch {
132
- }
133
- const fresh = (0, import_node_crypto.randomBytes)(installIDSize);
134
- const tmp = p + ".new";
135
- await import_node_fs.promises.writeFile(tmp, fresh, { mode: installIDFilePerm });
136
- if ((0, import_node_fs2.existsSync)(p)) {
137
- try {
138
- await import_node_fs.promises.unlink(tmp);
139
- } catch {
140
- }
141
- const data = await readAndValidate(p);
142
- return sha256Hex(data);
143
- }
144
- await import_node_fs.promises.rename(tmp, p);
145
- return sha256Hex(fresh);
146
- }
147
- async function rotate() {
148
- const p = installIdPath();
149
- const parent = path.dirname(p);
150
- await import_node_fs.promises.mkdir(parent, { recursive: true, mode: installIDDirPerm });
151
- try {
152
- await import_node_fs.promises.chmod(parent, installIDDirPerm);
153
- } catch {
154
- }
155
- const fresh = (0, import_node_crypto.randomBytes)(installIDSize);
156
- const tmp = p + ".new";
157
- await import_node_fs.promises.writeFile(tmp, fresh, { mode: installIDFilePerm });
158
- await import_node_fs.promises.rename(tmp, p);
159
- return sha256Hex(fresh);
160
- }
161
- async function resetForTest() {
162
- const p = installIdPath();
163
- try {
164
- await import_node_fs.promises.unlink(p);
165
- } catch {
166
- }
167
- try {
168
- await import_node_fs.promises.unlink(p + ".new");
169
- } catch {
170
- }
171
- }
172
5
 
173
- // src/telemetry/consent.ts
174
- var import_node_fs3 = require("fs");
175
- var import_node_fs4 = require("fs");
176
- var import_node_os2 = require("os");
177
- var path2 = __toESM(require("path"));
178
- var yaml = __toESM(require("js-yaml"));
179
- var deniedConsent = {
180
- allowed: false,
181
- promptVersion: 0,
182
- decisionSource: "config"
183
- };
184
- function xdgConfigHome() {
185
- return process.env.XDG_CONFIG_HOME ?? path2.join((0, import_node_os2.homedir)(), ".config");
186
- }
187
- function consentPath() {
188
- return path2.join(xdgConfigHome(), "kit", "config.yaml");
189
- }
190
- function legacyConsentPath() {
191
- return path2.join(xdgConfigHome(), "kit", "telemetry.yaml");
192
- }
193
- async function loadConsent() {
194
- const canonical = await readConsentBlock(consentPath(), "canonical");
195
- if (canonical !== null) {
196
- return canonical;
197
- }
198
- const legacy = await readConsentBlock(legacyConsentPath(), "legacy");
199
- if (legacy !== null) {
200
- return legacy;
201
- }
202
- return deniedConsent;
203
- }
204
- async function readConsentBlock(p, variant) {
205
- if (!(0, import_node_fs4.existsSync)(p)) {
206
- return null;
207
- }
208
- let data;
209
- try {
210
- const raw = await import_node_fs3.promises.readFile(p, "utf8");
211
- data = yaml.load(raw);
212
- } catch {
213
- return null;
214
- }
215
- if (typeof data !== "object" || data === null) {
216
- return null;
217
- }
218
- const root = data;
219
- let telemetry;
220
- if (variant === "canonical") {
221
- const kit = root.kit;
222
- if (typeof kit !== "object" || kit === null) {
223
- return null;
224
- }
225
- telemetry = kit.telemetry;
226
- } else {
227
- telemetry = root.telemetry;
228
- }
229
- if (typeof telemetry !== "object" || telemetry === null) {
230
- return null;
231
- }
232
- const block = telemetry.consent;
233
- if (typeof block !== "object" || block === null) {
234
- return null;
235
- }
236
- const c = block;
237
- const state = c.state;
238
- if (state !== "granted" && state !== "denied") {
239
- return null;
240
- }
241
- return {
242
- allowed: state === "granted",
243
- promptVersion: typeof c.prompt_version === "number" ? c.prompt_version : 0,
244
- decisionSource: typeof c.decision_source === "string" ? c.decision_source : "config",
245
- decidedAt: parseDecidedAt(c.decided_at)
246
- };
247
- }
248
- function parseDecidedAt(v) {
249
- if (typeof v === "string") {
250
- return v;
251
- }
252
- if (v instanceof Date && !Number.isNaN(v.getTime())) {
253
- return v.toISOString().replace(/\.\d{3}Z$/, "Z");
254
- }
255
- return void 0;
256
- }
257
6
 
258
- // src/telemetry/redact.ts
259
- var os = __toESM(require("os"));
260
- var TOKEN_SK = /\bsk-[A-Za-z0-9_-]{8,}\b/g;
261
- var TOKEN_GH = /\bgh[pousr]_[A-Za-z0-9_-]{16,}\b/g;
262
- var TOKEN_XOXB = /\bxoxb-[0-9]+-[0-9]+-[A-Za-z0-9]{24,}\b/g;
263
- var EMAIL = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
264
- var IPV6 = /(?<![0-9a-fA-F:])(?:(?:[0-9a-fA-F]{1,4}:){1,7}(?::[0-9a-fA-F]{1,4})+|(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4})(?![0-9a-fA-F:])/g;
265
- var IPV4 = /\b(?:\d{1,3}\.){3}\d{1,3}\b/g;
266
- function escapeRegex(s) {
267
- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
268
- }
269
- var HOME = os.homedir();
270
- var HOME_PATTERN = HOME && HOME !== "~" ? new RegExp(escapeRegex(HOME) + "([/\\w.\\-]*)", "g") : /(?!x)x/g;
271
- var REPLACEMENTS = [
272
- [TOKEN_SK, "<redacted:token>"],
273
- [TOKEN_GH, "<redacted:token>"],
274
- [TOKEN_XOXB, "<redacted:token>"],
275
- [EMAIL, "<redacted:email>"],
276
- [IPV6, "<redacted:ipv6>"],
277
- [IPV4, "<redacted:ipv4>"],
278
- [HOME_PATTERN, "$HOME$1"]
279
- ];
280
- function redactString(s) {
281
- let out = s;
282
- for (const [pat, repl] of REPLACEMENTS) {
283
- out = out.replace(pat, repl);
284
- }
285
- return out;
286
- }
287
- function redact(value) {
288
- if (typeof value === "string") return redactString(value);
289
- if (Array.isArray(value)) return value.map(redact);
290
- if (value !== null && typeof value === "object") {
291
- const out = {};
292
- for (const [k, v] of Object.entries(value)) {
293
- out[k] = redact(v);
294
- }
295
- return out;
296
- }
297
- return value;
298
- }
299
7
 
300
- // src/telemetry/client.ts
301
- var import_node_fs5 = require("fs");
302
- var import_node_os3 = require("os");
303
- var path3 = __toESM(require("path"));
304
- var yaml2 = __toESM(require("js-yaml"));
305
- var DEFAULT_QUEUE_SIZE = 1024;
306
- var FLUSH_INTERVAL_MS = 5e3;
307
- var FLUSH_BATCH_TRIGGER = 64;
308
- var HTTPS_CONNECT_TIMEOUT_MS = 5e3;
309
- var HTTPS_TOTAL_TIMEOUT_MS = 1e4;
310
- var JSONL_ROTATE_BYTES = 10 * 1024 * 1024;
311
- var FALLBACK_SDK_VERSION = "0.0.0-dev";
312
- var SCHEMA_VERSION = "1";
313
- var SDK_LANG = "ts";
314
- function defaultJsonlSinkFile() {
315
- const state = process.env.XDG_STATE_HOME ?? path3.join((0, import_node_os3.homedir)(), ".local", "state");
316
- return path3.join(state, "kit", "telemetry", "events.jsonl");
317
- }
318
- function consentAllowedSync() {
319
- if (readGrantedFrom(consentPath(), "canonical")) return true;
320
- if (readGrantedFrom(legacyConsentPath(), "legacy")) return true;
321
- return false;
322
- }
323
- function readGrantedFrom(p, variant) {
324
- if (!(0, import_node_fs5.existsSync)(p)) return false;
325
- let parsed;
326
- try {
327
- const raw = (0, import_node_fs5.readFileSync)(p, "utf8");
328
- parsed = yaml2.load(raw);
329
- } catch {
330
- return false;
331
- }
332
- if (typeof parsed !== "object" || parsed === null) return false;
333
- const root = parsed;
334
- let tel;
335
- if (variant === "canonical") {
336
- const kit = root.kit;
337
- if (typeof kit !== "object" || kit === null) return false;
338
- tel = kit.telemetry;
339
- } else {
340
- tel = root.telemetry;
341
- }
342
- if (typeof tel !== "object" || tel === null) return false;
343
- const block = tel.consent;
344
- if (typeof block !== "object" || block === null) return false;
345
- return block.state === "granted";
346
- }
347
- function resolveSdkVersion(explicit) {
348
- if (explicit && explicit.length > 0) return explicit;
349
- try {
350
- const here = __dirname;
351
- const candidates = [
352
- path3.join(here, "..", "..", "package.json"),
353
- path3.join(here, "..", "..", "..", "package.json")
354
- ];
355
- for (const candidate of candidates) {
356
- try {
357
- const raw = (0, import_node_fs5.readFileSync)(candidate, "utf8");
358
- const pkg = JSON.parse(raw);
359
- if (typeof pkg.version === "string" && pkg.version.length > 0) {
360
- return pkg.version;
361
- }
362
- } catch {
363
- }
364
- }
365
- } catch {
366
- }
367
- return FALLBACK_SDK_VERSION;
368
- }
369
- var Client = class {
370
- constructor(opts = {}) {
371
- this.queue = [];
372
- this.dropped = 0;
373
- this.flushing = false;
374
- this.closed = false;
375
- const env = process.env;
376
- this.endpoint = opts.endpoint ?? env.KIT_TELEMETRY_ENDPOINT;
377
- const rawSink = opts.sink ?? env.KIT_TELEMETRY_SINK;
378
- this.sinkKind = rawSink === "https" || rawSink === "jsonl" ? rawSink : "jsonl";
379
- this.sinkFile = opts.sinkFile ?? env.KIT_TELEMETRY_SINK_FILE ?? defaultJsonlSinkFile();
380
- const rawQueue = opts.queueSize ?? parseQueueSize(env.KIT_TELEMETRY_QUEUE_SIZE);
381
- this.queueCap = Number.isFinite(rawQueue) && rawQueue > 0 ? Math.floor(rawQueue) : DEFAULT_QUEUE_SIZE;
382
- this.userRedactor = opts.redactor;
383
- this.sdkVersion = resolveSdkVersion(opts.sdkVersion);
384
- this.flushTimer = setInterval(() => {
385
- void this.drainOnce();
386
- }, FLUSH_INTERVAL_MS);
387
- if (typeof this.flushTimer.unref === "function") {
388
- this.flushTimer.unref();
389
- }
390
- }
391
- /**
392
- * record enqueues an event for background delivery. Returns
393
- * synchronously; never throws. Gating order: closed → consent → mode.
394
- * Queue-full bumps `droppedCount` and returns silently.
395
- */
396
- record(event, attrs = {}) {
397
- if (this.closed) return;
398
- if (!consentAllowedSync()) return;
399
- const mode = resolveMode();
400
- if (mode === Mode.Off) return;
401
- if (this.queue.length >= this.queueCap) {
402
- this.dropped += 1;
403
- return;
404
- }
405
- this.queue.push({
406
- event,
407
- attrs,
408
- mode,
409
- occurred_at: (/* @__PURE__ */ new Date()).toISOString()
410
- });
411
- if (this.queue.length >= FLUSH_BATCH_TRIGGER) {
412
- setImmediate(() => void this.drainOnce());
413
- }
414
- }
415
- /** Saturation counter — reads, not writes. */
416
- get droppedCount() {
417
- return this.dropped;
418
- }
419
- /**
420
- * shutdown stops the flush timer, drains pending events to the sink,
421
- * and resolves once drained OR the timeout elapses (default 5000ms).
422
- * Idempotent.
423
- */
424
- async shutdown(timeoutMs = 5e3) {
425
- if (this.closed) return;
426
- this.closed = true;
427
- if (this.flushTimer) {
428
- clearInterval(this.flushTimer);
429
- this.flushTimer = void 0;
430
- }
431
- const deadline = Date.now() + timeoutMs;
432
- while (this.queue.length > 0 && Date.now() < deadline) {
433
- await this.drainOnce();
434
- if (this.queue.length > 0) {
435
- await new Promise((r) => setTimeout(r, 25));
436
- }
437
- }
438
- }
439
- /**
440
- * drainOnce ships every event currently in the queue (snapshot at
441
- * call time) to the configured sink. Errors bump `dropped` but never
442
- * propagate.
443
- */
444
- async drainOnce() {
445
- if (this.flushing) return;
446
- if (this.queue.length === 0) return;
447
- this.flushing = true;
448
- try {
449
- const batch = this.queue.splice(0, this.queue.length);
450
- const envelopes = await this.envelopeBatch(batch);
451
- if (envelopes.length === 0) return;
452
- if (this.sinkKind === "https") {
453
- await this.shipHttps(envelopes);
454
- } else {
455
- await this.shipJsonl(envelopes);
456
- }
457
- } catch {
458
- } finally {
459
- this.flushing = false;
460
- }
461
- }
462
- /**
463
- * envelopeBatch materialises pending records into on-wire envelopes,
464
- * applying the user redactor first and then the default `redact()`
465
- * pass. install_id is resolved lazily + cached.
466
- */
467
- async envelopeBatch(batch) {
468
- let installationId = "";
469
- try {
470
- if (!this.installIdPromise) {
471
- this.installIdPromise = getInstallId();
472
- }
473
- installationId = await this.installIdPromise;
474
- } catch {
475
- this.dropped += batch.length;
476
- return [];
477
- }
478
- return batch.map((p) => {
479
- let cleaned;
480
- if (p.mode === Mode.Anon) {
481
- cleaned = null;
482
- } else {
483
- const customised = this.userRedactor ? safeUserRedact(this.userRedactor, p.attrs, () => {
484
- this.dropped += 1;
485
- }) : p.attrs;
486
- cleaned = redact(customised);
487
- }
488
- return {
489
- schema_version: SCHEMA_VERSION,
490
- sdk_lang: SDK_LANG,
491
- sdk_version: this.sdkVersion,
492
- installation_id: installationId,
493
- mode: p.mode,
494
- occurred_at: p.occurred_at,
495
- event: p.event,
496
- attrs: cleaned
497
- };
498
- });
499
- }
500
- /**
501
- * shipHttps POSTs the batch as NDJSON. One retry on 5xx OR network
502
- * error, then drops the batch. `AbortController` enforces the
503
- * connect + total timeouts.
504
- */
505
- async shipHttps(envelopes) {
506
- if (!this.endpoint) {
507
- this.dropped += envelopes.length;
508
- return;
509
- }
510
- const body = envelopes.map((e) => JSON.stringify(e)).join("\n") + "\n";
511
- const headers = {
512
- "content-type": "application/x-ndjson",
513
- "user-agent": `kit-sdk-ts/${this.sdkVersion}`
514
- };
515
- for (let attempt = 0; attempt < 2; attempt += 1) {
516
- const total = new AbortController();
517
- const totalTimer = setTimeout(
518
- () => total.abort(),
519
- HTTPS_TOTAL_TIMEOUT_MS
520
- );
521
- const connect = setTimeout(
522
- () => total.abort(),
523
- HTTPS_CONNECT_TIMEOUT_MS
524
- );
525
- try {
526
- const res = await fetch(this.endpoint, {
527
- method: "POST",
528
- headers,
529
- body,
530
- signal: total.signal
531
- });
532
- clearTimeout(connect);
533
- clearTimeout(totalTimer);
534
- if (res.status < 500) {
535
- if (res.status >= 400) {
536
- this.dropped += envelopes.length;
537
- }
538
- return;
539
- }
540
- } catch {
541
- clearTimeout(connect);
542
- clearTimeout(totalTimer);
543
- }
544
- }
545
- this.dropped += envelopes.length;
546
- }
547
- /**
548
- * shipJsonl appends envelopes as NDJSON to `sinkFile`. Rotates to
549
- * `<sinkFile>.1` once the file crosses `JSONL_ROTATE_BYTES`. Single
550
- * append per batch keeps the I/O cost predictable.
551
- */
552
- async shipJsonl(envelopes) {
553
- await import_node_fs5.promises.mkdir(path3.dirname(this.sinkFile), { recursive: true });
554
- await this.maybeRotateJsonl();
555
- const body = envelopes.map((e) => JSON.stringify(e)).join("\n") + "\n";
556
- try {
557
- await import_node_fs5.promises.appendFile(this.sinkFile, body, { mode: 384 });
558
- } catch {
559
- this.dropped += envelopes.length;
560
- }
561
- }
562
- /** Rotate the JSONL sink when it crosses the size threshold. */
563
- async maybeRotateJsonl() {
564
- try {
565
- const stat = await import_node_fs5.promises.stat(this.sinkFile);
566
- if (stat.size < JSONL_ROTATE_BYTES) return;
567
- } catch {
568
- return;
569
- }
570
- const rotated = this.sinkFile + ".1";
571
- try {
572
- await import_node_fs5.promises.rename(this.sinkFile, rotated);
573
- } catch {
574
- }
575
- }
576
- };
577
- function parseQueueSize(raw) {
578
- if (!raw) return DEFAULT_QUEUE_SIZE;
579
- const n = Number.parseInt(raw, 10);
580
- return Number.isFinite(n) && n > 0 ? n : DEFAULT_QUEUE_SIZE;
581
- }
582
- function safeUserRedact(fn, attrs, onError) {
583
- try {
584
- return fn(attrs);
585
- } catch {
586
- onError();
587
- return attrs;
588
- }
589
- }
590
- // Annotate the CommonJS export names for ESM import in node:
591
- 0 && (module.exports = {
592
- Client,
593
- Mode,
594
- consentPath,
595
- deniedConsent,
596
- getInstallId,
597
- installIdPath,
598
- loadConsent,
599
- parseMode,
600
- redact,
601
- redactString,
602
- resetForTest,
603
- resolveMode,
604
- rotate
605
- });
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ var _chunkYOBAUCVNjs = require('../chunk-YOBAUCVN.js');
16
+ require('../chunk-KVG7YCTS.js');
17
+ require('../chunk-R5U7XKVJ.js');
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ exports.Client = _chunkYOBAUCVNjs.Client; exports.Mode = _chunkYOBAUCVNjs.Mode; exports.consentPath = _chunkYOBAUCVNjs.consentPath; exports.deniedConsent = _chunkYOBAUCVNjs.deniedConsent; exports.getInstallId = _chunkYOBAUCVNjs.getInstallId; exports.installIdPath = _chunkYOBAUCVNjs.installIdPath; exports.loadConsent = _chunkYOBAUCVNjs.loadConsent; exports.parseMode = _chunkYOBAUCVNjs.parseMode; exports.redact = _chunkYOBAUCVNjs.redact; exports.redactString = _chunkYOBAUCVNjs.redactString; exports.resetForTest = _chunkYOBAUCVNjs.resetForTest; exports.resolveMode = _chunkYOBAUCVNjs.resolveMode; exports.rotate = _chunkYOBAUCVNjs.rotate;