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

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.
@@ -5,6 +5,488 @@ var __export = (target, all) => {
5
5
  __defProp(target, name, { get: all[name], enumerable: true });
6
6
  };
7
7
 
8
+ // ../../harness-discovery/dist/environment.js
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ function targetPath(platform) {
12
+ return platform === "win32" ? path.win32 : path.posix;
13
+ }
14
+ function environmentValue(environment, name) {
15
+ const lowered = name.toLowerCase();
16
+ for (const [key, value] of Object.entries(environment)) {
17
+ if (key.toLowerCase() === lowered)
18
+ return value;
19
+ }
20
+ return void 0;
21
+ }
22
+ function pathDelimiter(platform) {
23
+ return platform === "win32" ? ";" : ":";
24
+ }
25
+ function pathDirectories(environment, platform) {
26
+ return (environmentValue(environment, "PATH") ?? "").split(pathDelimiter(platform)).map((directory) => directory.trim().replace(/^"|"$/gu, "")).filter(Boolean);
27
+ }
28
+ function executableExtensions(command, platform, environment) {
29
+ if (platform !== "win32")
30
+ return [""];
31
+ if (targetPath(platform).extname(command) !== "")
32
+ return [""];
33
+ return (environmentValue(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean);
34
+ }
35
+ function isExecutableFile(filePath, platform) {
36
+ try {
37
+ fs.accessSync(filePath, platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
38
+ return fs.statSync(filePath).isFile();
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ function subdirectoryNames(directory) {
44
+ try {
45
+ return fs.readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
46
+ } catch {
47
+ return [];
48
+ }
49
+ }
50
+ function newestFirst(names) {
51
+ return [...names].sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
52
+ }
53
+
54
+ // ../../harness-discovery/dist/invocation.js
55
+ import path2 from "node:path";
56
+ function commandInvocation(command, arguments_, environment, platform = process.platform) {
57
+ const extension = path2.win32.extname(command).toLowerCase();
58
+ if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
59
+ return { command, arguments: [...arguments_], windowsVerbatimArguments: false };
60
+ }
61
+ const quote = (value) => `"${value.replaceAll("%", "%%").replaceAll('"', '""')}"`;
62
+ const commandLine = [command, ...arguments_].map(quote).join(" ");
63
+ return {
64
+ command: environmentValue(environment, "ComSpec") ?? "cmd.exe",
65
+ arguments: ["/d", "/v:off", "/s", "/c", `"${commandLine}"`],
66
+ windowsVerbatimArguments: true
67
+ };
68
+ }
69
+
70
+ // ../../harness-discovery/dist/node-runtime.js
71
+ import path3 from "node:path";
72
+ function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
73
+ const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
74
+ const delimiter = platform === "win32" ? ";" : ":";
75
+ const runtimeDirectory = path3.dirname(runtimeExecutable);
76
+ const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
77
+ const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
78
+ if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
79
+ directories.push(runtimeDirectory);
80
+ }
81
+ return { ...environment, [pathKey]: directories.join(delimiter) };
82
+ }
83
+
84
+ // ../../harness-discovery/dist/resolve.js
85
+ import os from "node:os";
86
+
87
+ // ../../harness-discovery/dist/version-managers.js
88
+ function versionManagerBinaryDirectories(context) {
89
+ const { platform, environment, home } = context;
90
+ const list = context.subdirectories ?? subdirectoryNames;
91
+ const pathFlavor = targetPath(platform);
92
+ const value = (name) => environmentValue(environment, name);
93
+ const directories = [];
94
+ const versioned = (root, ...tail) => {
95
+ for (const version2 of newestFirst(list(root))) {
96
+ directories.push(pathFlavor.join(root, version2, ...tail));
97
+ }
98
+ };
99
+ if (platform === "win32") {
100
+ const appData = value("APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming");
101
+ const localAppData = value("LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local");
102
+ versioned(pathFlavor.join(appData, "nvm"));
103
+ versioned(value("FNM_DIR") ?? pathFlavor.join(appData, "fnm", "node-versions"), "installation");
104
+ directories.push(pathFlavor.join(localAppData, "Volta", "bin"));
105
+ directories.push(pathFlavor.join(home, ".bun", "bin"));
106
+ const pnpmHome2 = value("PNPM_HOME");
107
+ if (pnpmHome2)
108
+ directories.push(pnpmHome2);
109
+ directories.push(pathFlavor.join(localAppData, "pnpm"));
110
+ return directories;
111
+ }
112
+ versioned(pathFlavor.join(value("NVM_DIR") ?? pathFlavor.join(home, ".nvm"), "versions", "node"), "bin");
113
+ const fnmRoots = [
114
+ value("FNM_DIR"),
115
+ pathFlavor.join(home, ".local", "share", "fnm"),
116
+ pathFlavor.join(home, "Library", "Application Support", "fnm")
117
+ ].filter((root) => root !== void 0);
118
+ for (const root of fnmRoots) {
119
+ versioned(pathFlavor.join(root, "node-versions"), "installation", "bin");
120
+ }
121
+ const voltaHome = value("VOLTA_HOME") ?? pathFlavor.join(home, ".volta");
122
+ versioned(pathFlavor.join(voltaHome, "tools", "image", "node"), "bin");
123
+ directories.push(pathFlavor.join(voltaHome, "bin"));
124
+ const asdfHome = value("ASDF_DATA_DIR") ?? pathFlavor.join(home, ".asdf");
125
+ versioned(pathFlavor.join(asdfHome, "installs", "nodejs"), "bin");
126
+ directories.push(pathFlavor.join(asdfHome, "shims"));
127
+ const nodenvHome = value("NODENV_ROOT") ?? pathFlavor.join(home, ".nodenv");
128
+ versioned(pathFlavor.join(nodenvHome, "versions"), "bin");
129
+ directories.push(pathFlavor.join(nodenvHome, "shims"));
130
+ versioned(pathFlavor.join(value("N_PREFIX") ?? "/usr/local", "n", "versions", "node"), "bin");
131
+ directories.push(pathFlavor.join(home, ".bun", "bin"));
132
+ const pnpmHome = value("PNPM_HOME");
133
+ if (pnpmHome)
134
+ directories.push(pnpmHome);
135
+ directories.push(pathFlavor.join(home, "Library", "pnpm"));
136
+ directories.push(pathFlavor.join(home, ".local", "share", "pnpm"));
137
+ for (const prefix of ["/opt/homebrew/opt", "/usr/local/opt"]) {
138
+ for (const formula of newestFirst(list(prefix).filter((name) => name.startsWith("node@")))) {
139
+ directories.push(pathFlavor.join(prefix, formula, "bin"));
140
+ }
141
+ }
142
+ return directories;
143
+ }
144
+
145
+ // ../../harness-discovery/dist/resolve.js
146
+ var VERSION_MANAGER_ROOTS = "<version-managers>";
147
+ function installRootExtensions(platform) {
148
+ return platform === "win32" ? [".exe", ".cmd"] : [""];
149
+ }
150
+ function resolveHomeDirectory(input) {
151
+ return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os.homedir();
152
+ }
153
+ function templateVariables(environment, platform, home) {
154
+ const pathFlavor = targetPath(platform);
155
+ return {
156
+ HOME: home,
157
+ USERPROFILE: home,
158
+ APPDATA: environmentValue(environment, "APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming"),
159
+ LOCALAPPDATA: environmentValue(environment, "LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local")
160
+ };
161
+ }
162
+ function joinTemplate(platform, value) {
163
+ const pathFlavor = targetPath(platform);
164
+ const segments = value.split("/");
165
+ const head = segments[0] ?? "";
166
+ const tail = segments.slice(1);
167
+ if (head === "")
168
+ return pathFlavor.join(pathFlavor.sep, ...tail);
169
+ return tail.length === 0 ? head : pathFlavor.join(head, ...tail);
170
+ }
171
+ function expandInstallRoot(template, environment, platform, home) {
172
+ const variables = templateVariables(environment, platform, home);
173
+ let unresolved = false;
174
+ const substituted = template.replace(/^~(?=\/|$)/u, home).replace(/\$\{(\w+)\}/gu, (_match, name) => {
175
+ const value = variables[name] ?? environmentValue(environment, name);
176
+ if (value === void 0 || value === "") {
177
+ unresolved = true;
178
+ return "";
179
+ }
180
+ return value;
181
+ });
182
+ return unresolved ? void 0 : joinTemplate(platform, substituted);
183
+ }
184
+ function installRootDirectories(spec, input, dependencies, platform, home) {
185
+ const templates = (platform === "win32" ? spec.installRoots?.windows : spec.installRoots?.posix) ?? [];
186
+ const directories = [];
187
+ for (const template of templates) {
188
+ if (template === VERSION_MANAGER_ROOTS) {
189
+ directories.push(...versionManagerBinaryDirectories({
190
+ platform,
191
+ environment: input.environment,
192
+ home,
193
+ ...dependencies.subdirectories ? { subdirectories: dependencies.subdirectories } : {}
194
+ }));
195
+ continue;
196
+ }
197
+ const directory = expandInstallRoot(template, input.environment, platform, home);
198
+ if (directory !== void 0)
199
+ directories.push(directory);
200
+ }
201
+ return directories;
202
+ }
203
+ function harnessCandidates(spec, input, dependencies = {}) {
204
+ const platform = input.platform ?? process.platform;
205
+ const pathFlavor = targetPath(platform);
206
+ const configured = input.command ?? (spec.commandEnvironmentVariable ? environmentValue(input.environment, spec.commandEnvironmentVariable) : void 0);
207
+ const command = configured ?? spec.command;
208
+ if (pathFlavor.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
209
+ return [{ candidate: command, source: "configured" }];
210
+ }
211
+ const candidates = [];
212
+ const extensions = executableExtensions(command, platform, input.environment);
213
+ for (const directory of pathDirectories(input.environment, platform)) {
214
+ for (const extension of extensions) {
215
+ candidates.push({
216
+ candidate: pathFlavor.join(directory, command + extension),
217
+ source: "path"
218
+ });
219
+ }
220
+ }
221
+ if (configured !== void 0)
222
+ return candidates;
223
+ const home = resolveHomeDirectory(input);
224
+ for (const directory of installRootDirectories(spec, input, dependencies, platform, home)) {
225
+ for (const extension of installRootExtensions(platform)) {
226
+ candidates.push({
227
+ candidate: pathFlavor.join(directory, spec.command + extension),
228
+ source: "install-root"
229
+ });
230
+ }
231
+ }
232
+ return candidates;
233
+ }
234
+ function resolveHarnessExecutable(spec, input, dependencies = {}) {
235
+ const platform = input.platform ?? process.platform;
236
+ const isExecutable = dependencies.isExecutable ?? ((candidate) => isExecutableFile(candidate, platform));
237
+ const runnable = spec.runnableCandidate ?? ((candidate) => candidate);
238
+ const context = { platform, isExecutable };
239
+ for (const { candidate, source } of harnessCandidates(spec, input, dependencies)) {
240
+ const executable = runnable(candidate, context);
241
+ if (executable !== void 0 && isExecutable(executable))
242
+ return { executable, source };
243
+ }
244
+ return void 0;
245
+ }
246
+
247
+ // ../../harness-discovery/dist/installation.js
248
+ import { execFile } from "node:child_process";
249
+ import { homedir } from "node:os";
250
+ function runInstallationCommand(command, args, environment, timeout = 3e4) {
251
+ const env = withNodeRuntimeOnPath(environment);
252
+ const invocation = /\.[cm]?js$/i.test(command) ? commandInvocation(process.execPath, [command, ...args], env) : commandInvocation(command, args, env);
253
+ return new Promise((resolve, reject) => {
254
+ const child = execFile(invocation.command, invocation.arguments, {
255
+ env,
256
+ cwd: env.HOME ?? env.USERPROFILE ?? homedir(),
257
+ encoding: "utf8",
258
+ timeout,
259
+ killSignal: "SIGKILL",
260
+ maxBuffer: 1024 * 1024,
261
+ windowsHide: true,
262
+ windowsVerbatimArguments: invocation.windowsVerbatimArguments
263
+ }, (error51, stdout, stderr) => {
264
+ if (error51)
265
+ reject(new Error(error51.killed ? "Harness command timed out" : "Harness command failed; check the native installation and retry"));
266
+ else
267
+ resolve((stdout || stderr).trim());
268
+ });
269
+ child.stdin?.end();
270
+ });
271
+ }
272
+ function installationVersion(value) {
273
+ if (typeof value !== "string" || !/^v?\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(value.trim()))
274
+ throw new Error("Harness returned an invalid version");
275
+ return value.trim().replace(/^v/, "");
276
+ }
277
+ function versionFromOutput(output) {
278
+ return installationVersion(output.match(/\b\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?\b/)?.[0]);
279
+ }
280
+ function newerInstallationVersion(current, latest) {
281
+ const a = installationVersion(current).replace(/\+.*/, "");
282
+ const b = installationVersion(latest).replace(/\+.*/, "");
283
+ const coreA = a.replace(/-.*/, "").split(".").map(BigInt);
284
+ const coreB = b.replace(/-.*/, "").split(".").map(BigInt);
285
+ for (let i = 0; i < Math.max(coreA.length, coreB.length); i++) {
286
+ if ((coreA[i] ?? 0n) !== (coreB[i] ?? 0n))
287
+ return (coreB[i] ?? 0n) > (coreA[i] ?? 0n);
288
+ }
289
+ const preA = a.includes("-") ? a.slice(a.indexOf("-") + 1).split(".") : [];
290
+ const preB = b.includes("-") ? b.slice(b.indexOf("-") + 1).split(".") : [];
291
+ if (!preA.length || !preB.length)
292
+ return !!preA.length && !preB.length;
293
+ for (let i = 0; i < Math.max(preA.length, preB.length); i++) {
294
+ const x = preA[i];
295
+ const y = preB[i];
296
+ if (x === y)
297
+ continue;
298
+ if (x === void 0 || y === void 0)
299
+ return x === void 0;
300
+ const numericX = /^\d+$/.test(x);
301
+ const numericY = /^\d+$/.test(y);
302
+ if (numericX && numericY) {
303
+ if (BigInt(x) === BigInt(y))
304
+ continue;
305
+ return BigInt(y) > BigInt(x);
306
+ }
307
+ if (numericX !== numericY)
308
+ return numericX;
309
+ return y > x;
310
+ }
311
+ return false;
312
+ }
313
+ function createInstallationManager(options) {
314
+ let checking;
315
+ let updating;
316
+ const check2 = () => checking ??= options.check().finally(() => {
317
+ checking = void 0;
318
+ });
319
+ return (action) => {
320
+ if (updating)
321
+ return updating;
322
+ if (action === "check")
323
+ return check2();
324
+ updating = (async () => {
325
+ const before = await check2();
326
+ if (!before.updateAvailable)
327
+ return before;
328
+ if (!before.canUpdate)
329
+ throw new Error(before.message ?? "This installation cannot be updated automatically");
330
+ await options.update(before);
331
+ const after = await check2();
332
+ if (after.currentVersion === before.currentVersion)
333
+ throw new Error("The Harness version did not change; check the native updater and retry");
334
+ return after;
335
+ })().finally(() => {
336
+ updating = void 0;
337
+ });
338
+ return updating;
339
+ };
340
+ }
341
+ async function fetchInstallationText(url2) {
342
+ const request = async () => {
343
+ const response = await fetch(url2, { signal: AbortSignal.timeout(15e3) });
344
+ if (!response.ok)
345
+ throw new Error("Could not check the latest Harness version");
346
+ return response.text();
347
+ };
348
+ try {
349
+ return await request();
350
+ } catch (error51) {
351
+ if (error51 instanceof DOMException && (error51.name === "AbortError" || error51.name === "TimeoutError"))
352
+ throw error51;
353
+ return request();
354
+ }
355
+ }
356
+
357
+ // ../../harness-discovery/dist/npm-installation.js
358
+ import { readFile, realpath } from "node:fs/promises";
359
+ import path4 from "node:path";
360
+ function referencesNpmBin(shim, name, bin) {
361
+ if (bin.includes(".."))
362
+ return false;
363
+ const target = `node_modules/${name}/${bin.replace(/^\.\//, "")}`.toLowerCase();
364
+ const text = shim.replaceAll("\\", "/").toLowerCase();
365
+ return text.includes(`%dp0%/${target}"`) || text.includes(`%~dp0/${target}"`);
366
+ }
367
+ async function npmInstallation(command, packages, environment) {
368
+ let selected = await realpath(command);
369
+ if (process.platform === "win32" && /\.(cmd|bat)$/i.test(selected)) {
370
+ const shim = (await readFile(selected, "utf8")).replaceAll("\\", "/");
371
+ const root = path4.dirname(selected);
372
+ for (const name of packages) {
373
+ const directory2 = path4.join(root, "node_modules", ...name.split("/"));
374
+ const metadata = await readFile(path4.join(directory2, "package.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
375
+ const bins = typeof metadata?.bin === "string" ? [metadata.bin] : Object.values(metadata?.bin ?? {});
376
+ const bin = bins.find((entry) => referencesNpmBin(shim, name, entry));
377
+ if (bin) {
378
+ selected = await realpath(path4.join(directory2, bin));
379
+ break;
380
+ }
381
+ }
382
+ }
383
+ let directory = path4.dirname(selected);
384
+ for (let depth = 0; depth < 8; depth++) {
385
+ const metadata = await readFile(path4.join(directory, "package.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
386
+ if (metadata?.name && packages.includes(metadata.name)) {
387
+ const name = metadata.name;
388
+ const currentVersion = installationVersion(metadata.version);
389
+ const segments = name.split("/");
390
+ let modules = directory;
391
+ for (let index = 0; index < segments.length; index++)
392
+ modules = path4.dirname(modules);
393
+ const prefix = process.platform === "win32" ? path4.dirname(modules) : path4.dirname(path4.dirname(modules));
394
+ const globalRoot = process.platform === "win32" ? path4.join(prefix, "node_modules") : path4.join(prefix, "lib", "node_modules");
395
+ const env = withNodeRuntimeOnPath(environment);
396
+ const npm = resolveHarnessExecutable({ id: "npm", command: "npm", installRoots: { posix: [], windows: [] } }, { environment: env });
397
+ let globalInstall = modules === globalRoot;
398
+ if (process.platform === "win32") {
399
+ const project = (await Promise.all(["package.json", "package-lock.json", "npm-shrinkwrap.json"].map((file2) => readFile(path4.join(prefix, file2), "utf8").then(() => true, (error51) => error51.code !== "ENOENT")))).some(Boolean);
400
+ const bins = typeof metadata.bin === "string" ? { [name.split("/").at(-1) ?? name]: metadata.bin } : metadata.bin ?? {};
401
+ const launchers = await Promise.all(Object.entries(bins).map(async ([bin, entry]) => {
402
+ if (path4.basename(bin) !== bin || entry.includes(".."))
403
+ return false;
404
+ const target = await realpath(path4.join(directory, entry)).catch(() => "");
405
+ if (target.toLowerCase() !== selected.toLowerCase())
406
+ return false;
407
+ const shim = await readFile(path4.join(prefix, `${bin}.cmd`), "utf8").catch(() => "");
408
+ return referencesNpmBin(shim, name, entry);
409
+ }));
410
+ globalInstall = globalInstall && !project && launchers.some(Boolean);
411
+ }
412
+ const canUpdate = globalInstall && !!npm;
413
+ return {
414
+ prefix,
415
+ currentVersion,
416
+ canUpdate,
417
+ latest: async () => {
418
+ const data = JSON.parse(await fetchInstallationText(`https://registry.npmjs.org/${encodeURIComponent(name)}/latest`));
419
+ return installationVersion(data.version);
420
+ },
421
+ update: async (version2) => {
422
+ if (!canUpdate || !npm)
423
+ throw new Error("Use the original package manager to update this installation");
424
+ await runInstallationCommand(npm.executable, ["install", "--global", "--prefix", prefix, `${name}@${installationVersion(version2)}`], env, 3e5);
425
+ }
426
+ };
427
+ }
428
+ const parent = path4.dirname(directory);
429
+ if (parent === directory)
430
+ break;
431
+ directory = parent;
432
+ }
433
+ return null;
434
+ }
435
+
436
+ // ../../harness-discovery/dist/installer.js
437
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
438
+ import { tmpdir } from "node:os";
439
+ import { join } from "node:path";
440
+ function createHarnessInstaller(environment, source) {
441
+ return async () => {
442
+ if (!["darwin", "linux", "win32"].includes(process.platform))
443
+ throw new Error("Unsupported installation platform");
444
+ const env = withNodeRuntimeOnPath(environment);
445
+ if ("npm" in source) {
446
+ const npm = resolveHarnessExecutable({
447
+ id: "npm",
448
+ command: "npm",
449
+ installRoots: {
450
+ posix: [
451
+ "~/.npm-global/bin",
452
+ "~/.local/bin",
453
+ VERSION_MANAGER_ROOTS,
454
+ "/opt/homebrew/bin",
455
+ "/usr/local/bin",
456
+ "/usr/bin"
457
+ ],
458
+ windows: [
459
+ "${APPDATA}/npm",
460
+ VERSION_MANAGER_ROOTS,
461
+ "${ProgramFiles}/nodejs",
462
+ "${LOCALAPPDATA}/Programs/nodejs"
463
+ ]
464
+ }
465
+ }, { environment: env });
466
+ if (!npm)
467
+ throw new Error("Install Node.js and npm first");
468
+ await runInstallationCommand(npm.executable, ["install", "--global", source.npm], {
469
+ ...env,
470
+ ...source.allowScripts ? { npm_config_allow_scripts: source.allowScripts } : {}
471
+ }, 6e5);
472
+ return;
473
+ }
474
+ const windows = process.platform === "win32";
475
+ const url2 = windows ? source.windows : source.posix;
476
+ if (new URL(url2).protocol !== "https:")
477
+ throw new Error("Installer requires HTTPS");
478
+ const script = await fetchInstallationText(url2);
479
+ const directory = await mkdtemp(join(tmpdir(), "codexhost-installer-"));
480
+ try {
481
+ const file2 = join(directory, windows ? "install.ps1" : "install.sh");
482
+ await writeFile(file2, script, { mode: 384 });
483
+ await runInstallationCommand(windows ? "powershell.exe" : source.shell ?? "bash", windows ? ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", file2] : [file2], env, 6e5);
484
+ } finally {
485
+ await rm(directory, { recursive: true, force: true });
486
+ }
487
+ };
488
+ }
489
+
8
490
  // dist/kimi-adapter.js
9
491
  import { readFile as readFile5 } from "node:fs/promises";
10
492
  import path8 from "node:path";
@@ -14594,6 +15076,71 @@ var harnessDisplaySetSchema = external_exports.strictObject({
14594
15076
  initializeOnly: external_exports.boolean().optional()
14595
15077
  });
14596
15078
 
15079
+ // ../../shared-contracts/dist/ids.js
15080
+ var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
15081
+ message: "Identifier must not be empty or whitespace"
15082
+ });
15083
+ var harnessIdSchema = opaqueIdSchema.brand();
15084
+ var hostThreadIdSchema = opaqueIdSchema.brand();
15085
+ var hostTurnIdSchema = opaqueIdSchema.brand();
15086
+ var hostItemIdSchema = opaqueIdSchema.brand();
15087
+ var hostInteractionIdSchema = opaqueIdSchema.brand();
15088
+
15089
+ // ../../shared-contracts/dist/harness-plugins.js
15090
+ var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15091
+ var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
15092
+ var HARNESS_PLUGIN_LIMIT = 128;
15093
+ var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id) => id !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
15094
+ var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
15095
+ var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
15096
+ var pluginPresentationShape = {
15097
+ id: harnessPluginIdSchema,
15098
+ name: external_exports.string().trim().min(1).max(128),
15099
+ version: external_exports.string().min(1).max(128),
15100
+ /** The factory accepts a persisted local entrypoint through its construction context. */
15101
+ launchCommand: external_exports.literal(true).optional(),
15102
+ links: external_exports.object({
15103
+ documentation: documentationUrlSchema.optional(),
15104
+ installation: documentationUrlSchema.optional()
15105
+ }).strict().optional()
15106
+ };
15107
+ var harnessPluginManifestSchema = external_exports.object({
15108
+ manifestVersion: external_exports.literal(1),
15109
+ ...pluginPresentationShape,
15110
+ adapterApiVersion: external_exports.number().int().positive(),
15111
+ entry: relativeResourceSchema,
15112
+ icon: relativeResourceSchema.optional()
15113
+ }).strict();
15114
+ var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
15115
+ var harnessPluginDescriptorSchema = external_exports.object({
15116
+ ...pluginPresentationShape,
15117
+ icon: harnessPluginIconSchema.optional()
15118
+ }).strict();
15119
+ var harnessPluginListParamsSchema = external_exports.object({}).strict();
15120
+ var harnessPluginListResultSchema = external_exports.object({
15121
+ plugins: external_exports.array(harnessPluginDescriptorSchema).max(HARNESS_PLUGIN_LIMIT)
15122
+ }).strict();
15123
+ var harnessPluginConfigurationSchema = external_exports.object({
15124
+ version: external_exports.literal(1),
15125
+ enabled: external_exports.array(harnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
15126
+ }).strict().refine((value) => new Set(value.enabled).size === value.enabled.length, {
15127
+ message: "Enabled plugin IDs must be unique",
15128
+ path: ["enabled"]
15129
+ });
15130
+
15131
+ // ../../shared-contracts/dist/harness-long-context.js
15132
+ var HARNESS_LONG_CONTEXT_GET_METHOD = "codexhost/harness/long-context/get";
15133
+ var HARNESS_LONG_CONTEXT_SET_METHOD = "codexhost/harness/long-context/set";
15134
+ var harnessLongContextGetSchema = external_exports.object({
15135
+ harnessId: harnessPluginIdSchema
15136
+ }).strict();
15137
+ var harnessLongContextSetSchema = harnessLongContextGetSchema.extend({
15138
+ enabled: external_exports.boolean()
15139
+ });
15140
+ var harnessLongContextSchema = external_exports.object({
15141
+ enabled: external_exports.boolean()
15142
+ }).strict();
15143
+
14597
15144
  // ../../shared-contracts/dist/console.js
14598
15145
  var consoleAnnouncementSchema = external_exports.strictObject({
14599
15146
  title: external_exports.string().trim().min(1).max(200),
@@ -14610,8 +15157,11 @@ var CONSOLE_HOST_METHODS = Object.freeze([
14610
15157
  "codexhost/harness/display-settings/get",
14611
15158
  "codexhost/harness/display-settings/set",
14612
15159
  "codexhost/harness/inspect",
15160
+ "codexhost/harness/installation",
14613
15161
  "codexhost/harness/launch-settings/get",
14614
15162
  "codexhost/harness/launch-settings/set",
15163
+ HARNESS_LONG_CONTEXT_GET_METHOD,
15164
+ HARNESS_LONG_CONTEXT_SET_METHOD,
14615
15165
  "codexhost/harness/web-ui/open",
14616
15166
  "codexhost/harness/accounts/sources",
14617
15167
  "codexhost/harness/accounts/list",
@@ -14671,16 +15221,6 @@ var loadedSessionsSchema = external_exports.array(external_exports.strictObject(
14671
15221
  inactiveMs: external_exports.number().nonnegative()
14672
15222
  }));
14673
15223
 
14674
- // ../../shared-contracts/dist/ids.js
14675
- var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
14676
- message: "Identifier must not be empty or whitespace"
14677
- });
14678
- var harnessIdSchema = opaqueIdSchema.brand();
14679
- var hostThreadIdSchema = opaqueIdSchema.brand();
14680
- var hostTurnIdSchema = opaqueIdSchema.brand();
14681
- var hostItemIdSchema = opaqueIdSchema.brand();
14682
- var hostInteractionIdSchema = opaqueIdSchema.brand();
14683
-
14684
15224
  // ../../shared-contracts/dist/manual-compaction.js
14685
15225
  var threadManualCompactionStartedSchema = external_exports.strictObject({
14686
15226
  threadId: hostThreadIdSchema,
@@ -15177,79 +15717,37 @@ var threadOwnershipListParamsSchema = external_exports.object({
15177
15717
  message: "Thread ownership-list IDs must be unique",
15178
15718
  path: ["threadIds", index]
15179
15719
  });
15180
- }
15181
- seen.add(threadId);
15182
- }
15183
- });
15184
- var codexThreadOwnershipSchema = external_exports.object({
15185
- threadId: hostThreadIdSchema,
15186
- owner: external_exports.literal("codex")
15187
- }).strict();
15188
- var externalThreadOwnershipSchema = external_exports.object({
15189
- threadId: hostThreadIdSchema,
15190
- owner: external_exports.literal("external"),
15191
- harnessId: external_exports.string().max(256).pipe(harnessIdSchema)
15192
- }).strict();
15193
- var threadOwnershipSchema = external_exports.discriminatedUnion("owner", [
15194
- codexThreadOwnershipSchema,
15195
- externalThreadOwnershipSchema
15196
- ]);
15197
- var threadOwnershipListResultSchema = external_exports.object({
15198
- threads: external_exports.array(threadOwnershipSchema).min(1).max(THREAD_OWNERSHIP_LIST_MAX_LENGTH)
15199
- }).strict().superRefine(({ threads }, context) => {
15200
- const seen = /* @__PURE__ */ new Set();
15201
- for (const [index, thread] of threads.entries()) {
15202
- if (seen.has(thread.threadId)) {
15203
- context.addIssue({
15204
- code: "custom",
15205
- message: "Thread ownership-list results must be unique",
15206
- path: ["threads", index, "threadId"]
15207
- });
15208
- }
15209
- seen.add(thread.threadId);
15210
- }
15211
- });
15212
-
15213
- // ../../shared-contracts/dist/harness-plugins.js
15214
- var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15215
- var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
15216
- var HARNESS_PLUGIN_LIMIT = 128;
15217
- var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id) => id !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
15218
- var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
15219
- var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
15220
- var pluginPresentationShape = {
15221
- id: harnessPluginIdSchema,
15222
- name: external_exports.string().trim().min(1).max(128),
15223
- version: external_exports.string().min(1).max(128),
15224
- /** The factory accepts a persisted local entrypoint through its construction context. */
15225
- launchCommand: external_exports.literal(true).optional(),
15226
- links: external_exports.object({
15227
- documentation: documentationUrlSchema.optional(),
15228
- installation: documentationUrlSchema.optional()
15229
- }).strict().optional()
15230
- };
15231
- var harnessPluginManifestSchema = external_exports.object({
15232
- manifestVersion: external_exports.literal(1),
15233
- ...pluginPresentationShape,
15234
- adapterApiVersion: external_exports.number().int().positive(),
15235
- entry: relativeResourceSchema,
15236
- icon: relativeResourceSchema.optional()
15237
- }).strict();
15238
- var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
15239
- var harnessPluginDescriptorSchema = external_exports.object({
15240
- ...pluginPresentationShape,
15241
- icon: harnessPluginIconSchema.optional()
15720
+ }
15721
+ seen.add(threadId);
15722
+ }
15723
+ });
15724
+ var codexThreadOwnershipSchema = external_exports.object({
15725
+ threadId: hostThreadIdSchema,
15726
+ owner: external_exports.literal("codex")
15242
15727
  }).strict();
