tenjin-cli 0.1.0-alpha.31 → 0.1.0-alpha.33
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.
- package/README.md +45 -26
- package/dist/{_esm-MEXZI5DL.js → _esm-BIN7VY2L.js} +128 -132
- package/dist/{alive-J64H46HI.js → alive-GSOWKUOY.js} +13 -6
- package/dist/auto-update-Y24UL56V.js +24 -0
- package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
- package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
- package/dist/chunk-2GP3HRYK.js.map +1 -0
- package/dist/chunk-2M2VPI2E.js +560 -0
- package/dist/chunk-2M2VPI2E.js.map +1 -0
- package/dist/{chunk-D65GNPS3.js → chunk-2RWB7RKE.js} +288 -108
- package/dist/chunk-2RWB7RKE.js.map +1 -0
- package/dist/{chunk-AGZ7PJKY.js → chunk-36RVGZNY.js} +22 -5
- package/dist/chunk-36RVGZNY.js.map +1 -0
- package/dist/chunk-3AIHRXKO.js +72 -0
- package/dist/chunk-3AIHRXKO.js.map +1 -0
- package/dist/{chunk-S4SAZ7OD.js → chunk-3FMZGI7I.js} +12 -2
- package/dist/{chunk-S4SAZ7OD.js.map → chunk-3FMZGI7I.js.map} +1 -1
- package/dist/chunk-3GNJXKIT.js +198 -0
- package/dist/chunk-3GNJXKIT.js.map +1 -0
- package/dist/{chunk-UQUOVWBG.js → chunk-4K7TQHNP.js} +7 -7
- package/dist/{chunk-A36LQPHV.js → chunk-4LMUQMBH.js} +1 -1
- package/dist/{chunk-A36LQPHV.js.map → chunk-4LMUQMBH.js.map} +1 -1
- package/dist/{chunk-KXQ4UIP7.js → chunk-4USCZ2NI.js} +2 -2
- package/dist/chunk-4YOZGGTZ.js +247 -0
- package/dist/chunk-4YOZGGTZ.js.map +1 -0
- package/dist/chunk-62KNUYWD.js +111 -0
- package/dist/chunk-62KNUYWD.js.map +1 -0
- package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
- package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
- package/dist/{chunk-5MARFNSB.js → chunk-A5GKIG5O.js} +49 -30
- package/dist/chunk-A5GKIG5O.js.map +1 -0
- package/dist/{chunk-YFPY4ONH.js → chunk-AGMVASXZ.js} +4 -4
- package/dist/chunk-BF4XHEQK.js +116 -0
- package/dist/chunk-BF4XHEQK.js.map +1 -0
- package/dist/chunk-BFDQ4WNW.js +119 -0
- package/dist/chunk-BFDQ4WNW.js.map +1 -0
- package/dist/{chunk-P4NH7OUK.js → chunk-C2Q76BVM.js} +49 -50
- package/dist/chunk-C2Q76BVM.js.map +1 -0
- package/dist/chunk-CEXSOI5R.js +808 -0
- package/dist/chunk-CEXSOI5R.js.map +1 -0
- package/dist/{chunk-QSCPK4F5.js → chunk-E7SW44LM.js} +4 -11
- package/dist/chunk-E7SW44LM.js.map +1 -0
- package/dist/chunk-EDJWHDDL.js +33 -0
- package/dist/chunk-EDJWHDDL.js.map +1 -0
- package/dist/chunk-F3ED5WTR.js +13 -0
- package/dist/chunk-F3ED5WTR.js.map +1 -0
- package/dist/{chunk-K72RURN3.js → chunk-FVIGCDSV.js} +2 -2
- package/dist/chunk-FVIGCDSV.js.map +1 -0
- package/dist/{chunk-5K5W4S66.js → chunk-GTTUCOPD.js} +2 -2
- package/dist/{chunk-4ZZO6ULA.js → chunk-HDPUXS3Z.js} +19 -48
- package/dist/chunk-HDPUXS3Z.js.map +1 -0
- package/dist/{chunk-LEFIX6RS.js → chunk-HGGWCP7W.js} +31 -11
- package/dist/chunk-HGGWCP7W.js.map +1 -0
- package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
- package/dist/chunk-HMWYAUA6.js +478 -0
- package/dist/chunk-HMWYAUA6.js.map +1 -0
- package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
- package/dist/chunk-IADZOXKN.js.map +1 -0
- package/dist/{chunk-7Q5FDF65.js → chunk-IE7P2BZE.js} +3 -3
- package/dist/{chunk-77TCKDEC.js → chunk-ILNIZ5I2.js} +788 -508
- package/dist/chunk-ILNIZ5I2.js.map +1 -0
- package/dist/{hosts-FWZOV26H.js → chunk-INTFHMU4.js} +79 -24
- package/dist/chunk-INTFHMU4.js.map +1 -0
- package/dist/{chunk-6E5R45ZO.js → chunk-J57UC3DD.js} +4 -4
- package/dist/{chunk-6E5R45ZO.js.map → chunk-J57UC3DD.js.map} +1 -1
- package/dist/chunk-JNJWBTU2.js +3497 -0
- package/dist/chunk-JNJWBTU2.js.map +1 -0
- package/dist/{chunk-7WU4OPLP.js → chunk-KM7RY2ZS.js} +5 -3
- package/dist/{chunk-7WU4OPLP.js.map → chunk-KM7RY2ZS.js.map} +1 -1
- package/dist/chunk-L6JEXB3E.js +293 -0
- package/dist/chunk-L6JEXB3E.js.map +1 -0
- package/dist/chunk-LRW6S53P.js +450 -0
- package/dist/chunk-LRW6S53P.js.map +1 -0
- package/dist/{chunk-UKY4CHNC.js → chunk-LXAYUOXI.js} +24 -11
- package/dist/chunk-LXAYUOXI.js.map +1 -0
- package/dist/{chunk-WJXLQXJY.js → chunk-MPZUYCAP.js} +4 -1
- package/dist/{chunk-WJXLQXJY.js.map → chunk-MPZUYCAP.js.map} +1 -1
- package/dist/chunk-NDGZDTSJ.js +393 -0
- package/dist/chunk-NDGZDTSJ.js.map +1 -0
- package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
- package/dist/chunk-OJNTCYQQ.js.map +1 -0
- package/dist/{chunk-OHRR5OYM.js → chunk-P3LFTKE7.js} +5 -10
- package/dist/chunk-P3LFTKE7.js.map +1 -0
- package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
- package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
- package/dist/{chunk-5C32RLTA.js → chunk-RVPYTUP4.js} +20 -5
- package/dist/chunk-RVPYTUP4.js.map +1 -0
- package/dist/{chunk-YVFXE7RR.js → chunk-SNNSAGMT.js} +7279 -2627
- package/dist/chunk-SNNSAGMT.js.map +1 -0
- package/dist/{chunk-WK7F3B2E.js → chunk-SO3XRZPX.js} +3 -3
- package/dist/{chunk-R5LCN54M.js → chunk-TC2WZLSC.js} +13 -17
- package/dist/{chunk-R5LCN54M.js.map → chunk-TC2WZLSC.js.map} +1 -1
- package/dist/{chunk-B7HUUJOK.js → chunk-TKPF35W6.js} +3 -3
- package/dist/{chunk-KXVP2VKA.js → chunk-U3IKUGRP.js} +32 -33
- package/dist/chunk-U3IKUGRP.js.map +1 -0
- package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
- package/dist/chunk-UUGOUOVT.js.map +1 -0
- package/dist/{chunk-2XLC3AEX.js → chunk-UXZONNEQ.js} +536 -510
- package/dist/chunk-UXZONNEQ.js.map +1 -0
- package/dist/{chunk-7ZRL2LBQ.js → chunk-V2LQLN5H.js} +6 -6
- package/dist/{chunk-NEFNKLBE.js → chunk-WFSPCCVW.js} +1536 -423
- package/dist/chunk-WFSPCCVW.js.map +1 -0
- package/dist/{chunk-27EPWVOY.js → chunk-WXA2BWTE.js} +7 -3
- package/dist/chunk-WXA2BWTE.js.map +1 -0
- package/dist/chunk-WYXUQGOL.js +191 -0
- package/dist/chunk-WYXUQGOL.js.map +1 -0
- package/dist/chunk-X5ZBP3IY.js +97 -0
- package/dist/chunk-X5ZBP3IY.js.map +1 -0
- package/dist/{chunk-MNXS2U45.js → chunk-ZDZERB6L.js} +206 -297
- package/dist/chunk-ZDZERB6L.js.map +1 -0
- package/dist/chunk-ZNNXRNFD.js +113 -0
- package/dist/chunk-ZNNXRNFD.js.map +1 -0
- package/dist/{chunk-FW75G2W4.js → chunk-ZURZHELF.js} +5 -5
- package/dist/{cli-D5OE3URZ.js → cli-E36SPKBW.js} +145 -64
- package/dist/{cli-D5OE3URZ.js.map → cli-E36SPKBW.js.map} +1 -1
- package/dist/{codex-event-PPNVRRDH.js → codex-event-ZO2GEFE6.js} +2 -2
- package/dist/{codex-host-2RJOJW2B.js → codex-host-KECJVTA2.js} +7 -6
- package/dist/codex-install-HQZDGFXW.js +436 -0
- package/dist/codex-install-HQZDGFXW.js.map +1 -0
- package/dist/{config-ZD4OB2DO.js → config-HY2E4GGW.js} +21 -17
- package/dist/doctor-I6XQEKWD.js +1323 -0
- package/dist/doctor-I6XQEKWD.js.map +1 -0
- package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
- package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
- package/dist/{fund-5ITKQGYF.js → fund-2QRO7OJL.js} +43 -37
- package/dist/{fund-5ITKQGYF.js.map → fund-2QRO7OJL.js.map} +1 -1
- package/dist/hook-command-2UBCSZG6.js +43 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
- package/dist/hosts/claude/tenjin/hooks/register.tsx +51 -11
- package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +2 -1
- package/dist/hosts/codex/tenjin/.mcp.json +3 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +51 -5
- package/dist/hosts-DVQJ32QC.js +38 -0
- package/dist/index.js +32 -11
- package/dist/index.js.map +1 -1
- package/dist/install-ILUX5C4A.js +107 -0
- package/dist/{install-identity-K7EJIQFP.js → install-identity-TZKGY6LQ.js} +11 -10
- package/dist/install-wallet-5M4OTYLX.js +281 -0
- package/dist/install-wallet-5M4OTYLX.js.map +1 -0
- package/dist/isows-native-Q2UDIVPT.js +9 -0
- package/dist/isows-native-Q2UDIVPT.js.map +1 -0
- package/dist/{mcp-3LIJSSJB.js → mcp-LE4DUS22.js} +785 -211
- package/dist/mcp-LE4DUS22.js.map +1 -0
- package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
- package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
- package/dist/{package-ZKQFDWLE.js → package-IJFGMWEV.js} +4 -2
- package/dist/passphrase-IFTDS3CU.js +44 -0
- package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
- package/dist/{pay-WHBERZ3W.js → pay-WCG3IH4R.js} +29 -29
- package/dist/{payments-KVICEKD2.js → payments-HFPPWHTV.js} +15 -14
- package/dist/{payments-KVICEKD2.js.map → payments-HFPPWHTV.js.map} +1 -1
- package/dist/plugin-registration-PZFI5GZW.js +68 -0
- package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
- package/dist/runtime-UZOKSUZX.js +1321 -0
- package/dist/runtime-UZOKSUZX.js.map +1 -0
- package/dist/runtime-fetch-ZSSSK72Y.js +23 -0
- package/dist/runtime-layout-WIDILZ6K.js +25 -0
- package/dist/{send-7G7Y7DLN.js → send-GCVEAQKL.js} +24 -22
- package/dist/{send-7G7Y7DLN.js.map → send-GCVEAQKL.js.map} +1 -1
- package/dist/{status-OF7RH5HM.js → status-HCVAOCN7.js} +55 -25
- package/dist/status-HCVAOCN7.js.map +1 -0
- package/dist/{status-line-XOUE6MPL.js → status-line-OPCXDHL2.js} +10 -9
- package/dist/{status-line-XOUE6MPL.js.map → status-line-OPCXDHL2.js.map} +1 -1
- package/dist/uninstall-BAWRBXXQ.js +481 -0
- package/dist/uninstall-BAWRBXXQ.js.map +1 -0
- package/dist/update-CACXLQLR.js +56 -0
- package/dist/update-CACXLQLR.js.map +1 -0
- package/dist/{usdc-OGOGEHV2.js → usdc-VG4CIOUK.js} +6 -8
- package/dist/usdc-VG4CIOUK.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-S3DA7DFW.js → viemAdapter-By13KInL-DOFTEIJV.js} +3 -3
- package/dist/viemAdapter-By13KInL-DOFTEIJV.js.map +1 -0
- package/dist/wallet-QL4UUXEZ.js +55 -0
- package/dist/wallet-QL4UUXEZ.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +8 -8
- package/docs/agent-permissions.md +50 -28
- package/docs/safety-model.md +1 -1
- package/docs/troubleshooting.md +72 -1
- package/package.json +17 -4
- package/scripts/installers/install.ps1 +67 -0
- package/scripts/installers/install.sh +68 -0
- package/dist/_esm-C5CRWCYU.js +0 -3737
- package/dist/_esm-C5CRWCYU.js.map +0 -1
- package/dist/ccip-NLCSCHKI.js +0 -19
- package/dist/chunk-27EPWVOY.js.map +0 -1
- package/dist/chunk-2XLC3AEX.js.map +0 -1
- package/dist/chunk-4ZZO6ULA.js.map +0 -1
- package/dist/chunk-5C32RLTA.js.map +0 -1
- package/dist/chunk-5IEP5EGE.js +0 -5332
- package/dist/chunk-5IEP5EGE.js.map +0 -1
- package/dist/chunk-5MARFNSB.js.map +0 -1
- package/dist/chunk-77TCKDEC.js.map +0 -1
- package/dist/chunk-7EKYXMUO.js +0 -7536
- package/dist/chunk-7EKYXMUO.js.map +0 -1
- package/dist/chunk-7QKHZQKW.js.map +0 -1
- package/dist/chunk-AGZ7PJKY.js.map +0 -1
- package/dist/chunk-AKWGE6JQ.js.map +0 -1
- package/dist/chunk-BL3332HQ.js +0 -7611
- package/dist/chunk-BL3332HQ.js.map +0 -1
- package/dist/chunk-D65GNPS3.js.map +0 -1
- package/dist/chunk-EGELTSPU.js +0 -2865
- package/dist/chunk-EGELTSPU.js.map +0 -1
- package/dist/chunk-GA7JETVM.js +0 -150
- package/dist/chunk-GA7JETVM.js.map +0 -1
- package/dist/chunk-I3EQFHCD.js +0 -175
- package/dist/chunk-I3EQFHCD.js.map +0 -1
- package/dist/chunk-K3I7C2MO.js +0 -1185
- package/dist/chunk-K3I7C2MO.js.map +0 -1
- package/dist/chunk-K72RURN3.js.map +0 -1
- package/dist/chunk-KXVP2VKA.js.map +0 -1
- package/dist/chunk-LEFIX6RS.js.map +0 -1
- package/dist/chunk-MNXS2U45.js.map +0 -1
- package/dist/chunk-NEFNKLBE.js.map +0 -1
- package/dist/chunk-OHRR5OYM.js.map +0 -1
- package/dist/chunk-P4NH7OUK.js.map +0 -1
- package/dist/chunk-QSCPK4F5.js.map +0 -1
- package/dist/chunk-SJLTEINJ.js.map +0 -1
- package/dist/chunk-TTNESUPQ.js.map +0 -1
- package/dist/chunk-UKY4CHNC.js.map +0 -1
- package/dist/chunk-V6BSF6OC.js +0 -260
- package/dist/chunk-V6BSF6OC.js.map +0 -1
- package/dist/chunk-YVFXE7RR.js.map +0 -1
- package/dist/codex-install-UUZ6QMBQ.js +0 -221
- package/dist/codex-install-UUZ6QMBQ.js.map +0 -1
- package/dist/doctor-KBR34Q4B.js +0 -601
- package/dist/doctor-KBR34Q4B.js.map +0 -1
- package/dist/hook-command-4TYCHHRL.js +0 -39
- package/dist/hosts-FWZOV26H.js.map +0 -1
- package/dist/install-XWGE4Q7L.js +0 -77
- package/dist/install-wallet-XQ6XFZV4.js +0 -117
- package/dist/install-wallet-XQ6XFZV4.js.map +0 -1
- package/dist/mcp-3LIJSSJB.js.map +0 -1
- package/dist/plugin-registration-5TIA564H.js +0 -54
- package/dist/status-OF7RH5HM.js.map +0 -1
- package/dist/uninstall-JXUAFNDB.js +0 -158
- package/dist/uninstall-JXUAFNDB.js.map +0 -1
- package/dist/update-ZKUERSO2.js +0 -44
- package/dist/wallet-2HA6W4R4.js +0 -43
- /package/dist/{_esm-MEXZI5DL.js.map → _esm-BIN7VY2L.js.map} +0 -0
- /package/dist/{alive-J64H46HI.js.map → alive-GSOWKUOY.js.map} +0 -0
- /package/dist/{ccip-7RMRLAGV.js.map → auto-update-Y24UL56V.js.map} +0 -0
- /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
- /package/dist/{chunk-UQUOVWBG.js.map → chunk-4K7TQHNP.js.map} +0 -0
- /package/dist/{chunk-KXQ4UIP7.js.map → chunk-4USCZ2NI.js.map} +0 -0
- /package/dist/{chunk-YFPY4ONH.js.map → chunk-AGMVASXZ.js.map} +0 -0
- /package/dist/{chunk-5K5W4S66.js.map → chunk-GTTUCOPD.js.map} +0 -0
- /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
- /package/dist/{chunk-7Q5FDF65.js.map → chunk-IE7P2BZE.js.map} +0 -0
- /package/dist/{chunk-WK7F3B2E.js.map → chunk-SO3XRZPX.js.map} +0 -0
- /package/dist/{chunk-B7HUUJOK.js.map → chunk-TKPF35W6.js.map} +0 -0
- /package/dist/{chunk-7ZRL2LBQ.js.map → chunk-V2LQLN5H.js.map} +0 -0
- /package/dist/{chunk-FW75G2W4.js.map → chunk-ZURZHELF.js.map} +0 -0
- /package/dist/{codex-event-PPNVRRDH.js.map → codex-event-ZO2GEFE6.js.map} +0 -0
- /package/dist/{codex-host-2RJOJW2B.js.map → codex-host-KECJVTA2.js.map} +0 -0
- /package/dist/{config-ZD4OB2DO.js.map → config-HY2E4GGW.js.map} +0 -0
- /package/dist/{env-proxy-XL4P73MZ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
- /package/dist/{hook-command-4TYCHHRL.js.map → hook-command-2UBCSZG6.js.map} +0 -0
- /package/dist/{install-XWGE4Q7L.js.map → hosts-DVQJ32QC.js.map} +0 -0
- /package/dist/{install-identity-K7EJIQFP.js.map → install-ILUX5C4A.js.map} +0 -0
- /package/dist/{package-ZKQFDWLE.js.map → install-identity-TZKGY6LQ.js.map} +0 -0
- /package/dist/{paths-POPTXJO6.js.map → package-IJFGMWEV.js.map} +0 -0
- /package/dist/{pay-WHBERZ3W.js.map → passphrase-IFTDS3CU.js.map} +0 -0
- /package/dist/{plugin-registration-5TIA564H.js.map → paths-XCSAKISU.js.map} +0 -0
- /package/dist/{redact-6W23GGJC.js.map → pay-WCG3IH4R.js.map} +0 -0
- /package/dist/{update-ZKUERSO2.js.map → plugin-registration-PZFI5GZW.js.map} +0 -0
- /package/dist/{usdc-OGOGEHV2.js.map → redact-D7ASVWKL.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-S3DA7DFW.js.map → runtime-fetch-ZSSSK72Y.js.map} +0 -0
- /package/dist/{wallet-2HA6W4R4.js.map → runtime-layout-WIDILZ6K.js.map} +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
nodeBinPath,
|
|
4
|
+
readRuntimeState,
|
|
5
|
+
versionEntry
|
|
6
|
+
} from "./chunk-ZNNXRNFD.js";
|
|
7
|
+
import {
|
|
8
|
+
configPath,
|
|
9
|
+
defaultDataDir,
|
|
10
|
+
runtimeDir
|
|
11
|
+
} from "./chunk-OJNTCYQQ.js";
|
|
12
|
+
|
|
13
|
+
// src/lib/auto-update.ts
|
|
14
|
+
import { spawn } from "node:child_process";
|
|
15
|
+
import { closeSync, existsSync, openSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { join, resolve } from "node:path";
|
|
18
|
+
var AUTO_UPDATE_FILE = "auto-update.json";
|
|
19
|
+
var AUTO_UPDATE_LOG = "auto-update.log";
|
|
20
|
+
var DAY_MS = 864e5;
|
|
21
|
+
var TLS_OFF = "TLS certificate checks are turned off (NODE_TLS_REJECT_UNAUTHORIZED=0); set NODE_EXTRA_CA_CERTS instead";
|
|
22
|
+
function maybeAutoUpdate(o) {
|
|
23
|
+
try {
|
|
24
|
+
const { env } = o;
|
|
25
|
+
if (env.CI !== void 0 && env.CI.length > 0) return;
|
|
26
|
+
if (env.TENJIN_NO_UPDATE_CHECK === "1") return;
|
|
27
|
+
const home = o.home ?? homedir();
|
|
28
|
+
if (resolve(o.dataDir) !== resolve(defaultDataDir(home))) return;
|
|
29
|
+
if (!autoMode(o.dataDir)) return;
|
|
30
|
+
const root = runtimeDir(o.dataDir);
|
|
31
|
+
const state = readRuntimeState(root);
|
|
32
|
+
if (state === null) return;
|
|
33
|
+
const node = nodeBinPath(root, state.current.node);
|
|
34
|
+
const entry = versionEntry(root, state.current.cli);
|
|
35
|
+
if (!existsSync(node) || !existsSync(entry)) return;
|
|
36
|
+
const nowMs = (o.now ?? Date.now)();
|
|
37
|
+
const previous = readAutoUpdate(root);
|
|
38
|
+
const started = Date.parse(previous?.startedAt ?? "");
|
|
39
|
+
if (!Number.isNaN(started) && nowMs - started >= 0 && nowMs - started < DAY_MS) return;
|
|
40
|
+
if (env.NODE_TLS_REJECT_UNAUTHORIZED === "0") {
|
|
41
|
+
const at = new Date(nowMs).toISOString();
|
|
42
|
+
writeRecord(root, { startedAt: at, finishedAt: at, outcome: "skipped", reason: TLS_OFF });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
writeRecord(root, { ...previous, startedAt: new Date(nowMs).toISOString() });
|
|
46
|
+
const fd = openSync(join(root, AUTO_UPDATE_LOG), "w", 384);
|
|
47
|
+
try {
|
|
48
|
+
const child = (o.spawnImpl ?? spawn)(node, [entry, "update", "--background"], {
|
|
49
|
+
detached: true,
|
|
50
|
+
stdio: ["ignore", fd, fd],
|
|
51
|
+
cwd: home,
|
|
52
|
+
windowsHide: true,
|
|
53
|
+
// The child's own nudge would ask npm again for what it just learned.
|
|
54
|
+
env: { ...env, TENJIN_NO_UPDATE_CHECK: "1" }
|
|
55
|
+
});
|
|
56
|
+
child.on("error", () => void 0);
|
|
57
|
+
child.unref();
|
|
58
|
+
} finally {
|
|
59
|
+
closeSync(fd);
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function autoMode(dataDir) {
|
|
65
|
+
let text;
|
|
66
|
+
try {
|
|
67
|
+
text = readFileSync(configPath(dataDir), "utf8");
|
|
68
|
+
} catch {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const raw = JSON.parse(text);
|
|
72
|
+
const mode = raw?.update?.mode;
|
|
73
|
+
return mode === void 0 || mode === "auto";
|
|
74
|
+
}
|
|
75
|
+
function readAutoUpdate(root) {
|
|
76
|
+
try {
|
|
77
|
+
const raw = JSON.parse(readFileSync(join(root, AUTO_UPDATE_FILE), "utf8"));
|
|
78
|
+
return typeof raw === "object" && raw !== null && !Array.isArray(raw) ? raw : null;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function recordAutoUpdate(root, result) {
|
|
84
|
+
const startedAt = readAutoUpdate(root)?.startedAt;
|
|
85
|
+
writeRecord(root, { ...startedAt !== void 0 ? { startedAt } : {}, ...result });
|
|
86
|
+
}
|
|
87
|
+
function writeRecord(root, record) {
|
|
88
|
+
const path = join(root, AUTO_UPDATE_FILE);
|
|
89
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
90
|
+
writeFileSync(tmp, `${JSON.stringify(record, null, 2)}
|
|
91
|
+
`, { mode: 384 });
|
|
92
|
+
renameSync(tmp, path);
|
|
93
|
+
}
|
|
94
|
+
function autoUpdateLine(root) {
|
|
95
|
+
const r = readAutoUpdate(root);
|
|
96
|
+
if (r === null || r.finishedAt === void 0) return null;
|
|
97
|
+
const when = r.finishedAt.slice(0, 10);
|
|
98
|
+
if (r.outcome === "updated") return `Auto-update: ${when} updated ${r.from} -> ${r.to}`;
|
|
99
|
+
if (r.outcome === "current") return `Auto-update: ${when} up to date (${r.to ?? r.from})`;
|
|
100
|
+
if (r.outcome === "failed") return `Auto-update: ${when} failed: ${r.reason ?? "unknown"}`;
|
|
101
|
+
if (r.outcome === "skipped" && r.reason !== void 0) {
|
|
102
|
+
return `Auto-update: ${when} skipped: ${r.reason}`;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
AUTO_UPDATE_FILE,
|
|
109
|
+
AUTO_UPDATE_LOG,
|
|
110
|
+
TLS_OFF,
|
|
111
|
+
maybeAutoUpdate,
|
|
112
|
+
readAutoUpdate,
|
|
113
|
+
recordAutoUpdate,
|
|
114
|
+
autoUpdateLine
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=chunk-BF4XHEQK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/auto-update.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { closeSync, existsSync, openSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\nimport { configPath, defaultDataDir, runtimeDir } from './paths';\nimport { nodeBinPath, readRuntimeState, versionEntry } from './runtime-layout';\n\n/**\n * BACKGROUND AUTO-UPDATE, the way Claude Code's native installer does it:\n * downloaded in the background, used from the next session. At most once a\n * day, at the start of a Claude Code or Codex session, this starts\n * `tenjin update --background` DETACHED on the runtime's own Node and current\n * entry, and returns: the caller adds no latency and never waits.\n * The child is `tenjin update`'s runtime branch (the release's build\n * provenance is checked before it is downloaded and the build before the\n * switch, the previous version stays, an older one is never switched to, the\n * runtime lock is held), except that it takes only a release published at\n * least a day ago (`BACKGROUND_COOLDOWN_MS` in commands/update). So npm and PATH\n * are never involved, and a running session keeps its version until the next\n * one. Codex has no SessionStart hook, so `tenjin mcp --harness codex` starts\n * it as the server starts; its routing legs are `mcp_tool` calls into that\n * server, so the switch moves nothing the session is using, and the launcher\n * it rewrites starts the next session's server.\n *\n * `node:*`, the paths and the runtime layout only: the `alive` leg and\n * `tenjin mcp` load this, and neither may pay for zod, the config schema or\n * the runtime's writer. The config is read raw for the same reason.\n *\n * <root>/auto-update.json when the last run started, and how it ended\n * <root>/auto-update.log the last run's output, overwritten each run\n */\n\nexport const AUTO_UPDATE_FILE = 'auto-update.json';\nexport const AUTO_UPDATE_LOG = 'auto-update.log';\n\nconst DAY_MS = 86_400_000;\n\n/** Why no background update starts while Node checks no TLS certificate. */\nexport const TLS_OFF =\n 'TLS certificate checks are turned off (NODE_TLS_REJECT_UNAUTHORIZED=0); set NODE_EXTRA_CA_CERTS instead';\n\nexport interface AutoUpdateRecord {\n /** When the last background run was started (ISO). */\n startedAt?: string;\n /** When it finished (ISO); absent while it runs, or if it died. */\n finishedAt?: string;\n outcome?: 'updated' | 'current' | 'failed' | 'skipped';\n from?: string;\n to?: string;\n reason?: string;\n}\n\ntype Spawn = typeof spawn;\n\n/**\n * Start the background update if one is due. Synchronous and never throws:\n * every gate that does not hold returns without spawning, and so does any\n * error, since the session it rides on must start regardless.\n */\nexport function maybeAutoUpdate(o: {\n dataDir: string;\n env: NodeJS.ProcessEnv;\n home?: string;\n now?: () => number;\n spawnImpl?: Spawn;\n}): void {\n try {\n const { env } = o;\n // The same two doors the update nudge has (lib/update-check).\n if (env.CI !== undefined && env.CI.length > 0) return;\n if (env.TENJIN_NO_UPDATE_CHECK === '1') return;\n const home = o.home ?? homedir();\n if (resolve(o.dataDir) !== resolve(defaultDataDir(home))) return;\n if (!autoMode(o.dataDir)) return;\n\n const root = runtimeDir(o.dataDir);\n const state = readRuntimeState(root);\n if (state === null) return;\n const node = nodeBinPath(root, state.current.node);\n const entry = versionEntry(root, state.current.cli);\n if (!existsSync(node) || !existsSync(entry)) return;\n\n const nowMs = (o.now ?? Date.now)();\n const previous = readAutoUpdate(root);\n const started = Date.parse(previous?.startedAt ?? '');\n // A start in the future (a clock set back) counts as due, not as a day away.\n if (!Number.isNaN(started) && nowMs - started >= 0 && nowMs - started < DAY_MS) return;\n\n // NOT WITH TLS CERTIFICATE CHECKS TURNED OFF: the child inherits this\n // environment, and then anyone on the network path can answer for the\n // registry, the dist-tags, the attestations and the tarball alike, so no\n // check the update makes would hold. Recorded as a run, once a day, so\n // doctor names the cause and the fix.\n if (env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {\n const at = new Date(nowMs).toISOString();\n writeRecord(root, { startedAt: at, finishedAt: at, outcome: 'skipped', reason: TLS_OFF });\n return;\n }\n\n // Stamped BEFORE the spawn, so a second session starting in the same\n // second finds it and stays put. The last result is kept for doctor.\n writeRecord(root, { ...previous, startedAt: new Date(nowMs).toISOString() });\n const fd = openSync(join(root, AUTO_UPDATE_LOG), 'w', 0o600);\n try {\n const child = (o.spawnImpl ?? spawn)(node, [entry, 'update', '--background'], {\n detached: true,\n stdio: ['ignore', fd, fd],\n cwd: home,\n windowsHide: true,\n // The child's own nudge would ask npm again for what it just learned.\n env: { ...env, TENJIN_NO_UPDATE_CHECK: '1' },\n });\n child.on('error', () => undefined);\n child.unref();\n } finally {\n closeSync(fd);\n }\n } catch {\n // Never the session's business.\n }\n}\n\n/**\n * `update.mode` as stored, read without the config schema: absent (the\n * default) or `auto` runs; `nudge` and `off` were typed by the person, and an\n * unparsable file is not read as consent. A missing file is the default.\n */\nfunction autoMode(dataDir: string): boolean {\n let text: string;\n try {\n text = readFileSync(configPath(dataDir), 'utf8');\n } catch {\n return true;\n }\n const raw = JSON.parse(text) as { update?: { mode?: unknown } } | null;\n const mode = raw?.update?.mode;\n return mode === undefined || mode === 'auto';\n}\n\n/** The last run's record, or null when there is none or it is unreadable. */\nexport function readAutoUpdate(root: string): AutoUpdateRecord | null {\n try {\n const raw = JSON.parse(readFileSync(join(root, AUTO_UPDATE_FILE), 'utf8')) as unknown;\n return typeof raw === 'object' && raw !== null && !Array.isArray(raw)\n ? (raw as AutoUpdateRecord)\n : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Replace the record with how a run ended, keeping when it started, so no\n * field of an earlier run survives into this one. Throws; the caller decides.\n */\nexport function recordAutoUpdate(root: string, result: Omit<AutoUpdateRecord, 'startedAt'>): void {\n const startedAt = readAutoUpdate(root)?.startedAt;\n writeRecord(root, { ...(startedAt !== undefined ? { startedAt } : {}), ...result });\n}\n\nfunction writeRecord(root: string, record: AutoUpdateRecord): void {\n const path = join(root, AUTO_UPDATE_FILE);\n const tmp = `${path}.${process.pid}.tmp`;\n writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\\n`, { mode: 0o600 });\n renameSync(tmp, path);\n}\n\n/** Doctor's one line about the last finished run, or null when there is none. */\nexport function autoUpdateLine(root: string): string | null {\n const r = readAutoUpdate(root);\n if (r === null || r.finishedAt === undefined) return null;\n const when = r.finishedAt.slice(0, 10);\n if (r.outcome === 'updated') return `Auto-update: ${when} updated ${r.from} -> ${r.to}`;\n if (r.outcome === 'current') return `Auto-update: ${when} up to date (${r.to ?? r.from})`;\n if (r.outcome === 'failed') return `Auto-update: ${when} failed: ${r.reason ?? 'unknown'}`;\n // A run that chose to wait (a release under a day old, TLS checks turned\n // off) says why, so the person sees what holds the update back.\n if (r.outcome === 'skipped' && r.reason !== undefined) {\n return `Auto-update: ${when} skipped: ${r.reason}`;\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,WAAW,YAAY,UAAU,cAAc,YAAY,qBAAqB;AACzF,SAAS,eAAe;AACxB,SAAS,MAAM,eAAe;AA6BvB,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAE/B,IAAM,SAAS;AAGR,IAAM,UACX;AAoBK,SAAS,gBAAgB,GAMvB;AACP,MAAI;AACF,UAAM,EAAE,IAAI,IAAI;AAEhB,QAAI,IAAI,OAAO,UAAa,IAAI,GAAG,SAAS,EAAG;AAC/C,QAAI,IAAI,2BAA2B,IAAK;AACxC,UAAM,OAAO,EAAE,QAAQ,QAAQ;AAC/B,QAAI,QAAQ,EAAE,OAAO,MAAM,QAAQ,eAAe,IAAI,CAAC,EAAG;AAC1D,QAAI,CAAC,SAAS,EAAE,OAAO,EAAG;AAE1B,UAAM,OAAO,WAAW,EAAE,OAAO;AACjC,UAAM,QAAQ,iBAAiB,IAAI;AACnC,QAAI,UAAU,KAAM;AACpB,UAAM,OAAO,YAAY,MAAM,MAAM,QAAQ,IAAI;AACjD,UAAM,QAAQ,aAAa,MAAM,MAAM,QAAQ,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equire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
KEYCHAIN_LOCKED_FIX,
|
|
4
|
+
REPAIR_CLAUSE,
|
|
5
|
+
REPAIR_IN_TERMINAL,
|
|
6
|
+
unlockReasonOf
|
|
7
|
+
} from "./chunk-X5ZBP3IY.js";
|
|
8
|
+
|
|
9
|
+
// src/router/wallet-reasons.ts
|
|
10
|
+
var ASK_FOR_REPAIR = "Ask the person to run `tenjin wallet repair` in their own terminal, then start a new Claude Code session. Never ask for the passphrase.";
|
|
11
|
+
var WALLET_REASONS = {
|
|
12
|
+
no_wallet: {
|
|
13
|
+
reason: "this machine has no wallet",
|
|
14
|
+
fix: "Run `tenjin doctor`.",
|
|
15
|
+
agentFix: "Run `tenjin doctor`."
|
|
16
|
+
},
|
|
17
|
+
wallet_corrupt: {
|
|
18
|
+
// Both causes: a wallet.json nothing can parse, and a keystore that
|
|
19
|
+
// decrypts to a key that does not match its stored address. Doctor and
|
|
20
|
+
// install show this fix themselves, so it must not send the person there.
|
|
21
|
+
reason: "the wallet file cannot be read or does not match its key",
|
|
22
|
+
fix: "Move the wallet file aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one.",
|
|
23
|
+
agentFix: "Ask the person to move the wallet file aside and run `tenjin wallet create` for a fresh key, or to set TENJIN_WALLET_KEY to the intended one. Never ask for the key."
|
|
24
|
+
},
|
|
25
|
+
env_key_invalid: {
|
|
26
|
+
reason: "TENJIN_WALLET_KEY is not a valid private key",
|
|
27
|
+
fix: "Fix or unset TENJIN_WALLET_KEY in the environment Claude Code starts from, then quit Claude Code fully and start a new session.",
|
|
28
|
+
agentFix: "Ask the person to fix or unset TENJIN_WALLET_KEY in the environment Claude Code starts from, then quit Claude Code fully and start a new session. Never ask for the key."
|
|
29
|
+
},
|
|
30
|
+
passphrase_missing: {
|
|
31
|
+
reason: "no saved wallet passphrase can be reached",
|
|
32
|
+
fix: `${REPAIR_IN_TERMINAL} Then start a new Claude Code session.`,
|
|
33
|
+
agentFix: ASK_FOR_REPAIR
|
|
34
|
+
},
|
|
35
|
+
passphrase_wrong: {
|
|
36
|
+
reason: "the saved wallet passphrase does not open the wallet",
|
|
37
|
+
fix: `${REPAIR_IN_TERMINAL} Then start a new Claude Code session.`,
|
|
38
|
+
agentFix: ASK_FOR_REPAIR
|
|
39
|
+
},
|
|
40
|
+
env_passphrase_wrong: {
|
|
41
|
+
reason: "TENJIN_WALLET_PASSPHRASE is set but does not open the wallet",
|
|
42
|
+
// Shown only when no saved passphrase opens the wallet either, so removing
|
|
43
|
+
// the variable alone never unlocks it: repair first, then remove it.
|
|
44
|
+
fix: `Run \`tenjin wallet repair\` yourself ${REPAIR_CLAUSE}, then remove TENJIN_WALLET_PASSPHRASE from the environment Claude Code starts from, then quit Claude Code fully and start a new session.`,
|
|
45
|
+
agentFix: "Ask the person to run `tenjin wallet repair` in their own terminal, then to remove TENJIN_WALLET_PASSPHRASE from the environment Claude Code starts from, then quit Claude Code fully and start a new session. Never ask for the passphrase."
|
|
46
|
+
},
|
|
47
|
+
keychain_locked: {
|
|
48
|
+
reason: "the keychain holding the wallet passphrase is locked or did not answer",
|
|
49
|
+
fix: KEYCHAIN_LOCKED_FIX,
|
|
50
|
+
agentFix: "Ask the person to unlock their keychain (or log in to the desktop session) and retry."
|
|
51
|
+
},
|
|
52
|
+
wallet_locked: {
|
|
53
|
+
reason: "`tenjin mcp` cannot unlock the wallet",
|
|
54
|
+
fix: "Run `tenjin doctor`.",
|
|
55
|
+
agentFix: "Run `tenjin doctor`."
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var UNKNOWN_DETAIL = {
|
|
59
|
+
keychain_locked: "the keychain holding the passphrase did not answer",
|
|
60
|
+
unlock_timeout: "the unlock did not finish in time",
|
|
61
|
+
wallet_locked: "the unlock failed for a reason Tenjin could not classify",
|
|
62
|
+
balance_unreadable: "the wallet balance could not be read",
|
|
63
|
+
check_failed: "the check itself failed",
|
|
64
|
+
not_checked: "no unlock has been tried yet"
|
|
65
|
+
};
|
|
66
|
+
var WALLET_CLASS = /* @__PURE__ */ new Set([
|
|
67
|
+
"no_wallet",
|
|
68
|
+
"wallet_corrupt",
|
|
69
|
+
"env_key_invalid",
|
|
70
|
+
"passphrase_missing",
|
|
71
|
+
"passphrase_wrong",
|
|
72
|
+
"env_passphrase_wrong",
|
|
73
|
+
"keychain_locked",
|
|
74
|
+
"unlock_timeout",
|
|
75
|
+
"wallet_locked",
|
|
76
|
+
"wallet_low"
|
|
77
|
+
]);
|
|
78
|
+
var WALLET_UNLOCKED = "Tenjin wallet unlocked.";
|
|
79
|
+
var WALLET_FUNDED = "Tenjin wallet funded.";
|
|
80
|
+
var NO_SESSION_CHECKED = "this shell passes; no running Claude session checked";
|
|
81
|
+
function entryFor(reason) {
|
|
82
|
+
return reason === "unlock_timeout" ? WALLET_REASONS.wallet_locked : WALLET_REASONS[reason];
|
|
83
|
+
}
|
|
84
|
+
function sessionStartMessage(reason) {
|
|
85
|
+
const r = entryFor(reason);
|
|
86
|
+
return {
|
|
87
|
+
systemMessage: `Tenjin can't use its wallet in this session: ${r.reason}. ${r.fix}`,
|
|
88
|
+
additionalContext: `Tenjin's wallet cannot sign in this session (${r.reason}), so Tenjin is not routing lookups and paid lookups will not run. ${r.agentFix}`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function stillLockedSentence(reason) {
|
|
92
|
+
const r = entryFor(reason);
|
|
93
|
+
return `Tenjin wallet is still locked: ${r.reason}. ${r.fix}`;
|
|
94
|
+
}
|
|
95
|
+
function agentFixFor(reason, fallback) {
|
|
96
|
+
return Object.prototype.hasOwnProperty.call(WALLET_REASONS, reason) ? WALLET_REASONS[reason].agentFix : fallback;
|
|
97
|
+
}
|
|
98
|
+
function agentFixOf(err) {
|
|
99
|
+
const why = unlockReasonOf(err);
|
|
100
|
+
return why === null ? err.fix ?? "" : agentFixFor(why, err.fix ?? "");
|
|
101
|
+
}
|
|
102
|
+
function walletClearedSentence(previousWhy) {
|
|
103
|
+
if (previousWhy === "wallet_low") return WALLET_FUNDED;
|
|
104
|
+
return WALLET_CLASS.has(previousWhy) ? WALLET_UNLOCKED : null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
WALLET_REASONS,
|
|
109
|
+
UNKNOWN_DETAIL,
|
|
110
|
+
WALLET_CLASS,
|
|
111
|
+
WALLET_UNLOCKED,
|
|
112
|
+
NO_SESSION_CHECKED,
|
|
113
|
+
sessionStartMessage,
|
|
114
|
+
stillLockedSentence,
|
|
115
|
+
agentFixFor,
|
|
116
|
+
agentFixOf,
|
|
117
|
+
walletClearedSentence
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=chunk-BFDQ4WNW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/wallet-reasons.ts"],"sourcesContent":["import {\n KEYCHAIN_LOCKED_FIX,\n REPAIR_CLAUSE,\n REPAIR_IN_TERMINAL,\n unlockReasonOf,\n type UnlockReason,\n} from '../lib/wallet-unlock';\n\nexport {\n ENV_PASSPHRASE_WRONG,\n KEYCHAIN_LOCKED_FIX,\n REPAIR_CLAUSE,\n REPAIR_IN_TERMINAL,\n} from '../lib/wallet-unlock';\n\n/** The model-facing fix for a saved passphrase that is gone or wrong. */\nexport const ASK_FOR_REPAIR =\n 'Ask the person to run `tenjin wallet repair` in their own terminal, then start a new Claude Code session. Never ask for the passphrase.';\n\n/**\n * EVERY WORD TENJIN SAYS ABOUT A WALLET THAT CANNOT SIGN, in one place. Pure\n * strings, importing only `../lib/wallet-unlock`, so `alive` and the hooks can\n * carry them without pulling anything else into their chunks.\n *\n * Each reason has TWO fixes, because two different readers see them (B1):\n * - `fix` is for the PERSON: doctor, install at a terminal, repair, wallet\n * errors, SessionStart's `systemMessage`, and hook notices (the harness shows\n * those in `systemMessage` too). Any `fix` that names `tenjin wallet repair`\n * carries {@link REPAIR_CLAUSE}, so the person hears that it asks in their own\n * terminal and that the passphrase never goes into chat.\n * - `agentFix` is for the MODEL only: SessionStart's `additionalContext`, offer\n * notes, the `request` tool's text and MCP tool errors. It tells the model to\n * ask the person to act, and never to ask for the passphrase or key, so a\n * helpful agent never solicits a secret into the transcript.\n *\n * `reason` is a fragment that slots into a sentence (\"... (reason), so ...\").\n * `no_wallet` keeps fee.ts's `UNPAID.no_wallet` wording byte for byte, and\n * `wallet_low` is not here at all: funding copy is out of scope (S5, S6).\n */\nexport const WALLET_REASONS: Record<\n Exclude<UnlockReason, 'unlock_timeout'> | 'wallet_locked',\n { reason: string; fix: string; agentFix: string }\n> = {\n no_wallet: {\n reason: 'this machine has no wallet',\n fix: 'Run `tenjin doctor`.',\n agentFix: 'Run `tenjin doctor`.',\n },\n wallet_corrupt: {\n // Both causes: a wallet.json nothing can parse, and a keystore that\n // decrypts to a key that does not match its stored address. Doctor and\n // install show this fix themselves, so it must not send the person there.\n reason: 'the wallet file cannot be read or does not match its key',\n fix: 'Move the wallet file aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one.',\n agentFix:\n 'Ask the person to move the wallet file aside and run `tenjin wallet create` for a fresh key, or to set TENJIN_WALLET_KEY to the intended one. Never ask for the key.',\n },\n env_key_invalid: {\n reason: 'TENJIN_WALLET_KEY is not a valid private key',\n fix: 'Fix or unset TENJIN_WALLET_KEY in the environment Claude Code starts from, then quit Claude Code fully and start a new session.',\n agentFix:\n 'Ask the person to fix or unset TENJIN_WALLET_KEY in the environment Claude Code starts from, then quit Claude Code fully and start a new session. Never ask for the key.',\n },\n passphrase_missing: {\n reason: 'no saved wallet passphrase can be reached',\n fix: `${REPAIR_IN_TERMINAL} Then start a new Claude Code session.`,\n agentFix: ASK_FOR_REPAIR,\n },\n passphrase_wrong: {\n reason: 'the saved wallet passphrase does not open the wallet',\n fix: `${REPAIR_IN_TERMINAL} Then start a new Claude Code session.`,\n agentFix: ASK_FOR_REPAIR,\n },\n env_passphrase_wrong: {\n reason: 'TENJIN_WALLET_PASSPHRASE is set but does not open the wallet',\n // Shown only when no saved passphrase opens the wallet either, so removing\n // the variable alone never unlocks it: repair first, then remove it.\n fix: `Run \\`tenjin wallet repair\\` yourself ${REPAIR_CLAUSE}, then remove TENJIN_WALLET_PASSPHRASE from the environment Claude Code starts from, then quit Claude Code fully and start a new session.`,\n agentFix:\n 'Ask the person to run `tenjin wallet repair` in their own terminal, then to remove TENJIN_WALLET_PASSPHRASE from the environment Claude Code starts from, then quit Claude Code fully and start a new session. Never ask for the passphrase.',\n },\n keychain_locked: {\n reason: 'the keychain holding the wallet passphrase is locked or did not answer',\n fix: KEYCHAIN_LOCKED_FIX,\n agentFix:\n 'Ask the person to unlock their keychain (or log in to the desktop session) and retry.',\n },\n wallet_locked: {\n reason: '`tenjin mcp` cannot unlock the wallet',\n fix: 'Run `tenjin doctor`.',\n agentFix: 'Run `tenjin doctor`.',\n },\n};\n\n/**\n * Why a verdict is unknown, by its reason: the store or the clock did not\n * answer, or nothing was tried. Said as \"could not check: <detail>\", never as\n * a fault the person must fix.\n */\nexport const UNKNOWN_DETAIL: Readonly<Record<string, string>> = {\n keychain_locked: 'the keychain holding the passphrase did not answer',\n unlock_timeout: 'the unlock did not finish in time',\n wallet_locked: 'the unlock failed for a reason Tenjin could not classify',\n balance_unreadable: 'the wallet balance could not be read',\n check_failed: 'the check itself failed',\n not_checked: 'no unlock has been tried yet',\n};\n\n/** Every reason a notice treats as \"the wallet\": the unlock reasons, the\n * unclassified fallback, and a balance below the routing deposit. */\nexport const WALLET_CLASS: ReadonlySet<string> = new Set<string>([\n 'no_wallet',\n 'wallet_corrupt',\n 'env_key_invalid',\n 'passphrase_missing',\n 'passphrase_wrong',\n 'env_passphrase_wrong',\n 'keychain_locked',\n 'unlock_timeout',\n 'wallet_locked',\n 'wallet_low',\n]);\n\n/** One-time line once a paid call succeeds after an unlock reason was told. */\nexport const WALLET_UNLOCKED = 'Tenjin wallet unlocked.';\n\n/** One-time line once a paid call succeeds after `wallet_low` was told. */\nexport const WALLET_FUNDED = 'Tenjin wallet funded.';\n\n/** Doctor's session-row detail when this shell signs and no served router was seen. */\nexport const NO_SESSION_CHECKED = 'this shell passes; no running Claude session checked';\n\n/**\n * The entry for a reason. `unlock_timeout` has none of its own (it is no-fault\n * and normally says nothing); a caller that still asks gets the unclassified\n * fallback's wording rather than a crash.\n */\nfunction entryFor(reason: UnlockReason | 'wallet_locked') {\n return reason === 'unlock_timeout' ? WALLET_REASONS.wallet_locked : WALLET_REASONS[reason];\n}\n\n/**\n * SessionStart's two fields for a wallet that cannot sign: `systemMessage` is\n * the person's (person `fix`), `additionalContext` the model's (`agentFix`).\n */\nexport function sessionStartMessage(reason: UnlockReason | 'wallet_locked'): {\n systemMessage: string;\n additionalContext: string;\n} {\n const r = entryFor(reason);\n return {\n systemMessage: `Tenjin can't use its wallet in this session: ${r.reason}. ${r.fix}`,\n additionalContext: `Tenjin's wallet cannot sign in this session (${r.reason}), so Tenjin is not routing lookups and paid lookups will not run. ${r.agentFix}`,\n };\n}\n\n/** A wallet-news line in `systemMessage`. Its reader is the person, so the person `fix`. */\nexport function stillLockedSentence(reason: UnlockReason | 'wallet_locked'): string {\n const r = entryFor(reason);\n return `Tenjin wallet is still locked: ${r.reason}. ${r.fix}`;\n}\n\n/**\n * `WALLET_REASONS[reason].agentFix` for a wallet reason; `fallback` otherwise.\n * For model-facing text only (B1). Pass it a reason from `details.unlock`\n * (`unlockReasonOf`) or from a verdict, never from `classifyUnlockError`'s\n * `wallet_locked` fallback for an undetailed error, which would swap a\n * non-wallet error's own fix for wallet advice.\n */\nexport function agentFixFor(reason: string, fallback: string): string {\n return Object.prototype.hasOwnProperty.call(WALLET_REASONS, reason)\n ? WALLET_REASONS[reason as keyof typeof WALLET_REASONS].agentFix\n : fallback;\n}\n\n/**\n * An error's fix, as the MODEL reads it in the `request` tool's text (B1). An\n * error carrying `details.unlock` gets its reason's `agentFix`, which asks the\n * person to act and never asks for the passphrase or key; every other error\n * keeps its own fix byte for byte. Gated on `unlockReasonOf`, never on\n * `classifyUnlockError`: that one calls every undetailed error `wallet_locked`,\n * and the request tool carries `REGISTRY_MISMATCH`, HTTP failures and the\n * rest, whose own fixes must survive.\n */\nexport function agentFixOf(err: { fix?: string | undefined }): string {\n const why = unlockReasonOf(err);\n return why === null ? (err.fix ?? '') : agentFixFor(why, err.fix ?? '');\n}\n\n/**\n * The line that clears a wallet notice told earlier in the session, once a\n * paid call succeeds: funded for `wallet_low`, unlocked for any unlock reason\n * or the unclassified fallback, null for anything else (no wallet news).\n */\nexport function walletClearedSentence(previousWhy: string): string | null {\n if (previousWhy === 'wallet_low') return WALLET_FUNDED;\n return WALLET_CLASS.has(previousWhy) ? WALLET_UNLOCKED : null;\n}\n"],"mappings":";;;;;;;;;AAgBO,IAAM,iBACX;AAsBK,IAAM,iBAGT;AAAA,EACF,WAAW;AAAA,IACT,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,UAAU;AAAA,EACZ;AAAA,EACA,gBAAgB;AAAA;AAAA;AAAA;AAAA,IAId,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,UACE;AAAA,EACJ;AAAA,EACA,iBAAiB;AAAA,IACf,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,UACE;AAAA,EACJ;AAAA,EACA,oBAAoB;AAAA,IAClB,QAAQ;AAAA,IACR,KAAK,GAAG,kBAAkB;AAAA,IAC1B,UAAU;AAAA,EACZ;AAAA,EACA,kBAAkB;AAAA,IAChB,QAAQ;AAAA,IACR,KAAK,GAAG,kBAAkB;AAAA,IAC1B,UAAU;AAAA,EACZ;AAAA,EACA,sBAAsB;AAAA,IACpB,QAAQ;AAAA;AAAA;AAAA,IAGR,KAAK,yCAAyC,aAAa;AAAA,IAC3D,UACE;AAAA,EACJ;AAAA,EACA,iBAAiB;AAAA,IACf,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,UACE;AAAA,EACJ;AAAA,EACA,eAAe;AAAA,IACb,QAAQ;A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";
|
|
|
14
14
|
var OFFER_PREFIX = "offer-";
|
|
15
15
|
var SESSION_FILE = "session.json";
|
|
16
16
|
var REDIRECT_PREFIX = "redirect-";
|
|
17
|
-
var
|
|
18
|
-
var AUGMENT_BODY_SUFFIX = ".docs";
|
|
17
|
+
var NOTE_PREFIX = "note-";
|
|
19
18
|
var QUERY_PREFIX = "query-";
|
|
20
19
|
var CALL_FILE_RE = /^[a-f0-9]{64}\.json$/;
|
|
21
20
|
var STALE_AFTER_MS = 9e4;
|
|
22
21
|
var RECENT_MS = 1e4;
|
|
23
22
|
var EXPIRY_MS = 10 * 6e4;
|
|
24
23
|
var SESSION_ACTIVE_MS = 10 * 6e4;
|
|
25
|
-
var
|
|
24
|
+
var NOTE_REPEAT_MS = 5 * 6e4;
|
|
26
25
|
var MAX_RECORDS = 256;
|
|
27
26
|
var MAX_SESSIONS = 4096;
|
|
28
27
|
var MAX_RECORD_BYTES = 4096;
|
|
28
|
+
var OFFER_ID_RE = /^[\w.:-]{1,200}$/;
|
|
29
29
|
var digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
30
30
|
function bounded(value, limit) {
|
|
31
31
|
const chars = Array.from(value);
|
|
@@ -38,7 +38,7 @@ function sanitize(value, limit) {
|
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
40
|
async function clean(value, limit) {
|
|
41
|
-
const { mask } = await import("./redact-
|
|
41
|
+
const { mask } = await import("./redact-D7ASVWKL.js");
|
|
42
42
|
return sanitize(mask(value), limit);
|
|
43
43
|
}
|
|
44
44
|
async function endpointOf(value) {
|
|
@@ -79,7 +79,7 @@ async function markOffered(dataDir, sessionId, toolUseId, offer, now = Date.now(
|
|
|
79
79
|
const saved = {
|
|
80
80
|
version: 1,
|
|
81
81
|
at: now,
|
|
82
|
-
...offer.offerId !== void 0 &&
|
|
82
|
+
...offer.offerId !== void 0 && OFFER_ID_RE.test(offer.offerId) ? { offerId: offer.offerId } : {},
|
|
83
83
|
...offer.label !== void 0 ? { label: sanitize(offer.label, 32) } : {},
|
|
84
84
|
.../^\d{1,78}$/.test(offer.priceAtomic) ? { priceAtomic: offer.priceAtomic } : {}
|
|
85
85
|
};
|
|
@@ -93,58 +93,57 @@ async function wasOffered(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
|
93
93
|
const stamp = await readStamp(path);
|
|
94
94
|
return stamp !== null && now - stamp.at <= EXPIRY_MS;
|
|
95
95
|
}
|
|
96
|
-
async function
|
|
97
|
-
|
|
98
|
-
const saved = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
provider: sanitize(docs.provider, 60),
|
|
102
|
-
...docs.label !== void 0 ? { label: sanitize(docs.label, 32) } : {}
|
|
103
|
-
};
|
|
104
|
-
return await write(`${base}.json`, saved) ? `${base}${AUGMENT_BODY_SUFFIX}` : null;
|
|
96
|
+
async function markNoted(dataDir, sessionId, toolUseId, note, now = Date.now()) {
|
|
97
|
+
if (!OFFER_ID_RE.test(note.offerId) || !note.line.includes(note.offerId)) return false;
|
|
98
|
+
const saved = { version: 1, at: now, offerId: note.offerId, line: note.line };
|
|
99
|
+
if (Buffer.byteLength(JSON.stringify(saved), "utf8") > MAX_RECORD_BYTES) return false;
|
|
100
|
+
return write(notePath(dataDir, sessionId, toolUseId), saved);
|
|
105
101
|
}
|
|
106
|
-
async function
|
|
107
|
-
const
|
|
108
|
-
const row = await readJson(`${base}.json`);
|
|
102
|
+
async function noteOf(dataDir, sessionId, toolUseId, now = Date.now()) {
|
|
103
|
+
const row = await readJson(notePath(dataDir, sessionId, toolUseId));
|
|
109
104
|
const stamp = stampOf(row);
|
|
110
105
|
if (row === null || stamp === null || now - stamp.at > EXPIRY_MS) return null;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
provider,
|
|
116
|
-
...label !== "" ? { label } : {},
|
|
117
|
-
body: `${base}${AUGMENT_BODY_SUFFIX}`
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
async function claimQuery(dataDir, sessionId, agentId, query, now = Date.now()) {
|
|
121
|
-
const key = digest(JSON.stringify([agentId ?? "", query]));
|
|
122
|
-
const path = join(sessionDir(dataDir, sessionId), `${QUERY_PREFIX}${key}.json`);
|
|
123
|
-
const stamp = { version: 1, at: now };
|
|
124
|
-
try {
|
|
125
|
-
await writeFileAtomicExclusive(path, JSON.stringify(stamp), { mode: 384, dirMode: 448 });
|
|
126
|
-
return true;
|
|
127
|
-
} catch {
|
|
106
|
+
const { offerId, line: line2 } = row;
|
|
107
|
+
if (typeof offerId !== "string" || !OFFER_ID_RE.test(offerId)) return null;
|
|
108
|
+
if (typeof line2 !== "string" || /[\p{Cc}\p{Cf}]/u.test(line2) || !line2.includes(offerId)) {
|
|
109
|
+
return null;
|
|
128
110
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
111
|
+
return { offerId, line: line2 };
|
|
112
|
+
}
|
|
113
|
+
function notePath(dataDir, sessionId, toolUseId) {
|
|
114
|
+
return join(sessionDir(dataDir, sessionId), `${NOTE_PREFIX}${digest(toolUseId)}.json`);
|
|
115
|
+
}
|
|
116
|
+
async function claimNote(dataDir, sessionId, agentId, query, now = Date.now()) {
|
|
117
|
+
return claimOnce(
|
|
118
|
+
(window) => {
|
|
119
|
+
const key = digest(JSON.stringify([agentId ?? "", query, window]));
|
|
120
|
+
return join(sessionDir(dataDir, sessionId), `${QUERY_PREFIX}${key}.json`);
|
|
121
|
+
},
|
|
122
|
+
NOTE_REPEAT_MS,
|
|
123
|
+
now
|
|
124
|
+
);
|
|
132
125
|
}
|
|
133
126
|
function redirectPath(dataDir, sessionId, agentId, target, window) {
|
|
134
127
|
const key = digest(JSON.stringify([agentId ?? "", target, window]));
|
|
135
128
|
return join(sessionDir(dataDir, sessionId), `${REDIRECT_PREFIX}${key}.json`);
|
|
136
129
|
}
|
|
137
130
|
async function claimRedirect(dataDir, sessionId, agentId, target, now = Date.now()) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
return claimOnce(
|
|
132
|
+
(window) => redirectPath(dataDir, sessionId, agentId, target, window),
|
|
133
|
+
EXPIRY_MS,
|
|
134
|
+
now
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
async function claimOnce(pathFor, span, now) {
|
|
138
|
+
const window = Math.floor(now / span);
|
|
139
|
+
const previous = await readStamp(pathFor(window - 1));
|
|
140
|
+
if (previous !== null && now - previous.at <= span) return false;
|
|
141
141
|
const stamp = { version: 1, at: now };
|
|
142
142
|
try {
|
|
143
|
-
await writeFileAtomicExclusive(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
);
|
|
143
|
+
await writeFileAtomicExclusive(pathFor(window), JSON.stringify(stamp), {
|
|
144
|
+
mode: 384,
|
|
145
|
+
dirMode: 448
|
|
146
|
+
});
|
|
148
147
|
return true;
|
|
149
148
|
} catch {
|
|
150
149
|
return false;
|
|
@@ -246,7 +245,7 @@ async function pruneProgress(directory, now = Date.now()) {
|
|
|
246
245
|
}
|
|
247
246
|
}
|
|
248
247
|
function agesByMtime(name) {
|
|
249
|
-
return name.startsWith(".")
|
|
248
|
+
return name.startsWith(".");
|
|
250
249
|
}
|
|
251
250
|
async function mtimeOf(path) {
|
|
252
251
|
try {
|
|
@@ -383,9 +382,9 @@ export {
|
|
|
383
382
|
bindDecision,
|
|
384
383
|
markOffered,
|
|
385
384
|
wasOffered,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
385
|
+
markNoted,
|
|
386
|
+
noteOf,
|
|
387
|
+
claimNote,
|
|
389
388
|
claimRedirect,
|
|
390
389
|
redirectClaimed,
|
|
391
390
|
writeProgress,
|
|
@@ -395,4 +394,4 @@ export {
|
|
|
395
394
|
pruneSessions,
|
|
396
395
|
renderProgress
|
|
397
396
|
};
|
|
398
|
-
//# sourceMappingURL=chunk-
|
|
397
|
+
//# sourceMappingURL=chunk-C2Q76BVM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/progress.ts"],"sourcesContent":["import { createHash, randomUUID } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport { lstat, open, opendir, rm } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { writeFileAtomic, writeFileAtomicExclusive } from '../lib/atomic-json';\n\n/**\n * The live status line's evidence: what this session is looking up right now,\n * which provider is actually being called, and what it cost.\n *\n * DISPLAY ONLY, AND STRICTLY DOWNSTREAM. Nothing here is read by the gate, the\n * decision, the spend policy or the paying leg; every write is best effort and\n * every failure is swallowed, so a full disk or a read-only data dir loses the\n * footer and changes no routing or payment outcome. That is the whole contract\n * this module has to keep. Two markers are read back by the hooks, the offer\n * mark and the redirect claims, and both only ever make a hook say less: losing\n * either routes a call exactly as a session with no record would, and a claim\n * that cannot be written denies nothing. The free-docs\n * records are the same kind: a lost note record is a search with no line\n * after it, and a lost query claim is one more line.\n *\n * KEYED TO THE SESSION, NEVER GUESSED FROM IT. A record lives under the SHA-256\n * of the harness's own `session_id`, so the renderer for one session cannot see\n * another's. The hook knows that id; the tool, which runs inside the MCP server\n * process, does not, so it resolves the session in one of exactly two ways:\n *\n * - BY BINDING. An `execute` decision leaves an `id-<hash>.json` marker in the\n * session that produced it, and the model passes that id back on the tool\n * call. Resolving through the marker is proof, not inference.\n * - BY SOLE ACTIVITY. With no id, the request belongs to the only session that\n * has been active recently, and when two have been, it belongs to neither as\n * far as this module is concerned: {@link resolveProgressSession} returns\n * null and nothing is written. A missing footer is the correct failure;\n * showing one session's lookup in another session's terminal is not.\n */\n\nconst PROGRESS_DIR = 'progress';\n/** The binding marker's prefix, so it can never be read back as a call record. */\nconst BINDING_PREFIX = 'id-';\n/** A pre-call redirect's marker, keyed by the harness's `tool_use_id`. */\nconst OFFER_PREFIX = 'offer-';\n/** The session's own liveness touch, likewise outside the call-record pattern. */\nconst SESSION_FILE = 'session.json';\n/** A pre-call redirect, one file per agent and target in the session. */\nconst REDIRECT_PREFIX = 'redirect-';\n/** A search the pre-call hook noted a free lookup on, keyed by its `tool_use_id`. */\nconst NOTE_PREFIX = 'note-';\n/** One agent's search query that was noted, one file per window, so the same\n * one is not noted twice. */\nconst QUERY_PREFIX = 'query-';\n/** Call records are named by a 64-hex digest and nothing else is read as one. */\nconst CALL_FILE_RE = /^[a-f0-9]{64}\\.json$/;\n\n/** An in-flight call older than this is shown as stale, never as running. */\nexport const STALE_AFTER_MS = 90_000;\n/**\n * How long a state stays on the footer once nothing has replaced it. The demo\n * holds each one for about ten seconds, which is what makes a decision that\n * takes a second readable at a one-second refresh; after that the line is\n * `x402 · ready` again.\n */\nexport const RECENT_MS = 10_000;\n/** Older than this and a record is ignored by the renderer and pruned on write. */\nexport const EXPIRY_MS = 10 * 60_000;\n/** How recently a session must have been touched to claim an id-less request. */\nexport const SESSION_ACTIVE_MS = 10 * 60_000;\n/** How long one agent's identical search is not given the same note again. */\nexport const NOTE_REPEAT_MS = 5 * 60_000;\n/** Above this many files a session directory is reported rather than scanned. */\nconst MAX_RECORDS = 256;\n/** A ceiling on the root scan. {@link pruneSessions} keeps it far below this:\n * a directory is one LIVE session, not one session this machine ever had. */\nconst MAX_SESSIONS = 4_096;\n/** A record larger than this is damaged or not ours; it is skipped unread. */\nconst MAX_RECORD_BYTES = 4_096;\n/** An offer id as a record keeps one: the server's opaque handle. */\nconst OFFER_ID_RE = /^[\\w.:-]{1,200}$/;\n\nexport type ProgressPhase = 'routing' | 'calling' | 'done';\n\n/** The two markers: a session's liveness touch and a decision-id binding. */\ninterface Stamp {\n version: 1;\n at: number;\n}\n\n/** What one call looks like on disk. Every string is already masked and bounded. */\ninterface SavedProgress extends Stamp {\n phase: ProgressPhase;\n /** The tool whose activity this is, as the footer names it. */\n operation: string;\n /** What the state SAYS: the outcome on `done`, and on an in-flight record the\n * stage, when it is not the tool's own `selecting service`. */\n outcome?: string;\n /** Host plus path of the provider actually called, without a scheme. */\n endpoint?: string;\n /** The service's display name as the server gave it. */\n label?: string;\n /** The call's parameters as compact JSON. */\n parameters?: string;\n /** What the provider was paid, as USD. */\n price?: string;\n}\n\n/**\n * THE NOTE RECORD, one per WebSearch the pre-call hook let run with a free\n * offer, keyed by its `tool_use_id`: the offer's id and the server's line,\n * which the after-call hook shows once the search has run. The CLI's alone:\n * the mod draws nothing on the search.\n */\ninterface SavedNote extends Stamp {\n offerId: string;\n line: string;\n}\n\n/** What a note record names: the offer and its line. */\nexport interface NotedOffer {\n offerId: string;\n line: string;\n}\n\n/**\n * THE OFFER RECORD, one per native call a hook redirected, keyed by its\n * `tool_use_id`: when it was made, the offer's id, its `label` when the\n * decision carried one, and its price in atomic USDC. Part of the state\n * contract between this CLI and the plugin's mod (`mod-state.ts`), which reads\n * it to draw the redirected row and to find the `request` call that takes the\n * offer up by its id; it never parses the reason the model read. Version 1\n * grows by optional fields only, so a reader ignores one it does not know, and\n * an older CLI's prune still reads it as a record.\n */\ninterface SavedOffer extends Stamp {\n offerId?: string;\n label?: string;\n priceAtomic?: string;\n}\n\n/** What the offer record names: the offer's id, display name and price. */\nexport interface OfferedTerms {\n offerId?: string;\n label?: string;\n priceAtomic: string;\n}\n\nexport interface ProgressStep {\n phase: ProgressPhase;\n operation?: string;\n outcome?: string;\n /** The executed provider's URL. It can differ from the hint's suggestion. */\n provider?: string;\n /** The service's display name, from its decision, shown in place of the URL. */\n label?: string;\n parameters?: unknown;\n price?: string;\n}\n\nconst digest = (value: string): string => createHash('sha256').update(value).digest('hex');\n\nfunction bounded(value: string, limit: number): string {\n const chars = Array.from(value);\n return chars.length <= limit ? value : `${chars.slice(0, limit - 1).join('')}…`;\n}\n\n/**\n * Provider text reaches a terminal here, so it is treated as hostile: control\n * characters, format characters and directional overrides are replaced before\n * anything is written, and again before anything is printed. A footer that can\n * be made to repaint the line above it is a spoofing surface, not a display.\n */\nexport function sanitize(value: string, limit: number): string {\n return bounded(\n value\n .replace(/[\\p{Cc}\\p{Cf}]/gu, ' ')\n .replace(/\\s+/g, ' ')\n .trim(),\n limit,\n );\n}\n\n/**\n * The CLI's own redaction, behind a dynamic import ON PURPOSE: the rule corpus\n * and the BIP-39 wordlist are a real parse cost, the renderer runs once a\n * second, and only the write path needs them. `dist-chunks.test.ts` pins it.\n */\nasync function clean(value: string, limit: number): Promise<string> {\n const { mask } = await import('../lib/redact');\n return sanitize(mask(value), limit);\n}\n\n/** Host plus path, which is what names a provider to a person watching. */\nasync function endpointOf(value: string): Promise<string> {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return 'invalid endpoint';\n }\n if (url.username !== '' || url.password !== '') return 'invalid endpoint';\n return clean(`${url.host}${url.pathname === '/' ? '' : url.pathname}`, 110);\n}\n\nasync function parametersOf(value: unknown): Promise<string | undefined> {\n let json: string | undefined;\n try {\n json = JSON.stringify(value);\n } catch {\n return undefined;\n }\n return json === undefined ? undefined : clean(json, 180);\n}\n\nexport function sessionDir(dataDir: string, sessionId: string): string {\n return join(dataDir, PROGRESS_DIR, digest(sessionId));\n}\n\n/** A fresh key for one call, so two overlapping lookups never share a record. */\nexport function newCallId(): string {\n return randomUUID();\n}\n\n/**\n * Mark this session live, so an id-less tool call made from it can be\n * attributed. Written on every hook event, including the ones that route\n * nothing: an open session has to be distinguishable from a closed one.\n */\nexport async function noteSession(\n dataDir: string,\n sessionId: string,\n now = Date.now(),\n): Promise<void> {\n await write(join(sessionDir(dataDir, sessionId), SESSION_FILE), { version: 1, at: now });\n}\n\n/** Record that this decision id was produced in this session. */\nexport async function bindDecision(\n dataDir: string,\n sessionId: string,\n decisionId: string,\n now = Date.now(),\n): Promise<void> {\n await write(join(sessionDir(dataDir, sessionId), `${BINDING_PREFIX}${digest(decisionId)}.json`), {\n version: 1,\n at: now,\n });\n}\n\n/**\n * ONE ROUTING ANSWER PER LOOKUP. The pre-call hook marks the native call it\n * redirected, by the harness's own `tool_use_id`, and the after-call hook reads\n * the mark before it asks again about the same call. Expires and is pruned like every\n * other record here.\n */\nexport async function markOffered(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n offer: OfferedTerms,\n now = Date.now(),\n): Promise<void> {\n const saved: SavedOffer = {\n version: 1,\n at: now,\n ...(offer.offerId !== undefined && OFFER_ID_RE.test(offer.offerId)\n ? { offerId: offer.offerId }\n : {}),\n ...(offer.label !== undefined ? { label: sanitize(offer.label, 32) } : {}),\n ...(/^\\d{1,78}$/.test(offer.priceAtomic) ? { priceAtomic: offer.priceAtomic } : {}),\n };\n await write(\n join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`),\n saved,\n );\n}\n\nexport async function wasOffered(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n now = Date.now(),\n): Promise<boolean> {\n const path = join(sessionDir(dataDir, sessionId), `${OFFER_PREFIX}${digest(toolUseId)}.json`);\n const stamp = await readStamp(path);\n return stamp !== null && now - stamp.at <= EXPIRY_MS;\n}\n\n/**\n * A FREE LOOKUP NOTED ON A SEARCH. The pre-call hook keeps the server's line\n * under the harness's own `tool_use_id`, for the after-call hook to show once\n * the search has run. False when nothing was written: the offer id is not an\n * id, the record would pass the 4,096-byte bound every read here holds, or\n * the write failed. That search then gets no line and no tail.\n */\nexport async function markNoted(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n note: NotedOffer,\n now = Date.now(),\n): Promise<boolean> {\n if (!OFFER_ID_RE.test(note.offerId) || !note.line.includes(note.offerId)) return false;\n const saved: SavedNote = { version: 1, at: now, offerId: note.offerId, line: note.line };\n if (Buffer.byteLength(JSON.stringify(saved), 'utf8') > MAX_RECORD_BYTES) return false;\n return write(notePath(dataDir, sessionId, toolUseId), saved);\n}\n\n/**\n * The note {@link markNoted} left for this call, or null: none, expired,\n * damaged, or a line that does not carry its own offer id. What is on disk is\n * input, so every field is checked again.\n */\nexport async function noteOf(\n dataDir: string,\n sessionId: string,\n toolUseId: string,\n now = Date.now(),\n): Promise<NotedOffer | null> {\n const row = await readJson(notePath(dataDir, sessionId, toolUseId));\n const stamp = stampOf(row);\n if (row === null || stamp === null || now - stamp.at > EXPIRY_MS) return null;\n const { offerId, line } = row;\n if (typeof offerId !== 'string' || !OFFER_ID_RE.test(offerId)) return null;\n if (typeof line !== 'string' || /[\\p{Cc}\\p{Cf}]/u.test(line) || !line.includes(offerId)) {\n return null;\n }\n return { offerId, line };\n}\n\nfunction notePath(dataDir: string, sessionId: string, toolUseId: string): string {\n return join(sessionDir(dataDir, sessionId), `${NOTE_PREFIX}${digest(toolUseId)}.json`);\n}\n\n/**\n * ONE NOTE PER QUERY. True, once, when this agent has not had this exact\n * search noted in the last {@link NOTE_REPEAT_MS}, and the claim is now its.\n * The same window-named exclusive create as {@link claimRedirect}, so two\n * parallel copies of one search get one note, after the window too.\n */\nexport async function claimNote(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n query: string,\n now = Date.now(),\n): Promise<boolean> {\n return claimOnce(\n (window) => {\n const key = digest(JSON.stringify([agentId ?? '', query, window]));\n return join(sessionDir(dataDir, sessionId), `${QUERY_PREFIX}${key}.json`);\n },\n NOTE_REPEAT_MS,\n now,\n );\n}\n\n/**\n * ONE RECORD PER AGENT, TARGET AND WINDOW. Subagents share the session id, so\n * the agent is in the key, and the main agent's part is the empty string, which\n * no `agent_id` can be: the decoder refuses an empty one. The target is in it\n * too, one file each, so parallel calls never share a record: one call's\n * redirect can be neither overwritten nor spent by another's. And so is the\n * {@link EXPIRY_MS} window the claim was made in, so a claim is only ever\n * created, never replaced: see {@link claimRedirect}.\n */\nfunction redirectPath(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n target: string,\n window: number,\n): string {\n const key = digest(JSON.stringify([agentId ?? '', target, window]));\n return join(sessionDir(dataDir, sessionId), `${REDIRECT_PREFIX}${key}.json`);\n}\n\n/**\n * NEVER REDIRECTED TWICE FOR ONE TARGET. True, once, when this agent has not\n * been redirected on this exact search or URL in the last {@link EXPIRY_MS},\n * and the claim is now its; the pre-call hook denies only on true. So the\n * agent's own retry of a redirected call runs, whether the lookup it was sent\n * to delivered, failed or was never called, and whatever other calls ran in\n * between.\n *\n * ONLY EVER AN EXCLUSIVE CREATE. Replacing an expired claim let two parallel\n * copies of one call both read the old stamp and both write, and both deny.\n * The claim's file is named by its window instead, so the one create per\n * window decides, and the previous window's claim, while it is still inside\n * {@link EXPIRY_MS}, is read and never touched: a claim made just before a\n * boundary still lasts its full span. A claim that cannot be written is false:\n * the call runs.\n */\nexport async function claimRedirect(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n target: string,\n now = Date.now(),\n): Promise<boolean> {\n return claimOnce(\n (window) => redirectPath(dataDir, sessionId, agentId, target, window),\n EXPIRY_MS,\n now,\n );\n}\n\n/**\n * The one create both claims make: the file named by the `span` window `now`\n * falls in, refused while the previous window's claim is inside its span. A\n * claim that cannot be written is false.\n */\nasync function claimOnce(\n pathFor: (window: number) => string,\n span: number,\n now: number,\n): Promise<boolean> {\n const window = Math.floor(now / span);\n const previous = await readStamp(pathFor(window - 1));\n if (previous !== null && now - previous.at <= span) return false;\n const stamp: Stamp = { version: 1, at: now };\n try {\n await writeFileAtomicExclusive(pathFor(window), JSON.stringify(stamp), {\n mode: 0o600,\n dirMode: 0o700,\n });\n return true;\n } catch {\n // Taken in this window, which is always inside the span, or not writable.\n return false;\n }\n}\n\n/**\n * THE READ HALF OF {@link claimRedirect}: true when this agent already holds a\n * live claim on this exact search or URL. The pre-call arms ask it BEFORE the\n * router, so the retry of a call they already redirected, which they would\n * only withhold, costs no decision and leaves no offer nobody sees. It never\n * writes and never decides on its own: a false here still goes through the\n * exclusive create, which is what keeps two parallel copies to one deny.\n */\nexport async function redirectClaimed(\n dataDir: string,\n sessionId: string,\n agentId: string | undefined,\n target: string,\n now = Date.now(),\n): Promise<boolean> {\n const window = Math.floor(now / EXPIRY_MS);\n for (const at of [window, window - 1]) {\n const stamp = await readStamp(redirectPath(dataDir, sessionId, agentId, target, at));\n if (stamp !== null && now - stamp.at <= EXPIRY_MS) return true;\n }\n return false;\n}\n\n/**\n * Which session directory a tool call belongs to, or null for \"cannot tell\".\n * Null is a normal answer and its only consequence is a footer that stays quiet.\n */\nexport async function resolveProgressSession(\n dataDir: string,\n opts: { id?: string; now?: number } = {},\n): Promise<string | null> {\n const now = opts.now ?? Date.now();\n const root = join(dataDir, PROGRESS_DIR);\n let names: string[];\n try {\n const directory = await opendir(root);\n names = [];\n for await (const entry of directory) {\n if (entry.isDirectory() && /^[a-f0-9]{64}$/.test(entry.name)) names.push(entry.name);\n if (names.length >= MAX_SESSIONS) break;\n }\n } catch {\n return null;\n }\n if (opts.id !== undefined && opts.id.length > 0) {\n const marker = `${BINDING_PREFIX}${digest(opts.id)}.json`;\n for (const name of names) {\n const bound = await readStamp(join(root, name, marker));\n if (bound !== null && now - bound.at <= EXPIRY_MS) return join(root, name);\n }\n // A stale or unknown id says nothing about which session asked, so the\n // sole-activity rule below still applies rather than a wrong attribution.\n }\n const live: string[] = [];\n for (const name of names) {\n const touched = await readStamp(join(root, name, SESSION_FILE));\n if (touched !== null && now - touched.at <= SESSION_ACTIVE_MS) live.push(name);\n if (live.length > 1) return null;\n }\n return live.length === 1 ? join(root, live[0] as string) : null;\n}\n\n/**\n * Record one step of one call. The caller holds the directory (from\n * {@link sessionDir} or {@link resolveProgressSession}) and the call id, so a\n * step never has to re-resolve anything on the hot path.\n */\nexport async function writeProgress(\n directory: string,\n callId: string,\n step: ProgressStep,\n now = Date.now(),\n): Promise<void> {\n const endpoint = step.provider === undefined ? undefined : await endpointOf(step.provider);\n const parameters =\n step.parameters === undefined ? undefined : await parametersOf(step.parameters);\n const saved: SavedProgress = {\n version: 1,\n at: now,\n phase: step.phase,\n operation: sanitize(step.operation ?? 'request', 24) || 'request',\n ...(step.outcome !== undefined ? { outcome: sanitize(step.outcome, 40) } : {}),\n ...(endpoint !== undefined ? { endpoint } : {}),\n ...(step.label !== undefined ? { label: sanitize(step.label, 32) } : {}),\n ...(parameters !== undefined ? { parameters } : {}),\n ...(step.price !== undefined ? { price: sanitize(step.price, 24) } : {}),\n };\n await write(join(directory, `${digest(callId)}.json`), saved);\n}\n\nexport interface LookupFooter {\n /** A decision is in flight. */\n routing(): Promise<void>;\n /** The EXECUTED provider, which can differ from what the hint suggested. */\n calling(step: { provider: string; label?: string; parameters?: unknown }): Promise<void>;\n /** The outcome, and what the provider was paid for it. */\n done(\n outcome: string,\n step?: { provider?: string; label?: string; parameters?: unknown; price?: string },\n ): Promise<void>;\n}\n\n/** A footer for a session this call cannot be attributed to, or for one step\n * of a call whose own footer speaks for it: it writes nothing. */\nexport const SILENT_FOOTER: LookupFooter = {\n routing: async () => undefined,\n calling: async () => undefined,\n done: async () => undefined,\n};\n\n/**\n * The `request` tool's footer: the session is resolved ONCE, at the top of the\n * call, and each later step is one small write. An unresolvable session yields\n * {@link SILENT_FOOTER}, and the lookup runs exactly as it would have.\n */\nexport async function openLookupFooter(\n dataDir: string,\n opts: { id?: string; operation?: string; now?: () => number } = {},\n): Promise<LookupFooter> {\n const now = opts.now ?? Date.now;\n const directory = await resolveProgressSession(dataDir, {\n ...(opts.id !== undefined ? { id: opts.id } : {}),\n now: now(),\n }).catch(() => null);\n if (directory === null) return SILENT_FOOTER;\n const callId = newCallId();\n const operation = opts.operation ?? 'request';\n const step = async (patch: ProgressStep): Promise<void> => {\n await writeProgress(directory, callId, { operation, ...patch }, now());\n };\n return {\n routing: async () => {\n await step({ phase: 'routing' });\n await pruneProgress(directory, now());\n },\n calling: async (calling) => step({ phase: 'calling', ...calling }),\n done: async (outcome, detail) => step({ phase: 'done', outcome, ...detail }),\n };\n}\n\n/**\n * Remove records past {@link EXPIRY_MS}. Run from a writer, never from the\n * renderer: the footer refreshes once a second and must stay read-only.\n */\nexport async function pruneProgress(directory: string, now = Date.now()): Promise<void> {\n try {\n const dir = await opendir(directory);\n let count = 0;\n for await (const entry of dir) {\n if (++count > MAX_RECORDS) return;\n if (!entry.isFile() || entry.name === SESSION_FILE) continue;\n const path = join(directory, entry.name);\n const record = agesByMtime(entry.name) ? await mtimeOf(path) : await readStamp(path);\n if (record === null || now - record.at > EXPIRY_MS) {\n await rm(path, { force: true }).catch(() => undefined);\n }\n }\n } catch {\n // Housekeeping only. Nothing downstream depends on it having run.\n }\n}\n\n/**\n * A FILE THAT IS NOT A WHOLE RECORD is aged by its mtime, never read as one: a\n * temp file between its write and its rename (every writer here names them\n * `.<name>.<suffix>`). Read as a record it is damaged, and the prune deleted\n * it out from under a parallel hook's rename. A docs body an older build left\n * (`augment-*.docs`) reads as damaged, and goes.\n */\nfunction agesByMtime(name: string): boolean {\n return name.startsWith('.');\n}\n\nasync function mtimeOf(path: string): Promise<Stamp | null> {\n try {\n return { version: 1, at: (await lstat(path)).mtimeMs };\n } catch {\n return null;\n }\n}\n\n/**\n * Remove the directories of sessions that are over.\n *\n * WITHOUT THIS THE ROOT ONLY GROWS, one directory per session this machine has\n * ever had, and a root big enough to hit {@link MAX_SESSIONS} would leave\n * {@link resolveProgressSession} scanning an arbitrary subset that need not\n * contain the session asking. Run from the hook, which is the one writer that\n * fires on every turn; a directory whose session is still live is never touched.\n */\nexport async function pruneSessions(dataDir: string, now = Date.now()): Promise<void> {\n const root = join(dataDir, PROGRESS_DIR);\n try {\n const directory = await opendir(root);\n let seen = 0;\n for await (const entry of directory) {\n if (++seen > MAX_SESSIONS) return;\n if (!entry.isDirectory() || !/^[a-f0-9]{64}$/.test(entry.name)) continue;\n const path = join(root, entry.name);\n const session = await readStamp(join(path, SESSION_FILE));\n if (session !== null && now - session.at <= SESSION_ACTIVE_MS) continue;\n // The touch is gone or old, so the only thing that can keep this\n // directory is a record still inside the renderer's window.\n if (await hasLiveRecord(path, now)) continue;\n await rm(path, { recursive: true, force: true }).catch(() => undefined);\n }\n } catch {\n // Housekeeping only. Nothing downstream depends on it having run.\n }\n}\n\nasync function hasLiveRecord(directory: string, now: number): Promise<boolean> {\n try {\n const dir = await opendir(directory);\n let count = 0;\n for await (const entry of dir) {\n if (++count > MAX_RECORDS) return true;\n if (!entry.isFile() || entry.name === SESSION_FILE) continue;\n const record = await readStamp(join(directory, entry.name));\n if (record !== null && now - record.at <= EXPIRY_MS) return true;\n }\n } catch {\n return true;\n }\n return false;\n}\n\n/**\n * The footer for one session: one line, bounded, sanitized, and empty of\n * everything but this session's own calls. Read-only by construction.\n */\nexport async function renderProgress(\n dataDir: string,\n sessionId: string,\n options: { now?: number; columns?: number } = {},\n): Promise<string> {\n const now = options.now ?? Date.now();\n // The harness truncates to the real terminal width, and `COLUMNS` rarely\n // survives into a status-line process, so the default is a wide terminal\n // rather than a narrow one: cutting a provider's path off at 80 columns on a\n // 200-column terminal loses exactly the part worth reading.\n const columns = Math.max(45, Math.min(400, options.columns || 160));\n const directory = sessionDir(dataDir, sessionId);\n const records: SavedProgress[] = [];\n try {\n const dir = await opendir(directory);\n let count = 0;\n for await (const entry of dir) {\n if (++count > MAX_RECORDS) return bounded('x402 · activity exceeds display limit', columns);\n if (!entry.isFile() || !CALL_FILE_RE.test(entry.name)) continue;\n const record = await readCall(join(directory, entry.name));\n if (record !== null && now - record.at <= EXPIRY_MS) records.push(record);\n }\n } catch (error) {\n // A SESSION WITH NO DIRECTORY IS IDLE, not broken: it has simply not looked\n // anything up yet, and the router being on is the thing the idle line says.\n // Any OTHER read failure is this display failing, and a display that failed\n // prints nothing rather than a status it did not read.\n return (error as NodeJS.ErrnoException).code === 'ENOENT' ? READY : '';\n }\n const running = records\n .filter((row) => row.phase !== 'done' && now - row.at <= holdMs(row))\n .sort((a, b) => b.at - a.at);\n // Only a LOOKUP goes stale out loud. A hook decision has a five-second budget,\n // so one still in flight after its hold is a dead hook, and the footer says\n // ready rather than naming a stage nothing is working on.\n const stale = records.filter(\n (row) => row.phase !== 'done' && now - row.at > holdMs(row) && row.operation === 'request',\n );\n const finished = records\n .filter((row) => row.phase === 'done' && now - row.at <= RECENT_MS)\n .sort((a, b) => b.at - a.at);\n const head = running[0] ?? finished[0] ?? stale.sort((a, b) => b.at - a.at)[0];\n if (head === undefined) return READY;\n // OVERLAPPING CALLS ARE COUNTED, NOT HIDDEN. The newest running call is the\n // one worth naming; the rest are a count, because a second endpoint and its\n // parameters do not fit a line beside the first.\n const alsoRunning = running.length - (running[0] === head ? 1 : 0);\n const suffix = alsoRunning > 0 ? ` · +${alsoRunning} more` : '';\n return bounded(`${line(head, now)}${suffix}`, columns);\n}\n\n/** What the footer says when this session has nothing running or just finished.\n * It is the visible proof that the router is on, so it is never blank. */\nconst READY = 'x402 · ready';\n\n/**\n * How long this state holds the line. A lookup in flight holds it until it\n * lands, because a provider call can take a minute; everything else holds it\n * for {@link RECENT_MS}, which is how the demo reads: one state per second or\n * so, each one still there when the next arrives.\n */\nfunction holdMs(row: SavedProgress): number {\n return row.phase !== 'done' && row.operation === 'request' ? STALE_AFTER_MS : RECENT_MS;\n}\n\n/**\n * One call, as the footer says it: `x402 · <tool>: <state> <label or host/path>\n * · <parameters> · <price>`. Every field is sanitized AGAIN here, because what is\n * on disk is input to this process even when this process wrote it.\n */\nfunction line(row: SavedProgress, now: number): string {\n const operation = sanitize(row.operation, 24) || 'request';\n if (row.phase !== 'done' && now - row.at > STALE_AFTER_MS) {\n return `x402 · ${operation}: stale, no outcome recorded`;\n }\n // `selecting service` is the demo's own word for a decision in flight, and a\n // stage the hook names for itself wins over it.\n const state =\n row.phase === 'routing'\n ? sanitize(row.outcome ?? 'selecting service', 40)\n : row.phase === 'calling'\n ? 'calling'\n : sanitize(row.outcome ?? 'done', 40);\n return (\n `x402 · ${operation}: ${state}` +\n // The service's name where its decision gave one, else the URL called.\n (row.label !== undefined\n ? ` ${sanitize(row.label, 32)}`\n : row.endpoint !== undefined\n ? ` ${sanitize(row.endpoint, 110)}`\n : '') +\n (row.parameters !== undefined ? ` · ${sanitize(row.parameters, 180)}` : '') +\n (row.price !== undefined ? ` · ${sanitize(row.price, 24)}` : '')\n );\n}\n\n/** Whether it landed. Every caller but the note record ignores the answer. */\nasync function write(path: string, body: Stamp | SavedProgress | SavedNote): Promise<boolean> {\n try {\n await writeFileAtomic(path, JSON.stringify(body), { mode: 0o600, dirMode: 0o700 });\n return true;\n } catch {\n // The footer is the only thing that can be lost here, by design.\n return false;\n }\n}\n\n/** A marker's timestamp, or null for absent, damaged or not ours. */\nasync function readStamp(path: string): Promise<Stamp | null> {\n return stampOf(await readJson(path));\n}\n\nfunction stampOf(row: Record<string, unknown> | null): Stamp | null {\n if (row === null) return null;\n return row.version === 1 && typeof row.at === 'number' && Number.isFinite(row.at)\n ? { version: 1, at: row.at }\n : null;\n}\n\n/** A call record, or null. Every field is re-checked: what is on disk is input. */\nasync function readCall(path: string): Promise<SavedProgress | null> {\n const row = await readJson(path);\n const stamp = stampOf(row);\n if (row === null || stamp === null || typeof row.operation !== 'string') return null;\n if (!['routing', 'calling', 'done'].includes(row.phase as string)) return null;\n const optional = ['outcome', 'endpoint', 'label', 'parameters', 'price'] as const;\n if (!optional.every((key) => row[key] === undefined || typeof row[key] === 'string')) return null;\n return {\n ...stamp,\n phase: row.phase as ProgressPhase,\n operation: row.operation,\n ...Object.fromEntries(\n optional.filter((key) => row[key] !== undefined).map((key) => [key, row[key]]),\n ),\n };\n}\n\n/**\n * One bounded JSON object, or null. `O_NOFOLLOW` because these files live under\n * a directory the user can write: a symlink planted here must not turn a footer\n * read into a read of something else.\n */\nasync function readJson(path: string): Promise<Record<string, unknown> | null> {\n const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => undefined);\n if (file === undefined) return null;\n try {\n if ((await file.stat()).size > MAX_RECORD_BYTES) return null;\n const buffer = Buffer.alloc(MAX_RECORD_BYTES + 1);\n const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);\n if (bytesRead > MAX_RECORD_BYTES) return null;\n const parsed: unknown = JSON.parse(buffer.subarray(0, bytesRead).toString('utf8'));\n return parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)\n ? null\n : (parsed as Record<string, unknown>);\n } catch {\n return null;\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n"],"mappings":";;;;;;;AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,iBAAiB;AAC1B,SAAS,OAAO,M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