claude-use 11.87.5 → 11.88.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/README.md +1 -0
- package/dist/cli.cjs +545 -119
- package/dist/index.cjs +531 -185
- package/dist/index.mjs +516 -183
- package/dist/types/index.d.ts +388 -5
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -41980,7 +41980,7 @@ var init_package = __esm({
|
|
|
41980
41980
|
"package.json"() {
|
|
41981
41981
|
package_default = {
|
|
41982
41982
|
name: "claude-use",
|
|
41983
|
-
version: "11.
|
|
41983
|
+
version: "11.88.0",
|
|
41984
41984
|
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.",
|
|
41985
41985
|
license: "MIT",
|
|
41986
41986
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -127199,30 +127199,60 @@ function parseRcRequestBody(kind, body) {
|
|
|
127199
127199
|
}
|
|
127200
127200
|
function createRcSessionTracker(deps) {
|
|
127201
127201
|
const entries = /* @__PURE__ */ new Map();
|
|
127202
|
-
const
|
|
127202
|
+
const retirePending = (entry, requestId, reason) => {
|
|
127203
|
+
if (entry.pending.delete(requestId)) {
|
|
127204
|
+
entry.retired.set(requestId, deps.now());
|
|
127205
|
+
deps.onTransition?.({ kind: "pending-retired", session: entry.id, requestId, reason, at: deps.now() });
|
|
127206
|
+
}
|
|
127207
|
+
};
|
|
127208
|
+
const addPending = (entry, pending) => {
|
|
127209
|
+
if (entry.retired.has(pending.requestId)) {
|
|
127210
|
+
return;
|
|
127211
|
+
}
|
|
127212
|
+
const born = !entry.pending.has(pending.requestId);
|
|
127213
|
+
entry.pending.set(pending.requestId, pending);
|
|
127214
|
+
if (born) {
|
|
127215
|
+
deps.onTransition?.({ kind: "pending-born", session: entry.id, requestId: pending.requestId, type: pending.type, summary: pending.summary, at: pending.observedAt });
|
|
127216
|
+
}
|
|
127217
|
+
};
|
|
127218
|
+
const expire = (id2, reason) => {
|
|
127219
|
+
const entry = entries.get(id2);
|
|
127220
|
+
if (entry === void 0) {
|
|
127221
|
+
return;
|
|
127222
|
+
}
|
|
127223
|
+
for (const requestId of [...entry.pending.keys()]) {
|
|
127224
|
+
retirePending(entry, requestId, "session-ended");
|
|
127225
|
+
}
|
|
127203
127226
|
entries.delete(id2);
|
|
127227
|
+
deps.onTransition?.({ kind: "session-ended", session: id2, reason, at: deps.now() });
|
|
127204
127228
|
};
|
|
127205
127229
|
const expirePendings = (entry, now) => {
|
|
127206
127230
|
for (const [requestId, pending] of entry.pending) {
|
|
127207
127231
|
if (now - pending.observedAt >= RC_PENDING_DEADLINE_MS) {
|
|
127208
|
-
entry
|
|
127232
|
+
retirePending(entry, requestId, "expired");
|
|
127233
|
+
}
|
|
127234
|
+
}
|
|
127235
|
+
for (const [requestId, retiredAt] of entry.retired) {
|
|
127236
|
+
if (now - retiredAt >= RC_PENDING_DEADLINE_MS) {
|
|
127237
|
+
entry.retired.delete(requestId);
|
|
127209
127238
|
}
|
|
127210
127239
|
}
|
|
127211
127240
|
};
|
|
127212
127241
|
const sweep = () => {
|
|
127213
127242
|
for (const [id2, entry] of entries) {
|
|
127214
127243
|
if (deps.now() - entry.lastSeenAt >= deps.idleMs) {
|
|
127215
|
-
expire(id2);
|
|
127244
|
+
expire(id2, "expired");
|
|
127216
127245
|
continue;
|
|
127217
127246
|
}
|
|
127218
127247
|
expirePendings(entry, deps.now());
|
|
127219
127248
|
}
|
|
127220
127249
|
};
|
|
127221
|
-
const timer = setInterval(sweep, deps.idleMs);
|
|
127250
|
+
const timer = setInterval(sweep, Math.min(deps.idleMs, RC_PENDING_DEADLINE_MS));
|
|
127222
127251
|
timer.unref();
|
|
127223
127252
|
const birth = (id2, facts) => {
|
|
127224
|
-
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), workerState: void 0, workerIdleSeconds: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map() };
|
|
127253
|
+
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new Map(), workerState: void 0, workerIdleSeconds: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map() };
|
|
127225
127254
|
entries.set(id2, record3);
|
|
127255
|
+
deps.onTransition?.({ kind: "session-appeared", session: id2, at: record3.createdAt });
|
|
127226
127256
|
return record3;
|
|
127227
127257
|
};
|
|
127228
127258
|
const persistCredential = (entry) => {
|
|
@@ -127230,6 +127260,13 @@ function createRcSessionTracker(deps) {
|
|
|
127230
127260
|
deps.credentialStore?.write(entry.id, { authorization: entry.oauthAuthorization, anthropicVersion: entry.anthropicVersion, anthropicClientPlatform: entry.anthropicClientPlatform });
|
|
127231
127261
|
}
|
|
127232
127262
|
};
|
|
127263
|
+
const refresh = (entry, facts) => {
|
|
127264
|
+
entry.lastSeenAt = deps.now();
|
|
127265
|
+
entry.oauthAuthorization = facts.oauthAuthorization ?? entry.oauthAuthorization;
|
|
127266
|
+
entry.anthropicVersion = facts.anthropicVersion ?? entry.anthropicVersion;
|
|
127267
|
+
entry.anthropicClientPlatform = facts.anthropicClientPlatform ?? entry.anthropicClientPlatform;
|
|
127268
|
+
persistCredential(entry);
|
|
127269
|
+
};
|
|
127233
127270
|
const observeExchange = (request7) => {
|
|
127234
127271
|
const method = (request7.method ?? "").toUpperCase();
|
|
127235
127272
|
if (!isRcSessionExchange(request7.url)) {
|
|
@@ -127268,7 +127305,12 @@ function createRcSessionTracker(deps) {
|
|
|
127268
127305
|
if (id3 === void 0) {
|
|
127269
127306
|
return;
|
|
127270
127307
|
}
|
|
127271
|
-
|
|
127308
|
+
const existing = entries.get(id3);
|
|
127309
|
+
if (existing === void 0) {
|
|
127310
|
+
persistCredential(birth(id3, facts));
|
|
127311
|
+
return;
|
|
127312
|
+
}
|
|
127313
|
+
refresh(existing, facts);
|
|
127272
127314
|
}
|
|
127273
127315
|
};
|
|
127274
127316
|
}
|
|
@@ -127277,12 +127319,10 @@ function createRcSessionTracker(deps) {
|
|
|
127277
127319
|
if (id2?.startsWith(RC_SESSION_ID_PREFIX) !== true) {
|
|
127278
127320
|
return void 0;
|
|
127279
127321
|
}
|
|
127280
|
-
const
|
|
127281
|
-
|
|
127282
|
-
|
|
127283
|
-
|
|
127284
|
-
entry.anthropicClientPlatform = facts.anthropicClientPlatform ?? entry.anthropicClientPlatform;
|
|
127285
|
-
persistCredential(entry);
|
|
127322
|
+
const tracked = entries.get(id2);
|
|
127323
|
+
if (tracked !== void 0) {
|
|
127324
|
+
refresh(tracked, facts);
|
|
127325
|
+
}
|
|
127286
127326
|
const bodyKind = method === "POST" && rest === `${id2}/worker/events` ? "worker-events" : method === "POST" && rest === `${id2}/events` ? "client-events" : method === "POST" && rest === `${id2}/worker/heartbeat` ? "heartbeat" : method === "PUT" && rest === `${id2}/worker` ? "worker-registration" : void 0;
|
|
127287
127327
|
let chunks = [];
|
|
127288
127328
|
let buffered = 0;
|
|
@@ -127303,10 +127343,10 @@ function createRcSessionTracker(deps) {
|
|
|
127303
127343
|
}
|
|
127304
127344
|
const now = deps.now();
|
|
127305
127345
|
for (const controlRequest of factsOfBody.controlRequests) {
|
|
127306
|
-
entryNow
|
|
127346
|
+
addPending(entryNow, { sessionId: id2, ...controlRequest, observedAt: now });
|
|
127307
127347
|
}
|
|
127308
127348
|
for (const requestId of factsOfBody.answeredRequestIds) {
|
|
127309
|
-
entryNow
|
|
127349
|
+
retirePending(entryNow, requestId, "answered");
|
|
127310
127350
|
}
|
|
127311
127351
|
for (const payload of factsOfBody.payloads) {
|
|
127312
127352
|
entryNow.liveTasks = applyAgentTaskEvent(entryNow.liveTasks, id2, payload, now);
|
|
@@ -127315,7 +127355,11 @@ function createRcSessionTracker(deps) {
|
|
|
127315
127355
|
entryNow.workerIdleSeconds = { value: factsOfBody.idleSeconds, observedAt: now };
|
|
127316
127356
|
}
|
|
127317
127357
|
if (factsOfBody.workerStatus !== void 0) {
|
|
127358
|
+
const previous = entryNow.workerState?.value;
|
|
127318
127359
|
entryNow.workerState = { value: factsOfBody.workerStatus, observedAt: now };
|
|
127360
|
+
if (previous !== factsOfBody.workerStatus) {
|
|
127361
|
+
deps.onTransition?.({ kind: "worker-state", session: id2, state: factsOfBody.workerStatus, ...previous === void 0 ? {} : { previous }, at: now });
|
|
127362
|
+
}
|
|
127319
127363
|
}
|
|
127320
127364
|
};
|
|
127321
127365
|
const archiving = method === "POST" && rest === `${id2}/archive`;
|
|
@@ -127340,10 +127384,13 @@ function createRcSessionTracker(deps) {
|
|
|
127340
127384
|
onResponse: (status, headers) => {
|
|
127341
127385
|
if (singleHeader(headers, CONFLICT_REASON_HEADER) !== void 0 || archiving && isSuccessful(status)) {
|
|
127342
127386
|
deps.credentialStore?.remove(id2);
|
|
127343
|
-
expire(id2);
|
|
127387
|
+
expire(id2, singleHeader(headers, CONFLICT_REASON_HEADER) === void 0 ? "archived" : "conflict");
|
|
127344
127388
|
return;
|
|
127345
127389
|
}
|
|
127346
127390
|
accepted = isSuccessful(status);
|
|
127391
|
+
if (accepted && !entries.has(id2)) {
|
|
127392
|
+
persistCredential(birth(id2, facts));
|
|
127393
|
+
}
|
|
127347
127394
|
file2();
|
|
127348
127395
|
},
|
|
127349
127396
|
onBodyChunk: () => {
|
|
@@ -127408,12 +127455,12 @@ function createRcSessionTracker(deps) {
|
|
|
127408
127455
|
const pending = pendingOfControlRequestPayload(event.payload);
|
|
127409
127456
|
if (pending !== void 0) {
|
|
127410
127457
|
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
127411
|
-
entry
|
|
127458
|
+
addPending(entry, { sessionId, ...pending, observedAt: deps.now() });
|
|
127412
127459
|
}
|
|
127413
127460
|
return;
|
|
127414
127461
|
}
|
|
127415
127462
|
for (const requestId of answeredRequestIdsOfControlResponsePayload(event.payload)) {
|
|
127416
|
-
entry
|
|
127463
|
+
retirePending(entry, requestId, "answered");
|
|
127417
127464
|
}
|
|
127418
127465
|
},
|
|
127419
127466
|
liveTasksOf: (sessionId) => {
|
|
@@ -127421,10 +127468,14 @@ function createRcSessionTracker(deps) {
|
|
|
127421
127468
|
return sortedEntries().filter((entry) => sessionId === void 0 || entry.id === sessionId).flatMap((entry) => [...entry.liveTasks.values()].sort((left, right) => left.observedAt - right.observedAt || (left.taskId < right.taskId ? -1 : 1)));
|
|
127422
127469
|
},
|
|
127423
127470
|
completePending: (sessionId, requestId) => {
|
|
127424
|
-
entries.get(sessionId)
|
|
127471
|
+
const entry = entries.get(sessionId);
|
|
127472
|
+
if (entry !== void 0) {
|
|
127473
|
+
retirePending(entry, requestId, "answered");
|
|
127474
|
+
}
|
|
127425
127475
|
},
|
|
127426
127476
|
close: () => {
|
|
127427
127477
|
clearInterval(timer);
|
|
127478
|
+
deps.onClose?.();
|
|
127428
127479
|
}
|
|
127429
127480
|
};
|
|
127430
127481
|
}
|
|
@@ -141660,104 +141711,8 @@ function createAgentTreesApiRouter(deps) {
|
|
|
141660
141711
|
};
|
|
141661
141712
|
}
|
|
141662
141713
|
|
|
141663
|
-
// src/frontdoor/
|
|
141664
|
-
|
|
141665
|
-
var FRONTDOOR_API_TAG2 = "frontdoor";
|
|
141666
|
-
var CHECK_API_TAG = "check";
|
|
141667
|
-
var DOCTOR_API_TAG = "doctor";
|
|
141668
|
-
var POOL_API_TAG = "pool";
|
|
141669
|
-
function createControlApiRouter(deps) {
|
|
141670
|
-
const authed = doorApiAuth(deps.expectedToken);
|
|
141671
|
-
return {
|
|
141672
|
-
usage: {
|
|
141673
|
-
list: authed.meta(openapi({ method: "GET", path: "/rest/usage/snapshots", summary: "List every identity's usage snapshot", tags: [USAGE_API_TAG] })).output(UsageListOutputSchema).handler(() => ({ snapshots: deps.usageSnapshots() })),
|
|
141674
|
-
resets: authed.meta(openapi({ method: "GET", path: "/rest/usage/resets", summary: "List every recorded quota window with when it resets", tags: [USAGE_API_TAG] })).output(ResetScheduleSchema).handler(() => collectResets(deps.usageSnapshots(), deps.now())),
|
|
141675
|
-
effectiveWindow: authed.meta(openapi({ method: "GET", path: "/rest/usage/windows", summary: "Read one identity's effective quota windows", tags: [USAGE_API_TAG] })).input(UsageWindowsInputSchema).output(UsageWindowsOutputSchema).handler(({ input: input2 }) => {
|
|
141676
|
-
const snapshot = deps.usageSnapshotOf(input2.identity);
|
|
141677
|
-
if (snapshot === void 0) {
|
|
141678
|
-
throw new ORPCError("NOT_FOUND", { message: `identity ${input2.identity} has no usage snapshot yet, so no quota window has been observed for it` });
|
|
141679
|
-
}
|
|
141680
|
-
const provider = input2.provider ?? ANTHROPIC_PROVIDER;
|
|
141681
|
-
const rateLimit = snapshot.providers[provider]?.rateLimit;
|
|
141682
|
-
const unified = rateLimit?.unified;
|
|
141683
|
-
const now = deps.now();
|
|
141684
|
-
return {
|
|
141685
|
-
identity: snapshot.identity,
|
|
141686
|
-
provider,
|
|
141687
|
-
...rateLimit === void 0 ? {} : { observedAt: rateLimit.observedAt },
|
|
141688
|
-
...unified?.fiveHour === void 0 ? {} : { fiveHour: effectiveWindow(unified.fiveHour, now) },
|
|
141689
|
-
...unified?.sevenDay === void 0 ? {} : { sevenDay: effectiveWindow(unified.sevenDay, now) }
|
|
141690
|
-
};
|
|
141691
|
-
}),
|
|
141692
|
-
live: authed.meta(openapi({ method: "GET", path: "/rest/usage/live", summary: "Read the live rate-limit observations the event backbone files", tags: [USAGE_API_TAG] })).input(RcSessionQuerySchema).output(UsageLiveOutputSchema).handler(({ input: input2 }) => {
|
|
141693
|
-
const sessions = deps.liveRateLimits(input2.session);
|
|
141694
|
-
if (input2.session !== void 0 && sessions.length === 0) {
|
|
141695
|
-
if (deps.list().some((session) => session.id === input2.session)) {
|
|
141696
|
-
throw new ORPCError("NOT_FOUND", { message: `session ${input2.session} has filed no rate_limit_event on its stream yet: the worker emits one only once a turn has completed, so retry after this session's next turn` });
|
|
141697
|
-
}
|
|
141698
|
-
throw new ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input2.session) });
|
|
141699
|
-
}
|
|
141700
|
-
return { latest: deps.latestRateLimit(), sessions };
|
|
141701
|
-
})
|
|
141702
|
-
},
|
|
141703
|
-
frontdoor: {
|
|
141704
|
-
status: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/status", summary: "Read the front door's status", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorStatusOutputSchema).handler(() => deps.frontDoorStatus()),
|
|
141705
|
-
sessions: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/sessions", summary: "Read the front door's session registry", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorSessionsOutputSchema).handler(() => ({ sessions: deps.frontDoorStatus().sessions }))
|
|
141706
|
-
},
|
|
141707
|
-
check: {
|
|
141708
|
-
// The report's own JSON shape is the contract (the same one `check --json` prints and `checkReportSchema.ts` defines), so the procedure returns exactly that conversion.
|
|
141709
|
-
run: authed.meta(openapi({ method: "GET", path: "/rest/check", summary: "Run the check report for one directory", tags: [CHECK_API_TAG] })).input(CheckRunInputSchema).output(CheckReportJsonSchema).handler(({ input: input2 }) => checkReportToJson(deps.checkReport(input2.path, input2.identity)))
|
|
141710
|
-
},
|
|
141711
|
-
doctor: {
|
|
141712
|
-
run: authed.meta(openapi({ method: "GET", path: "/rest/doctor", summary: "Run the doctor report", tags: [DOCTOR_API_TAG] })).output(DoctorRunOutputSchema).handler(() => deps.doctorReport())
|
|
141713
|
-
},
|
|
141714
|
-
pool: {
|
|
141715
|
-
pick: authed.meta(openapi({ method: "GET", path: "/rest/pool/pick", summary: "Rank one pool exactly as a launch from a directory would right now", tags: [POOL_API_TAG] })).input(PoolPickInputSchema).output(PoolPickReportSchema).handler(({ input: input2 }) => {
|
|
141716
|
-
const report = deps.poolPick(input2.pool, input2.path);
|
|
141717
|
-
if (report === void 0) {
|
|
141718
|
-
const live = deps.poolNames();
|
|
141719
|
-
throw new ORPCError("NOT_FOUND", {
|
|
141720
|
-
message: live.length === 0 ? `no pools are configured, so none is named ${input2.pool}` : `no pool is named ${input2.pool}; the live pools are ${live.map((name) => `"${name}"`).join(", ")}`
|
|
141721
|
-
});
|
|
141722
|
-
}
|
|
141723
|
-
return report;
|
|
141724
|
-
})
|
|
141725
|
-
}
|
|
141726
|
-
};
|
|
141727
|
-
}
|
|
141728
|
-
function createDoorApiRouter(deps) {
|
|
141729
|
-
const control = createControlApiRouter(deps);
|
|
141730
|
-
const lifecycle = createLifecycleApiRouter(deps);
|
|
141731
|
-
return { ...createRcApiRouter(deps), ...control, ...lifecycle, ...createConfigApiRouter(deps), ...createCodexApiRouter(deps), ...createLaunchApiRouter(deps), ...createAgentTreesApiRouter(deps), ...createEventsApiRouter(deps), frontdoor: { ...control.frontdoor, ...lifecycle.frontdoor } };
|
|
141732
|
-
}
|
|
141733
|
-
function createDoorApiNodeHandler(deps) {
|
|
141734
|
-
return doorApiNodeHandlerOf(createDoorApiRouter(deps), deps.expectedToken);
|
|
141735
|
-
}
|
|
141736
|
-
|
|
141737
|
-
// src/frontdoor/doorHealthEvents.ts
|
|
141738
|
-
function createDoorHealthPublisher(hub, now, pid) {
|
|
141739
|
-
const publisher = hub.publisher(DOOR_HEALTH_EVENT_SOURCE);
|
|
141740
|
-
return {
|
|
141741
|
-
generation: (ports) => {
|
|
141742
|
-
publisher.publish({ kind: "generation", pid, providerPort: ports.providerPort, connectPort: ports.connectPort, directPort: ports.directPort, observedAt: now() });
|
|
141743
|
-
},
|
|
141744
|
-
listenerFailed: (listener, message) => {
|
|
141745
|
-
publisher.publish({ kind: "listenerFailed", pid, listener, message, observedAt: now() });
|
|
141746
|
-
},
|
|
141747
|
-
idleShutdown: () => {
|
|
141748
|
-
publisher.publish({ kind: "idleShutdown", pid, observedAt: now() });
|
|
141749
|
-
},
|
|
141750
|
-
binaryTurnover: () => {
|
|
141751
|
-
publisher.publish({ kind: "binaryTurnover", pid, observedAt: now() });
|
|
141752
|
-
},
|
|
141753
|
-
superseded: (ownerPid) => {
|
|
141754
|
-
publisher.publish({ kind: "superseded", pid, ownerPid, observedAt: now() });
|
|
141755
|
-
},
|
|
141756
|
-
drained: () => {
|
|
141757
|
-
publisher.publish({ kind: "drained", pid, observedAt: now() });
|
|
141758
|
-
}
|
|
141759
|
-
};
|
|
141760
|
-
}
|
|
141714
|
+
// src/frontdoor/rcEventLog.ts
|
|
141715
|
+
init_zod();
|
|
141761
141716
|
|
|
141762
141717
|
// src/frontdoor/eventHub.ts
|
|
141763
141718
|
var DOOR_EVENT_BUFFER_EVENTS = 100;
|
|
@@ -141865,6 +141820,369 @@ function rcFanoutOnDoorHub(fanout, hub) {
|
|
|
141865
141820
|
};
|
|
141866
141821
|
}
|
|
141867
141822
|
|
|
141823
|
+
// src/frontdoor/rcEventLog.ts
|
|
141824
|
+
var RC_SESSION_EVENT_TOKEN_MAX_CHARS = 255;
|
|
141825
|
+
var HIGH_SURROGATE_FIRST = 55296;
|
|
141826
|
+
var HIGH_SURROGATE_LAST = 56319;
|
|
141827
|
+
var LOW_SURROGATE_FIRST = 56320;
|
|
141828
|
+
var LOW_SURROGATE_LAST = 57343;
|
|
141829
|
+
var CUT_MARKER = "...";
|
|
141830
|
+
var RC_SESSION_EVENT_SUMMARY_MAX_CHARS = RC_SESSION_EVENT_TOKEN_MAX_CHARS + " ".length + RC_PENDING_SUMMARY_EXCERPT_CHARS + CUT_MARKER.length;
|
|
141831
|
+
var RC_SESSION_EVENT_GENERATION_MAX_CHARS = "00000000-0000-4000-8000-000000000000".length;
|
|
141832
|
+
var SEQUENCE_MAX_DIGITS = String(Number.MAX_SAFE_INTEGER).length;
|
|
141833
|
+
var NUMBER_BYTES = Float64Array.BYTES_PER_ELEMENT;
|
|
141834
|
+
var NUMBER_FIELDS = ["at", "sequence"].length;
|
|
141835
|
+
var BYTES_PER_CODE_UNIT = Uint16Array.BYTES_PER_ELEMENT;
|
|
141836
|
+
var RC_SESSION_END_REASONS = ["expired", "archived", "conflict"];
|
|
141837
|
+
var RC_PENDING_RETIRE_REASONS = ["answered", "expired", "session-ended"];
|
|
141838
|
+
var transitionBase = { session: external_exports.string(), at: external_exports.number() };
|
|
141839
|
+
var cursorFields = { cursor: external_exports.string(), sequence: external_exports.int().positive() };
|
|
141840
|
+
var sessionAppearedShape = { kind: external_exports.literal("session-appeared"), ...transitionBase };
|
|
141841
|
+
var sessionEndedShape = { kind: external_exports.literal("session-ended"), reason: external_exports.enum(RC_SESSION_END_REASONS), ...transitionBase };
|
|
141842
|
+
var workerStateShape = { kind: external_exports.literal("worker-state"), state: external_exports.string(), previous: external_exports.string().optional(), ...transitionBase };
|
|
141843
|
+
var pendingBornShape = { kind: external_exports.literal("pending-born"), requestId: external_exports.string(), type: external_exports.string(), summary: external_exports.string(), ...transitionBase };
|
|
141844
|
+
var pendingRetiredShape = { kind: external_exports.literal("pending-retired"), requestId: external_exports.string(), reason: external_exports.enum(RC_PENDING_RETIRE_REASONS), ...transitionBase };
|
|
141845
|
+
var RcSessionTransitionSchema = external_exports.discriminatedUnion("kind", [
|
|
141846
|
+
external_exports.strictObject(sessionAppearedShape),
|
|
141847
|
+
external_exports.strictObject(sessionEndedShape),
|
|
141848
|
+
external_exports.strictObject(workerStateShape),
|
|
141849
|
+
external_exports.strictObject(pendingBornShape),
|
|
141850
|
+
external_exports.strictObject(pendingRetiredShape)
|
|
141851
|
+
]);
|
|
141852
|
+
var KIND_MAX_CHARS = Math.max(...RcSessionTransitionSchema.options.map((option) => option.shape.kind.value.length));
|
|
141853
|
+
var RC_SESSION_EVENT_MAX_BYTES = (RC_SESSION_EVENT_GENERATION_MAX_CHARS + ".".length + SEQUENCE_MAX_DIGITS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + KIND_MAX_CHARS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + RC_SESSION_EVENT_SUMMARY_MAX_CHARS) * BYTES_PER_CODE_UNIT + NUMBER_FIELDS * NUMBER_BYTES;
|
|
141854
|
+
var RC_SESSION_EVENT_LOG_CAPACITY = Math.floor(CONTROL_BODY_CAP_BYTES / RC_SESSION_EVENT_MAX_BYTES);
|
|
141855
|
+
var RcSessionEventSchema = external_exports.discriminatedUnion("kind", [
|
|
141856
|
+
external_exports.strictObject({ ...cursorFields, ...sessionAppearedShape }),
|
|
141857
|
+
external_exports.strictObject({ ...cursorFields, ...sessionEndedShape }),
|
|
141858
|
+
external_exports.strictObject({ ...cursorFields, ...workerStateShape }),
|
|
141859
|
+
external_exports.strictObject({ ...cursorFields, ...pendingBornShape }),
|
|
141860
|
+
external_exports.strictObject({ ...cursorFields, ...pendingRetiredShape })
|
|
141861
|
+
]);
|
|
141862
|
+
var RcSessionEventsReadInputSchema = external_exports.strictObject({
|
|
141863
|
+
/** The cursor of the last event the caller saw; every retained event when omitted. */
|
|
141864
|
+
since: external_exports.string().min(1).optional(),
|
|
141865
|
+
/** One `cse_` session id; every session when omitted. */
|
|
141866
|
+
session: external_exports.string().min(1).optional(),
|
|
141867
|
+
/** The most events one answer carries; every event after `since` when omitted. */
|
|
141868
|
+
limit: external_exports.int().positive().optional()
|
|
141869
|
+
});
|
|
141870
|
+
var RcSessionEventsPageInputSchema = RcSessionEventsReadInputSchema.extend({
|
|
141871
|
+
/** The most events this page carries: by default and at most, the bound the door's event backbone already holds per slow consumer (`DOOR_EVENT_BUFFER_EVENTS`, oRPC's own documented default for that case). A page lands whole in its reader, so a reader receives at most one consumer buffer's worth at a time (at worst `DOOR_EVENT_BUFFER_EVENTS` times `RC_SESSION_EVENT_MAX_BYTES`) and pages on with the cursor for more; a maximum of the whole window would let one page carry the log's entire memory budget into an agent's context. */
|
|
141872
|
+
limit: external_exports.int().positive().max(DOOR_EVENT_BUFFER_EVENTS).default(DOOR_EVENT_BUFFER_EVENTS)
|
|
141873
|
+
});
|
|
141874
|
+
var RcSessionEventsStreamInputSchema = RcSessionEventsReadInputSchema.omit({ limit: true });
|
|
141875
|
+
var RcSessionEventsReadOutputSchema = external_exports.discriminatedUnion("status", [
|
|
141876
|
+
external_exports.strictObject({ status: external_exports.literal("ok"), events: external_exports.readonly(external_exports.array(RcSessionEventSchema)), cursor: external_exports.string(), more: external_exports.boolean(), head: external_exports.string() }),
|
|
141877
|
+
external_exports.strictObject({ status: external_exports.literal("expired"), message: external_exports.string(), head: external_exports.string() })
|
|
141878
|
+
]);
|
|
141879
|
+
var CURSOR_SEPARATOR = ".";
|
|
141880
|
+
var RESYNC_ADVICE = "cursor expired, resync from status: read `rc status` for every session's present state, then resume after the head this answer names";
|
|
141881
|
+
function cursorOf(generation, sequence2) {
|
|
141882
|
+
return `${generation}${CURSOR_SEPARATOR}${String(sequence2)}`;
|
|
141883
|
+
}
|
|
141884
|
+
function parseCursor(cursor3) {
|
|
141885
|
+
const at2 = cursor3.lastIndexOf(CURSOR_SEPARATOR);
|
|
141886
|
+
if (at2 <= 0) {
|
|
141887
|
+
return void 0;
|
|
141888
|
+
}
|
|
141889
|
+
const digits = cursor3.slice(at2 + 1);
|
|
141890
|
+
if (!/^[0-9]+$/.test(digits)) {
|
|
141891
|
+
return void 0;
|
|
141892
|
+
}
|
|
141893
|
+
return { generation: cursor3.slice(0, at2), sequence: Number(digits) };
|
|
141894
|
+
}
|
|
141895
|
+
function codePointBoundary(text5, at2) {
|
|
141896
|
+
const before = text5.charCodeAt(at2 - 1);
|
|
141897
|
+
const after = text5.charCodeAt(at2);
|
|
141898
|
+
const isHigh = before >= HIGH_SURROGATE_FIRST && before <= HIGH_SURROGATE_LAST;
|
|
141899
|
+
const isLow = after >= LOW_SURROGATE_FIRST && after <= LOW_SURROGATE_LAST;
|
|
141900
|
+
return isHigh && isLow ? at2 - 1 : at2;
|
|
141901
|
+
}
|
|
141902
|
+
function bounded2(text5, maxChars) {
|
|
141903
|
+
const kept = text5.length <= maxChars ? text5 : `${text5.slice(0, codePointBoundary(text5, maxChars - CUT_MARKER.length))}${CUT_MARKER}`;
|
|
141904
|
+
return Buffer.from(kept, "utf16le").toString("utf16le");
|
|
141905
|
+
}
|
|
141906
|
+
function boundedTransition(transition) {
|
|
141907
|
+
const session = bounded2(transition.session, RC_SESSION_EVENT_TOKEN_MAX_CHARS);
|
|
141908
|
+
if (transition.kind === "worker-state") {
|
|
141909
|
+
return { ...transition, session, state: bounded2(transition.state, RC_SESSION_EVENT_TOKEN_MAX_CHARS), ...transition.previous === void 0 ? {} : { previous: bounded2(transition.previous, RC_SESSION_EVENT_TOKEN_MAX_CHARS) } };
|
|
141910
|
+
}
|
|
141911
|
+
if (transition.kind === "pending-born") {
|
|
141912
|
+
return { ...transition, session, requestId: bounded2(transition.requestId, RC_SESSION_EVENT_TOKEN_MAX_CHARS), type: bounded2(transition.type, RC_SESSION_EVENT_TOKEN_MAX_CHARS), summary: bounded2(transition.summary, RC_SESSION_EVENT_SUMMARY_MAX_CHARS) };
|
|
141913
|
+
}
|
|
141914
|
+
if (transition.kind === "pending-retired") {
|
|
141915
|
+
return { ...transition, session, requestId: bounded2(transition.requestId, RC_SESSION_EVENT_TOKEN_MAX_CHARS) };
|
|
141916
|
+
}
|
|
141917
|
+
return { ...transition, session };
|
|
141918
|
+
}
|
|
141919
|
+
function createRcSessionEventLog(deps) {
|
|
141920
|
+
if (deps.generation.includes(CURSOR_SEPARATOR)) {
|
|
141921
|
+
throw new Error(`a door generation id must not contain "${CURSOR_SEPARATOR}", which separates a cursor's generation from its sequence`);
|
|
141922
|
+
}
|
|
141923
|
+
if (deps.generation.length > RC_SESSION_EVENT_GENERATION_MAX_CHARS) {
|
|
141924
|
+
throw new Error(`a door generation id must be at most ${String(RC_SESSION_EVENT_GENERATION_MAX_CHARS)} characters, a UUID's length`);
|
|
141925
|
+
}
|
|
141926
|
+
const events = [];
|
|
141927
|
+
let lastSequence = 0;
|
|
141928
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
141929
|
+
let isClosed = false;
|
|
141930
|
+
const expired = (reason) => ({ status: "expired", message: `${reason}; ${RESYNC_ADVICE}`, head: cursorOf(deps.generation, lastSequence) });
|
|
141931
|
+
return {
|
|
141932
|
+
append: (transition) => {
|
|
141933
|
+
lastSequence += 1;
|
|
141934
|
+
events.push({ ...boundedTransition(transition), cursor: cursorOf(deps.generation, lastSequence), sequence: lastSequence });
|
|
141935
|
+
if (events.length > deps.capacity) {
|
|
141936
|
+
events.splice(0, events.length - deps.capacity);
|
|
141937
|
+
}
|
|
141938
|
+
for (const listener of listeners) {
|
|
141939
|
+
listener();
|
|
141940
|
+
}
|
|
141941
|
+
},
|
|
141942
|
+
head: () => cursorOf(deps.generation, lastSequence),
|
|
141943
|
+
read: ({ since, session, limit }) => {
|
|
141944
|
+
let after = 0;
|
|
141945
|
+
if (since !== void 0) {
|
|
141946
|
+
const parsed = parseCursor(since);
|
|
141947
|
+
if (parsed === void 0) {
|
|
141948
|
+
return expired(`"${since}" is not a cursor this door issues`);
|
|
141949
|
+
}
|
|
141950
|
+
if (parsed.generation !== deps.generation) {
|
|
141951
|
+
return expired(`the cursor "${since}" was issued by another generation of the front door, whose events this one never held`);
|
|
141952
|
+
}
|
|
141953
|
+
if (parsed.sequence > lastSequence) {
|
|
141954
|
+
return expired(`the cursor "${since}" names an event past this door's newest`);
|
|
141955
|
+
}
|
|
141956
|
+
const oldest = events[0]?.sequence ?? lastSequence + 1;
|
|
141957
|
+
if (parsed.sequence < oldest - 1) {
|
|
141958
|
+
return expired(`the events after "${since}" have been evicted (the log retains the newest ${String(deps.capacity)} and the oldest it still holds is "${cursorOf(deps.generation, oldest)}")`);
|
|
141959
|
+
}
|
|
141960
|
+
after = parsed.sequence;
|
|
141961
|
+
}
|
|
141962
|
+
const selected2 = [];
|
|
141963
|
+
let cursor3 = cursorOf(deps.generation, lastSequence);
|
|
141964
|
+
let more = false;
|
|
141965
|
+
for (const event of events) {
|
|
141966
|
+
if (event.sequence <= after || session !== void 0 && event.session !== session) {
|
|
141967
|
+
continue;
|
|
141968
|
+
}
|
|
141969
|
+
if (limit !== void 0 && selected2.length === limit) {
|
|
141970
|
+
more = true;
|
|
141971
|
+
cursor3 = selected2.at(-1)?.cursor ?? cursor3;
|
|
141972
|
+
break;
|
|
141973
|
+
}
|
|
141974
|
+
selected2.push(event);
|
|
141975
|
+
}
|
|
141976
|
+
return { status: "ok", events: selected2, cursor: cursor3, more, head: cursorOf(deps.generation, lastSequence) };
|
|
141977
|
+
},
|
|
141978
|
+
onAppend: (listener) => {
|
|
141979
|
+
listeners.add(listener);
|
|
141980
|
+
return () => {
|
|
141981
|
+
listeners.delete(listener);
|
|
141982
|
+
};
|
|
141983
|
+
},
|
|
141984
|
+
close: () => {
|
|
141985
|
+
if (isClosed) {
|
|
141986
|
+
return;
|
|
141987
|
+
}
|
|
141988
|
+
isClosed = true;
|
|
141989
|
+
for (const listener of listeners) {
|
|
141990
|
+
listener();
|
|
141991
|
+
}
|
|
141992
|
+
},
|
|
141993
|
+
closed: () => isClosed
|
|
141994
|
+
};
|
|
141995
|
+
}
|
|
141996
|
+
var RcSessionEventCursorExpiredError = class extends Error {
|
|
141997
|
+
/** The cursor naming the log's newest event at the moment of the refusal: where to resume after once the status read has restated the present. */
|
|
141998
|
+
head;
|
|
141999
|
+
constructor(message, head) {
|
|
142000
|
+
super(message);
|
|
142001
|
+
this.name = "RcSessionEventCursorExpiredError";
|
|
142002
|
+
this.head = head;
|
|
142003
|
+
}
|
|
142004
|
+
};
|
|
142005
|
+
function followRcSessionEvents(log, input2, signal) {
|
|
142006
|
+
return followAfter(log, input2.since ?? log.head(), input2.session, signal);
|
|
142007
|
+
}
|
|
142008
|
+
async function* followAfter(log, since, session, signal) {
|
|
142009
|
+
let cursor3 = since;
|
|
142010
|
+
let onAbort = () => void 0;
|
|
142011
|
+
const aborted2 = new Promise((resolve3) => {
|
|
142012
|
+
onAbort = resolve3;
|
|
142013
|
+
});
|
|
142014
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
142015
|
+
try {
|
|
142016
|
+
for (; ; ) {
|
|
142017
|
+
signal?.throwIfAborted();
|
|
142018
|
+
const closedBeforeRead = log.closed();
|
|
142019
|
+
let detach = () => void 0;
|
|
142020
|
+
const woken = new Promise((resolve3) => {
|
|
142021
|
+
detach = log.onAppend(resolve3);
|
|
142022
|
+
});
|
|
142023
|
+
try {
|
|
142024
|
+
const read = log.read({ since: cursor3, ...session === void 0 ? {} : { session } });
|
|
142025
|
+
if (read.status === "expired") {
|
|
142026
|
+
throw new RcSessionEventCursorExpiredError(read.message, read.head);
|
|
142027
|
+
}
|
|
142028
|
+
if (read.events.length === 0) {
|
|
142029
|
+
cursor3 = read.cursor;
|
|
142030
|
+
if (closedBeforeRead) {
|
|
142031
|
+
return;
|
|
142032
|
+
}
|
|
142033
|
+
await Promise.race([woken, aborted2]);
|
|
142034
|
+
continue;
|
|
142035
|
+
}
|
|
142036
|
+
for (const event of read.events) {
|
|
142037
|
+
yield event;
|
|
142038
|
+
cursor3 = event.cursor;
|
|
142039
|
+
}
|
|
142040
|
+
cursor3 = read.cursor;
|
|
142041
|
+
} finally {
|
|
142042
|
+
detach();
|
|
142043
|
+
}
|
|
142044
|
+
}
|
|
142045
|
+
} finally {
|
|
142046
|
+
signal?.removeEventListener("abort", onAbort);
|
|
142047
|
+
}
|
|
142048
|
+
}
|
|
142049
|
+
|
|
142050
|
+
// src/frontdoor/rcEventLogApi.ts
|
|
142051
|
+
var RC_API_TAG2 = "remote-control";
|
|
142052
|
+
var CURSOR_EXPIRED_CODE = "GONE";
|
|
142053
|
+
async function* sseOf(follower) {
|
|
142054
|
+
try {
|
|
142055
|
+
for await (const event of follower) {
|
|
142056
|
+
yield withEventMeta2(event, { id: event.cursor });
|
|
142057
|
+
}
|
|
142058
|
+
} catch (error63) {
|
|
142059
|
+
if (error63 instanceof RcSessionEventCursorExpiredError) {
|
|
142060
|
+
throw new ORPCError(CURSOR_EXPIRED_CODE, { message: error63.message, data: { head: error63.head } });
|
|
142061
|
+
}
|
|
142062
|
+
throw error63;
|
|
142063
|
+
}
|
|
142064
|
+
}
|
|
142065
|
+
function createRcSessionEventsApiRouter(deps) {
|
|
142066
|
+
const authed = doorApiAuth(deps.expectedToken);
|
|
142067
|
+
return {
|
|
142068
|
+
rcSessions: {
|
|
142069
|
+
events: authed.meta(openapi({ method: "GET", path: "/rest/rc/session-events", summary: "Stream every observed session's state transitions, pending requests and endings (SSE), resumable by cursor", tags: [RC_API_TAG2] })).input(RcSessionEventsStreamInputSchema).output(asyncIteratorObject(RcSessionEventSchema)).handler(({ input: input2, signal, lastEventId }) => sseOf(followRcSessionEvents(deps.sessionEvents, { since: lastEventId ?? input2.since, session: input2.session }, signal))),
|
|
142070
|
+
eventsPage: authed.meta(
|
|
142071
|
+
openapi({
|
|
142072
|
+
method: "POST",
|
|
142073
|
+
path: "/rest/rc/session-events/page",
|
|
142074
|
+
summary: "Read every observed session's state transitions, pending requests and endings after a cursor, one page at a time",
|
|
142075
|
+
tags: [RC_API_TAG2],
|
|
142076
|
+
// A POST because the page size is a number a query string cannot type, but the answer changes nothing.
|
|
142077
|
+
spec: (current) => ({ ...current, [READ_ONLY_OPERATION_EXTENSION]: true })
|
|
142078
|
+
})
|
|
142079
|
+
).input(RcSessionEventsPageInputSchema).output(RcSessionEventsReadOutputSchema).handler(({ input: input2 }) => deps.sessionEvents.read(input2))
|
|
142080
|
+
}
|
|
142081
|
+
};
|
|
142082
|
+
}
|
|
142083
|
+
|
|
142084
|
+
// src/frontdoor/controlApi.ts
|
|
142085
|
+
var USAGE_API_TAG = "usage";
|
|
142086
|
+
var FRONTDOOR_API_TAG2 = "frontdoor";
|
|
142087
|
+
var CHECK_API_TAG = "check";
|
|
142088
|
+
var DOCTOR_API_TAG = "doctor";
|
|
142089
|
+
var POOL_API_TAG = "pool";
|
|
142090
|
+
function createControlApiRouter(deps) {
|
|
142091
|
+
const authed = doorApiAuth(deps.expectedToken);
|
|
142092
|
+
return {
|
|
142093
|
+
usage: {
|
|
142094
|
+
list: authed.meta(openapi({ method: "GET", path: "/rest/usage/snapshots", summary: "List every identity's usage snapshot", tags: [USAGE_API_TAG] })).output(UsageListOutputSchema).handler(() => ({ snapshots: deps.usageSnapshots() })),
|
|
142095
|
+
resets: authed.meta(openapi({ method: "GET", path: "/rest/usage/resets", summary: "List every recorded quota window with when it resets", tags: [USAGE_API_TAG] })).output(ResetScheduleSchema).handler(() => collectResets(deps.usageSnapshots(), deps.now())),
|
|
142096
|
+
effectiveWindow: authed.meta(openapi({ method: "GET", path: "/rest/usage/windows", summary: "Read one identity's effective quota windows", tags: [USAGE_API_TAG] })).input(UsageWindowsInputSchema).output(UsageWindowsOutputSchema).handler(({ input: input2 }) => {
|
|
142097
|
+
const snapshot = deps.usageSnapshotOf(input2.identity);
|
|
142098
|
+
if (snapshot === void 0) {
|
|
142099
|
+
throw new ORPCError("NOT_FOUND", { message: `identity ${input2.identity} has no usage snapshot yet, so no quota window has been observed for it` });
|
|
142100
|
+
}
|
|
142101
|
+
const provider = input2.provider ?? ANTHROPIC_PROVIDER;
|
|
142102
|
+
const rateLimit = snapshot.providers[provider]?.rateLimit;
|
|
142103
|
+
const unified = rateLimit?.unified;
|
|
142104
|
+
const now = deps.now();
|
|
142105
|
+
return {
|
|
142106
|
+
identity: snapshot.identity,
|
|
142107
|
+
provider,
|
|
142108
|
+
...rateLimit === void 0 ? {} : { observedAt: rateLimit.observedAt },
|
|
142109
|
+
...unified?.fiveHour === void 0 ? {} : { fiveHour: effectiveWindow(unified.fiveHour, now) },
|
|
142110
|
+
...unified?.sevenDay === void 0 ? {} : { sevenDay: effectiveWindow(unified.sevenDay, now) }
|
|
142111
|
+
};
|
|
142112
|
+
}),
|
|
142113
|
+
live: authed.meta(openapi({ method: "GET", path: "/rest/usage/live", summary: "Read the live rate-limit observations the event backbone files", tags: [USAGE_API_TAG] })).input(RcSessionQuerySchema).output(UsageLiveOutputSchema).handler(({ input: input2 }) => {
|
|
142114
|
+
const sessions = deps.liveRateLimits(input2.session);
|
|
142115
|
+
if (input2.session !== void 0 && sessions.length === 0) {
|
|
142116
|
+
if (deps.list().some((session) => session.id === input2.session)) {
|
|
142117
|
+
throw new ORPCError("NOT_FOUND", { message: `session ${input2.session} has filed no rate_limit_event on its stream yet: the worker emits one only once a turn has completed, so retry after this session's next turn` });
|
|
142118
|
+
}
|
|
142119
|
+
throw new ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input2.session) });
|
|
142120
|
+
}
|
|
142121
|
+
return { latest: deps.latestRateLimit(), sessions };
|
|
142122
|
+
})
|
|
142123
|
+
},
|
|
142124
|
+
frontdoor: {
|
|
142125
|
+
status: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/status", summary: "Read the front door's status", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorStatusOutputSchema).handler(() => deps.frontDoorStatus()),
|
|
142126
|
+
sessions: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/sessions", summary: "Read the front door's session registry", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorSessionsOutputSchema).handler(() => ({ sessions: deps.frontDoorStatus().sessions }))
|
|
142127
|
+
},
|
|
142128
|
+
check: {
|
|
142129
|
+
// The report's own JSON shape is the contract (the same one `check --json` prints and `checkReportSchema.ts` defines), so the procedure returns exactly that conversion.
|
|
142130
|
+
run: authed.meta(openapi({ method: "GET", path: "/rest/check", summary: "Run the check report for one directory", tags: [CHECK_API_TAG] })).input(CheckRunInputSchema).output(CheckReportJsonSchema).handler(({ input: input2 }) => checkReportToJson(deps.checkReport(input2.path, input2.identity)))
|
|
142131
|
+
},
|
|
142132
|
+
doctor: {
|
|
142133
|
+
run: authed.meta(openapi({ method: "GET", path: "/rest/doctor", summary: "Run the doctor report", tags: [DOCTOR_API_TAG] })).output(DoctorRunOutputSchema).handler(() => deps.doctorReport())
|
|
142134
|
+
},
|
|
142135
|
+
pool: {
|
|
142136
|
+
pick: authed.meta(openapi({ method: "GET", path: "/rest/pool/pick", summary: "Rank one pool exactly as a launch from a directory would right now", tags: [POOL_API_TAG] })).input(PoolPickInputSchema).output(PoolPickReportSchema).handler(({ input: input2 }) => {
|
|
142137
|
+
const report = deps.poolPick(input2.pool, input2.path);
|
|
142138
|
+
if (report === void 0) {
|
|
142139
|
+
const live = deps.poolNames();
|
|
142140
|
+
throw new ORPCError("NOT_FOUND", {
|
|
142141
|
+
message: live.length === 0 ? `no pools are configured, so none is named ${input2.pool}` : `no pool is named ${input2.pool}; the live pools are ${live.map((name) => `"${name}"`).join(", ")}`
|
|
142142
|
+
});
|
|
142143
|
+
}
|
|
142144
|
+
return report;
|
|
142145
|
+
})
|
|
142146
|
+
}
|
|
142147
|
+
};
|
|
142148
|
+
}
|
|
142149
|
+
function createDoorApiRouter(deps) {
|
|
142150
|
+
const control = createControlApiRouter(deps);
|
|
142151
|
+
const lifecycle = createLifecycleApiRouter(deps);
|
|
142152
|
+
return { ...createRcApiRouter(deps), ...createRcSessionEventsApiRouter(deps), ...control, ...lifecycle, ...createConfigApiRouter(deps), ...createCodexApiRouter(deps), ...createLaunchApiRouter(deps), ...createAgentTreesApiRouter(deps), ...createEventsApiRouter(deps), frontdoor: { ...control.frontdoor, ...lifecycle.frontdoor } };
|
|
142153
|
+
}
|
|
142154
|
+
function createDoorApiNodeHandler(deps) {
|
|
142155
|
+
return doorApiNodeHandlerOf(createDoorApiRouter(deps), deps.expectedToken);
|
|
142156
|
+
}
|
|
142157
|
+
function frontDoorApiClient(port, ca2, token) {
|
|
142158
|
+
return createORPCClient(frontDoorApiLink(port, ca2, token));
|
|
142159
|
+
}
|
|
142160
|
+
|
|
142161
|
+
// src/frontdoor/doorHealthEvents.ts
|
|
142162
|
+
function createDoorHealthPublisher(hub, now, pid) {
|
|
142163
|
+
const publisher = hub.publisher(DOOR_HEALTH_EVENT_SOURCE);
|
|
142164
|
+
return {
|
|
142165
|
+
generation: (ports) => {
|
|
142166
|
+
publisher.publish({ kind: "generation", pid, providerPort: ports.providerPort, connectPort: ports.connectPort, directPort: ports.directPort, observedAt: now() });
|
|
142167
|
+
},
|
|
142168
|
+
listenerFailed: (listener, message) => {
|
|
142169
|
+
publisher.publish({ kind: "listenerFailed", pid, listener, message, observedAt: now() });
|
|
142170
|
+
},
|
|
142171
|
+
idleShutdown: () => {
|
|
142172
|
+
publisher.publish({ kind: "idleShutdown", pid, observedAt: now() });
|
|
142173
|
+
},
|
|
142174
|
+
binaryTurnover: () => {
|
|
142175
|
+
publisher.publish({ kind: "binaryTurnover", pid, observedAt: now() });
|
|
142176
|
+
},
|
|
142177
|
+
superseded: (ownerPid) => {
|
|
142178
|
+
publisher.publish({ kind: "superseded", pid, ownerPid, observedAt: now() });
|
|
142179
|
+
},
|
|
142180
|
+
drained: () => {
|
|
142181
|
+
publisher.publish({ kind: "drained", pid, observedAt: now() });
|
|
142182
|
+
}
|
|
142183
|
+
};
|
|
142184
|
+
}
|
|
142185
|
+
|
|
141868
142186
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
141869
142187
|
init_pick();
|
|
141870
142188
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
@@ -144988,6 +145306,107 @@ function readFrontDoorControlMaterial(fsPort, paths, purpose) {
|
|
|
144988
145306
|
}
|
|
144989
145307
|
return { port: state.port, ca: ca2, token };
|
|
144990
145308
|
}
|
|
145309
|
+
function frontDoorApiFromState(paths, fsPort = realFarmFs) {
|
|
145310
|
+
const { port, ca: ca2, token } = readFrontDoorControlMaterial(fsPort, paths, "its typed API");
|
|
145311
|
+
return frontDoorApiClient(port, ca2, token);
|
|
145312
|
+
}
|
|
145313
|
+
|
|
145314
|
+
// src/frontdoor/rcEventsCommand.ts
|
|
145315
|
+
init_commandDeps();
|
|
145316
|
+
init_cliError();
|
|
145317
|
+
function detailOf(event) {
|
|
145318
|
+
if (event.kind === "session-ended") {
|
|
145319
|
+
return event.reason;
|
|
145320
|
+
}
|
|
145321
|
+
if (event.kind === "worker-state") {
|
|
145322
|
+
return event.previous === void 0 ? event.state : `${event.previous} -> ${event.state}`;
|
|
145323
|
+
}
|
|
145324
|
+
if (event.kind === "pending-born") {
|
|
145325
|
+
return `${event.requestId} ${event.type}${event.summary === "" ? "" : ` ${event.summary}`}`;
|
|
145326
|
+
}
|
|
145327
|
+
if (event.kind === "pending-retired") {
|
|
145328
|
+
return `${event.requestId} ${event.reason}`;
|
|
145329
|
+
}
|
|
145330
|
+
return "";
|
|
145331
|
+
}
|
|
145332
|
+
function formatRcSessionEvent(event) {
|
|
145333
|
+
const detail = detailOf(event);
|
|
145334
|
+
return `${event.cursor} ${new Date(event.at).toISOString()} ${event.session} ${event.kind}${detail === "" ? "" : ` ${detail}`}`;
|
|
145335
|
+
}
|
|
145336
|
+
function expiredHeadOf(error63) {
|
|
145337
|
+
if (!(error63 instanceof ORPCError) || error63.code !== "GONE") {
|
|
145338
|
+
return void 0;
|
|
145339
|
+
}
|
|
145340
|
+
const data = error63.data;
|
|
145341
|
+
return typeof data === "object" && data !== null && "head" in data && typeof data.head === "string" ? data.head : void 0;
|
|
145342
|
+
}
|
|
145343
|
+
var RcSessionEventsStreamEndedError = class extends Error {
|
|
145344
|
+
lastCursor;
|
|
145345
|
+
constructor(cause, lastCursor) {
|
|
145346
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
145347
|
+
this.name = "RcSessionEventsStreamEndedError";
|
|
145348
|
+
this.lastCursor = lastCursor;
|
|
145349
|
+
}
|
|
145350
|
+
};
|
|
145351
|
+
async function printRcSessionEvents(events, options, write) {
|
|
145352
|
+
let last = options.since;
|
|
145353
|
+
try {
|
|
145354
|
+
for await (const event of events) {
|
|
145355
|
+
write(options.json ? JSON.stringify(event) : formatRcSessionEvent(event));
|
|
145356
|
+
last = event.cursor;
|
|
145357
|
+
}
|
|
145358
|
+
} catch (error63) {
|
|
145359
|
+
throw new RcSessionEventsStreamEndedError(error63, last);
|
|
145360
|
+
}
|
|
145361
|
+
return last;
|
|
145362
|
+
}
|
|
145363
|
+
function lastCursorOf(error63, since) {
|
|
145364
|
+
return error63 instanceof RcSessionEventsStreamEndedError ? error63.lastCursor : since;
|
|
145365
|
+
}
|
|
145366
|
+
function resumeHint(lastCursor) {
|
|
145367
|
+
return lastCursor === void 0 ? "no event was printed; follow afresh, or resume after the head `frontdoor rc events` names" : `resume with --since ${lastCursor}`;
|
|
145368
|
+
}
|
|
145369
|
+
function registerRcEventsCommand(rc, paths) {
|
|
145370
|
+
withExamples(
|
|
145371
|
+
rc.command("events").description(
|
|
145372
|
+
"Follow every observed Remote Control session at once: each session appearing or ending, each worker state change (idle, running, requires_action), and each pending control request's birth and retirement, every line tagged with its session and the cursor a later --since resumes after. A cursor the door no longer holds (evicted, or from a previous door) fails naming the head to resume after once `frontdoor rc status` has restated the present. It does not reconnect: when the stream ends or fails (a door restart above all, whose new generation would refuse the cursor anyway), or Ctrl-C leaves it, it names the last cursor printed. Read-only, until Ctrl-C leaves."
|
|
145373
|
+
).argument("[session]", "One cse_ session id, to follow that session alone; every observed session when omitted.").option("--all", "Follow every observed session: the explicit spelling of omitting the session.").option("--since <cursor>", "Resume after this cursor, replaying what was missed; only what happens next when omitted.").option("--json", "Print each event as one JSON line as it arrives.").action(async (session, options) => {
|
|
145374
|
+
if (options.all === true && session !== void 0) {
|
|
145375
|
+
throw new UsageError("name one session or pass --all, not both");
|
|
145376
|
+
}
|
|
145377
|
+
const client = frontDoorApiFromState(paths);
|
|
145378
|
+
const leave = new AbortController();
|
|
145379
|
+
const onInterrupt = () => {
|
|
145380
|
+
leave.abort();
|
|
145381
|
+
};
|
|
145382
|
+
process.once("SIGINT", onInterrupt);
|
|
145383
|
+
try {
|
|
145384
|
+
const stream = await client.rcSessions.events({ ...session === void 0 ? {} : { session }, ...options.since === void 0 ? {} : { since: options.since } }, { signal: leave.signal });
|
|
145385
|
+
const last = await printRcSessionEvents(stream, { json: options.json === true, since: options.since }, (line) => {
|
|
145386
|
+
console.log(line);
|
|
145387
|
+
});
|
|
145388
|
+
console.error(`agent-shim: the event stream ended; ${resumeHint(last)}`);
|
|
145389
|
+
} catch (error63) {
|
|
145390
|
+
if (leave.signal.aborted) {
|
|
145391
|
+
console.error(`agent-shim: left the event stream; ${resumeHint(lastCursorOf(error63, options.since))}`);
|
|
145392
|
+
return;
|
|
145393
|
+
}
|
|
145394
|
+
const cause = error63 instanceof RcSessionEventsStreamEndedError ? error63.cause : error63;
|
|
145395
|
+
const head = expiredHeadOf(cause);
|
|
145396
|
+
if (head !== void 0 && cause instanceof Error) {
|
|
145397
|
+
throw new Error(`${cause.message} (resume with --since ${head})`, { cause: error63 });
|
|
145398
|
+
}
|
|
145399
|
+
if (error63 instanceof RcSessionEventsStreamEndedError) {
|
|
145400
|
+
throw new Error(`${error63.message}; ${resumeHint(error63.lastCursor)}`, { cause: error63 });
|
|
145401
|
+
}
|
|
145402
|
+
throw error63;
|
|
145403
|
+
} finally {
|
|
145404
|
+
process.off("SIGINT", onInterrupt);
|
|
145405
|
+
}
|
|
145406
|
+
}),
|
|
145407
|
+
["agent-shim frontdoor rc events --all", "agent-shim frontdoor rc events --all --since 00000000-0000-4000-8000-000000000000.42 --json"]
|
|
145408
|
+
);
|
|
145409
|
+
}
|
|
144991
145410
|
|
|
144992
145411
|
// src/frontdoor/rcLiveUsage.ts
|
|
144993
145412
|
var RC_RATE_LIMIT_EVENT_TYPE = "rate_limit_event";
|
|
@@ -145553,6 +145972,7 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
145553
145972
|
}),
|
|
145554
145973
|
["agent-shim frontdoor rc watch", "agent-shim frontdoor rc watch cse_00000000-0000-4000-8000-000000000000 --json"]
|
|
145555
145974
|
);
|
|
145975
|
+
registerRcEventsCommand(rc, paths);
|
|
145556
145976
|
const selfhost = withExamples(
|
|
145557
145977
|
rc.command("selfhost").description("Mint the local credential behind the door's self-hosted Remote Control surface: the opt-in mode (AGENT_SHIM_FRONTDOOR_RC_SELF_HOST=1 in the door's environment) where the door serves the CCR surface itself and a session activates Remote Control with no Anthropic credential anywhere."),
|
|
145558
145978
|
["agent-shim frontdoor rc selfhost mint rig"]
|
|
@@ -148179,7 +148599,8 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148179
148599
|
log
|
|
148180
148600
|
}) : void 0;
|
|
148181
148601
|
const rcCredentialStore = createRcCredentialStore(realFarmFs, paths.frontdoorRcCredentialsDir);
|
|
148182
|
-
const
|
|
148602
|
+
const rcSessionEvents = createRcSessionEventLog({ generation: (0, import_node_crypto29.randomUUID)(), capacity: RC_SESSION_EVENT_LOG_CAPACITY });
|
|
148603
|
+
const rcTracker = createRcSessionTracker({ now: () => Date.now(), idleMs: RC_IDLE_EXPIRY_MS, credentialStore: rcCredentialStore, onTransition: rcSessionEvents.append, onClose: rcSessionEvents.close });
|
|
148183
148604
|
const doorEvents = createDoorEventHub();
|
|
148184
148605
|
const usagePublisher = doorEvents.publisher(USAGE_EVENT_SOURCE);
|
|
148185
148606
|
const usageEventNames = createIdentityNameReader(paths);
|
|
@@ -148509,6 +148930,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148509
148930
|
mcpOAuthCallbackUrl: rcMcpOAuthCallbackUrl,
|
|
148510
148931
|
teleport: rcTeleport,
|
|
148511
148932
|
fanout: rcFanout,
|
|
148933
|
+
sessionEvents: rcSessionEvents,
|
|
148512
148934
|
...controlDeps,
|
|
148513
148935
|
...lifecycleAndCodexDeps,
|
|
148514
148936
|
keychain: doorKeychainProbe(process.platform),
|
|
@@ -148614,7 +149036,11 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148614
149036
|
});
|
|
148615
149037
|
return { port: handle.port, listening: server, close: handle.close, drain: handle.drain };
|
|
148616
149038
|
},
|
|
148617
|
-
|
|
149039
|
+
// The tracker closes with the hub: its close ends every session-events follower, so a supervisor's open stream ends with the door instead of holding a retiring door's drain open for as long as the subscriber stays connected.
|
|
149040
|
+
closeRcStreamHub: () => {
|
|
149041
|
+
rcHub.close();
|
|
149042
|
+
rcTracker.close();
|
|
149043
|
+
},
|
|
148618
149044
|
respawnChain: {
|
|
148619
149045
|
generation: respawnGeneration,
|
|
148620
149046
|
startNext: async () => {
|