tenjin-cli 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +33 -0
- package/README.md +596 -79
- package/dist/{_esm-ZH2J4QEH.js → _esm-C5CRWCYU.js} +2 -2
- package/dist/_esm-N4KAVXQR.js +881 -0
- package/dist/buy-THMVOPUH.js +44 -0
- package/dist/ccip-RPPPKTJR.js +19 -0
- package/dist/{ccip-UCLT5VOW.js → ccip-ZGGWQN4X.js} +6 -5
- package/dist/chunk-2I4QTOLB.js +11 -0
- package/dist/chunk-2I4QTOLB.js.map +1 -0
- package/dist/chunk-2SDUV6MQ.js +352 -0
- package/dist/chunk-2SDUV6MQ.js.map +1 -0
- package/dist/chunk-3GSZUADW.js +199 -0
- package/dist/chunk-3GSZUADW.js.map +1 -0
- package/dist/{chunk-BRJHUQSY.js → chunk-47PP7TAG.js} +908 -812
- package/dist/chunk-47PP7TAG.js.map +1 -0
- package/dist/chunk-4NTZETIL.js +158 -0
- package/dist/chunk-4NTZETIL.js.map +1 -0
- package/dist/chunk-4TCU3YRD.js +130 -0
- package/dist/chunk-4TCU3YRD.js.map +1 -0
- package/dist/chunk-6BGYHARE.js +14620 -0
- package/dist/chunk-6BGYHARE.js.map +1 -0
- package/dist/chunk-6UY2UQMY.js +213 -0
- package/dist/chunk-6UY2UQMY.js.map +1 -0
- package/dist/{chunk-IPOWB3G3.js → chunk-7FK2UN2T.js} +3515 -507
- package/dist/chunk-7FK2UN2T.js.map +1 -0
- package/dist/chunk-ALUNME53.js +306 -0
- package/dist/chunk-ALUNME53.js.map +1 -0
- package/dist/{chunk-EXBMF5X7.js → chunk-CNUXRXI2.js} +526 -79
- package/dist/chunk-CNUXRXI2.js.map +1 -0
- package/dist/chunk-E6YOODH7.js +913 -0
- package/dist/chunk-E6YOODH7.js.map +1 -0
- package/dist/chunk-EDVI7RRD.js +317 -0
- package/dist/chunk-EDVI7RRD.js.map +1 -0
- package/dist/chunk-FKSAUOJU.js +137 -0
- package/dist/chunk-FKSAUOJU.js.map +1 -0
- package/dist/chunk-GKV6VZSZ.js +125 -0
- package/dist/chunk-GKV6VZSZ.js.map +1 -0
- package/dist/chunk-GUUAYR3K.js +175 -0
- package/dist/chunk-GUUAYR3K.js.map +1 -0
- package/dist/chunk-IAFYUFIC.js +1408 -0
- package/dist/chunk-IAFYUFIC.js.map +1 -0
- package/dist/chunk-IB63U6BM.js +185 -0
- package/dist/chunk-IB63U6BM.js.map +1 -0
- package/dist/chunk-IXTENA2H.js +235 -0
- package/dist/chunk-IXTENA2H.js.map +1 -0
- package/dist/chunk-JTYIX6OD.js +161 -0
- package/dist/chunk-JTYIX6OD.js.map +1 -0
- package/dist/chunk-KYQVEKP5.js +209 -0
- package/dist/chunk-KYQVEKP5.js.map +1 -0
- package/dist/chunk-KZAAWQNP.js +6199 -0
- package/dist/chunk-KZAAWQNP.js.map +1 -0
- package/dist/{chunk-T4LKNY7T.js → chunk-M2O56UK7.js} +225 -70
- package/dist/chunk-M2O56UK7.js.map +1 -0
- package/dist/chunk-MJZZTKCC.js +323 -0
- package/dist/chunk-MJZZTKCC.js.map +1 -0
- package/dist/chunk-NUF2PKJO.js +207 -0
- package/dist/chunk-NUF2PKJO.js.map +1 -0
- package/dist/chunk-O25VWJCG.js +1357 -0
- package/dist/chunk-O25VWJCG.js.map +1 -0
- package/dist/chunk-OCN27NJV.js +612 -0
- package/dist/chunk-OCN27NJV.js.map +1 -0
- package/dist/chunk-OZHJ3FLR.js +105 -0
- package/dist/chunk-OZHJ3FLR.js.map +1 -0
- package/dist/chunk-P74I3WH4.js +204 -0
- package/dist/chunk-P74I3WH4.js.map +1 -0
- package/dist/chunk-POJRB2AE.js +83 -0
- package/dist/chunk-POJRB2AE.js.map +1 -0
- package/dist/{chunk-YG2DO46P.js → chunk-PZRAAAY2.js} +107 -22
- package/dist/chunk-PZRAAAY2.js.map +1 -0
- package/dist/chunk-PZSUWDF2.js +35 -0
- package/dist/chunk-PZSUWDF2.js.map +1 -0
- package/dist/chunk-QW2Q2KAH.js +27 -0
- package/dist/chunk-QW2Q2KAH.js.map +1 -0
- package/dist/{chunk-CUWUHTIL.js → chunk-RBJPAZFI.js} +16 -202
- package/dist/chunk-RBJPAZFI.js.map +1 -0
- package/dist/chunk-RSBN67PA.js +152 -0
- package/dist/chunk-RSBN67PA.js.map +1 -0
- package/dist/chunk-S5RYMCV6.js +70 -0
- package/dist/chunk-S5RYMCV6.js.map +1 -0
- package/dist/chunk-SFGXAZ3M.js +316 -0
- package/dist/chunk-SFGXAZ3M.js.map +1 -0
- package/dist/chunk-SGK2B724.js +67 -0
- package/dist/chunk-SGK2B724.js.map +1 -0
- package/dist/chunk-TDDN5GXR.js +145 -0
- package/dist/chunk-TDDN5GXR.js.map +1 -0
- package/dist/{chunk-LPRVHM7P.js → chunk-U5S527PP.js} +1655 -114
- package/dist/chunk-U5S527PP.js.map +1 -0
- package/dist/chunk-UFPJBS4C.js +242 -0
- package/dist/chunk-UFPJBS4C.js.map +1 -0
- package/dist/chunk-UHTVXQ2O.js +140 -0
- package/dist/chunk-UHTVXQ2O.js.map +1 -0
- package/dist/chunk-UY6CGULW.js +83 -0
- package/dist/chunk-UY6CGULW.js.map +1 -0
- package/dist/chunk-VWY3U732.js +674 -0
- package/dist/chunk-VWY3U732.js.map +1 -0
- package/dist/{chunk-Q53IYV2G.js → chunk-W6R3HAAG.js} +20 -17
- package/dist/{chunk-Q53IYV2G.js.map → chunk-W6R3HAAG.js.map} +1 -1
- package/dist/chunk-XJN5WUKL.js +204 -0
- package/dist/chunk-XJN5WUKL.js.map +1 -0
- package/dist/chunk-XWHXX2BI.js +149 -0
- package/dist/chunk-XWHXX2BI.js.map +1 -0
- package/dist/{chunk-DXPYFVKG.js → chunk-Y7ERTA7D.js} +35 -15
- package/dist/chunk-Y7ERTA7D.js.map +1 -0
- package/dist/chunk-YLYINX2H.js +7806 -0
- package/dist/chunk-YLYINX2H.js.map +1 -0
- package/dist/chunk-ZE7KOO7A.js +233 -0
- package/dist/chunk-ZE7KOO7A.js.map +1 -0
- package/dist/chunk-ZQIQ55KK.js +51 -0
- package/dist/chunk-ZQIQ55KK.js.map +1 -0
- package/dist/{chunk-3IMLRUZE.js → chunk-ZXTAQYNA.js} +6 -2
- package/dist/{cli-WA65NP4Y.js → cli-Y2HBOSGK.js} +437 -175
- package/dist/cli-Y2HBOSGK.js.map +1 -0
- package/dist/config-WDGMZKHU.js +26 -0
- package/dist/config-WDGMZKHU.js.map +1 -0
- package/dist/dist-U4M6QCKE.js +2842 -0
- package/dist/dist-U4M6QCKE.js.map +1 -0
- package/dist/doctor-CSIWKWM2.js +27 -0
- package/dist/doctor-CSIWKWM2.js.map +1 -0
- package/dist/edit-E7N6F3OY.js +38 -0
- package/dist/edit-E7N6F3OY.js.map +1 -0
- package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js +18 -0
- package/dist/ethersCompat-Df4a6QIZ-WHYKB6HA.js.map +1 -0
- package/dist/fund-OKK627GL.js +38 -0
- package/dist/fund-OKK627GL.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspect-573WHEV4.js +35 -0
- package/dist/inspect-573WHEV4.js.map +1 -0
- package/dist/install-SQAYMNQC.js +1134 -0
- package/dist/install-SQAYMNQC.js.map +1 -0
- package/dist/{mine.wasm-GQECMSGN.js → mine.wasm-6PIT3DK6.js} +2 -2
- package/dist/outcome-W3KYGF23.js +22 -0
- package/dist/outcome-W3KYGF23.js.map +1 -0
- package/dist/publish-N5U4XYVA.js +40 -0
- package/dist/publish-N5U4XYVA.js.map +1 -0
- package/dist/read-PJ7Z6UGF.js +158 -0
- package/dist/read-PJ7Z6UGF.js.map +1 -0
- package/dist/run-FSO3MMXN.js +16883 -0
- package/dist/run-FSO3MMXN.js.map +1 -0
- package/dist/search-ZWOP4EGK.js +23 -0
- package/dist/search-ZWOP4EGK.js.map +1 -0
- package/dist/{secp256k1-BEZS642W.js → secp256k1-XRPVBC6V.js} +5 -4
- package/dist/secp256k1-XRPVBC6V.js.map +1 -0
- package/dist/send-F34ZDXDZ.js +223 -0
- package/dist/send-F34ZDXDZ.js.map +1 -0
- package/dist/session-4N4ZT3AH.js +88 -0
- package/dist/session-4N4ZT3AH.js.map +1 -0
- package/dist/skill-heal-XBEK272G.js +85 -0
- package/dist/skill-heal-XBEK272G.js.map +1 -0
- package/dist/uninstall-BTKPHPDL.js +68 -0
- package/dist/uninstall-BTKPHPDL.js.map +1 -0
- package/dist/usdc-4VCDHFWX.js +38 -0
- package/dist/usdc-4VCDHFWX.js.map +1 -0
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js +14 -0
- package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +1 -0
- package/dist/wallet-UL4P2JRO.js +42 -0
- package/dist/wallet-UL4P2JRO.js.map +1 -0
- package/dist/wallet-WJ6UP5OU.js +32 -0
- package/dist/wallet-WJ6UP5OU.js.map +1 -0
- package/docs/agent-permissions.md +294 -0
- package/package.json +25 -18
- package/skills/tenjin/SKILL.md +364 -0
- package/skills/tenjin-publish/SKILL.md +232 -0
- package/skills/tenjin-search/SKILL.md +341 -0
- package/dist/chunk-BRJHUQSY.js.map +0 -1
- package/dist/chunk-CUWUHTIL.js.map +0 -1
- package/dist/chunk-DXPYFVKG.js.map +0 -1
- package/dist/chunk-EXBMF5X7.js.map +0 -1
- package/dist/chunk-EZROUI5U.js +0 -135
- package/dist/chunk-EZROUI5U.js.map +0 -1
- package/dist/chunk-IPOWB3G3.js.map +0 -1
- package/dist/chunk-LPRVHM7P.js.map +0 -1
- package/dist/chunk-T4LKNY7T.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js +0 -51
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YG2DO46P.js.map +0 -1
- package/dist/chunk-ZPZFPVDN.js +0 -67
- package/dist/chunk-ZPZFPVDN.js.map +0 -1
- package/dist/cli-WA65NP4Y.js.map +0 -1
- package/dist/config-CEFTL5ZL.js +0 -164
- package/dist/config-CEFTL5ZL.js.map +0 -1
- package/dist/doctor-3QBYN46N.js +0 -338
- package/dist/doctor-3QBYN46N.js.map +0 -1
- package/dist/usdc-44R6XZF2.js +0 -18
- package/dist/wallet-ELBTBMXO.js +0 -20
- package/dist/wallet-XD576HF3.js +0 -173
- package/dist/wallet-XD576HF3.js.map +0 -1
- /package/dist/{_esm-ZH2J4QEH.js.map → _esm-C5CRWCYU.js.map} +0 -0
- /package/dist/{ccip-UCLT5VOW.js.map → _esm-N4KAVXQR.js.map} +0 -0
- /package/dist/{chunk-3IMLRUZE.js.map → buy-THMVOPUH.js.map} +0 -0
- /package/dist/{secp256k1-BEZS642W.js.map → ccip-RPPPKTJR.js.map} +0 -0
- /package/dist/{usdc-44R6XZF2.js.map → ccip-ZGGWQN4X.js.map} +0 -0
- /package/dist/{wallet-ELBTBMXO.js.map → chunk-ZXTAQYNA.js.map} +0 -0
- /package/dist/{mine.wasm-GQECMSGN.js.map → mine.wasm-6PIT3DK6.js.map} +0 -0
|
@@ -0,0 +1,1134 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
runWalletCreate
|
|
4
|
+
} from "./chunk-UFPJBS4C.js";
|
|
5
|
+
import "./chunk-MJZZTKCC.js";
|
|
6
|
+
import {
|
|
7
|
+
describeWallet,
|
|
8
|
+
resolveWalletProvider
|
|
9
|
+
} from "./chunk-CNUXRXI2.js";
|
|
10
|
+
import {
|
|
11
|
+
collectDoctorChecks,
|
|
12
|
+
isNoWalletCheck
|
|
13
|
+
} from "./chunk-VWY3U732.js";
|
|
14
|
+
import {
|
|
15
|
+
PERMISSIONS_DOC_URL,
|
|
16
|
+
recommendedPermissions
|
|
17
|
+
} from "./chunk-4TCU3YRD.js";
|
|
18
|
+
import "./chunk-3GSZUADW.js";
|
|
19
|
+
import "./chunk-UY6CGULW.js";
|
|
20
|
+
import "./chunk-NUF2PKJO.js";
|
|
21
|
+
import "./chunk-PZSUWDF2.js";
|
|
22
|
+
import {
|
|
23
|
+
walletFileExists
|
|
24
|
+
} from "./chunk-Y7ERTA7D.js";
|
|
25
|
+
import {
|
|
26
|
+
FREE_VERB_RULES,
|
|
27
|
+
STOP_HOOK_FILE,
|
|
28
|
+
WEBSEARCH_HOOK_FILE,
|
|
29
|
+
claudeSettingsPath,
|
|
30
|
+
inspectFreeVerbRules,
|
|
31
|
+
permissionsSkipped,
|
|
32
|
+
removeMarkerLines,
|
|
33
|
+
stopHookScript,
|
|
34
|
+
websearchHookScript,
|
|
35
|
+
wireFreeVerbAllowlist
|
|
36
|
+
} from "./chunk-E6YOODH7.js";
|
|
37
|
+
import {
|
|
38
|
+
installSkill
|
|
39
|
+
} from "./chunk-RSBN67PA.js";
|
|
40
|
+
import {
|
|
41
|
+
sanitizeForTerminal
|
|
42
|
+
} from "./chunk-IB63U6BM.js";
|
|
43
|
+
import {
|
|
44
|
+
persistInstallHarness,
|
|
45
|
+
persistPublishMode,
|
|
46
|
+
persistSearchHookMode
|
|
47
|
+
} from "./chunk-SFGXAZ3M.js";
|
|
48
|
+
import "./chunk-JTYIX6OD.js";
|
|
49
|
+
import {
|
|
50
|
+
ownsAnyLock,
|
|
51
|
+
releaseOwnedLocks
|
|
52
|
+
} from "./chunk-FKSAUOJU.js";
|
|
53
|
+
import {
|
|
54
|
+
CONFIG_DEFAULTS,
|
|
55
|
+
PublishModeSchema,
|
|
56
|
+
SearchHookModeSchema,
|
|
57
|
+
loadRawConfig,
|
|
58
|
+
parsePublishModeFlag,
|
|
59
|
+
parseSearchHookModeFlag
|
|
60
|
+
} from "./chunk-ALUNME53.js";
|
|
61
|
+
import {
|
|
62
|
+
hooksDir,
|
|
63
|
+
walletPath
|
|
64
|
+
} from "./chunk-ZQIQ55KK.js";
|
|
65
|
+
import {
|
|
66
|
+
CLI_SKILL_NAMES,
|
|
67
|
+
HARNESS_TARGETS,
|
|
68
|
+
HOSTED_SKILL_NAME,
|
|
69
|
+
SKILL_NAMES,
|
|
70
|
+
harnessDetectedBy,
|
|
71
|
+
harnessTargetDir,
|
|
72
|
+
isModelInvocationDisabled,
|
|
73
|
+
onPath,
|
|
74
|
+
readSkillFile,
|
|
75
|
+
resolveSkillsSource
|
|
76
|
+
} from "./chunk-P74I3WH4.js";
|
|
77
|
+
import {
|
|
78
|
+
hasCode
|
|
79
|
+
} from "./chunk-2I4QTOLB.js";
|
|
80
|
+
import {
|
|
81
|
+
CliError,
|
|
82
|
+
external_exports,
|
|
83
|
+
writeFileAtomic
|
|
84
|
+
} from "./chunk-PZRAAAY2.js";
|
|
85
|
+
import "./chunk-7FK2UN2T.js";
|
|
86
|
+
import "./chunk-M2O56UK7.js";
|
|
87
|
+
import "./chunk-UHTVXQ2O.js";
|
|
88
|
+
import "./chunk-W6R3HAAG.js";
|
|
89
|
+
import "./chunk-U5S527PP.js";
|
|
90
|
+
import "./chunk-47PP7TAG.js";
|
|
91
|
+
import "./chunk-XJN5WUKL.js";
|
|
92
|
+
import "./chunk-RBJPAZFI.js";
|
|
93
|
+
import "./chunk-KYQVEKP5.js";
|
|
94
|
+
import "./chunk-ZXTAQYNA.js";
|
|
95
|
+
|
|
96
|
+
// src/commands/install.ts
|
|
97
|
+
import { existsSync } from "fs";
|
|
98
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
99
|
+
import { fileURLToPath } from "url";
|
|
100
|
+
import { dirname, isAbsolute, join as join2 } from "path";
|
|
101
|
+
import { homedir } from "os";
|
|
102
|
+
import { styleText } from "util";
|
|
103
|
+
import { Stream } from "stream";
|
|
104
|
+
|
|
105
|
+
// src/lib/harness-hooks.ts
|
|
106
|
+
import { lstat, readFile, realpath } from "fs/promises";
|
|
107
|
+
import { join } from "path";
|
|
108
|
+
var WEBSEARCH_MATCHER = "WebSearch";
|
|
109
|
+
var HOOK_TIMEOUT_SECONDS = 5;
|
|
110
|
+
function hooksUndo(settingsPath, scriptsDir) {
|
|
111
|
+
return `Undo anytime: \`tenjin config set hooks.searchMode off\` disarms them, or delete the tenjin hook entries from ${settingsPath} and the scripts in ${scriptsDir}.`;
|
|
112
|
+
}
|
|
113
|
+
function skip(reason, args) {
|
|
114
|
+
return {
|
|
115
|
+
harness: args.harness,
|
|
116
|
+
...args.path !== void 0 ? { path: args.path } : {},
|
|
117
|
+
scriptsDir: args.scriptsDir,
|
|
118
|
+
mode: args.mode,
|
|
119
|
+
added: [],
|
|
120
|
+
alreadyPresent: [],
|
|
121
|
+
updated: [],
|
|
122
|
+
scripts: [],
|
|
123
|
+
skipped: reason,
|
|
124
|
+
...args.warning !== void 0 ? { warning: args.warning } : {},
|
|
125
|
+
...args.fix !== void 0 ? { fix: args.fix } : {}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function hooksSkipped(harness, homeDir, dataDir, mode, reason) {
|
|
129
|
+
return skip(reason, {
|
|
130
|
+
harness,
|
|
131
|
+
...harness === "claude" ? { path: claudeSettingsPath(homeDir) } : {},
|
|
132
|
+
scriptsDir: hooksDir(dataDir),
|
|
133
|
+
mode,
|
|
134
|
+
fix: fixFor(reason)
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function fixFor(reason) {
|
|
138
|
+
switch (reason) {
|
|
139
|
+
case "harness-not-claude":
|
|
140
|
+
return "Hooks are wired for Claude Code only. Re-run `tenjin install --harness claude` on a machine with Claude Code.";
|
|
141
|
+
case "mode-off":
|
|
142
|
+
return "Enable them with `tenjin config set hooks.searchMode auto`, then re-run `tenjin install`.";
|
|
143
|
+
case "declined":
|
|
144
|
+
case "dry-run":
|
|
145
|
+
return "Wire them with `tenjin install --search-hooks auto`.";
|
|
146
|
+
case "changed-since-read":
|
|
147
|
+
return "Another process changed the file mid-run; re-run `tenjin install`.";
|
|
148
|
+
default:
|
|
149
|
+
return "Fix the reported file, then re-run `tenjin install --search-hooks auto`.";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function isPlainObject(value) {
|
|
153
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
154
|
+
}
|
|
155
|
+
function quoteForShell(path, platform = process.platform) {
|
|
156
|
+
if (platform === "win32") return `"${path}"`;
|
|
157
|
+
return `'${path.replaceAll("'", `'\\''`)}'`;
|
|
158
|
+
}
|
|
159
|
+
function commandFor(scriptPath, platform) {
|
|
160
|
+
return `node ${quoteForShell(scriptPath, platform)}`;
|
|
161
|
+
}
|
|
162
|
+
function handlerFor(scriptPath, platform) {
|
|
163
|
+
return {
|
|
164
|
+
type: "command",
|
|
165
|
+
command: commandFor(scriptPath, platform),
|
|
166
|
+
timeout: HOOK_TIMEOUT_SECONDS
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function ownsEntry(entry, scriptFile) {
|
|
170
|
+
if (!isPlainObject(entry)) return false;
|
|
171
|
+
const handlers = entry.hooks;
|
|
172
|
+
if (!Array.isArray(handlers)) return false;
|
|
173
|
+
return handlers.some(
|
|
174
|
+
(h) => isPlainObject(h) && typeof h.command === "string" && h.command.includes(scriptFile)
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
function specs(dataDir) {
|
|
178
|
+
return [
|
|
179
|
+
{
|
|
180
|
+
event: "PreToolUse",
|
|
181
|
+
scriptFile: WEBSEARCH_HOOK_FILE,
|
|
182
|
+
script: websearchHookScript(dataDir),
|
|
183
|
+
matcher: WEBSEARCH_MATCHER
|
|
184
|
+
},
|
|
185
|
+
{ event: "Stop", scriptFile: STOP_HOOK_FILE, script: stopHookScript(dataDir) }
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
async function wireSearchHooks(opts) {
|
|
189
|
+
const { homeDir, dataDir, mode, platform } = opts;
|
|
190
|
+
const scriptsDir = hooksDir(dataDir);
|
|
191
|
+
const plan = specs(dataDir);
|
|
192
|
+
const found = await inspectSettings(homeDir, scriptsDir, mode);
|
|
193
|
+
if ("result" in found) return found.result;
|
|
194
|
+
const { path, raw, settings, hooks } = found;
|
|
195
|
+
const added = [];
|
|
196
|
+
const alreadyPresent = [];
|
|
197
|
+
const updated = [];
|
|
198
|
+
const nextHooks = { ...hooks };
|
|
199
|
+
for (const spec of plan) {
|
|
200
|
+
const existing = hooks[spec.event];
|
|
201
|
+
if (existing !== void 0 && !Array.isArray(existing)) {
|
|
202
|
+
return refuse(
|
|
203
|
+
path,
|
|
204
|
+
scriptsDir,
|
|
205
|
+
mode,
|
|
206
|
+
"unexpected-shape",
|
|
207
|
+
`${path} has a "hooks.${spec.event}" key that is not an array; it was left exactly as it is.`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const list = existing ?? [];
|
|
211
|
+
const desired = {
|
|
212
|
+
...spec.matcher !== void 0 ? { matcher: spec.matcher } : {},
|
|
213
|
+
hooks: [handlerFor(join(scriptsDir, spec.scriptFile), platform)]
|
|
214
|
+
};
|
|
215
|
+
const idx = list.findIndex((e) => ownsEntry(e, spec.scriptFile));
|
|
216
|
+
if (idx === -1) {
|
|
217
|
+
nextHooks[spec.event] = [...list, desired];
|
|
218
|
+
added.push(spec.event);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (JSON.stringify(list[idx]) === JSON.stringify(desired)) {
|
|
222
|
+
alreadyPresent.push(spec.event);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
nextHooks[spec.event] = list.map((e, i) => i === idx ? desired : e);
|
|
226
|
+
updated.push(spec.event);
|
|
227
|
+
}
|
|
228
|
+
if (added.length === 0 && updated.length === 0) {
|
|
229
|
+
const scripts2 = await writeScripts(plan, scriptsDir);
|
|
230
|
+
return { harness: "claude", path, scriptsDir, mode, added, alreadyPresent, updated, scripts: scripts2 };
|
|
231
|
+
}
|
|
232
|
+
const next = { ...settings, hooks: nextHooks };
|
|
233
|
+
const changed = async () => await readFile(path, "utf8").catch(() => null) !== raw;
|
|
234
|
+
if (await changed()) return refuseChanged(path, scriptsDir, mode, []);
|
|
235
|
+
const scripts = await writeScripts(plan, scriptsDir);
|
|
236
|
+
if (await changed()) return refuseChanged(path, scriptsDir, mode, scripts);
|
|
237
|
+
await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
|
|
238
|
+
`);
|
|
239
|
+
return { harness: "claude", path, scriptsDir, mode, added, alreadyPresent, updated, scripts };
|
|
240
|
+
}
|
|
241
|
+
function refuseChanged(path, scriptsDir, mode, scripts) {
|
|
242
|
+
return {
|
|
243
|
+
...refuse(
|
|
244
|
+
path,
|
|
245
|
+
scriptsDir,
|
|
246
|
+
mode,
|
|
247
|
+
"changed-since-read",
|
|
248
|
+
`${path} changed while it was being updated, so no hooks were registered. Re-run \`tenjin install\`.`
|
|
249
|
+
),
|
|
250
|
+
scripts
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async function writeScripts(plan, scriptsDir) {
|
|
254
|
+
const written = [];
|
|
255
|
+
for (const spec of plan) {
|
|
256
|
+
const target = join(scriptsDir, spec.scriptFile);
|
|
257
|
+
const onDisk = await readFile(target, "utf8").catch(() => null);
|
|
258
|
+
if (onDisk === spec.script) continue;
|
|
259
|
+
await writeFileAtomic(target, spec.script, { mode: 493, dirMode: 448 });
|
|
260
|
+
written.push(target);
|
|
261
|
+
}
|
|
262
|
+
return written;
|
|
263
|
+
}
|
|
264
|
+
function refuse(path, scriptsDir, mode, reason, warning) {
|
|
265
|
+
return skip(reason, { harness: "claude", path, scriptsDir, mode, warning, fix: fixFor(reason) });
|
|
266
|
+
}
|
|
267
|
+
async function inspectSettings(homeDir, scriptsDir, mode) {
|
|
268
|
+
const declaredPath = claudeSettingsPath(homeDir);
|
|
269
|
+
const entry = await lstat(declaredPath).catch(() => null);
|
|
270
|
+
let path = declaredPath;
|
|
271
|
+
if (entry !== null) {
|
|
272
|
+
try {
|
|
273
|
+
path = await realpath(declaredPath);
|
|
274
|
+
} catch (err) {
|
|
275
|
+
return {
|
|
276
|
+
result: refuse(
|
|
277
|
+
declaredPath,
|
|
278
|
+
scriptsDir,
|
|
279
|
+
mode,
|
|
280
|
+
"unresolvable",
|
|
281
|
+
`${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
|
|
282
|
+
)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
let settings = {};
|
|
287
|
+
let raw = null;
|
|
288
|
+
if (entry !== null) {
|
|
289
|
+
try {
|
|
290
|
+
raw = await readFile(path, "utf8");
|
|
291
|
+
} catch (err) {
|
|
292
|
+
return {
|
|
293
|
+
result: refuse(
|
|
294
|
+
path,
|
|
295
|
+
scriptsDir,
|
|
296
|
+
mode,
|
|
297
|
+
"unreadable",
|
|
298
|
+
`${path} could not be read (${err.message}); no hooks were registered.`
|
|
299
|
+
)
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
let parsed;
|
|
303
|
+
try {
|
|
304
|
+
parsed = JSON.parse(raw);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
return {
|
|
307
|
+
result: refuse(
|
|
308
|
+
path,
|
|
309
|
+
scriptsDir,
|
|
310
|
+
mode,
|
|
311
|
+
"unparsable",
|
|
312
|
+
`${path} is not valid JSON (${err.message}); it was left exactly as it is.`
|
|
313
|
+
)
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (!isPlainObject(parsed)) {
|
|
317
|
+
return {
|
|
318
|
+
result: refuse(
|
|
319
|
+
path,
|
|
320
|
+
scriptsDir,
|
|
321
|
+
mode,
|
|
322
|
+
"unexpected-shape",
|
|
323
|
+
`${path} is not a JSON object; it was left exactly as it is.`
|
|
324
|
+
)
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
settings = parsed;
|
|
328
|
+
}
|
|
329
|
+
const hooksValue = settings.hooks;
|
|
330
|
+
if (hooksValue !== void 0 && !isPlainObject(hooksValue)) {
|
|
331
|
+
return {
|
|
332
|
+
result: refuse(
|
|
333
|
+
path,
|
|
334
|
+
scriptsDir,
|
|
335
|
+
mode,
|
|
336
|
+
"unexpected-shape",
|
|
337
|
+
`${path} has a "hooks" key that is not an object; it was left exactly as it is.`
|
|
338
|
+
)
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
return { path, raw, settings, hooks: hooksValue ?? {} };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/lib/clack.ts
|
|
345
|
+
var SHOW_CURSOR = "\x1B[?25h";
|
|
346
|
+
function withInputEnd(streams, onEnd, run) {
|
|
347
|
+
const controller = new AbortController();
|
|
348
|
+
let settleEnd;
|
|
349
|
+
const ended = new Promise((resolve) => {
|
|
350
|
+
settleEnd = () => {
|
|
351
|
+
streams.output.write(SHOW_CURSOR);
|
|
352
|
+
resolve(onEnd);
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
const end = () => {
|
|
356
|
+
controller.abort();
|
|
357
|
+
settleEnd?.();
|
|
358
|
+
};
|
|
359
|
+
const onKeypress = (_text, key) => {
|
|
360
|
+
if (key?.ctrl === true && key.name === "d") end();
|
|
361
|
+
};
|
|
362
|
+
streams.input.on("keypress", onKeypress);
|
|
363
|
+
if (streams.input.readableEnded) {
|
|
364
|
+
queueMicrotask(end);
|
|
365
|
+
} else {
|
|
366
|
+
streams.input.once("end", end);
|
|
367
|
+
streams.input.once("close", end);
|
|
368
|
+
}
|
|
369
|
+
return Promise.race([run(controller.signal), ended]).finally(() => {
|
|
370
|
+
streams.input.off("keypress", onKeypress);
|
|
371
|
+
streams.input.off("end", end);
|
|
372
|
+
streams.input.off("close", end);
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
function resolveStreams(streams) {
|
|
376
|
+
return { input: streams.input ?? process.stdin, output: streams.output ?? process.stderr };
|
|
377
|
+
}
|
|
378
|
+
async function selectOne(opts) {
|
|
379
|
+
const { select, isCancel } = await import("./dist-U4M6QCKE.js");
|
|
380
|
+
const streams = resolveStreams(opts.streams ?? {});
|
|
381
|
+
return withInputEnd(streams, null, async (signal) => {
|
|
382
|
+
const answer = await select({
|
|
383
|
+
message: opts.message,
|
|
384
|
+
options: opts.choices.map((c) => ({
|
|
385
|
+
value: c.value,
|
|
386
|
+
label: c.label,
|
|
387
|
+
...c.hint !== void 0 ? { hint: c.hint } : {}
|
|
388
|
+
})),
|
|
389
|
+
initialValue: opts.initialValue,
|
|
390
|
+
input: streams.input,
|
|
391
|
+
output: streams.output,
|
|
392
|
+
signal
|
|
393
|
+
});
|
|
394
|
+
return isCancel(answer) ? null : answer;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
async function confirmChoice(message, initialValue = true, streams = {}) {
|
|
398
|
+
const { confirm, isCancel } = await import("./dist-U4M6QCKE.js");
|
|
399
|
+
const resolved = resolveStreams(streams);
|
|
400
|
+
return withInputEnd(resolved, false, async (signal) => {
|
|
401
|
+
const answer = await confirm({
|
|
402
|
+
message,
|
|
403
|
+
initialValue,
|
|
404
|
+
input: resolved.input,
|
|
405
|
+
output: resolved.output,
|
|
406
|
+
signal
|
|
407
|
+
});
|
|
408
|
+
return isCancel(answer) ? false : answer;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
async function intro(message) {
|
|
412
|
+
const clack = await import("./dist-U4M6QCKE.js");
|
|
413
|
+
clack.intro(message, { output: process.stderr });
|
|
414
|
+
}
|
|
415
|
+
async function outro(message) {
|
|
416
|
+
const clack = await import("./dist-U4M6QCKE.js");
|
|
417
|
+
clack.outro(message, { output: process.stderr });
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/commands/install.ts
|
|
421
|
+
var HARNESSES = HARNESS_TARGETS;
|
|
422
|
+
var InstallInputSchema = external_exports.object({
|
|
423
|
+
harness: external_exports.array(external_exports.string()).optional(),
|
|
424
|
+
dryRun: external_exports.boolean().optional(),
|
|
425
|
+
publishMode: external_exports.string().optional(),
|
|
426
|
+
noWallet: external_exports.boolean().optional(),
|
|
427
|
+
/**
|
|
428
|
+
* ACCEPTED AND IGNORED. `install` writes no CLAUDE.md/AGENTS.md line any more —
|
|
429
|
+
* a skill's own frontmatter description is the trigger surface the harness reads
|
|
430
|
+
* at session start, so the line only duplicated it. Both spellings still parse so
|
|
431
|
+
* a script or a released doc that passes one does not fail; neither does anything.
|
|
432
|
+
*/
|
|
433
|
+
claudeMd: external_exports.boolean().optional(),
|
|
434
|
+
/**
|
|
435
|
+
* Tri-state. `true` (`--allow-free-verbs`) wires the free-verb
|
|
436
|
+
* allowlist without asking, which is now also what an unanswered non-interactive
|
|
437
|
+
* run does, so the flag is kept for compatibility and as an explicit statement of
|
|
438
|
+
* intent. `false` (`--no-allow-free-verbs`) is the opt-out and is the only way to
|
|
439
|
+
* get a run that writes no permission rule. `undefined` asks when it can, and
|
|
440
|
+
* writes when it cannot ask.
|
|
441
|
+
*/
|
|
442
|
+
allowFreeVerbs: external_exports.boolean().optional(),
|
|
443
|
+
/** The harness search-hook behavior to install (`--search-hooks auto|remind|off`). */
|
|
444
|
+
searchHooks: external_exports.string().optional(),
|
|
445
|
+
/**
|
|
446
|
+
* `--no-hooks`: register no hooks THIS RUN, changing nothing persistent. It is
|
|
447
|
+
* deliberately not the same as `--search-hooks off`, which is a durable
|
|
448
|
+
* statement about behavior and writes `hooks.searchMode: off` to config.
|
|
449
|
+
*/
|
|
450
|
+
noHooks: external_exports.boolean().optional()
|
|
451
|
+
});
|
|
452
|
+
function walletFix(reason) {
|
|
453
|
+
switch (reason) {
|
|
454
|
+
case "no-passphrase-store":
|
|
455
|
+
return "No OS credential store is available to hold the wallet passphrase. Set TENJIN_WALLET_PASSPHRASE and re-run `tenjin install`, or run `tenjin wallet create` in a terminal to enter one.";
|
|
456
|
+
case "create-failed":
|
|
457
|
+
return "Fix the reported problem, then run `tenjin wallet create`.";
|
|
458
|
+
case "dry-run":
|
|
459
|
+
case "flag":
|
|
460
|
+
return "Create one with `tenjin wallet create`.";
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
var CODEX_NETWORK_RULE = "[sandbox_workspace_write]\nnetwork_access = true";
|
|
464
|
+
async function runInstall(input, ctx, deps = {}) {
|
|
465
|
+
return withInterruptGuard((markPhase) => installBody(input, ctx, deps, markPhase));
|
|
466
|
+
}
|
|
467
|
+
async function withInterruptGuard(fn) {
|
|
468
|
+
let phase;
|
|
469
|
+
const onSignal = (signal) => {
|
|
470
|
+
const wasWriting = ownsAnyLock() || phase === "writing-skills";
|
|
471
|
+
releaseOwnedLocks();
|
|
472
|
+
if (process.stdin.isTTY) process.stdin.setRawMode?.(false);
|
|
473
|
+
if (process.stdout.isTTY) process.stdout.write("\x1B[?25h");
|
|
474
|
+
process.stderr.write(
|
|
475
|
+
wasWriting ? `
|
|
476
|
+
Interrupted mid-write. Some files may be half-written; re-run \`tenjin install\` to finish.
|
|
477
|
+
` : phase === "wired" ? `
|
|
478
|
+
Interrupted after the skills were written; later setup steps may not have finished. Re-run \`tenjin install\` to finish.
|
|
479
|
+
` : "\nInterrupted before anything was written; nothing changed.\n"
|
|
480
|
+
);
|
|
481
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
482
|
+
};
|
|
483
|
+
process.on("SIGINT", onSignal);
|
|
484
|
+
process.on("SIGTERM", onSignal);
|
|
485
|
+
try {
|
|
486
|
+
return await fn((p) => {
|
|
487
|
+
phase = p;
|
|
488
|
+
});
|
|
489
|
+
} finally {
|
|
490
|
+
process.off("SIGINT", onSignal);
|
|
491
|
+
process.off("SIGTERM", onSignal);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
async function installBody(input, ctx, deps, markPhase) {
|
|
495
|
+
const parsed = InstallInputSchema.safeParse(input);
|
|
496
|
+
if (!parsed.success) {
|
|
497
|
+
throw new CliError("USAGE", "Invalid install options", {
|
|
498
|
+
fix: "Run `tenjin install --help`.",
|
|
499
|
+
details: parsed.error.issues
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
const dryRun = parsed.data.dryRun === true;
|
|
503
|
+
const noWallet = parsed.data.noWallet === true;
|
|
504
|
+
const noHooks = parsed.data.noHooks === true;
|
|
505
|
+
const allowFreeVerbs = parsed.data.allowFreeVerbs;
|
|
506
|
+
const publishModeFlag = parsed.data.publishMode !== void 0 ? parseModeFlag(parsed.data.publishMode) : void 0;
|
|
507
|
+
const searchHooksFlag = parsed.data.searchHooks !== void 0 ? parseSearchHookModeFlag(parsed.data.searchHooks, "--search-hooks") : void 0;
|
|
508
|
+
const env = deps.env ?? process.env;
|
|
509
|
+
const home = deps.homeDir ?? homedir();
|
|
510
|
+
if (!isAbsolute(home)) {
|
|
511
|
+
throw new CliError(
|
|
512
|
+
"INTERNAL",
|
|
513
|
+
"The home directory did not resolve to an absolute path, so nothing was installed.",
|
|
514
|
+
{
|
|
515
|
+
fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
|
|
516
|
+
}
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
const which = deps.which ?? ((bin) => onPath(bin, env));
|
|
520
|
+
const humanOutput = ctx.flags.json === true ? false : deps.isInteractive ?? ctx.io.isTTY;
|
|
521
|
+
const canPrompt = humanOutput && (deps.isInteractive ?? Boolean(process.stdin.isTTY));
|
|
522
|
+
const skillsSource = deps.skillsSourceDir ?? resolveSkillsSource(fileURLToPath(new URL(".", import.meta.url)));
|
|
523
|
+
await assertSkillsSource(skillsSource);
|
|
524
|
+
const plans = resolvePlans(parsed.data.harness, home, which);
|
|
525
|
+
const explicitHarness = parsed.data.harness !== void 0 && parsed.data.harness.length > 0;
|
|
526
|
+
const harnesses = [];
|
|
527
|
+
if (!dryRun) markPhase("writing-skills");
|
|
528
|
+
for (const plan of plans) {
|
|
529
|
+
harnesses.push(await applyPlan(plan, skillsSource, dryRun));
|
|
530
|
+
}
|
|
531
|
+
await assertSkillsLanded(plans, dryRun);
|
|
532
|
+
if (!dryRun) markPhase("wired");
|
|
533
|
+
if (explicitHarness && !dryRun) {
|
|
534
|
+
await underDataDir(
|
|
535
|
+
ctx.dataDir,
|
|
536
|
+
() => persistInstallHarness(
|
|
537
|
+
ctx.dataDir,
|
|
538
|
+
plans.map((p) => p.harness)
|
|
539
|
+
)
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
const pointerCleanup = dryRun ? [] : await removeMarkerLines(home);
|
|
543
|
+
if (canPrompt) await (deps.intro ?? intro)("tenjin install");
|
|
544
|
+
const publishMode = await underDataDir(
|
|
545
|
+
ctx.dataDir,
|
|
546
|
+
() => resolvePublishMode(publishModeFlag, ctx, deps, dryRun, canPrompt)
|
|
547
|
+
);
|
|
548
|
+
const permissions = await resolvePermissions({
|
|
549
|
+
plans,
|
|
550
|
+
home,
|
|
551
|
+
deps,
|
|
552
|
+
flag: allowFreeVerbs,
|
|
553
|
+
dryRun,
|
|
554
|
+
canPrompt
|
|
555
|
+
});
|
|
556
|
+
const hooks = await underDataDir(
|
|
557
|
+
ctx.dataDir,
|
|
558
|
+
() => resolveHooks({ plans, home, ctx, deps, flag: searchHooksFlag, noHooks, dryRun, canPrompt })
|
|
559
|
+
);
|
|
560
|
+
const wallet = await underDataDir(
|
|
561
|
+
ctx.dataDir,
|
|
562
|
+
() => resolveWallet(ctx, deps, walletSkip(dryRun, noWallet), canPrompt)
|
|
563
|
+
);
|
|
564
|
+
const doctorDeps = { ...deps.doctorDeps ?? {} };
|
|
565
|
+
doctorDeps.homeDir ??= home;
|
|
566
|
+
doctorDeps.which ??= which;
|
|
567
|
+
const collect = deps.collectChecks ?? ((c) => collectDoctorChecks(c, doctorDeps));
|
|
568
|
+
const doctor = await collect(ctx);
|
|
569
|
+
if (canPrompt) await (deps.outro ?? outro)("Setup complete.");
|
|
570
|
+
const data = {
|
|
571
|
+
dryRun,
|
|
572
|
+
skillsSource,
|
|
573
|
+
harnesses,
|
|
574
|
+
// One-time cleanup, reported because it edits a file the operator owns. Older
|
|
575
|
+
// versions wrote a pointer line into CLAUDE.md/AGENTS.md; nothing writes one
|
|
576
|
+
// now, so an install that finds one removes it and says which file it touched.
|
|
577
|
+
pointerCleanup,
|
|
578
|
+
doctor: { status: doctor.failure !== void 0 ? "fail" : "pass", checks: doctor.checks },
|
|
579
|
+
publishMode,
|
|
580
|
+
// Shipped with the install rather than left for the operator to discover after
|
|
581
|
+
// their first auto-mode denial (#33). Static constants, no config key: see
|
|
582
|
+
// lib/permissions.ts for why this is deliberately not operator-editable state.
|
|
583
|
+
// `wired` is the outcome of THIS run's settings.json write; the three
|
|
584
|
+
// recommendation tiers beside it are unchanged, so a machine consumer that
|
|
585
|
+
// read `alwaysSafe` / `optIn` / `neverAllowlisted` before still does.
|
|
586
|
+
permissions: { ...recommendedPermissions(), wired: permissions },
|
|
587
|
+
hooks,
|
|
588
|
+
wallet
|
|
589
|
+
};
|
|
590
|
+
if (!humanOutput) return { data };
|
|
591
|
+
const humanLines = buildWalkthrough(ctx.io, {
|
|
592
|
+
pointerCleanup,
|
|
593
|
+
dryRun,
|
|
594
|
+
dataDir: ctx.dataDir,
|
|
595
|
+
harnesses,
|
|
596
|
+
publishMode,
|
|
597
|
+
permissions,
|
|
598
|
+
hooks,
|
|
599
|
+
wallet,
|
|
600
|
+
doctor
|
|
601
|
+
});
|
|
602
|
+
return { data, humanLines };
|
|
603
|
+
}
|
|
604
|
+
function walletSkip(dryRun, noWallet) {
|
|
605
|
+
if (dryRun) return "dry-run";
|
|
606
|
+
if (noWallet) return "flag";
|
|
607
|
+
return void 0;
|
|
608
|
+
}
|
|
609
|
+
async function underDataDir(dataDir, fn) {
|
|
610
|
+
try {
|
|
611
|
+
return await fn();
|
|
612
|
+
} catch (err) {
|
|
613
|
+
if (!hasCode(err, "EACCES") && !hasCode(err, "EPERM")) throw err;
|
|
614
|
+
throw new CliError("INTERNAL", `Could not use the Tenjin data directory ${dataDir}.`, {
|
|
615
|
+
fix: `Permission denied. Check that you can write to it (\`ls -ld ${dataDir}\`), then re-run \`tenjin install\`.`,
|
|
616
|
+
cause: err
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
var EXAMPLE_QUESTION = "what actually changed in <library> v3's public API";
|
|
621
|
+
function buildWalkthrough(io, s) {
|
|
622
|
+
const lines = [];
|
|
623
|
+
if (s.dryRun) {
|
|
624
|
+
lines.push(paint(io, "yellow", "Dry run: nothing was written."));
|
|
625
|
+
lines.push("");
|
|
626
|
+
}
|
|
627
|
+
lines.push(...summaryLines(io, s));
|
|
628
|
+
const notices = noticeLines(io, s);
|
|
629
|
+
if (notices.length > 0) lines.push("", ...notices);
|
|
630
|
+
return lines;
|
|
631
|
+
}
|
|
632
|
+
function noticeLines(io, s) {
|
|
633
|
+
const lines = [];
|
|
634
|
+
for (const h of s.harnesses) {
|
|
635
|
+
if (h.hostedArrivedFirst) {
|
|
636
|
+
lines.push(
|
|
637
|
+
paint(
|
|
638
|
+
io,
|
|
639
|
+
"dim",
|
|
640
|
+
`The hosted ${HOSTED_SKILL_NAME} skill was already in ${h.skillsDir}: kept as the zero-install fallback, and the CLI skills now take precedence.`
|
|
641
|
+
)
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
if (h.codexNetworkRule !== void 0) {
|
|
645
|
+
lines.push(paint(io, "dim", "Codex blocks network by default; add to ~/.codex/config.toml:"));
|
|
646
|
+
for (const rl of h.codexNetworkRule.split("\n")) lines.push(paint(io, "dim", ` ${rl}`));
|
|
647
|
+
}
|
|
648
|
+
for (const w of h.warnings) lines.push(paint(io, "yellow", `! ${w}`));
|
|
649
|
+
}
|
|
650
|
+
if (s.pointerCleanup.length > 0) {
|
|
651
|
+
lines.push(
|
|
652
|
+
`Removed the old Tenjin pointer line from ${s.pointerCleanup.join(" and ")}; the skills carry their own triggers now.`
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
if (s.permissions.removed.length > 0) {
|
|
656
|
+
lines.push(
|
|
657
|
+
`Removed ${s.permissions.removed.length} permission rule(s) an older tenjin left in ${s.permissions.path ?? "your settings"} for commands that no longer exist.`
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
if (s.permissions.added.length > 0) {
|
|
661
|
+
lines.push(
|
|
662
|
+
paint(
|
|
663
|
+
io,
|
|
664
|
+
"dim",
|
|
665
|
+
`${s.permissions.added.length} free tenjin commands were allowed in ${s.permissions.path}. None can spend USDC or open your wallet keystore; see them with \`tenjin doctor\`.`
|
|
666
|
+
)
|
|
667
|
+
);
|
|
668
|
+
lines.push(paint(io, "dim", `Undo anytime: remove those lines from ${s.permissions.path}.`));
|
|
669
|
+
}
|
|
670
|
+
if (s.hooks.added.length > 0 || s.hooks.updated.length > 0) {
|
|
671
|
+
lines.push(paint(io, "dim", hooksDisclosure(s.hooks)));
|
|
672
|
+
lines.push(
|
|
673
|
+
paint(io, "dim", hooksUndo(s.hooks.path ?? "~/.claude/settings.json", s.hooks.scriptsDir))
|
|
674
|
+
);
|
|
675
|
+
lines.push(
|
|
676
|
+
`${paint(io, "bold", "Restart Claude Code")} to load them; hooks are read once at session start.`
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
if (s.hooks.warning !== void 0) {
|
|
680
|
+
lines.push(paint(io, "yellow", `! ${sanitizeForTerminal(s.hooks.warning)}`));
|
|
681
|
+
}
|
|
682
|
+
for (const line of walletDisclosure(s.wallet, s.dataDir)) lines.push(paint(io, "dim", line));
|
|
683
|
+
if (s.wallet.warning !== void 0) {
|
|
684
|
+
lines.push(paint(io, "yellow", `! ${sanitizeForTerminal(s.wallet.warning)}`));
|
|
685
|
+
}
|
|
686
|
+
if (s.permissions.warning !== void 0) {
|
|
687
|
+
lines.push(paint(io, "yellow", `! ${sanitizeForTerminal(s.permissions.warning)}`));
|
|
688
|
+
}
|
|
689
|
+
lines.push(...doctorNotices(io, s.doctor, s.wallet));
|
|
690
|
+
return lines;
|
|
691
|
+
}
|
|
692
|
+
function summaryLines(io, s) {
|
|
693
|
+
return [
|
|
694
|
+
...s.harnesses.map((h) => skillsLine(io, h, s.dryRun)),
|
|
695
|
+
publishingLine(io, s.publishMode.value),
|
|
696
|
+
permissionsLine(io, s.permissions),
|
|
697
|
+
hooksLine(io, s.hooks),
|
|
698
|
+
walletLine(io, s.wallet),
|
|
699
|
+
`${paint(io, "bold", "Next:")} tenjin search "${EXAMPLE_QUESTION}"`
|
|
700
|
+
];
|
|
701
|
+
}
|
|
702
|
+
function hooksDisclosure(h) {
|
|
703
|
+
const shared = "A Stop hook reminds you locally when a MISS you searched for is still unpublished; it makes no network call.";
|
|
704
|
+
if (h.mode === "remind") {
|
|
705
|
+
return `The WebSearch hook prints a one-line reminder that Tenjin may have an answer; it sends nothing off-machine. ${shared}`;
|
|
706
|
+
}
|
|
707
|
+
return `Before a web search, the WebSearch hook asks tenjin.blog the same question (free and anonymous, ~2s budget, 5s harness kill) and mentions a tested answer if one exists; the query text leaves the machine. It can never block or change the search. ${shared}`;
|
|
708
|
+
}
|
|
709
|
+
function hooksLine(io, h) {
|
|
710
|
+
const label = paint(io, "bold", "Search hooks:");
|
|
711
|
+
const wrote = h.added.length + h.updated.length;
|
|
712
|
+
if (wrote > 0) {
|
|
713
|
+
return `${paint(io, "green", "\u2713")} ${label} ${h.mode} mode, ${wrote} hook(s) registered in ${h.path}. Change: tenjin config set hooks.searchMode <auto|remind|off>`;
|
|
714
|
+
}
|
|
715
|
+
if (h.skipped === void 0) {
|
|
716
|
+
return `${paint(io, "green", "\u2713")} ${label} ${h.mode} mode, already registered in ${h.path}`;
|
|
717
|
+
}
|
|
718
|
+
if (h.skipped === "harness-not-claude") {
|
|
719
|
+
return `${paint(io, "dim", "-")} ${label} not wired (Claude Code only).`;
|
|
720
|
+
}
|
|
721
|
+
if (h.skipped === "dry-run") {
|
|
722
|
+
return `${paint(io, "dim", "-")} ${label} unchanged (dry run).`;
|
|
723
|
+
}
|
|
724
|
+
if (h.skipped === "mode-off") {
|
|
725
|
+
return `${paint(io, "dim", "-")} ${label} off (hooks.searchMode). Turn them on: tenjin config set hooks.searchMode auto, then tenjin install`;
|
|
726
|
+
}
|
|
727
|
+
if (h.skipped === "declined") {
|
|
728
|
+
return `${paint(io, "dim", "-")} ${label} not registered this run; nothing was configured. Register them: tenjin install`;
|
|
729
|
+
}
|
|
730
|
+
if (h.skipped === "changed-since-read") {
|
|
731
|
+
return `${paint(io, "yellow", "!")} ${label} ${h.path} changed while it was being updated, so nothing was written. Re-run: tenjin install`;
|
|
732
|
+
}
|
|
733
|
+
return `${paint(io, "yellow", "!")} ${label} ${h.path} was left untouched. Fix it, then: tenjin install`;
|
|
734
|
+
}
|
|
735
|
+
function harnessLabel(h) {
|
|
736
|
+
return h === "claude" ? "Claude Code" : h === "codex" ? "Codex" : "Agent Skills";
|
|
737
|
+
}
|
|
738
|
+
function skillsLine(io, h, dryRun) {
|
|
739
|
+
const changed = h.skills.some((s) => s.status !== "up-to-date");
|
|
740
|
+
const verb = dryRun ? "would install" : changed ? "installed" : "up to date";
|
|
741
|
+
const head = `${harnessLabel(h.harness)}: ${h.skills.length} skills ${verb}`;
|
|
742
|
+
return `${paint(io, "green", "\u2713")} ${paint(io, "bold", head)} in ${h.skillsDir}. ${skillRoster(h)}.`;
|
|
743
|
+
}
|
|
744
|
+
function publishingLine(io, mode) {
|
|
745
|
+
return `${paint(io, "green", "\u2713")} ${paint(io, "bold", `Publishing: ${mode}`)}. ${modeBlurb(mode)}`;
|
|
746
|
+
}
|
|
747
|
+
function permissionsLine(io, p) {
|
|
748
|
+
const label = paint(io, "bold", "Permissions:");
|
|
749
|
+
if (p.added.length > 0) {
|
|
750
|
+
return `${paint(io, "green", "\u2713")} ${label} ${p.added.length} free tenjin commands added to ${p.path}. Full caveats: ${PERMISSIONS_DOC_URL}`;
|
|
751
|
+
}
|
|
752
|
+
if (p.skipped === void 0) {
|
|
753
|
+
return `${paint(io, "green", "\u2713")} ${label} the ${FREE_VERB_RULES.length} free tenjin commands were already allowed in ${p.path}`;
|
|
754
|
+
}
|
|
755
|
+
if (p.skipped === "harness-not-claude") {
|
|
756
|
+
return `${paint(io, "dim", "-")} ${label} not wired (Claude Code only). The lines your harness needs: ${PERMISSIONS_DOC_URL}`;
|
|
757
|
+
}
|
|
758
|
+
if (p.skipped === "dry-run") {
|
|
759
|
+
return `${paint(io, "dim", "-")} ${label} unchanged (dry run).`;
|
|
760
|
+
}
|
|
761
|
+
if (p.skipped === "declined" || p.skipped === "not-requested") {
|
|
762
|
+
return `${paint(io, "dim", "-")} ${label} unchanged. Allow the ${FREE_VERB_RULES.length} free tenjin commands with: tenjin install --allow-free-verbs`;
|
|
763
|
+
}
|
|
764
|
+
if (p.skipped === "changed-since-read") {
|
|
765
|
+
return `${paint(io, "yellow", "!")} ${label} ${p.path} changed while it was being updated, so nothing was written. Re-run: tenjin install`;
|
|
766
|
+
}
|
|
767
|
+
return `${paint(io, "yellow", "!")} ${label} ${p.path} was left untouched. Fix it, then: tenjin install --allow-free-verbs`;
|
|
768
|
+
}
|
|
769
|
+
function walletLine(io, w) {
|
|
770
|
+
const label = paint(io, "bold", "Wallet:");
|
|
771
|
+
if (w.status === "existing") {
|
|
772
|
+
return `${paint(io, "green", "\u2713")} ${label} ${w.address} (existing). Check funds with: tenjin wallet balance`;
|
|
773
|
+
}
|
|
774
|
+
if (w.status === "created") {
|
|
775
|
+
return `${paint(io, "green", "\u2713")} ${label} ${w.address}, holding $0. Fund it with a few dollars of USDC on Base, then: tenjin wallet balance`;
|
|
776
|
+
}
|
|
777
|
+
if (w.status === "skipped") {
|
|
778
|
+
const icon = w.reason === "no-passphrase-store" || w.reason === "create-failed" ? "!" : "-";
|
|
779
|
+
const color = icon === "!" ? "yellow" : "dim";
|
|
780
|
+
return `${paint(io, color, icon)} ${label} none (${w.reason}). ${w.fix}`;
|
|
781
|
+
}
|
|
782
|
+
return `${paint(io, "dim", "-")} ${label} none. Create one later with: tenjin wallet create`;
|
|
783
|
+
}
|
|
784
|
+
function walletDisclosure(w, dataDir) {
|
|
785
|
+
if (w.status !== "created") return [];
|
|
786
|
+
return [
|
|
787
|
+
`A wallet was created at ${walletPath(dataDir)}: the key is encrypted at rest (keystore v3, scrypt, mode 0600) and never leaves this machine.`,
|
|
788
|
+
"It holds $0. Funding it is a human step: run `tenjin fund` (card checkout via Coinbase, opened in your browser), or send USDC on Base to that address."
|
|
789
|
+
];
|
|
790
|
+
}
|
|
791
|
+
function skillRoster(h) {
|
|
792
|
+
const cli = h.skills.filter((s) => s.cli).map((s) => s.name);
|
|
793
|
+
const hosted = h.skills.filter((s) => !s.cli).map((s) => s.name);
|
|
794
|
+
const parts = [];
|
|
795
|
+
if (cli.length > 0) parts.push(`${cli.join(", ")} (CLI)`);
|
|
796
|
+
if (hosted.length > 0) parts.push(`${hosted.join(", ")} (hosted, zero-install fallback)`);
|
|
797
|
+
return parts.join("; ");
|
|
798
|
+
}
|
|
799
|
+
function modeBlurb(v) {
|
|
800
|
+
return v === "auto" ? "Your agent publishes clean pieces on its own; your harness still shows each command for approval." : v === "review" ? "Your agent asks you in chat before every publish." : "Fully unattended; only hard blocks stop it.";
|
|
801
|
+
}
|
|
802
|
+
async function resolveWallet(ctx, deps, skipReason, canPrompt) {
|
|
803
|
+
const exists = await (deps.walletExists ?? walletFileExists)(ctx.dataDir);
|
|
804
|
+
if (exists) {
|
|
805
|
+
return {
|
|
806
|
+
status: "existing",
|
|
807
|
+
address: await (deps.walletAddress ?? existingWalletAddress)(ctx)
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
if (skipReason !== void 0) {
|
|
811
|
+
return { status: "skipped", reason: skipReason, fix: walletFix(skipReason) };
|
|
812
|
+
}
|
|
813
|
+
if (canPrompt) {
|
|
814
|
+
const confirm = deps.confirmWallet ?? defaultConfirm;
|
|
815
|
+
if (!await confirm(WALLET_QUESTION)) return { status: "declined" };
|
|
816
|
+
}
|
|
817
|
+
try {
|
|
818
|
+
const create = deps.createWallet ?? ((c) => defaultCreateWallet(c, deps.walletPassphrase, deps.env));
|
|
819
|
+
return { status: "created", address: await create(ctx) };
|
|
820
|
+
} catch (err) {
|
|
821
|
+
const reason = isNoPassphraseError(err) ? "no-passphrase-store" : "create-failed";
|
|
822
|
+
return {
|
|
823
|
+
status: "skipped",
|
|
824
|
+
reason,
|
|
825
|
+
fix: walletFix(reason),
|
|
826
|
+
...reason === "create-failed" ? { warning: `The wallet could not be created: ${errorText(err)}` } : {}
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function isNoPassphraseError(err) {
|
|
831
|
+
return err instanceof CliError && err.code === "USAGE" && err.message.includes("No wallet passphrase is available");
|
|
832
|
+
}
|
|
833
|
+
function errorText(err) {
|
|
834
|
+
return err instanceof Error ? err.message : String(err);
|
|
835
|
+
}
|
|
836
|
+
async function existingWalletAddress(ctx) {
|
|
837
|
+
return (await describeWallet(resolveWalletProvider(ctx))).address;
|
|
838
|
+
}
|
|
839
|
+
async function defaultCreateWallet(ctx, passphrase, env) {
|
|
840
|
+
const result = await runWalletCreate(ctx, {
|
|
841
|
+
...passphrase !== void 0 ? { passphrase } : {},
|
|
842
|
+
...env !== void 0 ? { env } : {}
|
|
843
|
+
});
|
|
844
|
+
return result.data.address;
|
|
845
|
+
}
|
|
846
|
+
function defaultConfirm(label) {
|
|
847
|
+
return confirmChoice(label, true);
|
|
848
|
+
}
|
|
849
|
+
function summaryAlreadySaysNoWallet(wallet) {
|
|
850
|
+
return wallet.status === "declined" || wallet.status === "skipped";
|
|
851
|
+
}
|
|
852
|
+
function doctorNotices(io, doctor, wallet) {
|
|
853
|
+
const problems = doctor.checks.filter(
|
|
854
|
+
(c) => c.status !== "ok" && !(summaryAlreadySaysNoWallet(wallet) && isNoWalletCheck(c))
|
|
855
|
+
);
|
|
856
|
+
if (problems.length === 0) return [];
|
|
857
|
+
const lines = [paint(io, "yellow", "Some checks need attention:")];
|
|
858
|
+
for (const c of problems) {
|
|
859
|
+
const icon = c.status === "fail" ? paint(io, "red", "\u2717") : paint(io, "yellow", "!");
|
|
860
|
+
lines.push(` ${icon} ${c.name}: ${sanitizeForTerminal(c.detail)}`);
|
|
861
|
+
if (c.fix !== void 0) {
|
|
862
|
+
lines.push(paint(io, "dim", ` fix: ${sanitizeForTerminal(c.fix)}`));
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return lines;
|
|
866
|
+
}
|
|
867
|
+
var DEFAULT_MODE = CONFIG_DEFAULTS.publish.mode;
|
|
868
|
+
var RECOMMENDED_MODE = "auto";
|
|
869
|
+
var PUBLISH_MODE_CHOICES = [
|
|
870
|
+
{
|
|
871
|
+
value: "auto",
|
|
872
|
+
label: "Auto (recommended)",
|
|
873
|
+
hint: "your agent publishes clean pieces on its own; your harness still shows each command for approval"
|
|
874
|
+
},
|
|
875
|
+
{ value: "review", label: "Ask me in chat first" },
|
|
876
|
+
{ value: "full-auto", label: "Fully unattended", hint: "only hard blocks stop it" }
|
|
877
|
+
];
|
|
878
|
+
var PUBLISH_MODE_QUESTION = "When your agent has something worth publishing:";
|
|
879
|
+
async function resolvePublishMode(flag, ctx, deps, dryRun, interactive) {
|
|
880
|
+
if (flag !== void 0) {
|
|
881
|
+
if (!dryRun) await persistPublishMode(ctx.dataDir, flag);
|
|
882
|
+
return { value: flag, source: "flag" };
|
|
883
|
+
}
|
|
884
|
+
const config = await loadRawConfig(ctx.dataDir);
|
|
885
|
+
if (config.publish?.mode !== void 0) {
|
|
886
|
+
return { value: config.publish.mode, source: "existing" };
|
|
887
|
+
}
|
|
888
|
+
if (dryRun) return { value: DEFAULT_MODE, source: "default-skipped" };
|
|
889
|
+
if (!interactive) {
|
|
890
|
+
await persistPublishMode(ctx.dataDir, RECOMMENDED_MODE);
|
|
891
|
+
return { value: RECOMMENDED_MODE, source: "headless-default" };
|
|
892
|
+
}
|
|
893
|
+
const answer = await (deps.promptPublishMode ?? defaultPromptPublishMode)();
|
|
894
|
+
if (answer === null) return { value: DEFAULT_MODE, source: "default-skipped" };
|
|
895
|
+
const parsed = PublishModeSchema.safeParse(answer);
|
|
896
|
+
if (!parsed.success) return { value: DEFAULT_MODE, source: "default-skipped" };
|
|
897
|
+
await persistPublishMode(ctx.dataDir, parsed.data);
|
|
898
|
+
return { value: parsed.data, source: "prompt" };
|
|
899
|
+
}
|
|
900
|
+
function defaultPromptPublishMode() {
|
|
901
|
+
return selectOne({
|
|
902
|
+
message: PUBLISH_MODE_QUESTION,
|
|
903
|
+
choices: PUBLISH_MODE_CHOICES.map((c) => ({ ...c })),
|
|
904
|
+
initialValue: "auto"
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
function parseModeFlag(value) {
|
|
908
|
+
return parsePublishModeFlag(value, "--publish-mode");
|
|
909
|
+
}
|
|
910
|
+
var PERMISSIONS_QUESTION = [
|
|
911
|
+
"Let your agent search tenjin without permission popups?",
|
|
912
|
+
`Adds ${FREE_VERB_RULES.length} free commands to ~/.claude/settings.json.`,
|
|
913
|
+
"None can spend USDC or move your keys; doctor may check your wallet still opens.",
|
|
914
|
+
"Three send or store data (search, outcome, read).",
|
|
915
|
+
`Full caveats: ${PERMISSIONS_DOC_URL}`
|
|
916
|
+
].join(" ");
|
|
917
|
+
var WALLET_QUESTION = "Create a wallet now?";
|
|
918
|
+
async function resolvePermissions(args) {
|
|
919
|
+
const { plans, home, deps, flag, dryRun, canPrompt } = args;
|
|
920
|
+
if (!plans.some((p) => p.harness === "claude")) {
|
|
921
|
+
return permissionsSkipped(plans[0]?.harness ?? "shared", home, "harness-not-claude");
|
|
922
|
+
}
|
|
923
|
+
if (dryRun) return permissionsSkipped("claude", home, "dry-run");
|
|
924
|
+
if (flag === false) return permissionsSkipped("claude", home, "declined");
|
|
925
|
+
const probe = await (deps.inspectPermissions ?? inspectFreeVerbRules)(home);
|
|
926
|
+
if (probe.satisfied !== void 0) return probe.satisfied;
|
|
927
|
+
if (probe.pending !== null && probe.pending.length === 0) return wireFreeVerbAllowlist(home);
|
|
928
|
+
if (flag === true || !canPrompt) return wireFreeVerbAllowlist(home);
|
|
929
|
+
const confirm = deps.confirmPermissions ?? defaultConfirm;
|
|
930
|
+
if (!await confirm(PERMISSIONS_QUESTION)) {
|
|
931
|
+
return permissionsSkipped("claude", home, "declined");
|
|
932
|
+
}
|
|
933
|
+
return wireFreeVerbAllowlist(home);
|
|
934
|
+
}
|
|
935
|
+
var SEARCH_HOOKS_QUESTION = "Let Tenjin ride along with your web searches? (Escape skips, registering nothing)";
|
|
936
|
+
var SEARCH_HOOKS_CHOICES = [
|
|
937
|
+
{
|
|
938
|
+
value: "auto",
|
|
939
|
+
label: "Yes, check Tenjin first (recommended)",
|
|
940
|
+
hint: "before a WebSearch, ask tenjin.blog the same question (free, anonymous, 2s budget) and mention a tested answer; the query text leaves the machine"
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
value: "remind",
|
|
944
|
+
label: "Just remind me",
|
|
945
|
+
hint: "a one-line reminder, nothing sent off-machine"
|
|
946
|
+
},
|
|
947
|
+
{ value: "off", label: "No hooks", hint: "nothing is registered" }
|
|
948
|
+
];
|
|
949
|
+
async function resolveHooks(args) {
|
|
950
|
+
const { plans, home, ctx, deps, flag, noHooks, dryRun, canPrompt } = args;
|
|
951
|
+
const dataDir = ctx.dataDir;
|
|
952
|
+
const stored = (await loadRawConfig(dataDir)).hooks?.searchMode;
|
|
953
|
+
if (!plans.some((p) => p.harness === "claude")) {
|
|
954
|
+
const harness = plans[0]?.harness ?? "shared";
|
|
955
|
+
return hooksSkipped(
|
|
956
|
+
harness,
|
|
957
|
+
home,
|
|
958
|
+
dataDir,
|
|
959
|
+
flag ?? stored ?? DEFAULT_HOOK_MODE,
|
|
960
|
+
"harness-not-claude"
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
if (noHooks) {
|
|
964
|
+
return hooksSkipped("claude", home, dataDir, stored ?? DEFAULT_HOOK_MODE, "declined");
|
|
965
|
+
}
|
|
966
|
+
const mode = await chooseHookMode(flag, stored, deps, dryRun, canPrompt);
|
|
967
|
+
if (mode === null) {
|
|
968
|
+
return hooksSkipped("claude", home, dataDir, stored ?? DEFAULT_HOOK_MODE, "declined");
|
|
969
|
+
}
|
|
970
|
+
if (dryRun) return hooksSkipped("claude", home, dataDir, mode, "dry-run");
|
|
971
|
+
if (mode !== (stored ?? DEFAULT_HOOK_MODE) || stored === void 0) {
|
|
972
|
+
await persistSearchHookMode(dataDir, mode);
|
|
973
|
+
}
|
|
974
|
+
if (mode === "off") return hooksSkipped("claude", home, dataDir, mode, "mode-off");
|
|
975
|
+
return wireSearchHooks({ homeDir: home, dataDir, mode });
|
|
976
|
+
}
|
|
977
|
+
var DEFAULT_HOOK_MODE = CONFIG_DEFAULTS.hooks.searchMode;
|
|
978
|
+
async function chooseHookMode(flag, stored, deps, dryRun, canPrompt) {
|
|
979
|
+
if (flag !== void 0) return flag;
|
|
980
|
+
if (dryRun || !canPrompt) return stored ?? DEFAULT_HOOK_MODE;
|
|
981
|
+
const answer = await (deps.promptSearchHooks ?? defaultPromptSearchHooks)();
|
|
982
|
+
if (answer === null) return null;
|
|
983
|
+
const parsed = SearchHookModeSchema.safeParse(answer);
|
|
984
|
+
return parsed.success ? parsed.data : null;
|
|
985
|
+
}
|
|
986
|
+
function defaultPromptSearchHooks() {
|
|
987
|
+
return selectOne({
|
|
988
|
+
message: SEARCH_HOOKS_QUESTION,
|
|
989
|
+
choices: SEARCH_HOOKS_CHOICES.map((c) => ({ ...c })),
|
|
990
|
+
initialValue: "auto"
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
function resolvePlans(override, home, which) {
|
|
994
|
+
if (override !== void 0 && override.length > 0) {
|
|
995
|
+
const plans2 = override.map((v) => planFor(validateHarness(v), ["override"], true, home));
|
|
996
|
+
return dedupeBySkillsDir(plans2);
|
|
997
|
+
}
|
|
998
|
+
const plans = [];
|
|
999
|
+
const claudeBy = harnessDetectedBy(home, "claude", which);
|
|
1000
|
+
const codexBy = harnessDetectedBy(home, "codex", which);
|
|
1001
|
+
if (claudeBy.length > 0) plans.push(planFor("claude", claudeBy, true, home));
|
|
1002
|
+
if (codexBy.length > 0) plans.push(planFor("codex", codexBy, true, home));
|
|
1003
|
+
if (plans.length === 0) {
|
|
1004
|
+
plans.push(planFor("shared", ["fallback"], false, home));
|
|
1005
|
+
}
|
|
1006
|
+
return dedupeBySkillsDir(plans);
|
|
1007
|
+
}
|
|
1008
|
+
function planFor(harness, detectedBy, detected, home) {
|
|
1009
|
+
const skillsDir = harnessTargetDir(home, harness);
|
|
1010
|
+
return { harness, detected, detectedBy, skillsDir, wiresAgentsMd: harness !== "claude", home };
|
|
1011
|
+
}
|
|
1012
|
+
function dedupeBySkillsDir(plans) {
|
|
1013
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1014
|
+
const out = [];
|
|
1015
|
+
for (const p of plans) {
|
|
1016
|
+
if (seen.has(p.skillsDir)) continue;
|
|
1017
|
+
seen.add(p.skillsDir);
|
|
1018
|
+
out.push(p);
|
|
1019
|
+
}
|
|
1020
|
+
return out;
|
|
1021
|
+
}
|
|
1022
|
+
function validateHarness(value) {
|
|
1023
|
+
if (HARNESSES.includes(value)) return value;
|
|
1024
|
+
throw new CliError("USAGE", `Unknown harness "${value}"`, {
|
|
1025
|
+
fix: `--harness must be one of: ${HARNESSES.join(", ")}.`
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
async function applyPlan(plan, skillsSource, dryRun) {
|
|
1029
|
+
const skills = [];
|
|
1030
|
+
const warnings = [];
|
|
1031
|
+
for (const name of SKILL_NAMES) {
|
|
1032
|
+
const { status, warning, preexisting } = await installSkill(
|
|
1033
|
+
join2(skillsSource, name),
|
|
1034
|
+
join2(plan.skillsDir, name),
|
|
1035
|
+
dryRun,
|
|
1036
|
+
name
|
|
1037
|
+
);
|
|
1038
|
+
skills.push({
|
|
1039
|
+
name,
|
|
1040
|
+
status,
|
|
1041
|
+
preexisting,
|
|
1042
|
+
cli: CLI_SKILL_NAMES.includes(name),
|
|
1043
|
+
modelInvocable: await landedInvocable(plan.skillsDir, skillsSource, name, dryRun)
|
|
1044
|
+
});
|
|
1045
|
+
if (warning !== void 0) warnings.push(warning);
|
|
1046
|
+
}
|
|
1047
|
+
const hostedPreexisting = skills.some((s) => s.name === HOSTED_SKILL_NAME && s.preexisting);
|
|
1048
|
+
const hostedArrivedFirst = hostedPreexisting && !skills.some((s) => s.cli && s.preexisting);
|
|
1049
|
+
const result = {
|
|
1050
|
+
harness: plan.harness,
|
|
1051
|
+
detected: plan.detected,
|
|
1052
|
+
detectedBy: plan.detectedBy,
|
|
1053
|
+
skillsDir: plan.skillsDir,
|
|
1054
|
+
skills,
|
|
1055
|
+
hostedPreexisting,
|
|
1056
|
+
hostedArrivedFirst,
|
|
1057
|
+
notes: notesFor(plan, hostedArrivedFirst),
|
|
1058
|
+
warnings
|
|
1059
|
+
};
|
|
1060
|
+
if (plan.wiresAgentsMd) result.codexNetworkRule = CODEX_NETWORK_RULE;
|
|
1061
|
+
return result;
|
|
1062
|
+
}
|
|
1063
|
+
function notesFor(plan, hostedArrivedFirst) {
|
|
1064
|
+
const notes = plan.harness === "claude" ? [
|
|
1065
|
+
"Installed at the user level (~/.claude/skills). A Claude Code plugin will later make this automatic."
|
|
1066
|
+
] : [
|
|
1067
|
+
"Copied into the shared Agent Skills location (~/.agents/skills). Codex and any Agent-Skills-compatible harness read it there."
|
|
1068
|
+
];
|
|
1069
|
+
if (hostedArrivedFirst) {
|
|
1070
|
+
notes.push(
|
|
1071
|
+
`The hosted ${HOSTED_SKILL_NAME} skill was already here; the skill stays as the zero-install fallback (its file is replaced by this package's mirror) and the CLI skills (${CLI_SKILL_NAMES.join(", ")}) take precedence while the CLI is installed.`
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
return notes;
|
|
1075
|
+
}
|
|
1076
|
+
async function landedInvocable(skillsDir, skillsSource, name, dryRun) {
|
|
1077
|
+
const read = await readSkillFile(join2(dryRun ? skillsSource : skillsDir, name, "SKILL.md"));
|
|
1078
|
+
if (read.kind !== "ok") return false;
|
|
1079
|
+
return !isModelInvocationDisabled(read.bytes.toString("utf8"));
|
|
1080
|
+
}
|
|
1081
|
+
async function assertSkillsLanded(plans, dryRun) {
|
|
1082
|
+
if (dryRun) return;
|
|
1083
|
+
const missing = [];
|
|
1084
|
+
for (const plan of plans) {
|
|
1085
|
+
for (const name of SKILL_NAMES) {
|
|
1086
|
+
if (!existsSync(join2(plan.skillsDir, name, "SKILL.md"))) {
|
|
1087
|
+
missing.push(join2(plan.skillsDir, name));
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
if (missing.length === 0) return;
|
|
1092
|
+
throw new CliError("INTERNAL", `Skills were not written: ${missing.join(", ")}`, {
|
|
1093
|
+
// Safe to point at permissions because nothing removes a landed file any more:
|
|
1094
|
+
// each shipped file arrives by its own atomic rename. When this was a
|
|
1095
|
+
// rm-then-write it also fired on a lost race, and sent people to chmod a
|
|
1096
|
+
// directory that was fine.
|
|
1097
|
+
fix: `Check that you can write to the skills directory (\`ls -ld ${dirname(missing[0] ?? "")}\`), then re-run \`tenjin install\`.`
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
function paint(io, format, text) {
|
|
1101
|
+
if (io.stdout instanceof Stream) return styleText(format, text, { stream: io.stdout });
|
|
1102
|
+
return styleText(format, text);
|
|
1103
|
+
}
|
|
1104
|
+
async function assertSkillsSource(dir) {
|
|
1105
|
+
for (const name of SKILL_NAMES) {
|
|
1106
|
+
if (!existsSync(join2(dir, name, "SKILL.md"))) {
|
|
1107
|
+
throw new CliError("INTERNAL", `Packaged skill "${name}" is missing under ${dir}`, {
|
|
1108
|
+
fix: "Reinstall tenjin-cli; the published package must ship every skill under skills/."
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
for (const name of CLI_SKILL_NAMES) {
|
|
1113
|
+
const text = await readFile2(join2(dir, name, "SKILL.md"), "utf8");
|
|
1114
|
+
if (isModelInvocationDisabled(text)) {
|
|
1115
|
+
throw new CliError(
|
|
1116
|
+
"INTERNAL",
|
|
1117
|
+
`Packaged skill "${name}" carries disable-model-invocation: true, so no harness would surface it`,
|
|
1118
|
+
{
|
|
1119
|
+
fix: "Reinstall tenjin-cli; the published CLI skills must be model-invocable."
|
|
1120
|
+
}
|
|
1121
|
+
);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
export {
|
|
1126
|
+
PERMISSIONS_QUESTION,
|
|
1127
|
+
PUBLISH_MODE_CHOICES,
|
|
1128
|
+
PUBLISH_MODE_QUESTION,
|
|
1129
|
+
SEARCH_HOOKS_CHOICES,
|
|
1130
|
+
SEARCH_HOOKS_QUESTION,
|
|
1131
|
+
WALLET_QUESTION,
|
|
1132
|
+
runInstall
|
|
1133
|
+
};
|
|
1134
|
+
//# sourceMappingURL=install-SQAYMNQC.js.map
|