tokenmaxxing 1.96.0 → 1.98.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.96.0",
3
+ "version": "1.98.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",
@@ -124,12 +124,12 @@ const PiTrustSchema = z.record(z.string(), z.unknown());
124
124
  function readPiJson<T extends z.ZodType>(file: string, schema: T): z.output<T> | null {
125
125
  let text: string;
126
126
  try {
127
- text = readFileSync(file, "utf8");
127
+ text = new TextDecoder().decode(readFileSync(file));
128
128
  } catch (e) {
129
129
  if (ErrnoSchema.safeParse(e).data?.code === "ENOENT") return null;
130
130
  throw e;
131
131
  }
132
- const parsed = schema.safeParse(JsonTextSchema.safeParse(text.startsWith("") ? text.slice(1) : text).data);
132
+ const parsed = schema.safeParse(JsonTextSchema.safeParse(text).data);
133
133
  if (!parsed.success) log("pisupervisor.pi_file_unreadable", { file });
134
134
  return parsed.success ? parsed.data : null;
135
135
  }
@@ -23,7 +23,7 @@ const ROW_POLL_MS = 200;
23
23
  async function awaitEnforcedRow(input: { transcriptPath: string; lastAssistantMessage: string | undefined; now: number }): Promise<TranscriptRow | null> {
24
24
  const deadline = Date.now() + ROW_WAIT_MS;
25
25
  while (true) {
26
- const row = findEnforcedRow({ rows: readTranscriptTail(input.transcriptPath), lastAssistantMessage: input.lastAssistantMessage, now: input.now });
26
+ const row = findEnforcedRow({ rows: await readTranscriptTail(input.transcriptPath), lastAssistantMessage: input.lastAssistantMessage, now: input.now });
27
27
  if (row || Date.now() >= deadline) return row;
28
28
  await Bun.sleep(ROW_POLL_MS);
29
29
  }
package/src/lib/http.ts CHANGED
@@ -49,12 +49,5 @@ export function safeErrorDetail(input: { text: string }): string {
49
49
  export const http = ky.create({
50
50
  timeout: 15_000,
51
51
  throwHttpErrors: false,
52
- retry: {
53
- limit: 2,
54
- methods: ["get"],
55
- statusCodes: [429, 500, 502, 503, 504],
56
- afterStatusCodes: [429, 503],
57
- maxRetryAfter: 10_000,
58
- backoffLimit: 3000,
59
- },
52
+ retry: 0,
60
53
  });
package/src/lib/proc.ts CHANGED
@@ -46,9 +46,7 @@ export function pidStartTime(pid: number): string | null {
46
46
  }
47
47
 
48
48
  export async function readStdin(): Promise<string> {
49
- const chunks: Uint8Array[] = [];
50
- for await (const chunk of Bun.stdin.stream()) chunks.push(chunk);
51
- return Buffer.concat(chunks).toString("utf8");
49
+ return Buffer.from(await Bun.stdin.bytes()).toString("utf8");
52
50
  }
53
51
 
54
52
  export async function* readLines(stream: ReadableStream<Uint8Array>): AsyncGenerator<string> {
package/src/lib/usage.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { closeSync, fstatSync, openSync, readSync } from "node:fs";
2
1
  import { z } from "zod";
3
2
  import { http } from "./http.ts";
4
3
  import { errorMessage, log } from "./log.ts";
@@ -66,23 +65,11 @@ export type TranscriptRow = z.infer<typeof TranscriptRowSchema>;
66
65
 
67
66
  const TRANSCRIPT_TAIL_BYTES = 256 * 1024;
68
67
 
69
- export function readTranscriptTail(path: string, maxBytes = TRANSCRIPT_TAIL_BYTES): TranscriptRow[] {
70
- let text: string;
71
- try {
72
- const fd = openSync(path, "r");
73
- try {
74
- const size = fstatSync(fd).size;
75
- const start = Math.max(0, size - maxBytes);
76
- const buf = Buffer.alloc(size - start);
77
- readSync(fd, buf, 0, buf.length, start);
78
- text = buf.toString("utf8");
79
- if (start > 0) text = text.slice(text.indexOf("\n") + 1);
80
- } finally {
81
- closeSync(fd);
82
- }
83
- } catch {
84
- return [];
85
- }
68
+ export async function readTranscriptTail(path: string): Promise<TranscriptRow[]> {
69
+ const file = Bun.file(path);
70
+ const start = Math.max(0, file.size - TRANSCRIPT_TAIL_BYTES);
71
+ let text = await file.slice(start).text();
72
+ if (start > 0) text = text.slice(text.indexOf("\n") + 1);
86
73
  const rows: TranscriptRow[] = [];
87
74
  for (const line of text.split("\n")) {
88
75
  const parsed = TranscriptRowSchema.safeParse(JsonTextSchema.safeParse(line).data);