tenjin-cli 0.1.0-alpha.14 → 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 (253) hide show
  1. package/NOTICE.md +54 -7
  2. package/README.md +41 -295
  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-ACBEHJAH.js → chunk-2U5ZVEV3.js} +14 -16
  13. package/dist/chunk-2U5ZVEV3.js.map +1 -0
  14. package/dist/{chunk-MJSXP4LW.js → chunk-3AJS6LLN.js} +11 -8
  15. package/dist/chunk-3AJS6LLN.js.map +1 -0
  16. package/dist/{chunk-OWVVI4VQ.js → chunk-3AUDA53C.js} +7650 -7361
  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-PAOVPSP6.js → chunk-BBVUVBUO.js} +517 -138
  28. package/dist/chunk-BBVUVBUO.js.map +1 -0
  29. package/dist/{chunk-ETKZWJ4B.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-PKW3H26Z.js → chunk-OJLYNM4Z.js} +56 -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-QWBUKIP2.js → chunk-U5DXNFJC.js} +23 -94
  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-7GJQ5RGA.js → chunk-YEETV6IW.js} +1077 -1039
  72. package/dist/chunk-YEETV6IW.js.map +1 -0
  73. package/dist/{chunk-B676GPS2.js → chunk-YJHHCWM3.js} +39 -16
  74. package/dist/chunk-YJHHCWM3.js.map +1 -0
  75. package/dist/{cli-U2BEUA55.js → cli-M3XCSOU6.js} +295 -349
  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-3ZW7HPY5.js → fund-A54P2QFK.js} +81 -22
  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-CJWPGMIQ.js → mcp-HJC2PLRV.js} +3725 -10661
  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-C5EOKXOU.js → send-ASD2ZXJD.js} +28 -30
  98. package/dist/send-ASD2ZXJD.js.map +1 -0
  99. package/dist/{chunk-NAAMHWSI.js → skill-placement-NFVHY6A3.js} +159 -12
  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-24Y2CQTT.js → update-ANJ2AOTN.js} +133 -17
  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 +68 -342
  117. package/docs/safety-model.md +25 -6
  118. package/package.json +8 -7
  119. package/LICENSE +0 -21
  120. package/dist/buy-2JBYPHAI.js +0 -46
  121. package/dist/chunk-3P3ES4XU.js +0 -144
  122. package/dist/chunk-3P3ES4XU.js.map +0 -1
  123. package/dist/chunk-3ZW7HPY5.js.map +0 -1
  124. package/dist/chunk-47PP7TAG.js.map +0 -1
  125. package/dist/chunk-4UHNXY6B.js +0 -786
  126. package/dist/chunk-4UHNXY6B.js.map +0 -1
  127. package/dist/chunk-4Y53PDH6.js +0 -213
  128. package/dist/chunk-4Y53PDH6.js.map +0 -1
  129. package/dist/chunk-54AJIO3E.js +0 -198
  130. package/dist/chunk-54AJIO3E.js.map +0 -1
  131. package/dist/chunk-736DW4V3.js +0 -65
  132. package/dist/chunk-736DW4V3.js.map +0 -1
  133. package/dist/chunk-7GJQ5RGA.js.map +0 -1
  134. package/dist/chunk-7NADDA2V.js +0 -161
  135. package/dist/chunk-7NADDA2V.js.map +0 -1
  136. package/dist/chunk-ACBEHJAH.js.map +0 -1
  137. package/dist/chunk-B676GPS2.js.map +0 -1
  138. package/dist/chunk-DAZAXFSF.js +0 -1357
  139. package/dist/chunk-DAZAXFSF.js.map +0 -1
  140. package/dist/chunk-DTCXO7HS.js +0 -791
  141. package/dist/chunk-DTCXO7HS.js.map +0 -1
  142. package/dist/chunk-ETKZWJ4B.js.map +0 -1
  143. package/dist/chunk-FDUD3W5V.js +0 -317
  144. package/dist/chunk-FDUD3W5V.js.map +0 -1
  145. package/dist/chunk-GEHL43VE.js +0 -711
  146. package/dist/chunk-GEHL43VE.js.map +0 -1
  147. package/dist/chunk-IU2HVT3Y.js +0 -313
  148. package/dist/chunk-IU2HVT3Y.js.map +0 -1
  149. package/dist/chunk-IUQZ4Z7M.js +0 -162
  150. package/dist/chunk-IUQZ4Z7M.js.map +0 -1
  151. package/dist/chunk-IXZJ3JOO.js +0 -614
  152. package/dist/chunk-IXZJ3JOO.js.map +0 -1
  153. package/dist/chunk-J6FUAIRR.js +0 -205
  154. package/dist/chunk-J6FUAIRR.js.map +0 -1
  155. package/dist/chunk-L6G35FU5.js +0 -105
  156. package/dist/chunk-L6G35FU5.js.map +0 -1
  157. package/dist/chunk-LSWP7MU2.js +0 -290
  158. package/dist/chunk-LSWP7MU2.js.map +0 -1
  159. package/dist/chunk-M2O56UK7.js.map +0 -1
  160. package/dist/chunk-MJSXP4LW.js.map +0 -1
  161. package/dist/chunk-MJZZTKCC.js.map +0 -1
  162. package/dist/chunk-NAAMHWSI.js.map +0 -1
  163. package/dist/chunk-O75FOHXS.js +0 -372
  164. package/dist/chunk-O75FOHXS.js.map +0 -1
  165. package/dist/chunk-OWVVI4VQ.js.map +0 -1
  166. package/dist/chunk-PAOVPSP6.js.map +0 -1
  167. package/dist/chunk-PCX2JQ2J.js +0 -233
  168. package/dist/chunk-PCX2JQ2J.js.map +0 -1
  169. package/dist/chunk-PKW3H26Z.js.map +0 -1
  170. package/dist/chunk-PQZVDCCA.js +0 -125
  171. package/dist/chunk-PQZVDCCA.js.map +0 -1
  172. package/dist/chunk-QWBUKIP2.js.map +0 -1
  173. package/dist/chunk-SGK2B724.js +0 -67
  174. package/dist/chunk-SGK2B724.js.map +0 -1
  175. package/dist/chunk-UHTVXQ2O.js +0 -140
  176. package/dist/chunk-UHTVXQ2O.js.map +0 -1
  177. package/dist/chunk-UO22YNY4.js.map +0 -1
  178. package/dist/chunk-VEAERJVJ.js +0 -43
  179. package/dist/chunk-VEAERJVJ.js.map +0 -1
  180. package/dist/chunk-VRPLZERE.js +0 -1421
  181. package/dist/chunk-VRPLZERE.js.map +0 -1
  182. package/dist/chunk-W4VW5XYB.js +0 -149
  183. package/dist/chunk-W4VW5XYB.js.map +0 -1
  184. package/dist/chunk-WU5CZPLD.js +0 -145
  185. package/dist/chunk-WU5CZPLD.js.map +0 -1
  186. package/dist/chunk-WYLMJQVH.js +0 -240
  187. package/dist/chunk-WYLMJQVH.js.map +0 -1
  188. package/dist/chunk-XGZ5EVMB.js +0 -35
  189. package/dist/chunk-XGZ5EVMB.js.map +0 -1
  190. package/dist/chunk-XVPQGCH4.js +0 -176
  191. package/dist/chunk-XVPQGCH4.js.map +0 -1
  192. package/dist/chunk-ZOBNS7CX.js.map +0 -1
  193. package/dist/chunk-ZQIQ55KK.js +0 -51
  194. package/dist/chunk-ZQIQ55KK.js.map +0 -1
  195. package/dist/cli-U2BEUA55.js.map +0 -1
  196. package/dist/config-CNUIX23Q.js +0 -32
  197. package/dist/doctor-QJJXRWTO.js +0 -31
  198. package/dist/edit-HJ44P44P.js +0 -40
  199. package/dist/fund-Y5IAHZ5D.js +0 -40
  200. package/dist/inspect-NFQ6SQQQ.js +0 -37
  201. package/dist/install-DXX7PVUP.js +0 -854
  202. package/dist/install-DXX7PVUP.js.map +0 -1
  203. package/dist/outcome-ANV4QIED.js +0 -24
  204. package/dist/publish-PCBTCXCZ.js +0 -42
  205. package/dist/read-W7QVRBVD.js +0 -160
  206. package/dist/read-W7QVRBVD.js.map +0 -1
  207. package/dist/run-CJWPGMIQ.js.map +0 -1
  208. package/dist/search-JGAVKTYJ.js +0 -25
  209. package/dist/secp256k1-XRPVBC6V.js.map +0 -1
  210. package/dist/send-C5EOKXOU.js.map +0 -1
  211. package/dist/session-OBCUUIFX.js +0 -89
  212. package/dist/session-OBCUUIFX.js.map +0 -1
  213. package/dist/skill-heal-D6EPLPS6.js +0 -84
  214. package/dist/skill-heal-D6EPLPS6.js.map +0 -1
  215. package/dist/uninstall-OWJNJ5LI.js +0 -73
  216. package/dist/uninstall-OWJNJ5LI.js.map +0 -1
  217. package/dist/update-24Y2CQTT.js.map +0 -1
  218. package/dist/usdc-4VCDHFWX.js +0 -38
  219. package/dist/usdc-4VCDHFWX.js.map +0 -1
  220. package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
  221. package/dist/wallet-OFXDIIGP.js +0 -33
  222. package/dist/wallet-OFXDIIGP.js.map +0 -1
  223. package/dist/wallet-SLRIYJ2U.js +0 -42
  224. package/dist/wallet-SLRIYJ2U.js.map +0 -1
  225. package/docs/command-reference.md +0 -261
  226. package/skills/tenjin/SKILL.md +0 -364
  227. package/skills/tenjin-publish/SKILL.md +0 -224
  228. package/skills/tenjin-publish/references/maintain.md +0 -39
  229. package/skills/tenjin-search/SKILL.md +0 -149
  230. package/skills/tenjin-search/references/permissions.md +0 -106
  231. /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
  232. /package/dist/{buy-2JBYPHAI.js.map → ccip-7RMRLAGV.js.map} +0 -0
  233. /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
  234. /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
  235. /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
  236. /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
  237. /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
  238. /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
  239. /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
  240. /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
  241. /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
  242. /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
  243. /package/dist/{ccip-ZGGWQN4X.js.map → config-MXOX7XDR.js.map} +0 -0
  244. /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
  245. /package/dist/{config-CNUIX23Q.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
  246. /package/dist/{doctor-QJJXRWTO.js.map → install-XUM2XSHW.js.map} +0 -0
  247. /package/dist/{edit-HJ44P44P.js.map → paths-P2N4JTDZ.js.map} +0 -0
  248. /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-SBXZEPEP.js.map} +0 -0
  249. /package/dist/{fund-Y5IAHZ5D.js.map → redact-46ZHF2NH.js.map} +0 -0
  250. /package/dist/{inspect-NFQ6SQQQ.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
  251. /package/dist/{outcome-ANV4QIED.js.map → status-line-wiring-BYPHTYZE.js.map} +0 -0
  252. /package/dist/{publish-PCBTCXCZ.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
  253. /package/dist/{search-JGAVKTYJ.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,33 +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-MJSXP4LW.js";
8
+ } from "./chunk-3AJS6LLN.js";
8
9
  import {
9
10
  emitWriteNotice,
10
11
  sanitizeForTerminal
11
- } from "./chunk-B676GPS2.js";
12
- import "./chunk-LSWP7MU2.js";
12
+ } from "./chunk-YJHHCWM3.js";
13
+ import "./chunk-BBVUVBUO.js";
13
14
  import {
14
15
  package_default
15
- } from "./chunk-ETKZWJ4B.js";
16
- import "./chunk-ZQIQ55KK.js";
17
- import "./chunk-QWBUKIP2.js";
16
+ } from "./chunk-BFFM2WFK.js";
18
17
  import {
19
18
  CliError
20
- } from "./chunk-PAOVPSP6.js";
19
+ } from "./chunk-OCBHUHWB.js";
20
+ import {
21
+ defaultDataDir
22
+ } from "./chunk-2BKS2FVE.js";
23
+ import "./chunk-7WEQQJLG.js";
21
24
  import "./chunk-ZXTAQYNA.js";
