@karlorz/codexhost-cli-win32-x64 0.16.1-2 → 0.17.0-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 +2 -2
- package/THIRD_PARTY_NOTICES.txt +6 -2
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +86 -20
- package/app/console-web.js +76 -17
- package/app/cpa-live-voice-hook.js +62 -8
- package/app/desktop-controller.mjs +107 -31
- package/app/host-runtime.mjs +2560 -1634
- package/app/plugins/antigravity/plugin.mjs +66 -2
- package/app/plugins/claude-code/plugin.mjs +43 -6
- package/app/plugins/codebuddy/plugin.mjs +41 -0
- package/app/plugins/codex-usage/plugin.mjs +31 -0
- package/app/plugins/copilot/plugin.mjs +31 -0
- package/app/plugins/cursor-cli/plugin.mjs +40 -5
- package/app/plugins/deepseek-harness/plugin.mjs +490 -46
- package/app/plugins/devin/assets/icon.svg +1 -0
- package/app/plugins/devin/manifest.json +30 -0
- package/app/plugins/devin/plugin.mjs +23536 -0
- package/app/plugins/enabled.json +2 -0
- package/app/plugins/grok/plugin.mjs +1615 -495
- package/app/plugins/hermes/plugin.mjs +484 -196
- package/app/plugins/kimi-code/plugin.mjs +31 -0
- package/app/plugins/kiro-cli/plugin.mjs +31 -0
- package/app/plugins/omp/plugin.mjs +31 -0
- package/app/plugins/opencode/plugin.mjs +31 -0
- package/app/plugins/pi/plugin.mjs +1491 -411
- package/app/plugins/qoder/plugin.mjs +9555 -8654
- package/app/plugins/qoder-cn/plugin.mjs +9555 -8654
- package/app/plugins/qwen-code/assets/icon.svg +1 -0
- package/app/plugins/qwen-code/manifest.json +29 -0
- package/app/plugins/qwen-code/plugin.mjs +29471 -0
- package/app/plugins/workbuddy/plugin.mjs +41 -0
- package/app/plugins/zcode/plugin.mjs +31 -0
- package/app/renderer-extension.js +966 -233
- 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/licenses/Qwen-Code-SDK-LICENSE.txt +203 -0
- package/package.json +2 -2
|
@@ -1158,10 +1158,10 @@ function mergeDefs(...defs) {
|
|
|
1158
1158
|
function cloneDef(schema) {
|
|
1159
1159
|
return mergeDefs(schema._zod.def);
|
|
1160
1160
|
}
|
|
1161
|
-
function getElementAtPath(obj,
|
|
1162
|
-
if (!
|
|
1161
|
+
function getElementAtPath(obj, path22) {
|
|
1162
|
+
if (!path22)
|
|
1163
1163
|
return obj;
|
|
1164
|
-
return
|
|
1164
|
+
return path22.reduce((acc, key) => acc?.[key], obj);
|
|
1165
1165
|
}
|
|
1166
1166
|
function promiseAllObject(promisesObj) {
|
|
1167
1167
|
const keys = Object.keys(promisesObj);
|
|
@@ -1570,11 +1570,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1570
1570
|
}
|
|
1571
1571
|
return false;
|
|
1572
1572
|
}
|
|
1573
|
-
function prefixIssues(
|
|
1573
|
+
function prefixIssues(path22, issues) {
|
|
1574
1574
|
return issues.map((iss) => {
|
|
1575
1575
|
var _a3;
|
|
1576
1576
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1577
|
-
iss.path.unshift(
|
|
1577
|
+
iss.path.unshift(path22);
|
|
1578
1578
|
return iss;
|
|
1579
1579
|
});
|
|
1580
1580
|
}
|
|
@@ -1721,16 +1721,16 @@ function flattenError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1721
1721
|
}
|
|
1722
1722
|
function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
1723
1723
|
const fieldErrors = { _errors: [] };
|
|
1724
|
-
const processError = (error54,
|
|
1724
|
+
const processError = (error54, path22 = []) => {
|
|
1725
1725
|
for (const issue2 of error54.issues) {
|
|
1726
1726
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1727
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1727
|
+
issue2.errors.map((issues) => processError({ issues }, [...path22, ...issue2.path]));
|
|
1728
1728
|
} else if (issue2.code === "invalid_key") {
|
|
1729
|
-
processError({ issues: issue2.issues }, [...
|
|
1729
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
1730
1730
|
} else if (issue2.code === "invalid_element") {
|
|
1731
|
-
processError({ issues: issue2.issues }, [...
|
|
1731
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
1732
1732
|
} else {
|
|
1733
|
-
const fullpath = [...
|
|
1733
|
+
const fullpath = [...path22, ...issue2.path];
|
|
1734
1734
|
if (fullpath.length === 0) {
|
|
1735
1735
|
fieldErrors._errors.push(mapper(issue2));
|
|
1736
1736
|
} else {
|
|
@@ -1757,17 +1757,17 @@ function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1757
1757
|
}
|
|
1758
1758
|
function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
1759
1759
|
const result = { errors: [] };
|
|
1760
|
-
const processError = (error54,
|
|
1760
|
+
const processError = (error54, path22 = []) => {
|
|
1761
1761
|
var _a3, _b;
|
|
1762
1762
|
for (const issue2 of error54.issues) {
|
|
1763
1763
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1764
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1764
|
+
issue2.errors.map((issues) => processError({ issues }, [...path22, ...issue2.path]));
|
|
1765
1765
|
} else if (issue2.code === "invalid_key") {
|
|
1766
|
-
processError({ issues: issue2.issues }, [...
|
|
1766
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
1767
1767
|
} else if (issue2.code === "invalid_element") {
|
|
1768
|
-
processError({ issues: issue2.issues }, [...
|
|
1768
|
+
processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
|
|
1769
1769
|
} else {
|
|
1770
|
-
const fullpath = [...
|
|
1770
|
+
const fullpath = [...path22, ...issue2.path];
|
|
1771
1771
|
if (fullpath.length === 0) {
|
|
1772
1772
|
result.errors.push(mapper(issue2));
|
|
1773
1773
|
continue;
|
|
@@ -1799,8 +1799,8 @@ function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1799
1799
|
}
|
|
1800
1800
|
function toDotPath(_path) {
|
|
1801
1801
|
const segs = [];
|
|
1802
|
-
const
|
|
1803
|
-
for (const seg of
|
|
1802
|
+
const path22 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1803
|
+
for (const seg of path22) {
|
|
1804
1804
|
if (typeof seg === "number")
|
|
1805
1805
|
segs.push(`[${seg}]`);
|
|
1806
1806
|
else if (typeof seg === "symbol")
|
|
@@ -14492,13 +14492,13 @@ function resolveRef(ref, ctx) {
|
|
|
14492
14492
|
if (!ref.startsWith("#")) {
|
|
14493
14493
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14494
14494
|
}
|
|
14495
|
-
const
|
|
14496
|
-
if (
|
|
14495
|
+
const path22 = ref.slice(1).split("/").filter(Boolean);
|
|
14496
|
+
if (path22.length === 0) {
|
|
14497
14497
|
return ctx.rootSchema;
|
|
14498
14498
|
}
|
|
14499
14499
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14500
|
-
if (
|
|
14501
|
-
const key =
|
|
14500
|
+
if (path22[0] === defsKey) {
|
|
14501
|
+
const key = path22[1];
|
|
14502
14502
|
if (!key || !ctx.defs[key]) {
|
|
14503
14503
|
throw new Error(`Reference not found: ${ref}`);
|
|
14504
14504
|
}
|
|
@@ -16525,6 +16525,37 @@ var voiceSettingsStateSchema = external_exports.strictObject({
|
|
|
16525
16525
|
})
|
|
16526
16526
|
});
|
|
16527
16527
|
|
|
16528
|
+
// ../../shared-contracts/dist/background-activity.js
|
|
16529
|
+
var backgroundActivitySchema = external_exports.strictObject({
|
|
16530
|
+
id: external_exports.string().min(1),
|
|
16531
|
+
kind: external_exports.enum(["task", "monitor", "loop", "subagent"]),
|
|
16532
|
+
label: external_exports.string(),
|
|
16533
|
+
status: external_exports.enum(["running", "scheduled", "completed", "failed", "cancelled", "unknown"]),
|
|
16534
|
+
canStop: external_exports.boolean(),
|
|
16535
|
+
/** Existing detached command Item presented by Desktop's native process UI. */
|
|
16536
|
+
commandItemId: hostItemIdSchema.optional(),
|
|
16537
|
+
schedule: external_exports.string().optional(),
|
|
16538
|
+
nextRunAt: external_exports.string().datetime({ offset: true }).optional(),
|
|
16539
|
+
relatedActivityId: external_exports.string().optional(),
|
|
16540
|
+
threadId: hostThreadIdSchema.optional()
|
|
16541
|
+
});
|
|
16542
|
+
var backgroundActivityDetailSchema = external_exports.strictObject({
|
|
16543
|
+
activity: backgroundActivitySchema,
|
|
16544
|
+
output: external_exports.string(),
|
|
16545
|
+
truncated: external_exports.boolean()
|
|
16546
|
+
});
|
|
16547
|
+
var threadActivityParamsSchema = external_exports.strictObject({ threadId: hostThreadIdSchema });
|
|
16548
|
+
var threadActivityItemParamsSchema = threadActivityParamsSchema.extend({
|
|
16549
|
+
activityId: external_exports.string().min(1)
|
|
16550
|
+
});
|
|
16551
|
+
var threadActivityListResultSchema = external_exports.strictObject({
|
|
16552
|
+
supported: external_exports.boolean(),
|
|
16553
|
+
activities: external_exports.array(backgroundActivitySchema)
|
|
16554
|
+
});
|
|
16555
|
+
var threadActivityStopResultSchema = external_exports.strictObject({
|
|
16556
|
+
outcome: external_exports.enum(["stopped", "alreadyStopped", "notFound"])
|
|
16557
|
+
});
|
|
16558
|
+
|
|
16528
16559
|
// ../../shared-contracts/dist/index.js
|
|
16529
16560
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
16530
16561
|
|
|
@@ -17047,6 +17078,13 @@ var grokCommandCatalog = harnessCommandCatalogSchema.parse({
|
|
|
17047
17078
|
}
|
|
17048
17079
|
},
|
|
17049
17080
|
argumentMode: "text"
|
|
17081
|
+
},
|
|
17082
|
+
{
|
|
17083
|
+
id: "grok.loop",
|
|
17084
|
+
invocation: "/loop",
|
|
17085
|
+
label: "Loop",
|
|
17086
|
+
description: "Create a native timed Loop; include the interval and task",
|
|
17087
|
+
argumentMode: "text"
|
|
17050
17088
|
}
|
|
17051
17089
|
]
|
|
17052
17090
|
});
|
|
@@ -17128,7 +17166,7 @@ async function readGrokCredentials(environment) {
|
|
|
17128
17166
|
}
|
|
17129
17167
|
|
|
17130
17168
|
// dist/grok-adapter.js
|
|
17131
|
-
import
|
|
17169
|
+
import path21 from "node:path";
|
|
17132
17170
|
|
|
17133
17171
|
// ../../harness-plugin-files/dist/grok-computer-use.js
|
|
17134
17172
|
import { randomUUID } from "node:crypto";
|
|
@@ -17822,11 +17860,371 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
|
17822
17860
|
return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
|
|
17823
17861
|
}
|
|
17824
17862
|
|
|
17863
|
+
// ../../harness-adapter/dist/local-media-markdown.js
|
|
17864
|
+
import { existsSync, statSync } from "node:fs";
|
|
17865
|
+
import path10 from "node:path";
|
|
17866
|
+
import { fileURLToPath } from "node:url";
|
|
17867
|
+
var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
17868
|
+
".aac",
|
|
17869
|
+
".gif",
|
|
17870
|
+
".jpeg",
|
|
17871
|
+
".jpg",
|
|
17872
|
+
".m4a",
|
|
17873
|
+
".m4v",
|
|
17874
|
+
".mov",
|
|
17875
|
+
".mp3",
|
|
17876
|
+
".mp4",
|
|
17877
|
+
".ogg",
|
|
17878
|
+
".png",
|
|
17879
|
+
".svg",
|
|
17880
|
+
".wav",
|
|
17881
|
+
".webm",
|
|
17882
|
+
".webp"
|
|
17883
|
+
]);
|
|
17884
|
+
function rewriteLocalMediaMarkdown(text, roots, options = {}) {
|
|
17885
|
+
return projectLocalMedia(text, roots, options.exists ?? mediaFileExists, options.holdIncomplete === true, options.relativeImagesOnly === true).text;
|
|
17886
|
+
}
|
|
17887
|
+
var LocalMediaMarkdownStream = class {
|
|
17888
|
+
#roots;
|
|
17889
|
+
#exists;
|
|
17890
|
+
#relativeImagesOnly;
|
|
17891
|
+
#native = "";
|
|
17892
|
+
#text = "";
|
|
17893
|
+
/** Native text length represented by `#text`; the rest is held. */
|
|
17894
|
+
#consumed = 0;
|
|
17895
|
+
#verbatim = false;
|
|
17896
|
+
constructor(roots, exists = mediaFileExists, options = {}) {
|
|
17897
|
+
this.#roots = [...roots];
|
|
17898
|
+
this.#relativeImagesOnly = options.relativeImagesOnly === true;
|
|
17899
|
+
const known = /* @__PURE__ */ new Map();
|
|
17900
|
+
this.#exists = (absolutePath) => {
|
|
17901
|
+
let found = known.get(absolutePath);
|
|
17902
|
+
if (found === void 0) {
|
|
17903
|
+
found = exists(absolutePath);
|
|
17904
|
+
known.set(absolutePath, found);
|
|
17905
|
+
}
|
|
17906
|
+
return found;
|
|
17907
|
+
};
|
|
17908
|
+
}
|
|
17909
|
+
/** Projected text published so far: every returned delta, concatenated. */
|
|
17910
|
+
get text() {
|
|
17911
|
+
return this.#text;
|
|
17912
|
+
}
|
|
17913
|
+
/** Add native text and return the projected text it makes publishable, possibly empty. */
|
|
17914
|
+
append(text) {
|
|
17915
|
+
this.#native += text;
|
|
17916
|
+
return this.#advance(true);
|
|
17917
|
+
}
|
|
17918
|
+
/** Return the projected text still held at the end of the stream. */
|
|
17919
|
+
flush() {
|
|
17920
|
+
return this.#advance(false);
|
|
17921
|
+
}
|
|
17922
|
+
#advance(holdIncomplete) {
|
|
17923
|
+
const next = this.#verbatim ? void 0 : projectLocalMedia(this.#native, this.#roots, this.#exists, holdIncomplete, this.#relativeImagesOnly);
|
|
17924
|
+
let delta;
|
|
17925
|
+
if (next?.text.startsWith(this.#text)) {
|
|
17926
|
+
delta = next.text.slice(this.#text.length);
|
|
17927
|
+
this.#consumed = next.consumed;
|
|
17928
|
+
} else {
|
|
17929
|
+
this.#verbatim = true;
|
|
17930
|
+
delta = this.#native.slice(this.#consumed);
|
|
17931
|
+
this.#consumed = this.#native.length;
|
|
17932
|
+
}
|
|
17933
|
+
this.#text += delta;
|
|
17934
|
+
return delta;
|
|
17935
|
+
}
|
|
17936
|
+
};
|
|
17937
|
+
function projectLocalMedia(text, roots, exists, holdIncomplete, relativeImagesOnly) {
|
|
17938
|
+
let output = "";
|
|
17939
|
+
let index = 0;
|
|
17940
|
+
let fence = null;
|
|
17941
|
+
while (index < text.length) {
|
|
17942
|
+
if (fence) {
|
|
17943
|
+
const close = closingFenceEnd(text, index, fence.marker, fence.length);
|
|
17944
|
+
if (close === -1)
|
|
17945
|
+
break;
|
|
17946
|
+
output += text.slice(index, close);
|
|
17947
|
+
index = close;
|
|
17948
|
+
fence = null;
|
|
17949
|
+
continue;
|
|
17950
|
+
}
|
|
17951
|
+
const next = earliestIndex([
|
|
17952
|
+
text.indexOf("![", index),
|
|
17953
|
+
text.indexOf("`", index),
|
|
17954
|
+
indexOfLineStartTilde(text, index)
|
|
17955
|
+
]);
|
|
17956
|
+
if (next === -1)
|
|
17957
|
+
break;
|
|
17958
|
+
output += text.slice(index, next);
|
|
17959
|
+
index = next;
|
|
17960
|
+
const marker = text[next];
|
|
17961
|
+
let markerLength = 1;
|
|
17962
|
+
if (marker === "`" || marker === "~") {
|
|
17963
|
+
let runEnd = next;
|
|
17964
|
+
while (text[runEnd] === marker)
|
|
17965
|
+
runEnd += 1;
|
|
17966
|
+
markerLength = runEnd - next;
|
|
17967
|
+
if (runEnd === text.length && holdIncomplete) {
|
|
17968
|
+
return { text: output, consumed: next };
|
|
17969
|
+
}
|
|
17970
|
+
if (runEnd - next >= 3) {
|
|
17971
|
+
const kind = fenceLineKind(text, next);
|
|
17972
|
+
if (kind === "opaque")
|
|
17973
|
+
break;
|
|
17974
|
+
if (kind === "flat") {
|
|
17975
|
+
fence = { marker, length: runEnd - next };
|
|
17976
|
+
output += text.slice(next, runEnd);
|
|
17977
|
+
index = runEnd;
|
|
17978
|
+
continue;
|
|
17979
|
+
}
|
|
17980
|
+
}
|
|
17981
|
+
if (marker === "~") {
|
|
17982
|
+
output += text.slice(next, runEnd);
|
|
17983
|
+
index = runEnd;
|
|
17984
|
+
continue;
|
|
17985
|
+
}
|
|
17986
|
+
}
|
|
17987
|
+
if (text.startsWith("![", next)) {
|
|
17988
|
+
const image = parseMarkdownImage(text, next);
|
|
17989
|
+
if (image.kind === "text") {
|
|
17990
|
+
output += text.slice(next, image.end);
|
|
17991
|
+
index = image.end;
|
|
17992
|
+
continue;
|
|
17993
|
+
}
|
|
17994
|
+
if (image.kind === "open") {
|
|
17995
|
+
if (!holdIncomplete)
|
|
17996
|
+
break;
|
|
17997
|
+
return { text: output + text.slice(next, image.holdFrom), consumed: image.holdFrom };
|
|
17998
|
+
}
|
|
17999
|
+
const resolved2 = relativeImagesOnly && /^(?:[\\/]|[a-z][a-z\d+.-]*:)/i.test(image.destination.trim()) ? null : resolveLocalMediaPath(image.destination, roots, exists);
|
|
18000
|
+
output += resolved2 === null ? text.slice(next, image.end) : text.slice(next, image.destinationStart) + markdownDestination(resolved2, image.bracketed) + text.slice(image.destinationEnd, image.end);
|
|
18001
|
+
index = image.end;
|
|
18002
|
+
continue;
|
|
18003
|
+
}
|
|
18004
|
+
const code = parseInlineCode(text, next, markerLength);
|
|
18005
|
+
if (code.kind !== "code" || holdIncomplete && code.end === text.length) {
|
|
18006
|
+
if (holdIncomplete && code.kind !== "text")
|
|
18007
|
+
return { text: output, consumed: next };
|
|
18008
|
+
output += text.slice(next, next + markerLength);
|
|
18009
|
+
index = next + markerLength;
|
|
18010
|
+
continue;
|
|
18011
|
+
}
|
|
18012
|
+
const resolved = relativeImagesOnly || markerLength !== 1 || /[\r\n]/u.test(code.content) ? null : resolveLocalMediaPath(code.content, roots, exists);
|
|
18013
|
+
output += resolved === null ? text.slice(next, code.end) : mediaMarkdownImage(resolved);
|
|
18014
|
+
index = code.end;
|
|
18015
|
+
}
|
|
18016
|
+
return { text: output + text.slice(index), consumed: text.length };
|
|
18017
|
+
}
|
|
18018
|
+
function fenceLineKind(text, index) {
|
|
18019
|
+
const prefix = text.slice(text.lastIndexOf("\n", index - 1) + 1, index);
|
|
18020
|
+
if (prefix === "")
|
|
18021
|
+
return "flat";
|
|
18022
|
+
let remaining = prefix.replace(/^[ \t]+/u, "");
|
|
18023
|
+
while (remaining) {
|
|
18024
|
+
const marker = /^(?:>|(?:[-+*]|\d{1,9}[.)])(?=[ \t]))[ \t]*/u.exec(remaining);
|
|
18025
|
+
if (!marker)
|
|
18026
|
+
return null;
|
|
18027
|
+
remaining = remaining.slice(marker[0].length);
|
|
18028
|
+
}
|
|
18029
|
+
return "opaque";
|
|
18030
|
+
}
|
|
18031
|
+
function indexOfLineStartTilde(text, start) {
|
|
18032
|
+
for (let tilde = text.indexOf("~", start); tilde !== -1; tilde = text.indexOf("~", tilde + 1)) {
|
|
18033
|
+
if (fenceLineKind(text, tilde) !== null)
|
|
18034
|
+
return tilde;
|
|
18035
|
+
}
|
|
18036
|
+
return -1;
|
|
18037
|
+
}
|
|
18038
|
+
function closingFenceEnd(text, start, marker, length) {
|
|
18039
|
+
const closing = new RegExp(`^ {0,3}${marker === "`" ? "`" : "~"}{${length},}[ \\t]*\\r?$`, "u");
|
|
18040
|
+
let lineStart = text.indexOf("\n", start);
|
|
18041
|
+
while (lineStart !== -1) {
|
|
18042
|
+
lineStart += 1;
|
|
18043
|
+
const newline2 = text.indexOf("\n", lineStart);
|
|
18044
|
+
const lineEnd = newline2 === -1 ? text.length : newline2;
|
|
18045
|
+
if (closing.test(text.slice(lineStart, lineEnd)))
|
|
18046
|
+
return lineEnd;
|
|
18047
|
+
lineStart = newline2;
|
|
18048
|
+
}
|
|
18049
|
+
return -1;
|
|
18050
|
+
}
|
|
18051
|
+
function earliestIndex(candidates) {
|
|
18052
|
+
let next = -1;
|
|
18053
|
+
for (const candidate of candidates) {
|
|
18054
|
+
if (candidate === -1)
|
|
18055
|
+
continue;
|
|
18056
|
+
if (next === -1 || candidate < next)
|
|
18057
|
+
next = candidate;
|
|
18058
|
+
}
|
|
18059
|
+
return next;
|
|
18060
|
+
}
|
|
18061
|
+
function parseInlineCode(text, start, length) {
|
|
18062
|
+
let index = start + length;
|
|
18063
|
+
while (index < text.length) {
|
|
18064
|
+
const tick = text.indexOf("`", index);
|
|
18065
|
+
if (/\n[^\S\n]*\n/u.test(text.slice(index, tick < 0 ? text.length : tick))) {
|
|
18066
|
+
return { kind: "text" };
|
|
18067
|
+
}
|
|
18068
|
+
if (tick === -1)
|
|
18069
|
+
break;
|
|
18070
|
+
let end = tick + 1;
|
|
18071
|
+
while (text[end] === "`")
|
|
18072
|
+
end += 1;
|
|
18073
|
+
if (end - tick === length) {
|
|
18074
|
+
return { kind: "code", content: text.slice(start + length, tick), end };
|
|
18075
|
+
}
|
|
18076
|
+
index = end;
|
|
18077
|
+
}
|
|
18078
|
+
return { kind: "open" };
|
|
18079
|
+
}
|
|
18080
|
+
function parseMarkdownImage(text, start) {
|
|
18081
|
+
const openLabel = { kind: "open", holdFrom: start + 2 };
|
|
18082
|
+
let index = start + 2;
|
|
18083
|
+
while (index < text.length) {
|
|
18084
|
+
const character = text[index];
|
|
18085
|
+
if (character === "\n")
|
|
18086
|
+
return { kind: "text", end: start + 1 };
|
|
18087
|
+
if (character === "\\") {
|
|
18088
|
+
index += 2;
|
|
18089
|
+
continue;
|
|
18090
|
+
}
|
|
18091
|
+
if (character === "]")
|
|
18092
|
+
break;
|
|
18093
|
+
index += 1;
|
|
18094
|
+
}
|
|
18095
|
+
if (index + 1 >= text.length)
|
|
18096
|
+
return openLabel;
|
|
18097
|
+
if (text[index + 1] !== "(")
|
|
18098
|
+
return { kind: "text", end: start + 1 };
|
|
18099
|
+
const destinationStart = index + 2;
|
|
18100
|
+
const open3 = { kind: "open", holdFrom: destinationStart };
|
|
18101
|
+
const malformed = { kind: "text", end: destinationStart };
|
|
18102
|
+
index = skipBlanks(text, destinationStart);
|
|
18103
|
+
if (index >= text.length)
|
|
18104
|
+
return open3;
|
|
18105
|
+
let destination;
|
|
18106
|
+
let destinationEnd;
|
|
18107
|
+
let bracketed = false;
|
|
18108
|
+
if (text[index] === "<") {
|
|
18109
|
+
bracketed = true;
|
|
18110
|
+
let close = index + 1;
|
|
18111
|
+
while (close < text.length && text[close] !== ">" && text[close] !== "\n")
|
|
18112
|
+
close += 1;
|
|
18113
|
+
if (close >= text.length)
|
|
18114
|
+
return open3;
|
|
18115
|
+
if (text[close] === "\n")
|
|
18116
|
+
return malformed;
|
|
18117
|
+
destination = text.slice(index + 1, close);
|
|
18118
|
+
destinationEnd = close + 1;
|
|
18119
|
+
index = destinationEnd;
|
|
18120
|
+
} else {
|
|
18121
|
+
const begin = index;
|
|
18122
|
+
while (index < text.length) {
|
|
18123
|
+
const character = text[index];
|
|
18124
|
+
if (character === "\n" || character === " " || character === " " || character === ")")
|
|
18125
|
+
break;
|
|
18126
|
+
index += character === "\\" ? 2 : 1;
|
|
18127
|
+
}
|
|
18128
|
+
if (index >= text.length)
|
|
18129
|
+
return open3;
|
|
18130
|
+
destination = unescapeMarkdown(text.slice(begin, index));
|
|
18131
|
+
destinationEnd = index;
|
|
18132
|
+
}
|
|
18133
|
+
index = skipBlanks(text, index);
|
|
18134
|
+
if (index >= text.length)
|
|
18135
|
+
return open3;
|
|
18136
|
+
const opener = text[index];
|
|
18137
|
+
if (opener === '"' || opener === "'" || opener === "(") {
|
|
18138
|
+
const closer = opener === "(" ? ")" : opener;
|
|
18139
|
+
index += 1;
|
|
18140
|
+
while (index < text.length && text[index] !== closer && text[index] !== "\n")
|
|
18141
|
+
index += 1;
|
|
18142
|
+
if (index >= text.length)
|
|
18143
|
+
return open3;
|
|
18144
|
+
if (text[index] === "\n")
|
|
18145
|
+
return malformed;
|
|
18146
|
+
index = skipBlanks(text, index + 1);
|
|
18147
|
+
if (index >= text.length)
|
|
18148
|
+
return open3;
|
|
18149
|
+
}
|
|
18150
|
+
if (text[index] !== ")")
|
|
18151
|
+
return malformed;
|
|
18152
|
+
return {
|
|
18153
|
+
kind: "image",
|
|
18154
|
+
destination,
|
|
18155
|
+
destinationStart,
|
|
18156
|
+
destinationEnd,
|
|
18157
|
+
end: index + 1,
|
|
18158
|
+
bracketed
|
|
18159
|
+
};
|
|
18160
|
+
}
|
|
18161
|
+
function skipBlanks(text, start) {
|
|
18162
|
+
let index = start;
|
|
18163
|
+
while (text[index] === " " || text[index] === " ")
|
|
18164
|
+
index += 1;
|
|
18165
|
+
return index;
|
|
18166
|
+
}
|
|
18167
|
+
function mediaMarkdownImage(absolutePath) {
|
|
18168
|
+
const name = path10.basename(absolutePath).replaceAll("]", "\\]");
|
|
18169
|
+
return `})`;
|
|
18170
|
+
}
|
|
18171
|
+
function markdownDestination(absolutePath, bracketed) {
|
|
18172
|
+
const encoded = absolutePath.replaceAll("%", "%2525");
|
|
18173
|
+
const destination = /^[A-Za-z]:\\/.test(encoded) ? encoded.replaceAll("\\", "/") : encoded.replaceAll("\\", "\\\\");
|
|
18174
|
+
return bracketed || /[\s()]/.test(destination) ? `<${destination}>` : destination;
|
|
18175
|
+
}
|
|
18176
|
+
function unescapeMarkdown(value) {
|
|
18177
|
+
return value.replace(/\\([\\()])/g, "$1");
|
|
18178
|
+
}
|
|
18179
|
+
function resolveLocalMediaPath(raw, roots, exists = mediaFileExists) {
|
|
18180
|
+
const trimmed = raw.trim();
|
|
18181
|
+
if (trimmed.length === 0 || isRemoteMediaUrl(trimmed))
|
|
18182
|
+
return null;
|
|
18183
|
+
const stripped = stripFileUrl(trimmed);
|
|
18184
|
+
if (stripped === null)
|
|
18185
|
+
return null;
|
|
18186
|
+
if (isAbsoluteMediaPath(stripped)) {
|
|
18187
|
+
const absolute = path10.resolve(stripped);
|
|
18188
|
+
return hasMediaExtension(absolute) && exists(absolute) ? absolute : null;
|
|
18189
|
+
}
|
|
18190
|
+
for (const root of roots) {
|
|
18191
|
+
const absolute = path10.resolve(root, stripped);
|
|
18192
|
+
if (hasMediaExtension(absolute) && exists(absolute))
|
|
18193
|
+
return absolute;
|
|
18194
|
+
}
|
|
18195
|
+
return null;
|
|
18196
|
+
}
|
|
18197
|
+
function isRemoteMediaUrl(value) {
|
|
18198
|
+
return /^(?:https?:|data:|app:|blob:)/i.test(value);
|
|
18199
|
+
}
|
|
18200
|
+
function stripFileUrl(value) {
|
|
18201
|
+
if (!value.toLowerCase().startsWith("file:"))
|
|
18202
|
+
return value;
|
|
18203
|
+
try {
|
|
18204
|
+
return fileURLToPath(value);
|
|
18205
|
+
} catch {
|
|
18206
|
+
return null;
|
|
18207
|
+
}
|
|
18208
|
+
}
|
|
18209
|
+
function isAbsoluteMediaPath(value) {
|
|
18210
|
+
return path10.isAbsolute(value) || /^[a-zA-Z]:[\\/]/.test(value);
|
|
18211
|
+
}
|
|
18212
|
+
function hasMediaExtension(value) {
|
|
18213
|
+
return MEDIA_EXTENSIONS.has(path10.extname(value).toLowerCase());
|
|
18214
|
+
}
|
|
18215
|
+
function mediaFileExists(absolutePath) {
|
|
18216
|
+
try {
|
|
18217
|
+
return existsSync(absolutePath) && statSync(absolutePath).isFile();
|
|
18218
|
+
} catch {
|
|
18219
|
+
return false;
|
|
18220
|
+
}
|
|
18221
|
+
}
|
|
18222
|
+
|
|
17825
18223
|
// dist/acp-transport.js
|
|
17826
18224
|
import { spawn, spawnSync } from "node:child_process";
|
|
17827
18225
|
import { readdir, readFile as readFile5 } from "node:fs/promises";
|
|
17828
18226
|
import os6 from "node:os";
|
|
17829
|
-
import
|
|
18227
|
+
import path17 from "node:path";
|
|
17830
18228
|
import { Readable, Writable } from "node:stream";
|
|
17831
18229
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
17832
18230
|
|
|
@@ -22015,8 +22413,8 @@ function parseGrokAvailableCommands(value) {
|
|
|
22015
22413
|
});
|
|
22016
22414
|
}
|
|
22017
22415
|
function isGrokSkill(command) {
|
|
22018
|
-
const
|
|
22019
|
-
return typeof
|
|
22416
|
+
const path22 = command.meta?.path;
|
|
22417
|
+
return typeof path22 === "string" && /(^|[\\/])SKILL\.md$/u.test(path22) || typeof command.meta?.qualifiedName === "string";
|
|
22020
22418
|
}
|
|
22021
22419
|
function grokLiveCommands(native) {
|
|
22022
22420
|
return native.map((command) => ({
|
|
@@ -22027,7 +22425,7 @@ function grokLiveCommands(native) {
|
|
|
22027
22425
|
}
|
|
22028
22426
|
|
|
22029
22427
|
// dist/command.js
|
|
22030
|
-
import
|
|
22428
|
+
import path11 from "node:path";
|
|
22031
22429
|
var GrokExecutableError = class extends Error {
|
|
22032
22430
|
code = "GROK_NOT_FOUND";
|
|
22033
22431
|
};
|
|
@@ -22056,7 +22454,7 @@ function resolveGrokExecutable(input = {}) {
|
|
|
22056
22454
|
});
|
|
22057
22455
|
if (!resolution)
|
|
22058
22456
|
throw new GrokExecutableError("Grok CLI is not installed");
|
|
22059
|
-
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable :
|
|
22457
|
+
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path11.resolve(resolution.executable);
|
|
22060
22458
|
}
|
|
22061
22459
|
function grokInvocation(command, platform = process.platform, modelId) {
|
|
22062
22460
|
const arguments_ = ["agent", "--no-leader"];
|
|
@@ -22069,7 +22467,7 @@ function grokInvocation(command, platform = process.platform, modelId) {
|
|
|
22069
22467
|
|
|
22070
22468
|
// dist/grok-fork.js
|
|
22071
22469
|
import { isDeepStrictEqual } from "node:util";
|
|
22072
|
-
import
|
|
22470
|
+
import path15 from "node:path";
|
|
22073
22471
|
|
|
22074
22472
|
// dist/grok-history-groups.js
|
|
22075
22473
|
function grokPromptIndex(event) {
|
|
@@ -22213,7 +22611,7 @@ function placeGrokGoalHelpers(replay, groups) {
|
|
|
22213
22611
|
|
|
22214
22612
|
// dist/grok-file-change.js
|
|
22215
22613
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
22216
|
-
import
|
|
22614
|
+
import path12 from "node:path";
|
|
22217
22615
|
|
|
22218
22616
|
// ../../../node_modules/diff/libesm/diff/base.js
|
|
22219
22617
|
var Diff = class {
|
|
@@ -22315,16 +22713,16 @@ var Diff = class {
|
|
|
22315
22713
|
}
|
|
22316
22714
|
}
|
|
22317
22715
|
}
|
|
22318
|
-
addToPath(
|
|
22319
|
-
const last =
|
|
22716
|
+
addToPath(path22, added, removed, oldPosInc, options) {
|
|
22717
|
+
const last = path22.lastComponent;
|
|
22320
22718
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
22321
22719
|
return {
|
|
22322
|
-
oldPos:
|
|
22720
|
+
oldPos: path22.oldPos + oldPosInc,
|
|
22323
22721
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
22324
22722
|
};
|
|
22325
22723
|
} else {
|
|
22326
22724
|
return {
|
|
22327
|
-
oldPos:
|
|
22725
|
+
oldPos: path22.oldPos + oldPosInc,
|
|
22328
22726
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
22329
22727
|
};
|
|
22330
22728
|
}
|
|
@@ -22637,13 +23035,13 @@ function isRecord5(value) {
|
|
|
22637
23035
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22638
23036
|
}
|
|
22639
23037
|
function validAbsolutePath(value) {
|
|
22640
|
-
return typeof value === "string" &&
|
|
23038
|
+
return typeof value === "string" && path12.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
|
|
22641
23039
|
}
|
|
22642
23040
|
function displayPath(nativePath, cwd) {
|
|
22643
|
-
const resolvedCwd =
|
|
22644
|
-
const resolvedPath =
|
|
22645
|
-
const relative =
|
|
22646
|
-
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
23041
|
+
const resolvedCwd = path12.resolve(cwd);
|
|
23042
|
+
const resolvedPath = path12.resolve(nativePath);
|
|
23043
|
+
const relative = path12.relative(resolvedCwd, resolvedPath);
|
|
23044
|
+
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path12.sep}`);
|
|
22647
23045
|
const selected = inside ? relative : resolvedPath;
|
|
22648
23046
|
const normalized = selected.replaceAll("\\", "/");
|
|
22649
23047
|
if (normalized.length === 0 || normalized === ".")
|
|
@@ -22705,309 +23103,20 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
|
|
|
22705
23103
|
|
|
22706
23104
|
// dist/grok-generated-image.js
|
|
22707
23105
|
import path13 from "node:path";
|
|
22708
|
-
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
|
|
22713
|
-
|
|
22714
|
-
".aac",
|
|
22715
|
-
".gif",
|
|
22716
|
-
".jpeg",
|
|
22717
|
-
".jpg",
|
|
22718
|
-
".m4a",
|
|
22719
|
-
".m4v",
|
|
22720
|
-
".mov",
|
|
22721
|
-
".mp3",
|
|
22722
|
-
".mp4",
|
|
22723
|
-
".ogg",
|
|
22724
|
-
".png",
|
|
22725
|
-
".svg",
|
|
22726
|
-
".wav",
|
|
22727
|
-
".webm",
|
|
22728
|
-
".webp"
|
|
22729
|
-
]);
|
|
22730
|
-
function grokMediaResolveRoots(cwd, sessionDirectory) {
|
|
22731
|
-
const roots = [path12.resolve(cwd)];
|
|
22732
|
-
if (sessionDirectory) {
|
|
22733
|
-
const session = path12.resolve(sessionDirectory);
|
|
22734
|
-
roots.push(session, path12.join(session, "videos"), path12.join(session, "images"));
|
|
23106
|
+
import { statSync as statSync2 } from "node:fs";
|
|
23107
|
+
function mediaFileExists2(absolutePath) {
|
|
23108
|
+
try {
|
|
23109
|
+
return statSync2(absolutePath).isFile();
|
|
23110
|
+
} catch {
|
|
23111
|
+
return false;
|
|
22735
23112
|
}
|
|
22736
|
-
const home = process.env.HOME ?? process.env.USERPROFILE ?? os5.homedir();
|
|
22737
|
-
if (home)
|
|
22738
|
-
roots.push(path12.join(home, "Downloads"));
|
|
22739
|
-
return roots;
|
|
22740
23113
|
}
|
|
22741
|
-
|
|
22742
|
-
|
|
22743
|
-
|
|
22744
|
-
let output = "";
|
|
22745
|
-
let index = 0;
|
|
22746
|
-
let fence = false;
|
|
22747
|
-
while (index < text.length) {
|
|
22748
|
-
if (fence) {
|
|
22749
|
-
const fenceEnd = text.indexOf("```", index);
|
|
22750
|
-
if (fenceEnd === -1) {
|
|
22751
|
-
output += text.slice(index);
|
|
22752
|
-
break;
|
|
22753
|
-
}
|
|
22754
|
-
output += text.slice(index, fenceEnd + 3);
|
|
22755
|
-
index = fenceEnd + 3;
|
|
22756
|
-
fence = false;
|
|
22757
|
-
continue;
|
|
22758
|
-
}
|
|
22759
|
-
const fenceStart = text.indexOf("```", index);
|
|
22760
|
-
const imageStart = text.indexOf("![", index);
|
|
22761
|
-
const tickStart = indexOfInlineTick(text, index);
|
|
22762
|
-
const next = earliestIndex([fenceStart, imageStart, tickStart]);
|
|
22763
|
-
if (next === -1) {
|
|
22764
|
-
output += text.slice(index);
|
|
22765
|
-
break;
|
|
22766
|
-
}
|
|
22767
|
-
output += text.slice(index, next);
|
|
22768
|
-
if (next === fenceStart) {
|
|
22769
|
-
output += "```";
|
|
22770
|
-
index = fenceStart + 3;
|
|
22771
|
-
fence = true;
|
|
22772
|
-
continue;
|
|
22773
|
-
}
|
|
22774
|
-
if (next === imageStart) {
|
|
22775
|
-
const parsed = parseMarkdownImage(text, imageStart);
|
|
22776
|
-
if (!parsed) {
|
|
22777
|
-
output += "!";
|
|
22778
|
-
index = imageStart + 1;
|
|
22779
|
-
continue;
|
|
22780
|
-
}
|
|
22781
|
-
if (!parsed.closed) {
|
|
22782
|
-
output += holdIncomplete ? text.slice(imageStart, parsed.destinationStart) : text.slice(imageStart);
|
|
22783
|
-
break;
|
|
22784
|
-
}
|
|
22785
|
-
const resolved2 = resolveLocalMediaPath(parsed.destination, roots, exists);
|
|
22786
|
-
output += text.slice(imageStart, parsed.destinationStart) + formatMarkdownDestination(resolved2 ?? parsed.destination, parsed.bracketed) + text.slice(parsed.destinationEnd, parsed.end);
|
|
22787
|
-
index = parsed.end;
|
|
22788
|
-
continue;
|
|
22789
|
-
}
|
|
22790
|
-
const inline = parseInlineCode(text, tickStart);
|
|
22791
|
-
if (!inline.closed) {
|
|
22792
|
-
if (!holdIncomplete)
|
|
22793
|
-
output += text.slice(tickStart);
|
|
22794
|
-
break;
|
|
22795
|
-
}
|
|
22796
|
-
const resolved = resolveLocalMediaPath(inline.content, roots, exists);
|
|
22797
|
-
output += resolved ? mediaMarkdownImage(resolved) : text.slice(tickStart, inline.end);
|
|
22798
|
-
index = inline.end;
|
|
22799
|
-
}
|
|
22800
|
-
return output;
|
|
23114
|
+
var GENERATED_IMAGE_TYPES = /* @__PURE__ */ new Set(["ImageGen", "ImageEdit"]);
|
|
23115
|
+
function isRecord6(value) {
|
|
23116
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22801
23117
|
}
|
|
22802
|
-
function
|
|
22803
|
-
|
|
22804
|
-
while (index < text.length) {
|
|
22805
|
-
const tick = text.indexOf("`", index);
|
|
22806
|
-
if (tick === -1)
|
|
22807
|
-
return -1;
|
|
22808
|
-
if (text.startsWith("```", tick)) {
|
|
22809
|
-
index = tick + 3;
|
|
22810
|
-
continue;
|
|
22811
|
-
}
|
|
22812
|
-
return tick;
|
|
22813
|
-
}
|
|
22814
|
-
return -1;
|
|
22815
|
-
}
|
|
22816
|
-
function earliestIndex(candidates) {
|
|
22817
|
-
let next = -1;
|
|
22818
|
-
for (const candidate of candidates) {
|
|
22819
|
-
if (candidate === -1)
|
|
22820
|
-
continue;
|
|
22821
|
-
if (next === -1 || candidate < next)
|
|
22822
|
-
next = candidate;
|
|
22823
|
-
}
|
|
22824
|
-
return next;
|
|
22825
|
-
}
|
|
22826
|
-
function parseInlineCode(text, start) {
|
|
22827
|
-
let index = start + 1;
|
|
22828
|
-
while (index < text.length) {
|
|
22829
|
-
const character = text[index];
|
|
22830
|
-
if (character === "\n")
|
|
22831
|
-
return { closed: false, content: text.slice(start + 1, index), end: index };
|
|
22832
|
-
if (character === "`")
|
|
22833
|
-
return { closed: true, content: text.slice(start + 1, index), end: index + 1 };
|
|
22834
|
-
index += 1;
|
|
22835
|
-
}
|
|
22836
|
-
return { closed: false, content: text.slice(start + 1), end: text.length };
|
|
22837
|
-
}
|
|
22838
|
-
function mediaMarkdownImage(absolutePath) {
|
|
22839
|
-
const name = path12.basename(absolutePath).replaceAll("]", "\\]");
|
|
22840
|
-
return `})`;
|
|
22841
|
-
}
|
|
22842
|
-
function parseMarkdownImage(text, start) {
|
|
22843
|
-
if (text.slice(start, start + 2) !== "![")
|
|
22844
|
-
return null;
|
|
22845
|
-
let index = start + 2;
|
|
22846
|
-
while (index < text.length) {
|
|
22847
|
-
const character = text[index];
|
|
22848
|
-
if (character === "\n")
|
|
22849
|
-
return null;
|
|
22850
|
-
if (character === "\\" && index + 1 < text.length) {
|
|
22851
|
-
index += 2;
|
|
22852
|
-
continue;
|
|
22853
|
-
}
|
|
22854
|
-
if (character === "]")
|
|
22855
|
-
break;
|
|
22856
|
-
index += 1;
|
|
22857
|
-
}
|
|
22858
|
-
if (text[index] !== "]" || text[index + 1] !== "(")
|
|
22859
|
-
return null;
|
|
22860
|
-
const destinationStart = index + 2;
|
|
22861
|
-
index = destinationStart;
|
|
22862
|
-
while (text[index] === " " || text[index] === " ")
|
|
22863
|
-
index += 1;
|
|
22864
|
-
if (index >= text.length) {
|
|
22865
|
-
return {
|
|
22866
|
-
closed: false,
|
|
22867
|
-
destination: "",
|
|
22868
|
-
destinationStart,
|
|
22869
|
-
destinationEnd: index,
|
|
22870
|
-
end: text.length,
|
|
22871
|
-
bracketed: false
|
|
22872
|
-
};
|
|
22873
|
-
}
|
|
22874
|
-
let destination;
|
|
22875
|
-
let destinationEnd;
|
|
22876
|
-
let bracketed = false;
|
|
22877
|
-
if (text[index] === "<") {
|
|
22878
|
-
bracketed = true;
|
|
22879
|
-
const close = text.indexOf(">", index + 1);
|
|
22880
|
-
if (close === -1 || text.slice(index, close).includes("\n")) {
|
|
22881
|
-
return {
|
|
22882
|
-
closed: false,
|
|
22883
|
-
destination: text.slice(index + 1),
|
|
22884
|
-
destinationStart,
|
|
22885
|
-
destinationEnd: text.length,
|
|
22886
|
-
end: text.length,
|
|
22887
|
-
bracketed: true
|
|
22888
|
-
};
|
|
22889
|
-
}
|
|
22890
|
-
destination = text.slice(index + 1, close);
|
|
22891
|
-
destinationEnd = close + 1;
|
|
22892
|
-
index = destinationEnd;
|
|
22893
|
-
} else {
|
|
22894
|
-
const begin = index;
|
|
22895
|
-
while (index < text.length) {
|
|
22896
|
-
const character = text[index];
|
|
22897
|
-
if (character === "\n" || character === " " || character === " " || character === ")")
|
|
22898
|
-
break;
|
|
22899
|
-
if (character === "\\" && index + 1 < text.length) {
|
|
22900
|
-
index += 2;
|
|
22901
|
-
continue;
|
|
22902
|
-
}
|
|
22903
|
-
index += 1;
|
|
22904
|
-
}
|
|
22905
|
-
destination = unescapeMarkdown(text.slice(begin, index));
|
|
22906
|
-
destinationEnd = index;
|
|
22907
|
-
}
|
|
22908
|
-
while (text[index] === " " || text[index] === " ")
|
|
22909
|
-
index += 1;
|
|
22910
|
-
if (text[index] === '"' || text[index] === "'" || text[index] === "(") {
|
|
22911
|
-
const closer = text[index] === "(" ? ")" : text[index];
|
|
22912
|
-
index += 1;
|
|
22913
|
-
while (index < text.length && text[index] !== closer && text[index] !== "\n")
|
|
22914
|
-
index += 1;
|
|
22915
|
-
if (text[index] !== closer) {
|
|
22916
|
-
return {
|
|
22917
|
-
closed: false,
|
|
22918
|
-
destination,
|
|
22919
|
-
destinationStart,
|
|
22920
|
-
destinationEnd,
|
|
22921
|
-
end: text.length,
|
|
22922
|
-
bracketed
|
|
22923
|
-
};
|
|
22924
|
-
}
|
|
22925
|
-
index += 1;
|
|
22926
|
-
while (text[index] === " " || text[index] === " ")
|
|
22927
|
-
index += 1;
|
|
22928
|
-
}
|
|
22929
|
-
if (text[index] !== ")") {
|
|
22930
|
-
return {
|
|
22931
|
-
closed: false,
|
|
22932
|
-
destination,
|
|
22933
|
-
destinationStart,
|
|
22934
|
-
destinationEnd,
|
|
22935
|
-
end: text.length,
|
|
22936
|
-
bracketed
|
|
22937
|
-
};
|
|
22938
|
-
}
|
|
22939
|
-
return {
|
|
22940
|
-
closed: true,
|
|
22941
|
-
destination,
|
|
22942
|
-
destinationStart,
|
|
22943
|
-
destinationEnd,
|
|
22944
|
-
end: index + 1,
|
|
22945
|
-
bracketed
|
|
22946
|
-
};
|
|
22947
|
-
}
|
|
22948
|
-
function formatMarkdownDestination(destination, bracketed) {
|
|
22949
|
-
if (bracketed || /[\s()]/.test(destination))
|
|
22950
|
-
return `<${destination}>`;
|
|
22951
|
-
return destination.replaceAll(" ", "%20");
|
|
22952
|
-
}
|
|
22953
|
-
function unescapeMarkdown(value) {
|
|
22954
|
-
return value.replace(/\\([\\()])/g, "$1");
|
|
22955
|
-
}
|
|
22956
|
-
function resolveLocalMediaPath(raw, roots, exists = mediaFileExists) {
|
|
22957
|
-
const trimmed = raw.trim();
|
|
22958
|
-
if (trimmed.length === 0 || isRemoteMediaUrl(trimmed))
|
|
22959
|
-
return null;
|
|
22960
|
-
const stripped = stripFileUrl(trimmed);
|
|
22961
|
-
if (!hasMediaExtension(stripped))
|
|
22962
|
-
return null;
|
|
22963
|
-
if (isAbsoluteMediaPath(stripped)) {
|
|
22964
|
-
const absolute = path12.resolve(stripped);
|
|
22965
|
-
return exists(absolute) ? absolute : null;
|
|
22966
|
-
}
|
|
22967
|
-
for (const root of roots) {
|
|
22968
|
-
const absolute = path12.resolve(root, stripped);
|
|
22969
|
-
if (exists(absolute))
|
|
22970
|
-
return absolute;
|
|
22971
|
-
}
|
|
22972
|
-
return null;
|
|
22973
|
-
}
|
|
22974
|
-
function isRemoteMediaUrl(value) {
|
|
22975
|
-
return /^(?:https?:|data:|app:|blob:)/i.test(value);
|
|
22976
|
-
}
|
|
22977
|
-
function stripFileUrl(value) {
|
|
22978
|
-
if (!value.toLowerCase().startsWith("file:"))
|
|
22979
|
-
return value;
|
|
22980
|
-
try {
|
|
22981
|
-
const url2 = new URL(value);
|
|
22982
|
-
if (url2.protocol !== "file:")
|
|
22983
|
-
return value;
|
|
22984
|
-
return decodeURIComponent(url2.pathname);
|
|
22985
|
-
} catch {
|
|
22986
|
-
return value.replace(/^file:\/\//i, "");
|
|
22987
|
-
}
|
|
22988
|
-
}
|
|
22989
|
-
function isAbsoluteMediaPath(value) {
|
|
22990
|
-
return path12.isAbsolute(value) || /^[a-zA-Z]:[\\/]/.test(value);
|
|
22991
|
-
}
|
|
22992
|
-
function hasMediaExtension(value) {
|
|
22993
|
-
const pathname = value.split(/[?#]/, 1)[0] ?? value;
|
|
22994
|
-
return MEDIA_EXTENSIONS.has(path12.extname(pathname).toLowerCase());
|
|
22995
|
-
}
|
|
22996
|
-
function mediaFileExists(absolutePath) {
|
|
22997
|
-
try {
|
|
22998
|
-
return existsSync(absolutePath) && statSync(absolutePath).isFile();
|
|
22999
|
-
} catch {
|
|
23000
|
-
return false;
|
|
23001
|
-
}
|
|
23002
|
-
}
|
|
23003
|
-
|
|
23004
|
-
// dist/grok-generated-image.js
|
|
23005
|
-
var GENERATED_IMAGE_TYPES = /* @__PURE__ */ new Set(["ImageGen", "ImageEdit"]);
|
|
23006
|
-
function isRecord6(value) {
|
|
23007
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23008
|
-
}
|
|
23009
|
-
function stringField(value, key) {
|
|
23010
|
-
return isRecord6(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
23118
|
+
function stringField(value, key) {
|
|
23119
|
+
return isRecord6(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
23011
23120
|
}
|
|
23012
23121
|
function fromNativeRecord(value, exists) {
|
|
23013
23122
|
if (!isRecord6(value))
|
|
@@ -23040,7 +23149,7 @@ function parseJsonObject(text) {
|
|
|
23040
23149
|
return null;
|
|
23041
23150
|
}
|
|
23042
23151
|
}
|
|
23043
|
-
function projectGrokGeneratedImage(content, rawOutput, exists =
|
|
23152
|
+
function projectGrokGeneratedImage(content, rawOutput, exists = mediaFileExists2) {
|
|
23044
23153
|
const fromRaw = fromNativeRecord(rawOutput, exists);
|
|
23045
23154
|
if (fromRaw)
|
|
23046
23155
|
return fromRaw;
|
|
@@ -23074,9 +23183,30 @@ function grokGeneratedImageItem(image, itemId, sourceItemId) {
|
|
|
23074
23183
|
};
|
|
23075
23184
|
}
|
|
23076
23185
|
|
|
23186
|
+
// dist/local-media-markdown.js
|
|
23187
|
+
import os5 from "node:os";
|
|
23188
|
+
import path14 from "node:path";
|
|
23189
|
+
function grokMediaResolveRoots(cwd, sessionDirectory) {
|
|
23190
|
+
const roots = [path14.resolve(cwd)];
|
|
23191
|
+
if (sessionDirectory) {
|
|
23192
|
+
const session = path14.resolve(sessionDirectory);
|
|
23193
|
+
roots.push(session, path14.join(session, "videos"), path14.join(session, "images"));
|
|
23194
|
+
}
|
|
23195
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? os5.homedir();
|
|
23196
|
+
if (home)
|
|
23197
|
+
roots.push(path14.join(home, "Downloads"));
|
|
23198
|
+
return roots;
|
|
23199
|
+
}
|
|
23200
|
+
|
|
23077
23201
|
// dist/grok-tool-output.js
|
|
23078
23202
|
var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
|
|
23079
|
-
var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
23203
|
+
var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
23204
|
+
"bash",
|
|
23205
|
+
"run_terminal_command",
|
|
23206
|
+
"shell",
|
|
23207
|
+
"cursor_shell",
|
|
23208
|
+
"monitor"
|
|
23209
|
+
]);
|
|
23080
23210
|
function isRecord7(value) {
|
|
23081
23211
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23082
23212
|
}
|
|
@@ -24168,11 +24298,11 @@ function parseGrokForkResponse(value) {
|
|
|
24168
24298
|
}
|
|
24169
24299
|
function projectRelativePath(value, cwds) {
|
|
24170
24300
|
const normalized = value.replaceAll("\\", "/");
|
|
24171
|
-
if (!
|
|
24301
|
+
if (!path15.isAbsolute(value))
|
|
24172
24302
|
return normalized;
|
|
24173
24303
|
for (const cwd of cwds) {
|
|
24174
|
-
const relative =
|
|
24175
|
-
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
24304
|
+
const relative = path15.relative(path15.resolve(cwd), path15.resolve(value));
|
|
24305
|
+
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path15.sep}`)) {
|
|
24176
24306
|
return relative.replaceAll("\\", "/");
|
|
24177
24307
|
}
|
|
24178
24308
|
}
|
|
@@ -24237,8 +24367,8 @@ async function forkGrokSession(input) {
|
|
|
24237
24367
|
error: error51("sessionNotFound", "Grok Native Session is unavailable")
|
|
24238
24368
|
};
|
|
24239
24369
|
}
|
|
24240
|
-
const sourceCwd =
|
|
24241
|
-
const targetCwd =
|
|
24370
|
+
const sourceCwd = path15.resolve(located.cwd);
|
|
24371
|
+
const targetCwd = path15.resolve(input.cwd);
|
|
24242
24372
|
const source = await readSnapshot({ ...input, cwd: sourceCwd }, sourceRef.data.nativeSessionId);
|
|
24243
24373
|
if (!source.ok)
|
|
24244
24374
|
return source;
|
|
@@ -24322,15 +24452,15 @@ function isRecord10(value) {
|
|
|
24322
24452
|
function optionalNonNegativeInt(value) {
|
|
24323
24453
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
24324
24454
|
}
|
|
24325
|
-
function firstPresent(
|
|
24455
|
+
function firstPresent(record3, keys) {
|
|
24326
24456
|
for (const key of keys) {
|
|
24327
|
-
if (
|
|
24328
|
-
return
|
|
24457
|
+
if (record3[key] !== void 0)
|
|
24458
|
+
return record3[key];
|
|
24329
24459
|
}
|
|
24330
24460
|
return void 0;
|
|
24331
24461
|
}
|
|
24332
|
-
function optionalErrorMessage(
|
|
24333
|
-
const value = firstPresent(
|
|
24462
|
+
function optionalErrorMessage(record3) {
|
|
24463
|
+
const value = firstPresent(record3, ["errorMessage", "error_message", "message"]);
|
|
24334
24464
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
24335
24465
|
}
|
|
24336
24466
|
function isGrokExtensionSessionUpdateMethod(method) {
|
|
@@ -24373,10 +24503,228 @@ function grokCompactionEventFromUpdate(update) {
|
|
|
24373
24503
|
return null;
|
|
24374
24504
|
}
|
|
24375
24505
|
|
|
24506
|
+
// dist/grok-background.js
|
|
24507
|
+
var GROK_TASK_KILL_METHOD = "x.ai/task/kill";
|
|
24508
|
+
var GROK_TASK_LIST_METHOD = "x.ai/task/list";
|
|
24509
|
+
var GROK_SCHEDULER_DELETE_METHOD = "x.ai/scheduler/delete";
|
|
24510
|
+
var GROK_BACKGROUND_NOTIFICATION_METHODS = [
|
|
24511
|
+
"x.ai/task_backgrounded",
|
|
24512
|
+
"_x.ai/task_backgrounded",
|
|
24513
|
+
"x.ai/task_completed",
|
|
24514
|
+
"_x.ai/task_completed",
|
|
24515
|
+
"x.ai/monitor_event",
|
|
24516
|
+
"_x.ai/monitor_event",
|
|
24517
|
+
"x.ai/scheduled_task_created",
|
|
24518
|
+
"_x.ai/scheduled_task_created",
|
|
24519
|
+
"x.ai/scheduled_task_fired",
|
|
24520
|
+
"_x.ai/scheduled_task_fired",
|
|
24521
|
+
"x.ai/scheduled_task_deleted",
|
|
24522
|
+
"_x.ai/scheduled_task_deleted"
|
|
24523
|
+
];
|
|
24524
|
+
var BACKGROUND_SESSION_UPDATES = /* @__PURE__ */ new Set([
|
|
24525
|
+
"task_backgrounded",
|
|
24526
|
+
"task_completed",
|
|
24527
|
+
"monitor_event",
|
|
24528
|
+
"scheduled_task_created",
|
|
24529
|
+
"scheduled_task_fired",
|
|
24530
|
+
"scheduled_task_deleted"
|
|
24531
|
+
]);
|
|
24532
|
+
function isRecord11(value) {
|
|
24533
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24534
|
+
}
|
|
24535
|
+
function firstPresent2(record3, keys) {
|
|
24536
|
+
for (const key of keys) {
|
|
24537
|
+
if (record3[key] !== void 0)
|
|
24538
|
+
return record3[key];
|
|
24539
|
+
}
|
|
24540
|
+
return void 0;
|
|
24541
|
+
}
|
|
24542
|
+
function stringField4(record3, keys) {
|
|
24543
|
+
const value = firstPresent2(record3, keys);
|
|
24544
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
24545
|
+
}
|
|
24546
|
+
function optionalString(record3, keys) {
|
|
24547
|
+
const value = firstPresent2(record3, keys);
|
|
24548
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
24549
|
+
}
|
|
24550
|
+
function numberField2(record3, keys) {
|
|
24551
|
+
const value = firstPresent2(record3, keys);
|
|
24552
|
+
if (value === null)
|
|
24553
|
+
return null;
|
|
24554
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
24555
|
+
}
|
|
24556
|
+
function booleanField(record3, keys) {
|
|
24557
|
+
const value = firstPresent2(record3, keys);
|
|
24558
|
+
return typeof value === "boolean" ? value : void 0;
|
|
24559
|
+
}
|
|
24560
|
+
function snapshotRecord(value) {
|
|
24561
|
+
if (!isRecord11(value))
|
|
24562
|
+
return void 0;
|
|
24563
|
+
const nested = value.task_snapshot ?? value.taskSnapshot;
|
|
24564
|
+
return isRecord11(nested) ? nested : value;
|
|
24565
|
+
}
|
|
24566
|
+
function backgroundKind(value, monitorDescription) {
|
|
24567
|
+
if (monitorDescription)
|
|
24568
|
+
return "monitor";
|
|
24569
|
+
if (typeof value === "string" && value.toLowerCase() === "monitor")
|
|
24570
|
+
return "monitor";
|
|
24571
|
+
return "run";
|
|
24572
|
+
}
|
|
24573
|
+
function isGrokBackgroundNotificationMethod(method) {
|
|
24574
|
+
return GROK_BACKGROUND_NOTIFICATION_METHODS.includes(method);
|
|
24575
|
+
}
|
|
24576
|
+
function fields(value) {
|
|
24577
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
|
|
24578
|
+
}
|
|
24579
|
+
function grokBackgroundEventFromUpdate(update) {
|
|
24580
|
+
if (!isRecord11(update) || typeof update.sessionUpdate !== "string" || !BACKGROUND_SESSION_UPDATES.has(update.sessionUpdate))
|
|
24581
|
+
return null;
|
|
24582
|
+
const taskId = stringField4(update, ["task_id", "taskId"]);
|
|
24583
|
+
if (update.sessionUpdate === "task_backgrounded") {
|
|
24584
|
+
const toolCallId = stringField4(update, ["tool_call_id", "toolCallId"]);
|
|
24585
|
+
const command = stringField4(update, ["command"]);
|
|
24586
|
+
if (!taskId || !toolCallId || !command)
|
|
24587
|
+
return null;
|
|
24588
|
+
const monitorDescription = optionalString(update, [
|
|
24589
|
+
"monitor_description",
|
|
24590
|
+
"monitorDescription"
|
|
24591
|
+
]);
|
|
24592
|
+
return {
|
|
24593
|
+
type: "task.backgrounded",
|
|
24594
|
+
taskId,
|
|
24595
|
+
toolCallId,
|
|
24596
|
+
command,
|
|
24597
|
+
kind: backgroundKind(void 0, monitorDescription),
|
|
24598
|
+
...fields({
|
|
24599
|
+
cwd: optionalString(update, ["cwd"]),
|
|
24600
|
+
outputFile: optionalString(update, ["output_file", "outputFile"]),
|
|
24601
|
+
description: monitorDescription ?? optionalString(update, ["description"])
|
|
24602
|
+
})
|
|
24603
|
+
};
|
|
24604
|
+
}
|
|
24605
|
+
if (update.sessionUpdate === "task_completed") {
|
|
24606
|
+
const snapshot = snapshotRecord(firstPresent2(update, ["task_snapshot", "taskSnapshot"]) ?? update);
|
|
24607
|
+
const id = snapshot && stringField4(snapshot, ["task_id", "taskId"]);
|
|
24608
|
+
if (!snapshot || !id)
|
|
24609
|
+
return null;
|
|
24610
|
+
return {
|
|
24611
|
+
type: "task.completed",
|
|
24612
|
+
taskId: id,
|
|
24613
|
+
kind: backgroundKind(snapshot.kind),
|
|
24614
|
+
...fields({
|
|
24615
|
+
command: optionalString(snapshot, ["command"]),
|
|
24616
|
+
description: optionalString(snapshot, ["description", "display_command", "displayCommand"]),
|
|
24617
|
+
output: optionalString(snapshot, ["output"]),
|
|
24618
|
+
outputFile: optionalString(snapshot, ["output_file", "outputFile"]),
|
|
24619
|
+
truncated: booleanField(snapshot, ["truncated"]),
|
|
24620
|
+
exitCode: numberField2(snapshot, ["exit_code", "exitCode"]),
|
|
24621
|
+
signal: optionalString(snapshot, ["signal"]),
|
|
24622
|
+
explicitlyKilled: booleanField(snapshot, ["explicitly_killed", "explicitlyKilled"])
|
|
24623
|
+
})
|
|
24624
|
+
};
|
|
24625
|
+
}
|
|
24626
|
+
if (!taskId)
|
|
24627
|
+
return null;
|
|
24628
|
+
if (update.sessionUpdate === "monitor_event") {
|
|
24629
|
+
const text = optionalString(update, ["event_text", "eventText"]);
|
|
24630
|
+
return text === void 0 ? null : {
|
|
24631
|
+
type: "monitor.event",
|
|
24632
|
+
taskId,
|
|
24633
|
+
text,
|
|
24634
|
+
...fields({ description: optionalString(update, ["description"]) })
|
|
24635
|
+
};
|
|
24636
|
+
}
|
|
24637
|
+
if (update.sessionUpdate === "scheduled_task_created" || update.sessionUpdate === "scheduled_task_fired") {
|
|
24638
|
+
const prompt = optionalString(update, ["prompt"]);
|
|
24639
|
+
const humanSchedule = optionalString(update, ["human_schedule", "humanSchedule"]);
|
|
24640
|
+
if (prompt === void 0 || !humanSchedule)
|
|
24641
|
+
return null;
|
|
24642
|
+
const next = optionalString(update, ["next_fire_at", "nextFireAt"]);
|
|
24643
|
+
const common = {
|
|
24644
|
+
taskId,
|
|
24645
|
+
prompt,
|
|
24646
|
+
humanSchedule,
|
|
24647
|
+
...fields({ nextFireAt: next && Number.isFinite(Date.parse(next)) ? next : void 0 })
|
|
24648
|
+
};
|
|
24649
|
+
return update.sessionUpdate === "scheduled_task_created" ? { type: "scheduled.created", ...common } : {
|
|
24650
|
+
type: "scheduled.fired",
|
|
24651
|
+
...common,
|
|
24652
|
+
...fields({ subagentId: stringField4(update, ["subagent_id", "subagentId"]) })
|
|
24653
|
+
};
|
|
24654
|
+
}
|
|
24655
|
+
if (update.sessionUpdate === "scheduled_task_deleted")
|
|
24656
|
+
return {
|
|
24657
|
+
type: "scheduled.deleted",
|
|
24658
|
+
taskId,
|
|
24659
|
+
...fields({ reason: optionalString(update, ["reason"]) })
|
|
24660
|
+
};
|
|
24661
|
+
return null;
|
|
24662
|
+
}
|
|
24663
|
+
function grokToolIsBackgrounded(rawOutput, rawInput) {
|
|
24664
|
+
const exitCode = isRecord11(rawOutput) ? numberField2(rawOutput, ["exit_code", "exitCode"]) : void 0;
|
|
24665
|
+
if (exitCode !== void 0 && exitCode !== null)
|
|
24666
|
+
return false;
|
|
24667
|
+
if (isRecord11(rawOutput) && optionalString(rawOutput, ["signal"]) === "backgrounded")
|
|
24668
|
+
return true;
|
|
24669
|
+
if (grokBackgroundTaskId(rawOutput, rawInput))
|
|
24670
|
+
return true;
|
|
24671
|
+
return Boolean(isRecord11(rawInput) && (rawInput.background === true || rawInput.is_background === true));
|
|
24672
|
+
}
|
|
24673
|
+
function grokBackgroundTaskId(rawOutput, rawInput) {
|
|
24674
|
+
if (isRecord11(rawOutput)) {
|
|
24675
|
+
const id = stringField4(rawOutput, ["task_id", "taskId"]);
|
|
24676
|
+
if (id)
|
|
24677
|
+
return id;
|
|
24678
|
+
}
|
|
24679
|
+
if (isRecord11(rawInput))
|
|
24680
|
+
return stringField4(rawInput, ["task_id", "taskId"]);
|
|
24681
|
+
return void 0;
|
|
24682
|
+
}
|
|
24683
|
+
function grokBackgroundCompletionOutcome(event) {
|
|
24684
|
+
if (event.explicitlyKilled || event.signal === "killed" || event.signal === "session_restart") {
|
|
24685
|
+
return { status: "cancelled", reason: "Background command stopped" };
|
|
24686
|
+
}
|
|
24687
|
+
if (event.exitCode === 0) {
|
|
24688
|
+
return { status: "succeeded" };
|
|
24689
|
+
}
|
|
24690
|
+
return {
|
|
24691
|
+
status: "failed",
|
|
24692
|
+
error: {
|
|
24693
|
+
code: "nativeFailure",
|
|
24694
|
+
message: event.signal ? `Grok background command ended with signal ${event.signal}` : `Grok background command exited ${event.exitCode}`,
|
|
24695
|
+
retryable: false
|
|
24696
|
+
}
|
|
24697
|
+
};
|
|
24698
|
+
}
|
|
24699
|
+
function applyGrokScheduledEvent(loops, event, observedIds) {
|
|
24700
|
+
observedIds?.add(event.taskId);
|
|
24701
|
+
if (event.type === "scheduled.deleted") {
|
|
24702
|
+
loops.delete(event.taskId);
|
|
24703
|
+
return;
|
|
24704
|
+
}
|
|
24705
|
+
const current = loops.get(event.taskId);
|
|
24706
|
+
loops.set(event.taskId, {
|
|
24707
|
+
taskId: event.taskId,
|
|
24708
|
+
prompt: event.prompt,
|
|
24709
|
+
humanSchedule: event.humanSchedule,
|
|
24710
|
+
...event.nextFireAt ? { nextFireAt: event.nextFireAt } : {},
|
|
24711
|
+
...event.type === "scheduled.fired" && event.subagentId ? { lastSubagentId: event.subagentId } : current?.lastSubagentId ? { lastSubagentId: current.lastSubagentId } : {}
|
|
24712
|
+
});
|
|
24713
|
+
}
|
|
24714
|
+
function collectGrokScheduledLoops(events) {
|
|
24715
|
+
const loops = /* @__PURE__ */ new Map();
|
|
24716
|
+
for (const event of events) {
|
|
24717
|
+
if (event.type === "scheduled.created" || event.type === "scheduled.fired" || event.type === "scheduled.deleted") {
|
|
24718
|
+
applyGrokScheduledEvent(loops, event);
|
|
24719
|
+
}
|
|
24720
|
+
}
|
|
24721
|
+
return loops;
|
|
24722
|
+
}
|
|
24723
|
+
|
|
24376
24724
|
// dist/grok-manual-compaction.js
|
|
24377
24725
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
24378
24726
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
24379
|
-
function
|
|
24727
|
+
function isRecord12(value) {
|
|
24380
24728
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24381
24729
|
}
|
|
24382
24730
|
function optionalNonNegativeInt2(value) {
|
|
@@ -24388,7 +24736,7 @@ function optionalErrorMessage2(value) {
|
|
|
24388
24736
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
24389
24737
|
if (cancelled)
|
|
24390
24738
|
return { outcome: "cancelled" };
|
|
24391
|
-
if (!
|
|
24739
|
+
if (!isRecord12(value))
|
|
24392
24740
|
return { outcome: "succeeded" };
|
|
24393
24741
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
24394
24742
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -24421,12 +24769,12 @@ function parseGrokCompactResult(value, cancelled = false) {
|
|
|
24421
24769
|
}
|
|
24422
24770
|
|
|
24423
24771
|
// dist/grok-rewind.js
|
|
24424
|
-
import
|
|
24772
|
+
import path16 from "node:path";
|
|
24425
24773
|
var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
24426
24774
|
function error52(code, message, retryable = false) {
|
|
24427
24775
|
return { code, message, retryable };
|
|
24428
24776
|
}
|
|
24429
|
-
function
|
|
24777
|
+
function isRecord13(value) {
|
|
24430
24778
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24431
24779
|
}
|
|
24432
24780
|
function buildGrokRewindParams(input) {
|
|
@@ -24438,10 +24786,10 @@ function buildGrokRewindParams(input) {
|
|
|
24438
24786
|
};
|
|
24439
24787
|
}
|
|
24440
24788
|
function parseGrokRewindResponse(value) {
|
|
24441
|
-
if (!
|
|
24789
|
+
if (!isRecord13(value))
|
|
24442
24790
|
return null;
|
|
24443
|
-
const payload = typeof value.success !== "boolean" &&
|
|
24444
|
-
if (!
|
|
24791
|
+
const payload = typeof value.success !== "boolean" && isRecord13(value.result) ? value.result : value;
|
|
24792
|
+
if (!isRecord13(payload) || typeof payload.success !== "boolean")
|
|
24445
24793
|
return null;
|
|
24446
24794
|
return rewindPayload(payload);
|
|
24447
24795
|
}
|
|
@@ -24501,8 +24849,8 @@ async function rewindGrokSession(input) {
|
|
|
24501
24849
|
error: error52("sessionNotFound", "Grok Native Session is unavailable")
|
|
24502
24850
|
};
|
|
24503
24851
|
}
|
|
24504
|
-
const sourceCwd =
|
|
24505
|
-
const targetCwd =
|
|
24852
|
+
const sourceCwd = path16.resolve(located.cwd);
|
|
24853
|
+
const targetCwd = path16.resolve(input.cwd);
|
|
24506
24854
|
if (sourceCwd !== targetCwd) {
|
|
24507
24855
|
return {
|
|
24508
24856
|
ok: false,
|
|
@@ -24607,14 +24955,14 @@ var GROK_CLOCK_ELICIT_PERSIST_FIXTURE = {
|
|
|
24607
24955
|
...GROK_CLOCK_ELICIT_FIXTURE,
|
|
24608
24956
|
persist: ["session", "always"]
|
|
24609
24957
|
};
|
|
24610
|
-
function
|
|
24958
|
+
function isRecord14(value) {
|
|
24611
24959
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24612
24960
|
}
|
|
24613
24961
|
function nonEmptyString(value) {
|
|
24614
24962
|
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
24615
24963
|
}
|
|
24616
|
-
function hasOnlyKeys(
|
|
24617
|
-
return Object.keys(
|
|
24964
|
+
function hasOnlyKeys(record3, allowed) {
|
|
24965
|
+
return Object.keys(record3).every((key) => allowed.has(key));
|
|
24618
24966
|
}
|
|
24619
24967
|
function clampText(value, max) {
|
|
24620
24968
|
return value.length <= max ? value : value.slice(0, max);
|
|
@@ -24648,11 +24996,11 @@ function parsePersistOffer(value) {
|
|
|
24648
24996
|
return out.length > 0 ? out : "invalid";
|
|
24649
24997
|
}
|
|
24650
24998
|
function schemaIsSupportedEmptyObject(schema) {
|
|
24651
|
-
if (!
|
|
24999
|
+
if (!isRecord14(schema) || !hasOnlyKeys(schema, SCHEMA_KEYS) || schema.type !== "object") {
|
|
24652
25000
|
return false;
|
|
24653
25001
|
}
|
|
24654
25002
|
if (schema.properties !== void 0) {
|
|
24655
|
-
if (!
|
|
25003
|
+
if (!isRecord14(schema.properties) || Object.keys(schema.properties).length !== 0)
|
|
24656
25004
|
return false;
|
|
24657
25005
|
}
|
|
24658
25006
|
if (schema.required !== void 0) {
|
|
@@ -24662,7 +25010,7 @@ function schemaIsSupportedEmptyObject(schema) {
|
|
|
24662
25010
|
return true;
|
|
24663
25011
|
}
|
|
24664
25012
|
function parseGrokMcpElicitParams(params) {
|
|
24665
|
-
if (!
|
|
25013
|
+
if (!isRecord14(params))
|
|
24666
25014
|
return { status: "invalid", message: "elicitation params must be an object" };
|
|
24667
25015
|
const sessionId = nonEmptyString(params.sessionId);
|
|
24668
25016
|
const toolCallId = nonEmptyString(params.toolCallId);
|
|
@@ -24690,7 +25038,7 @@ function parseGrokMcpElicitParams(params) {
|
|
|
24690
25038
|
return { status: "invalid", message: "form elicitation contains unreviewed fields" };
|
|
24691
25039
|
}
|
|
24692
25040
|
if (params.requestedSchema !== void 0) {
|
|
24693
|
-
if (!
|
|
25041
|
+
if (!isRecord14(params.requestedSchema)) {
|
|
24694
25042
|
return { status: "invalid", message: "requestedSchema must be an object" };
|
|
24695
25043
|
}
|
|
24696
25044
|
if (!schemaIsSupportedEmptyObject(params.requestedSchema))
|
|
@@ -24757,7 +25105,7 @@ function projectGrokMcpElicitApproval(input) {
|
|
|
24757
25105
|
};
|
|
24758
25106
|
}
|
|
24759
25107
|
function grokElicitationResolvedToolCallId(update) {
|
|
24760
|
-
if (!
|
|
25108
|
+
if (!isRecord14(update) || update.sessionUpdate !== "interaction_resolved")
|
|
24761
25109
|
return void 0;
|
|
24762
25110
|
return nonEmptyString(update.tool_call_id) ?? nonEmptyString(update.toolCallId);
|
|
24763
25111
|
}
|
|
@@ -24887,19 +25235,19 @@ var GrokPermissionConfirmation = class {
|
|
|
24887
25235
|
// dist/grok-questions.js
|
|
24888
25236
|
var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
|
|
24889
25237
|
var GROK_QUESTION_ACTIVITY_METHOD = "_x.ai/ask_user_question_activity";
|
|
24890
|
-
function
|
|
25238
|
+
function isRecord15(value) {
|
|
24891
25239
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24892
25240
|
}
|
|
24893
25241
|
function nonEmptyString2(value) {
|
|
24894
25242
|
return typeof value === "string" && value.trim().length > 0;
|
|
24895
25243
|
}
|
|
24896
25244
|
function parseGrokQuestionRequest(value) {
|
|
24897
|
-
if (!
|
|
25245
|
+
if (!isRecord15(value) || !nonEmptyString2(value.sessionId) || !nonEmptyString2(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0) {
|
|
24898
25246
|
throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
|
|
24899
25247
|
}
|
|
24900
25248
|
const seen = /* @__PURE__ */ new Set();
|
|
24901
25249
|
const questions = value.questions.map((question) => {
|
|
24902
|
-
if (!
|
|
25250
|
+
if (!isRecord15(question) || !nonEmptyString2(question.question) || seen.has(question.question) || !Array.isArray(question.options) || question.multiSelect != null && typeof question.multiSelect !== "boolean" || question.multi_select != null && typeof question.multi_select !== "boolean") {
|
|
24903
25251
|
throw new Error("Grok question text must be unique and options/multiSelect must be valid");
|
|
24904
25252
|
}
|
|
24905
25253
|
if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
|
|
@@ -24907,7 +25255,7 @@ function parseGrokQuestionRequest(value) {
|
|
|
24907
25255
|
seen.add(question.question);
|
|
24908
25256
|
const labels = /* @__PURE__ */ new Set();
|
|
24909
25257
|
const options = question.options.map((option) => {
|
|
24910
|
-
if (!
|
|
25258
|
+
if (!isRecord15(option) || !nonEmptyString2(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string") {
|
|
24911
25259
|
throw new Error("Grok question options require unique labels and text descriptions/previews");
|
|
24912
25260
|
}
|
|
24913
25261
|
labels.add(option.label);
|
|
@@ -25078,8 +25426,8 @@ function parseGrokInterjectResult(value) {
|
|
|
25078
25426
|
return { status: "queued" };
|
|
25079
25427
|
if (typeof value !== "object" || Array.isArray(value))
|
|
25080
25428
|
return null;
|
|
25081
|
-
const
|
|
25082
|
-
const nested =
|
|
25429
|
+
const record3 = value;
|
|
25430
|
+
const nested = record3.status === void 0 && typeof record3.result === "object" && record3.result !== null ? record3.result : record3;
|
|
25083
25431
|
const status2 = nested.status ?? nested.ok;
|
|
25084
25432
|
if (status2 === void 0 || status2 === "queued" || status2 === true)
|
|
25085
25433
|
return { status: "queued" };
|
|
@@ -25097,16 +25445,16 @@ var GrokTransportError = class extends Error {
|
|
|
25097
25445
|
this.name = "GrokTransportError";
|
|
25098
25446
|
}
|
|
25099
25447
|
};
|
|
25100
|
-
function
|
|
25448
|
+
function isRecord16(value) {
|
|
25101
25449
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25102
25450
|
}
|
|
25103
25451
|
function acpToolName(update, metadata) {
|
|
25104
|
-
if (!
|
|
25452
|
+
if (!isRecord16(update))
|
|
25105
25453
|
return void 0;
|
|
25106
25454
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
25107
25455
|
return update.name;
|
|
25108
|
-
const meta3 =
|
|
25109
|
-
const tool = meta3 &&
|
|
25456
|
+
const meta3 = isRecord16(update._meta) ? update._meta : metadata;
|
|
25457
|
+
const tool = meta3 && isRecord16(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
25110
25458
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
25111
25459
|
}
|
|
25112
25460
|
function errorText(error53) {
|
|
@@ -25162,14 +25510,20 @@ function signalProcessTree(child, signal) {
|
|
|
25162
25510
|
try {
|
|
25163
25511
|
process.kill(-child.pid, signal);
|
|
25164
25512
|
} catch (error53) {
|
|
25165
|
-
if (!
|
|
25166
|
-
|
|
25513
|
+
if (!isRecord16(error53) || error53.code === "ESRCH")
|
|
25514
|
+
return;
|
|
25515
|
+
try {
|
|
25516
|
+
child.kill(signal);
|
|
25517
|
+
} catch (fallback) {
|
|
25518
|
+
if (!isRecord16(fallback) || fallback.code !== "ESRCH")
|
|
25519
|
+
throw fallback;
|
|
25520
|
+
}
|
|
25167
25521
|
}
|
|
25168
25522
|
}
|
|
25169
25523
|
function grokNotificationMetadata(envelope, update) {
|
|
25170
|
-
if (!
|
|
25524
|
+
if (!isRecord16(envelope) && !isRecord16(update))
|
|
25171
25525
|
return void 0;
|
|
25172
|
-
return { ...
|
|
25526
|
+
return { ...isRecord16(update) ? update : {}, ...isRecord16(envelope) ? envelope : {} };
|
|
25173
25527
|
}
|
|
25174
25528
|
function transportEvent(update, metadata) {
|
|
25175
25529
|
const extension = update;
|
|
@@ -25211,6 +25565,9 @@ function transportEvent(update, metadata) {
|
|
|
25211
25565
|
const compaction = grokCompactionEventFromUpdate(extension);
|
|
25212
25566
|
if (compaction)
|
|
25213
25567
|
return compaction;
|
|
25568
|
+
const background = grokBackgroundEventFromUpdate(extension);
|
|
25569
|
+
if (background)
|
|
25570
|
+
return { ...background, ...metadata ? { metadata } : {} };
|
|
25214
25571
|
const subagent = grokSubagentEventFromUpdate(extension);
|
|
25215
25572
|
if (subagent)
|
|
25216
25573
|
return subagent;
|
|
@@ -25270,13 +25627,13 @@ function transportEvent(update, metadata) {
|
|
|
25270
25627
|
function grokHomeDir(options) {
|
|
25271
25628
|
const environment = { ...process.env, ...options.environment };
|
|
25272
25629
|
const home = environment.HOME ?? environment.USERPROFILE ?? os6.homedir();
|
|
25273
|
-
return environment.GROK_HOME ??
|
|
25630
|
+
return environment.GROK_HOME ?? path17.join(home, ".grok");
|
|
25274
25631
|
}
|
|
25275
25632
|
function grokNativeSessionDirectory(options, sessionId) {
|
|
25276
|
-
return
|
|
25633
|
+
return path17.join(grokHomeDir(options), "sessions", encodeURIComponent(path17.resolve(options.cwd)), sessionId);
|
|
25277
25634
|
}
|
|
25278
25635
|
function nativeSessionFile(options, sessionId, fileName) {
|
|
25279
|
-
return
|
|
25636
|
+
return path17.join(grokNativeSessionDirectory(options, sessionId), fileName);
|
|
25280
25637
|
}
|
|
25281
25638
|
function nativeHistoryPath(options, sessionId) {
|
|
25282
25639
|
return nativeSessionFile(options, sessionId, "updates.jsonl");
|
|
@@ -25289,14 +25646,14 @@ async function readNativeSignals(options, sessionId) {
|
|
|
25289
25646
|
}
|
|
25290
25647
|
}
|
|
25291
25648
|
function isMissingFile(error53) {
|
|
25292
|
-
return
|
|
25649
|
+
return isRecord16(error53) && error53.code === "ENOENT";
|
|
25293
25650
|
}
|
|
25294
25651
|
async function locateGrokNativeSession(options, sessionId) {
|
|
25295
25652
|
if (sessionId.length === 0)
|
|
25296
25653
|
return null;
|
|
25297
25654
|
let entries;
|
|
25298
25655
|
try {
|
|
25299
|
-
entries = await readdir(
|
|
25656
|
+
entries = await readdir(path17.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
|
|
25300
25657
|
} catch (error53) {
|
|
25301
25658
|
if (isMissingFile(error53))
|
|
25302
25659
|
return null;
|
|
@@ -25310,9 +25667,9 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
25310
25667
|
continue;
|
|
25311
25668
|
let summaryRaw;
|
|
25312
25669
|
try {
|
|
25313
|
-
summaryRaw = await readFile5(
|
|
25670
|
+
summaryRaw = await readFile5(path17.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
25314
25671
|
} catch (error53) {
|
|
25315
|
-
if (isMissingFile(error53) ||
|
|
25672
|
+
if (isMissingFile(error53) || isRecord16(error53) && error53.code === "ENOTDIR")
|
|
25316
25673
|
continue;
|
|
25317
25674
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
25318
25675
|
cause: error53
|
|
@@ -25324,11 +25681,11 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
25324
25681
|
} catch {
|
|
25325
25682
|
continue;
|
|
25326
25683
|
}
|
|
25327
|
-
if (!
|
|
25684
|
+
if (!isRecord16(parsed))
|
|
25328
25685
|
continue;
|
|
25329
25686
|
const info = parsed.info;
|
|
25330
|
-
const cwd =
|
|
25331
|
-
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ?
|
|
25687
|
+
const cwd = isRecord16(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path17.resolve(info.cwd) : path17.resolve(decodeURIComponent(entry.name));
|
|
25688
|
+
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path17.resolve(parsed.source_workspace_dir) : void 0;
|
|
25332
25689
|
matches.push({
|
|
25333
25690
|
cwd,
|
|
25334
25691
|
...sourceWorkspaceDir ? { sourceWorkspaceDir } : {}
|
|
@@ -25338,7 +25695,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
25338
25695
|
}
|
|
25339
25696
|
async function readGrokNativeHistory(options, sessionId) {
|
|
25340
25697
|
try {
|
|
25341
|
-
return parseNativeHistory(await readFile5(nativeHistoryPath({ ...options, cwd:
|
|
25698
|
+
return parseNativeHistory(await readFile5(nativeHistoryPath({ ...options, cwd: path17.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
|
|
25342
25699
|
} catch (error53) {
|
|
25343
25700
|
if (isMissingFile(error53))
|
|
25344
25701
|
return [];
|
|
@@ -25354,20 +25711,20 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
25354
25711
|
for (const line of contents.split("\n")) {
|
|
25355
25712
|
if (line.length === 0)
|
|
25356
25713
|
continue;
|
|
25357
|
-
let
|
|
25714
|
+
let record3;
|
|
25358
25715
|
try {
|
|
25359
|
-
|
|
25716
|
+
record3 = JSON.parse(line);
|
|
25360
25717
|
} catch {
|
|
25361
25718
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
25362
25719
|
}
|
|
25363
|
-
if (!
|
|
25720
|
+
if (!isRecord16(record3) || !isRecord16(record3.params))
|
|
25364
25721
|
continue;
|
|
25365
|
-
const params =
|
|
25366
|
-
if (params.sessionId !== sessionId || !
|
|
25722
|
+
const params = record3.params;
|
|
25723
|
+
if (params.sessionId !== sessionId || !isRecord16(params.update))
|
|
25367
25724
|
continue;
|
|
25368
25725
|
let metadata = grokNotificationMetadata(params._meta, params.update._meta);
|
|
25369
|
-
if (typeof
|
|
25370
|
-
metadata = { nativeTimestampMs:
|
|
25726
|
+
if (typeof record3.timestamp === "number" && Number.isFinite(record3.timestamp))
|
|
25727
|
+
metadata = { nativeTimestampMs: record3.timestamp * 1e3, ...metadata };
|
|
25371
25728
|
const event = transportEvent(params.update, metadata);
|
|
25372
25729
|
if (event)
|
|
25373
25730
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -25433,7 +25790,7 @@ var GrokAcpTransport = class {
|
|
|
25433
25790
|
if (!this.#connection)
|
|
25434
25791
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
25435
25792
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
25436
|
-
return
|
|
25793
|
+
return isRecord16(result) ? result.usage : void 0;
|
|
25437
25794
|
}
|
|
25438
25795
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
25439
25796
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -25538,7 +25895,7 @@ var GrokAcpTransport = class {
|
|
|
25538
25895
|
sessionId: this.#sessionId,
|
|
25539
25896
|
toolCallId
|
|
25540
25897
|
}), 3e3, "Grok question activity");
|
|
25541
|
-
if (!
|
|
25898
|
+
if (!isRecord16(raw) || !("timeout" in raw))
|
|
25542
25899
|
throw new GrokTransportError("protocolError", "Invalid Grok activity acknowledgement");
|
|
25543
25900
|
return raw.timeout === null ? null : questionAutoResolutionSchema.parse(raw.timeout);
|
|
25544
25901
|
} catch (error53) {
|
|
@@ -25810,7 +26167,7 @@ var GrokAcpTransport = class {
|
|
|
25810
26167
|
}
|
|
25811
26168
|
} : {}
|
|
25812
26169
|
});
|
|
25813
|
-
if (!
|
|
26170
|
+
if (!isRecord16(response) || !isRecord16(response._meta) || !isRecord16(response._meta.model)) {
|
|
25814
26171
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
25815
26172
|
}
|
|
25816
26173
|
const selected = response._meta.model.Ok;
|
|
@@ -25850,7 +26207,7 @@ var GrokAcpTransport = class {
|
|
|
25850
26207
|
permission_mode: mode
|
|
25851
26208
|
});
|
|
25852
26209
|
const response = await connection.request("_x.ai/session/info", { sessionId });
|
|
25853
|
-
if (!
|
|
26210
|
+
if (!isRecord16(response) || !isRecord16(response.result) || response.result.sessionId !== sessionId) {
|
|
25854
26211
|
throw new Error("Grok did not confirm the target Session");
|
|
25855
26212
|
}
|
|
25856
26213
|
})()
|
|
@@ -25922,12 +26279,62 @@ var GrokAcpTransport = class {
|
|
|
25922
26279
|
this.#background?.onEvent(enriched);
|
|
25923
26280
|
}
|
|
25924
26281
|
#handleExtensionNotification(method, params) {
|
|
25925
|
-
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
26282
|
+
if (!isGrokExtensionSessionUpdateMethod(method) && !isGrokBackgroundNotificationMethod(method)) {
|
|
25926
26283
|
return;
|
|
25927
|
-
|
|
26284
|
+
}
|
|
26285
|
+
if (typeof params.sessionId !== "string" || !isRecord16(params.update))
|
|
25928
26286
|
return;
|
|
25929
26287
|
this.#handleUpdate(params);
|
|
25930
26288
|
}
|
|
26289
|
+
async killTask(taskId, source = "clientUi") {
|
|
26290
|
+
const result = await this.#extResult(GROK_TASK_KILL_METHOD, {
|
|
26291
|
+
sessionId: this.sessionId,
|
|
26292
|
+
taskId,
|
|
26293
|
+
source
|
|
26294
|
+
});
|
|
26295
|
+
if (!isRecord16(result) || result.taskId !== taskId || !["killed", "already_exited", "not_found"].includes(String(result.outcome)))
|
|
26296
|
+
throw new GrokTransportError("protocolError", "Malformed Grok task kill response");
|
|
26297
|
+
return result.outcome;
|
|
26298
|
+
}
|
|
26299
|
+
async listTasks() {
|
|
26300
|
+
return this.#extResult(GROK_TASK_LIST_METHOD, { sessionId: this.sessionId });
|
|
26301
|
+
}
|
|
26302
|
+
async getSubagent(id) {
|
|
26303
|
+
return this.#extResult("x.ai/subagent/get", { subagentId: id, block: false });
|
|
26304
|
+
}
|
|
26305
|
+
async deleteScheduledTask(taskId) {
|
|
26306
|
+
const result = await this.#extResult(GROK_SCHEDULER_DELETE_METHOD, {
|
|
26307
|
+
sessionId: this.sessionId,
|
|
26308
|
+
taskId
|
|
26309
|
+
});
|
|
26310
|
+
if (!isRecord16(result) || result.taskId !== taskId || typeof result.deleted !== "boolean")
|
|
26311
|
+
throw new GrokTransportError("protocolError", "Malformed Grok scheduler delete response");
|
|
26312
|
+
return result.deleted;
|
|
26313
|
+
}
|
|
26314
|
+
async #extResult(method, params) {
|
|
26315
|
+
if (!this.#connection || !this.#sessionId || this.#closed || this.#closing) {
|
|
26316
|
+
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
26317
|
+
}
|
|
26318
|
+
let raw;
|
|
26319
|
+
try {
|
|
26320
|
+
raw = await withTimeout(this.#connection.request(method, params), this.#options.commandTimeoutMs, `Grok ${method}`);
|
|
26321
|
+
} catch (error53) {
|
|
26322
|
+
if (!isRecord16(error53) || error53.code !== -32601)
|
|
26323
|
+
throw error53;
|
|
26324
|
+
try {
|
|
26325
|
+
raw = await withTimeout(this.#connection.request(`_${method}`, params), this.#options.commandTimeoutMs, `Grok _${method}`);
|
|
26326
|
+
} catch (fallback) {
|
|
26327
|
+
if (isRecord16(fallback) && fallback.code === -32601)
|
|
26328
|
+
throw new GrokTransportError("unsupported", `Grok does not support ${method}`);
|
|
26329
|
+
throw fallback;
|
|
26330
|
+
}
|
|
26331
|
+
}
|
|
26332
|
+
if (isRecord16(raw) && raw.error !== void 0 && raw.error !== null) {
|
|
26333
|
+
const message = typeof raw.error === "string" ? raw.error : isRecord16(raw.error) && typeof raw.error.message === "string" ? raw.error.message : `Grok ${method} failed`;
|
|
26334
|
+
throw new GrokTransportError("unavailable", message);
|
|
26335
|
+
}
|
|
26336
|
+
return isRecord16(raw) && "result" in raw ? raw.result : raw;
|
|
26337
|
+
}
|
|
25931
26338
|
#handlePermission(params) {
|
|
25932
26339
|
const observer = this.#activePrompt ?? this.#background;
|
|
25933
26340
|
if (params.sessionId !== this.#sessionId || !observer) {
|
|
@@ -25977,7 +26384,7 @@ var GrokAcpTransport = class {
|
|
|
25977
26384
|
// dist/session-import.js
|
|
25978
26385
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
25979
26386
|
import { opendir as opendir2, readFile as readFile6, stat as stat2 } from "node:fs/promises";
|
|
25980
|
-
import
|
|
26387
|
+
import path18 from "node:path";
|
|
25981
26388
|
import { createInterface as createInterface2 } from "node:readline";
|
|
25982
26389
|
|
|
25983
26390
|
// ../../harness-adapter/dist/session-import.js
|
|
@@ -26098,7 +26505,7 @@ var SessionImportScope = class {
|
|
|
26098
26505
|
// dist/session-import.js
|
|
26099
26506
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
26100
26507
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
26101
|
-
function
|
|
26508
|
+
function isRecord17(value) {
|
|
26102
26509
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26103
26510
|
}
|
|
26104
26511
|
async function readJson(file2, signal) {
|
|
@@ -26111,7 +26518,7 @@ function processAlive(pid) {
|
|
|
26111
26518
|
process.kill(pid, 0);
|
|
26112
26519
|
return true;
|
|
26113
26520
|
} catch (error53) {
|
|
26114
|
-
return
|
|
26521
|
+
return isRecord17(error53) && error53.code === "EPERM";
|
|
26115
26522
|
}
|
|
26116
26523
|
}
|
|
26117
26524
|
async function firstUserText(file2, signal) {
|
|
@@ -26128,10 +26535,10 @@ async function firstUserText(file2, signal) {
|
|
|
26128
26535
|
} catch {
|
|
26129
26536
|
continue;
|
|
26130
26537
|
}
|
|
26131
|
-
const update =
|
|
26132
|
-
if (!
|
|
26538
|
+
const update = isRecord17(entry) && isRecord17(entry.params) ? entry.params.update : null;
|
|
26539
|
+
if (!isRecord17(update) || update.sessionUpdate !== "user_message_chunk")
|
|
26133
26540
|
continue;
|
|
26134
|
-
const text =
|
|
26541
|
+
const text = isRecord17(update.content) ? update.content.text : null;
|
|
26135
26542
|
return typeof text === "string" ? text : "";
|
|
26136
26543
|
}
|
|
26137
26544
|
return null;
|
|
@@ -26198,7 +26605,7 @@ var GrokSessionImport = class {
|
|
|
26198
26605
|
const active = /* @__PURE__ */ new Set();
|
|
26199
26606
|
let entries;
|
|
26200
26607
|
try {
|
|
26201
|
-
entries = await readJson(
|
|
26608
|
+
entries = await readJson(path18.join(this.#home(), "active_sessions.json"), signal);
|
|
26202
26609
|
} catch (error53) {
|
|
26203
26610
|
signal.throwIfAborted();
|
|
26204
26611
|
if (isStorageAccessError(error53))
|
|
@@ -26208,14 +26615,14 @@ var GrokSessionImport = class {
|
|
|
26208
26615
|
if (!Array.isArray(entries))
|
|
26209
26616
|
return active;
|
|
26210
26617
|
for (const entry of entries) {
|
|
26211
|
-
if (
|
|
26618
|
+
if (isRecord17(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
26212
26619
|
active.add(entry.session_id);
|
|
26213
26620
|
}
|
|
26214
26621
|
return active;
|
|
26215
26622
|
}
|
|
26216
26623
|
/** Session ID to every directory claiming it. Enumerated links are not followed. */
|
|
26217
26624
|
async #sessionDirectories(signal) {
|
|
26218
|
-
const root =
|
|
26625
|
+
const root = path18.join(this.#home(), "sessions");
|
|
26219
26626
|
const found = /* @__PURE__ */ new Map();
|
|
26220
26627
|
const info = await optionalLstat(root);
|
|
26221
26628
|
if (!info)
|
|
@@ -26226,7 +26633,7 @@ var GrokSessionImport = class {
|
|
|
26226
26633
|
signal.throwIfAborted();
|
|
26227
26634
|
if (!workspace.isDirectory())
|
|
26228
26635
|
continue;
|
|
26229
|
-
const workspaceDirectory =
|
|
26636
|
+
const workspaceDirectory = path18.join(root, workspace.name);
|
|
26230
26637
|
const sessions = await opendir2(workspaceDirectory).catch((error53) => {
|
|
26231
26638
|
if (isMissingFileError(error53))
|
|
26232
26639
|
return null;
|
|
@@ -26239,7 +26646,7 @@ var GrokSessionImport = class {
|
|
|
26239
26646
|
if (!session.isDirectory())
|
|
26240
26647
|
continue;
|
|
26241
26648
|
const directories = found.get(session.name) ?? [];
|
|
26242
|
-
directories.push(
|
|
26649
|
+
directories.push(path18.join(workspaceDirectory, session.name));
|
|
26243
26650
|
found.set(session.name, directories);
|
|
26244
26651
|
}
|
|
26245
26652
|
}
|
|
@@ -26247,25 +26654,25 @@ var GrokSessionImport = class {
|
|
|
26247
26654
|
}
|
|
26248
26655
|
async #candidate(sessionDirectory, active, signal) {
|
|
26249
26656
|
signal.throwIfAborted();
|
|
26250
|
-
const nativeSessionId =
|
|
26657
|
+
const nativeSessionId = path18.basename(sessionDirectory);
|
|
26251
26658
|
const files = [
|
|
26252
|
-
|
|
26253
|
-
|
|
26659
|
+
path18.join(sessionDirectory, "summary.json"),
|
|
26660
|
+
path18.join(sessionDirectory, "updates.jsonl")
|
|
26254
26661
|
];
|
|
26255
26662
|
return readStableFiles(files, async ([summaryInfo, updates]) => {
|
|
26256
26663
|
if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
|
|
26257
26664
|
return null;
|
|
26258
26665
|
try {
|
|
26259
26666
|
const summary = await readJson(files[0], signal);
|
|
26260
|
-
if (!
|
|
26667
|
+
if (!isRecord17(summary) || !isRecord17(summary.info) || summary.info.id !== nativeSessionId)
|
|
26261
26668
|
return null;
|
|
26262
26669
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
26263
26670
|
return null;
|
|
26264
26671
|
const nativeCwd = summary.info.cwd;
|
|
26265
|
-
if (typeof nativeCwd !== "string" || !
|
|
26672
|
+
if (typeof nativeCwd !== "string" || !path18.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
|
|
26266
26673
|
return null;
|
|
26267
|
-
const cwd =
|
|
26268
|
-
if (encodeURIComponent(cwd) !==
|
|
26674
|
+
const cwd = path18.resolve(nativeCwd);
|
|
26675
|
+
if (encodeURIComponent(cwd) !== path18.basename(path18.dirname(sessionDirectory)))
|
|
26269
26676
|
return null;
|
|
26270
26677
|
if (!(await stat2(cwd)).isDirectory())
|
|
26271
26678
|
return null;
|
|
@@ -26508,8 +26915,488 @@ var GrokSubagentLifecycle = class {
|
|
|
26508
26915
|
}
|
|
26509
26916
|
};
|
|
26510
26917
|
|
|
26918
|
+
// dist/grok-activity.js
|
|
26919
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
26920
|
+
import path19 from "node:path";
|
|
26921
|
+
var record2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26922
|
+
var fail = (code, message) => ({ ok: false, error: { code, message, retryable: false } });
|
|
26923
|
+
function parseGrokTaskList(value, sessionId) {
|
|
26924
|
+
if (!record2(value) || !Array.isArray(value.tasks))
|
|
26925
|
+
throw new Error("Malformed Grok task list");
|
|
26926
|
+
return value.tasks.map((entry) => {
|
|
26927
|
+
if (!record2(entry) || typeof entry.task_id !== "string" || typeof entry.command !== "string" || typeof entry.output !== "string" || typeof entry.completed !== "boolean" || typeof entry.truncated !== "boolean")
|
|
26928
|
+
throw new Error("Malformed Grok task snapshot");
|
|
26929
|
+
return entry;
|
|
26930
|
+
}).filter((entry) => (!entry.owner_session_id || entry.owner_session_id === sessionId) && entry.is_backgrounded === true);
|
|
26931
|
+
}
|
|
26932
|
+
async function readGrokScheduledLoops(directory) {
|
|
26933
|
+
let raw;
|
|
26934
|
+
try {
|
|
26935
|
+
raw = JSON.parse(await readFile7(path19.join(directory, "resources_state.json"), "utf8"));
|
|
26936
|
+
} catch (error53) {
|
|
26937
|
+
if (error53.code === "ENOENT")
|
|
26938
|
+
return null;
|
|
26939
|
+
throw error53;
|
|
26940
|
+
}
|
|
26941
|
+
if (!record2(raw) || !record2(raw.state))
|
|
26942
|
+
throw new Error("Malformed Grok resource state");
|
|
26943
|
+
const scheduler = raw.state["grok_build.Scheduler"];
|
|
26944
|
+
if (scheduler === void 0)
|
|
26945
|
+
return /* @__PURE__ */ new Map();
|
|
26946
|
+
if (!record2(scheduler) || !Array.isArray(scheduler.tasks))
|
|
26947
|
+
throw new Error("Malformed Grok scheduler state");
|
|
26948
|
+
const loops = /* @__PURE__ */ new Map();
|
|
26949
|
+
for (const task of scheduler.tasks) {
|
|
26950
|
+
if (!record2(task) || typeof task.id !== "string" || typeof task.prompt !== "string" || typeof task.intervalSecs !== "number" || task.intervalSecs <= 0)
|
|
26951
|
+
throw new Error("Malformed Grok scheduled task");
|
|
26952
|
+
const anchor = typeof task.lastFiredAt === "string" ? task.lastFiredAt : task.createdAt;
|
|
26953
|
+
const next = typeof anchor === "string" ? Date.parse(anchor) + task.intervalSecs * 1e3 : NaN;
|
|
26954
|
+
loops.set(task.id, {
|
|
26955
|
+
taskId: task.id,
|
|
26956
|
+
prompt: task.prompt,
|
|
26957
|
+
humanSchedule: `every ${task.intervalSecs} seconds`,
|
|
26958
|
+
...(task.recurring !== false || task.lastFiredAt == null) && (typeof task.expiresAt !== "string" || Date.parse(task.expiresAt) > Date.now()) && Number.isFinite(next) ? { nextFireAt: new Date(next).toISOString() } : {},
|
|
26959
|
+
...typeof task.lastSubagentId === "string" ? { lastSubagentId: task.lastSubagentId } : {}
|
|
26960
|
+
});
|
|
26961
|
+
}
|
|
26962
|
+
return loops;
|
|
26963
|
+
}
|
|
26964
|
+
function createGrokActivity(options) {
|
|
26965
|
+
let tasks = [];
|
|
26966
|
+
const summaries = () => [
|
|
26967
|
+
...tasks.map((task) => {
|
|
26968
|
+
const commandItemId = options.commandItemId?.(task.task_id);
|
|
26969
|
+
return {
|
|
26970
|
+
id: `task:${task.task_id}`,
|
|
26971
|
+
kind: task.kind === "monitor" ? "monitor" : "task",
|
|
26972
|
+
label: task.description ?? task.command,
|
|
26973
|
+
status: !task.completed ? "running" : task.explicitly_killed ? "cancelled" : task.exit_code === 0 ? "completed" : task.exit_code != null || task.signal ? "failed" : "unknown",
|
|
26974
|
+
canStop: !task.completed && Boolean(options.killTask),
|
|
26975
|
+
...commandItemId ? { commandItemId } : {}
|
|
26976
|
+
};
|
|
26977
|
+
}),
|
|
26978
|
+
...[...options.loops.values()].map((loop) => ({
|
|
26979
|
+
id: `loop:${loop.taskId}`,
|
|
26980
|
+
kind: "loop",
|
|
26981
|
+
label: loop.prompt,
|
|
26982
|
+
status: "scheduled",
|
|
26983
|
+
canStop: Boolean(options.deleteLoop),
|
|
26984
|
+
schedule: loop.humanSchedule,
|
|
26985
|
+
...loop.nextFireAt ? { nextRunAt: loop.nextFireAt } : {},
|
|
26986
|
+
...loop.lastSubagentId ? { relatedActivityId: `subagent:${loop.lastSubagentId}` } : {}
|
|
26987
|
+
})),
|
|
26988
|
+
...[...options.children.values()].map((child) => ({
|
|
26989
|
+
id: `subagent:${child.nativeSubagentId}`,
|
|
26990
|
+
kind: "subagent",
|
|
26991
|
+
label: child.description,
|
|
26992
|
+
status: child.status === "pending" || child.status === "running" ? "running" : child.status === "interrupted" ? "cancelled" : child.status,
|
|
26993
|
+
canStop: false
|
|
26994
|
+
}))
|
|
26995
|
+
];
|
|
26996
|
+
const capability = {
|
|
26997
|
+
subagents: () => [...options.children.values()].map((state) => ({
|
|
26998
|
+
activityId: `subagent:${state.nativeSubagentId}`,
|
|
26999
|
+
state
|
|
27000
|
+
})),
|
|
27001
|
+
async list() {
|
|
27002
|
+
if (!options.isOpen())
|
|
27003
|
+
return fail("nativeFailure", "Grok Session is closed");
|
|
27004
|
+
try {
|
|
27005
|
+
const loops = await readGrokScheduledLoops(options.directory);
|
|
27006
|
+
if (!options.isOpen())
|
|
27007
|
+
return fail("nativeFailure", "Grok Session changed");
|
|
27008
|
+
if (loops) {
|
|
27009
|
+
for (const id of options.loops.keys())
|
|
27010
|
+
if (!options.observedLoopIds.has(id) && !loops.has(id))
|
|
27011
|
+
options.loops.delete(id);
|
|
27012
|
+
for (const [id, loop] of loops)
|
|
27013
|
+
if (!options.observedLoopIds.has(id))
|
|
27014
|
+
options.loops.set(id, loop);
|
|
27015
|
+
}
|
|
27016
|
+
for (const loop of options.loops.values()) {
|
|
27017
|
+
if (loop.lastSubagentId && !options.children.has(loop.lastSubagentId))
|
|
27018
|
+
options.children.set(loop.lastSubagentId, {
|
|
27019
|
+
subagentId: loop.lastSubagentId,
|
|
27020
|
+
nativeSubagentId: loop.lastSubagentId,
|
|
27021
|
+
description: loop.prompt,
|
|
27022
|
+
background: true,
|
|
27023
|
+
status: "pending"
|
|
27024
|
+
});
|
|
27025
|
+
}
|
|
27026
|
+
if (options.listTasks) {
|
|
27027
|
+
const nativeTasks = parseGrokTaskList(await options.listTasks(), options.sessionId);
|
|
27028
|
+
if (!options.isOpen())
|
|
27029
|
+
return fail("nativeFailure", "Grok Session changed");
|
|
27030
|
+
tasks = nativeTasks;
|
|
27031
|
+
options.observeTasks?.(tasks);
|
|
27032
|
+
}
|
|
27033
|
+
if (options.getChild)
|
|
27034
|
+
for (const [id, child] of options.children) {
|
|
27035
|
+
if (child.status !== "running" && child.status !== "pending")
|
|
27036
|
+
continue;
|
|
27037
|
+
const raw = await options.getChild(id);
|
|
27038
|
+
if (!options.isOpen())
|
|
27039
|
+
return fail("nativeFailure", "Grok Session changed");
|
|
27040
|
+
if (!record2(raw))
|
|
27041
|
+
throw new Error("Malformed native child response");
|
|
27042
|
+
const snapshot = raw.snapshot;
|
|
27043
|
+
if (snapshot === null)
|
|
27044
|
+
continue;
|
|
27045
|
+
if (!record2(snapshot) || snapshot.subagentId !== id || snapshot.parentSessionId !== options.sessionId)
|
|
27046
|
+
throw new Error("Native child owner mismatch");
|
|
27047
|
+
const status2 = snapshot.status;
|
|
27048
|
+
if (!["initializing", "running", "completed", "failed", "cancelled"].includes(String(status2)))
|
|
27049
|
+
throw new Error("Unknown native child status");
|
|
27050
|
+
options.children.set(id, {
|
|
27051
|
+
...child,
|
|
27052
|
+
status: status2 === "initializing" ? "pending" : status2 === "cancelled" ? "interrupted" : status2
|
|
27053
|
+
});
|
|
27054
|
+
}
|
|
27055
|
+
return { ok: true, value: summaries() };
|
|
27056
|
+
} catch (error53) {
|
|
27057
|
+
return fail("nativeFailure", error53 instanceof Error ? error53.message : "Grok activity read failed");
|
|
27058
|
+
}
|
|
27059
|
+
},
|
|
27060
|
+
async read(id) {
|
|
27061
|
+
const listed = await capability.list();
|
|
27062
|
+
if (!listed.ok)
|
|
27063
|
+
return listed;
|
|
27064
|
+
const activity = listed.value.find((entry) => entry.id === id);
|
|
27065
|
+
if (!activity)
|
|
27066
|
+
return fail("invalidRequest", "Native background activity was not found");
|
|
27067
|
+
let output = "";
|
|
27068
|
+
let truncated = false;
|
|
27069
|
+
if (activity.kind === "task" || activity.kind === "monitor") {
|
|
27070
|
+
const task = tasks.find((entry) => `task:${entry.task_id}` === id);
|
|
27071
|
+
output = task?.output ?? "";
|
|
27072
|
+
truncated = task?.truncated ?? false;
|
|
27073
|
+
} else if (activity.kind === "loop") {
|
|
27074
|
+
output = activity.label;
|
|
27075
|
+
} else {
|
|
27076
|
+
const snapshot = await options.readChild(id.slice("subagent:".length));
|
|
27077
|
+
if (!snapshot.ok)
|
|
27078
|
+
return snapshot;
|
|
27079
|
+
output = snapshot.value.turns.flatMap((turn) => turn.items.flatMap(({ item }) => {
|
|
27080
|
+
if (item.type === "agentMessage" || item.type === "reasoning")
|
|
27081
|
+
return [item.text];
|
|
27082
|
+
if (item.type === "commandExecution")
|
|
27083
|
+
return [`$ ${item.command}
|
|
27084
|
+
${item.output ?? ""}`];
|
|
27085
|
+
return [];
|
|
27086
|
+
})).join("\n\n");
|
|
27087
|
+
}
|
|
27088
|
+
if (output.length > options.outputLimit) {
|
|
27089
|
+
output = output.slice(0, options.outputLimit);
|
|
27090
|
+
truncated = true;
|
|
27091
|
+
}
|
|
27092
|
+
return { ok: true, value: { activity, output, truncated } };
|
|
27093
|
+
},
|
|
27094
|
+
async stop(id) {
|
|
27095
|
+
const listed = await capability.list();
|
|
27096
|
+
if (!listed.ok)
|
|
27097
|
+
return listed;
|
|
27098
|
+
const activity = listed.value.find((entry) => entry.id === id);
|
|
27099
|
+
if (!activity)
|
|
27100
|
+
return { ok: true, value: { outcome: "notFound" } };
|
|
27101
|
+
if (!activity.canStop)
|
|
27102
|
+
return fail("unsupported", "Native activity cannot be stopped through this interface");
|
|
27103
|
+
try {
|
|
27104
|
+
if (activity.kind === "loop" && options.deleteLoop) {
|
|
27105
|
+
const deleted = await options.deleteLoop(id.slice("loop:".length));
|
|
27106
|
+
const nativeId = id.slice("loop:".length);
|
|
27107
|
+
options.observedLoopIds.add(nativeId);
|
|
27108
|
+
options.loops.delete(nativeId);
|
|
27109
|
+
return { ok: true, value: { outcome: deleted ? "stopped" : "notFound" } };
|
|
27110
|
+
}
|
|
27111
|
+
if (options.killTask) {
|
|
27112
|
+
const result = await options.killTask(id.slice("task:".length));
|
|
27113
|
+
return {
|
|
27114
|
+
ok: true,
|
|
27115
|
+
value: {
|
|
27116
|
+
outcome: result === "killed" ? "stopped" : result === "already_exited" ? "alreadyStopped" : "notFound"
|
|
27117
|
+
}
|
|
27118
|
+
};
|
|
27119
|
+
}
|
|
27120
|
+
return fail("unsupported", "Native stop is unavailable");
|
|
27121
|
+
} catch (error53) {
|
|
27122
|
+
return fail("nativeFailure", error53 instanceof Error ? error53.message : "Grok activity stop failed");
|
|
27123
|
+
}
|
|
27124
|
+
}
|
|
27125
|
+
};
|
|
27126
|
+
return capability;
|
|
27127
|
+
}
|
|
27128
|
+
|
|
27129
|
+
// dist/grok-background-items.js
|
|
27130
|
+
import { open as open2 } from "node:fs/promises";
|
|
27131
|
+
import { StringDecoder } from "node:string_decoder";
|
|
27132
|
+
var POLL_INTERVAL_MS = 1e3;
|
|
27133
|
+
var READ_CHUNK_BYTES = 64 * 1024;
|
|
27134
|
+
var MAX_READ_BYTES_PER_TICK = 512 * 1024;
|
|
27135
|
+
var MAX_TOMBSTONES = 1e3;
|
|
27136
|
+
var GrokBackgroundItems = class {
|
|
27137
|
+
#byTaskId = /* @__PURE__ */ new Map();
|
|
27138
|
+
#byCallId = /* @__PURE__ */ new Map();
|
|
27139
|
+
#tombstones = /* @__PURE__ */ new Map();
|
|
27140
|
+
#tombstoneCallIds = /* @__PURE__ */ new Set();
|
|
27141
|
+
#emit;
|
|
27142
|
+
#outputLimit;
|
|
27143
|
+
constructor(options) {
|
|
27144
|
+
this.#emit = options.emit;
|
|
27145
|
+
this.#outputLimit = options.outputLimit;
|
|
27146
|
+
}
|
|
27147
|
+
running() {
|
|
27148
|
+
return [...this.#byTaskId.values()].filter((followed) => !followed.completed && !followed.outcome).map((followed) => followed.command);
|
|
27149
|
+
}
|
|
27150
|
+
taskIds() {
|
|
27151
|
+
return this.running().map((command) => command.taskId);
|
|
27152
|
+
}
|
|
27153
|
+
commandItemId(taskId) {
|
|
27154
|
+
return this.#byTaskId.get(taskId)?.command.item.itemId ?? this.#tombstones.get(taskId)?.itemId;
|
|
27155
|
+
}
|
|
27156
|
+
hasCallId(callId) {
|
|
27157
|
+
return this.#byCallId.has(callId) || this.#tombstoneCallIds.has(callId);
|
|
27158
|
+
}
|
|
27159
|
+
follow(command) {
|
|
27160
|
+
if (this.#tombstones.has(command.taskId) || this.#tombstoneCallIds.has(command.callId)) {
|
|
27161
|
+
return;
|
|
27162
|
+
}
|
|
27163
|
+
const existing = this.#byTaskId.get(command.taskId);
|
|
27164
|
+
if (existing?.completed)
|
|
27165
|
+
return;
|
|
27166
|
+
if (existing) {
|
|
27167
|
+
existing.command = command;
|
|
27168
|
+
this.#byCallId.set(command.callId, command.taskId);
|
|
27169
|
+
existing.outputFile ??= command.outputFile;
|
|
27170
|
+
if (existing.outputFile && !existing.timer && !existing.completed) {
|
|
27171
|
+
existing.timer = setInterval(() => void this.#poll(existing), POLL_INTERVAL_MS);
|
|
27172
|
+
existing.timer.unref();
|
|
27173
|
+
}
|
|
27174
|
+
return;
|
|
27175
|
+
}
|
|
27176
|
+
const followed = {
|
|
27177
|
+
command,
|
|
27178
|
+
outputFile: command.outputFile,
|
|
27179
|
+
offset: 0,
|
|
27180
|
+
decoder: new StringDecoder("utf8"),
|
|
27181
|
+
output: command.item.output ?? "",
|
|
27182
|
+
truncated: command.item.outputTruncated === true,
|
|
27183
|
+
timer: null,
|
|
27184
|
+
reading: Promise.resolve(),
|
|
27185
|
+
outcome: void 0,
|
|
27186
|
+
completed: false,
|
|
27187
|
+
exitCode: command.item.exitCode,
|
|
27188
|
+
fileOutput: "",
|
|
27189
|
+
nativeTruncated: false
|
|
27190
|
+
};
|
|
27191
|
+
this.#byTaskId.set(command.taskId, followed);
|
|
27192
|
+
this.#byCallId.set(command.callId, command.taskId);
|
|
27193
|
+
if (followed.outputFile) {
|
|
27194
|
+
followed.timer = setInterval(() => void this.#poll(followed), POLL_INTERVAL_MS);
|
|
27195
|
+
followed.timer.unref();
|
|
27196
|
+
}
|
|
27197
|
+
}
|
|
27198
|
+
replaceSnapshot(taskIdOrCallId, snapshotText) {
|
|
27199
|
+
const followed = this.#lookup(taskIdOrCallId);
|
|
27200
|
+
if (!followed || followed.completed || !snapshotText)
|
|
27201
|
+
return Boolean(followed);
|
|
27202
|
+
if (followed.outputFile) {
|
|
27203
|
+
return true;
|
|
27204
|
+
}
|
|
27205
|
+
this.#applySnapshot(followed, snapshotText);
|
|
27206
|
+
return true;
|
|
27207
|
+
}
|
|
27208
|
+
append(taskIdOrCallId, text) {
|
|
27209
|
+
const followed = this.#lookup(taskIdOrCallId);
|
|
27210
|
+
if (!followed || followed.completed || !text)
|
|
27211
|
+
return Boolean(followed);
|
|
27212
|
+
if (followed.outputFile) {
|
|
27213
|
+
return true;
|
|
27214
|
+
}
|
|
27215
|
+
this.#append(followed, text);
|
|
27216
|
+
return true;
|
|
27217
|
+
}
|
|
27218
|
+
settle(taskId, outcome, output, outputFile, exitCode, truncated) {
|
|
27219
|
+
const followed = this.#byTaskId.get(taskId);
|
|
27220
|
+
if (!followed) {
|
|
27221
|
+
if (this.#tombstones.has(taskId))
|
|
27222
|
+
return true;
|
|
27223
|
+
return false;
|
|
27224
|
+
}
|
|
27225
|
+
if (followed.outcome)
|
|
27226
|
+
return true;
|
|
27227
|
+
followed.outcome = outcome;
|
|
27228
|
+
followed.nativeTruncated ||= truncated === true;
|
|
27229
|
+
followed.outputFile ??= outputFile;
|
|
27230
|
+
if (exitCode !== void 0) {
|
|
27231
|
+
followed.exitCode = exitCode;
|
|
27232
|
+
}
|
|
27233
|
+
if (followed.timer)
|
|
27234
|
+
clearInterval(followed.timer);
|
|
27235
|
+
followed.timer = null;
|
|
27236
|
+
if (followed.outputFile) {
|
|
27237
|
+
void this.#poll(followed).then(() => this.#complete(followed, outcome));
|
|
27238
|
+
} else {
|
|
27239
|
+
if (output !== void 0 && output.length > 0) {
|
|
27240
|
+
this.#applySnapshot(followed, output);
|
|
27241
|
+
}
|
|
27242
|
+
this.#complete(followed, outcome);
|
|
27243
|
+
}
|
|
27244
|
+
return true;
|
|
27245
|
+
}
|
|
27246
|
+
abandonAll(reason) {
|
|
27247
|
+
for (const followed of this.#byTaskId.values()) {
|
|
27248
|
+
if (followed.timer) {
|
|
27249
|
+
clearInterval(followed.timer);
|
|
27250
|
+
followed.timer = null;
|
|
27251
|
+
}
|
|
27252
|
+
this.#complete(followed, followed.outcome ?? { status: "cancelled", reason });
|
|
27253
|
+
}
|
|
27254
|
+
this.#byTaskId.clear();
|
|
27255
|
+
this.#byCallId.clear();
|
|
27256
|
+
}
|
|
27257
|
+
#lookup(taskIdOrCallId) {
|
|
27258
|
+
return this.#byTaskId.get(taskIdOrCallId) ?? this.#byTaskId.get(this.#byCallId.get(taskIdOrCallId) ?? "");
|
|
27259
|
+
}
|
|
27260
|
+
#applySnapshot(followed, snapshotText) {
|
|
27261
|
+
if (followed.completed)
|
|
27262
|
+
return;
|
|
27263
|
+
if (snapshotText.startsWith(followed.output)) {
|
|
27264
|
+
const delta = snapshotText.slice(followed.output.length);
|
|
27265
|
+
if (delta.length > 0) {
|
|
27266
|
+
this.#append(followed, delta);
|
|
27267
|
+
}
|
|
27268
|
+
} else if (snapshotText !== followed.output) {
|
|
27269
|
+
const bounded2 = snapshotText.slice(0, this.#outputLimit);
|
|
27270
|
+
const wasTruncated = snapshotText.length > this.#outputLimit;
|
|
27271
|
+
followed.output = bounded2;
|
|
27272
|
+
followed.truncated ||= wasTruncated;
|
|
27273
|
+
followed.command = {
|
|
27274
|
+
...followed.command,
|
|
27275
|
+
item: {
|
|
27276
|
+
...followed.command.item,
|
|
27277
|
+
output: followed.output,
|
|
27278
|
+
outputTruncated: followed.truncated
|
|
27279
|
+
}
|
|
27280
|
+
};
|
|
27281
|
+
}
|
|
27282
|
+
}
|
|
27283
|
+
#append(followed, text) {
|
|
27284
|
+
if (followed.completed || text.length === 0)
|
|
27285
|
+
return;
|
|
27286
|
+
const remaining = Math.max(0, this.#outputLimit - followed.output.length);
|
|
27287
|
+
const chunk = remaining > 0 ? text.slice(0, remaining) : "";
|
|
27288
|
+
if (text.length > remaining)
|
|
27289
|
+
followed.truncated = true;
|
|
27290
|
+
if (!chunk)
|
|
27291
|
+
return;
|
|
27292
|
+
followed.output += chunk;
|
|
27293
|
+
followed.command = {
|
|
27294
|
+
...followed.command,
|
|
27295
|
+
item: {
|
|
27296
|
+
...followed.command.item,
|
|
27297
|
+
output: followed.output,
|
|
27298
|
+
outputTruncated: followed.truncated
|
|
27299
|
+
}
|
|
27300
|
+
};
|
|
27301
|
+
this.#emit({
|
|
27302
|
+
type: "item.updated",
|
|
27303
|
+
turnId: followed.command.turnId,
|
|
27304
|
+
itemId: followed.command.item.itemId,
|
|
27305
|
+
update: { type: "output.append", text: chunk }
|
|
27306
|
+
});
|
|
27307
|
+
}
|
|
27308
|
+
#complete(followed, outcome) {
|
|
27309
|
+
if (followed.completed)
|
|
27310
|
+
return;
|
|
27311
|
+
followed.completed = true;
|
|
27312
|
+
followed.outcome = outcome;
|
|
27313
|
+
if (followed.timer) {
|
|
27314
|
+
clearInterval(followed.timer);
|
|
27315
|
+
followed.timer = null;
|
|
27316
|
+
}
|
|
27317
|
+
const taskId = followed.command.taskId;
|
|
27318
|
+
const callId = followed.command.callId;
|
|
27319
|
+
this.#recordTombstone(taskId, callId, followed.command.item.itemId);
|
|
27320
|
+
this.#byTaskId.delete(taskId);
|
|
27321
|
+
this.#byCallId.delete(callId);
|
|
27322
|
+
const resolvedExitCode = followed.exitCode !== void 0 ? followed.exitCode : followed.command.item.exitCode;
|
|
27323
|
+
const item = {
|
|
27324
|
+
...followed.command.item,
|
|
27325
|
+
output: followed.output,
|
|
27326
|
+
outputTruncated: followed.truncated || followed.nativeTruncated,
|
|
27327
|
+
...resolvedExitCode !== void 0 ? { exitCode: resolvedExitCode } : {}
|
|
27328
|
+
};
|
|
27329
|
+
this.#emit({
|
|
27330
|
+
type: "item.completed",
|
|
27331
|
+
turnId: followed.command.turnId,
|
|
27332
|
+
snapshot: { item, outcome }
|
|
27333
|
+
});
|
|
27334
|
+
}
|
|
27335
|
+
#recordTombstone(taskId, callId, itemId) {
|
|
27336
|
+
if (this.#tombstones.size >= MAX_TOMBSTONES) {
|
|
27337
|
+
const oldestKey = this.#tombstones.keys().next().value;
|
|
27338
|
+
if (oldestKey !== void 0) {
|
|
27339
|
+
const oldest = this.#tombstones.get(oldestKey);
|
|
27340
|
+
if (oldest)
|
|
27341
|
+
this.#tombstoneCallIds.delete(oldest.callId);
|
|
27342
|
+
this.#tombstones.delete(oldestKey);
|
|
27343
|
+
}
|
|
27344
|
+
}
|
|
27345
|
+
this.#tombstones.set(taskId, { callId, itemId });
|
|
27346
|
+
this.#tombstoneCallIds.add(callId);
|
|
27347
|
+
}
|
|
27348
|
+
#poll(followed) {
|
|
27349
|
+
if (followed.completed || followed.truncated) {
|
|
27350
|
+
if (followed.timer) {
|
|
27351
|
+
clearInterval(followed.timer);
|
|
27352
|
+
followed.timer = null;
|
|
27353
|
+
}
|
|
27354
|
+
return followed.reading;
|
|
27355
|
+
}
|
|
27356
|
+
followed.reading = followed.reading.then(() => this.#read(followed));
|
|
27357
|
+
return followed.reading;
|
|
27358
|
+
}
|
|
27359
|
+
async #read(followed) {
|
|
27360
|
+
if (!followed.outputFile || followed.completed || followed.truncated)
|
|
27361
|
+
return;
|
|
27362
|
+
try {
|
|
27363
|
+
const handle = await open2(followed.outputFile, "r");
|
|
27364
|
+
try {
|
|
27365
|
+
let totalReadThisTick = 0;
|
|
27366
|
+
const buffer = Buffer.alloc(READ_CHUNK_BYTES);
|
|
27367
|
+
while (!followed.completed && !followed.truncated) {
|
|
27368
|
+
const toRead = Math.min(buffer.length, MAX_READ_BYTES_PER_TICK - totalReadThisTick);
|
|
27369
|
+
if (toRead <= 0)
|
|
27370
|
+
break;
|
|
27371
|
+
const { bytesRead } = await handle.read(buffer, 0, toRead, followed.offset);
|
|
27372
|
+
if (bytesRead === 0)
|
|
27373
|
+
break;
|
|
27374
|
+
followed.offset += bytesRead;
|
|
27375
|
+
totalReadThisTick += bytesRead;
|
|
27376
|
+
followed.fileOutput += followed.decoder.write(buffer.subarray(0, bytesRead));
|
|
27377
|
+
this.#applySnapshot(followed, followed.fileOutput);
|
|
27378
|
+
if (followed.fileOutput.length > this.#outputLimit) {
|
|
27379
|
+
followed.fileOutput = followed.fileOutput.slice(0, this.#outputLimit);
|
|
27380
|
+
followed.truncated = true;
|
|
27381
|
+
}
|
|
27382
|
+
if (totalReadThisTick >= MAX_READ_BYTES_PER_TICK)
|
|
27383
|
+
break;
|
|
27384
|
+
}
|
|
27385
|
+
} finally {
|
|
27386
|
+
await handle.close();
|
|
27387
|
+
}
|
|
27388
|
+
} catch (error53) {
|
|
27389
|
+
if (isRecord18(error53) && error53.code === "ENOENT")
|
|
27390
|
+
return;
|
|
27391
|
+
}
|
|
27392
|
+
}
|
|
27393
|
+
};
|
|
27394
|
+
function isRecord18(value) {
|
|
27395
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27396
|
+
}
|
|
27397
|
+
|
|
26511
27398
|
// dist/grok-models.js
|
|
26512
|
-
function
|
|
27399
|
+
function isRecord19(value) {
|
|
26513
27400
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26514
27401
|
}
|
|
26515
27402
|
function nonBlank(value) {
|
|
@@ -26521,7 +27408,7 @@ function thinkingOptions(value) {
|
|
|
26521
27408
|
const seen = /* @__PURE__ */ new Set();
|
|
26522
27409
|
const options = [];
|
|
26523
27410
|
for (const candidate of value) {
|
|
26524
|
-
if (!
|
|
27411
|
+
if (!isRecord19(candidate) || !nonBlank(candidate.label))
|
|
26525
27412
|
continue;
|
|
26526
27413
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
26527
27414
|
if (!id.success || seen.has(id.data))
|
|
@@ -26532,7 +27419,7 @@ function thinkingOptions(value) {
|
|
|
26532
27419
|
return options;
|
|
26533
27420
|
}
|
|
26534
27421
|
function parseGrokModelState(value) {
|
|
26535
|
-
if (!
|
|
27422
|
+
if (!isRecord19(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
26536
27423
|
return null;
|
|
26537
27424
|
}
|
|
26538
27425
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -26544,12 +27431,12 @@ function parseGrokModelState(value) {
|
|
|
26544
27431
|
const models = [];
|
|
26545
27432
|
let currentThinkingOptionId;
|
|
26546
27433
|
for (const candidate of value.availableModels) {
|
|
26547
|
-
if (!
|
|
27434
|
+
if (!isRecord19(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
26548
27435
|
continue;
|
|
26549
27436
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
26550
27437
|
if (!ref.success)
|
|
26551
27438
|
continue;
|
|
26552
|
-
const metadata =
|
|
27439
|
+
const metadata = isRecord19(candidate._meta) ? candidate._meta : {};
|
|
26553
27440
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
26554
27441
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
26555
27442
|
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
@@ -26588,10 +27475,10 @@ function parseGrokModelState(value) {
|
|
|
26588
27475
|
};
|
|
26589
27476
|
}
|
|
26590
27477
|
function modelStateFromInitialize(response) {
|
|
26591
|
-
return parseGrokModelState(
|
|
27478
|
+
return parseGrokModelState(isRecord19(response._meta) ? response._meta.modelState : void 0);
|
|
26592
27479
|
}
|
|
26593
27480
|
function modelStateFromSessionResponse(response) {
|
|
26594
|
-
return parseGrokModelState(
|
|
27481
|
+
return parseGrokModelState(isRecord19(response) ? response.models : void 0);
|
|
26595
27482
|
}
|
|
26596
27483
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
26597
27484
|
const selectedModel = model2;
|
|
@@ -26610,12 +27497,20 @@ function stateForGrokModel(modelState, nativeState, model2 = modelState.currentM
|
|
|
26610
27497
|
}
|
|
26611
27498
|
|
|
26612
27499
|
// dist/grok-credits.js
|
|
26613
|
-
import { readFile as
|
|
27500
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
26614
27501
|
import os7 from "node:os";
|
|
26615
|
-
import
|
|
27502
|
+
import path20 from "node:path";
|
|
26616
27503
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
27504
|
+
var GROK_SETTINGS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/settings";
|
|
26617
27505
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
26618
|
-
|
|
27506
|
+
var PLAN_TIMEOUT_MS = 2e3;
|
|
27507
|
+
function parseGrokPlan(value) {
|
|
27508
|
+
if (!isRecord20(value) || typeof value.subscription_tier_display !== "string")
|
|
27509
|
+
return void 0;
|
|
27510
|
+
const plan = value.subscription_tier_display.trim();
|
|
27511
|
+
return plan && plan.length <= 128 && !/[\u0000-\u001f\u007f]/u.test(plan) ? plan : void 0;
|
|
27512
|
+
}
|
|
27513
|
+
function isRecord20(value) {
|
|
26619
27514
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26620
27515
|
}
|
|
26621
27516
|
function finitePercent(value) {
|
|
@@ -26624,7 +27519,7 @@ function finitePercent(value) {
|
|
|
26624
27519
|
return Math.min(100, Math.max(0, value));
|
|
26625
27520
|
}
|
|
26626
27521
|
function nonNegativeCentValue(value) {
|
|
26627
|
-
if (!
|
|
27522
|
+
if (!isRecord20(value))
|
|
26628
27523
|
return void 0;
|
|
26629
27524
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
26630
27525
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -26632,7 +27527,7 @@ function nonNegativeCentValue(value) {
|
|
|
26632
27527
|
return amount;
|
|
26633
27528
|
}
|
|
26634
27529
|
function grokHome3(environment) {
|
|
26635
|
-
return environment.GROK_HOME ??
|
|
27530
|
+
return environment.GROK_HOME ?? path20.join(environment.HOME ?? environment.USERPROFILE ?? os7.homedir(), ".grok");
|
|
26636
27531
|
}
|
|
26637
27532
|
function periodTypeFrom(value) {
|
|
26638
27533
|
if (typeof value !== "string")
|
|
@@ -26648,7 +27543,7 @@ function productUsageFrom(value) {
|
|
|
26648
27543
|
if (!Array.isArray(value))
|
|
26649
27544
|
return void 0;
|
|
26650
27545
|
const products = value.flatMap((entry) => {
|
|
26651
|
-
if (!
|
|
27546
|
+
if (!isRecord20(entry) || typeof entry.product !== "string")
|
|
26652
27547
|
return [];
|
|
26653
27548
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
26654
27549
|
const labels = {
|
|
@@ -26669,10 +27564,10 @@ function productUsageFrom(value) {
|
|
|
26669
27564
|
return products.length > 0 ? products : void 0;
|
|
26670
27565
|
}
|
|
26671
27566
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
26672
|
-
if (!
|
|
27567
|
+
if (!isRecord20(value) || !isRecord20(value.config))
|
|
26673
27568
|
return null;
|
|
26674
27569
|
const config2 = value.config;
|
|
26675
|
-
const period =
|
|
27570
|
+
const period = isRecord20(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
26676
27571
|
const periodType = periodTypeFrom(period?.type);
|
|
26677
27572
|
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);
|
|
26678
27573
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -26699,11 +27594,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
26699
27594
|
};
|
|
26700
27595
|
}
|
|
26701
27596
|
function selectAccessToken(auth, now) {
|
|
26702
|
-
if (!
|
|
27597
|
+
if (!isRecord20(auth))
|
|
26703
27598
|
return null;
|
|
26704
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
27599
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord20(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")));
|
|
26705
27600
|
for (const [, value] of entries) {
|
|
26706
|
-
if (!
|
|
27601
|
+
if (!isRecord20(value) || typeof value.key !== "string")
|
|
26707
27602
|
continue;
|
|
26708
27603
|
if (typeof value.expires_at === "string") {
|
|
26709
27604
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -26724,26 +27619,30 @@ async function fetchGrokAccount(input = {}) {
|
|
|
26724
27619
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
|
|
26725
27620
|
return null;
|
|
26726
27621
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
26727
|
-
const authPath =
|
|
26728
|
-
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await
|
|
27622
|
+
const authPath = path20.join(grokHome3(environment), "auth.json");
|
|
27623
|
+
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile8(authPath, "utf8");
|
|
26729
27624
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
26730
27625
|
if (!token)
|
|
26731
27626
|
return null;
|
|
26732
27627
|
const fetchImpl = input.fetch ?? fetch;
|
|
26733
|
-
const
|
|
27628
|
+
const request = (url2, timeoutMs) => fetchImpl(url2, {
|
|
26734
27629
|
method: "GET",
|
|
26735
27630
|
headers: {
|
|
26736
27631
|
Authorization: `Bearer ${token.key}`,
|
|
26737
27632
|
"x-xai-token-auth": "xai-grok-cli",
|
|
26738
27633
|
Accept: "application/json"
|
|
26739
27634
|
},
|
|
26740
|
-
signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(
|
|
27635
|
+
signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs)
|
|
26741
27636
|
});
|
|
27637
|
+
const credits = request(GROK_CREDITS_ENDPOINT, REQUEST_TIMEOUT_MS);
|
|
27638
|
+
const plan = input.includePlan === false ? Promise.resolve(void 0) : request(GROK_SETTINGS_ENDPOINT, input.planTimeoutMs ?? PLAN_TIMEOUT_MS).then(async (response2) => response2.ok ? parseGrokPlan(await response2.json()) : void 0).catch(() => void 0);
|
|
27639
|
+
const response = await credits;
|
|
26742
27640
|
if (!response.ok)
|
|
26743
27641
|
return null;
|
|
26744
27642
|
const snapshot = parseGrokCreditsResponse(await response.json(), now.toISOString());
|
|
26745
27643
|
if (!snapshot)
|
|
26746
27644
|
return null;
|
|
27645
|
+
const planName = await plan;
|
|
26747
27646
|
return {
|
|
26748
27647
|
credits: {
|
|
26749
27648
|
usedPercent: snapshot.usedPercent,
|
|
@@ -26752,14 +27651,15 @@ async function fetchGrokAccount(input = {}) {
|
|
|
26752
27651
|
...snapshot.productUsage ? { productUsage: [...snapshot.productUsage] } : {}
|
|
26753
27652
|
},
|
|
26754
27653
|
...token.email ? { email: token.email } : {},
|
|
26755
|
-
...token.label ? { label: token.label } : {}
|
|
27654
|
+
...token.label ? { label: token.label } : {},
|
|
27655
|
+
...planName ? { plan: planName } : {}
|
|
26756
27656
|
};
|
|
26757
27657
|
} catch {
|
|
26758
27658
|
return null;
|
|
26759
27659
|
}
|
|
26760
27660
|
}
|
|
26761
27661
|
async function fetchGrokCredits(input = {}) {
|
|
26762
|
-
const account = await fetchGrokAccount(input);
|
|
27662
|
+
const account = await fetchGrokAccount({ ...input, includePlan: false });
|
|
26763
27663
|
if (!account?.credits)
|
|
26764
27664
|
return null;
|
|
26765
27665
|
const { credits } = account;
|
|
@@ -26774,7 +27674,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
26774
27674
|
|
|
26775
27675
|
// dist/grok-usage.js
|
|
26776
27676
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
26777
|
-
function
|
|
27677
|
+
function isRecord21(value) {
|
|
26778
27678
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26779
27679
|
}
|
|
26780
27680
|
function optionalToken(value) {
|
|
@@ -26791,7 +27691,7 @@ function combineUsage(base, next) {
|
|
|
26791
27691
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
26792
27692
|
}
|
|
26793
27693
|
function usageFromNative(value) {
|
|
26794
|
-
if (!
|
|
27694
|
+
if (!isRecord21(value))
|
|
26795
27695
|
return null;
|
|
26796
27696
|
const inputTokens = optionalToken(value.inputTokens);
|
|
26797
27697
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -26815,7 +27715,7 @@ function usageFromNative(value) {
|
|
|
26815
27715
|
}
|
|
26816
27716
|
}
|
|
26817
27717
|
function usageFromResponse(value) {
|
|
26818
|
-
if (!
|
|
27718
|
+
if (!isRecord21(value))
|
|
26819
27719
|
return null;
|
|
26820
27720
|
const buckets = [
|
|
26821
27721
|
value.input_tokens,
|
|
@@ -26915,7 +27815,7 @@ var GrokTurnUsage = class {
|
|
|
26915
27815
|
}
|
|
26916
27816
|
};
|
|
26917
27817
|
function usageFromSignals(value) {
|
|
26918
|
-
if (!
|
|
27818
|
+
if (!isRecord21(value))
|
|
26919
27819
|
return null;
|
|
26920
27820
|
try {
|
|
26921
27821
|
return parseHostUsage({
|
|
@@ -26935,7 +27835,7 @@ var summedUsageFields = [
|
|
|
26935
27835
|
"totalTokens"
|
|
26936
27836
|
];
|
|
26937
27837
|
function nativeCostTicks(value) {
|
|
26938
|
-
if (!
|
|
27838
|
+
if (!isRecord21(value))
|
|
26939
27839
|
return void 0;
|
|
26940
27840
|
const ticks = value.costUsdTicks;
|
|
26941
27841
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -26943,7 +27843,7 @@ function nativeCostTicks(value) {
|
|
|
26943
27843
|
return ticks;
|
|
26944
27844
|
}
|
|
26945
27845
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
26946
|
-
if (!
|
|
27846
|
+
if (!isRecord21(value))
|
|
26947
27847
|
return void 0;
|
|
26948
27848
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
26949
27849
|
return void 0;
|
|
@@ -26974,7 +27874,7 @@ function sessionUsageFromHistory(events) {
|
|
|
26974
27874
|
continue;
|
|
26975
27875
|
const usage = usageFromNative(event.usage);
|
|
26976
27876
|
const ticks2 = nativeCostTicks(event.usage);
|
|
26977
|
-
const complete =
|
|
27877
|
+
const complete = isRecord21(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
26978
27878
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
26979
27879
|
}
|
|
26980
27880
|
if (latestByKey.size === 0)
|
|
@@ -27028,7 +27928,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
27028
27928
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
27029
27929
|
try {
|
|
27030
27930
|
if (update?.sessionUpdate === "usage_update") {
|
|
27031
|
-
const cost =
|
|
27931
|
+
const cost = isRecord21(update.cost) ? update.cost : null;
|
|
27032
27932
|
return parseHostUsage({
|
|
27033
27933
|
contextUsedTokens: update.used,
|
|
27034
27934
|
contextWindowTokens: update.size,
|
|
@@ -27161,6 +28061,14 @@ var GrokHarnessSession = class {
|
|
|
27161
28061
|
#costRequest = 0;
|
|
27162
28062
|
#historyLength;
|
|
27163
28063
|
#goalHelpers = [];
|
|
28064
|
+
backgroundActivity;
|
|
28065
|
+
#nativeTasksRunning = false;
|
|
28066
|
+
#backgroundItems;
|
|
28067
|
+
#loops;
|
|
28068
|
+
#observedLoopIds = /* @__PURE__ */ new Set();
|
|
28069
|
+
#activityChildren = /* @__PURE__ */ new Map();
|
|
28070
|
+
#earlyBackground = /* @__PURE__ */ new Map();
|
|
28071
|
+
#pendingBackground = /* @__PURE__ */ new Map();
|
|
27164
28072
|
constructor(cwd, transport, opened, modelState, onClosed, options) {
|
|
27165
28073
|
this.#cwd = cwd;
|
|
27166
28074
|
this.#historyLength = options.history.length;
|
|
@@ -27173,12 +28081,44 @@ var GrokHarnessSession = class {
|
|
|
27173
28081
|
this.#closeTimeoutMs = options.closeTimeoutMs;
|
|
27174
28082
|
this.#randomUUID = options.randomUUID;
|
|
27175
28083
|
this.#toolOutputLimit = options.toolOutputLimit;
|
|
28084
|
+
this.#backgroundItems = new GrokBackgroundItems({
|
|
28085
|
+
outputLimit: options.toolOutputLimit,
|
|
28086
|
+
emit: (event) => this.#event(event)
|
|
28087
|
+
});
|
|
28088
|
+
this.#loops = collectGrokScheduledLoops(options.history);
|
|
28089
|
+
for (const event of options.history)
|
|
28090
|
+
this.#observeActivityChild(event);
|
|
28091
|
+
this.backgroundActivity = createGrokActivity({
|
|
28092
|
+
sessionId: opened.sessionId,
|
|
28093
|
+
directory: options.sessionDirectory,
|
|
28094
|
+
loops: this.#loops,
|
|
28095
|
+
observedLoopIds: this.#observedLoopIds,
|
|
28096
|
+
children: this.#activityChildren,
|
|
28097
|
+
outputLimit: options.toolOutputLimit,
|
|
28098
|
+
commandItemId: (taskId) => this.#backgroundItems.commandItemId(taskId),
|
|
28099
|
+
observeTasks: (tasks) => {
|
|
28100
|
+
this.#nativeTasksRunning = tasks.some((task) => !task.completed);
|
|
28101
|
+
for (const task of tasks)
|
|
28102
|
+
if (task.completed)
|
|
28103
|
+
this.#backgroundItems.settle(task.task_id, grokBackgroundCompletionOutcome({
|
|
28104
|
+
...task.exit_code !== void 0 ? { exitCode: task.exit_code } : {},
|
|
28105
|
+
...task.signal ? { signal: task.signal } : {},
|
|
28106
|
+
...task.explicitly_killed ? { explicitlyKilled: true } : {}
|
|
28107
|
+
}), task.output, void 0, task.exit_code, task.truncated);
|
|
28108
|
+
},
|
|
28109
|
+
readChild: options.readChild,
|
|
28110
|
+
isOpen: () => this.#phase === "open",
|
|
28111
|
+
...transport.getSubagent ? { getChild: transport.getSubagent.bind(transport) } : {},
|
|
28112
|
+
...transport.listTasks ? { listTasks: transport.listTasks.bind(transport) } : {},
|
|
28113
|
+
...transport.killTask ? { killTask: transport.killTask.bind(transport) } : {},
|
|
28114
|
+
...transport.deleteScheduledTask ? { deleteLoop: transport.deleteScheduledTask.bind(transport) } : {}
|
|
28115
|
+
});
|
|
27176
28116
|
this.initialUsage = options.initialUsage ?? null;
|
|
27177
28117
|
this.#usage = this.initialUsage;
|
|
27178
28118
|
this.#initialCostUsd = this.initialUsage?.totalCostUsd ?? 0;
|
|
27179
28119
|
this.capabilities = ((session) => ({
|
|
27180
28120
|
...capabilitiesForModels(modelState),
|
|
27181
|
-
...transport.
|
|
28121
|
+
...transport.observeBackground ? { autonomousTurns: { observe: true } } : {},
|
|
27182
28122
|
get steer() {
|
|
27183
28123
|
return session.#canSteerActiveTurn();
|
|
27184
28124
|
}
|
|
@@ -27241,12 +28181,19 @@ var GrokHarnessSession = class {
|
|
|
27241
28181
|
return goalControl(prompt);
|
|
27242
28182
|
}, (goal) => this.#event({ type: "goal.changed", goal }), 3e4, () => transport.getHistory());
|
|
27243
28183
|
this.goals = goals;
|
|
28184
|
+
}
|
|
28185
|
+
if (transport.observeBackground) {
|
|
28186
|
+
const goals = this.goals;
|
|
27244
28187
|
transport.observeBackground({
|
|
27245
28188
|
onEvent: (event) => {
|
|
27246
28189
|
if (event.type === "goal.changed") {
|
|
28190
|
+
if (!goals)
|
|
28191
|
+
return;
|
|
27247
28192
|
void goals.observe(event.update).catch((error53) => this.handleTransportFault(new GrokTransportError("protocolError", String(error53))));
|
|
27248
28193
|
return;
|
|
27249
28194
|
}
|
|
28195
|
+
if (this.#applyBackgroundLifecycle(event))
|
|
28196
|
+
return;
|
|
27250
28197
|
this.#backgroundQueue = this.#backgroundQueue.then(() => this.#backgroundEvent(event)).catch((error53) => this.handleTransportFault(new GrokTransportError("protocolError", String(error53))));
|
|
27251
28198
|
},
|
|
27252
28199
|
onPermission: async (request) => {
|
|
@@ -27262,7 +28209,7 @@ var GrokHarnessSession = class {
|
|
|
27262
28209
|
return this.#active ? this.#active.questions.ask(request) : { outcome: "cancelled" };
|
|
27263
28210
|
}
|
|
27264
28211
|
});
|
|
27265
|
-
void
|
|
28212
|
+
void goals?.read();
|
|
27266
28213
|
}
|
|
27267
28214
|
}
|
|
27268
28215
|
async questionActivity(interactionId) {
|
|
@@ -27420,8 +28367,7 @@ var GrokHarnessSession = class {
|
|
|
27420
28367
|
usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
|
|
27421
28368
|
agent: null,
|
|
27422
28369
|
agentMessageId: null,
|
|
27423
|
-
|
|
27424
|
-
projectedAgentText: "",
|
|
28370
|
+
agentMedia: null,
|
|
27425
28371
|
reasoning: null,
|
|
27426
28372
|
reasoningMessageId: null,
|
|
27427
28373
|
compactionItem: null,
|
|
@@ -27443,7 +28389,147 @@ var GrokHarnessSession = class {
|
|
|
27443
28389
|
return active;
|
|
27444
28390
|
}
|
|
27445
28391
|
hasBackgroundWork() {
|
|
27446
|
-
return this.goals?.active === true;
|
|
28392
|
+
return this.goals?.active === true || this.#backgroundItems.taskIds().length > 0 || this.#nativeTasksRunning || this.#loops.size > 0 || this.#pendingBackground.size > 0 || [...this.#activityChildren.values()].some((child) => child.status === "running" || child.status === "pending");
|
|
28393
|
+
}
|
|
28394
|
+
async stopBackgroundWork() {
|
|
28395
|
+
const listed = await this.backgroundActivity.list();
|
|
28396
|
+
if (!listed.ok)
|
|
28397
|
+
return listed;
|
|
28398
|
+
const ids = [
|
|
28399
|
+
.../* @__PURE__ */ new Set([
|
|
28400
|
+
...this.#backgroundItems.taskIds(),
|
|
28401
|
+
...listed.value.filter((entry) => (entry.kind === "task" || entry.kind === "monitor") && entry.status === "running").map((entry) => entry.id.slice("task:".length))
|
|
28402
|
+
])
|
|
28403
|
+
];
|
|
28404
|
+
if (ids.length === 0)
|
|
28405
|
+
return { ok: true, value: void 0 };
|
|
28406
|
+
const kill = this.#transport.killTask?.bind(this.#transport);
|
|
28407
|
+
if (!kill) {
|
|
28408
|
+
return {
|
|
28409
|
+
ok: false,
|
|
28410
|
+
error: {
|
|
28411
|
+
code: "unsupported",
|
|
28412
|
+
message: "Grok cannot stop background tasks on this transport",
|
|
28413
|
+
retryable: false
|
|
28414
|
+
}
|
|
28415
|
+
};
|
|
28416
|
+
}
|
|
28417
|
+
try {
|
|
28418
|
+
await Promise.all(ids.map((taskId) => kill(taskId, "teardown")));
|
|
28419
|
+
return { ok: true, value: void 0 };
|
|
28420
|
+
} catch (error53) {
|
|
28421
|
+
return { ok: false, error: normalizeError(error53, "nativeFailure") };
|
|
28422
|
+
}
|
|
28423
|
+
}
|
|
28424
|
+
#observeActivityChild(event) {
|
|
28425
|
+
if (event.type === "subagent.spawned") {
|
|
28426
|
+
this.#activityChildren.set(event.nativeSubagentId, {
|
|
28427
|
+
subagentId: event.nativeSubagentId,
|
|
28428
|
+
nativeSubagentId: event.nativeSubagentId,
|
|
28429
|
+
description: event.description ?? "Grok Subagent",
|
|
28430
|
+
background: true,
|
|
28431
|
+
status: "running",
|
|
28432
|
+
...event.role ? { role: event.role } : {},
|
|
28433
|
+
...event.model ? { model: event.model } : {}
|
|
28434
|
+
});
|
|
28435
|
+
}
|
|
28436
|
+
if (event.type === "subagent.finished") {
|
|
28437
|
+
const child = this.#activityChildren.get(event.nativeSubagentId);
|
|
28438
|
+
if (child)
|
|
28439
|
+
this.#activityChildren.set(event.nativeSubagentId, {
|
|
28440
|
+
...child,
|
|
28441
|
+
status: event.status,
|
|
28442
|
+
...event.resultSummary ? { resultSummary: event.resultSummary } : {}
|
|
28443
|
+
});
|
|
28444
|
+
}
|
|
28445
|
+
}
|
|
28446
|
+
#applyBackgroundLifecycle(event) {
|
|
28447
|
+
this.#observeActivityChild(event);
|
|
28448
|
+
if (event.type === "task.backgrounded") {
|
|
28449
|
+
this.#nativeTasksRunning = true;
|
|
28450
|
+
this.#acceptBackgrounded(event);
|
|
28451
|
+
return true;
|
|
28452
|
+
}
|
|
28453
|
+
if (event.type === "task.completed") {
|
|
28454
|
+
const outcome = grokBackgroundCompletionOutcome(event);
|
|
28455
|
+
this.#backgroundItems.settle(event.taskId, outcome, event.output, event.outputFile, event.exitCode, event.truncated);
|
|
28456
|
+
void this.backgroundActivity.list();
|
|
28457
|
+
return true;
|
|
28458
|
+
}
|
|
28459
|
+
if (event.type === "monitor.event") {
|
|
28460
|
+
this.#backgroundItems.append(event.taskId, event.text.endsWith("\n") ? event.text : `${event.text}
|
|
28461
|
+
`);
|
|
28462
|
+
return true;
|
|
28463
|
+
}
|
|
28464
|
+
if (event.type === "scheduled.created" || event.type === "scheduled.fired" || event.type === "scheduled.deleted") {
|
|
28465
|
+
if (event.type === "scheduled.fired" && event.subagentId && !this.#activityChildren.has(event.subagentId))
|
|
28466
|
+
this.#activityChildren.set(event.subagentId, {
|
|
28467
|
+
subagentId: event.subagentId,
|
|
28468
|
+
nativeSubagentId: event.subagentId,
|
|
28469
|
+
description: event.prompt,
|
|
28470
|
+
background: true,
|
|
28471
|
+
status: "running"
|
|
28472
|
+
});
|
|
28473
|
+
applyGrokScheduledEvent(this.#loops, event, this.#observedLoopIds);
|
|
28474
|
+
return true;
|
|
28475
|
+
}
|
|
28476
|
+
return false;
|
|
28477
|
+
}
|
|
28478
|
+
#holdBackgroundCommand(active, callId, item, rawOutput) {
|
|
28479
|
+
active.tools.delete(callId);
|
|
28480
|
+
this.#event({ type: "item.detached", turnId: active.command.turnId, itemId: item.itemId });
|
|
28481
|
+
const taskId = grokBackgroundTaskId(rawOutput);
|
|
28482
|
+
const held = { turnId: active.command.turnId, item };
|
|
28483
|
+
if (taskId) {
|
|
28484
|
+
this.#followBackground(callId, held, {
|
|
28485
|
+
taskId,
|
|
28486
|
+
kind: "run",
|
|
28487
|
+
description: item.command
|
|
28488
|
+
});
|
|
28489
|
+
return;
|
|
28490
|
+
}
|
|
28491
|
+
const early = this.#earlyBackground.get(callId);
|
|
28492
|
+
if (early) {
|
|
28493
|
+
this.#earlyBackground.delete(callId);
|
|
28494
|
+
this.#followBackground(callId, held, early);
|
|
28495
|
+
} else
|
|
28496
|
+
this.#pendingBackground.set(callId, held);
|
|
28497
|
+
}
|
|
28498
|
+
#acceptBackgrounded(event) {
|
|
28499
|
+
const active = this.#active;
|
|
28500
|
+
const tool = active?.tools.get(event.toolCallId);
|
|
28501
|
+
if (tool?.item.type === "commandExecution" && active) {
|
|
28502
|
+
active.tools.delete(event.toolCallId);
|
|
28503
|
+
this.#event({
|
|
28504
|
+
type: "item.detached",
|
|
28505
|
+
turnId: active.command.turnId,
|
|
28506
|
+
itemId: tool.item.itemId
|
|
28507
|
+
});
|
|
28508
|
+
this.#followBackground(event.toolCallId, { turnId: active.command.turnId, item: tool.item }, event);
|
|
28509
|
+
return;
|
|
28510
|
+
}
|
|
28511
|
+
const pending = this.#pendingBackground.get(event.toolCallId);
|
|
28512
|
+
if (pending)
|
|
28513
|
+
this.#followBackground(event.toolCallId, pending, event);
|
|
28514
|
+
else if (!this.#backgroundItems.hasCallId(event.toolCallId))
|
|
28515
|
+
this.#earlyBackground.set(event.toolCallId, event);
|
|
28516
|
+
else {
|
|
28517
|
+
const running = this.#backgroundItems.running().find((r) => r.callId === event.toolCallId);
|
|
28518
|
+
if (running)
|
|
28519
|
+
this.#followBackground(event.toolCallId, running, event);
|
|
28520
|
+
}
|
|
28521
|
+
}
|
|
28522
|
+
#followBackground(callId, held, event) {
|
|
28523
|
+
this.#pendingBackground.delete(callId);
|
|
28524
|
+
this.#backgroundItems.follow({
|
|
28525
|
+
turnId: held.turnId,
|
|
28526
|
+
callId,
|
|
28527
|
+
taskId: event.taskId,
|
|
28528
|
+
item: held.item,
|
|
28529
|
+
kind: event.kind,
|
|
28530
|
+
description: event.description ?? event.command ?? held.item.command,
|
|
28531
|
+
...event.outputFile ? { outputFile: event.outputFile } : {}
|
|
28532
|
+
});
|
|
27447
28533
|
}
|
|
27448
28534
|
async #backgroundEvent(event) {
|
|
27449
28535
|
await this.#goalCommand;
|
|
@@ -27509,6 +28595,23 @@ var GrokHarnessSession = class {
|
|
|
27509
28595
|
async #executeHarnessCommand(command) {
|
|
27510
28596
|
if (this.#phase !== "open")
|
|
27511
28597
|
return { ok: false, error: invalidState("Grok Session is not open") };
|
|
28598
|
+
if (command.commandId === "grok.loop") {
|
|
28599
|
+
if (command.arguments && (Object.keys(command.arguments).some((key) => key !== "text") || command.arguments.text !== void 0 && typeof command.arguments.text !== "string"))
|
|
28600
|
+
return {
|
|
28601
|
+
ok: false,
|
|
28602
|
+
error: {
|
|
28603
|
+
code: "invalidRequest",
|
|
28604
|
+
message: "Grok loop accepts a text argument",
|
|
28605
|
+
retryable: false
|
|
28606
|
+
}
|
|
28607
|
+
};
|
|
28608
|
+
const text = String(command.arguments?.text ?? "").trim();
|
|
28609
|
+
return this.#startTurn({
|
|
28610
|
+
type: "turn.start",
|
|
28611
|
+
turnId: command.turnId,
|
|
28612
|
+
input: [{ type: "text", text: text ? `/loop ${text}` : "/loop" }]
|
|
28613
|
+
}, true);
|
|
28614
|
+
}
|
|
27512
28615
|
if (command.commandId === "grok.goal" || command.commandId === "grok.desktop-goal") {
|
|
27513
28616
|
const prompt = grokGoalPrompt(command.arguments);
|
|
27514
28617
|
if (!prompt.ok)
|
|
@@ -27644,8 +28747,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
27644
28747
|
textIdentity: { turnIndex: this.#snapshot.turns.length, agentMessage: 0, reasoning: 0 },
|
|
27645
28748
|
agent: null,
|
|
27646
28749
|
agentMessageId: null,
|
|
27647
|
-
|
|
27648
|
-
projectedAgentText: "",
|
|
28750
|
+
agentMedia: null,
|
|
27649
28751
|
reasoning: null,
|
|
27650
28752
|
reasoningMessageId: null,
|
|
27651
28753
|
compactionItem: null,
|
|
@@ -27981,6 +29083,8 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
27981
29083
|
const contextUsage = usageFromUpdate(event.type === "usage" ? event.update : void 0, event.metadata, this.#state.effectiveModel ? this.#modelState.contextWindowTokensByModel.get(this.#state.effectiveModel.id) : void 0);
|
|
27982
29084
|
if (contextUsage)
|
|
27983
29085
|
this.#publishUsage(contextUsage, active.command.turnId);
|
|
29086
|
+
if (this.#applyBackgroundLifecycle(event))
|
|
29087
|
+
return;
|
|
27984
29088
|
if (event.type === "agent.text")
|
|
27985
29089
|
this.#appendAgent(active, event.text, event.messageId);
|
|
27986
29090
|
else if (event.type === "agent.thought")
|
|
@@ -28075,19 +29179,16 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28075
29179
|
itemId: grokTextItemId(this.#transport.sessionId, active.textIdentity.turnIndex, "agentMessage", ++active.textIdentity.agentMessage),
|
|
28076
29180
|
text: ""
|
|
28077
29181
|
};
|
|
28078
|
-
active.
|
|
28079
|
-
active.projectedAgentText = "";
|
|
29182
|
+
active.agentMedia = new LocalMediaMarkdownStream(this.#mediaRoots);
|
|
28080
29183
|
this.#event({ type: "item.started", turnId: active.command.turnId, item: active.agent });
|
|
28081
29184
|
}
|
|
28082
|
-
active.
|
|
28083
|
-
|
|
28084
|
-
|
|
28085
|
-
|
|
28086
|
-
|
|
28087
|
-
if (delta.length === 0)
|
|
29185
|
+
const delta = active.agentMedia?.append(text) ?? "";
|
|
29186
|
+
this.#publishAgent(active, delta);
|
|
29187
|
+
}
|
|
29188
|
+
#publishAgent(active, delta) {
|
|
29189
|
+
if (!active.agent || !active.agentMedia || !delta)
|
|
28088
29190
|
return;
|
|
28089
|
-
active.
|
|
28090
|
-
active.agent = { ...active.agent, text: active.projectedAgentText };
|
|
29191
|
+
active.agent = { ...active.agent, text: active.agentMedia.text };
|
|
28091
29192
|
this.#event({
|
|
28092
29193
|
type: "item.updated",
|
|
28093
29194
|
turnId: active.command.turnId,
|
|
@@ -28162,9 +29263,16 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28162
29263
|
active.tools.set(event.callId, {
|
|
28163
29264
|
item,
|
|
28164
29265
|
...event.status ? { status: event.status } : {},
|
|
28165
|
-
...generatedImage ? { generatedImage } : {}
|
|
29266
|
+
...generatedImage ? { generatedImage } : {},
|
|
29267
|
+
...event.rawInput !== void 0 ? { rawInput: event.rawInput } : {}
|
|
28166
29268
|
});
|
|
28167
29269
|
this.#event({ type: "item.started", turnId: active.command.turnId, item });
|
|
29270
|
+
const background = this.#earlyBackground.get(event.callId);
|
|
29271
|
+
if (background) {
|
|
29272
|
+
this.#earlyBackground.delete(event.callId);
|
|
29273
|
+
this.#acceptBackgrounded(background);
|
|
29274
|
+
return;
|
|
29275
|
+
}
|
|
28168
29276
|
if (event.status === "completed" || event.status === "failed") {
|
|
28169
29277
|
this.#completeTool(active, event.callId, event.status, event.content, event.rawOutput);
|
|
28170
29278
|
}
|
|
@@ -28198,6 +29306,13 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28198
29306
|
});
|
|
28199
29307
|
return;
|
|
28200
29308
|
}
|
|
29309
|
+
if (this.#backgroundItems.hasCallId(event.callId) || this.#pendingBackground.has(event.callId)) {
|
|
29310
|
+
const projection2 = projectGrokToolOutput(event.content, event.rawOutput, this.#toolOutputLimit);
|
|
29311
|
+
const text = projection2.output?.content.flatMap((entry) => entry.type === "text" ? [entry.text] : []).join("") ?? "";
|
|
29312
|
+
if (text)
|
|
29313
|
+
this.#backgroundItems.replaceSnapshot(event.callId, text);
|
|
29314
|
+
return;
|
|
29315
|
+
}
|
|
28201
29316
|
const tool = active.tools.get(event.callId);
|
|
28202
29317
|
if (!tool)
|
|
28203
29318
|
return;
|
|
@@ -28240,11 +29355,15 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28240
29355
|
const tool = active.tools.get(callId);
|
|
28241
29356
|
if (!tool)
|
|
28242
29357
|
return;
|
|
28243
|
-
active.tools.delete(callId);
|
|
28244
29358
|
const projection = projectGrokToolOutput(content, rawOutput, this.#toolOutputLimit);
|
|
28245
29359
|
if (hasGrokToolProjection(projection)) {
|
|
28246
29360
|
tool.item = applyGrokToolProjection(tool.item, projection);
|
|
28247
29361
|
}
|
|
29362
|
+
if (tool.item.type === "commandExecution" && status2 !== "failed" && grokToolIsBackgrounded(rawOutput, tool.rawInput)) {
|
|
29363
|
+
this.#holdBackgroundCommand(active, callId, tool.item, rawOutput);
|
|
29364
|
+
return;
|
|
29365
|
+
}
|
|
29366
|
+
active.tools.delete(callId);
|
|
28248
29367
|
const outcome = status2 === "failed" ? {
|
|
28249
29368
|
status: "failed",
|
|
28250
29369
|
error: {
|
|
@@ -28348,25 +29467,12 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28348
29467
|
}
|
|
28349
29468
|
#completeAgent(active, outcome) {
|
|
28350
29469
|
const item = active.agent;
|
|
28351
|
-
if (item && active.
|
|
28352
|
-
|
|
28353
|
-
const delta = flushed.startsWith(item.text) ? flushed.slice(item.text.length) : "";
|
|
28354
|
-
if (delta.length > 0) {
|
|
28355
|
-
active.projectedAgentText = flushed;
|
|
28356
|
-
active.agent = { ...item, text: flushed };
|
|
28357
|
-
this.#event({
|
|
28358
|
-
type: "item.updated",
|
|
28359
|
-
turnId: active.command.turnId,
|
|
28360
|
-
itemId: item.itemId,
|
|
28361
|
-
update: { type: "text.append", text: delta }
|
|
28362
|
-
});
|
|
28363
|
-
}
|
|
28364
|
-
}
|
|
29470
|
+
if (item && active.agentMedia)
|
|
29471
|
+
this.#publishAgent(active, active.agentMedia.flush());
|
|
28365
29472
|
const completed = active.agent ?? item;
|
|
28366
29473
|
active.agent = null;
|
|
28367
29474
|
active.agentMessageId = null;
|
|
28368
|
-
active.
|
|
28369
|
-
active.projectedAgentText = "";
|
|
29475
|
+
active.agentMedia = null;
|
|
28370
29476
|
if (completed)
|
|
28371
29477
|
this.#completeItem(active, completed, outcome);
|
|
28372
29478
|
}
|
|
@@ -28446,8 +29552,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28446
29552
|
update: { type: "text.append", text: delta }
|
|
28447
29553
|
});
|
|
28448
29554
|
active.agent = { ...pendingMessage, text };
|
|
28449
|
-
active.
|
|
28450
|
-
active.projectedAgentText = text;
|
|
29555
|
+
active.agentMedia = null;
|
|
28451
29556
|
}
|
|
28452
29557
|
this.#completeReasoning(active, itemOutcome);
|
|
28453
29558
|
this.#completeAgent(active, itemOutcome);
|
|
@@ -28456,8 +29561,11 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28456
29561
|
this.#completeItem(active, active.compactionItem, itemOutcome);
|
|
28457
29562
|
active.compactionItem = null;
|
|
28458
29563
|
}
|
|
28459
|
-
for (const tool of active.tools
|
|
29564
|
+
for (const [callId, tool] of active.tools) {
|
|
29565
|
+
if (this.#pendingBackground.has(callId) || this.#backgroundItems.hasCallId(callId))
|
|
29566
|
+
continue;
|
|
28460
29567
|
this.#completeItem(active, tool.item, itemOutcome);
|
|
29568
|
+
}
|
|
28461
29569
|
active.tools.clear();
|
|
28462
29570
|
for (const item of persistedMessages) {
|
|
28463
29571
|
if (item.itemId === pendingId)
|
|
@@ -28511,6 +29619,9 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28511
29619
|
return;
|
|
28512
29620
|
this.#phase = "closing";
|
|
28513
29621
|
this.goals?.close();
|
|
29622
|
+
this.#backgroundItems.abandonAll("Grok Session closed");
|
|
29623
|
+
this.#pendingBackground.clear();
|
|
29624
|
+
this.#loops.clear();
|
|
28514
29625
|
const active = this.#active;
|
|
28515
29626
|
if (active) {
|
|
28516
29627
|
active.cancellationRequested = true;
|
|
@@ -28538,6 +29649,9 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
|
|
|
28538
29649
|
return;
|
|
28539
29650
|
const normalized = normalizeError(error53, "processExited");
|
|
28540
29651
|
this.goals?.close();
|
|
29652
|
+
this.#backgroundItems.abandonAll(normalized.message);
|
|
29653
|
+
this.#pendingBackground.clear();
|
|
29654
|
+
this.#loops.clear();
|
|
28541
29655
|
if (this.#active)
|
|
28542
29656
|
this.#finish(this.#active, { status: "failed", error: normalized });
|
|
28543
29657
|
this.#phase = "faulted";
|
|
@@ -28656,7 +29770,7 @@ var GrokAdapter = class {
|
|
|
28656
29770
|
async inspect(input = {}) {
|
|
28657
29771
|
if (this.#closePromise)
|
|
28658
29772
|
return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
|
|
28659
|
-
const cwd =
|
|
29773
|
+
const cwd = path21.resolve(input.cwd ?? process.cwd());
|
|
28660
29774
|
if (!input.refresh) {
|
|
28661
29775
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
28662
29776
|
if (cached2)
|
|
@@ -28731,7 +29845,7 @@ var GrokAdapter = class {
|
|
|
28731
29845
|
}
|
|
28732
29846
|
};
|
|
28733
29847
|
}
|
|
28734
|
-
const cwd =
|
|
29848
|
+
const cwd = path21.resolve(input.cwd);
|
|
28735
29849
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
28736
29850
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
28737
29851
|
return {
|
|
@@ -28902,9 +30016,15 @@ var GrokAdapter = class {
|
|
|
28902
30016
|
randomUUID: this.#dependencies.randomUUID,
|
|
28903
30017
|
refreshCredits: () => this.refreshCredits(),
|
|
28904
30018
|
sessionDirectory,
|
|
30019
|
+
readChild: (id) => this.subagents.readSnapshot({
|
|
30020
|
+
parent: nativeRef(transport.sessionId),
|
|
30021
|
+
nativeSubagentId: id,
|
|
30022
|
+
cwd
|
|
30023
|
+
}),
|
|
28905
30024
|
toolOutputLimit: this.#toolOutputLimit
|
|
28906
30025
|
});
|
|
28907
30026
|
session = openedSession;
|
|
30027
|
+
await openedSession.backgroundActivity.list();
|
|
28908
30028
|
this.#sessions.add(openedSession);
|
|
28909
30029
|
this.#scheduleCreditsRefresh();
|
|
28910
30030
|
return { ok: true, value: openedSession };
|