@emesoft/tokenhub 0.9.1 → 0.9.3
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 -0
- package/bin/tokenhub.js +6 -2
- package/claude-plugin/.claude-plugin/marketplace.json +5 -0
- package/claude-plugin/plugins/tokenhub-usage/.claude-plugin/plugin.json +8 -0
- package/claude-plugin/plugins/tokenhub-usage/hooks/hooks.json +1 -0
- package/claude-plugin/plugins/tokenhub-usage/hooks/register.tsx +242 -0
- package/claude-plugin/plugins/tokenhub-usage/types/index.d.ts +24 -0
- package/lib/install-log.d.ts +2 -0
- package/lib/install-log.js +46 -0
- package/lib/install-ui.d.ts +27 -0
- package/lib/install-ui.js +66 -0
- package/lib/model-picker.d.ts +1 -0
- package/lib/model-picker.js +13 -3
- package/lib/pair.d.ts +6 -0
- package/lib/pair.js +72 -29
- package/lib/progress.d.ts +39 -0
- package/lib/progress.js +231 -0
- package/lib/remote-download.d.ts +4 -0
- package/lib/remote-download.js +67 -7
- package/lib/remote-install.d.ts +4 -1
- package/lib/remote-install.js +145 -53
- package/lib/remote-text.js +57 -0
- package/package.json +4 -1
package/lib/remote-install.js
CHANGED
|
@@ -4,9 +4,12 @@ import { createServer } from "node:net";
|
|
|
4
4
|
import { hostname } from "node:os";
|
|
5
5
|
import { basename, dirname, join } from "node:path";
|
|
6
6
|
import { findOnPath, findRealClaude, normalizeDir } from "./claude-shim.js";
|
|
7
|
+
import { createInstallUi } from "./install-ui.js";
|
|
8
|
+
import { installLogPath } from "./install-log.js";
|
|
7
9
|
import { ensureLauncher, hasPsBlock, launcherWins, realWindowsSystem, removeLauncher } from "./launcher-precedence.js";
|
|
8
10
|
import { pairRemote, checkRemoteToken, revokeRemoteToken } from "./remote.js";
|
|
9
|
-
import { downloadRemote, HOOK_FILE, readCurrent } from "./remote-download.js";
|
|
11
|
+
import { compareVersions, downloadRemote, HOOK_FILE, pruneVersions, readCurrent, stableHookPath, syncStableHook } from "./remote-download.js";
|
|
12
|
+
import { formatTransfer } from "./progress.js";
|
|
10
13
|
import { appConfigDir, exeName, legacyConfigDir, remoteDir, shimDir } from "./remote-paths.js";
|
|
11
14
|
import { installShimFiles, removeShimFiles, shimInstalled, shimPresent } from "./remote-shim.js";
|
|
12
15
|
import { detectLang, text } from "./remote-text.js";
|
|
@@ -154,20 +157,66 @@ async function runHookScript(verb, { script, claudeDir, node, run }) {
|
|
|
154
157
|
const lines = (result.code === 0 ? result.stdout : result.stderr || result.stdout).split(/\r?\n/).filter((line) => line.trim() !== "");
|
|
155
158
|
return { ok: result.code === 0, output: lines };
|
|
156
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* The `version` the running host wrote into `host.json` (empty from a host older than 0.1.5, which wrote none).
|
|
162
|
+
* @param {string} appDir The app config folder.
|
|
163
|
+
* @returns {string} The version, or "" when there is none or the file is unreadable.
|
|
164
|
+
*/
|
|
165
|
+
function hostVersion(appDir) {
|
|
166
|
+
try {
|
|
167
|
+
const version = JSON.parse(readFileSync(join(appDir, "host.json"), "utf8")).version;
|
|
168
|
+
return typeof version === "string" ? version : "";
|
|
169
|
+
} catch {
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* After an update: a Remote daemon of an older version that is still running would keep serving the old code, so it is stopped when it
|
|
175
|
+
* hosts no sessions (the next `claude` starts the new one), and the user is told to close their Claude windows when it does. A daemon that
|
|
176
|
+
* is not ours, or is as new as the installed version, is left alone.
|
|
177
|
+
*
|
|
178
|
+
* @param {object} options
|
|
179
|
+
* @param {string} options.appDir The app config folder (`host.json`).
|
|
180
|
+
* @param {string} options.root The Remote folder.
|
|
181
|
+
* @param {string} options.version The version just installed.
|
|
182
|
+
* @param {string} options.platform Node platform name.
|
|
183
|
+
* @param {Record<string, string | undefined>} options.env Environment for `tfc`.
|
|
184
|
+
* @param {Proc} options.proc Process facts.
|
|
185
|
+
* @param {import("./run.js").Runner} options.run Runs `tfc ls`.
|
|
186
|
+
* @param {import("./install-ui.js").InstallUi} options.ui Output.
|
|
187
|
+
* @param {Record<string, any>} options.t The messages.
|
|
188
|
+
* @returns {Promise<void>}
|
|
189
|
+
*/
|
|
190
|
+
async function retireOldDaemon({ appDir, root, version, platform, env, proc, run, ui, t }) {
|
|
191
|
+
const state = await daemonState({ appDir, root, platform, proc });
|
|
192
|
+
if (state.state !== "running") return;
|
|
193
|
+
const running = hostVersion(appDir);
|
|
194
|
+
if (running && compareVersions(running, version) >= 0) return;
|
|
195
|
+
const stopped = await stopDaemon({ appDir, root, platform, force: false, env, proc, run });
|
|
196
|
+
if (stopped.status === "stopped") {
|
|
197
|
+
ui.detail(t.oldDaemonStopped(running || t.versionUnknown, version));
|
|
198
|
+
pruneVersions(root, version);
|
|
199
|
+
} else if (stopped.status === "busy") {
|
|
200
|
+
ui.say(t.closeWindows(version));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
157
203
|
/**
|
|
158
204
|
* Set up TokenHub Remote on this computer (the step `connect` offers after the settings are written).
|
|
159
205
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
206
|
+
* Four steps, shown on the progress bar (see `createInstallUi`): download the daemon (verified, nothing in place before it checks out;
|
|
207
|
+
* an older daemon that still runs is stopped when it hosts no sessions); pair this computer with the `remote` kind, or keep the token it
|
|
208
|
+
* already has when the pool still accepts it, and write `relay.json`; install the Claude Code hooks and `/tf-remote` by running the hook script's own
|
|
209
|
+
* `install` on the stable copy `<remote>/current/tf-remote-hook.mjs` (so `settings.json` never names a version); and, after asking, the
|
|
210
|
+
* `claude` launcher and its PATH entry. The download comes first so a failed download does not leave a pairing behind. What was done is
|
|
211
|
+
* recorded in `<remote>/install.json` as it goes. Sizes, paths, diffs and hook output go to `<remote>/install.log`, and are printed only with `--verbose`.
|
|
164
212
|
*
|
|
165
213
|
* @param {object} options
|
|
166
214
|
* @param {string} options.pool Pool address from `resolvePoolUrl`.
|
|
167
215
|
* @param {string} [options.baseUrl] Address the key was issued by (the public origin); defaults to `pool`.
|
|
168
216
|
* @param {string} options.settingsFile Claude Code's `settings.json`; its folder gets the hooks and `/tf-remote`.
|
|
169
217
|
* @param {"en" | "vi"} [options.lang] Message language.
|
|
170
|
-
* @param {(line: string) => void} [options.log] Output sink.
|
|
218
|
+
* @param {(line: string) => void} [options.log] Output sink for the default `ui` (plain step lines, no bar).
|
|
219
|
+
* @param {import("./install-ui.js").InstallUi} [options.ui] The caller's output (bar, plain lines, log). Without it the installer makes its own plain one, finishes it and prints the summary; with it the summary is returned for the caller to print after `finish`.
|
|
171
220
|
* @param {(url: string) => void} options.open Browser opener.
|
|
172
221
|
* @param {AbortSignal} [options.signal] Aborts the flow (Ctrl+C).
|
|
173
222
|
* @param {(question: string, defaultYes?: boolean) => Promise<boolean>} options.ask Yes/no prompt (false without a terminal).
|
|
@@ -181,10 +230,11 @@ async function runHookScript(verb, { script, claudeDir, node, run }) {
|
|
|
181
230
|
* @param {string} [options.node] Node program that runs the hook script (this one by default).
|
|
182
231
|
* @param {typeof fetch} [options.fetchImpl] `fetch` override for tests.
|
|
183
232
|
* @param {import("./run.js").Runner} [options.run] Process runner for `xattr`, `icacls` and the hook script (tests replace it).
|
|
233
|
+
* @param {Proc} [options.proc] Process facts for the old-daemon check (tests replace them).
|
|
184
234
|
* @param {ReturnType<typeof windowsUserPath>} [options.userPath] Registry access for the PATH edit (tests replace it).
|
|
185
235
|
* @param {typeof pickHookPort} [options.pickPort] Chooses the hook port when `relay.json` has none (tests replace it).
|
|
186
236
|
* @param {import("./launcher-precedence.js").WinSystem} [options.launcherSys] Windows access for the launcher check: Machine Path, PowerShell profiles and policies, elevation (tests replace it).
|
|
187
|
-
* @returns {Promise<{ ok: true, version: string, shim: boolean, launcher?: string } | { ok: false, code: number }>} The outcome (`launcher`: what makes `claude` start it on Windows, see `ensureLauncher`); on failure the exit code.
|
|
237
|
+
* @returns {Promise<{ ok: true, version: string, shim: boolean, launcher?: string, summary: string[] } | { ok: false, code: number }>} The outcome (`launcher`: what makes `claude` start it on Windows, see `ensureLauncher`; `summary`: the closing lines); on failure the exit code.
|
|
188
238
|
*/
|
|
189
239
|
export async function installRemote({
|
|
190
240
|
pool,
|
|
@@ -192,9 +242,10 @@ export async function installRemote({
|
|
|
192
242
|
settingsFile,
|
|
193
243
|
lang = detectLang(),
|
|
194
244
|
log = console.log,
|
|
245
|
+
ui: given,
|
|
195
246
|
open,
|
|
196
247
|
signal,
|
|
197
|
-
ask,
|
|
248
|
+
ask: rawAsk,
|
|
198
249
|
shim,
|
|
199
250
|
deviceName = hostname(),
|
|
200
251
|
intervalOverrideMs,
|
|
@@ -205,13 +256,16 @@ export async function installRemote({
|
|
|
205
256
|
node = process.execPath,
|
|
206
257
|
fetchImpl = fetch,
|
|
207
258
|
run = defaultRun,
|
|
259
|
+
proc,
|
|
208
260
|
userPath,
|
|
209
261
|
pickPort = pickHookPort,
|
|
210
262
|
launcherSys,
|
|
211
263
|
}) {
|
|
212
264
|
const t = text(lang);
|
|
265
|
+
const ui = given ?? createInstallUi({ log, env, plain: true, total: 4 });
|
|
266
|
+
const ask = ui.ask(rawAsk);
|
|
213
267
|
if (platform !== "win32" && platform !== "darwin") {
|
|
214
|
-
|
|
268
|
+
ui.say(t.unsupported(platform));
|
|
215
269
|
return { ok: false, code: 1 };
|
|
216
270
|
}
|
|
217
271
|
const root = remoteDir(env, home);
|
|
@@ -219,21 +273,44 @@ export async function installRemote({
|
|
|
219
273
|
const relayFile = join(appConfigDir(env, home), "relay.json");
|
|
220
274
|
const legacyFile = join(legacyConfigDir(env, home), "relay.json");
|
|
221
275
|
const claudeDir = dirname(settingsFile);
|
|
276
|
+
const logFile = installLogPath(root);
|
|
222
277
|
let origin = baseUrl ?? pool;
|
|
278
|
+
ui.useLog(logFile, "tokenhub connect --remote");
|
|
279
|
+
/** An error the user must see, with where the details are. @param {string} message What went wrong. @returns {{ ok: false, code: number }} */
|
|
280
|
+
const fail = (message, code = 1) => {
|
|
281
|
+
ui.say(message);
|
|
282
|
+
ui.say(t.seeLog(logFile));
|
|
283
|
+
return { ok: false, code };
|
|
284
|
+
};
|
|
223
285
|
|
|
224
|
-
|
|
225
|
-
|
|
286
|
+
// Step 4: download (or keep) the daemon.
|
|
287
|
+
ui.begin(t.stepCheck);
|
|
226
288
|
let download;
|
|
227
289
|
try {
|
|
228
|
-
download = await downloadRemote({
|
|
290
|
+
download = await downloadRemote({
|
|
291
|
+
pool,
|
|
292
|
+
root,
|
|
293
|
+
platform,
|
|
294
|
+
arch,
|
|
295
|
+
log: (line) => ui.detail(line.trim()),
|
|
296
|
+
fetchImpl,
|
|
297
|
+
signal,
|
|
298
|
+
run,
|
|
299
|
+
onProgress: ({ version, done, total }) => ui.update({ label: t.stepDownload(version, total ? formatTransfer(done, total) : ""), within: total ? done / total : 0 }),
|
|
300
|
+
});
|
|
229
301
|
} catch (error) {
|
|
230
|
-
|
|
231
|
-
|
|
302
|
+
if (signal?.aborted) {
|
|
303
|
+
ui.say("Cancelled.");
|
|
304
|
+
return { ok: false, code: 130 };
|
|
305
|
+
}
|
|
306
|
+
return fail(t.failed(error.message));
|
|
232
307
|
}
|
|
233
|
-
log(download.action === "updated" ? t.updated(download.version, download.previous) : download.action === "repaired" ? t.repaired(download.version) : download.action === "kept" ? t.kept(download.version) : t.installed(download.version));
|
|
234
308
|
saveRecord(root, { version: download.version });
|
|
309
|
+
await retireOldDaemon({ appDir: dirname(relayFile), root, version: download.version, platform, env, proc: proc ?? realProc(platform, run), run, ui, t });
|
|
310
|
+
ui.complete(download.action === "updated" ? t.doneDownload.updated(download.version, download.previous) : t.doneDownload[download.action](download.version));
|
|
235
311
|
|
|
236
|
-
//
|
|
312
|
+
// Step 5: pair this computer (keep the token it already has unless the pool says it was revoked, or it is for another pool).
|
|
313
|
+
ui.begin(t.stepPair);
|
|
237
314
|
const record = readRecord(root);
|
|
238
315
|
let existing = readRelayJson(relayFile);
|
|
239
316
|
// Version 0.1.0 wrote relay.json into TicketFlow's config folder. When that file is ours, its token carries over and the file goes
|
|
@@ -250,22 +327,21 @@ export async function installRemote({
|
|
|
250
327
|
let token;
|
|
251
328
|
let name = deviceName;
|
|
252
329
|
let relayOrigin;
|
|
330
|
+
let pairedBefore = false;
|
|
253
331
|
if (existing?.deviceToken && record?.pool === origin && record.tokenSha256 === sha256(existing.deviceToken)) {
|
|
254
332
|
const check = await checkRemoteToken({ pool: origin, token: existing.deviceToken, signal, fetchImpl });
|
|
255
333
|
if (check.status !== "revoked") {
|
|
256
334
|
token = existing.deviceToken;
|
|
257
335
|
name = check.status === "valid" ? check.deviceName : (existing.name ?? deviceName);
|
|
258
336
|
relayOrigin = check.status === "valid" ? check.relayOrigin : undefined;
|
|
259
|
-
|
|
337
|
+
pairedBefore = true;
|
|
338
|
+
ui.detail(t.keepingToken(name));
|
|
260
339
|
}
|
|
261
340
|
}
|
|
262
341
|
if (!token) {
|
|
263
|
-
|
|
264
|
-
const paired = await pairRemote({ pool, deviceName, log, open, signal, intervalOverrideMs, fetchImpl });
|
|
265
|
-
if (!paired.ok) {
|
|
266
|
-
log(t.pairingFailed);
|
|
267
|
-
return { ok: false, code: paired.code };
|
|
268
|
-
}
|
|
342
|
+
ui.say(t.pairing);
|
|
343
|
+
const paired = await pairRemote({ pool, deviceName, log: ui.say, open, signal, intervalOverrideMs, fetchImpl });
|
|
344
|
+
if (!paired.ok) return paired.code === 130 ? { ok: false, code: 130 } : fail(t.pairingFailed, paired.code);
|
|
269
345
|
token = paired.token;
|
|
270
346
|
origin = paired.baseUrl;
|
|
271
347
|
const check = await checkRemoteToken({ pool: origin, token, signal, fetchImpl });
|
|
@@ -276,38 +352,53 @@ export async function installRemote({
|
|
|
276
352
|
// Keep other keys of an existing relay.json (a hook port, say); the three the daemon needs are ours. A new file gets a free hook port.
|
|
277
353
|
const hookPort = existing?.hookPort ?? (await pickPort());
|
|
278
354
|
const restricted = await writeRelayJson(relayFile, { ...existing, relayUrl, deviceToken: token, name, ...(hookPort ? { hookPort } : {}) }, { platform, env, run });
|
|
279
|
-
if (!restricted)
|
|
355
|
+
if (!restricted) ui.say(`(could not restrict access to ${relayFile}; the folder's own permissions apply)`);
|
|
280
356
|
if (legacy) {
|
|
281
357
|
rmSync(legacyFile, { force: true });
|
|
282
|
-
|
|
358
|
+
ui.detail(t.movedConfig(legacyFile, relayFile));
|
|
283
359
|
}
|
|
284
360
|
saveRecord(root, { pool: origin, deviceName: name, tokenSha256: sha256(token), relayFile });
|
|
361
|
+
ui.complete(pairedBefore ? t.donePairedKept(name) : t.donePaired(name));
|
|
285
362
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
363
|
+
// Step 6: the hooks and /tf-remote. Settings name the stable copy of the script, so an update leaves settings.json alone.
|
|
364
|
+
ui.begin(t.stepHooks);
|
|
365
|
+
let hooks;
|
|
366
|
+
try {
|
|
367
|
+
const stable = syncStableHook(root, join(download.dir, HOOK_FILE));
|
|
368
|
+
ui.detail(`hook script: ${stable.path} (${stable.changed ? "updated" : "unchanged"})`);
|
|
369
|
+
hooks = await runHookScript("install", { script: stable.path, claudeDir, node, run });
|
|
370
|
+
} catch (error) {
|
|
371
|
+
hooks = { ok: false, output: [String(error.message ?? error)] };
|
|
292
372
|
}
|
|
373
|
+
for (const line of hooks.output) ui.detail(line);
|
|
374
|
+
if (!hooks.ok) return fail(t.hooksFailed(hooks.output.at(-1) ?? "?"));
|
|
293
375
|
saveRecord(root, { claudeDir });
|
|
376
|
+
ui.complete(t.doneHooks);
|
|
294
377
|
|
|
378
|
+
// Step 7: the launcher.
|
|
379
|
+
ui.begin(t.stepLauncher);
|
|
295
380
|
const registry = userPath ?? windowsUserPath({ run });
|
|
296
|
-
const
|
|
381
|
+
const shimBefore = shimInstalled(binDir, platform);
|
|
382
|
+
const shimOn = await offerShim({ shim, ask, ui, t, binDir, platform, env, home, run, userPath: registry, root });
|
|
297
383
|
// Windows: the user Path is only half of what a new process gets (the Machine Path comes first), so check that `claude` would win.
|
|
298
|
-
|
|
384
|
+
const launcher = shimOn && platform === "win32" ? await ensureLauncher({ binDir, env, userPath: registry, sys: launcherSys ?? realWindowsSystem({ run }), ask, log: ui.say, t, previous: record?.launcher }) : undefined;
|
|
299
385
|
if (launcher) saveRecord(root, { launcher: launcher.record });
|
|
386
|
+
ui.complete(t.doneLauncher(!shimOn ? "skipped" : shimBefore ? "kept" : "on"));
|
|
387
|
+
|
|
300
388
|
const tfc = join(download.dir, exeName("tfc", platform));
|
|
301
389
|
const claudeCmd = join(binDir, "claude.cmd");
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
390
|
+
const summary = [
|
|
391
|
+
t.ready(download.version, name),
|
|
392
|
+
!shimOn ? t.nextNoShim(tfc) : launcher?.how === "profile" ? t.nextPowerShell : launcher?.how === "none" ? t.nextByHand(claudeCmd) : t.nextNew,
|
|
393
|
+
...(launcher?.how === "profile" ? [t.noteShells] : []),
|
|
394
|
+
t.manage(`${origin}/member/remote`),
|
|
395
|
+
t.details(logFile),
|
|
396
|
+
];
|
|
397
|
+
if (!given) {
|
|
398
|
+
ui.finish(t.finished);
|
|
399
|
+
for (const line of summary) ui.say(line);
|
|
400
|
+
}
|
|
401
|
+
return { ok: true, version: download.version, shim: shimOn, launcher: launcher?.how, summary };
|
|
311
402
|
}
|
|
312
403
|
/** @param {Record<string, any> | undefined} existing An existing `relay.json`. @returns {string | undefined} The origin its `relayUrl` was made from. */
|
|
313
404
|
function relayOriginFromFile(existing) {
|
|
@@ -321,32 +412,33 @@ function relayOriginFromFile(existing) {
|
|
|
321
412
|
/**
|
|
322
413
|
* The launcher step: explain it, ask (unless a flag or an earlier install already decided), write the shim, edit PATH.
|
|
323
414
|
*
|
|
324
|
-
* @param {object} options What `installRemote` has: `shim`, `ask
|
|
415
|
+
* @param {object} options What `installRemote` has: `shim`, `ask` (already wrapped by the ui), `ui`, `t`, `binDir`, `platform`, `env`, `home`, `run`, `userPath`, `root`.
|
|
325
416
|
* @returns {Promise<boolean>} Whether the launcher is installed afterwards.
|
|
326
417
|
*/
|
|
327
|
-
async function offerShim({ shim, ask,
|
|
418
|
+
async function offerShim({ shim, ask, ui, t, binDir, platform, env, home, run, userPath, root }) {
|
|
328
419
|
const already = shimInstalled(binDir, platform);
|
|
329
420
|
let want = shim ?? already;
|
|
330
421
|
if (shim === undefined && !already) {
|
|
331
|
-
for (const line of t.shimIntro(binDir, platform === "win32" ? t.wherePath : t.whereProfile))
|
|
422
|
+
for (const line of t.shimIntro(binDir, platform === "win32" ? t.wherePath : t.whereProfile)) ui.say(line);
|
|
332
423
|
want = await ask(t.askShim, true);
|
|
333
424
|
}
|
|
334
425
|
if (!want) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
426
|
+
ui.detail(t.shimSkipped);
|
|
427
|
+
ui.detail(` ${join(readCurrent(root)?.dir ?? "", exeName("tfc", platform))}`);
|
|
428
|
+
ui.detail(t.shimSkippedHint);
|
|
338
429
|
return false;
|
|
339
430
|
}
|
|
340
431
|
const realClaude = findRealClaude({ pathValue: env.PATH ?? env.Path ?? "", shimDirs: [binDir], env, platform, home });
|
|
341
|
-
if (!realClaude)
|
|
432
|
+
if (!realClaude) ui.say(t.shimNoClaude);
|
|
342
433
|
installShimFiles({ binDir, platform, realClaude });
|
|
343
|
-
|
|
434
|
+
ui.detail(t.shimOn(binDir));
|
|
344
435
|
try {
|
|
345
436
|
const edited = await addBinToPath({ dir: binDir, platform, home, userPath: userPath ?? windowsUserPath({ run }) });
|
|
346
437
|
saveRecord(root, { shim: { binDir, targets: edited.targets } });
|
|
438
|
+
for (const target of edited.targets) ui.detail(`PATH: ${target.kind}${target.file ? ` ${target.file}` : ""}`);
|
|
347
439
|
} catch (error) {
|
|
348
440
|
saveRecord(root, { shim: { binDir, targets: [] } });
|
|
349
|
-
|
|
441
|
+
ui.say(t.shimPathFailed(error.message));
|
|
350
442
|
}
|
|
351
443
|
return true;
|
|
352
444
|
}
|
|
@@ -503,8 +595,8 @@ export async function disconnectRemote({ settingsFile, lang = detectLang(), log
|
|
|
503
595
|
|
|
504
596
|
const claudeDir = record?.claudeDir ?? dirname(settingsFile);
|
|
505
597
|
const current = readCurrent(root);
|
|
506
|
-
const script = current ? join(current.dir, HOOK_FILE) : undefined;
|
|
507
|
-
if (script
|
|
598
|
+
const script = [stableHookPath(root), current ? join(current.dir, HOOK_FILE) : undefined].find((file) => file && existsSync(file));
|
|
599
|
+
if (script) {
|
|
508
600
|
const hooks = await runHookScript("uninstall", { script, claudeDir, node, run });
|
|
509
601
|
if (hooks.ok) log(t.hooksRemoved);
|
|
510
602
|
else log(t.hooksStay(claudeDir));
|
package/lib/remote-text.js
CHANGED
|
@@ -71,6 +71,35 @@ const TEXT = {
|
|
|
71
71
|
lineShim: (on) => ` Launcher: ${on ? "on: `claude` starts through Remote" : "off"}`,
|
|
72
72
|
next: "Next: open a NEW terminal, run `claude`, type /tf-remote and scan the QR code with your phone.",
|
|
73
73
|
nextNoShim: (tfc) => `Next: run \`${tfc}\` instead of \`claude\`, type /tf-remote and scan the QR code with your phone.`,
|
|
74
|
+
// the bar: what is happening (shown while it runs), and what a finished step says (the plain line)
|
|
75
|
+
stepKey: "Pairing with your gateway…",
|
|
76
|
+
stepStatusLine: "Setting up the status line…",
|
|
77
|
+
stepPicker: "Setting up the model picker…",
|
|
78
|
+
stepCheck: "Checking TokenHub Remote…",
|
|
79
|
+
stepDownload: (version, transfer) => `Downloading Remote ${version}${transfer ? ` · ${transfer}` : ""}`,
|
|
80
|
+
stepPair: "Pairing this computer…",
|
|
81
|
+
stepHooks: "Adding hooks and /tf-remote…",
|
|
82
|
+
stepLauncher: "Setting up the launcher…",
|
|
83
|
+
doneKey: "Gateway key saved",
|
|
84
|
+
doneStatusLine: (result) => ({ installed: "Status line added", updated: "Status line refreshed", kept: "Status line left as it was" })[result] ?? "Status line skipped",
|
|
85
|
+
donePicker: (installed) => (installed ? "Model picker installed" : "Model picker skipped"),
|
|
86
|
+
doneDownload: { installed: (v) => `Remote ${v} downloaded`, updated: (v, previous) => `Remote updated to ${v} (was ${previous})`, repaired: (v) => `Remote ${v} reinstalled`, kept: (v) => `Remote ${v} already installed` },
|
|
87
|
+
donePaired: (name) => `Computer paired as ${name}`,
|
|
88
|
+
donePairedKept: (name) => `Computer already paired as ${name}`,
|
|
89
|
+
doneHooks: "Hooks and /tf-remote ready",
|
|
90
|
+
doneLauncher: (how) => ({ on: "Launcher installed", kept: "Launcher already in place", skipped: "Launcher skipped" })[how] ?? "Launcher skipped",
|
|
91
|
+
finished: "Done",
|
|
92
|
+
// the summary
|
|
93
|
+
ready: (version, name) => `TokenHub Remote ${version} is ready on ${name}.`,
|
|
94
|
+
nextNew: "Next: open a new terminal, run `claude`, type /tf-remote and scan the QR.",
|
|
95
|
+
nextPowerShell: "Next: open a new PowerShell window, run `claude`, type /tf-remote and scan the QR.",
|
|
96
|
+
noteShells: "cmd and Git Bash still start Claude without Remote: run `tokenhub connect --remote` again to cover them.",
|
|
97
|
+
manage: (url) => `Manage your computers: ${url}`,
|
|
98
|
+
details: (file) => `(details: ${file})`,
|
|
99
|
+
seeLog: (file) => `Details: ${file}`,
|
|
100
|
+
closeWindows: (version) => `Close your open Claude windows to start using Remote ${version}`,
|
|
101
|
+
versionUnknown: "unknown",
|
|
102
|
+
oldDaemonStopped: (previous, version) => `Stopped the Remote daemon of version ${previous}; the next claude starts ${version}.`,
|
|
74
103
|
// disconnect
|
|
75
104
|
busy: (n) => `${n === undefined ? "Hosted Claude sessions" : `${n} hosted Claude session(s)`} may be running through TokenHub Remote. Close them (or run \`tokenhub disconnect --force\` to stop them) and run this again. Nothing was changed.`,
|
|
76
105
|
stopped: "Stopped the Remote daemon.",
|
|
@@ -160,6 +189,34 @@ const TEXT = {
|
|
|
160
189
|
lineShim: (on) => ` Khởi chạy: ${on ? "bật: `claude` mở qua Remote" : "tắt"}`,
|
|
161
190
|
next: "Tiếp theo: mở cửa sổ terminal MỚI, chạy `claude`, gõ /tf-remote rồi quét mã QR bằng điện thoại.",
|
|
162
191
|
nextNoShim: (tfc) => `Tiếp theo: chạy \`${tfc}\` thay cho \`claude\`, gõ /tf-remote rồi quét mã QR bằng điện thoại.`,
|
|
192
|
+
// thanh tiến trình: việc đang làm (hiện khi chạy), và dòng của một bước đã xong (chế độ chữ thường)
|
|
193
|
+
stepKey: "Đang ghép với gateway…",
|
|
194
|
+
stepStatusLine: "Đang cài dòng trạng thái…",
|
|
195
|
+
stepPicker: "Đang cài bộ chọn model…",
|
|
196
|
+
stepCheck: "Đang kiểm tra TokenHub Remote…",
|
|
197
|
+
stepDownload: (version, transfer) => `Đang tải Remote ${version}${transfer ? ` · ${transfer}` : ""}`,
|
|
198
|
+
stepPair: "Đang ghép máy này…",
|
|
199
|
+
stepHooks: "Đang thêm hook và /tf-remote…",
|
|
200
|
+
stepLauncher: "Đang cài trình khởi chạy…",
|
|
201
|
+
doneKey: "Đã lưu khóa gateway",
|
|
202
|
+
doneStatusLine: (result) => ({ installed: "Đã thêm dòng trạng thái", updated: "Đã làm mới dòng trạng thái", kept: "Giữ nguyên dòng trạng thái cũ" })[result] ?? "Bỏ qua dòng trạng thái",
|
|
203
|
+
donePicker: (installed) => (installed ? "Đã cài bộ chọn model" : "Bỏ qua bộ chọn model"),
|
|
204
|
+
doneDownload: { installed: (v) => `Đã tải Remote ${v}`, updated: (v, previous) => `Đã cập nhật Remote lên ${v} (trước đó ${previous})`, repaired: (v) => `Đã cài lại Remote ${v}`, kept: (v) => `Remote ${v} đã được cài` },
|
|
205
|
+
donePaired: (name) => `Đã ghép máy với tên ${name}`,
|
|
206
|
+
donePairedKept: (name) => `Máy đã được ghép với tên ${name}`,
|
|
207
|
+
doneHooks: "Hook và /tf-remote đã sẵn sàng",
|
|
208
|
+
doneLauncher: (how) => ({ on: "Đã cài trình khởi chạy", kept: "Trình khởi chạy đã có sẵn", skipped: "Bỏ qua trình khởi chạy" })[how] ?? "Bỏ qua trình khởi chạy",
|
|
209
|
+
finished: "Xong",
|
|
210
|
+
ready: (version, name) => `TokenHub Remote ${version} đã sẵn sàng trên ${name}.`,
|
|
211
|
+
nextNew: "Tiếp theo: mở terminal mới, chạy `claude`, gõ /tf-remote rồi quét mã QR.",
|
|
212
|
+
nextPowerShell: "Tiếp theo: mở cửa sổ PowerShell mới, chạy `claude`, gõ /tf-remote rồi quét mã QR.",
|
|
213
|
+
noteShells: "cmd và Git Bash vẫn mở Claude không có Remote: chạy lại `tokenhub connect --remote` để áp dụng cho chúng.",
|
|
214
|
+
manage: (url) => `Quản lý các máy của bạn: ${url}`,
|
|
215
|
+
details: (file) => `(chi tiết: ${file})`,
|
|
216
|
+
seeLog: (file) => `Chi tiết: ${file}`,
|
|
217
|
+
closeWindows: (version) => `Hãy đóng các cửa sổ Claude đang mở để dùng Remote ${version}`,
|
|
218
|
+
versionUnknown: "không rõ",
|
|
219
|
+
oldDaemonStopped: (previous, version) => `Đã dừng daemon Remote phiên bản ${previous}; lần chạy claude kế tiếp sẽ dùng ${version}.`,
|
|
163
220
|
busy: (n) => `${n === undefined ? "Có thể còn phiên Claude" : `Còn ${n} phiên Claude`} đang chạy qua TokenHub Remote. Hãy đóng chúng (hoặc chạy \`tokenhub disconnect --force\` để dừng) rồi chạy lại. Chưa có gì bị thay đổi.`,
|
|
164
221
|
stopped: "Đã dừng daemon Remote.",
|
|
165
222
|
revoked: "Đã thu hồi token Remote của máy này trên pool.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emesoft/tokenhub",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Connect Claude Code to a TokenHub pool in one command, and track your spend from the terminal",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"claude-plugin/plugins/tokenhub-models/.claude-plugin",
|
|
27
27
|
"claude-plugin/plugins/tokenhub-models/hooks",
|
|
28
28
|
"claude-plugin/plugins/tokenhub-models/types",
|
|
29
|
+
"claude-plugin/plugins/tokenhub-usage/.claude-plugin",
|
|
30
|
+
"claude-plugin/plugins/tokenhub-usage/hooks",
|
|
31
|
+
"claude-plugin/plugins/tokenhub-usage/types",
|
|
29
32
|
"README.md",
|
|
30
33
|
"LICENSE"
|
|
31
34
|
],
|