22
25
 
23
26
  // src/commands/update.ts
24
- import { spawn } from "child_process";
25
- import { homedir } from "os";
26
- 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";
27
32
 
28
33
  // src/lib/install-location.ts
29
- import { existsSync, realpathSync, statSync } from "fs";
30
- import { delimiter, dirname, join, sep } from "path";
34
+ import { existsSync, realpathSync, statSync } from "node:fs";
35
+ import { delimiter, dirname, join, sep } from "node:path";
31
36
  var REFUSALS = [
32
37
  {
33
38
  test: isSourceCheckout,
@@ -282,15 +287,125 @@ async function runUpdate(opts, ctx, deps = {}) {
282
287
  ctx.io,
283
288
  `tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`
284
289
  );
290
+ const refresh = await refreshProfiles(ctx, deps);
285
291
  return {
286
- data: data(true),
287
- 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)]
288
294
  };
289
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
+ }
290
398
  var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
291
399
  let child;
292
400
  try {
293
- 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
+ });
294
409
  } catch (cause) {
295
410
  res({ kind: "start-failed", cause });
296
411
  return;
@@ -313,6 +428,7 @@ var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
313
428
  });
314
429
  export {
315
430
  runUpdate,
316
- spawnCapture
431
+ spawnCapture,
432
+ versionFreeEntry
317
433
  };
318
- //# sourceMappingURL=update-24Y2CQTT.js.map
434
+ //# sourceMappingURL=update-ANJ2AOTN.js.map