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.cjs CHANGED
@@ -2693,7 +2693,7 @@ var init_package = __esm({
2693
2693
  "package.json"() {
2694
2694
  package_default = {
2695
2695
  name: "claude-use",
2696
- version: "9.15.0",
2696
+ version: "9.16.0",
2697
2697
  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.",
2698
2698
  license: "MIT",
2699
2699
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -6687,7 +6687,7 @@ function buildEnv(params) {
6687
6687
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
6688
6688
  let providerCustomHeaders;
6689
6689
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
6690
- env.CLAUDE_CONFIG_DIR = import_node_path33.default.join(params.identitiesDir, params.resolvedIdentityName);
6690
+ env.CLAUDE_CONFIG_DIR = import_node_path34.default.join(params.identitiesDir, params.resolvedIdentityName);
6691
6691
  }
6692
6692
  if (params.provider !== void 0) {
6693
6693
  const providerEnv = params.provider.definition.env ?? {};
@@ -6731,11 +6731,11 @@ function buildEnv(params) {
6731
6731
  }
6732
6732
  return env;
6733
6733
  }
6734
- var import_node_path33, LOOPBACK_HOSTS;
6734
+ var import_node_path34, LOOPBACK_HOSTS;
6735
6735
  var init_flags = __esm({
6736
6736
  "src/launcher/flags.ts"() {
6737
6737
  "use strict";
6738
- import_node_path33 = __toESM(require("node:path"), 1);
6738
+ import_node_path34 = __toESM(require("node:path"), 1);
6739
6739
  init_envBool();
6740
6740
  init_credential();
6741
6741
  init_headers();
@@ -7063,7 +7063,7 @@ function decideLaunch(params, readOnly) {
7063
7063
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
7064
7064
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
7065
7065
  });
7066
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path34.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7066
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path35.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7067
7067
  log.error(
7068
7068
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
7069
7069
  );
@@ -7175,7 +7175,7 @@ function decideLaunch(params, readOnly) {
7175
7175
  extraFlags: splitExtraFlags(env.CLAUDE_EXTRA_FLAGS),
7176
7176
  passthrough: parsedArgv.rest
7177
7177
  });
7178
- const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : import_node_path34.default.join(paths.identitiesDir, identityDecision.name);
7178
+ const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : import_node_path35.default.join(paths.identitiesDir, identityDecision.name);
7179
7179
  const decision = {
7180
7180
  identitySource: identityDecision.source,
7181
7181
  configDirEscapeHatch: identityDecision.configDirEscapeHatch,
@@ -7216,7 +7216,7 @@ function prepareLaunch(params) {
7216
7216
  );
7217
7217
  const updateCheck = runLaunchUpdateCheck({
7218
7218
  mode: params.updateMode ?? "off",
7219
- checkPath: import_node_path34.default.join(paths.root, "update.check"),
7219
+ checkPath: import_node_path35.default.join(paths.root, "update.check"),
7220
7220
  currentVersion: package_default.version,
7221
7221
  port: params.update
7222
7222
  });
@@ -7347,12 +7347,12 @@ function runLaunchPlan(plan, spawn3) {
7347
7347
  function runLauncher(params) {
7348
7348
  params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
7349
7349
  }
7350
- var import_node_crypto10, import_node_path34;
7350
+ var import_node_crypto10, import_node_path35;
7351
7351
  var init_launcher = __esm({
7352
7352
  "src/launcher.ts"() {
7353
7353
  "use strict";
7354
7354
  import_node_crypto10 = require("node:crypto");
7355
- import_node_path34 = __toESM(require("node:path"), 1);
7355
+ import_node_path35 = __toESM(require("node:path"), 1);
7356
7356
  init_package();
7357
7357
  init_envBool();
7358
7358
  init_argv();
@@ -7383,13 +7383,13 @@ function agentShimCliPath(distDir = typeof __AGENT_SHIM_DIST_DIR__ === "string"
7383
7383
  if (distDir === void 0) {
7384
7384
  throw new OwnCliPathUnknownError();
7385
7385
  }
7386
- return import_node_path35.default.join(distDir, OWN_CLI_FILE_NAME);
7386
+ return import_node_path36.default.join(distDir, OWN_CLI_FILE_NAME);
7387
7387
  }
7388
- var import_node_path35, OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
7388
+ var import_node_path36, OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
7389
7389
  var init_ownCli = __esm({
7390
7390
  "src/ownCli.ts"() {
7391
7391
  "use strict";
7392
- import_node_path35 = __toESM(require("node:path"), 1);
7392
+ import_node_path36 = __toESM(require("node:path"), 1);
7393
7393
  init_cliError();
7394
7394
  OWN_CLI_FILE_NAME = "cli.cjs";
7395
7395
  OwnCliPathUnknownError = class extends CliError {
@@ -7474,7 +7474,7 @@ request.on("error", (error) => finish(failed, (error.code ? error.code + ": " :
7474
7474
  // src/frontdoor/trust.ts
7475
7475
  function resolveTrustBundle(params) {
7476
7476
  const { caCertFile, bundlesDir, variable, inherited, fs: fs12 } = params;
7477
- if (inherited === void 0 || inherited === "" || import_node_path36.default.resolve(inherited) === import_node_path36.default.resolve(caCertFile)) {
7477
+ if (inherited === void 0 || inherited === "" || import_node_path37.default.resolve(inherited) === import_node_path37.default.resolve(caCertFile)) {
7478
7478
  return { path: caCertFile };
7479
7479
  }
7480
7480
  const caPem = fs12.readFileUtf8(caCertFile);
@@ -7492,19 +7492,19 @@ function resolveTrustBundle(params) {
7492
7492
  }
7493
7493
  const combined = `${inheritedPem.trimEnd()}
7494
7494
  ${caPem}`;
7495
- const bundle = import_node_path36.default.join(bundlesDir, `${(0, import_node_crypto11.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
7495
+ const bundle = import_node_path37.default.join(bundlesDir, `${(0, import_node_crypto11.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
7496
7496
  if (!fs12.exists(bundle)) {
7497
7497
  fs12.mkdirp(bundlesDir);
7498
7498
  fs12.writeFileAtomic(bundle, combined);
7499
7499
  }
7500
7500
  return { path: bundle };
7501
7501
  }
7502
- var import_node_crypto11, import_node_path36, BUNDLE_NAME_HEX_DIGITS;
7502
+ var import_node_crypto11, import_node_path37, BUNDLE_NAME_HEX_DIGITS;
7503
7503
  var init_trust = __esm({
7504
7504
  "src/frontdoor/trust.ts"() {
7505
7505
  "use strict";
7506
7506
  import_node_crypto11 = require("node:crypto");
7507
- import_node_path36 = __toESM(require("node:path"), 1);
7507
+ import_node_path37 = __toESM(require("node:path"), 1);
7508
7508
  BUNDLE_NAME_HEX_DIGITS = 16;
7509
7509
  }
7510
7510
  });
@@ -7894,11 +7894,11 @@ var init_identityClaude = __esm({
7894
7894
  });
7895
7895
 
7896
7896
  // src/usage/providerQuota.ts
7897
- var import_zod25, 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;
7897
+ var import_zod27, 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;
7898
7898
  var init_providerQuota = __esm({
7899
7899
  "src/usage/providerQuota.ts"() {
7900
7900
  "use strict";
7901
- import_zod25 = require("zod");
7901
+ import_zod27 = require("zod");
7902
7902
  init_schema2();
7903
7903
  MS_PER_SECOND7 = 1e3;
7904
7904
  SECONDS_PER_HOUR = 3600;
@@ -7912,35 +7912,35 @@ var init_providerQuota = __esm({
7912
7912
  [ZAI_UNIT_HOURS, SECONDS_PER_HOUR * MS_PER_SECOND7],
7913
7913
  [ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY4 * SECONDS_PER_HOUR * MS_PER_SECOND7]
7914
7914
  ]);
7915
- ZaiLimitSchema = import_zod25.z.object({
7916
- type: import_zod25.z.string(),
7917
- unit: import_zod25.z.number().int(),
7918
- number: import_zod25.z.number().int().positive(),
7919
- percentage: import_zod25.z.number().nonnegative(),
7920
- nextResetTime: import_zod25.z.number().positive().optional(),
7921
- usage: import_zod25.z.number().nonnegative().optional(),
7922
- currentValue: import_zod25.z.number().nonnegative().optional(),
7923
- remaining: import_zod25.z.number().nonnegative().optional()
7915
+ ZaiLimitSchema = import_zod27.z.object({
7916
+ type: import_zod27.z.string(),
7917
+ unit: import_zod27.z.number().int(),
7918
+ number: import_zod27.z.number().int().positive(),
7919
+ percentage: import_zod27.z.number().nonnegative(),
7920
+ nextResetTime: import_zod27.z.number().positive().optional(),
7921
+ usage: import_zod27.z.number().nonnegative().optional(),
7922
+ currentValue: import_zod27.z.number().nonnegative().optional(),
7923
+ remaining: import_zod27.z.number().nonnegative().optional()
7924
7924
  });
7925
- ZaiResponseSchema = import_zod25.z.object({
7926
- success: import_zod25.z.boolean(),
7927
- msg: import_zod25.z.string().optional(),
7928
- data: import_zod25.z.object({ level: import_zod25.z.string().optional(), limits: import_zod25.z.array(ZaiLimitSchema) })
7925
+ ZaiResponseSchema = import_zod27.z.object({
7926
+ success: import_zod27.z.boolean(),
7927
+ msg: import_zod27.z.string().optional(),
7928
+ data: import_zod27.z.object({ level: import_zod27.z.string().optional(), limits: import_zod27.z.array(ZaiLimitSchema) })
7929
7929
  });
7930
7930
  OPENROUTER_HOST = "openrouter.ai";
7931
7931
  OPENROUTER_KEY_URL = `https://${OPENROUTER_HOST}/api/v1/key`;
7932
7932
  OPENROUTER_CREDITS_URL = `https://${OPENROUTER_HOST}/api/v1/credits`;
7933
7933
  MS_PER_DAY3 = HOURS_PER_DAY4 * SECONDS_PER_HOUR * MS_PER_SECOND7;
7934
- OpenRouterKeySchema = import_zod25.z.object({
7935
- data: import_zod25.z.object({
7936
- limit: import_zod25.z.number().nonnegative().nullable(),
7937
- limit_remaining: import_zod25.z.number().nullable(),
7938
- limit_reset: import_zod25.z.string().nullable(),
7939
- is_free_tier: import_zod25.z.boolean().optional(),
7940
- free_model_daily_requests: import_zod25.z.object({ used: import_zod25.z.number().nonnegative(), limit: import_zod25.z.number().nonnegative(), remaining: import_zod25.z.number() }).optional()
7934
+ OpenRouterKeySchema = import_zod27.z.object({
7935
+ data: import_zod27.z.object({
7936
+ limit: import_zod27.z.number().nonnegative().nullable(),
7937
+ limit_remaining: import_zod27.z.number().nullable(),
7938
+ limit_reset: import_zod27.z.string().nullable(),
7939
+ is_free_tier: import_zod27.z.boolean().optional(),
7940
+ free_model_daily_requests: import_zod27.z.object({ used: import_zod27.z.number().nonnegative(), limit: import_zod27.z.number().nonnegative(), remaining: import_zod27.z.number() }).optional()
7941
7941
  })
7942
7942
  });
7943
- OpenRouterCreditsSchema = import_zod25.z.object({ data: import_zod25.z.object({ total_credits: import_zod25.z.number().nonnegative(), total_usage: import_zod25.z.number().nonnegative() }) });
7943
+ OpenRouterCreditsSchema = import_zod27.z.object({ data: import_zod27.z.object({ total_credits: import_zod27.z.number().nonnegative(), total_usage: import_zod27.z.number().nonnegative() }) });
7944
7944
  }
7945
7945
  });
7946
7946
 
@@ -8026,6 +8026,9 @@ var init_realAnthropicUsageProbe = __esm({
8026
8026
  var index_exports = {};
8027
8027
  __export(index_exports, {
8028
8028
  AMBIENT_CREDENTIAL_VARS: () => AMBIENT_CREDENTIAL_VARS,
8029
+ AgentKindSchema: () => AgentKindSchema,
8030
+ AgentMetaSchema: () => AgentMetaSchema,
8031
+ AgentNodeSchema: () => AgentNodeSchema,
8029
8032
  CHECK_CREDENTIAL_APPLIES: () => CHECK_CREDENTIAL_APPLIES,
8030
8033
  CODEX_APP_SERVER_GENERATED_AGAINST: () => CODEX_APP_SERVER_GENERATED_AGAINST,
8031
8034
  CODEX_APP_SERVER_TIMEOUT_MS: () => CODEX_APP_SERVER_TIMEOUT_MS,
@@ -8172,6 +8175,8 @@ __export(index_exports, {
8172
8175
  RcStreamEventSchema: () => RcStreamEventSchema,
8173
8176
  ResetRowSchema: () => ResetRowSchema,
8174
8177
  ResetScheduleSchema: () => ResetScheduleSchema,
8178
+ SessionAgentTreeSchema: () => SessionAgentTreeSchema,
8179
+ TaskItemSchema: () => TaskItemSchema,
8175
8180
  USAGE_EVENT_SOURCE: () => USAGE_EVENT_SOURCE,
8176
8181
  UpdateCheckOutputSchema: () => UpdateCheckOutputSchema,
8177
8182
  UsageError: () => UsageError,
@@ -8182,6 +8187,7 @@ __export(index_exports, {
8182
8187
  UsageWindowsInputSchema: () => UsageWindowsInputSchema,
8183
8188
  UsageWindowsOutputSchema: () => UsageWindowsOutputSchema,
8184
8189
  WhenSchema: () => WhenSchema,
8190
+ WorkflowRunSchema: () => WorkflowRunSchema,
8185
8191
  addDirectoryRule: () => addDirectoryRule,
8186
8192
  addIdentity: () => addIdentity,
8187
8193
  addPool: () => addPool,
@@ -8283,6 +8289,7 @@ __export(index_exports, {
8283
8289
  listIdentities: () => listIdentities,
8284
8290
  listProfiles: () => listProfiles,
8285
8291
  listProviders: () => listProviders,
8292
+ listSessions: () => listSessions2,
8286
8293
  listUsageSnapshots: () => listUsageSnapshots,
8287
8294
  matchBranch: () => matchBranch,
8288
8295
  mintLeaf: () => mintLeaf,
@@ -8317,6 +8324,7 @@ __export(index_exports, {
8317
8324
  readProvider: () => readProvider,
8318
8325
  readRcSelfHostRecord: () => readRcSelfHostRecord,
8319
8326
  readRcSessionFile: () => readRcSessionFile,
8327
+ readSessionAgentTree: () => readSessionAgentTree,
8320
8328
  readUsageSnapshot: () => readUsageSnapshot,
8321
8329
  realCodexAppServerPort: () => realCodexAppServerPort,
8322
8330
  realConnectCertStore: () => realConnectCertStore,
@@ -8910,8 +8918,8 @@ function parseConnectTarget(authority) {
8910
8918
  function isInterceptedHost(host, interceptHosts) {
8911
8919
  return interceptHosts.includes(host);
8912
8920
  }
8913
- function servedByPipeline(path37) {
8914
- return path37?.startsWith(ROUTED_PATH_PREFIX) === true;
8921
+ function servedByPipeline(path38) {
8922
+ return path38?.startsWith(ROUTED_PATH_PREFIX) === true;
8915
8923
  }
8916
8924
  var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
8917
8925
  "connection",
@@ -9446,11 +9454,11 @@ function createRcSessionTracker(deps) {
9446
9454
  };
9447
9455
  const observeExchange = (request4) => {
9448
9456
  const method = (request4.method ?? "").toUpperCase();
9449
- const path37 = new URL(request4.url ?? "/", "http://127.0.0.1").pathname;
9450
- if (!path37.startsWith(RC_SESSIONS_PATH_PREFIX)) {
9457
+ const path38 = new URL(request4.url ?? "/", "http://127.0.0.1").pathname;
9458
+ if (!path38.startsWith(RC_SESSIONS_PATH_PREFIX)) {
9451
9459
  return void 0;
9452
9460
  }
9453
- const tail = path37.slice(RC_SESSIONS_PATH_PREFIX.length);
9461
+ const tail = path38.slice(RC_SESSIONS_PATH_PREFIX.length);
9454
9462
  const facts = {
9455
9463
  oauthAuthorization: oauthAuthorizationOf(request4.headers),
9456
9464
  anthropicVersion: singleHeader(request4.headers, "anthropic-version"),
@@ -9832,8 +9840,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
9832
9840
  function isRcReadFileEncoding(value) {
9833
9841
  return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value);
9834
9842
  }
9835
- function buildRcReadFilePayload(requestId, path37, options) {
9836
- return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path37, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
9843
+ function buildRcReadFilePayload(requestId, path38, options) {
9844
+ return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path38, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
9837
9845
  }
9838
9846
  function buildRcFileSuggestionsPayload(requestId, query) {
9839
9847
  return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
@@ -9935,15 +9943,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
9935
9943
  const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
9936
9944
  return result.ok ? { ...result, requestId } : result;
9937
9945
  }
9938
- async function readRcSessionFile(deps, sessionId, path37, options) {
9939
- if (path37 === "") {
9946
+ async function readRcSessionFile(deps, sessionId, path38, options) {
9947
+ if (path38 === "") {
9940
9948
  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" };
9941
9949
  }
9942
9950
  if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
9943
9951
  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" };
9944
9952
  }
9945
9953
  const requestId = deps.newUuid();
9946
- const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path37, options), `read ${path37} from session ${sessionId}`);
9954
+ const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path38, options), `read ${path38} from session ${sessionId}`);
9947
9955
  return result.ok ? { ...result, requestId } : result;
9948
9956
  }
9949
9957
  async function suggestRcSessionFiles(deps, sessionId, query) {
@@ -10112,11 +10120,11 @@ function createRcControlHandler(deps) {
10112
10120
  path: "read-file",
10113
10121
  read: (body) => {
10114
10122
  const session = bodyString(body, "session");
10115
- const path37 = bodyString(body, "path");
10123
+ const path38 = bodyString(body, "path");
10116
10124
  const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
10117
10125
  const encoding = "encoding" in body && isRcReadFileEncoding(body.encoding) ? body.encoding : void 0;
10118
- const refused2 = session === void 0 || path37 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
10119
- 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 } }) };
10126
+ const refused2 = session === void 0 || path38 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
10127
+ 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 } }) };
10120
10128
  }
10121
10129
  },
10122
10130
  {
@@ -10426,9 +10434,9 @@ function requestIdOfBody(body) {
10426
10434
  }
10427
10435
  function frontDoorRcControl(transport, token) {
10428
10436
  const headers = { authorization: `Bearer ${token}` };
10429
- const listAnswerOf = async (path37, what) => {
10437
+ const listAnswerOf = async (path38, what) => {
10430
10438
  try {
10431
- return await transport.request({ method: "GET", path: path37, headers });
10439
+ return await transport.request({ method: "GET", path: path38, headers });
10432
10440
  } catch (error) {
10433
10441
  throw new Error(`${what}: could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
10434
10442
  }
@@ -10500,10 +10508,10 @@ function frontDoorRcControl(transport, token) {
10500
10508
  }
10501
10509
  return pending;
10502
10510
  };
10503
- const writeOf = async (path37, body, describeFailure) => {
10511
+ const writeOf = async (path38, body, describeFailure2) => {
10504
10512
  let answer;
10505
10513
  try {
10506
- answer = await transport.request({ method: "POST", path: path37, headers: { ...headers, "content-type": "application/json" }, body });
10514
+ answer = await transport.request({ method: "POST", path: path38, headers: { ...headers, "content-type": "application/json" }, body });
10507
10515
  } catch (error) {
10508
10516
  return { ok: false, message: `could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}` };
10509
10517
  }
@@ -10515,7 +10523,7 @@ function frontDoorRcControl(transport, token) {
10515
10523
  const requestId = requestIdOfBody(answer.body);
10516
10524
  return requestId === void 0 ? { ok: true, sequenceNums } : { ok: true, sequenceNums, requestId };
10517
10525
  }
10518
- return { ok: false, message: describeFailure(answer.status, controlErrorOf(answer.body) ?? answer.body) };
10526
+ return { ok: false, message: describeFailure2(answer.status, controlErrorOf(answer.body) ?? answer.body) };
10519
10527
  };
10520
10528
  const sessionQuery = (sessionId) => sessionId === void 0 ? "" : `?session=${encodeURIComponent(sessionId)}`;
10521
10529
  return {
@@ -10534,10 +10542,10 @@ function frontDoorRcControl(transport, token) {
10534
10542
  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}`),
10535
10543
  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}`),
10536
10544
  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}`),
10537
- readFile: async (sessionId, path37, options) => await writeOf(
10545
+ readFile: async (sessionId, path38, options) => await writeOf(
10538
10546
  `${CONTROL_PATH_PREFIX}/read-file`,
10539
- JSON.stringify({ session: sessionId, path: path37, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
10540
- (status, message) => `reading ${path37} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
10547
+ JSON.stringify({ session: sessionId, path: path38, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
10548
+ (status, message) => `reading ${path38} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
10541
10549
  ),
10542
10550
  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}`),
10543
10551
  keepAlive: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/keep-alive`, JSON.stringify({ session: sessionId }), (status, message) => `keeping ${sessionId} alive failed (HTTP ${String(status)}): ${message}`),
@@ -10696,12 +10704,12 @@ function tlsFacts(options) {
10696
10704
  }
10697
10705
  function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
10698
10706
  const agent = new ExemptTlsAgent();
10699
- const post = async (path37, headers, body) => await new Promise((resolve, reject) => {
10707
+ const post = async (path38, headers, body) => await new Promise((resolve, reject) => {
10700
10708
  const options = {
10701
10709
  host: target.host,
10702
10710
  port: target.port,
10703
10711
  method: "POST",
10704
- path: path37,
10712
+ path: path38,
10705
10713
  // 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.
10706
10714
  headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
10707
10715
  agent
@@ -10766,12 +10774,12 @@ function lateRcStreamDial(resolve) {
10766
10774
  }
10767
10775
  function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
10768
10776
  const agent = new ExemptTlsAgent();
10769
- const request4 = async (method, path37, headers, body, signal) => await new Promise((resolve, reject) => {
10777
+ const request4 = async (method, path38, headers, body, signal) => await new Promise((resolve, reject) => {
10770
10778
  const options = {
10771
10779
  host: target.host,
10772
10780
  port: target.port,
10773
10781
  method,
10774
- path: path37,
10782
+ path: path38,
10775
10783
  // 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.
10776
10784
  headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
10777
10785
  agent,
@@ -10813,9 +10821,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
10813
10821
  return { status, body: await readAll(response) };
10814
10822
  },
10815
10823
  openStream: async (sessionId, headers, resume, signal) => {
10816
- 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)}`;
10824
+ 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)}`;
10817
10825
  const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
10818
- const { status, response } = await request4("GET", path37, streamHeaders, void 0, signal);
10826
+ const { status, response } = await request4("GET", path38, streamHeaders, void 0, signal);
10819
10827
  if (!isSuccessful2(status)) {
10820
10828
  await readAll(response);
10821
10829
  return { status, chunks: NO_CHUNKS };
@@ -11966,19 +11974,19 @@ function writePools(paths, pools) {
11966
11974
  applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
11967
11975
  }
11968
11976
  function poolCycleOf(pools, name) {
11969
- const walk = (current, path37) => {
11977
+ const walk = (current, path38) => {
11970
11978
  for (const entry of pools[current]?.identities ?? []) {
11971
11979
  const nested = poolNameOf(poolMemberIdentity(entry));
11972
11980
  if (nested === void 0) {
11973
11981
  continue;
11974
11982
  }
11975
11983
  if (nested === name) {
11976
- return [...path37, nested];
11984
+ return [...path38, nested];
11977
11985
  }
11978
- if (path37.includes(nested)) {
11986
+ if (path38.includes(nested)) {
11979
11987
  continue;
11980
11988
  }
11981
- const found = walk(nested, [...path37, nested]);
11989
+ const found = walk(nested, [...path38, nested]);
11982
11990
  if (found !== void 0) {
11983
11991
  return found;
11984
11992
  }
@@ -14112,7 +14120,7 @@ function profileValue(name, paths) {
14112
14120
  function createConfigApiRouter(deps) {
14113
14121
  const authed = doorApiAuth(deps.expectedToken);
14114
14122
  const { paths } = deps;
14115
- const route = (path37, summary) => authed.meta((0, import_openapi3.openapi)({ method: "POST", path: path37, summary, tags: [CONFIG_API_TAG] }));
14123
+ const route = (path38, summary) => authed.meta((0, import_openapi3.openapi)({ method: "POST", path: path38, summary, tags: [CONFIG_API_TAG] }));
14116
14124
  return {
14117
14125
  config: {
14118
14126
  identity: {
@@ -16687,6 +16695,376 @@ init_preflight();
16687
16695
  init_pick();
16688
16696
  init_plan2();
16689
16697
  init_poolPick();
16698
+
16699
+ // src/agents/read.ts
16700
+ var import_node_path33 = __toESM(require("node:path"), 1);
16701
+ var import_zod26 = require("zod");
16702
+
16703
+ // src/agents/schema.ts
16704
+ var import_zod25 = require("zod");
16705
+ var AgentMetaSchema = import_zod25.z.looseObject({
16706
+ agentType: import_zod25.z.string(),
16707
+ isFork: import_zod25.z.boolean().optional(),
16708
+ description: import_zod25.z.string().optional(),
16709
+ name: import_zod25.z.string().optional(),
16710
+ toolUseId: import_zod25.z.string().optional(),
16711
+ spawnDepth: import_zod25.z.number().int().nonnegative().optional(),
16712
+ parentAgentId: import_zod25.z.string().optional(),
16713
+ model: import_zod25.z.string().optional(),
16714
+ requestShape: import_zod25.z.string().optional(),
16715
+ requestNonInteractive: import_zod25.z.boolean().optional(),
16716
+ workflowPhase: import_zod25.z.string().optional(),
16717
+ taskKind: import_zod25.z.string().optional(),
16718
+ teamName: import_zod25.z.string().optional(),
16719
+ worktreePath: import_zod25.z.string().optional(),
16720
+ worktreeBranch: import_zod25.z.string().optional(),
16721
+ stoppedByUser: import_zod25.z.boolean().optional()
16722
+ });
16723
+ var AgentKindSchema = import_zod25.z.enum(["subagent", "fork", "workflow-agent", "teammate"]);
16724
+ var AgentNodeSchema = import_zod25.z.lazy(
16725
+ () => import_zod25.z.strictObject({
16726
+ id: import_zod25.z.string(),
16727
+ kind: AgentKindSchema,
16728
+ agentType: import_zod25.z.string(),
16729
+ description: import_zod25.z.string().optional(),
16730
+ name: import_zod25.z.string().optional(),
16731
+ toolUseId: import_zod25.z.string().optional(),
16732
+ spawnDepth: import_zod25.z.number().int().nonnegative().optional(),
16733
+ model: import_zod25.z.string().optional(),
16734
+ background: import_zod25.z.boolean().optional(),
16735
+ workflowRunId: import_zod25.z.string().optional(),
16736
+ workflowPhase: import_zod25.z.string().optional(),
16737
+ teamName: import_zod25.z.string().optional(),
16738
+ stoppedByUser: import_zod25.z.boolean().optional(),
16739
+ transcript: import_zod25.z.string(),
16740
+ children: import_zod25.z.array(AgentNodeSchema)
16741
+ })
16742
+ );
16743
+ var TaskItemSchema = import_zod25.z.strictObject({
16744
+ id: import_zod25.z.string(),
16745
+ subject: import_zod25.z.string(),
16746
+ description: import_zod25.z.string().optional(),
16747
+ status: import_zod25.z.string(),
16748
+ /** What a spinner shows while the task runs. */
16749
+ activeForm: import_zod25.z.string().optional(),
16750
+ /** The teammate or agent name the task is assigned to, as Agent Teams writes it. */
16751
+ owner: import_zod25.z.string().optional(),
16752
+ /** Free-form data the harness attaches to a task, kept as written. */
16753
+ metadata: import_zod25.z.record(import_zod25.z.string(), import_zod25.z.unknown()).optional(),
16754
+ blocks: import_zod25.z.array(import_zod25.z.string()),
16755
+ blockedBy: import_zod25.z.array(import_zod25.z.string()),
16756
+ /** 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. */
16757
+ taskList: import_zod25.z.string().optional()
16758
+ });
16759
+ var WorkflowRunSchema = import_zod25.z.strictObject({
16760
+ runId: import_zod25.z.string(),
16761
+ workflowName: import_zod25.z.string().optional(),
16762
+ status: import_zod25.z.string().optional(),
16763
+ startTime: import_zod25.z.number().optional(),
16764
+ phases: import_zod25.z.array(import_zod25.z.string()),
16765
+ summary: import_zod25.z.string().optional()
16766
+ });
16767
+ var AgentTreeProblemSchema = import_zod25.z.strictObject({
16768
+ /** Relative to the identity's configuration directory. */
16769
+ path: import_zod25.z.string(),
16770
+ reason: import_zod25.z.string()
16771
+ });
16772
+ var SessionAgentTreeSchema = import_zod25.z.strictObject({
16773
+ project: import_zod25.z.string(),
16774
+ sessionId: import_zod25.z.string(),
16775
+ /** True for a session directory a resume superseded (`<session-id>.superseded-<epoch-ms>`). */
16776
+ superseded: import_zod25.z.boolean(),
16777
+ /** The agents the session itself spawned, each with its descendants. */
16778
+ agents: import_zod25.z.array(AgentNodeSchema),
16779
+ tasks: import_zod25.z.array(TaskItemSchema),
16780
+ workflowRuns: import_zod25.z.array(WorkflowRunSchema),
16781
+ problems: import_zod25.z.array(AgentTreeProblemSchema)
16782
+ });
16783
+
16784
+ // src/agents/read.ts
16785
+ var PROJECTS_DIR = "projects";
16786
+ var TASKS_DIR = "tasks";
16787
+ var SUBAGENTS_DIR = "subagents";
16788
+ var WORKFLOWS_DIR = "workflows";
16789
+ var AGENT_FILE_PREFIX = "agent-";
16790
+ var META_SUFFIX = ".meta.json";
16791
+ var TRANSCRIPT_SUFFIX = ".jsonl";
16792
+ var SHORT_SESSION_ID_LENGTH = 8;
16793
+ var SHORT_SESSION_LIST_PREFIX = "session-";
16794
+ var JSON_SUFFIX = ".json";
16795
+ var WORKFLOW_RUN_PREFIX = "wf_";
16796
+ var ARCHIVED_RE = /^(.+)\.(?:superseded|orphaned)-.+$/;
16797
+ var FORK_AGENT_TYPE = "fork";
16798
+ var WORKFLOW_AGENT_TYPE = "workflow-subagent";
16799
+ var TEAMMATE_TASK_KIND = "in_process_teammate";
16800
+ var BACKGROUND_REQUEST_SHAPE = "background";
16801
+ var SESSION_SPAWN_DEPTH = 1;
16802
+ function parseEntry2(project, entry) {
16803
+ const match = ARCHIVED_RE.exec(entry);
16804
+ const base = match?.[1];
16805
+ return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
16806
+ }
16807
+ function listSessions2(fs12, configDir) {
16808
+ const found = [];
16809
+ for (const project of fs12.readdir(import_node_path33.default.join(configDir, PROJECTS_DIR))) {
16810
+ const projectDir = import_node_path33.default.join(configDir, PROJECTS_DIR, project);
16811
+ const entries = /* @__PURE__ */ new Set();
16812
+ for (const name of fs12.readdir(projectDir)) {
16813
+ if (name.endsWith(TRANSCRIPT_SUFFIX)) {
16814
+ entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
16815
+ continue;
16816
+ }
16817
+ const children = fs12.readdir(import_node_path33.default.join(projectDir, name));
16818
+ if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
16819
+ entries.add(name);
16820
+ }
16821
+ }
16822
+ for (const entry of entries) {
16823
+ found.push(parseEntry2(project, entry));
16824
+ }
16825
+ }
16826
+ return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
16827
+ }
16828
+ function locateAgents(fs12, configDir, relativeDir, workflowRunId, report) {
16829
+ const located = [];
16830
+ for (const name of listDirOrReport(fs12, configDir, relativeDir, report)) {
16831
+ if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
16832
+ continue;
16833
+ }
16834
+ const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
16835
+ located.push({
16836
+ id,
16837
+ metaPath: import_node_path33.default.join(relativeDir, name),
16838
+ transcriptPath: import_node_path33.default.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
16839
+ workflowRunId
16840
+ });
16841
+ }
16842
+ return located;
16843
+ }
16844
+ function kindOf(meta, workflowRunId) {
16845
+ if (meta.isFork === true || meta.agentType === FORK_AGENT_TYPE) {
16846
+ return "fork";
16847
+ }
16848
+ if (workflowRunId !== void 0 || meta.agentType === WORKFLOW_AGENT_TYPE) {
16849
+ return "workflow-agent";
16850
+ }
16851
+ if (meta.taskKind === TEAMMATE_TASK_KIND || meta.teamName !== void 0) {
16852
+ return "teammate";
16853
+ }
16854
+ return "subagent";
16855
+ }
16856
+ function toNode(read, children) {
16857
+ const { located, meta } = read;
16858
+ return {
16859
+ id: located.id,
16860
+ kind: kindOf(meta, located.workflowRunId),
16861
+ agentType: meta.agentType,
16862
+ ...meta.description === void 0 ? {} : { description: meta.description },
16863
+ ...meta.name === void 0 ? {} : { name: meta.name },
16864
+ ...meta.toolUseId === void 0 ? {} : { toolUseId: meta.toolUseId },
16865
+ ...meta.spawnDepth === void 0 ? {} : { spawnDepth: meta.spawnDepth },
16866
+ ...meta.model === void 0 ? {} : { model: meta.model },
16867
+ ...meta.requestShape === void 0 ? {} : { background: meta.requestShape === BACKGROUND_REQUEST_SHAPE },
16868
+ ...located.workflowRunId === void 0 ? {} : { workflowRunId: located.workflowRunId },
16869
+ ...meta.workflowPhase === void 0 ? {} : { workflowPhase: meta.workflowPhase },
16870
+ ...meta.teamName === void 0 ? {} : { teamName: meta.teamName },
16871
+ ...meta.stoppedByUser === void 0 ? {} : { stoppedByUser: meta.stoppedByUser },
16872
+ transcript: located.transcriptPath,
16873
+ children
16874
+ };
16875
+ }
16876
+ function describeFailure(error) {
16877
+ return error instanceof Error ? error.message : String(error);
16878
+ }
16879
+ function readFileOrReport(fs12, configDir, relative, report) {
16880
+ try {
16881
+ return fs12.readFileUtf8(import_node_path33.default.join(configDir, relative));
16882
+ } catch (error) {
16883
+ report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
16884
+ return void 0;
16885
+ }
16886
+ }
16887
+ function listDirOrReport(fs12, configDir, relative, report) {
16888
+ try {
16889
+ return fs12.readdir(import_node_path33.default.join(configDir, relative));
16890
+ } catch (error) {
16891
+ report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
16892
+ return [];
16893
+ }
16894
+ }
16895
+ function parseJson2(text) {
16896
+ try {
16897
+ const value = JSON.parse(text);
16898
+ return value;
16899
+ } catch {
16900
+ return void 0;
16901
+ }
16902
+ }
16903
+ var TaskFileSchema = import_zod26.z.object({ ...TaskItemSchema.omit({ taskList: true }).shape, blocks: import_zod26.z.array(import_zod26.z.string()).default([]), blockedBy: import_zod26.z.array(import_zod26.z.string()).default([]) });
16904
+ var WorkflowRunFileSchema = import_zod26.z.object({
16905
+ runId: import_zod26.z.string(),
16906
+ workflowName: import_zod26.z.string().optional(),
16907
+ status: import_zod26.z.string().optional(),
16908
+ startTime: import_zod26.z.number().optional(),
16909
+ phases: import_zod26.z.array(import_zod26.z.object({ title: import_zod26.z.string() })).default([]),
16910
+ summary: import_zod26.z.string().optional()
16911
+ });
16912
+ function readSessionAgentTree(fs12, configDir, ref, options = {}) {
16913
+ const problems = [];
16914
+ const report = (problem) => {
16915
+ problems.push(problem);
16916
+ };
16917
+ const sessionRelative = import_node_path33.default.join(PROJECTS_DIR, ref.project, ref.entry);
16918
+ const subagentsRelative = import_node_path33.default.join(sessionRelative, SUBAGENTS_DIR);
16919
+ const workflowsUnderSubagents = import_node_path33.default.join(subagentsRelative, WORKFLOWS_DIR);
16920
+ const located = locateAgents(fs12, configDir, subagentsRelative, void 0, report);
16921
+ for (const runDir of listDirOrReport(fs12, configDir, workflowsUnderSubagents, report)) {
16922
+ if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
16923
+ located.push(...locateAgents(fs12, configDir, import_node_path33.default.join(workflowsUnderSubagents, runDir), runDir, report));
16924
+ }
16925
+ }
16926
+ const agents = /* @__PURE__ */ new Map();
16927
+ for (const candidate of located) {
16928
+ const text = readFileOrReport(fs12, configDir, candidate.metaPath, report);
16929
+ if (text === void 0) {
16930
+ continue;
16931
+ }
16932
+ const parsed = AgentMetaSchema.safeParse(parseJson2(text));
16933
+ if (!parsed.success) {
16934
+ report({ path: candidate.metaPath, reason: "meta file is not a JSON object with an agentType" });
16935
+ continue;
16936
+ }
16937
+ agents.set(candidate.id, { located: candidate, meta: parsed.data });
16938
+ }
16939
+ const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
16940
+ const parentOf3 = resolveParents(fs12, configDir, agents, report);
16941
+ const childrenOf = /* @__PURE__ */ new Map();
16942
+ const roots = [];
16943
+ for (const id of agents.keys()) {
16944
+ const parent = parentOf3.get(id);
16945
+ if (parent === void 0) {
16946
+ roots.push(id);
16947
+ } else {
16948
+ childrenOf.set(parent, [...childrenOf.get(parent) ?? [], id]);
16949
+ }
16950
+ }
16951
+ const build = (id) => {
16952
+ const read = agents.get(id);
16953
+ if (read === void 0) {
16954
+ throw new Error(`agent ${id} is in the tree but was never read`);
16955
+ }
16956
+ return toNode(read, (childrenOf.get(id) ?? []).sort().map(build));
16957
+ };
16958
+ return {
16959
+ project: ref.project,
16960
+ sessionId: ref.sessionId,
16961
+ superseded: ref.superseded,
16962
+ agents: roots.sort().map(build),
16963
+ tasks: readTasks(fs12, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
16964
+ workflowRuns: readWorkflowRuns(fs12, configDir, import_node_path33.default.join(sessionRelative, WORKFLOWS_DIR), report),
16965
+ problems
16966
+ };
16967
+ }
16968
+ function resolveParents(fs12, configDir, agents, report) {
16969
+ const parentOf3 = /* @__PURE__ */ new Map();
16970
+ const transcriptCache = /* @__PURE__ */ new Map();
16971
+ const transcriptOf = (agent) => {
16972
+ const cached = transcriptCache.get(agent.located.id);
16973
+ if (cached !== void 0) {
16974
+ return cached;
16975
+ }
16976
+ const text = readFileOrReport(fs12, configDir, agent.located.transcriptPath, report) ?? "";
16977
+ transcriptCache.set(agent.located.id, text);
16978
+ return text;
16979
+ };
16980
+ const wouldCycle = (child, parent) => {
16981
+ for (let cursor = parent; cursor !== void 0; cursor = parentOf3.get(cursor)) {
16982
+ if (cursor === child) {
16983
+ return true;
16984
+ }
16985
+ }
16986
+ return false;
16987
+ };
16988
+ const attach = (child, parent) => {
16989
+ if (wouldCycle(child.located.id, parent)) {
16990
+ report({ path: child.located.metaPath, reason: `parent ${parent} would make a cycle` });
16991
+ return;
16992
+ }
16993
+ parentOf3.set(child.located.id, parent);
16994
+ };
16995
+ for (const agent of agents.values()) {
16996
+ const { meta, located } = agent;
16997
+ if (meta.parentAgentId !== void 0 && agents.has(meta.parentAgentId)) {
16998
+ attach(agent, meta.parentAgentId);
16999
+ continue;
17000
+ }
17001
+ const depth = meta.spawnDepth;
17002
+ if (depth !== void 0 && depth <= SESSION_SPAWN_DEPTH || meta.toolUseId === void 0) {
17003
+ if (meta.parentAgentId !== void 0) {
17004
+ report({ path: located.metaPath, reason: `parentAgentId ${meta.parentAgentId} names no agent in this session` });
17005
+ }
17006
+ continue;
17007
+ }
17008
+ const toolUseId = meta.toolUseId;
17009
+ const owners = [...agents.values()].filter(
17010
+ (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)
17011
+ );
17012
+ const owner = owners[0];
17013
+ if (owners.length === 1 && owner !== void 0) {
17014
+ attach(agent, owner.located.id);
17015
+ } else if (owners.length > 1) {
17016
+ report({ path: located.metaPath, reason: "more than one agent transcript records the call that spawned it" });
17017
+ } else if (depth !== void 0) {
17018
+ report({ path: located.metaPath, reason: "no agent transcript records the call that spawned it" });
17019
+ }
17020
+ }
17021
+ return parentOf3;
17022
+ }
17023
+ function ownTaskLists(sessionId) {
17024
+ return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
17025
+ }
17026
+ function readTasks(fs12, configDir, ownLists, sharedLists, report) {
17027
+ const tasks = [];
17028
+ [...ownLists, ...sharedLists].forEach((scope, index) => {
17029
+ const relativeDir = import_node_path33.default.join(TASKS_DIR, scope);
17030
+ for (const name of [...listDirOrReport(fs12, configDir, relativeDir, report)].sort()) {
17031
+ if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
17032
+ continue;
17033
+ }
17034
+ const relative = import_node_path33.default.join(relativeDir, name);
17035
+ const text = readFileOrReport(fs12, configDir, relative, report);
17036
+ const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
17037
+ if (parsed.success) {
17038
+ tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
17039
+ } else if (text !== void 0) {
17040
+ report({ path: relative, reason: "task file is not a task" });
17041
+ }
17042
+ }
17043
+ });
17044
+ return tasks;
17045
+ }
17046
+ function readWorkflowRuns(fs12, configDir, relativeDir, report) {
17047
+ const runs = [];
17048
+ for (const name of [...listDirOrReport(fs12, configDir, relativeDir, report)].sort()) {
17049
+ if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
17050
+ continue;
17051
+ }
17052
+ const relative = import_node_path33.default.join(relativeDir, name);
17053
+ const text = readFileOrReport(fs12, configDir, relative, report);
17054
+ const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
17055
+ if (!parsed.success) {
17056
+ if (text !== void 0) {
17057
+ report({ path: relative, reason: "workflow run file is not a run record" });
17058
+ }
17059
+ continue;
17060
+ }
17061
+ const { phases, ...rest } = parsed.data;
17062
+ runs.push({ ...rest, phases: phases.map((phase) => phase.title) });
17063
+ }
17064
+ return runs;
17065
+ }
17066
+
17067
+ // src/index.ts
16690
17068
  init_conditions();
16691
17069
  init_ensure();
16692
17070
  init_supervisor();
@@ -16795,6 +17173,9 @@ init_ownCli();
16795
17173
  // Annotate the CommonJS export names for ESM import in node:
16796
17174
  0 && (module.exports = {
16797
17175
  AMBIENT_CREDENTIAL_VARS,
17176
+ AgentKindSchema,
17177
+ AgentMetaSchema,
17178
+ AgentNodeSchema,
16798
17179
  CHECK_CREDENTIAL_APPLIES,
16799
17180
  CODEX_APP_SERVER_GENERATED_AGAINST,
16800
17181
  CODEX_APP_SERVER_TIMEOUT_MS,
@@ -16941,6 +17322,8 @@ init_ownCli();
16941
17322
  RcStreamEventSchema,
16942
17323
  ResetRowSchema,
16943
17324
  ResetScheduleSchema,
17325
+ SessionAgentTreeSchema,
17326
+ TaskItemSchema,
16944
17327
  USAGE_EVENT_SOURCE,
16945
17328
  UpdateCheckOutputSchema,
16946
17329
  UsageError,
@@ -16951,6 +17334,7 @@ init_ownCli();
16951
17334
  UsageWindowsInputSchema,
16952
17335
  UsageWindowsOutputSchema,
16953
17336
  WhenSchema,
17337
+ WorkflowRunSchema,
16954
17338
  addDirectoryRule,
16955
17339
  addIdentity,
16956
17340
  addPool,
@@ -17052,6 +17436,7 @@ init_ownCli();
17052
17436
  listIdentities,
17053
17437
  listProfiles,
17054
17438
  listProviders,
17439
+ listSessions,
17055
17440
  listUsageSnapshots,
17056
17441
  matchBranch,
17057
17442
  mintLeaf,
@@ -17086,6 +17471,7 @@ init_ownCli();
17086
17471
  readProvider,
17087
17472
  readRcSelfHostRecord,
17088
17473
  readRcSessionFile,
17474
+ readSessionAgentTree,
17089
17475
  readUsageSnapshot,
17090
17476
  realCodexAppServerPort,
17091
17477
  realConnectCertStore,