@liberseek/boft-cli-win32-arm64 0.6.2 → 0.6.4

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.
@@ -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, path11) {
780
- if (!path11)
779
+ function getElementAtPath(obj, path12) {
780
+ if (!path12)
781
781
  return obj;
782
- return path11.reduce((acc, key) => acc?.[key], obj);
782
+ return path12.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(path11, issues) {
1191
+ function prefixIssues(path12, issues) {
1192
1192
  return issues.map((iss) => {
1193
1193
  var _a4;
1194
1194
  (_a4 = iss).path ?? (_a4.path = []);
1195
- iss.path.unshift(path11);
1195
+ iss.path.unshift(path12);
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, path11 = []) => {
1342
+ const processError = (error53, path12 = []) => {
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 }, [...path11, ...issue2.path]));
1345
+ issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
1346
1346
  } else if (issue2.code === "invalid_key") {
1347
- processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1347
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1348
1348
  } else if (issue2.code === "invalid_element") {
1349
- processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1349
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1350
1350
  } else {
1351
- const fullpath = [...path11, ...issue2.path];
1351
+ const fullpath = [...path12, ...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, path11 = []) => {
1378
+ const processError = (error53, path12 = []) => {
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 }, [...path11, ...issue2.path]));
1382
+ issue2.errors.map((issues) => processError({ issues }, [...path12, ...issue2.path]));
1383
1383
  } else if (issue2.code === "invalid_key") {
1384
- processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1384
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1385
1385
  } else if (issue2.code === "invalid_element") {
1386
- processError({ issues: issue2.issues }, [...path11, ...issue2.path]);
1386
+ processError({ issues: issue2.issues }, [...path12, ...issue2.path]);
1387
1387
  } else {
1388
- const fullpath = [...path11, ...issue2.path];
1388
+ const fullpath = [...path12, ...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 path11 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
- for (const seg of path11) {
1420
+ const path12 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1421
+ for (const seg of path12) {
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 path11 = ref.slice(1).split("/").filter(Boolean);
14114
- if (path11.length === 0) {
14113
+ const path12 = ref.slice(1).split("/").filter(Boolean);
14114
+ if (path12.length === 0) {
14115
14115
  return ctx.rootSchema;
14116
14116
  }
14117
14117
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14118
- if (path11[0] === defsKey) {
14119
- const key = path11[1];
14118
+ if (path12[0] === defsKey) {
14119
+ const key = path12[1];
14120
14120
  if (!key || !ctx.defs[key]) {
14121
14121
  throw new Error(`Reference not found: ${ref}`);
14122
14122
  }
@@ -14550,6 +14550,8 @@ var threadUsageSnapshotSchema = external_exports.object({
14550
14550
  reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
14551
14551
  totalTokens: nonNegativeSafeIntegerSchema.optional(),
14552
14552
  totalCostUsd: finiteNonNegativeNumberSchema.optional(),
14553
+ totalCredits: finiteNonNegativeNumberSchema.optional(),
14554
+ contextUsagePercent: finiteNonNegativeNumberSchema.optional(),
14553
14555
  cacheHitRatePercent: cacheHitRatePercentSchema.optional(),
14554
14556
  contextWindowTokens: nonNegativeSafeIntegerSchema.optional(),
14555
14557
  contextUsedTokens: nonNegativeSafeIntegerSchema.optional(),
@@ -15505,7 +15507,9 @@ var usageFields = /* @__PURE__ */ new Set([
15505
15507
  ...tokenFields,
15506
15508
  ...safeIntegerFields,
15507
15509
  ...percentFields,
15508
- "totalCostUsd"
15510
+ "totalCostUsd",
15511
+ "totalCredits",
15512
+ "contextUsagePercent"
15509
15513
  ]);
15510
15514
  function isRecord(value) {
15511
15515
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -15539,6 +15543,12 @@ function parseHostUsage(value) {
15539
15543
  if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
15540
15544
  throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
15541
15545
  }
15546
+ for (const field of ["totalCredits", "contextUsagePercent"]) {
15547
+ const candidate = value[field];
15548
+ if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
15549
+ throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
15550
+ }
15551
+ }
15542
15552
  for (const field of percentFields) {
15543
15553
  const candidate = value[field];
15544
15554
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
@@ -15567,10 +15577,13 @@ var HARNESS_BROKER_PROTOCOL_VERSION = 1;
15567
15577
  var HARNESS_BROKER_MAX_FRAME_BYTES = 8 * 1024 * 1024;
15568
15578
  var HARNESS_BROKER_MAX_PENDING_REQUESTS = 32;
15569
15579
  var HARNESS_BROKER_REQUEST_TIMEOUT_MS = 15e3;
15580
+ var HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE = 100;
15570
15581
  var harnessBrokerMethodSchema = external_exports.enum([
15571
15582
  "adapter.inspect",
15572
15583
  "adapter.inspectAccount",
15573
15584
  "adapter.open",
15585
+ "adapter.sessionImport.list",
15586
+ "adapter.sessionImport.resolve",
15574
15587
  "adapter.subagent.readSnapshot",
15575
15588
  "session.readSnapshot",
15576
15589
  "session.refreshUsage",
@@ -15719,6 +15732,27 @@ var brokerOpenInputSchema = external_exports.discriminatedUnion("kind", [
15719
15732
  rollbackSchema
15720
15733
  ]);
15721
15734
  var brokerInspectInputSchema = external_exports.object({ cwd: cwdSchema.optional(), refresh: external_exports.boolean().optional() }).strict();
15735
+ var brokerSessionImportListParamsSchema = external_exports.object({
15736
+ offset: external_exports.number().int().nonnegative().safe(),
15737
+ limit: external_exports.number().int().min(1).max(HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE)
15738
+ }).strict();
15739
+ var brokerSessionImportResolveParamsSchema = external_exports.object({ nativeSessionId: harnessSessionImportIdSchema }).strict();
15740
+ var brokerSessionImportCandidatesSchema = external_exports.array(harnessSessionImportCandidateSchema);
15741
+ var brokerSessionImportPageSchema = external_exports.object({
15742
+ candidates: external_exports.array(harnessSessionImportCandidateSchema).max(HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE),
15743
+ total: external_exports.number().int().nonnegative().safe()
15744
+ }).strict();
15745
+ var brokerSessionImportSourceSchema = external_exports.object({
15746
+ candidate: harnessSessionImportCandidateSchema,
15747
+ nativeRef: nativeSessionRefSchema
15748
+ }).strict().superRefine((source, context) => {
15749
+ if (source.nativeRef.harnessId !== "claude-code" || source.nativeRef.nativeSessionId !== source.candidate.nativeSessionId) {
15750
+ context.addIssue({
15751
+ code: "custom",
15752
+ message: "Claude Session import source identity does not match"
15753
+ });
15754
+ }
15755
+ });
15722
15756
  var textInputSchema = external_exports.object({ type: external_exports.literal("text"), text: external_exports.string().max(4e6) }).strict();
15723
15757
  var turnStartSchema = external_exports.object({
15724
15758
  type: external_exports.literal("turn.start"),
@@ -16246,6 +16280,7 @@ var BrokeredHarnessAdapter = class {
16246
16280
  #descriptorPath;
16247
16281
  #connection = null;
16248
16282
  #closed = false;
16283
+ #sessionImportListing = null;
16249
16284
  subagents = {
16250
16285
  readSnapshot: async (input) => {
16251
16286
  try {
@@ -16258,6 +16293,84 @@ var BrokeredHarnessAdapter = class {
16258
16293
  }
16259
16294
  }
16260
16295
  };
16296
+ sessionImport = Object.freeze({
16297
+ listCandidates: () => {
16298
+ this.#sessionImportListing ??= this.#listSessionImportCandidates().finally(() => {
16299
+ this.#sessionImportListing = null;
16300
+ });
16301
+ return this.#sessionImportListing;
16302
+ },
16303
+ resolveCandidate: async (nativeSessionId) => {
16304
+ if (this.#closed) {
16305
+ return {
16306
+ ok: false,
16307
+ error: unavailable("Claude Aqua broker adapter is closed", false)
16308
+ };
16309
+ }
16310
+ try {
16311
+ const result = parseHarnessResult(await (await this.#connect()).request("adapter.sessionImport.resolve", {
16312
+ nativeSessionId
16313
+ }));
16314
+ if (!result.ok)
16315
+ return result;
16316
+ const parsed = brokerSessionImportSourceSchema.safeParse(result.value);
16317
+ if (!parsed.success || parsed.data.candidate.nativeSessionId !== nativeSessionId) {
16318
+ return {
16319
+ ok: false,
16320
+ error: {
16321
+ ...unavailable("Harness broker returned an invalid Session source", false),
16322
+ code: "protocolError"
16323
+ }
16324
+ };
16325
+ }
16326
+ return { ok: true, value: parsed.data };
16327
+ } catch (error52) {
16328
+ this.#connection = null;
16329
+ return {
16330
+ ok: false,
16331
+ error: unavailable(error52 instanceof Error ? error52.message : String(error52))
16332
+ };
16333
+ }
16334
+ }
16335
+ });
16336
+ async #listSessionImportCandidates() {
16337
+ if (this.#closed) {
16338
+ return {
16339
+ ok: false,
16340
+ error: unavailable("Claude Aqua broker adapter is closed", false)
16341
+ };
16342
+ }
16343
+ try {
16344
+ const candidates = [];
16345
+ for (; ; ) {
16346
+ const result = parseHarnessResult(await (await this.#connect()).request("adapter.sessionImport.list", {
16347
+ offset: candidates.length,
16348
+ limit: HARNESS_BROKER_SESSION_IMPORT_PAGE_SIZE
16349
+ }));
16350
+ if (!result.ok)
16351
+ return result;
16352
+ const parsed = brokerSessionImportPageSchema.safeParse(result.value);
16353
+ if (!parsed.success || parsed.data.total < candidates.length + parsed.data.candidates.length || parsed.data.candidates.length === 0 && candidates.length < parsed.data.total) {
16354
+ return {
16355
+ ok: false,
16356
+ error: {
16357
+ ...unavailable("Harness broker returned invalid Session candidates", false),
16358
+ code: "protocolError"
16359
+ }
16360
+ };
16361
+ }
16362
+ candidates.push(...parsed.data.candidates);
16363
+ if (candidates.length === parsed.data.total)
16364
+ return { ok: true, value: candidates };
16365
+ }
16366
+ } catch (error52) {
16367
+ this.#connection = null;
16368
+ return {
16369
+ ok: false,
16370
+ error: unavailable(error52 instanceof Error ? error52.message : String(error52))
16371
+ };
16372
+ }
16373
+ }
16261
16374
  constructor(input = {}) {
16262
16375
  if (input.commandCatalog)
16263
16376
  this.commandCatalog = input.commandCatalog;
@@ -16319,7 +16432,7 @@ var BrokeredHarnessAdapter = class {
16319
16432
 
16320
16433
  // dist/claude-code-adapter.js
16321
16434
  import { randomUUID as randomUUID2 } from "node:crypto";
16322
- import path9 from "node:path";
16435
+ import path10 from "node:path";
16323
16436
 
16324
16437
  // ../../../node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs
16325
16438
  import { createRequire as DW } from "node:module";
@@ -16389,6 +16502,8 @@ import { promisify as tEe } from "util";
16389
16502
  import { execFileSync as GSe } from "child_process";
16390
16503
  import { lstatSync as WSe } from "fs";
16391
16504
  import { join as VSe } from "path";
16505
+ import { readdir as FT, stat as CEe } from "fs/promises";
16506
+ import { basename as REe, join as zT } from "path";
16392
16507
  import { open as UEe, readdir as sF, rm as iF, stat as $Ee } from "fs/promises";
16393
16508
  import { join as mc } from "path";
16394
16509
  import { randomUUID as n_ } from "crypto";
@@ -25149,6 +25264,19 @@ function Xc(e, t) {
25149
25264
  }
25150
25265
  return;
25151
25266
  }
25267
+ function HO(e, t) {
25268
+ let r = e.data;
25269
+ if (r.isSidechain === true) return null;
25270
+ let n = go(r.firstPromptLocked === true ? r.firstPrompt : r.commandFallback) || void 0, o = go(r.customTitle) || go(r.aiTitle) || void 0, i = o || go(r.lastPrompt) || go(r.summaryHint) || n;
25271
+ if (!i) return null;
25272
+ return { sessionId: e.sessionId, summary: i, lastModified: e.mtime, fileSize: void 0, customTitle: o, firstPrompt: n, gitBranch: go(r.gitBranch) || void 0, cwd: go(r.cwd) || t || void 0, tag: go(r.tag) || void 0, createdAt: JW(r.createdAt) };
25273
+ }
25274
+ function go(e) {
25275
+ return typeof e === "string" ? e : void 0;
25276
+ }
25277
+ function JW(e) {
25278
+ return typeof e === "number" ? e : void 0;
25279
+ }
25152
25280
  var It = class extends Error {
25153
25281
  };
25154
25282
  function Cs() {
@@ -39482,6 +39610,14 @@ async function ao(e) {
39482
39610
  }
39483
39611
  }
39484
39612
  var dn = 65536;
39613
+ var sEe = /* @__PURE__ */ new Set(["sdk-cli", "sdk-ts", "sdk-py"]);
39614
+ function B1(e, t) {
39615
+ let r = pc(e, "entrypoint") ?? er(t, "entrypoint");
39616
+ if (r && sEe.has(r)) return true;
39617
+ let n = e.split(`
39618
+ `).find((i) => i.includes('"parentUuid":')) ?? e, o = pc(n, "sessionKind");
39619
+ return o === "daemon" || o === "daemon-worker";
39620
+ }
39485
39621
  var aEe = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
39486
39622
  function ze(e) {
39487
39623
  if (typeof e !== "string") return null;
@@ -39724,6 +39860,126 @@ function fc(e, t, r) {
39724
39860
  `).findLast((T) => T.includes('"type":"tag"') && T.includes('"tag":"')), b = y ? er(y, "tag") || void 0 : void 0;
39725
39861
  return { sessionId: e, summary: g, lastModified: i, fileSize: s, customTitle: u, firstPrompt: d, gitBranch: h, cwd: _, tag: b, createdAt: m };
39726
39862
  }
39863
+ async function Gp(e, t, r) {
39864
+ let n;
39865
+ try {
39866
+ n = await FT(e);
39867
+ } catch {
39868
+ return [];
39869
+ }
39870
+ return (await Promise.all(n.map(async (i) => {
39871
+ if (!i.endsWith(".jsonl")) return null;
39872
+ let s = ze(i.slice(0, -6));
39873
+ if (!s) return null;
39874
+ let a = zT(e, i);
39875
+ if (!t) return { sessionId: s, filePath: a, mtime: 0, projectPath: r };
39876
+ try {
39877
+ let c = await CEe(a);
39878
+ return { sessionId: s, filePath: a, mtime: c.mtime.getTime(), projectPath: r };
39879
+ } catch {
39880
+ return null;
39881
+ }
39882
+ }))).filter((i) => i !== null);
39883
+ }
39884
+ async function tF(e, t) {
39885
+ let r = await r_(e.filePath);
39886
+ if (!r) return null;
39887
+ if (!t && B1(r.head, r.tail)) return null;
39888
+ let n = fc(e.sessionId, r, e.projectPath);
39889
+ if (!n) return null;
39890
+ if (e.mtime) n.lastModified = e.mtime;
39891
+ return n;
39892
+ }
39893
+ var IEe = 32;
39894
+ function PEe(e, t) {
39895
+ if (t.mtime !== e.mtime) return t.mtime - e.mtime;
39896
+ return t.sessionId < e.sessionId ? -1 : t.sessionId > e.sessionId ? 1 : 0;
39897
+ }
39898
+ async function DEe(e, t, r, n) {
39899
+ e.sort(PEe);
39900
+ let o = [], i = t && t > 0 ? t : 1 / 0, s = 0, a = /* @__PURE__ */ new Set();
39901
+ for (let c = 0; c < e.length && o.length < i; ) {
39902
+ let u = Math.min(c + IEe, e.length), d = e.slice(c, u), f = await Promise.all(d.map((m) => tF(m, n)));
39903
+ for (let m = 0; m < f.length && o.length < i; m++) {
39904
+ c++;
39905
+ let g = f[m];
39906
+ if (!g) continue;
39907
+ if (a.has(g.sessionId)) continue;
39908
+ if (a.add(g.sessionId), s < r) {
39909
+ s++;
39910
+ continue;
39911
+ }
39912
+ o.push(g);
39913
+ }
39914
+ }
39915
+ return o;
39916
+ }
39917
+ async function LEe(e, t) {
39918
+ let r = await Promise.all(e.map((i) => tF(i, t))), n = /* @__PURE__ */ new Map();
39919
+ for (let i of r) {
39920
+ if (!i) continue;
39921
+ let s = n.get(i.sessionId);
39922
+ if (!s || i.lastModified > s.lastModified) n.set(i.sessionId, i);
39923
+ }
39924
+ let o = [...n.values()];
39925
+ return o.sort((i, s) => s.lastModified !== i.lastModified ? s.lastModified - i.lastModified : s.sessionId < i.sessionId ? -1 : s.sessionId > i.sessionId ? 1 : 0), o;
39926
+ }
39927
+ async function NEe(e, t, r) {
39928
+ let n = await Jo(e), o;
39929
+ if (t) try {
39930
+ o = await ao(n);
39931
+ } catch {
39932
+ o = [];
39933
+ }
39934
+ else o = [];
39935
+ if (o.length <= 1) {
39936
+ let f = [];
39937
+ for (let m of await fr(n)) f.push(...await Gp(m, r, n));
39938
+ return f;
39939
+ }
39940
+ let i = fn(), s = process.platform === "win32", a = o.map((f) => {
39941
+ let m = us(f);
39942
+ return { path: f, prefix: s ? m.toLowerCase() : m };
39943
+ });
39944
+ a.sort((f, m) => m.prefix.length - f.prefix.length);
39945
+ let c;
39946
+ try {
39947
+ c = await FT(i, { withFileTypes: true });
39948
+ } catch {
39949
+ let f = [];
39950
+ for (let m of await fr(n)) f.push(...await Gp(m, r, n));
39951
+ return f;
39952
+ }
39953
+ let u = [], d = /* @__PURE__ */ new Set();
39954
+ for (let f of await fr(n)) {
39955
+ let m = REe(f);
39956
+ d.add(s ? m.toLowerCase() : m), u.push(...await Gp(f, r, n));
39957
+ }
39958
+ for (let f of c) {
39959
+ if (!f.isDirectory()) continue;
39960
+ let m = s ? f.name.toLowerCase() : f.name;
39961
+ if (d.has(m)) continue;
39962
+ for (let { path: g, prefix: h } of a) if (m === h || h.length >= dc && m.startsWith(h + "-")) {
39963
+ d.add(m), u.push(...await Gp(zT(i, f.name), r, g));
39964
+ break;
39965
+ }
39966
+ }
39967
+ return u;
39968
+ }
39969
+ async function MEe(e) {
39970
+ let t = fn(), r;
39971
+ try {
39972
+ r = await FT(t, { withFileTypes: true });
39973
+ } catch {
39974
+ return [];
39975
+ }
39976
+ return (await Promise.all(r.filter((o) => o.isDirectory()).map((o) => Gp(zT(t, o.name), e)))).flat();
39977
+ }
39978
+ async function rF(e) {
39979
+ let { dir: t, limit: r, offset: n, includeWorktrees: o, includeProgrammatic: i } = e ?? {}, s = n ?? 0, a = i ?? true, c = r !== void 0 && r > 0 || s > 0, u = t ? await NEe(t, o ?? true, c) : await MEe(c);
39980
+ if (!c) return LEe(u, a);
39981
+ return DEe(u, r, s, a);
39982
+ }
39727
39983
  async function nF(e, t = {}) {
39728
39984
  let r = ze(e);
39729
39985
  if (!r) return;
@@ -41782,6 +42038,10 @@ function bUe(e, t) {
41782
42038
  n.spawnAbort(m), r.setError(m);
41783
42039
  }), dO(r, n, e, o), r;
41784
42040
  }
42041
+ async function Ikt(e) {
42042
+ if (e?.sessionStore) return vUe(e.sessionStore, e);
42043
+ return rF(e);
42044
+ }
41785
42045
  async function Pkt(e, t) {
41786
42046
  if (t?.sessionStore) return TUe(t.sessionStore, e, t);
41787
42047
  return nF(e, t);
@@ -41821,9 +42081,53 @@ function lW(e) {
41821
42081
  `) + `
41822
42082
  `;
41823
42083
  }
42084
+ function uW(e, t, r) {
42085
+ if (t !== void 0 && t > 0) return e.slice(r, r + t);
42086
+ if (r > 0) return e.slice(r);
42087
+ return e;
42088
+ }
41824
42089
  function cO(e) {
41825
42090
  return typeof e === "object" && e !== null && "type" in e && e.type === "agent_metadata";
41826
42091
  }
42092
+ async function vUe(e, t) {
42093
+ let r = cW(t.dir), n = us(r), o = t.offset ?? 0, i = t.limit;
42094
+ if (e.listSessionSummaries) return SUe(e, n, r, t.dir, i, o);
42095
+ if (!e.listSessions) throw Error("sessionStore.listSessions is not implemented -- cannot list sessions. Provide a store with a listSessions() method.");
42096
+ let a = (await e.listSessions(n)).slice().sort((u, d) => d.mtime - u.mtime), c = uW(a, i, o);
42097
+ return pW(e, c, t.dir, r);
42098
+ }
42099
+ async function SUe(e, t, r, n, o, i) {
42100
+ let s = await e.listSessionSummaries(t), a = e.listSessions ? new Map((await e.listSessions(t)).map((f) => [f.sessionId, f])) : void 0, c = [];
42101
+ for (let f of s) {
42102
+ let m = a?.get(f.sessionId);
42103
+ if (a && !m) continue;
42104
+ let g = m !== void 0 && f.mtime < m.mtime;
42105
+ c.push({ sessionId: f.sessionId, mtime: g ? m.mtime : f.mtime, info: g ? void 0 : HO(f, r) });
42106
+ }
42107
+ if (a) {
42108
+ let f = new Set(s.map((m) => m.sessionId));
42109
+ for (let [m, g] of a) if (!f.has(m)) c.push({ sessionId: m, mtime: g.mtime });
42110
+ } else ce("listSessionSummaries without listSessions: gap-fill skipped; sessions lacking a sidecar will be omitted");
42111
+ c.sort((f, m) => m.mtime - f.mtime);
42112
+ let u = uW(c, o, i), d = u.filter((f) => f.info === void 0);
42113
+ if (d.length > 0) {
42114
+ let f = await pW(e, d, n, r), m = new Map(f.map((g) => [g.sessionId, g]));
42115
+ for (let g of u) if (g.info === void 0) g.info = m.get(g.sessionId) ?? null;
42116
+ }
42117
+ return u.flatMap((f) => f.info ? [f.info] : []);
42118
+ }
42119
+ async function pW(e, t, r, n) {
42120
+ return (await Promise.allSettled(t.map(async (i) => {
42121
+ let s = await fW(e, i.sessionId, r);
42122
+ if (!s) return null;
42123
+ let a = fc(i.sessionId, dW(s, i.mtime), n);
42124
+ return a ? { ...a, lastModified: i.mtime } : null;
42125
+ }))).flatMap((i, s) => {
42126
+ let a = t[s];
42127
+ if (i.status === "fulfilled") return i.value ? [i.value] : [];
42128
+ return [{ sessionId: a.sessionId, summary: "", lastModified: a.mtime }];
42129
+ });
42130
+ }
41827
42131
  function dW(e, t) {
41828
42132
  let r = Buffer.from(e, "utf-8"), n = r.length, o = r.subarray(0, dn).toString("utf-8"), i = n > dn ? r.subarray(n - dn).toString("utf-8") : o;
41829
42133
  return { mtime: t, size: n, head: o, tail: i };
@@ -42929,26 +43233,150 @@ async function forkClaudeSession(input) {
42929
43233
  return { ok: true, value: { sessionId: derivedSessionId } };
42930
43234
  }
42931
43235
 
43236
+ // dist/claude-session-import.js
43237
+ import { realpath, stat } from "node:fs/promises";
43238
+ import path6 from "node:path";
43239
+ function titleFromMetadata(metadata) {
43240
+ for (const value of [metadata.customTitle, metadata.summary, metadata.firstPrompt]) {
43241
+ if (typeof value !== "string")
43242
+ continue;
43243
+ const title = value.replaceAll("\0", "").trim().slice(0, HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH);
43244
+ if (title)
43245
+ return title;
43246
+ }
43247
+ return null;
43248
+ }
43249
+ async function sourceFromMetadata(metadata, isRunning, signal, canonicalCwds, preferredCwds = []) {
43250
+ signal.throwIfAborted();
43251
+ if (typeof metadata.sessionId !== "string" || metadata.sessionId.trim().length === 0 || typeof metadata.lastModified !== "number" || !Number.isFinite(metadata.lastModified)) {
43252
+ return null;
43253
+ }
43254
+ const candidates = [
43255
+ ...preferredCwds,
43256
+ ...typeof metadata.cwd === "string" ? [metadata.cwd] : []
43257
+ ];
43258
+ let cwd = null;
43259
+ for (const candidate2 of new Set(candidates)) {
43260
+ if (!path6.isAbsolute(candidate2))
43261
+ continue;
43262
+ let canonical = canonicalCwds.get(candidate2);
43263
+ if (!canonical) {
43264
+ canonical = (async () => {
43265
+ try {
43266
+ const resolved = await realpath(candidate2);
43267
+ return (await stat(resolved)).isDirectory() ? resolved : null;
43268
+ } catch {
43269
+ return null;
43270
+ }
43271
+ })();
43272
+ canonicalCwds.set(candidate2, canonical);
43273
+ }
43274
+ cwd = await canonical;
43275
+ signal.throwIfAborted();
43276
+ if (cwd)
43277
+ break;
43278
+ }
43279
+ if (!cwd)
43280
+ return null;
43281
+ const nativeSessionId = metadata.sessionId.trim();
43282
+ const candidate = harnessSessionImportCandidateSchema.safeParse({
43283
+ nativeSessionId,
43284
+ cwd,
43285
+ title: titleFromMetadata(metadata),
43286
+ updatedAt: Math.floor(metadata.lastModified),
43287
+ // We know about sessions opened through this Adapter. Other Claude clients do not
43288
+ // expose a reliable cross-process ownership signal, so their activity stays unknown.
43289
+ running: isRunning(nativeSessionId) ? true : null
43290
+ });
43291
+ const nativeRef = nativeSessionRefSchema.safeParse({
43292
+ harnessId: "claude-code",
43293
+ nativeSessionId,
43294
+ formatVersion: 1
43295
+ });
43296
+ return candidate.success && nativeRef.success ? { candidate: candidate.data, nativeRef: nativeRef.data } : null;
43297
+ }
43298
+ var ClaudeSessionImportIndex = class {
43299
+ #dependencies;
43300
+ #listing;
43301
+ constructor(dependencies) {
43302
+ this.#dependencies = dependencies;
43303
+ }
43304
+ list(signal) {
43305
+ this.#listing ??= this.#scan(signal).finally(() => {
43306
+ this.#listing = void 0;
43307
+ });
43308
+ return this.#listing;
43309
+ }
43310
+ async #scan(signal) {
43311
+ signal.throwIfAborted();
43312
+ const metadata = await this.#dependencies.listSessions();
43313
+ signal.throwIfAborted();
43314
+ const sources = [];
43315
+ const identities = /* @__PURE__ */ new Set();
43316
+ const canonicalCwds = /* @__PURE__ */ new Map();
43317
+ for (const session of metadata) {
43318
+ const source = await sourceFromMetadata(session, this.#dependencies.isRunning, signal, canonicalCwds);
43319
+ if (!source)
43320
+ continue;
43321
+ const identity = source.candidate.nativeSessionId;
43322
+ if (identities.has(identity)) {
43323
+ throw new Error(`Claude Session identity is ambiguous: ${identity}`);
43324
+ }
43325
+ identities.add(identity);
43326
+ sources.push(source);
43327
+ }
43328
+ return sources;
43329
+ }
43330
+ async resolve(nativeSessionId, signal) {
43331
+ signal.throwIfAborted();
43332
+ const metadata = await this.#dependencies.getSessionInfo({ sessionId: nativeSessionId });
43333
+ signal.throwIfAborted();
43334
+ if (!metadata || metadata.sessionId !== nativeSessionId)
43335
+ return null;
43336
+ const preferredCwds = [];
43337
+ if (typeof metadata.cwd === "string" && path6.isAbsolute(metadata.cwd)) {
43338
+ try {
43339
+ const messages = await this.#dependencies.readSessionMessages({
43340
+ cwd: metadata.cwd,
43341
+ sessionId: nativeSessionId
43342
+ });
43343
+ signal.throwIfAborted();
43344
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
43345
+ const message = messages[index];
43346
+ if (typeof message !== "object" || message === null || Array.isArray(message) || typeof message.cwd !== "string") {
43347
+ continue;
43348
+ }
43349
+ const cwd = message.cwd;
43350
+ if (path6.isAbsolute(cwd) && !preferredCwds.includes(cwd))
43351
+ preferredCwds.push(cwd);
43352
+ }
43353
+ } catch {
43354
+ }
43355
+ }
43356
+ return sourceFromMetadata(metadata, this.#dependencies.isRunning, signal, /* @__PURE__ */ new Map(), preferredCwds);
43357
+ }
43358
+ };
43359
+
42932
43360
  // dist/claude-transcript.js
42933
43361
  import os3 from "node:os";
42934
- import path6 from "node:path";
42935
- import { readFile as readFile2, readdir, stat } from "node:fs/promises";
43362
+ import path7 from "node:path";
43363
+ import { readFile as readFile2, readdir, stat as stat2 } from "node:fs/promises";
42936
43364
  function projectDirectoryName(cwd) {
42937
43365
  return cwd.replace(/[^A-Za-z0-9]/gu, "-");
42938
43366
  }
42939
43367
  function configDirectory(environment) {
42940
- return environment.CLAUDE_CONFIG_DIR ? path6.resolve(environment.CLAUDE_CONFIG_DIR) : path6.join(os3.homedir(), ".claude");
43368
+ return environment.CLAUDE_CONFIG_DIR ? path7.resolve(environment.CLAUDE_CONFIG_DIR) : path7.join(os3.homedir(), ".claude");
42941
43369
  }
42942
43370
  async function existingFile(file2) {
42943
43371
  try {
42944
- return (await stat(file2)).isFile();
43372
+ return (await stat2(file2)).isFile();
42945
43373
  } catch {
42946
43374
  return false;
42947
43375
  }
42948
43376
  }
42949
43377
  async function findTranscriptFile(environment, cwd, relativeName) {
42950
- const projectsDirectory = path6.join(configDirectory(environment), "projects");
42951
- const expected = path6.join(projectsDirectory, projectDirectoryName(cwd), relativeName);
43378
+ const projectsDirectory = path7.join(configDirectory(environment), "projects");
43379
+ const expected = path7.join(projectsDirectory, projectDirectoryName(cwd), relativeName);
42952
43380
  if (await existingFile(expected))
42953
43381
  return expected;
42954
43382
  let projects;
@@ -42958,7 +43386,7 @@ async function findTranscriptFile(environment, cwd, relativeName) {
42958
43386
  return null;
42959
43387
  }
42960
43388
  for (const project of projects) {
42961
- const candidate = path6.join(projectsDirectory, project, relativeName);
43389
+ const candidate = path7.join(projectsDirectory, project, relativeName);
42962
43390
  if (await existingFile(candidate))
42963
43391
  return candidate;
42964
43392
  }
@@ -42992,7 +43420,7 @@ async function readClaudeTranscript(input) {
42992
43420
  return parseTranscriptRecords(await readFile2(transcript, "utf8"), input.sessionId);
42993
43421
  }
42994
43422
  async function readClaudeSubagentTranscript(input) {
42995
- const relativeName = path6.join(input.sessionId, "subagents", `agent-${input.nativeSubagentId}.jsonl`);
43423
+ const relativeName = path7.join(input.sessionId, "subagents", `agent-${input.nativeSubagentId}.jsonl`);
42996
43424
  const transcript = await findTranscriptFile(input.environment, input.cwd, relativeName);
42997
43425
  if (!transcript)
42998
43426
  return null;
@@ -43259,7 +43687,7 @@ function projectClaudeAccountUsage(usage, account) {
43259
43687
 
43260
43688
  // dist/gateway-models.js
43261
43689
  import { readFile as readFile3 } from "node:fs/promises";
43262
- import path7 from "node:path";
43690
+ import path8 from "node:path";
43263
43691
  var GATEWAY_MODELS_TIMEOUT_MS = 3e3;
43264
43692
  var GATEWAY_MODELS_MAX_BYTES = 2 * 1024 * 1024;
43265
43693
  var OFFICIAL_ANTHROPIC_HOST = "api.anthropic.com";
@@ -43301,14 +43729,14 @@ function claudeConfigDirectory(environment) {
43301
43729
  if (configured)
43302
43730
  return configured;
43303
43731
  const home = trimmedEnv(environment, "HOME") ?? trimmedEnv(environment, "USERPROFILE");
43304
- return home ? path7.join(home, ".claude") : void 0;
43732
+ return home ? path8.join(home, ".claude") : void 0;
43305
43733
  }
43306
43734
  async function readClaudeUserSettingsEnv(environment) {
43307
43735
  const configDir = claudeConfigDirectory(environment);
43308
43736
  if (!configDir)
43309
43737
  return {};
43310
43738
  try {
43311
- const raw = await readFile3(path7.join(configDir, "settings.json"), "utf8");
43739
+ const raw = await readFile3(path8.join(configDir, "settings.json"), "utf8");
43312
43740
  const parsed = JSON.parse(raw);
43313
43741
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
43314
43742
  return {};
@@ -43440,7 +43868,7 @@ async function applyGatewayModelCatalog(snapshot, environment, dependencies = {}
43440
43868
  }
43441
43869
 
43442
43870
  // dist/file-change.js
43443
- import path8 from "node:path";
43871
+ import path9 from "node:path";
43444
43872
  var hunkSchema = external_exports.object({
43445
43873
  oldStart: external_exports.number().int().nonnegative(),
43446
43874
  oldLines: external_exports.number().int().nonnegative(),
@@ -43488,10 +43916,10 @@ function parseClaudeNativeFileChange(toolName, value) {
43488
43916
  };
43489
43917
  }
43490
43918
  function displayPath(nativePath, cwd) {
43491
- const resolvedCwd = path8.resolve(cwd);
43492
- const resolvedPath = path8.isAbsolute(nativePath) ? path8.resolve(nativePath) : path8.resolve(cwd, nativePath);
43493
- const relative = path8.relative(resolvedCwd, resolvedPath);
43494
- const selected = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path8.sep}`) ? relative : resolvedPath;
43919
+ const resolvedCwd = path9.resolve(cwd);
43920
+ const resolvedPath = path9.isAbsolute(nativePath) ? path9.resolve(nativePath) : path9.resolve(cwd, nativePath);
43921
+ const relative = path9.relative(resolvedCwd, resolvedPath);
43922
+ const selected = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path9.sep}`) ? relative : resolvedPath;
43495
43923
  const normalized = selected.replaceAll("\\", "/");
43496
43924
  return validNativePath(normalized) && normalized !== "." ? normalized : null;
43497
43925
  }
@@ -43503,7 +43931,7 @@ function projectClaudeFileChange(value, cwd) {
43503
43931
  `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`,
43504
43932
  ...hunk.lines
43505
43933
  ]);
43506
- const absoluteDisplayPath = path8.posix.isAbsolute(normalizedPath);
43934
+ const absoluteDisplayPath = path9.posix.isAbsolute(normalizedPath);
43507
43935
  const oldHeader = value.kind === "add" ? "/dev/null" : absoluteDisplayPath ? normalizedPath : `a/${normalizedPath}`;
43508
43936
  const newHeader = absoluteDisplayPath ? normalizedPath : `b/${normalizedPath}`;
43509
43937
  const unifiedDiff = [`--- ${oldHeader}`, `+++ ${newHeader}`, ...body, ""].join("\n");
@@ -45631,6 +46059,9 @@ var ClaudeHarnessSession = class {
45631
46059
  initialState;
45632
46060
  initialUsage = null;
45633
46061
  outputs;
46062
+ get nativeSessionId() {
46063
+ return this.#sessionId;
46064
+ }
45634
46065
  #channel = new HarnessOutputChannel();
45635
46066
  #cancelTimeoutMs;
45636
46067
  #closeTimeoutMs;
@@ -47333,9 +47764,31 @@ var ClaudeCodeAdapter = class {
47333
47764
  }
47334
47765
  }
47335
47766
  };
47767
+ sessionImport = Object.freeze({
47768
+ listCandidates: async () => {
47769
+ const result = await this.#readImport((signal) => this.#importIndex.list(signal));
47770
+ return result.ok ? { ok: true, value: result.value.map(({ candidate }) => candidate) } : result;
47771
+ },
47772
+ resolveCandidate: async (nativeSessionId) => {
47773
+ const result = await this.#readImport((signal) => this.#importIndex.resolve(nativeSessionId, signal));
47774
+ if (!result.ok)
47775
+ return result;
47776
+ return result.value ? { ok: true, value: result.value } : {
47777
+ ok: false,
47778
+ error: {
47779
+ code: "sessionNotFound",
47780
+ message: "Claude Code Session is no longer importable",
47781
+ retryable: false
47782
+ }
47783
+ };
47784
+ }
47785
+ });
47336
47786
  #cancelTimeoutMs;
47337
47787
  #closeTimeoutMs;
47338
47788
  #dependencies;
47789
+ #importAbort = new AbortController();
47790
+ #importIndex;
47791
+ #importRequests = /* @__PURE__ */ new Set();
47339
47792
  #toolOutputLimit;
47340
47793
  #continuationQuiescenceMs;
47341
47794
  #inspectionCache = /* @__PURE__ */ new Map();
@@ -47384,10 +47837,10 @@ var ClaudeCodeAdapter = class {
47384
47837
  forkSession: ({ checkpointId, cwd, sourceSessionId }) => Mkt(sourceSessionId, { dir: cwd, upToMessageId: checkpointId }),
47385
47838
  getSessionInfo: async ({ sessionId }) => {
47386
47839
  const info = await Pkt(sessionId);
47387
- if (!info)
47388
- return void 0;
47389
- return info.cwd ? { cwd: info.cwd } : {};
47840
+ return info;
47390
47841
  },
47842
+ // Include SDK-origin Sessions so an orphaned codexhost mapping can also be recovered.
47843
+ listSessions: () => Ikt(),
47391
47844
  readSessionMessages: async ({ cwd, sessionId }) => {
47392
47845
  const transcript = await readClaudeTranscript({
47393
47846
  cwd,
@@ -47408,6 +47861,30 @@ var ClaudeCodeAdapter = class {
47408
47861
  return jkt(sessionId, nativeSubagentId2, { dir: cwd });
47409
47862
  }
47410
47863
  };
47864
+ this.#importIndex = new ClaudeSessionImportIndex({
47865
+ getSessionInfo: (input) => this.#dependencies.getSessionInfo(input),
47866
+ isRunning: (nativeSessionId) => [...this.#sessions].some((session) => session.nativeSessionId === nativeSessionId),
47867
+ listSessions: () => this.#dependencies.listSessions(),
47868
+ readSessionMessages: (input) => this.#dependencies.readSessionMessages(input)
47869
+ });
47870
+ }
47871
+ #readImport(operation) {
47872
+ if (this.#importAbort.signal.aborted) {
47873
+ return Promise.resolve({
47874
+ ok: false,
47875
+ error: invalidState("Claude Code Adapter is closed")
47876
+ });
47877
+ }
47878
+ const request = operation(this.#importAbort.signal).then((value) => ({ ok: true, value })).catch(() => ({
47879
+ ok: false,
47880
+ error: {
47881
+ code: "unavailable",
47882
+ message: "Claude Code Session discovery failed; check native storage access and duplicate Session identities, then retry after closing native clients",
47883
+ retryable: true
47884
+ }
47885
+ })).finally(() => this.#importRequests.delete(request));
47886
+ this.#importRequests.add(request);
47887
+ return request;
47411
47888
  }
47412
47889
  async inspect(input = {}) {
47413
47890
  if (this.#closePromise) {
@@ -47416,7 +47893,7 @@ var ClaudeCodeAdapter = class {
47416
47893
  error: invalidState("Claude Code Adapter is closing")
47417
47894
  };
47418
47895
  }
47419
- const cwd = path9.resolve(input.cwd ?? process.cwd());
47896
+ const cwd = path10.resolve(input.cwd ?? process.cwd());
47420
47897
  if (!input.refresh) {
47421
47898
  const cached2 = this.#inspectionCache.get(cwd);
47422
47899
  if (cached2)
@@ -47562,7 +48039,7 @@ var ClaudeCodeAdapter = class {
47562
48039
  let sourceSnapshot;
47563
48040
  try {
47564
48041
  const messages = await this.#dependencies.readSessionMessages({
47565
- cwd: path9.resolve(input.cwd),
48042
+ cwd: path10.resolve(input.cwd),
47566
48043
  sessionId: sourceRef.data.nativeSessionId
47567
48044
  });
47568
48045
  sourceSnapshot = mapClaudeSnapshot(messages, sourceRef.data.nativeSessionId);
@@ -47604,7 +48081,7 @@ var ClaudeCodeAdapter = class {
47604
48081
  } else {
47605
48082
  const forked2 = await forkClaudeSession({
47606
48083
  checkpoint: retained.checkpoint,
47607
- cwd: path9.resolve(input.cwd),
48084
+ cwd: path10.resolve(input.cwd),
47608
48085
  dependencies: this.#dependencies,
47609
48086
  harnessId: this.harnessId,
47610
48087
  sourceRef: sourceRef.data
@@ -47659,7 +48136,7 @@ var ClaudeCodeAdapter = class {
47659
48136
  }
47660
48137
  };
47661
48138
  }
47662
- const cwd = path9.resolve(input.cwd);
48139
+ const cwd = path10.resolve(input.cwd);
47663
48140
  const nativeRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
47664
48141
  if (nativeRef && (!nativeRef.success || nativeRef.data.harnessId !== this.harnessId)) {
47665
48142
  return {
@@ -47715,8 +48192,10 @@ var ClaudeCodeAdapter = class {
47715
48192
  }
47716
48193
  close() {
47717
48194
  if (!this.#closePromise) {
48195
+ this.#importAbort.abort();
47718
48196
  this.#inspectionCache.clear();
47719
48197
  this.#closePromise = Promise.all([
48198
+ ...this.#importRequests,
47720
48199
  ...[...this.#inspectors].map((inspector) => inspector.close()),
47721
48200
  ...[...this.#sessions].map((session) => session.close()),
47722
48201
  ...this.#inspectionInFlight.values()
@@ -47727,7 +48206,7 @@ var ClaudeCodeAdapter = class {
47727
48206
  };
47728
48207
 
47729
48208
  // dist/user-shell-environment.js
47730
- import path10 from "node:path";
48209
+ import path11 from "node:path";
47731
48210
  import { spawnSync } from "node:child_process";
47732
48211
  var ENVIRONMENT_MARKER = Buffer.from("\0CODEXHOST_USER_SHELL_ENV_V1\0");
47733
48212
  var ENVIRONMENT_COMMAND = "printf '\\0CODEXHOST_USER_SHELL_ENV_V1\\0'; /usr/bin/env -0";
@@ -47770,7 +48249,7 @@ function withUserShellEnvironment(environment, dependencies) {
47770
48249
  if (platform === "win32" || !environment.HOME)
47771
48250
  return environment;
47772
48251
  const shell = environment.SHELL?.trim() || defaultShell(platform);
47773
- if (!shell || !SUPPORTED_SHELLS.has(path10.basename(shell)))
48252
+ if (!shell || !SUPPORTED_SHELLS.has(path11.basename(shell)))
47774
48253
  return environment;
47775
48254
  const cacheKey = `${platform}\0${shell}\0${environment.HOME}`;
47776
48255
  const cached2 = dependencies ? void 0 : shellEnvironmentCache.get(cacheKey);