@codexhost/cli-darwin-x64 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +16496 -16342
- package/app/console-web.js +4290 -2314
- package/app/desktop-controller.mjs +16266 -360
- package/app/host-runtime.mjs +4707 -986
- package/app/plugins/antigravity/plugin.mjs +1201 -1044
- package/app/plugins/claude-code/plugin.mjs +517 -139
- package/app/plugins/codebuddy/plugin.mjs +1521 -868
- package/app/plugins/cursor-cli/plugin.mjs +824 -436
- package/app/plugins/deepseek-harness/plugin.mjs +25516 -26242
- package/app/plugins/enabled.json +2 -1
- package/app/plugins/grok/plugin.mjs +995 -515
- package/app/plugins/hermes/plugin.mjs +18815 -23119
- package/app/plugins/kimi-code/plugin.mjs +1105 -713
- package/app/plugins/kiro-cli/plugin.mjs +1018 -600
- package/app/plugins/omp/plugin.mjs +1097 -586
- package/app/plugins/opencode/plugin.mjs +1020 -710
- package/app/plugins/pi/plugin.mjs +15952 -15716
- package/app/plugins/qoder/plugin.mjs +738 -385
- package/app/plugins/qoder-cn/plugin.mjs +404 -49
- package/app/plugins/workbuddy/plugin.mjs +715 -108
- package/app/plugins/zcode/assets/icon.svg +8 -0
- package/app/plugins/zcode/manifest.json +14 -0
- package/app/plugins/zcode/plugin.mjs +19251 -0
- package/app/renderer-extension.js +2854 -630
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
|
@@ -5,20 +5,387 @@ 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
|
+
}, (error53, stdout, stderr) => {
|
|
264
|
+
if (error53)
|
|
265
|
+
reject(new Error(error53.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 createInstallationManager(options) {
|
|
278
|
+
let checking;
|
|
279
|
+
let updating;
|
|
280
|
+
const check2 = () => checking ??= options.check().finally(() => {
|
|
281
|
+
checking = void 0;
|
|
282
|
+
});
|
|
283
|
+
return (action) => {
|
|
284
|
+
if (updating)
|
|
285
|
+
return updating;
|
|
286
|
+
if (action === "check")
|
|
287
|
+
return check2();
|
|
288
|
+
updating = (async () => {
|
|
289
|
+
const before = await check2();
|
|
290
|
+
if (!before.updateAvailable)
|
|
291
|
+
return before;
|
|
292
|
+
if (!before.canUpdate)
|
|
293
|
+
throw new Error(before.message ?? "This installation cannot be updated automatically");
|
|
294
|
+
await options.update(before);
|
|
295
|
+
const after = await check2();
|
|
296
|
+
if (after.currentVersion === before.currentVersion)
|
|
297
|
+
throw new Error("The Harness version did not change; check the native updater and retry");
|
|
298
|
+
return after;
|
|
299
|
+
})().finally(() => {
|
|
300
|
+
updating = void 0;
|
|
301
|
+
});
|
|
302
|
+
return updating;
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
async function fetchInstallationText(url2) {
|
|
306
|
+
const request = async () => {
|
|
307
|
+
const response = await fetch(url2, { signal: AbortSignal.timeout(15e3) });
|
|
308
|
+
if (!response.ok)
|
|
309
|
+
throw new Error("Could not check the latest Harness version");
|
|
310
|
+
return response.text();
|
|
311
|
+
};
|
|
312
|
+
try {
|
|
313
|
+
return await request();
|
|
314
|
+
} catch (error53) {
|
|
315
|
+
if (error53 instanceof DOMException && (error53.name === "AbortError" || error53.name === "TimeoutError"))
|
|
316
|
+
throw error53;
|
|
317
|
+
return request();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ../../harness-discovery/dist/installer.js
|
|
322
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
323
|
+
import { tmpdir } from "node:os";
|
|
324
|
+
import { join } from "node:path";
|
|
325
|
+
function createHarnessInstaller(environment, source) {
|
|
326
|
+
return async () => {
|
|
327
|
+
if (!["darwin", "linux", "win32"].includes(process.platform))
|
|
328
|
+
throw new Error("Unsupported installation platform");
|
|
329
|
+
const env = withNodeRuntimeOnPath(environment);
|
|
330
|
+
if ("npm" in source) {
|
|
331
|
+
const npm = resolveHarnessExecutable({
|
|
332
|
+
id: "npm",
|
|
333
|
+
command: "npm",
|
|
334
|
+
installRoots: {
|
|
335
|
+
posix: [
|
|
336
|
+
"~/.npm-global/bin",
|
|
337
|
+
"~/.local/bin",
|
|
338
|
+
VERSION_MANAGER_ROOTS,
|
|
339
|
+
"/opt/homebrew/bin",
|
|
340
|
+
"/usr/local/bin",
|
|
341
|
+
"/usr/bin"
|
|
342
|
+
],
|
|
343
|
+
windows: [
|
|
344
|
+
"${APPDATA}/npm",
|
|
345
|
+
VERSION_MANAGER_ROOTS,
|
|
346
|
+
"${ProgramFiles}/nodejs",
|
|
347
|
+
"${LOCALAPPDATA}/Programs/nodejs"
|
|
348
|
+
]
|
|
349
|
+
}
|
|
350
|
+
}, { environment: env });
|
|
351
|
+
if (!npm)
|
|
352
|
+
throw new Error("Install Node.js and npm first");
|
|
353
|
+
await runInstallationCommand(npm.executable, ["install", "--global", source.npm], {
|
|
354
|
+
...env,
|
|
355
|
+
...source.allowScripts ? { npm_config_allow_scripts: source.allowScripts } : {}
|
|
356
|
+
}, 6e5);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const windows = process.platform === "win32";
|
|
360
|
+
const url2 = windows ? source.windows : source.posix;
|
|
361
|
+
if (new URL(url2).protocol !== "https:")
|
|
362
|
+
throw new Error("Installer requires HTTPS");
|
|
363
|
+
const script = await fetchInstallationText(url2);
|
|
364
|
+
const directory = await mkdtemp(join(tmpdir(), "codexhost-installer-"));
|
|
365
|
+
try {
|
|
366
|
+
const file2 = join(directory, windows ? "install.ps1" : "install.sh");
|
|
367
|
+
await writeFile(file2, script, { mode: 384 });
|
|
368
|
+
await runInstallationCommand(windows ? "powershell.exe" : source.shell ?? "bash", windows ? ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", file2] : [file2], env, 6e5);
|
|
369
|
+
} finally {
|
|
370
|
+
await rm(directory, { recursive: true, force: true });
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
8
375
|
// dist/grok-adapter.js
|
|
9
376
|
import { randomUUID } from "node:crypto";
|
|
10
377
|
|
|
11
378
|
// dist/grok-credential-export.js
|
|
12
379
|
import { createHash } from "node:crypto";
|
|
13
380
|
import { readFile } from "node:fs/promises";
|
|
14
|
-
import
|
|
15
|
-
import
|
|
381
|
+
import os2 from "node:os";
|
|
382
|
+
import path4 from "node:path";
|
|
16
383
|
async function readGrokCredentials(environment) {
|
|
17
384
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((v) => v?.trim()))
|
|
18
385
|
return [];
|
|
19
386
|
try {
|
|
20
|
-
const home = environment.GROK_HOME ??
|
|
21
|
-
const auth = JSON.parse(await readFile(
|
|
387
|
+
const home = environment.GROK_HOME ?? path4.join(environment.HOME ?? os2.homedir(), ".grok");
|
|
388
|
+
const auth = JSON.parse(await readFile(path4.join(home, "auth.json"), "utf8"));
|
|
22
389
|
const client2 = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
23
390
|
const entry = auth[`https://auth.x.ai::${client2}`] ?? auth["https://auth.x.ai"];
|
|
24
391
|
if (!entry || entry.oidc_issuer !== "https://auth.x.ai" || entry.oidc_client_id !== client2)
|
|
@@ -45,7 +412,7 @@ async function readGrokCredentials(environment) {
|
|
|
45
412
|
}
|
|
46
413
|
|
|
47
414
|
// dist/grok-adapter.js
|
|
48
|
-
import
|
|
415
|
+
import path13 from "node:path";
|
|
49
416
|
|
|
50
417
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
51
418
|
var external_exports = {};
|
|
@@ -813,10 +1180,10 @@ function mergeDefs(...defs) {
|
|
|
813
1180
|
function cloneDef(schema) {
|
|
814
1181
|
return mergeDefs(schema._zod.def);
|
|
815
1182
|
}
|
|
816
|
-
function getElementAtPath(obj,
|
|
817
|
-
if (!
|
|
1183
|
+
function getElementAtPath(obj, path14) {
|
|
1184
|
+
if (!path14)
|
|
818
1185
|
return obj;
|
|
819
|
-
return
|
|
1186
|
+
return path14.reduce((acc, key) => acc?.[key], obj);
|
|
820
1187
|
}
|
|
821
1188
|
function promiseAllObject(promisesObj) {
|
|
822
1189
|
const keys = Object.keys(promisesObj);
|
|
@@ -1225,11 +1592,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1225
1592
|
}
|
|
1226
1593
|
return false;
|
|
1227
1594
|
}
|
|
1228
|
-
function prefixIssues(
|
|
1595
|
+
function prefixIssues(path14, issues) {
|
|
1229
1596
|
return issues.map((iss) => {
|
|
1230
1597
|
var _a3;
|
|
1231
1598
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1232
|
-
iss.path.unshift(
|
|
1599
|
+
iss.path.unshift(path14);
|
|
1233
1600
|
return iss;
|
|
1234
1601
|
});
|
|
1235
1602
|
}
|
|
@@ -1376,16 +1743,16 @@ function flattenError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1376
1743
|
}
|
|
1377
1744
|
function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
1378
1745
|
const fieldErrors = { _errors: [] };
|
|
1379
|
-
const processError = (error54,
|
|
1746
|
+
const processError = (error54, path14 = []) => {
|
|
1380
1747
|
for (const issue2 of error54.issues) {
|
|
1381
1748
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1382
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1749
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1383
1750
|
} else if (issue2.code === "invalid_key") {
|
|
1384
|
-
processError({ issues: issue2.issues }, [...
|
|
1751
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1385
1752
|
} else if (issue2.code === "invalid_element") {
|
|
1386
|
-
processError({ issues: issue2.issues }, [...
|
|
1753
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1387
1754
|
} else {
|
|
1388
|
-
const fullpath = [...
|
|
1755
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1389
1756
|
if (fullpath.length === 0) {
|
|
1390
1757
|
fieldErrors._errors.push(mapper(issue2));
|
|
1391
1758
|
} else {
|
|
@@ -1412,17 +1779,17 @@ function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1412
1779
|
}
|
|
1413
1780
|
function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
1414
1781
|
const result = { errors: [] };
|
|
1415
|
-
const processError = (error54,
|
|
1782
|
+
const processError = (error54, path14 = []) => {
|
|
1416
1783
|
var _a3, _b;
|
|
1417
1784
|
for (const issue2 of error54.issues) {
|
|
1418
1785
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1419
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1786
|
+
issue2.errors.map((issues) => processError({ issues }, [...path14, ...issue2.path]));
|
|
1420
1787
|
} else if (issue2.code === "invalid_key") {
|
|
1421
|
-
processError({ issues: issue2.issues }, [...
|
|
1788
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1422
1789
|
} else if (issue2.code === "invalid_element") {
|
|
1423
|
-
processError({ issues: issue2.issues }, [...
|
|
1790
|
+
processError({ issues: issue2.issues }, [...path14, ...issue2.path]);
|
|
1424
1791
|
} else {
|
|
1425
|
-
const fullpath = [...
|
|
1792
|
+
const fullpath = [...path14, ...issue2.path];
|
|
1426
1793
|
if (fullpath.length === 0) {
|
|
1427
1794
|
result.errors.push(mapper(issue2));
|
|
1428
1795
|
continue;
|
|
@@ -1454,8 +1821,8 @@ function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1454
1821
|
}
|
|
1455
1822
|
function toDotPath(_path) {
|
|
1456
1823
|
const segs = [];
|
|
1457
|
-
const
|
|
1458
|
-
for (const seg of
|
|
1824
|
+
const path14 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1825
|
+
for (const seg of path14) {
|
|
1459
1826
|
if (typeof seg === "number")
|
|
1460
1827
|
segs.push(`[${seg}]`);
|
|
1461
1828
|
else if (typeof seg === "symbol")
|
|
@@ -14147,13 +14514,13 @@ function resolveRef(ref, ctx) {
|
|
|
14147
14514
|
if (!ref.startsWith("#")) {
|
|
14148
14515
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14149
14516
|
}
|
|
14150
|
-
const
|
|
14151
|
-
if (
|
|
14517
|
+
const path14 = ref.slice(1).split("/").filter(Boolean);
|
|
14518
|
+
if (path14.length === 0) {
|
|
14152
14519
|
return ctx.rootSchema;
|
|
14153
14520
|
}
|
|
14154
14521
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14155
|
-
if (
|
|
14156
|
-
const key =
|
|
14522
|
+
if (path14[0] === defsKey) {
|
|
14523
|
+
const key = path14[1];
|
|
14157
14524
|
if (!key || !ctx.defs[key]) {
|
|
14158
14525
|
throw new Error(`Reference not found: ${ref}`);
|
|
14159
14526
|
}
|
|
@@ -14631,6 +14998,20 @@ var harnessDisplaySetSchema = external_exports.strictObject({
|
|
|
14631
14998
|
initializeOnly: external_exports.boolean().optional()
|
|
14632
14999
|
});
|
|
14633
15000
|
|
|
15001
|
+
// ../../shared-contracts/dist/ids.js
|
|
15002
|
+
var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
15003
|
+
message: "Identifier must not be empty or whitespace"
|
|
15004
|
+
});
|
|
15005
|
+
var harnessIdSchema = opaqueIdSchema.brand();
|
|
15006
|
+
var hostThreadIdSchema = opaqueIdSchema.brand();
|
|
15007
|
+
var hostTurnIdSchema = opaqueIdSchema.brand();
|
|
15008
|
+
var hostItemIdSchema = opaqueIdSchema.brand();
|
|
15009
|
+
var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
15010
|
+
|
|
15011
|
+
// ../../shared-contracts/dist/thread-prewarm.js
|
|
15012
|
+
var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
|
|
15013
|
+
var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
|
|
15014
|
+
|
|
14634
15015
|
// ../../shared-contracts/dist/console.js
|
|
14635
15016
|
var consoleAnnouncementSchema = external_exports.strictObject({
|
|
14636
15017
|
title: external_exports.string().trim().min(1).max(200),
|
|
@@ -14643,10 +15024,14 @@ var consoleOpenResultSchema = external_exports.strictObject({
|
|
|
14643
15024
|
url: external_exports.string().max(2048).regex(/^http:\/\/(?:127\.0\.0\.1|localhost):\d{1,5}\/(?:\?.*)?$/u)
|
|
14644
15025
|
});
|
|
14645
15026
|
var CONSOLE_HOST_METHODS = Object.freeze([
|
|
15027
|
+
"codexhost/console/remote-connections",
|
|
15028
|
+
"codexhost/runtime/status",
|
|
15029
|
+
"codexhost/remote/ssh-setup",
|
|
14646
15030
|
"codexhost/harness/plugins/list",
|
|
14647
15031
|
"codexhost/harness/display-settings/get",
|
|
14648
15032
|
"codexhost/harness/display-settings/set",
|
|
14649
15033
|
"codexhost/harness/inspect",
|
|
15034
|
+
"codexhost/harness/installation",
|
|
14650
15035
|
"codexhost/harness/launch-settings/get",
|
|
14651
15036
|
"codexhost/harness/launch-settings/set",
|
|
14652
15037
|
"codexhost/harness/web-ui/open",
|
|
@@ -14708,16 +15093,6 @@ var loadedSessionsSchema = external_exports.array(external_exports.strictObject(
|
|
|
14708
15093
|
inactiveMs: external_exports.number().nonnegative()
|
|
14709
15094
|
}));
|
|
14710
15095
|
|
|
14711
|
-
// ../../shared-contracts/dist/ids.js
|
|
14712
|
-
var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
14713
|
-
message: "Identifier must not be empty or whitespace"
|
|
14714
|
-
});
|
|
14715
|
-
var harnessIdSchema = opaqueIdSchema.brand();
|
|
14716
|
-
var hostThreadIdSchema = opaqueIdSchema.brand();
|
|
14717
|
-
var hostTurnIdSchema = opaqueIdSchema.brand();
|
|
14718
|
-
var hostItemIdSchema = opaqueIdSchema.brand();
|
|
14719
|
-
var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
14720
|
-
|
|
14721
15096
|
// ../../shared-contracts/dist/manual-compaction.js
|
|
14722
15097
|
var threadManualCompactionStartedSchema = external_exports.strictObject({
|
|
14723
15098
|
threadId: hostThreadIdSchema,
|
|
@@ -15293,14 +15668,17 @@ var harnessLaunchSettingsSchema = external_exports.object({
|
|
|
15293
15668
|
// ../../shared-contracts/dist/harness-installation.js
|
|
15294
15669
|
var harnessInstallationParamsSchema = external_exports.object({
|
|
15295
15670
|
harnessId: harnessIdSchema,
|
|
15296
|
-
action: external_exports.enum(["check", "update"])
|
|
15671
|
+
action: external_exports.enum(["check", "update", "install"])
|
|
15297
15672
|
}).strict();
|
|
15298
15673
|
var harnessInstallationStateSchema = external_exports.object({
|
|
15299
15674
|
currentVersion: external_exports.string().min(1).max(128),
|
|
15300
15675
|
latestVersion: external_exports.string().min(1).max(128),
|
|
15301
15676
|
updateAvailable: external_exports.boolean(),
|
|
15302
15677
|
canUpdate: external_exports.boolean(),
|
|
15303
|
-
|
|
15678
|
+
// Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
|
|
15679
|
+
message: external_exports.string().max(2048).optional(),
|
|
15680
|
+
messageCode: external_exports.string().min(1).max(128).optional(),
|
|
15681
|
+
latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
|
|
15304
15682
|
}).strict();
|
|
15305
15683
|
|
|
15306
15684
|
// ../../shared-contracts/dist/codex-accounts.js
|
|
@@ -15602,6 +15980,80 @@ var updateStatusResultSchema = external_exports.strictObject({
|
|
|
15602
15980
|
status: updateStatusSchema.nullable()
|
|
15603
15981
|
});
|
|
15604
15982
|
|
|
15983
|
+
// ../../shared-contracts/dist/remote-runtime.js
|
|
15984
|
+
var remoteUpdatePhaseSchema = external_exports.enum([
|
|
15985
|
+
"idle",
|
|
15986
|
+
"installing",
|
|
15987
|
+
"restarting",
|
|
15988
|
+
"succeeded",
|
|
15989
|
+
"failed"
|
|
15990
|
+
]);
|
|
15991
|
+
var runtimeStatusSchema = external_exports.object({
|
|
15992
|
+
runningVersion: external_exports.string().nullable(),
|
|
15993
|
+
installedVersion: external_exports.string().nullable(),
|
|
15994
|
+
restartRequired: external_exports.boolean(),
|
|
15995
|
+
remote: external_exports.boolean(),
|
|
15996
|
+
updateSupported: external_exports.boolean(),
|
|
15997
|
+
update: external_exports.object({
|
|
15998
|
+
phase: remoteUpdatePhaseSchema,
|
|
15999
|
+
targetVersion: external_exports.string().nullable(),
|
|
16000
|
+
error: external_exports.string().nullable()
|
|
16001
|
+
})
|
|
16002
|
+
});
|
|
16003
|
+
var remoteUpdateParamsSchema = external_exports.object({
|
|
16004
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
|
|
16005
|
+
}).strict();
|
|
16006
|
+
var remoteSshSetupParamsSchema = external_exports.object({
|
|
16007
|
+
hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
|
|
16008
|
+
port: external_exports.number().int().min(1).max(65535).nullable(),
|
|
16009
|
+
identity: external_exports.string().max(4096).nullable(),
|
|
16010
|
+
action: external_exports.enum(["inspect", "install", "update", "repair", "uninstall"]),
|
|
16011
|
+
uninstallPackage: external_exports.boolean().optional(),
|
|
16012
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
|
|
16013
|
+
}).strict();
|
|
16014
|
+
var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
|
|
16015
|
+
|
|
16016
|
+
// ../../shared-contracts/dist/remote-connections.js
|
|
16017
|
+
var hostId = external_exports.string().min(1).max(1024);
|
|
16018
|
+
var codexSshConnectionSchema = external_exports.object({
|
|
16019
|
+
hostId,
|
|
16020
|
+
displayName: external_exports.string().min(1).max(1024),
|
|
16021
|
+
source: external_exports.enum(["codex-managed", "discovered"]),
|
|
16022
|
+
sshAlias: external_exports.string().max(1024).nullable(),
|
|
16023
|
+
sshHost: external_exports.string().min(1).max(1024),
|
|
16024
|
+
sshPort: external_exports.number().int().min(1).max(65535).nullable(),
|
|
16025
|
+
identity: external_exports.string().max(4096).nullable(),
|
|
16026
|
+
autoConnect: external_exports.boolean(),
|
|
16027
|
+
connectionAnalyticsId: external_exports.string().max(1024).optional()
|
|
16028
|
+
});
|
|
16029
|
+
var codexSshDraftSchema = external_exports.strictObject({
|
|
16030
|
+
displayName: external_exports.string().min(1).max(1024),
|
|
16031
|
+
hostname: external_exports.string().min(1).max(1024),
|
|
16032
|
+
sshPort: external_exports.number().int().min(1).max(65535).nullable(),
|
|
16033
|
+
identity: external_exports.string().max(4096).nullable()
|
|
16034
|
+
});
|
|
16035
|
+
var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
|
|
16036
|
+
external_exports.strictObject({ action: external_exports.literal("list") }),
|
|
16037
|
+
external_exports.strictObject({
|
|
16038
|
+
action: external_exports.literal("save"),
|
|
16039
|
+
draft: codexSshDraftSchema,
|
|
16040
|
+
previous: codexSshConnectionSchema.nullable()
|
|
16041
|
+
}),
|
|
16042
|
+
external_exports.strictObject({ action: external_exports.literal("remove"), previous: codexSshConnectionSchema }),
|
|
16043
|
+
external_exports.strictObject({ action: external_exports.literal("connect"), hostId, enabled: external_exports.boolean() }),
|
|
16044
|
+
external_exports.strictObject({ action: external_exports.literal("state"), hostId }),
|
|
16045
|
+
external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
|
|
16046
|
+
external_exports.strictObject({
|
|
16047
|
+
action: external_exports.literal("update"),
|
|
16048
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
16049
|
+
version: remoteUpdateParamsSchema.shape.version
|
|
16050
|
+
})
|
|
16051
|
+
]);
|
|
16052
|
+
var remoteConnectionsReplySchema = external_exports.union([
|
|
16053
|
+
external_exports.strictObject({ result: jsonValueSchema }),
|
|
16054
|
+
external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
|
|
16055
|
+
]);
|
|
16056
|
+
|
|
15605
16057
|
// ../../shared-contracts/dist/index.js
|
|
15606
16058
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
15607
16059
|
|
|
@@ -19921,469 +20373,169 @@ var ClientSideConnection = class {
|
|
|
19921
20373
|
* @experimental
|
|
19922
20374
|
*/
|
|
19923
20375
|
unstable_didChangeDocument(params) {
|
|
19924
|
-
return this.connection.sendNotification(AGENT_METHODS.document_did_change, params);
|
|
19925
|
-
}
|
|
19926
|
-
/**
|
|
19927
|
-
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
19928
|
-
*
|
|
19929
|
-
* Notifies the agent that a document was closed.
|
|
19930
|
-
*
|
|
19931
|
-
* @experimental
|
|
19932
|
-
*/
|
|
19933
|
-
unstable_didCloseDocument(params) {
|
|
19934
|
-
return this.connection.sendNotification(AGENT_METHODS.document_did_close, params);
|
|
19935
|
-
}
|
|
19936
|
-
/**
|
|
19937
|
-
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
19938
|
-
*
|
|
19939
|
-
* Notifies the agent that a document was saved.
|
|
19940
|
-
*
|
|
19941
|
-
* @experimental
|
|
19942
|
-
*/
|
|
19943
|
-
unstable_didSaveDocument(params) {
|
|
19944
|
-
return this.connection.sendNotification(AGENT_METHODS.document_did_save, params);
|
|
19945
|
-
}
|
|
19946
|
-
/**
|
|
19947
|
-
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
19948
|
-
*
|
|
19949
|
-
* Notifies the agent that a document received focus.
|
|
19950
|
-
*
|
|
19951
|
-
* @experimental
|
|
19952
|
-
*/
|
|
19953
|
-
unstable_didFocusDocument(params) {
|
|
19954
|
-
return this.connection.sendNotification(AGENT_METHODS.document_did_focus, params);
|
|
19955
|
-
}
|
|
19956
|
-
/**
|
|
19957
|
-
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
19958
|
-
*
|
|
19959
|
-
* Notifies the agent that a NES suggestion was accepted.
|
|
19960
|
-
*
|
|
19961
|
-
* @experimental
|
|
19962
|
-
*/
|
|
19963
|
-
unstable_acceptNes(params) {
|
|
19964
|
-
return this.connection.sendNotification(AGENT_METHODS.nes_accept, params);
|
|
19965
|
-
}
|
|
19966
|
-
/**
|
|
19967
|
-
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
19968
|
-
*
|
|
19969
|
-
* Notifies the agent that a NES suggestion was rejected.
|
|
19970
|
-
*
|
|
19971
|
-
* @experimental
|
|
19972
|
-
*/
|
|
19973
|
-
unstable_rejectNes(params) {
|
|
19974
|
-
return this.connection.sendNotification(AGENT_METHODS.nes_reject, params);
|
|
19975
|
-
}
|
|
19976
|
-
request(method, params, options) {
|
|
19977
|
-
const spec = agentRequestSpecsByMethod[method];
|
|
19978
|
-
return this.connection.sendRequest(method, params, spec?.mapResponse, options);
|
|
19979
|
-
}
|
|
19980
|
-
notify(method, params) {
|
|
19981
|
-
return this.connection.sendNotification(method, params);
|
|
19982
|
-
}
|
|
19983
|
-
/**
|
|
19984
|
-
* Extension method.
|
|
19985
|
-
*
|
|
19986
|
-
* @deprecated Use {@link request}.
|
|
19987
|
-
*/
|
|
19988
|
-
extMethod(method, params) {
|
|
19989
|
-
return this.request(method, params);
|
|
19990
|
-
}
|
|
19991
|
-
/**
|
|
19992
|
-
* Extension notification.
|
|
19993
|
-
*
|
|
19994
|
-
* @deprecated Use {@link notify}.
|
|
19995
|
-
*/
|
|
19996
|
-
extNotification(method, params) {
|
|
19997
|
-
return this.notify(method, params);
|
|
19998
|
-
}
|
|
19999
|
-
/**
|
|
20000
|
-
* AbortSignal that aborts when the connection closes.
|
|
20001
|
-
*
|
|
20002
|
-
* This signal can be used to:
|
|
20003
|
-
* - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
|
|
20004
|
-
* - Check connection status synchronously: `if (connection.signal.aborted) {...}`
|
|
20005
|
-
* - Pass to other APIs (fetch, setTimeout) for automatic cancellation
|
|
20006
|
-
*
|
|
20007
|
-
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
20008
|
-
*
|
|
20009
|
-
* @example
|
|
20010
|
-
* ```typescript
|
|
20011
|
-
* const connection = new ClientSideConnection(client, stream);
|
|
20012
|
-
*
|
|
20013
|
-
* // Listen for closure
|
|
20014
|
-
* connection.signal.addEventListener('abort', () => {
|
|
20015
|
-
* console.log('Connection closed - performing cleanup');
|
|
20016
|
-
* });
|
|
20017
|
-
*
|
|
20018
|
-
* // Check status
|
|
20019
|
-
* if (connection.signal.aborted) {
|
|
20020
|
-
* console.log('Connection is already closed');
|
|
20021
|
-
* }
|
|
20022
|
-
*
|
|
20023
|
-
* // Pass to other APIs
|
|
20024
|
-
* fetch(url, { signal: connection.signal });
|
|
20025
|
-
* ```
|
|
20026
|
-
*/
|
|
20027
|
-
get signal() {
|
|
20028
|
-
return this.connection.signal;
|
|
20029
|
-
}
|
|
20030
|
-
/**
|
|
20031
|
-
* Promise that resolves when the connection closes.
|
|
20032
|
-
*
|
|
20033
|
-
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
20034
|
-
* Once closed, the connection cannot send or receive any more messages.
|
|
20035
|
-
*
|
|
20036
|
-
* This is useful for async/await style cleanup:
|
|
20037
|
-
*
|
|
20038
|
-
* @example
|
|
20039
|
-
* ```typescript
|
|
20040
|
-
* const connection = new ClientSideConnection(client, stream);
|
|
20041
|
-
* await connection.closed;
|
|
20042
|
-
* console.log('Connection closed - performing cleanup');
|
|
20043
|
-
* ```
|
|
20044
|
-
*/
|
|
20045
|
-
get closed() {
|
|
20046
|
-
return this.connection.closed;
|
|
20047
|
-
}
|
|
20048
|
-
};
|
|
20049
|
-
|
|
20050
|
-
// dist/grok-slash-commands.js
|
|
20051
|
-
var GROK_LIVE_COMMAND_ID_PREFIX = "grok.slash.";
|
|
20052
|
-
function isRecord3(value) {
|
|
20053
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20054
|
-
}
|
|
20055
|
-
function parseGrokAvailableCommands(value) {
|
|
20056
|
-
if (!Array.isArray(value))
|
|
20057
|
-
return [];
|
|
20058
|
-
return value.flatMap((entry) => {
|
|
20059
|
-
if (!isRecord3(entry))
|
|
20060
|
-
return [];
|
|
20061
|
-
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
20062
|
-
if (!name)
|
|
20063
|
-
return [];
|
|
20064
|
-
return [
|
|
20065
|
-
{
|
|
20066
|
-
name,
|
|
20067
|
-
description: typeof entry.description === "string" ? entry.description : "",
|
|
20068
|
-
meta: isRecord3(entry._meta) ? entry._meta : null
|
|
20069
|
-
}
|
|
20070
|
-
];
|
|
20071
|
-
});
|
|
20072
|
-
}
|
|
20073
|
-
function isGrokSkill(command) {
|
|
20074
|
-
const path13 = command.meta?.path;
|
|
20075
|
-
return typeof path13 === "string" && /(^|[\\/])SKILL\.md$/u.test(path13) || typeof command.meta?.qualifiedName === "string";
|
|
20076
|
-
}
|
|
20077
|
-
function grokLiveCommands(native) {
|
|
20078
|
-
return native.map((command) => ({
|
|
20079
|
-
name: command.name,
|
|
20080
|
-
description: command.description,
|
|
20081
|
-
kind: isGrokSkill(command) ? "skill" : "command"
|
|
20082
|
-
}));
|
|
20083
|
-
}
|
|
20084
|
-
|
|
20085
|
-
// dist/command.js
|
|
20086
|
-
import path5 from "node:path";
|
|
20087
|
-
|
|
20088
|
-
// ../../harness-discovery/dist/environment.js
|
|
20089
|
-
import fs from "node:fs";
|
|
20090
|
-
import path2 from "node:path";
|
|
20091
|
-
function targetPath(platform) {
|
|
20092
|
-
return platform === "win32" ? path2.win32 : path2.posix;
|
|
20093
|
-
}
|
|
20094
|
-
function environmentValue(environment, name) {
|
|
20095
|
-
const lowered = name.toLowerCase();
|
|
20096
|
-
for (const [key, value] of Object.entries(environment)) {
|
|
20097
|
-
if (key.toLowerCase() === lowered)
|
|
20098
|
-
return value;
|
|
20099
|
-
}
|
|
20100
|
-
return void 0;
|
|
20101
|
-
}
|
|
20102
|
-
function pathDelimiter(platform) {
|
|
20103
|
-
return platform === "win32" ? ";" : ":";
|
|
20104
|
-
}
|
|
20105
|
-
function pathDirectories(environment, platform) {
|
|
20106
|
-
return (environmentValue(environment, "PATH") ?? "").split(pathDelimiter(platform)).map((directory) => directory.trim().replace(/^"|"$/gu, "")).filter(Boolean);
|
|
20107
|
-
}
|
|
20108
|
-
function executableExtensions(command, platform, environment) {
|
|
20109
|
-
if (platform !== "win32")
|
|
20110
|
-
return [""];
|
|
20111
|
-
if (targetPath(platform).extname(command) !== "")
|
|
20112
|
-
return [""];
|
|
20113
|
-
return (environmentValue(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.trim()).filter(Boolean);
|
|
20114
|
-
}
|
|
20115
|
-
function isExecutableFile(filePath, platform) {
|
|
20116
|
-
try {
|
|
20117
|
-
fs.accessSync(filePath, platform === "win32" ? fs.constants.F_OK : fs.constants.X_OK);
|
|
20118
|
-
return fs.statSync(filePath).isFile();
|
|
20119
|
-
} catch {
|
|
20120
|
-
return false;
|
|
20376
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_change, params);
|
|
20121
20377
|
}
|
|
20122
|
-
|
|
20123
|
-
|
|
20124
|
-
|
|
20125
|
-
|
|
20126
|
-
|
|
20127
|
-
|
|
20378
|
+
/**
|
|
20379
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20380
|
+
*
|
|
20381
|
+
* Notifies the agent that a document was closed.
|
|
20382
|
+
*
|
|
20383
|
+
* @experimental
|
|
20384
|
+
*/
|
|
20385
|
+
unstable_didCloseDocument(params) {
|
|
20386
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_close, params);
|
|
20128
20387
|
}
|
|
20129
|
-
|
|
20130
|
-
|
|
20131
|
-
|
|
20132
|
-
|
|
20133
|
-
|
|
20134
|
-
|
|
20135
|
-
|
|
20136
|
-
|
|
20137
|
-
|
|
20138
|
-
if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
|
|
20139
|
-
return { command, arguments: [...arguments_], windowsVerbatimArguments: false };
|
|
20388
|
+
/**
|
|
20389
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20390
|
+
*
|
|
20391
|
+
* Notifies the agent that a document was saved.
|
|
20392
|
+
*
|
|
20393
|
+
* @experimental
|
|
20394
|
+
*/
|
|
20395
|
+
unstable_didSaveDocument(params) {
|
|
20396
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_save, params);
|
|
20140
20397
|
}
|
|
20141
|
-
|
|
20142
|
-
|
|
20143
|
-
|
|
20144
|
-
|
|
20145
|
-
|
|
20146
|
-
|
|
20147
|
-
|
|
20148
|
-
|
|
20149
|
-
|
|
20150
|
-
// ../../harness-discovery/dist/node-runtime.js
|
|
20151
|
-
import path4 from "node:path";
|
|
20152
|
-
function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
|
|
20153
|
-
const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
|
|
20154
|
-
const delimiter = platform === "win32" ? ";" : ":";
|
|
20155
|
-
const runtimeDirectory = path4.dirname(runtimeExecutable);
|
|
20156
|
-
const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
|
|
20157
|
-
const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
|
|
20158
|
-
if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
|
|
20159
|
-
directories.push(runtimeDirectory);
|
|
20398
|
+
/**
|
|
20399
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20400
|
+
*
|
|
20401
|
+
* Notifies the agent that a document received focus.
|
|
20402
|
+
*
|
|
20403
|
+
* @experimental
|
|
20404
|
+
*/
|
|
20405
|
+
unstable_didFocusDocument(params) {
|
|
20406
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_focus, params);
|
|
20160
20407
|
}
|
|
20161
|
-
|
|
20162
|
-
|
|
20163
|
-
|
|
20164
|
-
|
|
20165
|
-
|
|
20166
|
-
|
|
20167
|
-
|
|
20168
|
-
|
|
20169
|
-
|
|
20170
|
-
const list = context.subdirectories ?? subdirectoryNames;
|
|
20171
|
-
const pathFlavor = targetPath(platform);
|
|
20172
|
-
const value = (name) => environmentValue(environment, name);
|
|
20173
|
-
const directories = [];
|
|
20174
|
-
const versioned = (root, ...tail) => {
|
|
20175
|
-
for (const version2 of newestFirst(list(root))) {
|
|
20176
|
-
directories.push(pathFlavor.join(root, version2, ...tail));
|
|
20177
|
-
}
|
|
20178
|
-
};
|
|
20179
|
-
if (platform === "win32") {
|
|
20180
|
-
const appData = value("APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming");
|
|
20181
|
-
const localAppData = value("LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local");
|
|
20182
|
-
versioned(pathFlavor.join(appData, "nvm"));
|
|
20183
|
-
versioned(value("FNM_DIR") ?? pathFlavor.join(appData, "fnm", "node-versions"), "installation");
|
|
20184
|
-
directories.push(pathFlavor.join(localAppData, "Volta", "bin"));
|
|
20185
|
-
directories.push(pathFlavor.join(home, ".bun", "bin"));
|
|
20186
|
-
const pnpmHome2 = value("PNPM_HOME");
|
|
20187
|
-
if (pnpmHome2)
|
|
20188
|
-
directories.push(pnpmHome2);
|
|
20189
|
-
directories.push(pathFlavor.join(localAppData, "pnpm"));
|
|
20190
|
-
return directories;
|
|
20408
|
+
/**
|
|
20409
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20410
|
+
*
|
|
20411
|
+
* Notifies the agent that a NES suggestion was accepted.
|
|
20412
|
+
*
|
|
20413
|
+
* @experimental
|
|
20414
|
+
*/
|
|
20415
|
+
unstable_acceptNes(params) {
|
|
20416
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_accept, params);
|
|
20191
20417
|
}
|
|
20192
|
-
|
|
20193
|
-
|
|
20194
|
-
|
|
20195
|
-
|
|
20196
|
-
|
|
20197
|
-
|
|
20198
|
-
|
|
20199
|
-
|
|
20418
|
+
/**
|
|
20419
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20420
|
+
*
|
|
20421
|
+
* Notifies the agent that a NES suggestion was rejected.
|
|
20422
|
+
*
|
|
20423
|
+
* @experimental
|
|
20424
|
+
*/
|
|
20425
|
+
unstable_rejectNes(params) {
|
|
20426
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_reject, params);
|
|
20200
20427
|
}
|
|
20201
|
-
|
|
20202
|
-
|
|
20203
|
-
|
|
20204
|
-
const asdfHome = value("ASDF_DATA_DIR") ?? pathFlavor.join(home, ".asdf");
|
|
20205
|
-
versioned(pathFlavor.join(asdfHome, "installs", "nodejs"), "bin");
|
|
20206
|
-
directories.push(pathFlavor.join(asdfHome, "shims"));
|
|
20207
|
-
const nodenvHome = value("NODENV_ROOT") ?? pathFlavor.join(home, ".nodenv");
|
|
20208
|
-
versioned(pathFlavor.join(nodenvHome, "versions"), "bin");
|
|
20209
|
-
directories.push(pathFlavor.join(nodenvHome, "shims"));
|
|
20210
|
-
versioned(pathFlavor.join(value("N_PREFIX") ?? "/usr/local", "n", "versions", "node"), "bin");
|
|
20211
|
-
directories.push(pathFlavor.join(home, ".bun", "bin"));
|
|
20212
|
-
const pnpmHome = value("PNPM_HOME");
|
|
20213
|
-
if (pnpmHome)
|
|
20214
|
-
directories.push(pnpmHome);
|
|
20215
|
-
directories.push(pathFlavor.join(home, "Library", "pnpm"));
|
|
20216
|
-
directories.push(pathFlavor.join(home, ".local", "share", "pnpm"));
|
|
20217
|
-
for (const prefix of ["/opt/homebrew/opt", "/usr/local/opt"]) {
|
|
20218
|
-
for (const formula of newestFirst(list(prefix).filter((name) => name.startsWith("node@")))) {
|
|
20219
|
-
directories.push(pathFlavor.join(prefix, formula, "bin"));
|
|
20220
|
-
}
|
|
20428
|
+
request(method, params, options) {
|
|
20429
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
20430
|
+
return this.connection.sendRequest(method, params, spec?.mapResponse, options);
|
|
20221
20431
|
}
|
|
20222
|
-
|
|
20223
|
-
|
|
20224
|
-
|
|
20225
|
-
// ../../harness-discovery/dist/resolve.js
|
|
20226
|
-
var VERSION_MANAGER_ROOTS = "<version-managers>";
|
|
20227
|
-
function installRootExtensions(platform) {
|
|
20228
|
-
return platform === "win32" ? [".exe", ".cmd"] : [""];
|
|
20229
|
-
}
|
|
20230
|
-
function resolveHomeDirectory(input) {
|
|
20231
|
-
return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os2.homedir();
|
|
20232
|
-
}
|
|
20233
|
-
function templateVariables(environment, platform, home) {
|
|
20234
|
-
const pathFlavor = targetPath(platform);
|
|
20235
|
-
return {
|
|
20236
|
-
HOME: home,
|
|
20237
|
-
USERPROFILE: home,
|
|
20238
|
-
APPDATA: environmentValue(environment, "APPDATA") ?? pathFlavor.join(home, "AppData", "Roaming"),
|
|
20239
|
-
LOCALAPPDATA: environmentValue(environment, "LOCALAPPDATA") ?? pathFlavor.join(home, "AppData", "Local")
|
|
20240
|
-
};
|
|
20241
|
-
}
|
|
20242
|
-
function joinTemplate(platform, value) {
|
|
20243
|
-
const pathFlavor = targetPath(platform);
|
|
20244
|
-
const segments = value.split("/");
|
|
20245
|
-
const head = segments[0] ?? "";
|
|
20246
|
-
const tail = segments.slice(1);
|
|
20247
|
-
if (head === "")
|
|
20248
|
-
return pathFlavor.join(pathFlavor.sep, ...tail);
|
|
20249
|
-
return tail.length === 0 ? head : pathFlavor.join(head, ...tail);
|
|
20250
|
-
}
|
|
20251
|
-
function expandInstallRoot(template, environment, platform, home) {
|
|
20252
|
-
const variables = templateVariables(environment, platform, home);
|
|
20253
|
-
let unresolved = false;
|
|
20254
|
-
const substituted = template.replace(/^~(?=\/|$)/u, home).replace(/\$\{(\w+)\}/gu, (_match, name) => {
|
|
20255
|
-
const value = variables[name] ?? environmentValue(environment, name);
|
|
20256
|
-
if (value === void 0 || value === "") {
|
|
20257
|
-
unresolved = true;
|
|
20258
|
-
return "";
|
|
20259
|
-
}
|
|
20260
|
-
return value;
|
|
20261
|
-
});
|
|
20262
|
-
return unresolved ? void 0 : joinTemplate(platform, substituted);
|
|
20263
|
-
}
|
|
20264
|
-
function installRootDirectories(spec, input, dependencies, platform, home) {
|
|
20265
|
-
const templates = (platform === "win32" ? spec.installRoots?.windows : spec.installRoots?.posix) ?? [];
|
|
20266
|
-
const directories = [];
|
|
20267
|
-
for (const template of templates) {
|
|
20268
|
-
if (template === VERSION_MANAGER_ROOTS) {
|
|
20269
|
-
directories.push(...versionManagerBinaryDirectories({
|
|
20270
|
-
platform,
|
|
20271
|
-
environment: input.environment,
|
|
20272
|
-
home,
|
|
20273
|
-
...dependencies.subdirectories ? { subdirectories: dependencies.subdirectories } : {}
|
|
20274
|
-
}));
|
|
20275
|
-
continue;
|
|
20276
|
-
}
|
|
20277
|
-
const directory = expandInstallRoot(template, input.environment, platform, home);
|
|
20278
|
-
if (directory !== void 0)
|
|
20279
|
-
directories.push(directory);
|
|
20432
|
+
notify(method, params) {
|
|
20433
|
+
return this.connection.sendNotification(method, params);
|
|
20280
20434
|
}
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20287
|
-
|
|
20288
|
-
if (pathFlavor.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
20289
|
-
return [{ candidate: command, source: "configured" }];
|
|
20435
|
+
/**
|
|
20436
|
+
* Extension method.
|
|
20437
|
+
*
|
|
20438
|
+
* @deprecated Use {@link request}.
|
|
20439
|
+
*/
|
|
20440
|
+
extMethod(method, params) {
|
|
20441
|
+
return this.request(method, params);
|
|
20290
20442
|
}
|
|
20291
|
-
|
|
20292
|
-
|
|
20293
|
-
|
|
20294
|
-
|
|
20295
|
-
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
});
|
|
20299
|
-
}
|
|
20443
|
+
/**
|
|
20444
|
+
* Extension notification.
|
|
20445
|
+
*
|
|
20446
|
+
* @deprecated Use {@link notify}.
|
|
20447
|
+
*/
|
|
20448
|
+
extNotification(method, params) {
|
|
20449
|
+
return this.notify(method, params);
|
|
20300
20450
|
}
|
|
20301
|
-
|
|
20302
|
-
|
|
20303
|
-
|
|
20304
|
-
|
|
20305
|
-
|
|
20306
|
-
|
|
20307
|
-
|
|
20308
|
-
|
|
20309
|
-
|
|
20310
|
-
|
|
20451
|
+
/**
|
|
20452
|
+
* AbortSignal that aborts when the connection closes.
|
|
20453
|
+
*
|
|
20454
|
+
* This signal can be used to:
|
|
20455
|
+
* - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
|
|
20456
|
+
* - Check connection status synchronously: `if (connection.signal.aborted) {...}`
|
|
20457
|
+
* - Pass to other APIs (fetch, setTimeout) for automatic cancellation
|
|
20458
|
+
*
|
|
20459
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
20460
|
+
*
|
|
20461
|
+
* @example
|
|
20462
|
+
* ```typescript
|
|
20463
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
20464
|
+
*
|
|
20465
|
+
* // Listen for closure
|
|
20466
|
+
* connection.signal.addEventListener('abort', () => {
|
|
20467
|
+
* console.log('Connection closed - performing cleanup');
|
|
20468
|
+
* });
|
|
20469
|
+
*
|
|
20470
|
+
* // Check status
|
|
20471
|
+
* if (connection.signal.aborted) {
|
|
20472
|
+
* console.log('Connection is already closed');
|
|
20473
|
+
* }
|
|
20474
|
+
*
|
|
20475
|
+
* // Pass to other APIs
|
|
20476
|
+
* fetch(url, { signal: connection.signal });
|
|
20477
|
+
* ```
|
|
20478
|
+
*/
|
|
20479
|
+
get signal() {
|
|
20480
|
+
return this.connection.signal;
|
|
20311
20481
|
}
|
|
20312
|
-
|
|
20313
|
-
|
|
20314
|
-
|
|
20315
|
-
|
|
20316
|
-
|
|
20317
|
-
|
|
20318
|
-
|
|
20319
|
-
|
|
20320
|
-
|
|
20321
|
-
|
|
20322
|
-
|
|
20482
|
+
/**
|
|
20483
|
+
* Promise that resolves when the connection closes.
|
|
20484
|
+
*
|
|
20485
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
20486
|
+
* Once closed, the connection cannot send or receive any more messages.
|
|
20487
|
+
*
|
|
20488
|
+
* This is useful for async/await style cleanup:
|
|
20489
|
+
*
|
|
20490
|
+
* @example
|
|
20491
|
+
* ```typescript
|
|
20492
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
20493
|
+
* await connection.closed;
|
|
20494
|
+
* console.log('Connection closed - performing cleanup');
|
|
20495
|
+
* ```
|
|
20496
|
+
*/
|
|
20497
|
+
get closed() {
|
|
20498
|
+
return this.connection.closed;
|
|
20323
20499
|
}
|
|
20324
|
-
|
|
20325
|
-
}
|
|
20500
|
+
};
|
|
20326
20501
|
|
|
20327
|
-
//
|
|
20328
|
-
|
|
20329
|
-
|
|
20330
|
-
|
|
20331
|
-
|
|
20332
|
-
|
|
20333
|
-
|
|
20334
|
-
|
|
20335
|
-
|
|
20336
|
-
|
|
20337
|
-
|
|
20338
|
-
|
|
20339
|
-
|
|
20340
|
-
|
|
20341
|
-
|
|
20342
|
-
|
|
20343
|
-
|
|
20344
|
-
|
|
20345
|
-
|
|
20346
|
-
|
|
20347
|
-
|
|
20348
|
-
});
|
|
20349
|
-
child.stdin?.end();
|
|
20502
|
+
// dist/grok-slash-commands.js
|
|
20503
|
+
var GROK_LIVE_COMMAND_ID_PREFIX = "grok.slash.";
|
|
20504
|
+
function isRecord3(value) {
|
|
20505
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20506
|
+
}
|
|
20507
|
+
function parseGrokAvailableCommands(value) {
|
|
20508
|
+
if (!Array.isArray(value))
|
|
20509
|
+
return [];
|
|
20510
|
+
return value.flatMap((entry) => {
|
|
20511
|
+
if (!isRecord3(entry))
|
|
20512
|
+
return [];
|
|
20513
|
+
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
20514
|
+
if (!name)
|
|
20515
|
+
return [];
|
|
20516
|
+
return [
|
|
20517
|
+
{
|
|
20518
|
+
name,
|
|
20519
|
+
description: typeof entry.description === "string" ? entry.description : "",
|
|
20520
|
+
meta: isRecord3(entry._meta) ? entry._meta : null
|
|
20521
|
+
}
|
|
20522
|
+
];
|
|
20350
20523
|
});
|
|
20351
20524
|
}
|
|
20352
|
-
function
|
|
20353
|
-
|
|
20354
|
-
|
|
20355
|
-
return value.trim().replace(/^v/, "");
|
|
20525
|
+
function isGrokSkill(command) {
|
|
20526
|
+
const path14 = command.meta?.path;
|
|
20527
|
+
return typeof path14 === "string" && /(^|[\\/])SKILL\.md$/u.test(path14) || typeof command.meta?.qualifiedName === "string";
|
|
20356
20528
|
}
|
|
20357
|
-
function
|
|
20358
|
-
|
|
20359
|
-
|
|
20360
|
-
|
|
20361
|
-
|
|
20362
|
-
});
|
|
20363
|
-
return (action) => {
|
|
20364
|
-
if (updating)
|
|
20365
|
-
return updating;
|
|
20366
|
-
if (action === "check")
|
|
20367
|
-
return check2();
|
|
20368
|
-
updating = (async () => {
|
|
20369
|
-
const before = await check2();
|
|
20370
|
-
if (!before.updateAvailable)
|
|
20371
|
-
return before;
|
|
20372
|
-
if (!before.canUpdate)
|
|
20373
|
-
throw new Error(before.message ?? "This installation cannot be updated automatically");
|
|
20374
|
-
await options.update(before);
|
|
20375
|
-
const after = await check2();
|
|
20376
|
-
if (after.currentVersion === before.currentVersion)
|
|
20377
|
-
throw new Error("The Harness version did not change; check the native updater and retry");
|
|
20378
|
-
return after;
|
|
20379
|
-
})().finally(() => {
|
|
20380
|
-
updating = void 0;
|
|
20381
|
-
});
|
|
20382
|
-
return updating;
|
|
20383
|
-
};
|
|
20529
|
+
function grokLiveCommands(native) {
|
|
20530
|
+
return native.map((command) => ({
|
|
20531
|
+
name: command.name,
|
|
20532
|
+
description: command.description,
|
|
20533
|
+
kind: isGrokSkill(command) ? "skill" : "command"
|
|
20534
|
+
}));
|
|
20384
20535
|
}
|
|
20385
20536
|
|
|
20386
20537
|
// dist/command.js
|
|
20538
|
+
import path5 from "node:path";
|
|
20387
20539
|
var GrokExecutableError = class extends Error {
|
|
20388
20540
|
code = "GROK_NOT_FOUND";
|
|
20389
20541
|
};
|
|
@@ -20531,16 +20683,16 @@ var Diff = class {
|
|
|
20531
20683
|
}
|
|
20532
20684
|
}
|
|
20533
20685
|
}
|
|
20534
|
-
addToPath(
|
|
20535
|
-
const last =
|
|
20686
|
+
addToPath(path14, added, removed, oldPosInc, options) {
|
|
20687
|
+
const last = path14.lastComponent;
|
|
20536
20688
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
20537
20689
|
return {
|
|
20538
|
-
oldPos:
|
|
20690
|
+
oldPos: path14.oldPos + oldPosInc,
|
|
20539
20691
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
20540
20692
|
};
|
|
20541
20693
|
} else {
|
|
20542
20694
|
return {
|
|
20543
|
-
oldPos:
|
|
20695
|
+
oldPos: path14.oldPos + oldPosInc,
|
|
20544
20696
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
20545
20697
|
};
|
|
20546
20698
|
}
|
|
@@ -23268,6 +23420,323 @@ var GrokAcpTransport = class {
|
|
|
23268
23420
|
}
|
|
23269
23421
|
};
|
|
23270
23422
|
|
|
23423
|
+
// dist/session-import.js
|
|
23424
|
+
import { createReadStream } from "node:fs";
|
|
23425
|
+
import { opendir, readFile as readFile3, stat } from "node:fs/promises";
|
|
23426
|
+
import path11 from "node:path";
|
|
23427
|
+
import { createInterface } from "node:readline";
|
|
23428
|
+
|
|
23429
|
+
// ../../harness-adapter/dist/session-import.js
|
|
23430
|
+
import { lstat } from "node:fs/promises";
|
|
23431
|
+
var SessionImportChangedError = class extends Error {
|
|
23432
|
+
constructor(message = "Native Session changed during discovery; refresh and retry") {
|
|
23433
|
+
super(message);
|
|
23434
|
+
this.name = "SessionImportChangedError";
|
|
23435
|
+
}
|
|
23436
|
+
};
|
|
23437
|
+
function isMissingFileError(error53) {
|
|
23438
|
+
return typeof error53 === "object" && error53 !== null && "code" in error53 && error53.code === "ENOENT";
|
|
23439
|
+
}
|
|
23440
|
+
function sameFileFingerprint(left, right) {
|
|
23441
|
+
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;
|
|
23442
|
+
}
|
|
23443
|
+
var STORAGE_ACCESS_ERRORS = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EIO", "EMFILE", "ENFILE"]);
|
|
23444
|
+
function isStorageAccessError(error53) {
|
|
23445
|
+
return typeof error53 === "object" && error53 !== null && "code" in error53 && typeof error53.code === "string" && STORAGE_ACCESS_ERRORS.has(error53.code);
|
|
23446
|
+
}
|
|
23447
|
+
async function optionalLstat(file2) {
|
|
23448
|
+
try {
|
|
23449
|
+
return await lstat(file2);
|
|
23450
|
+
} catch (error53) {
|
|
23451
|
+
if (isMissingFileError(error53))
|
|
23452
|
+
return null;
|
|
23453
|
+
throw error53;
|
|
23454
|
+
}
|
|
23455
|
+
}
|
|
23456
|
+
async function readStableFiles(files, read) {
|
|
23457
|
+
const before = await Promise.all(files.map(optionalLstat));
|
|
23458
|
+
const value = await read(before);
|
|
23459
|
+
const after = await Promise.all(files.map(optionalLstat));
|
|
23460
|
+
if (before.some((info, index) => !sameFileFingerprint(info, after[index] ?? null)))
|
|
23461
|
+
throw new SessionImportChangedError();
|
|
23462
|
+
return value;
|
|
23463
|
+
}
|
|
23464
|
+
function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
|
|
23465
|
+
if (typeof value !== "string")
|
|
23466
|
+
return null;
|
|
23467
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
23468
|
+
if (!normalized)
|
|
23469
|
+
return null;
|
|
23470
|
+
if (normalized.length <= maxLength)
|
|
23471
|
+
return normalized;
|
|
23472
|
+
const characters = [...normalized];
|
|
23473
|
+
if (characters.length <= maxLength)
|
|
23474
|
+
return normalized;
|
|
23475
|
+
return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
|
|
23476
|
+
}
|
|
23477
|
+
function sessionImportCandidate(input) {
|
|
23478
|
+
const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
|
|
23479
|
+
const parsed = harnessSessionImportCandidateSchema.safeParse({
|
|
23480
|
+
nativeSessionId: input.nativeSessionId,
|
|
23481
|
+
cwd: input.cwd,
|
|
23482
|
+
title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
|
|
23483
|
+
updatedAt: Math.floor(time3),
|
|
23484
|
+
// Unknown must stay unknown; only an explicit boolean is a native statement.
|
|
23485
|
+
running: typeof input.running === "boolean" ? input.running : null
|
|
23486
|
+
});
|
|
23487
|
+
return parsed.success ? parsed.data : null;
|
|
23488
|
+
}
|
|
23489
|
+
var SessionImportScope = class {
|
|
23490
|
+
#abort = new AbortController();
|
|
23491
|
+
#options;
|
|
23492
|
+
#pending = /* @__PURE__ */ new Set();
|
|
23493
|
+
constructor(options) {
|
|
23494
|
+
this.#options = options;
|
|
23495
|
+
}
|
|
23496
|
+
#closed() {
|
|
23497
|
+
return {
|
|
23498
|
+
ok: false,
|
|
23499
|
+
error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
|
|
23500
|
+
};
|
|
23501
|
+
}
|
|
23502
|
+
read(operation) {
|
|
23503
|
+
const signal = this.#abort.signal;
|
|
23504
|
+
if (signal.aborted)
|
|
23505
|
+
return Promise.resolve(this.#closed());
|
|
23506
|
+
let started;
|
|
23507
|
+
try {
|
|
23508
|
+
started = operation(signal);
|
|
23509
|
+
} catch (error53) {
|
|
23510
|
+
started = Promise.reject(error53 instanceof Error ? error53 : new Error("Session read failed"));
|
|
23511
|
+
}
|
|
23512
|
+
const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
|
|
23513
|
+
ok: false,
|
|
23514
|
+
error: {
|
|
23515
|
+
code: "unavailable",
|
|
23516
|
+
message: this.#options.unavailableMessage,
|
|
23517
|
+
retryable: true
|
|
23518
|
+
}
|
|
23519
|
+
}).finally(() => this.#pending.delete(request));
|
|
23520
|
+
this.#pending.add(request);
|
|
23521
|
+
return request;
|
|
23522
|
+
}
|
|
23523
|
+
/** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
|
|
23524
|
+
async resolve(operation) {
|
|
23525
|
+
const result = await this.read(operation);
|
|
23526
|
+
if (!result.ok)
|
|
23527
|
+
return result;
|
|
23528
|
+
return result.value ? { ok: true, value: result.value } : {
|
|
23529
|
+
ok: false,
|
|
23530
|
+
error: {
|
|
23531
|
+
code: "sessionNotFound",
|
|
23532
|
+
message: this.#options.notFoundMessage,
|
|
23533
|
+
retryable: false
|
|
23534
|
+
}
|
|
23535
|
+
};
|
|
23536
|
+
}
|
|
23537
|
+
/** Idempotent. Resolves after every started read has settled. */
|
|
23538
|
+
async close() {
|
|
23539
|
+
this.#abort.abort();
|
|
23540
|
+
await Promise.allSettled(this.#pending);
|
|
23541
|
+
}
|
|
23542
|
+
};
|
|
23543
|
+
|
|
23544
|
+
// dist/session-import.js
|
|
23545
|
+
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
23546
|
+
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
23547
|
+
function isRecord12(value) {
|
|
23548
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23549
|
+
}
|
|
23550
|
+
async function readJson(file2, signal) {
|
|
23551
|
+
return JSON.parse(await readFile3(file2, { encoding: "utf8", signal }));
|
|
23552
|
+
}
|
|
23553
|
+
function processAlive(pid) {
|
|
23554
|
+
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
|
|
23555
|
+
return false;
|
|
23556
|
+
try {
|
|
23557
|
+
process.kill(pid, 0);
|
|
23558
|
+
return true;
|
|
23559
|
+
} catch (error53) {
|
|
23560
|
+
return isRecord12(error53) && error53.code === "EPERM";
|
|
23561
|
+
}
|
|
23562
|
+
}
|
|
23563
|
+
async function firstUserText(file2, signal) {
|
|
23564
|
+
const stream = createReadStream(file2, { encoding: "utf8", signal });
|
|
23565
|
+
const lines = createInterface({ input: stream, crlfDelay: Infinity });
|
|
23566
|
+
try {
|
|
23567
|
+
for await (const line of lines) {
|
|
23568
|
+
signal.throwIfAborted();
|
|
23569
|
+
if (!line.includes("user_message_chunk"))
|
|
23570
|
+
continue;
|
|
23571
|
+
let entry;
|
|
23572
|
+
try {
|
|
23573
|
+
entry = JSON.parse(line);
|
|
23574
|
+
} catch {
|
|
23575
|
+
continue;
|
|
23576
|
+
}
|
|
23577
|
+
const update = isRecord12(entry) && isRecord12(entry.params) ? entry.params.update : null;
|
|
23578
|
+
if (!isRecord12(update) || update.sessionUpdate !== "user_message_chunk")
|
|
23579
|
+
continue;
|
|
23580
|
+
const text = isRecord12(update.content) ? update.content.text : null;
|
|
23581
|
+
return typeof text === "string" ? text : "";
|
|
23582
|
+
}
|
|
23583
|
+
return null;
|
|
23584
|
+
} finally {
|
|
23585
|
+
lines.close();
|
|
23586
|
+
stream.destroy();
|
|
23587
|
+
}
|
|
23588
|
+
}
|
|
23589
|
+
var GrokSessionImport = class {
|
|
23590
|
+
#environment;
|
|
23591
|
+
#scope = new SessionImportScope({
|
|
23592
|
+
closedMessage: "Grok Session import is closed",
|
|
23593
|
+
unavailableMessage: "Grok sessions could not be read; close native clients, check storage access and retry",
|
|
23594
|
+
notFoundMessage: "Grok Session is no longer importable"
|
|
23595
|
+
});
|
|
23596
|
+
constructor(environment) {
|
|
23597
|
+
this.#environment = environment ? { ...environment } : void 0;
|
|
23598
|
+
}
|
|
23599
|
+
listCandidates() {
|
|
23600
|
+
return this.#scope.read(async (signal) => {
|
|
23601
|
+
const active = await this.#activeSessions(signal);
|
|
23602
|
+
const candidates = [];
|
|
23603
|
+
for (const [, directories] of await this.#sessionDirectories(signal)) {
|
|
23604
|
+
if (directories.length !== 1 || !directories[0])
|
|
23605
|
+
continue;
|
|
23606
|
+
try {
|
|
23607
|
+
const candidate = await this.#candidate(directories[0], active, signal);
|
|
23608
|
+
if (candidate)
|
|
23609
|
+
candidates.push(candidate);
|
|
23610
|
+
} catch (error53) {
|
|
23611
|
+
if (!(error53 instanceof SessionImportChangedError))
|
|
23612
|
+
throw error53;
|
|
23613
|
+
}
|
|
23614
|
+
}
|
|
23615
|
+
return candidates;
|
|
23616
|
+
});
|
|
23617
|
+
}
|
|
23618
|
+
resolveCandidate(nativeSessionId) {
|
|
23619
|
+
return this.#scope.resolve(async (signal) => {
|
|
23620
|
+
const directories = (await this.#sessionDirectories(signal)).get(nativeSessionId);
|
|
23621
|
+
if (directories?.length !== 1 || !directories[0])
|
|
23622
|
+
return null;
|
|
23623
|
+
const candidate = await this.#candidate(directories[0], await this.#activeSessions(signal), signal);
|
|
23624
|
+
if (!candidate)
|
|
23625
|
+
return null;
|
|
23626
|
+
return {
|
|
23627
|
+
candidate,
|
|
23628
|
+
nativeRef: nativeSessionRefSchema.parse({
|
|
23629
|
+
harnessId: "grok",
|
|
23630
|
+
nativeSessionId,
|
|
23631
|
+
formatVersion: 1
|
|
23632
|
+
})
|
|
23633
|
+
};
|
|
23634
|
+
});
|
|
23635
|
+
}
|
|
23636
|
+
close() {
|
|
23637
|
+
return this.#scope.close();
|
|
23638
|
+
}
|
|
23639
|
+
#home() {
|
|
23640
|
+
return grokHomeDir(this.#environment ? { environment: this.#environment } : {});
|
|
23641
|
+
}
|
|
23642
|
+
/** IDs a live Grok process currently holds open, from Grok's own registry. */
|
|
23643
|
+
async #activeSessions(signal) {
|
|
23644
|
+
const active = /* @__PURE__ */ new Set();
|
|
23645
|
+
let entries;
|
|
23646
|
+
try {
|
|
23647
|
+
entries = await readJson(path11.join(this.#home(), "active_sessions.json"), signal);
|
|
23648
|
+
} catch (error53) {
|
|
23649
|
+
signal.throwIfAborted();
|
|
23650
|
+
if (isStorageAccessError(error53))
|
|
23651
|
+
throw error53;
|
|
23652
|
+
return active;
|
|
23653
|
+
}
|
|
23654
|
+
if (!Array.isArray(entries))
|
|
23655
|
+
return active;
|
|
23656
|
+
for (const entry of entries) {
|
|
23657
|
+
if (isRecord12(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
23658
|
+
active.add(entry.session_id);
|
|
23659
|
+
}
|
|
23660
|
+
return active;
|
|
23661
|
+
}
|
|
23662
|
+
/** Session ID to every directory claiming it. Enumerated links are not followed. */
|
|
23663
|
+
async #sessionDirectories(signal) {
|
|
23664
|
+
const root = path11.join(this.#home(), "sessions");
|
|
23665
|
+
const found = /* @__PURE__ */ new Map();
|
|
23666
|
+
const info = await optionalLstat(root);
|
|
23667
|
+
if (!info)
|
|
23668
|
+
return found;
|
|
23669
|
+
if (!info.isDirectory())
|
|
23670
|
+
throw new Error("Grok Session store is not a directory");
|
|
23671
|
+
for await (const workspace of await opendir(root)) {
|
|
23672
|
+
signal.throwIfAborted();
|
|
23673
|
+
if (!workspace.isDirectory())
|
|
23674
|
+
continue;
|
|
23675
|
+
const workspaceDirectory = path11.join(root, workspace.name);
|
|
23676
|
+
const sessions = await opendir(workspaceDirectory).catch((error53) => {
|
|
23677
|
+
if (isMissingFileError(error53))
|
|
23678
|
+
return null;
|
|
23679
|
+
throw error53;
|
|
23680
|
+
});
|
|
23681
|
+
if (!sessions)
|
|
23682
|
+
continue;
|
|
23683
|
+
for await (const session of sessions) {
|
|
23684
|
+
signal.throwIfAborted();
|
|
23685
|
+
if (!session.isDirectory())
|
|
23686
|
+
continue;
|
|
23687
|
+
const directories = found.get(session.name) ?? [];
|
|
23688
|
+
directories.push(path11.join(workspaceDirectory, session.name));
|
|
23689
|
+
found.set(session.name, directories);
|
|
23690
|
+
}
|
|
23691
|
+
}
|
|
23692
|
+
return found;
|
|
23693
|
+
}
|
|
23694
|
+
async #candidate(sessionDirectory, active, signal) {
|
|
23695
|
+
signal.throwIfAborted();
|
|
23696
|
+
const nativeSessionId = path11.basename(sessionDirectory);
|
|
23697
|
+
const files = [
|
|
23698
|
+
path11.join(sessionDirectory, "summary.json"),
|
|
23699
|
+
path11.join(sessionDirectory, "updates.jsonl")
|
|
23700
|
+
];
|
|
23701
|
+
return readStableFiles(files, async ([summaryInfo, updates]) => {
|
|
23702
|
+
if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
|
|
23703
|
+
return null;
|
|
23704
|
+
try {
|
|
23705
|
+
const summary = await readJson(files[0], signal);
|
|
23706
|
+
if (!isRecord12(summary) || !isRecord12(summary.info) || summary.info.id !== nativeSessionId)
|
|
23707
|
+
return null;
|
|
23708
|
+
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
23709
|
+
return null;
|
|
23710
|
+
const nativeCwd = summary.info.cwd;
|
|
23711
|
+
if (typeof nativeCwd !== "string" || !path11.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
|
|
23712
|
+
return null;
|
|
23713
|
+
const cwd = path11.resolve(nativeCwd);
|
|
23714
|
+
if (encodeURIComponent(cwd) !== path11.basename(path11.dirname(sessionDirectory)))
|
|
23715
|
+
return null;
|
|
23716
|
+
if (!(await stat(cwd)).isDirectory())
|
|
23717
|
+
return null;
|
|
23718
|
+
const prompt = await firstUserText(files[1], signal);
|
|
23719
|
+
if (prompt === null)
|
|
23720
|
+
return null;
|
|
23721
|
+
const updatedAt = [summary.last_active_at, summary.updated_at].map((value) => typeof value === "string" ? Date.parse(value) : Number.NaN).find((value) => Number.isFinite(value) && value >= 0);
|
|
23722
|
+
return sessionImportCandidate({
|
|
23723
|
+
nativeSessionId,
|
|
23724
|
+
cwd,
|
|
23725
|
+
title: sessionImportTitle(summary.generated_title) ?? sessionImportTitle(summary.session_summary) ?? sessionImportTitle(prompt),
|
|
23726
|
+
updatedAt: updatedAt ?? updates.mtimeMs,
|
|
23727
|
+
// Grok registers open Sessions with their process. Absence is not proof of idleness.
|
|
23728
|
+
running: active.has(nativeSessionId) ? true : null
|
|
23729
|
+
});
|
|
23730
|
+
} catch (error53) {
|
|
23731
|
+
signal.throwIfAborted();
|
|
23732
|
+
if (isStorageAccessError(error53))
|
|
23733
|
+
throw error53;
|
|
23734
|
+
return null;
|
|
23735
|
+
}
|
|
23736
|
+
});
|
|
23737
|
+
}
|
|
23738
|
+
};
|
|
23739
|
+
|
|
23271
23740
|
// dist/grok-subagent-lifecycle.js
|
|
23272
23741
|
function subagentFailure() {
|
|
23273
23742
|
return {
|
|
@@ -23461,7 +23930,7 @@ var GrokSubagentLifecycle = class {
|
|
|
23461
23930
|
};
|
|
23462
23931
|
|
|
23463
23932
|
// dist/grok-models.js
|
|
23464
|
-
function
|
|
23933
|
+
function isRecord13(value) {
|
|
23465
23934
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23466
23935
|
}
|
|
23467
23936
|
function nonBlank(value) {
|
|
@@ -23473,7 +23942,7 @@ function thinkingOptions(value) {
|
|
|
23473
23942
|
const seen = /* @__PURE__ */ new Set();
|
|
23474
23943
|
const options = [];
|
|
23475
23944
|
for (const candidate of value) {
|
|
23476
|
-
if (!
|
|
23945
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.label))
|
|
23477
23946
|
continue;
|
|
23478
23947
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
23479
23948
|
if (!id.success || seen.has(id.data))
|
|
@@ -23484,7 +23953,7 @@ function thinkingOptions(value) {
|
|
|
23484
23953
|
return options;
|
|
23485
23954
|
}
|
|
23486
23955
|
function parseGrokModelState(value) {
|
|
23487
|
-
if (!
|
|
23956
|
+
if (!isRecord13(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
23488
23957
|
return null;
|
|
23489
23958
|
}
|
|
23490
23959
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -23495,12 +23964,12 @@ function parseGrokModelState(value) {
|
|
|
23495
23964
|
const models = [];
|
|
23496
23965
|
let currentThinkingOptionId;
|
|
23497
23966
|
for (const candidate of value.availableModels) {
|
|
23498
|
-
if (!
|
|
23967
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
23499
23968
|
continue;
|
|
23500
23969
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
23501
23970
|
if (!ref.success)
|
|
23502
23971
|
continue;
|
|
23503
|
-
const metadata =
|
|
23972
|
+
const metadata = isRecord13(candidate._meta) ? candidate._meta : {};
|
|
23504
23973
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
23505
23974
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
23506
23975
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
@@ -23535,10 +24004,10 @@ function parseGrokModelState(value) {
|
|
|
23535
24004
|
};
|
|
23536
24005
|
}
|
|
23537
24006
|
function modelStateFromInitialize(response) {
|
|
23538
|
-
return parseGrokModelState(
|
|
24007
|
+
return parseGrokModelState(isRecord13(response._meta) ? response._meta.modelState : void 0);
|
|
23539
24008
|
}
|
|
23540
24009
|
function modelStateFromSessionResponse(response) {
|
|
23541
|
-
return parseGrokModelState(
|
|
24010
|
+
return parseGrokModelState(isRecord13(response) ? response.models : void 0);
|
|
23542
24011
|
}
|
|
23543
24012
|
function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
23544
24013
|
const selectedModel = model;
|
|
@@ -23557,12 +24026,12 @@ function stateForGrokModel(modelState, nativeState, model = modelState.currentMo
|
|
|
23557
24026
|
}
|
|
23558
24027
|
|
|
23559
24028
|
// dist/grok-credits.js
|
|
23560
|
-
import { readFile as
|
|
24029
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
23561
24030
|
import os5 from "node:os";
|
|
23562
|
-
import
|
|
24031
|
+
import path12 from "node:path";
|
|
23563
24032
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
23564
24033
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
23565
|
-
function
|
|
24034
|
+
function isRecord14(value) {
|
|
23566
24035
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23567
24036
|
}
|
|
23568
24037
|
function finitePercent(value) {
|
|
@@ -23571,7 +24040,7 @@ function finitePercent(value) {
|
|
|
23571
24040
|
return Math.min(100, Math.max(0, value));
|
|
23572
24041
|
}
|
|
23573
24042
|
function nonNegativeCentValue(value) {
|
|
23574
|
-
if (!
|
|
24043
|
+
if (!isRecord14(value))
|
|
23575
24044
|
return void 0;
|
|
23576
24045
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
23577
24046
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -23579,7 +24048,7 @@ function nonNegativeCentValue(value) {
|
|
|
23579
24048
|
return amount;
|
|
23580
24049
|
}
|
|
23581
24050
|
function grokHome(environment) {
|
|
23582
|
-
return environment.GROK_HOME ??
|
|
24051
|
+
return environment.GROK_HOME ?? path12.join(environment.HOME ?? environment.USERPROFILE ?? os5.homedir(), ".grok");
|
|
23583
24052
|
}
|
|
23584
24053
|
function periodTypeFrom(value) {
|
|
23585
24054
|
if (typeof value !== "string")
|
|
@@ -23595,7 +24064,7 @@ function productUsageFrom(value) {
|
|
|
23595
24064
|
if (!Array.isArray(value))
|
|
23596
24065
|
return void 0;
|
|
23597
24066
|
const products = value.flatMap((entry) => {
|
|
23598
|
-
if (!
|
|
24067
|
+
if (!isRecord14(entry) || typeof entry.product !== "string")
|
|
23599
24068
|
return [];
|
|
23600
24069
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
23601
24070
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -23603,10 +24072,10 @@ function productUsageFrom(value) {
|
|
|
23603
24072
|
return products.length > 0 ? products : void 0;
|
|
23604
24073
|
}
|
|
23605
24074
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
23606
|
-
if (!
|
|
24075
|
+
if (!isRecord14(value) || !isRecord14(value.config))
|
|
23607
24076
|
return null;
|
|
23608
24077
|
const config2 = value.config;
|
|
23609
|
-
const period =
|
|
24078
|
+
const period = isRecord14(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
23610
24079
|
const periodType = periodTypeFrom(period?.type);
|
|
23611
24080
|
const resetsAt = (typeof period?.end === "string" && period.end.length > 0 ? period.end : void 0) ?? (typeof config2.billingPeriodEnd === "string" && config2.billingPeriodEnd.length > 0 ? config2.billingPeriodEnd : void 0);
|
|
23612
24081
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -23633,11 +24102,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
23633
24102
|
};
|
|
23634
24103
|
}
|
|
23635
24104
|
function selectAccessToken(auth, now) {
|
|
23636
|
-
if (!
|
|
24105
|
+
if (!isRecord14(auth))
|
|
23637
24106
|
return null;
|
|
23638
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
24107
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord14(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
|
|
23639
24108
|
for (const [, value] of entries) {
|
|
23640
|
-
if (!
|
|
24109
|
+
if (!isRecord14(value) || typeof value.key !== "string")
|
|
23641
24110
|
continue;
|
|
23642
24111
|
if (typeof value.expires_at === "string") {
|
|
23643
24112
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -23658,8 +24127,8 @@ async function fetchGrokAccount(input = {}) {
|
|
|
23658
24127
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
|
|
23659
24128
|
return null;
|
|
23660
24129
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
23661
|
-
const authPath =
|
|
23662
|
-
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await
|
|
24130
|
+
const authPath = path12.join(grokHome(environment), "auth.json");
|
|
24131
|
+
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile4(authPath, "utf8");
|
|
23663
24132
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
23664
24133
|
if (!token)
|
|
23665
24134
|
return null;
|
|
@@ -23708,7 +24177,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
23708
24177
|
|
|
23709
24178
|
// dist/grok-usage.js
|
|
23710
24179
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
23711
|
-
function
|
|
24180
|
+
function isRecord15(value) {
|
|
23712
24181
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23713
24182
|
}
|
|
23714
24183
|
function optionalToken(value) {
|
|
@@ -23725,7 +24194,7 @@ function combineUsage(base, next) {
|
|
|
23725
24194
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
23726
24195
|
}
|
|
23727
24196
|
function usageFromNative(value) {
|
|
23728
|
-
if (!
|
|
24197
|
+
if (!isRecord15(value))
|
|
23729
24198
|
return null;
|
|
23730
24199
|
const inputTokens = optionalToken(value.inputTokens);
|
|
23731
24200
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -23752,7 +24221,7 @@ function usageFromPrompt(response) {
|
|
|
23752
24221
|
return response.usage ? usageFromNative(response.usage) : null;
|
|
23753
24222
|
}
|
|
23754
24223
|
function usageFromSignals(value) {
|
|
23755
|
-
if (!
|
|
24224
|
+
if (!isRecord15(value))
|
|
23756
24225
|
return null;
|
|
23757
24226
|
try {
|
|
23758
24227
|
return parseHostUsage({
|
|
@@ -23772,7 +24241,7 @@ var summedUsageFields = [
|
|
|
23772
24241
|
"totalTokens"
|
|
23773
24242
|
];
|
|
23774
24243
|
function nativeCostTicks(value) {
|
|
23775
|
-
if (!
|
|
24244
|
+
if (!isRecord15(value))
|
|
23776
24245
|
return void 0;
|
|
23777
24246
|
const ticks = value.costUsdTicks;
|
|
23778
24247
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -23849,7 +24318,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
23849
24318
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
23850
24319
|
try {
|
|
23851
24320
|
if (update?.sessionUpdate === "usage_update") {
|
|
23852
|
-
const cost =
|
|
24321
|
+
const cost = isRecord15(update.cost) ? update.cost : null;
|
|
23853
24322
|
return parseHostUsage({
|
|
23854
24323
|
contextUsedTokens: update.used,
|
|
23855
24324
|
contextWindowTokens: update.size,
|
|
@@ -24861,6 +25330,7 @@ var GrokAdapter = class {
|
|
|
24861
25330
|
commandCatalog = grokCommandCatalog;
|
|
24862
25331
|
liveCommandCatalog = true;
|
|
24863
25332
|
harnessId = grokHarnessId;
|
|
25333
|
+
sessionImport;
|
|
24864
25334
|
subagents = {
|
|
24865
25335
|
readSnapshot: async (input) => {
|
|
24866
25336
|
if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
|
|
@@ -24908,6 +25378,7 @@ var GrokAdapter = class {
|
|
|
24908
25378
|
constructor(options = {}, dependencies) {
|
|
24909
25379
|
this.#closeTimeoutMs = options.closeTimeoutMs ?? DEFAULT_CLOSE_TIMEOUT_MS;
|
|
24910
25380
|
this.#environment = options.environment;
|
|
25381
|
+
this.sessionImport = new GrokSessionImport(options.environment);
|
|
24911
25382
|
this.#toolOutputLimit = options.toolOutputLimit ?? DEFAULT_GROK_TOOL_OUTPUT_LIMIT;
|
|
24912
25383
|
this.#dependencies = dependencies ?? {
|
|
24913
25384
|
randomUUID,
|
|
@@ -24951,7 +25422,7 @@ var GrokAdapter = class {
|
|
|
24951
25422
|
async inspect(input = {}) {
|
|
24952
25423
|
if (this.#closePromise)
|
|
24953
25424
|
return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
|
|
24954
|
-
const cwd =
|
|
25425
|
+
const cwd = path13.resolve(input.cwd ?? process.cwd());
|
|
24955
25426
|
if (!input.refresh) {
|
|
24956
25427
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
24957
25428
|
if (cached2)
|
|
@@ -25013,7 +25484,7 @@ var GrokAdapter = class {
|
|
|
25013
25484
|
}
|
|
25014
25485
|
};
|
|
25015
25486
|
}
|
|
25016
|
-
const cwd =
|
|
25487
|
+
const cwd = path13.resolve(input.cwd);
|
|
25017
25488
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
25018
25489
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
25019
25490
|
return {
|
|
@@ -25184,7 +25655,10 @@ var GrokAdapter = class {
|
|
|
25184
25655
|
if (!this.#closePromise) {
|
|
25185
25656
|
this.#accountAbort.abort();
|
|
25186
25657
|
this.#inspectionCache.clear();
|
|
25187
|
-
this.#closePromise = Promise.all([
|
|
25658
|
+
this.#closePromise = Promise.all([
|
|
25659
|
+
this.sessionImport.close(),
|
|
25660
|
+
...[...this.#sessions].map((session) => session.close())
|
|
25661
|
+
]).then(() => void 0);
|
|
25188
25662
|
}
|
|
25189
25663
|
return this.#closePromise;
|
|
25190
25664
|
}
|
|
@@ -25236,7 +25710,13 @@ function createHarnessAdapter(context) {
|
|
|
25236
25710
|
return Object.assign(new GrokAdapter({
|
|
25237
25711
|
...environment[GROK_COMMAND_ENV] ? { command: environment[GROK_COMMAND_ENV] } : {},
|
|
25238
25712
|
environment
|
|
25239
|
-
}), {
|
|
25713
|
+
}), {
|
|
25714
|
+
installation: createGrokInstallation(environment, environment[GROK_COMMAND_ENV]),
|
|
25715
|
+
install: createHarnessInstaller(environment, {
|
|
25716
|
+
npm: "@xai-official/grok",
|
|
25717
|
+
allowScripts: "@xai-official/grok"
|
|
25718
|
+
})
|
|
25719
|
+
});
|
|
25240
25720
|
}
|
|
25241
25721
|
export {
|
|
25242
25722
|
GROK_COMMAND_ENV,
|