tenjin-cli 0.1.0-alpha.15 → 0.1.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +54 -7
- package/README.md +41 -310
- package/dist/{_esm-N4KAVXQR.js → _esm-CE7KNONL.js} +9 -10
- package/dist/{ccip-ZGGWQN4X.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-RPPPKTJR.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-25TJPVBF.js +353 -0
- package/dist/chunk-25TJPVBF.js.map +1 -0
- package/dist/chunk-2BKS2FVE.js +93 -0
- package/dist/chunk-2BKS2FVE.js.map +1 -0
- package/dist/chunk-2QYORQBF.js +55 -0
- package/dist/chunk-2QYORQBF.js.map +1 -0
- package/dist/{chunk-NIKXHWOL.js → chunk-2U5ZVEV3.js} +16 -16
- package/dist/chunk-2U5ZVEV3.js.map +1 -0
- package/dist/{chunk-HPJGOLTN.js → chunk-3AJS6LLN.js} +13 -8
- package/dist/chunk-3AJS6LLN.js.map +1 -0
- package/dist/{chunk-KINZ23CV.js → chunk-3AUDA53C.js} +4740 -23
- package/dist/chunk-3AUDA53C.js.map +1 -0
- package/dist/{chunk-MJZZTKCC.js → chunk-56MOAIP5.js} +5 -10
- package/dist/chunk-56MOAIP5.js.map +1 -0
- package/dist/{chunk-U5S527PP.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5X4SZ5BF.js +227 -0
- package/dist/chunk-5X4SZ5BF.js.map +1 -0
- package/dist/chunk-7WEQQJLG.js +68 -0
- package/dist/chunk-7WEQQJLG.js.map +1 -0
- package/dist/{chunk-7FK2UN2T.js → chunk-AWQPGIR6.js} +65 -67
- package/dist/{chunk-7FK2UN2T.js.map → chunk-AWQPGIR6.js.map} +1 -1
- package/dist/{chunk-ZFJJ3EXC.js → chunk-BBVUVBUO.js} +516 -185
- package/dist/chunk-BBVUVBUO.js.map +1 -0
- package/dist/{chunk-JBIKAAT3.js → chunk-BFFM2WFK.js} +8 -8
- package/dist/chunk-BFFM2WFK.js.map +1 -0
- package/dist/{chunk-KYQVEKP5.js → chunk-BPMWXTFX.js} +8 -8
- package/dist/chunk-DMZZLPZN.js +205 -0
- package/dist/chunk-DMZZLPZN.js.map +1 -0
- package/dist/{chunk-47PP7TAG.js → chunk-EGELTSPU.js} +1356 -1356
- package/dist/chunk-EGELTSPU.js.map +1 -0
- package/dist/chunk-GULLJQXA.js +698 -0
- package/dist/chunk-GULLJQXA.js.map +1 -0
- package/dist/{chunk-S5RYMCV6.js → chunk-HPWO4O6S.js} +3 -3
- package/dist/chunk-HVRC33OL.js +174 -0
- package/dist/chunk-HVRC33OL.js.map +1 -0
- package/dist/{chunk-W6R3HAAG.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-XJN5WUKL.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-L3PVMIYQ.js +10328 -0
- package/dist/chunk-L3PVMIYQ.js.map +1 -0
- package/dist/{chunk-QW2Q2KAH.js → chunk-LHHMV4GU.js} +2 -2
- package/dist/{chunk-ZOBNS7CX.js → chunk-MEFB5KHA.js} +4 -18
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/{chunk-M2O56UK7.js → chunk-N35E6CM2.js} +293 -163
- package/dist/chunk-N35E6CM2.js.map +1 -0
- package/dist/chunk-OCBHUHWB.js +69 -0
- package/dist/chunk-OCBHUHWB.js.map +1 -0
- package/dist/chunk-OIM4HLN6.js +1405 -0
- package/dist/chunk-OIM4HLN6.js.map +1 -0
- package/dist/{chunk-VYOJOX4Z.js → chunk-OJLYNM4Z.js} +54 -33
- package/dist/chunk-OJLYNM4Z.js.map +1 -0
- package/dist/{chunk-POJRB2AE.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-PZEN5PHN.js +285 -0
- package/dist/chunk-PZEN5PHN.js.map +1 -0
- package/dist/chunk-SKAHDQH7.js +1785 -0
- package/dist/chunk-SKAHDQH7.js.map +1 -0
- package/dist/{chunk-KZAAWQNP.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-U5DXNFJC.js +137 -0
- package/dist/chunk-U5DXNFJC.js.map +1 -0
- package/dist/chunk-USS336NF.js +165 -0
- package/dist/chunk-USS336NF.js.map +1 -0
- package/dist/{chunk-UO22YNY4.js → chunk-WH7OWT6G.js} +49 -1
- package/dist/chunk-WH7OWT6G.js.map +1 -0
- package/dist/chunk-WXC57XGG.js +29 -0
- package/dist/chunk-WXC57XGG.js.map +1 -0
- package/dist/{chunk-YLYINX2H.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/{chunk-CPCX67TI.js → chunk-YEETV6IW.js} +1079 -1039
- package/dist/chunk-YEETV6IW.js.map +1 -0
- package/dist/{chunk-OLWTRUTS.js → chunk-YJHHCWM3.js} +35 -16
- package/dist/chunk-YJHHCWM3.js.map +1 -0
- package/dist/{cli-KKRKBU5T.js → cli-M3XCSOU6.js} +289 -374
- package/dist/cli-M3XCSOU6.js.map +1 -0
- package/dist/config-MXOX7XDR.js +41 -0
- package/dist/{dist-U4M6QCKE.js → dist-3LOO6M4U.js} +10 -10
- package/dist/doctor-LU4YIZWM.js +349 -0
- package/dist/doctor-LU4YIZWM.js.map +1 -0
- package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/{chunk-KAJZHIQ4.js → fund-A54P2QFK.js} +80 -24
- package/dist/fund-A54P2QFK.js.map +1 -0
- package/dist/hook-command-U6KWPEDQ.js +377 -0
- package/dist/hook-command-U6KWPEDQ.js.map +1 -0
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/install-XUM2XSHW.js +53 -0
- package/dist/install-wallet-QIOFORTX.js +105 -0
- package/dist/install-wallet-QIOFORTX.js.map +1 -0
- package/dist/{run-XYTQ5TWQ.js → mcp-HJC2PLRV.js} +3727 -10670
- package/dist/mcp-HJC2PLRV.js.map +1 -0
- package/dist/paths-P2N4JTDZ.js +49 -0
- package/dist/pay-SBXZEPEP.js +37 -0
- package/dist/redact-46ZHF2NH.js +17 -0
- package/dist/{secp256k1-XRPVBC6V.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/{send-G746D7PQ.js → send-ASD2ZXJD.js} +28 -29
- package/dist/send-ASD2ZXJD.js.map +1 -0
- package/dist/{chunk-QZ6ROAJU.js → skill-placement-NFVHY6A3.js} +157 -11
- package/dist/skill-placement-NFVHY6A3.js.map +1 -0
- package/dist/status-T2SDB57A.js +63 -0
- package/dist/status-T2SDB57A.js.map +1 -0
- package/dist/status-line-CGPUSDMC.js +71 -0
- package/dist/status-line-CGPUSDMC.js.map +1 -0
- package/dist/status-line-wiring-BYPHTYZE.js +30 -0
- package/dist/tenjin-daemon.mjs +20060 -0
- package/dist/tenjin-shim.mjs +251 -0
- package/dist/tenjin-vitest-reporter.mjs +49 -0
- package/dist/uninstall-FKYZHAM3.js +144 -0
- package/dist/uninstall-FKYZHAM3.js.map +1 -0
- package/dist/{update-R76LHOZW.js → update-ANJ2AOTN.js} +133 -16
- package/dist/update-ANJ2AOTN.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-TUQJBMHM.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
- package/dist/wallet-PWAHVKWW.js +31 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +65 -354
- package/docs/safety-model.md +16 -6
- package/package.json +8 -7
- package/LICENSE +0 -21
- package/dist/buy-VIRNSYGN.js +0 -47
- package/dist/chunk-2MYQN7HM.js +0 -247
- package/dist/chunk-2MYQN7HM.js.map +0 -1
- package/dist/chunk-2RF2GIJQ.js +0 -1188
- package/dist/chunk-2RF2GIJQ.js.map +0 -1
- package/dist/chunk-3GL2Z5QK.js +0 -57
- package/dist/chunk-3GL2Z5QK.js.map +0 -1
- package/dist/chunk-47PP7TAG.js.map +0 -1
- package/dist/chunk-4CQIDQOT.js +0 -167
- package/dist/chunk-4CQIDQOT.js.map +0 -1
- package/dist/chunk-4KG27W2S.js +0 -614
- package/dist/chunk-4KG27W2S.js.map +0 -1
- package/dist/chunk-5QQTYWEU.js +0 -199
- package/dist/chunk-5QQTYWEU.js.map +0 -1
- package/dist/chunk-65DTCCJ7.js +0 -21
- package/dist/chunk-65DTCCJ7.js.map +0 -1
- package/dist/chunk-A5DKHMUN.js +0 -173
- package/dist/chunk-A5DKHMUN.js.map +0 -1
- package/dist/chunk-B63XPWQ4.js +0 -246
- package/dist/chunk-B63XPWQ4.js.map +0 -1
- package/dist/chunk-CAR6FHK6.js +0 -105
- package/dist/chunk-CAR6FHK6.js.map +0 -1
- package/dist/chunk-CPCX67TI.js.map +0 -1
- package/dist/chunk-CQBVCYI2.js +0 -162
- package/dist/chunk-CQBVCYI2.js.map +0 -1
- package/dist/chunk-DBU5CXBV.js +0 -4731
- package/dist/chunk-DBU5CXBV.js.map +0 -1
- package/dist/chunk-DHJD77OW.js +0 -81
- package/dist/chunk-DHJD77OW.js.map +0 -1
- package/dist/chunk-EDZSNPE5.js +0 -35
- package/dist/chunk-EDZSNPE5.js.map +0 -1
- package/dist/chunk-EFWZPUTC.js +0 -65
- package/dist/chunk-EFWZPUTC.js.map +0 -1
- package/dist/chunk-EPFL6CTE.js +0 -448
- package/dist/chunk-EPFL6CTE.js.map +0 -1
- package/dist/chunk-GHLVXVZD.js +0 -142
- package/dist/chunk-GHLVXVZD.js.map +0 -1
- package/dist/chunk-H3SOOJ2I.js +0 -580
- package/dist/chunk-H3SOOJ2I.js.map +0 -1
- package/dist/chunk-HPJGOLTN.js.map +0 -1
- package/dist/chunk-HRGBS2PA.js +0 -203
- package/dist/chunk-HRGBS2PA.js.map +0 -1
- package/dist/chunk-ITUXPJIS.js +0 -314
- package/dist/chunk-ITUXPJIS.js.map +0 -1
- package/dist/chunk-JBIKAAT3.js.map +0 -1
- package/dist/chunk-KAJZHIQ4.js.map +0 -1
- package/dist/chunk-KINZ23CV.js.map +0 -1
- package/dist/chunk-LRYV3SK7.js +0 -235
- package/dist/chunk-LRYV3SK7.js.map +0 -1
- package/dist/chunk-M2O56UK7.js.map +0 -1
- package/dist/chunk-MJZZTKCC.js.map +0 -1
- package/dist/chunk-NIKXHWOL.js.map +0 -1
- package/dist/chunk-OKDRDT74.js +0 -209
- package/dist/chunk-OKDRDT74.js.map +0 -1
- package/dist/chunk-OKYSNAS3.js +0 -2144
- package/dist/chunk-OKYSNAS3.js.map +0 -1
- package/dist/chunk-OLWTRUTS.js.map +0 -1
- package/dist/chunk-QQ6ELLSA.js +0 -143
- package/dist/chunk-QQ6ELLSA.js.map +0 -1
- package/dist/chunk-QZ6ROAJU.js.map +0 -1
- package/dist/chunk-R7RSCBI7.js +0 -794
- package/dist/chunk-R7RSCBI7.js.map +0 -1
- package/dist/chunk-SGK2B724.js +0 -67
- package/dist/chunk-SGK2B724.js.map +0 -1
- package/dist/chunk-U6VPKMGC.js +0 -390
- package/dist/chunk-U6VPKMGC.js.map +0 -1
- package/dist/chunk-UHTVXQ2O.js +0 -140
- package/dist/chunk-UHTVXQ2O.js.map +0 -1
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-US456VUI.js +0 -149
- package/dist/chunk-US456VUI.js.map +0 -1
- package/dist/chunk-V44J2MXV.js +0 -400
- package/dist/chunk-V44J2MXV.js.map +0 -1
- package/dist/chunk-VJQKL3YH.js +0 -216
- package/dist/chunk-VJQKL3YH.js.map +0 -1
- package/dist/chunk-VJSQSLBM.js +0 -1442
- package/dist/chunk-VJSQSLBM.js.map +0 -1
- package/dist/chunk-VYOJOX4Z.js.map +0 -1
- package/dist/chunk-WY2K35OL.js +0 -269
- package/dist/chunk-WY2K35OL.js.map +0 -1
- package/dist/chunk-ZFJJ3EXC.js.map +0 -1
- package/dist/chunk-ZOBNS7CX.js.map +0 -1
- package/dist/cli-KKRKBU5T.js.map +0 -1
- package/dist/config-JMRUNYE6.js +0 -37
- package/dist/discover-B5HF6SHM.js +0 -102
- package/dist/discover-B5HF6SHM.js.map +0 -1
- package/dist/doctor-ZBG7X66D.js +0 -32
- package/dist/edit-PZJIILQE.js +0 -40
- package/dist/fund-EUDH5KPA.js +0 -40
- package/dist/inspect-QC6WEQPN.js +0 -37
- package/dist/install-GNK2W3PI.js +0 -972
- package/dist/install-GNK2W3PI.js.map +0 -1
- package/dist/outcome-KSGWZHUS.js +0 -24
- package/dist/pay-BC4UICPA.js +0 -361
- package/dist/pay-BC4UICPA.js.map +0 -1
- package/dist/publish-LXWFDIKF.js +0 -42
- package/dist/read-JMNUQ56P.js +0 -160
- package/dist/read-JMNUQ56P.js.map +0 -1
- package/dist/run-XYTQ5TWQ.js.map +0 -1
- package/dist/search-TSQAB45E.js +0 -25
- package/dist/secp256k1-XRPVBC6V.js.map +0 -1
- package/dist/send-G746D7PQ.js.map +0 -1
- package/dist/session-JBKWMJ24.js +0 -89
- package/dist/session-JBKWMJ24.js.map +0 -1
- package/dist/skill-heal-WKD67SLJ.js +0 -92
- package/dist/skill-heal-WKD67SLJ.js.map +0 -1
- package/dist/skill-placement-RIU4AMC2.js +0 -20
- package/dist/skill-placement-RIU4AMC2.js.map +0 -1
- package/dist/uninstall-5E263VTS.js +0 -73
- package/dist/uninstall-5E263VTS.js.map +0 -1
- package/dist/update-R76LHOZW.js.map +0 -1
- package/dist/usdc-4VCDHFWX.js +0 -38
- package/dist/usdc-4VCDHFWX.js.map +0 -1
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
- package/dist/wallet-TQ7D5EQ7.js +0 -41
- package/dist/wallet-TQ7D5EQ7.js.map +0 -1
- package/dist/wallet-ZAVXWLWP.js +0 -32
- package/dist/wallet-ZAVXWLWP.js.map +0 -1
- package/docs/command-reference.md +0 -303
- package/skills/tenjin/SKILL.md +0 -373
- package/skills/tenjin-pay/SKILL.md +0 -76
- package/skills/tenjin-publish/SKILL.md +0 -227
- package/skills/tenjin-publish/references/maintain.md +0 -39
- package/skills/tenjin-search/SKILL.md +0 -154
- package/skills/tenjin-search/references/permissions.md +0 -112
- /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
- /package/dist/{buy-VIRNSYGN.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
- /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
- /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{ccip-ZGGWQN4X.js.map → config-MXOX7XDR.js.map} +0 -0
- /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
- /package/dist/{config-JMRUNYE6.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
- /package/dist/{doctor-ZBG7X66D.js.map → install-XUM2XSHW.js.map} +0 -0
- /package/dist/{edit-PZJIILQE.js.map → paths-P2N4JTDZ.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-SBXZEPEP.js.map} +0 -0
- /package/dist/{fund-EUDH5KPA.js.map → redact-46ZHF2NH.js.map} +0 -0
- /package/dist/{inspect-QC6WEQPN.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
- /package/dist/{outcome-KSGWZHUS.js.map → status-line-wiring-BYPHTYZE.js.map} +0 -0
- /package/dist/{publish-LXWFDIKF.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
- /package/dist/{search-TSQAB45E.js.map → wallet-PWAHVKWW.js.map} +0 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
paint
|
|
4
|
+
} from "./chunk-YJHHCWM3.js";
|
|
5
|
+
import {
|
|
6
|
+
persistRouterDefaults
|
|
7
|
+
} from "./chunk-GULLJQXA.js";
|
|
8
|
+
import {
|
|
9
|
+
onPath
|
|
10
|
+
} from "./chunk-U5DXNFJC.js";
|
|
11
|
+
import {
|
|
12
|
+
resolveContextSettings
|
|
13
|
+
} from "./chunk-OJLYNM4Z.js";
|
|
14
|
+
import {
|
|
15
|
+
toMoney
|
|
16
|
+
} from "./chunk-WH7OWT6G.js";
|
|
17
|
+
import {
|
|
18
|
+
ensureStatusLine
|
|
19
|
+
} from "./chunk-HVRC33OL.js";
|
|
20
|
+
import {
|
|
21
|
+
appendAllowlistRules,
|
|
22
|
+
claudeAdapter,
|
|
23
|
+
claudeSettingsPath,
|
|
24
|
+
inspectHooksFile,
|
|
25
|
+
ownsHookEntry,
|
|
26
|
+
writeHooks
|
|
27
|
+
} from "./chunk-SKAHDQH7.js";
|
|
28
|
+
import {
|
|
29
|
+
CliError
|
|
30
|
+
} from "./chunk-OCBHUHWB.js";
|
|
31
|
+
|
|
32
|
+
// src/router/install.ts
|
|
33
|
+
import { execFile } from "node:child_process";
|
|
34
|
+
import { readFile } from "node:fs/promises";
|
|
35
|
+
import { homedir } from "node:os";
|
|
36
|
+
import { isAbsolute, join } from "node:path";
|
|
37
|
+
import { promisify } from "node:util";
|
|
38
|
+
var exec = promisify(execFile);
|
|
39
|
+
var HOOK_TIMEOUT_SECONDS = 5;
|
|
40
|
+
var MCP_SERVER_NAME = "x402";
|
|
41
|
+
var ALLOW_RULE = "mcp__x402__request";
|
|
42
|
+
function mcpScope(project) {
|
|
43
|
+
return project === true ? "project" : "user";
|
|
44
|
+
}
|
|
45
|
+
function mcpAddCommand(project) {
|
|
46
|
+
return `claude mcp add ${MCP_SERVER_NAME} -s ${mcpScope(project)} -- tenjin mcp`;
|
|
47
|
+
}
|
|
48
|
+
function mcpRemoveCommand(project) {
|
|
49
|
+
return `claude mcp remove ${MCP_SERVER_NAME} -s ${mcpScope(project)}`;
|
|
50
|
+
}
|
|
51
|
+
var MCP_ADD_COMMAND = mcpAddCommand();
|
|
52
|
+
function routerSettingsPath(opts = {}) {
|
|
53
|
+
if (opts.project === true) return join(opts.cwd ?? process.cwd(), ".claude", "settings.json");
|
|
54
|
+
return claudeSettingsPath(opts.homeDir ?? homedir());
|
|
55
|
+
}
|
|
56
|
+
function routerHookPlan() {
|
|
57
|
+
const handler = (command) => [
|
|
58
|
+
{ type: "command", command, timeout: HOOK_TIMEOUT_SECONDS }
|
|
59
|
+
];
|
|
60
|
+
return [
|
|
61
|
+
{ event: "UserPromptSubmit", hooks: handler("tenjin hook prompt") },
|
|
62
|
+
{ event: "PreToolUse", matcher: "WebSearch|WebFetch", hooks: handler("tenjin hook native") }
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
var DISCLOSURE = [
|
|
66
|
+
"What leaves this machine: the bounded text of each prompt and each native search query or URL, sent to Tenjin for the free routing gate.",
|
|
67
|
+
"What is kept when a lookup is paid: the capability chosen, a hash of the contract, a hash of the arguments, and your wallet address. No prompt text, no arguments, no hint text.",
|
|
68
|
+
"What never leaves: your private key. It is decrypted in this CLI to sign, and never sent anywhere."
|
|
69
|
+
];
|
|
70
|
+
async function runRouterInstall(args, ctx, deps = {}) {
|
|
71
|
+
const env = deps.env ?? process.env;
|
|
72
|
+
const home = deps.homeDir ?? homedir();
|
|
73
|
+
if (!isAbsolute(home)) {
|
|
74
|
+
throw new CliError("INTERNAL", "The home directory is not an absolute path.", {
|
|
75
|
+
fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
79
|
+
const project = args.project ?? (args.refresh === true && (await probeOurEntries(routerSettingsPath({ project: true, cwd }), ctx.dataDir)).state === "present");
|
|
80
|
+
const settingsPath = routerSettingsPath({
|
|
81
|
+
...project ? { project: true } : {},
|
|
82
|
+
homeDir: home,
|
|
83
|
+
cwd
|
|
84
|
+
});
|
|
85
|
+
if (args.refresh === true) {
|
|
86
|
+
const probe = await probeOurEntries(settingsPath, ctx.dataDir);
|
|
87
|
+
if (probe.state === "unreadable") {
|
|
88
|
+
throw new CliError("CONFIG_INVALID", `Could not inspect ${settingsPath}: ${probe.reason}`, {
|
|
89
|
+
fix: `Fix ${settingsPath}, then re-run: tenjin update`
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (probe.state === "absent") {
|
|
93
|
+
throw new CliError(
|
|
94
|
+
"REFUSED",
|
|
95
|
+
`Nothing to refresh in ${settingsPath}: no Tenjin hook entries are registered here.`,
|
|
96
|
+
{ fix: "Run `tenjin install` to set this machine up." }
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const hooks = await writeHooks({
|
|
101
|
+
adapter: claudeAdapter,
|
|
102
|
+
homeDir: home,
|
|
103
|
+
dataDir: ctx.dataDir,
|
|
104
|
+
env,
|
|
105
|
+
plan: routerHookPlan(),
|
|
106
|
+
settingsPath
|
|
107
|
+
});
|
|
108
|
+
const permissions = await ensureAllowRule(settingsPath);
|
|
109
|
+
const statusLine = await ensureStatusLine(settingsPath, {
|
|
110
|
+
...args.statusLine !== void 0 ? { mode: args.statusLine } : {},
|
|
111
|
+
...args.refresh === true ? { refreshOnly: true } : {}
|
|
112
|
+
});
|
|
113
|
+
const mcp = await registerMcpServer(deps, env, project, cwd, home);
|
|
114
|
+
if (args.refresh === true) {
|
|
115
|
+
if (mcp.reconciled === "unrepaired") {
|
|
116
|
+
throw new CliError(
|
|
117
|
+
"REFUSED",
|
|
118
|
+
`The ${MCP_SERVER_NAME} MCP registration (${mcpScope(project)} scope) is not the router's and this run could not repair it: ${mcp.reason ?? "unknown reason"}.`,
|
|
119
|
+
{ fix: `Run: ${mcp.command}`, details: { settingsPath, hooks, permissions, mcp } }
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
data: {
|
|
124
|
+
settingsPath,
|
|
125
|
+
hooks,
|
|
126
|
+
permissions,
|
|
127
|
+
statusLine,
|
|
128
|
+
mcp,
|
|
129
|
+
refresh: true,
|
|
130
|
+
scope: mcpScope(project)
|
|
131
|
+
},
|
|
132
|
+
humanLines: refreshLines(ctx, problems(ctx, hooks, permissions, statusLine, mcp))
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const spend = await persistRouterDefaults(ctx.dataDir);
|
|
136
|
+
const { resolveWallet } = await import("./install-wallet-QIOFORTX.js");
|
|
137
|
+
const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? "flag" : void 0, false);
|
|
138
|
+
const effective = await resolveContextSettings(ctx);
|
|
139
|
+
const data = {
|
|
140
|
+
settingsPath,
|
|
141
|
+
hooks,
|
|
142
|
+
permissions,
|
|
143
|
+
statusLine,
|
|
144
|
+
spend: { ...spend, effective: effectiveLimits(effective.policy) },
|
|
145
|
+
mcp,
|
|
146
|
+
wallet,
|
|
147
|
+
disclosure: DISCLOSURE
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
data,
|
|
151
|
+
humanLines: lines(ctx, {
|
|
152
|
+
project,
|
|
153
|
+
hooks,
|
|
154
|
+
permissions,
|
|
155
|
+
statusLine,
|
|
156
|
+
mcp,
|
|
157
|
+
wallet,
|
|
158
|
+
policy: effective.policy
|
|
159
|
+
})
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function ensureAllowRule(path) {
|
|
163
|
+
const result = await appendAllowlistRules(path, [ALLOW_RULE]);
|
|
164
|
+
return {
|
|
165
|
+
path: result.path,
|
|
166
|
+
rule: ALLOW_RULE,
|
|
167
|
+
added: result.added.length > 0,
|
|
168
|
+
...result.warning !== void 0 ? { warning: result.warning } : result.skipped !== void 0 ? { warning: `${result.path} was left untouched (${result.skipped}).` } : {}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async function registerMcpServer(deps, env, project, cwd, home) {
|
|
172
|
+
const scope = mcpScope(project);
|
|
173
|
+
const command = mcpAddCommand(project);
|
|
174
|
+
const base = { name: MCP_SERVER_NAME, scope, command };
|
|
175
|
+
const existing = await (deps.readMcpEntry ?? readMcpEntry)(scope, cwd, home);
|
|
176
|
+
if (existing.state === "ok") {
|
|
177
|
+
return { ...base, registered: true, reconciled: "already-registered" };
|
|
178
|
+
}
|
|
179
|
+
if (existing.state === "unreadable") {
|
|
180
|
+
return {
|
|
181
|
+
...base,
|
|
182
|
+
registered: false,
|
|
183
|
+
reconciled: "unrepaired",
|
|
184
|
+
reason: `the ${scope}-scope registration file could not be read, so nothing was written over it`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (existing.state === "wrong-command") {
|
|
188
|
+
return {
|
|
189
|
+
...base,
|
|
190
|
+
registered: false,
|
|
191
|
+
reconciled: "unrepaired",
|
|
192
|
+
command: `${mcpRemoveCommand(project)} && ${command}`,
|
|
193
|
+
reason: `an MCP server named ${MCP_SERVER_NAME} is already registered at ${scope} scope and launches something else. This command will not remove a registration it did not write; run the two commands above if that entry is stale`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const which = deps.which ?? ((bin) => onPath(bin, env));
|
|
197
|
+
if (!which("claude")) {
|
|
198
|
+
return {
|
|
199
|
+
...base,
|
|
200
|
+
registered: false,
|
|
201
|
+
reconciled: "unavailable",
|
|
202
|
+
reason: "the `claude` binary is not on PATH"
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
await (deps.registerMcp ?? runClaudeMcpAdd)(command, { scope, cwd });
|
|
207
|
+
return { ...base, registered: true, reconciled: "added" };
|
|
208
|
+
} catch (err) {
|
|
209
|
+
return {
|
|
210
|
+
...base,
|
|
211
|
+
registered: false,
|
|
212
|
+
reconciled: "unavailable",
|
|
213
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function classifyMcpEntry(entry) {
|
|
218
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return "absent";
|
|
219
|
+
const { command, args } = entry;
|
|
220
|
+
if (typeof command !== "string" || command.length === 0) return "wrong-command";
|
|
221
|
+
const binary = command.split(/[\\/]/).pop();
|
|
222
|
+
const runsRouter = binary === "tenjin" && Array.isArray(args) && args.length === 1 && args[0] === "mcp";
|
|
223
|
+
return runsRouter ? "ok" : "wrong-command";
|
|
224
|
+
}
|
|
225
|
+
async function readMcpEntry(scope, cwd, home) {
|
|
226
|
+
const path = scope === "project" ? join(cwd, ".mcp.json") : join(home, ".claude.json");
|
|
227
|
+
let raw;
|
|
228
|
+
try {
|
|
229
|
+
raw = await readFile(path, "utf8");
|
|
230
|
+
} catch (err) {
|
|
231
|
+
const code = err.code;
|
|
232
|
+
if (code === "ENOENT" || code === "ENOTDIR") return { found: false, state: "absent" };
|
|
233
|
+
return { found: true, state: "unreadable" };
|
|
234
|
+
}
|
|
235
|
+
let parsed;
|
|
236
|
+
try {
|
|
237
|
+
parsed = JSON.parse(raw);
|
|
238
|
+
} catch {
|
|
239
|
+
return { found: true, state: "unreadable" };
|
|
240
|
+
}
|
|
241
|
+
const servers = parsed?.mcpServers;
|
|
242
|
+
if (servers === void 0) return { found: true, state: "absent" };
|
|
243
|
+
if (servers === null || typeof servers !== "object" || Array.isArray(servers)) {
|
|
244
|
+
return { found: true, state: "unreadable" };
|
|
245
|
+
}
|
|
246
|
+
const entry = servers[MCP_SERVER_NAME];
|
|
247
|
+
if (entry === void 0) return { found: true, state: "absent" };
|
|
248
|
+
return { found: true, state: classifyMcpEntry(entry) };
|
|
249
|
+
}
|
|
250
|
+
async function runClaudeMcpAdd(_command, opts) {
|
|
251
|
+
await exec("claude", ["mcp", "add", MCP_SERVER_NAME, "-s", opts.scope, "--", "tenjin", "mcp"], {
|
|
252
|
+
timeout: 2e4,
|
|
253
|
+
cwd: opts.cwd
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function effectiveLimits(policy) {
|
|
257
|
+
return {
|
|
258
|
+
maxAutoSpend: toMoney(policy.maxAutoSpendAtomic.toString()).usd,
|
|
259
|
+
sessionBudget: policy.sessionBudgetAtomic === 0n ? "no daily ceiling" : toMoney(policy.sessionBudgetAtomic.toString()).usd
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function statusLineProblems(ctx, result) {
|
|
263
|
+
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
264
|
+
if (result.warning !== void 0) {
|
|
265
|
+
return [warn(`The live status line was not registered (${result.warning})`)];
|
|
266
|
+
}
|
|
267
|
+
if (result.state !== "foreign") return [];
|
|
268
|
+
return [
|
|
269
|
+
warn("You already have a status line, so it was left exactly as it is."),
|
|
270
|
+
" To show the live x402 footer beside it, run:",
|
|
271
|
+
" tenjin install --status-line compose",
|
|
272
|
+
...result.compose === void 0 ? [] : [" or set this command yourself:", ` ${result.compose}`]
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
function lines(ctx, s) {
|
|
276
|
+
const ok = paint(ctx.io, "green", "\u2713");
|
|
277
|
+
const limits = effectiveLimits(s.policy);
|
|
278
|
+
const daily = s.policy.sessionBudgetAtomic === 0n ? "no daily limit" : `$${limits.sessionBudget} a day`;
|
|
279
|
+
const blocked = s.hooks.skipped !== void 0;
|
|
280
|
+
const needsMcp = !blocked && !s.mcp.registered;
|
|
281
|
+
const where = s.project ? " in this project" : "";
|
|
282
|
+
const fund = paint(ctx.io, "bold", "tenjin wallet fund");
|
|
283
|
+
return [
|
|
284
|
+
blocked ? paint(ctx.io, "yellow", `! Tenjin could not finish setting up Claude Code${where}`) : needsMcp ? paint(ctx.io, "yellow", "! Almost done: Claude Code needs one command") : `${ok} Tenjin is set up for Claude Code${where}`,
|
|
285
|
+
...walletLines(ctx, ok, s.wallet),
|
|
286
|
+
` Spends at most $${limits.maxAutoSpend} a lookup, ${daily}`,
|
|
287
|
+
...s.statusLine.state === "ours" || s.statusLine.state === "composed" ? [" Live status line on: each lookup names its provider while it runs"] : [],
|
|
288
|
+
...problems(ctx, s.hooks, s.permissions, s.statusLine, s.mcp),
|
|
289
|
+
"",
|
|
290
|
+
blocked ? "Next: fix the file above, then run tenjin install again" : needsMcp ? s.wallet.status === "created" ? `Next: run the command above and ${fund}, then restart Claude Code` : "Next: run the command above, then restart Claude Code" : s.wallet.status === "created" ? `Next: ${fund}, then restart Claude Code` : "Next: restart Claude Code"
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
function refreshLines(ctx, issues) {
|
|
294
|
+
if (issues.length === 0) return [`${paint(ctx.io, "green", "\u2713")} Tenjin is up to date`];
|
|
295
|
+
return [paint(ctx.io, "yellow", "! Tenjin is updated, but needs one fix"), ...issues];
|
|
296
|
+
}
|
|
297
|
+
function walletLines(ctx, ok, w) {
|
|
298
|
+
if (w.status === "created") return [`${ok} Wallet created: ${w.address}`];
|
|
299
|
+
if (w.status === "existing") return [`${ok} Wallet: ${w.address}`];
|
|
300
|
+
if (w.reason === "flag") return [" No wallet yet. Create one with: tenjin wallet create"];
|
|
301
|
+
return [
|
|
302
|
+
paint(ctx.io, "yellow", `! No wallet was created. ${w.warning ?? ""}`.trimEnd()),
|
|
303
|
+
` ${w.fix ?? "Create one with: tenjin wallet create"}`
|
|
304
|
+
];
|
|
305
|
+
}
|
|
306
|
+
function problems(ctx, hooks, permissions, statusLine, mcp) {
|
|
307
|
+
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
308
|
+
const out = [];
|
|
309
|
+
if (hooks.skipped !== void 0) {
|
|
310
|
+
out.push(
|
|
311
|
+
warn(
|
|
312
|
+
hooks.warning ?? `${hooks.path ?? "Your Claude Code settings file"} was left untouched (${hooks.skipped}).`
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
} else {
|
|
316
|
+
if (hooks.warning !== void 0) out.push(warn(hooks.warning));
|
|
317
|
+
if (permissions.warning !== void 0) out.push(warn(permissions.warning));
|
|
318
|
+
}
|
|
319
|
+
if (!mcp.registered) {
|
|
320
|
+
out.push(warn("Could not add the request tool to Claude Code. Run:"));
|
|
321
|
+
out.push(` ${mcp.command}`);
|
|
322
|
+
}
|
|
323
|
+
out.push(...statusLineProblems(ctx, statusLine));
|
|
324
|
+
return out;
|
|
325
|
+
}
|
|
326
|
+
async function probeOurEntries(path, dataDir) {
|
|
327
|
+
const found = await inspectHooksFile(path);
|
|
328
|
+
if ("refusal" in found) {
|
|
329
|
+
return { state: "unreadable", reason: found.refusal.reason };
|
|
330
|
+
}
|
|
331
|
+
const present = Object.values(found.hooks).some(
|
|
332
|
+
(list) => list.some((entry) => ownsHookEntry(entry, dataDir))
|
|
333
|
+
);
|
|
334
|
+
return present ? { state: "present" } : { state: "absent" };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export {
|
|
338
|
+
HOOK_TIMEOUT_SECONDS,
|
|
339
|
+
MCP_SERVER_NAME,
|
|
340
|
+
ALLOW_RULE,
|
|
341
|
+
mcpScope,
|
|
342
|
+
mcpAddCommand,
|
|
343
|
+
mcpRemoveCommand,
|
|
344
|
+
MCP_ADD_COMMAND,
|
|
345
|
+
routerSettingsPath,
|
|
346
|
+
routerHookPlan,
|
|
347
|
+
DISCLOSURE,
|
|
348
|
+
runRouterInstall,
|
|
349
|
+
classifyMcpEntry,
|
|
350
|
+
readMcpEntry,
|
|
351
|
+
statusLineProblems
|
|
352
|
+
};
|
|
353
|
+
//# sourceMappingURL=chunk-25TJPVBF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/install.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport { readFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { isAbsolute, join } from 'node:path';\nimport { promisify } from 'node:util';\nimport { claudeAdapter } from '../adapters/claude';\nimport { persistRouterDefaults } from '../commands/config';\nimport { CliError } from '../lib/errors';\nimport { appendAllowlistRules, claudeSettingsPath } from '../lib/harness-permissions';\nimport {\n inspectHooksFile,\n ownsHookEntry,\n pruneHooks,\n writeHooks,\n type HooksResult,\n} from '../lib/harness-hooks';\nimport { toMoney } from '../lib/money';\nimport { paint } from '../lib/output';\nimport { resolveContextSettings } from '../lib/settings';\nimport type { SpendPolicy } from '../lib/policy';\nimport { onPath } from '../lib/skill-wiring';\nimport type { WalletDeps, WalletOutcome } from '../commands/install-wallet';\nimport type { CommandContext, CommandResult } from '../context';\nimport { ensureStatusLine, type StatusLineMode, type StatusLineResult } from './status-line-wiring';\n\n/**\n * `tenjin install` for the router product: two hook entries, one MCP server,\n * one permission rule, the spend defaults, and a wallet when there is none.\n *\n * WHAT IT WRITES IS WHAT IT SAYS. There is no skill to materialize, no daemon\n * to start and no background process of any kind: the hooks are plain command\n * lines, the tool lives in an MCP server the harness starts per session, and\n * every other key in the settings file is preserved byte for byte.\n */\n\nconst exec = promisify(execFile);\n\n/**\n * The harness's kill budget for each hook entry, and the number every other\n * wait inside the hook is cut from: 1 s of stdin plus 3.5 s of gate, with\n * 500 ms left for node's boot and the transcript read (`wire.test.ts` pins it).\n * Raised from 3 s because a gate abort costs the turn its hint silently.\n *\n * A machine carrying the old number is converged by the writer, not by the\n * user: the entries are ours by marker, so `install`, `install --refresh` and\n * the refresh `tenjin update` spawns all rewrite them in place.\n */\nexport const HOOK_TIMEOUT_SECONDS = 5;\nexport const MCP_SERVER_NAME = 'x402';\nexport const ALLOW_RULE = 'mcp__x402__request';\n/**\n * The MCP registration follows the SAME SCOPE the hook entries do. A\n * `--project` install that wrote its hooks into the project and then registered\n * the server at user scope would reach into `~/.claude.json` on a run whose\n * whole point is to touch this project and nothing else, and `tenjin uninstall\n * --project` would leave that behind.\n *\n * Project scope writes `<project>/.mcp.json`, so the registration lives beside\n * the settings file that names the hooks and travels with the repository.\n */\nexport function mcpScope(project: boolean | undefined): 'user' | 'project' {\n return project === true ? 'project' : 'user';\n}\n\nexport function mcpAddCommand(project?: boolean): string {\n return `claude mcp add ${MCP_SERVER_NAME} -s ${mcpScope(project)} -- tenjin mcp`;\n}\n\nexport function mcpRemoveCommand(project?: boolean): string {\n return `claude mcp remove ${MCP_SERVER_NAME} -s ${mcpScope(project)}`;\n}\n\n/** The user-scope form, kept as the name the docs and the tests already use. */\nexport const MCP_ADD_COMMAND = mcpAddCommand();\n\n/**\n * Which settings file this machine's router wiring lives in, spelled once so\n * `install`, `uninstall` and `doctor` can never disagree about where to look.\n * A doctor reading the home file on a `--project` install reported a correctly\n * wired machine as unwired and exited 3.\n */\nexport function routerSettingsPath(\n opts: { project?: boolean; homeDir?: string; cwd?: string } = {},\n): string {\n if (opts.project === true) return join(opts.cwd ?? process.cwd(), '.claude', 'settings.json');\n return claudeSettingsPath(opts.homeDir ?? homedir());\n}\n\n/** The two entries, spelled once so `uninstall` and the tests read the same list. */\nexport function routerHookPlan(): unknown[] {\n const handler = (command: string) => [\n { type: 'command', command, timeout: HOOK_TIMEOUT_SECONDS },\n ];\n return [\n { event: 'UserPromptSubmit', hooks: handler('tenjin hook prompt') },\n { event: 'PreToolUse', matcher: 'WebSearch|WebFetch', hooks: handler('tenjin hook native') },\n ];\n}\n\nexport const DISCLOSURE: readonly string[] = [\n 'What leaves this machine: the bounded text of each prompt and each native search query or URL, sent to Tenjin for the free routing gate.',\n 'What is kept when a lookup is paid: the capability chosen, a hash of the contract, a hash of the arguments, and your wallet address. No prompt text, no arguments, no hint text.',\n 'What never leaves: your private key. It is decrypted in this CLI to sign, and never sent anywhere.',\n];\n\nexport interface RouterInstallArgs {\n /** Write into this project's `.claude/settings.json` instead of your home one. */\n project?: boolean;\n /**\n * Bring the entries this machine ALREADY has up to the running build, and\n * add nothing: no config write, no MCP registration, and a refusal when\n * nothing of ours is here. `tenjin update` spawns exactly this after it swaps\n * the binary, so the flag's name and meaning are a compatibility contract.\n */\n refresh?: boolean;\n /**\n * What to do about Claude Code's `statusLine`. Absent is the default path:\n * write ours when the key is free, and print the composition line when it is\n * not. `compose` wraps the status line already there and appends ours;\n * `skip` leaves the key alone entirely.\n */\n statusLine?: StatusLineMode;\n /** Create no wallet, for CI and scripted machines. */\n noWallet?: boolean;\n}\n\nexport interface RouterInstallDeps extends WalletDeps {\n homeDir?: string;\n cwd?: string;\n env?: NodeJS.ProcessEnv;\n /** PATH probe for the `claude` binary. */\n which?: (bin: string) => boolean;\n /** Runs `claude mcp add`; tests inject it so no binary is spawned. The scope\n * and the working directory are passed, because project scope is decided by\n * where the command runs as much as by the flag. */\n registerMcp?: (\n command: string,\n opts: { scope: 'user' | 'project'; cwd: string },\n ) => Promise<void>;\n /** Reads the registration the scope's own file holds; tests inject it. */\n readMcpEntry?: (\n scope: 'user' | 'project',\n cwd: string,\n home: string,\n ) => Promise<{ found: boolean; state: McpEntryState }>;\n}\n\nexport interface McpRegistration {\n name: string;\n registered: boolean;\n /** Which scope it went to, following the hook entries rather than the flag\n * being read twice. `project` writes `<project>/.mcp.json`. */\n scope: 'user' | 'project';\n /** The command to run by hand, when this run could not. */\n command: string;\n /**\n * WHAT THIS RUN ACTUALLY DID, which `registered` alone cannot say:\n * `already-registered` (the scope's file already launches `tenjin mcp`, and\n * nothing was spawned), `added`, `repaired` (a same-name entry launching\n * something else was removed and re-added, which only `uninstall` does now),\n * `unrepaired` (a registration this run KNOWS is wrong or unreadable and will\n * not touch) or `unavailable` (it is simply not there and this machine could\n * not add it, e.g. no `claude` on PATH). A refresh fails on `unrepaired`,\n * because reporting convergence over a registration that launches something\n * else is the thing to avoid; it still only prints the manual command for\n * `unavailable`.\n */\n reconciled: 'already-registered' | 'added' | 'repaired' | 'unrepaired' | 'unavailable';\n reason?: string;\n}\n\nexport async function runRouterInstall(\n args: RouterInstallArgs,\n ctx: CommandContext,\n deps: RouterInstallDeps = {},\n): Promise<CommandResult> {\n const env = deps.env ?? process.env;\n const home = deps.homeDir ?? homedir();\n if (!isAbsolute(home)) {\n throw new CliError('INTERNAL', 'The home directory is not an absolute path.', {\n fix: 'Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`.',\n });\n }\n const cwd = deps.cwd ?? process.cwd();\n // A refresh converges EVERY install this machine has, in the scope each one\n // was made in. `tenjin update` spawns it from the HOME directory, so looking\n // ONE SCOPE, THE ONE THIS RAN IN. `--refresh` converges the install whose\n // settings file is here: home by default, this project under `--project`.\n // The fan-out across recorded projects is gone with the list it read, along\n // with a failure mode where one project's broken JSON decided what every\n // other install got. `tenjin update` is a binary swap plus this, nothing more.\n // With no flag, a refresh converges the install that is actually HERE: the\n // project file when this directory carries our entries, the home file\n // otherwise. `--project` and its absence are still explicit targets, so\n // nothing silently moves an install from one scope to the other.\n const project =\n args.project ??\n (args.refresh === true &&\n (await probeOurEntries(routerSettingsPath({ project: true, cwd }), ctx.dataDir)).state ===\n 'present');\n const settingsPath = routerSettingsPath({\n ...(project ? { project: true } : {}),\n homeDir: home,\n cwd,\n });\n\n if (args.refresh === true) {\n const probe = await probeOurEntries(settingsPath, ctx.dataDir);\n // An unreadable file is not an absence, and telling someone to install over\n // it is the wrong instruction: the writer would refuse it too.\n if (probe.state === 'unreadable') {\n throw new CliError('CONFIG_INVALID', `Could not inspect ${settingsPath}: ${probe.reason}`, {\n fix: `Fix ${settingsPath}, then re-run: tenjin update`,\n });\n }\n if (probe.state === 'absent') {\n throw new CliError(\n 'REFUSED',\n `Nothing to refresh in ${settingsPath}: no Tenjin hook entries are registered here.`,\n { fix: 'Run `tenjin install` to set this machine up.' },\n );\n }\n }\n const hooks = await writeHooks({\n adapter: claudeAdapter,\n homeDir: home,\n dataDir: ctx.dataDir,\n env,\n plan: routerHookPlan(),\n settingsPath,\n });\n const permissions = await ensureAllowRule(settingsPath);\n const statusLine = await ensureStatusLine(settingsPath, {\n ...(args.statusLine !== undefined ? { mode: args.statusLine } : {}),\n ...(args.refresh === true ? { refreshOnly: true } : {}),\n });\n const mcp = await registerMcpServer(deps, env, project, cwd, home);\n if (args.refresh === true) {\n // The SAME writers, minus the one that decides anything: the entries are\n // rewritten in place by their ownership marker so an upgrade never\n // duplicates them, the rule and the registration are re-checked because a\n // new version can change either, and `config.json`, the wallet and\n // `spend.json` are not touched at all. Widening an agent's spend policy\n // during an unattended upgrade is not a convergence.\n // RECONCILED, not re-added: `claude mcp add` exits 1 on an existing entry,\n // so the registration is read first and only written when it is missing or\n // wrong (see {@link registerMcpServer}).\n // A registration this run KNOWS is wrong and could not repair is not a\n // converged install, and `tenjin update` reporting success over it is how\n // a machine keeps a stale `x402` server across upgrade after upgrade.\n if (mcp.reconciled === 'unrepaired') {\n throw new CliError(\n 'REFUSED',\n `The ${MCP_SERVER_NAME} MCP registration (${mcpScope(project)} scope) is not the router's and this run could not repair it: ${mcp.reason ?? 'unknown reason'}.`,\n { fix: `Run: ${mcp.command}`, details: { settingsPath, hooks, permissions, mcp } },\n );\n }\n return {\n data: {\n settingsPath,\n hooks,\n permissions,\n statusLine,\n mcp,\n refresh: true,\n scope: mcpScope(project),\n },\n humanLines: refreshLines(ctx, problems(ctx, hooks, permissions, statusLine, mcp)),\n };\n }\n const spend = await persistRouterDefaults(ctx.dataDir);\n // The shelf install's wallet step, unchanged except that it never asks: a\n // lookup cannot be paid without a wallet, so install makes one. A failure is\n // reported, never fatal; everything above is useful without it.\n const { resolveWallet } = await import('../commands/install-wallet');\n const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? 'flag' : undefined, false);\n // Read back AFTER the write: a machine that already carried its own caps\n // keeps them, and a readout quoting the defaults would describe limits this\n // run did not set.\n const effective = await resolveContextSettings(ctx);\n\n const data = {\n settingsPath,\n hooks,\n permissions,\n statusLine,\n spend: { ...spend, effective: effectiveLimits(effective.policy) },\n mcp,\n wallet,\n disclosure: DISCLOSURE,\n };\n return {\n data,\n humanLines: lines(ctx, {\n project,\n hooks,\n permissions,\n statusLine,\n mcp,\n wallet,\n policy: effective.policy,\n }),\n };\n}\n\nexport interface AllowRuleResult {\n path: string;\n rule: string;\n added: boolean;\n /** Set when the file could not be written; the rule is then not in force. */\n warning?: string;\n}\n\n/**\n * The one permission rule, through the shared allowlist writer rather than a\n * third hand-rolled one: it resolves a symlinked settings.json before the\n * rename, refuses a file it cannot parse, and compares the bytes it read before\n * committing, none of which a local copy of the merge would have.\n */\nasync function ensureAllowRule(path: string): Promise<AllowRuleResult> {\n const result = await appendAllowlistRules(path, [ALLOW_RULE]);\n return {\n path: result.path,\n rule: ALLOW_RULE,\n added: result.added.length > 0,\n ...(result.warning !== undefined\n ? { warning: result.warning }\n : result.skipped !== undefined\n ? { warning: `${result.path} was left untouched (${result.skipped}).` }\n : {}),\n };\n}\n\n/**\n * RECONCILE, do not re-add blindly. `claude mcp add` is not idempotent: Claude\n * Code 2.1.280 exits 1 on a second identical add with \"MCP server x402 already\n * exists in .mcp.json\". Running it unconditionally therefore reported a\n * perfectly healthy machine as an unregistered one and printed a repair command\n * that would fail the same way, while a same-name entry launching something\n * else never converged, because `add` refuses to overwrite it.\n *\n * So the scope's own file is read first: an entry that already launches\n * `tenjin mcp` is the goal state and nothing is spawned, and a file that cannot\n * be read is refused out loud rather than written over.\n *\n * AN `x402` ENTRY THAT LAUNCHES SOMETHING ELSE IS SOMEBODY ELSE'S. This command\n * will not delete it. It may be another tool of the user's that happens to\n * share the name, and an installer that removes a registration nobody asked it\n * to touch has destroyed configuration to make its own output look tidy. The\n * conflict is reported with the exact two commands to run, and the user decides.\n */\nasync function registerMcpServer(\n deps: RouterInstallDeps,\n env: NodeJS.ProcessEnv,\n project: boolean,\n cwd: string,\n home: string,\n): Promise<McpRegistration> {\n const scope = mcpScope(project);\n const command = mcpAddCommand(project);\n const base = { name: MCP_SERVER_NAME, scope, command };\n const existing = await (deps.readMcpEntry ?? readMcpEntry)(scope, cwd, home);\n if (existing.state === 'ok') {\n return { ...base, registered: true, reconciled: 'already-registered' };\n }\n if (existing.state === 'unreadable') {\n return {\n ...base,\n registered: false,\n reconciled: 'unrepaired',\n reason: `the ${scope}-scope registration file could not be read, so nothing was written over it`,\n };\n }\n // REFUSED, NOT REPLACED. Nothing of the user's is removed to make room.\n if (existing.state === 'wrong-command') {\n return {\n ...base,\n registered: false,\n reconciled: 'unrepaired',\n command: `${mcpRemoveCommand(project)} && ${command}`,\n reason: `an MCP server named ${MCP_SERVER_NAME} is already registered at ${scope} scope and launches something else. This command will not remove a registration it did not write; run the two commands above if that entry is stale`,\n };\n }\n const which = deps.which ?? ((bin: string) => onPath(bin, env));\n if (!which('claude')) {\n return {\n ...base,\n registered: false,\n reconciled: 'unavailable',\n reason: 'the `claude` binary is not on PATH',\n };\n }\n try {\n await (deps.registerMcp ?? runClaudeMcpAdd)(command, { scope, cwd });\n return { ...base, registered: true, reconciled: 'added' };\n } catch (err) {\n return {\n ...base,\n registered: false,\n reconciled: 'unavailable',\n reason: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\nexport type McpEntryState = 'ok' | 'absent' | 'wrong-command' | 'unreadable';\n\n/**\n * What an entry named `x402` actually launches. The name proves nothing: a\n * stale entry pointing at another binary would read as a working request tool.\n */\nexport function classifyMcpEntry(entry: unknown): McpEntryState {\n if (entry === null || typeof entry !== 'object' || Array.isArray(entry)) return 'absent';\n const { command, args } = entry as { command?: unknown; args?: unknown };\n if (typeof command !== 'string' || command.length === 0) return 'wrong-command';\n // The basename, so `/opt/homebrew/bin/tenjin` and a bare `tenjin` both pass.\n const binary = command.split(/[\\\\/]/).pop();\n const runsRouter =\n binary === 'tenjin' && Array.isArray(args) && args.length === 1 && args[0] === 'mcp';\n return runsRouter ? 'ok' : 'wrong-command';\n}\n\n/**\n * The file each scope writes: the project's own `.mcp.json`, or the user's\n * `~/.claude.json`. Neither can inherit from the other. Shared by `install`,\n * which reconciles against it, and `doctor`, which reports it.\n */\nexport async function readMcpEntry(\n scope: 'user' | 'project',\n cwd: string,\n home: string,\n): Promise<{ found: boolean; state: McpEntryState }> {\n const path = scope === 'project' ? join(cwd, '.mcp.json') : join(home, '.claude.json');\n // ONLY \"it is not there\" is an absence. A permission or filesystem error on a\n // file that DOES exist says nothing about what is registered in it, and\n // treating it as missing sent the refresh on to `claude mcp add` over a\n // registration it had never read: a failed add then looked like a machine\n // that simply lacks the tooling, and `tenjin update` exited 0 over whatever\n // was actually in there.\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code === 'ENOENT' || code === 'ENOTDIR') return { found: false, state: 'absent' };\n return { found: true, state: 'unreadable' };\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n // NOT an absence: the harness's own file is there and unreadable to this\n // build, so neither \"register it\" nor \"it is missing\" is a true statement.\n return { found: true, state: 'unreadable' };\n }\n const servers = (parsed as { mcpServers?: unknown } | null)?.mcpServers;\n if (servers === undefined) return { found: true, state: 'absent' };\n if (servers === null || typeof servers !== 'object' || Array.isArray(servers)) {\n return { found: true, state: 'unreadable' };\n }\n const entry = (servers as Record<string, unknown>)[MCP_SERVER_NAME];\n if (entry === undefined) return { found: true, state: 'absent' };\n return { found: true, state: classifyMcpEntry(entry) };\n}\n\n/** Project scope is decided by the working directory as well as the flag:\n * `claude` writes `.mcp.json` beside the project it was run in. */\nasync function runClaudeMcpAdd(\n _command: string,\n opts: { scope: 'user' | 'project'; cwd: string },\n): Promise<void> {\n await exec('claude', ['mcp', 'add', MCP_SERVER_NAME, '-s', opts.scope, '--', 'tenjin', 'mcp'], {\n timeout: 20_000,\n cwd: opts.cwd,\n });\n}\n\ninterface EffectiveLimits {\n maxAutoSpend: string;\n sessionBudget: string;\n}\n\nfunction effectiveLimits(policy: SpendPolicy): EffectiveLimits {\n return {\n maxAutoSpend: toMoney(policy.maxAutoSpendAtomic.toString()).usd,\n sessionBudget:\n policy.sessionBudgetAtomic === 0n\n ? 'no daily ceiling'\n : toMoney(policy.sessionBudgetAtomic.toString()).usd,\n };\n}\n\n/** Only the status-line state that needs the user: one this install would not\n * touch, with the command that adds the footer beside it. */\nexport function statusLineProblems(ctx: CommandContext, result: StatusLineResult): string[] {\n const warn = (text: string) => paint(ctx.io, 'yellow', `! ${text}`);\n if (result.warning !== undefined) {\n return [warn(`The live status line was not registered (${result.warning})`)];\n }\n if (result.state !== 'foreign') return [];\n return [\n warn('You already have a status line, so it was left exactly as it is.'),\n ' To show the live x402 footer beside it, run:',\n ' tenjin install --status-line compose',\n ...(result.compose === undefined\n ? []\n : [' or set this command yourself:', ` ${result.compose}`]),\n ];\n}\n\n/**\n * A few lines a first-time user can read at a glance: it worked, here is your\n * wallet, here is the one thing to do next. The file paths, entry counts and\n * data-handling detail stay in `--json` and the docs; the terminal only grows\n * a line when something needs the user.\n */\nfunction lines(\n ctx: CommandContext,\n s: {\n project: boolean;\n hooks: HooksResult;\n permissions: AllowRuleResult;\n statusLine: StatusLineResult;\n mcp: McpRegistration;\n wallet: WalletOutcome;\n policy: SpendPolicy;\n },\n): string[] {\n const ok = paint(ctx.io, 'green', '✓');\n const limits = effectiveLimits(s.policy);\n const daily =\n s.policy.sessionBudgetAtomic === 0n ? 'no daily limit' : `$${limits.sessionBudget} a day`;\n // The first line only says \"set up\" when it is: a settings file this run\n // would not write to means nothing was set up, and hooks without the MCP\n // server point at a `request` tool that is not there.\n const blocked = s.hooks.skipped !== undefined;\n const needsMcp = !blocked && !s.mcp.registered;\n const where = s.project ? ' in this project' : '';\n const fund = paint(ctx.io, 'bold', 'tenjin wallet fund');\n return [\n blocked\n ? paint(ctx.io, 'yellow', `! Tenjin could not finish setting up Claude Code${where}`)\n : needsMcp\n ? paint(ctx.io, 'yellow', '! Almost done: Claude Code needs one command')\n : `${ok} Tenjin is set up for Claude Code${where}`,\n ...walletLines(ctx, ok, s.wallet),\n ` Spends at most $${limits.maxAutoSpend} a lookup, ${daily}`,\n ...(s.statusLine.state === 'ours' || s.statusLine.state === 'composed'\n ? [' Live status line on: each lookup names its provider while it runs']\n : []),\n ...problems(ctx, s.hooks, s.permissions, s.statusLine, s.mcp),\n '',\n blocked\n ? 'Next: fix the file above, then run tenjin install again'\n : needsMcp\n ? s.wallet.status === 'created'\n ? `Next: run the command above and ${fund}, then restart Claude Code`\n : 'Next: run the command above, then restart Claude Code'\n : s.wallet.status === 'created'\n ? `Next: ${fund}, then restart Claude Code`\n : 'Next: restart Claude Code',\n ];\n}\n\n/** \"Up to date\" only when nothing below it needs the user. */\nfunction refreshLines(ctx: CommandContext, issues: string[]): string[] {\n if (issues.length === 0) return [`${paint(ctx.io, 'green', '✓')} Tenjin is up to date`];\n return [paint(ctx.io, 'yellow', '! Tenjin is updated, but needs one fix'), ...issues];\n}\n\nfunction walletLines(ctx: CommandContext, ok: string, w: WalletOutcome): string[] {\n if (w.status === 'created') return [`${ok} Wallet created: ${w.address}`];\n if (w.status === 'existing') return [`${ok} Wallet: ${w.address}`];\n if (w.reason === 'flag') return [' No wallet yet. Create one with: tenjin wallet create'];\n return [\n paint(ctx.io, 'yellow', `! No wallet was created. ${w.warning ?? ''}`.trimEnd()),\n ` ${w.fix ?? 'Create one with: tenjin wallet create'}`,\n ];\n}\n\n/** Only what needs the user, each with the command that fixes it. */\nfunction problems(\n ctx: CommandContext,\n hooks: HooksResult,\n permissions: AllowRuleResult,\n statusLine: StatusLineResult,\n mcp: McpRegistration,\n): string[] {\n const warn = (text: string) => paint(ctx.io, 'yellow', `! ${text}`);\n const out: string[] = [];\n // The hooks and the permission rule share one settings file, so a file this\n // run would not touch is reported once, not once per writer.\n if (hooks.skipped !== undefined) {\n out.push(\n warn(\n hooks.warning ??\n `${hooks.path ?? 'Your Claude Code settings file'} was left untouched (${hooks.skipped}).`,\n ),\n );\n } else {\n if (hooks.warning !== undefined) out.push(warn(hooks.warning));\n if (permissions.warning !== undefined) out.push(warn(permissions.warning));\n }\n if (!mcp.registered) {\n // The reason stays in --json: raw exec output is noise here, the fix is not.\n out.push(warn('Could not add the request tool to Claude Code. Run:'));\n out.push(` ${mcp.command}`);\n }\n out.push(...statusLineProblems(ctx, statusLine));\n return out;\n}\n\n/**\n * THREE ANSWERS, NOT TWO. A settings file that cannot be read or parsed is not\n * a file without our entries, and collapsing the two let `refreshEveryInstall`\n * read a momentarily broken project settings file as confirmed absence and\n * strike the project off `install.routerProjects` for good: repairing the file\n * afterwards did not bring it back, so every later `tenjin update` from HOME\n * silently skipped it.\n */\ntype EntriesProbe =\n { state: 'present' } | { state: 'absent' } | { state: 'unreadable'; reason: string };\n\nasync function probeOurEntries(path: string, dataDir: string): Promise<EntriesProbe> {\n const found = await inspectHooksFile(path);\n if ('refusal' in found) {\n // `unreadable` here is the inspection's own vocabulary for \"the file exists\n // and this build could not use it\"; a file that is simply not there comes\n // back as an empty, readable inspection rather than a refusal.\n return { state: 'unreadable', reason: found.refusal.reason };\n }\n const present = Object.values(found.hooks).some((list) =>\n list.some((entry) => ownsHookEntry(entry, dataDir)),\n );\n return present ? { state: 'present' } : { state: 'absent' };\n}\n\n/** Shared with `uninstall`: the prune this module's writer already performs. */\nexport { pruneHooks };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,YAAY,YAAY;AACjC,SAAS,iBAAiB;AA+B1B,IAAM,OAAO,UAAU,QAAQ;AAYxB,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB;AACxB,IAAM,aAAa;AAWnB,SAAS,SAAS,SAAkD;AACzE,SAAO,YAAY,OAAO,YAAY;AACxC;AAEO,SAAS,cAAc,SAA2B;AACvD,SAAO,kBAAkB,eAAe,OAAO,SAAS,OAAO,CAAC;AAClE;AAEO,SAAS,iBAAiB,SAA2B;AAC1D,SAAO,qBAAqB,eAAe,OA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ACpE,QAAI,KAAK,KAAK,IAAI,OAAO,EAAE;AAAA,EAC7B;AACA,MAAI,KAAK,GAAG,mBAAmB,KAAK,UAAU,CAAC;AAC/C,SAAO;AACT;AAaA,eAAe,gBAAgB,MAAc,SAAwC;AACnF,QAAM,QAAQ,MAAM,iBAAiB,IAAI;AACzC,MAAI,aAAa,OAAO;AAItB,WAAO,EAAE,OAAO,cAAc,QAAQ,MAAM,QAAQ,OAAO;AAAA,EAC7D;AACA,QAAM,UAAU,OAAO,OAAO,MAAM,KAAK,EAAE;AAAA,IAAK,CAAC,SAC/C,KAAK,KAAK,CAAC,UAAU,cAAc,OAAO,OAAO,CAAC;AAAA,EACpD;AACA,SAAO,UAAU,EAAE,OAAO,UAAU,IAAI,EAAE,OAAO,SAAS;AAC5D;","names":[]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/paths.ts
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
function dataDir(env = process.env) {
|
|
7
|
+
const override = env.TENJIN_DATA_DIR;
|
|
8
|
+
if (override !== void 0 && override.length > 0) return resolve(override);
|
|
9
|
+
return defaultDataDir();
|
|
10
|
+
}
|
|
11
|
+
function defaultDataDir(home = homedir()) {
|
|
12
|
+
return join(home, ".tenjin");
|
|
13
|
+
}
|
|
14
|
+
function configPath(dir = dataDir()) {
|
|
15
|
+
return join(dir, "config.json");
|
|
16
|
+
}
|
|
17
|
+
function walletPath(dir = dataDir()) {
|
|
18
|
+
return join(dir, "wallet.json");
|
|
19
|
+
}
|
|
20
|
+
function sessionPath(dir = dataDir()) {
|
|
21
|
+
return join(dir, "session.json");
|
|
22
|
+
}
|
|
23
|
+
function spendLedgerPath(dir = dataDir()) {
|
|
24
|
+
return join(dir, "spend.json");
|
|
25
|
+
}
|
|
26
|
+
function updateCheckPath(dir = dataDir()) {
|
|
27
|
+
return join(dir, "update-check.json");
|
|
28
|
+
}
|
|
29
|
+
function hooksDir(dir = dataDir()) {
|
|
30
|
+
return join(dir, "hooks");
|
|
31
|
+
}
|
|
32
|
+
function hookHealthPath(dir = dataDir()) {
|
|
33
|
+
return join(dir, "hook-health.json");
|
|
34
|
+
}
|
|
35
|
+
function passphraseBlobPath(dir = dataDir()) {
|
|
36
|
+
return join(dir, "passphrase.dpapi");
|
|
37
|
+
}
|
|
38
|
+
function passphraseBlobPathFor(account, dir = dataDir()) {
|
|
39
|
+
return join(dir, `passphrase.${account}.dpapi`);
|
|
40
|
+
}
|
|
41
|
+
function archivedWalletPath(account, dir = dataDir()) {
|
|
42
|
+
return join(dir, `wallet.${account}.json.bak`);
|
|
43
|
+
}
|
|
44
|
+
function loopDbPath(dir = dataDir()) {
|
|
45
|
+
return join(dir, "loop.db");
|
|
46
|
+
}
|
|
47
|
+
function daemonTokenPath(dir = dataDir()) {
|
|
48
|
+
return join(dir, "daemon.token");
|
|
49
|
+
}
|
|
50
|
+
function daemonPidPath(dir = dataDir()) {
|
|
51
|
+
return join(dir, "daemon.pid");
|
|
52
|
+
}
|
|
53
|
+
function daemonLogPath(dir = dataDir()) {
|
|
54
|
+
return join(dir, "daemon.log");
|
|
55
|
+
}
|
|
56
|
+
function daemonSpawnPath(dir = dataDir()) {
|
|
57
|
+
return join(dir, "daemon.spawn");
|
|
58
|
+
}
|
|
59
|
+
function daemonBundlePath(dir = dataDir()) {
|
|
60
|
+
return join(hooksDir(dir), "tenjin-daemon.mjs");
|
|
61
|
+
}
|
|
62
|
+
function shimBundlePath(dir = dataDir()) {
|
|
63
|
+
return join(hooksDir(dir), "tenjin-shim.mjs");
|
|
64
|
+
}
|
|
65
|
+
var VITEST_REPORTER_FILE = "tenjin-vitest-reporter.mjs";
|
|
66
|
+
function vitestReporterPath(dir = dataDir()) {
|
|
67
|
+
return join(hooksDir(dir), VITEST_REPORTER_FILE);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
dataDir,
|
|
72
|
+
defaultDataDir,
|
|
73
|
+
configPath,
|
|
74
|
+
walletPath,
|
|
75
|
+
sessionPath,
|
|
76
|
+
spendLedgerPath,
|
|
77
|
+
updateCheckPath,
|
|
78
|
+
hooksDir,
|
|
79
|
+
hookHealthPath,
|
|
80
|
+
passphraseBlobPath,
|
|
81
|
+
passphraseBlobPathFor,
|
|
82
|
+
archivedWalletPath,
|
|
83
|
+
loopDbPath,
|
|
84
|
+
daemonTokenPath,
|
|
85
|
+
daemonPidPath,
|
|
86
|
+
daemonLogPath,
|
|
87
|
+
daemonSpawnPath,
|
|
88
|
+
daemonBundlePath,
|
|
89
|
+
shimBundlePath,
|
|
90
|
+
VITEST_REPORTER_FILE,
|
|
91
|
+
vitestReporterPath
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=chunk-2BKS2FVE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/paths.ts"],"sourcesContent":["import { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\n/**\n * Where the CLI keeps its config and wallet. Defaults to ~/.tenjin, overridable\n * via TENJIN_DATA_DIR (CI, ephemeral agents, and every test — which point it at\n * a temp dir so the real home is never touched).\n */\nexport function dataDir(env: NodeJS.ProcessEnv = process.env): string {\n const override = env.TENJIN_DATA_DIR;\n // Absolute, always: the daemon compares this string against its own\n // `data_dir` and is spawned with it as `cwd`, so a relative override must\n // mean the same directory from every process.\n if (override !== undefined && override.length > 0) return resolve(override);\n return defaultDataDir();\n}\n\n/**\n * The data dir a run with no override resolves. Split out of {@link dataDir} so\n * a caller holding a home directory can ask whether some other profile IS the\n * default one, without a second copy of the `.tenjin` literal.\n */\nexport function defaultDataDir(home: string = homedir()): string {\n return join(home, '.tenjin');\n}\n\nexport function configPath(dir: string = dataDir()): string {\n return join(dir, 'config.json');\n}\n\nexport function walletPath(dir: string = dataDir()): string {\n return join(dir, 'wallet.json');\n}\n\n/**\n * Where the delegated P-256 session key + its wallet-signed SIWX delegation are\n * cached (B3, D35). A short-lived (≤24h) hot key: lower stakes than wallet.json,\n * but still written 0600 and address-bound so a wallet change invalidates it.\n */\nexport function sessionPath(dir: string = dataDir()): string {\n return join(dir, 'session.json');\n}\n\n/**\n * Where the client-side rolling spend ledger lives (lib/wallet/spend.ts).\n *\n * Its own file, NOT session.json: the two schemas are incompatible and both\n * readers treat a parse failure as \"absent\", so a shared path meant each writer\n * silently destroyed the other's file — a session key wiped the spend window, and\n * the next spend wiped the session key.\n */\nexport function spendLedgerPath(dir: string = dataDir()): string {\n return join(dir, 'spend.json');\n}\n\n/**\n * Where the once-a-day \"a newer tenjin-cli exists\" check caches the registry\n * answer. A pure cache: nothing here is authoritative, so an unreadable file is\n * simply re-fetched.\n */\nexport function updateCheckPath(dir: string = dataDir()): string {\n return join(dir, 'update-check.json');\n}\n\n/**\n * Where `install` writes the standalone harness hook scripts. Under the data dir\n * rather than the harness's own config directory: the scripts are ours, a harness\n * only ever holds the path to them, and one location serves every harness.\n */\nexport function hooksDir(dir: string = dataDir()): string {\n return join(dir, 'hooks');\n}\n\n/**\n * How the marketplace has been answering the dispatch hook lately, so a run of\n * failures stops the arm instead of paying the fetch budget per subagent through\n * an outage. Hook-written, unlocked, and cheap to lose, since a missing file\n * reads as \"healthy\". Its own file because two hooks writing one unlocked file\n * would erase each other.\n */\nexport function hookHealthPath(dir: string = dataDir()): string {\n return join(dir, 'hook-health.json');\n}\n\n/**\n * Where the LEGACY (pre-per-wallet) Windows DPAPI passphrase blob lives. The\n * file holds a DPAPI CurrentUser ciphertext, not the passphrase in plaintext.\n * New writes go to the per-wallet path below; this one is only read as a\n * migration fallback and removed after a verified per-wallet copy exists.\n */\nexport function passphraseBlobPath(dir: string = dataDir()): string {\n return join(dir, 'passphrase.dpapi');\n}\n\n/**\n * The per-wallet Windows DPAPI passphrase blob: one file per wallet address\n * (lowercase), so creating a new wallet never clobbers an old wallet's blob.\n * Only ever written on win32; other platforms use their own OS store.\n */\nexport function passphraseBlobPathFor(account: string, dir: string = dataDir()): string {\n return join(dir, `passphrase.${account}.dpapi`);\n}\n\n/**\n * Where `wallet create --replace` parks the outgoing wallet's keystore, keyed by\n * its lowercase address so successive replaces can never collide. Together with\n * the wallet's per-address passphrase entry in the OS store, this file keeps the\n * replaced wallet's funds recoverable; it is never read by the active-wallet\n * path.\n */\nexport function archivedWalletPath(account: string, dir: string = dataDir()): string {\n return join(dir, `wallet.${account}.json.bak`);\n}\n\n/**\n * The loop daemon's own state, all under the data dir (tenjin-notes\n * loop-redesign/02-redesign.md §4, §10).\n */\nexport function loopDbPath(dir: string = dataDir()): string {\n return join(dir, 'loop.db');\n}\n\n/** 32 random bytes, hex, 0600. Minted by `tenjin daemon start`, rotated only by\n * reinstall, NEVER deleted by the daemon: every transport reads it, and an idle\n * exit that removed it would strand them all. */\nexport function daemonTokenPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.token');\n}\n\n/** `{ pid, port, started_at, data_dir }`, advisory: written after the bind,\n * removed at exit only by the process whose pid it names. Liveness is\n * `GET /health`, never this file alone. */\nexport function daemonPidPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.pid');\n}\n\n/** Where a detached daemon's stdout and stderr go, and where the shim writes its\n * one `daemon-down` line when it cannot reach one. */\nexport function daemonLogPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.log');\n}\n\n/** An empty file whose mtime is the last spawn attempt; the shim's backoff. */\nexport function daemonSpawnPath(dir: string = dataDir()): string {\n return join(dir, 'daemon.spawn');\n}\n\n/** The single-file daemon bundle `tenjin daemon start` copies from `dist`. */\nexport function daemonBundlePath(dir: string = dataDir()): string {\n return join(hooksDir(dir), 'tenjin-daemon.mjs');\n}\n\n/** The ensure-and-forward shim the two `command` hook entries run. */\nexport function shimBundlePath(dir: string = dataDir()): string {\n return join(hooksDir(dir), 'tenjin-shim.mjs');\n}\n\n/** Tenjin's own vitest reporter, copied beside the bundles. NOT A HOOK ENTRY\n * and never spawned: a repo's own `vitest.config.ts` imports it by this\n * absolute path, which is why `doctor` can hint at it verbatim. */\nexport const VITEST_REPORTER_FILE = 'tenjin-vitest-reporter.mjs';\n\nexport function vitestReporterPath(dir: string = dataDir()): string {\n return join(hooksDir(dir), VITEST_REPORTER_FILE);\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;AACxB,SAAS,MAAM,eAAe;AAOvB,SAAS,QAAQ,MAAyB,QAAQ,KAAa;AACpE,QAAM,WAAW,IAAI;AAIrB,MAAI,aAAa,UAAa,SAAS,SAAS,EAAG,QAAO,QAAQ,QAAQ;AAC1E,SAAO,eAAe;AACxB;AAOO,SAAS,eAAe,OAAe,QAAQ,GAAW;AAC/D,SAAO,KAAK,MAAM,SAAS;AAC7B;AAEO,SAAS,WAAW,MAAc,QAAQ,GAAW;AAC1D,SAAO,KAAK,KAAK,aAAa;AAChC;AAEO,SAAS,WAAW,MAAc,QAAQ,GAAW;AAC1D,SAAO,KAAK,KAAK,aAAa;AAChC;AAOO,SAAS,YAAY,MAAc,QAAQ,GAAW;AAC3D,SAAO,KAAK,KAAK,cAAc;AACjC;AAUO,SAAS,gBAAgB,MAAc,QAAQ,GAAW;AAC/D,SAAO,KAAK,KAAK,YAAY;AAC/B;AAOO,SAAS,gBAAgB,MAAc,QAAQ,GAAW;AAC/D,SAAO,KAAK,KAAK,mBAAmB;AACtC;AAOO,SAAS,SAAS,MAAc,QAAQ,GAAW;AACxD,SAAO,KAAK,KAAK,OAAO;AAC1B;AASO,SAAS,eAAe,MAAc,QAAQ,GAAW;AAC9D,SAAO,KAAK,KAAK,kBAAkB;AACrC;AAQO,SAAS,mBAAmB,MAAc,QAAQ,GAAW;AAClE,SAAO,KAAK,KAAK,kBAAkB;AACrC;AAOO,SAAS,sBAAsB,SAAiB,MAAc,QAAQ,GAAW;AACtF,SAAO,KAAK,KAAK,cAAc,OAAO,QAAQ;AAChD;AASO,SAAS,mBAAmB,SAAiB,MAAc,QAAQ,GAAW;AACnF,SAAO,KAAK,KAAK,UAAU,OAAO,WAAW;AAC/C;AAMO,SAAS,WAAW,MAAc,QAAQ,GAAW;AAC1D,SAAO,KAAK,KAAK,SAAS;AAC5B;AAKO,SAAS,gBAAgB,MAAc,QAAQ,GAAW;AAC/D,SAAO,KAAK,KAAK,cAAc;AACjC;AAKO,SAAS,cAAc,MAAc,QAAQ,GAAW;AAC7D,SAAO,KAAK,KAAK,YAAY;AAC/B;AAIO,SAAS,cAAc,MAAc,QAAQ,GAAW;AAC7D,SAAO,KAAK,KAAK,YAAY;AAC/B;AAGO,SAAS,gBAAgB,MAAc,QAAQ,GAAW;AAC/D,SAAO,KAAK,KAAK,cAAc;AACjC;AAGO,SAAS,iBAAiB,MAAc,QAAQ,GAAW;AAChE,SAAO,KAAK,SAAS,GAAG,GAAG,mBAAmB;AAChD;AAGO,SAAS,eAAe,MAAc,QAAQ,GAAW;AAC9D,SAAO,KAAK,SAAS,GAAG,GAAG,iBAAiB;AAC9C;AAKO,IAAM,uBAAuB;AAE7B,SAAS,mBAAmB,MAAc,QAAQ,GAAW;AAClE,SAAO,KAAK,SAAS,GAAG,GAAG,oBAAoB;AACjD;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/clack.ts
|
|
4
|
+
var SHOW_CURSOR = "\x1B[?25h";
|
|
5
|
+
function withInputEnd(streams, onEnd, run) {
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
let settleEnd;
|
|
8
|
+
const ended = new Promise((resolve) => {
|
|
9
|
+
settleEnd = () => {
|
|
10
|
+
streams.output.write(SHOW_CURSOR);
|
|
11
|
+
resolve(onEnd);
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
const end = () => {
|
|
15
|
+
controller.abort();
|
|
16
|
+
settleEnd?.();
|
|
17
|
+
};
|
|
18
|
+
const onKeypress = (_text, key) => {
|
|
19
|
+
if (key?.ctrl === true && key.name === "d") end();
|
|
20
|
+
};
|
|
21
|
+
streams.input.on("keypress", onKeypress);
|
|
22
|
+
if (streams.input.readableEnded) {
|
|
23
|
+
queueMicrotask(end);
|
|
24
|
+
} else {
|
|
25
|
+
streams.input.once("end", end);
|
|
26
|
+
streams.input.once("close", end);
|
|
27
|
+
}
|
|
28
|
+
return Promise.race([run(controller.signal), ended]).finally(() => {
|
|
29
|
+
streams.input.off("keypress", onKeypress);
|
|
30
|
+
streams.input.off("end", end);
|
|
31
|
+
streams.input.off("close", end);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function resolveStreams(streams) {
|
|
35
|
+
return { input: streams.input ?? process.stdin, output: streams.output ?? process.stderr };
|
|
36
|
+
}
|
|
37
|
+
async function confirmChoice(message, initialValue = true, streams = {}) {
|
|
38
|
+
const { confirm, isCancel } = await import("./dist-3LOO6M4U.js");
|
|
39
|
+
const resolved = resolveStreams(streams);
|
|
40
|
+
return withInputEnd(resolved, false, async (signal) => {
|
|
41
|
+
const answer = await confirm({
|
|
42
|
+
message,
|
|
43
|
+
initialValue,
|
|
44
|
+
input: resolved.input,
|
|
45
|
+
output: resolved.output,
|
|
46
|
+
signal
|
|
47
|
+
});
|
|
48
|
+
return isCancel(answer) ? false : answer;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
confirmChoice
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=chunk-2QYORQBF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/clack.ts"],"sourcesContent":["import type { Readable, Writable } from 'node:stream';\n\n/**\n * The pretty-prompt renderer behind the install walkthrough's seams.\n *\n * @clack/prompts is a devDependency BUNDLED by tsup (published `dependencies`\n * stays `{}`), and every entry point here is behind a dynamic `import()` so it\n * lands in its own split chunk: a `search` or `doctor` run never parses it.\n *\n * Nothing in this module is reachable from a machine run. Commands call it only\n * on the real interactive path (a TTY on both stdout and stdin, no `--json`),\n * and always through an injectable seam, so unit tests supply answers directly\n * and never touch clack or a terminal.\n *\n * Prompts render on STDERR, like every other prompt in this CLI: stdout carries\n * the human walkthrough (or a single JSON envelope) and must not be interleaved\n * with prompt chrome.\n */\n\n/** Cancel (ctrl-C, escape) is not an answer. Callers map `null` to their own default. */\nexport type Cancelled = null;\n\nexport interface SelectChoice<T extends string> {\n value: T;\n label: string;\n /** The one line of consequence shown beside the label. */\n hint?: string;\n}\n\n/** Streams a prompt reads and draws on. Injected by tests; defaults to the real ones. */\ninterface PromptStreams {\n input?: Readable;\n output?: Writable;\n}\n\n/** DECTCUM show-cursor. Written on the EOF path in case the prompt did not get to. */\nconst SHOW_CURSOR = '\\x1b[?25h';\n\n/**\n * Settle a prompt when its input goes away instead of hanging forever.\n *\n * Ctrl-D at a clack prompt leaves its promise unsettled: no resolve, no reject,\n * no cancel symbol. The process then dies on an unsettled top-level await with\n * exit 13, nothing printed, and the cursor still hidden. The readline seam this\n * replaced handled it on purpose (\"ctrl-D mid-prompt reads as the default\"), and\n * that behavior has to survive the renderer swap.\n *\n * \"Input goes away\" is two different events, and only covering one of them was\n * the original bug:\n *\n * - The STREAM ends. A pipe closes, a harness detaches, stdin was already at\n * EOF. Caught via `end` / `close`.\n * - The ctrl-D BYTE (0x04) arrives with the stream still open. This is what a\n * real terminal sends, and it is the common case. A prompt puts stdin in raw\n * mode, where 0x04 is ordinary data rather than EOF, so no stream event ever\n * fires; clack has no binding for it and simply keeps waiting. Caught via the\n * `keypress` decoder readline installs, which is a read-only view of the same\n * bytes: listening there takes nothing away from the prompt, where a `data`\n * listener would risk flipping the stream to flowing before clack reads it.\n *\n * Two mechanisms settle it, because one of them is advisory. The AbortSignal is\n * clack's own teardown: it flips the prompt to `cancel`, which restores the\n * cursor and raw mode and resolves with the cancel symbol. The race is the\n * guarantee, for a prompt that is not yet listening or never settles anyway; on\n * that path we restore the cursor ourselves, since no prompt did.\n */\nfunction withInputEnd<T>(\n streams: Required<PromptStreams>,\n onEnd: T,\n run: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n const controller = new AbortController();\n let settleEnd: (() => void) | undefined;\n const ended = new Promise<T>((resolve) => {\n settleEnd = () => {\n streams.output.write(SHOW_CURSOR);\n resolve(onEnd);\n };\n });\n\n const end = (): void => {\n controller.abort();\n settleEnd?.();\n };\n const onKeypress = (_text: string | undefined, key?: { name?: string; ctrl?: boolean }): void => {\n if (key?.ctrl === true && key.name === 'd') end();\n };\n\n streams.input.on('keypress', onKeypress);\n // A stream that finished before we got here never emits `end` again, so ask.\n if (streams.input.readableEnded) {\n queueMicrotask(end);\n } else {\n streams.input.once('end', end);\n streams.input.once('close', end);\n }\n\n return Promise.race([run(controller.signal), ended]).finally(() => {\n streams.input.off('keypress', onKeypress);\n streams.input.off('end', end);\n streams.input.off('close', end);\n });\n}\n\nfunction resolveStreams(streams: PromptStreams): Required<PromptStreams> {\n return { input: streams.input ?? process.stdin, output: streams.output ?? process.stderr };\n}\n\n/**\n * A single-choice list. Returns the chosen value, or `null` when the operator\n * cancelled or the input ended, both of which callers treat as \"leave everything\n * as it was\".\n */\nexport async function selectOne<T extends string>(opts: {\n message: string;\n choices: readonly SelectChoice<T>[];\n initialValue: T;\n streams?: PromptStreams;\n}): Promise<T | Cancelled> {\n const { select, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<T | Cancelled>(streams, null, async (signal) => {\n // Instantiated at `string`, not at `T`: clack's `Option<Value>` is a conditional\n // type that a generic `T extends string` cannot resolve. The values come from\n // this call's own choices, so narrowing the answer back is sound.\n const answer = await select<string>({\n message: opts.message,\n options: opts.choices.map((c) => ({\n value: c.value as string,\n label: c.label,\n ...(c.hint !== undefined ? { hint: c.hint } : {}),\n })),\n initialValue: opts.initialValue,\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : (answer as T);\n });\n}\n\n/** A multi-choice list. Returns the selected values, or `null` when cancelled. */\nexport async function selectMany<T extends string>(opts: {\n message: string;\n choices: readonly SelectChoice<T>[];\n initialValues: readonly T[];\n required?: boolean;\n streams?: PromptStreams;\n}): Promise<T[] | Cancelled> {\n const { multiselect, isCancel } = await import('@clack/prompts');\n const streams = resolveStreams(opts.streams ?? {});\n return withInputEnd<T[] | Cancelled>(streams, null, async (signal) => {\n const answer = await multiselect<string>({\n message: opts.message,\n options: opts.choices.map((c) => ({\n value: c.value as string,\n label: c.label,\n ...(c.hint !== undefined ? { hint: c.hint } : {}),\n })),\n initialValues: [...opts.initialValues] as string[],\n required: opts.required ?? true,\n input: streams.input,\n output: streams.output,\n signal,\n });\n return isCancel(answer) ? null : (answer as T[]);\n });\n}\n\n/** A yes/no confirm. Cancelling, or an input that ends, reads as no. */\nexport async function confirmChoice(\n message: string,\n initialValue = true,\n streams: PromptStreams = {},\n): Promise<boolean> {\n const { confirm, isCancel } = await import('@clack/prompts');\n const resolved = resolveStreams(streams);\n return withInputEnd<boolean>(resolved, false, async (signal) => {\n const answer = await confirm({\n message,\n initialValue,\n input: resolved.input,\n output: resolved.output,\n signal,\n });\n return isCancel(answer) ? false : answer;\n });\n}\n\n/** Open the walkthrough's prompt sequence with a title bar. */\nexport async function intro(message: string): Promise<void> {\n const clack = await import('@clack/prompts');\n clack.intro(message, { output: process.stderr });\n}\n\n/** Close it, so the last prompt is not left dangling above plain stdout lines. */\nexport async function outro(message: string): Promise<void> {\n const clack = await import('@clack/prompts');\n clack.outro(message, { output: process.stderr });\n}\n"],"mappings":";;;AAoCA,IAAM,cAAc;AA8BpB,SAAS,aACP,SACA,OACA,KACY;AACZ,QAAM,aAAa,IAAI,gBAAgB;AACvC,MAAI;AACJ,QAAM,QAAQ,IAAI,QAAW,CAAC,YAAY;AACxC,gBAAY,MAAM;AAChB,cAAQ,OAAO,MAAM,WAAW;AAChC,cAAQ,KAAK;AAAA,IACf;AAAA,EACF,CAAC;AAED,QA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