tenjin-cli 0.1.0-alpha.15 → 0.1.0-alpha.16

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 (267) hide show
  1. package/NOTICE.md +54 -7
  2. package/README.md +41 -310
  3. package/dist/{_esm-N4KAVXQR.js → _esm-CE7KNONL.js} +9 -10
  4. package/dist/{ccip-ZGGWQN4X.js → ccip-7RMRLAGV.js} +4 -4
  5. package/dist/{ccip-RPPPKTJR.js → ccip-NLCSCHKI.js} +5 -5
  6. package/dist/chunk-25TJPVBF.js +353 -0
  7. package/dist/chunk-25TJPVBF.js.map +1 -0
  8. package/dist/chunk-2BKS2FVE.js +93 -0
  9. package/dist/chunk-2BKS2FVE.js.map +1 -0
  10. package/dist/chunk-2QYORQBF.js +55 -0
  11. package/dist/chunk-2QYORQBF.js.map +1 -0
  12. package/dist/{chunk-NIKXHWOL.js → chunk-2U5ZVEV3.js} +16 -16
  13. package/dist/chunk-2U5ZVEV3.js.map +1 -0
  14. package/dist/{chunk-HPJGOLTN.js → chunk-3AJS6LLN.js} +13 -8
  15. package/dist/chunk-3AJS6LLN.js.map +1 -0
  16. package/dist/{chunk-KINZ23CV.js → chunk-3AUDA53C.js} +4740 -23
  17. package/dist/chunk-3AUDA53C.js.map +1 -0
  18. package/dist/{chunk-MJZZTKCC.js → chunk-56MOAIP5.js} +5 -10
  19. package/dist/chunk-56MOAIP5.js.map +1 -0
  20. package/dist/{chunk-U5S527PP.js → chunk-5IEP5EGE.js} +3 -3
  21. package/dist/chunk-5X4SZ5BF.js +227 -0
  22. package/dist/chunk-5X4SZ5BF.js.map +1 -0
  23. package/dist/chunk-7WEQQJLG.js +68 -0
  24. package/dist/chunk-7WEQQJLG.js.map +1 -0
  25. package/dist/{chunk-7FK2UN2T.js → chunk-AWQPGIR6.js} +65 -67
  26. package/dist/{chunk-7FK2UN2T.js.map → chunk-AWQPGIR6.js.map} +1 -1
  27. package/dist/{chunk-ZFJJ3EXC.js → chunk-BBVUVBUO.js} +516 -185
  28. package/dist/chunk-BBVUVBUO.js.map +1 -0
  29. package/dist/{chunk-JBIKAAT3.js → chunk-BFFM2WFK.js} +8 -8
  30. package/dist/chunk-BFFM2WFK.js.map +1 -0
  31. package/dist/{chunk-KYQVEKP5.js → chunk-BPMWXTFX.js} +8 -8
  32. package/dist/chunk-DMZZLPZN.js +205 -0
  33. package/dist/chunk-DMZZLPZN.js.map +1 -0
  34. package/dist/{chunk-47PP7TAG.js → chunk-EGELTSPU.js} +1356 -1356
  35. package/dist/chunk-EGELTSPU.js.map +1 -0
  36. package/dist/chunk-GULLJQXA.js +698 -0
  37. package/dist/chunk-GULLJQXA.js.map +1 -0
  38. package/dist/{chunk-S5RYMCV6.js → chunk-HPWO4O6S.js} +3 -3
  39. package/dist/chunk-HVRC33OL.js +174 -0
  40. package/dist/chunk-HVRC33OL.js.map +1 -0
  41. package/dist/{chunk-W6R3HAAG.js → chunk-JRGFKVAZ.js} +2 -2
  42. package/dist/{chunk-XJN5WUKL.js → chunk-KG3D7FIF.js} +2 -2
  43. package/dist/chunk-L3PVMIYQ.js +10328 -0
  44. package/dist/chunk-L3PVMIYQ.js.map +1 -0
  45. package/dist/{chunk-QW2Q2KAH.js → chunk-LHHMV4GU.js} +2 -2
  46. package/dist/{chunk-ZOBNS7CX.js → chunk-MEFB5KHA.js} +4 -18
  47. package/dist/chunk-MEFB5KHA.js.map +1 -0
  48. package/dist/{chunk-M2O56UK7.js → chunk-N35E6CM2.js} +293 -163
  49. package/dist/chunk-N35E6CM2.js.map +1 -0
  50. package/dist/chunk-OCBHUHWB.js +69 -0
  51. package/dist/chunk-OCBHUHWB.js.map +1 -0
  52. package/dist/chunk-OIM4HLN6.js +1405 -0
  53. package/dist/chunk-OIM4HLN6.js.map +1 -0
  54. package/dist/{chunk-VYOJOX4Z.js → chunk-OJLYNM4Z.js} +54 -33
  55. package/dist/chunk-OJLYNM4Z.js.map +1 -0
  56. package/dist/{chunk-POJRB2AE.js → chunk-POUWHWID.js} +2 -2
  57. package/dist/chunk-PZEN5PHN.js +285 -0
  58. package/dist/chunk-PZEN5PHN.js.map +1 -0
  59. package/dist/chunk-SKAHDQH7.js +1785 -0
  60. package/dist/chunk-SKAHDQH7.js.map +1 -0
  61. package/dist/{chunk-KZAAWQNP.js → chunk-TTNESUPQ.js} +3 -3
  62. package/dist/chunk-U5DXNFJC.js +137 -0
  63. package/dist/chunk-U5DXNFJC.js.map +1 -0
  64. package/dist/chunk-USS336NF.js +165 -0
  65. package/dist/chunk-USS336NF.js.map +1 -0
  66. package/dist/{chunk-UO22YNY4.js → chunk-WH7OWT6G.js} +49 -1
  67. package/dist/chunk-WH7OWT6G.js.map +1 -0
  68. package/dist/chunk-WXC57XGG.js +29 -0
  69. package/dist/chunk-WXC57XGG.js.map +1 -0
  70. package/dist/{chunk-YLYINX2H.js → chunk-XZKD7DIF.js} +3 -3
  71. package/dist/{chunk-CPCX67TI.js → chunk-YEETV6IW.js} +1079 -1039
  72. package/dist/chunk-YEETV6IW.js.map +1 -0
  73. package/dist/{chunk-OLWTRUTS.js → chunk-YJHHCWM3.js} +35 -16
  74. package/dist/chunk-YJHHCWM3.js.map +1 -0
  75. package/dist/{cli-KKRKBU5T.js → cli-M3XCSOU6.js} +289 -374
  76. package/dist/cli-M3XCSOU6.js.map +1 -0
  77. package/dist/config-MXOX7XDR.js +41 -0
  78. package/dist/{dist-U4M6QCKE.js → dist-3LOO6M4U.js} +10 -10
  79. package/dist/doctor-LU4YIZWM.js +349 -0
  80. package/dist/doctor-LU4YIZWM.js.map +1 -0
  81. package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
  82. package/dist/{chunk-KAJZHIQ4.js → fund-A54P2QFK.js} +80 -24
  83. package/dist/fund-A54P2QFK.js.map +1 -0
  84. package/dist/hook-command-U6KWPEDQ.js +377 -0
  85. package/dist/hook-command-U6KWPEDQ.js.map +1 -0
  86. package/dist/index.js +8 -3
  87. package/dist/index.js.map +1 -1
  88. package/dist/install-XUM2XSHW.js +53 -0
  89. package/dist/install-wallet-QIOFORTX.js +105 -0
  90. package/dist/install-wallet-QIOFORTX.js.map +1 -0
  91. package/dist/{run-XYTQ5TWQ.js → mcp-HJC2PLRV.js} +3727 -10670
  92. package/dist/mcp-HJC2PLRV.js.map +1 -0
  93. package/dist/paths-P2N4JTDZ.js +49 -0
  94. package/dist/pay-SBXZEPEP.js +37 -0
  95. package/dist/redact-46ZHF2NH.js +17 -0
  96. package/dist/{secp256k1-XRPVBC6V.js → secp256k1-ZZZT2CAX.js} +3 -3
  97. package/dist/{send-G746D7PQ.js → send-ASD2ZXJD.js} +28 -29
  98. package/dist/send-ASD2ZXJD.js.map +1 -0
  99. package/dist/{chunk-QZ6ROAJU.js → skill-placement-NFVHY6A3.js} +157 -11
  100. package/dist/skill-placement-NFVHY6A3.js.map +1 -0
  101. package/dist/status-T2SDB57A.js +63 -0
  102. package/dist/status-T2SDB57A.js.map +1 -0
  103. package/dist/status-line-CGPUSDMC.js +71 -0
  104. package/dist/status-line-CGPUSDMC.js.map +1 -0
  105. package/dist/status-line-wiring-BYPHTYZE.js +30 -0
  106. package/dist/tenjin-daemon.mjs +20060 -0
  107. package/dist/tenjin-shim.mjs +251 -0
  108. package/dist/tenjin-vitest-reporter.mjs +49 -0
  109. package/dist/uninstall-FKYZHAM3.js +144 -0
  110. package/dist/uninstall-FKYZHAM3.js.map +1 -0
  111. package/dist/{update-R76LHOZW.js → update-ANJ2AOTN.js} +133 -16
  112. package/dist/update-ANJ2AOTN.js.map +1 -0
  113. package/dist/{viemAdapter-By13KInL-TUQJBMHM.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
  114. package/dist/wallet-PWAHVKWW.js +31 -0
  115. package/dist/wallet-kdf-worker.mjs +980 -0
  116. package/docs/agent-permissions.md +65 -354
  117. package/docs/safety-model.md +16 -6
  118. package/package.json +8 -7
  119. package/LICENSE +0 -21
  120. package/dist/buy-VIRNSYGN.js +0 -47
  121. package/dist/chunk-2MYQN7HM.js +0 -247
  122. package/dist/chunk-2MYQN7HM.js.map +0 -1
  123. package/dist/chunk-2RF2GIJQ.js +0 -1188
  124. package/dist/chunk-2RF2GIJQ.js.map +0 -1
  125. package/dist/chunk-3GL2Z5QK.js +0 -57
  126. package/dist/chunk-3GL2Z5QK.js.map +0 -1
  127. package/dist/chunk-47PP7TAG.js.map +0 -1
  128. package/dist/chunk-4CQIDQOT.js +0 -167
  129. package/dist/chunk-4CQIDQOT.js.map +0 -1
  130. package/dist/chunk-4KG27W2S.js +0 -614
  131. package/dist/chunk-4KG27W2S.js.map +0 -1
  132. package/dist/chunk-5QQTYWEU.js +0 -199
  133. package/dist/chunk-5QQTYWEU.js.map +0 -1
  134. package/dist/chunk-65DTCCJ7.js +0 -21
  135. package/dist/chunk-65DTCCJ7.js.map +0 -1
  136. package/dist/chunk-A5DKHMUN.js +0 -173
  137. package/dist/chunk-A5DKHMUN.js.map +0 -1
  138. package/dist/chunk-B63XPWQ4.js +0 -246
  139. package/dist/chunk-B63XPWQ4.js.map +0 -1
  140. package/dist/chunk-CAR6FHK6.js +0 -105
  141. package/dist/chunk-CAR6FHK6.js.map +0 -1
  142. package/dist/chunk-CPCX67TI.js.map +0 -1
  143. package/dist/chunk-CQBVCYI2.js +0 -162
  144. package/dist/chunk-CQBVCYI2.js.map +0 -1
  145. package/dist/chunk-DBU5CXBV.js +0 -4731
  146. package/dist/chunk-DBU5CXBV.js.map +0 -1
  147. package/dist/chunk-DHJD77OW.js +0 -81
  148. package/dist/chunk-DHJD77OW.js.map +0 -1
  149. package/dist/chunk-EDZSNPE5.js +0 -35
  150. package/dist/chunk-EDZSNPE5.js.map +0 -1
  151. package/dist/chunk-EFWZPUTC.js +0 -65
  152. package/dist/chunk-EFWZPUTC.js.map +0 -1
  153. package/dist/chunk-EPFL6CTE.js +0 -448
  154. package/dist/chunk-EPFL6CTE.js.map +0 -1
  155. package/dist/chunk-GHLVXVZD.js +0 -142
  156. package/dist/chunk-GHLVXVZD.js.map +0 -1
  157. package/dist/chunk-H3SOOJ2I.js +0 -580
  158. package/dist/chunk-H3SOOJ2I.js.map +0 -1
  159. package/dist/chunk-HPJGOLTN.js.map +0 -1
  160. package/dist/chunk-HRGBS2PA.js +0 -203
  161. package/dist/chunk-HRGBS2PA.js.map +0 -1
  162. package/dist/chunk-ITUXPJIS.js +0 -314
  163. package/dist/chunk-ITUXPJIS.js.map +0 -1
  164. package/dist/chunk-JBIKAAT3.js.map +0 -1
  165. package/dist/chunk-KAJZHIQ4.js.map +0 -1
  166. package/dist/chunk-KINZ23CV.js.map +0 -1
  167. package/dist/chunk-LRYV3SK7.js +0 -235
  168. package/dist/chunk-LRYV3SK7.js.map +0 -1
  169. package/dist/chunk-M2O56UK7.js.map +0 -1
  170. package/dist/chunk-MJZZTKCC.js.map +0 -1
  171. package/dist/chunk-NIKXHWOL.js.map +0 -1
  172. package/dist/chunk-OKDRDT74.js +0 -209
  173. package/dist/chunk-OKDRDT74.js.map +0 -1
  174. package/dist/chunk-OKYSNAS3.js +0 -2144
  175. package/dist/chunk-OKYSNAS3.js.map +0 -1
  176. package/dist/chunk-OLWTRUTS.js.map +0 -1
  177. package/dist/chunk-QQ6ELLSA.js +0 -143
  178. package/dist/chunk-QQ6ELLSA.js.map +0 -1
  179. package/dist/chunk-QZ6ROAJU.js.map +0 -1
  180. package/dist/chunk-R7RSCBI7.js +0 -794
  181. package/dist/chunk-R7RSCBI7.js.map +0 -1
  182. package/dist/chunk-SGK2B724.js +0 -67
  183. package/dist/chunk-SGK2B724.js.map +0 -1
  184. package/dist/chunk-U6VPKMGC.js +0 -390
  185. package/dist/chunk-U6VPKMGC.js.map +0 -1
  186. package/dist/chunk-UHTVXQ2O.js +0 -140
  187. package/dist/chunk-UHTVXQ2O.js.map +0 -1
  188. package/dist/chunk-UO22YNY4.js.map +0 -1
  189. package/dist/chunk-US456VUI.js +0 -149
  190. package/dist/chunk-US456VUI.js.map +0 -1
  191. package/dist/chunk-V44J2MXV.js +0 -400
  192. package/dist/chunk-V44J2MXV.js.map +0 -1
  193. package/dist/chunk-VJQKL3YH.js +0 -216
  194. package/dist/chunk-VJQKL3YH.js.map +0 -1
  195. package/dist/chunk-VJSQSLBM.js +0 -1442
  196. package/dist/chunk-VJSQSLBM.js.map +0 -1
  197. package/dist/chunk-VYOJOX4Z.js.map +0 -1
  198. package/dist/chunk-WY2K35OL.js +0 -269
  199. package/dist/chunk-WY2K35OL.js.map +0 -1
  200. package/dist/chunk-ZFJJ3EXC.js.map +0 -1
  201. package/dist/chunk-ZOBNS7CX.js.map +0 -1
  202. package/dist/cli-KKRKBU5T.js.map +0 -1
  203. package/dist/config-JMRUNYE6.js +0 -37
  204. package/dist/discover-B5HF6SHM.js +0 -102
  205. package/dist/discover-B5HF6SHM.js.map +0 -1
  206. package/dist/doctor-ZBG7X66D.js +0 -32
  207. package/dist/edit-PZJIILQE.js +0 -40
  208. package/dist/fund-EUDH5KPA.js +0 -40
  209. package/dist/inspect-QC6WEQPN.js +0 -37
  210. package/dist/install-GNK2W3PI.js +0 -972
  211. package/dist/install-GNK2W3PI.js.map +0 -1
  212. package/dist/outcome-KSGWZHUS.js +0 -24
  213. package/dist/pay-BC4UICPA.js +0 -361
  214. package/dist/pay-BC4UICPA.js.map +0 -1
  215. package/dist/publish-LXWFDIKF.js +0 -42
  216. package/dist/read-JMNUQ56P.js +0 -160
  217. package/dist/read-JMNUQ56P.js.map +0 -1
  218. package/dist/run-XYTQ5TWQ.js.map +0 -1
  219. package/dist/search-TSQAB45E.js +0 -25
  220. package/dist/secp256k1-XRPVBC6V.js.map +0 -1
  221. package/dist/send-G746D7PQ.js.map +0 -1
  222. package/dist/session-JBKWMJ24.js +0 -89
  223. package/dist/session-JBKWMJ24.js.map +0 -1
  224. package/dist/skill-heal-WKD67SLJ.js +0 -92
  225. package/dist/skill-heal-WKD67SLJ.js.map +0 -1
  226. package/dist/skill-placement-RIU4AMC2.js +0 -20
  227. package/dist/skill-placement-RIU4AMC2.js.map +0 -1
  228. package/dist/uninstall-5E263VTS.js +0 -73
  229. package/dist/uninstall-5E263VTS.js.map +0 -1
  230. package/dist/update-R76LHOZW.js.map +0 -1
  231. package/dist/usdc-4VCDHFWX.js +0 -38
  232. package/dist/usdc-4VCDHFWX.js.map +0 -1
  233. package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
  234. package/dist/wallet-TQ7D5EQ7.js +0 -41
  235. package/dist/wallet-TQ7D5EQ7.js.map +0 -1
  236. package/dist/wallet-ZAVXWLWP.js +0 -32
  237. package/dist/wallet-ZAVXWLWP.js.map +0 -1
  238. package/docs/command-reference.md +0 -303
  239. package/skills/tenjin/SKILL.md +0 -373
  240. package/skills/tenjin-pay/SKILL.md +0 -76
  241. package/skills/tenjin-publish/SKILL.md +0 -227
  242. package/skills/tenjin-publish/references/maintain.md +0 -39
  243. package/skills/tenjin-search/SKILL.md +0 -154
  244. package/skills/tenjin-search/references/permissions.md +0 -112
  245. /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
  246. /package/dist/{buy-VIRNSYGN.js.map → ccip-7RMRLAGV.js.map} +0 -0
  247. /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
  248. /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
  249. /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
  250. /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
  251. /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
  252. /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
  253. /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
  254. /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
  255. /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
  256. /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
  257. /package/dist/{ccip-ZGGWQN4X.js.map → config-MXOX7XDR.js.map} +0 -0
  258. /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
  259. /package/dist/{config-JMRUNYE6.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
  260. /package/dist/{doctor-ZBG7X66D.js.map → install-XUM2XSHW.js.map} +0 -0
  261. /package/dist/{edit-PZJIILQE.js.map → paths-P2N4JTDZ.js.map} +0 -0
  262. /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-SBXZEPEP.js.map} +0 -0
  263. /package/dist/{fund-EUDH5KPA.js.map → redact-46ZHF2NH.js.map} +0 -0
  264. /package/dist/{inspect-QC6WEQPN.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
  265. /package/dist/{outcome-KSGWZHUS.js.map → status-line-wiring-BYPHTYZE.js.map} +0 -0
  266. /package/dist/{publish-LXWFDIKF.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
  267. /package/dist/{search-TSQAB45E.js.map → wallet-PWAHVKWW.js.map} +0 -0
@@ -0,0 +1,251 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+
3
+ // src/hooks/shim-main.ts
4
+ import { readFileSync as readFileSync2 } from "node:fs";
5
+ import { parseArgs } from "node:util";
6
+
7
+ // src/hooks/shim.ts
8
+ import { spawn } from "node:child_process";
9
+ import {
10
+ appendFileSync,
11
+ closeSync,
12
+ existsSync,
13
+ mkdirSync,
14
+ openSync,
15
+ readFileSync,
16
+ statSync,
17
+ unlinkSync,
18
+ writeFileSync
19
+ } from "node:fs";
20
+
21
+ // src/lib/paths.ts
22
+ import { homedir } from "node:os";
23
+ import { join, resolve } from "node:path";
24
+ function dataDir(env = process.env) {
25
+ const override = env.TENJIN_DATA_DIR;
26
+ if (override !== void 0 && override.length > 0) return resolve(override);
27
+ return defaultDataDir();
28
+ }
29
+ function defaultDataDir(home = homedir()) {
30
+ return join(home, ".tenjin");
31
+ }
32
+ function hooksDir(dir = dataDir()) {
33
+ return join(dir, "hooks");
34
+ }
35
+ function daemonTokenPath(dir = dataDir()) {
36
+ return join(dir, "daemon.token");
37
+ }
38
+ function daemonPidPath(dir = dataDir()) {
39
+ return join(dir, "daemon.pid");
40
+ }
41
+ function daemonLogPath(dir = dataDir()) {
42
+ return join(dir, "daemon.log");
43
+ }
44
+ function daemonSpawnPath(dir = dataDir()) {
45
+ return join(dir, "daemon.spawn");
46
+ }
47
+ function daemonBundlePath(dir = dataDir()) {
48
+ return join(hooksDir(dir), "tenjin-daemon.mjs");
49
+ }
50
+
51
+ // src/hooks/constants.ts
52
+ var SLACK_MS = 500;
53
+ var HARNESS_MS = 5e3;
54
+ var SPAWN_MS = 500;
55
+ var HEALTH_MS = 200;
56
+ var SPAWN_BACKOFF_MS = 6e4;
57
+ var MAX_BODY_BYTES = 4 * 1024 * 1024;
58
+ var LOG_TRUNCATE_BYTES = 5 * 1024 * 1024;
59
+
60
+ // src/hooks/shim.ts
61
+ function resolveDataDir(env = process.env) {
62
+ return dataDir(env);
63
+ }
64
+ function readPid(dataDir3) {
65
+ try {
66
+ const raw = JSON.parse(readFileSync(daemonPidPath(dataDir3), "utf8"));
67
+ if (typeof raw.pid === "number" && typeof raw.port === "number" && typeof raw.started_at === "number" && typeof raw.data_dir === "string") {
68
+ return { pid: raw.pid, port: raw.port, started_at: raw.started_at, data_dir: raw.data_dir };
69
+ }
70
+ return null;
71
+ } catch {
72
+ return null;
73
+ }
74
+ }
75
+ function readToken(dataDir3) {
76
+ try {
77
+ const t = readFileSync(daemonTokenPath(dataDir3), "utf8").trim();
78
+ return t.length > 0 ? t : null;
79
+ } catch {
80
+ return null;
81
+ }
82
+ }
83
+ function logDown(dataDir3, reason) {
84
+ try {
85
+ mkdirSync(dataDir3, { recursive: true, mode: 448 });
86
+ appendFileSync(daemonLogPath(dataDir3), `${(/* @__PURE__ */ new Date()).toISOString()} daemon-down ${reason}
87
+ `);
88
+ } catch {
89
+ }
90
+ }
91
+ async function health(port, timeoutMs = HEALTH_MS) {
92
+ try {
93
+ const res = await fetch(`http://127.0.0.1:${port}/health`, {
94
+ signal: AbortSignal.timeout(timeoutMs)
95
+ });
96
+ if (!res.ok) return null;
97
+ const body = await res.json();
98
+ if (typeof body.pid !== "number" || typeof body.data_dir !== "string") return null;
99
+ return body;
100
+ } catch {
101
+ return null;
102
+ }
103
+ }
104
+ function daemonEnv(dataDir3, env = process.env) {
105
+ const keep = [
106
+ "PATH",
107
+ "HOME",
108
+ "USERPROFILE",
109
+ "TMPDIR",
110
+ "TEMP",
111
+ "TMP",
112
+ "HTTP_PROXY",
113
+ "HTTPS_PROXY",
114
+ "NO_PROXY",
115
+ "http_proxy",
116
+ "https_proxy",
117
+ "no_proxy"
118
+ ];
119
+ const out = {};
120
+ for (const k of keep) if (env[k] !== void 0) out[k] = env[k];
121
+ out.TENJIN_DATA_DIR = dataDir3;
122
+ return out;
123
+ }
124
+ function inBackoff(dataDir3, now = Date.now()) {
125
+ try {
126
+ return now - statSync(daemonSpawnPath(dataDir3)).mtimeMs < SPAWN_BACKOFF_MS;
127
+ } catch {
128
+ return false;
129
+ }
130
+ }
131
+ function spawnDaemon(dataDir3, env = process.env) {
132
+ mkdirSync(dataDir3, { recursive: true, mode: 448 });
133
+ writeFileSync(daemonSpawnPath(dataDir3), "");
134
+ const log = openSync(daemonLogPath(dataDir3), "a");
135
+ try {
136
+ const child = spawn(process.execPath, [daemonBundlePath(dataDir3)], {
137
+ detached: true,
138
+ stdio: ["ignore", log, log],
139
+ env: daemonEnv(dataDir3, env),
140
+ // Never the hook's cwd: a detached daemon would pin a project worktree.
141
+ cwd: dataDir3,
142
+ windowsHide: true
143
+ });
144
+ child.unref();
145
+ } finally {
146
+ closeSync(log);
147
+ }
148
+ }
149
+ function sleep(ms) {
150
+ return new Promise((r) => setTimeout(r, ms));
151
+ }
152
+ async function ensureDaemon(dataDir3, opts = {}) {
153
+ const now = opts.now ?? (() => Date.now());
154
+ const pid = readPid(dataDir3);
155
+ if (pid !== null) {
156
+ const h = await health(pid.port);
157
+ if (h !== null && h.data_dir === dataDir3) return { ok: true, health: h, spawned: false };
158
+ }
159
+ if (!existsSync(daemonBundlePath(dataDir3)))
160
+ return { ok: false, reason: "no bundle; run `tenjin daemon start`" };
161
+ if (inBackoff(dataDir3, now())) return { ok: false, reason: "spawn backoff" };
162
+ try {
163
+ spawnDaemon(dataDir3, opts.env);
164
+ } catch (err) {
165
+ return {
166
+ ok: false,
167
+ reason: `spawn failed: ${err instanceof Error ? err.message : String(err)}`
168
+ };
169
+ }
170
+ const budget = opts.spawnMs ?? SPAWN_MS;
171
+ const until = now() + budget;
172
+ const settled = async () => {
173
+ const fresh = readPid(dataDir3);
174
+ if (fresh === null || pid !== null && fresh.started_at === pid.started_at) return null;
175
+ const h = await health(fresh.port);
176
+ return h !== null && h.data_dir === dataDir3 ? h : null;
177
+ };
178
+ const won = (h) => {
179
+ try {
180
+ unlinkSync(daemonSpawnPath(dataDir3));
181
+ } catch {
182
+ }
183
+ return { ok: true, health: h, spawned: true };
184
+ };
185
+ while (now() < until) {
186
+ await sleep(20);
187
+ const h = await settled();
188
+ if (h !== null) return won(h);
189
+ }
190
+ const late = await settled();
191
+ if (late !== null) return won(late);
192
+ return { ok: false, reason: `spawned but not healthy within ${budget} ms` };
193
+ }
194
+ async function forward(dataDir3, harness, stdin, startedAt2) {
195
+ const token = readToken(dataDir3);
196
+ if (token === null) {
197
+ logDown(dataDir3, "no token; run `tenjin daemon start`");
198
+ return;
199
+ }
200
+ const ensured = await ensureDaemon(dataDir3);
201
+ if (!ensured.ok) {
202
+ logDown(dataDir3, ensured.reason);
203
+ return;
204
+ }
205
+ const remaining = HARNESS_MS - SLACK_MS - (Date.now() - startedAt2);
206
+ if (remaining <= 0) {
207
+ logDown(dataDir3, "no time left after ensure");
208
+ return;
209
+ }
210
+ try {
211
+ const res = await fetch(`http://127.0.0.1:${ensured.health.port}/hook/${harness}`, {
212
+ method: "POST",
213
+ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
214
+ body: stdin,
215
+ signal: AbortSignal.timeout(remaining)
216
+ });
217
+ if (res.status === 200) {
218
+ const body = await res.text();
219
+ if (body.length > 0) writeFileSync(1, body);
220
+ } else if (res.status === 404) {
221
+ logDown(
222
+ dataDir3,
223
+ `hook answered 404: the daemon on 127.0.0.1:${ensured.health.port} (v${ensured.health.version}) has no /hook/${harness} route; run \`tenjin install\` to replace it`
224
+ );
225
+ } else if (res.status !== 204) {
226
+ logDown(dataDir3, `hook answered ${res.status}`);
227
+ }
228
+ } catch (err) {
229
+ logDown(dataDir3, `forward failed: ${err instanceof Error ? err.name : String(err)}`);
230
+ }
231
+ }
232
+
233
+ // src/hooks/shim-main.ts
234
+ var startedAt = Date.now();
235
+ var dataDir2 = resolveDataDir();
236
+ try {
237
+ const { values } = parseArgs({
238
+ options: { harness: { type: "string" }, ensure: { type: "boolean" } },
239
+ strict: false
240
+ });
241
+ if (typeof values.harness === "string") {
242
+ const stdin = readFileSync2(0, "utf8");
243
+ await forward(dataDir2, values.harness, stdin, startedAt);
244
+ } else {
245
+ const r = await ensureDaemon(dataDir2);
246
+ if (!r.ok) logDown(dataDir2, r.reason);
247
+ }
248
+ } catch (err) {
249
+ logDown(dataDir2, `shim: ${err instanceof Error ? err.message : String(err)}`);
250
+ }
251
+ process.exit(0);
@@ -0,0 +1,49 @@
1
+ // src/hooks/failure/vitest-reporter.ts
2
+ import { renameSync, unlinkSync, writeFileSync } from "node:fs";
3
+ var TenjinVitestReporter = class {
4
+ #outputFile;
5
+ #startTime = 0;
6
+ constructor(options) {
7
+ this.#outputFile = options !== void 0 && typeof options.outputFile === "string" && options.outputFile.length > 0 ? options.outputFile : ".vitest-report.json";
8
+ }
9
+ onInit() {
10
+ this.#startTime = Date.now();
11
+ try {
12
+ unlinkSync(this.#outputFile);
13
+ } catch {
14
+ }
15
+ }
16
+ onTestRunEnd(testModules, unhandledErrors) {
17
+ const endTime = Date.now();
18
+ const failed = [];
19
+ for (const testModule of testModules) {
20
+ for (const testCase of testModule.children.allTests("failed")) {
21
+ const parent = testCase.parent;
22
+ failed.push({
23
+ file: testModule.moduleId,
24
+ suite: parent !== void 0 && parent.type === "suite" ? parent.fullName ?? "" : "",
25
+ test: testCase.name
26
+ });
27
+ }
28
+ }
29
+ const report = {
30
+ startTime: this.#startTime,
31
+ endTime,
32
+ failed,
33
+ success: failed.length === 0 && unhandledErrors.length === 0
34
+ };
35
+ const tmp = this.#outputFile + ".tmp-" + process.pid;
36
+ try {
37
+ writeFileSync(tmp, JSON.stringify(report));
38
+ renameSync(tmp, this.#outputFile);
39
+ } catch {
40
+ try {
41
+ unlinkSync(tmp);
42
+ } catch {
43
+ }
44
+ }
45
+ }
46
+ };
47
+ export {
48
+ TenjinVitestReporter as default
49
+ };
@@ -0,0 +1,144 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ ALLOW_RULE,
4
+ MCP_SERVER_NAME,
5
+ mcpRemoveCommand,
6
+ mcpScope,
7
+ routerSettingsPath
8
+ } from "./chunk-25TJPVBF.js";
9
+ import "./chunk-YJHHCWM3.js";
10
+ import {
11
+ persistRouterProject
12
+ } from "./chunk-GULLJQXA.js";
13
+ import "./chunk-WXC57XGG.js";
14
+ import "./chunk-2QYORQBF.js";
15
+ import "./chunk-MEFB5KHA.js";
16
+ import {
17
+ onPath
18
+ } from "./chunk-U5DXNFJC.js";
19
+ import "./chunk-OJLYNM4Z.js";
20
+ import "./chunk-WH7OWT6G.js";
21
+ import "./chunk-BBVUVBUO.js";
22
+ import {
23
+ removeStatusLine
24
+ } from "./chunk-HVRC33OL.js";
25
+ import {
26
+ inspectHooksFile,
27
+ pruneHooks
28
+ } from "./chunk-SKAHDQH7.js";
29
+ import "./chunk-BFFM2WFK.js";
30
+ import "./chunk-OCBHUHWB.js";
31
+ import "./chunk-2BKS2FVE.js";
32
+ import {
33
+ writeFileAtomic
34
+ } from "./chunk-7WEQQJLG.js";
35
+ import "./chunk-ZXTAQYNA.js";
36
+
37
+ // src/router/uninstall.ts
38
+ import { execFile } from "node:child_process";
39
+ import { homedir } from "node:os";
40
+ import { readFile, stat } from "node:fs/promises";
41
+ import { isAbsolute } from "node:path";
42
+ import { promisify } from "node:util";
43
+ var exec = promisify(execFile);
44
+ var MCP_REMOVE_COMMAND = mcpRemoveCommand();
45
+ async function runRouterUninstall(args, ctx, deps = {}) {
46
+ const env = deps.env ?? process.env;
47
+ const home = deps.homeDir ?? homedir();
48
+ if (!isAbsolute(home)) throw new Error("The home directory is not an absolute path.");
49
+ const cwd = deps.cwd ?? process.cwd();
50
+ const settingsPath = routerSettingsPath({
51
+ ...args.project === true ? { project: true } : {},
52
+ homeDir: home,
53
+ cwd
54
+ });
55
+ const removed = await removeFromSettings(settingsPath, ctx.dataDir);
56
+ const statusLine = await removeStatusLine(settingsPath);
57
+ if (args.project === true) {
58
+ await persistRouterProject(ctx.dataDir, cwd, false).catch(() => void 0);
59
+ }
60
+ const mcp = await removeMcpServer(deps, env, args.project === true, cwd);
61
+ const data = {
62
+ settingsPath,
63
+ ...removed,
64
+ statusLine,
65
+ mcp,
66
+ kept: ["wallet.json", "spend.json", "config.json"]
67
+ };
68
+ return {
69
+ data,
70
+ humanLines: [
71
+ removed.warning === void 0 ? `removed ${removed.events.length > 0 ? removed.events.join(", ") : "no"} hook entries and ${removed.ruleRemoved ? "the" : "no"} permission rule from ${settingsPath}` : `${settingsPath} was left untouched (${removed.warning})`,
72
+ statusLine.wrote ? "removed the x402 status line" : statusLine.state === "composed" ? "status line: yours also runs the x402 footer; edit that command to drop it" : "status line: none of ours was registered",
73
+ mcp.removed ? `removed the ${MCP_SERVER_NAME} MCP server (${mcp.scope} scope)` : `mcp: run ${mcp.command}`,
74
+ "Your wallet, spend ledger and config are kept."
75
+ ]
76
+ };
77
+ }
78
+ async function removeFromSettings(path, dataDir) {
79
+ const found = await inspectHooksFile(path);
80
+ if ("refusal" in found) {
81
+ return { events: [], ruleRemoved: false, wrote: false, warning: found.refusal.reason };
82
+ }
83
+ const { raw, settings, hooks } = found;
84
+ if (raw === null) return { events: [], ruleRemoved: false, wrote: false };
85
+ const pruned = pruneHooks(hooks, dataDir);
86
+ const permissions = settings.permissions !== null && typeof settings.permissions === "object" && !Array.isArray(settings.permissions) ? settings.permissions : void 0;
87
+ const allow = Array.isArray(permissions?.allow) ? permissions.allow : void 0;
88
+ const ruleRemoved = allow?.includes(ALLOW_RULE) === true;
89
+ const next = {
90
+ ...settings,
91
+ hooks: pruned.next,
92
+ ...permissions !== void 0 && allow !== void 0 ? { permissions: { ...permissions, allow: allow.filter((r) => r !== ALLOW_RULE) } } : {}
93
+ };
94
+ const body = `${JSON.stringify(next, null, 2)}
95
+ `;
96
+ if (body === raw) {
97
+ return { events: pruned.removed, ruleRemoved, wrote: false };
98
+ }
99
+ const mode = await stat(found.path).then((s) => ({ mode: s.mode & 511 })).catch(() => ({}));
100
+ if (await readFile(found.path, "utf8").catch(() => null) !== raw) {
101
+ return { events: [], ruleRemoved: false, wrote: false, warning: "changed-since-read" };
102
+ }
103
+ try {
104
+ await writeFileAtomic(found.path, body, mode);
105
+ } catch (err) {
106
+ return {
107
+ events: [],
108
+ ruleRemoved: false,
109
+ wrote: false,
110
+ warning: err instanceof Error ? err.message : String(err)
111
+ };
112
+ }
113
+ return { events: pruned.removed, ruleRemoved, wrote: true };
114
+ }
115
+ async function removeMcpServer(deps, env, project, cwd) {
116
+ const scope = mcpScope(project);
117
+ const command = mcpRemoveCommand(project);
118
+ const which = deps.which ?? ((bin) => onPath(bin, env));
119
+ if (!which("claude")) {
120
+ return { removed: false, scope, command, reason: "the `claude` binary is not on PATH" };
121
+ }
122
+ try {
123
+ await (deps.removeMcp ?? runClaudeMcpRemove)({ scope, cwd });
124
+ return { removed: true, scope, command };
125
+ } catch (err) {
126
+ return {
127
+ removed: false,
128
+ scope,
129
+ command,
130
+ reason: err instanceof Error ? err.message : String(err)
131
+ };
132
+ }
133
+ }
134
+ async function runClaudeMcpRemove(opts) {
135
+ await exec("claude", ["mcp", "remove", MCP_SERVER_NAME, "-s", opts.scope], {
136
+ timeout: 2e4,
137
+ cwd: opts.cwd
138
+ });
139
+ }
140
+ export {
141
+ MCP_REMOVE_COMMAND,
142
+ runRouterUninstall
143
+ };
144
+ //# sourceMappingURL=uninstall-FKYZHAM3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/router/uninstall.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { homedir } from 'node:os';\nimport { readFile, stat } from 'node:fs/promises';\nimport { isAbsolute } from 'node:path';\nimport { promisify } from 'node:util';\nimport { persistRouterProject } from '../commands/config';\nimport { writeFileAtomic } from '../lib/atomic-json';\nimport { inspectHooksFile, pruneHooks } from '../lib/harness-hooks';\nimport { onPath } from '../lib/skill-wiring';\nimport type { CommandContext, CommandResult } from '../context';\nimport {\n ALLOW_RULE,\n MCP_SERVER_NAME,\n mcpRemoveCommand,\n mcpScope,\n routerSettingsPath,\n} from './install';\nimport { removeStatusLine } from './status-line-wiring';\n\n/**\n * `tenjin uninstall`: take out the hook entries, the allow rule and the MCP\n * registration, and nothing else.\n *\n * THE WALLET AND `spend.json` STAY. Removing an integration is not a reason to\n * destroy a key that holds funds or a ledger that records what was spent; both\n * are the user's, and `tenjin wallet` is where they go to move either.\n */\n\nconst exec = promisify(execFile);\n/** The user-scope form; `--project` removes at project scope symmetrically. */\nexport const MCP_REMOVE_COMMAND = mcpRemoveCommand();\n\nexport interface RouterUninstallArgs {\n project?: boolean;\n}\n\nexport interface RouterUninstallDeps {\n homeDir?: string;\n cwd?: string;\n env?: NodeJS.ProcessEnv;\n which?: (bin: string) => boolean;\n removeMcp?: (opts: { scope: 'user' | 'project'; cwd: string }) => Promise<void>;\n}\n\nexport async function runRouterUninstall(\n args: RouterUninstallArgs,\n ctx: CommandContext,\n deps: RouterUninstallDeps = {},\n): Promise<CommandResult> {\n const env = deps.env ?? process.env;\n const home = deps.homeDir ?? homedir();\n if (!isAbsolute(home)) throw new Error('The home directory is not an absolute path.');\n const cwd = deps.cwd ?? process.cwd();\n const settingsPath = routerSettingsPath({\n ...(args.project === true ? { project: true } : {}),\n homeDir: home,\n cwd,\n });\n\n const removed = await removeFromSettings(settingsPath, ctx.dataDir);\n // OURS ALONE, and after the hooks write so the two never touch the file at\n // once. A COMPOSED status line is the user's own text with ours appended:\n // deleting it would take their line with it, so it is reported and kept.\n const statusLine = await removeStatusLine(settingsPath);\n // Forgotten, so a later `tenjin update` does not go looking for a project\n // this machine no longer wires.\n if (args.project === true) {\n await persistRouterProject(ctx.dataDir, cwd, false).catch(() => undefined);\n }\n // The SAME scope the install used, or a `--project` uninstall would leave the\n // project's registration behind and reach into the user's file instead.\n const mcp = await removeMcpServer(deps, env, args.project === true, cwd);\n const data = {\n settingsPath,\n ...removed,\n statusLine,\n mcp,\n kept: ['wallet.json', 'spend.json', 'config.json'],\n };\n return {\n data,\n humanLines: [\n removed.warning === undefined\n ? `removed ${removed.events.length > 0 ? removed.events.join(', ') : 'no'} hook entries and ${removed.ruleRemoved ? 'the' : 'no'} permission rule from ${settingsPath}`\n : `${settingsPath} was left untouched (${removed.warning})`,\n statusLine.wrote\n ? 'removed the x402 status line'\n : statusLine.state === 'composed'\n ? 'status line: yours also runs the x402 footer; edit that command to drop it'\n : 'status line: none of ours was registered',\n mcp.removed\n ? `removed the ${MCP_SERVER_NAME} MCP server (${mcp.scope} scope)`\n : `mcp: run ${mcp.command}`,\n 'Your wallet, spend ledger and config are kept.',\n ],\n };\n}\n\ninterface SettingsRemoval {\n /** The events an entry of ours was taken out of. */\n events: string[];\n ruleRemoved: boolean;\n wrote: boolean;\n warning?: string;\n}\n\nasync function removeFromSettings(path: string, dataDir: string): Promise<SettingsRemoval> {\n const found = await inspectHooksFile(path);\n if ('refusal' in found) {\n return { events: [], ruleRemoved: false, wrote: false, warning: found.refusal.reason };\n }\n const { raw, settings, hooks } = found;\n if (raw === null) return { events: [], ruleRemoved: false, wrote: false };\n const pruned = pruneHooks(hooks, dataDir);\n const permissions =\n settings.permissions !== null &&\n typeof settings.permissions === 'object' &&\n !Array.isArray(settings.permissions)\n ? (settings.permissions as Record<string, unknown>)\n : undefined;\n const allow = Array.isArray(permissions?.allow) ? permissions.allow : undefined;\n const ruleRemoved = allow?.includes(ALLOW_RULE) === true;\n const next = {\n ...settings,\n hooks: pruned.next,\n ...(permissions !== undefined && allow !== undefined\n ? { permissions: { ...permissions, allow: allow.filter((r) => r !== ALLOW_RULE) } }\n : {}),\n };\n const body = `${JSON.stringify(next, null, 2)}\\n`;\n if (body === raw) {\n return { events: pruned.removed, ruleRemoved, wrote: false };\n }\n const mode = await stat(found.path)\n .then((s) => ({ mode: s.mode & 0o777 }))\n .catch(() => ({}));\n if ((await readFile(found.path, 'utf8').catch(() => null)) !== raw) {\n return { events: [], ruleRemoved: false, wrote: false, warning: 'changed-since-read' };\n }\n try {\n await writeFileAtomic(found.path, body, mode);\n } catch (err) {\n return {\n events: [],\n ruleRemoved: false,\n wrote: false,\n warning: err instanceof Error ? err.message : String(err),\n };\n }\n return { events: pruned.removed, ruleRemoved, wrote: true };\n}\n\nasync function removeMcpServer(\n deps: RouterUninstallDeps,\n env: NodeJS.ProcessEnv,\n project: boolean,\n cwd: string,\n): Promise<{ removed: boolean; scope: 'user' | 'project'; command: string; reason?: string }> {\n const scope = mcpScope(project);\n const command = mcpRemoveCommand(project);\n const which = deps.which ?? ((bin: string) => onPath(bin, env));\n if (!which('claude')) {\n return { removed: false, scope, command, reason: 'the `claude` binary is not on PATH' };\n }\n try {\n await (deps.removeMcp ?? runClaudeMcpRemove)({ scope, cwd });\n return { removed: true, scope, command };\n } catch (err) {\n return {\n removed: false,\n scope,\n command,\n reason: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\nasync function runClaudeMcpRemove(opts: { scope: 'user' | 'project'; cwd: string }): Promise<void> {\n await exec('claude', ['mcp', 'remove', MCP_SERVER_NAME, '-s', opts.scope], {\n timeout: 20_000,\n cwd: opts.cwd,\n });\n}\n"],"mappings":"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","names":[]}
@@ -1,32 +1,38 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
+ NUDGE_OPT_OUT,
3
4
  channelTag,
4
5
  fetchDistTags,
5
6
  isNewer,
6
7
  resolveTarget
7
- } from "./chunk-HPJGOLTN.js";
8
+ } from "./chunk-3AJS6LLN.js";
8
9
  import {
9
10
  emitWriteNotice,
10
11
  sanitizeForTerminal
11
- } from "./chunk-OLWTRUTS.js";
12
- import "./chunk-U6VPKMGC.js";
12
+ } from "./chunk-YJHHCWM3.js";
13
+ import "./chunk-BBVUVBUO.js";
13
14
  import {
14
15
  package_default
15
- } from "./chunk-JBIKAAT3.js";
16
- import "./chunk-2MYQN7HM.js";
16
+ } from "./chunk-BFFM2WFK.js";
17
17
  import {
18
18
  CliError
19
- } from "./chunk-ZFJJ3EXC.js";
19
+ } from "./chunk-OCBHUHWB.js";
20
+ import {
21
+ defaultDataDir
22
+ } from "./chunk-2BKS2FVE.js";
23
+ import "./chunk-7WEQQJLG.js";
20
24
  import "./chunk-ZXTAQYNA.js";
