harnesstap 1.3.2 → 1.4.0

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 (210) hide show
  1. package/README.md +2 -0
  2. package/dist/apply-SUNDXRJ3.js +54 -0
  3. package/dist/{approve-L7IFSYBO.js → approve-FBGYQGWN.js} +14 -15
  4. package/dist/{approve-L7IFSYBO.js.map → approve-FBGYQGWN.js.map} +1 -1
  5. package/dist/{audit-PBJDK7A4.js → audit-VI4QZ6X2.js} +30 -39
  6. package/dist/{audit-PBJDK7A4.js.map → audit-VI4QZ6X2.js.map} +1 -1
  7. package/dist/{auth-OM73RLNS.js → auth-4CQCDS2W.js} +17 -19
  8. package/dist/{auth-OM73RLNS.js.map → auth-4CQCDS2W.js.map} +1 -1
  9. package/dist/bin.js +3 -3
  10. package/dist/{chunk-YRGM7RAD.js → chunk-23XSG7LI.js} +7 -11
  11. package/dist/{chunk-YRGM7RAD.js.map → chunk-23XSG7LI.js.map} +1 -1
  12. package/dist/{chunk-LDVXYN6F.js → chunk-2A36HWDE.js} +63 -13
  13. package/dist/chunk-2A36HWDE.js.map +1 -0
  14. package/dist/{chunk-QNAIDM6W.js → chunk-3FS775NP.js} +51 -4
  15. package/dist/chunk-3FS775NP.js.map +1 -0
  16. package/dist/{chunk-XCPWLGPB.js → chunk-3P6BWL5F.js} +2 -2
  17. package/dist/{chunk-JJJJ2RAD.js → chunk-43BDGVN3.js} +19 -6
  18. package/dist/chunk-43BDGVN3.js.map +1 -0
  19. package/dist/{chunk-CZ4T75PP.js → chunk-4ZQ2SCGY.js} +146 -78
  20. package/dist/chunk-4ZQ2SCGY.js.map +1 -0
  21. package/dist/{chunk-ZVANUFPF.js → chunk-6LTLYV5D.js} +353 -267
  22. package/dist/chunk-6LTLYV5D.js.map +1 -0
  23. package/dist/{chunk-OPVIX7E4.js → chunk-73OJQTBW.js} +6 -2
  24. package/dist/chunk-73OJQTBW.js.map +1 -0
  25. package/dist/{chunk-WXRPQICX.js → chunk-7HP6AAI3.js} +2 -2
  26. package/dist/{chunk-ENHDEB7Z.js → chunk-BPWFQKI5.js} +5 -7
  27. package/dist/{chunk-ENHDEB7Z.js.map → chunk-BPWFQKI5.js.map} +1 -1
  28. package/dist/{chunk-64R32MG2.js → chunk-D432JAXV.js} +44 -19
  29. package/dist/chunk-D432JAXV.js.map +1 -0
  30. package/dist/chunk-DF4Z7LAD.js +3463 -0
  31. package/dist/chunk-DF4Z7LAD.js.map +1 -0
  32. package/dist/{chunk-FUV7QYBS.js → chunk-EOPFER6N.js} +71 -318
  33. package/dist/chunk-EOPFER6N.js.map +1 -0
  34. package/dist/chunk-G6WKY2W4.js +389 -0
  35. package/dist/chunk-G6WKY2W4.js.map +1 -0
  36. package/dist/{chunk-IHW4PCDT.js → chunk-GRASK6M6.js} +5 -5
  37. package/dist/{chunk-R4PTE774.js → chunk-IE7B6Q5K.js} +33 -39
  38. package/dist/chunk-IE7B6Q5K.js.map +1 -0
  39. package/dist/{chunk-UNRR4KH5.js → chunk-IMROMZ2K.js} +6 -5
  40. package/dist/{chunk-UNRR4KH5.js.map → chunk-IMROMZ2K.js.map} +1 -1
  41. package/dist/{chunk-G5RWVZZ7.js → chunk-L6YZE5MY.js} +3 -3
  42. package/dist/{chunk-SNVAMWB7.js → chunk-M2U3J7UX.js} +7 -1
  43. package/dist/chunk-M2U3J7UX.js.map +1 -0
  44. package/dist/{chunk-AFKCNFPP.js → chunk-M4KLHJ6U.js} +16 -13
  45. package/dist/chunk-M4KLHJ6U.js.map +1 -0
  46. package/dist/{chunk-XRXFJTAT.js → chunk-MR7IOHSX.js} +16 -19
  47. package/dist/chunk-MR7IOHSX.js.map +1 -0
  48. package/dist/{chunk-UEHDEADL.js → chunk-N3VGY3T3.js} +15 -15
  49. package/dist/chunk-N3VGY3T3.js.map +1 -0
  50. package/dist/{chunk-IKAGGJEO.js → chunk-N3ZCH64F.js} +496 -10
  51. package/dist/chunk-N3ZCH64F.js.map +1 -0
  52. package/dist/{chunk-U472S6IB.js → chunk-OML4HXKT.js} +20 -22
  53. package/dist/chunk-OML4HXKT.js.map +1 -0
  54. package/dist/{chunk-3EGM4IUI.js → chunk-P2C7JPLD.js} +3 -3
  55. package/dist/{chunk-MFCZN253.js → chunk-PCMON7Y2.js} +7 -7
  56. package/dist/{chunk-FBYAIBHP.js → chunk-PNGF5EV2.js} +2 -2
  57. package/dist/{chunk-6JMVGKMD.js → chunk-QA5U36JN.js} +187 -203
  58. package/dist/chunk-QA5U36JN.js.map +1 -0
  59. package/dist/{chunk-AVZOFMJX.js → chunk-R7ZOYVN3.js} +241 -126
  60. package/dist/chunk-R7ZOYVN3.js.map +1 -0
  61. package/dist/{chunk-YVJQ2QDG.js → chunk-RDG5DT7S.js} +45 -49
  62. package/dist/{chunk-YVJQ2QDG.js.map → chunk-RDG5DT7S.js.map} +1 -1
  63. package/dist/{chunk-VQVUJYYY.js → chunk-REHRUNBB.js} +8 -3
  64. package/dist/chunk-REHRUNBB.js.map +1 -0
  65. package/dist/{chunk-Y2JGMICO.js → chunk-RFQ3N7FB.js} +19 -29
  66. package/dist/chunk-RFQ3N7FB.js.map +1 -0
  67. package/dist/{chunk-EY4ES5MG.js → chunk-RVEXPMM3.js} +3 -3
  68. package/dist/{chunk-6I3RY6R5.js → chunk-TPEJFLV7.js} +13 -15
  69. package/dist/{chunk-6I3RY6R5.js.map → chunk-TPEJFLV7.js.map} +1 -1
  70. package/dist/{chunk-IAZNF35S.js → chunk-U6DXASQP.js} +2 -2
  71. package/dist/{chunk-OQ4KBUN2.js → chunk-ULCD6DJE.js} +30 -8
  72. package/dist/chunk-ULCD6DJE.js.map +1 -0
  73. package/dist/{chunk-BXSS2S4W.js → chunk-UVVZHWD2.js} +2 -2
  74. package/dist/{chunk-24V5ZSIF.js → chunk-WG5A6EAU.js} +269 -13
  75. package/dist/chunk-WG5A6EAU.js.map +1 -0
  76. package/dist/{chunk-LGWUTV5Q.js → chunk-WGP4GUYZ.js} +10 -10
  77. package/dist/{chunk-GWQVYGRD.js → chunk-XTVGCVU4.js} +124 -83
  78. package/dist/chunk-XTVGCVU4.js.map +1 -0
  79. package/dist/{chunk-YX7MVSDA.js → chunk-XUJKZQZA.js} +8 -8
  80. package/dist/chunk-XUJKZQZA.js.map +1 -0
  81. package/dist/chunk-ZUASVASP.js +30317 -0
  82. package/dist/chunk-ZUASVASP.js.map +1 -0
  83. package/dist/{compile-SDOASKGL.js → compile-GXADKGH5.js} +37 -50
  84. package/dist/{compile-SDOASKGL.js.map → compile-GXADKGH5.js.map} +1 -1
  85. package/dist/{config-4VZTVZKF.js → config-JMHNA2U5.js} +22 -35
  86. package/dist/{config-4VZTVZKF.js.map → config-JMHNA2U5.js.map} +1 -1
  87. package/dist/cursor-local-install-46RWRBDT.js +98 -0
  88. package/dist/cursor-local-install-46RWRBDT.js.map +1 -0
  89. package/dist/{doctor-HH6CFBRQ.js → doctor-N7ZULPOL.js} +18 -19
  90. package/dist/{doctor-HH6CFBRQ.js.map → doctor-N7ZULPOL.js.map} +1 -1
  91. package/dist/{environment-K7YMJJYN.js → environment-OBB3WU5B.js} +60 -71
  92. package/dist/{environment-K7YMJJYN.js.map → environment-OBB3WU5B.js.map} +1 -1
  93. package/dist/{github-A6TYG7WS.js → github-PBYBGOLH.js} +17 -17
  94. package/dist/{harness-772XBFZQ.js → harness-7KYATIV6.js} +56 -67
  95. package/dist/{harness-772XBFZQ.js.map → harness-7KYATIV6.js.map} +1 -1
  96. package/dist/{help-QR4VTJZU.js → help-EE3AJQD4.js} +48 -52
  97. package/dist/help-EE3AJQD4.js.map +1 -0
  98. package/dist/{help-TLHNRJJ6.js → help-VXWKLQ6A.js} +55 -15
  99. package/dist/help-VXWKLQ6A.js.map +1 -0
  100. package/dist/index.d.ts +7 -0
  101. package/dist/index.js +16 -24
  102. package/dist/{init-AOKFPZHG.js → init-LBTMPDVJ.js} +43 -56
  103. package/dist/init-LBTMPDVJ.js.map +1 -0
  104. package/dist/live-read-cache-TUSP7U3D.js +10 -0
  105. package/dist/{lock-INAXNLMC.js → lock-WLJRXRVK.js} +16 -16
  106. package/dist/{marketplace-TUVLLPBG.js → marketplace-GXSV6QIY.js} +62 -28
  107. package/dist/marketplace-GXSV6QIY.js.map +1 -0
  108. package/dist/{mcp-MMWGRASN.js → mcp-XPDWWU75.js} +35 -48
  109. package/dist/{mcp-MMWGRASN.js.map → mcp-XPDWWU75.js.map} +1 -1
  110. package/dist/{migrate-55S4XODX.js → migrate-SBUIWN3U.js} +79 -64
  111. package/dist/migrate-SBUIWN3U.js.map +1 -0
  112. package/dist/open-HDGLYYVU.js +24 -0
  113. package/dist/{pack-VZIBS42E.js → pack-A73LDVOX.js} +16 -22
  114. package/dist/{pack-VZIBS42E.js.map → pack-A73LDVOX.js.map} +1 -1
  115. package/dist/plugin-CEO6ZJM5.js +51 -0
  116. package/dist/plugin-from-project-UK7VJVUP.js +18 -0
  117. package/dist/{policy-P3HGLEZS.js → policy-6VY3CMSU.js} +13 -14
  118. package/dist/{policy-P3HGLEZS.js.map → policy-6VY3CMSU.js.map} +1 -1
  119. package/dist/{profile-STS3CZUK.js → profile-YCKPMRRU.js} +96 -102
  120. package/dist/profile-YCKPMRRU.js.map +1 -0
  121. package/dist/{project-R4DGM3ZG.js → project-KHPPBKPN.js} +63 -77
  122. package/dist/{project-R4DGM3ZG.js.map → project-KHPPBKPN.js.map} +1 -1
  123. package/dist/{resource-GJVEDXVZ.js → resource-IJU3FAN5.js} +42 -49
  124. package/dist/{resource-GJVEDXVZ.js.map → resource-IJU3FAN5.js.map} +1 -1
  125. package/dist/{version-FUHV4O6U.js → version-Z66FWWMQ.js} +2 -2
  126. package/dist/version-Z66FWWMQ.js.map +1 -0
  127. package/package.json +3 -2
  128. package/dist/apply-Q5SFF3FY.js +0 -67
  129. package/dist/chunk-24V5ZSIF.js.map +0 -1
  130. package/dist/chunk-3JOPDYQD.js +0 -730
  131. package/dist/chunk-3JOPDYQD.js.map +0 -1
  132. package/dist/chunk-555XE3NJ.js +0 -60
  133. package/dist/chunk-555XE3NJ.js.map +0 -1
  134. package/dist/chunk-64R32MG2.js.map +0 -1
  135. package/dist/chunk-6JMVGKMD.js.map +0 -1
  136. package/dist/chunk-6ZWKF3YZ.js +0 -7795
  137. package/dist/chunk-6ZWKF3YZ.js.map +0 -1
  138. package/dist/chunk-AFKCNFPP.js.map +0 -1
  139. package/dist/chunk-AUWWL6KX.js +0 -296
  140. package/dist/chunk-AUWWL6KX.js.map +0 -1
  141. package/dist/chunk-AVZOFMJX.js.map +0 -1
  142. package/dist/chunk-CZ4T75PP.js.map +0 -1
  143. package/dist/chunk-FUV7QYBS.js.map +0 -1
  144. package/dist/chunk-GWQVYGRD.js.map +0 -1
  145. package/dist/chunk-HENOKIBB.js +0 -346
  146. package/dist/chunk-HENOKIBB.js.map +0 -1
  147. package/dist/chunk-HWL67OCJ.js +0 -238
  148. package/dist/chunk-HWL67OCJ.js.map +0 -1
  149. package/dist/chunk-IKAGGJEO.js.map +0 -1
  150. package/dist/chunk-JJJJ2RAD.js.map +0 -1
  151. package/dist/chunk-JRFUTIEH.js +0 -426
  152. package/dist/chunk-JRFUTIEH.js.map +0 -1
  153. package/dist/chunk-KJIFZLHN.js +0 -11066
  154. package/dist/chunk-KJIFZLHN.js.map +0 -1
  155. package/dist/chunk-LDVXYN6F.js.map +0 -1
  156. package/dist/chunk-MHOTXMD2.js +0 -430
  157. package/dist/chunk-MHOTXMD2.js.map +0 -1
  158. package/dist/chunk-NEPUP33Q.js +0 -35
  159. package/dist/chunk-NEPUP33Q.js.map +0 -1
  160. package/dist/chunk-OPVIX7E4.js.map +0 -1
  161. package/dist/chunk-OQ4KBUN2.js.map +0 -1
  162. package/dist/chunk-OXVCYRZB.js +0 -491
  163. package/dist/chunk-OXVCYRZB.js.map +0 -1
  164. package/dist/chunk-PJQAMC6L.js +0 -183
  165. package/dist/chunk-PJQAMC6L.js.map +0 -1
  166. package/dist/chunk-PW5QXRBA.js +0 -1173
  167. package/dist/chunk-PW5QXRBA.js.map +0 -1
  168. package/dist/chunk-QNAIDM6W.js.map +0 -1
  169. package/dist/chunk-R4PTE774.js.map +0 -1
  170. package/dist/chunk-S2E4KSYW.js +0 -610
  171. package/dist/chunk-S2E4KSYW.js.map +0 -1
  172. package/dist/chunk-SNVAMWB7.js.map +0 -1
  173. package/dist/chunk-U472S6IB.js.map +0 -1
  174. package/dist/chunk-UEHDEADL.js.map +0 -1
  175. package/dist/chunk-VQVUJYYY.js.map +0 -1
  176. package/dist/chunk-XRXFJTAT.js.map +0 -1
  177. package/dist/chunk-Y2JGMICO.js.map +0 -1
  178. package/dist/chunk-YX7MVSDA.js.map +0 -1
  179. package/dist/chunk-ZGRBIBO7.js +0 -681
  180. package/dist/chunk-ZGRBIBO7.js.map +0 -1
  181. package/dist/chunk-ZTBAMBAI.js +0 -6448
  182. package/dist/chunk-ZTBAMBAI.js.map +0 -1
  183. package/dist/chunk-ZVANUFPF.js.map +0 -1
  184. package/dist/help-QR4VTJZU.js.map +0 -1
  185. package/dist/help-TLHNRJJ6.js.map +0 -1
  186. package/dist/init-AOKFPZHG.js.map +0 -1
  187. package/dist/marketplace-TUVLLPBG.js.map +0 -1
  188. package/dist/migrate-55S4XODX.js.map +0 -1
  189. package/dist/open-SLFQV45J.js +0 -32
  190. package/dist/plugin-WLEFFBRY.js +0 -64
  191. package/dist/plugin-from-project-UV2O364T.js +0 -16
  192. package/dist/profile-STS3CZUK.js.map +0 -1
  193. /package/dist/{apply-Q5SFF3FY.js.map → apply-SUNDXRJ3.js.map} +0 -0
  194. /package/dist/{chunk-XCPWLGPB.js.map → chunk-3P6BWL5F.js.map} +0 -0
  195. /package/dist/{chunk-WXRPQICX.js.map → chunk-7HP6AAI3.js.map} +0 -0
  196. /package/dist/{chunk-IHW4PCDT.js.map → chunk-GRASK6M6.js.map} +0 -0
  197. /package/dist/{chunk-G5RWVZZ7.js.map → chunk-L6YZE5MY.js.map} +0 -0
  198. /package/dist/{chunk-3EGM4IUI.js.map → chunk-P2C7JPLD.js.map} +0 -0
  199. /package/dist/{chunk-MFCZN253.js.map → chunk-PCMON7Y2.js.map} +0 -0
  200. /package/dist/{chunk-FBYAIBHP.js.map → chunk-PNGF5EV2.js.map} +0 -0
  201. /package/dist/{chunk-EY4ES5MG.js.map → chunk-RVEXPMM3.js.map} +0 -0
  202. /package/dist/{chunk-IAZNF35S.js.map → chunk-U6DXASQP.js.map} +0 -0
  203. /package/dist/{chunk-BXSS2S4W.js.map → chunk-UVVZHWD2.js.map} +0 -0
  204. /package/dist/{chunk-LGWUTV5Q.js.map → chunk-WGP4GUYZ.js.map} +0 -0
  205. /package/dist/{github-A6TYG7WS.js.map → github-PBYBGOLH.js.map} +0 -0
  206. /package/dist/{open-SLFQV45J.js.map → live-read-cache-TUSP7U3D.js.map} +0 -0
  207. /package/dist/{lock-INAXNLMC.js.map → lock-WLJRXRVK.js.map} +0 -0
  208. /package/dist/{plugin-WLEFFBRY.js.map → open-HDGLYYVU.js.map} +0 -0
  209. /package/dist/{plugin-from-project-UV2O364T.js.map → plugin-CEO6ZJM5.js.map} +0 -0
  210. /package/dist/{version-FUHV4O6U.js.map → plugin-from-project-UK7VJVUP.js.map} +0 -0
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  parseJsonc
3
- } from "./chunk-VQVUJYYY.js";
3
+ } from "./chunk-REHRUNBB.js";
4
4
  import {
5
5
  PACKAGE_VERSION,
6
6
  fetchWithTimeout,
7
7
  getHarnesstapDir
8
- } from "./chunk-24V5ZSIF.js";
8
+ } from "./chunk-WG5A6EAU.js";
9
9
 
