@codexhost/cli-win32-arm64 0.11.0 → 0.12.0
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 +44 -2
- package/app/console-web.js +2216 -492
- package/app/desktop-controller.mjs +391 -189
- package/app/host-runtime.mjs +3917 -625
- package/app/plugins/antigravity/plugin.mjs +15634 -15526
- package/app/plugins/claude-code/plugin.mjs +215 -70
- package/app/plugins/codebuddy/plugin.mjs +1260 -827
- package/app/plugins/cursor-cli/plugin.mjs +529 -370
- package/app/plugins/deepseek-harness/plugin.mjs +25467 -26242
- package/app/plugins/enabled.json +2 -1
- package/app/plugins/grok/plugin.mjs +936 -505
- package/app/plugins/hermes/plugin.mjs +18659 -23012
- package/app/plugins/kimi-code/plugin.mjs +1046 -703
- package/app/plugins/kiro-cli/plugin.mjs +959 -590
- package/app/plugins/omp/plugin.mjs +1038 -576
- package/app/plugins/opencode/plugin.mjs +961 -700
- package/app/plugins/pi/plugin.mjs +15911 -15724
- package/app/plugins/qoder/plugin.mjs +679 -375
- package/app/plugins/qoder-cn/plugin.mjs +345 -39
- package/app/plugins/workbuddy/plugin.mjs +417 -40
- package/app/plugins/zcode/assets/icon.svg +8 -0
- package/app/plugins/zcode/manifest.json +14 -0
- package/app/plugins/zcode/plugin.mjs +19202 -0
- package/app/renderer-extension.js +2495 -486
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +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
|
}
|
|
@@ -14647,6 +15014,7 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
14647
15014
|
"codexhost/harness/display-settings/get",
|
|
14648
15015
|
"codexhost/harness/display-settings/set",
|
|
14649
15016
|
"codexhost/harness/inspect",
|
|
15017
|
+
"codexhost/harness/installation",
|
|
14650
15018
|
"codexhost/harness/launch-settings/get",
|
|
14651
15019
|
"codexhost/harness/launch-settings/set",
|
|
14652
15020
|
"codexhost/harness/web-ui/open",
|
|
@@ -15293,14 +15661,17 @@ var harnessLaunchSettingsSchema = external_exports.object({
|
|
|
15293
15661
|
// ../../shared-contracts/dist/harness-installation.js
|
|
15294
15662
|
var harnessInstallationParamsSchema = external_exports.object({
|
|
15295
15663
|
harnessId: harnessIdSchema,
|
|
15296
|
-
action: external_exports.enum(["check", "update"])
|
|
15664
|
+
action: external_exports.enum(["check", "update", "install"])
|
|
15297
15665
|
}).strict();
|
|
15298
15666
|
var harnessInstallationStateSchema = external_exports.object({
|
|
15299
15667
|
currentVersion: external_exports.string().min(1).max(128),
|
|
15300
15668
|
latestVersion: external_exports.string().min(1).max(128),
|
|
15301
15669
|
updateAvailable: external_exports.boolean(),
|
|
15302
15670
|
canUpdate: external_exports.boolean(),
|
|
15303
|
-
|
|
15671
|
+
// Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
|
|
15672
|
+
message: external_exports.string().max(2048).optional(),
|
|
15673
|
+
messageCode: external_exports.string().min(1).max(128).optional(),
|
|
15674
|
+
latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
|
|
15304
15675
|
}).strict();
|
|
15305
15676
|
|
|
15306
15677
|
// ../../shared-contracts/dist/codex-accounts.js
|
|
@@ -15602,6 +15973,38 @@ var updateStatusResultSchema = external_exports.strictObject({
|
|
|
15602
15973
|
status: updateStatusSchema.nullable()
|
|
15603
15974
|
});
|
|
15604
15975
|
|
|
15976
|
+
// ../../shared-contracts/dist/remote-runtime.js
|
|
15977
|
+
var remoteUpdatePhaseSchema = external_exports.enum([
|
|
15978
|
+
"idle",
|
|
15979
|
+
"installing",
|
|
15980
|
+
"restarting",
|
|
15981
|
+
"succeeded",
|
|
15982
|
+
"failed"
|
|
15983
|
+
]);
|
|
15984
|
+
var runtimeStatusSchema = external_exports.object({
|
|
15985
|
+
runningVersion: external_exports.string().nullable(),
|
|
15986
|
+
installedVersion: external_exports.string().nullable(),
|
|
15987
|
+
restartRequired: external_exports.boolean(),
|
|
15988
|
+
remote: external_exports.boolean(),
|
|
15989
|
+
updateSupported: external_exports.boolean(),
|
|
15990
|
+
update: external_exports.object({
|
|
15991
|
+
phase: remoteUpdatePhaseSchema,
|
|
15992
|
+
targetVersion: external_exports.string().nullable(),
|
|
15993
|
+
error: external_exports.string().nullable()
|
|
15994
|
+
})
|
|
15995
|
+
});
|
|
15996
|
+
var remoteUpdateParamsSchema = external_exports.object({
|
|
15997
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
|
|
15998
|
+
}).strict();
|
|
15999
|
+
var remoteSshSetupParamsSchema = external_exports.object({
|
|
16000
|
+
hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
|
|
16001
|
+
port: external_exports.number().int().min(1).max(65535).nullable(),
|
|
16002
|
+
identity: external_exports.string().max(4096).nullable(),
|
|
16003
|
+
action: external_exports.enum(["inspect", "install", "update", "repair"]),
|
|
16004
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
|
|
16005
|
+
}).strict();
|
|
16006
|
+
var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
|
|
16007
|
+
|
|
15605
16008
|
// ../../shared-contracts/dist/index.js
|
|
15606
16009
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
15607
16010
|
|
|
@@ -19921,469 +20324,169 @@ var ClientSideConnection = class {
|
|
|
19921
20324
|
* @experimental
|
|
19922
20325
|
*/
|
|
19923
20326
|
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;
|
|
20327
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_change, params);
|
|
20121
20328
|
}
|
|
20122
|
-
|
|
20123
|
-
|
|
20124
|
-
|
|
20125
|
-
|
|
20126
|
-
|
|
20127
|
-
|
|
20329
|
+
/**
|
|
20330
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20331
|
+
*
|
|
20332
|
+
* Notifies the agent that a document was closed.
|
|
20333
|
+
*
|
|
20334
|
+
* @experimental
|
|
20335
|
+
*/
|
|
20336
|
+
unstable_didCloseDocument(params) {
|
|
20337
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_close, params);
|
|
20128
20338
|
}
|
|
20129
|
-
|
|
20130
|
-
|
|
20131
|
-
|
|
20132
|
-
|
|
20133
|
-
|
|
20134
|
-
|
|
20135
|
-
|
|
20136
|
-
|
|
20137
|
-
|
|
20138
|
-
if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
|
|
20139
|
-
return { command, arguments: [...arguments_], windowsVerbatimArguments: false };
|
|
20339
|
+
/**
|
|
20340
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20341
|
+
*
|
|
20342
|
+
* Notifies the agent that a document was saved.
|
|
20343
|
+
*
|
|
20344
|
+
* @experimental
|
|
20345
|
+
*/
|
|
20346
|
+
unstable_didSaveDocument(params) {
|
|
20347
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_save, params);
|
|
20140
20348
|
}
|
|
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);
|
|
20349
|
+
/**
|
|
20350
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20351
|
+
*
|
|
20352
|
+
* Notifies the agent that a document received focus.
|
|
20353
|
+
*
|
|
20354
|
+
* @experimental
|
|
20355
|
+
*/
|
|
20356
|
+
unstable_didFocusDocument(params) {
|
|
20357
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_focus, params);
|
|
20160
20358
|
}
|
|
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;
|
|
20359
|
+
/**
|
|
20360
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20361
|
+
*
|
|
20362
|
+
* Notifies the agent that a NES suggestion was accepted.
|
|
20363
|
+
*
|
|
20364
|
+
* @experimental
|
|
20365
|
+
*/
|
|
20366
|
+
unstable_acceptNes(params) {
|
|
20367
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_accept, params);
|
|
20191
20368
|
}
|
|
20192
|
-
|
|
20193
|
-
|
|
20194
|
-
|
|
20195
|
-
|
|
20196
|
-
|
|
20197
|
-
|
|
20198
|
-
|
|
20199
|
-
|
|
20369
|
+
/**
|
|
20370
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
20371
|
+
*
|
|
20372
|
+
* Notifies the agent that a NES suggestion was rejected.
|
|
20373
|
+
*
|
|
20374
|
+
* @experimental
|
|
20375
|
+
*/
|
|
20376
|
+
unstable_rejectNes(params) {
|
|
20377
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_reject, params);
|
|
20200
20378
|
}
|
|
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
|
-
}
|
|
20379
|
+
request(method, params, options) {
|
|
20380
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
20381
|
+
return this.connection.sendRequest(method, params, spec?.mapResponse, options);
|
|
20221
20382
|
}
|
|
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);
|
|
20383
|
+
notify(method, params) {
|
|
20384
|
+
return this.connection.sendNotification(method, params);
|
|
20280
20385
|
}
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
|
|
20286
|
-
|
|
20287
|
-
|
|
20288
|
-
if (pathFlavor.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
20289
|
-
return [{ candidate: command, source: "configured" }];
|
|
20386
|
+
/**
|
|
20387
|
+
* Extension method.
|
|
20388
|
+
*
|
|
20389
|
+
* @deprecated Use {@link request}.
|
|
20390
|
+
*/
|
|
20391
|
+
extMethod(method, params) {
|
|
20392
|
+
return this.request(method, params);
|
|
20290
20393
|
}
|
|
20291
|
-
|
|
20292
|
-
|
|
20293
|
-
|
|
20294
|
-
|
|
20295
|
-
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
});
|
|
20299
|
-
}
|
|
20394
|
+
/**
|
|
20395
|
+
* Extension notification.
|
|
20396
|
+
*
|
|
20397
|
+
* @deprecated Use {@link notify}.
|
|
20398
|
+
*/
|
|
20399
|
+
extNotification(method, params) {
|
|
20400
|
+
return this.notify(method, params);
|
|
20300
20401
|
}
|
|
20301
|
-
|
|
20302
|
-
|
|
20303
|
-
|
|
20304
|
-
|
|
20305
|
-
|
|
20306
|
-
|
|
20307
|
-
|
|
20308
|
-
|
|
20309
|
-
|
|
20310
|
-
|
|
20402
|
+
/**
|
|
20403
|
+
* AbortSignal that aborts when the connection closes.
|
|
20404
|
+
*
|
|
20405
|
+
* This signal can be used to:
|
|
20406
|
+
* - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
|
|
20407
|
+
* - Check connection status synchronously: `if (connection.signal.aborted) {...}`
|
|
20408
|
+
* - Pass to other APIs (fetch, setTimeout) for automatic cancellation
|
|
20409
|
+
*
|
|
20410
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
20411
|
+
*
|
|
20412
|
+
* @example
|
|
20413
|
+
* ```typescript
|
|
20414
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
20415
|
+
*
|
|
20416
|
+
* // Listen for closure
|
|
20417
|
+
* connection.signal.addEventListener('abort', () => {
|
|
20418
|
+
* console.log('Connection closed - performing cleanup');
|
|
20419
|
+
* });
|
|
20420
|
+
*
|
|
20421
|
+
* // Check status
|
|
20422
|
+
* if (connection.signal.aborted) {
|
|
20423
|
+
* console.log('Connection is already closed');
|
|
20424
|
+
* }
|
|
20425
|
+
*
|
|
20426
|
+
* // Pass to other APIs
|
|
20427
|
+
* fetch(url, { signal: connection.signal });
|
|
20428
|
+
* ```
|
|
20429
|
+
*/
|
|
20430
|
+
get signal() {
|
|
20431
|
+
return this.connection.signal;
|
|
20311
20432
|
}
|
|
20312
|
-
|
|
20313
|
-
|
|
20314
|
-
|
|
20315
|
-
|
|
20316
|
-
|
|
20317
|
-
|
|
20318
|
-
|
|
20319
|
-
|
|
20320
|
-
|
|
20321
|
-
|
|
20322
|
-
|
|
20433
|
+
/**
|
|
20434
|
+
* Promise that resolves when the connection closes.
|
|
20435
|
+
*
|
|
20436
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
20437
|
+
* Once closed, the connection cannot send or receive any more messages.
|
|
20438
|
+
*
|
|
20439
|
+
* This is useful for async/await style cleanup:
|
|
20440
|
+
*
|
|
20441
|
+
* @example
|
|
20442
|
+
* ```typescript
|
|
20443
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
20444
|
+
* await connection.closed;
|
|
20445
|
+
* console.log('Connection closed - performing cleanup');
|
|
20446
|
+
* ```
|
|
20447
|
+
*/
|
|
20448
|
+
get closed() {
|
|
20449
|
+
return this.connection.closed;
|
|
20323
20450
|
}
|
|
20324
|
-
|
|
20325
|
-
}
|
|
20451
|
+
};
|
|
20326
20452
|
|
|
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();
|
|
20453
|
+
// dist/grok-slash-commands.js
|
|
20454
|
+
var GROK_LIVE_COMMAND_ID_PREFIX = "grok.slash.";
|
|
20455
|
+
function isRecord3(value) {
|
|
20456
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20457
|
+
}
|
|
20458
|
+
function parseGrokAvailableCommands(value) {
|
|
20459
|
+
if (!Array.isArray(value))
|
|
20460
|
+
return [];
|
|
20461
|
+
return value.flatMap((entry) => {
|
|
20462
|
+
if (!isRecord3(entry))
|
|
20463
|
+
return [];
|
|
20464
|
+
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
20465
|
+
if (!name)
|
|
20466
|
+
return [];
|
|
20467
|
+
return [
|
|
20468
|
+
{
|
|
20469
|
+
name,
|
|
20470
|
+
description: typeof entry.description === "string" ? entry.description : "",
|
|
20471
|
+
meta: isRecord3(entry._meta) ? entry._meta : null
|
|
20472
|
+
}
|
|
20473
|
+
];
|
|
20350
20474
|
});
|
|
20351
20475
|
}
|
|
20352
|
-
function
|
|
20353
|
-
|
|
20354
|
-
|
|
20355
|
-
return value.trim().replace(/^v/, "");
|
|
20476
|
+
function isGrokSkill(command) {
|
|
20477
|
+
const path14 = command.meta?.path;
|
|
20478
|
+
return typeof path14 === "string" && /(^|[\\/])SKILL\.md$/u.test(path14) || typeof command.meta?.qualifiedName === "string";
|
|
20356
20479
|
}
|
|
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
|
-
};
|
|
20480
|
+
function grokLiveCommands(native) {
|
|
20481
|
+
return native.map((command) => ({
|
|
20482
|
+
name: command.name,
|
|
20483
|
+
description: command.description,
|
|
20484
|
+
kind: isGrokSkill(command) ? "skill" : "command"
|
|
20485
|
+
}));
|
|
20384
20486
|
}
|
|
20385
20487
|
|
|
20386
20488
|
// dist/command.js
|
|
20489
|
+
import path5 from "node:path";
|
|
20387
20490
|
var GrokExecutableError = class extends Error {
|
|
20388
20491
|
code = "GROK_NOT_FOUND";
|
|
20389
20492
|
};
|
|
@@ -20531,16 +20634,16 @@ var Diff = class {
|
|
|
20531
20634
|
}
|
|
20532
20635
|
}
|
|
20533
20636
|
}
|
|
20534
|
-
addToPath(
|
|
20535
|
-
const last =
|
|
20637
|
+
addToPath(path14, added, removed, oldPosInc, options) {
|
|
20638
|
+
const last = path14.lastComponent;
|
|
20536
20639
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
20537
20640
|
return {
|
|
20538
|
-
oldPos:
|
|
20641
|
+
oldPos: path14.oldPos + oldPosInc,
|
|
20539
20642
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
20540
20643
|
};
|
|
20541
20644
|
} else {
|
|
20542
20645
|
return {
|
|
20543
|
-
oldPos:
|
|
20646
|
+
oldPos: path14.oldPos + oldPosInc,
|
|
20544
20647
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
20545
20648
|
};
|
|
20546
20649
|
}
|
|
@@ -23268,6 +23371,323 @@ var GrokAcpTransport = class {
|
|
|
23268
23371
|
}
|
|
23269
23372
|
};
|
|
23270
23373
|
|
|
23374
|
+
// dist/session-import.js
|
|
23375
|
+
import { createReadStream } from "node:fs";
|
|
23376
|
+
import { opendir, readFile as readFile3, stat } from "node:fs/promises";
|
|
23377
|
+
import path11 from "node:path";
|
|
23378
|
+
import { createInterface } from "node:readline";
|
|
23379
|
+
|
|
23380
|
+
// ../../harness-adapter/dist/session-import.js
|
|
23381
|
+
import { lstat } from "node:fs/promises";
|
|
23382
|
+
var SessionImportChangedError = class extends Error {
|
|
23383
|
+
constructor(message = "Native Session changed during discovery; refresh and retry") {
|
|
23384
|
+
super(message);
|
|
23385
|
+
this.name = "SessionImportChangedError";
|
|
23386
|
+
}
|
|
23387
|
+
};
|
|
23388
|
+
function isMissingFileError(error53) {
|
|
23389
|
+
return typeof error53 === "object" && error53 !== null && "code" in error53 && error53.code === "ENOENT";
|
|
23390
|
+
}
|
|
23391
|
+
function sameFileFingerprint(left, right) {
|
|
23392
|
+
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;
|
|
23393
|
+
}
|
|
23394
|
+
var STORAGE_ACCESS_ERRORS = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EIO", "EMFILE", "ENFILE"]);
|
|
23395
|
+
function isStorageAccessError(error53) {
|
|
23396
|
+
return typeof error53 === "object" && error53 !== null && "code" in error53 && typeof error53.code === "string" && STORAGE_ACCESS_ERRORS.has(error53.code);
|
|
23397
|
+
}
|
|
23398
|
+
async function optionalLstat(file2) {
|
|
23399
|
+
try {
|
|
23400
|
+
return await lstat(file2);
|
|
23401
|
+
} catch (error53) {
|
|
23402
|
+
if (isMissingFileError(error53))
|
|
23403
|
+
return null;
|
|
23404
|
+
throw error53;
|
|
23405
|
+
}
|
|
23406
|
+
}
|
|
23407
|
+
async function readStableFiles(files, read) {
|
|
23408
|
+
const before = await Promise.all(files.map(optionalLstat));
|
|
23409
|
+
const value = await read(before);
|
|
23410
|
+
const after = await Promise.all(files.map(optionalLstat));
|
|
23411
|
+
if (before.some((info, index) => !sameFileFingerprint(info, after[index] ?? null)))
|
|
23412
|
+
throw new SessionImportChangedError();
|
|
23413
|
+
return value;
|
|
23414
|
+
}
|
|
23415
|
+
function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
|
|
23416
|
+
if (typeof value !== "string")
|
|
23417
|
+
return null;
|
|
23418
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
23419
|
+
if (!normalized)
|
|
23420
|
+
return null;
|
|
23421
|
+
if (normalized.length <= maxLength)
|
|
23422
|
+
return normalized;
|
|
23423
|
+
const characters = [...normalized];
|
|
23424
|
+
if (characters.length <= maxLength)
|
|
23425
|
+
return normalized;
|
|
23426
|
+
return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
|
|
23427
|
+
}
|
|
23428
|
+
function sessionImportCandidate(input) {
|
|
23429
|
+
const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
|
|
23430
|
+
const parsed = harnessSessionImportCandidateSchema.safeParse({
|
|
23431
|
+
nativeSessionId: input.nativeSessionId,
|
|
23432
|
+
cwd: input.cwd,
|
|
23433
|
+
title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
|
|
23434
|
+
updatedAt: Math.floor(time3),
|
|
23435
|
+
// Unknown must stay unknown; only an explicit boolean is a native statement.
|
|
23436
|
+
running: typeof input.running === "boolean" ? input.running : null
|
|
23437
|
+
});
|
|
23438
|
+
return parsed.success ? parsed.data : null;
|
|
23439
|
+
}
|
|
23440
|
+
var SessionImportScope = class {
|
|
23441
|
+
#abort = new AbortController();
|
|
23442
|
+
#options;
|
|
23443
|
+
#pending = /* @__PURE__ */ new Set();
|
|
23444
|
+
constructor(options) {
|
|
23445
|
+
this.#options = options;
|
|
23446
|
+
}
|
|
23447
|
+
#closed() {
|
|
23448
|
+
return {
|
|
23449
|
+
ok: false,
|
|
23450
|
+
error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
|
|
23451
|
+
};
|
|
23452
|
+
}
|
|
23453
|
+
read(operation) {
|
|
23454
|
+
const signal = this.#abort.signal;
|
|
23455
|
+
if (signal.aborted)
|
|
23456
|
+
return Promise.resolve(this.#closed());
|
|
23457
|
+
let started;
|
|
23458
|
+
try {
|
|
23459
|
+
started = operation(signal);
|
|
23460
|
+
} catch (error53) {
|
|
23461
|
+
started = Promise.reject(error53 instanceof Error ? error53 : new Error("Session read failed"));
|
|
23462
|
+
}
|
|
23463
|
+
const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
|
|
23464
|
+
ok: false,
|
|
23465
|
+
error: {
|
|
23466
|
+
code: "unavailable",
|
|
23467
|
+
message: this.#options.unavailableMessage,
|
|
23468
|
+
retryable: true
|
|
23469
|
+
}
|
|
23470
|
+
}).finally(() => this.#pending.delete(request));
|
|
23471
|
+
this.#pending.add(request);
|
|
23472
|
+
return request;
|
|
23473
|
+
}
|
|
23474
|
+
/** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
|
|
23475
|
+
async resolve(operation) {
|
|
23476
|
+
const result = await this.read(operation);
|
|
23477
|
+
if (!result.ok)
|
|
23478
|
+
return result;
|
|
23479
|
+
return result.value ? { ok: true, value: result.value } : {
|
|
23480
|
+
ok: false,
|
|
23481
|
+
error: {
|
|
23482
|
+
code: "sessionNotFound",
|
|
23483
|
+
message: this.#options.notFoundMessage,
|
|
23484
|
+
retryable: false
|
|
23485
|
+
}
|
|
23486
|
+
};
|
|
23487
|
+
}
|
|
23488
|
+
/** Idempotent. Resolves after every started read has settled. */
|
|
23489
|
+
async close() {
|
|
23490
|
+
this.#abort.abort();
|
|
23491
|
+
await Promise.allSettled(this.#pending);
|
|
23492
|
+
}
|
|
23493
|
+
};
|
|
23494
|
+
|
|
23495
|
+
// dist/session-import.js
|
|
23496
|
+
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
23497
|
+
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
23498
|
+
function isRecord12(value) {
|
|
23499
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23500
|
+
}
|
|
23501
|
+
async function readJson(file2, signal) {
|
|
23502
|
+
return JSON.parse(await readFile3(file2, { encoding: "utf8", signal }));
|
|
23503
|
+
}
|
|
23504
|
+
function processAlive(pid) {
|
|
23505
|
+
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
|
|
23506
|
+
return false;
|
|
23507
|
+
try {
|
|
23508
|
+
process.kill(pid, 0);
|
|
23509
|
+
return true;
|
|
23510
|
+
} catch (error53) {
|
|
23511
|
+
return isRecord12(error53) && error53.code === "EPERM";
|
|
23512
|
+
}
|
|
23513
|
+
}
|
|
23514
|
+
async function firstUserText(file2, signal) {
|
|
23515
|
+
const stream = createReadStream(file2, { encoding: "utf8", signal });
|
|
23516
|
+
const lines = createInterface({ input: stream, crlfDelay: Infinity });
|
|
23517
|
+
try {
|
|
23518
|
+
for await (const line of lines) {
|
|
23519
|
+
signal.throwIfAborted();
|
|
23520
|
+
if (!line.includes("user_message_chunk"))
|
|
23521
|
+
continue;
|
|
23522
|
+
let entry;
|
|
23523
|
+
try {
|
|
23524
|
+
entry = JSON.parse(line);
|
|
23525
|
+
} catch {
|
|
23526
|
+
continue;
|
|
23527
|
+
}
|
|
23528
|
+
const update = isRecord12(entry) && isRecord12(entry.params) ? entry.params.update : null;
|
|
23529
|
+
if (!isRecord12(update) || update.sessionUpdate !== "user_message_chunk")
|
|
23530
|
+
continue;
|
|
23531
|
+
const text = isRecord12(update.content) ? update.content.text : null;
|
|
23532
|
+
return typeof text === "string" ? text : "";
|
|
23533
|
+
}
|
|
23534
|
+
return null;
|
|
23535
|
+
} finally {
|
|
23536
|
+
lines.close();
|
|
23537
|
+
stream.destroy();
|
|
23538
|
+
}
|
|
23539
|
+
}
|
|
23540
|
+
var GrokSessionImport = class {
|
|
23541
|
+
#environment;
|
|
23542
|
+
#scope = new SessionImportScope({
|
|
23543
|
+
closedMessage: "Grok Session import is closed",
|
|
23544
|
+
unavailableMessage: "Grok sessions could not be read; close native clients, check storage access and retry",
|
|
23545
|
+
notFoundMessage: "Grok Session is no longer importable"
|
|
23546
|
+
});
|
|
23547
|
+
constructor(environment) {
|
|
23548
|
+
this.#environment = environment ? { ...environment } : void 0;
|
|
23549
|
+
}
|
|
23550
|
+
listCandidates() {
|
|
23551
|
+
return this.#scope.read(async (signal) => {
|
|
23552
|
+
const active = await this.#activeSessions(signal);
|
|
23553
|
+
const candidates = [];
|
|
23554
|
+
for (const [, directories] of await this.#sessionDirectories(signal)) {
|
|
23555
|
+
if (directories.length !== 1 || !directories[0])
|
|
23556
|
+
continue;
|
|
23557
|
+
try {
|
|
23558
|
+
const candidate = await this.#candidate(directories[0], active, signal);
|
|
23559
|
+
if (candidate)
|
|
23560
|
+
candidates.push(candidate);
|
|
23561
|
+
} catch (error53) {
|
|
23562
|
+
if (!(error53 instanceof SessionImportChangedError))
|
|
23563
|
+
throw error53;
|
|
23564
|
+
}
|
|
23565
|
+
}
|
|
23566
|
+
return candidates;
|
|
23567
|
+
});
|
|
23568
|
+
}
|
|
23569
|
+
resolveCandidate(nativeSessionId) {
|
|
23570
|
+
return this.#scope.resolve(async (signal) => {
|
|
23571
|
+
const directories = (await this.#sessionDirectories(signal)).get(nativeSessionId);
|
|
23572
|
+
if (directories?.length !== 1 || !directories[0])
|
|
23573
|
+
return null;
|
|
23574
|
+
const candidate = await this.#candidate(directories[0], await this.#activeSessions(signal), signal);
|
|
23575
|
+
if (!candidate)
|
|
23576
|
+
return null;
|
|
23577
|
+
return {
|
|
23578
|
+
candidate,
|
|
23579
|
+
nativeRef: nativeSessionRefSchema.parse({
|
|
23580
|
+
harnessId: "grok",
|
|
23581
|
+
nativeSessionId,
|
|
23582
|
+
formatVersion: 1
|
|
23583
|
+
})
|
|
23584
|
+
};
|
|
23585
|
+
});
|
|
23586
|
+
}
|
|
23587
|
+
close() {
|
|
23588
|
+
return this.#scope.close();
|
|
23589
|
+
}
|
|
23590
|
+
#home() {
|
|
23591
|
+
return grokHomeDir(this.#environment ? { environment: this.#environment } : {});
|
|
23592
|
+
}
|
|
23593
|
+
/** IDs a live Grok process currently holds open, from Grok's own registry. */
|
|
23594
|
+
async #activeSessions(signal) {
|
|
23595
|
+
const active = /* @__PURE__ */ new Set();
|
|
23596
|
+
let entries;
|
|
23597
|
+
try {
|
|
23598
|
+
entries = await readJson(path11.join(this.#home(), "active_sessions.json"), signal);
|
|
23599
|
+
} catch (error53) {
|
|
23600
|
+
signal.throwIfAborted();
|
|
23601
|
+
if (isStorageAccessError(error53))
|
|
23602
|
+
throw error53;
|
|
23603
|
+
return active;
|
|
23604
|
+
}
|
|
23605
|
+
if (!Array.isArray(entries))
|
|
23606
|
+
return active;
|
|
23607
|
+
for (const entry of entries) {
|
|
23608
|
+
if (isRecord12(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
23609
|
+
active.add(entry.session_id);
|
|
23610
|
+
}
|
|
23611
|
+
return active;
|
|
23612
|
+
}
|
|
23613
|
+
/** Session ID to every directory claiming it. Enumerated links are not followed. */
|
|
23614
|
+
async #sessionDirectories(signal) {
|
|
23615
|
+
const root = path11.join(this.#home(), "sessions");
|
|
23616
|
+
const found = /* @__PURE__ */ new Map();
|
|
23617
|
+
const info = await optionalLstat(root);
|
|
23618
|
+
if (!info)
|
|
23619
|
+
return found;
|
|
23620
|
+
if (!info.isDirectory())
|
|
23621
|
+
throw new Error("Grok Session store is not a directory");
|
|
23622
|
+
for await (const workspace of await opendir(root)) {
|
|
23623
|
+
signal.throwIfAborted();
|
|
23624
|
+
if (!workspace.isDirectory())
|
|
23625
|
+
continue;
|
|
23626
|
+
const workspaceDirectory = path11.join(root, workspace.name);
|
|
23627
|
+
const sessions = await opendir(workspaceDirectory).catch((error53) => {
|
|
23628
|
+
if (isMissingFileError(error53))
|
|
23629
|
+
return null;
|
|
23630
|
+
throw error53;
|
|
23631
|
+
});
|
|
23632
|
+
if (!sessions)
|
|
23633
|
+
continue;
|
|
23634
|
+
for await (const session of sessions) {
|
|
23635
|
+
signal.throwIfAborted();
|
|
23636
|
+
if (!session.isDirectory())
|
|
23637
|
+
continue;
|
|
23638
|
+
const directories = found.get(session.name) ?? [];
|
|
23639
|
+
directories.push(path11.join(workspaceDirectory, session.name));
|
|
23640
|
+
found.set(session.name, directories);
|
|
23641
|
+
}
|
|
23642
|
+
}
|
|
23643
|
+
return found;
|
|
23644
|
+
}
|
|
23645
|
+
async #candidate(sessionDirectory, active, signal) {
|
|
23646
|
+
signal.throwIfAborted();
|
|
23647
|
+
const nativeSessionId = path11.basename(sessionDirectory);
|
|
23648
|
+
const files = [
|
|
23649
|
+
path11.join(sessionDirectory, "summary.json"),
|
|
23650
|
+
path11.join(sessionDirectory, "updates.jsonl")
|
|
23651
|
+
];
|
|
23652
|
+
return readStableFiles(files, async ([summaryInfo, updates]) => {
|
|
23653
|
+
if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
|
|
23654
|
+
return null;
|
|
23655
|
+
try {
|
|
23656
|
+
const summary = await readJson(files[0], signal);
|
|
23657
|
+
if (!isRecord12(summary) || !isRecord12(summary.info) || summary.info.id !== nativeSessionId)
|
|
23658
|
+
return null;
|
|
23659
|
+
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
23660
|
+
return null;
|
|
23661
|
+
const nativeCwd = summary.info.cwd;
|
|
23662
|
+
if (typeof nativeCwd !== "string" || !path11.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
|
|
23663
|
+
return null;
|
|
23664
|
+
const cwd = path11.resolve(nativeCwd);
|
|
23665
|
+
if (encodeURIComponent(cwd) !== path11.basename(path11.dirname(sessionDirectory)))
|
|
23666
|
+
return null;
|
|
23667
|
+
if (!(await stat(cwd)).isDirectory())
|
|
23668
|
+
return null;
|
|
23669
|
+
const prompt = await firstUserText(files[1], signal);
|
|
23670
|
+
if (prompt === null)
|
|
23671
|
+
return null;
|
|
23672
|
+
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);
|
|
23673
|
+
return sessionImportCandidate({
|
|
23674
|
+
nativeSessionId,
|
|
23675
|
+
cwd,
|
|
23676
|
+
title: sessionImportTitle(summary.generated_title) ?? sessionImportTitle(summary.session_summary) ?? sessionImportTitle(prompt),
|
|
23677
|
+
updatedAt: updatedAt ?? updates.mtimeMs,
|
|
23678
|
+
// Grok registers open Sessions with their process. Absence is not proof of idleness.
|
|
23679
|
+
running: active.has(nativeSessionId) ? true : null
|
|
23680
|
+
});
|
|
23681
|
+
} catch (error53) {
|
|
23682
|
+
signal.throwIfAborted();
|
|
23683
|
+
if (isStorageAccessError(error53))
|
|
23684
|
+
throw error53;
|
|
23685
|
+
return null;
|
|
23686
|
+
}
|
|
23687
|
+
});
|
|
23688
|
+
}
|
|
23689
|
+
};
|
|
23690
|
+
|
|
23271
23691
|
// dist/grok-subagent-lifecycle.js
|
|
23272
23692
|
function subagentFailure() {
|
|
23273
23693
|
return {
|
|
@@ -23461,7 +23881,7 @@ var GrokSubagentLifecycle = class {
|
|
|
23461
23881
|
};
|
|
23462
23882
|
|
|
23463
23883
|
// dist/grok-models.js
|
|
23464
|
-
function
|
|
23884
|
+
function isRecord13(value) {
|
|
23465
23885
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23466
23886
|
}
|
|
23467
23887
|
function nonBlank(value) {
|
|
@@ -23473,7 +23893,7 @@ function thinkingOptions(value) {
|
|
|
23473
23893
|
const seen = /* @__PURE__ */ new Set();
|
|
23474
23894
|
const options = [];
|
|
23475
23895
|
for (const candidate of value) {
|
|
23476
|
-
if (!
|
|
23896
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.label))
|
|
23477
23897
|
continue;
|
|
23478
23898
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
23479
23899
|
if (!id.success || seen.has(id.data))
|
|
@@ -23484,7 +23904,7 @@ function thinkingOptions(value) {
|
|
|
23484
23904
|
return options;
|
|
23485
23905
|
}
|
|
23486
23906
|
function parseGrokModelState(value) {
|
|
23487
|
-
if (!
|
|
23907
|
+
if (!isRecord13(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
23488
23908
|
return null;
|
|
23489
23909
|
}
|
|
23490
23910
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -23495,12 +23915,12 @@ function parseGrokModelState(value) {
|
|
|
23495
23915
|
const models = [];
|
|
23496
23916
|
let currentThinkingOptionId;
|
|
23497
23917
|
for (const candidate of value.availableModels) {
|
|
23498
|
-
if (!
|
|
23918
|
+
if (!isRecord13(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
23499
23919
|
continue;
|
|
23500
23920
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
23501
23921
|
if (!ref.success)
|
|
23502
23922
|
continue;
|
|
23503
|
-
const metadata =
|
|
23923
|
+
const metadata = isRecord13(candidate._meta) ? candidate._meta : {};
|
|
23504
23924
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
23505
23925
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
23506
23926
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
@@ -23535,10 +23955,10 @@ function parseGrokModelState(value) {
|
|
|
23535
23955
|
};
|
|
23536
23956
|
}
|
|
23537
23957
|
function modelStateFromInitialize(response) {
|
|
23538
|
-
return parseGrokModelState(
|
|
23958
|
+
return parseGrokModelState(isRecord13(response._meta) ? response._meta.modelState : void 0);
|
|
23539
23959
|
}
|
|
23540
23960
|
function modelStateFromSessionResponse(response) {
|
|
23541
|
-
return parseGrokModelState(
|
|
23961
|
+
return parseGrokModelState(isRecord13(response) ? response.models : void 0);
|
|
23542
23962
|
}
|
|
23543
23963
|
function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
23544
23964
|
const selectedModel = model;
|
|
@@ -23557,12 +23977,12 @@ function stateForGrokModel(modelState, nativeState, model = modelState.currentMo
|
|
|
23557
23977
|
}
|
|
23558
23978
|
|
|
23559
23979
|
// dist/grok-credits.js
|
|
23560
|
-
import { readFile as
|
|
23980
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
23561
23981
|
import os5 from "node:os";
|
|
23562
|
-
import
|
|
23982
|
+
import path12 from "node:path";
|
|
23563
23983
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
23564
23984
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
23565
|
-
function
|
|
23985
|
+
function isRecord14(value) {
|
|
23566
23986
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23567
23987
|
}
|
|
23568
23988
|
function finitePercent(value) {
|
|
@@ -23571,7 +23991,7 @@ function finitePercent(value) {
|
|
|
23571
23991
|
return Math.min(100, Math.max(0, value));
|
|
23572
23992
|
}
|
|
23573
23993
|
function nonNegativeCentValue(value) {
|
|
23574
|
-
if (!
|
|
23994
|
+
if (!isRecord14(value))
|
|
23575
23995
|
return void 0;
|
|
23576
23996
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
23577
23997
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -23579,7 +23999,7 @@ function nonNegativeCentValue(value) {
|
|
|
23579
23999
|
return amount;
|
|
23580
24000
|
}
|
|
23581
24001
|
function grokHome(environment) {
|
|
23582
|
-
return environment.GROK_HOME ??
|
|
24002
|
+
return environment.GROK_HOME ?? path12.join(environment.HOME ?? environment.USERPROFILE ?? os5.homedir(), ".grok");
|
|
23583
24003
|
}
|
|
23584
24004
|
function periodTypeFrom(value) {
|
|
23585
24005
|
if (typeof value !== "string")
|
|
@@ -23595,7 +24015,7 @@ function productUsageFrom(value) {
|
|
|
23595
24015
|
if (!Array.isArray(value))
|
|
23596
24016
|
return void 0;
|
|
23597
24017
|
const products = value.flatMap((entry) => {
|
|
23598
|
-
if (!
|
|
24018
|
+
if (!isRecord14(entry) || typeof entry.product !== "string")
|
|
23599
24019
|
return [];
|
|
23600
24020
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
23601
24021
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -23603,10 +24023,10 @@ function productUsageFrom(value) {
|
|
|
23603
24023
|
return products.length > 0 ? products : void 0;
|
|
23604
24024
|
}
|
|
23605
24025
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
23606
|
-
if (!
|
|
24026
|
+
if (!isRecord14(value) || !isRecord14(value.config))
|
|
23607
24027
|
return null;
|
|
23608
24028
|
const config2 = value.config;
|
|
23609
|
-
const period =
|
|
24029
|
+
const period = isRecord14(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
23610
24030
|
const periodType = periodTypeFrom(period?.type);
|
|
23611
24031
|
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
24032
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -23633,11 +24053,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
23633
24053
|
};
|
|
23634
24054
|
}
|
|
23635
24055
|
function selectAccessToken(auth, now) {
|
|
23636
|
-
if (!
|
|
24056
|
+
if (!isRecord14(auth))
|
|
23637
24057
|
return null;
|
|
23638
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
24058
|
+
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
24059
|
for (const [, value] of entries) {
|
|
23640
|
-
if (!
|
|
24060
|
+
if (!isRecord14(value) || typeof value.key !== "string")
|
|
23641
24061
|
continue;
|
|
23642
24062
|
if (typeof value.expires_at === "string") {
|
|
23643
24063
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -23658,8 +24078,8 @@ async function fetchGrokAccount(input = {}) {
|
|
|
23658
24078
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
|
|
23659
24079
|
return null;
|
|
23660
24080
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
23661
|
-
const authPath =
|
|
23662
|
-
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await
|
|
24081
|
+
const authPath = path12.join(grokHome(environment), "auth.json");
|
|
24082
|
+
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile4(authPath, "utf8");
|
|
23663
24083
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
23664
24084
|
if (!token)
|
|
23665
24085
|
return null;
|
|
@@ -23708,7 +24128,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
23708
24128
|
|
|
23709
24129
|
// dist/grok-usage.js
|
|
23710
24130
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
23711
|
-
function
|
|
24131
|
+
function isRecord15(value) {
|
|
23712
24132
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23713
24133
|
}
|
|
23714
24134
|
function optionalToken(value) {
|
|
@@ -23725,7 +24145,7 @@ function combineUsage(base, next) {
|
|
|
23725
24145
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
23726
24146
|
}
|
|
23727
24147
|
function usageFromNative(value) {
|
|
23728
|
-
if (!
|
|
24148
|
+
if (!isRecord15(value))
|
|
23729
24149
|
return null;
|
|
23730
24150
|
const inputTokens = optionalToken(value.inputTokens);
|
|
23731
24151
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -23752,7 +24172,7 @@ function usageFromPrompt(response) {
|
|
|
23752
24172
|
return response.usage ? usageFromNative(response.usage) : null;
|
|
23753
24173
|
}
|
|
23754
24174
|
function usageFromSignals(value) {
|
|
23755
|
-
if (!
|
|
24175
|
+
if (!isRecord15(value))
|
|
23756
24176
|
return null;
|
|
23757
24177
|
try {
|
|
23758
24178
|
return parseHostUsage({
|
|
@@ -23772,7 +24192,7 @@ var summedUsageFields = [
|
|
|
23772
24192
|
"totalTokens"
|
|
23773
24193
|
];
|
|
23774
24194
|
function nativeCostTicks(value) {
|
|
23775
|
-
if (!
|
|
24195
|
+
if (!isRecord15(value))
|
|
23776
24196
|
return void 0;
|
|
23777
24197
|
const ticks = value.costUsdTicks;
|
|
23778
24198
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -23849,7 +24269,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
23849
24269
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
23850
24270
|
try {
|
|
23851
24271
|
if (update?.sessionUpdate === "usage_update") {
|
|
23852
|
-
const cost =
|
|
24272
|
+
const cost = isRecord15(update.cost) ? update.cost : null;
|
|
23853
24273
|
return parseHostUsage({
|
|
23854
24274
|
contextUsedTokens: update.used,
|
|
23855
24275
|
contextWindowTokens: update.size,
|
|
@@ -24861,6 +25281,7 @@ var GrokAdapter = class {
|
|
|
24861
25281
|
commandCatalog = grokCommandCatalog;
|
|
24862
25282
|
liveCommandCatalog = true;
|
|
24863
25283
|
harnessId = grokHarnessId;
|
|
25284
|
+
sessionImport;
|
|
24864
25285
|
subagents = {
|
|
24865
25286
|
readSnapshot: async (input) => {
|
|
24866
25287
|
if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
|
|
@@ -24908,6 +25329,7 @@ var GrokAdapter = class {
|
|
|
24908
25329
|
constructor(options = {}, dependencies) {
|
|
24909
25330
|
this.#closeTimeoutMs = options.closeTimeoutMs ?? DEFAULT_CLOSE_TIMEOUT_MS;
|
|
24910
25331
|
this.#environment = options.environment;
|
|
25332
|
+
this.sessionImport = new GrokSessionImport(options.environment);
|
|
24911
25333
|
this.#toolOutputLimit = options.toolOutputLimit ?? DEFAULT_GROK_TOOL_OUTPUT_LIMIT;
|
|
24912
25334
|
this.#dependencies = dependencies ?? {
|
|
24913
25335
|
randomUUID,
|
|
@@ -24951,7 +25373,7 @@ var GrokAdapter = class {
|
|
|
24951
25373
|
async inspect(input = {}) {
|
|
24952
25374
|
if (this.#closePromise)
|
|
24953
25375
|
return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
|
|
24954
|
-
const cwd =
|
|
25376
|
+
const cwd = path13.resolve(input.cwd ?? process.cwd());
|
|
24955
25377
|
if (!input.refresh) {
|
|
24956
25378
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
24957
25379
|
if (cached2)
|
|
@@ -25013,7 +25435,7 @@ var GrokAdapter = class {
|
|
|
25013
25435
|
}
|
|
25014
25436
|
};
|
|
25015
25437
|
}
|
|
25016
|
-
const cwd =
|
|
25438
|
+
const cwd = path13.resolve(input.cwd);
|
|
25017
25439
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
25018
25440
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
25019
25441
|
return {
|
|
@@ -25184,7 +25606,10 @@ var GrokAdapter = class {
|
|
|
25184
25606
|
if (!this.#closePromise) {
|
|
25185
25607
|
this.#accountAbort.abort();
|
|
25186
25608
|
this.#inspectionCache.clear();
|
|
25187
|
-
this.#closePromise = Promise.all([
|
|
25609
|
+
this.#closePromise = Promise.all([
|
|
25610
|
+
this.sessionImport.close(),
|
|
25611
|
+
...[...this.#sessions].map((session) => session.close())
|
|
25612
|
+
]).then(() => void 0);
|
|
25188
25613
|
}
|
|
25189
25614
|
return this.#closePromise;
|
|
25190
25615
|
}
|
|
@@ -25236,7 +25661,13 @@ function createHarnessAdapter(context) {
|
|
|
25236
25661
|
return Object.assign(new GrokAdapter({
|
|
25237
25662
|
...environment[GROK_COMMAND_ENV] ? { command: environment[GROK_COMMAND_ENV] } : {},
|
|
25238
25663
|
environment
|
|
25239
|
-
}), {
|
|
25664
|
+
}), {
|
|
25665
|
+
installation: createGrokInstallation(environment, environment[GROK_COMMAND_ENV]),
|
|
25666
|
+
install: createHarnessInstaller(environment, {
|
|
25667
|
+
npm: "@xai-official/grok",
|
|
25668
|
+
allowScripts: "@xai-official/grok"
|
|
25669
|
+
})
|
|
25670
|
+
});
|
|
25240
25671
|
}
|
|
25241
25672
|
export {
|
|
25242
25673
|
GROK_COMMAND_ENV,
|