tenjin-cli 0.1.0-alpha.30 → 0.1.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -116
- package/dist/{_esm-CE7KNONL.js → _esm-MEXZI5DL.js} +4 -4
- package/dist/{alive-3J3CHOQP.js → alive-J64H46HI.js} +14 -4
- package/dist/{chunk-O2FRQ2L2.js → chunk-27EPWVOY.js} +4 -64
- package/dist/chunk-27EPWVOY.js.map +1 -0
- package/dist/{chunk-OSYTBCUC.js → chunk-2XLC3AEX.js} +16 -14
- package/dist/{chunk-OSYTBCUC.js.map → chunk-2XLC3AEX.js.map} +1 -1
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/{chunk-PAYV4XUA.js → chunk-4ZZO6ULA.js} +2 -2
- package/dist/{chunk-VUFAK2LW.js → chunk-5C32RLTA.js} +2 -2
- package/dist/{chunk-VUFAK2LW.js.map → chunk-5C32RLTA.js.map} +1 -1
- package/dist/{chunk-YHKXNYTB.js → chunk-5K5W4S66.js} +2 -2
- package/dist/{chunk-3O2BQIF6.js → chunk-5MARFNSB.js} +273 -482
- package/dist/chunk-5MARFNSB.js.map +1 -0
- package/dist/{chunk-HPWO4O6S.js → chunk-6E5R45ZO.js} +2 -2
- package/dist/{chunk-JMM6YE7J.js → chunk-77TCKDEC.js} +125 -312
- package/dist/chunk-77TCKDEC.js.map +1 -0
- package/dist/{chunk-LFZJM56J.js → chunk-7Q5FDF65.js} +2 -2
- package/dist/chunk-7WEQQJLG.js +68 -0
- package/dist/chunk-7WEQQJLG.js.map +1 -0
- package/dist/{chunk-AWFUPKTM.js → chunk-7WU4OPLP.js} +12 -6
- package/dist/{chunk-AWFUPKTM.js.map → chunk-7WU4OPLP.js.map} +1 -1
- package/dist/{chunk-AEG2PXBP.js → chunk-7ZRL2LBQ.js} +3 -3
- package/dist/{chunk-IOODYAXL.js → chunk-AGZ7PJKY.js} +6 -4
- package/dist/{chunk-IOODYAXL.js.map → chunk-AGZ7PJKY.js.map} +1 -1
- package/dist/{chunk-VFMQTSXG.js → chunk-B7HUUJOK.js} +3 -3
- package/dist/{chunk-EL56RW2J.js → chunk-BL3332HQ.js} +7 -7
- package/dist/{chunk-5LJCEMFD.js → chunk-D65GNPS3.js} +35 -27
- package/dist/{chunk-5LJCEMFD.js.map → chunk-D65GNPS3.js.map} +1 -1
- package/dist/{chunk-P7LABKCW.js → chunk-DOQGNFHM.js} +33 -2
- package/dist/{chunk-P7LABKCW.js.map → chunk-DOQGNFHM.js.map} +1 -1
- package/dist/{chunk-OK2TDZQU.js → chunk-FW75G2W4.js} +7 -5
- package/dist/chunk-FW75G2W4.js.map +1 -0
- package/dist/chunk-GA7JETVM.js +150 -0
- package/dist/chunk-GA7JETVM.js.map +1 -0
- package/dist/{chunk-6W5GYG3W.js → chunk-I3EQFHCD.js} +48 -1
- package/dist/chunk-I3EQFHCD.js.map +1 -0
- package/dist/{chunk-EBVIKMCH.js → chunk-JKKAIPTU.js} +2 -2
- package/dist/{chunk-N35E6CM2.js → chunk-K3I7C2MO.js} +6 -6
- package/dist/{chunk-KYFZTGMC.js → chunk-K72RURN3.js} +5 -3
- package/dist/{chunk-KYFZTGMC.js.map → chunk-K72RURN3.js.map} +1 -1
- package/dist/{chunk-RAULEAZ6.js → chunk-KXQ4UIP7.js} +3 -3
- package/dist/{chunk-VZGAONSJ.js → chunk-KXVP2VKA.js} +5 -5
- package/dist/chunk-LEFIX6RS.js +100 -0
- package/dist/chunk-LEFIX6RS.js.map +1 -0
- package/dist/{chunk-TTBKWWTV.js → chunk-MNXS2U45.js} +246 -83
- package/dist/chunk-MNXS2U45.js.map +1 -0
- package/dist/{chunk-AWQPGIR6.js → chunk-NEFNKLBE.js} +5 -5
- package/dist/chunk-OHRR5OYM.js +63 -0
- package/dist/chunk-OHRR5OYM.js.map +1 -0
- package/dist/{chunk-U6YQ6FRI.js → chunk-P4NH7OUK.js} +31 -11
- package/dist/chunk-P4NH7OUK.js.map +1 -0
- package/dist/chunk-QSCPK4F5.js +145 -0
- package/dist/chunk-QSCPK4F5.js.map +1 -0
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-YFQOA5AU.js → chunk-R5LCN54M.js} +4 -4
- package/dist/{chunk-KHE6L6TD.js → chunk-UKY4CHNC.js} +92 -10
- package/dist/chunk-UKY4CHNC.js.map +1 -0
- package/dist/{chunk-QUVVWYJW.js → chunk-UQUOVWBG.js} +8 -6
- package/dist/{chunk-QUVVWYJW.js.map → chunk-UQUOVWBG.js.map} +1 -1
- package/dist/{chunk-HE2MS4QO.js → chunk-V6BSF6OC.js} +17 -13
- package/dist/{chunk-HE2MS4QO.js.map → chunk-V6BSF6OC.js.map} +1 -1
- package/dist/{chunk-WVUSXNIE.js → chunk-WJXLQXJY.js} +6 -2
- package/dist/{chunk-WVUSXNIE.js.map → chunk-WJXLQXJY.js.map} +1 -1
- package/dist/{chunk-NZIP4PA2.js → chunk-WK7F3B2E.js} +2 -2
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/{chunk-SPAVAYSW.js → chunk-YFPY4ONH.js} +6 -4
- package/dist/{chunk-SPAVAYSW.js.map → chunk-YFPY4ONH.js.map} +1 -1
- package/dist/{chunk-WO5BJNIB.js → chunk-YVFXE7RR.js} +9 -129
- package/dist/chunk-YVFXE7RR.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-O5SN7ZJ4.js → cli-D5OE3URZ.js} +128 -56
- package/dist/{cli-O5SN7ZJ4.js.map → cli-D5OE3URZ.js.map} +1 -1
- package/dist/codex-event-PPNVRRDH.js +16 -0
- package/dist/codex-host-2RJOJW2B.js +28 -0
- package/dist/codex-install-UUZ6QMBQ.js +221 -0
- package/dist/codex-install-UUZ6QMBQ.js.map +1 -0
- package/dist/{config-OJQI27LT.js → config-ZD4OB2DO.js} +18 -12
- package/dist/{doctor-IQQJHGGM.js → doctor-KBR34Q4B.js} +48 -37
- package/dist/doctor-KBR34Q4B.js.map +1 -0
- package/dist/{fund-WEV6DMTD.js → fund-5ITKQGYF.js} +38 -31
- package/dist/{fund-WEV6DMTD.js.map → fund-5ITKQGYF.js.map} +1 -1
- package/dist/hook-command-4TYCHHRL.js +39 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +3 -2
- package/dist/hosts/claude/tenjin/hooks/hooks.json +4 -1
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
- package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
- package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
- package/dist/hosts/codex/tenjin/.mcp.json +12 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +52 -0
- package/dist/hosts-FWZOV26H.js +216 -0
- package/dist/hosts-FWZOV26H.js.map +1 -0
- package/dist/index.js +5 -5
- package/dist/{install-TUCRF32I.js → install-XWGE4Q7L.js} +38 -21
- package/dist/{install-identity-WHPNMNMQ.js → install-identity-K7EJIQFP.js} +11 -7
- package/dist/{install-wallet-MA27FTQ5.js → install-wallet-XQ6XFZV4.js} +27 -23
- package/dist/{install-wallet-MA27FTQ5.js.map → install-wallet-XQ6XFZV4.js.map} +1 -1
- package/dist/{mcp-QML7ZMPH.js → mcp-3LIJSSJB.js} +184 -58
- package/dist/mcp-3LIJSSJB.js.map +1 -0
- package/dist/{package-LGKYOEPV.js → package-ZKQFDWLE.js} +2 -2
- package/dist/{pay-2C2UBBXJ.js → pay-WHBERZ3W.js} +27 -23
- package/dist/{payments-C44QUFXU.js → payments-KVICEKD2.js} +14 -10
- package/dist/{payments-C44QUFXU.js.map → payments-KVICEKD2.js.map} +1 -1
- package/dist/plugin-registration-5TIA564H.js +54 -0
- package/dist/plugin-registration-5TIA564H.js.map +1 -0
- package/dist/{send-KVJX4XIR.js → send-7G7Y7DLN.js} +25 -19
- package/dist/{send-KVJX4XIR.js.map → send-7G7Y7DLN.js.map} +1 -1
- package/dist/{status-S7C3WMSH.js → status-OF7RH5HM.js} +26 -21
- package/dist/{status-S7C3WMSH.js.map → status-OF7RH5HM.js.map} +1 -1
- package/dist/{status-line-YR2T5HC4.js → status-line-XOUE6MPL.js} +10 -6
- package/dist/{status-line-YR2T5HC4.js.map → status-line-XOUE6MPL.js.map} +1 -1
- package/dist/{uninstall-HY6LKIIT.js → uninstall-JXUAFNDB.js} +30 -21
- package/dist/{uninstall-HY6LKIIT.js.map → uninstall-JXUAFNDB.js.map} +1 -1
- package/dist/update-ZKUERSO2.js +44 -0
- package/dist/update-ZKUERSO2.js.map +1 -0
- package/dist/{usdc-JK4RRFFQ.js → usdc-OGOGEHV2.js} +7 -6
- package/dist/usdc-OGOGEHV2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-S3DA7DFW.js} +2 -2
- package/dist/viemAdapter-By13KInL-S3DA7DFW.js.map +1 -0
- package/dist/{wallet-PD2IMZDU.js → wallet-2HA6W4R4.js} +24 -20
- package/dist/wallet-2HA6W4R4.js.map +1 -0
- package/docs/agent-permissions.md +21 -5
- package/package.json +1 -1
- package/dist/chunk-3O2BQIF6.js.map +0 -1
- package/dist/chunk-6W5GYG3W.js.map +0 -1
- package/dist/chunk-JMM6YE7J.js.map +0 -1
- package/dist/chunk-KHE6L6TD.js.map +0 -1
- package/dist/chunk-O2FRQ2L2.js.map +0 -1
- package/dist/chunk-OK2TDZQU.js.map +0 -1
- package/dist/chunk-TTBKWWTV.js.map +0 -1
- package/dist/chunk-U6YQ6FRI.js.map +0 -1
- package/dist/chunk-WO5BJNIB.js.map +0 -1
- package/dist/doctor-IQQJHGGM.js.map +0 -1
- package/dist/hook-command-D2P3ILRV.js +0 -32
- package/dist/mcp-QML7ZMPH.js.map +0 -1
- package/dist/update-OJV22LR3.js +0 -36
- /package/dist/{_esm-CE7KNONL.js.map → _esm-MEXZI5DL.js.map} +0 -0
- /package/dist/{alive-3J3CHOQP.js.map → alive-J64H46HI.js.map} +0 -0
- /package/dist/{chunk-PAYV4XUA.js.map → chunk-4ZZO6ULA.js.map} +0 -0
- /package/dist/{chunk-YHKXNYTB.js.map → chunk-5K5W4S66.js.map} +0 -0
- /package/dist/{chunk-HPWO4O6S.js.map → chunk-6E5R45ZO.js.map} +0 -0
- /package/dist/{chunk-LFZJM56J.js.map → chunk-7Q5FDF65.js.map} +0 -0
- /package/dist/{chunk-AEG2PXBP.js.map → chunk-7ZRL2LBQ.js.map} +0 -0
- /package/dist/{chunk-VFMQTSXG.js.map → chunk-B7HUUJOK.js.map} +0 -0
- /package/dist/{chunk-EL56RW2J.js.map → chunk-BL3332HQ.js.map} +0 -0
- /package/dist/{chunk-EBVIKMCH.js.map → chunk-JKKAIPTU.js.map} +0 -0
- /package/dist/{chunk-N35E6CM2.js.map → chunk-K3I7C2MO.js.map} +0 -0
- /package/dist/{chunk-RAULEAZ6.js.map → chunk-KXQ4UIP7.js.map} +0 -0
- /package/dist/{chunk-VZGAONSJ.js.map → chunk-KXVP2VKA.js.map} +0 -0
- /package/dist/{chunk-AWQPGIR6.js.map → chunk-NEFNKLBE.js.map} +0 -0
- /package/dist/{chunk-YFQOA5AU.js.map → chunk-R5LCN54M.js.map} +0 -0
- /package/dist/{chunk-NZIP4PA2.js.map → chunk-WK7F3B2E.js.map} +0 -0
- /package/dist/{config-OJQI27LT.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{hook-command-D2P3ILRV.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{install-TUCRF32I.js.map → codex-event-PPNVRRDH.js.map} +0 -0
- /package/dist/{install-identity-WHPNMNMQ.js.map → codex-host-2RJOJW2B.js.map} +0 -0
- /package/dist/{package-LGKYOEPV.js.map → config-ZD4OB2DO.js.map} +0 -0
- /package/dist/{pay-2C2UBBXJ.js.map → hook-command-4TYCHHRL.js.map} +0 -0
- /package/dist/{update-OJV22LR3.js.map → install-XWGE4Q7L.js.map} +0 -0
- /package/dist/{usdc-JK4RRFFQ.js.map → install-identity-K7EJIQFP.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → package-ZKQFDWLE.js.map} +0 -0
- /package/dist/{wallet-PD2IMZDU.js.map → pay-WHBERZ3W.js.map} +0 -0
|
@@ -1,46 +1,62 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
CONTEXT_MAX,
|
|
4
|
+
HARNESS_MS,
|
|
5
|
+
PATCH_TOOL,
|
|
6
|
+
SHELL_TOOL,
|
|
7
|
+
decode,
|
|
8
|
+
encode,
|
|
9
|
+
hasErrorMarker
|
|
10
|
+
} from "./chunk-3623BLPV.js";
|
|
2
11
|
import {
|
|
3
12
|
modeGatedPointer
|
|
4
13
|
} from "./chunk-A36LQPHV.js";
|
|
5
14
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
codexHome,
|
|
16
|
+
withAppServer
|
|
17
|
+
} from "./chunk-QSCPK4F5.js";
|
|
8
18
|
import {
|
|
9
19
|
HOOK_TOOL
|
|
10
20
|
} from "./chunk-AKWGE6JQ.js";
|
|
11
21
|
import {
|
|
12
22
|
LEGACY_MCP_SERVER_NAME
|
|
13
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-WJXLQXJY.js";
|
|
14
24
|
import {
|
|
15
|
-
|
|
16
|
-
} from "./chunk-
|
|
25
|
+
AGENT_ID_RE
|
|
26
|
+
} from "./chunk-XKESD27X.js";
|
|
17
27
|
import {
|
|
18
28
|
CHANNEL_DEPOSIT_ATOMIC,
|
|
19
29
|
ROUTING_FEE_ATOMIC,
|
|
20
30
|
usd
|
|
21
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-4ZZO6ULA.js";
|
|
22
32
|
import {
|
|
23
33
|
LockTimeoutError,
|
|
24
34
|
withFileLock
|
|
25
35
|
} from "./chunk-MEFB5KHA.js";
|
|
26
36
|
import {
|
|
27
37
|
style
|
|
28
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-K72RURN3.js";
|
|
39
|
+
import {
|
|
40
|
+
confirmChoice
|
|
41
|
+
} from "./chunk-DOQGNFHM.js";
|
|
29
42
|
import {
|
|
30
43
|
projectRouterPath,
|
|
31
44
|
readProjectRouterFile,
|
|
32
45
|
routerSettings
|
|
33
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-YFPY4ONH.js";
|
|
34
47
|
import {
|
|
35
48
|
hasCode
|
|
36
49
|
} from "./chunk-2I4QTOLB.js";
|
|
37
50
|
import {
|
|
38
51
|
isTeamShelfOrigin,
|
|
39
52
|
loadProjectConfig
|
|
40
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-7WU4OPLP.js";
|
|
54
|
+
import {
|
|
55
|
+
parseUsdToAtomic,
|
|
56
|
+
toMoney
|
|
57
|
+
} from "./chunk-Y527D4TV.js";
|
|
41
58
|
import {
|
|
42
59
|
CONFIG_KEYS,
|
|
43
|
-
CliError,
|
|
44
60
|
DEFAULT_MAX_AUTO_SPEND,
|
|
45
61
|
DEFAULT_SESSION_BUDGET,
|
|
46
62
|
EXPERIMENTAL_CONFIG_KEYS,
|
|
@@ -49,7 +65,6 @@ import {
|
|
|
49
65
|
LOOP_CONFIG_KEYS,
|
|
50
66
|
MAX_AUTO_SPEND_FLOOR_ATOMIC,
|
|
51
67
|
MAX_AUTO_SPEND_FLOOR_WHY,
|
|
52
|
-
PRODUCTION_ORIGIN,
|
|
53
68
|
PUBLISH_CONFIG_KEYS,
|
|
54
69
|
PublishModeSchema,
|
|
55
70
|
RETIRED_PAYMENT_GUIDANCE,
|
|
@@ -59,20 +74,24 @@ import {
|
|
|
59
74
|
SEND_MAX_UNSET,
|
|
60
75
|
TEAM_CONFIG_KEYS,
|
|
61
76
|
UPDATE_CONFIG_KEYS,
|
|
62
|
-
isSameDeployment,
|
|
63
77
|
loadRawConfig,
|
|
64
78
|
parseAckServerWarnings,
|
|
65
79
|
parseLoopValue,
|
|
66
80
|
parsePublicFallbackFlag,
|
|
67
81
|
parseUpdateModeFlag,
|
|
68
|
-
parseUsdToAtomic,
|
|
69
82
|
resolveSettings,
|
|
70
|
-
retiredPaymentKeys
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
retiredPaymentKeys
|
|
84
|
+
} from "./chunk-YVFXE7RR.js";
|
|
85
|
+
import {
|
|
86
|
+
PRODUCTION_ORIGIN,
|
|
87
|
+
isSameDeployment
|
|
88
|
+
} from "./chunk-XQJXNMSB.js";
|
|
89
|
+
import {
|
|
90
|
+
CliError
|
|
91
|
+
} from "./chunk-3UCIG4TG.js";
|
|
73
92
|
import {
|
|
74
93
|
writeFileAtomic
|
|
75
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-7WEQQJLG.js";
|
|
76
95
|
import {
|
|
77
96
|
configPath,
|
|
78
97
|
hooksDir
|
|
@@ -85,432 +104,14 @@ import { dirname as dirname3 } from "node:path";
|
|
|
85
104
|
|
|
86
105
|
// src/lib/harness-permissions.ts
|
|
87
106
|
import { chmod, lstat, mkdir, readFile, realpath, stat as stat2 } from "node:fs/promises";
|
|
88
|
-
import { dirname, join as
|
|
107
|
+
import { dirname, join as join2 } from "node:path";
|
|
89
108
|
|
|
90
109
|
// src/lib/codex-rules.ts
|
|
91
110
|
import { execFile } from "node:child_process";
|
|
92
111
|
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
112
|
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
113
|
function codexRulesPath(home, env = process.env) {
|
|
513
|
-
return
|
|
114
|
+
return join(codexHome(home, env), "rules", "tenjin.rules");
|
|
514
115
|
}
|
|
515
116
|
function prefixTokens(rule) {
|
|
516
117
|
const m = /^Bash\(tenjin ((?:[a-z][a-z-]* )*[a-z][a-z-]*):\*\)$/.exec(rule);
|
|
@@ -569,7 +170,7 @@ async function removeCodexGrant(home, env = process.env) {
|
|
|
569
170
|
|
|
570
171
|
// src/lib/harness-permissions.ts
|
|
571
172
|
function claudeSettingsPath(homeDir) {
|
|
572
|
-
return
|
|
173
|
+
return join2(homeDir, ".claude", "settings.json");
|
|
573
174
|
}
|
|
574
175
|
async function inspectClaudeGrant(homeDir, mode) {
|
|
575
176
|
const found = await inspectAllowlist(homeDir, mode);
|
|
@@ -948,10 +549,10 @@ async function inspectAllowlistAt(declaredPath, rules, list = "allow") {
|
|
|
948
549
|
// src/lib/skill-wiring.ts
|
|
949
550
|
import { existsSync, statSync } from "node:fs";
|
|
950
551
|
import { constants, open } from "node:fs/promises";
|
|
951
|
-
import { delimiter, join as
|
|
552
|
+
import { delimiter, join as join4 } from "node:path";
|
|
952
553
|
|
|
953
554
|
// src/lib/skills-source.ts
|
|
954
|
-
import { dirname as dirname2, join as
|
|
555
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
955
556
|
var SKILL_NAMES = ["tenjin-search", "tenjin-publish", "tenjin"];
|
|
956
557
|
var RETIRED_SKILL_NAMES = ["tenjin-pay"];
|
|
957
558
|
var PACKAGED_SKILL_NAMES = [...SKILL_NAMES];
|
|
@@ -961,7 +562,7 @@ var SHIPPED_SKILL_FILES = {
|
|
|
961
562
|
tenjin: ["SKILL.md"],
|
|
962
563
|
"tenjin-pay": ["SKILL.md"]
|
|
963
564
|
};
|
|
964
|
-
var SENTINEL =
|
|
565
|
+
var SENTINEL = join3("tenjin", "SKILL.md");
|
|
965
566
|
|
|
966
567
|
// src/lib/skill-wiring.ts
|
|
967
568
|
var CLI_SKILL_NAMES = [
|
|
@@ -969,19 +570,19 @@ var CLI_SKILL_NAMES = [
|
|
|
969
570
|
"tenjin-publish"
|
|
970
571
|
];
|
|
971
572
|
function skillsDirsFor(home) {
|
|
972
|
-
return [
|
|
573
|
+
return [join4(home, ".claude", "skills"), join4(home, ".agents", "skills")];
|
|
973
574
|
}
|
|
974
575
|
function harnessTargetDir(home, harness) {
|
|
975
|
-
if (harness === "claude") return
|
|
976
|
-
return
|
|
576
|
+
if (harness === "claude") return join4(home, ".claude", "skills");
|
|
577
|
+
return join4(home, ".agents", "skills");
|
|
977
578
|
}
|
|
978
579
|
function harnessFlagFor(home, dir) {
|
|
979
|
-
if (dir ===
|
|
580
|
+
if (dir === join4(home, ".claude", "skills")) return "claude";
|
|
980
581
|
return "codex";
|
|
981
582
|
}
|
|
982
583
|
function harnessDetectedBy(home, harness, which) {
|
|
983
584
|
const reasons = [];
|
|
984
|
-
if (existsSync(
|
|
585
|
+
if (existsSync(join4(home, `.${harness}`))) reasons.push("home-dir");
|
|
985
586
|
if (which(harness)) reasons.push("binary");
|
|
986
587
|
return reasons;
|
|
987
588
|
}
|
|
@@ -1008,7 +609,7 @@ function onPath(bin, env) {
|
|
|
1008
609
|
for (const part of raw.split(delimiter)) {
|
|
1009
610
|
if (part.length === 0) continue;
|
|
1010
611
|
for (const ext of exts) {
|
|
1011
|
-
if (isFile(
|
|
612
|
+
if (isFile(join4(part, bin + ext))) return true;
|
|
1012
613
|
}
|
|
1013
614
|
}
|
|
1014
615
|
return false;
|
|
@@ -1056,7 +657,7 @@ function extractFrontmatter(text) {
|
|
|
1056
657
|
}
|
|
1057
658
|
|
|
1058
659
|
// src/adapters/claude.ts
|
|
1059
|
-
var
|
|
660
|
+
var NATIVE_TO_EVENT = {
|
|
1060
661
|
SessionStart: "session.start",
|
|
1061
662
|
UserPromptSubmit: "prompt",
|
|
1062
663
|
PreToolUse: "tool.before",
|
|
@@ -1078,73 +679,73 @@ function matcherOf(re) {
|
|
|
1078
679
|
return re.source.replace(/^\^\(?/, "").replace(/\)?\$$/, "");
|
|
1079
680
|
}
|
|
1080
681
|
var SESSION_START_MATCHER = "startup|clear|compact";
|
|
1081
|
-
function
|
|
682
|
+
function isRecord(v) {
|
|
1082
683
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1083
684
|
}
|
|
1084
|
-
function
|
|
685
|
+
function str(v) {
|
|
1085
686
|
return typeof v === "string" ? v : void 0;
|
|
1086
687
|
}
|
|
1087
688
|
function toolKind(name) {
|
|
1088
689
|
for (const kind of Object.keys(TOOLS)) if (TOOLS[kind].test(name)) return kind;
|
|
1089
690
|
return "other";
|
|
1090
691
|
}
|
|
1091
|
-
function
|
|
692
|
+
function canonicalTool(name, input) {
|
|
1092
693
|
const kind = toolKind(name);
|
|
1093
694
|
switch (kind) {
|
|
1094
695
|
case "shell":
|
|
1095
|
-
return { name, kind, command:
|
|
696
|
+
return { name, kind, command: str(input.command) ?? "" };
|
|
1096
697
|
case "edit":
|
|
1097
698
|
case "read": {
|
|
1098
|
-
const path =
|
|
699
|
+
const path = str(input.file_path);
|
|
1099
700
|
return { name, kind, paths: path === void 0 ? [] : [path] };
|
|
1100
701
|
}
|
|
1101
702
|
case "dispatch": {
|
|
1102
|
-
const description =
|
|
703
|
+
const description = str(input.description);
|
|
1103
704
|
return {
|
|
1104
705
|
name,
|
|
1105
706
|
kind,
|
|
1106
|
-
task:
|
|
707
|
+
task: str(input.prompt) ?? "",
|
|
1107
708
|
...description !== void 0 ? { description } : {}
|
|
1108
709
|
};
|
|
1109
710
|
}
|
|
1110
711
|
case "web":
|
|
1111
|
-
return { name, kind, query:
|
|
712
|
+
return { name, kind, query: str(input.query) ?? "" };
|
|
1112
713
|
case "fetch":
|
|
1113
|
-
return { name, kind, url:
|
|
714
|
+
return { name, kind, url: str(input.url) ?? "", prompt: str(input.prompt) ?? "" };
|
|
1114
715
|
default:
|
|
1115
716
|
return { name, kind };
|
|
1116
717
|
}
|
|
1117
718
|
}
|
|
1118
719
|
function toolResult(v) {
|
|
1119
720
|
if (typeof v === "string") return { text: v };
|
|
1120
|
-
if (!
|
|
721
|
+
if (!isRecord(v)) return void 0;
|
|
1121
722
|
const out = {};
|
|
1122
|
-
const stdout =
|
|
1123
|
-
const stderr =
|
|
1124
|
-
const error =
|
|
723
|
+
const stdout = str(v.stdout);
|
|
724
|
+
const stderr = str(v.stderr);
|
|
725
|
+
const error = str(v.error);
|
|
1125
726
|
if (stdout !== void 0) out.stdout = stdout;
|
|
1126
727
|
if (stderr !== void 0) out.stderr = stderr;
|
|
1127
728
|
if (error !== void 0) out.error = error;
|
|
1128
729
|
if (stdout === void 0 && stderr === void 0 && error === void 0) {
|
|
1129
|
-
const text =
|
|
730
|
+
const text = str(v.text) ?? str(v.content) ?? str(v.result);
|
|
1130
731
|
if (text !== void 0) out.text = text;
|
|
1131
732
|
}
|
|
1132
733
|
return out;
|
|
1133
734
|
}
|
|
1134
735
|
function decode2(raw) {
|
|
1135
|
-
if (!
|
|
1136
|
-
const native =
|
|
736
|
+
if (!isRecord(raw)) return null;
|
|
737
|
+
const native = str(raw.hook_event_name);
|
|
1137
738
|
if (native === void 0) return null;
|
|
1138
|
-
const event =
|
|
739
|
+
const event = NATIVE_TO_EVENT[native];
|
|
1139
740
|
if (event === void 0) return null;
|
|
1140
|
-
const session =
|
|
741
|
+
const session = str(raw.session_id);
|
|
1141
742
|
if (session === void 0 || session.length === 0) return null;
|
|
1142
743
|
const input = {
|
|
1143
744
|
harness: "claude",
|
|
1144
745
|
event,
|
|
1145
746
|
native: { event: native },
|
|
1146
747
|
session,
|
|
1147
|
-
cwd:
|
|
748
|
+
cwd: str(raw.cwd) ?? "",
|
|
1148
749
|
raw
|
|
1149
750
|
};
|
|
1150
751
|
if (raw.agent_id !== void 0 && raw.agent_id !== null) {
|
|
@@ -1152,28 +753,28 @@ function decode2(raw) {
|
|
|
1152
753
|
if (typeof id !== "string" || !AGENT_ID_RE.test(id)) return null;
|
|
1153
754
|
input.agent = id;
|
|
1154
755
|
}
|
|
1155
|
-
const turn =
|
|
756
|
+
const turn = str(raw.prompt_id);
|
|
1156
757
|
if (turn !== void 0) input.turn = turn;
|
|
1157
|
-
const prompt =
|
|
758
|
+
const prompt = str(raw.prompt);
|
|
1158
759
|
if (prompt !== void 0) input.prompt = prompt;
|
|
1159
|
-
const agentType =
|
|
760
|
+
const agentType = str(raw.agent_type);
|
|
1160
761
|
if (agentType !== void 0) input.agentType = agentType;
|
|
1161
|
-
const lastMessage =
|
|
762
|
+
const lastMessage = str(raw.last_assistant_message);
|
|
1162
763
|
if (lastMessage !== void 0) input.lastMessage = lastMessage;
|
|
1163
764
|
if (typeof raw.stop_hook_active === "boolean") input.stopFuse = raw.stop_hook_active;
|
|
1164
|
-
const source =
|
|
765
|
+
const source = str(raw.source);
|
|
1165
766
|
if (source !== void 0) input.source = source;
|
|
1166
|
-
const path =
|
|
1167
|
-
const agentPath =
|
|
767
|
+
const path = str(raw.transcript_path);
|
|
768
|
+
const agentPath = str(raw.agent_transcript_path);
|
|
1168
769
|
if (path !== void 0 || agentPath !== void 0) {
|
|
1169
770
|
input.transcript = {};
|
|
1170
771
|
if (path !== void 0) input.transcript.path = path;
|
|
1171
772
|
if (agentPath !== void 0) input.transcript.agentPath = agentPath;
|
|
1172
773
|
}
|
|
1173
774
|
if (event === "tool.before" || event === "tool.after") {
|
|
1174
|
-
const name =
|
|
1175
|
-
const tool =
|
|
1176
|
-
const callId =
|
|
775
|
+
const name = str(raw.tool_name) ?? "";
|
|
776
|
+
const tool = canonicalTool(name, isRecord(raw.tool_input) ? raw.tool_input : {});
|
|
777
|
+
const callId = str(raw.tool_use_id);
|
|
1177
778
|
if (callId !== void 0) tool.callId = callId;
|
|
1178
779
|
if (event === "tool.after") {
|
|
1179
780
|
if (native === "PostToolUseFailure") {
|
|
@@ -1211,14 +812,14 @@ function httpHandler(url, token, timeoutSeconds) {
|
|
|
1211
812
|
timeout: timeoutSeconds
|
|
1212
813
|
};
|
|
1213
814
|
}
|
|
1214
|
-
function
|
|
815
|
+
function commandHandler(shimPath, timeoutSeconds) {
|
|
1215
816
|
return {
|
|
1216
817
|
type: "command",
|
|
1217
818
|
command: `node ${JSON.stringify(shimPath)} --harness claude`,
|
|
1218
819
|
timeout: timeoutSeconds
|
|
1219
820
|
};
|
|
1220
821
|
}
|
|
1221
|
-
var
|
|
822
|
+
var registrar = {
|
|
1222
823
|
configPath(home) {
|
|
1223
824
|
return claudeSettingsPath(home);
|
|
1224
825
|
},
|
|
@@ -1229,7 +830,7 @@ var registrar2 = {
|
|
|
1229
830
|
*/
|
|
1230
831
|
plan({ url, token, shimPath, timeoutSeconds }) {
|
|
1231
832
|
const http = [httpHandler(url, token, timeoutSeconds)];
|
|
1232
|
-
const command = [
|
|
833
|
+
const command = [commandHandler(shimPath, timeoutSeconds)];
|
|
1233
834
|
return [
|
|
1234
835
|
{ event: "SessionStart", matcher: SESSION_START_MATCHER, hooks: command },
|
|
1235
836
|
{ event: "UserPromptSubmit", hooks: command },
|
|
@@ -1261,7 +862,197 @@ var registrar2 = {
|
|
|
1261
862
|
write: wireFreeVerbAllowlist
|
|
1262
863
|
}
|
|
1263
864
|
};
|
|
1264
|
-
var claudeAdapter = { id: "claude", decode: decode2, encode: encode2, registrar
|
|
865
|
+
var claudeAdapter = { id: "claude", decode: decode2, encode: encode2, registrar };
|
|
866
|
+
|
|
867
|
+
// src/adapters/codex.ts
|
|
868
|
+
import { join as join6 } from "node:path";
|
|
869
|
+
|
|
870
|
+
// src/lib/codex-trust.ts
|
|
871
|
+
import { join as join5 } from "node:path";
|
|
872
|
+
function codexConfigPath(home, env = process.env) {
|
|
873
|
+
return join5(codexHome(home, env), "config.toml");
|
|
874
|
+
}
|
|
875
|
+
function isRecord2(v) {
|
|
876
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
877
|
+
}
|
|
878
|
+
function foldTrust(rows, keys) {
|
|
879
|
+
const wanted = new Set(keys);
|
|
880
|
+
const mine = rows.filter((r) => typeof r.key === "string" && wanted.has(r.key));
|
|
881
|
+
if (mine.length === 0) return "untrusted";
|
|
882
|
+
const status = (r) => typeof r.trustStatus === "string" ? r.trustStatus : "unknown";
|
|
883
|
+
if (mine.some((r) => r.enabled === false)) return "disabled";
|
|
884
|
+
if (mine.some((r) => status(r) === "modified")) return "modified";
|
|
885
|
+
const good = mine.filter((r) => status(r) === "trusted" || status(r) === "managed");
|
|
886
|
+
if (good.length === 0) return "untrusted";
|
|
887
|
+
if (good.length < keys.length) return "partial";
|
|
888
|
+
return "trusted";
|
|
889
|
+
}
|
|
890
|
+
var PROBE_MS = 8e3;
|
|
891
|
+
async function listHooksViaAppServer(home, env, timeoutMs) {
|
|
892
|
+
return await withAppServer(home, env, timeoutMs, async (request) => {
|
|
893
|
+
const result = await request("hooks/list", { cwds: [] });
|
|
894
|
+
return result === void 0 ? null : rowsOf(result);
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
function rowsOf(result) {
|
|
898
|
+
if (!isRecord2(result) || !Array.isArray(result.data)) return [];
|
|
899
|
+
const out = [];
|
|
900
|
+
for (const group of result.data) {
|
|
901
|
+
if (!isRecord2(group) || !Array.isArray(group.hooks)) continue;
|
|
902
|
+
for (const hook of group.hooks) if (isRecord2(hook)) out.push(hook);
|
|
903
|
+
}
|
|
904
|
+
return out;
|
|
905
|
+
}
|
|
906
|
+
async function trustCodexHooks(home, keys, ownedBy, opts = {}) {
|
|
907
|
+
const env = opts.env ?? process.env;
|
|
908
|
+
const timeoutMs = opts.timeoutMs ?? PROBE_MS;
|
|
909
|
+
if (keys.length === 0) return { ok: true, trusted: [] };
|
|
910
|
+
const run = async (request) => {
|
|
911
|
+
const before = await request("hooks/list", { cwds: [] });
|
|
912
|
+
if (before === void 0) {
|
|
913
|
+
return {
|
|
914
|
+
ok: false,
|
|
915
|
+
trusted: [],
|
|
916
|
+
failedAt: "list",
|
|
917
|
+
reason: "hooks/list did not answer"
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
const wanted = new Set(keys);
|
|
921
|
+
const mine = rowsOf(before).filter(
|
|
922
|
+
(r) => typeof r.key === "string" && wanted.has(r.key) && ownedBy(r)
|
|
923
|
+
);
|
|
924
|
+
if (mine.length !== keys.length) {
|
|
925
|
+
return {
|
|
926
|
+
ok: false,
|
|
927
|
+
trusted: [],
|
|
928
|
+
failedAt: "list",
|
|
929
|
+
reason: `Codex listed ${mine.length} of the ${keys.length} entries this install wrote`
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
const value = {};
|
|
933
|
+
for (const row of mine) {
|
|
934
|
+
const hash = typeof row.currentHash === "string" ? row.currentHash : null;
|
|
935
|
+
if (hash === null) {
|
|
936
|
+
return {
|
|
937
|
+
ok: false,
|
|
938
|
+
trusted: [],
|
|
939
|
+
failedAt: "list",
|
|
940
|
+
reason: "Codex reported an entry with no currentHash"
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
value[row.key] = { trusted_hash: hash, enabled: true };
|
|
944
|
+
}
|
|
945
|
+
const wrote = await request("config/batchWrite", {
|
|
946
|
+
edits: [{ keyPath: "hooks.state", value, mergeStrategy: "upsert" }],
|
|
947
|
+
reloadUserConfig: true
|
|
948
|
+
});
|
|
949
|
+
if (wrote === void 0) {
|
|
950
|
+
return {
|
|
951
|
+
ok: false,
|
|
952
|
+
trusted: [],
|
|
953
|
+
failedAt: "write",
|
|
954
|
+
reason: "config/batchWrite was refused"
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
const after = await request("hooks/list", { cwds: [] });
|
|
958
|
+
if (after === void 0) {
|
|
959
|
+
return {
|
|
960
|
+
ok: false,
|
|
961
|
+
trusted: [],
|
|
962
|
+
failedAt: "verify",
|
|
963
|
+
reason: "the verifying hooks/list did not answer"
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
const confirmed = rowsOf(after).filter(
|
|
967
|
+
(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
|
|
968
|
+
);
|
|
969
|
+
if (confirmed.length !== keys.length) {
|
|
970
|
+
return {
|
|
971
|
+
ok: false,
|
|
972
|
+
trusted: confirmed.map((r) => r.key),
|
|
973
|
+
failedAt: "verify",
|
|
974
|
+
reason: `Codex confirmed ${confirmed.length} of ${keys.length} entries as trusted after the write`
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
return { ok: true, trusted: confirmed.map((r) => r.key) };
|
|
978
|
+
};
|
|
979
|
+
const outcome = opts.connect !== void 0 ? await run(opts.connect) : await withAppServer(home, env, timeoutMs, run);
|
|
980
|
+
return outcome ?? {
|
|
981
|
+
ok: false,
|
|
982
|
+
trusted: [],
|
|
983
|
+
failedAt: "list",
|
|
984
|
+
reason: "the codex app server could not be reached"
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
async function readCodexTrust(home, keys, opts = {}) {
|
|
988
|
+
const env = opts.env ?? process.env;
|
|
989
|
+
const configPath2 = codexConfigPath(home, env);
|
|
990
|
+
const base = { configPath: configPath2, trusted: 0, expected: keys.length };
|
|
991
|
+
if (keys.length === 0) return { ...base, state: "unknown", source: "none" };
|
|
992
|
+
const list = await (opts.listHooks ?? ((h, e) => listHooksViaAppServer(h, e, opts.timeoutMs ?? PROBE_MS)))(home, env);
|
|
993
|
+
if (list !== null) {
|
|
994
|
+
const state = foldTrust(list, keys);
|
|
995
|
+
const wanted = new Set(keys);
|
|
996
|
+
const trusted = list.filter(
|
|
997
|
+
(r) => typeof r.key === "string" && wanted.has(r.key) && (r.trustStatus === "trusted" || r.trustStatus === "managed")
|
|
998
|
+
).length;
|
|
999
|
+
return { ...base, trusted, state, source: "app-server" };
|
|
1000
|
+
}
|
|
1001
|
+
return { ...base, state: "unknown", source: "none" };
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// src/adapters/codex.ts
|
|
1005
|
+
function commandHandler2(shimPath, timeoutSeconds) {
|
|
1006
|
+
return {
|
|
1007
|
+
type: "command",
|
|
1008
|
+
command: `node ${JSON.stringify(shimPath)} --harness codex`,
|
|
1009
|
+
timeout: timeoutSeconds
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
var registrar2 = {
|
|
1013
|
+
configPath(home, env) {
|
|
1014
|
+
return join6(codexHome(home, env), "hooks.json");
|
|
1015
|
+
},
|
|
1016
|
+
/**
|
|
1017
|
+
* Seven `command` entries, every one through the shim: a Codex handler
|
|
1018
|
+
* carries no URL or token, so the daemon is ensured on each fire and the
|
|
1019
|
+
* entry holds nothing worth protecting. The matchers are the two hooked
|
|
1020
|
+
* tool names the arms read; a child's fires arrive through the same entries.
|
|
1021
|
+
*/
|
|
1022
|
+
plan({ shimPath, timeoutSeconds }) {
|
|
1023
|
+
const command = [commandHandler2(shimPath, timeoutSeconds)];
|
|
1024
|
+
return [
|
|
1025
|
+
{ event: "SessionStart", hooks: command },
|
|
1026
|
+
{ event: "UserPromptSubmit", hooks: command },
|
|
1027
|
+
{ event: "PreToolUse", matcher: `${SHELL_TOOL}|${PATCH_TOOL}`, hooks: command },
|
|
1028
|
+
{ event: "PostToolUse", matcher: SHELL_TOOL, hooks: command },
|
|
1029
|
+
{ event: "SubagentStart", hooks: command },
|
|
1030
|
+
{ event: "SubagentStop", hooks: command },
|
|
1031
|
+
{ event: "Stop", hooks: command }
|
|
1032
|
+
];
|
|
1033
|
+
},
|
|
1034
|
+
/**
|
|
1035
|
+
* Codex reads hooks once, at session start. `install` now trusts the entries
|
|
1036
|
+
* it writes through Codex's own supported path (lib/codex-trust.ts), so the
|
|
1037
|
+
* `/hooks` walkthrough this used to carry is gone; what is left is the one
|
|
1038
|
+
* fact no installer can change, which is that the session already open still
|
|
1039
|
+
* has the hook set it started with (tenjin-agent#343).
|
|
1040
|
+
*/
|
|
1041
|
+
activation() {
|
|
1042
|
+
return ["Start a new Codex session: hooks are read at session start."];
|
|
1043
|
+
},
|
|
1044
|
+
grant: {
|
|
1045
|
+
path: codexRulesPath,
|
|
1046
|
+
inspect: inspectCodexGrant,
|
|
1047
|
+
write: wireCodexGrant,
|
|
1048
|
+
remove: removeCodexGrant
|
|
1049
|
+
},
|
|
1050
|
+
trust: {
|
|
1051
|
+
ensure: trustCodexHooks,
|
|
1052
|
+
read: readCodexTrust
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
var codexAdapter = { id: "codex", decode, encode, registrar: registrar2 };
|
|
1265
1056
|
|
|
1266
1057
|
// src/adapters/registry.ts
|
|
1267
1058
|
var ADAPTERS = {
|
|
@@ -2224,4 +2015,4 @@ export {
|
|
|
2224
2015
|
persistInstallHarness,
|
|
2225
2016
|
persistGrantDeclined
|
|
2226
2017
|
};
|
|
2227
|
-
//# sourceMappingURL=chunk-
|
|
2018
|
+
//# sourceMappingURL=chunk-5MARFNSB.js.map
|