agent-shim 11.0.0 → 11.2.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/dist/cli.cjs CHANGED
@@ -3467,14 +3467,14 @@ var init_schemas = __esm({
3467
3467
  const desc = Object.getOwnPropertyDescriptor(def, "shape");
3468
3468
  const sh2 = desc?.get ? desc.get.raw : def.shape ?? {};
3469
3469
  if (sh2) {
3470
- const get2 = () => {
3470
+ const get3 = () => {
3471
3471
  const newSh = { ...sh2 };
3472
3472
  Object.defineProperty(def, "shape", { value: newSh });
3473
- get2.raw = newSh;
3473
+ get3.raw = newSh;
3474
3474
  return newSh;
3475
3475
  };
3476
- get2.raw = sh2;
3477
- Object.defineProperty(def, "shape", { get: get2 });
3476
+ get3.raw = sh2;
3477
+ Object.defineProperty(def, "shape", { get: get3 });
3478
3478
  }
3479
3479
  const _normalized = cached(() => normalizeDef(def));
3480
3480
  defineLazyInternal(inst, "propValues", (zod) => {
@@ -33969,7 +33969,7 @@ var init_package = __esm({
33969
33969
  "package.json"() {
33970
33970
  package_default = {
33971
33971
  name: "agent-shim",
33972
- version: "11.0.0",
33972
+ version: "11.2.0",
33973
33973
  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.",
33974
33974
  license: "MIT",
33975
33975
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -109879,12 +109879,12 @@ function resolveWriteTarget(context) {
109879
109879
  activeConfigProfile: context.activeConfigProfile
109880
109880
  });
109881
109881
  }
109882
- function resolveCategoryState(get2) {
109882
+ function resolveCategoryState(get3) {
109883
109883
  return {
109884
- runtime: get2("runtime") ?? SHIPPED_CATEGORY_DEFAULTS.runtime,
109885
- history: get2("history") ?? SHIPPED_CATEGORY_DEFAULTS.history,
109886
- knowledge: get2("knowledge") ?? SHIPPED_CATEGORY_DEFAULTS.knowledge,
109887
- settings: get2("settings") ?? SHIPPED_CATEGORY_DEFAULTS.settings
109884
+ runtime: get3("runtime") ?? SHIPPED_CATEGORY_DEFAULTS.runtime,
109885
+ history: get3("history") ?? SHIPPED_CATEGORY_DEFAULTS.history,
109886
+ knowledge: get3("knowledge") ?? SHIPPED_CATEGORY_DEFAULTS.knowledge,
109887
+ settings: get3("settings") ?? SHIPPED_CATEGORY_DEFAULTS.settings
109888
109888
  };
109889
109889
  }
109890
109890
  function currentCategoryState(context) {
@@ -113453,6 +113453,7 @@ function createDoorPipelines(deps) {
113453
113453
  responseObservers: deps.responseObservers,
113454
113454
  admit: admitLaunch(deps.isLiveToken),
113455
113455
  headroom: { headroomSocket: deps.headroomSocket, hopSecret: deps.hopSecret, custody: deps.custody, log: deps.log },
113456
+ headroomDecision: deps.headroomDecision,
113456
113457
  now: deps.now,
113457
113458
  log: deps.log
113458
113459
  },
@@ -113460,12 +113461,45 @@ function createDoorPipelines(deps) {
113460
113461
  resolveRoute: deps.resolveRoute,
113461
113462
  responseObservers: [],
113462
113463
  admit: admitHop(deps.hopSecret, deps.custody),
113464
+ headroomDecision: deps.headroomDecision,
113463
113465
  now: deps.now,
113464
113466
  log: deps.log
113465
113467
  }
113466
113468
  };
113467
113469
  }
113468
113470
 
113471
+ // src/frontdoor/headroomDecision.ts
113472
+ init_pick();
113473
+ function createHeadroomDecision() {
113474
+ const sessions = /* @__PURE__ */ new Map();
113475
+ return {
113476
+ decide: async (sessionId, wanted, nowMs, available) => {
113477
+ if (sessionId === void 0) {
113478
+ return wanted && await available();
113479
+ }
113480
+ const state = sessions.get(sessionId);
113481
+ const atBoundary = state === void 0 || nowMs - state.lastEndedAtMs > PROMPT_CACHE_TTL_MS || state.cacheReadInputTokens === 0;
113482
+ const viaHeadroom = atBoundary ? wanted && await available() : state.viaHeadroom;
113483
+ sessions.set(sessionId, { viaHeadroom, lastEndedAtMs: state?.lastEndedAtMs ?? nowMs, cacheReadInputTokens: state?.cacheReadInputTokens ?? 0 });
113484
+ return viaHeadroom;
113485
+ },
113486
+ observe: ({ sessionId, endedAtMs, cacheReadInputTokens }) => {
113487
+ if (sessionId === void 0 || cacheReadInputTokens === void 0) {
113488
+ return;
113489
+ }
113490
+ const state = sessions.get(sessionId);
113491
+ if (state !== void 0) {
113492
+ sessions.set(sessionId, { ...state, lastEndedAtMs: endedAtMs, cacheReadInputTokens });
113493
+ }
113494
+ for (const [id2, held] of sessions) {
113495
+ if (endedAtMs - held.lastEndedAtMs > PROMPT_CACHE_TTL_MS) {
113496
+ sessions.delete(id2);
113497
+ }
113498
+ }
113499
+ }
113500
+ };
113501
+ }
113502
+
113469
113503
  // src/frontdoor/commands.ts
113470
113504
  init_capability();
113471
113505
  init_capture();
@@ -126230,6 +126264,33 @@ async function answerBadGateway(response, message) {
126230
126264
  response.end();
126231
126265
  }
126232
126266
  var HOP_AGENT = new http4.Agent({ keepAlive: false });
126267
+ async function headroomReady(deps, signal) {
126268
+ const target = deps.headroomSocket();
126269
+ if (target === void 0 || target.refused !== void 0) {
126270
+ return false;
126271
+ }
126272
+ const { socketPath } = target;
126273
+ return await new Promise((resolve2) => {
126274
+ const probe = http4.get({ socketPath, path: "/health", agent: HOP_AGENT, signal }, (response) => {
126275
+ void (0, import_consumers.buffer)(response).then(
126276
+ (body) => {
126277
+ try {
126278
+ const parsed = JSON.parse(body.toString("utf8"));
126279
+ resolve2(response.statusCode === HTTP_STATUS.ok && typeof parsed === "object" && parsed !== null && "ready" in parsed && parsed.ready === true);
126280
+ } catch {
126281
+ resolve2(false);
126282
+ }
126283
+ },
126284
+ () => {
126285
+ resolve2(false);
126286
+ }
126287
+ );
126288
+ });
126289
+ probe.on("error", () => {
126290
+ resolve2(false);
126291
+ });
126292
+ });
126293
+ }
126233
126294
  var HOP_RESET_RETRIES = 1;
126234
126295
  var HOP_RESET_CODES = /* @__PURE__ */ new Set(["ECONNRESET", "EPIPE"]);
126235
126296
  async function collectBody(request7) {
@@ -126451,7 +126512,9 @@ async function serveRouted(request7, deps) {
126451
126512
  response2.end();
126452
126513
  return;
126453
126514
  }
126454
- const viaHeadroom = identified.session.headroom && resolution.route.headroomEligible && deps.headroom !== void 0;
126515
+ const { headroom } = deps;
126516
+ const wantsHeadroom = await deps.headroomDecision.decide(identified.session.sessionId, identified.session.headroom, deps.now(), async () => headroom !== void 0 && await headroomReady(headroom, request7.signal));
126517
+ const viaHeadroom = wantsHeadroom && resolution.route.headroomEligible && deps.headroom !== void 0;
126455
126518
  const response = createRoutedResponse(request7.response, { deps, session: identified.session, route: resolution.route.name, request: { ...observed, viaHeadroom } });
126456
126519
  try {
126457
126520
  if (viaHeadroom) {
@@ -130625,8 +130688,14 @@ function realFrontDoorSupervisorPorts(paths) {
130625
130688
  log(`job keeper failed: ${error63 instanceof Error ? error63.message : String(error63)}`);
130626
130689
  }
130627
130690
  }, ANTHROPIC_USAGE_FRESHNESS_MS).unref();
130691
+ const headroomDecision = createHeadroomDecision();
130692
+ const recordUsage = withQuotaRefresh(usageStore.record, quotaRefresher);
130628
130693
  const usageMiddleware = createUsageMiddleware({
130629
- record: withQuotaRefresh(usageStore.record, quotaRefresher),
130694
+ // Each finished response also tells the per-session headroom decision when the session's cache was last touched and whether it read from it.
130695
+ record: (record2) => {
130696
+ headroomDecision.observe({ sessionId: record2.sessionId, endedAtMs: Date.parse(record2.at) + record2.durationMs, cacheReadInputTokens: record2.usage?.cacheReadInputTokens });
130697
+ recordUsage(record2);
130698
+ },
130630
130699
  defer: (task) => {
130631
130700
  setImmediate(task);
130632
130701
  },
@@ -130641,6 +130710,7 @@ function realFrontDoorSupervisorPorts(paths) {
130641
130710
  headroomSocket: () => headroomSocketTarget(realFarmFs, realHeadroomSocketTrust, paths),
130642
130711
  // The per-generation capability the direct listener demands: held only in this process's memory, so a loopback process that discovers the direct port still cannot use it.
130643
130712
  hopSecret: (0, import_node_crypto20.randomUUID)(),
130713
+ headroomDecision,
130644
130714
  custody: createCredentialCustody(() => (0, import_node_crypto20.randomUUID)()),
130645
130715
  log
130646
130716
  });
package/dist/index.cjs CHANGED
@@ -2758,7 +2758,7 @@ var init_package = __esm({
2758
2758
  "package.json"() {
2759
2759
  package_default = {
2760
2760
  name: "agent-shim",
2761
- version: "11.0.0",
2761
+ version: "11.2.0",
2762
2762
  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.",
2763
2763
  license: "MIT",
2764
2764
  author: "Joseph Mearman <joseph@mearman.co.uk>",
package/dist/index.mjs CHANGED
@@ -2734,7 +2734,7 @@ var init_package = __esm({
2734
2734
  "package.json"() {
2735
2735
  package_default = {
2736
2736
  name: "agent-shim",
2737
- version: "11.0.0",
2737
+ version: "11.2.0",
2738
2738
  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.",
2739
2739
  license: "MIT",
2740
2740
  author: "Joseph Mearman <joseph@mearman.co.uk>",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-shim",
3
- "version": "11.0.0",
3
+ "version": "11.2.0",
4
4
  "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.",
5
5
  "license": "MIT",
6
6
  "author": "Joseph Mearman <joseph@mearman.co.uk>",