tenjin-cli 0.1.0-alpha.28 → 0.1.0-alpha.29
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 +13 -10
- package/dist/{chunk-ZG6ZZLO7.js → chunk-25GGN553.js} +9 -11
- package/dist/{chunk-ZG6ZZLO7.js.map → chunk-25GGN553.js.map} +1 -1
- package/dist/{chunk-B2L53TMK.js → chunk-2SNUOHAT.js} +28 -23
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/{chunk-UEOWNDQG.js → chunk-3FY5HG7R.js} +82 -13
- package/dist/chunk-3FY5HG7R.js.map +1 -0
- package/dist/{chunk-DJYAPACT.js → chunk-4FYMDRD3.js} +32 -24
- package/dist/chunk-4FYMDRD3.js.map +1 -0
- package/dist/{chunk-ZP7AHN7Z.js → chunk-AMEUXNJT.js} +3 -5
- package/dist/{chunk-ZP7AHN7Z.js.map → chunk-AMEUXNJT.js.map} +1 -1
- package/dist/chunk-EWLU46J6.js +100 -0
- package/dist/chunk-EWLU46J6.js.map +1 -0
- package/dist/{chunk-RLPLYUME.js → chunk-LRCJ2IZ5.js} +3 -3
- package/dist/{chunk-RLPLYUME.js.map → chunk-LRCJ2IZ5.js.map} +1 -1
- package/dist/{chunk-YFJJYHVG.js → chunk-LX5OT4TQ.js} +3 -3
- package/dist/{chunk-YFJJYHVG.js.map → chunk-LX5OT4TQ.js.map} +1 -1
- package/dist/{chunk-ZO3X5NPG.js → chunk-MG3G644T.js} +4 -4
- package/dist/{chunk-6KA4HFX5.js → chunk-MOG7PB3A.js} +3 -3
- package/dist/{chunk-DYSDQE7S.js → chunk-MRUPDSUM.js} +14 -93
- package/dist/chunk-MRUPDSUM.js.map +1 -0
- package/dist/{chunk-KAMRYUK2.js → chunk-OOSRB3OF.js} +2 -2
- package/dist/{chunk-PZ5N6BAL.js → chunk-ORWL5BSN.js} +5 -4
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/chunk-P4LVLFO4.js +29 -0
- package/dist/chunk-P4LVLFO4.js.map +1 -0
- package/dist/{chunk-ZP5PV3JB.js → chunk-QTGUDCIR.js} +5 -5
- package/dist/{chunk-FQ6DHINU.js → chunk-R4AO7GC2.js} +437 -78
- package/dist/chunk-R4AO7GC2.js.map +1 -0
- package/dist/{chunk-UOW5JXYY.js → chunk-RJEPZMYY.js} +10 -4
- package/dist/chunk-RJEPZMYY.js.map +1 -0
- package/dist/{chunk-VSUHGRVB.js → chunk-SBL4THYT.js} +712 -93
- package/dist/chunk-SBL4THYT.js.map +1 -0
- package/dist/{chunk-BRHREK7E.js → chunk-SFEQGENI.js} +2 -2
- package/dist/{chunk-K6AXXYCG.js → chunk-SJLTEINJ.js} +10 -2
- package/dist/{chunk-K6AXXYCG.js.map → chunk-SJLTEINJ.js.map} +1 -1
- package/dist/{chunk-XVTD7UWR.js → chunk-TROZ6HL4.js} +2 -2
- package/dist/{chunk-3QJREVMX.js → chunk-USOLCBKC.js} +5 -5
- package/dist/{chunk-W6JX4LYF.js → chunk-VKQXVCZR.js} +46 -5
- package/dist/chunk-VKQXVCZR.js.map +1 -0
- package/dist/{chunk-QTND6XWJ.js → chunk-VVAHFCX2.js} +51 -3
- package/dist/chunk-VVAHFCX2.js.map +1 -0
- package/dist/{chunk-7H3RN4WJ.js → chunk-WM7TJEBP.js} +5 -5
- package/dist/{chunk-MNTQMZJB.js → chunk-XDYKZRLN.js} +22 -13
- package/dist/chunk-XDYKZRLN.js.map +1 -0
- package/dist/{chunk-A5H3E5QA.js → chunk-XJQ6CH7X.js} +3 -2
- package/dist/{chunk-7R37M6WV.js → chunk-ZQNGTLOC.js} +5 -5
- package/dist/{cli-234DNHN6.js → cli-JPTDHGRX.js} +38 -33
- package/dist/{cli-234DNHN6.js.map → cli-JPTDHGRX.js.map} +1 -1
- package/dist/{config-IY2OJCAK.js → config-YYKDH2TH.js} +11 -11
- package/dist/{doctor-2UZZF44A.js → doctor-SSTXGCHX.js} +60 -56
- package/dist/doctor-SSTXGCHX.js.map +1 -0
- package/dist/{fund-RZ2QFULK.js → fund-QWVWRVDK.js} +14 -16
- package/dist/{fund-RZ2QFULK.js.map → fund-QWVWRVDK.js.map} +1 -1
- package/dist/hook-command-VWJXRT7H.js +31 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
- package/dist/hosts/claude/tenjin/.mcp.json +2 -1
- package/dist/hosts/claude/tenjin/hooks/hooks.json +18 -3
- package/dist/index.js +6 -6
- package/dist/{install-O5FJ5EP3.js → install-2GXXD4DK.js} +19 -16
- package/dist/{install-identity-QM44IQ6Z.js → install-identity-FK3YF227.js} +7 -8
- package/dist/{install-wallet-Z52EDLPB.js → install-wallet-TC22U52X.js} +17 -12
- package/dist/{install-wallet-Z52EDLPB.js.map → install-wallet-TC22U52X.js.map} +1 -1
- package/dist/{mcp-33HAADDF.js → mcp-42H2F4NY.js} +2091 -348
- package/dist/mcp-42H2F4NY.js.map +1 -0
- package/dist/{package-RT24HTTP.js → package-6DJA3Y2O.js} +2 -2
- package/dist/{paths-MUXHUOCM.js → paths-POPTXJO6.js} +6 -2
- package/dist/{pay-IR2V76FX.js → pay-LSDJBIAZ.js} +18 -15
- package/dist/payments-SPECLBRQ.js +105 -0
- package/dist/payments-SPECLBRQ.js.map +1 -0
- package/dist/{send-PI4NUA7I.js → send-MHAOLPK3.js} +12 -14
- package/dist/{send-PI4NUA7I.js.map → send-MHAOLPK3.js.map} +1 -1
- package/dist/status-O2RWLPS5.js +114 -0
- package/dist/status-O2RWLPS5.js.map +1 -0
- package/dist/{status-line-2G5JPQAE.js → status-line-45TVCRM3.js} +7 -8
- package/dist/{status-line-2G5JPQAE.js.map → status-line-45TVCRM3.js.map} +1 -1
- package/dist/{uninstall-THKUH5ZT.js → uninstall-VOK2Z5M4.js} +27 -17
- package/dist/uninstall-VOK2Z5M4.js.map +1 -0
- package/dist/update-FGP3HNLD.js +33 -0
- package/dist/{wallet-53EFH4M5.js → wallet-DA7OFNEW.js} +17 -12
- package/docs/agent-permissions.md +11 -8
- package/docs/safety-model.md +3 -1
- package/package.json +2 -2
- package/dist/chunk-AO54FM4H.js +0 -563
- package/dist/chunk-AO54FM4H.js.map +0 -1
- package/dist/chunk-B2L53TMK.js.map +0 -1
- package/dist/chunk-DJYAPACT.js.map +0 -1
- package/dist/chunk-DYSDQE7S.js.map +0 -1
- package/dist/chunk-FQ6DHINU.js.map +0 -1
- package/dist/chunk-FZTSGQVK.js +0 -52
- package/dist/chunk-FZTSGQVK.js.map +0 -1
- package/dist/chunk-MNTQMZJB.js.map +0 -1
- package/dist/chunk-PZ5N6BAL.js.map +0 -1
- package/dist/chunk-QTND6XWJ.js.map +0 -1
- package/dist/chunk-UEOWNDQG.js.map +0 -1
- package/dist/chunk-UOW5JXYY.js.map +0 -1
- package/dist/chunk-VSUHGRVB.js.map +0 -1
- package/dist/chunk-W6JX4LYF.js.map +0 -1
- package/dist/doctor-2UZZF44A.js.map +0 -1
- package/dist/hook-command-PZHKS7ES.js +0 -31
- package/dist/mcp-33HAADDF.js.map +0 -1
- package/dist/payments-GFV4HU5R.js +0 -47
- package/dist/payments-GFV4HU5R.js.map +0 -1
- package/dist/status-ZUHTJK46.js +0 -71
- package/dist/status-ZUHTJK46.js.map +0 -1
- package/dist/uninstall-THKUH5ZT.js.map +0 -1
- package/dist/update-NPZDP24E.js +0 -18
- /package/dist/{chunk-ZO3X5NPG.js.map → chunk-MG3G644T.js.map} +0 -0
- /package/dist/{chunk-6KA4HFX5.js.map → chunk-MOG7PB3A.js.map} +0 -0
- /package/dist/{chunk-KAMRYUK2.js.map → chunk-OOSRB3OF.js.map} +0 -0
- /package/dist/{chunk-ZP5PV3JB.js.map → chunk-QTGUDCIR.js.map} +0 -0
- /package/dist/{chunk-BRHREK7E.js.map → chunk-SFEQGENI.js.map} +0 -0
- /package/dist/{chunk-XVTD7UWR.js.map → chunk-TROZ6HL4.js.map} +0 -0
- /package/dist/{chunk-3QJREVMX.js.map → chunk-USOLCBKC.js.map} +0 -0
- /package/dist/{chunk-7H3RN4WJ.js.map → chunk-WM7TJEBP.js.map} +0 -0
- /package/dist/{chunk-A5H3E5QA.js.map → chunk-XJQ6CH7X.js.map} +0 -0
- /package/dist/{chunk-7R37M6WV.js.map → chunk-ZQNGTLOC.js.map} +0 -0
- /package/dist/{config-IY2OJCAK.js.map → config-YYKDH2TH.js.map} +0 -0
- /package/dist/{hook-command-PZHKS7ES.js.map → hook-command-VWJXRT7H.js.map} +0 -0
- /package/dist/{install-O5FJ5EP3.js.map → install-2GXXD4DK.js.map} +0 -0
- /package/dist/{install-identity-QM44IQ6Z.js.map → install-identity-FK3YF227.js.map} +0 -0
- /package/dist/{package-RT24HTTP.js.map → package-6DJA3Y2O.js.map} +0 -0
- /package/dist/{paths-MUXHUOCM.js.map → paths-POPTXJO6.js.map} +0 -0
- /package/dist/{pay-IR2V76FX.js.map → pay-LSDJBIAZ.js.map} +0 -0
- /package/dist/{update-NPZDP24E.js.map → update-FGP3HNLD.js.map} +0 -0
- /package/dist/{wallet-53EFH4M5.js.map → wallet-DA7OFNEW.js.map} +0 -0
package/dist/chunk-AO54FM4H.js
DELETED
|
@@ -1,563 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
NUDGE_OPT_OUT,
|
|
4
|
-
channelTag,
|
|
5
|
-
fetchDistTags,
|
|
6
|
-
isNewer,
|
|
7
|
-
resolveTarget
|
|
8
|
-
} from "./chunk-7H3RN4WJ.js";
|
|
9
|
-
import {
|
|
10
|
-
emitWriteNotice,
|
|
11
|
-
sanitizeForTerminal
|
|
12
|
-
} from "./chunk-XVTD7UWR.js";
|
|
13
|
-
import {
|
|
14
|
-
CliError
|
|
15
|
-
} from "./chunk-QTND6XWJ.js";
|
|
16
|
-
import {
|
|
17
|
-
defaultDataDir
|
|
18
|
-
} from "./chunk-K6AXXYCG.js";
|
|
19
|
-
import {
|
|
20
|
-
package_default
|
|
21
|
-
} from "./chunk-RLPLYUME.js";
|
|
22
|
-
|
|
23
|
-
// src/commands/update.ts
|
|
24
|
-
import { spawn } from "node:child_process";
|
|
25
|
-
import { existsSync as existsSync2, statSync as statSync2 } from "node:fs";
|
|
26
|
-
import { homedir } from "node:os";
|
|
27
|
-
import { resolve, sep as sep2 } from "node:path";
|
|
28
|
-
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29
|
-
|
|
30
|
-
// src/lib/install-location.ts
|
|
31
|
-
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
32
|
-
import { delimiter, dirname, join, sep } from "node:path";
|
|
33
|
-
var REFUSALS = [
|
|
34
|
-
{
|
|
35
|
-
test: isSourceCheckout,
|
|
36
|
-
error: () => new CliError("REFUSED", "tenjin-cli is running from a source checkout, not an install", {
|
|
37
|
-
fix: "Update the checkout instead: git pull && pnpm install"
|
|
38
|
-
}),
|
|
39
|
-
needsVersion: false,
|
|
40
|
-
appliesToCheck: false
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
test: (moduleDir) => moduleDir.split(sep).includes("_npx"),
|
|
44
|
-
error: (spec) => new CliError("REFUSED", "tenjin-cli is running from the npx cache, not an install", {
|
|
45
|
-
// Writing a global here would "succeed" and change nothing: the next
|
|
46
|
-
// `npx tenjin` still resolves its own cached copy.
|
|
47
|
-
fix: `npx fetches its own copy every time. To keep one: npm i -g ${spec}`
|
|
48
|
-
}),
|
|
49
|
-
needsVersion: true,
|
|
50
|
-
appliesToCheck: false
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
// The ONLY manager still refused. `yarn global add` is yarn-1 only, and
|
|
54
|
-
// berry dropped global installs altogether, so there is no one command this
|
|
55
|
-
// can drive across the versions a user might have. Every other manager is
|
|
56
|
-
// delegated to rather than refused (see MANAGERS).
|
|
57
|
-
test: (moduleDir) => classifyManager(moduleDir) === "yarn",
|
|
58
|
-
error: (spec) => new CliError(
|
|
59
|
-
"REFUSED",
|
|
60
|
-
"This tenjin-cli was installed with yarn, whose global install exists only in yarn 1",
|
|
61
|
-
{ fix: `yarn global add ${spec}` }
|
|
62
|
-
),
|
|
63
|
-
needsVersion: true,
|
|
64
|
-
appliesToCheck: false
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
// Scoped to npm on purpose: the prefix-vs-project-root test is written for
|
|
68
|
-
// npm's layout. pnpm's global store and bun's global dir both keep a
|
|
69
|
-
// package.json beside `node_modules`, so an unscoped test would read either
|
|
70
|
-
// as a project-local install and refuse the very case we now delegate.
|
|
71
|
-
test: (moduleDir) => classifyManager(moduleDir) === "npm" && !isGlobalTree(moduleDir),
|
|
72
|
-
error: (spec) => new CliError(
|
|
73
|
-
"REFUSED",
|
|
74
|
-
"This tenjin-cli is a project-local dependency, not a global install",
|
|
75
|
-
{
|
|
76
|
-
fix: `Update it where it is declared: npm i ${spec}`
|
|
77
|
-
}
|
|
78
|
-
),
|
|
79
|
-
needsVersion: true,
|
|
80
|
-
appliesToCheck: false
|
|
81
|
-
}
|
|
82
|
-
];
|
|
83
|
-
function refuse(moduleDir, opts) {
|
|
84
|
-
for (const entry of REFUSALS) {
|
|
85
|
-
if (opts.check && !entry.appliesToCheck) continue;
|
|
86
|
-
if (entry.needsVersion !== (opts.spec !== null)) continue;
|
|
87
|
-
if (entry.test(moduleDir)) throw entry.error(opts.spec ?? "", moduleDir);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function isSourceCheckout(moduleDir) {
|
|
91
|
-
let dir = moduleDir;
|
|
92
|
-
for (let i = 0; i < 8; i += 1) {
|
|
93
|
-
if (existsSync(join(dir, "package.json"))) return existsSync(join(dir, "src"));
|
|
94
|
-
const parent = dirname(dir);
|
|
95
|
-
if (parent === dir) break;
|
|
96
|
-
dir = parent;
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
function isGlobalTree(moduleDir) {
|
|
101
|
-
const segs = moduleDir.split(sep);
|
|
102
|
-
const i = segs.lastIndexOf("node_modules");
|
|
103
|
-
if (i <= 0) return false;
|
|
104
|
-
return !existsSync(join(segs.slice(0, i).join(sep), "package.json"));
|
|
105
|
-
}
|
|
106
|
-
function classifyManager(moduleDir) {
|
|
107
|
-
const segs = moduleDir.split(sep);
|
|
108
|
-
const pair = (a, b) => segs.includes(a) && segs.includes(b);
|
|
109
|
-
if (segs.includes(".pnpm") || pair("pnpm", "global")) return "pnpm";
|
|
110
|
-
if (segs.includes(".bun")) return "bun";
|
|
111
|
-
if (segs.includes(".yarn") || pair("yarn", "global")) return "yarn";
|
|
112
|
-
return "npm";
|
|
113
|
-
}
|
|
114
|
-
var MANAGERS = {
|
|
115
|
-
npm: {
|
|
116
|
-
bin: "npm",
|
|
117
|
-
scriptSuffixes: ["npm-cli.js"],
|
|
118
|
-
besideNode: true,
|
|
119
|
-
args: (spec) => ["install", "-g", "--ignore-scripts", spec],
|
|
120
|
-
manual: (spec) => `npm i -g ${spec}`
|
|
121
|
-
},
|
|
122
|
-
pnpm: {
|
|
123
|
-
bin: "pnpm",
|
|
124
|
-
// corepack's shim resolves to `pnpm.js`, a standalone install to `pnpm.cjs`.
|
|
125
|
-
scriptSuffixes: [".cjs", ".js"],
|
|
126
|
-
besideNode: false,
|
|
127
|
-
args: (spec) => ["add", "-g", "--ignore-scripts", spec],
|
|
128
|
-
manual: (spec) => `pnpm add -g ${spec}`
|
|
129
|
-
},
|
|
130
|
-
bun: {
|
|
131
|
-
bin: "bun",
|
|
132
|
-
scriptSuffixes: [],
|
|
133
|
-
besideNode: false,
|
|
134
|
-
// No --ignore-scripts: bun's flag surface for it is not stable across the
|
|
135
|
-
// versions in the wild, and an unknown flag would fail the install outright.
|
|
136
|
-
args: (spec) => ["add", "-g", spec],
|
|
137
|
-
manual: (spec) => `bun add -g ${spec}`
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
function resolveManagerScript(manager, execPath, env = process.env) {
|
|
141
|
-
const plan = MANAGERS[manager];
|
|
142
|
-
if (plan.scriptSuffixes.length === 0) return null;
|
|
143
|
-
const beside = plan.besideNode ? scriptNear(dirname(execPath), plan.bin) : null;
|
|
144
|
-
return beside ?? scriptOnPath(plan.bin, plan.scriptSuffixes, env);
|
|
145
|
-
}
|
|
146
|
-
function scriptNear(dir, bin) {
|
|
147
|
-
const candidates = [
|
|
148
|
-
join(dir, "node_modules", bin, "bin", `${bin}-cli.js`),
|
|
149
|
-
join(dir, "..", "lib", "node_modules", bin, "bin", `${bin}-cli.js`)
|
|
150
|
-
];
|
|
151
|
-
return candidates.find(isFile) ?? null;
|
|
152
|
-
}
|
|
153
|
-
function scriptOnPath(bin, suffixes, env) {
|
|
154
|
-
const exts = process.platform === "win32" ? ["", ...(env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter((e) => e.length > 0)] : [""];
|
|
155
|
-
for (const part of (env.PATH ?? "").split(delimiter)) {
|
|
156
|
-
if (part.length === 0) continue;
|
|
157
|
-
for (const ext of exts) {
|
|
158
|
-
if (!isFile(join(part, `${bin}${ext}`))) continue;
|
|
159
|
-
const real = realpathOrNull(join(part, `${bin}${ext}`));
|
|
160
|
-
if (real !== null && suffixes.some((suffix) => real.endsWith(suffix))) return real;
|
|
161
|
-
const near = scriptNear(part, bin);
|
|
162
|
-
if (near !== null) return near;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
function isFile(p) {
|
|
168
|
-
try {
|
|
169
|
-
return statSync(p).isFile();
|
|
170
|
-
} catch {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function realpathOrNull(p) {
|
|
175
|
-
try {
|
|
176
|
-
return realpathSync(p);
|
|
177
|
-
} catch {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// src/router/mcp-processes.ts
|
|
183
|
-
import { execFile } from "node:child_process";
|
|
184
|
-
import { stat } from "node:fs/promises";
|
|
185
|
-
import { dirname as dirname2, join as join2 } from "node:path";
|
|
186
|
-
import { fileURLToPath } from "node:url";
|
|
187
|
-
import { promisify } from "node:util";
|
|
188
|
-
var exec = promisify(execFile);
|
|
189
|
-
var listMcpProcesses = async () => {
|
|
190
|
-
if (process.platform === "win32" || typeof process.getuid !== "function") return null;
|
|
191
|
-
try {
|
|
192
|
-
const { stdout } = await exec(
|
|
193
|
-
"ps",
|
|
194
|
-
["-U", String(process.getuid()), "-o", "pid=,lstart=,args="],
|
|
195
|
-
{ timeout: 5e3, env: { ...process.env, LC_ALL: "C" }, maxBuffer: 4 * 1024 * 1024 }
|
|
196
|
-
);
|
|
197
|
-
return parsePs(stdout, process.pid);
|
|
198
|
-
} catch {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
var PS_LINE = /^\s*(\d+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4})\s+(.*)$/;
|
|
203
|
-
function parsePs(stdout, selfPid) {
|
|
204
|
-
const found = [];
|
|
205
|
-
for (const line of stdout.split("\n")) {
|
|
206
|
-
const m = PS_LINE.exec(line);
|
|
207
|
-
if (m === null) continue;
|
|
208
|
-
const pid = Number(m[1]);
|
|
209
|
-
if (pid === selfPid || !isTenjinMcp(m[3])) continue;
|
|
210
|
-
const startedAt = Date.parse(m[2].replace(/\s+/g, " "));
|
|
211
|
-
found.push({ pid, startedAt: Number.isNaN(startedAt) ? null : startedAt });
|
|
212
|
-
}
|
|
213
|
-
return found;
|
|
214
|
-
}
|
|
215
|
-
function isTenjinMcp(args) {
|
|
216
|
-
const tokens = args.trim().split(/\s+/);
|
|
217
|
-
const bin = tokens.findIndex(
|
|
218
|
-
(t) => /(^|[/\\])tenjin(\.js|\.cmd)?$/.test(t) || /[/\\]tenjin-cli[/\\]/.test(t)
|
|
219
|
-
);
|
|
220
|
-
return bin >= 0 && tokens[bin + 1] === "mcp";
|
|
221
|
-
}
|
|
222
|
-
var installedAt = async () => {
|
|
223
|
-
let dir = dirname2(fileURLToPath(import.meta.url));
|
|
224
|
-
for (let i = 0; i < 6; i += 1) {
|
|
225
|
-
try {
|
|
226
|
-
const st = await stat(join2(dir, "package.json"));
|
|
227
|
-
return Math.max(st.ctimeMs, st.mtimeMs);
|
|
228
|
-
} catch {
|
|
229
|
-
dir = dirname2(dir);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return null;
|
|
233
|
-
};
|
|
234
|
-
var RECONNECT_FIX = "Type /reload-plugins in this Claude Code session, or start a new session.";
|
|
235
|
-
var NEW_SESSION_FIX = "Start a new Claude Code session: the earlier Tenjin setup is still in this one, and /reload-plugins would run both.";
|
|
236
|
-
function mcpServersState(procs, installed, version = package_default.version, fix = RECONNECT_FIX) {
|
|
237
|
-
const check = (detail) => ({
|
|
238
|
-
stale: 0,
|
|
239
|
-
check: { name: "mcp server", status: "ok", required: false, detail }
|
|
240
|
-
});
|
|
241
|
-
if (procs === null) {
|
|
242
|
-
return check("unknown: running `tenjin mcp` processes cannot be listed on this platform");
|
|
243
|
-
}
|
|
244
|
-
if (procs.length === 0) return check("none running (starts with the next session)");
|
|
245
|
-
if (installed === null) {
|
|
246
|
-
return check(`${procs.length} running; when this build was installed is unknown`);
|
|
247
|
-
}
|
|
248
|
-
const stale = procs.filter((p) => p.startedAt !== null && p.startedAt < installed).length;
|
|
249
|
-
if (stale === 0) {
|
|
250
|
-
return check(`${procs.length} running, all started after this install`);
|
|
251
|
-
}
|
|
252
|
-
const which = stale === 1 ? "process" : "processes";
|
|
253
|
-
return {
|
|
254
|
-
stale,
|
|
255
|
-
check: {
|
|
256
|
-
name: "mcp server",
|
|
257
|
-
status: "warn",
|
|
258
|
-
required: false,
|
|
259
|
-
detail: `${stale} running \`tenjin mcp\` ${which} started before this install (${version}), so ${stale === 1 ? "it runs" : "they run"} the older build, where the hooks can fail with "Tool hook not found"`,
|
|
260
|
-
fix
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
async function readMcpServers(deps = {}, opts = {}) {
|
|
265
|
-
const [procs, installed] = await Promise.all([
|
|
266
|
-
(deps.listMcpProcesses ?? listMcpProcesses)().catch(() => null),
|
|
267
|
-
(deps.installedAt ?? installedAt)().catch(() => null)
|
|
268
|
-
]);
|
|
269
|
-
const fix = opts.settingsInstallPending === true ? NEW_SESSION_FIX : RECONNECT_FIX;
|
|
270
|
-
return mcpServersState(procs, installed, package_default.version, fix);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/commands/update.ts
|
|
274
|
-
var INSTALL_TIMEOUT_MS = 3e5;
|
|
275
|
-
function resolveManager(manager, deps) {
|
|
276
|
-
const script = deps.managerScript !== void 0 ? deps.managerScript : resolveManagerScript(manager, process.execPath);
|
|
277
|
-
return script === null ? { cmd: MANAGERS[manager].bin, prefix: [] } : { cmd: process.execPath, prefix: [script] };
|
|
278
|
-
}
|
|
279
|
-
async function runUpdate(opts, ctx, deps = {}) {
|
|
280
|
-
const current = deps.currentVersion ?? package_default.version;
|
|
281
|
-
const channel = channelTag(current);
|
|
282
|
-
const moduleDir = deps.moduleDir ?? fileURLToPath2(new URL(".", import.meta.url));
|
|
283
|
-
if (channel === null) {
|
|
284
|
-
throw new CliError("REFUSED", `tenjin-cli reports an unrecognizable version (${current})`, {
|
|
285
|
-
fix: "Reinstall a published build: npm i -g tenjin-cli"
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
refuse(moduleDir, { check: opts.check, spec: null });
|
|
289
|
-
const tags = await fetchDistTags({
|
|
290
|
-
fetchImpl: deps.fetchImpl,
|
|
291
|
-
timeoutMs: ctx.flags.timeout
|
|
292
|
-
});
|
|
293
|
-
if (tags === null) {
|
|
294
|
-
throw new CliError("NETWORK_ERROR", "Could not read tenjin-cli dist-tags from npm", {
|
|
295
|
-
fix: "Check access to registry.npmjs.org and retry"
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
const latest = resolveTarget(current, tags);
|
|
299
|
-
if (latest === null) {
|
|
300
|
-
const raw = tags[channel];
|
|
301
|
-
throw raw === void 0 ? new CliError("RESOURCE_NOT_FOUND", "npm has no published tenjin-cli on the latest tag", {
|
|
302
|
-
fix: "Pick a version yourself: npm view tenjin-cli versions"
|
|
303
|
-
}) : new CliError(
|
|
304
|
-
"RESOURCE_NOT_FOUND",
|
|
305
|
-
// Registry-controlled: bounded here, escaped by the error emitter.
|
|
306
|
-
`npm's latest tenjin-cli (${raw.slice(0, 40)}) is not a version this build can read`,
|
|
307
|
-
{
|
|
308
|
-
fix: "Install it by name: npm i -g tenjin-cli@<version> (npm view tenjin-cli versions)"
|
|
309
|
-
}
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
const updateAvailable = isNewer(latest, current);
|
|
313
|
-
const data = (updated) => ({
|
|
314
|
-
current,
|
|
315
|
-
latest,
|
|
316
|
-
updateAvailable,
|
|
317
|
-
updated
|
|
318
|
-
});
|
|
319
|
-
if (!updateAvailable) {
|
|
320
|
-
return {
|
|
321
|
-
data: data(false),
|
|
322
|
-
humanLines: [`tenjin-cli ${current} is up to date`]
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
if (opts.check) {
|
|
326
|
-
return {
|
|
327
|
-
data: data(false),
|
|
328
|
-
humanLines: [
|
|
329
|
-
`tenjin-cli ${latest} is available (you have ${current}).`,
|
|
330
|
-
"Run tenjin update to install it."
|
|
331
|
-
]
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
const spec = `tenjin-cli@${latest}`;
|
|
335
|
-
refuse(moduleDir, { check: false, spec });
|
|
336
|
-
const human = ctx.io.isTTY && !ctx.flags.json;
|
|
337
|
-
let tail = "";
|
|
338
|
-
const onOutput = (chunk) => {
|
|
339
|
-
tail = (tail + chunk).slice(-2e3);
|
|
340
|
-
if (human) ctx.io.stderr.write(chunk.split("\n").map(sanitizeForTerminal).join("\n"));
|
|
341
|
-
};
|
|
342
|
-
const manager = classifyManager(moduleDir);
|
|
343
|
-
const plan = MANAGERS[manager];
|
|
344
|
-
const args = plan.args(spec);
|
|
345
|
-
const resolved = resolveManager(manager, deps);
|
|
346
|
-
const manual = `Run it yourself: ${plan.manual(spec)}`;
|
|
347
|
-
const outcome = await (deps.spawnImpl ?? spawnCapture)(
|
|
348
|
-
resolved.cmd,
|
|
349
|
-
[...resolved.prefix, ...args],
|
|
350
|
-
{ cwd: homedir(), timeoutMs: INSTALL_TIMEOUT_MS },
|
|
351
|
-
onOutput
|
|
352
|
-
);
|
|
353
|
-
if (outcome.kind === "start-failed") {
|
|
354
|
-
throw new CliError("UPDATE_FAILED", `Could not start ${manager}`, {
|
|
355
|
-
fix: manual,
|
|
356
|
-
cause: outcome.cause
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
if (outcome.kind === "timeout") {
|
|
360
|
-
throw new CliError(
|
|
361
|
-
"UPDATE_FAILED",
|
|
362
|
-
`${manager} did not finish in ${INSTALL_TIMEOUT_MS / 1e3}s`,
|
|
363
|
-
{ fix: manual, details: { output: tail } }
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
if (outcome.code !== 0) {
|
|
367
|
-
throw new CliError("UPDATE_FAILED", `${manager} ${args.join(" ")} exited ${outcome.code}`, {
|
|
368
|
-
// EACCES on a root-owned global prefix is the common cause; the operator
|
|
369
|
-
// fixing that themselves beats this CLI ever escalating.
|
|
370
|
-
fix: manual,
|
|
371
|
-
details: { output: tail }
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
emitWriteNotice(
|
|
375
|
-
ctx.io,
|
|
376
|
-
`tenjin update: replaced the global tenjin-cli with ${latest} via ${manager}`
|
|
377
|
-
);
|
|
378
|
-
const refresh = await refreshProfiles(ctx, deps);
|
|
379
|
-
const servers = await readMcpServers(deps, {
|
|
380
|
-
settingsInstallPending: refresh.settingsInstallPending
|
|
381
|
-
});
|
|
382
|
-
return {
|
|
383
|
-
data: { ...data(true), refresh, mcpServer: servers.check },
|
|
384
|
-
humanLines: [
|
|
385
|
-
`Updated tenjin-cli ${current} -> ${latest}.`,
|
|
386
|
-
...refreshLines(refresh),
|
|
387
|
-
...refresh.notices,
|
|
388
|
-
...servers.stale > 0 ? [`! ${servers.check.detail}. ${servers.check.fix ?? ""}`.trim()] : []
|
|
389
|
-
]
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
var REFRESH_TIMEOUT_MS = 6e4;
|
|
393
|
-
async function refreshProfiles(ctx, deps) {
|
|
394
|
-
const home = deps.homeDir ?? homedir();
|
|
395
|
-
const candidates = [ctx.dataDir];
|
|
396
|
-
const fixFor = (dataDir) => manualFix(dataDir, home, ctx.dataDir);
|
|
397
|
-
const profiles = [];
|
|
398
|
-
const unrun = [];
|
|
399
|
-
for (const dataDir of candidates) {
|
|
400
|
-
if (isExistingDir(dataDir)) profiles.push(dataDir);
|
|
401
|
-
else unrun.push({ dataDir, reason: "It is not a directory.", fix: fixFor(dataDir) });
|
|
402
|
-
}
|
|
403
|
-
const entry = versionFreeEntry(deps.refreshCommand ?? process.argv[1]);
|
|
404
|
-
if (entry === null) {
|
|
405
|
-
const reason = "This build has no entry the update could safely re-execute.";
|
|
406
|
-
return {
|
|
407
|
-
profiles: [],
|
|
408
|
-
failed: candidates.map((d) => ({ dataDir: d, reason, fix: fixFor(d) })),
|
|
409
|
-
notices: [],
|
|
410
|
-
settingsInstallPending: false
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
const failed = [...unrun];
|
|
414
|
-
const notices = [];
|
|
415
|
-
let settingsInstallPending = false;
|
|
416
|
-
for (const dataDir of profiles) {
|
|
417
|
-
let tail = "";
|
|
418
|
-
const outcome = await (deps.spawnImpl ?? spawnCapture)(
|
|
419
|
-
process.execPath,
|
|
420
|
-
[entry, "install", "--refresh"],
|
|
421
|
-
{
|
|
422
|
-
cwd: homedir(),
|
|
423
|
-
timeoutMs: REFRESH_TIMEOUT_MS,
|
|
424
|
-
// TENJIN_DATA_DIR aims the child at this profile; the nudge opt-out is
|
|
425
|
-
// what keeps it from touching any other file in there (lib/update-check).
|
|
426
|
-
env: { TENJIN_DATA_DIR: dataDir, [NUDGE_OPT_OUT]: "1" }
|
|
427
|
-
},
|
|
428
|
-
(chunk) => {
|
|
429
|
-
tail = (tail + chunk).slice(-REFRESH_TAIL_LIMIT);
|
|
430
|
-
}
|
|
431
|
-
);
|
|
432
|
-
if (outcome.kind !== "exit" || outcome.code !== 0) {
|
|
433
|
-
failed.push({ dataDir, reason: refreshReason(outcome, tail), fix: fixFor(dataDir) });
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
const reported = envelopeData(tail);
|
|
437
|
-
for (const notice of noticesOf(reported)) if (!notices.includes(notice)) notices.push(notice);
|
|
438
|
-
const migration = reported?.migration;
|
|
439
|
-
if (migration?.state === "pending" || migration?.state === "blocked") {
|
|
440
|
-
settingsInstallPending = true;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return { profiles, failed, notices, settingsInstallPending };
|
|
444
|
-
}
|
|
445
|
-
function envelopeData(output) {
|
|
446
|
-
const lines = output.split("\n");
|
|
447
|
-
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
448
|
-
if (lines[i]?.trim() !== "{" && !lines[i]?.trim().startsWith('{"')) continue;
|
|
449
|
-
try {
|
|
450
|
-
const parsed = JSON.parse(lines.slice(i).join("\n"));
|
|
451
|
-
if (parsed?.ok === true && parsed.data !== null && typeof parsed.data === "object") {
|
|
452
|
-
return parsed.data;
|
|
453
|
-
}
|
|
454
|
-
} catch {
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
return null;
|
|
459
|
-
}
|
|
460
|
-
function noticesOf(data) {
|
|
461
|
-
const raw = data?.notices;
|
|
462
|
-
if (!Array.isArray(raw)) return [];
|
|
463
|
-
return raw.filter((n) => typeof n === "string").map((n) => sanitizeForTerminal(n).trim().slice(0, REASON_LIMIT)).filter((n) => n.length > 0).slice(0, 5);
|
|
464
|
-
}
|
|
465
|
-
var REFRESH_TAIL_LIMIT = 64e3;
|
|
466
|
-
var REASON_LIMIT = 300;
|
|
467
|
-
function refreshReason(outcome, output) {
|
|
468
|
-
const reported = envelopeMessage(output);
|
|
469
|
-
if (reported !== void 0) return reported;
|
|
470
|
-
if (outcome.kind === "timeout") return `It did not finish in ${REFRESH_TIMEOUT_MS / 1e3}s.`;
|
|
471
|
-
if (outcome.kind === "start-failed") return "The refresh could not be started.";
|
|
472
|
-
return `The refresh exited ${outcome.code} without reporting a reason.`;
|
|
473
|
-
}
|
|
474
|
-
function envelopeMessage(output) {
|
|
475
|
-
const lines = output.split("\n");
|
|
476
|
-
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
477
|
-
const line = lines[i]?.trim();
|
|
478
|
-
if (line === void 0 || !line.startsWith("{")) continue;
|
|
479
|
-
let parsed;
|
|
480
|
-
try {
|
|
481
|
-
parsed = JSON.parse(lines.slice(i).join("\n"));
|
|
482
|
-
} catch {
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
if (parsed?.ok !== false || typeof parsed.error?.message !== "string") continue;
|
|
486
|
-
const message = sanitizeForTerminal(parsed.error.message).trim();
|
|
487
|
-
if (message.length > 0) return message.slice(0, REASON_LIMIT);
|
|
488
|
-
}
|
|
489
|
-
return void 0;
|
|
490
|
-
}
|
|
491
|
-
function isExistingDir(path) {
|
|
492
|
-
return statSync2(path, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
493
|
-
}
|
|
494
|
-
function manualFix(dataDir, home, invoking) {
|
|
495
|
-
const bare = resolve(dataDir) === resolve(defaultDataDir(home)) && resolve(dataDir) === resolve(invoking);
|
|
496
|
-
const command = bare ? "tenjin install" : `TENJIN_DATA_DIR=${dataDir} tenjin install`;
|
|
497
|
-
return `Run \`${command}\` to bring the Claude Code plugin up to this version.`;
|
|
498
|
-
}
|
|
499
|
-
function versionFreeEntry(entry) {
|
|
500
|
-
if (entry === void 0 || entry.length === 0) return null;
|
|
501
|
-
const segs = entry.split(sep2);
|
|
502
|
-
const store = segs.indexOf(".pnpm");
|
|
503
|
-
if (store === -1) return segs.join(sep2);
|
|
504
|
-
const inner = segs.indexOf("node_modules", store);
|
|
505
|
-
if (inner === -1) return null;
|
|
506
|
-
const derived = [...segs.slice(0, store), ...segs.slice(inner + 1)].join(sep2);
|
|
507
|
-
return existsSync2(derived) ? derived : null;
|
|
508
|
-
}
|
|
509
|
-
function refreshLines(refresh) {
|
|
510
|
-
const failedDirs = new Set(refresh.failed.map((f) => f.dataDir));
|
|
511
|
-
const done = refresh.profiles.filter((p) => !failedDirs.has(p));
|
|
512
|
-
if (refresh.failed.length === 0) {
|
|
513
|
-
return [
|
|
514
|
-
done.length > 1 ? `Refreshed the Claude Code plugin for ${done.length} profiles: ${done.join(", ")}.` : `Refreshed the Claude Code plugin for ${done[0]}.`
|
|
515
|
-
];
|
|
516
|
-
}
|
|
517
|
-
const total = done.length + refresh.failed.length;
|
|
518
|
-
const lines = done.length > 0 ? [
|
|
519
|
-
`Refreshed the Claude Code plugin for ${done.length} of ${total} profiles: ${done.join(", ")}.`
|
|
520
|
-
] : [];
|
|
521
|
-
lines.push(`Could not refresh the Claude Code plugin for ${refresh.failed.length}:`);
|
|
522
|
-
lines.push(...refresh.failed.map((f) => `- ${f.dataDir}: ${f.reason} ${f.fix}`));
|
|
523
|
-
return lines;
|
|
524
|
-
}
|
|
525
|
-
var spawnCapture = (cmd, args, opts, onOutput) => new Promise((res) => {
|
|
526
|
-
let child;
|
|
527
|
-
try {
|
|
528
|
-
child = spawn(cmd, args, {
|
|
529
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
530
|
-
cwd: opts.cwd,
|
|
531
|
-
// Layered onto this process's environment rather than replacing it: the
|
|
532
|
-
// child is a Node CLI that needs PATH and HOME, and only the keys named
|
|
533
|
-
// here are being decided.
|
|
534
|
-
...opts.env !== void 0 ? { env: { ...process.env, ...opts.env } } : {}
|
|
535
|
-
});
|
|
536
|
-
} catch (cause) {
|
|
537
|
-
res({ kind: "start-failed", cause });
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
let timedOut = false;
|
|
541
|
-
const timer = setTimeout(() => {
|
|
542
|
-
timedOut = true;
|
|
543
|
-
child.kill("SIGKILL");
|
|
544
|
-
}, opts.timeoutMs);
|
|
545
|
-
child.stdout?.on("data", (chunk) => onOutput(chunk.toString()));
|
|
546
|
-
child.stderr?.on("data", (chunk) => onOutput(chunk.toString()));
|
|
547
|
-
child.on("error", (cause) => {
|
|
548
|
-
clearTimeout(timer);
|
|
549
|
-
res({ kind: "start-failed", cause });
|
|
550
|
-
});
|
|
551
|
-
child.on("close", (code) => {
|
|
552
|
-
clearTimeout(timer);
|
|
553
|
-
res(timedOut ? { kind: "timeout" } : { kind: "exit", code: code ?? 1 });
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
export {
|
|
558
|
-
readMcpServers,
|
|
559
|
-
runUpdate,
|
|
560
|
-
versionFreeEntry,
|
|
561
|
-
spawnCapture
|
|
562
|
-
};
|
|
563
|
-
//# sourceMappingURL=chunk-AO54FM4H.js.map
|