tokenmaxxing 1.84.0 → 1.86.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/entries/supervisor.ts +14 -3
- package/src/lib/compact.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenmaxxing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.86.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",
|
|
@@ -419,7 +419,8 @@ export async function runSupervisor(argv: string[]): Promise<number> {
|
|
|
419
419
|
if (existsSync(marker)) rmSync(marker, { force: true });
|
|
420
420
|
|
|
421
421
|
const gate: MarkerGate = { launchedAt: Date.now(), overriddenUntil };
|
|
422
|
-
const
|
|
422
|
+
const launched = await withLock(claudePool.lockFile, async () => {
|
|
423
|
+
if (terminating) return null;
|
|
423
424
|
const picked = (wanted == null ? null : (loadAccounts(claudePool).accounts.find((a) => a.id === wanted) ?? null)) ?? pickSeat(gate.launchedAt, model);
|
|
424
425
|
log("supervisor.launch", { sid, respawns, seat: picked?.id.slice(0, 8) ?? null, args: launchArgs.join(" "), injected: firstLine !== null });
|
|
425
426
|
const spawned = Bun.spawn([real, ...launchArgs], {
|
|
@@ -435,6 +436,7 @@ export async function runSupervisor(argv: string[]): Promise<number> {
|
|
|
435
436
|
...(picked ? { CLAUDE_SECURESTORAGE_CONFIG_DIR: storeDirFor(picked.id) } : {}),
|
|
436
437
|
},
|
|
437
438
|
});
|
|
439
|
+
child = spawned;
|
|
438
440
|
if (relay !== null) relay.attach(spawned.stdin!, firstLine);
|
|
439
441
|
firstLine = null;
|
|
440
442
|
if (picked) {
|
|
@@ -450,8 +452,12 @@ export async function runSupervisor(argv: string[]): Promise<number> {
|
|
|
450
452
|
}
|
|
451
453
|
return { child: spawned, seat: picked };
|
|
452
454
|
});
|
|
455
|
+
if (launched == null) {
|
|
456
|
+
await releaseClaim();
|
|
457
|
+
return 143;
|
|
458
|
+
}
|
|
453
459
|
|
|
454
|
-
child =
|
|
460
|
+
const { child: proc, seat } = launched;
|
|
455
461
|
let seatCheckAt = 0;
|
|
456
462
|
await raceMarkerOrExit({
|
|
457
463
|
child: proc,
|
|
@@ -492,7 +498,12 @@ export async function runSupervisor(argv: string[]): Promise<number> {
|
|
|
492
498
|
delete compactEnv.TOKENMAXXING_SESSION_ID;
|
|
493
499
|
delete compactEnv.TOKENMAXXING_LAUNCHED_AT;
|
|
494
500
|
delete compactEnv.TOKENMAXXING_MODEL;
|
|
495
|
-
const outcome = await compactClaudeSession({ real, sid: m.sessionId, transcript, env: compactEnv });
|
|
501
|
+
const outcome = await compactClaudeSession({ real, sid: m.sessionId, transcript, env: compactEnv, onSpawn: (p) => { child = p; } });
|
|
502
|
+
child = null;
|
|
503
|
+
if (terminating) {
|
|
504
|
+
await releaseClaim();
|
|
505
|
+
return 143;
|
|
506
|
+
}
|
|
496
507
|
log("supervisor.compact", { sid: m.sessionId.slice(0, 8), seat: seat.id.slice(0, 8), ok: outcome.ok, reason: outcome.ok ? undefined : outcome.reason });
|
|
497
508
|
if (!outcome.ok) say(`\x1b[33m compaction did not land (${outcome.reason}) - resuming with the full context\x1b[0m\n`, `tokenmaxxing: compaction did not land; resuming with the full context. (${outcome.reason})`);
|
|
498
509
|
compacted = outcome.ok;
|
package/src/lib/compact.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { statSync } from "node:fs";
|
|
2
|
+
import type { Subprocess } from "bun";
|
|
2
3
|
import { delay } from "es-toolkit";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import pkg from "../../package.json" with { type: "json" };
|
|
@@ -13,7 +14,7 @@ const PIPE_GRACE_MS = 2_000;
|
|
|
13
14
|
|
|
14
15
|
const CompactBoundarySchema = z.looseObject({ type: z.literal("system"), subtype: z.literal("compact_boundary") });
|
|
15
16
|
|
|
16
|
-
export async function compactClaudeSession(input: { real: string; sid: string; transcript: string; env: Record<string, string | undefined
|
|
17
|
+
export async function compactClaudeSession(input: { real: string; sid: string; transcript: string; env: Record<string, string | undefined>; onSpawn: (child: Subprocess) => void }): Promise<CompactOutcome> {
|
|
17
18
|
const offset = statSync(input.transcript).size;
|
|
18
19
|
const p = Bun.spawn([input.real, "-p", "--resume", input.sid, "/compact"], {
|
|
19
20
|
env: input.env,
|
|
@@ -23,6 +24,7 @@ export async function compactClaudeSession(input: { real: string; sid: string; t
|
|
|
23
24
|
timeout: CLAUDE_COMPACT_KILL_MS,
|
|
24
25
|
killSignal: "SIGKILL",
|
|
25
26
|
});
|
|
27
|
+
input.onSpawn(p);
|
|
26
28
|
const reads = Promise.all([p.stdout.text(), p.stderr.text()]);
|
|
27
29
|
const settled = await Promise.race([reads, p.exited.then(() => delay(PIPE_GRACE_MS)).then(() => null)]);
|
|
28
30
|
await p.exited;
|