tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.30
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 +149 -264
- package/dist/{_esm-FEASBWRP.js → _esm-CE7KNONL.js} +9 -10
- package/dist/alive-3J3CHOQP.js +21 -0
- package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-2SNUOHAT.js +75 -0
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/chunk-3O2BQIF6.js +2227 -0
- package/dist/chunk-3O2BQIF6.js.map +1 -0
- package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5LJCEMFD.js +12700 -0
- package/dist/chunk-5LJCEMFD.js.map +1 -0
- package/dist/chunk-6W5GYG3W.js +128 -0
- package/dist/chunk-6W5GYG3W.js.map +1 -0
- package/dist/chunk-7EKYXMUO.js +7536 -0
- package/dist/chunk-7EKYXMUO.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/chunk-A36LQPHV.js +29 -0
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/chunk-AEG2PXBP.js +192 -0
- package/dist/chunk-AEG2PXBP.js.map +1 -0
- package/dist/chunk-AKWGE6JQ.js +49 -0
- package/dist/chunk-AKWGE6JQ.js.map +1 -0
- package/dist/chunk-AWFUPKTM.js +238 -0
- package/dist/chunk-AWFUPKTM.js.map +1 -0
- package/dist/{chunk-UGX7YPX2.js → chunk-AWQPGIR6.js} +7 -9
- package/dist/{chunk-UGX7YPX2.js.map → chunk-AWQPGIR6.js.map} +1 -1
- package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
- package/dist/chunk-EBVIKMCH.js +108 -0
- package/dist/chunk-EBVIKMCH.js.map +1 -0
- package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
- package/dist/{chunk-S3IGX57D.js → chunk-EL56RW2J.js} +166 -7237
- package/dist/chunk-EL56RW2J.js.map +1 -0
- package/dist/chunk-HE2MS4QO.js +256 -0
- package/dist/chunk-HE2MS4QO.js.map +1 -0
- package/dist/{chunk-CYOF7ROH.js → chunk-HPWO4O6S.js} +3 -3
- package/dist/chunk-IOODYAXL.js +324 -0
- package/dist/chunk-IOODYAXL.js.map +1 -0
- package/dist/chunk-JMM6YE7J.js +2174 -0
- package/dist/chunk-JMM6YE7J.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KHE6L6TD.js +416 -0
- package/dist/chunk-KHE6L6TD.js.map +1 -0
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/chunk-KYFZTGMC.js +237 -0
- package/dist/chunk-KYFZTGMC.js.map +1 -0
- package/dist/chunk-LFZJM56J.js +159 -0
- package/dist/chunk-LFZJM56J.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-NCE5NSN6.js → chunk-N35E6CM2.js} +140 -10
- package/dist/chunk-N35E6CM2.js.map +1 -0
- package/dist/chunk-NZIP4PA2.js +114 -0
- package/dist/chunk-NZIP4PA2.js.map +1 -0
- package/dist/chunk-O2FRQ2L2.js +168 -0
- package/dist/chunk-O2FRQ2L2.js.map +1 -0
- package/dist/chunk-OK2TDZQU.js +404 -0
- package/dist/chunk-OK2TDZQU.js.map +1 -0
- package/dist/chunk-ORWL5BSN.js +269 -0
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/{chunk-Z6MFJV5Z.js → chunk-OSYTBCUC.js} +850 -499
- package/dist/chunk-OSYTBCUC.js.map +1 -0
- package/dist/chunk-P7LABKCW.js +90 -0
- package/dist/chunk-P7LABKCW.js.map +1 -0
- package/dist/chunk-PAYV4XUA.js +151 -0
- package/dist/chunk-PAYV4XUA.js.map +1 -0
- package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QUVVWYJW.js +112 -0
- package/dist/chunk-QUVVWYJW.js.map +1 -0
- package/dist/chunk-RAULEAZ6.js +228 -0
- package/dist/chunk-RAULEAZ6.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-SPAVAYSW.js +125 -0
- package/dist/chunk-SPAVAYSW.js.map +1 -0
- package/dist/chunk-TTBKWWTV.js +1605 -0
- package/dist/chunk-TTBKWWTV.js.map +1 -0
- package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-U6YQ6FRI.js +378 -0
- package/dist/chunk-U6YQ6FRI.js.map +1 -0
- package/dist/chunk-VFMQTSXG.js +29 -0
- package/dist/chunk-VFMQTSXG.js.map +1 -0
- package/dist/chunk-VUFAK2LW.js +115 -0
- package/dist/chunk-VUFAK2LW.js.map +1 -0
- package/dist/chunk-VZGAONSJ.js +194 -0
- package/dist/chunk-VZGAONSJ.js.map +1 -0
- package/dist/{chunk-OYMYCW7J.js → chunk-WO5BJNIB.js} +682 -53
- package/dist/chunk-WO5BJNIB.js.map +1 -0
- package/dist/chunk-WVUSXNIE.js +39 -0
- package/dist/chunk-WVUSXNIE.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/{chunk-XJIW7USF.js → chunk-YFQOA5AU.js} +118 -9
- package/dist/chunk-YFQOA5AU.js.map +1 -0
- package/dist/chunk-YHKXNYTB.js +105 -0
- package/dist/chunk-YHKXNYTB.js.map +1 -0
- package/dist/{cli-SBXI5AMS.js → cli-O5SN7ZJ4.js} +382 -214
- package/dist/cli-O5SN7ZJ4.js.map +1 -0
- package/dist/config-OJQI27LT.js +45 -0
- package/dist/dist-3LOO6M4U.js +2842 -0
- package/dist/dist-3LOO6M4U.js.map +1 -0
- package/dist/doctor-IQQJHGGM.js +590 -0
- package/dist/doctor-IQQJHGGM.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/fund-WEV6DMTD.js +365 -0
- package/dist/fund-WEV6DMTD.js.map +1 -0
- package/dist/hook-command-D2P3ILRV.js +32 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +14 -0
- package/dist/hosts/claude/tenjin/.mcp.json +12 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +221 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/install-TUCRF32I.js +60 -0
- package/dist/install-identity-WHPNMNMQ.js +26 -0
- package/dist/install-wallet-MA27FTQ5.js +113 -0
- package/dist/install-wallet-MA27FTQ5.js.map +1 -0
- package/dist/mcp-QML7ZMPH.js +13427 -0
- package/dist/mcp-QML7ZMPH.js.map +1 -0
- package/dist/package-LGKYOEPV.js +37 -0
- package/dist/package-LGKYOEPV.js.map +1 -0
- package/dist/paths-POPTXJO6.js +61 -0
- package/dist/paths-POPTXJO6.js.map +1 -0
- package/dist/pay-2C2UBBXJ.js +51 -0
- package/dist/pay-2C2UBBXJ.js.map +1 -0
- package/dist/payments-C44QUFXU.js +106 -0
- package/dist/payments-C44QUFXU.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-KVJX4XIR.js +222 -0
- package/dist/send-KVJX4XIR.js.map +1 -0
- package/dist/status-S7C3WMSH.js +115 -0
- package/dist/status-S7C3WMSH.js.map +1 -0
- package/dist/status-line-YR2T5HC4.js +86 -0
- package/dist/status-line-YR2T5HC4.js.map +1 -0
- package/dist/uninstall-HY6LKIIT.js +149 -0
- package/dist/uninstall-HY6LKIIT.js.map +1 -0
- package/dist/update-OJV22LR3.js +36 -0
- package/dist/update-OJV22LR3.js.map +1 -0
- package/dist/usdc-JK4RRFFQ.js +39 -0
- package/dist/usdc-JK4RRFFQ.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
- package/dist/viemAdapter-By13KInL-X2VY6CY3.js.map +1 -0
- package/dist/wallet-PD2IMZDU.js +39 -0
- package/dist/wallet-PD2IMZDU.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +180 -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-MUBUQVC3.js +0 -67
- package/dist/chunk-MUBUQVC3.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-CE7KNONL.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → alive-3J3CHOQP.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-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-HPWO4O6S.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 → config-OJQI27LT.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → hook-command-D2P3ILRV.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → install-TUCRF32I.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → install-identity-WHPNMNMQ.js.map} +0 -0
|
@@ -0,0 +1,2227 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
modeGatedPointer
|
|
4
|
+
} from "./chunk-A36LQPHV.js";
|
|
5
|
+
import {
|
|
6
|
+
AGENT_ID_RE
|
|
7
|
+
} from "./chunk-XKESD27X.js";
|
|
8
|
+
import {
|
|
9
|
+
HOOK_TOOL
|
|
10
|
+
} from "./chunk-AKWGE6JQ.js";
|
|
11
|
+
import {
|
|
12
|
+
LEGACY_MCP_SERVER_NAME
|
|
13
|
+
} from "./chunk-WVUSXNIE.js";
|
|
14
|
+
import {
|
|
15
|
+
confirmChoice
|
|
16
|
+
} from "./chunk-P7LABKCW.js";
|
|
17
|
+
import {
|
|
18
|
+
CHANNEL_DEPOSIT_ATOMIC,
|
|
19
|
+
ROUTING_FEE_ATOMIC,
|
|
20
|
+
usd
|
|
21
|
+
} from "./chunk-PAYV4XUA.js";
|
|
22
|
+
import {
|
|
23
|
+
LockTimeoutError,
|
|
24
|
+
withFileLock
|
|
25
|
+
} from "./chunk-MEFB5KHA.js";
|
|
26
|
+
import {
|
|
27
|
+
style
|
|
28
|
+
} from "./chunk-KYFZTGMC.js";
|
|
29
|
+
import {
|
|
30
|
+
projectRouterPath,
|
|
31
|
+
readProjectRouterFile,
|
|
32
|
+
routerSettings
|
|
33
|
+
} from "./chunk-SPAVAYSW.js";
|
|
34
|
+
import {
|
|
35
|
+
hasCode
|
|
36
|
+
} from "./chunk-2I4QTOLB.js";
|
|
37
|
+
import {
|
|
38
|
+
isTeamShelfOrigin,
|
|
39
|
+
loadProjectConfig
|
|
40
|
+
} from "./chunk-AWFUPKTM.js";
|
|
41
|
+
import {
|
|
42
|
+
CONFIG_KEYS,
|
|
43
|
+
CliError,
|
|
44
|
+
DEFAULT_MAX_AUTO_SPEND,
|
|
45
|
+
DEFAULT_SESSION_BUDGET,
|
|
46
|
+
EXPERIMENTAL_CONFIG_KEYS,
|
|
47
|
+
HARNESSES,
|
|
48
|
+
HOOKS_CONFIG_KEYS,
|
|
49
|
+
LOOP_CONFIG_KEYS,
|
|
50
|
+
MAX_AUTO_SPEND_FLOOR_ATOMIC,
|
|
51
|
+
MAX_AUTO_SPEND_FLOOR_WHY,
|
|
52
|
+
PRODUCTION_ORIGIN,
|
|
53
|
+
PUBLISH_CONFIG_KEYS,
|
|
54
|
+
PublishModeSchema,
|
|
55
|
+
RETIRED_PAYMENT_GUIDANCE,
|
|
56
|
+
ROUTER_CONFIG_KEYS,
|
|
57
|
+
ROUTER_CONTEXTS,
|
|
58
|
+
RawConfigSchema,
|
|
59
|
+
SEND_MAX_UNSET,
|
|
60
|
+
TEAM_CONFIG_KEYS,
|
|
61
|
+
UPDATE_CONFIG_KEYS,
|
|
62
|
+
isSameDeployment,
|
|
63
|
+
loadRawConfig,
|
|
64
|
+
parseAckServerWarnings,
|
|
65
|
+
parseLoopValue,
|
|
66
|
+
parsePublicFallbackFlag,
|
|
67
|
+
parseUpdateModeFlag,
|
|
68
|
+
parseUsdToAtomic,
|
|
69
|
+
resolveSettings,
|
|
70
|
+
retiredPaymentKeys,
|
|
71
|
+
toMoney
|
|
72
|
+
} from "./chunk-WO5BJNIB.js";
|
|
73
|
+
import {
|
|
74
|
+
writeFileAtomic
|
|
75
|
+
} from "./chunk-O2FRQ2L2.js";
|
|
76
|
+
import {
|
|
77
|
+
configPath,
|
|
78
|
+
hooksDir
|
|
79
|
+
} from "./chunk-SJLTEINJ.js";
|
|
80
|
+
|
|
81
|
+
// src/commands/config.ts
|
|
82
|
+
import { mkdir as mkdir2 } from "node:fs/promises";
|
|
83
|
+
import { homedir } from "node:os";
|
|
84
|
+
import { dirname as dirname3 } from "node:path";
|
|
85
|
+
|
|
86
|
+
// src/lib/harness-permissions.ts
|
|
87
|
+
import { chmod, lstat, mkdir, readFile, realpath, stat as stat2 } from "node:fs/promises";
|
|
88
|
+
import { dirname, join as join4 } from "node:path";
|
|
89
|
+
|
|
90
|
+
// src/lib/codex-rules.ts
|
|
91
|
+
import { execFile } from "node:child_process";
|
|
92
|
+
import { rm, stat } from "node:fs/promises";
|
|
93
|
+
import { join as join3 } from "node:path";
|
|
94
|
+
|
|
95
|
+
// src/adapters/codex.ts
|
|
96
|
+
import { join as join2 } from "node:path";
|
|
97
|
+
|
|
98
|
+
// src/hooks/constants.ts
|
|
99
|
+
var HARNESS_MS = 5e3;
|
|
100
|
+
var MAX_BODY_BYTES = 4 * 1024 * 1024;
|
|
101
|
+
var LOG_TRUNCATE_BYTES = 5 * 1024 * 1024;
|
|
102
|
+
var CONTEXT_MAX = 1e4;
|
|
103
|
+
|
|
104
|
+
// src/lib/codex-trust.ts
|
|
105
|
+
import { spawn } from "node:child_process";
|
|
106
|
+
import { join } from "node:path";
|
|
107
|
+
function codexConfigPath(home, env = process.env) {
|
|
108
|
+
return join(codexHome(home, env), "config.toml");
|
|
109
|
+
}
|
|
110
|
+
function isRecord(v) {
|
|
111
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
112
|
+
}
|
|
113
|
+
function foldTrust(rows, keys) {
|
|
114
|
+
const wanted = new Set(keys);
|
|
115
|
+
const mine = rows.filter((r) => typeof r.key === "string" && wanted.has(r.key));
|
|
116
|
+
if (mine.length === 0) return "untrusted";
|
|
117
|
+
const status = (r) => typeof r.trustStatus === "string" ? r.trustStatus : "unknown";
|
|
118
|
+
if (mine.some((r) => r.enabled === false)) return "disabled";
|
|
119
|
+
if (mine.some((r) => status(r) === "modified")) return "modified";
|
|
120
|
+
const good = mine.filter((r) => status(r) === "trusted" || status(r) === "managed");
|
|
121
|
+
if (good.length === 0) return "untrusted";
|
|
122
|
+
if (good.length < keys.length) return "partial";
|
|
123
|
+
return "trusted";
|
|
124
|
+
}
|
|
125
|
+
var PROBE_MS = 8e3;
|
|
126
|
+
async function withAppServer(home, env, timeoutMs, fn) {
|
|
127
|
+
let child;
|
|
128
|
+
try {
|
|
129
|
+
child = spawn("codex", ["app-server"], {
|
|
130
|
+
env: { ...env, CODEX_HOME: codexHome(home, env) },
|
|
131
|
+
stdio: ["pipe", "pipe", "ignore"]
|
|
132
|
+
});
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
let dead = false;
|
|
137
|
+
const pending = /* @__PURE__ */ new Map();
|
|
138
|
+
const fail = () => {
|
|
139
|
+
dead = true;
|
|
140
|
+
for (const resolve2 of pending.values()) resolve2(void 0);
|
|
141
|
+
pending.clear();
|
|
142
|
+
};
|
|
143
|
+
child.on("error", fail);
|
|
144
|
+
child.on("exit", fail);
|
|
145
|
+
let buffered = "";
|
|
146
|
+
child.stdout?.setEncoding("utf8");
|
|
147
|
+
child.stdout?.on("data", (chunk) => {
|
|
148
|
+
buffered += chunk;
|
|
149
|
+
let cut = buffered.indexOf("\n");
|
|
150
|
+
while (cut !== -1) {
|
|
151
|
+
const line = buffered.slice(0, cut);
|
|
152
|
+
buffered = buffered.slice(cut + 1);
|
|
153
|
+
cut = buffered.indexOf("\n");
|
|
154
|
+
let msg;
|
|
155
|
+
try {
|
|
156
|
+
msg = JSON.parse(line);
|
|
157
|
+
} catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!isRecord(msg) || typeof msg.id !== "number") continue;
|
|
161
|
+
const waiting = pending.get(msg.id);
|
|
162
|
+
if (waiting === void 0) continue;
|
|
163
|
+
pending.delete(msg.id);
|
|
164
|
+
waiting(msg.error !== void 0 ? void 0 : msg.result);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
let nextId = 1;
|
|
168
|
+
const send = (payload) => {
|
|
169
|
+
try {
|
|
170
|
+
child.stdin?.write(`${JSON.stringify(payload)}
|
|
171
|
+
`);
|
|
172
|
+
return true;
|
|
173
|
+
} catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const request = async (method, params) => {
|
|
178
|
+
if (dead) return void 0;
|
|
179
|
+
const id = ++nextId;
|
|
180
|
+
return await new Promise((resolve2) => {
|
|
181
|
+
const timer = setTimeout(() => {
|
|
182
|
+
pending.delete(id);
|
|
183
|
+
resolve2(void 0);
|
|
184
|
+
}, timeoutMs);
|
|
185
|
+
pending.set(id, (value) => {
|
|
186
|
+
clearTimeout(timer);
|
|
187
|
+
resolve2(value);
|
|
188
|
+
});
|
|
189
|
+
if (!send({ jsonrpc: "2.0", id, method, params })) {
|
|
190
|
+
pending.delete(id);
|
|
191
|
+
clearTimeout(timer);
|
|
192
|
+
resolve2(void 0);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
try {
|
|
197
|
+
send({
|
|
198
|
+
jsonrpc: "2.0",
|
|
199
|
+
id: 1,
|
|
200
|
+
method: "initialize",
|
|
201
|
+
params: { clientInfo: { name: "tenjin", title: "tenjin", version: "1" } }
|
|
202
|
+
});
|
|
203
|
+
send({ jsonrpc: "2.0", method: "initialized", params: {} });
|
|
204
|
+
return await fn(request);
|
|
205
|
+
} catch {
|
|
206
|
+
return null;
|
|
207
|
+
} finally {
|
|
208
|
+
try {
|
|
209
|
+
child.stdin?.end();
|
|
210
|
+
} catch {
|
|
211
|
+
}
|
|
212
|
+
child.kill("SIGTERM");
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function listHooksViaAppServer(home, env, timeoutMs) {
|
|
216
|
+
return await withAppServer(home, env, timeoutMs, async (request) => {
|
|
217
|
+
const result = await request("hooks/list", { cwds: [] });
|
|
218
|
+
return result === void 0 ? null : rowsOf(result);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function rowsOf(result) {
|
|
222
|
+
if (!isRecord(result) || !Array.isArray(result.data)) return [];
|
|
223
|
+
const out = [];
|
|
224
|
+
for (const group of result.data) {
|
|
225
|
+
if (!isRecord(group) || !Array.isArray(group.hooks)) continue;
|
|
226
|
+
for (const hook of group.hooks) if (isRecord(hook)) out.push(hook);
|
|
227
|
+
}
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
async function trustCodexHooks(home, keys, ownedBy, opts = {}) {
|
|
231
|
+
const env = opts.env ?? process.env;
|
|
232
|
+
const timeoutMs = opts.timeoutMs ?? PROBE_MS;
|
|
233
|
+
if (keys.length === 0) return { ok: true, trusted: [] };
|
|
234
|
+
const run = async (request) => {
|
|
235
|
+
const before = await request("hooks/list", { cwds: [] });
|
|
236
|
+
if (before === void 0) {
|
|
237
|
+
return {
|
|
238
|
+
ok: false,
|
|
239
|
+
trusted: [],
|
|
240
|
+
failedAt: "list",
|
|
241
|
+
reason: "hooks/list did not answer"
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
const wanted = new Set(keys);
|
|
245
|
+
const mine = rowsOf(before).filter(
|
|
246
|
+
(r) => typeof r.key === "string" && wanted.has(r.key) && ownedBy(r)
|
|
247
|
+
);
|
|
248
|
+
if (mine.length !== keys.length) {
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
trusted: [],
|
|
252
|
+
failedAt: "list",
|
|
253
|
+
reason: `Codex listed ${mine.length} of the ${keys.length} entries this install wrote`
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
const value = {};
|
|
257
|
+
for (const row of mine) {
|
|
258
|
+
const hash = typeof row.currentHash === "string" ? row.currentHash : null;
|
|
259
|
+
if (hash === null) {
|
|
260
|
+
return {
|
|
261
|
+
ok: false,
|
|
262
|
+
trusted: [],
|
|
263
|
+
failedAt: "list",
|
|
264
|
+
reason: "Codex reported an entry with no currentHash"
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
value[row.key] = { trusted_hash: hash, enabled: true };
|
|
268
|
+
}
|
|
269
|
+
const wrote = await request("config/batchWrite", {
|
|
270
|
+
edits: [{ keyPath: "hooks.state", value, mergeStrategy: "upsert" }],
|
|
271
|
+
reloadUserConfig: true
|
|
272
|
+
});
|
|
273
|
+
if (wrote === void 0) {
|
|
274
|
+
return {
|
|
275
|
+
ok: false,
|
|
276
|
+
trusted: [],
|
|
277
|
+
failedAt: "write",
|
|
278
|
+
reason: "config/batchWrite was refused"
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
const after = await request("hooks/list", { cwds: [] });
|
|
282
|
+
if (after === void 0) {
|
|
283
|
+
return {
|
|
284
|
+
ok: false,
|
|
285
|
+
trusted: [],
|
|
286
|
+
failedAt: "verify",
|
|
287
|
+
reason: "the verifying hooks/list did not answer"
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const confirmed = rowsOf(after).filter(
|
|
291
|
+
(r) => typeof r.key === "string" && wanted.has(r.key) && ownedBy(r) && r.enabled !== false && (r.trustStatus === "trusted" || r.trustStatus === "managed") && r.currentHash === value[r.key]?.trusted_hash
|
|
292
|
+
);
|
|
293
|
+
if (confirmed.length !== keys.length) {
|
|
294
|
+
return {
|
|
295
|
+
ok: false,
|
|
296
|
+
trusted: confirmed.map((r) => r.key),
|
|
297
|
+
failedAt: "verify",
|
|
298
|
+
reason: `Codex confirmed ${confirmed.length} of ${keys.length} entries as trusted after the write`
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return { ok: true, trusted: confirmed.map((r) => r.key) };
|
|
302
|
+
};
|
|
303
|
+
const outcome = opts.connect !== void 0 ? await run(opts.connect) : await withAppServer(home, env, timeoutMs, run);
|
|
304
|
+
return outcome ?? {
|
|
305
|
+
ok: false,
|
|
306
|
+
trusted: [],
|
|
307
|
+
failedAt: "list",
|
|
308
|
+
reason: "the codex app server could not be reached"
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
async function readCodexTrust(home, keys, opts = {}) {
|
|
312
|
+
const env = opts.env ?? process.env;
|
|
313
|
+
const configPath2 = codexConfigPath(home, env);
|
|
314
|
+
const base = { configPath: configPath2, trusted: 0, expected: keys.length };
|
|
315
|
+
if (keys.length === 0) return { ...base, state: "unknown", source: "none" };
|
|
316
|
+
const list = await (opts.listHooks ?? ((h, e) => listHooksViaAppServer(h, e, opts.timeoutMs ?? PROBE_MS)))(home, env);
|
|
317
|
+
if (list !== null) {
|
|
318
|
+
const state = foldTrust(list, keys);
|
|
319
|
+
const wanted = new Set(keys);
|
|
320
|
+
const trusted = list.filter(
|
|
321
|
+
(r) => typeof r.key === "string" && wanted.has(r.key) && (r.trustStatus === "trusted" || r.trustStatus === "managed")
|
|
322
|
+
).length;
|
|
323
|
+
return { ...base, trusted, state, source: "app-server" };
|
|
324
|
+
}
|
|
325
|
+
return { ...base, state: "unknown", source: "none" };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/adapters/error-markers.ts
|
|
329
|
+
var ERROR_MARKERS = [
|
|
330
|
+
// Test-runner verdicts. Uppercase only, and a whole word.
|
|
331
|
+
/\bFAIL\b/,
|
|
332
|
+
/AssertionError/,
|
|
333
|
+
/\b[1-9]\d* (?:failed|failing|errors?)\b/i,
|
|
334
|
+
// `Error:`, `TypeError:`, `ReferenceError:`, `ModuleNotFoundError:` — the
|
|
335
|
+
// JS and Python convention of naming the class before the colon — and the
|
|
336
|
+
// lowercase `error:` that rustc, gcc, clang, esbuild and git open a
|
|
337
|
+
// diagnostic line with. Line-start only: "an error: occurred" mid-sentence
|
|
338
|
+
// is prose.
|
|
339
|
+
/^[ \t]*(?:\w*Error|error):/m,
|
|
340
|
+
/Traceback \(most recent call last\)/,
|
|
341
|
+
/ModuleNotFoundError|ImportError:/,
|
|
342
|
+
/Cannot find module/i,
|
|
343
|
+
// A code the shell or a runner states outright. Never zero.
|
|
344
|
+
/exit code [1-9]\d*/i,
|
|
345
|
+
// libuv/POSIX codes: unambiguous, and the common real failures.
|
|
346
|
+
/\b(?:ENOENT|EADDRINUSE|ECONNREFUSED|EACCES|EPERM)\b/,
|
|
347
|
+
// Toolchain-specific prefixes: npm, pnpm, tsc, cargo, go, git.
|
|
348
|
+
/^[ \t]*npm ERR!/m,
|
|
349
|
+
/ERR_PNPM_/,
|
|
350
|
+
/error TS\d+:/,
|
|
351
|
+
/^[ \t]*error\[E\d+\]/m,
|
|
352
|
+
/^[ \t]*panic:/m,
|
|
353
|
+
/^[ \t]*fatal:/m,
|
|
354
|
+
/Unhandled(?:PromiseRejection|Rejection)/,
|
|
355
|
+
/segmentation fault/i
|
|
356
|
+
];
|
|
357
|
+
function hasErrorMarker(text) {
|
|
358
|
+
return ERROR_MARKERS.some((re) => re.test(text));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// src/adapters/codex.ts
|
|
362
|
+
var NATIVE_TO_EVENT = {
|
|
363
|
+
SessionStart: "session.start",
|
|
364
|
+
UserPromptSubmit: "prompt",
|
|
365
|
+
PreToolUse: "tool.before",
|
|
366
|
+
PostToolUse: "tool.after",
|
|
367
|
+
SubagentStart: "agent.start",
|
|
368
|
+
SubagentStop: "agent.stop",
|
|
369
|
+
Stop: "turn.end"
|
|
370
|
+
};
|
|
371
|
+
var SHELL_TOOL = "Bash";
|
|
372
|
+
var PATCH_TOOL = "apply_patch";
|
|
373
|
+
var BLOCK_EVENTS = /* @__PURE__ */ new Set(["turn.end", "agent.stop"]);
|
|
374
|
+
function isRecord2(v) {
|
|
375
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
376
|
+
}
|
|
377
|
+
function str(v) {
|
|
378
|
+
return typeof v === "string" ? v : void 0;
|
|
379
|
+
}
|
|
380
|
+
var PATCH_PATH_RE = /^\*\*\* (?:Add File|Update File|Delete File|Move to): (.+)$/;
|
|
381
|
+
function patchPaths(patch) {
|
|
382
|
+
const out = [];
|
|
383
|
+
for (const line of patch.split("\n")) {
|
|
384
|
+
const m = PATCH_PATH_RE.exec(line.trimEnd());
|
|
385
|
+
const path = m?.[1]?.trim();
|
|
386
|
+
if (path !== void 0 && path.length > 0 && !out.includes(path)) out.push(path);
|
|
387
|
+
}
|
|
388
|
+
return out;
|
|
389
|
+
}
|
|
390
|
+
function canonicalTool(name, input) {
|
|
391
|
+
if (name === SHELL_TOOL) return { name, kind: "shell", command: str(input.command) ?? "" };
|
|
392
|
+
if (name === PATCH_TOOL)
|
|
393
|
+
return { name, kind: "edit", paths: patchPaths(str(input.command) ?? "") };
|
|
394
|
+
return { name, kind: "other" };
|
|
395
|
+
}
|
|
396
|
+
function decode(raw) {
|
|
397
|
+
if (!isRecord2(raw)) return null;
|
|
398
|
+
const native = str(raw.hook_event_name);
|
|
399
|
+
if (native === void 0) return null;
|
|
400
|
+
const event = NATIVE_TO_EVENT[native];
|
|
401
|
+
if (event === void 0) return null;
|
|
402
|
+
const session = str(raw.session_id);
|
|
403
|
+
if (session === void 0 || session.length === 0) return null;
|
|
404
|
+
const input = {
|
|
405
|
+
harness: "codex",
|
|
406
|
+
event,
|
|
407
|
+
native: { event: native },
|
|
408
|
+
session,
|
|
409
|
+
cwd: str(raw.cwd) ?? "",
|
|
410
|
+
raw
|
|
411
|
+
};
|
|
412
|
+
if (raw.agent_id !== void 0 && raw.agent_id !== null) {
|
|
413
|
+
const id = raw.agent_id;
|
|
414
|
+
if (typeof id !== "string" || !AGENT_ID_RE.test(id)) return null;
|
|
415
|
+
input.agent = id;
|
|
416
|
+
}
|
|
417
|
+
const turn = str(raw.turn_id);
|
|
418
|
+
if (turn !== void 0) input.turn = turn;
|
|
419
|
+
const prompt = str(raw.prompt);
|
|
420
|
+
if (prompt !== void 0) input.prompt = prompt;
|
|
421
|
+
const agentType = str(raw.agent_type);
|
|
422
|
+
if (agentType !== void 0) input.agentType = agentType;
|
|
423
|
+
const lastMessage = str(raw.last_assistant_message);
|
|
424
|
+
if (lastMessage !== void 0) input.lastMessage = lastMessage;
|
|
425
|
+
if (typeof raw.stop_hook_active === "boolean") input.stopFuse = raw.stop_hook_active;
|
|
426
|
+
const source = str(raw.source);
|
|
427
|
+
if (source !== void 0) input.source = source;
|
|
428
|
+
const path = str(raw.transcript_path);
|
|
429
|
+
const agentPath = str(raw.agent_transcript_path);
|
|
430
|
+
if (path !== void 0 || agentPath !== void 0) {
|
|
431
|
+
input.transcript = {};
|
|
432
|
+
if (path !== void 0) input.transcript.path = path;
|
|
433
|
+
if (agentPath !== void 0) input.transcript.agentPath = agentPath;
|
|
434
|
+
}
|
|
435
|
+
if (event === "tool.before" || event === "tool.after") {
|
|
436
|
+
const name = str(raw.tool_name) ?? "";
|
|
437
|
+
const tool = canonicalTool(name, isRecord2(raw.tool_input) ? raw.tool_input : {});
|
|
438
|
+
const callId = str(raw.tool_use_id);
|
|
439
|
+
if (callId !== void 0) tool.callId = callId;
|
|
440
|
+
if (event === "tool.after") {
|
|
441
|
+
const text = str(raw.tool_response);
|
|
442
|
+
if (text !== void 0) tool.result = { text };
|
|
443
|
+
if (tool.kind === "shell" && text !== void 0 && hasErrorMarker(text)) tool.ok = false;
|
|
444
|
+
}
|
|
445
|
+
input.tool = tool;
|
|
446
|
+
}
|
|
447
|
+
return input;
|
|
448
|
+
}
|
|
449
|
+
function encode(emit, input) {
|
|
450
|
+
if (emit === null || emit.context === void 0 || emit.context.length === 0) return null;
|
|
451
|
+
const text = emit.context.slice(0, CONTEXT_MAX);
|
|
452
|
+
if (BLOCK_EVENTS.has(input.event)) return { decision: "block", reason: text };
|
|
453
|
+
return { hookSpecificOutput: { hookEventName: input.native.event, additionalContext: text } };
|
|
454
|
+
}
|
|
455
|
+
function codexHome(home, env = process.env) {
|
|
456
|
+
const override = env.CODEX_HOME;
|
|
457
|
+
return override !== void 0 && override.length > 0 ? override : join2(home, ".codex");
|
|
458
|
+
}
|
|
459
|
+
function commandHandler(shimPath, timeoutSeconds) {
|
|
460
|
+
return {
|
|
461
|
+
type: "command",
|
|
462
|
+
command: `node ${JSON.stringify(shimPath)} --harness codex`,
|
|
463
|
+
timeout: timeoutSeconds
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
var registrar = {
|
|
467
|
+
configPath(home, env) {
|
|
468
|
+
return join2(codexHome(home, env), "hooks.json");
|
|
469
|
+
},
|
|
470
|
+
/**
|
|
471
|
+
* Seven `command` entries, every one through the shim: a Codex handler
|
|
472
|
+
* carries no URL or token, so the daemon is ensured on each fire and the
|
|
473
|
+
* entry holds nothing worth protecting. The matchers are the two hooked
|
|
474
|
+
* tool names the arms read; a child's fires arrive through the same entries.
|
|
475
|
+
*/
|
|
476
|
+
plan({ shimPath, timeoutSeconds }) {
|
|
477
|
+
const command = [commandHandler(shimPath, timeoutSeconds)];
|
|
478
|
+
return [
|
|
479
|
+
{ event: "SessionStart", hooks: command },
|
|
480
|
+
{ event: "UserPromptSubmit", hooks: command },
|
|
481
|
+
{ event: "PreToolUse", matcher: `${SHELL_TOOL}|${PATCH_TOOL}`, hooks: command },
|
|
482
|
+
{ event: "PostToolUse", matcher: SHELL_TOOL, hooks: command },
|
|
483
|
+
{ event: "SubagentStart", hooks: command },
|
|
484
|
+
{ event: "SubagentStop", hooks: command },
|
|
485
|
+
{ event: "Stop", hooks: command }
|
|
486
|
+
];
|
|
487
|
+
},
|
|
488
|
+
/**
|
|
489
|
+
* Codex reads hooks once, at session start. `install` now trusts the entries
|
|
490
|
+
* it writes through Codex's own supported path (lib/codex-trust.ts), so the
|
|
491
|
+
* `/hooks` walkthrough this used to carry is gone; what is left is the one
|
|
492
|
+
* fact no installer can change, which is that the session already open still
|
|
493
|
+
* has the hook set it started with (tenjin-agent#343).
|
|
494
|
+
*/
|
|
495
|
+
activation() {
|
|
496
|
+
return ["Start a new Codex session: hooks are read at session start."];
|
|
497
|
+
},
|
|
498
|
+
grant: {
|
|
499
|
+
path: codexRulesPath,
|
|
500
|
+
inspect: inspectCodexGrant,
|
|
501
|
+
write: wireCodexGrant,
|
|
502
|
+
remove: removeCodexGrant
|
|
503
|
+
},
|
|
504
|
+
trust: {
|
|
505
|
+
ensure: trustCodexHooks,
|
|
506
|
+
read: readCodexTrust
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
var codexAdapter = { id: "codex", decode, encode, registrar };
|
|
510
|
+
|
|
511
|
+
// src/lib/codex-rules.ts
|
|
512
|
+
function codexRulesPath(home, env = process.env) {
|
|
513
|
+
return join3(codexHome(home, env), "rules", "tenjin.rules");
|
|
514
|
+
}
|
|
515
|
+
function prefixTokens(rule) {
|
|
516
|
+
const m = /^Bash\(tenjin ((?:[a-z][a-z-]* )*[a-z][a-z-]*):\*\)$/.exec(rule);
|
|
517
|
+
const verbs = m?.[1];
|
|
518
|
+
if (verbs === void 0) return null;
|
|
519
|
+
return ["tenjin", ...verbs.split(" ")];
|
|
520
|
+
}
|
|
521
|
+
function prefixRuleLine(tokens) {
|
|
522
|
+
const pattern = tokens.map((t) => JSON.stringify(t)).join(", ");
|
|
523
|
+
return `prefix_rule(pattern=[${pattern}], decision="allow")`;
|
|
524
|
+
}
|
|
525
|
+
function grantedPrefixes(rules) {
|
|
526
|
+
return rules.map(prefixTokens).filter((t) => t !== null);
|
|
527
|
+
}
|
|
528
|
+
function rulesFileBody(rules) {
|
|
529
|
+
const lines = [
|
|
530
|
+
"# Written by `tenjin install`. Change it with `tenjin config set publish.mode`",
|
|
531
|
+
"# or `tenjin uninstall`, not by hand: the next install rewrites it whole.",
|
|
532
|
+
"# Your own rules live in default.rules and are never touched by Tenjin.",
|
|
533
|
+
"",
|
|
534
|
+
...grantedPrefixes(rules).map(prefixRuleLine)
|
|
535
|
+
];
|
|
536
|
+
return `${lines.join("\n")}
|
|
537
|
+
`;
|
|
538
|
+
}
|
|
539
|
+
async function verifyPrefixAllowed(rulesPath, tokens, env = process.env, timeoutMs = VERIFY_MS) {
|
|
540
|
+
return await new Promise((resolve2) => {
|
|
541
|
+
execFile(
|
|
542
|
+
"codex",
|
|
543
|
+
["execpolicy", "check", "--rules", rulesPath, ...tokens],
|
|
544
|
+
{ env, timeout: timeoutMs, windowsHide: true },
|
|
545
|
+
(_err, stdout) => {
|
|
546
|
+
if (typeof stdout !== "string" || stdout.length === 0) {
|
|
547
|
+
resolve2(null);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
try {
|
|
551
|
+
const parsed = JSON.parse(stdout);
|
|
552
|
+
const decision = typeof parsed === "object" && parsed !== null ? parsed.decision : void 0;
|
|
553
|
+
resolve2(decision === "allow");
|
|
554
|
+
} catch {
|
|
555
|
+
resolve2(null);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
var VERIFY_MS = 5e3;
|
|
562
|
+
async function removeCodexGrant(home, env = process.env) {
|
|
563
|
+
const path = codexRulesPath(home, env);
|
|
564
|
+
const found = await stat(path).catch(() => null);
|
|
565
|
+
if (found === null || !found.isFile()) return { path, removed: false };
|
|
566
|
+
await rm(path, { force: true });
|
|
567
|
+
return { path, removed: true };
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// src/lib/harness-permissions.ts
|
|
571
|
+
function claudeSettingsPath(homeDir) {
|
|
572
|
+
return join4(homeDir, ".claude", "settings.json");
|
|
573
|
+
}
|
|
574
|
+
async function inspectClaudeGrant(homeDir, mode) {
|
|
575
|
+
const found = await inspectAllowlist(homeDir, mode);
|
|
576
|
+
if ("result" in found) {
|
|
577
|
+
const refused = found.result;
|
|
578
|
+
return {
|
|
579
|
+
harness: "claude",
|
|
580
|
+
state: "unknown",
|
|
581
|
+
...refused.path !== void 0 ? { path: refused.path } : {},
|
|
582
|
+
rules: [],
|
|
583
|
+
missing: [],
|
|
584
|
+
detail: refused.warning ?? `${claudeSettingsPath(homeDir)} could not be read.`,
|
|
585
|
+
...refused.fix !== void 0 ? { fix: refused.fix } : {}
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
const missing = [...found.added];
|
|
589
|
+
return {
|
|
590
|
+
harness: "claude",
|
|
591
|
+
state: missing.length === 0 ? "granted" : "pending",
|
|
592
|
+
path: found.path,
|
|
593
|
+
rules: [...found.alreadyPresent],
|
|
594
|
+
missing,
|
|
595
|
+
detail: missing.length === 0 ? `${found.alreadyPresent.length} rules in ${found.path}` : `${missing.length} of this mode's rules are missing from ${found.path}`,
|
|
596
|
+
...missing.length === 0 ? {} : { fix: "tenjin install" }
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
async function tighten(path) {
|
|
600
|
+
if (process.platform === "win32") return;
|
|
601
|
+
const found = await stat2(path).catch(() => null);
|
|
602
|
+
if (found === null || (found.mode & 63) === 0) return;
|
|
603
|
+
await chmod(path, 384).catch(() => void 0);
|
|
604
|
+
}
|
|
605
|
+
async function inspectCodexGrant(homeDir, mode, env = process.env) {
|
|
606
|
+
const path = codexRulesPath(homeDir, env);
|
|
607
|
+
const writable = rulesForPublishMode(mode);
|
|
608
|
+
const want = rulesFileBody(writable);
|
|
609
|
+
const rules = grantedPrefixes(writable).map((tokens) => tokens.join(" "));
|
|
610
|
+
const found = await readFile(path, "utf8").catch(() => null);
|
|
611
|
+
if (found !== want) {
|
|
612
|
+
return {
|
|
613
|
+
harness: "codex",
|
|
614
|
+
state: "pending",
|
|
615
|
+
path,
|
|
616
|
+
rules: [],
|
|
617
|
+
missing: rules,
|
|
618
|
+
detail: found === null ? `no grant is installed at ${path}` : `${path} does not match what publish.mode ${mode} calls for`,
|
|
619
|
+
fix: "tenjin install"
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
const probe = grantedPrefixes(writable).at(-1);
|
|
623
|
+
const agreed = probe === void 0 ? null : await verifyPrefixAllowed(path, probe, env);
|
|
624
|
+
if (agreed === false) {
|
|
625
|
+
return {
|
|
626
|
+
harness: "codex",
|
|
627
|
+
state: "pending",
|
|
628
|
+
path,
|
|
629
|
+
rules: [],
|
|
630
|
+
missing: rules,
|
|
631
|
+
detail: `${path} is installed but Codex does not read it as granting \`${probe?.join(" ")}\``,
|
|
632
|
+
fix: "tenjin install"
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
if (agreed === null) {
|
|
636
|
+
return {
|
|
637
|
+
harness: "codex",
|
|
638
|
+
state: "unknown",
|
|
639
|
+
path,
|
|
640
|
+
rules,
|
|
641
|
+
missing: [],
|
|
642
|
+
detail: `${rules.length} prefixes written to ${path}, but codex could not be asked whether it reads them as a grant`,
|
|
643
|
+
fix: "Check `codex execpolicy check --rules <file> tenjin publish x` on the machine itself."
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
harness: "codex",
|
|
648
|
+
state: "granted",
|
|
649
|
+
path,
|
|
650
|
+
rules,
|
|
651
|
+
missing: [],
|
|
652
|
+
detail: `${rules.length} prefixes in ${path}, confirmed by codex execpolicy`
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
async function wireCodexGrant(homeDir, mode, env = process.env) {
|
|
656
|
+
const path = codexRulesPath(homeDir, env);
|
|
657
|
+
const rules = rulesForPublishMode(mode);
|
|
658
|
+
const body = rulesFileBody(rules);
|
|
659
|
+
const granted = grantedPrefixes(rules).map((t) => t.join(" "));
|
|
660
|
+
try {
|
|
661
|
+
await mkdir(dirname(path), { recursive: true });
|
|
662
|
+
const current = await readFile(path, "utf8").catch(() => null);
|
|
663
|
+
if (current === body) {
|
|
664
|
+
await tighten(path);
|
|
665
|
+
return { path, granted, wrote: false };
|
|
666
|
+
}
|
|
667
|
+
await writeFileAtomic(path, body, { mode: 384 });
|
|
668
|
+
return { path, granted, wrote: true };
|
|
669
|
+
} catch (err) {
|
|
670
|
+
return {
|
|
671
|
+
path,
|
|
672
|
+
granted: [],
|
|
673
|
+
wrote: false,
|
|
674
|
+
error: err instanceof Error ? err.message : String(err)
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
var FREE_VERB_RULES = [
|
|
679
|
+
"Bash(tenjin search:*)",
|
|
680
|
+
"Bash(tenjin wallet fund:*)",
|
|
681
|
+
"Bash(tenjin inspect:*)",
|
|
682
|
+
"Bash(tenjin read:*)",
|
|
683
|
+
"Bash(tenjin outcome:*)",
|
|
684
|
+
"Bash(tenjin doctor:*)",
|
|
685
|
+
"Bash(tenjin wallet show:*)",
|
|
686
|
+
"Bash(tenjin wallet balance:*)",
|
|
687
|
+
"Bash(tenjin config get:*)"
|
|
688
|
+
];
|
|
689
|
+
var PUBLISH_MODE_RULE = "Bash(tenjin publish:*)";
|
|
690
|
+
var EDIT_MODE_RULE = "Bash(tenjin edit:*)";
|
|
691
|
+
var MODE_GATED_RULES = [PUBLISH_MODE_RULE, EDIT_MODE_RULE];
|
|
692
|
+
function rulesForPublishMode(mode) {
|
|
693
|
+
return mode === "review" ? FREE_VERB_RULES : [...FREE_VERB_RULES, ...MODE_GATED_RULES];
|
|
694
|
+
}
|
|
695
|
+
function retiredFor(mode) {
|
|
696
|
+
const retired = new Set(LEGACY_ALLOWLIST_RULES);
|
|
697
|
+
if (mode === "review") for (const rule of MODE_GATED_RULES) retired.add(rule);
|
|
698
|
+
return retired;
|
|
699
|
+
}
|
|
700
|
+
var LEGACY_ALLOWLIST_RULES = [
|
|
701
|
+
"Bash(tenjin candidate list:*)",
|
|
702
|
+
"Bash(tenjin fund:*)"
|
|
703
|
+
];
|
|
704
|
+
var MODE_GRANT_UNDO = [
|
|
705
|
+
"tenjin install --publish-mode review",
|
|
706
|
+
"tenjin config set publish.mode review",
|
|
707
|
+
"tenjin uninstall"
|
|
708
|
+
];
|
|
709
|
+
function modeGrantFor(mode, added, present, planned) {
|
|
710
|
+
const wasAdded = MODE_GATED_RULES.filter((r) => added.includes(r));
|
|
711
|
+
const wasPresent = MODE_GATED_RULES.filter((r) => present.includes(r));
|
|
712
|
+
const rules = [...wasAdded, ...wasPresent];
|
|
713
|
+
if (rules.length === 0) return void 0;
|
|
714
|
+
const state = wasAdded.length === 0 ? "already-present" : wasPresent.length === 0 ? "added" : "mixed";
|
|
715
|
+
const verb = state === "already-present" ? "already present" : state === "mixed" ? planned ? "would be in place" : "in place" : planned ? "would be added" : "added";
|
|
716
|
+
return {
|
|
717
|
+
rules: MODE_GATED_RULES.filter((r) => rules.includes(r)),
|
|
718
|
+
state,
|
|
719
|
+
disclosure: `${MODE_GATED_RULES.join(" and ")} ${verb}: on publish.mode ${mode} your agent can publish to the public marketplace under your identity, update its own posts, and open your wallet keystore to sign, without a harness prompt.`,
|
|
720
|
+
undo: [...MODE_GRANT_UNDO]
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
function fixFor(reason, harness = "claude") {
|
|
724
|
+
switch (reason) {
|
|
725
|
+
case "harness-unsupported":
|
|
726
|
+
return `No permission rules were written: ${harness} has no surface for them.`;
|
|
727
|
+
case "not-requested":
|
|
728
|
+
case "declined":
|
|
729
|
+
case "dry-run":
|
|
730
|
+
return "Add them with `tenjin install`.";
|
|
731
|
+
case "changed-since-read":
|
|
732
|
+
return "Another process changed the file mid-run; re-run `tenjin install`.";
|
|
733
|
+
default:
|
|
734
|
+
return "Fix the reported file, then run `tenjin install`.";
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
function tiers(added, alreadyPresent, mode, planned = false) {
|
|
738
|
+
const gated = new Set(MODE_GATED_RULES);
|
|
739
|
+
const grant = modeGrantFor(mode, added, alreadyPresent, planned);
|
|
740
|
+
return {
|
|
741
|
+
addedFree: added.filter((r) => !gated.has(r)),
|
|
742
|
+
alreadyPresentFree: alreadyPresent.filter((r) => !gated.has(r)),
|
|
743
|
+
...grant !== void 0 ? { modeGrant: grant } : {}
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
function skip(harness, path, reason, warning) {
|
|
747
|
+
return {
|
|
748
|
+
harness,
|
|
749
|
+
...path !== void 0 ? { path } : {},
|
|
750
|
+
added: [],
|
|
751
|
+
removed: [],
|
|
752
|
+
alreadyPresent: [],
|
|
753
|
+
addedFree: [],
|
|
754
|
+
alreadyPresentFree: [],
|
|
755
|
+
skipped: reason,
|
|
756
|
+
...warning !== void 0 ? { warning } : {},
|
|
757
|
+
fix: fixFor(reason, harness)
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
function isPlainObject(value) {
|
|
761
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
762
|
+
}
|
|
763
|
+
async function writeSettings(path, next) {
|
|
764
|
+
const current = await stat2(path).catch(() => null);
|
|
765
|
+
await writeFileAtomic(
|
|
766
|
+
path,
|
|
767
|
+
`${JSON.stringify(next, null, 2)}
|
|
768
|
+
`,
|
|
769
|
+
current === null ? {} : { mode: current.mode & 511 }
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
async function retractModeGatedRules(homeDir) {
|
|
773
|
+
const found = await inspectAllowlist(homeDir, "review");
|
|
774
|
+
if ("result" in found) {
|
|
775
|
+
const refused = found.result;
|
|
776
|
+
return {
|
|
777
|
+
...refused,
|
|
778
|
+
fix: `${refused.path ?? claudeSettingsPath(homeDir)} could not be read, so ${MODE_GATED_RULES.join(" and ")} may still be allowed there. Remove those lines by hand, or run \`tenjin uninstall\`.`
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
const { path, raw, settings, permissions, allow } = found;
|
|
782
|
+
const gated = new Set(MODE_GATED_RULES);
|
|
783
|
+
const removed = allow.filter((r) => typeof r === "string" && gated.has(r));
|
|
784
|
+
if (removed.length === 0) {
|
|
785
|
+
return {
|
|
786
|
+
harness: "claude",
|
|
787
|
+
path,
|
|
788
|
+
added: [],
|
|
789
|
+
alreadyPresent: [],
|
|
790
|
+
addedFree: [],
|
|
791
|
+
alreadyPresentFree: [],
|
|
792
|
+
removed: []
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
const kept = allow.filter((r) => !(typeof r === "string" && gated.has(r)));
|
|
796
|
+
const next = { ...settings, permissions: { ...permissions, allow: kept } };
|
|
797
|
+
const current = await readFile(path, "utf8").catch(() => null);
|
|
798
|
+
if (current !== raw) {
|
|
799
|
+
return skip(
|
|
800
|
+
"claude",
|
|
801
|
+
path,
|
|
802
|
+
"changed-since-read",
|
|
803
|
+
`${path} changed while it was being updated, so nothing was written. Re-run to retract ${MODE_GATED_RULES.join(" and ")}.`
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
await writeSettings(path, next);
|
|
807
|
+
return {
|
|
808
|
+
harness: "claude",
|
|
809
|
+
path,
|
|
810
|
+
added: [],
|
|
811
|
+
alreadyPresent: [],
|
|
812
|
+
addedFree: [],
|
|
813
|
+
alreadyPresentFree: [],
|
|
814
|
+
removed
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
async function wireFreeVerbAllowlist(homeDir, mode = "review") {
|
|
818
|
+
const found = await inspectAllowlist(homeDir, mode);
|
|
819
|
+
if ("result" in found) return found.result;
|
|
820
|
+
const { path, raw, settings, permissions, allow, added, alreadyPresent } = found;
|
|
821
|
+
const retired = retiredFor(mode);
|
|
822
|
+
const removed = allow.filter((r) => typeof r === "string" && retired.has(r));
|
|
823
|
+
if (added.length === 0 && removed.length === 0) {
|
|
824
|
+
return {
|
|
825
|
+
harness: "claude",
|
|
826
|
+
path,
|
|
827
|
+
added: [],
|
|
828
|
+
alreadyPresent,
|
|
829
|
+
...tiers([], alreadyPresent, mode),
|
|
830
|
+
removed: []
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
const kept = allow.filter((r) => !(typeof r === "string" && retired.has(r)));
|
|
834
|
+
const next = {
|
|
835
|
+
...settings,
|
|
836
|
+
permissions: { ...permissions, allow: [...kept, ...added] }
|
|
837
|
+
};
|
|
838
|
+
const current = await readFile(path, "utf8").catch(() => null);
|
|
839
|
+
if (current !== raw) {
|
|
840
|
+
return skip(
|
|
841
|
+
"claude",
|
|
842
|
+
path,
|
|
843
|
+
"changed-since-read",
|
|
844
|
+
`${path} changed while it was being updated, so nothing was written. Re-run \`tenjin install\`.`
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
await writeSettings(path, next);
|
|
848
|
+
return {
|
|
849
|
+
harness: "claude",
|
|
850
|
+
path,
|
|
851
|
+
added,
|
|
852
|
+
alreadyPresent,
|
|
853
|
+
...tiers(added, alreadyPresent, mode),
|
|
854
|
+
removed
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
async function inspectFreeVerbRules(homeDir, mode = "review") {
|
|
858
|
+
const found = await inspectAllowlist(homeDir, mode);
|
|
859
|
+
if ("result" in found) return { pending: null };
|
|
860
|
+
if (found.added.length > 0) return { pending: found.added };
|
|
861
|
+
const retired = retiredFor(mode);
|
|
862
|
+
if (found.allow.some((r) => typeof r === "string" && retired.has(r))) return { pending: [] };
|
|
863
|
+
return {
|
|
864
|
+
pending: [],
|
|
865
|
+
satisfied: {
|
|
866
|
+
harness: "claude",
|
|
867
|
+
path: found.path,
|
|
868
|
+
added: [],
|
|
869
|
+
alreadyPresent: found.alreadyPresent,
|
|
870
|
+
...tiers([], found.alreadyPresent, mode),
|
|
871
|
+
removed: []
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
async function inspectAllowlist(homeDir, mode) {
|
|
876
|
+
return inspectAllowlistAt(claudeSettingsPath(homeDir), rulesForPublishMode(mode));
|
|
877
|
+
}
|
|
878
|
+
async function inspectAllowlistAt(declaredPath, rules, list = "allow") {
|
|
879
|
+
const refuse = (p, reason, warning) => ({ result: skip("claude", p, reason, warning) });
|
|
880
|
+
const entry = await lstat(declaredPath).catch(() => null);
|
|
881
|
+
let path = declaredPath;
|
|
882
|
+
if (entry !== null) {
|
|
883
|
+
try {
|
|
884
|
+
path = await realpath(declaredPath);
|
|
885
|
+
} catch (err) {
|
|
886
|
+
return refuse(
|
|
887
|
+
declaredPath,
|
|
888
|
+
"unresolvable",
|
|
889
|
+
`${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
let settings = {};
|
|
894
|
+
let raw = null;
|
|
895
|
+
if (entry !== null) {
|
|
896
|
+
try {
|
|
897
|
+
raw = await readFile(path, "utf8");
|
|
898
|
+
} catch (err) {
|
|
899
|
+
return refuse(
|
|
900
|
+
path,
|
|
901
|
+
"unreadable",
|
|
902
|
+
`${path} could not be read (${err.message}); no permissions were written.`
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
let parsed;
|
|
906
|
+
try {
|
|
907
|
+
parsed = JSON.parse(raw);
|
|
908
|
+
} catch (err) {
|
|
909
|
+
return refuse(
|
|
910
|
+
path,
|
|
911
|
+
"unparsable",
|
|
912
|
+
`${path} is not valid JSON (${err.message}); it was left exactly as it is.`
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
if (!isPlainObject(parsed)) {
|
|
916
|
+
return refuse(
|
|
917
|
+
path,
|
|
918
|
+
"unexpected-shape",
|
|
919
|
+
`${path} is not a JSON object; it was left exactly as it is.`
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
settings = parsed;
|
|
923
|
+
}
|
|
924
|
+
const permissionsValue = settings.permissions;
|
|
925
|
+
if (permissionsValue !== void 0 && !isPlainObject(permissionsValue)) {
|
|
926
|
+
return refuse(
|
|
927
|
+
path,
|
|
928
|
+
"unexpected-shape",
|
|
929
|
+
`${path} has a "permissions" key that is not an object; it was left exactly as it is.`
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
const permissions = permissionsValue ?? {};
|
|
933
|
+
const allowValue = permissions[list];
|
|
934
|
+
if (allowValue !== void 0 && !Array.isArray(allowValue)) {
|
|
935
|
+
return refuse(
|
|
936
|
+
path,
|
|
937
|
+
"unexpected-shape",
|
|
938
|
+
`${path} has a "permissions.${list}" key that is not an array; it was left exactly as it is.`
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
const allow = allowValue ?? [];
|
|
942
|
+
const present = new Set(allow.filter((e) => typeof e === "string"));
|
|
943
|
+
const added = rules.filter((rule) => !present.has(rule));
|
|
944
|
+
const alreadyPresent = rules.filter((rule) => present.has(rule));
|
|
945
|
+
return { path, raw, settings, permissions, allow, added, alreadyPresent: [...alreadyPresent] };
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/lib/skill-wiring.ts
|
|
949
|
+
import { existsSync, statSync } from "node:fs";
|
|
950
|
+
import { constants, open } from "node:fs/promises";
|
|
951
|
+
import { delimiter, join as join6 } from "node:path";
|
|
952
|
+
|
|
953
|
+
// src/lib/skills-source.ts
|
|
954
|
+
import { dirname as dirname2, join as join5 } from "node:path";
|
|
955
|
+
var SKILL_NAMES = ["tenjin-search", "tenjin-publish", "tenjin"];
|
|
956
|
+
var RETIRED_SKILL_NAMES = ["tenjin-pay"];
|
|
957
|
+
var PACKAGED_SKILL_NAMES = [...SKILL_NAMES];
|
|
958
|
+
var SHIPPED_SKILL_FILES = {
|
|
959
|
+
"tenjin-search": ["SKILL.md", "references/permissions.md"],
|
|
960
|
+
"tenjin-publish": ["SKILL.md", "references/maintain.md"],
|
|
961
|
+
tenjin: ["SKILL.md"],
|
|
962
|
+
"tenjin-pay": ["SKILL.md"]
|
|
963
|
+
};
|
|
964
|
+
var SENTINEL = join5("tenjin", "SKILL.md");
|
|
965
|
+
|
|
966
|
+
// src/lib/skill-wiring.ts
|
|
967
|
+
var CLI_SKILL_NAMES = [
|
|
968
|
+
"tenjin-search",
|
|
969
|
+
"tenjin-publish"
|
|
970
|
+
];
|
|
971
|
+
function skillsDirsFor(home) {
|
|
972
|
+
return [join6(home, ".claude", "skills"), join6(home, ".agents", "skills")];
|
|
973
|
+
}
|
|
974
|
+
function harnessTargetDir(home, harness) {
|
|
975
|
+
if (harness === "claude") return join6(home, ".claude", "skills");
|
|
976
|
+
return join6(home, ".agents", "skills");
|
|
977
|
+
}
|
|
978
|
+
function harnessFlagFor(home, dir) {
|
|
979
|
+
if (dir === join6(home, ".claude", "skills")) return "claude";
|
|
980
|
+
return "codex";
|
|
981
|
+
}
|
|
982
|
+
function harnessDetectedBy(home, harness, which) {
|
|
983
|
+
const reasons = [];
|
|
984
|
+
if (existsSync(join6(home, `.${harness}`))) reasons.push("home-dir");
|
|
985
|
+
if (which(harness)) reasons.push("binary");
|
|
986
|
+
return reasons;
|
|
987
|
+
}
|
|
988
|
+
function detectHarnesses(home, which) {
|
|
989
|
+
return {
|
|
990
|
+
claude: harnessDetectedBy(home, "claude", which).length > 0,
|
|
991
|
+
codex: harnessDetectedBy(home, "codex", which).length > 0
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
function harnessReads(home, dir, present) {
|
|
995
|
+
if (harnessFlagFor(home, dir) === "claude") return present.claude;
|
|
996
|
+
return present.codex;
|
|
997
|
+
}
|
|
998
|
+
function harnessRequested(home, dir, requested) {
|
|
999
|
+
return requested.some((h) => harnessTargetDir(home, h) === dir);
|
|
1000
|
+
}
|
|
1001
|
+
function harnessInPlay(home, dir, present, requested) {
|
|
1002
|
+
if (requested.length > 0) return harnessRequested(home, dir, requested);
|
|
1003
|
+
return harnessReads(home, dir, present);
|
|
1004
|
+
}
|
|
1005
|
+
function onPath(bin, env) {
|
|
1006
|
+
const raw = env.PATH ?? "";
|
|
1007
|
+
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
|
|
1008
|
+
for (const part of raw.split(delimiter)) {
|
|
1009
|
+
if (part.length === 0) continue;
|
|
1010
|
+
for (const ext of exts) {
|
|
1011
|
+
if (isFile(join6(part, bin + ext))) return true;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
return false;
|
|
1015
|
+
}
|
|
1016
|
+
function isFile(p) {
|
|
1017
|
+
try {
|
|
1018
|
+
return statSync(p).isFile();
|
|
1019
|
+
} catch {
|
|
1020
|
+
return false;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
async function readSkillFile(path) {
|
|
1024
|
+
let handle;
|
|
1025
|
+
try {
|
|
1026
|
+
handle = await open(path, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
|
|
1027
|
+
} catch (err) {
|
|
1028
|
+
if (hasCode(err, "ENOENT")) return { kind: "absent" };
|
|
1029
|
+
return { kind: "unreadable", err };
|
|
1030
|
+
}
|
|
1031
|
+
try {
|
|
1032
|
+
if (!(await handle.stat()).isFile()) return { kind: "not-regular" };
|
|
1033
|
+
return { kind: "ok", bytes: await handle.readFile() };
|
|
1034
|
+
} catch (err) {
|
|
1035
|
+
return { kind: "unreadable", err };
|
|
1036
|
+
} finally {
|
|
1037
|
+
await handle.close().catch(() => void 0);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function skillFrontmatterName(skillMd) {
|
|
1041
|
+
const frontmatter = extractFrontmatter(skillMd);
|
|
1042
|
+
if (frontmatter === null) return null;
|
|
1043
|
+
for (const line of frontmatter) {
|
|
1044
|
+
const m = /^name:\s*(.+?)\s*$/.exec(line);
|
|
1045
|
+
if (m !== null) return (m[1] ?? "").replace(/^["']|["']$/g, "");
|
|
1046
|
+
}
|
|
1047
|
+
return null;
|
|
1048
|
+
}
|
|
1049
|
+
function extractFrontmatter(text) {
|
|
1050
|
+
const lines = text.replace(/^\uFEFF/, "").split(/\r?\n/);
|
|
1051
|
+
const open2 = lines.findIndex((l) => l.trim().length > 0);
|
|
1052
|
+
if (open2 === -1 || lines[open2]?.trim() !== "---") return null;
|
|
1053
|
+
const end = lines.findIndex((l, i) => i > open2 && l.trim() === "---");
|
|
1054
|
+
if (end === -1) return null;
|
|
1055
|
+
return lines.slice(open2 + 1, end);
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// src/adapters/claude.ts
|
|
1059
|
+
var NATIVE_TO_EVENT2 = {
|
|
1060
|
+
SessionStart: "session.start",
|
|
1061
|
+
UserPromptSubmit: "prompt",
|
|
1062
|
+
PreToolUse: "tool.before",
|
|
1063
|
+
PostToolUse: "tool.after",
|
|
1064
|
+
PostToolUseFailure: "tool.after",
|
|
1065
|
+
SubagentStart: "agent.start",
|
|
1066
|
+
SubagentStop: "agent.stop",
|
|
1067
|
+
Stop: "turn.end"
|
|
1068
|
+
};
|
|
1069
|
+
var TOOLS = {
|
|
1070
|
+
web: /^WebSearch$/,
|
|
1071
|
+
fetch: /^WebFetch$/,
|
|
1072
|
+
dispatch: /^(Agent|Task)$/,
|
|
1073
|
+
shell: /^Bash$/,
|
|
1074
|
+
edit: /^(Edit|Write|MultiEdit)$/,
|
|
1075
|
+
read: /^Read$/
|
|
1076
|
+
};
|
|
1077
|
+
function matcherOf(re) {
|
|
1078
|
+
return re.source.replace(/^\^\(?/, "").replace(/\)?\$$/, "");
|
|
1079
|
+
}
|
|
1080
|
+
var SESSION_START_MATCHER = "startup|clear|compact";
|
|
1081
|
+
function isRecord3(v) {
|
|
1082
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1083
|
+
}
|
|
1084
|
+
function str2(v) {
|
|
1085
|
+
return typeof v === "string" ? v : void 0;
|
|
1086
|
+
}
|
|
1087
|
+
function toolKind(name) {
|
|
1088
|
+
for (const kind of Object.keys(TOOLS)) if (TOOLS[kind].test(name)) return kind;
|
|
1089
|
+
return "other";
|
|
1090
|
+
}
|
|
1091
|
+
function canonicalTool2(name, input) {
|
|
1092
|
+
const kind = toolKind(name);
|
|
1093
|
+
switch (kind) {
|
|
1094
|
+
case "shell":
|
|
1095
|
+
return { name, kind, command: str2(input.command) ?? "" };
|
|
1096
|
+
case "edit":
|
|
1097
|
+
case "read": {
|
|
1098
|
+
const path = str2(input.file_path);
|
|
1099
|
+
return { name, kind, paths: path === void 0 ? [] : [path] };
|
|
1100
|
+
}
|
|
1101
|
+
case "dispatch": {
|
|
1102
|
+
const description = str2(input.description);
|
|
1103
|
+
return {
|
|
1104
|
+
name,
|
|
1105
|
+
kind,
|
|
1106
|
+
task: str2(input.prompt) ?? "",
|
|
1107
|
+
...description !== void 0 ? { description } : {}
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
case "web":
|
|
1111
|
+
return { name, kind, query: str2(input.query) ?? "" };
|
|
1112
|
+
case "fetch":
|
|
1113
|
+
return { name, kind, url: str2(input.url) ?? "", prompt: str2(input.prompt) ?? "" };
|
|
1114
|
+
default:
|
|
1115
|
+
return { name, kind };
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
function toolResult(v) {
|
|
1119
|
+
if (typeof v === "string") return { text: v };
|
|
1120
|
+
if (!isRecord3(v)) return void 0;
|
|
1121
|
+
const out = {};
|
|
1122
|
+
const stdout = str2(v.stdout);
|
|
1123
|
+
const stderr = str2(v.stderr);
|
|
1124
|
+
const error = str2(v.error);
|
|
1125
|
+
if (stdout !== void 0) out.stdout = stdout;
|
|
1126
|
+
if (stderr !== void 0) out.stderr = stderr;
|
|
1127
|
+
if (error !== void 0) out.error = error;
|
|
1128
|
+
if (stdout === void 0 && stderr === void 0 && error === void 0) {
|
|
1129
|
+
const text = str2(v.text) ?? str2(v.content) ?? str2(v.result);
|
|
1130
|
+
if (text !== void 0) out.text = text;
|
|
1131
|
+
}
|
|
1132
|
+
return out;
|
|
1133
|
+
}
|
|
1134
|
+
function decode2(raw) {
|
|
1135
|
+
if (!isRecord3(raw)) return null;
|
|
1136
|
+
const native = str2(raw.hook_event_name);
|
|
1137
|
+
if (native === void 0) return null;
|
|
1138
|
+
const event = NATIVE_TO_EVENT2[native];
|
|
1139
|
+
if (event === void 0) return null;
|
|
1140
|
+
const session = str2(raw.session_id);
|
|
1141
|
+
if (session === void 0 || session.length === 0) return null;
|
|
1142
|
+
const input = {
|
|
1143
|
+
harness: "claude",
|
|
1144
|
+
event,
|
|
1145
|
+
native: { event: native },
|
|
1146
|
+
session,
|
|
1147
|
+
cwd: str2(raw.cwd) ?? "",
|
|
1148
|
+
raw
|
|
1149
|
+
};
|
|
1150
|
+
if (raw.agent_id !== void 0 && raw.agent_id !== null) {
|
|
1151
|
+
const id = raw.agent_id;
|
|
1152
|
+
if (typeof id !== "string" || !AGENT_ID_RE.test(id)) return null;
|
|
1153
|
+
input.agent = id;
|
|
1154
|
+
}
|
|
1155
|
+
const turn = str2(raw.prompt_id);
|
|
1156
|
+
if (turn !== void 0) input.turn = turn;
|
|
1157
|
+
const prompt = str2(raw.prompt);
|
|
1158
|
+
if (prompt !== void 0) input.prompt = prompt;
|
|
1159
|
+
const agentType = str2(raw.agent_type);
|
|
1160
|
+
if (agentType !== void 0) input.agentType = agentType;
|
|
1161
|
+
const lastMessage = str2(raw.last_assistant_message);
|
|
1162
|
+
if (lastMessage !== void 0) input.lastMessage = lastMessage;
|
|
1163
|
+
if (typeof raw.stop_hook_active === "boolean") input.stopFuse = raw.stop_hook_active;
|
|
1164
|
+
const source = str2(raw.source);
|
|
1165
|
+
if (source !== void 0) input.source = source;
|
|
1166
|
+
const path = str2(raw.transcript_path);
|
|
1167
|
+
const agentPath = str2(raw.agent_transcript_path);
|
|
1168
|
+
if (path !== void 0 || agentPath !== void 0) {
|
|
1169
|
+
input.transcript = {};
|
|
1170
|
+
if (path !== void 0) input.transcript.path = path;
|
|
1171
|
+
if (agentPath !== void 0) input.transcript.agentPath = agentPath;
|
|
1172
|
+
}
|
|
1173
|
+
if (event === "tool.before" || event === "tool.after") {
|
|
1174
|
+
const name = str2(raw.tool_name) ?? "";
|
|
1175
|
+
const tool = canonicalTool2(name, isRecord3(raw.tool_input) ? raw.tool_input : {});
|
|
1176
|
+
const callId = str2(raw.tool_use_id);
|
|
1177
|
+
if (callId !== void 0) tool.callId = callId;
|
|
1178
|
+
if (event === "tool.after") {
|
|
1179
|
+
if (native === "PostToolUseFailure") {
|
|
1180
|
+
tool.ok = false;
|
|
1181
|
+
if (typeof raw.error === "string") tool.result = { error: raw.error };
|
|
1182
|
+
else {
|
|
1183
|
+
const result = toolResult(raw.error);
|
|
1184
|
+
if (result !== void 0) tool.result = result;
|
|
1185
|
+
}
|
|
1186
|
+
} else {
|
|
1187
|
+
const result = toolResult(raw.tool_response);
|
|
1188
|
+
if (result !== void 0) tool.result = result;
|
|
1189
|
+
tool.ok = !(tool.kind === "shell" && hasErrorMarker((result?.stdout ?? "") + "\n" + (result?.stderr ?? "")));
|
|
1190
|
+
}
|
|
1191
|
+
if (typeof raw.is_interrupt === "boolean") tool.interrupted = raw.is_interrupt;
|
|
1192
|
+
}
|
|
1193
|
+
input.tool = tool;
|
|
1194
|
+
}
|
|
1195
|
+
return input;
|
|
1196
|
+
}
|
|
1197
|
+
function encode2(emit, input) {
|
|
1198
|
+
if (emit === null || emit.context === void 0 || emit.context.length === 0) return null;
|
|
1199
|
+
return {
|
|
1200
|
+
hookSpecificOutput: {
|
|
1201
|
+
hookEventName: input.native.event,
|
|
1202
|
+
additionalContext: emit.context.slice(0, CONTEXT_MAX)
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
function httpHandler(url, token, timeoutSeconds) {
|
|
1207
|
+
return {
|
|
1208
|
+
type: "http",
|
|
1209
|
+
url,
|
|
1210
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
1211
|
+
timeout: timeoutSeconds
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
function commandHandler2(shimPath, timeoutSeconds) {
|
|
1215
|
+
return {
|
|
1216
|
+
type: "command",
|
|
1217
|
+
command: `node ${JSON.stringify(shimPath)} --harness claude`,
|
|
1218
|
+
timeout: timeoutSeconds
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
var registrar2 = {
|
|
1222
|
+
configPath(home) {
|
|
1223
|
+
return claudeSettingsPath(home);
|
|
1224
|
+
},
|
|
1225
|
+
/**
|
|
1226
|
+
* 9 `http` entries and 2 `command` entries (02-redesign.md §4). SessionStart
|
|
1227
|
+
* and UserPromptSubmit run the shim because every turn begins with a prompt:
|
|
1228
|
+
* the daemon is then up before any tool-path fire of that turn.
|
|
1229
|
+
*/
|
|
1230
|
+
plan({ url, token, shimPath, timeoutSeconds }) {
|
|
1231
|
+
const http = [httpHandler(url, token, timeoutSeconds)];
|
|
1232
|
+
const command = [commandHandler2(shimPath, timeoutSeconds)];
|
|
1233
|
+
return [
|
|
1234
|
+
{ event: "SessionStart", matcher: SESSION_START_MATCHER, hooks: command },
|
|
1235
|
+
{ event: "UserPromptSubmit", hooks: command },
|
|
1236
|
+
// ONE entry for both web kinds. The arms are separate; the harness entry
|
|
1237
|
+
// is not, because a settings file with two PreToolUse entries whose
|
|
1238
|
+
// matchers overlap is two POSTs for one tool call.
|
|
1239
|
+
{
|
|
1240
|
+
event: "PreToolUse",
|
|
1241
|
+
matcher: `${matcherOf(TOOLS.web)}|${matcherOf(TOOLS.fetch)}`,
|
|
1242
|
+
hooks: http
|
|
1243
|
+
},
|
|
1244
|
+
{ event: "PreToolUse", matcher: matcherOf(TOOLS.dispatch), hooks: http },
|
|
1245
|
+
{
|
|
1246
|
+
event: "PreToolUse",
|
|
1247
|
+
matcher: `${matcherOf(TOOLS.edit)}|${matcherOf(TOOLS.shell)}`,
|
|
1248
|
+
hooks: http
|
|
1249
|
+
},
|
|
1250
|
+
{ event: "PostToolUse", matcher: matcherOf(TOOLS.shell), hooks: http },
|
|
1251
|
+
{ event: "PostToolUse", matcher: matcherOf(TOOLS.read), hooks: http },
|
|
1252
|
+
{ event: "PostToolUseFailure", matcher: matcherOf(TOOLS.shell), hooks: http },
|
|
1253
|
+
{ event: "SubagentStart", hooks: http },
|
|
1254
|
+
{ event: "SubagentStop", hooks: http },
|
|
1255
|
+
{ event: "Stop", hooks: http }
|
|
1256
|
+
];
|
|
1257
|
+
},
|
|
1258
|
+
grant: {
|
|
1259
|
+
path: claudeSettingsPath,
|
|
1260
|
+
inspect: inspectClaudeGrant,
|
|
1261
|
+
write: wireFreeVerbAllowlist
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
var claudeAdapter = { id: "claude", decode: decode2, encode: encode2, registrar: registrar2 };
|
|
1265
|
+
|
|
1266
|
+
// src/adapters/registry.ts
|
|
1267
|
+
var ADAPTERS = {
|
|
1268
|
+
claude: claudeAdapter,
|
|
1269
|
+
codex: codexAdapter
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
// src/lib/harness-hooks.ts
|
|
1273
|
+
import { chmod as chmod2, lstat as lstat2, readFile as readFile2, realpath as realpath2, stat as stat3 } from "node:fs/promises";
|
|
1274
|
+
import { resolve } from "node:path";
|
|
1275
|
+
var OUR_HOOK_FILES = ["tenjin-daemon.mjs", "tenjin-shim.mjs"];
|
|
1276
|
+
var OUR_HOOK_COMMAND = "tenjin hook ";
|
|
1277
|
+
var LOOP_URL_RE = new RegExp(`^http://127\\.0\\.0\\.1:\\d+/hook/(?:${HARNESSES.join("|")})$`);
|
|
1278
|
+
var HOOK_TIMEOUT_SECONDS = HARNESS_MS / 1e3;
|
|
1279
|
+
function isPlainObject2(value) {
|
|
1280
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1281
|
+
}
|
|
1282
|
+
function ownsHandler(handler, dataDir2) {
|
|
1283
|
+
if (!isPlainObject2(handler)) return false;
|
|
1284
|
+
if (handler.type === "mcp_tool") {
|
|
1285
|
+
return handler.server === LEGACY_MCP_SERVER_NAME && handler.tool === HOOK_TOOL;
|
|
1286
|
+
}
|
|
1287
|
+
const url = handler.url;
|
|
1288
|
+
if (typeof url === "string" && LOOP_URL_RE.test(url)) return true;
|
|
1289
|
+
const command = handler.command;
|
|
1290
|
+
if (typeof command !== "string") return false;
|
|
1291
|
+
if (command.includes(OUR_HOOK_COMMAND)) return true;
|
|
1292
|
+
if (OUR_HOOK_FILES.some((file) => command.includes(file))) return true;
|
|
1293
|
+
return command.includes(hooksDir(resolve(dataDir2)));
|
|
1294
|
+
}
|
|
1295
|
+
function ownsHookEntry(entry, dataDir2) {
|
|
1296
|
+
if (!isPlainObject2(entry)) return false;
|
|
1297
|
+
const handlers = entry.hooks;
|
|
1298
|
+
if (!Array.isArray(handlers)) return false;
|
|
1299
|
+
return handlers.some((h) => ownsHandler(h, dataDir2));
|
|
1300
|
+
}
|
|
1301
|
+
async function inspectHooksFile(declaredPath) {
|
|
1302
|
+
const entry = await lstat2(declaredPath).catch(() => null);
|
|
1303
|
+
let path = declaredPath;
|
|
1304
|
+
if (entry !== null) {
|
|
1305
|
+
try {
|
|
1306
|
+
path = await realpath2(declaredPath);
|
|
1307
|
+
} catch (err) {
|
|
1308
|
+
return {
|
|
1309
|
+
refusal: {
|
|
1310
|
+
reason: "unresolvable",
|
|
1311
|
+
path: declaredPath,
|
|
1312
|
+
message: `${declaredPath} could not be resolved (${err.message}); its "hooks" key was left exactly as it is.`
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
let settings = {};
|
|
1318
|
+
let raw = null;
|
|
1319
|
+
if (entry !== null) {
|
|
1320
|
+
try {
|
|
1321
|
+
raw = await readFile2(path, "utf8");
|
|
1322
|
+
} catch (err) {
|
|
1323
|
+
return {
|
|
1324
|
+
refusal: {
|
|
1325
|
+
reason: "unreadable",
|
|
1326
|
+
path,
|
|
1327
|
+
message: `${path} could not be read (${err.message}); no hooks were registered.`
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
let parsed;
|
|
1332
|
+
try {
|
|
1333
|
+
parsed = JSON.parse(raw);
|
|
1334
|
+
} catch (err) {
|
|
1335
|
+
return {
|
|
1336
|
+
refusal: {
|
|
1337
|
+
reason: "unparsable",
|
|
1338
|
+
path,
|
|
1339
|
+
message: `${path} is not valid JSON (${err.message}); its "hooks" key was left exactly as it is.`
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
if (!isPlainObject2(parsed)) {
|
|
1344
|
+
return {
|
|
1345
|
+
refusal: {
|
|
1346
|
+
reason: "unexpected-shape",
|
|
1347
|
+
path,
|
|
1348
|
+
message: `${path} is not a JSON object; its "hooks" key was left exactly as it is.`
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
settings = parsed;
|
|
1353
|
+
}
|
|
1354
|
+
const hooksValue = settings.hooks;
|
|
1355
|
+
if (hooksValue !== void 0 && !isPlainObject2(hooksValue)) {
|
|
1356
|
+
return {
|
|
1357
|
+
refusal: {
|
|
1358
|
+
reason: "unexpected-shape",
|
|
1359
|
+
path,
|
|
1360
|
+
message: `${path} has a "hooks" key that is not an object; its "hooks" key was left exactly as it is.`
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
const hooks = {};
|
|
1365
|
+
for (const [event, list] of Object.entries(hooksValue ?? {})) {
|
|
1366
|
+
if (!Array.isArray(list)) {
|
|
1367
|
+
return {
|
|
1368
|
+
refusal: {
|
|
1369
|
+
reason: "unexpected-shape",
|
|
1370
|
+
path,
|
|
1371
|
+
message: `${path} has a "hooks.${event}" that is not an array of entries; its "hooks" key was left exactly as it is.`
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
hooks[event] = list;
|
|
1376
|
+
}
|
|
1377
|
+
return { path, raw, settings, hooks };
|
|
1378
|
+
}
|
|
1379
|
+
async function readHooksObject(path) {
|
|
1380
|
+
try {
|
|
1381
|
+
const parsed = JSON.parse(await readFile2(path, "utf8"));
|
|
1382
|
+
const hooks = isPlainObject2(parsed) ? parsed.hooks : void 0;
|
|
1383
|
+
return isPlainObject2(hooks) ? hooks : null;
|
|
1384
|
+
} catch {
|
|
1385
|
+
return null;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
function urlPort(url) {
|
|
1389
|
+
try {
|
|
1390
|
+
const port = Number(new URL(url).port);
|
|
1391
|
+
return Number.isFinite(port) && port > 0 ? port : null;
|
|
1392
|
+
} catch {
|
|
1393
|
+
return null;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
async function registeredHooks(adapter, homeDir, dataDir2, env = process.env) {
|
|
1397
|
+
const path = adapter.registrar.configPath(homeDir, env);
|
|
1398
|
+
const hooks = await readHooksObject(path);
|
|
1399
|
+
const out = { path, entries: 0, port: null, handlers: [] };
|
|
1400
|
+
if (hooks === null) return out;
|
|
1401
|
+
for (const [event, list] of Object.entries(hooks)) {
|
|
1402
|
+
if (!Array.isArray(list)) continue;
|
|
1403
|
+
list.forEach((entry, groupIndex) => {
|
|
1404
|
+
if (!ownsHookEntry(entry, dataDir2)) return;
|
|
1405
|
+
out.entries += 1;
|
|
1406
|
+
entry.hooks.forEach((handler, handlerIndex) => {
|
|
1407
|
+
if (!ownsHandler(handler, dataDir2)) return;
|
|
1408
|
+
out.handlers.push({ event, groupIndex, handlerIndex });
|
|
1409
|
+
if (!isPlainObject2(handler) || typeof handler.url !== "string") return;
|
|
1410
|
+
out.port ??= urlPort(handler.url);
|
|
1411
|
+
});
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
return out;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// src/lib/harness-presence.ts
|
|
1418
|
+
async function installedHarnessInPlay(adapter, home, dataDir2, options = {}) {
|
|
1419
|
+
const env = options.env ?? process.env;
|
|
1420
|
+
const which = options.which ?? ((bin) => onPath(bin, env));
|
|
1421
|
+
if (harnessInPlay(
|
|
1422
|
+
home,
|
|
1423
|
+
harnessTargetDir(home, adapter.id),
|
|
1424
|
+
detectHarnesses(home, which),
|
|
1425
|
+
options.requested ?? []
|
|
1426
|
+
)) {
|
|
1427
|
+
return true;
|
|
1428
|
+
}
|
|
1429
|
+
return (await registeredHooks(adapter, home, dataDir2, env)).entries > 0;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// src/router/spend-question.ts
|
|
1433
|
+
var ROUTER_DEFAULTS = {
|
|
1434
|
+
maxAutoSpend: DEFAULT_MAX_AUTO_SPEND,
|
|
1435
|
+
sessionBudget: DEFAULT_SESSION_BUDGET
|
|
1436
|
+
};
|
|
1437
|
+
function shownLimits(config) {
|
|
1438
|
+
return {
|
|
1439
|
+
maxAutoSpend: config.maxAutoSpend ?? ROUTER_DEFAULTS.maxAutoSpend,
|
|
1440
|
+
sessionBudget: config.sessionBudget ?? ROUTER_DEFAULTS.sessionBudget
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
function limitsUsd(limits) {
|
|
1444
|
+
return {
|
|
1445
|
+
maxAutoSpend: toMoney(limits.maxAutoSpend).usd,
|
|
1446
|
+
sessionBudget: limits.sessionBudget === "none" ? "none" : toMoney(limits.sessionBudget).usd
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
var ROUTING_FEE_TERMS = `Routing costs $${usd(ROUTING_FEE_ATOMIC)} a call, paid from channel deposits of up to $${usd(CHANNEL_DEPOSIT_ATOMIC)} that stay yours until spent; each deposit counts against these limits.`;
|
|
1450
|
+
var FEE_APPROVAL = "Either answer also approves the routing fee.";
|
|
1451
|
+
var DEFAULTS_USD = limitsUsd(ROUTER_DEFAULTS);
|
|
1452
|
+
var SPEND_QUESTION = `Use the defaults ($${DEFAULTS_USD.sessionBudget} a day, $${DEFAULTS_USD.maxAutoSpend} a call) or set your own limits.`;
|
|
1453
|
+
function spendChoiceQuestion() {
|
|
1454
|
+
return `${SPEND_QUESTION} ${ROUTING_FEE_TERMS} ${FEE_APPROVAL}`;
|
|
1455
|
+
}
|
|
1456
|
+
function spendOptions(install) {
|
|
1457
|
+
return [
|
|
1458
|
+
{ id: "default", label: "Use the defaults", recommended: true, command: `${install} --yes` },
|
|
1459
|
+
{
|
|
1460
|
+
id: "custom",
|
|
1461
|
+
label: "Set my own limits",
|
|
1462
|
+
recommended: false,
|
|
1463
|
+
ask: [
|
|
1464
|
+
"The most Tenjin may pay in a day, in USD, or none for no daily limit",
|
|
1465
|
+
"The most it may pay for one call, in USD, at least 0.25"
|
|
1466
|
+
],
|
|
1467
|
+
command: `${install} --max-auto-spend <usd> --session-budget <usd|none>`
|
|
1468
|
+
}
|
|
1469
|
+
];
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// src/commands/config.ts
|
|
1473
|
+
var SHELF_KEYS = /* @__PURE__ */ new Set([
|
|
1474
|
+
"allowlistCreators",
|
|
1475
|
+
"publicShelfUrl",
|
|
1476
|
+
"shelfBypassSecret",
|
|
1477
|
+
"evalCohort",
|
|
1478
|
+
...PUBLISH_CONFIG_KEYS,
|
|
1479
|
+
...HOOKS_CONFIG_KEYS,
|
|
1480
|
+
...LOOP_CONFIG_KEYS,
|
|
1481
|
+
...TEAM_CONFIG_KEYS
|
|
1482
|
+
]);
|
|
1483
|
+
var KEY_WIDTH = Math.max(
|
|
1484
|
+
...[...CONFIG_KEYS, ...UPDATE_CONFIG_KEYS, ...ROUTER_CONFIG_KEYS, ...EXPERIMENTAL_CONFIG_KEYS].filter((key) => !SHELF_KEYS.has(key)).map((key) => key.length)
|
|
1485
|
+
);
|
|
1486
|
+
var KEY_DESCRIPTIONS = {
|
|
1487
|
+
maxAutoSpend: "automatic router limit per call, the runaway guard: at least 0.25 (the default); router.enabled false turns the router off",
|
|
1488
|
+
sessionBudget: "automatic router daily limit, the main control (5 by default): 0 blocks automatic spend, none removes the ceiling",
|
|
1489
|
+
sendMaxAmount: "hard cap per tenjin wallet send; unset = send refuses until set, 0 disables send, none = uncapped; never bypassed by --yes",
|
|
1490
|
+
allowlistCreators: "only auto-pay these creators (empty = any)",
|
|
1491
|
+
baseUrl: "Tenjin API base URL the router asks",
|
|
1492
|
+
publicShelfUrl: "the public marketplace, consume-only: the second shelf a team-mode search falls through to",
|
|
1493
|
+
shelfBypassSecret: "the team shelf's Vercel protection-bypass secret; setting it is what turns team mode on (printed as set/unset)",
|
|
1494
|
+
rpcUrl: "Base RPC endpoint for balance reads",
|
|
1495
|
+
evalCohort: "opt in to the search evaluation cohort",
|
|
1496
|
+
bazaarRegistries: "x402 registries used to verify direct-payment listings",
|
|
1497
|
+
"publish.mode": "review=always ask, auto=ask on findings, full-auto=only hard blocks stop it",
|
|
1498
|
+
"publish.defaultPrice": "price used when none is given",
|
|
1499
|
+
"publish.ackServerWarnings": "whether a yes covers the MARKETPLACE scan's warn findings: mode=only the ones an earlier render already showed you (full-auto still acks), on=any of them, off=never",
|
|
1500
|
+
"hooks.prompt": "answer the prompt you just typed with what the shelves already know",
|
|
1501
|
+
"hooks.web-search": "ask Tenjin before the agent runs a WebSearch",
|
|
1502
|
+
"hooks.web-fetch": "ask Tenjin before the agent fetches a page",
|
|
1503
|
+
"hooks.subagent": "ask Tenjin with a subagent work order (the most sensitive payload any hook sees) and hand the answer to the child at its start",
|
|
1504
|
+
"hooks.failure": "answer a failing command with the fix this machine or a shelf already has",
|
|
1505
|
+
"hooks.publish": "the turn-end ask to publish what this turn settled, spoken to you and to each subagent at its own end",
|
|
1506
|
+
"hooks.primer": "one-paragraph search-first primer at session start",
|
|
1507
|
+
"update.mode": "nudge=report a newer version (stderr line, JSON envelope, hook output), off=neither report nor ask npm",
|
|
1508
|
+
"loop.human_wait_ms": "ms a hook fire may take when a human is waiting on it (prompt, Stop, SessionStart)",
|
|
1509
|
+
"loop.tool_wait_ms": "ms a hook fire may take when a tool call is waiting on it",
|
|
1510
|
+
"loop.idle_exit_min": "minutes without a hook fire before the loop daemon exits",
|
|
1511
|
+
"loop.port": "the loop daemon's loopback port; null derives one from the data dir (set only when doctor reports a foreign listener)",
|
|
1512
|
+
"team.publicFallback": "on=a team-shelf miss falls through to the public marketplace, off=team-only (public-only lookup stages are dropped)",
|
|
1513
|
+
"router.enabled": "false stops every router hook and the request tool; --project sets it for this repository, --project --local for you alone in it",
|
|
1514
|
+
"router.context": "session=a hook packet carries up to six prior messages, turn=the current turn only; --project and --local as for router.enabled",
|
|
1515
|
+
"experimental.bazaar": "EXPERIMENTAL. on=the router may also suggest unreviewed sellers from Coinbase's open x402 Bazaar, off=curated services and Tenjin's reviewed list only"
|
|
1516
|
+
};
|
|
1517
|
+
var EXPERIMENTAL_BAZAAR_WARNING = "Experimental: the router may now also suggest sellers from Coinbase's open x402 Bazaar. They are unreviewed third parties, Tenjin has not checked them, matches can be noisy, prices can vary with the input, and payments are real, under your spend limits. To find them, short snippets of your prompts are sent to Coinbase's public Bazaar search. Tenjin's reviewed list stays on either way. Turn this off with `tenjin config set experimental.bazaar off`.";
|
|
1518
|
+
function isExperimentalKey(key) {
|
|
1519
|
+
return EXPERIMENTAL_CONFIG_KEYS.includes(key);
|
|
1520
|
+
}
|
|
1521
|
+
function isLoopKey(key) {
|
|
1522
|
+
return LOOP_CONFIG_KEYS.includes(key);
|
|
1523
|
+
}
|
|
1524
|
+
function isTeamKey(key) {
|
|
1525
|
+
return TEAM_CONFIG_KEYS.includes(key);
|
|
1526
|
+
}
|
|
1527
|
+
function isRouterKey(key) {
|
|
1528
|
+
return ROUTER_CONFIG_KEYS.includes(key);
|
|
1529
|
+
}
|
|
1530
|
+
function renderRouterSetting(key, settings) {
|
|
1531
|
+
const { value, source, path } = key === "router.enabled" ? settings.enabled : settings.context;
|
|
1532
|
+
return { value, source, ...path !== void 0 ? { path } : {} };
|
|
1533
|
+
}
|
|
1534
|
+
async function resolveRouterFromContext(ctx) {
|
|
1535
|
+
return routerSettings({ cwd: process.cwd(), dataDir: ctx.dataDir });
|
|
1536
|
+
}
|
|
1537
|
+
function renderLoopSetting(key, settings) {
|
|
1538
|
+
const field = key.slice("loop.".length);
|
|
1539
|
+
const { value, source } = settings.loop[field];
|
|
1540
|
+
return { value: value === null ? "null" : String(value), source };
|
|
1541
|
+
}
|
|
1542
|
+
function isPublishKey(key) {
|
|
1543
|
+
return PUBLISH_CONFIG_KEYS.includes(key);
|
|
1544
|
+
}
|
|
1545
|
+
function isHooksKey(key) {
|
|
1546
|
+
return HOOKS_CONFIG_KEYS.includes(key);
|
|
1547
|
+
}
|
|
1548
|
+
function isUpdateKey(key) {
|
|
1549
|
+
return UPDATE_CONFIG_KEYS.includes(key);
|
|
1550
|
+
}
|
|
1551
|
+
async function runConfigList(ctx) {
|
|
1552
|
+
const settings = await resolveFromContext(ctx);
|
|
1553
|
+
const data = {};
|
|
1554
|
+
const humanLines = [];
|
|
1555
|
+
const show = (key, line) => {
|
|
1556
|
+
if (!SHELF_KEYS.has(key)) humanLines.push(line);
|
|
1557
|
+
};
|
|
1558
|
+
for (const key of CONFIG_KEYS) {
|
|
1559
|
+
const entry = renderSetting(key, settings[key].value, settings[key].source);
|
|
1560
|
+
data[key] = entry;
|
|
1561
|
+
show(key, describedLine(key, entry));
|
|
1562
|
+
}
|
|
1563
|
+
for (const key of PUBLISH_CONFIG_KEYS) {
|
|
1564
|
+
const entry = renderPublishSetting(key, settings);
|
|
1565
|
+
data[key] = entry;
|
|
1566
|
+
show(key, describedLine(key, entry, downgradeNote(key, settings)));
|
|
1567
|
+
}
|
|
1568
|
+
for (const key of HOOKS_CONFIG_KEYS) {
|
|
1569
|
+
const entry = renderHooksSetting(key, settings);
|
|
1570
|
+
data[key] = entry;
|
|
1571
|
+
show(key, describedLine(key, entry));
|
|
1572
|
+
}
|
|
1573
|
+
for (const key of UPDATE_CONFIG_KEYS) {
|
|
1574
|
+
const entry = {
|
|
1575
|
+
value: settings.updateMode.value,
|
|
1576
|
+
source: settings.updateMode.source
|
|
1577
|
+
};
|
|
1578
|
+
data[key] = entry;
|
|
1579
|
+
show(key, describedLine(key, entry));
|
|
1580
|
+
}
|
|
1581
|
+
for (const key of LOOP_CONFIG_KEYS) {
|
|
1582
|
+
const entry = renderLoopSetting(key, settings);
|
|
1583
|
+
data[key] = entry;
|
|
1584
|
+
show(key, describedLine(key, entry));
|
|
1585
|
+
}
|
|
1586
|
+
for (const key of TEAM_CONFIG_KEYS) {
|
|
1587
|
+
const entry = {
|
|
1588
|
+
value: settings.teamPublicFallback.value,
|
|
1589
|
+
source: settings.teamPublicFallback.source
|
|
1590
|
+
};
|
|
1591
|
+
data[key] = entry;
|
|
1592
|
+
show(key, describedLine(key, entry));
|
|
1593
|
+
}
|
|
1594
|
+
const router = await resolveRouterFromContext(ctx);
|
|
1595
|
+
for (const key of ROUTER_CONFIG_KEYS) {
|
|
1596
|
+
const entry = renderRouterSetting(key, router);
|
|
1597
|
+
data[key] = entry;
|
|
1598
|
+
show(key, describedLine(key, entry));
|
|
1599
|
+
}
|
|
1600
|
+
for (const key of EXPERIMENTAL_CONFIG_KEYS) {
|
|
1601
|
+
const entry = {
|
|
1602
|
+
value: settings.experimentalBazaar.value,
|
|
1603
|
+
source: settings.experimentalBazaar.source
|
|
1604
|
+
};
|
|
1605
|
+
data[key] = entry;
|
|
1606
|
+
show(key, describedLine(key, entry));
|
|
1607
|
+
}
|
|
1608
|
+
return { data, humanLines };
|
|
1609
|
+
}
|
|
1610
|
+
async function runConfigGet({ key }, ctx) {
|
|
1611
|
+
if (isPublishKey(key)) {
|
|
1612
|
+
const settings2 = await resolveFromContext(ctx);
|
|
1613
|
+
const entry2 = renderPublishSetting(key, settings2);
|
|
1614
|
+
return {
|
|
1615
|
+
data: { key, ...entry2 },
|
|
1616
|
+
humanLines: [withNote(formatLine(key, entry2), downgradeNote(key, settings2))]
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
if (isHooksKey(key)) {
|
|
1620
|
+
const entry2 = renderHooksSetting(key, await resolveFromContext(ctx));
|
|
1621
|
+
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
1622
|
+
}
|
|
1623
|
+
if (isUpdateKey(key)) {
|
|
1624
|
+
const { updateMode } = await resolveFromContext(ctx);
|
|
1625
|
+
const entry2 = { value: updateMode.value, source: updateMode.source };
|
|
1626
|
+
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
1627
|
+
}
|
|
1628
|
+
if (isLoopKey(key)) {
|
|
1629
|
+
const entry2 = renderLoopSetting(key, await resolveFromContext(ctx));
|
|
1630
|
+
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
1631
|
+
}
|
|
1632
|
+
if (isTeamKey(key)) {
|
|
1633
|
+
const { teamPublicFallback } = await resolveFromContext(ctx);
|
|
1634
|
+
const entry2 = {
|
|
1635
|
+
value: teamPublicFallback.value,
|
|
1636
|
+
source: teamPublicFallback.source
|
|
1637
|
+
};
|
|
1638
|
+
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
1639
|
+
}
|
|
1640
|
+
if (isRouterKey(key)) {
|
|
1641
|
+
const entry2 = renderRouterSetting(key, await resolveRouterFromContext(ctx));
|
|
1642
|
+
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
1643
|
+
}
|
|
1644
|
+
if (isExperimentalKey(key)) {
|
|
1645
|
+
const { experimentalBazaar } = await resolveFromContext(ctx);
|
|
1646
|
+
const entry2 = {
|
|
1647
|
+
value: experimentalBazaar.value,
|
|
1648
|
+
source: experimentalBazaar.source
|
|
1649
|
+
};
|
|
1650
|
+
return { data: { key, ...entry2 }, humanLines: [formatLine(key, entry2)] };
|
|
1651
|
+
}
|
|
1652
|
+
const configKey = assertKey(key);
|
|
1653
|
+
const settings = await resolveFromContext(ctx);
|
|
1654
|
+
const entry = renderSetting(configKey, settings[configKey].value, settings[configKey].source);
|
|
1655
|
+
return { data: { key: configKey, ...entry }, humanLines: [formatLine(configKey, entry)] };
|
|
1656
|
+
}
|
|
1657
|
+
async function runConfigSet({
|
|
1658
|
+
key,
|
|
1659
|
+
value,
|
|
1660
|
+
project,
|
|
1661
|
+
local
|
|
1662
|
+
}, ctx, deps = {}) {
|
|
1663
|
+
if (local === true && project !== true) {
|
|
1664
|
+
throw new CliError("USAGE", "--local names the personal project file, so it needs --project", {
|
|
1665
|
+
fix: `Run \`tenjin config set --project --local ${key} ${value}\`.`
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
if (isRouterKey(key)) {
|
|
1669
|
+
return setRouterKey(key, value, ctx, project === true ? { local: local === true } : void 0);
|
|
1670
|
+
}
|
|
1671
|
+
if (project === true) {
|
|
1672
|
+
throw new CliError("USAGE", `${key} is not a project key`, {
|
|
1673
|
+
fix: `--project applies to ${ROUTER_CONFIG_KEYS.join(" and ")} only; drop it to set ${key} for this machine.`
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
if (isPublishKey(key)) return setPublishKey(key, value, ctx, deps);
|
|
1677
|
+
if (isHooksKey(key)) return setHooksKey(key, value, ctx);
|
|
1678
|
+
if (isUpdateKey(key)) return setUpdateKey(key, value, ctx);
|
|
1679
|
+
if (isLoopKey(key)) return setLoopKey(key, value, ctx);
|
|
1680
|
+
if (isTeamKey(key)) return setTeamKey(key, value, ctx);
|
|
1681
|
+
if (isExperimentalKey(key)) return setExperimentalKey(key, value, ctx);
|
|
1682
|
+
const configKey = assertKey(key);
|
|
1683
|
+
const stored = parseValue(configKey, value);
|
|
1684
|
+
await persist(ctx.dataDir, (existing) => ({ ...existing, [configKey]: stored }));
|
|
1685
|
+
const entry = renderSetting(configKey, stored, "file");
|
|
1686
|
+
const warning = await halfWiredTeamShelf(configKey, ctx.dataDir);
|
|
1687
|
+
return {
|
|
1688
|
+
data: { key: configKey, ...entry, ...warning !== void 0 ? { warning } : {} },
|
|
1689
|
+
humanLines: [formatLine(configKey, entry), ...warning !== void 0 ? [warning] : []]
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
async function halfWiredTeamShelf(configKey, dataDir2) {
|
|
1693
|
+
if (configKey !== "shelfBypassSecret" && configKey !== "baseUrl" && configKey !== "publicShelfUrl") {
|
|
1694
|
+
return void 0;
|
|
1695
|
+
}
|
|
1696
|
+
const config = await loadRawConfig(dataDir2).catch(() => void 0);
|
|
1697
|
+
if (config === void 0) return void 0;
|
|
1698
|
+
const s = resolveSettings({ config, flags: {}, env: {} });
|
|
1699
|
+
if (s.shelfBypassSecret.value.length === 0) return void 0;
|
|
1700
|
+
const baseUrl = s.baseUrl.value;
|
|
1701
|
+
if (isTeamShelfOrigin(new URL(baseUrl).origin, s.publicShelfUrl.value)) return void 0;
|
|
1702
|
+
const isProduction = isSameDeployment(new URL(baseUrl).origin, PRODUCTION_ORIGIN);
|
|
1703
|
+
const cause = isProduction ? `baseUrl is the public marketplace (${baseUrl})` : `baseUrl and publicShelfUrl are the same shelf (${baseUrl})`;
|
|
1704
|
+
const fix = isProduction ? "Point baseUrl at the team deployment to finish team mode: `tenjin config set baseUrl <team shelf url>`." : `A team shelf must differ from the shelf it falls through to: \`tenjin config set publicShelfUrl ${PRODUCTION_ORIGIN}\`.`;
|
|
1705
|
+
return `Warning: shelfBypassSecret is set, but ${cause}, so this machine stays in PUBLIC mode \u2014 publishes go to the marketplace with the scan\u2019s warn tier and the confirm cascade on. ` + fix;
|
|
1706
|
+
}
|
|
1707
|
+
async function setPublishKey(key, value, ctx, deps) {
|
|
1708
|
+
const entry = key === "publish.mode" ? { value: parsePublishMode(value), source: "file" } : key === "publish.ackServerWarnings" ? { value: parseAckServerWarnings(value, key), source: "file" } : { value: toMoney(parseUsdToAtomic(value)), source: "file" };
|
|
1709
|
+
const subkey = key === "publish.mode" ? "mode" : key === "publish.ackServerWarnings" ? "ackServerWarnings" : "defaultPrice";
|
|
1710
|
+
const stored = key === "publish.defaultPrice" ? entry.value.atomic : entry.value;
|
|
1711
|
+
const persistEntry = async () => persist(ctx.dataDir, (existing) => ({
|
|
1712
|
+
...existing,
|
|
1713
|
+
publish: { ...existing.publish, [subkey]: stored }
|
|
1714
|
+
}));
|
|
1715
|
+
const humanLines = [formatLine(key, entry)];
|
|
1716
|
+
if (key !== "publish.mode") {
|
|
1717
|
+
await persistEntry();
|
|
1718
|
+
return { data: { key, ...entry }, humanLines };
|
|
1719
|
+
}
|
|
1720
|
+
const allowlist = await syncPublishRule(entry.value, ctx, deps);
|
|
1721
|
+
const failure = grantSyncFailure(allowlist);
|
|
1722
|
+
if (failure !== void 0) {
|
|
1723
|
+
throw new CliError(
|
|
1724
|
+
"REFUSED",
|
|
1725
|
+
`publish.mode was not changed because the ${failure.harness} grant could not be updated: ${failure.reason}`,
|
|
1726
|
+
{
|
|
1727
|
+
fix: failure.fix ?? `Fix the permissions for ${failure.path}, then re-run \`tenjin config set publish.mode ${entry.value}\`.`,
|
|
1728
|
+
details: { key, value: entry.value, allowlist }
|
|
1729
|
+
}
|
|
1730
|
+
);
|
|
1731
|
+
}
|
|
1732
|
+
await persistEntry();
|
|
1733
|
+
return {
|
|
1734
|
+
data: { key, ...entry, allowlist },
|
|
1735
|
+
humanLines: [...humanLines, ...allowlistLines(allowlist)]
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
function grantSyncFailure(sync) {
|
|
1739
|
+
for (const [harness, result] of Object.entries(sync.byHarness)) {
|
|
1740
|
+
if ("error" in result && result.error !== void 0) {
|
|
1741
|
+
return { harness, path: result.path, reason: result.error };
|
|
1742
|
+
}
|
|
1743
|
+
if ("warning" in result && result.warning !== void 0) {
|
|
1744
|
+
return {
|
|
1745
|
+
harness,
|
|
1746
|
+
path: result.path ?? "(unknown path)",
|
|
1747
|
+
reason: result.warning,
|
|
1748
|
+
...result.fix !== void 0 ? { fix: result.fix } : {}
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return void 0;
|
|
1753
|
+
}
|
|
1754
|
+
function publishRuleQuestion(mode, pending, harnesses) {
|
|
1755
|
+
const gated = new Set(MODE_GATED_RULES);
|
|
1756
|
+
const others = pending.filter((rule) => !gated.has(rule)).length;
|
|
1757
|
+
const also = others > 0 ? ` Also adds the ${others} command-grant rule(s) \`tenjin install\` writes.` : "";
|
|
1758
|
+
const targets = harnesses.map(
|
|
1759
|
+
(harness) => harness === "claude" ? "Claude Code" : harness === "codex" ? "Codex" : harness
|
|
1760
|
+
).join(" and ");
|
|
1761
|
+
return `publish.mode ${mode} is unattended only if ${targets} carries the matching grant for ${MODE_GATED_RULES.join(" and ")}. Update the ${targets} grant now?${also}`;
|
|
1762
|
+
}
|
|
1763
|
+
async function syncPublishRule(mode, ctx, deps) {
|
|
1764
|
+
const home = deps.homeDir ?? homedir();
|
|
1765
|
+
const nothing = { byHarness: {} };
|
|
1766
|
+
const write = async () => {
|
|
1767
|
+
const result = await (deps.wireAllowlist ?? wireFreeVerbAllowlist)(home, mode);
|
|
1768
|
+
if (result.skipped !== void 0) {
|
|
1769
|
+
return {
|
|
1770
|
+
byHarness: { claude: result },
|
|
1771
|
+
skipped: "unwritable",
|
|
1772
|
+
...result.fix !== void 0 ? { pointer: result.fix } : {}
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
return { byHarness: { claude: result } };
|
|
1776
|
+
};
|
|
1777
|
+
const adapters = deps.adapters ?? ADAPTERS;
|
|
1778
|
+
const env = deps.env ?? process.env;
|
|
1779
|
+
const which = deps.which ?? ((bin) => onPath(bin, env));
|
|
1780
|
+
const requested = await loadRawConfig(ctx.dataDir).then((config) => config.install?.harness ?? []).catch(() => []);
|
|
1781
|
+
const inPlay = deps.harnessesInPlay ?? (await Promise.all(
|
|
1782
|
+
Object.values(adapters).map(async (adapter) => ({
|
|
1783
|
+
adapter,
|
|
1784
|
+
selected: await installedHarnessInPlay(adapter, home, ctx.dataDir, {
|
|
1785
|
+
env,
|
|
1786
|
+
which,
|
|
1787
|
+
requested
|
|
1788
|
+
})
|
|
1789
|
+
}))
|
|
1790
|
+
)).filter((entry) => entry.selected).map((entry) => entry.adapter.id);
|
|
1791
|
+
const selectedAdapters = inPlay.map((harness) => adapters[harness]);
|
|
1792
|
+
const isClaude = inPlay.includes("claude");
|
|
1793
|
+
const withOtherGrants = async (sync) => {
|
|
1794
|
+
const byHarness = { ...sync.byHarness };
|
|
1795
|
+
for (const adapter of selectedAdapters) {
|
|
1796
|
+
if (adapter.id === "claude" || adapter.registrar.grant === void 0) continue;
|
|
1797
|
+
const result = await adapter.registrar.grant.write(home, mode, env);
|
|
1798
|
+
byHarness[adapter.id] = result;
|
|
1799
|
+
}
|
|
1800
|
+
return { ...sync, byHarness };
|
|
1801
|
+
};
|
|
1802
|
+
if (selectedAdapters.every((adapter) => adapter.registrar.grant === void 0)) {
|
|
1803
|
+
return { ...nothing, skipped: "not-claude" };
|
|
1804
|
+
}
|
|
1805
|
+
const probe = isClaude ? await (deps.inspectAllowlist ?? inspectFreeVerbRules)(home, mode) : { pending: [] };
|
|
1806
|
+
const gated = new Set(MODE_GATED_RULES);
|
|
1807
|
+
const missing = (probe.pending ?? []).filter((r) => gated.has(r));
|
|
1808
|
+
const pointer = modeGatedPointer(mode, missing) ?? void 0;
|
|
1809
|
+
if (mode === "review") {
|
|
1810
|
+
const retracted = isClaude ? await (deps.retractModeGated ?? retractModeGatedRules)(home) : void 0;
|
|
1811
|
+
if (retracted?.skipped !== void 0) {
|
|
1812
|
+
return {
|
|
1813
|
+
...nothing,
|
|
1814
|
+
skipped: "unwritable",
|
|
1815
|
+
...retracted.fix !== void 0 ? { pointer: retracted.fix } : {}
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
return await withOtherGrants({
|
|
1819
|
+
byHarness: retracted === void 0 ? {} : { claude: retracted }
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
if (probe.satisfied !== void 0 && selectedAdapters.length === 1 && isClaude) return nothing;
|
|
1823
|
+
const canPrompt = ctx.flags.json === true ? false : deps.isInteractive ?? Boolean(process.stdin.isTTY);
|
|
1824
|
+
if (!canPrompt) {
|
|
1825
|
+
return { ...nothing, skipped: "no-tty", ...pointer ? { pointer } : {} };
|
|
1826
|
+
}
|
|
1827
|
+
const confirm = deps.confirmRule ?? ((label) => confirmChoice(label, true));
|
|
1828
|
+
const grantable = selectedAdapters.filter((adapter) => adapter.registrar.grant !== void 0).map((adapter) => adapter.id);
|
|
1829
|
+
if (!await confirm(publishRuleQuestion(mode, probe.pending ?? [], grantable))) {
|
|
1830
|
+
return { ...nothing, skipped: "declined", ...pointer ? { pointer } : {} };
|
|
1831
|
+
}
|
|
1832
|
+
return await withOtherGrants(isClaude ? await write() : nothing);
|
|
1833
|
+
}
|
|
1834
|
+
function allowlistLines(sync) {
|
|
1835
|
+
const lines = [];
|
|
1836
|
+
const claude = sync.byHarness.claude;
|
|
1837
|
+
if ((claude?.added.length ?? 0) > 0) {
|
|
1838
|
+
lines.push(`Added ${claude?.added.length ?? 0} harness rule(s) to your allowlist.`);
|
|
1839
|
+
}
|
|
1840
|
+
if ((claude?.removed.length ?? 0) > 0) {
|
|
1841
|
+
lines.push(`Removed ${claude?.removed.join(", ")} from your allowlist.`);
|
|
1842
|
+
}
|
|
1843
|
+
const grant = sync.byHarness.codex;
|
|
1844
|
+
if (grant !== void 0 && grant.error === void 0 && grant.wrote) {
|
|
1845
|
+
lines.push(
|
|
1846
|
+
`Codex now allows ${grant.granted.length} tenjin command prefix(es) in ${grant.path}.`
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
1849
|
+
if (grant?.error !== void 0) {
|
|
1850
|
+
lines.push(`Codex's grant at ${grant.path} could not be updated (${grant.error}).`);
|
|
1851
|
+
}
|
|
1852
|
+
if (sync.pointer !== void 0) lines.push(sync.pointer);
|
|
1853
|
+
return lines;
|
|
1854
|
+
}
|
|
1855
|
+
async function setHooksKey(key, value, ctx) {
|
|
1856
|
+
const arm = key.slice("hooks.".length);
|
|
1857
|
+
const parsed = parseBoolean(value);
|
|
1858
|
+
await persistHookArm(ctx.dataDir, arm, parsed);
|
|
1859
|
+
const entry = { value: parsed, source: "file" };
|
|
1860
|
+
return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };
|
|
1861
|
+
}
|
|
1862
|
+
async function setUpdateKey(key, value, ctx) {
|
|
1863
|
+
const parsed = parseUpdateModeFlag(value, key);
|
|
1864
|
+
await persist(ctx.dataDir, (existing) => ({
|
|
1865
|
+
...existing,
|
|
1866
|
+
update: { ...existing.update, mode: parsed }
|
|
1867
|
+
}));
|
|
1868
|
+
const entry = { value: parsed, source: "file" };
|
|
1869
|
+
return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };
|
|
1870
|
+
}
|
|
1871
|
+
async function setLoopKey(key, value, ctx) {
|
|
1872
|
+
const parsed = parseLoopValue(key, value);
|
|
1873
|
+
const field = key.slice("loop.".length);
|
|
1874
|
+
await persist(ctx.dataDir, (existing) => ({
|
|
1875
|
+
...existing,
|
|
1876
|
+
loop: { ...existing.loop, [field]: parsed }
|
|
1877
|
+
}));
|
|
1878
|
+
const entry = {
|
|
1879
|
+
value: parsed === null ? "null" : String(parsed),
|
|
1880
|
+
source: "file"
|
|
1881
|
+
};
|
|
1882
|
+
return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };
|
|
1883
|
+
}
|
|
1884
|
+
async function setTeamKey(key, value, ctx) {
|
|
1885
|
+
const parsed = parsePublicFallbackFlag(value, key);
|
|
1886
|
+
await persist(ctx.dataDir, (existing) => ({
|
|
1887
|
+
...existing,
|
|
1888
|
+
team: { ...existing.team, publicFallback: parsed }
|
|
1889
|
+
}));
|
|
1890
|
+
const entry = { value: parsed, source: "file" };
|
|
1891
|
+
return { data: { key, ...entry }, humanLines: [formatLine(key, entry)] };
|
|
1892
|
+
}
|
|
1893
|
+
async function setExperimentalKey(key, value, ctx) {
|
|
1894
|
+
const parsed = parsePublicFallbackFlag(value, key);
|
|
1895
|
+
await persist(ctx.dataDir, (existing) => ({
|
|
1896
|
+
...existing,
|
|
1897
|
+
experimental: { ...existing.experimental, bazaar: parsed }
|
|
1898
|
+
}));
|
|
1899
|
+
const entry = { value: parsed, source: "file" };
|
|
1900
|
+
const warning = parsed === "on" ? EXPERIMENTAL_BAZAAR_WARNING : void 0;
|
|
1901
|
+
return {
|
|
1902
|
+
data: { key, ...entry, ...warning !== void 0 ? { warning } : {} },
|
|
1903
|
+
humanLines: [formatLine(key, entry), ...warning !== void 0 ? [warning] : []]
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
async function setRouterKey(key, value, ctx, project) {
|
|
1907
|
+
const field = key === "router.enabled" ? "enabled" : "context";
|
|
1908
|
+
const parsed = field === "enabled" ? parseBoolean(value) : parseRouterContext(value);
|
|
1909
|
+
let written;
|
|
1910
|
+
if (project === void 0) {
|
|
1911
|
+
await persist(ctx.dataDir, (existing) => ({
|
|
1912
|
+
...existing,
|
|
1913
|
+
router: { ...existing.router, [field]: parsed }
|
|
1914
|
+
}));
|
|
1915
|
+
written = { value: parsed, source: "file", path: configPath(ctx.dataDir) };
|
|
1916
|
+
} else {
|
|
1917
|
+
const path = await projectRouterPath({ cwd: process.cwd(), local: project.local });
|
|
1918
|
+
await persistProjectRouter(path, field, parsed);
|
|
1919
|
+
written = { value: parsed, source: project.local ? "local" : "project", path };
|
|
1920
|
+
}
|
|
1921
|
+
const effective = renderRouterSetting(key, await resolveRouterFromContext(ctx));
|
|
1922
|
+
const humanLines = [formatLine(key, written)];
|
|
1923
|
+
if (effective.value !== written.value) {
|
|
1924
|
+
humanLines.push(
|
|
1925
|
+
`Still ${String(effective.value)} here: ${effective.path ?? "the default"} is tighter, and a nearer file can only tighten an outer one.`
|
|
1926
|
+
);
|
|
1927
|
+
}
|
|
1928
|
+
if (project?.local === true) {
|
|
1929
|
+
humanLines.push("Keep .tenjin/config.local.json out of git: add it to .gitignore.");
|
|
1930
|
+
}
|
|
1931
|
+
return { data: { key, ...written, effective }, humanLines };
|
|
1932
|
+
}
|
|
1933
|
+
function parseRouterContext(value) {
|
|
1934
|
+
const found = ROUTER_CONTEXTS.find((context) => context === value);
|
|
1935
|
+
if (found !== void 0) return found;
|
|
1936
|
+
throw new CliError("USAGE", `Invalid router.context: ${JSON.stringify(value)}`, {
|
|
1937
|
+
fix: 'Use "session" or "turn".'
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
async function persistProjectRouter(path, field, value) {
|
|
1941
|
+
await mkdir2(dirname3(path), { recursive: true, mode: 493 });
|
|
1942
|
+
const lockPath = `${path}.lock`;
|
|
1943
|
+
try {
|
|
1944
|
+
await withFileLock(lockPath, () => mergeProjectRouter(path, field, value));
|
|
1945
|
+
} catch (err) {
|
|
1946
|
+
if (err instanceof LockTimeoutError) {
|
|
1947
|
+
throw new CliError("INTERNAL", err.message, {
|
|
1948
|
+
fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,
|
|
1949
|
+
cause: err
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
throw err;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
async function mergeProjectRouter(path, field, value) {
|
|
1956
|
+
const existing = await readProjectRouterFile(path);
|
|
1957
|
+
const block = existing?.json.router;
|
|
1958
|
+
const next = {
|
|
1959
|
+
...existing?.json ?? {},
|
|
1960
|
+
router: { ...block !== void 0 ? block : {}, [field]: value }
|
|
1961
|
+
};
|
|
1962
|
+
await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
|
|
1963
|
+
`, {
|
|
1964
|
+
mode: 420,
|
|
1965
|
+
dirMode: 493
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
function parsePublishMode(value) {
|
|
1969
|
+
const parsed = PublishModeSchema.safeParse(value);
|
|
1970
|
+
if (parsed.success) return parsed.data;
|
|
1971
|
+
throw new CliError("USAGE", `Invalid publish mode: ${JSON.stringify(value)}`, {
|
|
1972
|
+
fix: 'Use "review", "auto", or "full-auto".'
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
async function persistHookArm(dir, arm, value) {
|
|
1976
|
+
await persist(dir, (existing) => ({
|
|
1977
|
+
...existing,
|
|
1978
|
+
hooks: { ...existing.hooks, [arm]: value }
|
|
1979
|
+
}));
|
|
1980
|
+
}
|
|
1981
|
+
async function persistPublishMode(dir, mode) {
|
|
1982
|
+
await persist(dir, (existing) => ({
|
|
1983
|
+
...existing,
|
|
1984
|
+
publish: { ...existing.publish, mode }
|
|
1985
|
+
}));
|
|
1986
|
+
}
|
|
1987
|
+
async function persistRouterProject(dir, projectDir, present = true) {
|
|
1988
|
+
await persist(dir, (existing) => {
|
|
1989
|
+
const known = new Set(existing.install?.routerProjects ?? []);
|
|
1990
|
+
if (present) known.add(projectDir);
|
|
1991
|
+
else known.delete(projectDir);
|
|
1992
|
+
return { ...existing, install: { ...existing.install, routerProjects: [...known].sort() } };
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
async function persistRouterDefaults(dir, refresh = false, limits = ROUTER_DEFAULTS, chosen = []) {
|
|
1996
|
+
const result = { set: [], kept: [], removed: [] };
|
|
1997
|
+
if (refresh && retiredPaymentKeys(await loadRawConfig(dir)).length === 0) return result;
|
|
1998
|
+
await persist(dir, (existing) => {
|
|
1999
|
+
const next = { ...existing };
|
|
2000
|
+
result.removed = retiredPaymentKeys(existing);
|
|
2001
|
+
for (const key of result.removed) delete next[key];
|
|
2002
|
+
if (refresh) return next;
|
|
2003
|
+
for (const key of Object.keys(ROUTER_DEFAULTS)) {
|
|
2004
|
+
const value = limits[key];
|
|
2005
|
+
if (existing[key] !== void 0 && !chosen.includes(key)) result.kept.push(key);
|
|
2006
|
+
else if (value !== void 0) {
|
|
2007
|
+
next[key] = value;
|
|
2008
|
+
result.set.push(key);
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
return next;
|
|
2012
|
+
});
|
|
2013
|
+
return result;
|
|
2014
|
+
}
|
|
2015
|
+
async function persistInstallHarness(dir, harness) {
|
|
2016
|
+
await persist(dir, (existing) => ({
|
|
2017
|
+
...existing,
|
|
2018
|
+
install: { ...existing.install, harness: [...harness] }
|
|
2019
|
+
}));
|
|
2020
|
+
}
|
|
2021
|
+
async function persistGrantDeclined(dir, declined) {
|
|
2022
|
+
await persist(dir, (existing) => ({
|
|
2023
|
+
...existing,
|
|
2024
|
+
install: { ...existing.install, grantDeclined: declined }
|
|
2025
|
+
}));
|
|
2026
|
+
}
|
|
2027
|
+
async function resolveFromContext(ctx) {
|
|
2028
|
+
const config = await loadRawConfig(ctx.dataDir);
|
|
2029
|
+
const project = await loadProjectConfig(process.cwd());
|
|
2030
|
+
return resolveSettings({
|
|
2031
|
+
config,
|
|
2032
|
+
flags: { baseUrl: ctx.flags.baseUrl },
|
|
2033
|
+
env: process.env,
|
|
2034
|
+
project: project?.layer
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
function assertKey(key) {
|
|
2038
|
+
if (key === "bazaarPay" || key === "confirm") {
|
|
2039
|
+
throw new CliError("USAGE", `Retired config key: ${key}`, { fix: RETIRED_PAYMENT_GUIDANCE });
|
|
2040
|
+
}
|
|
2041
|
+
if (CONFIG_KEYS.includes(key)) return key;
|
|
2042
|
+
throw new CliError("USAGE", `Unknown config key: ${JSON.stringify(key)}`, {
|
|
2043
|
+
fix: `Valid keys: ${[...CONFIG_KEYS, ...PUBLISH_CONFIG_KEYS, ...HOOKS_CONFIG_KEYS, ...ROUTER_CONFIG_KEYS, ...EXPERIMENTAL_CONFIG_KEYS].join(", ")}.`
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
function renderSetting(key, stored, source) {
|
|
2047
|
+
return { ...renderValue(key, stored), source };
|
|
2048
|
+
}
|
|
2049
|
+
function renderPublishSetting(key, settings) {
|
|
2050
|
+
if (key === "publish.mode") {
|
|
2051
|
+
return { value: settings.publishMode.value, source: settings.publishMode.source };
|
|
2052
|
+
}
|
|
2053
|
+
if (key === "publish.ackServerWarnings") {
|
|
2054
|
+
return {
|
|
2055
|
+
value: settings.publishAckServerWarnings.value,
|
|
2056
|
+
source: settings.publishAckServerWarnings.source
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
return {
|
|
2060
|
+
value: toMoney(settings.publishDefaultPrice.value),
|
|
2061
|
+
source: settings.publishDefaultPrice.source
|
|
2062
|
+
};
|
|
2063
|
+
}
|
|
2064
|
+
function renderHooksSetting(key, settings) {
|
|
2065
|
+
const { value, source } = settings.hooks[key.slice("hooks.".length)];
|
|
2066
|
+
return { value, source };
|
|
2067
|
+
}
|
|
2068
|
+
function renderValue(key, stored) {
|
|
2069
|
+
if (key === "shelfBypassSecret") {
|
|
2070
|
+
return { value: typeof stored === "string" && stored.length > 0 ? "set" : "unset" };
|
|
2071
|
+
}
|
|
2072
|
+
if (Array.isArray(stored) || typeof stored === "boolean") return { value: stored };
|
|
2073
|
+
if (key === "sessionBudget" && stored === "none") return { value: null };
|
|
2074
|
+
if (key === "maxAutoSpend" || key === "sessionBudget") return { value: toMoney(stored) };
|
|
2075
|
+
if (key === "sendMaxAmount") {
|
|
2076
|
+
return { value: stored === "none" || stored === SEND_MAX_UNSET ? stored : toMoney(stored) };
|
|
2077
|
+
}
|
|
2078
|
+
return { value: stored };
|
|
2079
|
+
}
|
|
2080
|
+
function parseValue(key, value) {
|
|
2081
|
+
switch (key) {
|
|
2082
|
+
case "sessionBudget":
|
|
2083
|
+
return value === "none" ? "none" : parseUsdToAtomic(value);
|
|
2084
|
+
case "maxAutoSpend":
|
|
2085
|
+
return parseAutoSpend(value);
|
|
2086
|
+
case "sendMaxAmount":
|
|
2087
|
+
return value === "none" ? "none" : parseUsdToAtomic(value);
|
|
2088
|
+
case "allowlistCreators":
|
|
2089
|
+
return parseAllowlist(value);
|
|
2090
|
+
case "baseUrl":
|
|
2091
|
+
case "publicShelfUrl":
|
|
2092
|
+
case "rpcUrl":
|
|
2093
|
+
return parseHttpUrl(value);
|
|
2094
|
+
case "shelfBypassSecret":
|
|
2095
|
+
return value.trim();
|
|
2096
|
+
case "evalCohort":
|
|
2097
|
+
return parseBoolean(value);
|
|
2098
|
+
case "bazaarRegistries":
|
|
2099
|
+
return parseRegistryList(value);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
function parseAutoSpend(value) {
|
|
2103
|
+
const atomic = parseUsdToAtomic(value);
|
|
2104
|
+
if (BigInt(atomic) < MAX_AUTO_SPEND_FLOOR_ATOMIC) {
|
|
2105
|
+
throw new CliError("USAGE", `maxAutoSpend ${value} is below the 0.25 USD minimum.`, {
|
|
2106
|
+
fix: MAX_AUTO_SPEND_FLOOR_WHY
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
return atomic;
|
|
2110
|
+
}
|
|
2111
|
+
function parseRegistryList(value) {
|
|
2112
|
+
return value.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0).map((entry) => parseHttpUrl(entry));
|
|
2113
|
+
}
|
|
2114
|
+
function parseBoolean(value) {
|
|
2115
|
+
if (value === "true" || value === "on") return true;
|
|
2116
|
+
if (value === "false" || value === "off") return false;
|
|
2117
|
+
throw new CliError("USAGE", `Invalid boolean value: ${JSON.stringify(value)}`, {
|
|
2118
|
+
fix: 'Use "on" or "off" (or "true"/"false").'
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
function parseAllowlist(value) {
|
|
2122
|
+
const entries = value.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
2123
|
+
for (const entry of entries) {
|
|
2124
|
+
if (/\s/.test(entry)) {
|
|
2125
|
+
throw new CliError("USAGE", `Invalid creator entry: ${JSON.stringify(entry)}`, {
|
|
2126
|
+
fix: "Creator entries cannot contain spaces; separate multiple with commas."
|
|
2127
|
+
});
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
return entries;
|
|
2131
|
+
}
|
|
2132
|
+
function parseHttpUrl(value) {
|
|
2133
|
+
let url;
|
|
2134
|
+
try {
|
|
2135
|
+
url = new URL(value);
|
|
2136
|
+
} catch {
|
|
2137
|
+
throw new CliError("USAGE", `Invalid URL: ${JSON.stringify(value)}`, {
|
|
2138
|
+
fix: `Pass an absolute http(s) URL like ${PRODUCTION_ORIGIN}.`
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
2142
|
+
throw new CliError("USAGE", `URL must be http or https: ${JSON.stringify(value)}`, {
|
|
2143
|
+
fix: `Pass an absolute http(s) URL like ${PRODUCTION_ORIGIN}.`
|
|
2144
|
+
});
|
|
2145
|
+
}
|
|
2146
|
+
return value;
|
|
2147
|
+
}
|
|
2148
|
+
async function persist(dir, merge) {
|
|
2149
|
+
await mkdir2(dir, { recursive: true, mode: 448 });
|
|
2150
|
+
const lockPath = `${configPath(dir)}.lock`;
|
|
2151
|
+
try {
|
|
2152
|
+
await withFileLock(lockPath, async () => {
|
|
2153
|
+
const existing = await loadRawConfig(dir);
|
|
2154
|
+
const merged = merge(existing);
|
|
2155
|
+
const validated = RawConfigSchema.parse(merged);
|
|
2156
|
+
await writeFileAtomic(configPath(dir), `${JSON.stringify(validated, null, 2)}
|
|
2157
|
+
`, {
|
|
2158
|
+
mode: 384,
|
|
2159
|
+
dirMode: 448
|
|
2160
|
+
});
|
|
2161
|
+
});
|
|
2162
|
+
} catch (err) {
|
|
2163
|
+
if (err instanceof LockTimeoutError) {
|
|
2164
|
+
throw new CliError("INTERNAL", err.message, {
|
|
2165
|
+
fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,
|
|
2166
|
+
cause: err
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
throw err;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
function formatLine(key, entry) {
|
|
2173
|
+
const label = key.padEnd(KEY_WIDTH);
|
|
2174
|
+
const where = entry.path !== void 0 && (entry.source === "project" || entry.source === "local") ? ` ${entry.path}` : "";
|
|
2175
|
+
return ` ${label} ${displayValue(entry)} ${style("dim", `(${entry.source}${where})`)}`;
|
|
2176
|
+
}
|
|
2177
|
+
function describedLine(key, entry, note) {
|
|
2178
|
+
const description = KEY_DESCRIPTIONS[key];
|
|
2179
|
+
let line = formatLine(key, entry);
|
|
2180
|
+
if (description !== void 0) line += ` ${style("dim", `- ${description}`)}`;
|
|
2181
|
+
return withNote(line, note);
|
|
2182
|
+
}
|
|
2183
|
+
function withNote(line, note) {
|
|
2184
|
+
return note !== void 0 ? `${line} ${style("dim", `(${note})`)}` : line;
|
|
2185
|
+
}
|
|
2186
|
+
function downgradeNote(key, settings) {
|
|
2187
|
+
if (key !== "publish.mode" || settings.publishMode.downgradedWarning === void 0) {
|
|
2188
|
+
return void 0;
|
|
2189
|
+
}
|
|
2190
|
+
return "downgraded from full-auto: committed .tenjin.json (gitignore it to opt in)";
|
|
2191
|
+
}
|
|
2192
|
+
function displayValue(entry) {
|
|
2193
|
+
const { value } = entry;
|
|
2194
|
+
if (Array.isArray(value)) return value.length > 0 ? value.join(", ") : "(empty)";
|
|
2195
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
2196
|
+
if (value === null) return "none (no daily limit)";
|
|
2197
|
+
if (typeof value === "object") return `${value.usd} USD`;
|
|
2198
|
+
return value;
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
export {
|
|
2202
|
+
RETIRED_SKILL_NAMES,
|
|
2203
|
+
SHIPPED_SKILL_FILES,
|
|
2204
|
+
CLI_SKILL_NAMES,
|
|
2205
|
+
skillsDirsFor,
|
|
2206
|
+
readSkillFile,
|
|
2207
|
+
skillFrontmatterName,
|
|
2208
|
+
inspectHooksFile,
|
|
2209
|
+
ROUTER_DEFAULTS,
|
|
2210
|
+
shownLimits,
|
|
2211
|
+
ROUTING_FEE_TERMS,
|
|
2212
|
+
FEE_APPROVAL,
|
|
2213
|
+
SPEND_QUESTION,
|
|
2214
|
+
spendChoiceQuestion,
|
|
2215
|
+
spendOptions,
|
|
2216
|
+
EXPERIMENTAL_BAZAAR_WARNING,
|
|
2217
|
+
runConfigList,
|
|
2218
|
+
runConfigGet,
|
|
2219
|
+
runConfigSet,
|
|
2220
|
+
persistHookArm,
|
|
2221
|
+
persistPublishMode,
|
|
2222
|
+
persistRouterProject,
|
|
2223
|
+
persistRouterDefaults,
|
|
2224
|
+
persistInstallHarness,
|
|
2225
|
+
persistGrantDeclined
|
|
2226
|
+
};
|
|
2227
|
+
//# sourceMappingURL=chunk-3O2BQIF6.js.map
|