tenjin-cli 0.1.0-alpha.27 → 0.1.0-alpha.28
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 +6 -17
- package/dist/alive-3J3CHOQP.js +21 -0
- package/dist/{chunk-SKQQOEWH.js → chunk-3QJREVMX.js} +5 -7
- package/dist/{chunk-SKQQOEWH.js.map → chunk-3QJREVMX.js.map} +1 -1
- package/dist/{chunk-BOAI23CX.js → chunk-6KA4HFX5.js} +21 -15
- package/dist/chunk-6KA4HFX5.js.map +1 -0
- package/dist/chunk-6W5GYG3W.js +128 -0
- package/dist/chunk-6W5GYG3W.js.map +1 -0
- package/dist/{chunk-4L7KMA7P.js → chunk-7H3RN4WJ.js} +7 -9
- package/dist/{chunk-4L7KMA7P.js.map → chunk-7H3RN4WJ.js.map} +1 -1
- package/dist/{chunk-O7CUHHYU.js → chunk-7R37M6WV.js} +7 -9
- package/dist/{chunk-O7CUHHYU.js.map → chunk-7R37M6WV.js.map} +1 -1
- package/dist/{chunk-LAIZ2AQA.js → chunk-A5H3E5QA.js} +2 -2
- package/dist/{update-RJDA5ZY3.js → chunk-AO54FM4H.js} +147 -26
- package/dist/chunk-AO54FM4H.js.map +1 -0
- package/dist/{chunk-VNNXAYJE.js → chunk-BRHREK7E.js} +2 -2
- package/dist/{chunk-YQOQ6XEI.js → chunk-DJYAPACT.js} +35 -33
- package/dist/chunk-DJYAPACT.js.map +1 -0
- package/dist/{chunk-GU4GGKYP.js → chunk-DYSDQE7S.js} +36 -2
- package/dist/chunk-DYSDQE7S.js.map +1 -0
- package/dist/{chunk-YKM2ZTA2.js → chunk-FQ6DHINU.js} +36 -38
- package/dist/{chunk-YKM2ZTA2.js.map → chunk-FQ6DHINU.js.map} +1 -1
- package/dist/{chunk-6ZSGER3A.js → chunk-FZTSGQVK.js} +2 -2
- package/dist/{chunk-AWKQSKUL.js → chunk-KAMRYUK2.js} +2 -2
- package/dist/{chunk-2TYQD22Q.js → chunk-MNTQMZJB.js} +6 -8
- package/dist/{chunk-2TYQD22Q.js.map → chunk-MNTQMZJB.js.map} +1 -1
- package/dist/{chunk-VIOUZW7Z.js → chunk-QTND6XWJ.js} +159 -35
- package/dist/chunk-QTND6XWJ.js.map +1 -0
- package/dist/chunk-RLPLYUME.js +115 -0
- package/dist/{chunk-HC3QEZKT.js.map → chunk-RLPLYUME.js.map} +1 -1
- package/dist/{chunk-5NEHH2E5.js → chunk-UEOWNDQG.js} +8 -10
- package/dist/{chunk-5NEHH2E5.js.map → chunk-UEOWNDQG.js.map} +1 -1
- package/dist/{chunk-OHZYNZSD.js → chunk-UOW5JXYY.js} +5 -7
- package/dist/{chunk-OHZYNZSD.js.map → chunk-UOW5JXYY.js.map} +1 -1
- package/dist/chunk-VSUHGRVB.js +1455 -0
- package/dist/chunk-VSUHGRVB.js.map +1 -0
- package/dist/{chunk-64SE3QC5.js → chunk-W6JX4LYF.js} +12 -4
- package/dist/chunk-W6JX4LYF.js.map +1 -0
- package/dist/{chunk-5FGO6TYT.js → chunk-XVTD7UWR.js} +3 -5
- package/dist/{chunk-5FGO6TYT.js.map → chunk-XVTD7UWR.js.map} +1 -1
- package/dist/{chunk-X7I343ZY.js → chunk-YFJJYHVG.js} +2 -2
- package/dist/{chunk-XVYATBKD.js → chunk-ZG6ZZLO7.js} +898 -521
- package/dist/chunk-ZG6ZZLO7.js.map +1 -0
- package/dist/{chunk-DATCR7AU.js → chunk-ZO3X5NPG.js} +4 -6
- package/dist/{chunk-DATCR7AU.js.map → chunk-ZO3X5NPG.js.map} +1 -1
- package/dist/{chunk-VXIBZ6W5.js → chunk-ZP5PV3JB.js} +3 -3
- package/dist/{chunk-G4AM2SOL.js → chunk-ZP7AHN7Z.js} +4 -6
- package/dist/{chunk-G4AM2SOL.js.map → chunk-ZP7AHN7Z.js.map} +1 -1
- package/dist/{cli-6JNIPZQ6.js → cli-234DNHN6.js} +54 -53
- package/dist/{cli-6JNIPZQ6.js.map → cli-234DNHN6.js.map} +1 -1
- package/dist/{config-G75YT6NC.js → config-IY2OJCAK.js} +10 -13
- package/dist/{doctor-3GMDOW4Y.js → doctor-2UZZF44A.js} +267 -242
- package/dist/doctor-2UZZF44A.js.map +1 -0
- package/dist/{fund-3IPR5YRJ.js → fund-RZ2QFULK.js} +92 -38
- package/dist/{fund-3IPR5YRJ.js.map → fund-RZ2QFULK.js.map} +1 -1
- package/dist/hook-command-PZHKS7ES.js +31 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +14 -0
- package/dist/hosts/claude/tenjin/.mcp.json +11 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +206 -0
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/install-O5FJ5EP3.js +48 -0
- package/dist/{install-identity-PM4AGFFX.js → install-identity-QM44IQ6Z.js} +7 -8
- package/dist/{install-wallet-6756NOB5.js → install-wallet-Z52EDLPB.js} +14 -15
- package/dist/{install-wallet-6756NOB5.js.map → install-wallet-Z52EDLPB.js.map} +1 -1
- package/dist/{mcp-33FAAZ7F.js → mcp-33HAADDF.js} +80 -67
- package/dist/{mcp-33FAAZ7F.js.map → mcp-33HAADDF.js.map} +1 -1
- package/dist/package-RT24HTTP.js +37 -0
- package/dist/{pay-XOYR4PCH.js → pay-IR2V76FX.js} +16 -17
- package/dist/{payments-UTQDBO7H.js → payments-GFV4HU5R.js} +9 -10
- package/dist/{payments-UTQDBO7H.js.map → payments-GFV4HU5R.js.map} +1 -1
- package/dist/{send-CVGNOQW3.js → send-PI4NUA7I.js} +12 -14
- package/dist/{send-CVGNOQW3.js.map → send-PI4NUA7I.js.map} +1 -1
- package/dist/{status-NACN4DGX.js → status-ZUHTJK46.js} +6 -7
- package/dist/{status-NACN4DGX.js.map → status-ZUHTJK46.js.map} +1 -1
- package/dist/{status-line-3IQKGRUH.js → status-line-2G5JPQAE.js} +6 -7
- package/dist/{status-line-3IQKGRUH.js.map → status-line-2G5JPQAE.js.map} +1 -1
- package/dist/uninstall-THKUH5ZT.js +136 -0
- package/dist/uninstall-THKUH5ZT.js.map +1 -0
- package/dist/update-NPZDP24E.js +18 -0
- package/dist/update-NPZDP24E.js.map +1 -0
- package/dist/{wallet-B3FVHNTS.js → wallet-53EFH4M5.js} +11 -12
- package/dist/wallet-53EFH4M5.js.map +1 -0
- package/docs/agent-permissions.md +27 -17
- package/package.json +1 -1
- package/dist/chunk-64SE3QC5.js.map +0 -1
- package/dist/chunk-BOAI23CX.js.map +0 -1
- package/dist/chunk-DSNXKUXI.js +0 -172
- package/dist/chunk-DSNXKUXI.js.map +0 -1
- package/dist/chunk-GU4GGKYP.js.map +0 -1
- package/dist/chunk-H2L33M7F.js +0 -944
- package/dist/chunk-H2L33M7F.js.map +0 -1
- package/dist/chunk-HC3QEZKT.js +0 -87
- package/dist/chunk-JLEF5WHM.js +0 -132
- package/dist/chunk-JLEF5WHM.js.map +0 -1
- package/dist/chunk-MAQUL5BD.js +0 -99
- package/dist/chunk-MAQUL5BD.js.map +0 -1
- package/dist/chunk-PY7MQUKP.js +0 -755
- package/dist/chunk-PY7MQUKP.js.map +0 -1
- package/dist/chunk-TGLKKLQG.js +0 -11
- package/dist/chunk-TGLKKLQG.js.map +0 -1
- package/dist/chunk-VIOUZW7Z.js.map +0 -1
- package/dist/chunk-XVYATBKD.js.map +0 -1
- package/dist/chunk-YQOQ6XEI.js.map +0 -1
- package/dist/doctor-3GMDOW4Y.js.map +0 -1
- package/dist/hook-command-ZXX4FT4N.js +0 -32
- package/dist/install-6OROTYHZ.js +0 -72
- package/dist/status-line-wiring-QXBOOY2T.js +0 -31
- package/dist/uninstall-NYFKSYW4.js +0 -175
- package/dist/uninstall-NYFKSYW4.js.map +0 -1
- package/dist/update-RJDA5ZY3.js.map +0 -1
- /package/dist/{config-G75YT6NC.js.map → alive-3J3CHOQP.js.map} +0 -0
- /package/dist/{chunk-LAIZ2AQA.js.map → chunk-A5H3E5QA.js.map} +0 -0
- /package/dist/{chunk-VNNXAYJE.js.map → chunk-BRHREK7E.js.map} +0 -0
- /package/dist/{chunk-6ZSGER3A.js.map → chunk-FZTSGQVK.js.map} +0 -0
- /package/dist/{chunk-AWKQSKUL.js.map → chunk-KAMRYUK2.js.map} +0 -0
- /package/dist/{chunk-X7I343ZY.js.map → chunk-YFJJYHVG.js.map} +0 -0
- /package/dist/{chunk-VXIBZ6W5.js.map → chunk-ZP5PV3JB.js.map} +0 -0
- /package/dist/{hook-command-ZXX4FT4N.js.map → config-IY2OJCAK.js.map} +0 -0
- /package/dist/{install-6OROTYHZ.js.map → hook-command-PZHKS7ES.js.map} +0 -0
- /package/dist/{install-identity-PM4AGFFX.js.map → install-O5FJ5EP3.js.map} +0 -0
- /package/dist/{pay-XOYR4PCH.js.map → install-identity-QM44IQ6Z.js.map} +0 -0
- /package/dist/{status-line-wiring-QXBOOY2T.js.map → package-RT24HTTP.js.map} +0 -0
- /package/dist/{wallet-B3FVHNTS.js.map → pay-IR2V76FX.js.map} +0 -0
package/dist/chunk-PY7MQUKP.js
DELETED
|
@@ -1,755 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
ROUTER_PATH
|
|
4
|
-
} from "./chunk-64SE3QC5.js";
|
|
5
|
-
import {
|
|
6
|
-
RECONNECT_FIX,
|
|
7
|
-
readMcpServers
|
|
8
|
-
} from "./chunk-MAQUL5BD.js";
|
|
9
|
-
import {
|
|
10
|
-
ensureStatusLine
|
|
11
|
-
} from "./chunk-DSNXKUXI.js";
|
|
12
|
-
import {
|
|
13
|
-
envProxySupported,
|
|
14
|
-
proxyVariable
|
|
15
|
-
} from "./chunk-S4SAZ7OD.js";
|
|
16
|
-
import {
|
|
17
|
-
httpRequest
|
|
18
|
-
} from "./chunk-OHZYNZSD.js";
|
|
19
|
-
import {
|
|
20
|
-
CLI_SKILL_NAMES,
|
|
21
|
-
RETIRED_SKILL_NAMES,
|
|
22
|
-
SHIPPED_SKILL_FILES,
|
|
23
|
-
onPath,
|
|
24
|
-
persistRouterDefaults,
|
|
25
|
-
readSkillFile,
|
|
26
|
-
skillFrontmatterName,
|
|
27
|
-
skillsDirsFor
|
|
28
|
-
} from "./chunk-H2L33M7F.js";
|
|
29
|
-
import {
|
|
30
|
-
FEE_APPROVAL,
|
|
31
|
-
OWN_LIMITS_COMMANDS,
|
|
32
|
-
ROUTER_DEFAULTS,
|
|
33
|
-
ROUTING_FEE_TERMS,
|
|
34
|
-
limitsUsd,
|
|
35
|
-
shownLimits,
|
|
36
|
-
spendQuestion
|
|
37
|
-
} from "./chunk-GU4GGKYP.js";
|
|
38
|
-
import {
|
|
39
|
-
appendAllowlistRules,
|
|
40
|
-
claudeAdapter,
|
|
41
|
-
claudeSettingsPath,
|
|
42
|
-
inspectHooksFile,
|
|
43
|
-
ownsHookEntry,
|
|
44
|
-
writeHooks
|
|
45
|
-
} from "./chunk-XVYATBKD.js";
|
|
46
|
-
import {
|
|
47
|
-
HOOK_TOOL,
|
|
48
|
-
hookToolInput
|
|
49
|
-
} from "./chunk-AKWGE6JQ.js";
|
|
50
|
-
import {
|
|
51
|
-
MCP_SERVER_NAME,
|
|
52
|
-
REQUEST_TOOL
|
|
53
|
-
} from "./chunk-TGLKKLQG.js";
|
|
54
|
-
import {
|
|
55
|
-
askText,
|
|
56
|
-
selectOne
|
|
57
|
-
} from "./chunk-P7LABKCW.js";
|
|
58
|
-
import {
|
|
59
|
-
paint
|
|
60
|
-
} from "./chunk-5FGO6TYT.js";
|
|
61
|
-
import {
|
|
62
|
-
hasCode
|
|
63
|
-
} from "./chunk-2I4QTOLB.js";
|
|
64
|
-
import {
|
|
65
|
-
resolveContextSettings
|
|
66
|
-
} from "./chunk-G4AM2SOL.js";
|
|
67
|
-
import {
|
|
68
|
-
parseUsdToAtomic,
|
|
69
|
-
toMoney
|
|
70
|
-
} from "./chunk-6ZSGER3A.js";
|
|
71
|
-
import {
|
|
72
|
-
PRODUCTION_ORIGIN,
|
|
73
|
-
isSameDeployment,
|
|
74
|
-
loadRawConfig
|
|
75
|
-
} from "./chunk-VIOUZW7Z.js";
|
|
76
|
-
import {
|
|
77
|
-
CliError
|
|
78
|
-
} from "./chunk-JLEF5WHM.js";
|
|
79
|
-
|
|
80
|
-
// src/router/install.ts
|
|
81
|
-
import { execFile } from "node:child_process";
|
|
82
|
-
import { readFile, realpath } from "node:fs/promises";
|
|
83
|
-
import { homedir } from "node:os";
|
|
84
|
-
import { isAbsolute, join as join2 } from "node:path";
|
|
85
|
-
import { promisify } from "node:util";
|
|
86
|
-
|
|
87
|
-
// src/lib/skill-placement.ts
|
|
88
|
-
import { lstatSync } from "node:fs";
|
|
89
|
-
import { readdir, rm, rmdir } from "node:fs/promises";
|
|
90
|
-
import { dirname, join } from "node:path";
|
|
91
|
-
function isRealDirectory(path) {
|
|
92
|
-
try {
|
|
93
|
-
return lstatSync(path, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
94
|
-
} catch (err) {
|
|
95
|
-
if (hasCode(err, "ENOENT") || hasCode(err, "ENOTDIR")) return false;
|
|
96
|
-
throw err;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function removeOwnedSkill(name, skillsDir) {
|
|
100
|
-
if (!isRealDirectory(skillsDir)) {
|
|
101
|
-
return { changed: false };
|
|
102
|
-
}
|
|
103
|
-
const skillDir = join(skillsDir, name);
|
|
104
|
-
if (!isRealDirectory(skillDir)) {
|
|
105
|
-
return { changed: false };
|
|
106
|
-
}
|
|
107
|
-
const path = join(skillDir, "SKILL.md");
|
|
108
|
-
const read = await readSkillFile(path);
|
|
109
|
-
if (read.kind === "absent") return { changed: false };
|
|
110
|
-
if (read.kind !== "ok" || skillFrontmatterName(read.bytes.toString("utf8")) !== name) {
|
|
111
|
-
return { changed: false };
|
|
112
|
-
}
|
|
113
|
-
const shipped = SHIPPED_SKILL_FILES[name] ?? [];
|
|
114
|
-
const subdirs = /* @__PURE__ */ new Set();
|
|
115
|
-
for (const rel of shipped) {
|
|
116
|
-
if (rel === "SKILL.md") continue;
|
|
117
|
-
const file = join(skillDir, rel);
|
|
118
|
-
if (!isRealDirectory(dirname(file))) continue;
|
|
119
|
-
subdirs.add(dirname(file));
|
|
120
|
-
if (lstatSync(file, { throwIfNoEntry: false })?.isFile() === true) await rm(file);
|
|
121
|
-
}
|
|
122
|
-
await rm(path, { force: true });
|
|
123
|
-
for (const dir of [...subdirs, skillDir].sort((a, b) => b.length - a.length)) {
|
|
124
|
-
const rest = await readdir(dir).catch(() => null);
|
|
125
|
-
if (rest !== null && rest.length === 0) await rmdir(dir).catch(() => void 0);
|
|
126
|
-
}
|
|
127
|
-
return { changed: true };
|
|
128
|
-
}
|
|
129
|
-
async function removeRetiredSkills(home, project) {
|
|
130
|
-
const removed = [];
|
|
131
|
-
const dirs = [...skillsDirsFor(home), ...project ? skillsDirsFor(project) : []];
|
|
132
|
-
for (const dir of new Set(dirs)) {
|
|
133
|
-
for (const name of [...RETIRED_SKILL_NAMES, ...CLI_SKILL_NAMES]) {
|
|
134
|
-
if ((await removeOwnedSkill(name, dir)).changed) removed.push(join(dir, name));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return removed;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// src/router/reachability.ts
|
|
141
|
-
async function probeRouter(baseUrl, opts) {
|
|
142
|
-
const fail = (detail, fix) => ({
|
|
143
|
-
name: "router",
|
|
144
|
-
status: "fail",
|
|
145
|
-
required: true,
|
|
146
|
-
detail,
|
|
147
|
-
fix
|
|
148
|
-
});
|
|
149
|
-
let url;
|
|
150
|
-
try {
|
|
151
|
-
url = new URL(ROUTER_PATH, baseUrl).toString();
|
|
152
|
-
} catch {
|
|
153
|
-
return fail(
|
|
154
|
-
`the base URL ${JSON.stringify(baseUrl)} is not a URL`,
|
|
155
|
-
`Check TENJIN_BASE_URL, or set it with \`tenjin config set baseUrl ${PRODUCTION_ORIGIN}\`.`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
const host = new URL(url).host;
|
|
159
|
-
const probe = await httpRequest(url, {
|
|
160
|
-
method: "POST",
|
|
161
|
-
timeoutMs: opts.timeoutMs,
|
|
162
|
-
blockRedirects: true,
|
|
163
|
-
// A reachability check, not use: it must not count this machine as an install.
|
|
164
|
-
anonymous: true,
|
|
165
|
-
jsonBody: {},
|
|
166
|
-
...opts.fetchImpl !== void 0 ? { fetchImpl: opts.fetchImpl } : {}
|
|
167
|
-
});
|
|
168
|
-
const production = isSameDeployment(new URL(url).origin, PRODUCTION_ORIGIN);
|
|
169
|
-
const checkBase = production ? "Try again later." : "Check that the configured base URL names the Tenjin router (`tenjin config get baseUrl`), then try again later.";
|
|
170
|
-
const env = opts.env ?? process.env;
|
|
171
|
-
const network = networkFix(host, env, production, opts.proxySupported ?? envProxySupported());
|
|
172
|
-
const credentials = proxyCredentialsFix(env);
|
|
173
|
-
const unreached = production ? network : checkBase;
|
|
174
|
-
if (!probe.ok) {
|
|
175
|
-
const t = probe.transport;
|
|
176
|
-
if (t?.layer === "proxy" && t.proxyStatus === 407) {
|
|
177
|
-
return fail(
|
|
178
|
-
`a proxy between this machine and ${host} asked for its own credentials (407)`,
|
|
179
|
-
credentials
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
if (t?.layer === "proxy") {
|
|
183
|
-
return fail(
|
|
184
|
-
`a proxy refused the connection to ${host} (${t.proxyStatus}), so the router never answered`,
|
|
185
|
-
unreached
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
if (t?.layer === "dns") {
|
|
189
|
-
return fail(`${host} did not resolve (${t.code}), so the router was not reached`, unreached);
|
|
190
|
-
}
|
|
191
|
-
if (t?.layer === "tls") {
|
|
192
|
-
return fail(
|
|
193
|
-
`the TLS connection to ${host} failed (${t.code}). A proxy that inspects TLS causes this`,
|
|
194
|
-
`If this network inspects TLS, set NODE_EXTRA_CA_CERTS to its CA certificate. ${unreached}`
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
if (t?.layer === "connect") {
|
|
198
|
-
return fail(`could not connect to ${host} (${t.code})`, unreached);
|
|
199
|
-
}
|
|
200
|
-
return fail(`the router at ${url} is unreachable or erroring (${probe.message})`, unreached);
|
|
201
|
-
}
|
|
202
|
-
if (probe.status === 200 || probe.status === 400 || probe.status === 429) {
|
|
203
|
-
return { name: "router", status: "ok", required: true, detail: `${url} is live` };
|
|
204
|
-
}
|
|
205
|
-
if (probe.status === 404) {
|
|
206
|
-
return fail(`the router is not enabled at ${url}`, checkBase);
|
|
207
|
-
}
|
|
208
|
-
if (probe.status === 407) {
|
|
209
|
-
return fail(
|
|
210
|
-
`a proxy between this machine and ${host} asked for its own credentials (407)`,
|
|
211
|
-
credentials
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
if (probe.status === 401 || probe.status === 403) {
|
|
215
|
-
if (!fromDeployment(probe)) {
|
|
216
|
-
return fail(
|
|
217
|
-
`${host} answered ${probe.status} without the headers a Tenjin deployment sends, so a proxy, firewall or VPN on the way most likely refused the request`,
|
|
218
|
-
network
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
if (production) {
|
|
222
|
-
return fail(`${url} refused this machine (${probe.status})`, checkBase);
|
|
223
|
-
}
|
|
224
|
-
return fail(
|
|
225
|
-
`${url} is not a Tenjin router (it asked for credentials)`,
|
|
226
|
-
`Set the router URL with \`tenjin config set baseUrl ${PRODUCTION_ORIGIN}\`.`
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
if (probe.status >= 500) {
|
|
230
|
-
return fail(`the router at ${url} is unreachable or erroring (${probe.status})`, checkBase);
|
|
231
|
-
}
|
|
232
|
-
return fail(
|
|
233
|
-
`${url} answered ${probe.status}, which a Tenjin router does not`,
|
|
234
|
-
"Check that the configured base URL names a Tenjin deployment (`tenjin config get baseUrl`)."
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
function fromDeployment(probe) {
|
|
238
|
-
return probe.header("x-vercel-id") !== void 0 || probe.header("x-request-id") !== void 0;
|
|
239
|
-
}
|
|
240
|
-
function networkFix(host, env, production, proxySupported) {
|
|
241
|
-
const proxy = proxyVariable(env);
|
|
242
|
-
const config = production ? " Tenjin's own config is correct and needs no change." : "";
|
|
243
|
-
if (proxy !== void 0 && !proxySupported) {
|
|
244
|
-
return `This shell sets ${proxy}, but Node ${process.versions.node} cannot send Tenjin's requests through it. Upgrade to Node 24.14 or newer, or run from a network that reaches ${host} directly.${config}`;
|
|
245
|
-
}
|
|
246
|
-
const via = proxy !== void 0 ? ` (this shell sets ${proxy})` : "";
|
|
247
|
-
return `Allow ${host} through your proxy, firewall or VPN${via}, or run from a network that reaches it.${config}`;
|
|
248
|
-
}
|
|
249
|
-
function proxyCredentialsFix(env) {
|
|
250
|
-
const proxy = proxyVariable(env) ?? "HTTPS_PROXY";
|
|
251
|
-
return `Put the proxy's credentials in ${proxy} (\`http://user:password@proxy:port\`), then try again.`;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// src/router/install.ts
|
|
255
|
-
var exec = promisify(execFile);
|
|
256
|
-
var ROUTE_HOOK_TIMEOUT_SECONDS = 5;
|
|
257
|
-
var AFTER_CALL_TIMEOUT_SECONDS = 15;
|
|
258
|
-
var ALLOW_RULE = REQUEST_TOOL;
|
|
259
|
-
var DENY_RULE = `mcp__${MCP_SERVER_NAME}__${HOOK_TOOL}`;
|
|
260
|
-
function mcpScope(project) {
|
|
261
|
-
return project === true ? "project" : "user";
|
|
262
|
-
}
|
|
263
|
-
function mcpAddCommand(project) {
|
|
264
|
-
return `claude mcp add ${MCP_SERVER_NAME} -s ${mcpScope(project)} -- tenjin mcp`;
|
|
265
|
-
}
|
|
266
|
-
function mcpRemoveCommand(project) {
|
|
267
|
-
return `claude mcp remove ${MCP_SERVER_NAME} -s ${mcpScope(project)}`;
|
|
268
|
-
}
|
|
269
|
-
var MCP_ADD_COMMAND = mcpAddCommand();
|
|
270
|
-
function routerSettingsPath(opts = {}) {
|
|
271
|
-
if (opts.project === true) return join2(opts.cwd ?? process.cwd(), ".claude", "settings.json");
|
|
272
|
-
return claudeSettingsPath(opts.homeDir ?? homedir());
|
|
273
|
-
}
|
|
274
|
-
var DELEGATION_MATCHER = "Agent|Task";
|
|
275
|
-
var NATIVE_MATCHER = "WebSearch|WebFetch";
|
|
276
|
-
var ASK_MATCHER = "AskUserQuestion";
|
|
277
|
-
function routerHookPlan() {
|
|
278
|
-
const leg = (kind, timeout = ROUTE_HOOK_TIMEOUT_SECONDS) => [
|
|
279
|
-
{
|
|
280
|
-
type: "mcp_tool",
|
|
281
|
-
server: MCP_SERVER_NAME,
|
|
282
|
-
tool: HOOK_TOOL,
|
|
283
|
-
input: hookToolInput(kind),
|
|
284
|
-
timeout
|
|
285
|
-
}
|
|
286
|
-
];
|
|
287
|
-
const afterCall = () => leg("shortfall", AFTER_CALL_TIMEOUT_SECONDS);
|
|
288
|
-
return [
|
|
289
|
-
{ event: "UserPromptSubmit", hooks: leg("prompt") },
|
|
290
|
-
{ event: "PreToolUse", matcher: NATIVE_MATCHER, hooks: leg("native") },
|
|
291
|
-
{ event: "PreToolUse", matcher: DELEGATION_MATCHER, hooks: leg("agent") },
|
|
292
|
-
{ event: "PostToolUse", matcher: NATIVE_MATCHER, hooks: afterCall() },
|
|
293
|
-
{ event: "PostToolUseFailure", matcher: NATIVE_MATCHER, hooks: afterCall() },
|
|
294
|
-
{ event: "PreToolUse", matcher: ASK_MATCHER, hooks: leg("ask") },
|
|
295
|
-
{ event: "PostToolUse", matcher: ASK_MATCHER, hooks: leg("answer") }
|
|
296
|
-
];
|
|
297
|
-
}
|
|
298
|
-
var DISCLOSURE = [
|
|
299
|
-
"What leaves this machine: the bounded text of each prompt, each native search query or URL (and, when one came back short, its status, size or error), each task handed to a subagent, and each question your assistant asks you with your answers, sent to Tenjin for the free routing gate, beside this session's id. When the gate offers free library docs for a search, that search query also goes to Tenjin's docs lookup, which asks Context7.",
|
|
300
|
-
"What is kept when a lookup is paid: the capability chosen, a hash of the contract, a hash of the arguments, and your wallet address. No prompt text, no arguments, no hint text.",
|
|
301
|
-
"What never leaves: your private key. It is decrypted in this CLI to sign, and never sent anywhere."
|
|
302
|
-
];
|
|
303
|
-
async function inferRefreshProject(cwd, home, dataDir, readRegistration) {
|
|
304
|
-
const hooks = await probeOurEntries(routerSettingsPath({ project: true, cwd }), dataDir);
|
|
305
|
-
if (hooks.state !== "present") return false;
|
|
306
|
-
const [cwdPath, homePath] = await Promise.all([
|
|
307
|
-
realpath(cwd),
|
|
308
|
-
realpath(home).catch((err) => {
|
|
309
|
-
if (err.code === "ENOENT" || err.code === "ENOTDIR") return null;
|
|
310
|
-
throw err;
|
|
311
|
-
})
|
|
312
|
-
]);
|
|
313
|
-
if (cwdPath !== homePath) return true;
|
|
314
|
-
const user = await readRegistration("user", cwd, home);
|
|
315
|
-
if (user.state !== "absent") return false;
|
|
316
|
-
const project = await readRegistration("project", cwd, home);
|
|
317
|
-
return project.state !== "absent";
|
|
318
|
-
}
|
|
319
|
-
async function runRouterInstall(args, ctx, deps = {}) {
|
|
320
|
-
const env = deps.env ?? process.env;
|
|
321
|
-
const home = deps.homeDir ?? homedir();
|
|
322
|
-
if (!isAbsolute(home)) {
|
|
323
|
-
throw new CliError("INTERNAL", "The home directory is not an absolute path.", {
|
|
324
|
-
fix: "Set HOME to your home directory (`export HOME=...`), then re-run `tenjin install`."
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
const config = await loadRawConfig(ctx.dataDir);
|
|
328
|
-
const cwd = deps.cwd ?? process.cwd();
|
|
329
|
-
const project = args.project ?? (args.refresh === true && await inferRefreshProject(cwd, home, ctx.dataDir, deps.readMcpEntry ?? readMcpEntry));
|
|
330
|
-
const settingsPath = routerSettingsPath({
|
|
331
|
-
...project ? { project: true } : {},
|
|
332
|
-
homeDir: home,
|
|
333
|
-
cwd
|
|
334
|
-
});
|
|
335
|
-
if (args.refresh === true) {
|
|
336
|
-
const probe = await probeOurEntries(settingsPath, ctx.dataDir);
|
|
337
|
-
if (probe.state === "unreadable") {
|
|
338
|
-
throw new CliError("CONFIG_INVALID", `Could not inspect ${settingsPath}: ${probe.reason}`, {
|
|
339
|
-
fix: `Fix ${settingsPath}, then re-run: tenjin update`
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
if (probe.state === "absent") {
|
|
343
|
-
throw new CliError(
|
|
344
|
-
"REFUSED",
|
|
345
|
-
`Nothing to refresh in ${settingsPath}: no Tenjin hook entries are registered here.`,
|
|
346
|
-
{ fix: "Run `tenjin install` to set this machine up." }
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
const humanOutput = ctx.flags.json === true ? false : deps.isInteractive ?? ctx.io.isTTY;
|
|
351
|
-
const canPrompt = humanOutput && (deps.isInteractive ?? Boolean(process.stdin.isTTY));
|
|
352
|
-
const limits = args.refresh === true ? void 0 : args.yes === true ? shownLimits(config) : canPrompt ? await approveLimits(config, deps) : {};
|
|
353
|
-
const spend = await persistRouterDefaults(ctx.dataDir, args.refresh === true, limits);
|
|
354
|
-
const removedKeysLines = spend.removed.length > 0 ? [
|
|
355
|
-
`Removed retired settings: ${spend.removed.join(", ")}. Automatic router limits remain in effect; manual pay always requires consent.`
|
|
356
|
-
] : [];
|
|
357
|
-
const removedSkills = await removeRetiredSkills(home, project ? cwd : void 0);
|
|
358
|
-
const hooks = await writeHooks({
|
|
359
|
-
adapter: claudeAdapter,
|
|
360
|
-
homeDir: home,
|
|
361
|
-
dataDir: ctx.dataDir,
|
|
362
|
-
env,
|
|
363
|
-
plan: routerHookPlan(),
|
|
364
|
-
settingsPath
|
|
365
|
-
});
|
|
366
|
-
const permissions = await ensurePermissionRules(settingsPath);
|
|
367
|
-
const statusLine = await ensureStatusLine(settingsPath, {
|
|
368
|
-
...args.statusLine !== void 0 ? { mode: args.statusLine } : {},
|
|
369
|
-
...args.refresh === true ? { refreshOnly: true } : {}
|
|
370
|
-
});
|
|
371
|
-
const mcp = await registerMcpServer(deps, env, project, cwd, home);
|
|
372
|
-
const servers = await readMcpServers(deps);
|
|
373
|
-
const serverLines = servers.stale > 0 ? [paint(ctx.io, "yellow", `! ${servers.check.detail}. ${RECONNECT_FIX}`)] : [];
|
|
374
|
-
if (args.refresh === true) {
|
|
375
|
-
if (mcp.reconciled === "unrepaired") {
|
|
376
|
-
throw new CliError(
|
|
377
|
-
"REFUSED",
|
|
378
|
-
`The ${MCP_SERVER_NAME} MCP registration (${mcpScope(project)} scope) is not the router's and this run could not repair it: ${mcp.reason ?? "unknown reason"}.`,
|
|
379
|
-
{ fix: `Run: ${mcp.command}`, details: { settingsPath, hooks, permissions, mcp } }
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
return {
|
|
383
|
-
data: {
|
|
384
|
-
settingsPath,
|
|
385
|
-
hooks,
|
|
386
|
-
permissions,
|
|
387
|
-
statusLine,
|
|
388
|
-
mcp,
|
|
389
|
-
refresh: true,
|
|
390
|
-
spend,
|
|
391
|
-
removedSkills,
|
|
392
|
-
scope: mcpScope(project),
|
|
393
|
-
mcpServer: servers.check
|
|
394
|
-
},
|
|
395
|
-
humanLines: [
|
|
396
|
-
...refreshLines(ctx, problems(ctx, hooks, permissions, statusLine, mcp)),
|
|
397
|
-
...removedKeysLines,
|
|
398
|
-
...serverLines
|
|
399
|
-
]
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
const { resolveWallet } = await import("./install-wallet-6756NOB5.js");
|
|
403
|
-
const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? "flag" : void 0, false);
|
|
404
|
-
const effective = await resolveContextSettings(ctx);
|
|
405
|
-
const approval = !canPrompt && args.yes !== true && !spend.kept.includes("maxAutoSpend") ? spendApproval(config, args) : void 0;
|
|
406
|
-
const router = await probeRouter(effective.baseUrl, {
|
|
407
|
-
timeoutMs: ctx.flags.timeout,
|
|
408
|
-
env,
|
|
409
|
-
...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
|
|
410
|
-
});
|
|
411
|
-
const data = {
|
|
412
|
-
settingsPath,
|
|
413
|
-
hooks,
|
|
414
|
-
permissions,
|
|
415
|
-
statusLine,
|
|
416
|
-
spend: {
|
|
417
|
-
...spend,
|
|
418
|
-
effective: effectiveLimits(effective.policy),
|
|
419
|
-
...approval !== void 0 ? { approval } : {}
|
|
420
|
-
},
|
|
421
|
-
mcp,
|
|
422
|
-
wallet,
|
|
423
|
-
router: {
|
|
424
|
-
status: router.status === "ok" ? "ok" : "warn",
|
|
425
|
-
detail: router.detail,
|
|
426
|
-
...router.fix !== void 0 ? { fix: router.fix } : {}
|
|
427
|
-
},
|
|
428
|
-
disclosure: DISCLOSURE,
|
|
429
|
-
removedSkills,
|
|
430
|
-
mcpServer: servers.check
|
|
431
|
-
};
|
|
432
|
-
return {
|
|
433
|
-
data,
|
|
434
|
-
humanLines: [
|
|
435
|
-
...lines(ctx, {
|
|
436
|
-
project,
|
|
437
|
-
hooks,
|
|
438
|
-
permissions,
|
|
439
|
-
statusLine,
|
|
440
|
-
mcp,
|
|
441
|
-
wallet,
|
|
442
|
-
policy: effective.policy,
|
|
443
|
-
...approval !== void 0 ? { approval } : {},
|
|
444
|
-
router
|
|
445
|
-
}),
|
|
446
|
-
...removedKeysLines,
|
|
447
|
-
...serverLines
|
|
448
|
-
]
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
var AUTO_SPEND_FIX = `tenjin config set maxAutoSpend ${toMoney(ROUTER_DEFAULTS.maxAutoSpend).usd}`;
|
|
452
|
-
var DECLINED = "the router then pays for nothing on its own, and the question stays open until `tenjin install` in a terminal or `tenjin config set` answers it";
|
|
453
|
-
function spendApproval(config, args) {
|
|
454
|
-
const limits = shownLimits(config);
|
|
455
|
-
const approve = yesCommand(args);
|
|
456
|
-
return {
|
|
457
|
-
question: spendQuestion(limits),
|
|
458
|
-
limits: limitsUsd(limits),
|
|
459
|
-
routingFee: ROUTING_FEE_TERMS,
|
|
460
|
-
next: `In this session, show the user these limits and ask this question before you change any limit. If they say yes, run the same install again with --yes: \`${approve}\`. If they give other amounts, run ${OWN_LIMITS_COMMANDS}. If they say no, run nothing: ${DECLINED}.`,
|
|
461
|
-
approve,
|
|
462
|
-
own: OWN_LIMITS_COMMANDS.replaceAll("`", "")
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
function yesCommand(args) {
|
|
466
|
-
return [
|
|
467
|
-
"tenjin install",
|
|
468
|
-
...args.project === true ? ["--project"] : [],
|
|
469
|
-
...args.noWallet === true ? ["--no-wallet"] : [],
|
|
470
|
-
...args.statusLine !== void 0 ? [`--status-line ${args.statusLine}`] : [],
|
|
471
|
-
"--yes"
|
|
472
|
-
].join(" ");
|
|
473
|
-
}
|
|
474
|
-
async function approveLimits(config, deps) {
|
|
475
|
-
const shown = shownLimits(config);
|
|
476
|
-
const askCall = config.maxAutoSpend === void 0;
|
|
477
|
-
const askDay = config.sessionBudget === void 0;
|
|
478
|
-
if (!askCall && !askDay) return void 0;
|
|
479
|
-
const daily = shown.sessionBudget === "none" ? "no daily limit" : `$${toMoney(shown.sessionBudget).usd} a day`;
|
|
480
|
-
const fee = `
|
|
481
|
-
${ROUTING_FEE_TERMS}
|
|
482
|
-
${FEE_APPROVAL}`;
|
|
483
|
-
const choice = await (deps.promptLimits ?? promptLimits)(
|
|
484
|
-
`The router pays for tool calls without asking, up to:
|
|
485
|
-
$${toMoney(shown.maxAutoSpend).usd} a call, ${daily}${fee}`
|
|
486
|
-
);
|
|
487
|
-
if (choice === null) throw installCancelled();
|
|
488
|
-
if (choice === "approve") return shown;
|
|
489
|
-
const ask = deps.promptAmount ?? promptAmount;
|
|
490
|
-
return {
|
|
491
|
-
maxAutoSpend: askCall ? await askLimit(ask, "Most the router may pay for one call, in USD", "0.25", false) : shown.maxAutoSpend,
|
|
492
|
-
sessionBudget: askDay ? await askLimit(ask, "Most it may pay in a day, in USD, or none", "5", true) : shown.sessionBudget
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
async function askLimit(ask, question, placeholder, allowNone) {
|
|
496
|
-
let message = question;
|
|
497
|
-
for (; ; ) {
|
|
498
|
-
const answer = await ask(message, placeholder);
|
|
499
|
-
if (answer === null) throw installCancelled();
|
|
500
|
-
const parsed = parseLimit(answer, allowNone);
|
|
501
|
-
if (!("refusal" in parsed)) return parsed.value;
|
|
502
|
-
message = `${parsed.refusal} ${question}`;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
function parseLimit(answer, allowNone) {
|
|
506
|
-
const trimmed = answer.trim();
|
|
507
|
-
if (allowNone && trimmed === "none") return { value: "none" };
|
|
508
|
-
let atomic;
|
|
509
|
-
try {
|
|
510
|
-
atomic = parseUsdToAtomic(trimmed);
|
|
511
|
-
} catch (err) {
|
|
512
|
-
if (err instanceof CliError) return { refusal: `${err.message}.` };
|
|
513
|
-
throw err;
|
|
514
|
-
}
|
|
515
|
-
if (atomic === "0") return { refusal: "The limit must be more than zero." };
|
|
516
|
-
return { value: atomic };
|
|
517
|
-
}
|
|
518
|
-
function installCancelled() {
|
|
519
|
-
return new CliError("REFUSED", "Install cancelled before anything was written.", {
|
|
520
|
-
fix: "Re-run `tenjin install` and choose the spend limits."
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
function promptLimits(message) {
|
|
524
|
-
return selectOne({
|
|
525
|
-
message,
|
|
526
|
-
choices: [
|
|
527
|
-
{ value: "approve", label: "Use these limits" },
|
|
528
|
-
{ value: "own", label: "Choose my own" }
|
|
529
|
-
],
|
|
530
|
-
initialValue: "approve"
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
function promptAmount(message, placeholder) {
|
|
534
|
-
return askText({ message, placeholder });
|
|
535
|
-
}
|
|
536
|
-
async function ensurePermissionRules(path) {
|
|
537
|
-
const allow = await appendAllowlistRules(path, [ALLOW_RULE]);
|
|
538
|
-
const deny = await appendAllowlistRules(path, [DENY_RULE], "deny");
|
|
539
|
-
const warning = writerWarning(allow) ?? writerWarning(deny);
|
|
540
|
-
return {
|
|
541
|
-
path: allow.path,
|
|
542
|
-
rule: ALLOW_RULE,
|
|
543
|
-
added: allow.added.length > 0,
|
|
544
|
-
denyRule: DENY_RULE,
|
|
545
|
-
denyAdded: deny.added.length > 0,
|
|
546
|
-
...warning !== void 0 ? { warning } : {}
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
function writerWarning(result) {
|
|
550
|
-
return result.warning ?? (result.skipped !== void 0 ? `${result.path} was left untouched (${result.skipped}).` : void 0);
|
|
551
|
-
}
|
|
552
|
-
async function registerMcpServer(deps, env, project, cwd, home) {
|
|
553
|
-
const scope = mcpScope(project);
|
|
554
|
-
const command = mcpAddCommand(project);
|
|
555
|
-
const base = { name: MCP_SERVER_NAME, scope, command };
|
|
556
|
-
const existing = await (deps.readMcpEntry ?? readMcpEntry)(scope, cwd, home);
|
|
557
|
-
if (existing.state === "ok") {
|
|
558
|
-
return { ...base, registered: true, reconciled: "already-registered" };
|
|
559
|
-
}
|
|
560
|
-
if (existing.state === "unreadable") {
|
|
561
|
-
return {
|
|
562
|
-
...base,
|
|
563
|
-
registered: false,
|
|
564
|
-
reconciled: "unrepaired",
|
|
565
|
-
reason: `the ${scope}-scope registration file could not be read, so nothing was written over it`
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
if (existing.state === "wrong-command") {
|
|
569
|
-
return {
|
|
570
|
-
...base,
|
|
571
|
-
registered: false,
|
|
572
|
-
reconciled: "unrepaired",
|
|
573
|
-
command: `${mcpRemoveCommand(project)} && ${command}`,
|
|
574
|
-
reason: `an MCP server named ${MCP_SERVER_NAME} is already registered at ${scope} scope and launches something else. This command will not remove a registration it did not write; run the two commands above if that entry is stale`
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
const which = deps.which ?? ((bin) => onPath(bin, env));
|
|
578
|
-
if (!which("claude")) {
|
|
579
|
-
return {
|
|
580
|
-
...base,
|
|
581
|
-
registered: false,
|
|
582
|
-
reconciled: "unavailable",
|
|
583
|
-
reason: "the `claude` binary is not on PATH"
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
try {
|
|
587
|
-
await (deps.registerMcp ?? runClaudeMcpAdd)(command, { scope, cwd });
|
|
588
|
-
return { ...base, registered: true, reconciled: "added" };
|
|
589
|
-
} catch (err) {
|
|
590
|
-
return {
|
|
591
|
-
...base,
|
|
592
|
-
registered: false,
|
|
593
|
-
reconciled: "unavailable",
|
|
594
|
-
reason: err instanceof Error ? err.message : String(err)
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
function classifyMcpEntry(entry) {
|
|
599
|
-
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return "absent";
|
|
600
|
-
const { command, args } = entry;
|
|
601
|
-
if (typeof command !== "string" || command.length === 0) return "wrong-command";
|
|
602
|
-
const binary = command.split(/[\\/]/).pop();
|
|
603
|
-
const runsRouter = binary === "tenjin" && Array.isArray(args) && args.length === 1 && args[0] === "mcp";
|
|
604
|
-
return runsRouter ? "ok" : "wrong-command";
|
|
605
|
-
}
|
|
606
|
-
async function readMcpEntry(scope, cwd, home) {
|
|
607
|
-
const path = scope === "project" ? join2(cwd, ".mcp.json") : join2(home, ".claude.json");
|
|
608
|
-
let raw;
|
|
609
|
-
try {
|
|
610
|
-
raw = await readFile(path, "utf8");
|
|
611
|
-
} catch (err) {
|
|
612
|
-
const code = err.code;
|
|
613
|
-
if (code === "ENOENT" || code === "ENOTDIR") return { found: false, state: "absent" };
|
|
614
|
-
return { found: true, state: "unreadable" };
|
|
615
|
-
}
|
|
616
|
-
let parsed;
|
|
617
|
-
try {
|
|
618
|
-
parsed = JSON.parse(raw);
|
|
619
|
-
} catch {
|
|
620
|
-
return { found: true, state: "unreadable" };
|
|
621
|
-
}
|
|
622
|
-
const servers = parsed?.mcpServers;
|
|
623
|
-
if (servers === void 0) return { found: true, state: "absent" };
|
|
624
|
-
if (servers === null || typeof servers !== "object" || Array.isArray(servers)) {
|
|
625
|
-
return { found: true, state: "unreadable" };
|
|
626
|
-
}
|
|
627
|
-
const entry = servers[MCP_SERVER_NAME];
|
|
628
|
-
if (entry === void 0) return { found: true, state: "absent" };
|
|
629
|
-
return { found: true, state: classifyMcpEntry(entry) };
|
|
630
|
-
}
|
|
631
|
-
async function runClaudeMcpAdd(_command, opts) {
|
|
632
|
-
await exec("claude", ["mcp", "add", MCP_SERVER_NAME, "-s", opts.scope, "--", "tenjin", "mcp"], {
|
|
633
|
-
timeout: 2e4,
|
|
634
|
-
cwd: opts.cwd
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
function effectiveLimits(policy) {
|
|
638
|
-
return {
|
|
639
|
-
maxAutoSpend: toMoney(policy.maxAutoSpendAtomic.toString()).usd,
|
|
640
|
-
sessionBudget: policy.sessionBudgetAtomic === null ? "no daily ceiling" : toMoney(policy.sessionBudgetAtomic.toString()).usd
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
function statusLineProblems(ctx, result) {
|
|
644
|
-
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
645
|
-
if (result.warning !== void 0) {
|
|
646
|
-
return [warn(`The live status line was not registered (${result.warning})`)];
|
|
647
|
-
}
|
|
648
|
-
if (result.state !== "foreign") return [];
|
|
649
|
-
return [
|
|
650
|
-
warn("You already have a status line, so it was left exactly as it is."),
|
|
651
|
-
" To show the live x402 footer beside it, run:",
|
|
652
|
-
" tenjin install --status-line compose",
|
|
653
|
-
...result.compose === void 0 ? [] : [" or set this command yourself:", ` ${result.compose}`]
|
|
654
|
-
];
|
|
655
|
-
}
|
|
656
|
-
function lines(ctx, s) {
|
|
657
|
-
const ok = paint(ctx.io, "green", "\u2713");
|
|
658
|
-
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
659
|
-
const limits = effectiveLimits(s.policy);
|
|
660
|
-
const daily = s.policy.sessionBudgetAtomic === null ? "no daily limit" : `$${limits.sessionBudget} a day`;
|
|
661
|
-
const spend = s.approval !== void 0 ? [
|
|
662
|
-
warn("Automatic payments are off until the user approves a spend limit"),
|
|
663
|
-
` Ask the user in this session: ${s.approval.question}`,
|
|
664
|
-
` Yes: ${s.approval.approve}`,
|
|
665
|
-
` Other amounts: ${s.approval.own}`,
|
|
666
|
-
` No: run nothing, ${DECLINED.replaceAll("`", "")}`
|
|
667
|
-
] : s.policy.maxAutoSpendAtomic === 0n ? [
|
|
668
|
-
warn("Automatic payments are off: every paid lookup needs your approval"),
|
|
669
|
-
` To let the router pay without asking, run: ${AUTO_SPEND_FIX}`
|
|
670
|
-
] : [` Automatic router: up to $${limits.maxAutoSpend} per call; daily limit ${daily}`];
|
|
671
|
-
const router = s.router.status === "ok" ? [] : [
|
|
672
|
-
warn(`The router did not answer: ${s.router.detail}`),
|
|
673
|
-
...s.router.fix !== void 0 ? [` ${s.router.fix}`] : []
|
|
674
|
-
];
|
|
675
|
-
const blocked = s.hooks.skipped !== void 0;
|
|
676
|
-
const needsMcp = !blocked && !s.mcp.registered;
|
|
677
|
-
const where = s.project ? " in this project" : "";
|
|
678
|
-
const fund = paint(ctx.io, "bold", "tenjin wallet fund");
|
|
679
|
-
return [
|
|
680
|
-
blocked ? paint(ctx.io, "yellow", `! Tenjin could not finish setting up Claude Code${where}`) : needsMcp ? paint(ctx.io, "yellow", "! Almost done: Claude Code needs one command") : `${ok} Tenjin is set up for Claude Code${where}`,
|
|
681
|
-
...walletLines(ctx, ok, s.wallet),
|
|
682
|
-
...spend,
|
|
683
|
-
...s.statusLine.state === "ours" || s.statusLine.state === "composed" ? [" Live status line on: each lookup names its provider while it runs"] : [],
|
|
684
|
-
...problems(ctx, s.hooks, s.permissions, s.statusLine, s.mcp),
|
|
685
|
-
...router,
|
|
686
|
-
"",
|
|
687
|
-
blocked ? "Next: fix the file above, then run tenjin install again" : needsMcp ? s.wallet.status === "created" ? `Next: run the command above and ${fund}, then start a new Claude Code session so the hooks and the server load` : "Next: run the command above, then start a new Claude Code session so the hooks and the server load" : s.wallet.status === "created" ? `Next: ${fund}, then start a new Claude Code session so the hooks and the server load` : "Next: start a new Claude Code session so the hooks and the server load"
|
|
688
|
-
];
|
|
689
|
-
}
|
|
690
|
-
function refreshLines(ctx, issues) {
|
|
691
|
-
if (issues.length === 0) return [`${paint(ctx.io, "green", "\u2713")} Tenjin is up to date`];
|
|
692
|
-
return [paint(ctx.io, "yellow", "! Tenjin is updated, but needs one fix"), ...issues];
|
|
693
|
-
}
|
|
694
|
-
function walletLines(ctx, ok, w) {
|
|
695
|
-
if (w.status === "created") return [`${ok} Wallet created: ${w.address}`];
|
|
696
|
-
if (w.status === "existing") return [`${ok} Wallet: ${w.address}`];
|
|
697
|
-
if (w.reason === "flag") return [" No wallet yet. Create one with: tenjin wallet create"];
|
|
698
|
-
return [
|
|
699
|
-
paint(ctx.io, "yellow", `! No wallet was created. ${w.warning ?? ""}`.trimEnd()),
|
|
700
|
-
` ${w.fix ?? "Create one with: tenjin wallet create"}`
|
|
701
|
-
];
|
|
702
|
-
}
|
|
703
|
-
function problems(ctx, hooks, permissions, statusLine, mcp) {
|
|
704
|
-
const warn = (text) => paint(ctx.io, "yellow", `! ${text}`);
|
|
705
|
-
const out = [];
|
|
706
|
-
if (hooks.skipped !== void 0) {
|
|
707
|
-
out.push(
|
|
708
|
-
warn(
|
|
709
|
-
hooks.warning ?? `${hooks.path ?? "Your Claude Code settings file"} was left untouched (${hooks.skipped}).`
|
|
710
|
-
)
|
|
711
|
-
);
|
|
712
|
-
} else {
|
|
713
|
-
if (hooks.warning !== void 0) out.push(warn(hooks.warning));
|
|
714
|
-
if (permissions.warning !== void 0) out.push(warn(permissions.warning));
|
|
715
|
-
}
|
|
716
|
-
if (!mcp.registered) {
|
|
717
|
-
out.push(warn("Could not add the request tool to Claude Code. Run:"));
|
|
718
|
-
out.push(` ${mcp.command}`);
|
|
719
|
-
}
|
|
720
|
-
out.push(...statusLineProblems(ctx, statusLine));
|
|
721
|
-
return out;
|
|
722
|
-
}
|
|
723
|
-
async function probeOurEntries(path, dataDir) {
|
|
724
|
-
const found = await inspectHooksFile(path);
|
|
725
|
-
if ("refusal" in found) {
|
|
726
|
-
return { state: "unreadable", reason: found.refusal.reason };
|
|
727
|
-
}
|
|
728
|
-
const present = Object.values(found.hooks).some(
|
|
729
|
-
(list) => list.some((entry) => ownsHookEntry(entry, dataDir))
|
|
730
|
-
);
|
|
731
|
-
return present ? { state: "present" } : { state: "absent" };
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
export {
|
|
735
|
-
probeRouter,
|
|
736
|
-
ROUTE_HOOK_TIMEOUT_SECONDS,
|
|
737
|
-
AFTER_CALL_TIMEOUT_SECONDS,
|
|
738
|
-
ALLOW_RULE,
|
|
739
|
-
DENY_RULE,
|
|
740
|
-
mcpScope,
|
|
741
|
-
mcpAddCommand,
|
|
742
|
-
mcpRemoveCommand,
|
|
743
|
-
MCP_ADD_COMMAND,
|
|
744
|
-
routerSettingsPath,
|
|
745
|
-
DELEGATION_MATCHER,
|
|
746
|
-
NATIVE_MATCHER,
|
|
747
|
-
ASK_MATCHER,
|
|
748
|
-
routerHookPlan,
|
|
749
|
-
DISCLOSURE,
|
|
750
|
-
runRouterInstall,
|
|
751
|
-
classifyMcpEntry,
|
|
752
|
-
readMcpEntry,
|
|
753
|
-
statusLineProblems
|
|
754
|
-
};
|
|
755
|
-
//# sourceMappingURL=chunk-PY7MQUKP.js.map
|