claude-use 9.15.0 → 9.16.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/index.mjs CHANGED
@@ -2669,7 +2669,7 @@ var init_package = __esm({
2669
2669
  "package.json"() {
2670
2670
  package_default = {
2671
2671
  name: "claude-use",
2672
- version: "9.15.0",
2672
+ version: "9.16.0",
2673
2673
  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.",
2674
2674
  license: "MIT",
2675
2675
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -6630,7 +6630,7 @@ var init_headers = __esm({
6630
6630
  });
6631
6631
 
6632
6632
  // src/launcher/flags.ts
6633
- import path33 from "node:path";
6633
+ import path34 from "node:path";
6634
6634
  function resolveLaunchFlags(params) {
6635
6635
  return {
6636
6636
  skipPermissions: params.flags?.skipPermissions ?? parseEnvBool("AGENT_SHIM_SKIP_PERMISSIONS", params.env.AGENT_SHIM_SKIP_PERMISSIONS) ?? params.cascade?.skipPermissions ?? false,
@@ -6661,7 +6661,7 @@ function buildEnv(params) {
6661
6661
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
6662
6662
  let providerCustomHeaders;
6663
6663
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
6664
- env.CLAUDE_CONFIG_DIR = path33.join(params.identitiesDir, params.resolvedIdentityName);
6664
+ env.CLAUDE_CONFIG_DIR = path34.join(params.identitiesDir, params.resolvedIdentityName);
6665
6665
  }
6666
6666
  if (params.provider !== void 0) {
6667
6667
  const providerEnv = params.provider.definition.env ?? {};
@@ -6928,7 +6928,7 @@ var init_launchHook = __esm({
6928
6928
 
6929
6929
  // src/launcher.ts
6930
6930
  import { randomUUID as randomUUID4 } from "node:crypto";
6931
- import path34 from "node:path";
6931
+ import path35 from "node:path";
6932
6932
  function resolveIdentityCredential(identity, credential, env, port) {
6933
6933
  if (port === void 0) {
6934
6934
  return { ok: false, status: 1, message: `agent-shim: identity ${identity} needs its credential resolved, but this launcher has no credential port wired` };
@@ -7038,7 +7038,7 @@ function decideLaunch(params, readOnly) {
7038
7038
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
7039
7039
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
7040
7040
  });
7041
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(path34.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7041
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(path35.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7042
7042
  log.error(
7043
7043
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
7044
7044
  );
@@ -7150,7 +7150,7 @@ function decideLaunch(params, readOnly) {
7150
7150
  extraFlags: splitExtraFlags(env.CLAUDE_EXTRA_FLAGS),
7151
7151
  passthrough: parsedArgv.rest
7152
7152
  });
7153
- const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : path34.join(paths.identitiesDir, identityDecision.name);
7153
+ const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : path35.join(paths.identitiesDir, identityDecision.name);
7154
7154
  const decision = {
7155
7155
  identitySource: identityDecision.source,
7156
7156
  configDirEscapeHatch: identityDecision.configDirEscapeHatch,
@@ -7191,7 +7191,7 @@ function prepareLaunch(params) {
7191
7191
  );
7192
7192
  const updateCheck = runLaunchUpdateCheck({
7193
7193
  mode: params.updateMode ?? "off",
7194
- checkPath: path34.join(paths.root, "update.check"),
7194
+ checkPath: path35.join(paths.root, "update.check"),
7195
7195
  currentVersion: package_default.version,
7196
7196
  port: params.update
7197
7197
  });
@@ -7351,12 +7351,12 @@ var init_launcher = __esm({
7351
7351
  });
7352
7352
 
7353
7353
  // src/ownCli.ts
7354
- import path35 from "node:path";
7354
+ import path36 from "node:path";
7355
7355
  function agentShimCliPath(distDir = typeof __AGENT_SHIM_DIST_DIR__ === "string" ? __AGENT_SHIM_DIST_DIR__ : void 0) {
7356
7356
  if (distDir === void 0) {
7357
7357
  throw new OwnCliPathUnknownError();
7358
7358
  }
7359
- return path35.join(distDir, OWN_CLI_FILE_NAME);
7359
+ return path36.join(distDir, OWN_CLI_FILE_NAME);
7360
7360
  }
7361
7361
  var OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
7362
7362
  var init_ownCli = __esm({
@@ -7445,10 +7445,10 @@ request.on("error", (error) => finish(failed, (error.code ? error.code + ": " :
7445
7445
 
7446
7446
  // src/frontdoor/trust.ts
7447
7447
  import { createHash as createHash6 } from "node:crypto";
7448
- import path36 from "node:path";
7448
+ import path37 from "node:path";
7449
7449
  function resolveTrustBundle(params) {
7450
7450
  const { caCertFile, bundlesDir, variable, inherited, fs: fs12 } = params;
7451
- if (inherited === void 0 || inherited === "" || path36.resolve(inherited) === path36.resolve(caCertFile)) {
7451
+ if (inherited === void 0 || inherited === "" || path37.resolve(inherited) === path37.resolve(caCertFile)) {
7452
7452
  return { path: caCertFile };
7453
7453
  }
7454
7454
  const caPem = fs12.readFileUtf8(caCertFile);
@@ -7466,7 +7466,7 @@ function resolveTrustBundle(params) {
7466
7466
  }
7467
7467
  const combined = `${inheritedPem.trimEnd()}
7468
7468
  ${caPem}`;
7469
- const bundle = path36.join(bundlesDir, `${createHash6("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
7469
+ const bundle = path37.join(bundlesDir, `${createHash6("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
7470
7470
  if (!fs12.exists(bundle)) {
7471
7471
  fs12.mkdirp(bundlesDir);
7472
7472
  fs12.writeFileAtomic(bundle, combined);
@@ -7866,7 +7866,7 @@ var init_identityClaude = __esm({
7866
7866
  });
7867
7867
 
7868
7868
  // src/usage/providerQuota.ts
7869
- import { z as z25 } from "zod";
7869
+ import { z as z27 } from "zod";
7870
7870
  var MS_PER_SECOND7, SECONDS_PER_HOUR, HOURS_PER_DAY4, DAYS_PER_MONTH, ZAI_HOST, ZAI_QUOTA_URL, ZAI_UNIT_HOURS, ZAI_UNIT_MONTHS, ZAI_UNIT_MS, ZaiLimitSchema, ZaiResponseSchema, OPENROUTER_HOST, OPENROUTER_KEY_URL, OPENROUTER_CREDITS_URL, MS_PER_DAY3, OpenRouterKeySchema, OpenRouterCreditsSchema;
7871
7871
  var init_providerQuota = __esm({
7872
7872
  "src/usage/providerQuota.ts"() {
@@ -7884,35 +7884,35 @@ var init_providerQuota = __esm({
7884
7884
  [ZAI_UNIT_HOURS, SECONDS_PER_HOUR * MS_PER_SECOND7],
7885
7885
  [ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY4 * SECONDS_PER_HOUR * MS_PER_SECOND7]
7886
7886
  ]);
7887
- ZaiLimitSchema = z25.object({
7888
- type: z25.string(),
7889
- unit: z25.number().int(),
7890
- number: z25.number().int().positive(),
7891
- percentage: z25.number().nonnegative(),
7892
- nextResetTime: z25.number().positive().optional(),
7893
- usage: z25.number().nonnegative().optional(),
7894
- currentValue: z25.number().nonnegative().optional(),
7895
- remaining: z25.number().nonnegative().optional()
7887
+ ZaiLimitSchema = z27.object({
7888
+ type: z27.string(),
7889
+ unit: z27.number().int(),
7890
+ number: z27.number().int().positive(),
7891
+ percentage: z27.number().nonnegative(),
7892
+ nextResetTime: z27.number().positive().optional(),
7893
+ usage: z27.number().nonnegative().optional(),
7894
+ currentValue: z27.number().nonnegative().optional(),
7895
+ remaining: z27.number().nonnegative().optional()
7896
7896
  });
7897
- ZaiResponseSchema = z25.object({
7898
- success: z25.boolean(),
7899
- msg: z25.string().optional(),
7900
- data: z25.object({ level: z25.string().optional(), limits: z25.array(ZaiLimitSchema) })
7897
+ ZaiResponseSchema = z27.object({
7898
+ success: z27.boolean(),
7899
+ msg: z27.string().optional(),
7900
+ data: z27.object({ level: z27.string().optional(), limits: z27.array(ZaiLimitSchema) })
7901
7901
  });
7902
7902
  OPENROUTER_HOST = "openrouter.ai";
7903
7903
  OPENROUTER_KEY_URL = `https://${OPENROUTER_HOST}/api/v1/key`;
7904
7904
  OPENROUTER_CREDITS_URL = `https://${OPENROUTER_HOST}/api/v1/credits`;
7905
7905
  MS_PER_DAY3 = HOURS_PER_DAY4 * SECONDS_PER_HOUR * MS_PER_SECOND7;
7906
- OpenRouterKeySchema = z25.object({
7907
- data: z25.object({
7908
- limit: z25.number().nonnegative().nullable(),
7909
- limit_remaining: z25.number().nullable(),
7910
- limit_reset: z25.string().nullable(),
7911
- is_free_tier: z25.boolean().optional(),
7912
- free_model_daily_requests: z25.object({ used: z25.number().nonnegative(), limit: z25.number().nonnegative(), remaining: z25.number() }).optional()
7906
+ OpenRouterKeySchema = z27.object({
7907
+ data: z27.object({
7908
+ limit: z27.number().nonnegative().nullable(),
7909
+ limit_remaining: z27.number().nullable(),
7910
+ limit_reset: z27.string().nullable(),
7911
+ is_free_tier: z27.boolean().optional(),
7912
+ free_model_daily_requests: z27.object({ used: z27.number().nonnegative(), limit: z27.number().nonnegative(), remaining: z27.number() }).optional()
7913
7913
  })
7914
7914
  });
7915
- OpenRouterCreditsSchema = z25.object({ data: z25.object({ total_credits: z25.number().nonnegative(), total_usage: z25.number().nonnegative() }) });
7915
+ OpenRouterCreditsSchema = z27.object({ data: z27.object({ total_credits: z27.number().nonnegative(), total_usage: z27.number().nonnegative() }) });
7916
7916
  }
7917
7917
  });
7918
7918
 
@@ -8525,8 +8525,8 @@ function parseConnectTarget(authority) {
8525
8525
  function isInterceptedHost(host, interceptHosts) {
8526
8526
  return interceptHosts.includes(host);
8527
8527
  }
8528
- function servedByPipeline(path37) {
8529
- return path37?.startsWith(ROUTED_PATH_PREFIX) === true;
8528
+ function servedByPipeline(path38) {
8529
+ return path38?.startsWith(ROUTED_PATH_PREFIX) === true;
8530
8530
  }
8531
8531
  var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
8532
8532
  "connection",
@@ -9061,11 +9061,11 @@ function createRcSessionTracker(deps) {
9061
9061
  };
9062
9062
  const observeExchange = (request4) => {
9063
9063
  const method = (request4.method ?? "").toUpperCase();
9064
- const path37 = new URL(request4.url ?? "/", "http://127.0.0.1").pathname;
9065
- if (!path37.startsWith(RC_SESSIONS_PATH_PREFIX)) {
9064
+ const path38 = new URL(request4.url ?? "/", "http://127.0.0.1").pathname;
9065
+ if (!path38.startsWith(RC_SESSIONS_PATH_PREFIX)) {
9066
9066
  return void 0;
9067
9067
  }
9068
- const tail = path37.slice(RC_SESSIONS_PATH_PREFIX.length);
9068
+ const tail = path38.slice(RC_SESSIONS_PATH_PREFIX.length);
9069
9069
  const facts = {
9070
9070
  oauthAuthorization: oauthAuthorizationOf(request4.headers),
9071
9071
  anthropicVersion: singleHeader(request4.headers, "anthropic-version"),
@@ -9447,8 +9447,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
9447
9447
  function isRcReadFileEncoding(value) {
9448
9448
  return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value);
9449
9449
  }
9450
- function buildRcReadFilePayload(requestId, path37, options) {
9451
- return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path37, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
9450
+ function buildRcReadFilePayload(requestId, path38, options) {
9451
+ return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path38, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
9452
9452
  }
9453
9453
  function buildRcFileSuggestionsPayload(requestId, query) {
9454
9454
  return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
@@ -9550,15 +9550,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
9550
9550
  const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
9551
9551
  return result.ok ? { ...result, requestId } : result;
9552
9552
  }
9553
- async function readRcSessionFile(deps, sessionId, path37, options) {
9554
- if (path37 === "") {
9553
+ async function readRcSessionFile(deps, sessionId, path38, options) {
9554
+ if (path38 === "") {
9555
9555
  return { ok: false, message: "a read-file write needs a non-empty path: the SDK's own field names the file the worker resolves against the session's cwd, and an empty string names none" };
9556
9556
  }
9557
9557
  if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
9558
9558
  return { ok: false, message: "a read-file write's max-bytes is a positive whole number of bytes: the SDK's own field caps the read, and a zero or negative cap reads nothing" };
9559
9559
  }
9560
9560
  const requestId = deps.newUuid();
9561
- const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path37, options), `read ${path37} from session ${sessionId}`);
9561
+ const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path38, options), `read ${path38} from session ${sessionId}`);
9562
9562
  return result.ok ? { ...result, requestId } : result;
9563
9563
  }
9564
9564
  async function suggestRcSessionFiles(deps, sessionId, query) {
@@ -9727,11 +9727,11 @@ function createRcControlHandler(deps) {
9727
9727
  path: "read-file",
9728
9728
  read: (body) => {
9729
9729
  const session = bodyString(body, "session");
9730
- const path37 = bodyString(body, "path");
9730
+ const path38 = bodyString(body, "path");
9731
9731
  const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
9732
9732
  const encoding = "encoding" in body && isRcReadFileEncoding(body.encoding) ? body.encoding : void 0;
9733
- const refused2 = session === void 0 || path37 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
9734
- return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session, path37, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
9733
+ const refused2 = session === void 0 || path38 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
9734
+ return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session, path38, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
9735
9735
  }
9736
9736
  },
9737
9737
  {
@@ -10041,9 +10041,9 @@ function requestIdOfBody(body) {
10041
10041
  }
10042
10042
  function frontDoorRcControl(transport, token) {
10043
10043
  const headers = { authorization: `Bearer ${token}` };
10044
- const listAnswerOf = async (path37, what) => {
10044
+ const listAnswerOf = async (path38, what) => {
10045
10045
  try {
10046
- return await transport.request({ method: "GET", path: path37, headers });
10046
+ return await transport.request({ method: "GET", path: path38, headers });
10047
10047
  } catch (error) {
10048
10048
  throw new Error(`${what}: could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
10049
10049
  }
@@ -10115,10 +10115,10 @@ function frontDoorRcControl(transport, token) {
10115
10115
  }
10116
10116
  return pending;
10117
10117
  };
10118
- const writeOf = async (path37, body, describeFailure) => {
10118
+ const writeOf = async (path38, body, describeFailure2) => {
10119
10119
  let answer;
10120
10120
  try {
10121
- answer = await transport.request({ method: "POST", path: path37, headers: { ...headers, "content-type": "application/json" }, body });
10121
+ answer = await transport.request({ method: "POST", path: path38, headers: { ...headers, "content-type": "application/json" }, body });
10122
10122
  } catch (error) {
10123
10123
  return { ok: false, message: `could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}` };
10124
10124
  }
@@ -10130,7 +10130,7 @@ function frontDoorRcControl(transport, token) {
10130
10130
  const requestId = requestIdOfBody(answer.body);
10131
10131
  return requestId === void 0 ? { ok: true, sequenceNums } : { ok: true, sequenceNums, requestId };
10132
10132
  }
10133
- return { ok: false, message: describeFailure(answer.status, controlErrorOf(answer.body) ?? answer.body) };
10133
+ return { ok: false, message: describeFailure2(answer.status, controlErrorOf(answer.body) ?? answer.body) };
10134
10134
  };
10135
10135
  const sessionQuery = (sessionId) => sessionId === void 0 ? "" : `?session=${encodeURIComponent(sessionId)}`;
10136
10136
  return {
@@ -10149,10 +10149,10 @@ function frontDoorRcControl(transport, token) {
10149
10149
  endSession: async (sessionId, reason) => await writeOf(`${CONTROL_PATH_PREFIX}/end-session`, JSON.stringify({ session: sessionId, ...reason === void 0 ? {} : { reason } }), (status, message) => `ending ${sessionId} failed (HTTP ${String(status)}): ${message}`),
10150
10150
  getUsage: async (sessionId, skipBehaviors) => await writeOf(`${CONTROL_PATH_PREFIX}/get-usage`, JSON.stringify({ session: sessionId, ...skipBehaviors === void 0 ? {} : { skipBehaviors } }), (status, message) => `requesting the usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
10151
10151
  getContextUsage: async (sessionId, detail) => await writeOf(`${CONTROL_PATH_PREFIX}/get-context-usage`, JSON.stringify({ session: sessionId, ...detail === void 0 ? {} : { detail } }), (status, message) => `requesting the context usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
10152
- readFile: async (sessionId, path37, options) => await writeOf(
10152
+ readFile: async (sessionId, path38, options) => await writeOf(
10153
10153
  `${CONTROL_PATH_PREFIX}/read-file`,
10154
- JSON.stringify({ session: sessionId, path: path37, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
10155
- (status, message) => `reading ${path37} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
10154
+ JSON.stringify({ session: sessionId, path: path38, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
10155
+ (status, message) => `reading ${path38} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
10156
10156
  ),
10157
10157
  fileSuggestions: async (sessionId, query) => await writeOf(`${CONTROL_PATH_PREFIX}/file-suggestions`, JSON.stringify({ session: sessionId, query }), (status, message) => `requesting file suggestions from ${sessionId} failed (HTTP ${String(status)}): ${message}`),
10158
10158
  keepAlive: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/keep-alive`, JSON.stringify({ session: sessionId }), (status, message) => `keeping ${sessionId} alive failed (HTTP ${String(status)}): ${message}`),
@@ -10311,12 +10311,12 @@ function tlsFacts(options) {
10311
10311
  }
10312
10312
  function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
10313
10313
  const agent = new ExemptTlsAgent();
10314
- const post = async (path37, headers, body) => await new Promise((resolve, reject) => {
10314
+ const post = async (path38, headers, body) => await new Promise((resolve, reject) => {
10315
10315
  const options = {
10316
10316
  host: target.host,
10317
10317
  port: target.port,
10318
10318
  method: "POST",
10319
- path: path37,
10319
+ path: path38,
10320
10320
  // The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
10321
10321
  headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
10322
10322
  agent
@@ -10381,12 +10381,12 @@ function lateRcStreamDial(resolve) {
10381
10381
  }
10382
10382
  function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
10383
10383
  const agent = new ExemptTlsAgent();
10384
- const request4 = async (method, path37, headers, body, signal) => await new Promise((resolve, reject) => {
10384
+ const request4 = async (method, path38, headers, body, signal) => await new Promise((resolve, reject) => {
10385
10385
  const options = {
10386
10386
  host: target.host,
10387
10387
  port: target.port,
10388
10388
  method,
10389
- path: path37,
10389
+ path: path38,
10390
10390
  // The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
10391
10391
  headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
10392
10392
  agent,
@@ -10428,9 +10428,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
10428
10428
  return { status, body: await readAll(response) };
10429
10429
  },
10430
10430
  openStream: async (sessionId, headers, resume, signal) => {
10431
- const path37 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
10431
+ const path38 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
10432
10432
  const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
10433
- const { status, response } = await request4("GET", path37, streamHeaders, void 0, signal);
10433
+ const { status, response } = await request4("GET", path38, streamHeaders, void 0, signal);
10434
10434
  if (!isSuccessful2(status)) {
10435
10435
  await readAll(response);
10436
10436
  return { status, chunks: NO_CHUNKS };
@@ -11581,19 +11581,19 @@ function writePools(paths, pools) {
11581
11581
  applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
11582
11582
  }
11583
11583
  function poolCycleOf(pools, name) {
11584
- const walk = (current, path37) => {
11584
+ const walk = (current, path38) => {
11585
11585
  for (const entry of pools[current]?.identities ?? []) {
11586
11586
  const nested = poolNameOf(poolMemberIdentity(entry));
11587
11587
  if (nested === void 0) {
11588
11588
  continue;
11589
11589
  }
11590
11590
  if (nested === name) {
11591
- return [...path37, nested];
11591
+ return [...path38, nested];
11592
11592
  }
11593
- if (path37.includes(nested)) {
11593
+ if (path38.includes(nested)) {
11594
11594
  continue;
11595
11595
  }
11596
- const found = walk(nested, [...path37, nested]);
11596
+ const found = walk(nested, [...path38, nested]);
11597
11597
  if (found !== void 0) {
11598
11598
  return found;
11599
11599
  }
@@ -13727,7 +13727,7 @@ function profileValue(name, paths) {
13727
13727
  function createConfigApiRouter(deps) {
13728
13728
  const authed = doorApiAuth(deps.expectedToken);
13729
13729
  const { paths } = deps;
13730
- const route = (path37, summary) => authed.meta(openapi3({ method: "POST", path: path37, summary, tags: [CONFIG_API_TAG] }));
13730
+ const route = (path38, summary) => authed.meta(openapi3({ method: "POST", path: path38, summary, tags: [CONFIG_API_TAG] }));
13731
13731
  return {
13732
13732
  config: {
13733
13733
  identity: {
@@ -16302,6 +16302,376 @@ init_preflight();
16302
16302
  init_pick();
16303
16303
  init_plan2();
16304
16304
  init_poolPick();
16305
+
16306
+ // src/agents/read.ts
16307
+ import path33 from "node:path";
16308
+ import { z as z26 } from "zod";
16309
+
16310
+ // src/agents/schema.ts
16311
+ import { z as z25 } from "zod";
16312
+ var AgentMetaSchema = z25.looseObject({
16313
+ agentType: z25.string(),
16314
+ isFork: z25.boolean().optional(),
16315
+ description: z25.string().optional(),
16316
+ name: z25.string().optional(),
16317
+ toolUseId: z25.string().optional(),
16318
+ spawnDepth: z25.number().int().nonnegative().optional(),
16319
+ parentAgentId: z25.string().optional(),
16320
+ model: z25.string().optional(),
16321
+ requestShape: z25.string().optional(),
16322
+ requestNonInteractive: z25.boolean().optional(),
16323
+ workflowPhase: z25.string().optional(),
16324
+ taskKind: z25.string().optional(),
16325
+ teamName: z25.string().optional(),
16326
+ worktreePath: z25.string().optional(),
16327
+ worktreeBranch: z25.string().optional(),
16328
+ stoppedByUser: z25.boolean().optional()
16329
+ });
16330
+ var AgentKindSchema = z25.enum(["subagent", "fork", "workflow-agent", "teammate"]);
16331
+ var AgentNodeSchema = z25.lazy(
16332
+ () => z25.strictObject({
16333
+ id: z25.string(),
16334
+ kind: AgentKindSchema,
16335
+ agentType: z25.string(),
16336
+ description: z25.string().optional(),
16337
+ name: z25.string().optional(),
16338
+ toolUseId: z25.string().optional(),
16339
+ spawnDepth: z25.number().int().nonnegative().optional(),
16340
+ model: z25.string().optional(),
16341
+ background: z25.boolean().optional(),
16342
+ workflowRunId: z25.string().optional(),
16343
+ workflowPhase: z25.string().optional(),
16344
+ teamName: z25.string().optional(),
16345
+ stoppedByUser: z25.boolean().optional(),
16346
+ transcript: z25.string(),
16347
+ children: z25.array(AgentNodeSchema)
16348
+ })
16349
+ );
16350
+ var TaskItemSchema = z25.strictObject({
16351
+ id: z25.string(),
16352
+ subject: z25.string(),
16353
+ description: z25.string().optional(),
16354
+ status: z25.string(),
16355
+ /** What a spinner shows while the task runs. */
16356
+ activeForm: z25.string().optional(),
16357
+ /** The teammate or agent name the task is assigned to, as Agent Teams writes it. */
16358
+ owner: z25.string().optional(),
16359
+ /** Free-form data the harness attaches to a task, kept as written. */
16360
+ metadata: z25.record(z25.string(), z25.unknown()).optional(),
16361
+ blocks: z25.array(z25.string()),
16362
+ blockedBy: z25.array(z25.string()),
16363
+ /** The id of the shared task list this task belongs to (a team's name, or a custom list id), absent for the session's own list. */
16364
+ taskList: z25.string().optional()
16365
+ });
16366
+ var WorkflowRunSchema = z25.strictObject({
16367
+ runId: z25.string(),
16368
+ workflowName: z25.string().optional(),
16369
+ status: z25.string().optional(),
16370
+ startTime: z25.number().optional(),
16371
+ phases: z25.array(z25.string()),
16372
+ summary: z25.string().optional()
16373
+ });
16374
+ var AgentTreeProblemSchema = z25.strictObject({
16375
+ /** Relative to the identity's configuration directory. */
16376
+ path: z25.string(),
16377
+ reason: z25.string()
16378
+ });
16379
+ var SessionAgentTreeSchema = z25.strictObject({
16380
+ project: z25.string(),
16381
+ sessionId: z25.string(),
16382
+ /** True for a session directory a resume superseded (`<session-id>.superseded-<epoch-ms>`). */
16383
+ superseded: z25.boolean(),
16384
+ /** The agents the session itself spawned, each with its descendants. */
16385
+ agents: z25.array(AgentNodeSchema),
16386
+ tasks: z25.array(TaskItemSchema),
16387
+ workflowRuns: z25.array(WorkflowRunSchema),
16388
+ problems: z25.array(AgentTreeProblemSchema)
16389
+ });
16390
+
16391
+ // src/agents/read.ts
16392
+ var PROJECTS_DIR = "projects";
16393
+ var TASKS_DIR = "tasks";
16394
+ var SUBAGENTS_DIR = "subagents";
16395
+ var WORKFLOWS_DIR = "workflows";
16396
+ var AGENT_FILE_PREFIX = "agent-";
16397
+ var META_SUFFIX = ".meta.json";
16398
+ var TRANSCRIPT_SUFFIX = ".jsonl";
16399
+ var SHORT_SESSION_ID_LENGTH = 8;
16400
+ var SHORT_SESSION_LIST_PREFIX = "session-";
16401
+ var JSON_SUFFIX = ".json";
16402
+ var WORKFLOW_RUN_PREFIX = "wf_";
16403
+ var ARCHIVED_RE = /^(.+)\.(?:superseded|orphaned)-.+$/;
16404
+ var FORK_AGENT_TYPE = "fork";
16405
+ var WORKFLOW_AGENT_TYPE = "workflow-subagent";
16406
+ var TEAMMATE_TASK_KIND = "in_process_teammate";
16407
+ var BACKGROUND_REQUEST_SHAPE = "background";
16408
+ var SESSION_SPAWN_DEPTH = 1;
16409
+ function parseEntry2(project, entry) {
16410
+ const match = ARCHIVED_RE.exec(entry);
16411
+ const base = match?.[1];
16412
+ return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
16413
+ }
16414
+ function listSessions2(fs12, configDir) {
16415
+ const found = [];
16416
+ for (const project of fs12.readdir(path33.join(configDir, PROJECTS_DIR))) {
16417
+ const projectDir = path33.join(configDir, PROJECTS_DIR, project);
16418
+ const entries = /* @__PURE__ */ new Set();
16419
+ for (const name of fs12.readdir(projectDir)) {
16420
+ if (name.endsWith(TRANSCRIPT_SUFFIX)) {
16421
+ entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
16422
+ continue;
16423
+ }
16424
+ const children = fs12.readdir(path33.join(projectDir, name));
16425
+ if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
16426
+ entries.add(name);
16427
+ }
16428
+ }
16429
+ for (const entry of entries) {
16430
+ found.push(parseEntry2(project, entry));
16431
+ }
16432
+ }
16433
+ return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
16434
+ }
16435
+ function locateAgents(fs12, configDir, relativeDir, workflowRunId, report) {
16436
+ const located = [];
16437
+ for (const name of listDirOrReport(fs12, configDir, relativeDir, report)) {
16438
+ if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
16439
+ continue;
16440
+ }
16441
+ const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
16442
+ located.push({
16443
+ id,
16444
+ metaPath: path33.join(relativeDir, name),
16445
+ transcriptPath: path33.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
16446
+ workflowRunId
16447
+ });
16448
+ }
16449
+ return located;
16450
+ }
16451
+ function kindOf(meta, workflowRunId) {
16452
+ if (meta.isFork === true || meta.agentType === FORK_AGENT_TYPE) {
16453
+ return "fork";
16454
+ }
16455
+ if (workflowRunId !== void 0 || meta.agentType === WORKFLOW_AGENT_TYPE) {
16456
+ return "workflow-agent";
16457
+ }
16458
+ if (meta.taskKind === TEAMMATE_TASK_KIND || meta.teamName !== void 0) {
16459
+ return "teammate";
16460
+ }
16461
+ return "subagent";
16462
+ }
16463
+ function toNode(read, children) {
16464
+ const { located, meta } = read;
16465
+ return {
16466
+ id: located.id,
16467
+ kind: kindOf(meta, located.workflowRunId),
16468
+ agentType: meta.agentType,
16469
+ ...meta.description === void 0 ? {} : { description: meta.description },
16470
+ ...meta.name === void 0 ? {} : { name: meta.name },
16471
+ ...meta.toolUseId === void 0 ? {} : { toolUseId: meta.toolUseId },
16472
+ ...meta.spawnDepth === void 0 ? {} : { spawnDepth: meta.spawnDepth },
16473
+ ...meta.model === void 0 ? {} : { model: meta.model },
16474
+ ...meta.requestShape === void 0 ? {} : { background: meta.requestShape === BACKGROUND_REQUEST_SHAPE },
16475
+ ...located.workflowRunId === void 0 ? {} : { workflowRunId: located.workflowRunId },
16476
+ ...meta.workflowPhase === void 0 ? {} : { workflowPhase: meta.workflowPhase },
16477
+ ...meta.teamName === void 0 ? {} : { teamName: meta.teamName },
16478
+ ...meta.stoppedByUser === void 0 ? {} : { stoppedByUser: meta.stoppedByUser },
16479
+ transcript: located.transcriptPath,
16480
+ children
16481
+ };
16482
+ }
16483
+ function describeFailure(error) {
16484
+ return error instanceof Error ? error.message : String(error);
16485
+ }
16486
+ function readFileOrReport(fs12, configDir, relative, report) {
16487
+ try {
16488
+ return fs12.readFileUtf8(path33.join(configDir, relative));
16489
+ } catch (error) {
16490
+ report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
16491
+ return void 0;
16492
+ }
16493
+ }
16494
+ function listDirOrReport(fs12, configDir, relative, report) {
16495
+ try {
16496
+ return fs12.readdir(path33.join(configDir, relative));
16497
+ } catch (error) {
16498
+ report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
16499
+ return [];
16500
+ }
16501
+ }
16502
+ function parseJson2(text) {
16503
+ try {
16504
+ const value = JSON.parse(text);
16505
+ return value;
16506
+ } catch {
16507
+ return void 0;
16508
+ }
16509
+ }
16510
+ var TaskFileSchema = z26.object({ ...TaskItemSchema.omit({ taskList: true }).shape, blocks: z26.array(z26.string()).default([]), blockedBy: z26.array(z26.string()).default([]) });
16511
+ var WorkflowRunFileSchema = z26.object({
16512
+ runId: z26.string(),
16513
+ workflowName: z26.string().optional(),
16514
+ status: z26.string().optional(),
16515
+ startTime: z26.number().optional(),
16516
+ phases: z26.array(z26.object({ title: z26.string() })).default([]),
16517
+ summary: z26.string().optional()
16518
+ });
16519
+ function readSessionAgentTree(fs12, configDir, ref, options = {}) {
16520
+ const problems = [];
16521
+ const report = (problem) => {
16522
+ problems.push(problem);
16523
+ };
16524
+ const sessionRelative = path33.join(PROJECTS_DIR, ref.project, ref.entry);
16525
+ const subagentsRelative = path33.join(sessionRelative, SUBAGENTS_DIR);
16526
+ const workflowsUnderSubagents = path33.join(subagentsRelative, WORKFLOWS_DIR);
16527
+ const located = locateAgents(fs12, configDir, subagentsRelative, void 0, report);
16528
+ for (const runDir of listDirOrReport(fs12, configDir, workflowsUnderSubagents, report)) {
16529
+ if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
16530
+ located.push(...locateAgents(fs12, configDir, path33.join(workflowsUnderSubagents, runDir), runDir, report));
16531
+ }
16532
+ }
16533
+ const agents = /* @__PURE__ */ new Map();
16534
+ for (const candidate of located) {
16535
+ const text = readFileOrReport(fs12, configDir, candidate.metaPath, report);
16536
+ if (text === void 0) {
16537
+ continue;
16538
+ }
16539
+ const parsed = AgentMetaSchema.safeParse(parseJson2(text));
16540
+ if (!parsed.success) {
16541
+ report({ path: candidate.metaPath, reason: "meta file is not a JSON object with an agentType" });
16542
+ continue;
16543
+ }
16544
+ agents.set(candidate.id, { located: candidate, meta: parsed.data });
16545
+ }
16546
+ const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
16547
+ const parentOf3 = resolveParents(fs12, configDir, agents, report);
16548
+ const childrenOf = /* @__PURE__ */ new Map();
16549
+ const roots = [];
16550
+ for (const id of agents.keys()) {
16551
+ const parent = parentOf3.get(id);
16552
+ if (parent === void 0) {
16553
+ roots.push(id);
16554
+ } else {
16555
+ childrenOf.set(parent, [...childrenOf.get(parent) ?? [], id]);
16556
+ }
16557
+ }
16558
+ const build = (id) => {
16559
+ const read = agents.get(id);
16560
+ if (read === void 0) {
16561
+ throw new Error(`agent ${id} is in the tree but was never read`);
16562
+ }
16563
+ return toNode(read, (childrenOf.get(id) ?? []).sort().map(build));
16564
+ };
16565
+ return {
16566
+ project: ref.project,
16567
+ sessionId: ref.sessionId,
16568
+ superseded: ref.superseded,
16569
+ agents: roots.sort().map(build),
16570
+ tasks: readTasks(fs12, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
16571
+ workflowRuns: readWorkflowRuns(fs12, configDir, path33.join(sessionRelative, WORKFLOWS_DIR), report),
16572
+ problems
16573
+ };
16574
+ }
16575
+ function resolveParents(fs12, configDir, agents, report) {
16576
+ const parentOf3 = /* @__PURE__ */ new Map();
16577
+ const transcriptCache = /* @__PURE__ */ new Map();
16578
+ const transcriptOf = (agent) => {
16579
+ const cached = transcriptCache.get(agent.located.id);
16580
+ if (cached !== void 0) {
16581
+ return cached;
16582
+ }
16583
+ const text = readFileOrReport(fs12, configDir, agent.located.transcriptPath, report) ?? "";
16584
+ transcriptCache.set(agent.located.id, text);
16585
+ return text;
16586
+ };
16587
+ const wouldCycle = (child, parent) => {
16588
+ for (let cursor = parent; cursor !== void 0; cursor = parentOf3.get(cursor)) {
16589
+ if (cursor === child) {
16590
+ return true;
16591
+ }
16592
+ }
16593
+ return false;
16594
+ };
16595
+ const attach = (child, parent) => {
16596
+ if (wouldCycle(child.located.id, parent)) {
16597
+ report({ path: child.located.metaPath, reason: `parent ${parent} would make a cycle` });
16598
+ return;
16599
+ }
16600
+ parentOf3.set(child.located.id, parent);
16601
+ };
16602
+ for (const agent of agents.values()) {
16603
+ const { meta, located } = agent;
16604
+ if (meta.parentAgentId !== void 0 && agents.has(meta.parentAgentId)) {
16605
+ attach(agent, meta.parentAgentId);
16606
+ continue;
16607
+ }
16608
+ const depth = meta.spawnDepth;
16609
+ if (depth !== void 0 && depth <= SESSION_SPAWN_DEPTH || meta.toolUseId === void 0) {
16610
+ if (meta.parentAgentId !== void 0) {
16611
+ report({ path: located.metaPath, reason: `parentAgentId ${meta.parentAgentId} names no agent in this session` });
16612
+ }
16613
+ continue;
16614
+ }
16615
+ const toolUseId = meta.toolUseId;
16616
+ const owners = [...agents.values()].filter(
16617
+ (candidate) => candidate.located.id !== located.id && (depth === void 0 || candidate.meta.spawnDepth === void 0 || candidate.meta.spawnDepth === depth - 1) && candidate.located.workflowRunId === located.workflowRunId && transcriptOf(candidate).includes(toolUseId)
16618
+ );
16619
+ const owner = owners[0];
16620
+ if (owners.length === 1 && owner !== void 0) {
16621
+ attach(agent, owner.located.id);
16622
+ } else if (owners.length > 1) {
16623
+ report({ path: located.metaPath, reason: "more than one agent transcript records the call that spawned it" });
16624
+ } else if (depth !== void 0) {
16625
+ report({ path: located.metaPath, reason: "no agent transcript records the call that spawned it" });
16626
+ }
16627
+ }
16628
+ return parentOf3;
16629
+ }
16630
+ function ownTaskLists(sessionId) {
16631
+ return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
16632
+ }
16633
+ function readTasks(fs12, configDir, ownLists, sharedLists, report) {
16634
+ const tasks = [];
16635
+ [...ownLists, ...sharedLists].forEach((scope, index) => {
16636
+ const relativeDir = path33.join(TASKS_DIR, scope);
16637
+ for (const name of [...listDirOrReport(fs12, configDir, relativeDir, report)].sort()) {
16638
+ if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
16639
+ continue;
16640
+ }
16641
+ const relative = path33.join(relativeDir, name);
16642
+ const text = readFileOrReport(fs12, configDir, relative, report);
16643
+ const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
16644
+ if (parsed.success) {
16645
+ tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
16646
+ } else if (text !== void 0) {
16647
+ report({ path: relative, reason: "task file is not a task" });
16648
+ }
16649
+ }
16650
+ });
16651
+ return tasks;
16652
+ }
16653
+ function readWorkflowRuns(fs12, configDir, relativeDir, report) {
16654
+ const runs = [];
16655
+ for (const name of [...listDirOrReport(fs12, configDir, relativeDir, report)].sort()) {
16656
+ if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
16657
+ continue;
16658
+ }
16659
+ const relative = path33.join(relativeDir, name);
16660
+ const text = readFileOrReport(fs12, configDir, relative, report);
16661
+ const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
16662
+ if (!parsed.success) {
16663
+ if (text !== void 0) {
16664
+ report({ path: relative, reason: "workflow run file is not a run record" });
16665
+ }
16666
+ continue;
16667
+ }
16668
+ const { phases, ...rest } = parsed.data;
16669
+ runs.push({ ...rest, phases: phases.map((phase) => phase.title) });
16670
+ }
16671
+ return runs;
16672
+ }
16673
+
16674
+ // src/index.ts
16305
16675
  init_conditions();
16306
16676
  init_ensure();
16307
16677
  init_supervisor();
@@ -16409,6 +16779,9 @@ async function runClaudeLaunch(options) {
16409
16779
  init_ownCli();
16410
16780
  export {
16411
16781
  AMBIENT_CREDENTIAL_VARS,
16782
+ AgentKindSchema,
16783
+ AgentMetaSchema,
16784
+ AgentNodeSchema,
16412
16785
  CHECK_CREDENTIAL_APPLIES,
16413
16786
  CODEX_APP_SERVER_GENERATED_AGAINST,
16414
16787
  CODEX_APP_SERVER_TIMEOUT_MS,
@@ -16555,6 +16928,8 @@ export {
16555
16928
  RcStreamEventSchema,
16556
16929
  ResetRowSchema,
16557
16930
  ResetScheduleSchema,
16931
+ SessionAgentTreeSchema,
16932
+ TaskItemSchema,
16558
16933
  USAGE_EVENT_SOURCE,
16559
16934
  UpdateCheckOutputSchema,
16560
16935
  UsageError,
@@ -16565,6 +16940,7 @@ export {
16565
16940
  UsageWindowsInputSchema,
16566
16941
  UsageWindowsOutputSchema,
16567
16942
  WhenSchema,
16943
+ WorkflowRunSchema,
16568
16944
  addDirectoryRule,
16569
16945
  addIdentity,
16570
16946
  addPool,
@@ -16666,6 +17042,7 @@ export {
16666
17042
  listIdentities,
16667
17043
  listProfiles,
16668
17044
  listProviders,
17045
+ listSessions2 as listSessions,
16669
17046
  listUsageSnapshots,
16670
17047
  matchBranch,
16671
17048
  mintLeaf,
@@ -16700,6 +17077,7 @@ export {
16700
17077
  readProvider,
16701
17078
  readRcSelfHostRecord,
16702
17079
  readRcSessionFile,
17080
+ readSessionAgentTree,
16703
17081
  readUsageSnapshot,
16704
17082
  realCodexAppServerPort,
16705
17083
  realConnectCertStore,