agent-shim 11.71.1 → 11.72.1
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/dist/cli.cjs +114 -53
- package/dist/index.cjs +41 -27
- package/dist/index.mjs +41 -27
- package/dist/types/index.d.ts +870 -870
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -37387,7 +37387,7 @@ var init_package = __esm({
|
|
|
37387
37387
|
"package.json"() {
|
|
37388
37388
|
package_default = {
|
|
37389
37389
|
name: "agent-shim",
|
|
37390
|
-
version: "11.
|
|
37390
|
+
version: "11.72.1",
|
|
37391
37391
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
37392
37392
|
license: "MIT",
|
|
37393
37393
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -38399,36 +38399,71 @@ function readUsageLog(fs31, logDir, options = {}) {
|
|
|
38399
38399
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
38400
38400
|
continue;
|
|
38401
38401
|
}
|
|
38402
|
-
const
|
|
38403
|
-
if (
|
|
38402
|
+
const read = readSegment(fs31, logDir, segment);
|
|
38403
|
+
if (read === void 0) {
|
|
38404
38404
|
continue;
|
|
38405
38405
|
}
|
|
38406
|
-
|
|
38407
|
-
|
|
38408
|
-
|
|
38409
|
-
|
|
38410
|
-
continue;
|
|
38411
|
-
}
|
|
38412
|
-
let raw;
|
|
38413
|
-
try {
|
|
38414
|
-
raw = JSON.parse(line);
|
|
38415
|
-
} catch {
|
|
38416
|
-
invalidLines += 1;
|
|
38417
|
-
continue;
|
|
38418
|
-
}
|
|
38419
|
-
const parsed = UsageRecordSchema.safeParse(raw);
|
|
38420
|
-
if (!parsed.success) {
|
|
38421
|
-
invalidLines += 1;
|
|
38422
|
-
continue;
|
|
38423
|
-
}
|
|
38424
|
-
if (sinceMs === void 0 || Date.parse(parsed.data.at) >= sinceMs) {
|
|
38425
|
-
records.push(parsed.data);
|
|
38406
|
+
invalidLines += read.invalidLines;
|
|
38407
|
+
for (const record2 of read.records) {
|
|
38408
|
+
if (sinceMs === void 0 || Date.parse(record2.at) >= sinceMs) {
|
|
38409
|
+
records.push(record2);
|
|
38426
38410
|
}
|
|
38427
38411
|
}
|
|
38428
38412
|
}
|
|
38429
38413
|
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
38430
38414
|
return { records, invalidLines };
|
|
38431
38415
|
}
|
|
38416
|
+
function readSegment(fs31, logDir, segment) {
|
|
38417
|
+
const contents = fs31.readFileUtf8(import_node_path26.default.join(logDir, segment.name));
|
|
38418
|
+
if (contents === void 0) {
|
|
38419
|
+
return void 0;
|
|
38420
|
+
}
|
|
38421
|
+
const records = [];
|
|
38422
|
+
let invalidLines = 0;
|
|
38423
|
+
const lines = contents.split("\n");
|
|
38424
|
+
lines.pop();
|
|
38425
|
+
for (const line of lines) {
|
|
38426
|
+
if (line === "") {
|
|
38427
|
+
continue;
|
|
38428
|
+
}
|
|
38429
|
+
let raw;
|
|
38430
|
+
try {
|
|
38431
|
+
raw = JSON.parse(line);
|
|
38432
|
+
} catch {
|
|
38433
|
+
invalidLines += 1;
|
|
38434
|
+
continue;
|
|
38435
|
+
}
|
|
38436
|
+
const parsed = UsageRecordSchema.safeParse(raw);
|
|
38437
|
+
if (!parsed.success) {
|
|
38438
|
+
invalidLines += 1;
|
|
38439
|
+
continue;
|
|
38440
|
+
}
|
|
38441
|
+
records.push(parsed.data);
|
|
38442
|
+
}
|
|
38443
|
+
return { records, invalidLines };
|
|
38444
|
+
}
|
|
38445
|
+
function readRecentUsageRecords(fs31, logDir, count2) {
|
|
38446
|
+
const byDay = /* @__PURE__ */ new Map();
|
|
38447
|
+
for (const segment of listLogSegments(fs31, logDir)) {
|
|
38448
|
+
byDay.set(segment.day, [...byDay.get(segment.day) ?? [], segment]);
|
|
38449
|
+
}
|
|
38450
|
+
const days = [...byDay.values()];
|
|
38451
|
+
let records = [];
|
|
38452
|
+
for (let index = days.length - 1; index >= 0; index -= 1) {
|
|
38453
|
+
const dayRecords = [];
|
|
38454
|
+
for (const segment of days[index] ?? []) {
|
|
38455
|
+
dayRecords.push(...readSegment(fs31, logDir, segment)?.records ?? []);
|
|
38456
|
+
}
|
|
38457
|
+
records = [...dayRecords, ...records];
|
|
38458
|
+
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
38459
|
+
const olderDay = days[index - 1]?.[0];
|
|
38460
|
+
const newestHeld = records[records.length - count2];
|
|
38461
|
+
if (olderDay === void 0 || newestHeld !== void 0 && Date.parse(newestHeld.at) >= olderDay.endsAt) {
|
|
38462
|
+
break;
|
|
38463
|
+
}
|
|
38464
|
+
}
|
|
38465
|
+
return records.slice(-count2);
|
|
38466
|
+
}
|
|
38432
38467
|
function snapshotPath(snapshotsDir, identity) {
|
|
38433
38468
|
if (!isIdentityName(identity)) {
|
|
38434
38469
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
@@ -119889,7 +119924,7 @@ function blendedPricePerMTok(prices, mix) {
|
|
|
119889
119924
|
var SEED_LOOKBACK_RECORDS = 500;
|
|
119890
119925
|
function createTargetObservationStore(fs31, paths) {
|
|
119891
119926
|
let observations = /* @__PURE__ */ new Map();
|
|
119892
|
-
const seeded =
|
|
119927
|
+
const seeded = readRecentUsageRecords(fs31, paths.usageLogDir, SEED_LOOKBACK_RECORDS);
|
|
119893
119928
|
for (const record2 of seeded) {
|
|
119894
119929
|
observations = observeRecord(observations, record2);
|
|
119895
119930
|
}
|
|
@@ -134286,6 +134321,10 @@ async function collectBody(body) {
|
|
|
134286
134321
|
resolve3(result);
|
|
134287
134322
|
}
|
|
134288
134323
|
};
|
|
134324
|
+
if (body.destroyed) {
|
|
134325
|
+
settle2({ kind: "failed" });
|
|
134326
|
+
return;
|
|
134327
|
+
}
|
|
134289
134328
|
body.on("data", (chunk2) => {
|
|
134290
134329
|
if (settled) {
|
|
134291
134330
|
return;
|
|
@@ -134309,6 +134348,9 @@ async function collectBody(body) {
|
|
|
134309
134348
|
body.on("error", () => {
|
|
134310
134349
|
settle2({ kind: "failed" });
|
|
134311
134350
|
});
|
|
134351
|
+
body.on("close", () => {
|
|
134352
|
+
settle2({ kind: "failed" });
|
|
134353
|
+
});
|
|
134312
134354
|
});
|
|
134313
134355
|
}
|
|
134314
134356
|
function requestedModelOf(body) {
|
|
@@ -135223,6 +135265,9 @@ function createAntigravityRelay(params) {
|
|
|
135223
135265
|
let currentBlockIndex = -1;
|
|
135224
135266
|
let sawToolUse = false;
|
|
135225
135267
|
let finished = false;
|
|
135268
|
+
let stopReason = "end_turn";
|
|
135269
|
+
const content = [];
|
|
135270
|
+
let activeText;
|
|
135226
135271
|
let usage = {
|
|
135227
135272
|
input_tokens: 0,
|
|
135228
135273
|
cache_creation_input_tokens: 0,
|
|
@@ -135284,6 +135329,8 @@ function createAntigravityRelay(params) {
|
|
|
135284
135329
|
closeActiveBlock();
|
|
135285
135330
|
currentBlockIndex += 1;
|
|
135286
135331
|
activeBlockType = "text";
|
|
135332
|
+
activeText = { type: "text", text: "" };
|
|
135333
|
+
content.push(activeText);
|
|
135287
135334
|
frames.push({
|
|
135288
135335
|
event: "content_block_start",
|
|
135289
135336
|
data: {
|
|
@@ -135293,6 +135340,9 @@ function createAntigravityRelay(params) {
|
|
|
135293
135340
|
}
|
|
135294
135341
|
});
|
|
135295
135342
|
}
|
|
135343
|
+
if (activeText !== void 0) {
|
|
135344
|
+
activeText.text += part.text;
|
|
135345
|
+
}
|
|
135296
135346
|
frames.push({
|
|
135297
135347
|
event: "content_block_delta",
|
|
135298
135348
|
data: {
|
|
@@ -135309,6 +135359,7 @@ function createAntigravityRelay(params) {
|
|
|
135309
135359
|
const callName = part.functionCall.name;
|
|
135310
135360
|
const originalName = params.toolNames.get(callName) ?? callName;
|
|
135311
135361
|
const callId = params.fallbackId();
|
|
135362
|
+
content.push({ type: "tool_use", id: callId, name: originalName, input: part.functionCall.args });
|
|
135312
135363
|
if (typeof part.thoughtSignature === "string") {
|
|
135313
135364
|
rememberToolCallSignature(callId, part.thoughtSignature);
|
|
135314
135365
|
}
|
|
@@ -135342,7 +135393,7 @@ function createAntigravityRelay(params) {
|
|
|
135342
135393
|
}
|
|
135343
135394
|
}
|
|
135344
135395
|
if (candidate?.finishReason !== void 0) {
|
|
135345
|
-
|
|
135396
|
+
stopReason = sawToolUse ? "tool_use" : candidate.finishReason === "MAX_TOKENS" ? "max_tokens" : "end_turn";
|
|
135346
135397
|
closeActiveBlock();
|
|
135347
135398
|
frames.push({
|
|
135348
135399
|
event: "message_delta",
|
|
@@ -135365,7 +135416,7 @@ function createAntigravityRelay(params) {
|
|
|
135365
135416
|
if (!finished) {
|
|
135366
135417
|
ensureStarted();
|
|
135367
135418
|
closeActiveBlock();
|
|
135368
|
-
|
|
135419
|
+
stopReason = sawToolUse ? "tool_use" : "end_turn";
|
|
135369
135420
|
frames.push({
|
|
135370
135421
|
event: "message_delta",
|
|
135371
135422
|
data: {
|
|
@@ -135382,7 +135433,8 @@ function createAntigravityRelay(params) {
|
|
|
135382
135433
|
}
|
|
135383
135434
|
return { frames: [...frames], done: true };
|
|
135384
135435
|
};
|
|
135385
|
-
|
|
135436
|
+
const message = () => ({ id: messageId, type: "message", role: "assistant", model: params.servedModel, content: [...content], stop_reason: stopReason, stop_sequence: null, usage });
|
|
135437
|
+
return { pushChunk, finish, message };
|
|
135386
135438
|
}
|
|
135387
135439
|
|
|
135388
135440
|
// src/antigravity/route.ts
|
|
@@ -135701,12 +135753,12 @@ function createAntigravityRoute(ports) {
|
|
|
135701
135753
|
nowMs,
|
|
135702
135754
|
model: translated.model
|
|
135703
135755
|
});
|
|
135704
|
-
const
|
|
135756
|
+
const frames = async function* () {
|
|
135705
135757
|
try {
|
|
135706
135758
|
if (firstResult.done !== true) {
|
|
135707
135759
|
const step2 = relay.pushChunk(firstResult.value);
|
|
135708
135760
|
for (const frame of step2.frames) {
|
|
135709
|
-
yield
|
|
135761
|
+
yield frame;
|
|
135710
135762
|
}
|
|
135711
135763
|
if (!step2.done) {
|
|
135712
135764
|
for (; ; ) {
|
|
@@ -135719,7 +135771,7 @@ function createAntigravityRoute(ports) {
|
|
|
135719
135771
|
}
|
|
135720
135772
|
const nextStep = relay.pushChunk(nextResult.value);
|
|
135721
135773
|
for (const frame of nextStep.frames) {
|
|
135722
|
-
yield
|
|
135774
|
+
yield frame;
|
|
135723
135775
|
}
|
|
135724
135776
|
if (nextStep.done) {
|
|
135725
135777
|
break;
|
|
@@ -135729,30 +135781,40 @@ function createAntigravityRoute(ports) {
|
|
|
135729
135781
|
}
|
|
135730
135782
|
const finalStep = relay.finish();
|
|
135731
135783
|
for (const frame of finalStep.frames) {
|
|
135732
|
-
yield
|
|
135784
|
+
yield frame;
|
|
135733
135785
|
}
|
|
135734
135786
|
} catch (error63) {
|
|
135735
135787
|
if (!request7.signal.aborted) {
|
|
135736
135788
|
const errMsg = error63 instanceof Error ? error63.message : String(error63);
|
|
135737
|
-
yield
|
|
135738
|
-
event: "error",
|
|
135739
|
-
data: { type: "error", error: { type: "api_error", message: errMsg } }
|
|
135740
|
-
});
|
|
135789
|
+
yield { event: "error", data: { type: "error", error: { type: "api_error", message: errMsg } } };
|
|
135741
135790
|
}
|
|
135742
135791
|
}
|
|
135743
135792
|
};
|
|
135744
|
-
|
|
135745
|
-
|
|
135746
|
-
|
|
135747
|
-
|
|
135748
|
-
|
|
135749
|
-
|
|
135750
|
-
|
|
135751
|
-
|
|
135752
|
-
|
|
135753
|
-
|
|
135754
|
-
|
|
135755
|
-
|
|
135793
|
+
const served = requestedModel !== translated.model ? { requestedModel } : {};
|
|
135794
|
+
if (parsed.data.stream === true) {
|
|
135795
|
+
const rendered = async function* () {
|
|
135796
|
+
for await (const frame of frames()) {
|
|
135797
|
+
yield renderSseFrame2(frame);
|
|
135798
|
+
}
|
|
135799
|
+
};
|
|
135800
|
+
return {
|
|
135801
|
+
status: HTTP_STATUS.ok,
|
|
135802
|
+
headers: {
|
|
135803
|
+
"Content-Type": "text/event-stream",
|
|
135804
|
+
"Cache-Control": "no-cache",
|
|
135805
|
+
Connection: "keep-alive",
|
|
135806
|
+
...quotaHeaders2
|
|
135807
|
+
},
|
|
135808
|
+
body: rendered(),
|
|
135809
|
+
...served
|
|
135810
|
+
};
|
|
135811
|
+
}
|
|
135812
|
+
for await (const frame of frames()) {
|
|
135813
|
+
if (frame.event === "error") {
|
|
135814
|
+
return { status: HTTP_STATUS.badGateway, headers: { "Content-Type": "application/json" }, body: JSON.stringify(frame.data) };
|
|
135815
|
+
}
|
|
135816
|
+
}
|
|
135817
|
+
return { status: HTTP_STATUS.ok, headers: { "Content-Type": "application/json", ...quotaHeaders2 }, body: JSON.stringify(relay.message()), ...served };
|
|
135756
135818
|
};
|
|
135757
135819
|
}
|
|
135758
135820
|
|
|
@@ -139181,6 +139243,7 @@ function createRcEventFanout() {
|
|
|
139181
139243
|
function createRcStreamHub(deps) {
|
|
139182
139244
|
const attachments = /* @__PURE__ */ new Map();
|
|
139183
139245
|
let closed = false;
|
|
139246
|
+
const refusedAuthorizations = /* @__PURE__ */ new Map();
|
|
139184
139247
|
const lastSavedSequenceNums = /* @__PURE__ */ new Map();
|
|
139185
139248
|
const persistCursor = (sessionId) => {
|
|
139186
139249
|
if (deps.saveSequenceNum === void 0) {
|
|
@@ -139284,7 +139347,6 @@ function createRcStreamHub(deps) {
|
|
|
139284
139347
|
};
|
|
139285
139348
|
const runLoop = async (attachment) => {
|
|
139286
139349
|
let retriedUnauthorized = false;
|
|
139287
|
-
let refusedAuthorization;
|
|
139288
139350
|
for (; ; ) {
|
|
139289
139351
|
if (attachment.isStopped()) {
|
|
139290
139352
|
return;
|
|
@@ -139300,11 +139362,11 @@ function createRcStreamHub(deps) {
|
|
|
139300
139362
|
}
|
|
139301
139363
|
return;
|
|
139302
139364
|
}
|
|
139303
|
-
if (
|
|
139365
|
+
if (credential.authorization === refusedAuthorizations.get(attachment.sessionId)) {
|
|
139304
139366
|
await deps.sleep(deps.backoffMs);
|
|
139305
139367
|
continue;
|
|
139306
139368
|
}
|
|
139307
|
-
|
|
139369
|
+
refusedAuthorizations.delete(attachment.sessionId);
|
|
139308
139370
|
let outcome;
|
|
139309
139371
|
try {
|
|
139310
139372
|
outcome = await attempt(attachment, credential);
|
|
@@ -139332,7 +139394,7 @@ function createRcStreamHub(deps) {
|
|
|
139332
139394
|
continue;
|
|
139333
139395
|
}
|
|
139334
139396
|
deps.log?.(`rc stream ${attachment.sessionId}: the client read stream refused the observed Authorization bearer past one retry; waiting for a fresh one`);
|
|
139335
|
-
|
|
139397
|
+
refusedAuthorizations.set(attachment.sessionId, credential.authorization);
|
|
139336
139398
|
await deps.sleep(deps.backoffMs);
|
|
139337
139399
|
retriedUnauthorized = false;
|
|
139338
139400
|
}
|
|
@@ -139372,6 +139434,7 @@ function createRcStreamHub(deps) {
|
|
|
139372
139434
|
attachment.stop();
|
|
139373
139435
|
}
|
|
139374
139436
|
attachments.clear();
|
|
139437
|
+
refusedAuthorizations.clear();
|
|
139375
139438
|
}
|
|
139376
139439
|
};
|
|
139377
139440
|
}
|
|
@@ -140002,10 +140065,8 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
140002
140065
|
catalogueKeeper.tick();
|
|
140003
140066
|
everyFreshnessInterval(catalogueKeeper.tick);
|
|
140004
140067
|
const headroomDecision = createHeadroomDecision(createRoutingSettingReader(paths));
|
|
140005
|
-
const targetObservations = createTargetObservationStore(realFarmFs, paths);
|
|
140006
140068
|
const recordUsage = (record2) => {
|
|
140007
140069
|
withQuotaRefresh(usageStore.record, quotaRefresher)(record2);
|
|
140008
|
-
targetObservations.observe(record2);
|
|
140009
140070
|
};
|
|
140010
140071
|
const usageMiddleware = createUsageMiddleware({
|
|
140011
140072
|
// Each finished response also tells the per-session headroom decision when the session's cache was last touched and whether it read from it.
|
package/dist/index.cjs
CHANGED
|
@@ -4762,7 +4762,7 @@ var init_package = __esm({
|
|
|
4762
4762
|
"package.json"() {
|
|
4763
4763
|
package_default = {
|
|
4764
4764
|
name: "agent-shim",
|
|
4765
|
-
version: "11.
|
|
4765
|
+
version: "11.72.1",
|
|
4766
4766
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
4767
4767
|
license: "MIT",
|
|
4768
4768
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -7606,36 +7606,49 @@ function readUsageLog(fs14, logDir, options = {}) {
|
|
|
7606
7606
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
7607
7607
|
continue;
|
|
7608
7608
|
}
|
|
7609
|
-
const
|
|
7610
|
-
if (
|
|
7609
|
+
const read = readSegment(fs14, logDir, segment);
|
|
7610
|
+
if (read === void 0) {
|
|
7611
7611
|
continue;
|
|
7612
7612
|
}
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
continue;
|
|
7618
|
-
}
|
|
7619
|
-
let raw;
|
|
7620
|
-
try {
|
|
7621
|
-
raw = JSON.parse(line);
|
|
7622
|
-
} catch {
|
|
7623
|
-
invalidLines += 1;
|
|
7624
|
-
continue;
|
|
7625
|
-
}
|
|
7626
|
-
const parsed = UsageRecordSchema.safeParse(raw);
|
|
7627
|
-
if (!parsed.success) {
|
|
7628
|
-
invalidLines += 1;
|
|
7629
|
-
continue;
|
|
7630
|
-
}
|
|
7631
|
-
if (sinceMs === void 0 || Date.parse(parsed.data.at) >= sinceMs) {
|
|
7632
|
-
records.push(parsed.data);
|
|
7613
|
+
invalidLines += read.invalidLines;
|
|
7614
|
+
for (const record of read.records) {
|
|
7615
|
+
if (sinceMs === void 0 || Date.parse(record.at) >= sinceMs) {
|
|
7616
|
+
records.push(record);
|
|
7633
7617
|
}
|
|
7634
7618
|
}
|
|
7635
7619
|
}
|
|
7636
7620
|
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
7637
7621
|
return { records, invalidLines };
|
|
7638
7622
|
}
|
|
7623
|
+
function readSegment(fs14, logDir, segment) {
|
|
7624
|
+
const contents = fs14.readFileUtf8(import_node_path20.default.join(logDir, segment.name));
|
|
7625
|
+
if (contents === void 0) {
|
|
7626
|
+
return void 0;
|
|
7627
|
+
}
|
|
7628
|
+
const records = [];
|
|
7629
|
+
let invalidLines = 0;
|
|
7630
|
+
const lines = contents.split("\n");
|
|
7631
|
+
lines.pop();
|
|
7632
|
+
for (const line of lines) {
|
|
7633
|
+
if (line === "") {
|
|
7634
|
+
continue;
|
|
7635
|
+
}
|
|
7636
|
+
let raw;
|
|
7637
|
+
try {
|
|
7638
|
+
raw = JSON.parse(line);
|
|
7639
|
+
} catch {
|
|
7640
|
+
invalidLines += 1;
|
|
7641
|
+
continue;
|
|
7642
|
+
}
|
|
7643
|
+
const parsed = UsageRecordSchema.safeParse(raw);
|
|
7644
|
+
if (!parsed.success) {
|
|
7645
|
+
invalidLines += 1;
|
|
7646
|
+
continue;
|
|
7647
|
+
}
|
|
7648
|
+
records.push(parsed.data);
|
|
7649
|
+
}
|
|
7650
|
+
return { records, invalidLines };
|
|
7651
|
+
}
|
|
7639
7652
|
function snapshotPath(snapshotsDir, identity) {
|
|
7640
7653
|
if (!isIdentityName(identity)) {
|
|
7641
7654
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
@@ -19527,6 +19540,7 @@ function createRcEventFanout() {
|
|
|
19527
19540
|
function createRcStreamHub(deps) {
|
|
19528
19541
|
const attachments = /* @__PURE__ */ new Map();
|
|
19529
19542
|
let closed = false;
|
|
19543
|
+
const refusedAuthorizations = /* @__PURE__ */ new Map();
|
|
19530
19544
|
const lastSavedSequenceNums = /* @__PURE__ */ new Map();
|
|
19531
19545
|
const persistCursor = (sessionId) => {
|
|
19532
19546
|
if (deps.saveSequenceNum === void 0) {
|
|
@@ -19630,7 +19644,6 @@ function createRcStreamHub(deps) {
|
|
|
19630
19644
|
};
|
|
19631
19645
|
const runLoop = async (attachment) => {
|
|
19632
19646
|
let retriedUnauthorized = false;
|
|
19633
|
-
let refusedAuthorization;
|
|
19634
19647
|
for (; ; ) {
|
|
19635
19648
|
if (attachment.isStopped()) {
|
|
19636
19649
|
return;
|
|
@@ -19646,11 +19659,11 @@ function createRcStreamHub(deps) {
|
|
|
19646
19659
|
}
|
|
19647
19660
|
return;
|
|
19648
19661
|
}
|
|
19649
|
-
if (
|
|
19662
|
+
if (credential.authorization === refusedAuthorizations.get(attachment.sessionId)) {
|
|
19650
19663
|
await deps.sleep(deps.backoffMs);
|
|
19651
19664
|
continue;
|
|
19652
19665
|
}
|
|
19653
|
-
|
|
19666
|
+
refusedAuthorizations.delete(attachment.sessionId);
|
|
19654
19667
|
let outcome;
|
|
19655
19668
|
try {
|
|
19656
19669
|
outcome = await attempt(attachment, credential);
|
|
@@ -19678,7 +19691,7 @@ function createRcStreamHub(deps) {
|
|
|
19678
19691
|
continue;
|
|
19679
19692
|
}
|
|
19680
19693
|
deps.log?.(`rc stream ${attachment.sessionId}: the client read stream refused the observed Authorization bearer past one retry; waiting for a fresh one`);
|
|
19681
|
-
|
|
19694
|
+
refusedAuthorizations.set(attachment.sessionId, credential.authorization);
|
|
19682
19695
|
await deps.sleep(deps.backoffMs);
|
|
19683
19696
|
retriedUnauthorized = false;
|
|
19684
19697
|
}
|
|
@@ -19718,6 +19731,7 @@ function createRcStreamHub(deps) {
|
|
|
19718
19731
|
attachment.stop();
|
|
19719
19732
|
}
|
|
19720
19733
|
attachments.clear();
|
|
19734
|
+
refusedAuthorizations.clear();
|
|
19721
19735
|
}
|
|
19722
19736
|
};
|
|
19723
19737
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -4738,7 +4738,7 @@ var init_package = __esm({
|
|
|
4738
4738
|
"package.json"() {
|
|
4739
4739
|
package_default = {
|
|
4740
4740
|
name: "agent-shim",
|
|
4741
|
-
version: "11.
|
|
4741
|
+
version: "11.72.1",
|
|
4742
4742
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
4743
4743
|
license: "MIT",
|
|
4744
4744
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -7582,36 +7582,49 @@ function readUsageLog(fs14, logDir, options = {}) {
|
|
|
7582
7582
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
7583
7583
|
continue;
|
|
7584
7584
|
}
|
|
7585
|
-
const
|
|
7586
|
-
if (
|
|
7585
|
+
const read = readSegment(fs14, logDir, segment);
|
|
7586
|
+
if (read === void 0) {
|
|
7587
7587
|
continue;
|
|
7588
7588
|
}
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
continue;
|
|
7594
|
-
}
|
|
7595
|
-
let raw;
|
|
7596
|
-
try {
|
|
7597
|
-
raw = JSON.parse(line);
|
|
7598
|
-
} catch {
|
|
7599
|
-
invalidLines += 1;
|
|
7600
|
-
continue;
|
|
7601
|
-
}
|
|
7602
|
-
const parsed = UsageRecordSchema.safeParse(raw);
|
|
7603
|
-
if (!parsed.success) {
|
|
7604
|
-
invalidLines += 1;
|
|
7605
|
-
continue;
|
|
7606
|
-
}
|
|
7607
|
-
if (sinceMs === void 0 || Date.parse(parsed.data.at) >= sinceMs) {
|
|
7608
|
-
records.push(parsed.data);
|
|
7589
|
+
invalidLines += read.invalidLines;
|
|
7590
|
+
for (const record of read.records) {
|
|
7591
|
+
if (sinceMs === void 0 || Date.parse(record.at) >= sinceMs) {
|
|
7592
|
+
records.push(record);
|
|
7609
7593
|
}
|
|
7610
7594
|
}
|
|
7611
7595
|
}
|
|
7612
7596
|
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
7613
7597
|
return { records, invalidLines };
|
|
7614
7598
|
}
|
|
7599
|
+
function readSegment(fs14, logDir, segment) {
|
|
7600
|
+
const contents = fs14.readFileUtf8(path20.join(logDir, segment.name));
|
|
7601
|
+
if (contents === void 0) {
|
|
7602
|
+
return void 0;
|
|
7603
|
+
}
|
|
7604
|
+
const records = [];
|
|
7605
|
+
let invalidLines = 0;
|
|
7606
|
+
const lines = contents.split("\n");
|
|
7607
|
+
lines.pop();
|
|
7608
|
+
for (const line of lines) {
|
|
7609
|
+
if (line === "") {
|
|
7610
|
+
continue;
|
|
7611
|
+
}
|
|
7612
|
+
let raw;
|
|
7613
|
+
try {
|
|
7614
|
+
raw = JSON.parse(line);
|
|
7615
|
+
} catch {
|
|
7616
|
+
invalidLines += 1;
|
|
7617
|
+
continue;
|
|
7618
|
+
}
|
|
7619
|
+
const parsed = UsageRecordSchema.safeParse(raw);
|
|
7620
|
+
if (!parsed.success) {
|
|
7621
|
+
invalidLines += 1;
|
|
7622
|
+
continue;
|
|
7623
|
+
}
|
|
7624
|
+
records.push(parsed.data);
|
|
7625
|
+
}
|
|
7626
|
+
return { records, invalidLines };
|
|
7627
|
+
}
|
|
7615
7628
|
function snapshotPath(snapshotsDir, identity) {
|
|
7616
7629
|
if (!isIdentityName(identity)) {
|
|
7617
7630
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
@@ -19112,6 +19125,7 @@ function createRcEventFanout() {
|
|
|
19112
19125
|
function createRcStreamHub(deps) {
|
|
19113
19126
|
const attachments = /* @__PURE__ */ new Map();
|
|
19114
19127
|
let closed = false;
|
|
19128
|
+
const refusedAuthorizations = /* @__PURE__ */ new Map();
|
|
19115
19129
|
const lastSavedSequenceNums = /* @__PURE__ */ new Map();
|
|
19116
19130
|
const persistCursor = (sessionId) => {
|
|
19117
19131
|
if (deps.saveSequenceNum === void 0) {
|
|
@@ -19215,7 +19229,6 @@ function createRcStreamHub(deps) {
|
|
|
19215
19229
|
};
|
|
19216
19230
|
const runLoop = async (attachment) => {
|
|
19217
19231
|
let retriedUnauthorized = false;
|
|
19218
|
-
let refusedAuthorization;
|
|
19219
19232
|
for (; ; ) {
|
|
19220
19233
|
if (attachment.isStopped()) {
|
|
19221
19234
|
return;
|
|
@@ -19231,11 +19244,11 @@ function createRcStreamHub(deps) {
|
|
|
19231
19244
|
}
|
|
19232
19245
|
return;
|
|
19233
19246
|
}
|
|
19234
|
-
if (
|
|
19247
|
+
if (credential.authorization === refusedAuthorizations.get(attachment.sessionId)) {
|
|
19235
19248
|
await deps.sleep(deps.backoffMs);
|
|
19236
19249
|
continue;
|
|
19237
19250
|
}
|
|
19238
|
-
|
|
19251
|
+
refusedAuthorizations.delete(attachment.sessionId);
|
|
19239
19252
|
let outcome;
|
|
19240
19253
|
try {
|
|
19241
19254
|
outcome = await attempt(attachment, credential);
|
|
@@ -19263,7 +19276,7 @@ function createRcStreamHub(deps) {
|
|
|
19263
19276
|
continue;
|
|
19264
19277
|
}
|
|
19265
19278
|
deps.log?.(`rc stream ${attachment.sessionId}: the client read stream refused the observed Authorization bearer past one retry; waiting for a fresh one`);
|
|
19266
|
-
|
|
19279
|
+
refusedAuthorizations.set(attachment.sessionId, credential.authorization);
|
|
19267
19280
|
await deps.sleep(deps.backoffMs);
|
|
19268
19281
|
retriedUnauthorized = false;
|
|
19269
19282
|
}
|
|
@@ -19303,6 +19316,7 @@ function createRcStreamHub(deps) {
|
|
|
19303
19316
|
attachment.stop();
|
|
19304
19317
|
}
|
|
19305
19318
|
attachments.clear();
|
|
19319
|
+
refusedAuthorizations.clear();
|
|
19306
19320
|
}
|
|
19307
19321
|
};
|
|
19308
19322
|
}
|