15243
- var harnessPluginListParamsSchema = external_exports.object({}).strict();
15244
- var harnessPluginListResultSchema = external_exports.object({
15245
- plugins: external_exports.array(harnessPluginDescriptorSchema).max(HARNESS_PLUGIN_LIMIT)
15728
+ var externalThreadOwnershipSchema = external_exports.object({
15729
+ threadId: hostThreadIdSchema,
15730
+ owner: external_exports.literal("external"),
15731
+ harnessId: external_exports.string().max(256).pipe(harnessIdSchema)
15246
15732
  }).strict();
15247
- var harnessPluginConfigurationSchema = external_exports.object({
15248
- version: external_exports.literal(1),
15249
- enabled: external_exports.array(harnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
15250
- }).strict().refine((value) => new Set(value.enabled).size === value.enabled.length, {
15251
- message: "Enabled plugin IDs must be unique",
15252
- path: ["enabled"]
15733
+ var threadOwnershipSchema = external_exports.discriminatedUnion("owner", [
15734
+ codexThreadOwnershipSchema,
15735
+ externalThreadOwnershipSchema
15736
+ ]);
15737
+ var threadOwnershipListResultSchema = external_exports.object({
15738
+ threads: external_exports.array(threadOwnershipSchema).min(1).max(THREAD_OWNERSHIP_LIST_MAX_LENGTH)
15739
+ }).strict().superRefine(({ threads }, context) => {
15740
+ const seen = /* @__PURE__ */ new Set();
15741
+ for (const [index, thread] of threads.entries()) {
15742
+ if (seen.has(thread.threadId)) {
15743
+ context.addIssue({
15744
+ code: "custom",
15745
+ message: "Thread ownership-list results must be unique",
15746
+ path: ["threads", index, "threadId"]
15747
+ });
15748
+ }
15749
+ seen.add(thread.threadId);
15750
+ }
15253
15751
  });
15254
15752
 
15255
15753
  // ../../shared-contracts/dist/harness-route.js
@@ -15276,14 +15774,17 @@ var harnessLaunchSettingsSchema = external_exports.object({
15276
15774
  // ../../shared-contracts/dist/harness-installation.js
15277
15775
  var harnessInstallationParamsSchema = external_exports.object({
15278
15776
  harnessId: harnessIdSchema,
15279
- action: external_exports.enum(["check", "update"])
15777
+ action: external_exports.enum(["check", "update", "install"])
15280
15778
  }).strict();
15281
15779
  var harnessInstallationStateSchema = external_exports.object({
15282
15780
  currentVersion: external_exports.string().min(1).max(128),
15283
15781
  latestVersion: external_exports.string().min(1).max(128),
15284
15782
  updateAvailable: external_exports.boolean(),
15285
15783
  canUpdate: external_exports.boolean(),
15286
- message: external_exports.string().max(2048).optional()
15784
+ // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
15785
+ message: external_exports.string().max(2048).optional(),
15786
+ messageCode: external_exports.string().min(1).max(128).optional(),
15787
+ latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
15287
15788
  }).strict();
15288
15789
 
15289
15790
  // ../../shared-contracts/dist/codex-accounts.js
@@ -15578,7 +16079,7 @@ var updateStatusSchema = external_exports.strictObject({
15578
16079
  }
15579
16080
  });
15580
16081
  var updateEmptyParamsSchema = external_exports.strictObject({});
15581
- var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/LiberSeek\/BOFT-CLI\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
16082
+ var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/(LiberSeek|LIBERSEEK)\/BOFT-CLI\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
15582
16083
  var updateCheckResultSchema = external_exports.strictObject({
15583
16084
  currentVersion: updateSemanticVersionSchema,
15584
16085
  installation: updateInstallationSchema.nullable(),
@@ -19799,601 +20300,171 @@ var ClientSideConnection = class {
19799
20300
  return this.connection.sendRequest(AGENT_METHODS.nes_start, params);
19800
20301
  }
19801
20302
  /**
19802
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19803
- *
19804
- * Sends a NES suggestion request.
19805
- *
19806
- * @experimental
19807
- */
19808
- unstable_suggestNes(params) {
19809
- return this.connection.sendRequest(AGENT_METHODS.nes_suggest, params);
19810
- }
19811
- /**
19812
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19813
- *
19814
- * Closes a NES session.
19815
- *
19816
- * @experimental
19817
- */
19818
- unstable_closeNes(params) {
19819
- return this.connection.sendRequest(AGENT_METHODS.nes_close, params, emptyObjectResponse);
19820
- }
19821
- /**
19822
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19823
- *
19824
- * Notifies the agent that a document was opened.
19825
- *
19826
- * @experimental
19827
- */
19828
- unstable_didOpenDocument(params) {
19829
- return this.connection.sendNotification(AGENT_METHODS.document_did_open, params);
19830
- }
19831
- /**
19832
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19833
- *
19834
- * Notifies the agent that a document was changed.
19835
- *
19836
- * @experimental
19837
- */
19838
- unstable_didChangeDocument(params) {
19839
- return this.connection.sendNotification(AGENT_METHODS.document_did_change, params);
19840
- }
19841
- /**
19842
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19843
- *
19844
- * Notifies the agent that a document was closed.
19845
- *
19846
- * @experimental
19847
- */
19848
- unstable_didCloseDocument(params) {
19849
- return this.connection.sendNotification(AGENT_METHODS.document_did_close, params);
19850
- }
19851
- /**
19852
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19853
- *
19854
- * Notifies the agent that a document was saved.
19855
- *
19856
- * @experimental
19857
- */
19858
- unstable_didSaveDocument(params) {
19859
- return this.connection.sendNotification(AGENT_METHODS.document_did_save, params);
19860
- }
19861
- /**
19862
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19863
- *
19864
- * Notifies the agent that a document received focus.
19865
- *
19866
- * @experimental
19867
- */
19868
- unstable_didFocusDocument(params) {
19869
- return this.connection.sendNotification(AGENT_METHODS.document_did_focus, params);
19870
- }
19871
- /**
19872
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19873
- *
19874
- * Notifies the agent that a NES suggestion was accepted.
19875
- *
19876
- * @experimental
19877
- */
19878
- unstable_acceptNes(params) {
19879
- return this.connection.sendNotification(AGENT_METHODS.nes_accept, params);
19880
- }
19881
- /**
19882
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
19883
- *
19884
- * Notifies the agent that a NES suggestion was rejected.
19885
- *
19886
- * @experimental
19887
- */
19888
- unstable_rejectNes(params) {
19889
- return this.connection.sendNotification(AGENT_METHODS.nes_reject, params);
19890
- }
19891
- request(method, params, options) {
19892
- const spec = agentRequestSpecsByMethod[method];
19893
- return this.connection.sendRequest(method, params, spec?.mapResponse, options);
19894
- }
19895
- notify(method, params) {
19896
- return this.connection.sendNotification(method, params);
19897
- }
19898
- /**
19899
- * Extension method.
19900
- *
19901
- * @deprecated Use {@link request}.
19902
- */
19903
- extMethod(method, params) {
19904
- return this.request(method, params);
19905
- }
19906
- /**
19907
- * Extension notification.
19908
- *
19909
- * @deprecated Use {@link notify}.
19910
- */
19911
- extNotification(method, params) {
19912
- return this.notify(method, params);
19913
- }
19914
- /**
19915
- * AbortSignal that aborts when the connection closes.
19916
- *
19917
- * This signal can be used to:
19918
- * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
19919
- * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
19920
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
19921
- *
19922
- * The connection closes when the underlying stream ends, either normally or due to an error.
19923
- *
19924
- * @example
19925
- * ```typescript
19926
- * const connection = new ClientSideConnection(client, stream);
19927
- *
19928
- * // Listen for closure
19929
- * connection.signal.addEventListener('abort', () => {
19930
- * console.log('Connection closed - performing cleanup');
19931
- * });
19932
- *
19933
- * // Check status
19934
- * if (connection.signal.aborted) {
19935
- * console.log('Connection is already closed');
19936
- * }
19937
- *
19938
- * // Pass to other APIs
19939
- * fetch(url, { signal: connection.signal });
19940
- * ```
19941
- */
19942
- get signal() {
19943
- return this.connection.signal;
19944
- }
19945
- /**
19946
- * Promise that resolves when the connection closes.
19947
- *
19948
- * The connection closes when the underlying stream ends, either normally or due to an error.
19949
- * Once closed, the connection cannot send or receive any more messages.
19950
- *
19951
- * This is useful for async/await style cleanup:
19952
- *
19953
- * @example
19954
- * ```typescript
19955
- * const connection = new ClientSideConnection(client, stream);
19956
- * await connection.closed;
19957
- * console.log('Connection closed - performing cleanup');
19958
- * ```
19959
- */
19960
- get closed() {
19961
- return this.connection.closed;
19962
- }
19963
- };
19964
-
19965
- // dist/command.js
19966
- import path5 from "node:path";
19967
-
19968
- // ../../harness-discovery/dist/environment.js
19969
- import fs from "node:fs";
19970
- import path from "node:path";
19971
- function targetPath(platform) {
19972
- return platform === "win32" ? path.win32 : path.posix;
19973
- }
19974
- function environmentValue(environment, name) {
19975
- const lowered = name.toLowerCase();
19976
- for (const [key, value] of Object.entries(environment)) {
19977
- if (key.toLowerCase() === lowered)
19978
- return value;
19979
- }
19980
- return void 0;
19981
- }
19982
- function pathDelimiter(platform) {
19983
- return platform === "win32" ? ";" : ":";
19984
- }
19985
- function pathDirectories(environment, platform) {
19986
- return (environmentValue(environment, "PATH") ?? "").split(pathDelimiter(platform)).map((directory) => directory.trim().replace(/^"|"$/gu, "")).filter(Boolean);
19987
- }
19988
- function executableExtensions(command, platform, environment) {
19989
- if (platform !== "win32")
19990
- return [""];
19991
- if (targetPath(platform).extname(command) !== "")
19992
- return [""];
19993
- return (environmentValue(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean);
19994
- }
19995
- function isExecutableFile(filePath, platform) {
19996
- try {
19997
- fs.accessSync(filePath, platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
19998
- return fs.statSync(filePath).isFile();
19999
- } catch {
20000
- return false;
20001
- }
20002
- }
20003
- function subdirectoryNames(directory) {
20004
- try {
20005
- return fs.readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
20006
- } catch {
20007
- return [];
20008
- }
20009
- }
20010
- function newestFirst(names) {
20011
- return [...names].sort((left, right) => right.localeCompare(left, void 0, { numeric: true }));
20012
- }
20013
-
20014
- // ../../harness-discovery/dist/invocation.js
20015
- import path2 from "node:path";
20016
- function commandInvocation(command, arguments_, environment, platform = process.platform) {
20017
- const extension = path2.win32.extname(command).toLowerCase();
20018
- if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
20019
- return { command, arguments: [...arguments_], windowsVerbatimArguments: false };
20303
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20304
+ *
20305
+ * Sends a NES suggestion request.
20306
+ *
20307
+ * @experimental
20308
+ */
20309
+ unstable_suggestNes(params) {
20310
+ return this.connection.sendRequest(AGENT_METHODS.nes_suggest, params);
20020
20311
  }
20021
- const quote = (value) => `"${value.replaceAll("%", "%%").replaceAll('"', '""')}"`;
20022
- const commandLine = [command, ...arguments_].map(quote).join(" ");
20023
- return {
20024
- command: environmentValue(environment, "ComSpec") ?? "cmd.exe",
20025
- arguments: ["/d", "/v:off", "/s", "/c", `"${commandLine}"`],
20026
- windowsVerbatimArguments: true
20027
- };
20028
- }
20029
-
20030
- // ../../harness-discovery/dist/node-runtime.js
20031
- import path3 from "node:path";
20032
- function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
20033
- const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
20034
- const delimiter = platform === "win32" ? ";" : ":";
20035
- const runtimeDirectory = path3.dirname(runtimeExecutable);
20036
- const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
20037
- const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
20038
- if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
20039
- directories.push(runtimeDirectory);
20312
+ /**
20313
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20314
+ *
20315
+ * Closes a NES session.
20316
+ *
20317
+ * @experimental
20318
+ */
20319
+ unstable_closeNes(params) {
20320
+ return this.connection.sendRequest(AGENT_METHODS.nes_close, params, emptyObjectResponse);
20040
20321
  }
20041
- return { ...environment, [pathKey]: directories.join(delimiter) };
20042
- }
20043
-
20044
- // ../../harness-discovery/dist/resolve.js
20045
- import os from "node:os";
20046
-
20047
- // ../../harness-discovery/dist/version-managers.js
20048
- function versionManagerBinaryDirectories(context) {
20049
- const { platform, environment, home } = context;
20050
- const list = context.subdirectories ?? subdirectoryNames;
20051
- const pathFlavor = targetPath(platform);
20052
- const value = (name) => environmentValue(environment, name);
20053
- const directories = [];
20054
- const versioned = (root, ...tail) => {
20055
- for (const version2 of newestFirst(list(root))) {
20056
- directories.push(pathFlavor.join(root, version2, ...tail));
20057
- }
20058
- };
20059
- if (platform === "win32") {
20060
- const appData = value("APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming");
20061
- const localAppData = value("LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local");
20062
- versioned(pathFlavor.join(appData, "nvm"));
20063
- versioned(value("FNM_DIR") ?? pathFlavor.join(appData, "fnm", "node-versions"), "installation");
20064
- directories.push(pathFlavor.join(localAppData, "Volta", "bin"));
20065
- directories.push(pathFlavor.join(home, ".bun", "bin"));
20066
- const pnpmHome2 = value("PNPM_HOME");
20067
- if (pnpmHome2)
20068
- directories.push(pnpmHome2);
20069
- directories.push(pathFlavor.join(localAppData, "pnpm"));
20070
- return directories;
20322
+ /**
20323
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20324
+ *
20325
+ * Notifies the agent that a document was opened.
20326
+ *
20327
+ * @experimental
20328
+ */
20329
+ unstable_didOpenDocument(params) {
20330
+ return this.connection.sendNotification(AGENT_METHODS.document_did_open, params);
20071
20331
  }
20072
- versioned(pathFlavor.join(value("NVM_DIR") ?? pathFlavor.join(home, ".nvm"), "versions", "node"), "bin");
20073
- const fnmRoots = [
20074
- value("FNM_DIR"),
20075
- pathFlavor.join(home, ".local", "share", "fnm"),
20076
- pathFlavor.join(home, "Library", "Application Support", "fnm")
20077
- ].filter((root) => root !== void 0);
20078
- for (const root of fnmRoots) {
20079
- versioned(pathFlavor.join(root, "node-versions"), "installation", "bin");
20332
+ /**
20333
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20334
+ *
20335
+ * Notifies the agent that a document was changed.
20336
+ *
20337
+ * @experimental
20338
+ */
20339
+ unstable_didChangeDocument(params) {
20340
+ return this.connection.sendNotification(AGENT_METHODS.document_did_change, params);
20080
20341
  }
20081
- const voltaHome = value("VOLTA_HOME") ?? pathFlavor.join(home, ".volta");
20082
- versioned(pathFlavor.join(voltaHome, "tools", "image", "node"), "bin");
20083
- directories.push(pathFlavor.join(voltaHome, "bin"));
20084
- const asdfHome = value("ASDF_DATA_DIR") ?? pathFlavor.join(home, ".asdf");
20085
- versioned(pathFlavor.join(asdfHome, "installs", "nodejs"), "bin");
20086
- directories.push(pathFlavor.join(asdfHome, "shims"));
20087
- const nodenvHome = value("NODENV_ROOT") ?? pathFlavor.join(home, ".nodenv");
20088
- versioned(pathFlavor.join(nodenvHome, "versions"), "bin");
20089
- directories.push(pathFlavor.join(nodenvHome, "shims"));
20090
- versioned(pathFlavor.join(value("N_PREFIX") ?? "/usr/local", "n", "versions", "node"), "bin");
20091
- directories.push(pathFlavor.join(home, ".bun", "bin"));
20092
- const pnpmHome = value("PNPM_HOME");
20093
- if (pnpmHome)
20094
- directories.push(pnpmHome);
20095
- directories.push(pathFlavor.join(home, "Library", "pnpm"));
20096
- directories.push(pathFlavor.join(home, ".local", "share", "pnpm"));
20097
- for (const prefix of ["/opt/homebrew/opt", "/usr/local/opt"]) {
20098
- for (const formula of newestFirst(list(prefix).filter((name) => name.startsWith("node@")))) {
20099
- directories.push(pathFlavor.join(prefix, formula, "bin"));
20100
- }
20342
+ /**
20343
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20344
+ *
20345
+ * Notifies the agent that a document was closed.
20346
+ *
20347
+ * @experimental
20348
+ */
20349
+ unstable_didCloseDocument(params) {
20350
+ return this.connection.sendNotification(AGENT_METHODS.document_did_close, params);
20101
20351
  }
20102
- return directories;
20103
- }
20104
-
20105
- // ../../harness-discovery/dist/resolve.js
20106
- var VERSION_MANAGER_ROOTS = "<version-managers>";
20107
- function installRootExtensions(platform) {
20108
- return platform === "win32" ? [".exe", ".cmd"] : [""];
20109
- }
20110
- function resolveHomeDirectory(input) {
20111
- return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os.homedir();
20112
- }
20113
- function templateVariables(environment, platform, home) {
20114
- const pathFlavor = targetPath(platform);
20115
- return {
20116
- HOME: home,
20117
- USERPROFILE: home,
20118
- APPDATA: environmentValue(environment, "APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming"),
20119
- LOCALAPPDATA: environmentValue(environment, "LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local")
20120
- };
20121
- }
20122
- function joinTemplate(platform, value) {
20123
- const pathFlavor = targetPath(platform);
20124
- const segments = value.split("/");
20125
- const head = segments[0] ?? "";
20126
- const tail = segments.slice(1);
20127
- if (head === "")
20128
- return pathFlavor.join(pathFlavor.sep, ...tail);
20129
- return tail.length === 0 ? head : pathFlavor.join(head, ...tail);
20130
- }
20131
- function expandInstallRoot(template, environment, platform, home) {
20132
- const variables = templateVariables(environment, platform, home);
20133
- let unresolved = false;
20134
- const substituted = template.replace(/^~(?=\/|$)/u, home).replace(/\$\{(\w+)\}/gu, (_match, name) => {
20135
- const value = variables[name] ?? environmentValue(environment, name);
20136
- if (value === void 0 || value === "") {
20137
- unresolved = true;
20138
- return "";
20139
- }
20140
- return value;
20141
- });
20142
- return unresolved ? void 0 : joinTemplate(platform, substituted);
20143
- }
20144
- function installRootDirectories(spec, input, dependencies, platform, home) {
20145
- const templates = (platform === "win32" ? spec.installRoots?.windows : spec.installRoots?.posix) ?? [];
20146
- const directories = [];
20147
- for (const template of templates) {
20148
- if (template === VERSION_MANAGER_ROOTS) {
20149
- directories.push(...versionManagerBinaryDirectories({
20150
- platform,
20151
- environment: input.environment,
20152
- home,
20153
- ...dependencies.subdirectories ? { subdirectories: dependencies.subdirectories } : {}
20154
- }));
20155
- continue;
20156
- }
20157
- const directory = expandInstallRoot(template, input.environment, platform, home);
20158
- if (directory !== void 0)
20159
- directories.push(directory);
20352
+ /**
20353
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20354
+ *
20355
+ * Notifies the agent that a document was saved.
20356
+ *
20357
+ * @experimental
20358
+ */
20359
+ unstable_didSaveDocument(params) {
20360
+ return this.connection.sendNotification(AGENT_METHODS.document_did_save, params);
20160
20361
  }
20161
- return directories;
20162
- }
20163
- function harnessCandidates(spec, input, dependencies = {}) {
20164
- const platform = input.platform ?? process.platform;
20165
- const pathFlavor = targetPath(platform);
20166
- const configured = input.command ?? (spec.commandEnvironmentVariable ? environmentValue(input.environment, spec.commandEnvironmentVariable) : void 0);
20167
- const command = configured ?? spec.command;
20168
- if (pathFlavor.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
20169
- return [{ candidate: command, source: "configured" }];
20362
+ /**
20363
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20364
+ *
20365
+ * Notifies the agent that a document received focus.
20366
+ *
20367
+ * @experimental
20368
+ */
20369
+ unstable_didFocusDocument(params) {
20370
+ return this.connection.sendNotification(AGENT_METHODS.document_did_focus, params);
20170
20371
  }
20171
- const candidates = [];
20172
- const extensions = executableExtensions(command, platform, input.environment);
20173
- for (const directory of pathDirectories(input.environment, platform)) {
20174
- for (const extension of extensions) {
20175
- candidates.push({
20176
- candidate: pathFlavor.join(directory, command + extension),
20177
- source: "path"
20178
- });
20179
- }
20372
+ /**
20373
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20374
+ *
20375
+ * Notifies the agent that a NES suggestion was accepted.
20376
+ *
20377
+ * @experimental
20378
+ */
20379
+ unstable_acceptNes(params) {
20380
+ return this.connection.sendNotification(AGENT_METHODS.nes_accept, params);
20180
20381
  }
20181
- if (configured !== void 0)
20182
- return candidates;
20183
- const home = resolveHomeDirectory(input);
20184
- for (const directory of installRootDirectories(spec, input, dependencies, platform, home)) {
20185
- for (const extension of installRootExtensions(platform)) {
20186
- candidates.push({
20187
- candidate: pathFlavor.join(directory, spec.command + extension),
20188
- source: "install-root"
20189
- });
20190
- }
20382
+ /**
20383
+ * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
20384
+ *
20385
+ * Notifies the agent that a NES suggestion was rejected.
20386
+ *
20387
+ * @experimental
20388
+ */
20389
+ unstable_rejectNes(params) {
20390
+ return this.connection.sendNotification(AGENT_METHODS.nes_reject, params);
20191
20391
  }
20192
- return candidates;
20193
- }
20194
- function resolveHarnessExecutable(spec, input, dependencies = {}) {
20195
- const platform = input.platform ?? process.platform;
20196
- const isExecutable = dependencies.isExecutable ?? ((candidate) => isExecutableFile(candidate, platform));
20197
- const runnable = spec.runnableCandidate ?? ((candidate) => candidate);
20198
- const context = { platform, isExecutable };
20199
- for (const { candidate, source } of harnessCandidates(spec, input, dependencies)) {
20200
- const executable = runnable(candidate, context);
20201
- if (executable !== void 0 && isExecutable(executable))
20202
- return { executable, source };
20392
+ request(method, params, options) {
20393
+ const spec = agentRequestSpecsByMethod[method];
20394
+ return this.connection.sendRequest(method, params, spec?.mapResponse, options);
20203
20395
  }
20204
- return void 0;
20205
- }
20206
-
20207
- // ../../harness-discovery/dist/installation.js
20208
- import { execFile } from "node:child_process";
20209
- import { homedir } from "node:os";
20210
- function runInstallationCommand(command, args, environment, timeout = 3e4) {
20211
- const env = withNodeRuntimeOnPath(environment);
20212
- const invocation = /\.[cm]?js$/i.test(command) ? commandInvocation(process.execPath, [command, ...args], env) : commandInvocation(command, args, env);
20213
- return new Promise((resolve, reject) => {
20214
- const child = execFile(invocation.command, invocation.arguments, {
20215
- env,
20216
- cwd: env.HOME ?? env.USERPROFILE ?? homedir(),
20217
- encoding: "utf8",
20218
- timeout,
20219
- killSignal: "SIGKILL",
20220
- maxBuffer: 1024 * 1024,
20221
- windowsHide: true,
20222
- windowsVerbatimArguments: invocation.windowsVerbatimArguments
20223
- }, (error51, stdout, stderr) => {
20224
- if (error51)
20225
- reject(new Error(error51.killed ? "Harness command timed out" : "Harness command failed; check the native installation and retry"));
20226
- else
20227
- resolve((stdout || stderr).trim());
20228
- });
20229
- child.stdin?.end();
20230
- });
20231
- }
20232
- function installationVersion(value) {
20233
- if (typeof value !== "string" || !/^v?\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(value.trim()))
20234
- throw new Error("Harness returned an invalid version");
20235
- return value.trim().replace(/^v/, "");
20236
- }
20237
- function versionFromOutput(output) {
20238
- return installationVersion(output.match(/\b\d+(?:\.\d+){1,3}(?:-[\w.-]+)?(?:\+[\w.-]+)?\b/)?.[0]);
20239
- }
20240
- function newerInstallationVersion(current, latest) {
20241
- const a = installationVersion(current).replace(/\+.*/, "");
20242
- const b = installationVersion(latest).replace(/\+.*/, "");
20243
- const coreA = a.replace(/-.*/, "").split(".").map(BigInt);
20244
- const coreB = b.replace(/-.*/, "").split(".").map(BigInt);
20245
- for (let i = 0; i < Math.max(coreA.length, coreB.length); i++) {
20246
- if ((coreA[i] ?? 0n) !== (coreB[i] ?? 0n))
20247
- return (coreB[i] ?? 0n) > (coreA[i] ?? 0n);
20396
+ notify(method, params) {
20397
+ return this.connection.sendNotification(method, params);
20248
20398
  }
20249
- const preA = a.includes("-") ? a.slice(a.indexOf("-") + 1).split(".") : [];
20250
- const preB = b.includes("-") ? b.slice(b.indexOf("-") + 1).split(".") : [];
20251
- if (!preA.length || !preB.length)
20252
- return !!preA.length && !preB.length;
20253
- for (let i = 0; i < Math.max(preA.length, preB.length); i++) {
20254
- const x = preA[i];
20255
- const y = preB[i];
20256
- if (x === y)
20257
- continue;
20258
- if (x === void 0 || y === void 0)
20259
- return x === void 0;
20260
- const numericX = /^\d+$/.test(x);
20261
- const numericY = /^\d+$/.test(y);
20262
- if (numericX && numericY) {
20263
- if (BigInt(x) === BigInt(y))
20264
- continue;
20265
- return BigInt(y) > BigInt(x);
20266
- }
20267
- if (numericX !== numericY)
20268
- return numericX;
20269
- return y > x;
20399
+ /**
20400
+ * Extension method.
20401
+ *
20402
+ * @deprecated Use {@link request}.
20403
+ */
20404
+ extMethod(method, params) {
20405
+ return this.request(method, params);
20270
20406
  }
20271
- return false;
20272
- }
20273
- function createInstallationManager(options) {
20274
- let checking;
20275
- let updating;
20276
- const check2 = () => checking ??= options.check().finally(() => {
20277
- checking = void 0;
20278
- });
20279
- return (action) => {
20280
- if (updating)
20281
- return updating;
20282
- if (action === "check")
20283
- return check2();
20284
- updating = (async () => {
20285
- const before = await check2();
20286
- if (!before.updateAvailable)
20287
- return before;
20288
- if (!before.canUpdate)
20289
- throw new Error(before.message ?? "This installation cannot be updated automatically");
20290
- await options.update(before);
20291
- const after = await check2();
20292
- if (after.currentVersion === before.currentVersion)
20293
- throw new Error("The Harness version did not change; check the native updater and retry");
20294
- return after;
20295
- })().finally(() => {
20296
- updating = void 0;
20297
- });
20298
- return updating;
20299
- };
20300
- }
20301
- async function fetchInstallationText(url2) {
20302
- const request = async () => {
20303
- const response = await fetch(url2, { signal: AbortSignal.timeout(15e3) });
20304
- if (!response.ok)
20305
- throw new Error("Could not check the latest Harness version");
20306
- return response.text();
20307
- };
20308
- try {
20309
- return await request();
20310
- } catch (error51) {
20311
- if (error51 instanceof DOMException && (error51.name === "AbortError" || error51.name === "TimeoutError"))
20312
- throw error51;
20313
- return request();
20407
+ /**
20408
+ * Extension notification.
20409
+ *
20410
+ * @deprecated Use {@link notify}.
20411
+ */
20412
+ extNotification(method, params) {
20413
+ return this.notify(method, params);
20314
20414
  }
20315
- }
20316
-
20317
- // ../../harness-discovery/dist/npm-installation.js
20318
- import { readFile, realpath } from "node:fs/promises";
20319
- import path4 from "node:path";
20320
- function referencesNpmBin(shim, name, bin) {
20321
- if (bin.includes(".."))
20322
- return false;
20323
- const target = `node_modules/${name}/${bin.replace(/^\.\//, "")}`.toLowerCase();
20324
- const text = shim.replaceAll("\\", "/").toLowerCase();
20325
- return text.includes(`%dp0%/${target}"`) || text.includes(`%~dp0/${target}"`);
20326
- }
20327
- async function npmInstallation(command, packages, environment) {
20328
- let selected = await realpath(command);
20329
- if (process.platform === "win32" && /\.(cmd|bat)$/i.test(selected)) {
20330
- const shim = (await readFile(selected, "utf8")).replaceAll("\\", "/");
20331
- const root = path4.dirname(selected);
20332
- for (const name of packages) {
20333
- const directory2 = path4.join(root, "node_modules", ...name.split("/"));
20334
- const metadata = await readFile(path4.join(directory2, "package.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
20335
- const bins = typeof metadata?.bin === "string" ? [metadata.bin] : Object.values(metadata?.bin ?? {});
20336
- const bin = bins.find((entry) => referencesNpmBin(shim, name, entry));
20337
- if (bin) {
20338
- selected = await realpath(path4.join(directory2, bin));
20339
- break;
20340
- }
20341
- }
20415
+ /**
20416
+ * AbortSignal that aborts when the connection closes.
20417
+ *
20418
+ * This signal can be used to:
20419
+ * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
20420
+ * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
20421
+ * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
20422
+ *
20423
+ * The connection closes when the underlying stream ends, either normally or due to an error.
20424
+ *
20425
+ * @example
20426
+ * ```typescript
20427
+ * const connection = new ClientSideConnection(client, stream);
20428
+ *
20429
+ * // Listen for closure
20430
+ * connection.signal.addEventListener('abort', () => {
20431
+ * console.log('Connection closed - performing cleanup');
20432
+ * });
20433
+ *
20434
+ * // Check status
20435
+ * if (connection.signal.aborted) {
20436
+ * console.log('Connection is already closed');
20437
+ * }
20438
+ *
20439
+ * // Pass to other APIs
20440
+ * fetch(url, { signal: connection.signal });
20441
+ * ```
20442
+ */
20443
+ get signal() {
20444
+ return this.connection.signal;
20342
20445
  }
20343
- let directory = path4.dirname(selected);
20344
- for (let depth = 0; depth < 8; depth++) {
20345
- const metadata = await readFile(path4.join(directory, "package.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
20346
- if (metadata?.name && packages.includes(metadata.name)) {
20347
- const name = metadata.name;
20348
- const currentVersion = installationVersion(metadata.version);
20349
- const segments = name.split("/");
20350
- let modules = directory;
20351
- for (let index = 0; index < segments.length; index++)
20352
- modules = path4.dirname(modules);
20353
- const prefix = process.platform === "win32" ? path4.dirname(modules) : path4.dirname(path4.dirname(modules));
20354
- const globalRoot = process.platform === "win32" ? path4.join(prefix, "node_modules") : path4.join(prefix, "lib", "node_modules");
20355
- const env = withNodeRuntimeOnPath(environment);
20356
- const npm = resolveHarnessExecutable({ id: "npm", command: "npm", installRoots: { posix: [], windows: [] } }, { environment: env });
20357
- let globalInstall = modules === globalRoot;
20358
- if (process.platform === "win32") {
20359
- const project = (await Promise.all(["package.json", "package-lock.json", "npm-shrinkwrap.json"].map((file2) => readFile(path4.join(prefix, file2), "utf8").then(() => true, (error51) => error51.code !== "ENOENT")))).some(Boolean);
20360
- const bins = typeof metadata.bin === "string" ? { [name.split("/").at(-1) ?? name]: metadata.bin } : metadata.bin ?? {};
20361
- const launchers = await Promise.all(Object.entries(bins).map(async ([bin, entry]) => {
20362
- if (path4.basename(bin) !== bin || entry.includes(".."))
20363
- return false;
20364
- const target = await realpath(path4.join(directory, entry)).catch(() => "");
20365
- if (target.toLowerCase() !== selected.toLowerCase())
20366
- return false;
20367
- const shim = await readFile(path4.join(prefix, `${bin}.cmd`), "utf8").catch(() => "");
20368
- return referencesNpmBin(shim, name, entry);
20369
- }));
20370
- globalInstall = globalInstall && !project && launchers.some(Boolean);
20371
- }
20372
- const canUpdate = globalInstall && !!npm;
20373
- return {
20374
- prefix,
20375
- currentVersion,
20376
- canUpdate,
20377
- latest: async () => {
20378
- const data = JSON.parse(await fetchInstallationText(`https://registry.npmjs.org/${encodeURIComponent(name)}/latest`));
20379
- return installationVersion(data.version);
20380
- },
20381
- update: async (version2) => {
20382
- if (!canUpdate || !npm)
20383
- throw new Error("Use the original package manager to update this installation");
20384
- await runInstallationCommand(npm.executable, ["install", "--global", "--prefix", prefix, `${name}@${installationVersion(version2)}`], env, 3e5);
20385
- }
20386
- };
20387
- }
20388
- const parent = path4.dirname(directory);
20389
- if (parent === directory)
20390
- break;
20391
- directory = parent;
20446
+ /**
20447
+ * Promise that resolves when the connection closes.
20448
+ *
20449
+ * The connection closes when the underlying stream ends, either normally or due to an error.
20450
+ * Once closed, the connection cannot send or receive any more messages.
20451
+ *
20452
+ * This is useful for async/await style cleanup:
20453
+ *
20454
+ * @example
20455
+ * ```typescript
20456
+ * const connection = new ClientSideConnection(client, stream);
20457
+ * await connection.closed;
20458
+ * console.log('Connection closed - performing cleanup');
20459
+ * ```
20460
+ */
20461
+ get closed() {
20462
+ return this.connection.closed;
20392
20463
  }
20393
- return null;
20394
- }
20464
+ };
20395
20465
 
20396
20466
  // dist/command.js
20467
+ import path5 from "node:path";
20397
20468
  var KimiExecutableError = class extends Error {
20398
20469
  code = "KIMI_NOT_FOUND";
20399
20470
  };
@@ -20863,9 +20934,9 @@ var KimiAcpTransport = class {
20863
20934
 
20864
20935
  // dist/account-identity.js
20865
20936
  import { randomUUID } from "node:crypto";
20866
- import { readFile as readFile2, rename, unlink, writeFile } from "node:fs/promises";
20937
+ import { readFile as readFile2, rename, unlink, writeFile as writeFile2 } from "node:fs/promises";
20867
20938
  import { homedir as homedir2 } from "node:os";
20868
- import { join } from "node:path";
20939
+ import { join as join2 } from "node:path";
20869
20940
  var KIMI_USAGES_ENDPOINT = "https://api.kimi.com/coding/v1/usages";
20870
20941
  var KIMI_OAUTH_TOKEN_ENDPOINT = "https://auth.kimi.com/api/oauth/token";
20871
20942
  var KIMI_CODE_CLIENT_ID = "17e5f671-d194-4dfb-9706-5516cb48c098";
@@ -20887,10 +20958,10 @@ var refreshResponseSchema = external_exports.object({
20887
20958
  token_type: external_exports.string().optional()
20888
20959
  });
20889
20960
  function kimiHome(environment) {
20890
- return environment.KIMI_CODE_HOME ?? join(environment.HOME ?? homedir2(), ".kimi-code");
20961
+ return environment.KIMI_CODE_HOME ?? join2(environment.HOME ?? homedir2(), ".kimi-code");
20891
20962
  }
20892
20963
  function credentialPath(environment) {
20893
- return join(kimiHome(environment), "credentials", "kimi-code.json");
20964
+ return join2(kimiHome(environment), "credentials", "kimi-code.json");
20894
20965
  }
20895
20966
  function oauthTokenUrl(environment) {
20896
20967
  const host = environment.KIMI_CODE_OAUTH_HOST ?? environment.KIMI_OAUTH_HOST;
@@ -20995,7 +21066,7 @@ async function readNativeCredentials(filePath, readAuthFile) {
20995
21066
  async function defaultWriteAuthFile(filePath, contents) {
20996
21067
  const temporary = `${filePath}.${randomUUID()}.tmp`;
20997
21068
  try {
20998
- await writeFile(temporary, contents, { encoding: "utf8", mode: 384, flag: "wx" });
21069
+ await writeFile2(temporary, contents, { encoding: "utf8", mode: 384, flag: "wx" });
20999
21070
  await rename(temporary, filePath);
21000
21071
  } finally {
21001
21072
  await unlink(temporary).catch(() => void 0);
@@ -23152,7 +23223,7 @@ async function readKimiSessionUsage(sessionId, options = {}) {
23152
23223
  import { setTimeout as delay } from "node:timers/promises";
23153
23224
 
23154
23225
  // dist/command-history.js
23155
- import { appendFile, readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
23226
+ import { appendFile, readFile as readFile4, writeFile as writeFile3 } from "node:fs/promises";
23156
23227
  import path7 from "node:path";
23157
23228
  async function readKimiCommandHistory(sessionId, options) {
23158
23229
  const located = await locateKimiSession(sessionId, options);
@@ -23204,7 +23275,7 @@ async function copyKimiCommandHistory(turns, sessionId, options) {
23204
23275
  nativeTurnRef: { ...turn.nativeTurnRef, nativeSessionId: sessionId },
23205
23276
  ...turn.checkpoint ? { checkpoint: { ...turn.checkpoint, nativeSessionId: sessionId } } : {}
23206
23277
  }));
23207
- await writeFile2(path7.join(located.sessionDir, "codexhost-commands.jsonl"), copied.map((turn) => `${JSON.stringify(turn)}
23278
+ await writeFile3(path7.join(located.sessionDir, "codexhost-commands.jsonl"), copied.map((turn) => `${JSON.stringify(turn)}
23208
23279
  `).join(""), "utf8");
23209
23280
  }
23210
23281
 
@@ -24791,7 +24862,7 @@ var KimiAdapter = class {
24791
24862
  // dist/installation.js
24792
24863
  import { open, readFile as readFile6 } from "node:fs/promises";
24793
24864
  import { homedir as homedir3 } from "node:os";
24794
- import { join as join2 } from "node:path";
24865
+ import { join as join3 } from "node:path";
24795
24866
  function createKimiInstallation(environment) {
24796
24867
  const executable = () => resolveKimiExecutable({ environment });
24797
24868
  const run = (args, timeout) => runInstallationCommand(executable(), args, { ...environment, KIMI_CODE_NO_AUTO_UPDATE: "1" }, timeout);
@@ -24811,8 +24882,8 @@ function createKimiInstallation(environment) {
24811
24882
  return createInstallationManager({
24812
24883
  async check() {
24813
24884
  const currentVersion = versionFromOutput(await run(["--version"]));
24814
- const home = environment.KIMI_CODE_HOME ?? join2(environment.HOME ?? homedir3(), ".kimi-code");
24815
- const region = await readFile6(join2(home, "region"), "utf8").catch(() => "");
24885
+ const home = environment.KIMI_CODE_HOME ?? join3(environment.HOME ?? homedir3(), ".kimi-code");
24886
+ const region = await readFile6(join3(home, "region"), "utf8").catch(() => "");
24816
24887
  const base = region.trim() === "global" ? "https://code.kimi.ai/kimi-code" : "https://code.kimi.com/kimi-code";
24817
24888
  const latestVersion = installationVersion(await fetchInstallationText(`${base}/latest`));
24818
24889
  const npm = await npmInstallation(executable(), ["@moonshot-ai/kimi-code"], environment);
@@ -24822,7 +24893,10 @@ function createKimiInstallation(environment) {
24822
24893
  latestVersion,
24823
24894
  updateAvailable: newerInstallationVersion(currentVersion, latestVersion),
24824
24895
  canUpdate,
24825
- ...!canUpdate ? { message: "Use the original installer to update this Kimi installation" } : {}
24896
+ ...!canUpdate ? {
24897
+ messageCode: "original-installer",
24898
+ message: "Use the original installer to update this Kimi installation"
24899
+ } : {}
24826
24900
  };
24827
24901
  },
24828
24902
  async update(state) {
@@ -24845,7 +24919,13 @@ function createHarnessAdapter(context) {
24845
24919
  return Object.assign(new KimiAdapter({
24846
24920
  ...environment[KIMI_COMMAND_ENV] ? { command: environment[KIMI_COMMAND_ENV] } : {},
24847
24921
  environment
24848
- }), { installation: createKimiInstallation(environment) });
24922
+ }), {
24923
+ installation: createKimiInstallation(environment),
24924
+ install: createHarnessInstaller(environment, {
24925
+ posix: "https://code.kimi.com/kimi-code/install.sh",
24926
+ windows: "https://code.kimi.com/kimi-code/install.ps1"
24927
+ })
24928
+ });
24849
24929
  }
24850
24930
  export {
24851
24931
  createHarnessAdapter