@karlorz/codexhost-cli-win32-x64 0.16.1-3 → 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.
@@ -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, path21) {
1162
- if (!path21)
1161
+ function getElementAtPath(obj, path22) {
1162
+ if (!path22)
1163
1163
  return obj;
1164
- return path21.reduce((acc, key) => acc?.[key], obj);
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(path21, issues) {
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(path21);
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, path21 = []) => {
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 }, [...path21, ...issue2.path]));
1727
+ issue2.errors.map((issues) => processError({ issues }, [...path22, ...issue2.path]));
1728
1728
  } else if (issue2.code === "invalid_key") {
1729
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1729
+ processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
1730
1730
  } else if (issue2.code === "invalid_element") {
1731
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1731
+ processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
1732
1732
  } else {
1733
- const fullpath = [...path21, ...issue2.path];
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, path21 = []) => {
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 }, [...path21, ...issue2.path]));
1764
+ issue2.errors.map((issues) => processError({ issues }, [...path22, ...issue2.path]));
1765
1765
  } else if (issue2.code === "invalid_key") {
1766
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1766
+ processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
1767
1767
  } else if (issue2.code === "invalid_element") {
1768
- processError({ issues: issue2.issues }, [...path21, ...issue2.path]);
1768
+ processError({ issues: issue2.issues }, [...path22, ...issue2.path]);
1769
1769
  } else {
1770
- const fullpath = [...path21, ...issue2.path];
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 path21 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1803
- for (const seg of path21) {
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 path21 = ref.slice(1).split("/").filter(Boolean);
14496
- if (path21.length === 0) {
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 (path21[0] === defsKey) {
14501
- const key = path21[1];
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
  }
@@ -17166,7 +17166,7 @@ async function readGrokCredentials(environment) {
17166
17166
  }
17167
17167
 
17168
17168
  // dist/grok-adapter.js
17169
- import path20 from "node:path";
17169
+ import path21 from "node:path";
17170
17170
 
17171
17171
  // ../../harness-plugin-files/dist/grok-computer-use.js
17172
17172
  import { randomUUID } from "node:crypto";
@@ -17860,11 +17860,371 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
17860
17860
  return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
17861
17861
  }
17862
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 `![${name}](${markdownDestination(absolutePath, false)})`;
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
+
17863
18223
  // dist/acp-transport.js
17864
18224
  import { spawn, spawnSync } from "node:child_process";
17865
18225
  import { readdir, readFile as readFile5 } from "node:fs/promises";
17866
18226
  import os6 from "node:os";
17867
- import path16 from "node:path";
18227
+ import path17 from "node:path";
17868
18228
  import { Readable, Writable } from "node:stream";
17869
18229
  import { setTimeout as delay3 } from "node:timers/promises";
17870
18230
 
@@ -22053,8 +22413,8 @@ function parseGrokAvailableCommands(value) {
22053
22413
  });
22054
22414
  }
22055
22415
  function isGrokSkill(command) {
22056
- const path21 = command.meta?.path;
22057
- return typeof path21 === "string" && /(^|[\\/])SKILL\.md$/u.test(path21) || typeof command.meta?.qualifiedName === "string";
22416
+ const path22 = command.meta?.path;
22417
+ return typeof path22 === "string" && /(^|[\\/])SKILL\.md$/u.test(path22) || typeof command.meta?.qualifiedName === "string";
22058
22418
  }
