tokenmaxxing 1.47.0 → 1.49.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/status.ts +30 -1
- package/src/entries/stopfailurehook.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenmaxxing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.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/status.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { opencodeGo } from "../lib/opencodego.ts";
|
|
|
7
7
|
import { loadAccounts, loadConfig, saveAccounts } from "../lib/state.ts";
|
|
8
8
|
import { withLock } from "../lib/lock.ts";
|
|
9
9
|
import { codexPool, grokPool, opencodeGoPool } from "../lib/paths.ts";
|
|
10
|
-
import { earliestReset, isExhausted, isSessionWindow, limitWindows, nextWeeklyReset, sessionWindow, thresholdBars, weeklyWindow } from "../lib/picker.ts";
|
|
10
|
+
import { earliestReset, gatedWindows, isExhausted, isSessionWindow, limitWindows, liveUsed, nextWeeklyReset, sessionWindow, thresholdBars, weeklyWindow } from "../lib/picker.ts";
|
|
11
11
|
import type { Provider, SampleReport } from "../lib/provider.ts";
|
|
12
12
|
import { bar, c, count, emitJson, fmtAgo } from "./render.ts";
|
|
13
13
|
import { ThresholdsSchema, type Account, type Config, type Window } from "../lib/types.ts";
|
|
@@ -50,6 +50,7 @@ const PoolReportSchema = z.object({
|
|
|
50
50
|
thresholds: ThresholdsSchema,
|
|
51
51
|
bars: ThresholdsSchema,
|
|
52
52
|
projectionMargin: z.number(),
|
|
53
|
+
gatedNote: z.string().nullable(),
|
|
53
54
|
accounts: z.array(StatusAccountSchema),
|
|
54
55
|
});
|
|
55
56
|
type PoolReport = z.infer<typeof PoolReportSchema>;
|
|
@@ -77,6 +78,29 @@ function usageReport(a: Account, now: number): StatusAccount["usage"] {
|
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
function gatedNote(accounts: Account[], families: string[] | null, weeklyBar: number, now: number): string | null {
|
|
82
|
+
const groups = new Map<string, { carriers: number; capped: number }>();
|
|
83
|
+
for (const a of accounts) {
|
|
84
|
+
if (a.needsReauth === true) continue;
|
|
85
|
+
for (const w of gatedWindows(a, families)) {
|
|
86
|
+
const key = (w.name ?? "").toLowerCase();
|
|
87
|
+
const g = groups.get(key) ?? { carriers: 0, capped: 0 };
|
|
88
|
+
g.carriers++;
|
|
89
|
+
if (liveUsed(w, now) >= weeklyBar) g.capped++;
|
|
90
|
+
groups.set(key, g);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const capped = [...groups.entries()].filter(([, g]) => g.capped === g.carriers).map(([name]) => name);
|
|
94
|
+
if (capped.length === 0) return null;
|
|
95
|
+
const headroom = accounts.filter((a) => {
|
|
96
|
+
if (a.needsReauth === true) return false;
|
|
97
|
+
const w = weeklyWindow(a);
|
|
98
|
+
return w != null && liveUsed(w, now) < weeklyBar;
|
|
99
|
+
}).length;
|
|
100
|
+
if (headroom === 0) return null;
|
|
101
|
+
return `every ${capped.join(", ")} cap is at the weekly bar, but ${count({ n: headroom, noun: "account" })} still ha${headroom === 1 ? "s" : "ve"} weekly aggregate headroom for other models`;
|
|
102
|
+
}
|
|
103
|
+
|
|
80
104
|
async function collect(p: Provider, cfg: Config, now: number, cached: boolean): Promise<PoolReport> {
|
|
81
105
|
let idx = loadAccounts(p.pool);
|
|
82
106
|
let reports = new Map<string, SampleReport>();
|
|
@@ -119,6 +143,7 @@ async function collect(p: Provider, cfg: Config, now: number, cached: boolean):
|
|
|
119
143
|
thresholds: { session: cfg.thresholds.session, weekly: cfg.thresholds.weekly },
|
|
120
144
|
bars,
|
|
121
145
|
projectionMargin: cfg.policy.projectionMargin,
|
|
146
|
+
gatedNote: gatedNote(idx.accounts, ctx.families, bars.weekly, now),
|
|
122
147
|
accounts,
|
|
123
148
|
};
|
|
124
149
|
}
|
|
@@ -232,6 +257,10 @@ function renderPool(p: Provider, pool: PoolReport, header: string, now: number,
|
|
|
232
257
|
console.log(c.dim(header));
|
|
233
258
|
console.log();
|
|
234
259
|
renderGrid(pool.accounts.map((a) => card(p, a, now, staleAfterMs)));
|
|
260
|
+
if (pool.gatedNote) {
|
|
261
|
+
console.log(c.yellow(pool.gatedNote));
|
|
262
|
+
console.log();
|
|
263
|
+
}
|
|
235
264
|
}
|
|
236
265
|
|
|
237
266
|
export async function cmdStatus(opts: { json?: boolean; cached?: boolean } = {}): Promise<number> {
|
|
@@ -4,6 +4,7 @@ import { evaluateAndMaybeSwap } from "../lib/decide.ts";
|
|
|
4
4
|
import { supervisedSession, writeRespawnMarker } from "../lib/sessions.ts";
|
|
5
5
|
import { loadConfig } from "../lib/state.ts";
|
|
6
6
|
import { classifyEnforcedLimit, findEnforcedRow, parseErrorBody, readTranscriptTail } from "../lib/usage.ts";
|
|
7
|
+
import { paths } from "../lib/paths.ts";
|
|
7
8
|
import { JsonTextSchema, type EnforcedLimit } from "../lib/types.ts";
|
|
8
9
|
import { log } from "../lib/log.ts";
|
|
9
10
|
import { readStdin } from "./statusline.ts";
|
|
@@ -52,6 +53,16 @@ export async function runStopFailureHook(): Promise<number> {
|
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
if (session == null && limit != null) {
|
|
57
|
+
const shim = `${paths.binDir}/claude`;
|
|
58
|
+
log("stopfailure.unsupervised_hint", { sid: stdinSid });
|
|
59
|
+
process.stdout.write(
|
|
60
|
+
`${JSON.stringify({
|
|
61
|
+
systemMessage: `tokenmaxxing: this session runs outside the supervisor, so it cannot move to another account at the limit. Move it yourself: ${stdinSid ? `${shim} --resume ${stdinSid}` : `resume it through ${shim}`}`,
|
|
62
|
+
})}\n`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
const decision = await evaluateAndMaybeSwap(claude, now, canRespawn && enforced != null, enforced);
|
|
56
67
|
if (enforced && session && canRespawn && decision.account && (decision.swapped || decision.waitUntil !== undefined)) {
|
|
57
68
|
writeRespawnMarker({ session, sessionId: stdinSid ?? session.sid, accountId: decision.account.id, waitUntil: decision.waitUntil ?? now, compact: false });
|