@codexhost/cli-linux-arm64 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.txt +12 -0
  3. package/app/codexhost-distribution.json +1 -1
  4. package/app/desktop-controller.mjs +67 -26
  5. package/app/host-runtime.mjs +3774 -6483
  6. package/app/plugins/antigravity/plugin.mjs +114 -93
  7. package/app/plugins/claude-code/plugin.mjs +480 -239
  8. package/app/plugins/codebuddy/plugin.mjs +2177 -846
  9. package/app/plugins/cursor-cli/plugin.mjs +35065 -10156
  10. package/app/plugins/deepseek-harness/plugin.mjs +72 -84
  11. package/app/plugins/enabled.json +4 -1
  12. package/app/plugins/grok/plugin.mjs +60 -78
  13. package/app/plugins/hermes/plugin.mjs +2431 -174
  14. package/app/plugins/kiro-cli/plugin.mjs +67 -80
  15. package/app/plugins/omp/plugin.mjs +106 -91
  16. package/app/plugins/opencode/plugin.mjs +109 -123
  17. package/app/plugins/pi/plugin.mjs +71 -84
  18. package/app/plugins/qoder/assets/icon.svg +1 -0
  19. package/app/plugins/qoder/manifest.json +12 -0
  20. package/app/plugins/qoder/plugin.mjs +52267 -0
  21. package/app/plugins/qoder-cn/assets/icon.svg +1 -0
  22. package/app/plugins/qoder-cn/manifest.json +12 -0
  23. package/app/plugins/qoder-cn/plugin.mjs +52265 -0
  24. package/app/plugins/workbuddy/assets/icon.svg +29 -0
  25. package/app/plugins/workbuddy/manifest.json +14 -0
  26. package/app/plugins/workbuddy/plugin.mjs +24818 -0
  27. package/app/renderer-extension.js +3182 -960
  28. package/bin/codexhost +0 -0
  29. package/libexec/codexhost-shim +0 -0
  30. package/libexec/codexhost-updater +0 -0
  31. package/licenses/Qoder-Agent-SDK-LICENSE.txt +7 -0
  32. package/licenses/QoderCN-Agent-SDK-LICENSE.txt +7 -0
  33. package/licenses/tailwindcss-LICENSE.txt +21 -0
  34. package/package.json +1 -1
