tenjin-cli 0.1.0-alpha.7 → 0.1.0-alpha.9
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 +158 -236
- package/dist/{buy-XVOMNWKN.js → buy-3PPC2SRQ.js} +24 -22
- package/dist/{candidate-DJB2NNTG.js → candidate-FCBWDN4Y.js} +10 -8
- package/dist/{chunk-PLU3E63S.js → chunk-3MQSXDWS.js} +10 -11
- package/dist/chunk-3MQSXDWS.js.map +1 -0
- package/dist/{chunk-DH6D6QIO.js → chunk-6DWKU4RH.js} +11 -9
- package/dist/{chunk-DH6D6QIO.js.map → chunk-6DWKU4RH.js.map} +1 -1
- package/dist/{chunk-WDJTGVKN.js → chunk-6L34JW52.js} +5 -2
- package/dist/chunk-6L34JW52.js.map +1 -0
- package/dist/{chunk-6S44OLND.js → chunk-6RODLWPQ.js} +101 -36
- package/dist/chunk-6RODLWPQ.js.map +1 -0
- package/dist/{chunk-VZ3AJCO5.js → chunk-75G4REUY.js} +2 -2
- package/dist/{chunk-PIIWLEEG.js → chunk-7MJCZ2OX.js} +12 -12
- package/dist/{chunk-2KIDDWQO.js → chunk-ATSCQETF.js} +5 -5
- package/dist/{chunk-ZFE7STX7.js → chunk-AX5WQ3H5.js} +7 -5
- package/dist/{chunk-ZFE7STX7.js.map → chunk-AX5WQ3H5.js.map} +1 -1
- package/dist/{chunk-WRWCDLVK.js → chunk-BFAFOBO3.js} +23 -4
- package/dist/chunk-BFAFOBO3.js.map +1 -0
- package/dist/{chunk-DAJ56EUU.js → chunk-CTFFFQFH.js} +3 -3
- package/dist/{chunk-5X4EBGGU.js → chunk-E5PZEPUO.js} +11 -11
- package/dist/{chunk-GABYDXWL.js → chunk-FFTWWJRW.js} +21 -5
- package/dist/{chunk-GABYDXWL.js.map → chunk-FFTWWJRW.js.map} +1 -1
- package/dist/{chunk-WI5EOAQQ.js → chunk-G7ECLIN6.js} +21 -21
- package/dist/{chunk-CYRYVZPN.js → chunk-GJKDWZ6X.js} +3 -3
- package/dist/{chunk-RGFBBNGP.js → chunk-I4WQXOEL.js} +16 -13
- package/dist/chunk-I4WQXOEL.js.map +1 -0
- package/dist/{chunk-OTDI5FXG.js → chunk-JURZ2T2I.js} +3 -3
- package/dist/{chunk-UYP7G3GZ.js → chunk-KRHUDEIQ.js} +10 -172
- package/dist/chunk-KRHUDEIQ.js.map +1 -0
- package/dist/{chunk-2L73UI6T.js → chunk-MHRREGGN.js} +5 -10
- package/dist/chunk-MHRREGGN.js.map +1 -0
- package/dist/chunk-OQXHNWM3.js +47 -0
- package/dist/chunk-OQXHNWM3.js.map +1 -0
- package/dist/chunk-P74I3WH4.js +204 -0
- package/dist/chunk-P74I3WH4.js.map +1 -0
- package/dist/{chunk-ZEWY3RJ3.js → chunk-PT2NJUGG.js} +6 -6
- package/dist/{chunk-J6CVKC4M.js → chunk-PZRAAAY2.js} +4 -46
- package/dist/chunk-PZRAAAY2.js.map +1 -0
- package/dist/{chunk-XBJ3VLWX.js → chunk-PZSUWDF2.js} +2 -2
- package/dist/{chunk-BBUYCDSG.js → chunk-R2VLGNFD.js} +7 -2
- package/dist/chunk-R2VLGNFD.js.map +1 -0
- package/dist/{chunk-KT2DGKFT.js → chunk-S4IKXAUA.js} +5 -9
- package/dist/chunk-S4IKXAUA.js.map +1 -0
- package/dist/{chunk-E6BNARCS.js → chunk-TMZIXYPL.js} +7 -7
- package/dist/{chunk-YBMMV4Y4.js → chunk-TYVLXAB5.js} +26 -4
- package/dist/chunk-TYVLXAB5.js.map +1 -0
- package/dist/{chunk-GXYNLMUQ.js → chunk-V7BWPOKT.js} +38 -19
- package/dist/chunk-V7BWPOKT.js.map +1 -0
- package/dist/{chunk-L6AV2Q73.js → chunk-VE5BALOI.js} +5 -5
- package/dist/{chunk-GM4RZUVU.js → chunk-WGXUVCUF.js} +8 -6
- package/dist/{chunk-GM4RZUVU.js.map → chunk-WGXUVCUF.js.map} +1 -1
- package/dist/chunk-X3OOVSPX.js +154 -0
- package/dist/chunk-X3OOVSPX.js.map +1 -0
- package/dist/{chunk-2YX6LTCD.js → chunk-XDW6GOHO.js} +5 -5
- package/dist/{cli-7B2QNJG3.js → cli-ATFP3O6Y.js} +42 -29
- package/dist/{cli-7B2QNJG3.js.map → cli-ATFP3O6Y.js.map} +1 -1
- package/dist/{config-SAQEQRFB.js → config-VT5WU47R.js} +9 -6
- package/dist/dist-U4M6QCKE.js +2842 -0
- package/dist/dist-U4M6QCKE.js.map +1 -0
- package/dist/doctor-6PEYDTB5.js +24 -0
- package/dist/{edit-2QO5GQDU.js → edit-GKI37CRM.js} +21 -19
- package/dist/index.js +1 -1
- package/dist/{inspect-IPKKQB2S.js → inspect-ITZIRZDV.js} +19 -16
- package/dist/install-BMMUPFOK.js +922 -0
- package/dist/install-BMMUPFOK.js.map +1 -0
- package/dist/outcome-F5KN3K3Y.js +23 -0
- package/dist/{publish-7WIFFNFG.js → publish-F5G5WIFI.js} +22 -20
- package/dist/{read-5TQR7LCF.js → read-II2ZO4II.js} +21 -19
- package/dist/{read-5TQR7LCF.js.map → read-II2ZO4II.js.map} +1 -1
- package/dist/{run-NPKIP26Y.js → run-FJWMRXZ7.js} +68 -45
- package/dist/run-FJWMRXZ7.js.map +1 -0
- package/dist/search-Z2YALF6S.js +26 -0
- package/dist/{send-ENE47KQE.js → send-RWOBFOBK.js} +20 -18
- package/dist/{send-ENE47KQE.js.map → send-RWOBFOBK.js.map} +1 -1
- package/dist/{session-FZU4VFFE.js → session-DJV5T3BG.js} +17 -15
- package/dist/{session-FZU4VFFE.js.map → session-DJV5T3BG.js.map} +1 -1
- package/dist/skill-heal-OK6YALW6.js +85 -0
- package/dist/skill-heal-OK6YALW6.js.map +1 -0
- package/dist/{wallet-RBDVNZVR.js → wallet-AB4ISFMY.js} +8 -7
- package/dist/{wallet-OCCGEH6H.js → wallet-XVRLJZ63.js} +12 -10
- package/docs/agent-permissions.md +255 -0
- package/package.json +4 -1
- package/skills/tenjin/SKILL.md +126 -47
- package/skills/tenjin-search/SKILL.md +10 -6
- package/dist/chunk-2L73UI6T.js.map +0 -1
- package/dist/chunk-6S44OLND.js.map +0 -1
- package/dist/chunk-BBUYCDSG.js.map +0 -1
- package/dist/chunk-GXYNLMUQ.js.map +0 -1
- package/dist/chunk-J6CVKC4M.js.map +0 -1
- package/dist/chunk-KT2DGKFT.js.map +0 -1
- package/dist/chunk-PLU3E63S.js.map +0 -1
- package/dist/chunk-RGFBBNGP.js.map +0 -1
- package/dist/chunk-UYP7G3GZ.js.map +0 -1
- package/dist/chunk-WDJTGVKN.js.map +0 -1
- package/dist/chunk-WRWCDLVK.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/doctor-ENJ22XWN.js +0 -22
- package/dist/install-7ZIYISQ7.js +0 -589
- package/dist/install-7ZIYISQ7.js.map +0 -1
- package/dist/outcome-NSDE2KAJ.js +0 -20
- package/dist/run-NPKIP26Y.js.map +0 -1
- package/dist/search-63ELMRZH.js +0 -24
- /package/dist/{buy-XVOMNWKN.js.map → buy-3PPC2SRQ.js.map} +0 -0
- /package/dist/{candidate-DJB2NNTG.js.map → candidate-FCBWDN4Y.js.map} +0 -0
- /package/dist/{chunk-VZ3AJCO5.js.map → chunk-75G4REUY.js.map} +0 -0
- /package/dist/{chunk-PIIWLEEG.js.map → chunk-7MJCZ2OX.js.map} +0 -0
- /package/dist/{chunk-2KIDDWQO.js.map → chunk-ATSCQETF.js.map} +0 -0
- /package/dist/{chunk-DAJ56EUU.js.map → chunk-CTFFFQFH.js.map} +0 -0
- /package/dist/{chunk-5X4EBGGU.js.map → chunk-E5PZEPUO.js.map} +0 -0
- /package/dist/{chunk-WI5EOAQQ.js.map → chunk-G7ECLIN6.js.map} +0 -0
- /package/dist/{chunk-CYRYVZPN.js.map → chunk-GJKDWZ6X.js.map} +0 -0
- /package/dist/{chunk-OTDI5FXG.js.map → chunk-JURZ2T2I.js.map} +0 -0
- /package/dist/{chunk-ZEWY3RJ3.js.map → chunk-PT2NJUGG.js.map} +0 -0
- /package/dist/{chunk-XBJ3VLWX.js.map → chunk-PZSUWDF2.js.map} +0 -0
- /package/dist/{chunk-E6BNARCS.js.map → chunk-TMZIXYPL.js.map} +0 -0
- /package/dist/{chunk-L6AV2Q73.js.map → chunk-VE5BALOI.js.map} +0 -0
- /package/dist/{chunk-2YX6LTCD.js.map → chunk-XDW6GOHO.js.map} +0 -0
- /package/dist/{config-SAQEQRFB.js.map → config-VT5WU47R.js.map} +0 -0
- /package/dist/{doctor-ENJ22XWN.js.map → doctor-6PEYDTB5.js.map} +0 -0
- /package/dist/{edit-2QO5GQDU.js.map → edit-GKI37CRM.js.map} +0 -0
- /package/dist/{inspect-IPKKQB2S.js.map → inspect-ITZIRZDV.js.map} +0 -0
- /package/dist/{outcome-NSDE2KAJ.js.map → outcome-F5KN3K3Y.js.map} +0 -0
- /package/dist/{publish-7WIFFNFG.js.map → publish-F5G5WIFI.js.map} +0 -0
- /package/dist/{search-63ELMRZH.js.map → search-Z2YALF6S.js.map} +0 -0
- /package/dist/{wallet-OCCGEH6H.js.map → wallet-AB4ISFMY.js.map} +0 -0
- /package/dist/{wallet-RBDVNZVR.js.map → wallet-XVRLJZ63.js.map} +0 -0
|
@@ -0,0 +1,922 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
runWalletCreate
|
|
4
|
+
} from "./chunk-6DWKU4RH.js";
|
|
5
|
+
import {
|
|
6
|
+
collectDoctorChecks,
|
|
7
|
+
recommendedPermissions
|
|
8
|
+
} from "./chunk-6RODLWPQ.js";
|
|
9
|
+
import "./chunk-FFTWWJRW.js";
|
|
10
|
+
import "./chunk-MJZZTKCC.js";
|
|
11
|
+
import {
|
|
12
|
+
describeWallet,
|
|
13
|
+
resolveWalletProvider
|
|
14
|
+
} from "./chunk-I4WQXOEL.js";
|
|
15
|
+
import {
|
|
16
|
+
walletFileExists
|
|
17
|
+
} from "./chunk-BFAFOBO3.js";
|
|
18
|
+
import "./chunk-V7BWPOKT.js";
|
|
19
|
+
import "./chunk-6L34JW52.js";
|
|
20
|
+
import "./chunk-PZSUWDF2.js";
|
|
21
|
+
import {
|
|
22
|
+
deepestExisting,
|
|
23
|
+
installSkill,
|
|
24
|
+
resolveThroughLink,
|
|
25
|
+
wrapWriteError
|
|
26
|
+
} from "./chunk-X3OOVSPX.js";
|
|
27
|
+
import {
|
|
28
|
+
sanitizeForTerminal
|
|
29
|
+
} from "./chunk-R2VLGNFD.js";
|
|
30
|
+
import {
|
|
31
|
+
persistInstallHarness,
|
|
32
|
+
persistPublishMode
|
|
33
|
+
} from "./chunk-WGXUVCUF.js";
|
|
34
|
+
import "./chunk-CTFFFQFH.js";
|
|
35
|
+
import {
|
|
36
|
+
ownsAnyLock,
|
|
37
|
+
releaseOwnedLocks
|
|
38
|
+
} from "./chunk-TYVLXAB5.js";
|
|
39
|
+
import "./chunk-UO22YNY4.js";
|
|
40
|
+
import {
|
|
41
|
+
CONFIG_DEFAULTS,
|
|
42
|
+
PublishModeSchema,
|
|
43
|
+
loadRawConfig,
|
|
44
|
+
parsePublishModeFlag
|
|
45
|
+
} from "./chunk-KRHUDEIQ.js";
|
|
46
|
+
import "./chunk-OQXHNWM3.js";
|
|
47
|
+
import {
|
|
48
|
+
CLI_SKILL_NAMES,
|
|
49
|
+
HARNESS_TARGETS,
|
|
50
|
+
HOSTED_SKILL_NAME,
|
|
51
|
+
SKILL_NAMES,
|
|
52
|
+
harnessDetectedBy,
|
|
53
|
+
harnessTargetDir,
|
|
54
|
+
isModelInvocationDisabled,
|
|
55
|
+
onPath,
|
|
56
|
+
readSkillFile,
|
|
57
|
+
resolveSkillsSource
|
|
58
|
+
} from "./chunk-P74I3WH4.js";
|
|
59
|
+
import {
|
|
60
|
+
hasCode
|
|
61
|
+
} from "./chunk-2I4QTOLB.js";
|
|
62
|
+
import {
|
|
63
|
+
CliError,
|
|
64
|
+
external_exports,
|
|
65
|
+
writeFileAtomic
|
|
66
|
+
} from "./chunk-PZRAAAY2.js";
|
|
67
|
+
import "./chunk-7FK2UN2T.js";
|
|
68
|
+
import "./chunk-M2O56UK7.js";
|
|
69
|
+
import "./chunk-UHTVXQ2O.js";
|
|
70
|
+
import "./chunk-W6R3HAAG.js";
|
|
71
|
+
import "./chunk-U5S527PP.js";
|
|
72
|
+
import "./chunk-47PP7TAG.js";
|
|
73
|
+
import "./chunk-XJN5WUKL.js";
|
|
74
|
+
import "./chunk-RBJPAZFI.js";
|
|
75
|
+
import "./chunk-KYQVEKP5.js";
|
|
76
|
+
import "./chunk-ZXTAQYNA.js";
|
|
77
|
+
|
|
78
|
+
// src/commands/install.ts
|
|
79
|
+
import { existsSync } from "fs";
|
|
80
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
81
|
+
import { fileURLToPath } from "url";
|
|
82
|
+
import { dirname, isAbsolute, join as join2 } from "path";
|
|
83
|
+
import { homedir } from "os";
|
|
84
|
+
import { styleText } from "util";
|
|
85
|
+
import { Stream } from "stream";
|
|
86
|
+
|
|
87
|
+
// src/lib/harness-permissions.ts
|
|
88
|
+
import { lstat, readFile, realpath } from "fs/promises";
|
|
89
|
+
import { join } from "path";
|
|
90
|
+
function claudeSettingsPath(homeDir) {
|
|
91
|
+
return join(homeDir, ".claude", "settings.json");
|
|
92
|
+
}
|
|
93
|
+
var FREE_VERB_RULES = [
|
|
94
|
+
"Bash(tenjin search:*)",
|
|
95
|
+
"Bash(tenjin inspect:*)",
|
|
96
|
+
"Bash(tenjin read:*)",
|
|
97
|
+
"Bash(tenjin outcome:*)",
|
|
98
|
+
"Bash(tenjin doctor:*)",
|
|
99
|
+
"Bash(tenjin wallet show:*)",
|
|
100
|
+
"Bash(tenjin wallet balance:*)",
|
|
101
|
+
"Bash(tenjin config get:*)",
|
|
102
|
+
"Bash(tenjin candidate list:*)"
|
|
103
|
+
];
|
|
104
|
+
function skip(harness, path, reason, warning) {
|
|
105
|
+
return {
|
|
106
|
+
harness,
|
|
107
|
+
...path !== void 0 ? { path } : {},
|
|
108
|
+
added: [],
|
|
109
|
+
alreadyPresent: [],
|
|
110
|
+
skipped: reason,
|
|
111
|
+
...warning !== void 0 ? { warning } : {}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function permissionsSkipped(harness, homeDir, reason) {
|
|
115
|
+
const path = harness === "claude" ? claudeSettingsPath(homeDir) : void 0;
|
|
116
|
+
return skip(harness, path, reason);
|
|
117
|
+
}
|
|
118
|
+
function isPlainObject(value) {
|
|
119
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
120
|
+
}
|
|
121
|
+
async function wireFreeVerbAllowlist(homeDir) {
|
|
122
|
+
const found = await inspectAllowlist(homeDir);
|
|
123
|
+
if ("result" in found) return found.result;
|
|
124
|
+
const { path, raw, settings, permissions, allow, added, alreadyPresent } = found;
|
|
125
|
+
if (added.length === 0) return { harness: "claude", path, added: [], alreadyPresent };
|
|
126
|
+
const next = {
|
|
127
|
+
...settings,
|
|
128
|
+
permissions: { ...permissions, allow: [...allow, ...added] }
|
|
129
|
+
};
|
|
130
|
+
const current = await readFile(path, "utf8").catch(() => null);
|
|
131
|
+
if (current !== raw) {
|
|
132
|
+
return skip(
|
|
133
|
+
"claude",
|
|
134
|
+
path,
|
|
135
|
+
"changed-since-read",
|
|
136
|
+
`${path} changed while it was being updated, so nothing was written. Re-run \`tenjin install\`.`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
await writeFileAtomic(path, `${JSON.stringify(next, null, 2)}
|
|
140
|
+
`);
|
|
141
|
+
return { harness: "claude", path, added, alreadyPresent };
|
|
142
|
+
}
|
|
143
|
+
async function inspectFreeVerbRules(homeDir) {
|
|
144
|
+
const found = await inspectAllowlist(homeDir);
|
|
145
|
+
if ("result" in found) return { pending: null };
|
|
146
|
+
if (found.added.length > 0) return { pending: found.added };
|
|
147
|
+
return {
|
|
148
|
+
pending: [],
|
|
149
|
+
satisfied: {
|
|
150
|
+
harness: "claude",
|
|
151
|
+
path: found.path,
|
|
152
|
+
added: [],
|
|
153
|
+
alreadyPresent: found.alreadyPresent
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
async function inspectAllowlist(homeDir) {
|
|
158
|
+
const declaredPath = claudeSettingsPath(homeDir);
|
|
159
|
+
const refuse = (p, reason, warning) => ({ result: skip("claude", p, reason, warning) });
|
|
160
|
+
const entry = await lstat(declaredPath).catch(() => null);
|
|
161
|
+
let path = declaredPath;
|
|
162
|
+
if (entry !== null) {
|
|
163
|
+
try {
|
|
164
|
+
path = await realpath(declaredPath);
|
|
165
|
+
} catch (err) {
|
|
166
|
+
return refuse(
|
|
167
|
+
declaredPath,
|
|
168
|
+
"unresolvable",
|
|
169
|
+
`${declaredPath} could not be resolved (${err.message}); it was left exactly as it is.`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
let settings = {};
|
|
174
|
+
let raw = null;
|
|
175
|
+
if (entry !== null) {
|
|
176
|
+
try {
|
|
177
|
+
raw = await readFile(path, "utf8");
|
|
178
|
+
} catch (err) {
|
|
179
|
+
return refuse(
|
|
180
|
+
path,
|
|
181
|
+
"unreadable",
|
|
182
|
+
`${path} could not be read (${err.message}); no permissions were written.`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
let parsed;
|
|
186
|
+
try {
|
|
187
|
+
parsed = JSON.parse(raw);
|
|
188
|
+
} catch (err) {
|
|
189
|
+
return refuse(
|
|
190
|
+
path,
|
|
191
|
+
"unparsable",
|
|
192
|
+
`${path} is not valid JSON (${err.message}); it was left exactly as it is.`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (!isPlainObject(parsed)) {
|
|
196
|
+
return refuse(
|
|
197
|
+
path,
|
|
198
|
+
"unexpected-shape",
|
|
199
|
+
`${path} is not a JSON object; it was left exactly as it is.`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
settings = parsed;
|
|
203
|
+
}
|
|
204
|
+
const permissionsValue = settings.permissions;
|
|
205
|
+
if (permissionsValue !== void 0 && !isPlainObject(permissionsValue)) {
|
|
206
|
+
return refuse(
|
|
207
|
+
path,
|
|
208
|
+
"unexpected-shape",
|
|
209
|
+
`${path} has a "permissions" key that is not an object; it was left exactly as it is.`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
const permissions = permissionsValue ?? {};
|
|
213
|
+
const allowValue = permissions.allow;
|
|
214
|
+
if (allowValue !== void 0 && !Array.isArray(allowValue)) {
|
|
215
|
+
return refuse(
|
|
216
|
+
path,
|
|
217
|
+
"unexpected-shape",
|
|
218
|
+
`${path} has a "permissions.allow" key that is not an array; it was left exactly as it is.`
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
const allow = allowValue ?? [];
|
|
222
|
+
const present = new Set(allow.filter((e) => typeof e === "string"));
|
|
223
|
+
const added = FREE_VERB_RULES.filter((rule) => !present.has(rule));
|
|
224
|
+
const alreadyPresent = FREE_VERB_RULES.filter((rule) => present.has(rule));
|
|
225
|
+
return { path, raw, settings, permissions, allow, added, alreadyPresent: [...alreadyPresent] };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/lib/clack.ts
|
|
229
|
+
var SHOW_CURSOR = "\x1B[?25h";
|
|
230
|
+
function withInputEnd(streams, onEnd, run) {
|
|
231
|
+
const controller = new AbortController();
|
|
232
|
+
let settleEnd;
|
|
233
|
+
const ended = new Promise((resolve) => {
|
|
234
|
+
settleEnd = () => {
|
|
235
|
+
streams.output.write(SHOW_CURSOR);
|
|
236
|
+
resolve(onEnd);
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
const end = () => {
|
|
240
|
+
controller.abort();
|
|
241
|
+
settleEnd?.();
|
|
242
|
+
};
|
|
243
|
+
const onKeypress = (_text, key) => {
|
|
244
|
+
if (key?.ctrl === true && key.name === "d") end();
|
|
245
|
+
};
|
|
246
|
+
streams.input.on("keypress", onKeypress);
|
|
247
|
+
if (streams.input.readableEnded) {
|
|
248
|
+
queueMicrotask(end);
|
|
249
|
+
} else {
|
|
250
|
+
streams.input.once("end", end);
|
|
251
|
+
streams.input.once("close", end);
|
|
252
|
+
}
|
|
253
|
+
return Promise.race([run(controller.signal), ended]).finally(() => {
|
|
254
|
+
streams.input.off("keypress", onKeypress);
|
|
255
|
+
streams.input.off("end", end);
|
|
256
|
+
streams.input.off("close", end);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function resolveStreams(streams) {
|
|
260
|
+
return { input: streams.input ?? process.stdin, output: streams.output ?? process.stderr };
|
|
261
|
+
}
|
|
262
|
+
async function selectOne(opts) {
|
|
263
|
+
const { select, isCancel } = await import("./dist-U4M6QCKE.js");
|
|
264
|
+
const streams = resolveStreams(opts.streams ?? {});
|
|
265
|
+
return withInputEnd(streams, null, async (signal) => {
|
|
266
|
+
const answer = await select({
|
|
267
|
+
message: opts.message,
|
|
268
|
+
options: opts.choices.map((c) => ({
|
|
269
|
+
value: c.value,
|
|
270
|
+
label: c.label,
|
|
271
|
+
...c.hint !== void 0 ? { hint: c.hint } : {}
|
|
272
|
+
})),
|
|
273
|
+
initialValue: opts.initialValue,
|
|
274
|
+
input: streams.input,
|
|
275
|
+
output: streams.output,
|
|
276
|
+
signal
|
|
277
|
+
});
|
|
278
|
+
return isCancel(answer) ? null : answer;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
async function confirmChoice(message, initialValue = true, streams = {}) {
|
|
282
|
+
const { confirm, isCancel } = await import("./dist-U4M6QCKE.js");
|
|
283
|
+
const resolved = resolveStreams(streams);
|
|
284
|
+
return withInputEnd(resolved, false, async (signal) => {
|
|
285
|
+
const answer = await confirm({
|
|
286
|
+
message,
|
|
287
|
+
initialValue,
|
|
288
|
+
input: resolved.input,
|
|
289
|
+
output: resolved.output,
|
|
290
|
+
signal
|
|
291
|
+
});
|
|
292
|
+
return isCancel(answer) ? false : answer;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
async function intro(message) {
|
|
296
|
+
const clack = await import("./dist-U4M6QCKE.js");
|
|
297
|
+
clack.intro(message, { output: process.stderr });
|
|
298
|
+
}
|
|
299
|
+
async function outro(message) {
|
|
300
|
+
const clack = await import("./dist-U4M6QCKE.js");
|
|
301
|
+
clack.outro(message, { output: process.stderr });
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/commands/install.ts
|
|
305
|
+
var HARNESSES = HARNESS_TARGETS;
|
|
306
|
+
var InstallInputSchema = external_exports.object({
|
|
307
|
+
harness: external_exports.array(external_exports.string()).optional(),
|
|
308
|
+
dryRun: external_exports.boolean().optional(),
|
|
309
|
+
publishMode: external_exports.string().optional(),
|
|
310
|
+
noWallet: external_exports.boolean().optional(),
|
|
311
|
+
/** Opt-in for the ~/.claude/CLAUDE.md nudge: true (--claude-md), false
|
|
312
|
+
* (--no-claude-md), or undefined (skip). Never a question: the walkthrough is
|
|
313
|
+
* capped at three decisions. */
|
|
314
|
+
claudeMd: external_exports.boolean().optional(),
|
|
315
|
+
/** Wire the free-verb harness allowlist without asking (`--allow-free-verbs`). */
|
|
316
|
+
allowFreeVerbs: external_exports.boolean().optional()
|
|
317
|
+
});
|
|
318
|
+
var SKILLS_MARKER = "<!-- tenjin-cli:skills -->";
|
|
319
|
+
function nudgeLine(skillsDir) {
|
|
320
|
+
return `${SKILLS_MARKER} Tenjin: before regenerating public research (version-specific compatibility, integration gotchas, benchmarks, dated probes), run 'tenjin search "<question>" --json' first; it is free and anonymous but sends the generalized question text to tenjin.blog, so strip private identifiers. Skills (tenjin-search, tenjin-publish, tenjin) are installed at ${skillsDir}; read the relevant SKILL.md before using the CLI.`;
|
|
321
|
+
}
|
|
322
|
+
function upsertMarkerLine(existing, line) {
|
|
323
|
+
const text = existing ?? "";
|
|
324
|
+
if (!text.includes(SKILLS_MARKER)) {
|
|
325
|
+
const prefix = text.length === 0 || text.endsWith("\n") ? "" : "\n";
|
|
326
|
+
return { content: `${text}${prefix}${line}
|
|
327
|
+
`, change: "append" };
|
|
328
|
+
}
|
|
329
|
+
const lines = text.split("\n");
|
|
330
|
+
const idx = lines.findIndex((l) => l.includes(SKILLS_MARKER));
|
|
331
|
+
if (lines[idx] === line) return { content: null, change: "none" };
|
|
332
|
+
lines[idx] = line;
|
|
333
|
+
return { content: lines.join("\n"), change: "replace" };
|
|
334
|
+
}
|
|
335
|
+
var CODEX_NETWORK_RULE = "[sandbox_workspace_write]\nnetwork_access = true";
|
|
336
|
+
async function runInstall(input, ctx, deps = {}) {
|
|
337
|
+
return withInterruptGuard((markPhase) => installBody(input, ctx, deps, markPhase));
|
|
338
|
+
}
|
|
339
|
+
async function withInterruptGuard(fn) {
|
|
340
|
+
let phase;
|
|
341
|
+
const onSignal = (signal) => {
|
|
342
|
+
const wasWriting = ownsAnyLock() || phase === "writing-skills";
|
|
343
|
+
releaseOwnedLocks();
|
|
344
|
+
if (process.stdin.isTTY) process.stdin.setRawMode?.(false);
|
|
345
|
+
if (process.stdout.isTTY) process.stdout.write("\x1B[?25h");
|
|
346
|
+
process.stderr.write(
|
|
347
|
+
wasWriting ? `
|
|
348
|
+
Interrupted mid-write. Some files may be half-written; re-run \`tenjin install\` to finish.
|
|
349
|
+
` : phase === "wired" ? `
|
|
350
|
+
Interrupted after the skills were written; later setup steps may not have finished. Re-run \`tenjin install\` to finish.
|
|
351
|
+
` : "\nInterrupted before anything was written; nothing changed.\n"
|
|
352
|
+
);
|
|
353
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
354
|
+
};
|
|
355
|
+
process.on("SIGINT", onSignal);
|
|
356
|
+
process.on("SIGTERM", onSignal);
|
|
357
|
+
try {
|
|
358
|
+
return await fn((p) => {
|
|
359
|
+
phase = p;
|
|
360
|
+
});
|
|
361
|
+
} finally {
|
|
362
|
+
process.off("SIGINT", onSignal);
|
|
363
|
+
process.off("SIGTERM", onSignal);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function installBody(input, ctx, deps, markPhase) {
|
|
367
|
+
const parsed = InstallInputSchema.safeParse(input);
|
|
368
|
+
if (!parsed.success) {
|
|
369
|
+
throw new CliError("USAGE", "Invalid install options", {
|
|
370
|
+
fix: "Run `tenjin install --help`.",
|
|
371
|
+
details: parsed.error.issues
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const dryRun = parsed.data.dryRun === true;
|
|
375
|
+
const noWallet = parsed.data.noWallet === true;
|
|
376
|
+
const claudeMdFlag = parsed.data.claudeMd;
|
|
377
|
+
const allowFreeVerbs = parsed.data.allowFreeVerbs === true;
|
|
378
|
+
const publishModeFlag = parsed.data.publishMode !== void 0 ? parseModeFlag(parsed.data.publishMode) : void 0;
|
|
379
|
+
const env = deps.env ?? process.env;
|
|
380
|
+
const home = deps.homeDir ?? homedir();
|
|
381
|
+
if (!isAbsolute(home)) {
|
|
382
|
+
throw new CliError(
|
|
383
|
+
"INTERNAL",
|
|
384
|
+
"The home directory did not resolve to an absolute path, so nothing was installed.",
|
|
385
|
+
{
|
|
386
|
+
fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
const which = deps.which ?? ((bin) => onPath(bin, env));
|
|
391
|
+
const humanOutput = ctx.flags.json === true ? false : deps.isInteractive ?? ctx.io.isTTY;
|
|
392
|
+
const canPrompt = humanOutput && (deps.isInteractive ?? Boolean(process.stdin.isTTY));
|
|
393
|
+
const skillsSource = deps.skillsSourceDir ?? resolveSkillsSource(fileURLToPath(new URL(".", import.meta.url)));
|
|
394
|
+
await assertSkillsSource(skillsSource);
|
|
395
|
+
const plans = resolvePlans(parsed.data.harness, home, which);
|
|
396
|
+
const explicitHarness = parsed.data.harness !== void 0 && parsed.data.harness.length > 0;
|
|
397
|
+
const claudeMdWrite = claudeMdFlag === true;
|
|
398
|
+
const harnesses = [];
|
|
399
|
+
if (!dryRun) markPhase("writing-skills");
|
|
400
|
+
for (const plan of plans) {
|
|
401
|
+
harnesses.push(await applyPlan(plan, skillsSource, dryRun, claudeMdWrite));
|
|
402
|
+
}
|
|
403
|
+
await assertSkillsLanded(plans, dryRun);
|
|
404
|
+
if (!dryRun) markPhase("wired");
|
|
405
|
+
if (explicitHarness && !dryRun) {
|
|
406
|
+
await underDataDir(
|
|
407
|
+
ctx.dataDir,
|
|
408
|
+
() => persistInstallHarness(
|
|
409
|
+
ctx.dataDir,
|
|
410
|
+
plans.map((p) => p.harness)
|
|
411
|
+
)
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
const doctorDeps = { ...deps.doctorDeps ?? {} };
|
|
415
|
+
doctorDeps.homeDir ??= home;
|
|
416
|
+
doctorDeps.which ??= which;
|
|
417
|
+
const collect = deps.collectChecks ?? ((c) => collectDoctorChecks(c, doctorDeps));
|
|
418
|
+
const doctor = await collect(ctx);
|
|
419
|
+
if (canPrompt) await (deps.intro ?? intro)("tenjin install");
|
|
420
|
+
const publishMode = await underDataDir(
|
|
421
|
+
ctx.dataDir,
|
|
422
|
+
() => resolvePublishMode(publishModeFlag, ctx, deps, dryRun, canPrompt)
|
|
423
|
+
);
|
|
424
|
+
const permissions = await resolvePermissions({
|
|
425
|
+
plans,
|
|
426
|
+
home,
|
|
427
|
+
deps,
|
|
428
|
+
flag: allowFreeVerbs,
|
|
429
|
+
dryRun,
|
|
430
|
+
canPrompt
|
|
431
|
+
});
|
|
432
|
+
const wallet = humanOutput ? await resolveWallet(ctx, deps, dryRun || !canPrompt || noWallet) : void 0;
|
|
433
|
+
if (canPrompt) await (deps.outro ?? outro)("Setup complete.");
|
|
434
|
+
const data = {
|
|
435
|
+
dryRun,
|
|
436
|
+
skillsSource,
|
|
437
|
+
harnesses,
|
|
438
|
+
doctor: { status: doctor.failure !== void 0 ? "fail" : "pass", checks: doctor.checks },
|
|
439
|
+
publishMode,
|
|
440
|
+
// Shipped with the install rather than left for the operator to discover after
|
|
441
|
+
// their first auto-mode denial (#33). Static constants, no config key: see
|
|
442
|
+
// lib/permissions.ts for why this is deliberately not operator-editable state.
|
|
443
|
+
// `wired` is the outcome of THIS run's optional settings.json write; the three
|
|
444
|
+
// recommendation tiers beside it are unchanged, so a machine consumer that
|
|
445
|
+
// read `alwaysSafe` / `optIn` / `neverAllowlisted` before still does.
|
|
446
|
+
permissions: { ...recommendedPermissions(), wired: permissions }
|
|
447
|
+
};
|
|
448
|
+
if (!humanOutput) return { data };
|
|
449
|
+
const humanLines = buildWalkthrough(ctx.io, {
|
|
450
|
+
dryRun,
|
|
451
|
+
harnesses,
|
|
452
|
+
publishMode,
|
|
453
|
+
permissions,
|
|
454
|
+
wallet: wallet ?? { status: "none" },
|
|
455
|
+
doctor
|
|
456
|
+
});
|
|
457
|
+
return { data, humanLines };
|
|
458
|
+
}
|
|
459
|
+
async function underDataDir(dataDir, fn) {
|
|
460
|
+
try {
|
|
461
|
+
return await fn();
|
|
462
|
+
} catch (err) {
|
|
463
|
+
if (!hasCode(err, "EACCES") && !hasCode(err, "EPERM")) throw err;
|
|
464
|
+
throw new CliError("INTERNAL", `Could not use the Tenjin data directory ${dataDir}.`, {
|
|
465
|
+
fix: `Permission denied. Check that you can write to it (\`ls -ld ${dataDir}\`), then re-run \`tenjin install\`.`,
|
|
466
|
+
cause: err
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
var EXAMPLE_QUESTION = "what actually changed in <library> v3's public API";
|
|
471
|
+
function buildWalkthrough(io, s) {
|
|
472
|
+
const lines = [];
|
|
473
|
+
if (s.dryRun) lines.push(paint(io, "yellow", "Dry run: nothing was written."));
|
|
474
|
+
lines.push(...noticeLines(io, s));
|
|
475
|
+
if (lines.length > 0) lines.push("");
|
|
476
|
+
lines.push(...summaryLines(io, s));
|
|
477
|
+
return lines;
|
|
478
|
+
}
|
|
479
|
+
function noticeLines(io, s) {
|
|
480
|
+
const lines = [];
|
|
481
|
+
for (const h of s.harnesses) {
|
|
482
|
+
if (h.hostedArrivedFirst) {
|
|
483
|
+
lines.push(
|
|
484
|
+
paint(
|
|
485
|
+
io,
|
|
486
|
+
"dim",
|
|
487
|
+
`The hosted ${HOSTED_SKILL_NAME} skill was already in ${h.skillsDir}: kept as the zero-install fallback, and the CLI skills now take precedence.`
|
|
488
|
+
)
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
const nudgePaths = nudgeFilesTouched(h);
|
|
492
|
+
if (nudgePaths.length > 0) {
|
|
493
|
+
lines.push(
|
|
494
|
+
paint(
|
|
495
|
+
io,
|
|
496
|
+
"dim",
|
|
497
|
+
"The nudge tells agents to run a free anonymous `tenjin search` before regenerating research; the generalized question text is sent to tenjin.blog."
|
|
498
|
+
)
|
|
499
|
+
);
|
|
500
|
+
lines.push(
|
|
501
|
+
paint(
|
|
502
|
+
io,
|
|
503
|
+
"dim",
|
|
504
|
+
`Undo anytime: delete the ${SKILLS_MARKER} line from ${nudgePaths.join(" and ")}.`
|
|
505
|
+
)
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
if (h.codexNetworkRule !== void 0) {
|
|
509
|
+
lines.push(paint(io, "dim", "Codex blocks network by default; add to ~/.codex/config.toml:"));
|
|
510
|
+
for (const rl of h.codexNetworkRule.split("\n")) lines.push(paint(io, "dim", ` ${rl}`));
|
|
511
|
+
}
|
|
512
|
+
for (const w of h.warnings) lines.push(paint(io, "yellow", `! ${w}`));
|
|
513
|
+
}
|
|
514
|
+
if (s.permissions.warning !== void 0) {
|
|
515
|
+
lines.push(paint(io, "yellow", `! ${sanitizeForTerminal(s.permissions.warning)}`));
|
|
516
|
+
}
|
|
517
|
+
lines.push(...doctorNotices(io, s.doctor));
|
|
518
|
+
return lines;
|
|
519
|
+
}
|
|
520
|
+
function summaryLines(io, s) {
|
|
521
|
+
return [
|
|
522
|
+
...s.harnesses.map((h) => skillsLine(io, h, s.dryRun)),
|
|
523
|
+
publishingLine(io, s.publishMode.value),
|
|
524
|
+
permissionsLine(io, s.permissions),
|
|
525
|
+
walletLine(io, s.wallet),
|
|
526
|
+
`${paint(io, "bold", "Next:")} tenjin search "${EXAMPLE_QUESTION}"`
|
|
527
|
+
];
|
|
528
|
+
}
|
|
529
|
+
function harnessLabel(h) {
|
|
530
|
+
return h === "claude" ? "Claude Code" : h === "codex" ? "Codex" : "Agent Skills";
|
|
531
|
+
}
|
|
532
|
+
function skillsLine(io, h, dryRun) {
|
|
533
|
+
const changed = h.skills.some((s) => s.status !== "up-to-date");
|
|
534
|
+
const verb = dryRun ? "would install" : changed ? "installed" : "up to date";
|
|
535
|
+
const wired = [];
|
|
536
|
+
if (h.agentsMd !== void 0) wired.push("AGENTS.md nudge");
|
|
537
|
+
if (h.claudeMd !== void 0 && h.claudeMd.status !== "skipped") wired.push("CLAUDE.md nudge");
|
|
538
|
+
const suffix = wired.length > 0 ? ` + ${wired.join(" + ")}` : "";
|
|
539
|
+
const head = `${harnessLabel(h.harness)}: ${h.skills.length} skills ${verb}${suffix}`;
|
|
540
|
+
return `${paint(io, "green", "\u2713")} ${paint(io, "bold", head)} in ${h.skillsDir}. ${skillRoster(h)}.`;
|
|
541
|
+
}
|
|
542
|
+
function publishingLine(io, mode) {
|
|
543
|
+
return `${paint(io, "green", "\u2713")} ${paint(io, "bold", `Publishing: ${mode}`)}. ${modeBlurb(mode)}`;
|
|
544
|
+
}
|
|
545
|
+
function permissionsLine(io, p) {
|
|
546
|
+
const label = paint(io, "bold", "Permissions:");
|
|
547
|
+
if (p.added.length > 0) {
|
|
548
|
+
return `${paint(io, "green", "\u2713")} ${label} ${p.added.length} free tenjin commands added to ${p.path}. Full caveats: tenjin doctor`;
|
|
549
|
+
}
|
|
550
|
+
if (p.skipped === void 0) {
|
|
551
|
+
return `${paint(io, "green", "\u2713")} ${label} the ${FREE_VERB_RULES.length} free tenjin commands were already allowed in ${p.path}`;
|
|
552
|
+
}
|
|
553
|
+
if (p.skipped === "harness-not-claude") {
|
|
554
|
+
return `${paint(io, "dim", "-")} ${label} not wired (Claude Code only). Run \`tenjin doctor\` for the lines your harness needs.`;
|
|
555
|
+
}
|
|
556
|
+
if (p.skipped === "dry-run") {
|
|
557
|
+
return `${paint(io, "dim", "-")} ${label} unchanged (dry run).`;
|
|
558
|
+
}
|
|
559
|
+
if (p.skipped === "declined") {
|
|
560
|
+
return `${paint(io, "dim", "-")} ${label} unchanged. Add them anytime: tenjin install --allow-free-verbs`;
|
|
561
|
+
}
|
|
562
|
+
if (p.skipped === "not-requested") {
|
|
563
|
+
return `${paint(io, "dim", "-")} ${label} unchanged. Allow the ${FREE_VERB_RULES.length} free tenjin commands with: tenjin install --allow-free-verbs`;
|
|
564
|
+
}
|
|
565
|
+
if (p.skipped === "changed-since-read") {
|
|
566
|
+
return `${paint(io, "yellow", "!")} ${label} ${p.path} changed while it was being updated, so nothing was written. Re-run: tenjin install`;
|
|
567
|
+
}
|
|
568
|
+
return `${paint(io, "yellow", "!")} ${label} ${p.path} was left untouched. Fix it, then: tenjin install --allow-free-verbs`;
|
|
569
|
+
}
|
|
570
|
+
function walletLine(io, w) {
|
|
571
|
+
const label = paint(io, "bold", "Wallet:");
|
|
572
|
+
if (w.status === "existing") {
|
|
573
|
+
return `${paint(io, "green", "\u2713")} ${label} ${w.address} (existing). Check funds with: tenjin wallet balance`;
|
|
574
|
+
}
|
|
575
|
+
if (w.status === "created") {
|
|
576
|
+
return `${paint(io, "green", "\u2713")} ${label} ${w.address}. Fund it with a few dollars of USDC on Base, then: tenjin wallet balance`;
|
|
577
|
+
}
|
|
578
|
+
return `${paint(io, "dim", "-")} ${label} none. Create one later with: tenjin wallet create`;
|
|
579
|
+
}
|
|
580
|
+
function skillRoster(h) {
|
|
581
|
+
const cli = h.skills.filter((s) => s.cli).map((s) => s.name);
|
|
582
|
+
const hosted = h.skills.filter((s) => !s.cli).map((s) => s.name);
|
|
583
|
+
const parts = [];
|
|
584
|
+
if (cli.length > 0) parts.push(`${cli.join(", ")} (CLI)`);
|
|
585
|
+
if (hosted.length > 0) parts.push(`${hosted.join(", ")} (hosted, zero-install fallback)`);
|
|
586
|
+
return parts.join("; ");
|
|
587
|
+
}
|
|
588
|
+
function nudgeFilesTouched(h) {
|
|
589
|
+
const paths = [];
|
|
590
|
+
if (h.agentsMd !== void 0 && ["appended", "updated", "would-append", "would-update"].includes(h.agentsMd.status)) {
|
|
591
|
+
paths.push(h.agentsMd.path);
|
|
592
|
+
}
|
|
593
|
+
if (h.claudeMd !== void 0 && ["written", "updated", "would-write", "would-update"].includes(h.claudeMd.status)) {
|
|
594
|
+
paths.push(h.claudeMd.path);
|
|
595
|
+
}
|
|
596
|
+
return paths;
|
|
597
|
+
}
|
|
598
|
+
function modeBlurb(v) {
|
|
599
|
+
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.";
|
|
600
|
+
}
|
|
601
|
+
async function resolveWallet(ctx, deps, skipCreate) {
|
|
602
|
+
const exists = await (deps.walletExists ?? walletFileExists)(ctx.dataDir);
|
|
603
|
+
if (exists) {
|
|
604
|
+
return {
|
|
605
|
+
status: "existing",
|
|
606
|
+
address: await (deps.walletAddress ?? existingWalletAddress)(ctx)
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
if (skipCreate) return { status: "none" };
|
|
610
|
+
const confirm = deps.confirmWallet ?? defaultConfirm;
|
|
611
|
+
if (!await confirm(WALLET_QUESTION)) return { status: "none" };
|
|
612
|
+
return { status: "created", address: await (deps.createWallet ?? defaultCreateWallet)(ctx) };
|
|
613
|
+
}
|
|
614
|
+
async function existingWalletAddress(ctx) {
|
|
615
|
+
return (await describeWallet(resolveWalletProvider(ctx))).address;
|
|
616
|
+
}
|
|
617
|
+
async function defaultCreateWallet(ctx) {
|
|
618
|
+
const result = await runWalletCreate(ctx);
|
|
619
|
+
return result.data.address;
|
|
620
|
+
}
|
|
621
|
+
function defaultConfirm(label) {
|
|
622
|
+
return confirmChoice(label, true);
|
|
623
|
+
}
|
|
624
|
+
function doctorNotices(io, doctor) {
|
|
625
|
+
const problems = doctor.checks.filter((c) => c.status !== "ok");
|
|
626
|
+
if (problems.length === 0) return [];
|
|
627
|
+
const lines = [paint(io, "yellow", "Some checks need attention:")];
|
|
628
|
+
for (const c of problems) {
|
|
629
|
+
const icon = c.status === "fail" ? paint(io, "red", "\u2717") : paint(io, "yellow", "!");
|
|
630
|
+
lines.push(` ${icon} ${c.name}: ${sanitizeForTerminal(c.detail)}`);
|
|
631
|
+
if (c.fix !== void 0) {
|
|
632
|
+
lines.push(paint(io, "dim", ` fix: ${sanitizeForTerminal(c.fix)}`));
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return lines;
|
|
636
|
+
}
|
|
637
|
+
var DEFAULT_MODE = CONFIG_DEFAULTS.publish.mode;
|
|
638
|
+
var PUBLISH_MODE_CHOICES = [
|
|
639
|
+
{
|
|
640
|
+
value: "auto",
|
|
641
|
+
label: "Auto (recommended)",
|
|
642
|
+
hint: "your agent publishes clean pieces on its own; your harness still shows each command for approval"
|
|
643
|
+
},
|
|
644
|
+
{ value: "review", label: "Ask me in chat first" },
|
|
645
|
+
{ value: "full-auto", label: "Fully unattended", hint: "only hard blocks stop it" }
|
|
646
|
+
];
|
|
647
|
+
var PUBLISH_MODE_QUESTION = "When your agent has something worth publishing:";
|
|
648
|
+
async function resolvePublishMode(flag, ctx, deps, dryRun, interactive) {
|
|
649
|
+
if (flag !== void 0) {
|
|
650
|
+
if (!dryRun) await persistPublishMode(ctx.dataDir, flag);
|
|
651
|
+
return { value: flag, source: "flag" };
|
|
652
|
+
}
|
|
653
|
+
const config = await loadRawConfig(ctx.dataDir);
|
|
654
|
+
if (config.publish?.mode !== void 0) {
|
|
655
|
+
return { value: config.publish.mode, source: "existing" };
|
|
656
|
+
}
|
|
657
|
+
if (dryRun || !interactive) return { value: DEFAULT_MODE, source: "default-skipped" };
|
|
658
|
+
const answer = await (deps.promptPublishMode ?? defaultPromptPublishMode)();
|
|
659
|
+
if (answer === null) return { value: DEFAULT_MODE, source: "default-skipped" };
|
|
660
|
+
const parsed = PublishModeSchema.safeParse(answer);
|
|
661
|
+
if (!parsed.success) return { value: DEFAULT_MODE, source: "default-skipped" };
|
|
662
|
+
await persistPublishMode(ctx.dataDir, parsed.data);
|
|
663
|
+
return { value: parsed.data, source: "prompt" };
|
|
664
|
+
}
|
|
665
|
+
function defaultPromptPublishMode() {
|
|
666
|
+
return selectOne({
|
|
667
|
+
message: PUBLISH_MODE_QUESTION,
|
|
668
|
+
choices: PUBLISH_MODE_CHOICES.map((c) => ({ ...c })),
|
|
669
|
+
initialValue: "auto"
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
function parseModeFlag(value) {
|
|
673
|
+
return parsePublishModeFlag(value, "--publish-mode");
|
|
674
|
+
}
|
|
675
|
+
var PERMISSIONS_QUESTION = [
|
|
676
|
+
"Let your agent search tenjin without permission popups?",
|
|
677
|
+
`Adds ${FREE_VERB_RULES.length} free commands to ~/.claude/settings.json.`,
|
|
678
|
+
"None can spend USDC or open your wallet keystore;",
|
|
679
|
+
"three send or store data (search, outcome, read).",
|
|
680
|
+
"Full caveats: tenjin doctor."
|
|
681
|
+
].join(" ");
|
|
682
|
+
var WALLET_QUESTION = "Create a wallet now?";
|
|
683
|
+
async function resolvePermissions(args) {
|
|
684
|
+
const { plans, home, deps, flag, dryRun, canPrompt } = args;
|
|
685
|
+
if (!plans.some((p) => p.harness === "claude")) {
|
|
686
|
+
return permissionsSkipped(plans[0]?.harness ?? "shared", home, "harness-not-claude");
|
|
687
|
+
}
|
|
688
|
+
if (dryRun) return permissionsSkipped("claude", home, "dry-run");
|
|
689
|
+
if (flag) return wireFreeVerbAllowlist(home);
|
|
690
|
+
if (!canPrompt) return permissionsSkipped("claude", home, "not-requested");
|
|
691
|
+
const probe = await (deps.inspectPermissions ?? inspectFreeVerbRules)(home);
|
|
692
|
+
if (probe.satisfied !== void 0) return probe.satisfied;
|
|
693
|
+
const confirm = deps.confirmPermissions ?? defaultConfirm;
|
|
694
|
+
if (!await confirm(PERMISSIONS_QUESTION)) {
|
|
695
|
+
return permissionsSkipped("claude", home, "declined");
|
|
696
|
+
}
|
|
697
|
+
return wireFreeVerbAllowlist(home);
|
|
698
|
+
}
|
|
699
|
+
function resolvePlans(override, home, which) {
|
|
700
|
+
if (override !== void 0 && override.length > 0) {
|
|
701
|
+
const plans2 = override.map((v) => planFor(validateHarness(v), ["override"], true, home));
|
|
702
|
+
return dedupeBySkillsDir(plans2);
|
|
703
|
+
}
|
|
704
|
+
const plans = [];
|
|
705
|
+
const claudeBy = harnessDetectedBy(home, "claude", which);
|
|
706
|
+
const codexBy = harnessDetectedBy(home, "codex", which);
|
|
707
|
+
if (claudeBy.length > 0) plans.push(planFor("claude", claudeBy, true, home));
|
|
708
|
+
if (codexBy.length > 0) plans.push(planFor("codex", codexBy, true, home));
|
|
709
|
+
if (plans.length === 0) {
|
|
710
|
+
plans.push(planFor("shared", ["fallback"], false, home));
|
|
711
|
+
}
|
|
712
|
+
return dedupeBySkillsDir(plans);
|
|
713
|
+
}
|
|
714
|
+
function planFor(harness, detectedBy, detected, home) {
|
|
715
|
+
const skillsDir = harnessTargetDir(home, harness);
|
|
716
|
+
return { harness, detected, detectedBy, skillsDir, wiresAgentsMd: harness !== "claude", home };
|
|
717
|
+
}
|
|
718
|
+
function dedupeBySkillsDir(plans) {
|
|
719
|
+
const seen = /* @__PURE__ */ new Set();
|
|
720
|
+
const out = [];
|
|
721
|
+
for (const p of plans) {
|
|
722
|
+
if (seen.has(p.skillsDir)) continue;
|
|
723
|
+
seen.add(p.skillsDir);
|
|
724
|
+
out.push(p);
|
|
725
|
+
}
|
|
726
|
+
return out;
|
|
727
|
+
}
|
|
728
|
+
function validateHarness(value) {
|
|
729
|
+
if (HARNESSES.includes(value)) return value;
|
|
730
|
+
throw new CliError("USAGE", `Unknown harness "${value}"`, {
|
|
731
|
+
fix: `--harness must be one of: ${HARNESSES.join(", ")}.`
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
async function applyPlan(plan, skillsSource, dryRun, claudeMdWrite) {
|
|
735
|
+
const skills = [];
|
|
736
|
+
const warnings = [];
|
|
737
|
+
for (const name of SKILL_NAMES) {
|
|
738
|
+
const { status, warning, preexisting } = await installSkill(
|
|
739
|
+
join2(skillsSource, name),
|
|
740
|
+
join2(plan.skillsDir, name),
|
|
741
|
+
dryRun,
|
|
742
|
+
name
|
|
743
|
+
);
|
|
744
|
+
skills.push({
|
|
745
|
+
name,
|
|
746
|
+
status,
|
|
747
|
+
preexisting,
|
|
748
|
+
cli: CLI_SKILL_NAMES.includes(name),
|
|
749
|
+
modelInvocable: await landedInvocable(plan.skillsDir, skillsSource, name, dryRun)
|
|
750
|
+
});
|
|
751
|
+
if (warning !== void 0) warnings.push(warning);
|
|
752
|
+
}
|
|
753
|
+
const hostedPreexisting = skills.some((s) => s.name === HOSTED_SKILL_NAME && s.preexisting);
|
|
754
|
+
const hostedArrivedFirst = hostedPreexisting && !skills.some((s) => s.cli && s.preexisting);
|
|
755
|
+
const result = {
|
|
756
|
+
harness: plan.harness,
|
|
757
|
+
detected: plan.detected,
|
|
758
|
+
detectedBy: plan.detectedBy,
|
|
759
|
+
skillsDir: plan.skillsDir,
|
|
760
|
+
skills,
|
|
761
|
+
hostedPreexisting,
|
|
762
|
+
hostedArrivedFirst,
|
|
763
|
+
notes: notesFor(plan, hostedArrivedFirst),
|
|
764
|
+
warnings
|
|
765
|
+
};
|
|
766
|
+
if (plan.wiresAgentsMd) {
|
|
767
|
+
result.agentsMd = await wireAgentsMd(plan, dryRun);
|
|
768
|
+
result.codexNetworkRule = CODEX_NETWORK_RULE;
|
|
769
|
+
} else if (plan.harness === "claude") {
|
|
770
|
+
result.claudeMd = await wireClaudeMd(plan, dryRun, claudeMdWrite);
|
|
771
|
+
}
|
|
772
|
+
return result;
|
|
773
|
+
}
|
|
774
|
+
async function wireClaudeMd(plan, dryRun, write) {
|
|
775
|
+
const path = join2(plan.home, ".claude", "CLAUDE.md");
|
|
776
|
+
if (!write) return { path, status: "skipped" };
|
|
777
|
+
const probe = await probeMarkerText(path);
|
|
778
|
+
const { content, change } = upsertMarkerLine(probe.text, nudgeLine(plan.skillsDir));
|
|
779
|
+
if (change === "none") return { path, status: "up-to-date" };
|
|
780
|
+
const writeTo = await prepareMarkerWrite(path, probe);
|
|
781
|
+
if (!dryRun && content !== null) await writeMarkerFile(path, writeTo, content);
|
|
782
|
+
if (change === "append") return { path, status: dryRun ? "would-write" : "written" };
|
|
783
|
+
return { path, status: dryRun ? "would-update" : "updated" };
|
|
784
|
+
}
|
|
785
|
+
function notesFor(plan, hostedArrivedFirst) {
|
|
786
|
+
const notes = plan.harness === "claude" ? [
|
|
787
|
+
"Installed at the user level (~/.claude/skills). A Claude Code plugin will later make this automatic."
|
|
788
|
+
] : [
|
|
789
|
+
"Copied into the shared Agent Skills location (~/.agents/skills). Codex and any Agent-Skills-compatible harness read it there."
|
|
790
|
+
];
|
|
791
|
+
if (hostedArrivedFirst) {
|
|
792
|
+
notes.push(
|
|
793
|
+
`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.`
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
return notes;
|
|
797
|
+
}
|
|
798
|
+
async function landedInvocable(skillsDir, skillsSource, name, dryRun) {
|
|
799
|
+
const read = await readSkillFile(join2(dryRun ? skillsSource : skillsDir, name, "SKILL.md"));
|
|
800
|
+
if (read.kind !== "ok") return false;
|
|
801
|
+
return !isModelInvocationDisabled(read.bytes.toString("utf8"));
|
|
802
|
+
}
|
|
803
|
+
async function assertSkillsLanded(plans, dryRun) {
|
|
804
|
+
if (dryRun) return;
|
|
805
|
+
const missing = [];
|
|
806
|
+
for (const plan of plans) {
|
|
807
|
+
for (const name of SKILL_NAMES) {
|
|
808
|
+
if (!existsSync(join2(plan.skillsDir, name, "SKILL.md"))) {
|
|
809
|
+
missing.push(join2(plan.skillsDir, name));
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (missing.length === 0) return;
|
|
814
|
+
throw new CliError("INTERNAL", `Skills were not written: ${missing.join(", ")}`, {
|
|
815
|
+
// Safe to point at permissions because nothing removes a landed file any more:
|
|
816
|
+
// each shipped file arrives by its own atomic rename. When this was a
|
|
817
|
+
// rm-then-write it also fired on a lost race, and sent people to chmod a
|
|
818
|
+
// directory that was fine.
|
|
819
|
+
fix: `Check that you can write to the skills directory (\`ls -ld ${dirname(missing[0] ?? "")}\`), then re-run \`tenjin install\`.`
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
async function wireAgentsMd(plan, dryRun) {
|
|
823
|
+
const shared = join2(plan.home, ".agents", "AGENTS.md");
|
|
824
|
+
const codex = join2(plan.home, ".codex", "AGENTS.md");
|
|
825
|
+
const line = nudgeLine(plan.skillsDir);
|
|
826
|
+
const probes = /* @__PURE__ */ new Map();
|
|
827
|
+
for (const path of [shared, codex]) {
|
|
828
|
+
const probe = await probeMarkerText(path);
|
|
829
|
+
probes.set(path, probe);
|
|
830
|
+
if (probe.text?.includes(SKILLS_MARKER) === true) {
|
|
831
|
+
return upsertAgentsMd(path, probe, line, dryRun);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
const chosen = chooseAgentsMdPath(plan.home);
|
|
835
|
+
return upsertAgentsMd(chosen, probes.get(chosen), line, dryRun);
|
|
836
|
+
}
|
|
837
|
+
async function upsertAgentsMd(path, probe, line, dryRun) {
|
|
838
|
+
const { content, change } = upsertMarkerLine(probe.text, line);
|
|
839
|
+
if (change === "none") return { path, status: "already-present" };
|
|
840
|
+
const writeTo = await prepareMarkerWrite(path, probe);
|
|
841
|
+
if (!dryRun && content !== null) await writeMarkerFile(path, writeTo, content);
|
|
842
|
+
if (change === "append") return { path, status: dryRun ? "would-append" : "appended" };
|
|
843
|
+
return { path, status: dryRun ? "would-update" : "updated" };
|
|
844
|
+
}
|
|
845
|
+
async function prepareMarkerWrite(declared, probe) {
|
|
846
|
+
assertRegularMarker(declared, probe);
|
|
847
|
+
return resolveThroughLink(declared, "the Tenjin pointer");
|
|
848
|
+
}
|
|
849
|
+
async function probeMarkerText(declared) {
|
|
850
|
+
const read = await readSkillFile(declared);
|
|
851
|
+
if (read.kind === "absent") return { text: null, notRegular: false };
|
|
852
|
+
if (read.kind === "ok") return { text: read.bytes.toString("utf8"), notRegular: false };
|
|
853
|
+
if (read.kind === "not-regular") return { text: null, notRegular: true };
|
|
854
|
+
throw wrapWriteError(read.err, declared, "the Tenjin pointer", declared, {
|
|
855
|
+
verb: "read",
|
|
856
|
+
expected: ": the pointer lands in a regular markdown file"
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
function assertRegularMarker(declared, probe) {
|
|
860
|
+
if (!probe.notRegular) return;
|
|
861
|
+
throw new CliError(
|
|
862
|
+
"INTERNAL",
|
|
863
|
+
`${declared} is not a regular file, so the Tenjin pointer was not written.`,
|
|
864
|
+
{
|
|
865
|
+
fix: `Check what is there (\`ls -l ${declared}\`) and remove or replace it, then re-run \`tenjin install\`.`
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
async function writeMarkerFile(declared, writeTo, content) {
|
|
870
|
+
try {
|
|
871
|
+
await writeFileAtomic(writeTo, content);
|
|
872
|
+
} catch (err) {
|
|
873
|
+
throw wrapWriteError(
|
|
874
|
+
err,
|
|
875
|
+
declared,
|
|
876
|
+
"the Tenjin pointer",
|
|
877
|
+
await deepestExisting(dirname(writeTo)),
|
|
878
|
+
{ expected: ": the pointer lands in a regular markdown file" }
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function chooseAgentsMdPath(home) {
|
|
883
|
+
const shared = join2(home, ".agents", "AGENTS.md");
|
|
884
|
+
const codex = join2(home, ".codex", "AGENTS.md");
|
|
885
|
+
if (existsSync(shared)) return shared;
|
|
886
|
+
if (existsSync(codex)) return codex;
|
|
887
|
+
if (existsSync(join2(home, ".codex"))) return codex;
|
|
888
|
+
return shared;
|
|
889
|
+
}
|
|
890
|
+
function paint(io, format, text) {
|
|
891
|
+
if (io.stdout instanceof Stream) return styleText(format, text, { stream: io.stdout });
|
|
892
|
+
return styleText(format, text);
|
|
893
|
+
}
|
|
894
|
+
async function assertSkillsSource(dir) {
|
|
895
|
+
for (const name of SKILL_NAMES) {
|
|
896
|
+
if (!existsSync(join2(dir, name, "SKILL.md"))) {
|
|
897
|
+
throw new CliError("INTERNAL", `Packaged skill "${name}" is missing under ${dir}`, {
|
|
898
|
+
fix: "Reinstall tenjin-cli; the published package must ship every skill under skills/."
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
for (const name of CLI_SKILL_NAMES) {
|
|
903
|
+
const text = await readFile2(join2(dir, name, "SKILL.md"), "utf8");
|
|
904
|
+
if (isModelInvocationDisabled(text)) {
|
|
905
|
+
throw new CliError(
|
|
906
|
+
"INTERNAL",
|
|
907
|
+
`Packaged skill "${name}" carries disable-model-invocation: true, so no harness would surface it`,
|
|
908
|
+
{
|
|
909
|
+
fix: "Reinstall tenjin-cli; the published CLI skills must be model-invocable."
|
|
910
|
+
}
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
export {
|
|
916
|
+
PERMISSIONS_QUESTION,
|
|
917
|
+
PUBLISH_MODE_CHOICES,
|
|
918
|
+
PUBLISH_MODE_QUESTION,
|
|
919
|
+
WALLET_QUESTION,
|
|
920
|
+
runInstall
|
|
921
|
+
};
|
|
922
|
+
//# sourceMappingURL=install-BMMUPFOK.js.map
|