@liberseek/boft-cli-win32-arm64 0.7.8 → 0.7.9

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.
@@ -488,8 +488,8 @@ function createHarnessInstaller(environment, source) {
488
488
  }
489
489
 
490
490
  // dist/kimi-adapter.js
491
- import { readFile as readFile5 } from "node:fs/promises";
492
- import path8 from "node:path";
491
+ import { readFile as readFile6 } from "node:fs/promises";
492
+ import path9 from "node:path";
493
493
  import { isDeepStrictEqual } from "node:util";
494
494
 
495
495
  // ../../../node_modules/zod/v4/classic/external.js
@@ -1258,10 +1258,10 @@ function mergeDefs(...defs) {
1258
1258
  function cloneDef(schema) {
1259
1259
  return mergeDefs(schema._zod.def);
1260
1260
  }
1261
- function getElementAtPath(obj, path9) {
1262
- if (!path9)
1261
+ function getElementAtPath(obj, path10) {
1262
+ if (!path10)
1263
1263
  return obj;
1264
- return path9.reduce((acc, key) => acc?.[key], obj);
1264
+ return path10.reduce((acc, key) => acc?.[key], obj);
1265
1265
  }
1266
1266
  function promiseAllObject(promisesObj) {
1267
1267
  const keys = Object.keys(promisesObj);
@@ -1670,11 +1670,11 @@ function explicitlyAborted(x, startIndex = 0) {
1670
1670
  }
1671
1671
  return false;
1672
1672
  }
1673
- function prefixIssues(path9, issues) {
1673
+ function prefixIssues(path10, issues) {
1674
1674
  return issues.map((iss) => {
1675
1675
  var _a3;
1676
1676
  (_a3 = iss).path ?? (_a3.path = []);
1677
- iss.path.unshift(path9);
1677
+ iss.path.unshift(path10);
1678
1678
  return iss;
1679
1679
  });
1680
1680
  }
@@ -1821,16 +1821,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
1821
1821
  }
1822
1822
  function formatError(error51, mapper = (issue2) => issue2.message) {
1823
1823
  const fieldErrors = { _errors: [] };
1824
- const processError = (error52, path9 = []) => {
1824
+ const processError = (error52, path10 = []) => {
1825
1825
  for (const issue2 of error52.issues) {
1826
1826
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1827
- issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1827
+ issue2.errors.map((issues) => processError({ issues }, [...path10, ...issue2.path]));
1828
1828
  } else if (issue2.code === "invalid_key") {
1829
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1829
+ processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1830
1830
  } else if (issue2.code === "invalid_element") {
1831
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1831
+ processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1832
1832
  } else {
1833
- const fullpath = [...path9, ...issue2.path];
1833
+ const fullpath = [...path10, ...issue2.path];
1834
1834
  if (fullpath.length === 0) {
1835
1835
  fieldErrors._errors.push(mapper(issue2));
1836
1836
  } else {
@@ -1857,17 +1857,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
1857
1857
  }
1858
1858
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
1859
1859
  const result = { errors: [] };
1860
- const processError = (error52, path9 = []) => {
1860
+ const processError = (error52, path10 = []) => {
1861
1861
  var _a3, _b;
1862
1862
  for (const issue2 of error52.issues) {
1863
1863
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1864
- issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
1864
+ issue2.errors.map((issues) => processError({ issues }, [...path10, ...issue2.path]));
1865
1865
  } else if (issue2.code === "invalid_key") {
1866
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1866
+ processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1867
1867
  } else if (issue2.code === "invalid_element") {
1868
- processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
1868
+ processError({ issues: issue2.issues }, [...path10, ...issue2.path]);
1869
1869
  } else {
1870
- const fullpath = [...path9, ...issue2.path];
1870
+ const fullpath = [...path10, ...issue2.path];
1871
1871
  if (fullpath.length === 0) {
1872
1872
  result.errors.push(mapper(issue2));
1873
1873
  continue;
@@ -1899,8 +1899,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
1899
1899
  }
1900
1900
  function toDotPath(_path) {
1901
1901
  const segs = [];
1902
- const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1903
- for (const seg of path9) {
1902
+ const path10 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1903
+ for (const seg of path10) {
1904
1904
  if (typeof seg === "number")
1905
1905
  segs.push(`[${seg}]`);
1906
1906
  else if (typeof seg === "symbol")
@@ -14592,13 +14592,13 @@ function resolveRef(ref, ctx) {
14592
14592
  if (!ref.startsWith("#")) {
14593
14593
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14594
14594
  }
14595
- const path9 = ref.slice(1).split("/").filter(Boolean);
14596
- if (path9.length === 0) {
14595
+ const path10 = ref.slice(1).split("/").filter(Boolean);
14596
+ if (path10.length === 0) {
14597
14597
  return ctx.rootSchema;
14598
14598
  }
14599
14599
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14600
- if (path9[0] === defsKey) {
14601
- const key = path9[1];
14600
+ if (path10[0] === defsKey) {
14601
+ const key = path10[1];
14602
14602
  if (!key || !ctx.defs[key]) {
14603
14603
  throw new Error(`Reference not found: ${ref}`);
14604
14604
  }
@@ -15086,6 +15086,10 @@ var hostTurnIdSchema = opaqueIdSchema.brand();
15086
15086
  var hostItemIdSchema = opaqueIdSchema.brand();
15087
15087
  var hostInteractionIdSchema = opaqueIdSchema.brand();
15088
15088
 
15089
+ // ../../shared-contracts/dist/thread-prewarm.js
15090
+ var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
15091
+ var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
15092
+
15089
15093
  // ../../shared-contracts/dist/harness-plugins.js
15090
15094
  var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15091
15095
  var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
@@ -15153,6 +15157,9 @@ var consoleOpenResultSchema = external_exports.strictObject({
15153
15157
  url: external_exports.string().max(2048).regex(/^http:\/\/(?:127\.0\.0\.1|localhost):\d{1,5}\/(?:\?.*)?$/u)
15154
15158
  });
15155
15159
  var CONSOLE_HOST_METHODS = Object.freeze([
15160
+ "codexhost/console/remote-connections",
15161
+ "codexhost/runtime/status",
15162
+ "codexhost/remote/ssh-setup",
15156
15163
  "codexhost/harness/plugins/list",
15157
15164
  "codexhost/harness/display-settings/get",
15158
15165
  "codexhost/harness/display-settings/set",
@@ -16098,6 +16105,80 @@ var updateStatusResultSchema = external_exports.strictObject({
16098
16105
  status: updateStatusSchema.nullable()
16099
16106
  });
16100
16107
 
16108
+ // ../../shared-contracts/dist/remote-runtime.js
16109
+ var remoteUpdatePhaseSchema = external_exports.enum([
16110
+ "idle",
16111
+ "installing",
16112
+ "restarting",
16113
+ "succeeded",
16114
+ "failed"
16115
+ ]);
16116
+ var runtimeStatusSchema = external_exports.object({
16117
+ runningVersion: external_exports.string().nullable(),
16118
+ installedVersion: external_exports.string().nullable(),
16119
+ restartRequired: external_exports.boolean(),
16120
+ remote: external_exports.boolean(),
16121
+ updateSupported: external_exports.boolean(),
16122
+ update: external_exports.object({
16123
+ phase: remoteUpdatePhaseSchema,
16124
+ targetVersion: external_exports.string().nullable(),
16125
+ error: external_exports.string().nullable()
16126
+ })
16127
+ });
16128
+ var remoteUpdateParamsSchema = external_exports.object({
16129
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
16130
+ }).strict();
16131
+ var remoteSshSetupParamsSchema = external_exports.object({
16132
+ hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
16133
+ port: external_exports.number().int().min(1).max(65535).nullable(),
16134
+ identity: external_exports.string().max(4096).nullable(),
16135
+ action: external_exports.enum(["inspect", "install", "update", "repair", "uninstall"]),
16136
+ uninstallPackage: external_exports.boolean().optional(),
16137
+ version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
16138
+ }).strict();
16139
+ var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
16140
+
16141
+ // ../../shared-contracts/dist/remote-connections.js
16142
+ var hostId = external_exports.string().min(1).max(1024);
16143
+ var codexSshConnectionSchema = external_exports.object({
16144
+ hostId,
16145
+ displayName: external_exports.string().min(1).max(1024),
16146
+ source: external_exports.enum(["codex-managed", "discovered"]),
16147
+ sshAlias: external_exports.string().max(1024).nullable(),
16148
+ sshHost: external_exports.string().min(1).max(1024),
16149
+ sshPort: external_exports.number().int().min(1).max(65535).nullable(),
16150
+ identity: external_exports.string().max(4096).nullable(),
16151
+ autoConnect: external_exports.boolean(),
16152
+ connectionAnalyticsId: external_exports.string().max(1024).optional()
16153
+ });
16154
+ var codexSshDraftSchema = external_exports.strictObject({
16155
+ displayName: external_exports.string().min(1).max(1024),
16156
+ hostname: external_exports.string().min(1).max(1024),
16157
+ sshPort: external_exports.number().int().min(1).max(65535).nullable(),
16158
+ identity: external_exports.string().max(4096).nullable()
16159
+ });
16160
+ var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
16161
+ external_exports.strictObject({ action: external_exports.literal("list") }),
16162
+ external_exports.strictObject({
16163
+ action: external_exports.literal("save"),
16164
+ draft: codexSshDraftSchema,
16165
+ previous: codexSshConnectionSchema.nullable()
16166
+ }),
16167
+ external_exports.strictObject({ action: external_exports.literal("remove"), previous: codexSshConnectionSchema }),
16168
+ external_exports.strictObject({ action: external_exports.literal("connect"), hostId, enabled: external_exports.boolean() }),
16169
+ external_exports.strictObject({ action: external_exports.literal("state"), hostId }),
16170
+ external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
16171
+ external_exports.strictObject({
16172
+ action: external_exports.literal("update"),
16173
+ hostId: hostId.refine((id) => id !== "local"),
16174
+ version: remoteUpdateParamsSchema.shape.version
16175
+ })
16176
+ ]);
16177
+ var remoteConnectionsReplySchema = external_exports.union([
16178
+ external_exports.strictObject({ result: jsonValueSchema }),
16179
+ external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
16180
+ ]);
16181
+
16101
16182
  // ../../shared-contracts/dist/index.js
16102
16183
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
16103
16184
 
@@ -21256,16 +21337,16 @@ var Diff = class {
21256
21337
  }
21257
21338
  }
21258
21339
  }
21259
- addToPath(path9, added, removed, oldPosInc, options) {
21260
- const last = path9.lastComponent;
21340
+ addToPath(path10, added, removed, oldPosInc, options) {
21341
+ const last = path10.lastComponent;
21261
21342
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
21262
21343
  return {
21263
- oldPos: path9.oldPos + oldPosInc,
21344
+ oldPos: path10.oldPos + oldPosInc,
21264
21345
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
21265
21346
  };
21266
21347
  } else {
21267
21348
  return {
21268
- oldPos: path9.oldPos + oldPosInc,
21349
+ oldPos: path10.oldPos + oldPosInc,
21269
21350
  lastComponent: { count: 1, added, removed, previousComponent: last }
21270
21351
  };
21271
21352
  }
@@ -23219,19 +23300,259 @@ async function readKimiSessionUsage(sessionId, options = {}) {
23219
23300
  }
23220
23301
  }
23221
23302
 
23303
+ // dist/session-import.js
23304
+ import { readFile as readFile4, stat } from "node:fs/promises";
23305
+ import path7 from "node:path";
23306
+
23307
+ // ../../harness-adapter/dist/session-import.js
23308
+ import { lstat } from "node:fs/promises";
23309
+ var SessionImportChangedError = class extends Error {
23310
+ constructor(message = "Native Session changed during discovery; refresh and retry") {
23311
+ super(message);
23312
+ this.name = "SessionImportChangedError";
23313
+ }
23314
+ };
23315
+ function isMissingFileError(error51) {
23316
+ return typeof error51 === "object" && error51 !== null && "code" in error51 && error51.code === "ENOENT";
23317
+ }
23318
+ function sameFileFingerprint(left, right) {
23319
+ return left === null || right === null ? left === right : left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
23320
+ }
23321
+ var STORAGE_ACCESS_ERRORS = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EIO", "EMFILE", "ENFILE"]);
23322
+ function isStorageAccessError(error51) {
23323
+ return typeof error51 === "object" && error51 !== null && "code" in error51 && typeof error51.code === "string" && STORAGE_ACCESS_ERRORS.has(error51.code);
23324
+ }
23325
+ async function optionalLstat(file2) {
23326
+ try {
23327
+ return await lstat(file2);
23328
+ } catch (error51) {
23329
+ if (isMissingFileError(error51))
23330
+ return null;
23331
+ throw error51;
23332
+ }
23333
+ }
23334
+ async function readStableFiles(files, read) {
23335
+ const before = await Promise.all(files.map(optionalLstat));
23336
+ const value = await read(before);
23337
+ const after = await Promise.all(files.map(optionalLstat));
23338
+ if (before.some((info, index) => !sameFileFingerprint(info, after[index] ?? null)))
23339
+ throw new SessionImportChangedError();
23340
+ return value;
23341
+ }
23342
+ function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
23343
+ if (typeof value !== "string")
23344
+ return null;
23345
+ const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
23346
+ if (!normalized)
23347
+ return null;
23348
+ if (normalized.length <= maxLength)
23349
+ return normalized;
23350
+ const characters = [...normalized];
23351
+ if (characters.length <= maxLength)
23352
+ return normalized;
23353
+ return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
23354
+ }
23355
+ function sessionImportCandidate(input) {
23356
+ const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
23357
+ const parsed = harnessSessionImportCandidateSchema.safeParse({
23358
+ nativeSessionId: input.nativeSessionId,
23359
+ cwd: input.cwd,
23360
+ title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
23361
+ updatedAt: Math.floor(time3),
23362
+ // Unknown must stay unknown; only an explicit boolean is a native statement.
23363
+ running: typeof input.running === "boolean" ? input.running : null
23364
+ });
23365
+ return parsed.success ? parsed.data : null;
23366
+ }
23367
+ var SessionImportScope = class {
23368
+ #abort = new AbortController();
23369
+ #options;
23370
+ #pending = /* @__PURE__ */ new Set();
23371
+ constructor(options) {
23372
+ this.#options = options;
23373
+ }
23374
+ #closed() {
23375
+ return {
23376
+ ok: false,
23377
+ error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
23378
+ };
23379
+ }
23380
+ read(operation) {
23381
+ const signal = this.#abort.signal;
23382
+ if (signal.aborted)
23383
+ return Promise.resolve(this.#closed());
23384
+ let started;
23385
+ try {
23386
+ started = operation(signal);
23387
+ } catch (error51) {
23388
+ started = Promise.reject(error51 instanceof Error ? error51 : new Error("Session read failed"));
23389
+ }
23390
+ const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
23391
+ ok: false,
23392
+ error: {
23393
+ code: "unavailable",
23394
+ message: this.#options.unavailableMessage,
23395
+ retryable: true
23396
+ }
23397
+ }).finally(() => this.#pending.delete(request));
23398
+ this.#pending.add(request);
23399
+ return request;
23400
+ }
23401
+ /** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
23402
+ async resolve(operation) {
23403
+ const result = await this.read(operation);
23404
+ if (!result.ok)
23405
+ return result;
23406
+ return result.value ? { ok: true, value: result.value } : {
23407
+ ok: false,
23408
+ error: {
23409
+ code: "sessionNotFound",
23410
+ message: this.#options.notFoundMessage,
23411
+ retryable: false
23412
+ }
23413
+ };
23414
+ }
23415
+ /** Idempotent. Resolves after every started read has settled. */
23416
+ async close() {
23417
+ this.#abort.abort();
23418
+ await Promise.allSettled(this.#pending);
23419
+ }
23420
+ };
23421
+
23422
+ // dist/session-import.js
23423
+ function isRecord5(value) {
23424
+ return typeof value === "object" && value !== null && !Array.isArray(value);
23425
+ }
23426
+ var KimiSessionImport = class {
23427
+ #home;
23428
+ #scope = new SessionImportScope({
23429
+ closedMessage: "Kimi Session import is closed",
23430
+ unavailableMessage: "Kimi sessions could not be read; close native clients, check storage access and retry",
23431
+ notFoundMessage: "Kimi Session is no longer importable"
23432
+ });
23433
+ constructor(options) {
23434
+ this.#home = getKimiCodeHome(options.homeDirectory, options.environment);
23435
+ }
23436
+ listCandidates() {
23437
+ return this.#scope.read(async (signal) => {
23438
+ const candidates = [];
23439
+ for (const nativeSessionId of await this.#indexedSessions(signal)) {
23440
+ try {
23441
+ const source = await this.#source(nativeSessionId, signal);
23442
+ if (source)
23443
+ candidates.push(source.candidate);
23444
+ } catch (error51) {
23445
+ if (!(error51 instanceof SessionImportChangedError))
23446
+ throw error51;
23447
+ }
23448
+ }
23449
+ return candidates;
23450
+ });
23451
+ }
23452
+ resolveCandidate(nativeSessionId) {
23453
+ return this.#scope.resolve(async (signal) => (await this.#indexedSessions(signal)).has(nativeSessionId) ? this.#source(nativeSessionId, signal) : null);
23454
+ }
23455
+ close() {
23456
+ return this.#scope.close();
23457
+ }
23458
+ /** Live identities in Kimi's index. The last record of an identity decides, as in resume. */
23459
+ async #indexedSessions(signal) {
23460
+ const live = /* @__PURE__ */ new Set();
23461
+ let content;
23462
+ try {
23463
+ content = await readFile4(path7.join(this.#home, "session_index.jsonl"), {
23464
+ encoding: "utf8",
23465
+ signal
23466
+ });
23467
+ } catch (error51) {
23468
+ signal.throwIfAborted();
23469
+ if (isMissingFileError(error51))
23470
+ return live;
23471
+ throw error51;
23472
+ }
23473
+ for (const line of content.split("\n")) {
23474
+ if (!line.trim())
23475
+ continue;
23476
+ let entry;
23477
+ try {
23478
+ entry = JSON.parse(line);
23479
+ } catch {
23480
+ continue;
23481
+ }
23482
+ if (!isRecord5(entry) || typeof entry.sessionId !== "string" || !entry.sessionId)
23483
+ continue;
23484
+ if (entry.deleted || typeof entry.sessionDir !== "string")
23485
+ live.delete(entry.sessionId);
23486
+ else
23487
+ live.add(entry.sessionId);
23488
+ }
23489
+ return live;
23490
+ }
23491
+ async #source(nativeSessionId, signal) {
23492
+ signal.throwIfAborted();
23493
+ const options = { kimiCodeHome: this.#home };
23494
+ let located;
23495
+ try {
23496
+ located = await locateKimiSession(nativeSessionId, options);
23497
+ } catch (error51) {
23498
+ if (isStorageAccessError(error51))
23499
+ throw error51;
23500
+ return null;
23501
+ }
23502
+ if (!located)
23503
+ return null;
23504
+ const { state } = located;
23505
+ const files = [
23506
+ path7.join(located.sessionDir, "state.json"),
23507
+ path7.join(located.mainHomeDir, "wire.jsonl")
23508
+ ];
23509
+ return readStableFiles(files, async ([stateInfo, wire]) => {
23510
+ if (!stateInfo?.isFile() || !wire?.isFile())
23511
+ return null;
23512
+ try {
23513
+ if (typeof state.cwd !== "string" || !path7.isAbsolute(state.cwd))
23514
+ return null;
23515
+ const cwd = path7.resolve(state.cwd);
23516
+ if (!(await stat(cwd)).isDirectory())
23517
+ return null;
23518
+ signal.throwIfAborted();
23519
+ const { turns } = await readKimiSessionSnapshot(nativeSessionId, options);
23520
+ const prompt = turns.flatMap((turn) => turn.input).find((input) => input.type === "text" && input.text.trim().length > 0);
23521
+ if (!prompt || prompt.type !== "text")
23522
+ return null;
23523
+ const activity = turns.flatMap((turn) => [turn.completedAtMs, turn.startedAtMs]).filter((time3) => typeof time3 === "number" && Number.isFinite(time3));
23524
+ const candidate = sessionImportCandidate({
23525
+ nativeSessionId,
23526
+ cwd,
23527
+ title: sessionImportTitle(state.title) ?? sessionImportTitle(prompt.text),
23528
+ // Wire record times are milliseconds; the state file's unit is not documented.
23529
+ updatedAt: activity.length > 0 ? Math.max(...activity) : wire.mtimeMs
23530
+ // Kimi has no cross-process activity marker: idleness cannot be established.
23531
+ });
23532
+ return candidate ? { candidate, nativeRef: createKimiNativeSessionRef(nativeSessionId, cwd) } : null;
23533
+ } catch (error51) {
23534
+ signal.throwIfAborted();
23535
+ if (isStorageAccessError(error51))
23536
+ throw error51;
23537
+ return null;
23538
+ }
23539
+ });
23540
+ }
23541
+ };
23542
+
23222
23543
  // dist/kimi-session.js
23223
23544
  import { setTimeout as delay } from "node:timers/promises";
23224
23545
 
23225
23546
  // dist/command-history.js
23226
- import { appendFile, readFile as readFile4, writeFile as writeFile3 } from "node:fs/promises";
23227
- import path7 from "node:path";
23547
+ import { appendFile, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
23548
+ import path8 from "node:path";
23228
23549
  async function readKimiCommandHistory(sessionId, options) {
23229
23550
  const located = await locateKimiSession(sessionId, options);
23230
23551
  if (!located)
23231
23552
  return [];
23232
23553
  let content;
23233
23554
  try {
23234
- content = await readFile4(path7.join(located.sessionDir, "codexhost-commands.jsonl"), "utf8");
23555
+ content = await readFile5(path8.join(located.sessionDir, "codexhost-commands.jsonl"), "utf8");
23235
23556
  } catch (error51) {
23236
23557
  if (error51.code === "ENOENT")
23237
23558
  return [];
@@ -23261,7 +23582,7 @@ async function appendKimiCommandHistory(turn, options) {
23261
23582
  const located = await locateKimiSession(turn.nativeTurnRef.nativeSessionId, options);
23262
23583
  if (!located)
23263
23584
  throw new Error("Cannot persist Kimi command: native session is missing");
23264
- await appendFile(path7.join(located.sessionDir, "codexhost-commands.jsonl"), `${JSON.stringify(turn)}
23585
+ await appendFile(path8.join(located.sessionDir, "codexhost-commands.jsonl"), `${JSON.stringify(turn)}
23265
23586
  `, "utf8");
23266
23587
  }
23267
23588
  async function copyKimiCommandHistory(turns, sessionId, options) {
@@ -23275,7 +23596,7 @@ async function copyKimiCommandHistory(turns, sessionId, options) {
23275
23596
  nativeTurnRef: { ...turn.nativeTurnRef, nativeSessionId: sessionId },
23276
23597
  ...turn.checkpoint ? { checkpoint: { ...turn.checkpoint, nativeSessionId: sessionId } } : {}
23277
23598
  }));
23278
- await writeFile3(path7.join(located.sessionDir, "codexhost-commands.jsonl"), copied.map((turn) => `${JSON.stringify(turn)}
23599
+ await writeFile3(path8.join(located.sessionDir, "codexhost-commands.jsonl"), copied.map((turn) => `${JSON.stringify(turn)}
23279
23600
  `).join(""), "utf8");
23280
23601
  }
23281
23602
 
@@ -24447,6 +24768,7 @@ function stateFromConfig(sessionId, cwd, configOptions) {
24447
24768
  }
24448
24769
  var KimiAdapter = class {
24449
24770
  harnessId = kimiHarnessId3;
24771
+ sessionImport;
24450
24772
  #options;
24451
24773
  #deps;
24452
24774
  #sessions = /* @__PURE__ */ new Set();
@@ -24459,6 +24781,10 @@ var KimiAdapter = class {
24459
24781
  constructor(options = {}, dependencies = {}) {
24460
24782
  this.#options = options;
24461
24783
  this.#deps = dependencies;
24784
+ this.sessionImport = new KimiSessionImport({
24785
+ environment: { ...process.env, ...options.environment },
24786
+ homeDirectory: options.homeDirectory
24787
+ });
24462
24788
  }
24463
24789
  async inspectAccount() {
24464
24790
  if (this.#closed)
@@ -24497,10 +24823,10 @@ var KimiAdapter = class {
24497
24823
  return result;
24498
24824
  }
24499
24825
  const kimiHome2 = getKimiCodeHome(this.#options.homeDirectory, environment);
24500
- const configPath = path8.join(kimiHome2, "config.toml");
24826
+ const configPath = path9.join(kimiHome2, "config.toml");
24501
24827
  let nativeConfig = null;
24502
24828
  try {
24503
- const configContent = await readFile5(configPath, "utf8");
24829
+ const configContent = await readFile6(configPath, "utf8");
24504
24830
  nativeConfig = parseKimiConfigToml(configContent);
24505
24831
  } catch {
24506
24832
  nativeConfig = null;
@@ -24611,10 +24937,10 @@ var KimiAdapter = class {
24611
24937
  onFault: (error51) => session?.handleTransportFault(error51)
24612
24938
  });
24613
24939
  const kimiHome2 = getKimiCodeHome(this.#options.homeDirectory, environment);
24614
- const configPath = path8.join(kimiHome2, "config.toml");
24940
+ const configPath = path9.join(kimiHome2, "config.toml");
24615
24941
  let nativeConfig = null;
24616
24942
  try {
24617
- const configContent = await readFile5(configPath, "utf8");
24943
+ const configContent = await readFile6(configPath, "utf8");
24618
24944
  nativeConfig = parseKimiConfigToml(configContent);
24619
24945
  } catch {
24620
24946
  nativeConfig = null;
@@ -24671,7 +24997,7 @@ var KimiAdapter = class {
24671
24997
  await transport.close().catch(() => void 0);
24672
24998
  return err2("checkpointNotFound", "Kimi Checkpoint does not belong to the source Native Session");
24673
24999
  }
24674
- if (path8.resolve(cwd) !== path8.resolve(located.state.cwd)) {
25000
+ if (path9.resolve(cwd) !== path9.resolve(located.state.cwd)) {
24675
25001
  await transport.close().catch(() => void 0);
24676
25002
  return err2("unsupported", "Kimi Code cannot fork across different working directories");
24677
25003
  }
@@ -24794,7 +25120,7 @@ var KimiAdapter = class {
24794
25120
  const located = await locateKimiSession(sourceId, historyOptions);
24795
25121
  if (!located)
24796
25122
  return err2("sessionNotFound", "Kimi source session was not found");
24797
- if (path8.resolve(input.cwd) !== path8.resolve(located.state.cwd))
25123
+ if (path9.resolve(input.cwd) !== path9.resolve(located.state.cwd))
24798
25124
  return err2("unsupported", "Kimi cannot roll back into another working directory");
24799
25125
  const source = [...this.#sessions].find((candidate) => candidate.initialState.nativeRef?.nativeSessionId === sourceId);
24800
25126
  if (source) {
@@ -24852,6 +25178,7 @@ var KimiAdapter = class {
24852
25178
  return;
24853
25179
  this.#closed = true;
24854
25180
  this.#commandCatalog = KIMI_DEFAULT_COMMAND_CATALOG;
25181
+ await this.sessionImport.close();
24855
25182
  for (const session of this.#sessions) {
24856
25183
  await session.close().catch(() => void 0);
24857
25184
  }
@@ -24860,7 +25187,7 @@ var KimiAdapter = class {
24860
25187
  };
24861
25188
 
24862
25189
  // dist/installation.js
24863
- import { open, readFile as readFile6 } from "node:fs/promises";
25190
+ import { open, readFile as readFile7 } from "node:fs/promises";
24864
25191
  import { homedir as homedir3 } from "node:os";
24865
25192
  import { join as join3 } from "node:path";
24866
25193
  function createKimiInstallation(environment) {
@@ -24883,7 +25210,7 @@ function createKimiInstallation(environment) {
24883
25210
  async check() {
24884
25211
  const currentVersion = versionFromOutput(await run(["--version"]));
24885
25212
  const home = environment.KIMI_CODE_HOME ?? join3(environment.HOME ?? homedir3(), ".kimi-code");
24886
- const region = await readFile6(join3(home, "region"), "utf8").catch(() => "");
25213
+ const region = await readFile7(join3(home, "region"), "utf8").catch(() => "");
24887
25214
  const base = region.trim() === "global" ? "https://code.kimi.ai/kimi-code" : "https://code.kimi.com/kimi-code";
24888
25215
  const latestVersion = installationVersion(await fetchInstallationText(`${base}/latest`));
24889
25216
  const npm = await npmInstallation(executable(), ["@moonshot-ai/kimi-code"], environment);