@@ -776,10 +776,10 @@ function mergeDefs(...defs) {
776
776
  function cloneDef(schema) {
777
777
  return mergeDefs(schema._zod.def);
778
778
  }
779
- function getElementAtPath(obj, path12) {
780
- if (!path12)
779
+ function getElementAtPath(obj, path13) {
780
+ if (!path13)
781
781
  return obj;
782
- return path12.reduce((acc, key) => acc?.[key], obj);
782
+ return path13.reduce((acc, key) => acc?.[key], obj);
783
783
  }
784
784
  function promiseAllObject(promisesObj) {
785
785
  const keys = Object.keys(promisesObj);
@@ -1188,11 +1188,11 @@ function explicitlyAborted(x2, startIndex = 0) {
1188
1188
  }
1189
1189
  return false;
1190
1190
  }
1191
- function prefixIssues(path12, issues) {
1191
+ function prefixIssues(path13, issues) {
1192
1192
  return issues.map((iss) => {
1193
1193
  var _a4;
1194
1194
  (_a4 = iss).path ?? (_a4.path = []);
1195
- iss.path.unshift(path12);
1195
+ iss.path.unshift(path13);
1196
1196
  return iss;
1197
1197
  });
1198
1198
  }
@@ -1339,16 +1339,16 @@ function flattenError(error52, mapper = (issue2) => issue2.message) {
1339
1339
  }
1340
1340
  function formatError(error52, mapper = (issue2) => issue2.message) {
1341
1341
  const fieldErrors = { _errors: [] };
1342
- const processError = (error53, path12 = []) => {
1342
+ const processError = (error53, path13 = []) => {
1343
1343
  for (const issue2 of error53.issues) {
1344
1344
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1345
- issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
1345
+ issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
1346
1346
  } else if (issue2.code === "invalid_key") {
1347
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1347
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1348
1348
  } else if (issue2.code === "invalid_element") {
1349
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1349
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1350
1350
  } else {
1351
- const fullpath = [...path12, ...issue2.path];
1351
+ const fullpath = [...path13, ...issue2.path];
1352
1352
  if (fullpath.length === 0) {
1353
1353
  fieldErrors._errors.push(mapper(issue2));
1354
1354
  } else {
@@ -1375,17 +1375,17 @@ function formatError(error52, mapper = (issue2) => issue2.message) {
1375
1375
  }
1376
1376
  function treeifyError(error52, mapper = (issue2) => issue2.message) {
1377
1377
  const result = { errors: [] };
1378
- const processError = (error53, path12 = []) => {
1378
+ const processError = (error53, path13 = []) => {
1379
1379
  var _a4, _b2;
1380
1380
  for (const issue2 of error53.issues) {
1381
1381
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1382
- issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
1382
+ issue2.errors.map((issues) => processError({ issues }, [...path13, ...issue2.path]));
1383
1383
  } else if (issue2.code === "invalid_key") {
1384
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1384
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1385
1385
  } else if (issue2.code === "invalid_element") {
1386
- processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1386
+ processError({ issues: issue2.issues }, [...path13, ...issue2.path]);
1387
1387
  } else {
1388
- const fullpath = [...path12, ...issue2.path];
1388
+ const fullpath = [...path13, ...issue2.path];
1389
1389
  if (fullpath.length === 0) {
1390
1390
  result.errors.push(mapper(issue2));
1391
1391
  continue;
@@ -1417,8 +1417,8 @@ function treeifyError(error52, mapper = (issue2) => issue2.message) {
1417
1417
  }
1418
1418
  function toDotPath(_path) {
1419
1419
  const segs = [];
1420
- const path12 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
- for (const seg of path12) {
1420
+ const path13 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
+ for (const seg of path13) {
1422
1422
  if (typeof seg === "number")
1423
1423
  segs.push(`[${seg}]`);
1424
1424
  else if (typeof seg === "symbol")
@@ -14110,13 +14110,13 @@ function resolveRef(ref, ctx) {
14110
14110
  if (!ref.startsWith("#")) {
14111
14111
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14112
14112
  }
14113
- const path12 = ref.slice(1).split("/").filter(Boolean);
14114
- if (path12.length === 0) {
14113
+ const path13 = ref.slice(1).split("/").filter(Boolean);
14114
+ if (path13.length === 0) {
14115
14115
  return ctx.rootSchema;
14116
14116
  }
14117
14117
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14118
- if (path12[0] === defsKey) {
14119
- const key = path12[1];
14118
+ if (path13[0] === defsKey) {
14119
+ const key = path13[1];
14120
14120
  if (!key || !ctx.defs[key]) {
14121
14121
  throw new Error(`Reference not found: ${ref}`);
14122
14122
  }
@@ -14527,6 +14527,46 @@ config(en_default());
14527
14527
  // ../../shared-contracts/dist/version.js
14528
14528
  var WORKSPACE_CONTRACT_VERSION = 1;
14529
14529
 
14530
+ // ../../shared-contracts/dist/idle-release.js
14531
+ var IDLE_RELEASE_TIMEOUT_MINUTES_MIN = 5;
14532
+ var IDLE_RELEASE_TIMEOUT_MINUTES_MAX = 1440;
14533
+ var idleReleaseSettingsSchema = external_exports.strictObject({
14534
+ enabled: external_exports.boolean(),
14535
+ timeoutMinutes: external_exports.number().int().min(IDLE_RELEASE_TIMEOUT_MINUTES_MIN).max(IDLE_RELEASE_TIMEOUT_MINUTES_MAX)
14536
+ });
14537
+ var DEFAULT_IDLE_RELEASE_SETTINGS = Object.freeze({
14538
+ enabled: false,
14539
+ timeoutMinutes: 30
14540
+ });
14541
+
14542
+ // ../../shared-contracts/dist/loaded-sessions.js
14543
+ var loadedSessionStateSchema = external_exports.enum([
14544
+ "idle",
14545
+ "running",
14546
+ "busy",
14547
+ "closing",
14548
+ "failed",
14549
+ "blocked"
14550
+ ]);
14551
+ var loadedSessionReasonSchema = external_exports.enum([
14552
+ "none",
14553
+ "disabled",
14554
+ "timeout",
14555
+ "operation",
14556
+ "background",
14557
+ "identity",
14558
+ "persistence",
14559
+ "closeFailed"
14560
+ ]);
14561
+ var loadedSessionsSchema = external_exports.array(external_exports.strictObject({
14562
+ threadId: external_exports.string(),
14563
+ title: external_exports.string(),
14564
+ harnessId: external_exports.string(),
14565
+ state: loadedSessionStateSchema,
14566
+ reason: loadedSessionReasonSchema,
14567
+ inactiveMs: external_exports.number().nonnegative()
14568
+ }));
14569
+
14530
14570
  // ../../shared-contracts/dist/ids.js
14531
14571
  var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
14532
14572
  message: "Identifier must not be empty or whitespace"
@@ -15012,6 +15052,8 @@ var pluginPresentationShape = {
15012
15052
  id: harnessPluginIdSchema,
15013
15053
  name: external_exports.string().trim().min(1).max(128),
15014
15054
  version: external_exports.string().min(1).max(128),
15055
+ /** The factory accepts a persisted local entrypoint through its construction context. */
15056
+ launchCommand: external_exports.literal(true).optional(),
15015
15057
  links: external_exports.object({
15016
15058
  documentation: documentationUrlSchema.optional(),
15017
15059
  installation: documentationUrlSchema.optional()
@@ -15049,6 +15091,19 @@ var harnessPluginRouteSchema = external_exports.object({
15049
15091
  permissionModeId: harnessPermissionModeIdSchema.optional()
15050
15092
  }).strict();
15051
15093
 
15094
+ // ../../shared-contracts/dist/harness-launch-settings.js
15095
+ var harnessLaunchPathSchema = external_exports.string().trim().min(1).max(4096).refine((value) => !/[\u0000\r\n]/u.test(value), "Invalid entrypoint path");
15096
+ var harnessLaunchSettingsGetSchema = external_exports.object({
15097
+ harnessId: harnessPluginIdSchema
15098
+ }).strict();
15099
+ var harnessLaunchSettingsSetSchema = harnessLaunchSettingsGetSchema.extend({
15100
+ path: harnessLaunchPathSchema.nullable()
15101
+ });
15102
+ var harnessLaunchSettingsSchema = external_exports.object({
15103
+ path: harnessLaunchPathSchema.nullable(),
15104
+ restartRequired: external_exports.boolean()
15105
+ }).strict();
15106
+
15052
15107
  // ../../shared-contracts/dist/codex-accounts.js
15053
15108
  var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
15054
15109
  var nonBlankTextSchema3 = external_exports.string().trim().min(1);
@@ -15077,75 +15132,15 @@ var codexAccountSchema = external_exports.object({
15077
15132
  email: external_exports.string().email().max(320).optional(),
15078
15133
  planType: codexAccountPlanTypeSchema.optional()
15079
15134
  }).strict();
15080
- var codexAccountPhaseSchema = external_exports.enum(["ready", "changing", "unavailable"]);
15081
- var codexAccountPendingOperationSchema = external_exports.object({
15082
- operationId: nonBlankTextSchema3.max(1024),
15083
- kind: external_exports.enum(["login", "switch", "logout", "recovery"])
15084
- }).strict();
15085
- var codexAccountCapabilitiesSchema = external_exports.object({
15086
- manage: external_exports.boolean(),
15087
- switch: external_exports.boolean(),
15088
- login: external_exports.boolean(),
15089
- delete: external_exports.boolean(),
15090
- recover: external_exports.boolean().optional(),
15091
- logout: external_exports.boolean().optional(),
15092
- reason: external_exports.enum([
15093
- "ssh-single-account",
15094
- "unsupported-storage",
15095
- "unsupported-version",
15096
- "recovery-required",
15097
- "keyring-unavailable",
15098
- "migration-required"
15099
- ]).optional()
15100
- }).strict();
15135
+ var codexAccountPhaseSchema = external_exports.enum(["ready", "unavailable"]);
15101
15136
  var codexAccountListResultSchema = external_exports.object({
15102
15137
  version: external_exports.literal(2),
15103
15138
  currentAccountId: accountIdSchema.nullable(),
15104
15139
  phase: codexAccountPhaseSchema,
15105
15140
  revision: external_exports.number().int().nonnegative(),
15106
15141
  instanceId: nonBlankTextSchema3.max(1024).optional(),
15107
- cleanupRequired: external_exports.boolean().optional(),
15108
- /** Credentials were adopted; other native homes/history remain unmerged. */
15109
- legacyHistoryPreserved: external_exports.boolean().optional(),
15110
- pendingOperation: codexAccountPendingOperationSchema.optional(),
15111
- capabilities: codexAccountCapabilitiesSchema,
15112
- accounts: external_exports.array(codexAccountSchema).max(128)
15113
- }).strict();
15114
- var codexAccountActivateParamsSchema = external_exports.object({ accountId: accountIdSchema }).strict();
15115
- var codexAccountSwitchParamsSchema = external_exports.object({ accountId: accountIdSchema }).strict();
15116
- var codexAccountReadyMutationResultShape = {
15117
- phase: external_exports.literal("ready"),
15118
- revision: external_exports.number().int().nonnegative()
15119
- };
15120
- var codexAccountSwitchResultSchema = external_exports.object({
15121
- currentAccountId: accountIdSchema,
15122
- ...codexAccountReadyMutationResultShape
15123
- }).strict();
15124
- var codexAccountDeleteParamsSchema = external_exports.object({ accountId: accountIdSchema }).strict();
15125
- var codexAccountDeleteResultSchema = external_exports.object({ deletedAccountId: accountIdSchema }).strict();
15126
- var codexAccountLoginStartParamsSchema = external_exports.object({ accountId: accountIdSchema.optional() }).strict();
15127
- var codexAccountLoginStartResultSchema = external_exports.object({
15128
- accountId: accountIdSchema,
15129
- loginId: nonBlankTextSchema3.max(1024),
15130
- verificationUrl: external_exports.string().url().max(16384),
15131
- userCode: nonBlankTextSchema3.max(1024)
15132
- }).strict();
15133
- var codexAccountLoginCancelParamsSchema = external_exports.object({ loginId: nonBlankTextSchema3.max(1024) }).strict();
15134
- var codexAccountLoginCancelResultSchema = external_exports.object({ cancelled: external_exports.boolean() }).strict();
15135
- var codexAccountLoginCompletedSchema = external_exports.object({
15136
- accountId: accountIdSchema,
15137
- loginId: nonBlankTextSchema3.max(1024),
15138
- success: external_exports.boolean(),
15139
- error: external_exports.string().max(4096).nullable(),
15140
- saved: external_exports.boolean().optional(),
15141
- cleanupRequired: external_exports.boolean().optional()
15142
- }).strict();
15143
- var codexAccountLogoutParamsSchema = external_exports.object({}).strict();
15144
- var codexAccountLogoutResultSchema = external_exports.object({
15145
- currentAccountId: external_exports.null(),
15146
- ...codexAccountReadyMutationResultShape
15142
+ accounts: external_exports.array(codexAccountSchema).max(1)
15147
15143
  }).strict();
15148
- var codexAccountRecoverParamsSchema = external_exports.object({}).strict();
15149
15144
  var codexAccountUsageParamsSchema = external_exports.object({ accountId: accountIdSchema, refresh: external_exports.boolean().optional() }).strict();
15150
15145
  var codexAccountUsageResultSchema = external_exports.object({
15151
15146
  accountId: accountIdSchema,
@@ -15154,21 +15149,6 @@ var codexAccountUsageResultSchema = external_exports.object({
15154
15149
  freshness: external_exports.enum(["live", "cached"]),
15155
15150
  observedAt: external_exports.string().datetime().nullable()
15156
15151
  }).strict();
15157
- var codexAccountResetCreditConsumeParamsSchema = external_exports.object({
15158
- accountId: accountIdSchema,
15159
- idempotencyKey: external_exports.string().uuid().optional()
15160
- }).strict();
15161
- var codexAccountResetCreditConsumeOutcomeSchema = external_exports.enum([
15162
- "reset",
15163
- "nothingToReset",
15164
- "noCredit",
15165
- "alreadyRedeemed"
15166
- ]);
15167
- var codexAccountResetCreditConsumeResultSchema = external_exports.object({
15168
- accountId: accountIdSchema,
15169
- outcome: codexAccountResetCreditConsumeOutcomeSchema,
15170
- accountCredits: accountCreditsSnapshotSchema.optional()
15171
- }).strict();
15172
15152
 
15173
15153
  // ../../shared-contracts/dist/harness-session-import.js
15174
15154
  var HARNESS_SESSION_IMPORT_ID_MAX_LENGTH = 1024;
@@ -16509,7 +16489,7 @@ var BrokeredHarnessAdapter = class {
16509
16489
 
16510
16490
  // dist/claude-code-adapter.js
16511
16491
  import { randomUUID as randomUUID3 } from "node:crypto";
16512
- import path10 from "node:path";
16492
+ import path11 from "node:path";
16513
16493
 
16514
16494
  // ../../../node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs
16515
16495
  import { createRequire as DW } from "node:module";
@@ -20414,8 +20394,8 @@ var qU = v(function(BU) {
20414
20394
  BU._globalThis = void 0;
20415
20395
  BU._globalThis = typeof globalThis === "object" ? globalThis : global;
20416
20396
  });
20417
- var GU = v(function(os5) {
20418
- var Axe = os5 && os5.__createBinding || (Object.create ? function(e, t, r, n) {
20397
+ var GU = v(function(os6) {
20398
+ var Axe = os6 && os6.__createBinding || (Object.create ? function(e, t, r, n) {
20419
20399
  if (n === void 0) n = r;
20420
20400
  Object.defineProperty(e, n, { enumerable: true, get: function() {
20421
20401
  return t[r];
@@ -20423,11 +20403,11 @@ var GU = v(function(os5) {
20423
20403
  } : function(e, t, r, n) {
20424
20404
  if (n === void 0) n = r;
20425
20405
  e[n] = t[r];
20426
- }), kxe = os5 && os5.__exportStar || function(e, t) {
20406
+ }), kxe = os6 && os6.__exportStar || function(e, t) {
20427
20407
  for (var r in e) if (r !== "default" && !Object.prototype.hasOwnProperty.call(t, r)) Axe(t, e, r);
20428
20408
  };
20429
- Object.defineProperty(os5, "__esModule", { value: true });
20430
- kxe(qU(), os5);
20409
+ Object.defineProperty(os6, "__esModule", { value: true });
20410
+ kxe(qU(), os6);
20431
20411
  });
20432
20412
  var WU = v(function(is) {
20433
20413
  var Oxe = is && is.__createBinding || (Object.create ? function(e, t, r, n) {
@@ -42200,14 +42180,225 @@ var ClaudeBackgroundOccupancy = class {
42200
42180
  }
42201
42181
  };
42202
42182
 
42183
+ // dist/claude-session-import.js
42184
+ import { createReadStream } from "node:fs";
42185
+ import { opendir, realpath, stat } from "node:fs/promises";
42186
+ import os2 from "node:os";
42187
+ import path2 from "node:path";
42188
+ import { createInterface } from "node:readline";
42189
+ var CLAUDE_SESSION_IMPORT_TITLE_MAX_LENGTH = 120;
42190
+ var CLAUDE_INTERNAL_USER_TEXT = /^<(?:local-command-|command-)/u;
42191
+ var ClaudeSessionChangedError = class extends Error {
42192
+ constructor() {
42193
+ super("Claude Code Session changed during discovery; refresh and retry");
42194
+ }
42195
+ };
42196
+ function isRecord2(value) {
42197
+ return typeof value === "object" && value !== null && !Array.isArray(value);
42198
+ }
42199
+ function missing(error52) {
42200
+ return isRecord2(error52) && error52.code === "ENOENT";
42201
+ }
42202
+ function sameFile(left, right) {
42203
+ return left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs && left.ino === right.ino && left.dev === right.dev;
42204
+ }
42205
+ function cleanText(value) {
42206
+ if (typeof value !== "string")
42207
+ return null;
42208
+ const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
42209
+ if (!normalized)
42210
+ return null;
42211
+ const characters = [...normalized];
42212
+ if (characters.length <= CLAUDE_SESSION_IMPORT_TITLE_MAX_LENGTH)
42213
+ return normalized;
42214
+ return `${characters.slice(0, CLAUDE_SESSION_IMPORT_TITLE_MAX_LENGTH - 1).join("").trimEnd()}…`;
42215
+ }
42216
+ function userText(message) {
42217
+ if (!isRecord2(message) || message.role !== "user")
42218
+ return null;
42219
+ const { content } = message;
42220
+ const text = typeof content === "string" ? cleanText(content) : Array.isArray(content) ? cleanText(content.filter((block) => isRecord2(block) && block.type === "text" && typeof block.text === "string").map((block) => String(block.text)).join(" ")) : null;
42221
+ return text && !CLAUDE_INTERNAL_USER_TEXT.test(text) ? text : null;
42222
+ }
42223
+ function claudeProjectsDirectory(environment) {
42224
+ const home = (process.platform === "win32" ? environment.USERPROFILE : environment.HOME) || os2.homedir();
42225
+ return path2.join(path2.resolve(environment.CLAUDE_CONFIG_DIR ?? path2.join(home, ".claude")), "projects");
42226
+ }
42227
+ async function sessionFiles(directory, signal) {
42228
+ signal.throwIfAborted();
42229
+ const projects = await opendir(directory).catch((error52) => {
42230
+ if (missing(error52))
42231
+ return null;
42232
+ throw error52;
42233
+ });
42234
+ if (!projects)
42235
+ return [];
42236
+ const files = [];
42237
+ for await (const project of projects) {
42238
+ signal.throwIfAborted();
42239
+ if (!project.isDirectory())
42240
+ continue;
42241
+ const entries = await opendir(path2.join(directory, project.name)).catch((error52) => {
42242
+ if (missing(error52))
42243
+ return null;
42244
+ throw error52;
42245
+ });
42246
+ if (!entries)
42247
+ continue;
42248
+ for await (const entry of entries) {
42249
+ signal.throwIfAborted();
42250
+ if (entry.isFile() && entry.name.endsWith(".jsonl")) {
42251
+ files.push(path2.join(directory, project.name, entry.name));
42252
+ }
42253
+ }
42254
+ }
42255
+ return files;
42256
+ }
42257
+ async function readCandidate(file2, signal) {
42258
+ const nativeSessionId = path2.basename(file2, ".jsonl");
42259
+ if (!external_exports.uuid().safeParse(nativeSessionId).success)
42260
+ return null;
42261
+ const before = await stat(file2);
42262
+ if (!before.isFile() || before.size === 0)
42263
+ return null;
42264
+ const stream = createReadStream(file2, { encoding: "utf8", signal, end: before.size - 1 });
42265
+ const lines = createInterface({ input: stream, crlfDelay: Infinity });
42266
+ let cwd = null;
42267
+ let customTitle = null;
42268
+ let generatedTitle = null;
42269
+ let firstPrompt = null;
42270
+ let hasConversation = false;
42271
+ try {
42272
+ for await (const line of lines) {
42273
+ signal.throwIfAborted();
42274
+ if (!line.trim())
42275
+ continue;
42276
+ let entry;
42277
+ try {
42278
+ entry = JSON.parse(line);
42279
+ } catch {
42280
+ continue;
42281
+ }
42282
+ if (!isRecord2(entry))
42283
+ continue;
42284
+ if (typeof entry.sessionId === "string" && entry.sessionId !== nativeSessionId)
42285
+ return null;
42286
+ if (entry.isSidechain === true)
42287
+ continue;
42288
+ if (typeof entry.cwd === "string" && path2.isAbsolute(entry.cwd))
42289
+ cwd = entry.cwd;
42290
+ if (entry.type === "custom-title") {
42291
+ customTitle = cleanText(entry.customTitle);
42292
+ } else if (entry.type === "ai-title") {
42293
+ generatedTitle = cleanText(entry.aiTitle);
42294
+ } else if (entry.type === "summary") {
42295
+ generatedTitle = cleanText(entry.summary) ?? generatedTitle;
42296
+ } else if (entry.type === "user" || entry.type === "assistant") {
42297
+ hasConversation = true;
42298
+ if (!firstPrompt && entry.type === "user")
42299
+ firstPrompt = userText(entry.message);
42300
+ }
42301
+ }
42302
+ } finally {
42303
+ lines.close();
42304
+ stream.destroy();
42305
+ }
42306
+ if (!hasConversation || !cwd)
42307
+ return null;
42308
+ const after = await stat(file2);
42309
+ if (!sameFile(before, after))
42310
+ throw new ClaudeSessionChangedError();
42311
+ const resolvedCwd = await realpath(cwd);
42312
+ if (!(await stat(resolvedCwd)).isDirectory())
42313
+ return null;
42314
+ const candidate = harnessSessionImportCandidateSchema.safeParse({
42315
+ nativeSessionId,
42316
+ title: customTitle ?? generatedTitle ?? firstPrompt,
42317
+ updatedAt: Math.floor(before.mtimeMs),
42318
+ cwd: resolvedCwd,
42319
+ running: null
42320
+ });
42321
+ const nativeRef = nativeSessionRefSchema.safeParse({
42322
+ harnessId: "claude-code",
42323
+ nativeSessionId,
42324
+ formatVersion: 1
42325
+ });
42326
+ return candidate.success && nativeRef.success ? { candidate: candidate.data, nativeRef: nativeRef.data } : null;
42327
+ }
42328
+ var ClaudeSessionImportIndex = class {
42329
+ #directory;
42330
+ #cache = /* @__PURE__ */ new Map();
42331
+ #listing;
42332
+ constructor(environment) {
42333
+ this.#directory = claudeProjectsDirectory(environment);
42334
+ }
42335
+ list(signal) {
42336
+ this.#listing ??= this.#scan(signal).finally(() => {
42337
+ this.#listing = void 0;
42338
+ });
42339
+ return this.#listing;
42340
+ }
42341
+ async #scan(signal) {
42342
+ const next = /* @__PURE__ */ new Map();
42343
+ const identities = /* @__PURE__ */ new Set();
42344
+ const sources = [];
42345
+ for (const file2 of await sessionFiles(this.#directory, signal)) {
42346
+ signal.throwIfAborted();
42347
+ try {
42348
+ const fingerprint = await stat(file2);
42349
+ const cached2 = this.#cache.get(file2);
42350
+ const source = cached2 && sameFile(cached2.fingerprint, fingerprint) ? cached2.source : await readCandidate(file2, signal);
42351
+ if (!source)
42352
+ continue;
42353
+ if (!(await stat(source.candidate.cwd)).isDirectory())
42354
+ continue;
42355
+ if (identities.has(source.candidate.nativeSessionId)) {
42356
+ throw new Error("Claude Code Session identity is ambiguous across files");
42357
+ }
42358
+ identities.add(source.candidate.nativeSessionId);
42359
+ next.set(file2, { fingerprint, source });
42360
+ sources.push(source);
42361
+ } catch (error52) {
42362
+ if (!missing(error52) && !(error52 instanceof ClaudeSessionChangedError))
42363
+ throw error52;
42364
+ }
42365
+ }
42366
+ this.#cache = next;
42367
+ return structuredClone(sources.sort((left, right) => right.candidate.updatedAt - left.candidate.updatedAt));
42368
+ }
42369
+ async resolve(nativeSessionId, signal) {
42370
+ if (!external_exports.uuid().safeParse(nativeSessionId).success)
42371
+ return null;
42372
+ let selected;
42373
+ for (const file2 of await sessionFiles(this.#directory, signal)) {
42374
+ signal.throwIfAborted();
42375
+ if (path2.basename(file2, ".jsonl") !== nativeSessionId)
42376
+ continue;
42377
+ if (selected)
42378
+ throw new Error("Claude Code Session identity is ambiguous across files");
42379
+ selected = file2;
42380
+ }
42381
+ if (!selected)
42382
+ return null;
42383
+ try {
42384
+ const source = await readCandidate(selected, signal);
42385
+ return source?.candidate.nativeSessionId === nativeSessionId ? source : null;
42386
+ } catch (error52) {
42387
+ if (missing(error52))
42388
+ return null;
42389
+ throw error52;
42390
+ }
42391
+ }
42392
+ };
42393
+
42203
42394
  // dist/command.js
42204
- import path4 from "node:path";
42395
+ import path5 from "node:path";
42205
42396
 
42206
42397
  // ../../harness-discovery/dist/environment.js
42207
42398
  import fs from "node:fs";
42208
- import path2 from "node:path";
42399
+ import path3 from "node:path";
42209
42400
  function targetPath(platform) {
42210
- return platform === "win32" ? path2.win32 : path2.posix;
42401
+ return platform === "win32" ? path3.win32 : path3.posix;
42211
42402
  }
42212
42403
  function environmentValue(environment, name) {
42213
42404
  const lowered = name.toLowerCase();
@@ -42250,21 +42441,21 @@ function newestFirst(names) {
42250
42441
  }
42251
42442
 
42252
42443
  // ../../harness-discovery/dist/node-runtime.js
42253
- import path3 from "node:path";
42444
+ import path4 from "node:path";
42254
42445
  function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
42255
42446
  const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
42256
42447
  const delimiter = platform === "win32" ? ";" : ":";
42257
- const runtimeDirectory = path3.dirname(runtimeExecutable);
42448
+ const runtimeDirectory = path4.dirname(runtimeExecutable);
42258
42449
  const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
42259
42450
  const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
42260
42451
  if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
42261
- directories.unshift(runtimeDirectory);
42452
+ directories.push(runtimeDirectory);
42262
42453
  }
42263
42454
  return { ...environment, [pathKey]: directories.join(delimiter) };
42264
42455
  }
42265
42456
 
42266
42457
  // ../../harness-discovery/dist/resolve.js
42267
- import os2 from "node:os";
42458
+ import os3 from "node:os";
42268
42459
 
42269
42460
  // ../../harness-discovery/dist/version-managers.js
42270
42461
  function versionManagerBinaryDirectories(context) {
@@ -42330,7 +42521,7 @@ function installRootExtensions(platform) {
42330
42521
  return platform === "win32" ? [".exe", ".cmd"] : [""];
42331
42522
  }
42332
42523
  function resolveHomeDirectory(input) {
42333
- return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os2.homedir();
42524
+ return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os3.homedir();
42334
42525
  }
42335
42526
  function templateVariables(environment, platform, home) {
42336
42527
  const pathFlavor = targetPath(platform);
@@ -42472,14 +42663,14 @@ function resolveClaudeCodeExecutable(input = {}, dependencies = {}) {
42472
42663
  }, dependencies);
42473
42664
  if (!resolution)
42474
42665
  throw new ClaudeCodeExecutableError("Claude Code is not installed");
42475
- return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path4.resolve(resolution.executable);
42666
+ return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path5.resolve(resolution.executable);
42476
42667
  }
42477
42668
 
42478
42669
  // dist/pending-session.js
42479
42670
  import { randomUUID as randomUUID2 } from "node:crypto";
42480
- import { mkdir, open, readFile as readFile2, rename, rm as rm2, stat, unlink } from "node:fs/promises";
42481
- import os3 from "node:os";
42482
- import path5 from "node:path";
42671
+ import { mkdir, open, readFile as readFile2, rename, rm as rm2, stat as stat2, unlink } from "node:fs/promises";
42672
+ import os4 from "node:os";
42673
+ import path6 from "node:path";
42483
42674
  var reservationSchema = external_exports.strictObject({
42484
42675
  version: external_exports.literal(1),
42485
42676
  sessionId: external_exports.uuid(),
@@ -42492,13 +42683,13 @@ function isPendingClaudeSession(ref) {
42492
42683
  var ClaudePendingSessions = class {
42493
42684
  #directory;
42494
42685
  constructor(environment) {
42495
- this.#directory = path5.join(path5.resolve(environment.CLAUDE_CONFIG_DIR ?? path5.join(os3.homedir(), ".claude")), "codexhost", "pending-sessions");
42686
+ this.#directory = path6.join(path6.resolve(environment.CLAUDE_CONFIG_DIR ?? path6.join(os4.homedir(), ".claude")), "codexhost", "pending-sessions");
42496
42687
  }
42497
42688
  #path(ref, cwd) {
42498
- if (ref.harnessId !== "claude-code" || !external_exports.uuid().safeParse(ref.nativeSessionId).success || !external_exports.strictObject({ pendingSession: external_exports.literal(1) }).safeParse(ref.locator).success || !path5.isAbsolute(cwd)) {
42689
+ if (ref.harnessId !== "claude-code" || !external_exports.uuid().safeParse(ref.nativeSessionId).success || !external_exports.strictObject({ pendingSession: external_exports.literal(1) }).safeParse(ref.locator).success || !path6.isAbsolute(cwd)) {
42499
42690
  throw new Error("Claude Code pending Session identity is invalid");
42500
42691
  }
42501
- return path5.join(this.#directory, ref.nativeSessionId);
42692
+ return path6.join(this.#directory, ref.nativeSessionId);
42502
42693
  }
42503
42694
  async create(cwd, configuration) {
42504
42695
  const ref = nativeSessionRefSchema.parse({
@@ -42517,7 +42708,7 @@ var ClaudePendingSessions = class {
42517
42708
  await mkdir(this.#directory, { recursive: true, mode: 448 });
42518
42709
  await mkdir(directory, { mode: 448 });
42519
42710
  try {
42520
- const file2 = await open(path5.join(directory, "session.json"), "wx", 384);
42711
+ const file2 = await open(path6.join(directory, "session.json"), "wx", 384);
42521
42712
  try {
42522
42713
  await file2.writeFile(JSON.stringify(reservation));
42523
42714
  await file2.sync();
@@ -42534,13 +42725,13 @@ var ClaudePendingSessions = class {
42534
42725
  }
42535
42726
  async read(ref, cwd) {
42536
42727
  const directory = this.#path(ref, cwd);
42537
- const reservation = reservationSchema.parse(JSON.parse(await readFile2(path5.join(directory, "session.json"), "utf8")));
42728
+ const reservation = reservationSchema.parse(JSON.parse(await readFile2(path6.join(directory, "session.json"), "utf8")));
42538
42729
  if (reservation.sessionId !== ref.nativeSessionId || reservation.cwd !== cwd) {
42539
42730
  throw new Error("Claude Code pending Session does not belong to this working directory");
42540
42731
  }
42541
42732
  let started = false;
42542
42733
  try {
42543
- const claim = await stat(path5.join(directory, "started"));
42734
+ const claim = await stat2(path6.join(directory, "started"));
42544
42735
  if (!claim.isFile())
42545
42736
  throw new Error("Claude Code pending Session claim is invalid");
42546
42737
  started = true;
@@ -42553,7 +42744,7 @@ var ClaudePendingSessions = class {
42553
42744
  async saveConfiguration(ref, cwd, configuration) {
42554
42745
  await this.read(ref, cwd);
42555
42746
  const directory = this.#path(ref, cwd);
42556
- const temporary = path5.join(directory, `${randomUUID2()}.tmp`);
42747
+ const temporary = path6.join(directory, `${randomUUID2()}.tmp`);
42557
42748
  try {
42558
42749
  const file2 = await open(temporary, "wx", 384);
42559
42750
  try {
@@ -42567,7 +42758,7 @@ var ClaudePendingSessions = class {
42567
42758
  } finally {
42568
42759
  await file2.close();
42569
42760
  }
42570
- await rename(temporary, path5.join(directory, "session.json"));
42761
+ await rename(temporary, path6.join(directory, "session.json"));
42571
42762
  await this.#sync(directory);
42572
42763
  } finally {
42573
42764
  await rm2(temporary, { force: true });
@@ -42585,7 +42776,7 @@ var ClaudePendingSessions = class {
42585
42776
  }
42586
42777
  async claim(ref, cwd) {
42587
42778
  await this.read(ref, cwd);
42588
- const claim = await open(path5.join(this.#path(ref, cwd), "started"), "wx", 384);
42779
+ const claim = await open(path6.join(this.#path(ref, cwd), "started"), "wx", 384);
42589
42780
  try {
42590
42781
  await claim.sync();
42591
42782
  } finally {
@@ -42595,7 +42786,7 @@ var ClaudePendingSessions = class {
42595
42786
  }
42596
42787
  /** Only the claim owner may release, after proven close and before submitting any native input. */
42597
42788
  async release(ref, cwd) {
42598
- await unlink(path5.join(this.#path(ref, cwd), "started"));
42789
+ await unlink(path6.join(this.#path(ref, cwd), "started"));
42599
42790
  await this.#sync(this.#path(ref, cwd));
42600
42791
  }
42601
42792
  async discard(ref, cwd) {
@@ -42604,7 +42795,7 @@ var ClaudePendingSessions = class {
42604
42795
  };
42605
42796
 
42606
42797
  // dist/claude-fork.js
42607
- import path6 from "node:path";
42798
+ import path7 from "node:path";
42608
42799
  import { isDeepStrictEqual } from "node:util";
42609
42800
 
42610
42801
  // dist/item-identity.js
@@ -42614,7 +42805,7 @@ function claudeTranscriptItemId(nativeTurnKey, kind, ordinal) {
42614
42805
 
42615
42806
  // dist/claude-history.js
42616
42807
  var claudeCodeHarnessId = harnessIdSchema.parse("claude-code");
42617
- function isRecord2(value) {
42808
+ function isRecord3(value) {
42618
42809
  return typeof value === "object" && value !== null && !Array.isArray(value);
42619
42810
  }
42620
42811
  function textParts(value) {
@@ -42622,12 +42813,12 @@ function textParts(value) {
42622
42813
  return value.length > 0 ? [value] : [];
42623
42814
  if (!Array.isArray(value))
42624
42815
  return [];
42625
- return value.flatMap((part) => isRecord2(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []);
42816
+ return value.flatMap((part) => isRecord3(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []);
42626
42817
  }
42627
42818
  function thinkingParts(value) {
42628
42819
  if (!Array.isArray(value))
42629
42820
  return [];
42630
- return value.flatMap((part) => isRecord2(part) && part.type === "thinking" && typeof part.thinking === "string" ? [part.thinking] : []);
42821
+ return value.flatMap((part) => isRecord3(part) && part.type === "thinking" && typeof part.thinking === "string" ? [part.thinking] : []);
42631
42822
  }
42632
42823
  var localCommandRecordPattern = /^\s*<(local-command-(?:stdout|caveat))>[\s\S]*<\/\1>\s*$/u;
42633
42824
  var taskNotificationRecordPattern = /^\s*<task-notification>[\s\S]*<\/task-notification>\s*$/u;
@@ -42662,7 +42853,7 @@ function localCommandStdoutText(text) {
42662
42853
  return match[1] ?? "";
42663
42854
  }
42664
42855
  function isTaskNotificationOrigin(value) {
42665
- return isRecord2(value.origin) && value.origin.kind === "task-notification";
42856
+ return isRecord3(value.origin) && value.origin.kind === "task-notification";
42666
42857
  }
42667
42858
  function visibleUserTextParts(message) {
42668
42859
  if (message.type !== "user" || message.syntheticUser)
@@ -42673,24 +42864,24 @@ function visibleUserTextParts(message) {
42673
42864
  return parts.filter((part) => !isLocalCommandRecord(part) && !isTaskNotificationRecord(part));
42674
42865
  }
42675
42866
  function isInterruptionRecord(value, promptId) {
42676
- if (value.type !== "user" || promptId === null || value.promptId !== promptId || value.promptSource !== void 0 || !isRecord2(value.message))
42867
+ if (value.type !== "user" || promptId === null || value.promptId !== promptId || value.promptSource !== void 0 || !isRecord3(value.message))
42677
42868
  return false;
42678
42869
  const content = value.message.content;
42679
42870
  if (!Array.isArray(content) || content.length !== 1)
42680
42871
  return false;
42681
42872
  const part = content[0];
42682
- return isRecord2(part) && part.type === "text" && (part.text === "[Request interrupted by user]" || part.text === "[Request interrupted by user for tool use]");
42873
+ return isRecord3(part) && part.type === "text" && (part.text === "[Request interrupted by user]" || part.text === "[Request interrupted by user for tool use]");
42683
42874
  }
42684
42875
  function conversationMessages(values, sessionId) {
42685
42876
  const messages = [];
42686
42877
  const ids = /* @__PURE__ */ new Set();
42687
42878
  let promptId = null;
42688
42879
  for (const value of values) {
42689
- if (!isRecord2(value))
42880
+ if (!isRecord3(value))
42690
42881
  throw new Error("Claude history contains a malformed message");
42691
42882
  if (value.type === "system")
42692
42883
  continue;
42693
- if (value.type !== "user" && value.type !== "assistant" || typeof value.uuid !== "string" || value.uuid.length === 0 || value.session_id !== sessionId || !isRecord2(value.message) || value.message.role !== value.type) {
42884
+ if (value.type !== "user" && value.type !== "assistant" || typeof value.uuid !== "string" || value.uuid.length === 0 || value.session_id !== sessionId || !isRecord3(value.message) || value.message.role !== value.type) {
42694
42885
  throw new Error("Claude history contains an invalid message identity");
42695
42886
  }
42696
42887
  if (ids.has(value.uuid))
@@ -42822,7 +43013,7 @@ function mapClaudeSnapshot(values, sessionId) {
42822
43013
  let projectedReasoning = false;
42823
43014
  let projectedText = false;
42824
43015
  for (const [blockIndex, block] of content.entries()) {
42825
- if (!isRecord2(block))
43016
+ if (!isRecord3(block))
42826
43017
  continue;
42827
43018
  if (block.type === "thinking" && !projectedReasoning && reasoning.length > 0) {
42828
43019
  items.push({
@@ -42865,7 +43056,7 @@ function mapClaudeSnapshot(values, sessionId) {
42865
43056
  }
42866
43057
  } : { status: "succeeded" };
42867
43058
  const itemId = hostItemIdSchema.parse(`claude-item-v1-${message.uuid}-tool-${blockIndex}`);
42868
- if (block.name === "Bash" && isRecord2(block.input) && typeof block.input.command === "string") {
43059
+ if (block.name === "Bash" && isRecord3(block.input) && typeof block.input.command === "string") {
42869
43060
  items.push({
42870
43061
  item: {
42871
43062
  type: "commandExecution",
@@ -42903,7 +43094,7 @@ function toolResultBlocks(messages) {
42903
43094
  if (message.type !== "user" || !Array.isArray(message.message.content))
42904
43095
  continue;
42905
43096
  for (const block of message.message.content) {
42906
- if (isRecord2(block) && block.type === "tool_result" && typeof block.tool_use_id === "string") {
43097
+ if (isRecord3(block) && block.type === "tool_result" && typeof block.tool_use_id === "string") {
42907
43098
  results.set(block.tool_use_id, block);
42908
43099
  }
42909
43100
  }
@@ -42918,7 +43109,7 @@ function toolResultOutput(block) {
42918
43109
  }
42919
43110
  function resultSubagentId(value, block) {
42920
43111
  const nativeResult = value.tool_use_result;
42921
- if (isRecord2(nativeResult)) {
43112
+ if (isRecord3(nativeResult)) {
42922
43113
  const structured = nativeResult.agentId ?? nativeResult.agent_id ?? nativeResult.task_id;
42923
43114
  if (typeof structured === "string" && structured.length > 0)
42924
43115
  return structured;
@@ -42929,13 +43120,13 @@ function resultSubagentId(value, block) {
42929
43120
  function subagentPrompt(values, nativeSubagentId2) {
42930
43121
  const toolUses = /* @__PURE__ */ new Map();
42931
43122
  for (const value of values) {
42932
- if (!isRecord2(value) || !isRecord2(value.message) || !Array.isArray(value.message.content)) {
43123
+ if (!isRecord3(value) || !isRecord3(value.message) || !Array.isArray(value.message.content)) {
42933
43124
  continue;
42934
43125
  }
42935
43126
  for (const block of value.message.content) {
42936
- if (!isRecord2(block))
43127
+ if (!isRecord3(block))
42937
43128
  continue;
42938
- if (block.type === "tool_use" && typeof block.id === "string" && (block.name === "Agent" || block.name === "Task") && isRecord2(block.input) && typeof block.input.prompt === "string" && block.input.prompt.length > 0) {
43129
+ if (block.type === "tool_use" && typeof block.id === "string" && (block.name === "Agent" || block.name === "Task") && isRecord3(block.input) && typeof block.input.prompt === "string" && block.input.prompt.length > 0) {
42939
43130
  toolUses.set(block.id, block.input.prompt);
42940
43131
  continue;
42941
43132
  }
@@ -42949,7 +43140,7 @@ function subagentPrompt(values, nativeSubagentId2) {
42949
43140
  return void 0;
42950
43141
  }
42951
43142
  function mapClaudeSubagentSnapshot(values, parentSessionId, nativeSubagentId2, parentValues = []) {
42952
- const messages = conversationMessages(values.map((value) => isRecord2(value) ? { ...value, session_id: parentSessionId } : value), parentSessionId);
43143
+ const messages = conversationMessages(values.map((value) => isRecord3(value) ? { ...value, session_id: parentSessionId } : value), parentSessionId);
42953
43144
  const turns = [];
42954
43145
  for (let index = 0; index < messages.length; ) {
42955
43146
  const first = messages[index];
@@ -42976,7 +43167,7 @@ function mapClaudeSubagentSnapshot(values, parentSessionId, nativeSubagentId2, p
42976
43167
  const content = Array.isArray(message.message.content) ? message.message.content : [{ type: "text", text: message.message.content }];
42977
43168
  for (let blockIndex = 0; blockIndex < content.length; blockIndex += 1) {
42978
43169
  const block = content[blockIndex];
42979
- if (!isRecord2(block))
43170
+ if (!isRecord3(block))
42980
43171
  continue;
42981
43172
  const itemId = hostItemIdSchema.parse(`claude-subagent-item-v2-${nativeSubagentId2}-${message.uuid}-${blockIndex}`);
42982
43173
  if (block.type === "thinking" && typeof block.thinking === "string") {
@@ -43013,7 +43204,7 @@ function mapClaudeSubagentSnapshot(values, parentSessionId, nativeSubagentId2, p
43013
43204
  retryable: false
43014
43205
  }
43015
43206
  } : { status: "succeeded" };
43016
- if (block.name === "Bash" && isRecord2(block.input) && typeof block.input.command === "string") {
43207
+ if (block.name === "Bash" && isRecord3(block.input) && typeof block.input.command === "string") {
43017
43208
  items.push({
43018
43209
  item: {
43019
43210
  type: "commandExecution",
@@ -43143,7 +43334,7 @@ async function forkClaudeSession(input) {
43143
43334
  error: error51("protocolError", "Claude Code Session working directory is unavailable", false)
43144
43335
  };
43145
43336
  }
43146
- if (path6.resolve(sourceInfo.cwd) !== input.cwd) {
43337
+ if (path7.resolve(sourceInfo.cwd) !== input.cwd) {
43147
43338
  return {
43148
43339
  ok: false,
43149
43340
  error: error51("unsupported", "Claude Code cannot Fork across working directories", false)
@@ -43243,26 +43434,26 @@ async function forkClaudeSession(input) {
43243
43434
  }
43244
43435
 
43245
43436
  // dist/claude-transcript.js
43246
- import os4 from "node:os";
43247
- import path7 from "node:path";
43248
- import { readFile as readFile3, readdir, stat as stat2 } from "node:fs/promises";
43437
+ import os5 from "node:os";
43438
+ import path8 from "node:path";
43439
+ import { readFile as readFile3, readdir, stat as stat3 } from "node:fs/promises";
43249
43440
  function projectDirectoryName(cwd) {
43250
43441
  return cwd.replace(/[^A-Za-z0-9]/gu, "-");
43251
43442
  }
43252
43443
  function configDirectory(environment) {
43253
- return environment.CLAUDE_CONFIG_DIR ? path7.resolve(environment.CLAUDE_CONFIG_DIR) : path7.join(os4.homedir(), ".claude");
43444
+ return environment.CLAUDE_CONFIG_DIR ? path8.resolve(environment.CLAUDE_CONFIG_DIR) : path8.join(os5.homedir(), ".claude");
43254
43445
  }
43255
43446
  async function existingFile(file2) {
43256
43447
  try {
43257
- return (await stat2(file2)).isFile();
43448
+ return (await stat3(file2)).isFile();
43258
43449
  } catch {
43259
43450
  return false;
43260
43451
  }
43261
43452
  }
43262
43453
  async function findTranscript(input) {
43263
- const projectsDirectory = path7.join(configDirectory(input.environment), "projects");
43454
+ const projectsDirectory = path8.join(configDirectory(input.environment), "projects");
43264
43455
  const name = `${input.sessionId}.jsonl`;
43265
- const expected = path7.join(projectsDirectory, projectDirectoryName(input.cwd), name);
43456
+ const expected = path8.join(projectsDirectory, projectDirectoryName(input.cwd), name);
43266
43457
  if (await existingFile(expected))
43267
43458
  return expected;
43268
43459
  let projects;
@@ -43272,13 +43463,13 @@ async function findTranscript(input) {
43272
43463
  return null;
43273
43464
  }
43274
43465
  for (const project of projects) {
43275
- const candidate = path7.join(projectsDirectory, project, name);
43466
+ const candidate = path8.join(projectsDirectory, project, name);
43276
43467
  if (await existingFile(candidate))
43277
43468
  return candidate;
43278
43469
  }
43279
43470
  return null;
43280
43471
  }
43281
- function isRecord3(value) {
43472
+ function isRecord4(value) {
43282
43473
  return typeof value === "object" && value !== null && !Array.isArray(value);
43283
43474
  }
43284
43475
  async function readClaudeTranscript(input) {
@@ -43296,7 +43487,7 @@ async function readClaudeTranscript(input) {
43296
43487
  } catch {
43297
43488
  continue;
43298
43489
  }
43299
- if (!isRecord3(entry) || entry.type !== "user" && entry.type !== "assistant" || typeof entry.uuid !== "string" || !isRecord3(entry.message)) {
43490
+ if (!isRecord4(entry) || entry.type !== "user" && entry.type !== "assistant" || typeof entry.uuid !== "string" || !isRecord4(entry.message)) {
43300
43491
  continue;
43301
43492
  }
43302
43493
  messages.push({ ...entry, session_id: input.sessionId });
@@ -43563,7 +43754,7 @@ function projectClaudeAccountUsage(usage, account) {
43563
43754
  }
43564
43755
 
43565
43756
  // dist/file-change.js
43566
- import path8 from "node:path";
43757
+ import path9 from "node:path";
43567
43758
  var hunkSchema = external_exports.object({
43568
43759
  oldStart: external_exports.number().int().nonnegative(),
43569
43760
  oldLines: external_exports.number().int().nonnegative(),
@@ -43571,7 +43762,7 @@ var hunkSchema = external_exports.object({
43571
43762
  newLines: external_exports.number().int().nonnegative(),
43572
43763
  lines: external_exports.array(external_exports.string())
43573
43764
  }).strict();
43574
- function isRecord4(value) {
43765
+ function isRecord5(value) {
43575
43766
  return typeof value === "object" && value !== null && !Array.isArray(value);
43576
43767
  }
43577
43768
  function validNativePath(value) {
@@ -43595,7 +43786,7 @@ function validHunk(value) {
43595
43786
  return hunk;
43596
43787
  }
43597
43788
  function parseClaudeNativeFileChange(toolName, value) {
43598
- if (toolName !== "Edit" && toolName !== "Write" || !isRecord4(value))
43789
+ if (toolName !== "Edit" && toolName !== "Write" || !isRecord5(value))
43599
43790
  return null;
43600
43791
  if (!validNativePath(value.filePath) || !Array.isArray(value.structuredPatch))
43601
43792
  return null;
@@ -43611,10 +43802,10 @@ function parseClaudeNativeFileChange(toolName, value) {
43611
43802
  };
43612
43803
  }
43613
43804
  function displayPath(nativePath, cwd) {
43614
- const resolvedCwd = path8.resolve(cwd);
43615
- const resolvedPath = path8.isAbsolute(nativePath) ? path8.resolve(nativePath) : path8.resolve(cwd, nativePath);
43616
- const relative = path8.relative(resolvedCwd, resolvedPath);
43617
- const selected = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path8.sep}`) ? relative : resolvedPath;
43805
+ const resolvedCwd = path9.resolve(cwd);
43806
+ const resolvedPath = path9.isAbsolute(nativePath) ? path9.resolve(nativePath) : path9.resolve(cwd, nativePath);
43807
+ const relative = path9.relative(resolvedCwd, resolvedPath);
43808
+ const selected = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path9.sep}`) ? relative : resolvedPath;
43618
43809
  const normalized = selected.replaceAll("\\", "/");
43619
43810
  return validNativePath(normalized) && normalized !== "." ? normalized : null;
43620
43811
  }
@@ -43626,7 +43817,7 @@ function projectClaudeFileChange(value, cwd) {
43626
43817
  `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`,
43627
43818
  ...hunk.lines
43628
43819
  ]);
43629
- const absoluteDisplayPath = path8.posix.isAbsolute(normalizedPath);
43820
+ const absoluteDisplayPath = path9.posix.isAbsolute(normalizedPath);
43630
43821
  const oldHeader = value.kind === "add" ? "/dev/null" : absoluteDisplayPath ? normalizedPath : `a/${normalizedPath}`;
43631
43822
  const newHeader = absoluteDisplayPath ? normalizedPath : `b/${normalizedPath}`;
43632
43823
  const unifiedDiff = [`--- ${oldHeader}`, `+++ ${newHeader}`, ...body, ""].join("\n");
@@ -43639,7 +43830,7 @@ var AUTHENTICATION_ERRORS = /* @__PURE__ */ new Set(["authentication_failed", "o
43639
43830
  var SUBAGENT_TOOLS = /* @__PURE__ */ new Set(["Agent", "Task", "SendMessage"]);
43640
43831
  var SUBAGENT_DESCRIPTION_LIMIT = 500;
43641
43832
  var SUBAGENT_SUMMARY_LIMIT = 2e3;
43642
- function isRecord5(value) {
43833
+ function isRecord6(value) {
43643
43834
  return typeof value === "object" && value !== null && !Array.isArray(value);
43644
43835
  }
43645
43836
  function nativeUuid(message) {
@@ -43649,12 +43840,12 @@ function parentToolUseId(message) {
43649
43840
  return typeof message.parent_tool_use_id === "string" && message.parent_tool_use_id.length > 0 ? message.parent_tool_use_id : null;
43650
43841
  }
43651
43842
  function assistantNativeMessageId(message) {
43652
- if (!isRecord5(message.message))
43843
+ if (!isRecord6(message.message))
43653
43844
  return null;
43654
43845
  return typeof message.message.id === "string" && message.message.id.length > 0 ? message.message.id : null;
43655
43846
  }
43656
43847
  function assistantContent(message) {
43657
- if (message.type !== "assistant" || !isRecord5(message.message))
43848
+ if (message.type !== "assistant" || !isRecord6(message.message))
43658
43849
  return null;
43659
43850
  return Array.isArray(message.message.content) ? message.message.content : null;
43660
43851
  }
@@ -43662,10 +43853,10 @@ function assistantText(message) {
43662
43853
  const content = assistantContent(message);
43663
43854
  if (!content)
43664
43855
  return null;
43665
- return content.flatMap((block) => isRecord5(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("");
43856
+ return content.flatMap((block) => isRecord6(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("");
43666
43857
  }
43667
43858
  function assistantError(message) {
43668
- return isRecord5(message) && message.type === "assistant" && typeof message.error === "string" ? message.error : null;
43859
+ return isRecord6(message) && message.type === "assistant" && typeof message.error === "string" ? message.error : null;
43669
43860
  }
43670
43861
  function boundedString(value, limit) {
43671
43862
  if (typeof value !== "string")
@@ -43676,25 +43867,25 @@ function boundedString(value, limit) {
43676
43867
  return trimmed.slice(0, limit);
43677
43868
  }
43678
43869
  function subagentDescription(argumentsValue, toolName) {
43679
- if (!isRecord5(argumentsValue))
43870
+ if (!isRecord6(argumentsValue))
43680
43871
  return `${toolName} delegation`;
43681
43872
  return boundedString(argumentsValue.description, SUBAGENT_DESCRIPTION_LIMIT) ?? boundedString(argumentsValue.summary, SUBAGENT_DESCRIPTION_LIMIT) ?? boundedString(argumentsValue.name, SUBAGENT_DESCRIPTION_LIMIT) ?? `${toolName} delegation`;
43682
43873
  }
43683
43874
  function subagentPrompt2(argumentsValue) {
43684
- if (!isRecord5(argumentsValue))
43875
+ if (!isRecord6(argumentsValue))
43685
43876
  return void 0;
43686
43877
  return boundedString(argumentsValue.prompt ?? argumentsValue.message, SUBAGENT_SUMMARY_LIMIT);
43687
43878
  }
43688
43879
  function subagentRole(argumentsValue) {
43689
- if (!isRecord5(argumentsValue))
43880
+ if (!isRecord6(argumentsValue))
43690
43881
  return void 0;
43691
43882
  return boundedString(argumentsValue.subagent_type ?? argumentsValue.agent_type, SUBAGENT_DESCRIPTION_LIMIT);
43692
43883
  }
43693
43884
  function subagentBackground(argumentsValue) {
43694
- return isRecord5(argumentsValue) && argumentsValue.run_in_background === true;
43885
+ return isRecord6(argumentsValue) && argumentsValue.run_in_background === true;
43695
43886
  }
43696
43887
  function targetedSubagentId(argumentsValue) {
43697
- if (!isRecord5(argumentsValue))
43888
+ if (!isRecord6(argumentsValue))
43698
43889
  return void 0;
43699
43890
  return boundedString(argumentsValue.to ?? argumentsValue.recipient ?? argumentsValue.agentId, SUBAGENT_DESCRIPTION_LIMIT);
43700
43891
  }
@@ -43714,11 +43905,11 @@ function finiteNonNegativeNumber(value) {
43714
43905
  return typeof value === "number" && Number.isFinite(value) && value >= 0;
43715
43906
  }
43716
43907
  function parseResultModelUsage(value) {
43717
- if (!isRecord5(value))
43908
+ if (!isRecord6(value))
43718
43909
  return void 0;
43719
43910
  const usage = [];
43720
43911
  for (const entry of Object.values(value)) {
43721
- if (!isRecord5(entry) || !safeNonNegativeInteger(entry.inputTokens) || !safeNonNegativeInteger(entry.outputTokens)) {
43912
+ if (!isRecord6(entry) || !safeNonNegativeInteger(entry.inputTokens) || !safeNonNegativeInteger(entry.outputTokens)) {
43722
43913
  return void 0;
43723
43914
  }
43724
43915
  usage.push({ inputTokens: entry.inputTokens, outputTokens: entry.outputTokens });
@@ -43726,7 +43917,7 @@ function parseResultModelUsage(value) {
43726
43917
  return usage;
43727
43918
  }
43728
43919
  function parseLastRequestUsage(value, attribution = {}) {
43729
- if (!isRecord5(value))
43920
+ if (!isRecord6(value))
43730
43921
  return void 0;
43731
43922
  const inputTokens = value.input_tokens;
43732
43923
  const outputTokens = value.output_tokens;
@@ -43749,7 +43940,7 @@ function parseLastRequestUsage(value, attribution = {}) {
43749
43940
  };
43750
43941
  }
43751
43942
  function assistantRequestUsage(message, provider) {
43752
- if (!isRecord5(message.message))
43943
+ if (!isRecord6(message.message))
43753
43944
  return void 0;
43754
43945
  return parseLastRequestUsage(message.message.usage, {
43755
43946
  requestId: message.message.id ?? message.request_id,
@@ -43772,7 +43963,7 @@ function parseResultUsageEvent(message) {
43772
43963
  };
43773
43964
  }
43774
43965
  function parsePlanLimitWindow(value) {
43775
- if (!isRecord5(value))
43966
+ if (!isRecord6(value))
43776
43967
  return void 0;
43777
43968
  const utilization = value.utilization;
43778
43969
  if (typeof utilization !== "number" || !Number.isFinite(utilization) || utilization < 0) {
@@ -43784,12 +43975,12 @@ function parsePlanLimitWindow(value) {
43784
43975
  return { utilizationPercent, ...resetsAtUnix !== void 0 ? { resetsAtUnix } : {} };
43785
43976
  }
43786
43977
  function parseClaudePlanLimitEvent(message) {
43787
- if (!isRecord5(message) || message.type !== "rate_limit_event")
43978
+ if (!isRecord6(message) || message.type !== "rate_limit_event")
43788
43979
  return null;
43789
43980
  const info = message.rate_limit_info;
43790
- if (!isRecord5(info))
43981
+ if (!isRecord6(info))
43791
43982
  return null;
43792
- const windows = isRecord5(info.unifiedWindows) ? info.unifiedWindows : void 0;
43983
+ const windows = isRecord6(info.unifiedWindows) ? info.unifiedWindows : void 0;
43793
43984
  let fiveHour = parsePlanLimitWindow(windows?.five_hour);
43794
43985
  let sevenDay = parsePlanLimitWindow(windows?.seven_day);
43795
43986
  if (!fiveHour && !sevenDay) {
@@ -43807,7 +43998,7 @@ function parseClaudePlanLimitEvent(message) {
43807
43998
  };
43808
43999
  }
43809
44000
  function nativeSubagentId(nativeResult, outputText) {
43810
- if (isRecord5(nativeResult)) {
44001
+ if (isRecord6(nativeResult)) {
43811
44002
  const structured = boundedString(nativeResult.agentId ?? nativeResult.agent_id ?? nativeResult.task_id, SUBAGENT_DESCRIPTION_LIMIT);
43812
44003
  if (structured)
43813
44004
  return structured;
@@ -43815,7 +44006,7 @@ function nativeSubagentId(nativeResult, outputText) {
43815
44006
  return boundedString(/agentId:\s*([A-Za-z0-9_-]+)/u.exec(outputText ?? "")?.[1], SUBAGENT_DESCRIPTION_LIMIT);
43816
44007
  }
43817
44008
  function subagentContinuesInBackground(nativeResult, outputText) {
43818
- if (isRecord5(nativeResult)) {
44009
+ if (isRecord6(nativeResult)) {
43819
44010
  if (nativeResult.isAsync === true || nativeResult.is_async === true)
43820
44011
  return true;
43821
44012
  if (nativeResult.status === "async_launched")
@@ -43828,11 +44019,11 @@ function resultText(content, nativeResult) {
43828
44019
  if (typeof content === "string") {
43829
44020
  text = content;
43830
44021
  } else if (Array.isArray(content)) {
43831
- text = content.flatMap((block) => isRecord5(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("");
44022
+ text = content.flatMap((block) => isRecord6(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("");
43832
44023
  }
43833
44024
  if (text.length > 0)
43834
44025
  return text;
43835
- if (!isRecord5(nativeResult))
44026
+ if (!isRecord6(nativeResult))
43836
44027
  return void 0;
43837
44028
  const stdout = typeof nativeResult.stdout === "string" ? nativeResult.stdout : "";
43838
44029
  const stderr = typeof nativeResult.stderr === "string" ? nativeResult.stderr : "";
@@ -43844,13 +44035,13 @@ function userMessageText(content) {
43844
44035
  return content;
43845
44036
  if (!Array.isArray(content))
43846
44037
  return null;
43847
- const text = content.flatMap((block) => isRecord5(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("");
44038
+ const text = content.flatMap((block) => isRecord6(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("");
43848
44039
  return text.length > 0 ? text : null;
43849
44040
  }
43850
44041
  function parseClaudeTaskNotification(message) {
43851
- if (!isRecord5(message) || message.type !== "user" || !isRecord5(message.message))
44042
+ if (!isRecord6(message) || message.type !== "user" || !isRecord6(message.message))
43852
44043
  return null;
43853
- if (isRecord5(message.origin) && message.origin.kind !== "task-notification")
44044
+ if (isRecord6(message.origin) && message.origin.kind !== "task-notification")
43854
44045
  return null;
43855
44046
  const content = userMessageText(message.message.content);
43856
44047
  if (!content || !content.includes("<task-notification>"))
@@ -43909,7 +44100,7 @@ var ClaudeNativeTurnAccumulator = class {
43909
44100
  this.#cancelRequested = true;
43910
44101
  }
43911
44102
  consume(message) {
43912
- if (this.#completed || !isRecord5(message))
44103
+ if (this.#completed || !isRecord6(message))
43913
44104
  return { events: [] };
43914
44105
  const events = [];
43915
44106
  this.#consumeSegmentLevel(message, events);
@@ -43923,7 +44114,7 @@ var ClaudeNativeTurnAccumulator = class {
43923
44114
  this.#consumeCompaction(message, events);
43924
44115
  this.#consumeLocalCommandOutput(message, events);
43925
44116
  }
43926
- if (message.type === "stream_event" && isRecord5(message.event)) {
44117
+ if (message.type === "stream_event" && isRecord6(message.event)) {
43927
44118
  if (!nested)
43928
44119
  this.#consumeStreamEvent(message, events);
43929
44120
  } else if (message.type === "tool_progress") {
@@ -44030,7 +44221,7 @@ var ClaudeNativeTurnAccumulator = class {
44030
44221
  if (message.subtype !== "background_tasks_changed" || !Array.isArray(message.tasks))
44031
44222
  return;
44032
44223
  const nativeSubagentIds = message.tasks.flatMap((task) => {
44033
- if (!isRecord5(task))
44224
+ if (!isRecord6(task))
44034
44225
  return [];
44035
44226
  const taskId = boundedString(task.task_id, SUBAGENT_DESCRIPTION_LIMIT);
44036
44227
  return taskId ? [taskId] : [];
@@ -44090,7 +44281,7 @@ var ClaudeNativeTurnAccumulator = class {
44090
44281
  });
44091
44282
  return;
44092
44283
  }
44093
- if (message.subtype === "task_updated" && isRecord5(message.patch)) {
44284
+ if (message.subtype === "task_updated" && isRecord6(message.patch)) {
44094
44285
  const status = taskStatus(message.patch.status);
44095
44286
  if (!status)
44096
44287
  return;
@@ -44109,14 +44300,14 @@ var ClaudeNativeTurnAccumulator = class {
44109
44300
  }
44110
44301
  #consumeStreamEvent(message, events) {
44111
44302
  const event = message.event;
44112
- if (!isRecord5(event))
44303
+ if (!isRecord6(event))
44113
44304
  return;
44114
- if (event.type === "message_start" && isRecord5(event.message) && typeof event.message.id === "string" && event.message.id.length > 0) {
44305
+ if (event.type === "message_start" && isRecord6(event.message) && typeof event.message.id === "string" && event.message.id.length > 0) {
44115
44306
  this.#activeRootStreamMessageId = event.message.id;
44116
44307
  this.#messageState(event.message.id);
44117
44308
  return;
44118
44309
  }
44119
- if (event.type !== "content_block_delta" || !isRecord5(event.delta))
44310
+ if (event.type !== "content_block_delta" || !isRecord6(event.delta))
44120
44311
  return;
44121
44312
  const messageId = this.#activeRootStreamMessageId ?? nativeUuid(message) ?? this.#nextMessageId();
44122
44313
  if (!this.#activeRootStreamMessageId)
@@ -44192,7 +44383,7 @@ var ClaudeNativeTurnAccumulator = class {
44192
44383
  }
44193
44384
  #consumeToolUseBlocks(message, events, ignoreKnownIds) {
44194
44385
  for (const block of assistantContent(message) ?? []) {
44195
- if (!isRecord5(block) || block.type !== "tool_use")
44386
+ if (!isRecord6(block) || block.type !== "tool_use")
44196
44387
  continue;
44197
44388
  const argumentsResult = jsonValueSchema.safeParse(block.input);
44198
44389
  if (typeof block.id !== "string" || block.id.length === 0 || typeof block.name !== "string" || block.name.length === 0 || !argumentsResult.success) {
@@ -44244,9 +44435,9 @@ var ClaudeNativeTurnAccumulator = class {
44244
44435
  events.push(settled);
44245
44436
  }
44246
44437
  #consumeToolResults(message, events, ignoreUnknown) {
44247
- if (!isRecord5(message.message) || !Array.isArray(message.message.content))
44438
+ if (!isRecord6(message.message) || !Array.isArray(message.message.content))
44248
44439
  return;
44249
- const resultBlocks = message.message.content.filter((block) => isRecord5(block) && block.type === "tool_result");
44440
+ const resultBlocks = message.message.content.filter((block) => isRecord6(block) && block.type === "tool_result");
44250
44441
  if (resultBlocks.length === 0)
44251
44442
  return;
44252
44443
  if (resultBlocks.length > 1 && message.tool_use_result !== void 0) {
@@ -44315,7 +44506,7 @@ var ClaudeNativeTurnAccumulator = class {
44315
44506
 
44316
44507
  // dist/process-fence.js
44317
44508
  import { execFile } from "node:child_process";
44318
- import path9 from "node:path";
44509
+ import path10 from "node:path";
44319
44510
  import { setTimeout as setTimeout2 } from "node:timers/promises";
44320
44511
  import { promisify } from "node:util";
44321
44512
  var executeFile = promisify(execFile);
@@ -44339,9 +44530,9 @@ async function closeClaudeProcessGroup(child, timeoutMs) {
44339
44530
  if (child.exitCode !== null || child.signalCode !== null)
44340
44531
  throw new Error("Claude process tree cannot be confirmed after its Windows root exited");
44341
44532
  const root = process.env.SystemRoot ?? process.env.SYSTEMROOT;
44342
- if (!root || !path9.win32.isAbsolute(root))
44533
+ if (!root || !path10.win32.isAbsolute(root))
44343
44534
  throw new Error("Windows SystemRoot is unavailable");
44344
- await executeFile(path9.win32.join(root, "System32", "taskkill.exe"), ["/PID", String(pid), "/T", "/F"], {
44535
+ await executeFile(path10.win32.join(root, "System32", "taskkill.exe"), ["/PID", String(pid), "/T", "/F"], {
44345
44536
  timeout: timeoutMs,
44346
44537
  windowsHide: true
44347
44538
  });
@@ -44368,6 +44559,7 @@ async function closeClaudeProcessGroup(child, timeoutMs) {
44368
44559
 
44369
44560
  // dist/sdk-transport.js
44370
44561
  var CLIENT_APP = "codexhost-claude-code-adapter/0.0.0";
44562
+ var SESSION_ENTRYPOINT = "codexhost-sdk";
44371
44563
  var APPROVAL_TITLE_MAX_LENGTH = 120;
44372
44564
  var APPROVAL_DESCRIPTION_MAX_LENGTH = 500;
44373
44565
  var DEFAULT_ABORT_TIMEOUT_MS = 2e3;
@@ -44427,17 +44619,17 @@ function allowsDangerouslySkipPermissions(getuid = process.getuid) {
44427
44619
  function processExited(child) {
44428
44620
  return child.exitCode !== null || child.signalCode !== null;
44429
44621
  }
44430
- function isRecord6(value) {
44622
+ function isRecord7(value) {
44431
44623
  return typeof value === "object" && value !== null && !Array.isArray(value);
44432
44624
  }
44433
44625
  function permissionModeFromMessage(value) {
44434
- if (!isRecord6(value) || value.type !== "system" || value.subtype !== "init" && value.subtype !== "status" || !("permissionMode" in value) || value.permissionMode === void 0) {
44626
+ if (!isRecord7(value) || value.type !== "system" || value.subtype !== "init" && value.subtype !== "status" || !("permissionMode" in value) || value.permissionMode === void 0) {
44435
44627
  return void 0;
44436
44628
  }
44437
44629
  return isClaudePermissionMode(value.permissionMode) ? value.permissionMode : void 0;
44438
44630
  }
44439
44631
  function parseContextUsage(value) {
44440
- if (!isRecord6(value))
44632
+ if (!isRecord7(value))
44441
44633
  throw new Error("Claude SDK context Usage is invalid");
44442
44634
  const usedTokens = value.totalTokens;
44443
44635
  const maxTokens = value.maxTokens;
@@ -44454,7 +44646,7 @@ function parseQuestions(input) {
44454
44646
  const questions = [];
44455
44647
  const questionTexts = /* @__PURE__ */ new Set();
44456
44648
  for (const value of input.questions) {
44457
- if (!isRecord6(value))
44649
+ if (!isRecord7(value))
44458
44650
  return null;
44459
44651
  const question = value.question;
44460
44652
  const header = value.header;
@@ -44465,7 +44657,7 @@ function parseQuestions(input) {
44465
44657
  const labels = /* @__PURE__ */ new Set();
44466
44658
  const options = [];
44467
44659
  for (const option2 of value.options) {
44468
- if (!isRecord6(option2) || typeof option2.label !== "string" || option2.label.length === 0 || labels.has(option2.label) || typeof option2.description !== "string") {
44660
+ if (!isRecord7(option2) || typeof option2.label !== "string" || option2.label.length === 0 || labels.has(option2.label) || typeof option2.description !== "string") {
44469
44661
  return null;
44470
44662
  }
44471
44663
  labels.add(option2.label);
@@ -44507,7 +44699,7 @@ function permissionUpdateDestination(value) {
44507
44699
  return void 0;
44508
44700
  }
44509
44701
  function isPermissionUpdate(value) {
44510
- if (!isRecord6(value) || !permissionUpdateDestination(value.destination))
44702
+ if (!isRecord7(value) || !permissionUpdateDestination(value.destination))
44511
44703
  return false;
44512
44704
  if (value.type === "setMode") {
44513
44705
  return typeof value.mode === "string" && PERMISSION_MODES.has(value.mode);
@@ -44516,7 +44708,7 @@ function isPermissionUpdate(value) {
44516
44708
  return Array.isArray(value.directories) && value.directories.every((directory) => typeof directory === "string");
44517
44709
  }
44518
44710
  if (value.type === "addRules" || value.type === "replaceRules" || value.type === "removeRules") {
44519
- return typeof value.behavior === "string" && PERMISSION_BEHAVIORS.has(value.behavior) && Array.isArray(value.rules) && value.rules.every((rule) => isRecord6(rule) && typeof rule.toolName === "string" && (rule.ruleContent === void 0 || typeof rule.ruleContent === "string"));
44711
+ return typeof value.behavior === "string" && PERMISSION_BEHAVIORS.has(value.behavior) && Array.isArray(value.rules) && value.rules.every((rule) => isRecord7(rule) && typeof rule.toolName === "string" && (rule.ruleContent === void 0 || typeof rule.ruleContent === "string"));
44520
44712
  }
44521
44713
  return false;
44522
44714
  }
@@ -44661,6 +44853,7 @@ var ClaudeSdkTransport = class {
44661
44853
  forwardSubagentText: true,
44662
44854
  env: withNodeRuntimeOnPath({
44663
44855
  ...this.#environment,
44856
+ CLAUDE_CODE_ENTRYPOINT: SESSION_ENTRYPOINT,
44664
44857
  CLAUDE_AGENT_SDK_CLIENT_APP: CLIENT_APP
44665
44858
  }),
44666
44859
  spawnClaudeCodeProcess: (options) => this.#spawn(options)
@@ -44954,10 +45147,10 @@ var ClaudeSdkTransport = class {
44954
45147
  }
44955
45148
  }
44956
45149
  #observeBackgroundTasks(message) {
44957
- if (!isRecord6(message) || message.type !== "system")
45150
+ if (!isRecord7(message) || message.type !== "system")
44958
45151
  return;
44959
45152
  if (message.subtype === "background_tasks_changed" && Array.isArray(message.tasks)) {
44960
- this.#backgroundTasks = new Set(message.tasks.flatMap((task) => isRecord6(task) && typeof task.task_id === "string" ? [task.task_id] : []));
45153
+ this.#backgroundTasks = new Set(message.tasks.flatMap((task) => isRecord7(task) && typeof task.task_id === "string" ? [task.task_id] : []));
44961
45154
  } else if (message.subtype === "task_started" && typeof message.task_id === "string") {
44962
45155
  this.#backgroundTasks.add(message.task_id);
44963
45156
  } else if (message.subtype === "task_notification" && typeof message.task_id === "string" && ["completed", "failed", "stopped"].includes(String(message.status))) {
@@ -45006,7 +45199,7 @@ var ClaudeSdkTransport = class {
45006
45199
  events: [],
45007
45200
  nativeTurnKey: null
45008
45201
  });
45009
- if (autonomous.nativeTurnKey === null && isRecord6(message) && message.type === "user" && (message.parent_tool_use_id === null || message.parent_tool_use_id === void 0) && typeof message.uuid === "string" && message.uuid.length > 0) {
45202
+ if (autonomous.nativeTurnKey === null && isRecord7(message) && message.type === "user" && (message.parent_tool_use_id === null || message.parent_tool_use_id === void 0) && typeof message.uuid === "string" && message.uuid.length > 0) {
45010
45203
  autonomous.nativeTurnKey = message.uuid;
45011
45204
  }
45012
45205
  const interpreted = autonomous.accumulator.consume(message);
@@ -45348,11 +45541,11 @@ var ClaudeSubagentLifecycle = class {
45348
45541
  };
45349
45542
 
45350
45543
  // dist/task-tracker.js
45351
- function isRecord7(value) {
45544
+ function isRecord8(value) {
45352
45545
  return typeof value === "object" && value !== null && !Array.isArray(value);
45353
45546
  }
45354
45547
  function stringField(value, keys) {
45355
- if (!isRecord7(value))
45548
+ if (!isRecord8(value))
45356
45549
  return void 0;
45357
45550
  for (const key of keys) {
45358
45551
  const field = value[key];
@@ -45387,7 +45580,7 @@ var ClaudeTaskTracker = class {
45387
45580
  };
45388
45581
  }
45389
45582
  #create(args, result) {
45390
- if (!isRecord7(result) || !isRecord7(result.task))
45583
+ if (!isRecord8(result) || !isRecord8(result.task))
45391
45584
  return;
45392
45585
  const id = stringField(result.task, ["id"]);
45393
45586
  const subject = stringField(args, ["subject"]) ?? stringField(result.task, ["subject"]);
@@ -45405,7 +45598,7 @@ var ClaudeTaskTracker = class {
45405
45598
  const id = stringField(args, ["taskId", "id", "task_id"]);
45406
45599
  if (!id)
45407
45600
  return;
45408
- const status = isRecord7(args) ? taskStatus2(args.status) : void 0;
45601
+ const status = isRecord8(args) ? taskStatus2(args.status) : void 0;
45409
45602
  if (status === "deleted") {
45410
45603
  this.#tasks.delete(id);
45411
45604
  return;
@@ -45423,13 +45616,13 @@ var ClaudeTaskTracker = class {
45423
45616
  });
45424
45617
  }
45425
45618
  #replace(result) {
45426
- if (!isRecord7(result) || !Array.isArray(result.tasks))
45619
+ if (!isRecord8(result) || !Array.isArray(result.tasks))
45427
45620
  return;
45428
45621
  const next = /* @__PURE__ */ new Map();
45429
45622
  for (const value of result.tasks) {
45430
45623
  const id = stringField(value, ["id"]);
45431
45624
  const subject = stringField(value, ["subject"]);
45432
- const status = isRecord7(value) ? taskStatus2(value.status) : void 0;
45625
+ const status = isRecord8(value) ? taskStatus2(value.status) : void 0;
45433
45626
  if (!id || !subject || !status || status === "deleted")
45434
45627
  continue;
45435
45628
  const existing = this.#tasks.get(id);
@@ -45447,11 +45640,11 @@ var ClaudeTaskTracker = class {
45447
45640
  };
45448
45641
 
45449
45642
  // dist/tool-lifecycle.js
45450
- function isRecord8(value) {
45643
+ function isRecord9(value) {
45451
45644
  return typeof value === "object" && value !== null && !Array.isArray(value);
45452
45645
  }
45453
45646
  function stringField2(value, key) {
45454
- return isRecord8(value) && typeof value[key] === "string" ? value[key] : void 0;
45647
+ return isRecord9(value) && typeof value[key] === "string" ? value[key] : void 0;
45455
45648
  }
45456
45649
  function toolFailure(toolName) {
45457
45650
  return {
@@ -45552,6 +45745,7 @@ var ClaudeToolLifecycle = class {
45552
45745
  const fileItem = {
45553
45746
  type: "fileChange",
45554
45747
  itemId: this.#newItemId(),
45748
+ sourceItemIds: [tool.item.itemId],
45555
45749
  changes: [change]
45556
45750
  };
45557
45751
  this.#emit({ type: "item.started", turnId, item: fileItem });
@@ -45698,7 +45892,7 @@ var CONTEXT_USAGE_TTL_MS = 1e4;
45698
45892
  var CONTEXT_USAGE_FAILURE_COOLDOWN_MS = 5e3;
45699
45893
  var REQUEST_USAGE_RETRY_DELAYS_MS = [0, 100, 250, 500, 1e3];
45700
45894
  var DEFAULT_CONTINUATION_QUIESCENCE_MS = 2e3;
45701
- function isRecord9(value) {
45895
+ function isRecord10(value) {
45702
45896
  return typeof value === "object" && value !== null && !Array.isArray(value);
45703
45897
  }
45704
45898
  function safeNonNegativeInteger2(value) {
@@ -45707,7 +45901,7 @@ function safeNonNegativeInteger2(value) {
45707
45901
  function transcriptRequestUsage(messages, messageId) {
45708
45902
  for (let index = messages.length - 1; index >= 0; index -= 1) {
45709
45903
  const entry = messages[index];
45710
- if (!isRecord9(entry) || entry.type !== "assistant" || entry.parent_tool_use_id !== null && entry.parent_tool_use_id !== void 0 || !isRecord9(entry.message) || entry.message.id !== messageId || !isRecord9(entry.message.usage)) {
45904
+ if (!isRecord10(entry) || entry.type !== "assistant" || entry.parent_tool_use_id !== null && entry.parent_tool_use_id !== void 0 || !isRecord10(entry.message) || entry.message.id !== messageId || !isRecord10(entry.message.usage)) {
45711
45905
  continue;
45712
45906
  }
45713
45907
  const inputTokens = entry.message.usage.input_tokens;
@@ -45959,7 +46153,7 @@ var ClaudeHarnessSession = class {
45959
46153
  cwd: this.#cwd,
45960
46154
  sessionId: this.#sessionId
45961
46155
  });
45962
- const ids = new Set(messages.flatMap((message) => isRecord9(message) && typeof message.uuid === "string" ? [message.uuid] : []));
46156
+ const ids = new Set(messages.flatMap((message) => isRecord10(message) && typeof message.uuid === "string" ? [message.uuid] : []));
45963
46157
  if (this.#unpersistedMessageIds.every((id) => ids.has(id))) {
45964
46158
  this.#unpersistedMessageIds = [];
45965
46159
  break;
@@ -46272,7 +46466,7 @@ var ClaudeHarnessSession = class {
46272
46466
  return this.#closePromise;
46273
46467
  }
46274
46468
  async #selectModel(command) {
46275
- if (this.#acceptingTurn || this.#active || this.#configurationTask || this.#readingHistory) {
46469
+ if (this.#acceptingTurn || this.#configurationTask || this.#readingHistory) {
46276
46470
  return {
46277
46471
  ok: false,
46278
46472
  error: {
@@ -46330,7 +46524,7 @@ var ClaudeHarnessSession = class {
46330
46524
  }
46331
46525
  }
46332
46526
  async #selectThinking(command) {
46333
- if (this.#acceptingTurn || this.#active || this.#configurationTask || this.#readingHistory) {
46527
+ if (this.#acceptingTurn || this.#configurationTask || this.#readingHistory) {
46334
46528
  return {
46335
46529
  ok: false,
46336
46530
  error: {
@@ -47552,6 +47746,25 @@ var ClaudeHarnessSession = class {
47552
47746
  var ClaudeCodeAdapter = class {
47553
47747
  commandCatalog = claudeCommandCatalog;
47554
47748
  harnessId = claudeCodeHarnessId2;
47749
+ sessionImport = Object.freeze({
47750
+ listCandidates: async () => {
47751
+ const result = await this.#readImport((signal) => this.#importIndex.list(signal));
47752
+ return result.ok ? { ok: true, value: result.value.map(({ candidate }) => candidate) } : result;
47753
+ },
47754
+ resolveCandidate: async (nativeSessionId) => {
47755
+ const result = await this.#readImport((signal) => this.#importIndex.resolve(nativeSessionId, signal));
47756
+ if (!result.ok)
47757
+ return result;
47758
+ return result.value ? { ok: true, value: result.value } : {
47759
+ ok: false,
47760
+ error: {
47761
+ code: "sessionNotFound",
47762
+ message: "Claude Code Session is no longer importable",
47763
+ retryable: false
47764
+ }
47765
+ };
47766
+ }
47767
+ });
47555
47768
  subagents = {
47556
47769
  readSnapshot: async (input) => {
47557
47770
  if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
@@ -47595,6 +47808,9 @@ var ClaudeCodeAdapter = class {
47595
47808
  #cancelTimeoutMs;
47596
47809
  #closeTimeoutMs;
47597
47810
  #dependencies;
47811
+ #importAbort = new AbortController();
47812
+ #importIndex;
47813
+ #importRequests = /* @__PURE__ */ new Set();
47598
47814
  #pendingSessions;
47599
47815
  #toolOutputLimit;
47600
47816
  #continuationQuiescenceMs;
@@ -47606,7 +47822,9 @@ var ClaudeCodeAdapter = class {
47606
47822
  #latestPlanLimit = null;
47607
47823
  #accountInspection = null;
47608
47824
  constructor(options = {}, dependencies) {
47609
- this.#pendingSessions = new ClaudePendingSessions(options.environment ?? process.env);
47825
+ const environment = options.environment ?? process.env;
47826
+ this.#importIndex = new ClaudeSessionImportIndex(environment);
47827
+ this.#pendingSessions = new ClaudePendingSessions(environment);
47610
47828
  this.#closeTimeoutMs = options.closeTimeoutMs ?? DEFAULT_CLOSE_TIMEOUT_MS;
47611
47829
  this.#cancelTimeoutMs = options.cancelTimeoutMs ?? DEFAULT_CANCEL_TIMEOUT_MS;
47612
47830
  if (!Number.isSafeInteger(this.#cancelTimeoutMs) || this.#cancelTimeoutMs <= 0) {
@@ -47660,6 +47878,24 @@ var ClaudeCodeAdapter = class {
47660
47878
  readSubagentMessages: ({ cwd, sessionId, nativeSubagentId: nativeSubagentId2 }) => jkt(sessionId, nativeSubagentId2, { dir: cwd })
47661
47879
  };
47662
47880
  }
47881
+ #readImport(operation) {
47882
+ if (this.#importAbort.signal.aborted) {
47883
+ return Promise.resolve({
47884
+ ok: false,
47885
+ error: invalidState("Claude Code Adapter is closed")
47886
+ });
47887
+ }
47888
+ const request = operation(this.#importAbort.signal).then((value) => ({ ok: true, value })).catch(() => ({
47889
+ ok: false,
47890
+ error: {
47891
+ code: "unavailable",
47892
+ message: "Claude Code Session discovery failed; check storage access and duplicate Session identities, then retry after closing native clients",
47893
+ retryable: true
47894
+ }
47895
+ })).finally(() => this.#importRequests.delete(request));
47896
+ this.#importRequests.add(request);
47897
+ return request;
47898
+ }
47663
47899
  async inspect(input = {}) {
47664
47900
  if (this.#closePromise) {
47665
47901
  return {
@@ -47667,7 +47903,7 @@ var ClaudeCodeAdapter = class {
47667
47903
  error: invalidState("Claude Code Adapter is closing")
47668
47904
  };
47669
47905
  }
47670
- const cwd = path10.resolve(input.cwd ?? process.cwd());
47906
+ const cwd = path11.resolve(input.cwd ?? process.cwd());
47671
47907
  if (!input.refresh) {
47672
47908
  const cached2 = this.#inspectionCache.get(cwd);
47673
47909
  if (cached2)
@@ -47848,7 +48084,7 @@ var ClaudeCodeAdapter = class {
47848
48084
  }
47849
48085
  };
47850
48086
  }
47851
- const cwd = path10.resolve(input.cwd);
48087
+ const cwd = path11.resolve(input.cwd);
47852
48088
  if (input.kind === "rollbackLastTurn") {
47853
48089
  for (const source of this.#sessions) {
47854
48090
  const ready = await source.prepareRollback(input.sourceRef.nativeSessionId);
@@ -47957,8 +48193,10 @@ var ClaudeCodeAdapter = class {
47957
48193
  }
47958
48194
  close() {
47959
48195
  if (!this.#closePromise) {
48196
+ this.#importAbort.abort();
47960
48197
  this.#inspectionCache.clear();
47961
48198
  this.#closePromise = Promise.all([
48199
+ ...this.#importRequests,
47962
48200
  ...[...this.#inspectors].map((inspector) => inspector.close()),
47963
48201
  ...[...this.#sessions].map((session) => session.close()),
47964
48202
  ...this.#inspectionInFlight.values()
@@ -47969,8 +48207,8 @@ var ClaudeCodeAdapter = class {
47969
48207
  };
47970
48208
 
47971
48209
  // dist/user-shell-environment.js
47972
- import path11 from "node:path";
47973
- import { spawnSync } from "node:child_process";
48210
+ import path12 from "node:path";
48211
+ import { execFile as execFile2 } from "node:child_process";
47974
48212
  var ENVIRONMENT_MARKER = Buffer.from("\0CODEXHOST_USER_SHELL_ENV_V1\0");
47975
48213
  var ENVIRONMENT_COMMAND = "printf '\\0CODEXHOST_USER_SHELL_ENV_V1\\0'; /usr/bin/env -0";
47976
48214
  var SHELL_ENVIRONMENT_TIMEOUT_MS = 3e3;
@@ -48007,24 +48245,27 @@ function mergeMissingEnvironment(environment, shellEnvironment) {
48007
48245
  }
48008
48246
  return merged;
48009
48247
  }
48010
- function withUserShellEnvironment(environment, dependencies) {
48248
+ async function withUserShellEnvironment(environment, dependencies) {
48011
48249
  const platform = dependencies?.platform ?? process.platform;
48012
48250
  if (platform === "win32" || !environment.HOME)
48013
48251
  return environment;
48014
48252
  const shell = environment.SHELL?.trim() || defaultShell(platform);
48015
- if (!shell || !SUPPORTED_SHELLS.has(path11.basename(shell)))
48253
+ if (!shell || !SUPPORTED_SHELLS.has(path12.basename(shell)))
48016
48254
  return environment;
48017
48255
  const cacheKey = `${platform}\0${shell}\0${environment.HOME}`;
48018
48256
  const cached2 = dependencies ? void 0 : shellEnvironmentCache.get(cacheKey);
48019
48257
  if (cached2)
48020
48258
  return mergeMissingEnvironment(environment, cached2);
48021
- const run = dependencies?.run ?? ((command, arguments_, options) => spawnSync(command, arguments_, {
48022
- ...options,
48023
- encoding: "buffer",
48024
- stdio: ["ignore", "pipe", "ignore"]
48259
+ const run = dependencies?.run ?? ((command, arguments_, options) => new Promise((resolve2) => {
48260
+ const child = execFile2(command, arguments_, {
48261
+ ...options,
48262
+ encoding: "buffer",
48263
+ killSignal: "SIGKILL"
48264
+ }, (error52, stdout) => resolve2({ status: error52 ? 1 : 0, stdout }));
48265
+ child.stdin?.end();
48025
48266
  }));
48026
48267
  try {
48027
- const result = run(shell, ["-ilc", ENVIRONMENT_COMMAND], {
48268
+ const result = await run(shell, ["-ilc", ENVIRONMENT_COMMAND], {
48028
48269
  env: environment,
48029
48270
  maxBuffer: SHELL_ENVIRONMENT_MAX_BYTES,
48030
48271
  timeout: SHELL_ENVIRONMENT_TIMEOUT_MS,
@@ -48043,8 +48284,8 @@ function withUserShellEnvironment(environment, dependencies) {
48043
48284
 
48044
48285
  // dist/plugin.js
48045
48286
  var CLAUDE_CODE_COMMAND_ENV = "CODEXHOST_CLAUDE_COMMAND";
48046
- function createHarnessAdapter(context) {
48047
- const environment = withUserShellEnvironment({ ...context.environment });
48287
+ async function createHarnessAdapter(context) {
48288
+ const environment = await withUserShellEnvironment({ ...context.environment });
48048
48289
  if (context.platform === "darwin" && context.managedRemoteHost) {
48049
48290
  return new BrokeredHarnessAdapter({
48050
48291
  commandCatalog: claudeCommandCatalog,