tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.31
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/NOTICE.md +54 -7
- package/README.md +100 -266
- package/dist/{_esm-FEASBWRP.js → _esm-MEXZI5DL.js} +9 -10
- package/dist/alive-J64H46HI.js +31 -0
- package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-27EPWVOY.js +108 -0
- package/dist/chunk-27EPWVOY.js.map +1 -0
- package/dist/chunk-2SNUOHAT.js +75 -0
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/{chunk-Z6MFJV5Z.js → chunk-2XLC3AEX.js} +857 -504
- package/dist/chunk-2XLC3AEX.js.map +1 -0
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/chunk-4ZZO6ULA.js +151 -0
- package/dist/chunk-4ZZO6ULA.js.map +1 -0
- package/dist/chunk-5C32RLTA.js +115 -0
- package/dist/chunk-5C32RLTA.js.map +1 -0
- package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5K5W4S66.js +105 -0
- package/dist/chunk-5K5W4S66.js.map +1 -0
- package/dist/chunk-5MARFNSB.js +2018 -0
- package/dist/chunk-5MARFNSB.js.map +1 -0
- package/dist/{chunk-CYOF7ROH.js → chunk-6E5R45ZO.js} +3 -3
- package/dist/chunk-77TCKDEC.js +1987 -0
- package/dist/chunk-77TCKDEC.js.map +1 -0
- package/dist/chunk-7EKYXMUO.js +7536 -0
- package/dist/chunk-7EKYXMUO.js.map +1 -0
- package/dist/chunk-7Q5FDF65.js +159 -0
- package/dist/chunk-7Q5FDF65.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/{chunk-MUBUQVC3.js → chunk-7WEQQJLG.js} +6 -5
- package/dist/{chunk-MUBUQVC3.js.map → chunk-7WEQQJLG.js.map} +1 -1
- package/dist/chunk-7WU4OPLP.js +244 -0
- package/dist/chunk-7WU4OPLP.js.map +1 -0
- package/dist/chunk-7ZRL2LBQ.js +192 -0
- package/dist/chunk-7ZRL2LBQ.js.map +1 -0
- package/dist/chunk-A36LQPHV.js +29 -0
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/chunk-AGZ7PJKY.js +326 -0
- package/dist/chunk-AGZ7PJKY.js.map +1 -0
- package/dist/chunk-AKWGE6JQ.js +49 -0
- package/dist/chunk-AKWGE6JQ.js.map +1 -0
- package/dist/chunk-B7HUUJOK.js +29 -0
- package/dist/chunk-B7HUUJOK.js.map +1 -0
- package/dist/{chunk-S3IGX57D.js → chunk-BL3332HQ.js} +290 -7361
- package/dist/chunk-BL3332HQ.js.map +1 -0
- package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
- package/dist/chunk-D65GNPS3.js +12708 -0
- package/dist/chunk-D65GNPS3.js.map +1 -0
- package/dist/chunk-DOQGNFHM.js +121 -0
- package/dist/chunk-DOQGNFHM.js.map +1 -0
- package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
- package/dist/chunk-FW75G2W4.js +406 -0
- package/dist/chunk-FW75G2W4.js.map +1 -0
- package/dist/chunk-GA7JETVM.js +150 -0
- package/dist/chunk-GA7JETVM.js.map +1 -0
- package/dist/chunk-I3EQFHCD.js +175 -0
- package/dist/chunk-I3EQFHCD.js.map +1 -0
- package/dist/chunk-JKKAIPTU.js +108 -0
- package/dist/chunk-JKKAIPTU.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-NCE5NSN6.js → chunk-K3I7C2MO.js} +142 -12
- package/dist/chunk-K3I7C2MO.js.map +1 -0
- package/dist/chunk-K72RURN3.js +239 -0
- package/dist/chunk-K72RURN3.js.map +1 -0
- package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/chunk-KXQ4UIP7.js +228 -0
- package/dist/chunk-KXQ4UIP7.js.map +1 -0
- package/dist/chunk-KXVP2VKA.js +194 -0
- package/dist/chunk-KXVP2VKA.js.map +1 -0
- package/dist/chunk-LEFIX6RS.js +100 -0
- package/dist/chunk-LEFIX6RS.js.map +1 -0
- package/dist/chunk-LHHMV4GU.js +27 -0
- package/dist/chunk-LHHMV4GU.js.map +1 -0
- package/dist/{chunk-YBMMV4Y4.js → chunk-MEFB5KHA.js} +13 -5
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/chunk-MNXS2U45.js +1768 -0
- package/dist/chunk-MNXS2U45.js.map +1 -0
- package/dist/{chunk-UGX7YPX2.js → chunk-NEFNKLBE.js} +9 -11
- package/dist/{chunk-UGX7YPX2.js.map → chunk-NEFNKLBE.js.map} +1 -1
- package/dist/chunk-OHRR5OYM.js +63 -0
- package/dist/chunk-OHRR5OYM.js.map +1 -0
- package/dist/chunk-ORWL5BSN.js +269 -0
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/chunk-P4NH7OUK.js +398 -0
- package/dist/chunk-P4NH7OUK.js.map +1 -0
- package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QSCPK4F5.js +145 -0
- package/dist/chunk-QSCPK4F5.js.map +1 -0
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-XJIW7USF.js → chunk-R5LCN54M.js} +118 -9
- package/dist/chunk-R5LCN54M.js.map +1 -0
- package/dist/chunk-S4SAZ7OD.js +30 -0
- package/dist/chunk-S4SAZ7OD.js.map +1 -0
- package/dist/chunk-SJLTEINJ.js +117 -0
- package/dist/chunk-SJLTEINJ.js.map +1 -0
- package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-UKY4CHNC.js +498 -0
- package/dist/chunk-UKY4CHNC.js.map +1 -0
- package/dist/chunk-UQUOVWBG.js +114 -0
- package/dist/chunk-UQUOVWBG.js.map +1 -0
- package/dist/chunk-V6BSF6OC.js +260 -0
- package/dist/chunk-V6BSF6OC.js.map +1 -0
- package/dist/chunk-WJXLQXJY.js +43 -0
- package/dist/chunk-WJXLQXJY.js.map +1 -0
- package/dist/chunk-WK7F3B2E.js +114 -0
- package/dist/chunk-WK7F3B2E.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/chunk-YFPY4ONH.js +127 -0
- package/dist/chunk-YFPY4ONH.js.map +1 -0
- package/dist/{chunk-OYMYCW7J.js → chunk-YVFXE7RR.js} +606 -97
- package/dist/chunk-YVFXE7RR.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-SBXI5AMS.js → cli-D5OE3URZ.js} +458 -218
- package/dist/cli-D5OE3URZ.js.map +1 -0
- package/dist/codex-event-PPNVRRDH.js +16 -0
- package/dist/codex-host-2RJOJW2B.js +28 -0
- package/dist/codex-install-UUZ6QMBQ.js +221 -0
- package/dist/codex-install-UUZ6QMBQ.js.map +1 -0
- package/dist/config-ZD4OB2DO.js +51 -0
- package/dist/dist-3LOO6M4U.js +2842 -0
- package/dist/dist-3LOO6M4U.js.map +1 -0
- package/dist/doctor-KBR34Q4B.js +601 -0
- package/dist/doctor-KBR34Q4B.js.map +1 -0
- package/dist/env-proxy-XL4P73MZ.js +15 -0
- package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/ethersCompat-Df4a6QIZ-THAVUGIJ.js.map +1 -0
- package/dist/fund-5ITKQGYF.js +372 -0
- package/dist/fund-5ITKQGYF.js.map +1 -0
- package/dist/hook-command-4TYCHHRL.js +39 -0
- package/dist/hook-command-4TYCHHRL.js.map +1 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +15 -0
- package/dist/hosts/claude/tenjin/.mcp.json +12 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +224 -0
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
- package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
- package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
- package/dist/hosts/codex/tenjin/.mcp.json +12 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +52 -0
- package/dist/hosts-FWZOV26H.js +216 -0
- package/dist/hosts-FWZOV26H.js.map +1 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/install-XWGE4Q7L.js +77 -0
- package/dist/install-XWGE4Q7L.js.map +1 -0
- package/dist/install-identity-K7EJIQFP.js +30 -0
- package/dist/install-identity-K7EJIQFP.js.map +1 -0
- package/dist/install-wallet-XQ6XFZV4.js +117 -0
- package/dist/install-wallet-XQ6XFZV4.js.map +1 -0
- package/dist/mcp-3LIJSSJB.js +13553 -0
- package/dist/mcp-3LIJSSJB.js.map +1 -0
- package/dist/package-ZKQFDWLE.js +37 -0
- package/dist/package-ZKQFDWLE.js.map +1 -0
- package/dist/paths-POPTXJO6.js +61 -0
- package/dist/paths-POPTXJO6.js.map +1 -0
- package/dist/pay-WHBERZ3W.js +55 -0
- package/dist/pay-WHBERZ3W.js.map +1 -0
- package/dist/payments-KVICEKD2.js +110 -0
- package/dist/payments-KVICEKD2.js.map +1 -0
- package/dist/plugin-registration-5TIA564H.js +54 -0
- package/dist/plugin-registration-5TIA564H.js.map +1 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/redact-6W23GGJC.js.map +1 -0
- package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/secp256k1-ZZZT2CAX.js.map +1 -0
- package/dist/send-7G7Y7DLN.js +228 -0
- package/dist/send-7G7Y7DLN.js.map +1 -0
- package/dist/status-OF7RH5HM.js +120 -0
- package/dist/status-OF7RH5HM.js.map +1 -0
- package/dist/status-line-XOUE6MPL.js +90 -0
- package/dist/status-line-XOUE6MPL.js.map +1 -0
- package/dist/uninstall-JXUAFNDB.js +158 -0
- package/dist/uninstall-JXUAFNDB.js.map +1 -0
- package/dist/update-ZKUERSO2.js +44 -0
- package/dist/update-ZKUERSO2.js.map +1 -0
- package/dist/usdc-OGOGEHV2.js +40 -0
- package/dist/usdc-OGOGEHV2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-S3DA7DFW.js} +5 -5
- package/dist/viemAdapter-By13KInL-S3DA7DFW.js.map +1 -0
- package/dist/wallet-2HA6W4R4.js +43 -0
- package/dist/wallet-2HA6W4R4.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +196 -0
- package/docs/safety-model.md +59 -0
- package/docs/troubleshooting.md +13 -0
- package/package.json +28 -19
- package/LICENSE +0 -21
- package/dist/buy-EE6SEXP6.js +0 -1598
- package/dist/buy-EE6SEXP6.js.map +0 -1
- package/dist/candidate-ERMSYYQZ.js +0 -127
- package/dist/candidate-ERMSYYQZ.js.map +0 -1
- package/dist/chunk-3OV7E5G5.js +0 -18
- package/dist/chunk-3OV7E5G5.js.map +0 -1
- package/dist/chunk-4ONXEEQL.js +0 -152
- package/dist/chunk-4ONXEEQL.js.map +0 -1
- package/dist/chunk-662MSGZB.js +0 -286
- package/dist/chunk-662MSGZB.js.map +0 -1
- package/dist/chunk-7KUW4MJD.js +0 -59
- package/dist/chunk-7KUW4MJD.js.map +0 -1
- package/dist/chunk-AWPAWHNX.js +0 -333
- package/dist/chunk-AWPAWHNX.js.map +0 -1
- package/dist/chunk-DXTQ3CSI.js +0 -171
- package/dist/chunk-DXTQ3CSI.js.map +0 -1
- package/dist/chunk-ESPNTPQ2.js +0 -207
- package/dist/chunk-ESPNTPQ2.js.map +0 -1
- package/dist/chunk-FJPLRISB.js +0 -79
- package/dist/chunk-FJPLRISB.js.map +0 -1
- package/dist/chunk-GO75V3NZ.js +0 -160
- package/dist/chunk-GO75V3NZ.js.map +0 -1
- package/dist/chunk-JPHG2JW3.js +0 -96
- package/dist/chunk-JPHG2JW3.js.map +0 -1
- package/dist/chunk-NCE5NSN6.js.map +0 -1
- package/dist/chunk-OYMYCW7J.js.map +0 -1
- package/dist/chunk-RY4XKNV3.js +0 -140
- package/dist/chunk-RY4XKNV3.js.map +0 -1
- package/dist/chunk-S3IGX57D.js.map +0 -1
- package/dist/chunk-TLCMMYLY.js +0 -126
- package/dist/chunk-TLCMMYLY.js.map +0 -1
- package/dist/chunk-UO22YNY4.js +0 -69
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-XHC6FCGZ.js +0 -261
- package/dist/chunk-XHC6FCGZ.js.map +0 -1
- package/dist/chunk-XJIW7USF.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YN5SHIXQ.js +0 -126
- package/dist/chunk-YN5SHIXQ.js.map +0 -1
- package/dist/chunk-Z52RA3NC.js +0 -137
- package/dist/chunk-Z52RA3NC.js.map +0 -1
- package/dist/chunk-Z6MFJV5Z.js.map +0 -1
- package/dist/cli-SBXI5AMS.js.map +0 -1
- package/dist/config-VELDKLHY.js +0 -21
- package/dist/doctor-T3KWNNP2.js +0 -20
- package/dist/inspect-LMKOXE4Y.js +0 -96
- package/dist/inspect-LMKOXE4Y.js.map +0 -1
- package/dist/install-LEX3ENQ6.js +0 -387
- package/dist/install-LEX3ENQ6.js.map +0 -1
- package/dist/lookup-ZPN2Q67N.js +0 -129
- package/dist/lookup-ZPN2Q67N.js.map +0 -1
- package/dist/outcome-N7TAK6WR.js +0 -66
- package/dist/outcome-N7TAK6WR.js.map +0 -1
- package/dist/publish-BKBQQAW4.js +0 -1478
- package/dist/publish-BKBQQAW4.js.map +0 -1
- package/dist/usdc-JIAJW4SV.js +0 -22
- package/dist/wallet-CWEMYVIH.js +0 -179
- package/dist/wallet-CWEMYVIH.js.map +0 -1
- package/dist/wallet-PA54CRBL.js +0 -30
- package/skills/tenjin/SKILL.md +0 -199
- package/skills/tenjin-publish/SKILL.md +0 -111
- package/skills/tenjin-search/SKILL.md +0 -133
- /package/dist/{_esm-FEASBWRP.js.map → _esm-MEXZI5DL.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → alive-J64H46HI.js.map} +0 -0
- /package/dist/{ccip-XR5NE5QK.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{config-VELDKLHY.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-ZMHYXMO6.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-6E5R45ZO.js.map} +0 -0
- /package/dist/{chunk-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
- /package/dist/{chunk-QVX5MWJZ.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-HIVZG55D.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-RRN3YTK7.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-HSDCI7OV.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{doctor-T3KWNNP2.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → codex-event-PPNVRRDH.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → codex-host-2RJOJW2B.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → config-ZD4OB2DO.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
emitNotice
|
|
4
|
+
} from "./chunk-K72RURN3.js";
|
|
5
|
+
import {
|
|
6
|
+
external_exports,
|
|
7
|
+
loadConfig
|
|
8
|
+
} from "./chunk-YVFXE7RR.js";
|
|
9
|
+
import {
|
|
10
|
+
writeFileAtomic
|
|
11
|
+
} from "./chunk-7WEQQJLG.js";
|
|
12
|
+
import {
|
|
13
|
+
updateCheckPath
|
|
14
|
+
} from "./chunk-SJLTEINJ.js";
|
|
15
|
+
import {
|
|
16
|
+
package_default
|
|
17
|
+
} from "./chunk-5C32RLTA.js";
|
|
18
|
+
|
|
19
|
+
// src/lib/update-check.ts
|
|
20
|
+
import { readFile } from "node:fs/promises";
|
|
21
|
+
var NUDGE_OPT_OUT = "TENJIN_NO_UPDATE_CHECK";
|
|
22
|
+
var CHECK_INTERVAL_MS = 864e5;
|
|
23
|
+
var FETCH_TIMEOUT_MS = 1500;
|
|
24
|
+
var DIST_TAGS_URL = "https://registry.npmjs.org/-/package/tenjin-cli/dist-tags";
|
|
25
|
+
var TagEntrySchema = external_exports.object({
|
|
26
|
+
checkedAtMs: external_exports.number(),
|
|
27
|
+
/** The version the tag named. Absent when the answer was unusable. */
|
|
28
|
+
latest: external_exports.string().optional(),
|
|
29
|
+
/** When the nudge was last PRINTED for this tag. Absent until one has been. */
|
|
30
|
+
notifiedAtMs: external_exports.number().optional()
|
|
31
|
+
});
|
|
32
|
+
var CacheSchema = external_exports.object({
|
|
33
|
+
schemaVersion: external_exports.literal(1),
|
|
34
|
+
tags: external_exports.record(external_exports.string(), TagEntrySchema),
|
|
35
|
+
/**
|
|
36
|
+
* The resolved "you could upgrade" fact, written whenever it changes and
|
|
37
|
+
* cleared when it stops being true.
|
|
38
|
+
*
|
|
39
|
+
* Denormalized from `tags` on purpose: the generated hook scripts are
|
|
40
|
+
* standalone .mjs that cannot import this module and do not know which
|
|
41
|
+
* version is running, so a per-tag entry would leave them unable to tell an
|
|
42
|
+
* upgrade from a match. Storing the comparison's ANSWER is what lets a hook
|
|
43
|
+
* report it without reimplementing any of it.
|
|
44
|
+
*/
|
|
45
|
+
signal: external_exports.object({ current: external_exports.string(), latest: external_exports.string() }).optional()
|
|
46
|
+
});
|
|
47
|
+
var DistTagsSchema = external_exports.record(external_exports.string(), external_exports.string());
|
|
48
|
+
async function maybeUpdate(deps) {
|
|
49
|
+
try {
|
|
50
|
+
const env = deps.env ?? process.env;
|
|
51
|
+
if (env.CI !== void 0 && env.CI.length > 0) return;
|
|
52
|
+
if (env[NUDGE_OPT_OUT] === "1") return;
|
|
53
|
+
const mode = deps.mode ?? (await loadConfig(deps.dir)).update.mode;
|
|
54
|
+
if (mode === "off") return;
|
|
55
|
+
const nowMs = (deps.now ?? Date.now)();
|
|
56
|
+
const current = deps.currentVersion ?? package_default.version;
|
|
57
|
+
const path = updateCheckPath(deps.dir);
|
|
58
|
+
const tag = channelTag(current);
|
|
59
|
+
if (tag === null) return;
|
|
60
|
+
const cached = await readCache(path);
|
|
61
|
+
const entry = cached?.tags[tag];
|
|
62
|
+
const fresh = entry !== void 0 && nowMs - entry.checkedAtMs < CHECK_INTERVAL_MS;
|
|
63
|
+
let latest;
|
|
64
|
+
if (fresh) {
|
|
65
|
+
latest = entry.latest ?? null;
|
|
66
|
+
} else {
|
|
67
|
+
const answer = await resolveLatest(current, deps);
|
|
68
|
+
if (answer === null) return;
|
|
69
|
+
latest = answer.latest;
|
|
70
|
+
}
|
|
71
|
+
const upgradeable = latest !== null && isNewer(latest, current);
|
|
72
|
+
const human = deps.io.isTTY && !deps.json;
|
|
73
|
+
const notifiedAtMs = entry?.notifiedAtMs;
|
|
74
|
+
const due = human && upgradeable && (notifiedAtMs === void 0 || nowMs - notifiedAtMs >= CHECK_INTERVAL_MS);
|
|
75
|
+
const nudgedAtMs = due ? nowMs : notifiedAtMs;
|
|
76
|
+
const signal = upgradeable && latest !== null ? { current, latest } : void 0;
|
|
77
|
+
const signalChanged = cached?.signal?.current !== signal?.current || cached?.signal?.latest !== signal?.latest;
|
|
78
|
+
if (!fresh || due || signalChanged) {
|
|
79
|
+
await writeCache(path, {
|
|
80
|
+
schemaVersion: 1,
|
|
81
|
+
...signal !== void 0 ? { signal } : {},
|
|
82
|
+
// Read-modify-write: the tag this run did not ask about keeps whatever it
|
|
83
|
+
// knew, including its own nudge clock.
|
|
84
|
+
tags: {
|
|
85
|
+
...cached?.tags,
|
|
86
|
+
[tag]: {
|
|
87
|
+
checkedAtMs: fresh ? entry.checkedAtMs : nowMs,
|
|
88
|
+
...latest !== null ? { latest } : {},
|
|
89
|
+
...nudgedAtMs !== void 0 ? { notifiedAtMs: nudgedAtMs } : {}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (due && latest !== null) {
|
|
95
|
+
emitNotice(
|
|
96
|
+
deps.io,
|
|
97
|
+
`tenjin-cli ${latest} is available (you have ${current}). Update: run tenjin update`,
|
|
98
|
+
{ json: deps.json }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function readUpdateSignal(dir, currentVersion) {
|
|
105
|
+
try {
|
|
106
|
+
const current = currentVersion ?? package_default.version;
|
|
107
|
+
const tag = channelTag(current);
|
|
108
|
+
if (tag === null) return null;
|
|
109
|
+
if ((await loadConfig(dir)).update.mode === "off") return null;
|
|
110
|
+
const cached = await readCache(updateCheckPath(dir));
|
|
111
|
+
const latest = cached?.tags[tag]?.latest;
|
|
112
|
+
if (latest === void 0 || !isNewer(latest, current)) return null;
|
|
113
|
+
return { current, latest };
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function channelTag(version) {
|
|
119
|
+
return parseVersion(version) === null ? null : "latest";
|
|
120
|
+
}
|
|
121
|
+
function resolveTarget(current, tags) {
|
|
122
|
+
const channel = channelTag(current);
|
|
123
|
+
if (channel === null) return null;
|
|
124
|
+
const candidate = tags[channel];
|
|
125
|
+
if (candidate === void 0 || parseVersion(candidate) === null) return null;
|
|
126
|
+
return candidate;
|
|
127
|
+
}
|
|
128
|
+
async function fetchDistTags(opts) {
|
|
129
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
130
|
+
let json;
|
|
131
|
+
try {
|
|
132
|
+
const res = await doFetch(DIST_TAGS_URL, { signal: AbortSignal.timeout(opts.timeoutMs) });
|
|
133
|
+
if (!res.ok) return null;
|
|
134
|
+
json = await res.json();
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const parsed = DistTagsSchema.safeParse(json);
|
|
139
|
+
return parsed.success ? parsed.data : null;
|
|
140
|
+
}
|
|
141
|
+
async function resolveLatest(current, deps) {
|
|
142
|
+
const tags = await fetchDistTags({ fetchImpl: deps.fetchImpl, timeoutMs: FETCH_TIMEOUT_MS });
|
|
143
|
+
return tags === null ? null : { latest: resolveTarget(current, tags) };
|
|
144
|
+
}
|
|
145
|
+
async function writeCache(path, cache) {
|
|
146
|
+
await writeFileAtomic(path, `${JSON.stringify(cache, null, 2)}
|
|
147
|
+
`, {
|
|
148
|
+
mode: 384,
|
|
149
|
+
dirMode: 448
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async function readCache(path) {
|
|
153
|
+
try {
|
|
154
|
+
const parsed = CacheSchema.safeParse(JSON.parse(await readFile(path, "utf8")));
|
|
155
|
+
return parsed.success ? parsed.data : null;
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
var VERSION_RE = /^(\d+)\.(\d+)\.(\d+)(?:-alpha\.(\d+))?$/;
|
|
161
|
+
function parseVersion(raw) {
|
|
162
|
+
const m = VERSION_RE.exec(raw);
|
|
163
|
+
if (m === null) return null;
|
|
164
|
+
const [, major, minor, patch, alpha] = m;
|
|
165
|
+
if (major === void 0 || minor === void 0 || patch === void 0) return null;
|
|
166
|
+
return {
|
|
167
|
+
major: Number(major),
|
|
168
|
+
minor: Number(minor),
|
|
169
|
+
patch: Number(patch),
|
|
170
|
+
alpha: alpha !== void 0 ? Number(alpha) : null
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function isNewer(candidate, current) {
|
|
174
|
+
const a = parseVersion(candidate);
|
|
175
|
+
const b = parseVersion(current);
|
|
176
|
+
if (a === null || b === null) return false;
|
|
177
|
+
if (a.major !== b.major) return a.major > b.major;
|
|
178
|
+
if (a.minor !== b.minor) return a.minor > b.minor;
|
|
179
|
+
if (a.patch !== b.patch) return a.patch > b.patch;
|
|
180
|
+
if (a.alpha === null) return b.alpha !== null;
|
|
181
|
+
if (b.alpha === null) return false;
|
|
182
|
+
return a.alpha > b.alpha;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export {
|
|
186
|
+
NUDGE_OPT_OUT,
|
|
187
|
+
maybeUpdate,
|
|
188
|
+
readUpdateSignal,
|
|
189
|
+
channelTag,
|
|
190
|
+
resolveTarget,
|
|
191
|
+
fetchDistTags,
|
|
192
|
+
isNewer
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=chunk-KXVP2VKA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/update-check.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { z } from 'zod';\nimport pkg from '../../package.json';\nimport { writeFileAtomic } from './atomic-json';\nimport { loadConfig } from './config';\nimport type { UpdateMode } from './config';\nimport { emitNotice } from './output';\nimport type { Io } from './output';\nimport type { UpdateAvailable } from '../schemas';\nimport { updateCheckPath } from './paths';\n\n/**\n * \"A newer tenjin-cli exists\", asked of npm at most once a day and reported\n * three ways: one dim stderr line for a human at a terminal, `updateAvailable`\n * on the JSON envelope, and a line on the generated hook scripts' output.\n *\n * It REPORTS and never installs. A CLI that starts a fresh process per\n * invocation has no deferred-activation window to hide a binary swap in — \"next\n * start\" is \"mid-session\" for whatever is driving it — so the decision to run\n * `tenjin update` belongs to the agent or the human, not to this check.\n *\n * Everything here is subordinate to the command that ran: the fetch happens\n * AFTER the envelope is written, it never touches stdout, it never changes an\n * exit code, and every failure it can have (offline, slow registry, junk JSON, a\n * tag that does not exist) is swallowed. CI skips the whole thing: a build log\n * can act on none of it. `update.mode off` is the opt-out and silences all three\n * surfaces, including the request to npm.\n */\n\n/**\n * Silences this check for one process, cache write and registry request\n * included. Set by `update` on the `install --refresh` children it spawns: their\n * data dirs come out of a settings file this CLI does not own, and this check is\n * the one thing in a refresh that would CREATE such a directory — `writeCache`\n * mkdirs the tree — where the refresh itself only converges what exists.\n *\n * A separate switch rather than `CI`, which would also stand the skills heal\n * down (lib/skill-heal) and so gut the refresh it was set for.\n */\nexport const NUDGE_OPT_OUT = 'TENJIN_NO_UPDATE_CHECK';\n\nconst CHECK_INTERVAL_MS = 86_400_000; // 24h\nconst FETCH_TIMEOUT_MS = 1500;\nconst DIST_TAGS_URL = 'https://registry.npmjs.org/-/package/tenjin-cli/dist-tags';\n\n/** What is known about ONE dist-tag: when it was asked, and what it said. */\nconst TagEntrySchema = z.object({\n checkedAtMs: z.number(),\n /** The version the tag named. Absent when the answer was unusable. */\n latest: z.string().optional(),\n /** When the nudge was last PRINTED for this tag. Absent until one has been. */\n notifiedAtMs: z.number().optional(),\n});\n\n/**\n * The cache is a pure optimization, so a bad one is re-fetched, never repaired.\n * Keyed by dist-tag: an entry this build did not ask about is carried forward\n * untouched rather than evicted.\n */\nconst CacheSchema = z.object({\n schemaVersion: z.literal(1),\n tags: z.record(z.string(), TagEntrySchema),\n /**\n * The resolved \"you could upgrade\" fact, written whenever it changes and\n * cleared when it stops being true.\n *\n * Denormalized from `tags` on purpose: the generated hook scripts are\n * standalone .mjs that cannot import this module and do not know which\n * version is running, so a per-tag entry would leave them unable to tell an\n * upgrade from a match. Storing the comparison's ANSWER is what lets a hook\n * report it without reimplementing any of it.\n */\n signal: z.object({ current: z.string(), latest: z.string() }).optional(),\n});\ntype Cache = z.infer<typeof CacheSchema>;\n\n/** `{\"latest\":\"1.2.3\",\"alpha\":\"1.3.0-alpha.1\"}` — tag names are not fixed. */\nconst DistTagsSchema = z.record(z.string(), z.string());\n\nexport interface UpdateCheckDeps {\n dir: string;\n io: Io;\n /** The global --json flag; ANDed with io.isTTY exactly as the emit path does. */\n json: boolean;\n env?: NodeJS.ProcessEnv;\n /** Clock seam (ms since epoch) for deterministic TTL tests. */\n now?: () => number;\n /** Override global fetch (tests inject a stub returning canned Responses). */\n fetchImpl?: typeof fetch;\n /** The running version; defaults to this build's. Injectable for tests. */\n currentVersion?: string;\n /** Resolved update.mode; defaults to reading the config file. */\n mode?: UpdateMode;\n}\n\n/**\n * Print the update nudge if one is due. NEVER rejects — the caller awaits it\n * between a command's output and its exit, so a throw here would replace a\n * finished command's result with an internal error.\n */\nexport async function maybeUpdate(deps: UpdateCheckDeps): Promise<void> {\n try {\n const env = deps.env ?? process.env;\n // Never in CI, in either mode: a build log cannot act on a nudge, and a\n // build machine must not silently acquire a different binary mid-pipeline.\n if (env.CI !== undefined && env.CI.length > 0) return;\n if (env[NUDGE_OPT_OUT] === '1') return;\n\n const mode = deps.mode ?? (await loadConfig(deps.dir)).update.mode;\n if (mode === 'off') return;\n\n const nowMs = (deps.now ?? Date.now)();\n const current = deps.currentVersion ?? pkg.version;\n const path = updateCheckPath(deps.dir);\n const tag = channelTag(current);\n if (tag === null) return; // a version this build cannot parse follows no channel\n\n // Only this tag's entry answers this binary's question; the other channel's\n // is neither used nor disturbed.\n const cached = await readCache(path);\n const entry = cached?.tags[tag];\n const fresh = entry !== undefined && nowMs - entry.checkedAtMs < CHECK_INTERVAL_MS;\n\n // Resolved through the same function `tenjin update` uses, so the nudge can\n // never advertise a version the command would decline to install, nor stay\n // quiet about one it would.\n //\n // Only a registry that could not be ASKED returns without caching; an answer\n // this build cannot use has still been answered, and moves the clock below.\n let latest: string | null;\n if (fresh) {\n latest = entry.latest ?? null;\n } else {\n const answer = await resolveLatest(current, deps);\n if (answer === null) return;\n latest = answer.latest;\n }\n\n const upgradeable = latest !== null && isNewer(latest, current);\n\n // Once a day means once a day, not once per FETCH: a fresh cache would\n // otherwise repeat the same line on every command for 24h. The two clocks are\n // separate because they answer separate questions — when we last asked npm,\n // and when we last interrupted the human.\n //\n // `human` is part of `due` for the second of those: this code now runs on\n // every surface, to feed the envelope signal, so without it an agent run\n // would stamp the nudge clock having printed nothing and leave a shared\n // machine's terminal quiet for 24h.\n const human = deps.io.isTTY && !deps.json;\n const notifiedAtMs = entry?.notifiedAtMs;\n const due =\n human &&\n upgradeable &&\n (notifiedAtMs === undefined || nowMs - notifiedAtMs >= CHECK_INTERVAL_MS);\n\n // Carried forward when nothing is printed: the day since the last nudge does\n // not restart just because the registry was asked again.\n const nudgedAtMs = due ? nowMs : notifiedAtMs;\n\n // Carries the agent-visible half of the answer, so a hook or an envelope can\n // report it without knowing which version is running.\n const signal = upgradeable && latest !== null ? { current, latest } : undefined;\n const signalChanged =\n cached?.signal?.current !== signal?.current || cached?.signal?.latest !== signal?.latest;\n\n // Nothing learned and nothing said means nothing to write. Deliberately NOT\n // locked: two concurrent CLI processes can both nudge, and one duplicated\n // line is cheaper than a lock on the exit path of every command.\n if (!fresh || due || signalChanged) {\n await writeCache(path, {\n schemaVersion: 1,\n ...(signal !== undefined ? { signal } : {}),\n // Read-modify-write: the tag this run did not ask about keeps whatever it\n // knew, including its own nudge clock.\n tags: {\n ...cached?.tags,\n [tag]: {\n checkedAtMs: fresh ? entry.checkedAtMs : nowMs,\n ...(latest !== null ? { latest } : {}),\n ...(nudgedAtMs !== undefined ? { notifiedAtMs: nudgedAtMs } : {}),\n },\n },\n });\n }\n\n // Named as the command, not the npm invocation it wraps: `update` prints the\n // right instructions itself for an install it cannot perform (a source\n // checkout, a yarn global), so this line is correct everywhere.\n if (due && latest !== null) {\n emitNotice(\n deps.io,\n `tenjin-cli ${latest} is available (you have ${current}). Update: run tenjin update`,\n { json: deps.json },\n );\n }\n } catch {\n // Unreachable by construction (every step below is already guarded); here so\n // that staying invisible does not depend on that remaining true.\n }\n}\n\n/**\n * What the last check learned, for the envelope. Cache only: this runs before\n * every command's output, so it may not fetch, may not block, and may not throw.\n * Null when nothing newer is known, when the cache is absent or stale-shaped, or\n * when `update.mode` is `off` — off silences BOTH surfaces, not just the line a\n * human sees.\n *\n * Reporting rather than installing is the whole design. A CLI that starts a\n * fresh process per invocation has no deferred-activation moment to hide a\n * binary swap in, so the agent is told and decides for itself.\n */\nexport async function readUpdateSignal(\n dir: string,\n currentVersion?: string,\n): Promise<UpdateAvailable | null> {\n try {\n const current = currentVersion ?? pkg.version;\n const tag = channelTag(current);\n if (tag === null) return null;\n if ((await loadConfig(dir)).update.mode === 'off') return null;\n const cached = await readCache(updateCheckPath(dir));\n const latest = cached?.tags[tag]?.latest;\n if (latest === undefined || !isNewer(latest, current)) return null;\n return { current, latest };\n } catch {\n return null; // never the command's business\n }\n}\n\n/**\n * Which dist-tag this build follows, or null for a version string this package\n * has no channel for. Null rather than a default, because every caller's right\n * answer differs: the nudge goes quiet, and `tenjin update` refuses instead of\n * silently reporting a foreign build \"up to date\" against a tag it never\n * belonged to.\n *\n * Every build follows `latest`; see RELEASING.md, which changes with this.\n */\nexport function channelTag(version: string): 'latest' | null {\n return parseVersion(version) === null ? null : 'latest';\n}\n\n/**\n * The version this build can move to: whatever sits on the tag it follows.\n * Consulting a second tag added no reachable version and one way to be wrong: a\n * tag sitting ahead of `latest` could redirect the self-update to a build the\n * release line never promoted. Null both when that tag is absent and when it\n * names a version VERSION_RE rejects; `runUpdate` separates those, and neither\n * means the registry was unreachable.\n */\nexport function resolveTarget(current: string, tags: Record<string, string>): string | null {\n const channel = channelTag(current);\n if (channel === null) return null;\n const candidate = tags[channel];\n // Unparseable counts as absent: isNewer loses every comparison against junk,\n // so admitting one would read as \"up to date\" forever.\n if (candidate === undefined || parseVersion(candidate) === null) return null;\n return candidate;\n}\n\n/**\n * Ask the registry for tenjin-cli's whole dist-tag map. Returns null for every\n * failure there is, INCLUDING a response that arrives too late — the AbortSignal\n * is what bounds the delay a finished command can suffer. Nothing is written\n * here: a failed check caches nothing, so the next command retries rather than\n * going quiet for 24h over one dropped packet. The nudge passes its own short\n * budget; `tenjin update` passes the run's request timeout, because there the\n * fetch IS the command rather than a stowaway on someone else's exit path.\n *\n * The whole map rather than one tag, so a caller can tell an unreachable\n * registry (null) from one that answered without the tag it asked for (a map\n * that lacks the key) — two failures with two different fixes.\n */\nexport async function fetchDistTags(opts: {\n fetchImpl?: typeof fetch;\n timeoutMs: number;\n}): Promise<Record<string, string> | null> {\n const doFetch = opts.fetchImpl ?? fetch;\n let json: unknown;\n try {\n const res = await doFetch(DIST_TAGS_URL, { signal: AbortSignal.timeout(opts.timeoutMs) });\n if (!res.ok) return null;\n json = await res.json();\n } catch {\n return null;\n }\n const parsed = DistTagsSchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n}\n\n/**\n * The nudge's one-shot: fetch, then resolve. Null when the registry could not be\n * asked; `{ latest: null }` when it answered with nothing usable.\n */\nasync function resolveLatest(\n current: string,\n deps: UpdateCheckDeps,\n): Promise<{ latest: string | null } | null> {\n const tags = await fetchDistTags({ fetchImpl: deps.fetchImpl, timeoutMs: FETCH_TIMEOUT_MS });\n return tags === null ? null : { latest: resolveTarget(current, tags) };\n}\n\nasync function writeCache(path: string, cache: Cache): Promise<void> {\n await writeFileAtomic(path, `${JSON.stringify(cache, null, 2)}\\n`, {\n mode: 0o600,\n dirMode: 0o700,\n });\n}\n\nasync function readCache(path: string): Promise<Cache | null> {\n try {\n const parsed = CacheSchema.safeParse(JSON.parse(await readFile(path, 'utf8')));\n return parsed.success ? parsed.data : null;\n } catch {\n return null;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Version comparison: this package's shape only, no semver dependency.\n// ---------------------------------------------------------------------------\n\n/** `major.minor.patch` with an optional `-alpha.N` — every version tenjin-cli\n * has ever published. Anything else is unparseable ON PURPOSE (see isNewer). */\nconst VERSION_RE = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-alpha\\.(\\d+))?$/;\n\ninterface Version {\n major: number;\n minor: number;\n patch: number;\n /** null = a release; a number = that prerelease counter. */\n alpha: number | null;\n}\n\nfunction parseVersion(raw: string): Version | null {\n const m = VERSION_RE.exec(raw);\n if (m === null) return null;\n const [, major, minor, patch, alpha] = m;\n if (major === undefined || minor === undefined || patch === undefined) return null;\n return {\n major: Number(major),\n minor: Number(minor),\n patch: Number(patch),\n alpha: alpha !== undefined ? Number(alpha) : null,\n };\n}\n\n/**\n * Is `candidate` newer than `current`? An unparseable version on EITHER side is\n * \"not newer\": the registry is untrusted input, and the failure mode of guessing\n * is nagging every single command with a line the user cannot act on. A true\n * return therefore also certifies that BOTH sides parse, which is what lets\n * `tenjin update` splice the candidate into an npm argv without re-validating.\n */\nexport function isNewer(candidate: string, current: string): boolean {\n const a = parseVersion(candidate);\n const b = parseVersion(current);\n if (a === null || b === null) return false;\n if (a.major !== b.major) return a.major > b.major;\n if (a.minor !== b.minor) return a.minor > b.minor;\n if (a.patch !== b.patch) return a.patch > b.patch;\n // Same release triple: semver says a prerelease precedes its own release, so\n // 0.1.0 beats 0.1.0-alpha.9 and never the other way around.\n if (a.alpha === null) return b.alpha !== null;\n if (b.alpha === null) return false;\n return a.alpha > b.alpha;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAuClB,IAAM,gBAAgB;AAE7B,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AACzB,IAAM,gBAAgB;AAGtB,IAAM,iBAAiB,iBAAE,OAAO;AAAA,EAC9B,aAAa,iBAAE,OAAO;AAAA;AAAA,EAEtB,QAAQ,iBAAE,OAAO,EAAE,SAAS;AAAA;AAAA,EAE5B,cAAc,iBAAE,OAAO,EAAE,SAAS;AACpC,CAAC;AAOD,IAAM,cAAc,iBAAE,OAAO;AAAA,EAC3B,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,MAAM,iBAAE,OAAO,iBAAE,OAAO,GAAG,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWzC,QAAQ,iBAAE,OAAO,EAAE,SAAS,iBAAE,OAAO,GAAG,QAAQ,iBAAE,OAAO,EAAE,CAAC,EAAE,SAAS;AACzE,CAAC;AAID,IAAM,iBAAiB,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,OAAO,CAAC;AAuBtD,eAAsB,YAAY,MAAsC;AACtE,MAAI;AACF,UAAM,MAAM,KAAK,OAAO,QAAQ;AAGhC,QAAI,IAAI,OAAO,UAAa,IAAI,GAAG,SAAS,EAAG;AAC/C,QAAI,IAAI,aAAa,MAAM,IAAK;AAEhC,UAAM,OAAO,KAAK,SAAS,MAAM,WAAW,KAAK,GAAG,GAAG,OAAO;AAC9D,QAAI,SAAS,MAAO;AAEpB,UAAM,SAAS,KAAK,OAAO,KAAK,KAAK;AACrC,UAAM,UAAU,KAAK,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,MAAI,EAAE,UAAU,KAAM,QAAO,EAAE,UAAU;AACzC,MAAI,EAAE,UAAU,KAAM,QAAO;AAC7B,SAAO,EAAE,QAAQ,EAAE;AACrB;","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
CODEX_ALLOW_HOOK_COMMAND,
|
|
4
|
+
CODEX_ALLOW_HOOK_COMMAND_WINDOWS,
|
|
5
|
+
CODEX_HOOK_COUNT
|
|
6
|
+
} from "./chunk-GA7JETVM.js";
|
|
7
|
+
import {
|
|
8
|
+
resolveCodex,
|
|
9
|
+
withAppServer
|
|
10
|
+
} from "./chunk-QSCPK4F5.js";
|
|
11
|
+
import {
|
|
12
|
+
MARKETPLACE_NAME,
|
|
13
|
+
PLUGIN_ID
|
|
14
|
+
} from "./chunk-WJXLQXJY.js";
|
|
15
|
+
|
|
16
|
+
// src/router/codex-host.ts
|
|
17
|
+
import { execFile } from "node:child_process";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
import { promisify } from "node:util";
|
|
20
|
+
var CODEX_MARKETPLACE = MARKETPLACE_NAME;
|
|
21
|
+
var CODEX_PLUGIN = PLUGIN_ID;
|
|
22
|
+
var WEB_VERIFIED_VERSION = "0.154.0";
|
|
23
|
+
var exec = promisify(execFile);
|
|
24
|
+
function record(v) {
|
|
25
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
26
|
+
}
|
|
27
|
+
function at(v, ...keys) {
|
|
28
|
+
for (const key of keys) {
|
|
29
|
+
if (!record(v)) return void 0;
|
|
30
|
+
v = v[key];
|
|
31
|
+
}
|
|
32
|
+
return v;
|
|
33
|
+
}
|
|
34
|
+
async function codexVersion() {
|
|
35
|
+
const codex = resolveCodex();
|
|
36
|
+
if (codex === null) return null;
|
|
37
|
+
try {
|
|
38
|
+
const { stdout } = await exec(codex.cmd, [...codex.prefix, "--version"], {
|
|
39
|
+
timeout: 2e3,
|
|
40
|
+
maxBuffer: 16384,
|
|
41
|
+
windowsHide: true
|
|
42
|
+
});
|
|
43
|
+
return /(?:codex-cli|codex)\s+(\d+\.\d+\.\d+(?:[-+][\w.-]+)?)/.exec(stdout)?.[1] ?? null;
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function readCodexConfig(cwd, timeoutMs = 500) {
|
|
49
|
+
return withAppServer(
|
|
50
|
+
homedir(),
|
|
51
|
+
process.env,
|
|
52
|
+
timeoutMs,
|
|
53
|
+
async (request) => at(await request("config/read", { includeLayers: false, cwd }), "config")
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function listCodexHooks(cwd, timeoutMs) {
|
|
57
|
+
return withAppServer(
|
|
58
|
+
homedir(),
|
|
59
|
+
process.env,
|
|
60
|
+
timeoutMs,
|
|
61
|
+
(request) => request("hooks/list", { cwds: [cwd] })
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function isAllowHook(hook) {
|
|
65
|
+
return (
|
|
66
|
+
// On Windows, Codex lists the `commandWindows` form as the command.
|
|
67
|
+
[CODEX_ALLOW_HOOK_COMMAND, CODEX_ALLOW_HOOK_COMMAND_WINDOWS].includes(
|
|
68
|
+
String(at(hook, "command"))
|
|
69
|
+
) || String(at(hook, "key")).includes(":permission_request:")
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
function codexHookRows(list) {
|
|
73
|
+
const groups = at(list, "data");
|
|
74
|
+
if (!Array.isArray(groups)) return { state: "unknown", allowOff: false };
|
|
75
|
+
const ours = groups.flatMap((group) => {
|
|
76
|
+
const hooks = at(group, "hooks");
|
|
77
|
+
return Array.isArray(hooks) ? hooks : [];
|
|
78
|
+
}).filter((hook) => at(hook, "pluginId") === CODEX_PLUGIN);
|
|
79
|
+
if (ours.length === 0) return { state: "absent", allowOff: false };
|
|
80
|
+
const optedOut = (hook) => isAllowHook(hook) && at(hook, "enabled") === false;
|
|
81
|
+
const ready = ours.every(
|
|
82
|
+
(hook) => optedOut(hook) || at(hook, "enabled") === true && ["trusted", "managed"].includes(String(at(hook, "trustStatus")))
|
|
83
|
+
);
|
|
84
|
+
return {
|
|
85
|
+
state: ours.length === CODEX_HOOK_COUNT && ready ? "trusted" : "review",
|
|
86
|
+
allowOff: ours.some(optedOut)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
CODEX_MARKETPLACE,
|
|
92
|
+
CODEX_PLUGIN,
|
|
93
|
+
WEB_VERIFIED_VERSION,
|
|
94
|
+
at,
|
|
95
|
+
codexVersion,
|
|
96
|
+
readCodexConfig,
|
|
97
|
+
listCodexHooks,
|
|
98
|
+
codexHookRows
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=chunk-LEFIX6RS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/codex-host.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { homedir } from 'node:os';\nimport { promisify } from 'node:util';\nimport { withAppServer } from '../lib/codex-app-server';\nimport { resolveCodex } from '../lib/codex-bin';\nimport { MARKETPLACE_NAME, PLUGIN_ID } from './names';\nimport {\n CODEX_ALLOW_HOOK_COMMAND,\n CODEX_ALLOW_HOOK_COMMAND_WINDOWS,\n CODEX_HOOK_COUNT,\n} from './plugin-files';\n\n/**\n * WHAT CODEX SAYS ABOUT THE TENJIN PLUGIN, read through Codex's own app server\n * and CLI and never from its files.\n */\nexport const CODEX_MARKETPLACE = MARKETPLACE_NAME;\nexport const CODEX_PLUGIN = PLUGIN_ID;\n/** The last Codex build a `webrun` hook capture came from: a diagnostic, never a switch. */\nexport const WEB_VERIFIED_VERSION = '0.154.0';\n\nconst exec = promisify(execFile);\n\nfunction record(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\n\nexport function at(v: unknown, ...keys: string[]): unknown {\n for (const key of keys) {\n if (!record(v)) return undefined;\n v = v[key];\n }\n return v;\n}\n\nexport async function codexVersion(): Promise<string | null> {\n const codex = resolveCodex();\n if (codex === null) return null;\n try {\n const { stdout } = await exec(codex.cmd, [...codex.prefix, '--version'], {\n timeout: 2_000,\n maxBuffer: 16_384,\n windowsHide: true,\n });\n return /(?:codex-cli|codex)\\s+(\\d+\\.\\d+\\.\\d+(?:[-+][\\w.-]+)?)/.exec(stdout)?.[1] ?? null;\n } catch {\n return null;\n }\n}\n\n/** Codex's merged config for `cwd`, or null when its app server could not be asked. */\nexport async function readCodexConfig(cwd: string, timeoutMs = 500): Promise<unknown> {\n return withAppServer(homedir(), process.env, timeoutMs, async (request) =>\n at(await request('config/read', { includeLayers: false, cwd }), 'config'),\n );\n}\n\n/** Codex's hook list for `cwd` (`hooks/list`), or null when it could not be asked. */\nexport function listCodexHooks(cwd: string, timeoutMs: number): Promise<unknown> {\n return withAppServer(homedir(), process.env, timeoutMs, (request) =>\n request('hooks/list', { cwds: [cwd] }),\n );\n}\n\n/**\n * The plugin, as Codex's one `hooks/list` shows it. Every row carries its\n * `pluginId`, `enabled` and `trustStatus`: no Tenjin row means the plugin is\n * not installed (or is off), and every row present, enabled and trusted means\n * it is installed, on and trusted.\n */\nexport interface CodexHookRows {\n state: 'trusted' | 'review' | 'absent' | 'unknown';\n /** The request tool's allow hook is off in `/hooks`, so the tool asks first. */\n allowOff: boolean;\n}\n\nfunction isAllowHook(hook: unknown): boolean {\n return (\n // On Windows, Codex lists the `commandWindows` form as the command.\n [CODEX_ALLOW_HOOK_COMMAND, CODEX_ALLOW_HOOK_COMMAND_WINDOWS].includes(\n String(at(hook, 'command')),\n ) || String(at(hook, 'key')).includes(':permission_request:')\n );\n}\n\nexport function codexHookRows(list: unknown): CodexHookRows {\n const groups = at(list, 'data');\n if (!Array.isArray(groups)) return { state: 'unknown', allowOff: false };\n const ours = groups\n .flatMap((group) => {\n const hooks = at(group, 'hooks');\n return Array.isArray(hooks) ? (hooks as unknown[]) : [];\n })\n .filter((hook) => at(hook, 'pluginId') === CODEX_PLUGIN);\n if (ours.length === 0) return { state: 'absent', allowOff: false };\n // Turning the allow hook off is the documented opt-out, not a broken install.\n const optedOut = (hook: unknown) => isAllowHook(hook) && at(hook, 'enabled') === false;\n const ready = ours.every(\n (hook) =>\n optedOut(hook) ||\n (at(hook, 'enabled') === true &&\n ['trusted', 'managed'].includes(String(at(hook, 'trustStatus')))),\n );\n return {\n state: ours.length === CODEX_HOOK_COUNT && ready ? 'trusted' : 'review',\n allowOff: ours.some(optedOut),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAcnB,IAAM,oBAAoB;AAC1B,IAAM,eAAe;AAErB,IAAM,uBAAuB;AAEpC,IAAM,OAAO,UAAU,QAAQ;AAE/B,SAAS,OAAO,GAA0C;AACxD,SAAO,MAAM,QAAQ,OAAO,MAAM,YAAY,CAAC,MAAM,QAAQ,CAAC;AAChE;AAEO,SAAS,GAAG,MAAe,MAAyB;AACzD,aAAW,OAAO,MAAM;AACtB,QAAI,CAAC,OAAO,CAAC,EAAG,QAAO;AACvB,QAAI,EAAE,GAAG;AAAA,EACX;AACA,SAAO;AACT;AAEA,eAAsB,eAAuC;AAC3D,QAAM,QAAQ,aAAa;AAC3B,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI;AACF,UAAM,EAAE,OAAO,IAAI,MAAM,KAAK,MAAM,KAAK,CAAC,GAAG,MAAM,QAAQ,WAAW,GAAG;AAAA,MACvE,SAAS;AAAA,MACT,WAAW;AAAA,MACX,aAAa;AAAA,IACf,CAAC;AACD,WAAO,wDAAwD,KAAK,MAAM,IAAI,CAAC,KAAK;AAAA,EACtF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,eAAsB,gBAAgB,KAAa,YAAY,KAAuB;AACpF,SAAO;AAAA,IAAc,QAAQ;AAAA,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AoB,QAAQ,YAAY;AAAA,IAC/D,UAAU,KAAK,KAAK,QAAQ;AAAA,EAC9B;AACF;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/prompt.ts
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
function promptYesNo(prompt, opts = {}) {
|
|
6
|
+
const { defaultYes = false, input = process.stdin, output = process.stderr } = opts;
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const rl = createInterface({ input, output });
|
|
9
|
+
let settled = false;
|
|
10
|
+
const settle = (value) => {
|
|
11
|
+
if (settled) return;
|
|
12
|
+
settled = true;
|
|
13
|
+
rl.close();
|
|
14
|
+
resolve(value);
|
|
15
|
+
};
|
|
16
|
+
rl.once("close", () => settle(false));
|
|
17
|
+
rl.question(prompt, (answer) => {
|
|
18
|
+
const a = answer.trim().toLowerCase();
|
|
19
|
+
settle(a === "" ? defaultYes : a === "y" || a === "yes");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
promptYesNo
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-LHHMV4GU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/prompt.ts"],"sourcesContent":["import { createInterface } from 'node:readline';\n\nexport interface PromptYesNoOptions {\n /** What an EMPTY answer means; the closing of stdin (ctrl-D) is always false. */\n defaultYes?: boolean;\n /** Injectable streams for tests; label/echo go to stderr, never stdout. */\n input?: NodeJS.ReadableStream;\n output?: NodeJS.WritableStream;\n}\n\n/**\n * The one y/n reader every confirm gate shares (buy, send, install). \"y\"/\"yes\"\n * (any case) is true, an empty answer follows `defaultYes` (explicit at each\n * call site), anything else is false, and stdin closing mid-prompt resolves\n * false rather than hanging. The prompt writes to stderr so stdout stays a\n * single JSON envelope.\n */\nexport function promptYesNo(prompt: string, opts: PromptYesNoOptions = {}): Promise<boolean> {\n const { defaultYes = false, input = process.stdin, output = process.stderr } = opts;\n return new Promise((resolve) => {\n const rl = createInterface({ input, output });\n let settled = false;\n const settle = (value: boolean): void => {\n if (settled) return;\n settled = true;\n rl.close();\n resolve(value);\n };\n rl.once('close', () => settle(false));\n rl.question(prompt, (answer) => {\n const a = answer.trim().toLowerCase();\n settle(a === '' ? defaultYes : a === 'y' || a === 'yes');\n });\n });\n}\n"],"mappings":";;;AAAA,SAAS,uBAAuB;AAiBzB,SAAS,YAAY,QAAgB,OAA2B,CAAC,GAAqB;AAC3F,QAAM,EAAE,aAAa,OAAO,QAAQ,QAAQ,OAAO,SAAS,QAAQ,OAAO,IAAI;AAC/E,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,KAAK,gBAAgB,EAAE,OAAO,OAAO,CAAC;AAC5C,QAAI,UAAU;AACd,UAAM,SAAS,CAAC,UAAyB;AACvC,UAAI,QAAS;AACb,gBAAU;AACV,SAAG,MAAM;AACT,cAAQ,KAAK;AAAA,IACf;AACA,OAAG,KAAK,SAAS,MAAM,OAAO,KAAK,CAAC;AACpC,OAAG,SAAS,QAAQ,CAAC,WAAW;AAC9B,YAAM,IAAI,OAAO,KAAK,EAAE,YAAY;AACpC,aAAO,MAAM,KAAK,aAAa,MAAM,OAAO,MAAM,KAAK;AAAA,IACzD,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// src/lib/lock.ts
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { mkdirSync, rmSync } from "node:fs";
|
|
5
|
+
import { writeFile } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
var owned = /* @__PURE__ */ new Set();
|
|
6
8
|
var DEFAULTS = { timeoutMs: 5e3, retryMs: 25 };
|
|
7
9
|
var LockTimeoutError = class extends Error {
|
|
8
10
|
lockPath;
|
|
@@ -20,7 +22,8 @@ async function withFileLock(lockPath, fn, opts = {}) {
|
|
|
20
22
|
const deadline = Date.now() + timeoutMs;
|
|
21
23
|
for (; ; ) {
|
|
22
24
|
try {
|
|
23
|
-
|
|
25
|
+
mkdirSync(lockPath);
|
|
26
|
+
owned.add(lockPath);
|
|
24
27
|
break;
|
|
25
28
|
} catch (err) {
|
|
26
29
|
if (!isEexist(err)) throw err;
|
|
@@ -34,7 +37,12 @@ async function withFileLock(lockPath, fn, opts = {}) {
|
|
|
34
37
|
try {
|
|
35
38
|
return await fn();
|
|
36
39
|
} finally {
|
|
37
|
-
|
|
40
|
+
try {
|
|
41
|
+
rmSync(lockPath, { recursive: true, force: true });
|
|
42
|
+
owned.delete(lockPath);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
opts.onReleaseError?.(lockPath, err);
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
}
|
|
40
48
|
function isEexist(err) {
|
|
@@ -48,4 +56,4 @@ export {
|
|
|
48
56
|
LockTimeoutError,
|
|
49
57
|
withFileLock
|
|
50
58
|
};
|
|
51
|
-
//# sourceMappingURL=chunk-
|
|
59
|
+
//# sourceMappingURL=chunk-MEFB5KHA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/lock.ts"],"sourcesContent":["import { mkdirSync, rmSync } from 'node:fs';\nimport { writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\n/**\n * Locks this process currently holds. Ownership starts the instant `mkdir`\n * succeeds and ends when the release has removed the directory, so there is no\n * window where a lock is on disk and unaccounted for. A removal that FAILS keeps\n * the lock owned: the directory is still on disk, no successor can claim the path\n * while it exists, and a signal-time release gets another attempt. The one place\n * ownership is dropped without a successful removal is `releaseOwnedLocks`, which\n * runs only as the process exits, where a claim held by a dying process helps\n * nobody.\n *\n * It exists because the default signal action terminates WITHOUT running\n * `finally`: without this, one Ctrl-C leaves a lock nothing will ever clean and\n * every later run of the same command times out on it.\n */\nconst owned = new Set<string>();\n\n/** Does this process hold any lock right now? */\nexport function ownsAnyLock(): boolean {\n return owned.size > 0;\n}\n\n/**\n * Synchronously attempt to release every lock this process holds. BEST EFFORT: a\n * path that refuses to be removed is left on disk and the next run's timeout names\n * it. Safe to call from a signal handler, and a no-op when this process holds\n * none, so a run merely QUEUED behind another cannot remove that other run's lock.\n */\nexport function releaseOwnedLocks(): void {\n for (const path of owned) {\n // NEVER throws. This runs inside a signal handler, and a throw there is an\n // uncaught exception: the process dies with code 1 and a stack trace instead\n // of the diagnostic and exit 130 the handler promises. One lock we could not\n // remove must not cost the report, or the exit code, or the other locks.\n try {\n rmSync(path, { recursive: true, force: true });\n } catch {\n // Left behind; the next run's timeout names the path.\n }\n }\n owned.clear();\n}\n\nexport interface FileLockOptions {\n /** Give up acquiring after this long (ms). */\n timeoutMs?: number;\n /** Poll interval between acquisition attempts (ms). */\n retryMs?: number;\n /**\n * Called when the lock could not be removed on release. The protected work\n * succeeded, so this is not a failure of the command; it is a leftover that will\n * block later runs, and the caller is the only one able to say so.\n */\n onReleaseError?: (lockPath: string, err: unknown) => void;\n}\n\nconst DEFAULTS = { timeoutMs: 5000, retryMs: 25 };\n\n/** Thrown when the lock cannot be acquired within `timeoutMs`. Carries the lock\n * path so a caller can surface the manual-recovery step in its own error contract. */\nexport class LockTimeoutError extends Error {\n readonly lockPath: string;\n constructor(lockPath: string, timeoutMs: number) {\n super(\n `Timed out waiting for lock at ${lockPath} after ${timeoutMs}ms; if no other tenjin process is running, remove that directory and retry.`,\n );\n this.name = 'LockTimeoutError';\n this.lockPath = lockPath;\n }\n}\n\n/**\n * Minimal cross-process mutex: the lock IS a directory, and mkdir is atomic, so a\n * second holder gets EEXIST and retries with backoff until `timeoutMs`, then\n * throws LockTimeoutError. There is deliberately NO auto-steal of a \"stale\" lock:\n * concurrent waiters each judging a lock stale could remove a fresh holder's\n * directory and lose its update. A crashed holder's lock is recovered by hand (the\n * timeout error names the path); the pid+acquiredAt meta exists only to make that\n * manual call diagnosable. Always released in the finally.\n *\n * NO LONGER MIRRORED IN THE HOOKS. The generated scripts used to reimplement\n * this protocol byte for byte — they run as standalone .mjs files outside the\n * CLI and cannot import this module, yet wrote the same searches.json, and two\n * writers of one file that disagree about the mutex have no mutex. That file is\n * gone (tenjin-agent#209): hook state is one SQLite database and WAL serializes\n * the writers, so nothing outside this module implements this protocol any more.\n */\nexport async function withFileLock<T>(\n lockPath: string,\n fn: () => Promise<T>,\n opts: FileLockOptions = {},\n): Promise<T> {\n const { timeoutMs, retryMs } = { ...DEFAULTS, ...opts };\n const metaPath = join(lockPath, 'meta');\n const deadline = Date.now() + timeoutMs;\n for (;;) {\n try {\n // SYNCHRONOUS, for the same reason the release is: `await mkdir` finishes the\n // syscall before the continuation records ownership, so between the two the\n // directory is on disk and unclaimed. A signal there exits without removing\n // it and, with no stale recovery, nothing ever will. mkdirSync and the add\n // are one uninterruptible step.\n mkdirSync(lockPath);\n owned.add(lockPath); // owned from here, released only in the finally below\n break; // acquired\n } catch (err) {\n if (!isEexist(err)) throw err;\n if (Date.now() >= deadline) throw new LockTimeoutError(lockPath, timeoutMs);\n await delay(retryMs);\n }\n }\n await writeFile(metaPath, JSON.stringify({ pid: process.pid, acquiredAt: Date.now() })).catch(\n () => undefined,\n );\n try {\n return await fn();\n } finally {\n // SYNCHRONOUS, and in this order, because both are load-bearing. A signal\n // handler cannot run between two synchronous statements, so there is no instant\n // where the lock is on disk but unclaimed (a signal would exit without removing\n // it, and with no stale recovery nothing ever would) nor one where it is\n // claimed after release (a signal would remove whatever SUCCESSOR had since\n // acquired the path). An `await` here reopens the first window: `rm` yields, the\n // handler runs, sees no ownership, and leaves the directory behind.\n //\n // With no stealing, nothing else ever removes or replaces this directory, so\n // the lock here is provably the one we created — the unconditional rm is sound.\n try {\n rmSync(lockPath, { recursive: true, force: true });\n owned.delete(lockPath);\n } catch (err) {\n // KEEP ownership when the removal fails: the successor-steal risk only\n // exists once the directory is gone and someone else can take the path, so a\n // removal that failed leaves it on disk and still ours, and a signal-time\n // release gets another attempt. That only helps while THIS process lives,\n // though; once it exits normally the leftover blocks every later run, so the\n // caller is told rather than left to discover it as a timeout.\n opts.onReleaseError?.(lockPath, err);\n }\n }\n}\n\nfunction isEexist(err: unknown): boolean {\n return typeof err === 'object' && err !== null && (err as { code?: unknown }).code === 'EEXIST';\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;;AAAA,SAAS,WAAW,cAAc;AAClC,SAAS,iBAAiB;AAC1B,SAAS,YAAY;AAgBrB,IAAM,QAAQ,oBAAI,IAAY;AAyC9B,IAAM,WAAW,EAAE,WAAW,KAAM,SAAS,GAAG;AAIzC,IAAM,mBAAN,cAA+B,MAAM;AAAA,EACjC;AAAA,EACT,YAAY,UAAkB,WAAmB;AAC/C;AAAA,MACE,iCAAiC,QAAQ,UAAU,SAAS;AAAA,IAC9D;AACA,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;AAkBA,eAAsB,aACpB,UACA,IACA,OAAwB,CAAC,GACb;AACZ,QAAM,EAAE,WAAW,QAAQ,IAAI,EAAE,GAAG,UAAU,GAAG,KAAK;AACtD,QAAM,WAAW,KAAK,UAAU,MAAM;AACtC,QAAM,WAAW,KAAK,IAAI,IAAI;AAC9B,aAAS;AACP,QAAI;AAMF,gBAAU,QAAQ;AAClB,YAAM,IAAI,QAAQ;AAClB;AAAA,IACF,SAAS,KAAK;AACZ,UAAI,CAAC,SAAS,GAAG,EAAG,OAAM;AAC1B,UAAI,KAAK,IAAI,KAAK,SAAU,OAAM,IAAI,iBAAiB,UAAU,SAAS;AAC1E,YAAM,MAAM,OAAO;AAAA,IACrB;AAAA,EACF;AACA,QAAM,UAAU,UAAU,KAAK,UAAU,EAAE,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