21
25
 
22
26
  // src/commands/update.ts
23
- import { spawn } from "child_process";
24
- import { homedir } from "os";
25
- import { fileURLToPath } from "url";
27
+ import { spawn } from "node:child_process";
28
+ import { existsSync as existsSync2, statSync as statSync2 } from "node:fs";
29
+ import { homedir } from "node:os";
30
+ import { resolve, sep as sep2 } from "node:path";
31
+ import { fileURLToPath } from "node:url";
26
32
 
27
33
  // src/lib/install-location.ts
28
- import { existsSync, realpathSync, statSync } from "fs";
29
- import { delimiter, dirname, join, sep } from "path";
34
+ import { existsSync, realpathSync, statSync } from "node:fs";
35
+ import { delimiter, dirname, join, sep } from "node:path";
30
36
  var REFUSALS = [
31
37
  {
32
38
  test: isSourceCheckout,
@@ -281,15 +287,125 @@ async function runUpdate(opts, ctx, deps = {}) {
281
287
  ctx.io,
282
288
  `tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`
283
289
  );
290
+ const refresh = await refreshProfiles(ctx, deps);
284
291
  return {
285
- data: data(true),
286
- humanLines: [`Updated tenjin-cli ${current} -> ${latest}. New builds pick it up immediately.`]
292
+ data: { ...data(true), refresh },
293
+ humanLines: [`Updated tenjin-cli ${current} -> ${latest}.`, ...refreshLines(refresh)]
287
294
  };
288
295
  }
296
+ var REFRESH_TIMEOUT_MS = 6e4;
297
+ async function refreshProfiles(ctx, deps) {
298
+ const home = deps.homeDir ?? homedir();
299
+ const candidates = [ctx.dataDir];
300
+ const fixFor = (dataDir) => manualFix(dataDir, home, ctx.dataDir);
301
+ const profiles = [];
302
+ const unrun = [];
303
+ for (const dataDir of candidates) {
304
+ if (isExistingDir(dataDir)) profiles.push(dataDir);
305
+ else unrun.push({ dataDir, reason: "It is not a directory.", fix: fixFor(dataDir) });
306
+ }
307
+ const entry = versionFreeEntry(deps.refreshCommand ?? process.argv[1]);
308
+ if (entry === null) {
309
+ const reason = "This build has no entry the update could safely re-execute.";
310
+ return {
311
+ profiles: [],
312
+ failed: candidates.map((d) => ({ dataDir: d, reason, fix: fixFor(d) }))
313
+ };
314
+ }
315
+ const failed = [...unrun];
316
+ for (const dataDir of profiles) {
317
+ let tail = "";
318
+ const outcome = await (deps.spawnImpl ?? spawnCapture)(
319
+ process.execPath,
320
+ [entry, "install", "--refresh"],
321
+ {
322
+ cwd: homedir(),
323
+ timeoutMs: REFRESH_TIMEOUT_MS,
324
+ // TENJIN_DATA_DIR aims the child at this profile; the nudge opt-out is
325
+ // what keeps it from touching any other file in there (lib/update-check).
326
+ env: { TENJIN_DATA_DIR: dataDir, [NUDGE_OPT_OUT]: "1" }
327
+ },
328
+ (chunk) => {
329
+ tail = (tail + chunk).slice(-REFRESH_TAIL_LIMIT);
330
+ }
331
+ );
332
+ if (outcome.kind !== "exit" || outcome.code !== 0) {
333
+ failed.push({ dataDir, reason: refreshReason(outcome, tail), fix: fixFor(dataDir) });
334
+ }
335
+ }
336
+ return { profiles, failed };
337
+ }
338
+ var REFRESH_TAIL_LIMIT = 4e3;
339
+ var REASON_LIMIT = 300;
340
+ function refreshReason(outcome, output) {
341
+ const reported = envelopeMessage(output);
342
+ if (reported !== void 0) return reported;
343
+ if (outcome.kind === "timeout") return `It did not finish in ${REFRESH_TIMEOUT_MS / 1e3}s.`;
344
+ if (outcome.kind === "start-failed") return "The refresh could not be started.";
345
+ return `The refresh exited ${outcome.code} without reporting a reason.`;
346
+ }
347
+ function envelopeMessage(output) {
348
+ const lines = output.split("\n");
349
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
350
+ const line = lines[i]?.trim();
351
+ if (line === void 0 || !line.startsWith("{")) continue;
352
+ let parsed;
353
+ try {
354
+ parsed = JSON.parse(lines.slice(i).join("\n"));
355
+ } catch {
356
+ continue;
357
+ }
358
+ if (parsed?.ok !== false || typeof parsed.error?.message !== "string") continue;
359
+ const message = sanitizeForTerminal(parsed.error.message).trim();
360
+ if (message.length > 0) return message.slice(0, REASON_LIMIT);
361
+ }
362
+ return void 0;
363
+ }
364
+ function isExistingDir(path) {
365
+ return statSync2(path, { throwIfNoEntry: false })?.isDirectory() === true;
366
+ }
367
+ function manualFix(dataDir, home, invoking) {
368
+ const bare = resolve(dataDir) === resolve(defaultDataDir(home)) && resolve(dataDir) === resolve(invoking);
369
+ const command = bare ? "tenjin install" : `TENJIN_DATA_DIR=${dataDir} tenjin install`;
370
+ return `Run \`${command}\` to bring the skills and hook scripts up to this version.`;
371
+ }
372
+ function versionFreeEntry(entry) {
373
+ if (entry === void 0 || entry.length === 0) return null;
374
+ const segs = entry.split(sep2);
375
+ const store = segs.indexOf(".pnpm");
376
+ if (store === -1) return segs.join(sep2);
377
+ const inner = segs.indexOf("node_modules", store);
378
+ if (inner === -1) return null;
379
+ const derived = [...segs.slice(0, store), ...segs.slice(inner + 1)].join(sep2);
380
+ return existsSync2(derived) ? derived : null;
381
+ }
382
+ function refreshLines(refresh) {
383
+ const failedDirs = new Set(refresh.failed.map((f) => f.dataDir));
384
+ const done = refresh.profiles.filter((p) => !failedDirs.has(p));
385
+ if (refresh.failed.length === 0) {
386
+ return [
387
+ done.length > 1 ? `Refreshed the skills and hook scripts for ${done.length} profiles: ${done.join(", ")}.` : `Refreshed the skills and hook scripts for ${done[0]}.`
388
+ ];
389
+ }
390
+ const total = done.length + refresh.failed.length;
391
+ const lines = done.length > 0 ? [
392
+ `Refreshed the skills and hook scripts for ${done.length} of ${total} profiles: ${done.join(", ")}.`
393
+ ] : [];
394
+ lines.push(`Could not refresh the skills and hook scripts for ${refresh.failed.length}:`);
395
+ lines.push(...refresh.failed.map((f) => `- ${f.dataDir}: ${f.reason} ${f.fix}`));
396
+ return lines;
397
+ }
289
398
  var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
290
399
  let child;
291
400
  try {
292
- child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"], cwd: opts.cwd });
401
+ child = spawn(cmd, args, {
402
+ stdio: ["ignore", "pipe", "pipe"],
403
+ cwd: opts.cwd,
404
+ // Layered onto this process's environment rather than replacing it: the
405
+ // child is a Node CLI that needs PATH and HOME, and only the keys named
406
+ // here are being decided.
407
+ ...opts.env !== void 0 ? { env: { ...process.env, ...opts.env } } : {}
408
+ });
293
409
  } catch (cause) {
294
410
  res({ kind: "start-failed", cause });
295
411
  return;
@@ -312,6 +428,7 @@ var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
312
428
  });
313
429
  export {
314
430
  runUpdate,
315
- spawnCapture
431
+ spawnCapture,
432
+ versionFreeEntry
316
433
  };
317
- //# sourceMappingURL=update-R76LHOZW.js.map
434
+ //# sourceMappingURL=update-ANJ2AOTN.js.map