tokenmaxxing 1.78.0 → 1.79.0
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/package.json +1 -1
- package/src/cli/doctor.ts +4 -4
- package/src/cli/serve.ts +2 -2
- package/src/lib/claude.ts +3 -3
- package/src/lib/install.ts +112 -183
- package/src/main.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenmaxxing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.79.0",
|
|
4
4
|
"description": "Automatic Claude Code account switching: pool multiple accounts, start each session on its own account, and resume a session on a fresher account when quota fills.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/cli/doctor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { CLAUDE_BIN, verifyRealBin } from "../lib/claudebin.ts";
|
|
3
3
|
import { checkSettings, installedBin } from "../lib/settings.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { activationHint, CHECK_JOB, codexStoreHookTrust, findClaudeShadowers, HUB_JOB, isBinDirAhead, jobHealthy, shellRcPath } from "../lib/install.ts";
|
|
5
5
|
import { errorMessage } from "../lib/log.ts";
|
|
6
6
|
import { claudePool, codexPool, paths } from "../lib/paths.ts";
|
|
7
7
|
import { loadAccounts, loadConfig } from "../lib/state.ts";
|
|
@@ -29,10 +29,10 @@ export async function cmdDoctor(): Promise<number> {
|
|
|
29
29
|
check(s.stopOk, "Stop hook installed in settings.json", "run `tokenmaxxing init`");
|
|
30
30
|
check(s.stopFailureOk, "StopFailure hook installed in settings.json", "run `tokenmaxxing init`");
|
|
31
31
|
check(s.sessionStartOk, "SessionStart hook installed in settings.json", "run `tokenmaxxing init`");
|
|
32
|
-
check(
|
|
32
|
+
check(jobHealthy(CHECK_JOB), "periodic check timer active", activationHint(CHECK_JOB));
|
|
33
33
|
if (existsSync(paths.supervisorLink)) {
|
|
34
|
-
if (
|
|
35
|
-
else check(
|
|
34
|
+
if (HUB_JOB.skip()) note("usage hub service is owned outside init (TOKENMAXXING_SKIP_HUB set) - not verified here");
|
|
35
|
+
else check(jobHealthy(HUB_JOB), "usage hub service active", "run `tokenmaxxing init` (it writes the unit and activates it)");
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
const idx = loadAccounts(claudePool);
|
package/src/cli/serve.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { claude } from "../lib/claude.ts";
|
|
|
7
7
|
import { codex, observeCodex } from "../lib/codex.ts";
|
|
8
8
|
import { CODEX_USAGE_URL } from "../lib/codexusage.ts";
|
|
9
9
|
import { errorMessage, log } from "../lib/log.ts";
|
|
10
|
-
import {
|
|
10
|
+
import { deactivationHint, HUB_JOB } from "../lib/install.ts";
|
|
11
11
|
import { paths } from "../lib/paths.ts";
|
|
12
12
|
import { isExhausted, thresholdBars } from "../lib/picker.ts";
|
|
13
13
|
import type { Provider } from "../lib/provider.ts";
|
|
@@ -215,7 +215,7 @@ export async function cmdServe(args: string[]): Promise<number> {
|
|
|
215
215
|
},
|
|
216
216
|
});
|
|
217
217
|
} catch (e) {
|
|
218
|
-
emitError({ message: `cannot bind localhost:${cfg.hub.port}: ${errorMessage(e)} (another \`tokenmaxxing serve\` or the usage hub service may already hold the port - stop it first: ${
|
|
218
|
+
emitError({ message: `cannot bind localhost:${cfg.hub.port}: ${errorMessage(e)} (another \`tokenmaxxing serve\` or the usage hub service may already hold the port - stop it first: ${deactivationHint(HUB_JOB)})` });
|
|
219
219
|
return 1;
|
|
220
220
|
}
|
|
221
221
|
console.log(`${c.green("✓")} serving the CLIProxyAPI-compatible usage API at http://localhost:${server.port}/v0/management`);
|
package/src/lib/claude.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { readItem, writeItem, deleteItem, isolatedTarget, readStore, storeTarget, claudeAiOauthOnly } from "./credstore.ts";
|
|
5
5
|
import { CLAUDE_BIN, resolveRealBin, resolveVerifiedClaude } from "./claudebin.ts";
|
|
6
|
-
import { ensurePathInRc,
|
|
6
|
+
import { activationHint, CHECK_JOB, ensurePathInRc, HUB_JOB, installSupervisor, managedShellRcSkipLines, shellRcPath } from "./install.ts";
|
|
7
7
|
import { withLock } from "./lock.ts";
|
|
8
8
|
import { errorMessage, log } from "./log.ts";
|
|
9
9
|
import { claudeTierLabel, describeIdentity, fetchTokenIdentity, isDeadCredential, InvalidGrantError } from "./oauth.ts";
|
|
@@ -256,9 +256,9 @@ function install(): void {
|
|
|
256
256
|
const out = installSupervisor();
|
|
257
257
|
console.log(`${c.green("✓")} installed ${c.bold("claude")} supervisor + statusLine/Stop/StopFailure/SessionStart hooks`);
|
|
258
258
|
if (out.timerLoaded) console.log(`${c.green("✓")} periodic check timer active (every ${out.checkIntervalS}s)`);
|
|
259
|
-
else console.log(c.yellow(`⚠ check timer written but not activated - run: ${
|
|
259
|
+
else console.log(c.yellow(`⚠ check timer written but not activated - run: ${activationHint(CHECK_JOB)}`));
|
|
260
260
|
if (out.hubLoaded) console.log(`${c.green("✓")} usage hub service active`);
|
|
261
|
-
else console.log(c.yellow(`⚠ usage hub service written but not activated - run: ${
|
|
261
|
+
else console.log(c.yellow(`⚠ usage hub service written but not activated - run: ${activationHint(HUB_JOB)}`));
|
|
262
262
|
if (!out.pathAhead) {
|
|
263
263
|
console.log();
|
|
264
264
|
ensurePathAhead();
|
package/src/lib/install.ts
CHANGED
|
@@ -36,11 +36,11 @@ export function isNixPackaged(): boolean {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
function skipImperativeTimer(): boolean {
|
|
40
40
|
return envFlag("TOKENMAXXING_SKIP_TIMER");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
function skipImperativeHub(): boolean {
|
|
44
44
|
return envFlag("TOKENMAXXING_SKIP_HUB");
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -106,8 +106,8 @@ export function installSupervisor(): InstallOutcome {
|
|
|
106
106
|
claudeWrapper: paths.supervisorLink,
|
|
107
107
|
installedBin: target,
|
|
108
108
|
pathAhead: isBinDirAhead(),
|
|
109
|
-
timerLoaded:
|
|
110
|
-
hubLoaded:
|
|
109
|
+
timerLoaded: installJob(CHECK_JOB, checkIntervalS),
|
|
110
|
+
hubLoaded: installJob(HUB_JOB, checkIntervalS),
|
|
111
111
|
checkIntervalS,
|
|
112
112
|
};
|
|
113
113
|
}
|
|
@@ -205,9 +205,67 @@ export function uninstallCodexSupervisor(): void {
|
|
|
205
205
|
if (existsSync(codexSupervisorLink())) rmSync(codexSupervisorLink(), { force: true });
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
export type UnitJob = {
|
|
209
|
+
label: string;
|
|
210
|
+
arg: string;
|
|
211
|
+
log: string;
|
|
212
|
+
skip: () => boolean;
|
|
213
|
+
unit: string;
|
|
214
|
+
launchd: (intervalS: number) => string;
|
|
215
|
+
systemd: Record<string, (exec: string, intervalS: number) => string>;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export const CHECK_JOB: UnitJob = {
|
|
219
|
+
label: "com.tokenmaxxing.check",
|
|
220
|
+
arg: "check",
|
|
221
|
+
log: "check.stderr.log",
|
|
222
|
+
skip: skipImperativeTimer,
|
|
223
|
+
unit: "tokenmaxxing-check.timer",
|
|
224
|
+
launchd: (intervalS) => ` <key>StartInterval</key><integer>${intervalS}</integer>\n`,
|
|
225
|
+
systemd: {
|
|
226
|
+
"tokenmaxxing-check.service": (exec) => `[Unit]
|
|
227
|
+
Description=tokenmaxxing account-switch check
|
|
228
|
+
|
|
229
|
+
[Service]
|
|
230
|
+
Type=oneshot
|
|
231
|
+
ExecStart=${exec}
|
|
232
|
+
${systemdEnv()}`,
|
|
233
|
+
"tokenmaxxing-check.timer": (_exec, intervalS) => `[Unit]
|
|
234
|
+
Description=tokenmaxxing periodic account-switch check
|
|
235
|
+
|
|
236
|
+
[Timer]
|
|
237
|
+
OnBootSec=${intervalS}
|
|
238
|
+
OnUnitActiveSec=${intervalS}
|
|
239
|
+
AccuracySec=${Math.max(1, Math.floor(intervalS / 12))}
|
|
240
|
+
|
|
241
|
+
[Install]
|
|
242
|
+
WantedBy=timers.target
|
|
243
|
+
`,
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export const HUB_JOB: UnitJob = {
|
|
248
|
+
label: "com.tokenmaxxing.hub",
|
|
249
|
+
arg: "serve",
|
|
250
|
+
log: "hub.stderr.log",
|
|
251
|
+
skip: skipImperativeHub,
|
|
252
|
+
unit: "tokenmaxxing-hub.service",
|
|
253
|
+
launchd: () => ` <key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>\n <key>RunAtLoad</key><true/>\n`,
|
|
254
|
+
systemd: {
|
|
255
|
+
"tokenmaxxing-hub.service": (exec) => `[Unit]
|
|
256
|
+
Description=tokenmaxxing usage hub
|
|
257
|
+
StartLimitIntervalSec=0
|
|
258
|
+
|
|
259
|
+
[Service]
|
|
260
|
+
ExecStart=${exec}
|
|
261
|
+
${systemdEnv()}Restart=on-failure
|
|
262
|
+
RestartSec=5
|
|
263
|
+
|
|
264
|
+
[Install]
|
|
265
|
+
WantedBy=default.target
|
|
266
|
+
`,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
211
269
|
|
|
212
270
|
function launchdPlist(label: string): string {
|
|
213
271
|
return join(paths.launchdAgentsDir, `${label}.plist`);
|
|
@@ -233,110 +291,56 @@ function launchdEnv(): string {
|
|
|
233
291
|
return ` <key>EnvironmentVariables</key><dict><key>TOKENMAXXING_HOME</key><string>${escape(paths.home)}</string></dict>\n`;
|
|
234
292
|
}
|
|
235
293
|
|
|
236
|
-
function
|
|
237
|
-
if (
|
|
294
|
+
function installJob(job: UnitJob, intervalS: number): boolean {
|
|
295
|
+
if (job.skip()) return true;
|
|
238
296
|
|
|
239
297
|
if (process.platform === "darwin") {
|
|
240
|
-
const plist = launchdPlist(
|
|
298
|
+
const plist = launchdPlist(job.label);
|
|
241
299
|
writeFileAtomic(
|
|
242
300
|
plist,
|
|
243
301
|
`<?xml version="1.0" encoding="UTF-8"?>
|
|
244
302
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
245
303
|
<plist version="1.0">
|
|
246
304
|
<dict>
|
|
247
|
-
<key>Label</key><string>${
|
|
248
|
-
<key>ProgramArguments</key><array><string>${escape(installedBin())}</string><string
|
|
249
|
-
<key>
|
|
250
|
-
|
|
251
|
-
<key>StandardErrorPath</key><string>${escape(join(paths.home, "check.stderr.log"))}</string>
|
|
305
|
+
<key>Label</key><string>${job.label}</string>
|
|
306
|
+
<key>ProgramArguments</key><array><string>${escape(installedBin())}</string><string>${job.arg}</string></array>
|
|
307
|
+
${job.launchd(intervalS)}${launchdEnv()} <key>StandardOutPath</key><string>/dev/null</string>
|
|
308
|
+
<key>StandardErrorPath</key><string>${escape(join(paths.home, job.log))}</string>
|
|
252
309
|
</dict>
|
|
253
310
|
</plist>
|
|
254
311
|
`,
|
|
255
312
|
0o644,
|
|
256
313
|
);
|
|
257
314
|
const domain = launchdDomain();
|
|
258
|
-
run(["launchctl", "bootout", `${domain}/${
|
|
259
|
-
return run(["launchctl", "bootstrap", domain, plist]) ||
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const exec = `"${installedBin().replaceAll("%", "%%")}" check`;
|
|
263
|
-
writeFileAtomic(
|
|
264
|
-
join(paths.systemdUserDir, "tokenmaxxing-check.service"),
|
|
265
|
-
`[Unit]
|
|
266
|
-
Description=tokenmaxxing account-switch check
|
|
267
|
-
|
|
268
|
-
[Service]
|
|
269
|
-
Type=oneshot
|
|
270
|
-
ExecStart=${exec}
|
|
271
|
-
${systemdEnv()}`,
|
|
272
|
-
0o644,
|
|
273
|
-
);
|
|
274
|
-
writeFileAtomic(
|
|
275
|
-
join(paths.systemdUserDir, "tokenmaxxing-check.timer"),
|
|
276
|
-
`[Unit]
|
|
277
|
-
Description=tokenmaxxing periodic account-switch check
|
|
278
|
-
|
|
279
|
-
[Timer]
|
|
280
|
-
OnBootSec=${intervalS}
|
|
281
|
-
OnUnitActiveSec=${intervalS}
|
|
282
|
-
AccuracySec=${Math.max(1, Math.floor(intervalS / 12))}
|
|
283
|
-
|
|
284
|
-
[Install]
|
|
285
|
-
WantedBy=timers.target
|
|
286
|
-
`,
|
|
287
|
-
0o644,
|
|
288
|
-
);
|
|
289
|
-
return (
|
|
290
|
-
run(["systemctl", "--user", "daemon-reload"]) &&
|
|
291
|
-
run(["systemctl", "--user", "enable", "--now", "tokenmaxxing-check.timer"])
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export function timerActivationHint(): string {
|
|
296
|
-
if (process.platform === "darwin") {
|
|
297
|
-
return `launchctl bootstrap gui/$(id -u) ${launchdPlist(LAUNCHD_LABEL)}`;
|
|
298
|
-
}
|
|
299
|
-
return "systemctl --user daemon-reload && systemctl --user enable --now tokenmaxxing-check.timer";
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export function hubActivationHint(): string {
|
|
303
|
-
if (process.platform === "darwin") {
|
|
304
|
-
return `launchctl bootstrap gui/$(id -u) ${launchdPlist(LAUNCHD_HUB_LABEL)}`;
|
|
315
|
+
run(["launchctl", "bootout", `${domain}/${job.label}`]);
|
|
316
|
+
return run(["launchctl", "bootstrap", domain, plist]) || jobHealthy(job);
|
|
305
317
|
}
|
|
306
|
-
return `systemctl --user daemon-reload && systemctl --user enable --now ${HUB_UNIT}`;
|
|
307
|
-
}
|
|
308
318
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
return existsSync(launchdPlist(LAUNCHD_LABEL)) && run(["launchctl", "print", `${launchdDomain()}/${LAUNCHD_LABEL}`]);
|
|
313
|
-
}
|
|
314
|
-
return (
|
|
315
|
-
existsSync(join(paths.systemdUserDir, "tokenmaxxing-check.timer")) &&
|
|
316
|
-
run(["systemctl", "--user", "is-active", "--quiet", "tokenmaxxing-check.timer"])
|
|
317
|
-
);
|
|
319
|
+
const exec = `"${installedBin().replaceAll("%", "%%")}" ${job.arg}`;
|
|
320
|
+
for (const [file, text] of Object.entries(job.systemd)) writeFileAtomic(join(paths.systemdUserDir, file), text(exec, intervalS), 0o644);
|
|
321
|
+
return run(["systemctl", "--user", "daemon-reload"]) && run(["systemctl", "--user", "enable", "--now", job.unit]);
|
|
318
322
|
}
|
|
319
323
|
|
|
320
|
-
export function
|
|
321
|
-
if (skipImperativeHub()) return true;
|
|
324
|
+
export function activationHint(job: UnitJob): string {
|
|
322
325
|
if (process.platform === "darwin") {
|
|
323
|
-
return
|
|
326
|
+
return `launchctl bootstrap gui/$(id -u) ${launchdPlist(job.label)}`;
|
|
324
327
|
}
|
|
325
|
-
return
|
|
328
|
+
return `systemctl --user daemon-reload && systemctl --user enable --now ${job.unit}`;
|
|
326
329
|
}
|
|
327
330
|
|
|
328
|
-
export function
|
|
331
|
+
export function jobHealthy(job: UnitJob): boolean {
|
|
332
|
+
if (job.skip()) return true;
|
|
329
333
|
if (process.platform === "darwin") {
|
|
330
|
-
return
|
|
334
|
+
return existsSync(launchdPlist(job.label)) && run(["launchctl", "print", `${launchdDomain()}/${job.label}`]);
|
|
331
335
|
}
|
|
332
|
-
return "systemctl --user
|
|
336
|
+
return existsSync(join(paths.systemdUserDir, job.unit)) && run(["systemctl", "--user", "is-active", "--quiet", job.unit]);
|
|
333
337
|
}
|
|
334
338
|
|
|
335
|
-
export function
|
|
339
|
+
export function deactivationHint(job: UnitJob): string {
|
|
336
340
|
if (process.platform === "darwin") {
|
|
337
|
-
return `launchctl bootout gui/$(id -u)/${
|
|
341
|
+
return `launchctl bootout gui/$(id -u)/${job.label}`;
|
|
338
342
|
}
|
|
339
|
-
return `systemctl --user disable --now ${
|
|
343
|
+
return `systemctl --user disable --now ${job.unit}`;
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
function launchdJobLoaded(label: string): "loaded" | "not-loaded" | "unavailable" {
|
|
@@ -361,108 +365,42 @@ function systemdUnitActive(unit: string): "active" | "not-active" | "unavailable
|
|
|
361
365
|
}
|
|
362
366
|
}
|
|
363
367
|
|
|
364
|
-
function
|
|
365
|
-
if (process.platform === "darwin")
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
368
|
+
function jobFiles(job: UnitJob): string[] {
|
|
369
|
+
if (process.platform === "darwin") return [launchdPlist(job.label)];
|
|
370
|
+
return Object.keys(job.systemd).map((file) => join(paths.systemdUserDir, file));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function removeJobFiles(job: UnitJob): void {
|
|
374
|
+
for (const file of jobFiles(job)) rmSync(file, { force: true });
|
|
371
375
|
}
|
|
372
376
|
|
|
373
377
|
type UnitOutcome = "removed" | "skipped" | "still-loaded";
|
|
374
378
|
|
|
375
|
-
function
|
|
376
|
-
if (
|
|
379
|
+
function uninstallJob(job: UnitJob, live: boolean): UnitOutcome {
|
|
380
|
+
if (job.skip()) return "skipped";
|
|
377
381
|
if (!live) {
|
|
378
|
-
|
|
382
|
+
removeJobFiles(job);
|
|
379
383
|
return "removed";
|
|
380
384
|
}
|
|
381
385
|
if (process.platform === "darwin") {
|
|
382
|
-
const loaded = launchdJobLoaded(
|
|
383
|
-
const deactivated = loaded === "loaded" ? run(["launchctl", "bootout", `${launchdDomain()}/${
|
|
384
|
-
|
|
386
|
+
const loaded = launchdJobLoaded(job.label);
|
|
387
|
+
const deactivated = loaded === "loaded" ? run(["launchctl", "bootout", `${launchdDomain()}/${job.label}`]) : loaded === "not-loaded";
|
|
388
|
+
removeJobFiles(job);
|
|
385
389
|
return deactivated ? "removed" : "still-loaded";
|
|
386
390
|
}
|
|
387
|
-
const active = systemdUnitActive(
|
|
388
|
-
const deactivated = active !== "unavailable" && (run(["systemctl", "--user", "disable", "--now",
|
|
389
|
-
|
|
391
|
+
const active = systemdUnitActive(job.unit);
|
|
392
|
+
const deactivated = active !== "unavailable" && (run(["systemctl", "--user", "disable", "--now", job.unit]) || active === "not-active");
|
|
393
|
+
removeJobFiles(job);
|
|
390
394
|
run(["systemctl", "--user", "daemon-reload"]);
|
|
391
395
|
return deactivated ? "removed" : "still-loaded";
|
|
392
396
|
}
|
|
393
397
|
|
|
394
|
-
function
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
plist,
|
|
401
|
-
`<?xml version="1.0" encoding="UTF-8"?>
|
|
402
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
403
|
-
<plist version="1.0">
|
|
404
|
-
<dict>
|
|
405
|
-
<key>Label</key><string>${LAUNCHD_HUB_LABEL}</string>
|
|
406
|
-
<key>ProgramArguments</key><array><string>${escape(installedBin())}</string><string>serve</string></array>
|
|
407
|
-
<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict>
|
|
408
|
-
<key>RunAtLoad</key><true/>
|
|
409
|
-
${launchdEnv()} <key>StandardOutPath</key><string>/dev/null</string>
|
|
410
|
-
<key>StandardErrorPath</key><string>${escape(join(paths.home, "hub.stderr.log"))}</string>
|
|
411
|
-
</dict>
|
|
412
|
-
</plist>
|
|
413
|
-
`,
|
|
414
|
-
0o644,
|
|
415
|
-
);
|
|
416
|
-
const domain = launchdDomain();
|
|
417
|
-
run(["launchctl", "bootout", `${domain}/${LAUNCHD_HUB_LABEL}`]);
|
|
418
|
-
return run(["launchctl", "bootstrap", domain, plist]) || hubServiceHealthy();
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
const exec = `"${installedBin().replaceAll("%", "%%")}" serve`;
|
|
422
|
-
writeFileAtomic(
|
|
423
|
-
join(paths.systemdUserDir, HUB_UNIT),
|
|
424
|
-
`[Unit]
|
|
425
|
-
Description=tokenmaxxing usage hub
|
|
426
|
-
StartLimitIntervalSec=0
|
|
427
|
-
|
|
428
|
-
[Service]
|
|
429
|
-
ExecStart=${exec}
|
|
430
|
-
${systemdEnv()}Restart=on-failure
|
|
431
|
-
RestartSec=5
|
|
432
|
-
|
|
433
|
-
[Install]
|
|
434
|
-
WantedBy=default.target
|
|
435
|
-
`,
|
|
436
|
-
0o644,
|
|
437
|
-
);
|
|
438
|
-
return run(["systemctl", "--user", "daemon-reload"]) && run(["systemctl", "--user", "enable", "--now", HUB_UNIT]);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function removeHubUnits(): void {
|
|
442
|
-
if (process.platform === "darwin") {
|
|
443
|
-
rmSync(launchdPlist(LAUNCHD_HUB_LABEL), { force: true });
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
rmSync(join(paths.systemdUserDir, HUB_UNIT), { force: true });
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
function uninstallHubService(live: boolean): UnitOutcome {
|
|
450
|
-
if (skipImperativeHub()) return "skipped";
|
|
451
|
-
if (!live) {
|
|
452
|
-
removeHubUnits();
|
|
453
|
-
return "removed";
|
|
454
|
-
}
|
|
455
|
-
if (process.platform === "darwin") {
|
|
456
|
-
const loaded = launchdJobLoaded(LAUNCHD_HUB_LABEL);
|
|
457
|
-
const deactivated = loaded === "loaded" ? run(["launchctl", "bootout", `${launchdDomain()}/${LAUNCHD_HUB_LABEL}`]) : loaded === "not-loaded";
|
|
458
|
-
removeHubUnits();
|
|
459
|
-
return deactivated ? "removed" : "still-loaded";
|
|
460
|
-
}
|
|
461
|
-
const active = systemdUnitActive(HUB_UNIT);
|
|
462
|
-
const deactivated = active !== "unavailable" && (run(["systemctl", "--user", "disable", "--now", HUB_UNIT]) || active === "not-active");
|
|
463
|
-
removeHubUnits();
|
|
464
|
-
run(["systemctl", "--user", "daemon-reload"]);
|
|
465
|
-
return deactivated ? "removed" : "still-loaded";
|
|
398
|
+
function uninstallTarget(job: UnitJob, live: boolean): string {
|
|
399
|
+
const files = jobFiles(job).join(" and ");
|
|
400
|
+
if (!live) return files;
|
|
401
|
+
return process.platform === "darwin"
|
|
402
|
+
? `${files} (and launchctl bootout ${launchdDomain()}/${job.label})`
|
|
403
|
+
: `${files} (and systemctl --user disable --now ${job.unit})`;
|
|
466
404
|
}
|
|
467
405
|
|
|
468
406
|
export function shellRcPath(): string | null {
|
|
@@ -563,20 +501,11 @@ export function onLoginHome(): boolean {
|
|
|
563
501
|
}
|
|
564
502
|
|
|
565
503
|
export function uninstallTargets(live: boolean): string[] {
|
|
566
|
-
const timer =
|
|
567
|
-
process.platform === "darwin"
|
|
568
|
-
? `${launchdPlist(LAUNCHD_LABEL)}${live ? ` (and launchctl bootout ${launchdDomain()}/${LAUNCHD_LABEL})` : ""}`
|
|
569
|
-
: `${join(paths.systemdUserDir, "tokenmaxxing-check.timer")} and .service${live ? " (and systemctl --user disable --now tokenmaxxing-check.timer)" : ""}`;
|
|
570
|
-
const hub =
|
|
571
|
-
process.platform === "darwin"
|
|
572
|
-
? `${launchdPlist(LAUNCHD_HUB_LABEL)}${live ? ` (and launchctl bootout ${launchdDomain()}/${LAUNCHD_HUB_LABEL})` : ""}`
|
|
573
|
-
: `${join(paths.systemdUserDir, HUB_UNIT)}${live ? ` (and systemctl --user disable --now ${HUB_UNIT})` : ""}`;
|
|
574
504
|
const rc = shellRcPath();
|
|
575
505
|
return [
|
|
576
506
|
`${paths.claudeSettings}: the hook and statusline entries`,
|
|
577
507
|
`${codexPaths.hooksJson}: the codex Stop hook entry`,
|
|
578
|
-
...(
|
|
579
|
-
...(skipImperativeHub() ? [] : [hub]),
|
|
508
|
+
...[CHECK_JOB, HUB_JOB].filter((job) => !job.skip()).map((job) => uninstallTarget(job, live)),
|
|
580
509
|
paths.supervisorLink,
|
|
581
510
|
codexSupervisorLink(),
|
|
582
511
|
join(paths.binDir, "xx"),
|
|
@@ -587,8 +516,8 @@ export function uninstallTargets(live: boolean): string[] {
|
|
|
587
516
|
|
|
588
517
|
export function uninstallSupervisor(input: { live: boolean }): UninstallOutcome {
|
|
589
518
|
uninstallSettings();
|
|
590
|
-
const timer =
|
|
591
|
-
const hub =
|
|
519
|
+
const timer = uninstallJob(CHECK_JOB, input.live);
|
|
520
|
+
const hub = uninstallJob(HUB_JOB, input.live);
|
|
592
521
|
uninstallCodexSupervisor();
|
|
593
522
|
for (const f of [paths.supervisorLink, join(paths.binDir, "xx"), installedBin()]) {
|
|
594
523
|
if (existsSync(f)) rmSync(f, { force: true });
|
package/src/main.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { cmdCheck } from "./cli/check.ts";
|
|
|
23
23
|
import { cmdConfig } from "./cli/config.ts";
|
|
24
24
|
import { cmdSeat } from "./cli/seat.ts";
|
|
25
25
|
import { cmdServe } from "./cli/serve.ts";
|
|
26
|
-
import {
|
|
26
|
+
import { CHECK_JOB, deactivationHint, HUB_JOB, onLoginHome, uninstallSupervisor, uninstallTargets } from "./lib/install.ts";
|
|
27
27
|
import { errorMessage } from "./lib/log.ts";
|
|
28
28
|
import { HOME } from "./lib/paths.ts";
|
|
29
29
|
import { c, emitError } from "./cli/render.ts";
|
|
@@ -177,8 +177,8 @@ async function main(): Promise<number> {
|
|
|
177
177
|
...(out.pathLineRemoved ? ["rc PATH line"] : []),
|
|
178
178
|
];
|
|
179
179
|
console.log(`removed ${removed.join(", ")}`);
|
|
180
|
-
if (out.timer === "still-loaded") console.log(c.yellow(`⚠ the check job may still be loaded - run: ${
|
|
181
|
-
if (out.hub === "still-loaded") console.log(c.yellow(`⚠ the usage hub job may still be loaded - run: ${
|
|
180
|
+
if (out.timer === "still-loaded") console.log(c.yellow(`⚠ the check job may still be loaded - run: ${deactivationHint(CHECK_JOB)}`));
|
|
181
|
+
if (out.hub === "still-loaded") console.log(c.yellow(`⚠ the usage hub job may still be loaded - run: ${deactivationHint(HUB_JOB)}`));
|
|
182
182
|
if (!out.pathLineRemoved) console.log(c.dim("(no tokenmaxxing PATH line found in the shell rc)"));
|
|
183
183
|
console.log(`kept: accounts.json, config.json, and every account credential store (claude: stores/ and its keychain items on macOS; codex: codex-stores/; grok: grok-stores/; opencode-go: opencode-go-stores/) - remove accounts with \`xx rm\` to delete their credentials`);
|
|
184
184
|
return 0;
|