10
10
  // src/config/catalog.ts
11
11
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -641,15 +641,21 @@ async function readResponseBody(response) {
641
641
  return { body: {}, text };
642
642
  }
643
643
  }
644
- function describeApiFailure(response, body, text) {
644
+ function apiErrorText(body, text) {
645
645
  const parsed = parseApiError(body);
646
646
  if (parsed !== "{}") {
647
- return `${response.status} ${parsed}`;
647
+ return parsed;
648
648
  }
649
649
  const trimmed = text.trim();
650
- if (trimmed) {
651
- const preview = trimmed.length > 240 ? `${trimmed.slice(0, 240)}...` : trimmed;
652
- return `${response.status} ${preview}`;
650
+ if (!trimmed) {
651
+ return void 0;
652
+ }
653
+ return trimmed.length > 240 ? `${trimmed.slice(0, 240)}...` : trimmed;
654
+ }
655
+ function describeApiFailure(response, body, text) {
656
+ const detail = apiErrorText(body, text);
657
+ if (detail) {
658
+ return `${response.status} ${detail}`;
653
659
  }
654
660
  return `${response.status} empty response (try again)`;
655
661
  }
@@ -747,7 +753,7 @@ async function pollDeviceTokenOnce(baseUrl, deviceCode, opts) {
747
753
  }
748
754
  return {
749
755
  status: "error",
750
- message: `Failed to poll device token: ${describeApiFailure(response, body, text)}`
756
+ message: `Failed to poll device token: ${apiErrorText(body, text) ?? describeApiFailure(response, body, text)}`
751
757
  };
752
758
  }
753
759
  async function pollDeviceToken(baseUrl, deviceCode, opts) {
@@ -1093,6 +1099,473 @@ async function createPersistingCloudClient(accountName) {
1093
1099
  return { accountName: ensured.accountName, client };
1094
1100
  }
1095
1101
 
1102
+ // src/telemetry/config.ts
1103
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
1104
+ import { join as join3 } from "path";
1105
+ var DEFAULT_POSTHOG_PROJECT_API_KEY = "phc_qNGtvTMWscMjjt9yVoK2kySDnpCyMSNb4nNkkXabRtYv";
1106
+ var DEFAULT_POSTHOG_HOST = "https://eu.i.posthog.com";
1107
+ var FALSEY = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
1108
+ var TRUTHY = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
1109
+ function telemetryEnvFlag(name = "HARNESSTAP_TELEMETRY") {
1110
+ const raw = process.env[name]?.trim().toLowerCase();
1111
+ if (!raw) {
1112
+ return void 0;
1113
+ }
1114
+ if (FALSEY.has(raw)) {
1115
+ return false;
1116
+ }
1117
+ if (TRUTHY.has(raw)) {
1118
+ return true;
1119
+ }
1120
+ return void 0;
1121
+ }
1122
+ function telemetryConfigPath(harnesstapDir) {
1123
+ const jsoncPath = join3(harnesstapDir, "config.jsonc");
1124
+ const jsonPath = join3(harnesstapDir, "config.json");
1125
+ if (existsSync2(jsoncPath) || !existsSync2(jsonPath)) {
1126
+ return jsoncPath;
1127
+ }
1128
+ return jsonPath;
1129
+ }
1130
+ function readTelemetryConfigPreference(harnesstapDir) {
1131
+ const path = telemetryConfigPath(harnesstapDir);
1132
+ if (!existsSync2(path)) {
1133
+ return void 0;
1134
+ }
1135
+ try {
1136
+ const raw = parseJsonc(readFileSync2(path, "utf-8"));
1137
+ if (typeof raw.telemetry?.enabled === "boolean") {
1138
+ return raw.telemetry.enabled;
1139
+ }
1140
+ return void 0;
1141
+ } catch {
1142
+ return void 0;
1143
+ }
1144
+ }
1145
+ function isTelemetryEnabled(harnesstapDir = getHarnesstapDir()) {
1146
+ const env = telemetryEnvFlag();
1147
+ if (env === false) {
1148
+ return false;
1149
+ }
1150
+ if (env === true) {
1151
+ return Boolean(resolvePosthogProjectApiKey());
1152
+ }
1153
+ const preference = readTelemetryConfigPreference(harnesstapDir);
1154
+ if (preference !== true) {
1155
+ return false;
1156
+ }
1157
+ return Boolean(resolvePosthogProjectApiKey());
1158
+ }
1159
+ function resolvePosthogProjectApiKey() {
1160
+ if (Object.hasOwn(process.env, "HARNESSTAP_POSTHOG_PROJECT_API_KEY")) {
1161
+ const override = process.env.HARNESSTAP_POSTHOG_PROJECT_API_KEY?.trim();
1162
+ return override && override.length > 0 ? override : void 0;
1163
+ }
1164
+ return DEFAULT_POSTHOG_PROJECT_API_KEY;
1165
+ }
1166
+ function resolvePosthogHost() {
1167
+ const override = process.env.HARNESSTAP_POSTHOG_HOST?.trim();
1168
+ if (override) {
1169
+ return override.replace(/\/+$/, "");
1170
+ }
1171
+ return DEFAULT_POSTHOG_HOST;
1172
+ }
1173
+ function resolvePosthogCaptureUrl() {
1174
+ return `${resolvePosthogHost()}/capture/`;
1175
+ }
1176
+
1177
+ // src/telemetry/sanitize.ts
1178
+ var SECRET_KEY = /(token|secret|password|passwd|authorization|cookie|api[_-]?key|refresh|bearer|email)/i;
1179
+ var BLOCKED_KEY = /^(plugin_slug|org_id|path|filepath|file_path|content|contents|mcp|mcp_config)$/i;
1180
+ function looksLikeEmail(value) {
1181
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
1182
+ }
1183
+ function shortReason(error) {
1184
+ const raw = error instanceof Error ? error.message : String(error);
1185
+ return raw.replace(/Bearer\s+\S+/gi, "Bearer [redacted]").replace(/\s+/g, " ").trim().slice(0, 80);
1186
+ }
1187
+ function sanitizeTelemetryProps(props) {
1188
+ const next = {};
1189
+ for (const [key, value] of Object.entries(props)) {
1190
+ if (SECRET_KEY.test(key) || BLOCKED_KEY.test(key)) {
1191
+ continue;
1192
+ }
1193
+ if (typeof value === "string") {
1194
+ if (looksLikeEmail(value)) {
1195
+ continue;
1196
+ }
1197
+ next[key] = value.slice(0, 200);
1198
+ continue;
1199
+ }
1200
+ next[key] = value;
1201
+ }
1202
+ return next;
1203
+ }
1204
+ function extractCloudUserId(whoami, accountUserId) {
1205
+ if (accountUserId && !looksLikeEmail(accountUserId)) {
1206
+ return accountUserId;
1207
+ }
1208
+ if (!whoami) {
1209
+ return void 0;
1210
+ }
1211
+ const user = typeof whoami.user === "object" && whoami.user !== null ? whoami.user : void 0;
1212
+ const candidates = [user?.id, whoami.user_id, whoami.id, whoami.sub];
1213
+ for (const candidate of candidates) {
1214
+ if (typeof candidate === "string" && candidate.trim() && !looksLikeEmail(candidate)) {
1215
+ return candidate.trim();
1216
+ }
1217
+ }
1218
+ return void 0;
1219
+ }
1220
+
1221
+ // src/telemetry/capture.ts
1222
+ import http from "http";
1223
+ import https from "https";
1224
+
1225
+ // src/telemetry/product.ts
1226
+ var productOverride;
1227
+ function setTelemetryProduct(product) {
1228
+ productOverride = product;
1229
+ }
1230
+ function resolveTelemetryProduct() {
1231
+ if (productOverride) {
1232
+ return productOverride;
1233
+ }
1234
+ const env = process.env.HARNESSTAP_PRODUCT?.trim().toLowerCase();
1235
+ if (env === "cli" || env === "desktop") {
1236
+ return env;
1237
+ }
1238
+ const exe = `${process.argv[1] ?? ""} ${process.execPath}`;
1239
+ if (exe.includes("ht-agent")) {
1240
+ return "desktop";
1241
+ }
1242
+ return "cli";
1243
+ }
1244
+
1245
+ // src/telemetry/state.ts
1246
+ import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
1247
+ import { randomUUID } from "crypto";
1248
+ import { join as join4 } from "path";
1249
+ function statePath(harnesstapDir) {
1250
+ return join4(harnesstapDir, "telemetry-state.json");
1251
+ }
1252
+ function isRecord(value) {
1253
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1254
+ }
1255
+ function stringField(value) {
1256
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
1257
+ }
1258
+ function loadTelemetryState(harnesstapDir = getHarnesstapDir()) {
1259
+ const path = statePath(harnesstapDir);
1260
+ if (!existsSync3(path)) {
1261
+ return { distinct_id: randomUUID() };
1262
+ }
1263
+ try {
1264
+ const parsed = JSON.parse(readFileSync3(path, "utf-8"));
1265
+ if (!isRecord(parsed)) {
1266
+ return { distinct_id: randomUUID() };
1267
+ }
1268
+ return {
1269
+ distinct_id: stringField(parsed.distinct_id) ?? randomUUID(),
1270
+ ...stringField(parsed.identified_distinct_id) ? { identified_distinct_id: stringField(parsed.identified_distinct_id) } : {},
1271
+ ...stringField(parsed.cli_installed_at) ? { cli_installed_at: stringField(parsed.cli_installed_at) } : {},
1272
+ ...stringField(parsed.cli_first_run_at) ? { cli_first_run_at: stringField(parsed.cli_first_run_at) } : {},
1273
+ ...stringField(parsed.desktop_installed_at) ? { desktop_installed_at: stringField(parsed.desktop_installed_at) } : {},
1274
+ ...stringField(parsed.desktop_first_open_at) ? { desktop_first_open_at: stringField(parsed.desktop_first_open_at) } : {},
1275
+ ...stringField(parsed.cli_notice_shown_at) ? { cli_notice_shown_at: stringField(parsed.cli_notice_shown_at) } : {}
1276
+ };
1277
+ } catch {
1278
+ return { distinct_id: randomUUID() };
1279
+ }
1280
+ }
1281
+ function saveTelemetryState(state, harnesstapDir = getHarnesstapDir()) {
1282
+ mkdirSync(harnesstapDir, { recursive: true });
1283
+ writeFileSync2(statePath(harnesstapDir), `${JSON.stringify(state, null, 2)}
1284
+ `);
1285
+ }
1286
+ function updateTelemetryState(patch, harnesstapDir = getHarnesstapDir()) {
1287
+ const current = loadTelemetryState(harnesstapDir);
1288
+ const next = { ...current, ...patch };
1289
+ saveTelemetryState(next, harnesstapDir);
1290
+ return next;
1291
+ }
1292
+ function resolveDistinctId(harnesstapDir = getHarnesstapDir()) {
1293
+ const current = loadTelemetryState(harnesstapDir);
1294
+ if (current.identified_distinct_id) {
1295
+ return current.identified_distinct_id;
1296
+ }
1297
+ saveTelemetryState(current, harnesstapDir);
1298
+ return current.distinct_id;
1299
+ }
1300
+
1301
+ // src/telemetry/capture.ts
1302
+ var CAPTURE_TIMEOUT_MS = 800;
1303
+ var transportOverride;
1304
+ function unrefSocketRequest(url, body) {
1305
+ const parsed = new URL(url);
1306
+ const client = parsed.protocol === "https:" ? https : http;
1307
+ const request = client.request(
1308
+ {
1309
+ protocol: parsed.protocol,
1310
+ hostname: parsed.hostname,
1311
+ port: parsed.port,
1312
+ path: `${parsed.pathname}${parsed.search}`,
1313
+ method: "POST",
1314
+ headers: {
1315
+ "content-type": "application/json",
1316
+ "content-length": Buffer.byteLength(body)
1317
+ },
1318
+ timeout: CAPTURE_TIMEOUT_MS
1319
+ },
1320
+ (response) => {
1321
+ response.resume();
1322
+ }
1323
+ );
1324
+ request.on("error", () => void 0);
1325
+ request.on("timeout", () => {
1326
+ request.destroy();
1327
+ });
1328
+ request.on("socket", (socket) => {
1329
+ socket.unref();
1330
+ });
1331
+ request.end(body);
1332
+ }
1333
+ function defaultTelemetryTransport() {
1334
+ return {
1335
+ send(url, body) {
1336
+ unrefSocketRequest(url, body);
1337
+ }
1338
+ };
1339
+ }
1340
+ function transport() {
1341
+ return transportOverride ?? defaultTelemetryTransport();
1342
+ }
1343
+ function baseTelemetryProperties() {
1344
+ return {
1345
+ product: resolveTelemetryProduct(),
1346
+ app_version: PACKAGE_VERSION,
1347
+ os: process.platform,
1348
+ $lib: "harnesstap",
1349
+ $ip: null
1350
+ };
1351
+ }
1352
+ function captureEvent(event, properties = {}) {
1353
+ try {
1354
+ if (!isTelemetryEnabled()) {
1355
+ return;
1356
+ }
1357
+ const apiKey = resolvePosthogProjectApiKey();
1358
+ if (!apiKey) {
1359
+ return;
1360
+ }
1361
+ const payload = {
1362
+ api_key: apiKey,
1363
+ event,
1364
+ distinct_id: resolveDistinctId(),
1365
+ properties: sanitizeTelemetryProps({
1366
+ ...baseTelemetryProperties(),
1367
+ ...properties
1368
+ })
1369
+ };
1370
+ transport().send(resolvePosthogCaptureUrl(), JSON.stringify(payload));
1371
+ } catch {
1372
+ }
1373
+ }
1374
+
1375
+ // src/telemetry/install-method.ts
1376
+ var INSTALL_METHODS = /* @__PURE__ */ new Set([
1377
+ "brew",
1378
+ "npm",
1379
+ "bun",
1380
+ "npx",
1381
+ "curl",
1382
+ "unknown"
1383
+ ]);
1384
+ function isCliInstallMethod(value) {
1385
+ return INSTALL_METHODS.has(value);
1386
+ }
1387
+ function detectCliInstallMethod() {
1388
+ const override = process.env.HARNESSTAP_INSTALL_METHOD?.trim().toLowerCase();
1389
+ if (override && isCliInstallMethod(override)) {
1390
+ return override;
1391
+ }
1392
+ const haystack = [
1393
+ process.execPath,
1394
+ process.argv[1] ?? "",
1395
+ process.env.npm_execpath ?? "",
1396
+ process.env.npm_command ?? ""
1397
+ ].join(" ").toLowerCase();
1398
+ if (haystack.includes("npx")) {
1399
+ return "npx";
1400
+ }
1401
+ if (haystack.includes("/cellar/") || haystack.includes("homebrew")) {
1402
+ return "brew";
1403
+ }
1404
+ if (haystack.includes("bun")) {
1405
+ return "bun";
1406
+ }
1407
+ if (haystack.includes("node_modules") || haystack.includes("npm") || process.execPath.toLowerCase().includes("node") && haystack.includes("harnesstap")) {
1408
+ return "npm";
1409
+ }
1410
+ return "unknown";
1411
+ }
1412
+
1413
+ // src/telemetry/track.ts
1414
+ function trackCliStartup() {
1415
+ try {
1416
+ if (!isTelemetryEnabled()) {
1417
+ return;
1418
+ }
1419
+ const state = loadTelemetryState();
1420
+ const version = PACKAGE_VERSION;
1421
+ if (!state.cli_installed_at) {
1422
+ captureEvent("cli_installed", {
1423
+ install_method: detectCliInstallMethod(),
1424
+ version
1425
+ });
1426
+ }
1427
+ if (!state.cli_first_run_at) {
1428
+ captureEvent("cli_first_run", { version });
1429
+ }
1430
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1431
+ updateTelemetryState({
1432
+ ...state.cli_installed_at ? {} : { cli_installed_at: now },
1433
+ ...state.cli_first_run_at ? {} : { cli_first_run_at: now }
1434
+ });
1435
+ } catch {
1436
+ }
1437
+ }
1438
+ function trackCloudConnectStarted() {
1439
+ captureEvent("cloud_connect_started", {});
1440
+ }
1441
+ function trackCloudConnectFailed(reason, errorCode) {
1442
+ captureEvent("cloud_connect_failed", {
1443
+ reason,
1444
+ ...errorCode ? { error_code: errorCode } : {}
1445
+ });
1446
+ }
1447
+ function identifyFromCloudWhoami(input) {
1448
+ try {
1449
+ return extractCloudUserId(input.whoami, input.userId);
1450
+ } catch {
1451
+ return void 0;
1452
+ }
1453
+ }
1454
+ function trackCloudConnected(_input) {
1455
+ captureEvent("cloud_connected", {});
1456
+ captureEvent("signed_in", {});
1457
+ }
1458
+ function trackPluginInstalled(input) {
1459
+ void input.pluginSlug;
1460
+ void input.orgId;
1461
+ captureEvent("plugin_installed", { source: input.source });
1462
+ }
1463
+ function trackPluginApplied(input) {
1464
+ void input.pluginSlug;
1465
+ void input.orgId;
1466
+ captureEvent("plugin_applied", {
1467
+ ...input.harness ? { harness: input.harness } : {}
1468
+ });
1469
+ }
1470
+ function trackPluginUsed(input) {
1471
+ void input.pluginSlug;
1472
+ void input.orgId;
1473
+ captureEvent("plugin_used", {
1474
+ ...input.harness ? { harness: input.harness } : {}
1475
+ });
1476
+ }
1477
+
1478
+ // src/telemetry/copy.ts
1479
+ var TELEMETRY_SCOPE_SUMMARY = "HarnessTap can send anonymous product analytics to our EU PostHog project so we can see how the product is used.";
1480
+ var TELEMETRY_TRACKED_LINES = [
1481
+ "Which product you used (CLI or Desktop), version, and operating system",
1482
+ "How the CLI was installed",
1483
+ "HarnessTap Cloud interactions",
1484
+ "Plugin install, apply, and view occurrences"
1485
+ ];
1486
+ var TELEMETRY_NOT_TRACKED_LINES = [
1487
+ "No personal data: names, emails, file paths, code, secrets, or MCP configs",
1488
+ "No resource-related information: plugin names, contents, or organization ids"
1489
+ ];
1490
+ var TELEMETRY_CLI_DISABLE_INSTRUCTIONS = 'Disable with HARNESSTAP_TELEMETRY=0 or set "telemetry": { "enabled": false } in ~/.harnesstap/config.jsonc.';
1491
+ var TELEMETRY_CLI_ENABLE_INSTRUCTIONS = 'Enable with HARNESSTAP_TELEMETRY=1 or set "telemetry": { "enabled": true } in ~/.harnesstap/config.jsonc.';
1492
+ function formatTelemetryScopeBody() {
1493
+ return [
1494
+ TELEMETRY_SCOPE_SUMMARY,
1495
+ "",
1496
+ "What we track:",
1497
+ ...TELEMETRY_TRACKED_LINES.map((line) => `\u2022 ${line}`),
1498
+ "",
1499
+ "What we do not track:",
1500
+ ...TELEMETRY_NOT_TRACKED_LINES.map((line) => `\u2022 ${line}`)
1501
+ ].join("\n");
1502
+ }
1503
+ function formatCliTelemetryEnabledWarning() {
1504
+ return [
1505
+ "Anonymous usage telemetry is on.",
1506
+ formatTelemetryScopeBody(),
1507
+ TELEMETRY_CLI_DISABLE_INSTRUCTIONS
1508
+ ].join("\n");
1509
+ }
1510
+ function formatCliTelemetryUnsettledWarning() {
1511
+ return [
1512
+ "Anonymous usage telemetry is off until you opt in. No events are sent yet.",
1513
+ formatTelemetryScopeBody(),
1514
+ TELEMETRY_CLI_ENABLE_INSTRUCTIONS,
1515
+ TELEMETRY_CLI_DISABLE_INSTRUCTIONS
1516
+ ].join("\n");
1517
+ }
1518
+
1519
+ // src/telemetry/notice.ts
1520
+ var noticePrinter;
1521
+ function argvRequestsJson(argv) {
1522
+ for (let i = 0; i < argv.length; i++) {
1523
+ const arg = argv[i];
1524
+ if (arg === "--json" || arg === "--format=json") {
1525
+ return true;
1526
+ }
1527
+ if (arg === "--format" && argv[i + 1] === "json") {
1528
+ return true;
1529
+ }
1530
+ }
1531
+ return false;
1532
+ }
1533
+ function maybeWarnCliTelemetry(harnesstapDir = getHarnesstapDir(), opts) {
1534
+ try {
1535
+ const argv = opts?.argv ?? process.argv;
1536
+ const stdoutIsTTY = opts?.stdoutIsTTY ?? Boolean(process.stdout.isTTY);
1537
+ const skipForMachineOutput = argvRequestsJson(argv) || !stdoutIsTTY;
1538
+ if (skipForMachineOutput && !noticePrinter) {
1539
+ return;
1540
+ }
1541
+ const env = telemetryEnvFlag();
1542
+ if (env === false) {
1543
+ return;
1544
+ }
1545
+ const preference = readTelemetryConfigPreference(harnesstapDir);
1546
+ const enabled = isTelemetryEnabled(harnesstapDir);
1547
+ const unsettled = env === void 0 && preference === void 0;
1548
+ if (!enabled && !unsettled) {
1549
+ return;
1550
+ }
1551
+ const state = loadTelemetryState(harnesstapDir);
1552
+ if (state.cli_notice_shown_at) {
1553
+ return;
1554
+ }
1555
+ const message = enabled ? formatCliTelemetryEnabledWarning() : formatCliTelemetryUnsettledWarning();
1556
+ (noticePrinter ?? ((text) => {
1557
+ console.error(text);
1558
+ }))(message);
1559
+ updateTelemetryState(
1560
+ {
1561
+ cli_notice_shown_at: (/* @__PURE__ */ new Date()).toISOString()
1562
+ },
1563
+ harnesstapDir
1564
+ );
1565
+ } catch {
1566
+ }
1567
+ }
1568
+
1096
1569
  export {
1097
1570
  DEFAULT_CATALOG_SLUG,
1098
1571
  parsePluginSelector,
@@ -1135,6 +1608,19 @@ export {
1135
1608
  createCloudClient,
1136
1609
  ensureCloudAccountAccess,
1137
1610
  forceRefreshCloudAccountAccess,
1138
- createPersistingCloudClient
1611
+ createPersistingCloudClient,
1612
+ isTelemetryEnabled,
1613
+ setTelemetryProduct,
1614
+ shortReason,
1615
+ extractCloudUserId,
1616
+ maybeWarnCliTelemetry,
1617
+ trackCliStartup,
1618
+ trackCloudConnectStarted,
1619
+ trackCloudConnectFailed,
1620
+ identifyFromCloudWhoami,
1621
+ trackCloudConnected,
1622
+ trackPluginInstalled,
1623
+ trackPluginApplied,
1624
+ trackPluginUsed
1139
1625
  };
1140
- //# sourceMappingURL=chunk-IKAGGJEO.js.map
1626
+ //# sourceMappingURL=chunk-N3ZCH64F.js.map