22059
22419
  function grokLiveCommands(native) {
22060
22420
  return native.map((command) => ({
@@ -22065,7 +22425,7 @@ function grokLiveCommands(native) {
22065
22425
  }
22066
22426
 
22067
22427
  // dist/command.js
22068
- import path10 from "node:path";
22428
+ import path11 from "node:path";
22069
22429
  var GrokExecutableError = class extends Error {
22070
22430
  code = "GROK_NOT_FOUND";
22071
22431
  };
@@ -22094,7 +22454,7 @@ function resolveGrokExecutable(input = {}) {
22094
22454
  });
22095
22455
  if (!resolution)
22096
22456
  throw new GrokExecutableError("Grok CLI is not installed");
22097
- return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path10.resolve(resolution.executable);
22457
+ return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path11.resolve(resolution.executable);
22098
22458
  }
22099
22459
  function grokInvocation(command, platform = process.platform, modelId) {
22100
22460
  const arguments_ = ["agent", "--no-leader"];
@@ -22107,7 +22467,7 @@ function grokInvocation(command, platform = process.platform, modelId) {
22107
22467
 
22108
22468
  // dist/grok-fork.js
22109
22469
  import { isDeepStrictEqual } from "node:util";
22110
- import path14 from "node:path";
22470
+ import path15 from "node:path";
22111
22471
 
22112
22472
  // dist/grok-history-groups.js
22113
22473
  function grokPromptIndex(event) {
@@ -22251,7 +22611,7 @@ function placeGrokGoalHelpers(replay, groups) {
22251
22611
 
22252
22612
  // dist/grok-file-change.js
22253
22613
  import { Buffer as Buffer2 } from "node:buffer";
22254
- import path11 from "node:path";
22614
+ import path12 from "node:path";
22255
22615
 
22256
22616
  // ../../../node_modules/diff/libesm/diff/base.js
22257
22617
  var Diff = class {
@@ -22353,16 +22713,16 @@ var Diff = class {
22353
22713
  }
22354
22714
  }
22355
22715
  }
22356
- addToPath(path21, added, removed, oldPosInc, options) {
22357
- const last = path21.lastComponent;
22716
+ addToPath(path22, added, removed, oldPosInc, options) {
22717
+ const last = path22.lastComponent;
22358
22718
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
22359
22719
  return {
22360
- oldPos: path21.oldPos + oldPosInc,
22720
+ oldPos: path22.oldPos + oldPosInc,
22361
22721
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
22362
22722
  };
22363
22723
  } else {
22364
22724
  return {
22365
- oldPos: path21.oldPos + oldPosInc,
22725
+ oldPos: path22.oldPos + oldPosInc,
22366
22726
  lastComponent: { count: 1, added, removed, previousComponent: last }
22367
22727
  };
22368
22728
  }
@@ -22675,13 +23035,13 @@ function isRecord5(value) {
22675
23035
  return typeof value === "object" && value !== null && !Array.isArray(value);
22676
23036
  }
22677
23037
  function validAbsolutePath(value) {
22678
- return typeof value === "string" && path11.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
23038
+ return typeof value === "string" && path12.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
22679
23039
  }
22680
23040
  function displayPath(nativePath, cwd) {
22681
- const resolvedCwd = path11.resolve(cwd);
22682
- const resolvedPath = path11.resolve(nativePath);
22683
- const relative = path11.relative(resolvedCwd, resolvedPath);
22684
- const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path11.sep}`);
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}`);
22685
23045
  const selected = inside ? relative : resolvedPath;
22686
23046
  const normalized = selected.replaceAll("\\", "/");
22687
23047
  if (normalized.length === 0 || normalized === ".")
@@ -22743,303 +23103,14 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
22743
23103
 
22744
23104
  // dist/grok-generated-image.js
22745
23105
  import path13 from "node:path";
22746
-
22747
- // dist/local-media-markdown.js
22748
- import { existsSync, statSync } from "node:fs";
22749
- import os5 from "node:os";
22750
- import path12 from "node:path";
22751
- var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
22752
- ".aac",
22753
- ".gif",
22754
- ".jpeg",
22755
- ".jpg",
22756
- ".m4a",
22757
- ".m4v",
22758
- ".mov",
22759
- ".mp3",
22760
- ".mp4",
22761
- ".ogg",
22762
- ".png",
22763
- ".svg",
22764
- ".wav",
22765
- ".webm",
22766
- ".webp"
22767
- ]);
22768
- function grokMediaResolveRoots(cwd, sessionDirectory) {
22769
- const roots = [path12.resolve(cwd)];
22770
- if (sessionDirectory) {
22771
- const session = path12.resolve(sessionDirectory);
22772
- roots.push(session, path12.join(session, "videos"), path12.join(session, "images"));
22773
- }
22774
- const home = process.env.HOME ?? process.env.USERPROFILE ?? os5.homedir();
22775
- if (home)
22776
- roots.push(path12.join(home, "Downloads"));
22777
- return roots;
22778
- }
22779
- function rewriteLocalMediaMarkdown(text, roots, options = {}) {
22780
- const exists = options.exists ?? mediaFileExists;
22781
- const holdIncomplete = options.holdIncomplete === true;
22782
- let output = "";
22783
- let index = 0;
22784
- let fence = false;
22785
- while (index < text.length) {
22786
- if (fence) {
22787
- const fenceEnd = text.indexOf("```", index);
22788
- if (fenceEnd === -1) {
22789
- output += text.slice(index);
22790
- break;
22791
- }
22792
- output += text.slice(index, fenceEnd + 3);
22793
- index = fenceEnd + 3;
22794
- fence = false;
22795
- continue;
22796
- }
22797
- const fenceStart = text.indexOf("```", index);
22798
- const imageStart = text.indexOf("![", index);
22799
- const tickStart = indexOfInlineTick(text, index);
22800
- const next = earliestIndex([fenceStart, imageStart, tickStart]);
22801
- if (next === -1) {
22802
- output += text.slice(index);
22803
- break;
22804
- }
22805
- output += text.slice(index, next);
22806
- if (next === fenceStart) {
22807
- output += "```";
22808
- index = fenceStart + 3;
22809
- fence = true;
22810
- continue;
22811
- }
22812
- if (next === imageStart) {
22813
- const parsed = parseMarkdownImage(text, imageStart);
22814
- if (!parsed) {
22815
- output += "!";
22816
- index = imageStart + 1;
22817
- continue;
22818
- }
22819
- if (!parsed.closed) {
22820
- output += holdIncomplete ? text.slice(imageStart, parsed.destinationStart) : text.slice(imageStart);
22821
- break;
22822
- }
22823
- const resolved2 = resolveLocalMediaPath(parsed.destination, roots, exists);
22824
- output += text.slice(imageStart, parsed.destinationStart) + formatMarkdownDestination(resolved2 ?? parsed.destination, parsed.bracketed) + text.slice(parsed.destinationEnd, parsed.end);
22825
- index = parsed.end;
22826
- continue;
22827
- }
22828
- const inline = parseInlineCode(text, tickStart);
22829
- if (!inline.closed) {
22830
- if (!holdIncomplete)
22831
- output += text.slice(tickStart);
22832
- break;
22833
- }
22834
- const resolved = resolveLocalMediaPath(inline.content, roots, exists);
22835
- output += resolved ? mediaMarkdownImage(resolved) : text.slice(tickStart, inline.end);
22836
- index = inline.end;
22837
- }
22838
- return output;
22839
- }
22840
- function indexOfInlineTick(text, start) {
22841
- let index = start;
22842
- while (index < text.length) {
22843
- const tick = text.indexOf("`", index);
22844
- if (tick === -1)
22845
- return -1;
22846
- if (text.startsWith("```", tick)) {
22847
- index = tick + 3;
22848
- continue;
22849
- }
22850
- return tick;
22851
- }
22852
- return -1;
22853
- }
22854
- function earliestIndex(candidates) {
22855
- let next = -1;
22856
- for (const candidate of candidates) {
22857
- if (candidate === -1)
22858
- continue;
22859
- if (next === -1 || candidate < next)
22860
- next = candidate;
22861
- }
22862
- return next;
22863
- }
22864
- function parseInlineCode(text, start) {
22865
- let index = start + 1;
22866
- while (index < text.length) {
22867
- const character = text[index];
22868
- if (character === "\n")
22869
- return { closed: false, content: text.slice(start + 1, index), end: index };
22870
- if (character === "`")
22871
- return { closed: true, content: text.slice(start + 1, index), end: index + 1 };
22872
- index += 1;
22873
- }
22874
- return { closed: false, content: text.slice(start + 1), end: text.length };
22875
- }
22876
- function mediaMarkdownImage(absolutePath) {
22877
- const name = path12.basename(absolutePath).replaceAll("]", "\\]");
22878
- return `![${name}](${formatMarkdownDestination(absolutePath, false)})`;
22879
- }
22880
- function parseMarkdownImage(text, start) {
22881
- if (text.slice(start, start + 2) !== "![")
22882
- return null;
22883
- let index = start + 2;
22884
- while (index < text.length) {
22885
- const character = text[index];
22886
- if (character === "\n")
22887
- return null;
22888
- if (character === "\\" && index + 1 < text.length) {
22889
- index += 2;
22890
- continue;
22891
- }
22892
- if (character === "]")
22893
- break;
22894
- index += 1;
22895
- }
22896
- if (text[index] !== "]" || text[index + 1] !== "(")
22897
- return null;
22898
- const destinationStart = index + 2;
22899
- index = destinationStart;
22900
- while (text[index] === " " || text[index] === " ")
22901
- index += 1;
22902
- if (index >= text.length) {
22903
- return {
22904
- closed: false,
22905
- destination: "",
22906
- destinationStart,
22907
- destinationEnd: index,
22908
- end: text.length,
22909
- bracketed: false
22910
- };
22911
- }
22912
- let destination;
22913
- let destinationEnd;
22914
- let bracketed = false;
22915
- if (text[index] === "<") {
22916
- bracketed = true;
22917
- const close = text.indexOf(">", index + 1);
22918
- if (close === -1 || text.slice(index, close).includes("\n")) {
22919
- return {
22920
- closed: false,
22921
- destination: text.slice(index + 1),
22922
- destinationStart,
22923
- destinationEnd: text.length,
22924
- end: text.length,
22925
- bracketed: true
22926
- };
22927
- }
22928
- destination = text.slice(index + 1, close);
22929
- destinationEnd = close + 1;
22930
- index = destinationEnd;
22931
- } else {
22932
- const begin = index;
22933
- while (index < text.length) {
22934
- const character = text[index];
22935
- if (character === "\n" || character === " " || character === " " || character === ")")
22936
- break;
22937
- if (character === "\\" && index + 1 < text.length) {
22938
- index += 2;
22939
- continue;
22940
- }
22941
- index += 1;
22942
- }
22943
- destination = unescapeMarkdown(text.slice(begin, index));
22944
- destinationEnd = index;
22945
- }
22946
- while (text[index] === " " || text[index] === " ")
22947
- index += 1;
22948
- if (text[index] === '"' || text[index] === "'" || text[index] === "(") {
22949
- const closer = text[index] === "(" ? ")" : text[index];
22950
- index += 1;
22951
- while (index < text.length && text[index] !== closer && text[index] !== "\n")
22952
- index += 1;
22953
- if (text[index] !== closer) {
22954
- return {
22955
- closed: false,
22956
- destination,
22957
- destinationStart,
22958
- destinationEnd,
22959
- end: text.length,
22960
- bracketed
22961
- };
22962
- }
22963
- index += 1;
22964
- while (text[index] === " " || text[index] === " ")
22965
- index += 1;
22966
- }
22967
- if (text[index] !== ")") {
22968
- return {
22969
- closed: false,
22970
- destination,
22971
- destinationStart,
22972
- destinationEnd,
22973
- end: text.length,
22974
- bracketed
22975
- };
22976
- }
22977
- return {
22978
- closed: true,
22979
- destination,
22980
- destinationStart,
22981
- destinationEnd,
22982
- end: index + 1,
22983
- bracketed
22984
- };
22985
- }
22986
- function formatMarkdownDestination(destination, bracketed) {
22987
- if (bracketed || /[\s()]/.test(destination))
22988
- return `<${destination}>`;
22989
- return destination.replaceAll(" ", "%20");
22990
- }
22991
- function unescapeMarkdown(value) {
22992
- return value.replace(/\\([\\()])/g, "$1");
22993
- }
22994
- function resolveLocalMediaPath(raw, roots, exists = mediaFileExists) {
22995
- const trimmed = raw.trim();
22996
- if (trimmed.length === 0 || isRemoteMediaUrl(trimmed))
22997
- return null;
22998
- const stripped = stripFileUrl(trimmed);
22999
- if (!hasMediaExtension(stripped))
23000
- return null;
23001
- if (isAbsoluteMediaPath(stripped)) {
23002
- const absolute = path12.resolve(stripped);
23003
- return exists(absolute) ? absolute : null;
23004
- }
23005
- for (const root of roots) {
23006
- const absolute = path12.resolve(root, stripped);
23007
- if (exists(absolute))
23008
- return absolute;
23009
- }
23010
- return null;
23011
- }
23012
- function isRemoteMediaUrl(value) {
23013
- return /^(?:https?:|data:|app:|blob:)/i.test(value);
23014
- }
23015
- function stripFileUrl(value) {
23016
- if (!value.toLowerCase().startsWith("file:"))
23017
- return value;
23106
+ import { statSync as statSync2 } from "node:fs";
23107
+ function mediaFileExists2(absolutePath) {
23018
23108
  try {
23019
- const url2 = new URL(value);
23020
- if (url2.protocol !== "file:")
23021
- return value;
23022
- return decodeURIComponent(url2.pathname);
23023
- } catch {
23024
- return value.replace(/^file:\/\//i, "");
23025
- }
23026
- }
23027
- function isAbsoluteMediaPath(value) {
23028
- return path12.isAbsolute(value) || /^[a-zA-Z]:[\\/]/.test(value);
23029
- }
23030
- function hasMediaExtension(value) {
23031
- const pathname = value.split(/[?#]/, 1)[0] ?? value;
23032
- return MEDIA_EXTENSIONS.has(path12.extname(pathname).toLowerCase());
23033
- }
23034
- function mediaFileExists(absolutePath) {
23035
- try {
23036
- return existsSync(absolutePath) && statSync(absolutePath).isFile();
23109
+ return statSync2(absolutePath).isFile();
23037
23110
  } catch {
23038
23111
  return false;
23039
23112
  }
23040
23113
  }
23041
-
23042
- // dist/grok-generated-image.js
23043
23114
  var GENERATED_IMAGE_TYPES = /* @__PURE__ */ new Set(["ImageGen", "ImageEdit"]);
23044
23115
  function isRecord6(value) {
23045
23116
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -23078,7 +23149,7 @@ function parseJsonObject(text) {
23078
23149
  return null;
23079
23150
  }
23080
23151
  }
23081
- function projectGrokGeneratedImage(content, rawOutput, exists = mediaFileExists) {
23152
+ function projectGrokGeneratedImage(content, rawOutput, exists = mediaFileExists2) {
23082
23153
  const fromRaw = fromNativeRecord(rawOutput, exists);
23083
23154
  if (fromRaw)
23084
23155
  return fromRaw;
@@ -23112,6 +23183,21 @@ function grokGeneratedImageItem(image, itemId, sourceItemId) {
23112
23183
  };
23113
23184
  }
23114
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
+
23115
23201
  // dist/grok-tool-output.js
23116
23202
  var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
23117
23203
  var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set([
@@ -24212,11 +24298,11 @@ function parseGrokForkResponse(value) {
24212
24298
  }
24213
24299
  function projectRelativePath(value, cwds) {
24214
24300
  const normalized = value.replaceAll("\\", "/");
24215
- if (!path14.isAbsolute(value))
24301
+ if (!path15.isAbsolute(value))
24216
24302
  return normalized;
24217
24303
  for (const cwd of cwds) {
24218
- const relative = path14.relative(path14.resolve(cwd), path14.resolve(value));
24219
- if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path14.sep}`)) {
24304
+ const relative = path15.relative(path15.resolve(cwd), path15.resolve(value));
24305
+ if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path15.sep}`)) {
24220
24306
  return relative.replaceAll("\\", "/");
24221
24307
  }
24222
24308
  }
@@ -24281,8 +24367,8 @@ async function forkGrokSession(input) {
24281
24367
  error: error51("sessionNotFound", "Grok Native Session is unavailable")
24282
24368
  };
24283
24369
  }
24284
- const sourceCwd = path14.resolve(located.cwd);
24285
- const targetCwd = path14.resolve(input.cwd);
24370
+ const sourceCwd = path15.resolve(located.cwd);
24371
+ const targetCwd = path15.resolve(input.cwd);
24286
24372
  const source = await readSnapshot({ ...input, cwd: sourceCwd }, sourceRef.data.nativeSessionId);
24287
24373
  if (!source.ok)
24288
24374
  return source;
@@ -24683,7 +24769,7 @@ function parseGrokCompactResult(value, cancelled = false) {
24683
24769
  }
24684
24770
 
24685
24771
  // dist/grok-rewind.js
24686
- import path15 from "node:path";
24772
+ import path16 from "node:path";
24687
24773
  var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
24688
24774
  function error52(code, message, retryable = false) {
24689
24775
  return { code, message, retryable };
@@ -24763,8 +24849,8 @@ async function rewindGrokSession(input) {
24763
24849
  error: error52("sessionNotFound", "Grok Native Session is unavailable")
24764
24850
  };
24765
24851
  }
24766
- const sourceCwd = path15.resolve(located.cwd);
24767
- const targetCwd = path15.resolve(input.cwd);
24852
+ const sourceCwd = path16.resolve(located.cwd);
24853
+ const targetCwd = path16.resolve(input.cwd);
24768
24854
  if (sourceCwd !== targetCwd) {
24769
24855
  return {
24770
24856
  ok: false,
@@ -25424,8 +25510,14 @@ function signalProcessTree(child, signal) {
25424
25510
  try {
25425
25511
  process.kill(-child.pid, signal);
25426
25512
  } catch (error53) {
25427
- if (!isRecord16(error53) || error53.code !== "ESRCH")
25428
- throw error53;
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
+ }
25429
25521
  }
25430
25522
  }
25431
25523
  function grokNotificationMetadata(envelope, update) {
@@ -25535,13 +25627,13 @@ function transportEvent(update, metadata) {
25535
25627
  function grokHomeDir(options) {
25536
25628
  const environment = { ...process.env, ...options.environment };
25537
25629
  const home = environment.HOME ?? environment.USERPROFILE ?? os6.homedir();
25538
- return environment.GROK_HOME ?? path16.join(home, ".grok");
25630
+ return environment.GROK_HOME ?? path17.join(home, ".grok");
25539
25631
  }
25540
25632
  function grokNativeSessionDirectory(options, sessionId) {
25541
- return path16.join(grokHomeDir(options), "sessions", encodeURIComponent(path16.resolve(options.cwd)), sessionId);
25633
+ return path17.join(grokHomeDir(options), "sessions", encodeURIComponent(path17.resolve(options.cwd)), sessionId);
25542
25634
  }
25543
25635
  function nativeSessionFile(options, sessionId, fileName) {
25544
- return path16.join(grokNativeSessionDirectory(options, sessionId), fileName);
25636
+ return path17.join(grokNativeSessionDirectory(options, sessionId), fileName);
25545
25637
  }
25546
25638
  function nativeHistoryPath(options, sessionId) {
25547
25639
  return nativeSessionFile(options, sessionId, "updates.jsonl");
@@ -25561,7 +25653,7 @@ async function locateGrokNativeSession(options, sessionId) {
25561
25653
  return null;
25562
25654
  let entries;
25563
25655
  try {
25564
- entries = await readdir(path16.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
25656
+ entries = await readdir(path17.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
25565
25657
  } catch (error53) {
25566
25658
  if (isMissingFile(error53))
25567
25659
  return null;
@@ -25575,7 +25667,7 @@ async function locateGrokNativeSession(options, sessionId) {
25575
25667
  continue;
25576
25668
  let summaryRaw;
25577
25669
  try {
25578
- summaryRaw = await readFile5(path16.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
25670
+ summaryRaw = await readFile5(path17.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
25579
25671
  } catch (error53) {
25580
25672
  if (isMissingFile(error53) || isRecord16(error53) && error53.code === "ENOTDIR")
25581
25673
  continue;
@@ -25592,8 +25684,8 @@ async function locateGrokNativeSession(options, sessionId) {
25592
25684
  if (!isRecord16(parsed))
25593
25685
  continue;
25594
25686
  const info = parsed.info;
25595
- const cwd = isRecord16(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path16.resolve(info.cwd) : path16.resolve(decodeURIComponent(entry.name));
25596
- const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path16.resolve(parsed.source_workspace_dir) : void 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;
25597
25689
  matches.push({
25598
25690
  cwd,
25599
25691
  ...sourceWorkspaceDir ? { sourceWorkspaceDir } : {}
@@ -25603,7 +25695,7 @@ async function locateGrokNativeSession(options, sessionId) {
25603
25695
  }
25604
25696
  async function readGrokNativeHistory(options, sessionId) {
25605
25697
  try {
25606
- return parseNativeHistory(await readFile5(nativeHistoryPath({ ...options, cwd: path16.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
25698
+ return parseNativeHistory(await readFile5(nativeHistoryPath({ ...options, cwd: path17.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
25607
25699
  } catch (error53) {
25608
25700
  if (isMissingFile(error53))
25609
25701
  return [];
@@ -26292,7 +26384,7 @@ var GrokAcpTransport = class {
26292
26384
  // dist/session-import.js
26293
26385
  import { createReadStream as createReadStream2 } from "node:fs";
26294
26386
  import { opendir as opendir2, readFile as readFile6, stat as stat2 } from "node:fs/promises";
26295
- import path17 from "node:path";
26387
+ import path18 from "node:path";
26296
26388
  import { createInterface as createInterface2 } from "node:readline";
26297
26389
 
26298
26390
  // ../../harness-adapter/dist/session-import.js
@@ -26513,7 +26605,7 @@ var GrokSessionImport = class {
26513
26605
  const active = /* @__PURE__ */ new Set();
26514
26606
  let entries;
26515
26607
  try {
26516
- entries = await readJson(path17.join(this.#home(), "active_sessions.json"), signal);
26608
+ entries = await readJson(path18.join(this.#home(), "active_sessions.json"), signal);
26517
26609
  } catch (error53) {
26518
26610
  signal.throwIfAborted();
26519
26611
  if (isStorageAccessError(error53))
@@ -26530,7 +26622,7 @@ var GrokSessionImport = class {
26530
26622
  }
26531
26623
  /** Session ID to every directory claiming it. Enumerated links are not followed. */
26532
26624
  async #sessionDirectories(signal) {
26533
- const root = path17.join(this.#home(), "sessions");
26625
+ const root = path18.join(this.#home(), "sessions");
26534
26626
  const found = /* @__PURE__ */ new Map();
26535
26627
  const info = await optionalLstat(root);
26536
26628
  if (!info)
@@ -26541,7 +26633,7 @@ var GrokSessionImport = class {
26541
26633
  signal.throwIfAborted();
26542
26634
  if (!workspace.isDirectory())
26543
26635
  continue;
26544
- const workspaceDirectory = path17.join(root, workspace.name);
26636
+ const workspaceDirectory = path18.join(root, workspace.name);
26545
26637
  const sessions = await opendir2(workspaceDirectory).catch((error53) => {
26546
26638
  if (isMissingFileError(error53))
26547
26639
  return null;
@@ -26554,7 +26646,7 @@ var GrokSessionImport = class {
26554
26646
  if (!session.isDirectory())
26555
26647
  continue;
26556
26648
  const directories = found.get(session.name) ?? [];
26557
- directories.push(path17.join(workspaceDirectory, session.name));
26649
+ directories.push(path18.join(workspaceDirectory, session.name));
26558
26650
  found.set(session.name, directories);
26559
26651
  }
26560
26652
  }
@@ -26562,10 +26654,10 @@ var GrokSessionImport = class {
26562
26654
  }
26563
26655
  async #candidate(sessionDirectory, active, signal) {
26564
26656
  signal.throwIfAborted();
26565
- const nativeSessionId = path17.basename(sessionDirectory);
26657
+ const nativeSessionId = path18.basename(sessionDirectory);
26566
26658
  const files = [
26567
- path17.join(sessionDirectory, "summary.json"),
26568
- path17.join(sessionDirectory, "updates.jsonl")
26659
+ path18.join(sessionDirectory, "summary.json"),
26660
+ path18.join(sessionDirectory, "updates.jsonl")
26569
26661
  ];
26570
26662
  return readStableFiles(files, async ([summaryInfo, updates]) => {
26571
26663
  if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
@@ -26577,10 +26669,10 @@ var GrokSessionImport = class {
26577
26669
  if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
26578
26670
  return null;
26579
26671
  const nativeCwd = summary.info.cwd;
26580
- if (typeof nativeCwd !== "string" || !path17.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
26672
+ if (typeof nativeCwd !== "string" || !path18.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
26581
26673
  return null;
26582
- const cwd = path17.resolve(nativeCwd);
26583
- if (encodeURIComponent(cwd) !== path17.basename(path17.dirname(sessionDirectory)))
26674
+ const cwd = path18.resolve(nativeCwd);
26675
+ if (encodeURIComponent(cwd) !== path18.basename(path18.dirname(sessionDirectory)))
26584
26676
  return null;
26585
26677
  if (!(await stat2(cwd)).isDirectory())
26586
26678
  return null;
@@ -26825,7 +26917,7 @@ var GrokSubagentLifecycle = class {
26825
26917
 
26826
26918
  // dist/grok-activity.js
26827
26919
  import { readFile as readFile7 } from "node:fs/promises";
26828
- import path18 from "node:path";
26920
+ import path19 from "node:path";
26829
26921
  var record2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
26830
26922
  var fail = (code, message) => ({ ok: false, error: { code, message, retryable: false } });
26831
26923
  function parseGrokTaskList(value, sessionId) {
@@ -26840,7 +26932,7 @@ function parseGrokTaskList(value, sessionId) {
26840
26932
  async function readGrokScheduledLoops(directory) {
26841
26933
  let raw;
26842
26934
  try {
26843
- raw = JSON.parse(await readFile7(path18.join(directory, "resources_state.json"), "utf8"));
26935
+ raw = JSON.parse(await readFile7(path19.join(directory, "resources_state.json"), "utf8"));
26844
26936
  } catch (error53) {
26845
26937
  if (error53.code === "ENOENT")
26846
26938
  return null;
@@ -27407,9 +27499,17 @@ function stateForGrokModel(modelState, nativeState, model2 = modelState.currentM
27407
27499
  // dist/grok-credits.js
27408
27500
  import { readFile as readFile8 } from "node:fs/promises";
27409
27501
  import os7 from "node:os";
27410
- import path19 from "node:path";
27502
+ import path20 from "node:path";
27411
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";
27412
27505
  var REQUEST_TIMEOUT_MS = 15e3;
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
+ }
27413
27513
  function isRecord20(value) {
27414
27514
  return typeof value === "object" && value !== null && !Array.isArray(value);
27415
27515
  }
@@ -27427,7 +27527,7 @@ function nonNegativeCentValue(value) {
27427
27527
  return amount;
27428
27528
  }
27429
27529
  function grokHome3(environment) {
27430
- return environment.GROK_HOME ?? path19.join(environment.HOME ?? environment.USERPROFILE ?? os7.homedir(), ".grok");
27530
+ return environment.GROK_HOME ?? path20.join(environment.HOME ?? environment.USERPROFILE ?? os7.homedir(), ".grok");
27431
27531
  }
27432
27532
  function periodTypeFrom(value) {
27433
27533
  if (typeof value !== "string")
@@ -27519,26 +27619,30 @@ async function fetchGrokAccount(input = {}) {
27519
27619
  if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
27520
27620
  return null;
27521
27621
  const now = input.now ?? /* @__PURE__ */ new Date();
27522
- const authPath = path19.join(grokHome3(environment), "auth.json");
27622
+ const authPath = path20.join(grokHome3(environment), "auth.json");
27523
27623
  const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile8(authPath, "utf8");
27524
27624
  const token = selectAccessToken(JSON.parse(raw), now);
27525
27625
  if (!token)
27526
27626
  return null;
27527
27627
  const fetchImpl = input.fetch ?? fetch;
27528
- const response = await fetchImpl(GROK_CREDITS_ENDPOINT, {
27628
+ const request = (url2, timeoutMs) => fetchImpl(url2, {
27529
27629
  method: "GET",
27530
27630
  headers: {
27531
27631
  Authorization: `Bearer ${token.key}`,
27532
27632
  "x-xai-token-auth": "xai-grok-cli",
27533
27633
  Accept: "application/json"
27534
27634
  },
27535
- signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]) : AbortSignal.timeout(REQUEST_TIMEOUT_MS)
27635
+ signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs)
27536
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;
27537
27640
  if (!response.ok)
27538
27641
  return null;
27539
27642
  const snapshot = parseGrokCreditsResponse(await response.json(), now.toISOString());
27540
27643
  if (!snapshot)
27541
27644
  return null;
27645
+ const planName = await plan;
27542
27646
  return {
27543
27647
  credits: {
27544
27648
  usedPercent: snapshot.usedPercent,
@@ -27547,14 +27651,15 @@ async function fetchGrokAccount(input = {}) {
27547
27651
  ...snapshot.productUsage ? { productUsage: [...snapshot.productUsage] } : {}
27548
27652
  },
27549
27653
  ...token.email ? { email: token.email } : {},
27550
- ...token.label ? { label: token.label } : {}
27654
+ ...token.label ? { label: token.label } : {},
27655
+ ...planName ? { plan: planName } : {}
27551
27656
  };
27552
27657
  } catch {
27553
27658
  return null;
27554
27659
  }
27555
27660
  }
27556
27661
  async function fetchGrokCredits(input = {}) {
27557
- const account = await fetchGrokAccount(input);
27662
+ const account = await fetchGrokAccount({ ...input, includePlan: false });
27558
27663
  if (!account?.credits)
27559
27664
  return null;
27560
27665
  const { credits } = account;
@@ -28262,8 +28367,7 @@ var GrokHarnessSession = class {
28262
28367
  usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
28263
28368
  agent: null,
28264
28369
  agentMessageId: null,
28265
- rawAgentText: "",
28266
- projectedAgentText: "",
28370
+ agentMedia: null,
28267
28371
  reasoning: null,
28268
28372
  reasoningMessageId: null,
28269
28373
  compactionItem: null,
@@ -28643,8 +28747,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
28643
28747
  textIdentity: { turnIndex: this.#snapshot.turns.length, agentMessage: 0, reasoning: 0 },
28644
28748
  agent: null,
28645
28749
  agentMessageId: null,
28646
- rawAgentText: "",
28647
- projectedAgentText: "",
28750
+ agentMedia: null,
28648
28751
  reasoning: null,
28649
28752
  reasoningMessageId: null,
28650
28753
  compactionItem: null,
@@ -29076,19 +29179,16 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
29076
29179
  itemId: grokTextItemId(this.#transport.sessionId, active.textIdentity.turnIndex, "agentMessage", ++active.textIdentity.agentMessage),
29077
29180
  text: ""
29078
29181
  };
29079
- active.rawAgentText = "";
29080
- active.projectedAgentText = "";
29182
+ active.agentMedia = new LocalMediaMarkdownStream(this.#mediaRoots);
29081
29183
  this.#event({ type: "item.started", turnId: active.command.turnId, item: active.agent });
29082
29184
  }
29083
- active.rawAgentText += text;
29084
- const projected = rewriteLocalMediaMarkdown(active.rawAgentText, this.#mediaRoots, {
29085
- holdIncomplete: true
29086
- });
29087
- const delta = projected.startsWith(active.projectedAgentText) ? projected.slice(active.projectedAgentText.length) : text;
29088
- 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)
29089
29190
  return;
29090
- active.projectedAgentText += delta;
29091
- active.agent = { ...active.agent, text: active.projectedAgentText };
29191
+ active.agent = { ...active.agent, text: active.agentMedia.text };
29092
29192
  this.#event({
29093
29193
  type: "item.updated",
29094
29194
  turnId: active.command.turnId,
@@ -29367,25 +29467,12 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
29367
29467
  }
29368
29468
  #completeAgent(active, outcome) {
29369
29469
  const item = active.agent;
29370
- if (item && active.rawAgentText.length > 0) {
29371
- const flushed = rewriteLocalMediaMarkdown(active.rawAgentText, this.#mediaRoots);
29372
- const delta = flushed.startsWith(item.text) ? flushed.slice(item.text.length) : "";
29373
- if (delta.length > 0) {
29374
- active.projectedAgentText = flushed;
29375
- active.agent = { ...item, text: flushed };
29376
- this.#event({
29377
- type: "item.updated",
29378
- turnId: active.command.turnId,
29379
- itemId: item.itemId,
29380
- update: { type: "text.append", text: delta }
29381
- });
29382
- }
29383
- }
29470
+ if (item && active.agentMedia)
29471
+ this.#publishAgent(active, active.agentMedia.flush());
29384
29472
  const completed = active.agent ?? item;
29385
29473
  active.agent = null;
29386
29474
  active.agentMessageId = null;
29387
- active.rawAgentText = "";
29388
- active.projectedAgentText = "";
29475
+ active.agentMedia = null;
29389
29476
  if (completed)
29390
29477
  this.#completeItem(active, completed, outcome);
29391
29478
  }
@@ -29465,8 +29552,7 @@ Elapsed seconds: ${value.timeUsedSeconds}` : argument === "clear" ? "Goal cleare
29465
29552
  update: { type: "text.append", text: delta }
29466
29553
  });
29467
29554
  active.agent = { ...pendingMessage, text };
29468
- active.rawAgentText = text;
29469
- active.projectedAgentText = text;
29555
+ active.agentMedia = null;
29470
29556
  }
29471
29557
  this.#completeReasoning(active, itemOutcome);
29472
29558
  this.#completeAgent(active, itemOutcome);
@@ -29684,7 +29770,7 @@ var GrokAdapter = class {
29684
29770
  async inspect(input = {}) {
29685
29771
  if (this.#closePromise)
29686
29772
  return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
29687
- const cwd = path20.resolve(input.cwd ?? process.cwd());
29773
+ const cwd = path21.resolve(input.cwd ?? process.cwd());
29688
29774
  if (!input.refresh) {
29689
29775
  const cached2 = this.#inspectionCache.get(cwd);
29690
29776
  if (cached2)
@@ -29759,7 +29845,7 @@ var GrokAdapter = class {
29759
29845
  }
29760
29846
  };
29761
29847
  }
29762
- const cwd = path20.resolve(input.cwd);
29848
+ const cwd = path21.resolve(input.cwd);
29763
29849
  const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
29764
29850
  if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
29765
29851
  return {