tokenmaxxing 1.106.0 → 1.107.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenmaxxing",
3
- "version": "1.106.0",
3
+ "version": "1.107.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",
@@ -1,3 +1,5 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import { basename, dirname, join } from "node:path";
1
3
  import { z } from "zod";
2
4
  import { claude } from "../lib/claude.ts";
3
5
  import { evaluateAndMaybeSwap } from "../lib/decide.ts";
@@ -20,10 +22,18 @@ const StopFailureStdin = z.looseObject({
20
22
  const ROW_WAIT_MS = 3_000;
21
23
  const ROW_POLL_MS = 200;
22
24
 
23
- async function awaitEnforcedRow(input: { transcriptPath: string; error: string; lastAssistantMessage: string | undefined }): Promise<TranscriptRow | null> {
25
+ function subagentTranscript(transcriptPath: string, agentId: string): string {
26
+ const dir = join(dirname(transcriptPath), basename(transcriptPath, ".jsonl"), "subagents");
27
+ const name = `agent-${agentId}.jsonl`;
28
+ const found = existsSync(dir) ? readdirSync(dir, { recursive: true, encoding: "utf8" }).find((p) => basename(p) === name) : undefined;
29
+ return join(dir, found ?? name);
30
+ }
31
+
32
+ async function awaitEnforcedRow(input: { transcriptPath: string; agentId: string | undefined; error: string; lastAssistantMessage: string | undefined }): Promise<TranscriptRow | null> {
24
33
  const deadline = Date.now() + ROW_WAIT_MS;
25
34
  while (true) {
26
- const row = findEnforcedRow({ rows: await readTranscriptTail(input.transcriptPath), error: input.error, lastAssistantMessage: input.lastAssistantMessage });
35
+ const path = input.agentId === undefined ? input.transcriptPath : subagentTranscript(input.transcriptPath, input.agentId);
36
+ const row = findEnforcedRow({ rows: await readTranscriptTail(path), error: input.error, lastAssistantMessage: input.lastAssistantMessage });
27
37
  if (row || Date.now() >= deadline) return row;
28
38
  await Bun.sleep(ROW_POLL_MS);
29
39
  }
@@ -52,7 +62,7 @@ export async function runStopFailureHook(): Promise<number> {
52
62
  const canRespawn = session != null && mainLoop;
53
63
  const cfg = loadConfig();
54
64
  const row = stdin.transcript_path
55
- ? await awaitEnforcedRow({ transcriptPath: stdin.transcript_path, error, lastAssistantMessage: stdin.last_assistant_message })
65
+ ? await awaitEnforcedRow({ transcriptPath: stdin.transcript_path, agentId: stdin.agent_id, error, lastAssistantMessage: stdin.last_assistant_message })
56
66
  : null;
57
67
  const limit = row ? classifyEnforcedLimit(row, cfg.policy.switchModels) : null;
58
68