@codexhost/cli-win32-arm64 0.16.1 → 0.17.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.
@@ -603,7 +603,7 @@ async function readGrokCredentials(environment) {
603
603
  }
604
604
 
605
605
  // dist/grok-adapter.js
606
- import path15 from "node:path";
606
+ import path16 from "node:path";
607
607
 
608
608
  // ../../../node_modules/zod/v4/classic/external.js
609
609
  var external_exports = {};
@@ -1371,10 +1371,10 @@ function mergeDefs(...defs) {
1371
1371
  function cloneDef(schema) {
1372
1372
  return mergeDefs(schema._zod.def);
1373
1373
  }
1374
- function getElementAtPath(obj, path16) {
1375
- if (!path16)
1374
+ function getElementAtPath(obj, path17) {
1375
+ if (!path17)
1376
1376
  return obj;
1377
- return path16.reduce((acc, key) => acc?.[key], obj);
1377
+ return path17.reduce((acc, key) => acc?.[key], obj);
1378
1378
  }
1379
1379
  function promiseAllObject(promisesObj) {
1380
1380
  const keys = Object.keys(promisesObj);
@@ -1783,11 +1783,11 @@ function explicitlyAborted(x, startIndex = 0) {
1783
1783
  }
1784
1784
  return false;
1785
1785
  }
1786
- function prefixIssues(path16, issues) {
1786
+ function prefixIssues(path17, issues) {
1787
1787
  return issues.map((iss) => {
1788
1788
  var _a3;
1789
1789
  (_a3 = iss).path ?? (_a3.path = []);
1790
- iss.path.unshift(path16);
1790
+ iss.path.unshift(path17);
1791
1791
  return iss;
1792
1792
  });
1793
1793
  }
@@ -1934,16 +1934,16 @@ function flattenError(error53, mapper = (issue2) => issue2.message) {
1934
1934
  }
1935
1935
  function formatError(error53, mapper = (issue2) => issue2.message) {
1936
1936
  const fieldErrors = { _errors: [] };
1937
- const processError = (error54, path16 = []) => {
1937
+ const processError = (error54, path17 = []) => {
1938
1938
  for (const issue2 of error54.issues) {
1939
1939
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1940
- issue2.errors.map((issues) => processError({ issues }, [...path16, ...issue2.path]));
1940
+ issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
1941
1941
  } else if (issue2.code === "invalid_key") {
1942
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1942
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1943
1943
  } else if (issue2.code === "invalid_element") {
1944
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1944
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1945
1945
  } else {
1946
- const fullpath = [...path16, ...issue2.path];
1946
+ const fullpath = [...path17, ...issue2.path];
1947
1947
  if (fullpath.length === 0) {
1948
1948
  fieldErrors._errors.push(mapper(issue2));
1949
1949
  } else {
@@ -1970,17 +1970,17 @@ function formatError(error53, mapper = (issue2) => issue2.message) {
1970
1970
  }
1971
1971
  function treeifyError(error53, mapper = (issue2) => issue2.message) {
1972
1972
  const result = { errors: [] };
1973
- const processError = (error54, path16 = []) => {
1973
+ const processError = (error54, path17 = []) => {
1974
1974
  var _a3, _b;
1975
1975
  for (const issue2 of error54.issues) {
1976
1976
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1977
- issue2.errors.map((issues) => processError({ issues }, [...path16, ...issue2.path]));
1977
+ issue2.errors.map((issues) => processError({ issues }, [...path17, ...issue2.path]));
1978
1978
  } else if (issue2.code === "invalid_key") {
1979
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1979
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1980
1980
  } else if (issue2.code === "invalid_element") {
1981
- processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
1981
+ processError({ issues: issue2.issues }, [...path17, ...issue2.path]);
1982
1982
  } else {
1983
- const fullpath = [...path16, ...issue2.path];
1983
+ const fullpath = [...path17, ...issue2.path];
1984
1984
  if (fullpath.length === 0) {
1985
1985
  result.errors.push(mapper(issue2));
1986
1986
  continue;
@@ -2012,8 +2012,8 @@ function treeifyError(error53, mapper = (issue2) => issue2.message) {
2012
2012
  }
2013
2013
  function toDotPath(_path) {
2014
2014
  const segs = [];
2015
- const path16 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
2016
- for (const seg of path16) {
2015
+ const path17 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
2016
+ for (const seg of path17) {
2017
2017
  if (typeof seg === "number")
2018
2018
  segs.push(`[${seg}]`);
2019
2019
  else if (typeof seg === "symbol")
@@ -14705,13 +14705,13 @@ function resolveRef(ref, ctx) {
14705
14705
  if (!ref.startsWith("#")) {
14706
14706
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14707
14707
  }
14708
- const path16 = ref.slice(1).split("/").filter(Boolean);
14709
- if (path16.length === 0) {
14708
+ const path17 = ref.slice(1).split("/").filter(Boolean);
14709
+ if (path17.length === 0) {
14710
14710
  return ctx.rootSchema;
14711
14711
  }
14712
14712
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14713
- if (path16[0] === defsKey) {
14714
- const key = path16[1];
14713
+ if (path17[0] === defsKey) {
14714
+ const key = path17[1];
14715
14715
  if (!key || !ctx.defs[key]) {
14716
14716
  throw new Error(`Reference not found: ${ref}`);
14717
14717
  }
@@ -16977,11 +16977,371 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
16977
16977
  return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
16978
16978
  }
16979
16979
 
16980
+ // ../../harness-adapter/dist/local-media-markdown.js
16981
+ import { existsSync, statSync } from "node:fs";
16982
+ import path7 from "node:path";
16983
+ import { fileURLToPath } from "node:url";
16984
+ var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
16985
+ ".aac",
16986
+ ".gif",
16987
+ ".jpeg",
16988
+ ".jpg",
16989
+ ".m4a",
16990
+ ".m4v",
16991
+ ".mov",
16992
+ ".mp3",
16993
+ ".mp4",
16994
+ ".ogg",
16995
+ ".png",
16996
+ ".svg",
16997
+ ".wav",
16998
+ ".webm",
16999
+ ".webp"
17000
+ ]);
17001
+ function rewriteLocalMediaMarkdown(text, roots, options = {}) {
17002
+ return projectLocalMedia(text, roots, options.exists ?? mediaFileExists, options.holdIncomplete === true, options.relativeImagesOnly === true).text;
17003
+ }
17004
+ var LocalMediaMarkdownStream = class {
17005
+ #roots;
17006
+ #exists;
17007
+ #relativeImagesOnly;
17008
+ #native = "";
17009
+ #text = "";
17010
+ /** Native text length represented by `#text`; the rest is held. */
17011
+ #consumed = 0;
17012
+ #verbatim = false;
17013
+ constructor(roots, exists = mediaFileExists, options = {}) {
17014
+ this.#roots = [...roots];
17015
+ this.#relativeImagesOnly = options.relativeImagesOnly === true;
17016
+ const known = /* @__PURE__ */ new Map();
17017
+ this.#exists = (absolutePath) => {
17018
+ let found = known.get(absolutePath);
17019
+ if (found === void 0) {
17020
+ found = exists(absolutePath);
17021
+ known.set(absolutePath, found);
17022
+ }
17023
+ return found;
17024
+ };
17025
+ }
17026
+ /** Projected text published so far: every returned delta, concatenated. */
17027
+ get text() {
17028
+ return this.#text;
17029
+ }
17030
+ /** Add native text and return the projected text it makes publishable, possibly empty. */
17031
+ append(text) {
17032
+ this.#native += text;
17033
+ return this.#advance(true);
17034
+ }
17035
+ /** Return the projected text still held at the end of the stream. */
17036
+ flush() {
17037
+ return this.#advance(false);
17038
+ }
17039
+ #advance(holdIncomplete) {
17040
+ const next = this.#verbatim ? void 0 : projectLocalMedia(this.#native, this.#roots, this.#exists, holdIncomplete, this.#relativeImagesOnly);
17041
+ let delta;
17042
+ if (next?.text.startsWith(this.#text)) {
17043
+ delta = next.text.slice(this.#text.length);
17044
+ this.#consumed = next.consumed;
17045
+ } else {
17046
+ this.#verbatim = true;
17047
+ delta = this.#native.slice(this.#consumed);
17048
+ this.#consumed = this.#native.length;
17049
+ }
17050
+ this.#text += delta;
17051
+ return delta;
17052
+ }
17053
+ };
17054
+ function projectLocalMedia(text, roots, exists, holdIncomplete, relativeImagesOnly) {
17055
+ let output = "";
17056
+ let index = 0;
17057
+ let fence = null;
17058
+ while (index < text.length) {
17059
+ if (fence) {
17060
+ const close = closingFenceEnd(text, index, fence.marker, fence.length);
17061
+ if (close === -1)
17062
+ break;
17063
+ output += text.slice(index, close);
17064
+ index = close;
17065
+ fence = null;
17066
+ continue;
17067
+ }
17068
+ const next = earliestIndex([
17069
+ text.indexOf("![", index),
17070
+ text.indexOf("`", index),
17071
+ indexOfLineStartTilde(text, index)
17072
+ ]);
17073
+ if (next === -1)
17074
+ break;
17075
+ output += text.slice(index, next);
17076
+ index = next;
17077
+ const marker = text[next];
17078
+ let markerLength = 1;
17079
+ if (marker === "`" || marker === "~") {
17080
+ let runEnd = next;
17081
+ while (text[runEnd] === marker)
17082
+ runEnd += 1;
17083
+ markerLength = runEnd - next;
17084
+ if (runEnd === text.length && holdIncomplete) {
17085
+ return { text: output, consumed: next };
17086
+ }
17087
+ if (runEnd - next >= 3) {
17088
+ const kind = fenceLineKind(text, next);
17089
+ if (kind === "opaque")
17090
+ break;
17091
+ if (kind === "flat") {
17092
+ fence = { marker, length: runEnd - next };
17093
+ output += text.slice(next, runEnd);
17094
+ index = runEnd;
17095
+ continue;
17096
+ }
17097
+ }
17098
+ if (marker === "~") {
17099
+ output += text.slice(next, runEnd);
17100
+ index = runEnd;
17101
+ continue;
17102
+ }
17103
+ }
17104
+ if (text.startsWith("![", next)) {
17105
+ const image = parseMarkdownImage(text, next);
17106
+ if (image.kind === "text") {
17107
+ output += text.slice(next, image.end);
17108
+ index = image.end;
17109
+ continue;
17110
+ }
17111
+ if (image.kind === "open") {
17112
+ if (!holdIncomplete)
17113
+ break;
17114
+ return { text: output + text.slice(next, image.holdFrom), consumed: image.holdFrom };
17115
+ }
17116
+ const resolved2 = relativeImagesOnly && /^(?:[\\/]|[a-z][a-z\d+.-]*:)/i.test(image.destination.trim()) ? null : resolveLocalMediaPath(image.destination, roots, exists);
17117
+ output += resolved2 === null ? text.slice(next, image.end) : text.slice(next, image.destinationStart) + markdownDestination(resolved2, image.bracketed) + text.slice(image.destinationEnd, image.end);
17118
+ index = image.end;
17119
+ continue;
17120
+ }
17121
+ const code = parseInlineCode(text, next, markerLength);
17122
+ if (code.kind !== "code" || holdIncomplete && code.end === text.length) {
17123
+ if (holdIncomplete && code.kind !== "text")
17124
+ return { text: output, consumed: next };
17125
+ output += text.slice(next, next + markerLength);
17126
+ index = next + markerLength;
17127
+ continue;
17128
+ }
17129
+ const resolved = relativeImagesOnly || markerLength !== 1 || /[\r\n]/u.test(code.content) ? null : resolveLocalMediaPath(code.content, roots, exists);
17130
+ output += resolved === null ? text.slice(next, code.end) : mediaMarkdownImage(resolved);
17131
+ index = code.end;
17132
+ }
17133
+ return { text: output + text.slice(index), consumed: text.length };
17134
+ }
17135
+ function fenceLineKind(text, index) {
17136
+ const prefix = text.slice(text.lastIndexOf("\n", index - 1) + 1, index);
17137
+ if (prefix === "")
17138
+ return "flat";
17139
+ let remaining = prefix.replace(/^[ \t]+/u, "");
17140
+ while (remaining) {
17141
+ const marker = /^(?:>|(?:[-+*]|\d{1,9}[.)])(?=[ \t]))[ \t]*/u.exec(remaining);
17142
+ if (!marker)
17143
+ return null;
17144
+ remaining = remaining.slice(marker[0].length);
17145
+ }
17146
+ return "opaque";
17147
+ }
17148
+ function indexOfLineStartTilde(text, start) {
17149
+ for (let tilde = text.indexOf("~", start); tilde !== -1; tilde = text.indexOf("~", tilde + 1)) {
17150
+ if (fenceLineKind(text, tilde) !== null)
17151
+ return tilde;
17152
+ }
17153
+ return -1;
17154
+ }
17155
+ function closingFenceEnd(text, start, marker, length) {
17156
+ const closing = new RegExp(`^ {0,3}${marker === "`" ? "`" : "~"}{${length},}[ \\t]*\\r?$`, "u");
17157
+ let lineStart = text.indexOf("\n", start);
17158
+ while (lineStart !== -1) {
17159
+ lineStart += 1;
17160
+ const newline2 = text.indexOf("\n", lineStart);
17161
+ const lineEnd = newline2 === -1 ? text.length : newline2;
17162
+ if (closing.test(text.slice(lineStart, lineEnd)))
17163
+ return lineEnd;
17164
+ lineStart = newline2;
17165
+ }
17166
+ return -1;
17167
+ }
17168
+ function earliestIndex(candidates) {
17169
+ let next = -1;
17170
+ for (const candidate of candidates) {
17171
+ if (candidate === -1)
17172
+ continue;
17173
+ if (next === -1 || candidate < next)
17174
+ next = candidate;
17175
+ }
17176
+ return next;
17177
+ }
17178
+ function parseInlineCode(text, start, length) {
17179
+ let index = start + length;
17180
+ while (index < text.length) {
17181
+ const tick = text.indexOf("`", index);
17182
+ if (/\n[^\S\n]*\n/u.test(text.slice(index, tick < 0 ? text.length : tick))) {
17183
+ return { kind: "text" };
17184
+ }
17185
+ if (tick === -1)
17186
+ break;
17187
+ let end = tick + 1;
17188
+ while (text[end] === "`")
17189
+ end += 1;
17190
+ if (end - tick === length) {
17191
+ return { kind: "code", content: text.slice(start + length, tick), end };
17192
+ }
17193
+ index = end;
17194
+ }
17195
+ return { kind: "open" };
17196
+ }
17197
+ function parseMarkdownImage(text, start) {
17198
+ const openLabel = { kind: "open", holdFrom: start + 2 };
17199
+ let index = start + 2;
17200
+ while (index < text.length) {
17201
+ const character = text[index];
17202
+ if (character === "\n")
17203
+ return { kind: "text", end: start + 1 };
17204
+ if (character === "\\") {
17205
+ index += 2;
17206
+ continue;
17207
+ }
17208
+ if (character === "]")
17209
+ break;
17210
+ index += 1;
17211
+ }
17212
+ if (index + 1 >= text.length)
17213
+ return openLabel;
17214
+ if (text[index + 1] !== "(")
17215
+ return { kind: "text", end: start + 1 };
17216
+ const destinationStart = index + 2;
17217
+ const open = { kind: "open", holdFrom: destinationStart };
17218
+ const malformed = { kind: "text", end: destinationStart };
17219
+ index = skipBlanks(text, destinationStart);
17220
+ if (index >= text.length)
17221
+ return open;
17222
+ let destination;
17223
+ let destinationEnd;
17224
+ let bracketed = false;
17225
+ if (text[index] === "<") {
17226
+ bracketed = true;
17227
+ let close = index + 1;
17228
+ while (close < text.length && text[close] !== ">" && text[close] !== "\n")
17229
+ close += 1;
17230
+ if (close >= text.length)
17231
+ return open;
17232
+ if (text[close] === "\n")
17233
+ return malformed;
17234
+ destination = text.slice(index + 1, close);
17235
+ destinationEnd = close + 1;
17236
+ index = destinationEnd;
17237
+ } else {
17238
+ const begin = index;
17239
+ while (index < text.length) {
17240
+ const character = text[index];
17241
+ if (character === "\n" || character === " " || character === " " || character === ")")
17242
+ break;
17243
+ index += character === "\\" ? 2 : 1;
17244
+ }
17245
+ if (index >= text.length)
17246
+ return open;
17247
+ destination = unescapeMarkdown(text.slice(begin, index));
17248
+ destinationEnd = index;
17249
+ }
17250
+ index = skipBlanks(text, index);
17251
+ if (index >= text.length)
17252
+ return open;
17253
+ const opener = text[index];
17254
+ if (opener === '"' || opener === "'" || opener === "(") {
17255
+ const closer = opener === "(" ? ")" : opener;
17256
+ index += 1;
17257
+ while (index < text.length && text[index] !== closer && text[index] !== "\n")
17258
+ index += 1;
17259
+ if (index >= text.length)
17260
+ return open;
17261
+ if (text[index] === "\n")
17262
+ return malformed;
17263
+ index = skipBlanks(text, index + 1);
17264
+ if (index >= text.length)
17265
+ return open;
17266
+ }
17267
+ if (text[index] !== ")")
17268
+ return malformed;
17269
+ return {
17270
+ kind: "image",
17271
+ destination,
17272
+ destinationStart,
17273
+ destinationEnd,
17274
+ end: index + 1,
17275
+ bracketed
17276
+ };
17277
+ }
17278
+ function skipBlanks(text, start) {
17279
+ let index = start;
17280
+ while (text[index] === " " || text[index] === " ")
17281
+ index += 1;
17282
+ return index;
17283
+ }
17284
+ function mediaMarkdownImage(absolutePath) {
17285
+ const name = path7.basename(absolutePath).replaceAll("]", "\\]");
17286
+ return `![${name}](${markdownDestination(absolutePath, false)})`;
17287
+ }
17288
+ function markdownDestination(absolutePath, bracketed) {
17289
+ const encoded = absolutePath.replaceAll("%", "%2525");
17290
+ const destination = /^[A-Za-z]:\\/.test(encoded) ? encoded.replaceAll("\\", "/") : encoded.replaceAll("\\", "\\\\");
17291
+ return bracketed || /[\s()]/.test(destination) ? `<${destination}>` : destination;
17292
+ }
17293
+ function unescapeMarkdown(value) {
17294
+ return value.replace(/\\([\\()])/g, "$1");
17295
+ }
17296
+ function resolveLocalMediaPath(raw, roots, exists = mediaFileExists) {
17297
+ const trimmed = raw.trim();
17298
+ if (trimmed.length === 0 || isRemoteMediaUrl(trimmed))
17299
+ return null;
17300
+ const stripped = stripFileUrl(trimmed);
17301
+ if (stripped === null)
17302
+ return null;
17303
+ if (isAbsoluteMediaPath(stripped)) {
17304
+ const absolute = path7.resolve(stripped);
17305
+ return hasMediaExtension(absolute) && exists(absolute) ? absolute : null;
17306
+ }
17307
+ for (const root of roots) {
17308
+ const absolute = path7.resolve(root, stripped);
17309
+ if (hasMediaExtension(absolute) && exists(absolute))
17310
+ return absolute;
17311
+ }
17312
+ return null;
17313
+ }
17314
+ function isRemoteMediaUrl(value) {
17315
+ return /^(?:https?:|data:|app:|blob:)/i.test(value);
17316
+ }
17317
+ function stripFileUrl(value) {
17318
+ if (!value.toLowerCase().startsWith("file:"))
17319
+ return value;
17320
+ try {
17321
+ return fileURLToPath(value);
17322
+ } catch {
17323
+ return null;
17324
+ }
17325
+ }
17326
+ function isAbsoluteMediaPath(value) {
17327
+ return path7.isAbsolute(value) || /^[a-zA-Z]:[\\/]/.test(value);
17328
+ }
17329
+ function hasMediaExtension(value) {
17330
+ return MEDIA_EXTENSIONS.has(path7.extname(value).toLowerCase());
17331
+ }
17332
+ function mediaFileExists(absolutePath) {
17333
+ try {
17334
+ return existsSync(absolutePath) && statSync(absolutePath).isFile();
17335
+ } catch {
17336
+ return false;
17337
+ }
17338
+ }
17339
+
16980
17340
  // dist/acp-transport.js
16981
17341
  import { spawn, spawnSync } from "node:child_process";
16982
17342
  import { readdir, readFile as readFile3 } from "node:fs/promises";
16983
17343
  import os5 from "node:os";
16984
- import path12 from "node:path";
17344
+ import path13 from "node:path";
16985
17345
  import { Readable, Writable } from "node:stream";
16986
17346
 
16987
17347
  // ../../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js
@@ -21169,8 +21529,8 @@ function parseGrokAvailableCommands(value) {
21169
21529
  });
21170
21530
  }
21171
21531
  function isGrokSkill(command) {
21172
- const path16 = command.meta?.path;
21173
- return typeof path16 === "string" && /(^|[\\/])SKILL\.md$/u.test(path16) || typeof command.meta?.qualifiedName === "string";
21532
+ const path17 = command.meta?.path;
21533
+ return typeof path17 === "string" && /(^|[\\/])SKILL\.md$/u.test(path17) || typeof command.meta?.qualifiedName === "string";
21174
21534
  }
21175
21535
  function grokLiveCommands(native) {
21176
21536
  return native.map((command) => ({
@@ -21181,7 +21541,7 @@ function grokLiveCommands(native) {
21181
21541
  }
21182
21542
 
21183
21543
  // dist/command.js
21184
- import path7 from "node:path";
21544
+ import path8 from "node:path";
21185
21545
  var GrokExecutableError = class extends Error {
21186
21546
  code = "GROK_NOT_FOUND";
21187
21547
  };
@@ -21210,7 +21570,7 @@ function resolveGrokExecutable(input = {}) {
21210
21570
  });
21211
21571
  if (!resolution)
21212
21572
  throw new GrokExecutableError("Grok CLI is not installed");
21213
- return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path7.resolve(resolution.executable);
21573
+ return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path8.resolve(resolution.executable);
21214
21574
  }
21215
21575
  function grokInvocation(command, platform = process.platform, modelId) {
21216
21576
  const arguments_ = ["agent", "--no-leader"];
@@ -21223,11 +21583,11 @@ function grokInvocation(command, platform = process.platform, modelId) {
21223
21583
 
21224
21584
  // dist/grok-fork.js
21225
21585
  import { isDeepStrictEqual } from "node:util";
21226
- import path10 from "node:path";
21586
+ import path11 from "node:path";
21227
21587
 
21228
21588
  // dist/grok-file-change.js
21229
21589
  import { Buffer as Buffer2 } from "node:buffer";
21230
- import path8 from "node:path";
21590
+ import path9 from "node:path";
21231
21591
 
21232
21592
  // ../../../node_modules/diff/libesm/diff/base.js
21233
21593
  var Diff = class {
@@ -21329,16 +21689,16 @@ var Diff = class {
21329
21689
  }
21330
21690
  }
21331
21691
  }
21332
- addToPath(path16, added, removed, oldPosInc, options) {
21333
- const last = path16.lastComponent;
21692
+ addToPath(path17, added, removed, oldPosInc, options) {
21693
+ const last = path17.lastComponent;
21334
21694
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
21335
21695
  return {
21336
- oldPos: path16.oldPos + oldPosInc,
21696
+ oldPos: path17.oldPos + oldPosInc,
21337
21697
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
21338
21698
  };
21339
21699
  } else {
21340
21700
  return {
21341
- oldPos: path16.oldPos + oldPosInc,
21701
+ oldPos: path17.oldPos + oldPosInc,
21342
21702
  lastComponent: { count: 1, added, removed, previousComponent: last }
21343
21703
  };
21344
21704
  }
@@ -21651,13 +22011,13 @@ function isRecord5(value) {
21651
22011
  return typeof value === "object" && value !== null && !Array.isArray(value);
21652
22012
  }
21653
22013
  function validAbsolutePath(value) {
21654
- return typeof value === "string" && path8.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
22014
+ return typeof value === "string" && path9.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
21655
22015
  }
21656
22016
  function displayPath(nativePath, cwd) {
21657
- const resolvedCwd = path8.resolve(cwd);
21658
- const resolvedPath = path8.resolve(nativePath);
21659
- const relative = path8.relative(resolvedCwd, resolvedPath);
21660
- const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path8.sep}`);
22017
+ const resolvedCwd = path9.resolve(cwd);
22018
+ const resolvedPath = path9.resolve(nativePath);
22019
+ const relative = path9.relative(resolvedCwd, resolvedPath);
22020
+ const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path9.sep}`);
21661
22021
  const selected = inside ? relative : resolvedPath;
21662
22022
  const normalized = selected.replaceAll("\\", "/");
21663
22023
  if (normalized.length === 0 || normalized === ".")
@@ -21718,299 +22078,19 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
21718
22078
  }
21719
22079
 
21720
22080
  // dist/local-media-markdown.js
21721
- import { existsSync, statSync } from "node:fs";
21722
22081
  import os4 from "node:os";
21723
- import path9 from "node:path";
21724
- var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
21725
- ".aac",
21726
- ".gif",
21727
- ".jpeg",
21728
- ".jpg",
21729
- ".m4a",
21730
- ".m4v",
21731
- ".mov",
21732
- ".mp3",
21733
- ".mp4",
21734
- ".ogg",
21735
- ".png",
21736
- ".svg",
21737
- ".wav",
21738
- ".webm",
21739
- ".webp"
21740
- ]);
22082
+ import path10 from "node:path";
21741
22083
  function grokMediaResolveRoots(cwd, sessionDirectory) {
21742
- const roots = [path9.resolve(cwd)];
22084
+ const roots = [path10.resolve(cwd)];
21743
22085
  if (sessionDirectory) {
21744
- const session = path9.resolve(sessionDirectory);
21745
- roots.push(session, path9.join(session, "videos"), path9.join(session, "images"));
22086
+ const session = path10.resolve(sessionDirectory);
22087
+ roots.push(session, path10.join(session, "videos"), path10.join(session, "images"));
21746
22088
  }
21747
22089
  const home = process.env.HOME ?? process.env.USERPROFILE ?? os4.homedir();
21748
22090
  if (home)
21749
- roots.push(path9.join(home, "Downloads"));
22091
+ roots.push(path10.join(home, "Downloads"));
21750
22092
  return roots;
21751
22093
  }
21752
- function rewriteLocalMediaMarkdown(text, roots, options = {}) {
21753
- const exists = options.exists ?? mediaFileExists;
21754
- const holdIncomplete = options.holdIncomplete === true;
21755
- let output = "";
21756
- let index = 0;
21757
- let fence = false;
21758
- while (index < text.length) {
21759
- if (fence) {
21760
- const fenceEnd = text.indexOf("```", index);
21761
- if (fenceEnd === -1) {
21762
- output += text.slice(index);
21763
- break;
21764
- }
21765
- output += text.slice(index, fenceEnd + 3);
21766
- index = fenceEnd + 3;
21767
- fence = false;
21768
- continue;
21769
- }
21770
- const fenceStart = text.indexOf("```", index);
21771
- const imageStart = text.indexOf("![", index);
21772
- const tickStart = indexOfInlineTick(text, index);
21773
- const next = earliestIndex([fenceStart, imageStart, tickStart]);
21774
- if (next === -1) {
21775
- output += text.slice(index);
21776
- break;
21777
- }
21778
- output += text.slice(index, next);
21779
- if (next === fenceStart) {
21780
- output += "```";
21781
- index = fenceStart + 3;
21782
- fence = true;
21783
- continue;
21784
- }
21785
- if (next === imageStart) {
21786
- const parsed = parseMarkdownImage(text, imageStart);
21787
- if (!parsed) {
21788
- output += "!";
21789
- index = imageStart + 1;
21790
- continue;
21791
- }
21792
- if (!parsed.closed) {
21793
- output += holdIncomplete ? text.slice(imageStart, parsed.destinationStart) : text.slice(imageStart);
21794
- break;
21795
- }
21796
- const resolved2 = resolveLocalMediaPath(parsed.destination, roots, exists);
21797
- output += text.slice(imageStart, parsed.destinationStart) + formatMarkdownDestination(resolved2 ?? parsed.destination, parsed.bracketed) + text.slice(parsed.destinationEnd, parsed.end);
21798
- index = parsed.end;
21799
- continue;
21800
- }
21801
- const inline = parseInlineCode(text, tickStart);
21802
- if (!inline.closed) {
21803
- if (!holdIncomplete)
21804
- output += text.slice(tickStart);
21805
- break;
21806
- }
21807
- const resolved = resolveLocalMediaPath(inline.content, roots, exists);
21808
- output += resolved ? mediaMarkdownImage(resolved) : text.slice(tickStart, inline.end);
21809
- index = inline.end;
21810
- }
21811
- return output;
21812
- }
21813
- function indexOfInlineTick(text, start) {
21814
- let index = start;
21815
- while (index < text.length) {
21816
- const tick = text.indexOf("`", index);
21817
- if (tick === -1)
21818
- return -1;
21819
- if (text.startsWith("```", tick)) {
21820
- index = tick + 3;
21821
- continue;
21822
- }
21823
- return tick;
21824
- }
21825
- return -1;
21826
- }
21827
- function earliestIndex(candidates) {
21828
- let next = -1;
21829
- for (const candidate of candidates) {
21830
- if (candidate === -1)
21831
- continue;
21832
- if (next === -1 || candidate < next)
21833
- next = candidate;
21834
- }
21835
- return next;
21836
- }
21837
- function parseInlineCode(text, start) {
21838
- let index = start + 1;
21839
- while (index < text.length) {
21840
- const character = text[index];
21841
- if (character === "\n")
21842
- return { closed: false, content: text.slice(start + 1, index), end: index };
21843
- if (character === "`")
21844
- return { closed: true, content: text.slice(start + 1, index), end: index + 1 };
21845
- index += 1;
21846
- }
21847
- return { closed: false, content: text.slice(start + 1), end: text.length };
21848
- }
21849
- function mediaMarkdownImage(absolutePath) {
21850
- const name = path9.basename(absolutePath).replaceAll("]", "\\]");
21851
- return `![${name}](${formatMarkdownDestination(absolutePath, false)})`;
21852
- }
21853
- function parseMarkdownImage(text, start) {
21854
- if (text.slice(start, start + 2) !== "![")
21855
- return null;
21856
- let index = start + 2;
21857
- while (index < text.length) {
21858
- const character = text[index];
21859
- if (character === "\n")
21860
- return null;
21861
- if (character === "\\" && index + 1 < text.length) {
21862
- index += 2;
21863
- continue;
21864
- }
21865
- if (character === "]")
21866
- break;
21867
- index += 1;
21868
- }
21869
- if (text[index] !== "]" || text[index + 1] !== "(")
21870
- return null;
21871
- const destinationStart = index + 2;
21872
- index = destinationStart;
21873
- while (text[index] === " " || text[index] === " ")
21874
- index += 1;
21875
- if (index >= text.length) {
21876
- return {
21877
- closed: false,
21878
- destination: "",
21879
- destinationStart,
21880
- destinationEnd: index,
21881
- end: text.length,
21882
- bracketed: false
21883
- };
21884
- }
21885
- let destination;
21886
- let destinationEnd;
21887
- let bracketed = false;
21888
- if (text[index] === "<") {
21889
- bracketed = true;
21890
- const close = text.indexOf(">", index + 1);
21891
- if (close === -1 || text.slice(index, close).includes("\n")) {
21892
- return {
21893
- closed: false,
21894
- destination: text.slice(index + 1),
21895
- destinationStart,
21896
- destinationEnd: text.length,
21897
- end: text.length,
21898
- bracketed: true
21899
- };
21900
- }
21901
- destination = text.slice(index + 1, close);
21902
- destinationEnd = close + 1;
21903
- index = destinationEnd;
21904
- } else {
21905
- const begin = index;
21906
- while (index < text.length) {
21907
- const character = text[index];
21908
- if (character === "\n" || character === " " || character === " " || character === ")")
21909
- break;
21910
- if (character === "\\" && index + 1 < text.length) {
21911
- index += 2;
21912
- continue;
21913
- }
21914
- index += 1;
21915
- }
21916
- destination = unescapeMarkdown(text.slice(begin, index));
21917
- destinationEnd = index;
21918
- }
21919
- while (text[index] === " " || text[index] === " ")
21920
- index += 1;
21921
- if (text[index] === '"' || text[index] === "'" || text[index] === "(") {
21922
- const closer = text[index] === "(" ? ")" : text[index];
21923
- index += 1;
21924
- while (index < text.length && text[index] !== closer && text[index] !== "\n")
21925
- index += 1;
21926
- if (text[index] !== closer) {
21927
- return {
21928
- closed: false,
21929
- destination,
21930
- destinationStart,
21931
- destinationEnd,
21932
- end: text.length,
21933
- bracketed
21934
- };
21935
- }
21936
- index += 1;
21937
- while (text[index] === " " || text[index] === " ")
21938
- index += 1;
21939
- }
21940
- if (text[index] !== ")") {
21941
- return {
21942
- closed: false,
21943
- destination,
21944
- destinationStart,
21945
- destinationEnd,
21946
- end: text.length,
21947
- bracketed
21948
- };
21949
- }
21950
- return {
21951
- closed: true,
21952
- destination,
21953
- destinationStart,
21954
- destinationEnd,
21955
- end: index + 1,
21956
- bracketed
21957
- };
21958
- }
21959
- function formatMarkdownDestination(destination, bracketed) {
21960
- if (bracketed || /[\s()]/.test(destination))
21961
- return `<${destination}>`;
21962
- return destination.replaceAll(" ", "%20");
21963
- }
21964
- function unescapeMarkdown(value) {
21965
- return value.replace(/\\([\\()])/g, "$1");
21966
- }
21967
- function resolveLocalMediaPath(raw, roots, exists = mediaFileExists) {
21968
- const trimmed = raw.trim();
21969
- if (trimmed.length === 0 || isRemoteMediaUrl(trimmed))
21970
- return null;
21971
- const stripped = stripFileUrl(trimmed);
21972
- if (!hasMediaExtension(stripped))
21973
- return null;
21974
- if (isAbsoluteMediaPath(stripped)) {
21975
- const absolute = path9.resolve(stripped);
21976
- return exists(absolute) ? absolute : null;
21977
- }
21978
- for (const root of roots) {
21979
- const absolute = path9.resolve(root, stripped);
21980
- if (exists(absolute))
21981
- return absolute;
21982
- }
21983
- return null;
21984
- }
21985
- function isRemoteMediaUrl(value) {
21986
- return /^(?:https?:|data:|app:|blob:)/i.test(value);
21987
- }
21988
- function stripFileUrl(value) {
21989
- if (!value.toLowerCase().startsWith("file:"))
21990
- return value;
21991
- try {
21992
- const url2 = new URL(value);
21993
- if (url2.protocol !== "file:")
21994
- return value;
21995
- return decodeURIComponent(url2.pathname);
21996
- } catch {
21997
- return value.replace(/^file:\/\//i, "");
21998
- }
21999
- }
22000
- function isAbsoluteMediaPath(value) {
22001
- return path9.isAbsolute(value) || /^[a-zA-Z]:[\\/]/.test(value);
22002
- }
22003
- function hasMediaExtension(value) {
22004
- const pathname = value.split(/[?#]/, 1)[0] ?? value;
22005
- return MEDIA_EXTENSIONS.has(path9.extname(pathname).toLowerCase());
22006
- }
22007
- function mediaFileExists(absolutePath) {
22008
- try {
22009
- return existsSync(absolutePath) && statSync(absolutePath).isFile();
22010
- } catch {
22011
- return false;
22012
- }
22013
- }
22014
22094
 
22015
22095
  // dist/grok-tool-output.js
22016
22096
  var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
@@ -23011,11 +23091,11 @@ function parseGrokForkResponse(value) {
23011
23091
  }
23012
23092
  function projectRelativePath(value, cwds) {
23013
23093
  const normalized = value.replaceAll("\\", "/");
23014
- if (!path10.isAbsolute(value))
23094
+ if (!path11.isAbsolute(value))
23015
23095
  return normalized;
23016
23096
  for (const cwd of cwds) {
23017
- const relative = path10.relative(path10.resolve(cwd), path10.resolve(value));
23018
- if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path10.sep}`)) {
23097
+ const relative = path11.relative(path11.resolve(cwd), path11.resolve(value));
23098
+ if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path11.sep}`)) {
23019
23099
  return relative.replaceAll("\\", "/");
23020
23100
  }
23021
23101
  }
@@ -23080,8 +23160,8 @@ async function forkGrokSession(input) {
23080
23160
  error: error51("sessionNotFound", "Grok Native Session is unavailable")
23081
23161
  };
23082
23162
  }
23083
- const sourceCwd = path10.resolve(located.cwd);
23084
- const targetCwd = path10.resolve(input.cwd);
23163
+ const sourceCwd = path11.resolve(located.cwd);
23164
+ const targetCwd = path11.resolve(input.cwd);
23085
23165
  const source = await readSnapshot({ ...input, cwd: sourceCwd }, sourceRef.data.nativeSessionId);
23086
23166
  if (!source.ok)
23087
23167
  return source;
@@ -23264,7 +23344,7 @@ function parseGrokCompactResult(value, cancelled = false) {
23264
23344
  }
23265
23345
 
23266
23346
  // dist/grok-rewind.js
23267
- import path11 from "node:path";
23347
+ import path12 from "node:path";
23268
23348
  var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
23269
23349
  function error52(code, message, retryable = false) {
23270
23350
  return { code, message, retryable };
@@ -23337,8 +23417,8 @@ async function rewindGrokLastTurn(input) {
23337
23417
  error: error52("sessionNotFound", "Grok Native Session is unavailable")
23338
23418
  };
23339
23419
  }
23340
- const sourceCwd = path11.resolve(located.cwd);
23341
- const targetCwd = path11.resolve(input.cwd);
23420
+ const sourceCwd = path12.resolve(located.cwd);
23421
+ const targetCwd = path12.resolve(input.cwd);
23342
23422
  if (sourceCwd !== targetCwd) {
23343
23423
  return {
23344
23424
  ok: false,
@@ -23717,8 +23797,14 @@ function signalProcessTree(child, signal) {
23717
23797
  try {
23718
23798
  process.kill(-child.pid, signal);
23719
23799
  } catch (error53) {
23720
- if (!isRecord13(error53) || error53.code !== "ESRCH")
23721
- throw error53;
23800
+ if (!isRecord13(error53) || error53.code === "ESRCH")
23801
+ return;
23802
+ try {
23803
+ child.kill(signal);
23804
+ } catch (fallback) {
23805
+ if (!isRecord13(fallback) || fallback.code !== "ESRCH")
23806
+ throw fallback;
23807
+ }
23722
23808
  }
23723
23809
  }
23724
23810
  function transportEvent(update, metadata) {
@@ -23812,13 +23898,13 @@ function transportEvent(update, metadata) {
23812
23898
  function grokHomeDir(options) {
23813
23899
  const environment = { ...process.env, ...options.environment };
23814
23900
  const home = environment.HOME ?? environment.USERPROFILE ?? os5.homedir();
23815
- return environment.GROK_HOME ?? path12.join(home, ".grok");
23901
+ return environment.GROK_HOME ?? path13.join(home, ".grok");
23816
23902
  }
23817
23903
  function grokNativeSessionDirectory(options, sessionId) {
23818
- return path12.join(grokHomeDir(options), "sessions", encodeURIComponent(path12.resolve(options.cwd)), sessionId);
23904
+ return path13.join(grokHomeDir(options), "sessions", encodeURIComponent(path13.resolve(options.cwd)), sessionId);
23819
23905
  }
23820
23906
  function nativeSessionFile(options, sessionId, fileName) {
23821
- return path12.join(grokNativeSessionDirectory(options, sessionId), fileName);
23907
+ return path13.join(grokNativeSessionDirectory(options, sessionId), fileName);
23822
23908
  }
23823
23909
  function nativeHistoryPath(options, sessionId) {
23824
23910
  return nativeSessionFile(options, sessionId, "updates.jsonl");
@@ -23838,7 +23924,7 @@ async function locateGrokNativeSession(options, sessionId) {
23838
23924
  return null;
23839
23925
  let entries;
23840
23926
  try {
23841
- entries = await readdir(path12.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
23927
+ entries = await readdir(path13.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
23842
23928
  } catch (error53) {
23843
23929
  if (isMissingFile(error53))
23844
23930
  return null;
@@ -23852,7 +23938,7 @@ async function locateGrokNativeSession(options, sessionId) {
23852
23938
  continue;
23853
23939
  let summaryRaw;
23854
23940
  try {
23855
- summaryRaw = await readFile3(path12.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
23941
+ summaryRaw = await readFile3(path13.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
23856
23942
  } catch (error53) {
23857
23943
  if (isMissingFile(error53) || isRecord13(error53) && error53.code === "ENOTDIR")
23858
23944
  continue;
@@ -23869,8 +23955,8 @@ async function locateGrokNativeSession(options, sessionId) {
23869
23955
  if (!isRecord13(parsed))
23870
23956
  continue;
23871
23957
  const info = parsed.info;
23872
- const cwd = isRecord13(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path12.resolve(info.cwd) : path12.resolve(decodeURIComponent(entry.name));
23873
- const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path12.resolve(parsed.source_workspace_dir) : void 0;
23958
+ const cwd = isRecord13(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path13.resolve(info.cwd) : path13.resolve(decodeURIComponent(entry.name));
23959
+ const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path13.resolve(parsed.source_workspace_dir) : void 0;
23874
23960
  matches.push({
23875
23961
  cwd,
23876
23962
  ...sourceWorkspaceDir ? { sourceWorkspaceDir } : {}
@@ -23880,7 +23966,7 @@ async function locateGrokNativeSession(options, sessionId) {
23880
23966
  }
23881
23967
  async function readGrokNativeHistory(options, sessionId) {
23882
23968
  try {
23883
- return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd: path12.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
23969
+ return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd: path13.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
23884
23970
  } catch (error53) {
23885
23971
  if (isMissingFile(error53))
23886
23972
  return [];
@@ -24379,7 +24465,7 @@ var GrokAcpTransport = class {
24379
24465
  // dist/session-import.js
24380
24466
  import { createReadStream as createReadStream2 } from "node:fs";
24381
24467
  import { opendir as opendir2, readFile as readFile4, stat } from "node:fs/promises";
24382
- import path13 from "node:path";
24468
+ import path14 from "node:path";
24383
24469
  import { createInterface as createInterface2 } from "node:readline";
24384
24470
 
24385
24471
  // ../../harness-adapter/dist/session-import.js
@@ -24600,7 +24686,7 @@ var GrokSessionImport = class {
24600
24686
  const active = /* @__PURE__ */ new Set();
24601
24687
  let entries;
24602
24688
  try {
24603
- entries = await readJson(path13.join(this.#home(), "active_sessions.json"), signal);
24689
+ entries = await readJson(path14.join(this.#home(), "active_sessions.json"), signal);
24604
24690
  } catch (error53) {
24605
24691
  signal.throwIfAborted();
24606
24692
  if (isStorageAccessError(error53))
@@ -24617,7 +24703,7 @@ var GrokSessionImport = class {
24617
24703
  }
24618
24704
  /** Session ID to every directory claiming it. Enumerated links are not followed. */
24619
24705
  async #sessionDirectories(signal) {
24620
- const root = path13.join(this.#home(), "sessions");
24706
+ const root = path14.join(this.#home(), "sessions");
24621
24707
  const found = /* @__PURE__ */ new Map();
24622
24708
  const info = await optionalLstat(root);
24623
24709
  if (!info)
@@ -24628,7 +24714,7 @@ var GrokSessionImport = class {
24628
24714
  signal.throwIfAborted();
24629
24715
  if (!workspace.isDirectory())
24630
24716
  continue;
24631
- const workspaceDirectory = path13.join(root, workspace.name);
24717
+ const workspaceDirectory = path14.join(root, workspace.name);
24632
24718
  const sessions = await opendir2(workspaceDirectory).catch((error53) => {
24633
24719
  if (isMissingFileError(error53))
24634
24720
  return null;
@@ -24641,7 +24727,7 @@ var GrokSessionImport = class {
24641
24727
  if (!session.isDirectory())
24642
24728
  continue;
24643
24729
  const directories = found.get(session.name) ?? [];
24644
- directories.push(path13.join(workspaceDirectory, session.name));
24730
+ directories.push(path14.join(workspaceDirectory, session.name));
24645
24731
  found.set(session.name, directories);
24646
24732
  }
24647
24733
  }
@@ -24649,10 +24735,10 @@ var GrokSessionImport = class {
24649
24735
  }
24650
24736
  async #candidate(sessionDirectory, active, signal) {
24651
24737
  signal.throwIfAborted();
24652
- const nativeSessionId = path13.basename(sessionDirectory);
24738
+ const nativeSessionId = path14.basename(sessionDirectory);
24653
24739
  const files = [
24654
- path13.join(sessionDirectory, "summary.json"),
24655
- path13.join(sessionDirectory, "updates.jsonl")
24740
+ path14.join(sessionDirectory, "summary.json"),
24741
+ path14.join(sessionDirectory, "updates.jsonl")
24656
24742
  ];
24657
24743
  return readStableFiles(files, async ([summaryInfo, updates]) => {
24658
24744
  if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
@@ -24664,10 +24750,10 @@ var GrokSessionImport = class {
24664
24750
  if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
24665
24751
  return null;
24666
24752
  const nativeCwd = summary.info.cwd;
24667
- if (typeof nativeCwd !== "string" || !path13.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
24753
+ if (typeof nativeCwd !== "string" || !path14.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
24668
24754
  return null;
24669
- const cwd = path13.resolve(nativeCwd);
24670
- if (encodeURIComponent(cwd) !== path13.basename(path13.dirname(sessionDirectory)))
24755
+ const cwd = path14.resolve(nativeCwd);
24756
+ if (encodeURIComponent(cwd) !== path14.basename(path14.dirname(sessionDirectory)))
24671
24757
  return null;
24672
24758
  if (!(await stat(cwd)).isDirectory())
24673
24759
  return null;
@@ -24989,9 +25075,17 @@ function stateForGrokModel(modelState, nativeState, model2 = modelState.currentM
24989
25075
  // dist/grok-credits.js
24990
25076
  import { readFile as readFile5 } from "node:fs/promises";
24991
25077
  import os6 from "node:os";
24992
- import path14 from "node:path";
25078
+ import path15 from "node:path";
24993
25079
  var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
25080
+ var GROK_SETTINGS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/settings";
24994
25081
  var REQUEST_TIMEOUT_MS = 15e3;
25082
+ var PLAN_TIMEOUT_MS = 2e3;
25083
+ function parseGrokPlan(value) {
25084
+ if (!isRecord16(value) || typeof value.subscription_tier_display !== "string")
25085
+ return void 0;
25086
+ const plan = value.subscription_tier_display.trim();
25087
+ return plan && plan.length <= 128 && !/[\u0000-\u001f\u007f]/u.test(plan) ? plan : void 0;
25088
+ }
24995
25089
  function isRecord16(value) {
24996
25090
  return typeof value === "object" && value !== null && !Array.isArray(value);
24997
25091
  }
@@ -25009,7 +25103,7 @@ function nonNegativeCentValue(value) {
25009
25103
  return amount;
25010
25104
  }
25011
25105
  function grokHome2(environment) {
25012
- return environment.GROK_HOME ?? path14.join(environment.HOME ?? environment.USERPROFILE ?? os6.homedir(), ".grok");
25106
+ return environment.GROK_HOME ?? path15.join(environment.HOME ?? environment.USERPROFILE ?? os6.homedir(), ".grok");
25013
25107
  }
25014
25108
  function periodTypeFrom(value) {
25015
25109
  if (typeof value !== "string")
@@ -25101,26 +25195,30 @@ async function fetchGrokAccount(input = {}) {
25101
25195
  if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
25102
25196
  return null;
25103
25197
  const now = input.now ?? /* @__PURE__ */ new Date();
25104
- const authPath = path14.join(grokHome2(environment), "auth.json");
25198
+ const authPath = path15.join(grokHome2(environment), "auth.json");
25105
25199
  const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile5(authPath, "utf8");
25106
25200
  const token = selectAccessToken(JSON.parse(raw), now);
25107
25201
  if (!token)
25108
25202
  return null;
25109
25203
  const fetchImpl = input.fetch ?? fetch;
25110
- const response = await fetchImpl(GROK_CREDITS_ENDPOINT, {
25204
+ const request = (url2, timeoutMs) => fetchImpl(url2, {
25111
25205
  method: "GET",
25112
25206
  headers: {
25113
25207
  Authorization: `Bearer ${token.key}`,
25114
25208
  "x-xai-token-auth": "xai-grok-cli",
25115
25209
  Accept: "application/json"
25116
25210
  },
25117
- signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]) : AbortSignal.timeout(REQUEST_TIMEOUT_MS)
25211
+ signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs)
25118
25212
  });
25213
+ const credits = request(GROK_CREDITS_ENDPOINT, REQUEST_TIMEOUT_MS);
25214
+ 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);
25215
+ const response = await credits;
25119
25216
  if (!response.ok)
25120
25217
  return null;
25121
25218
  const snapshot = parseGrokCreditsResponse(await response.json(), now.toISOString());
25122
25219
  if (!snapshot)
25123
25220
  return null;
25221
+ const planName = await plan;
25124
25222
  return {
25125
25223
  credits: {
25126
25224
  usedPercent: snapshot.usedPercent,
@@ -25129,14 +25227,15 @@ async function fetchGrokAccount(input = {}) {
25129
25227
  ...snapshot.productUsage ? { productUsage: [...snapshot.productUsage] } : {}
25130
25228
  },
25131
25229
  ...token.email ? { email: token.email } : {},
25132
- ...token.label ? { label: token.label } : {}
25230
+ ...token.label ? { label: token.label } : {},
25231
+ ...planName ? { plan: planName } : {}
25133
25232
  };
25134
25233
  } catch {
25135
25234
  return null;
25136
25235
  }
25137
25236
  }
25138
25237
  async function fetchGrokCredits(input = {}) {
25139
- const account = await fetchGrokAccount(input);
25238
+ const account = await fetchGrokAccount({ ...input, includePlan: false });
25140
25239
  if (!account?.credits)
25141
25240
  return null;
25142
25241
  const { credits } = account;
@@ -25645,8 +25744,7 @@ var GrokHarnessSession = class {
25645
25744
  usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
25646
25745
  agent: null,
25647
25746
  agentMessageId: null,
25648
- rawAgentText: "",
25649
- projectedAgentText: "",
25747
+ agentMedia: null,
25650
25748
  reasoning: null,
25651
25749
  reasoningMessageId: null,
25652
25750
  compactionItem: null,
@@ -25735,8 +25833,7 @@ var GrokHarnessSession = class {
25735
25833
  questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
25736
25834
  agent: null,
25737
25835
  agentMessageId: null,
25738
- rawAgentText: "",
25739
- projectedAgentText: "",
25836
+ agentMedia: null,
25740
25837
  reasoning: null,
25741
25838
  reasoningMessageId: null,
25742
25839
  compactionItem: null,
@@ -26089,19 +26186,16 @@ var GrokHarnessSession = class {
26089
26186
  itemId: hostItemIdSchema.parse(this.#randomUUID()),
26090
26187
  text: ""
26091
26188
  };
26092
- active.rawAgentText = "";
26093
- active.projectedAgentText = "";
26189
+ active.agentMedia = new LocalMediaMarkdownStream(this.#mediaRoots);
26094
26190
  this.#event({ type: "item.started", turnId: active.command.turnId, item: active.agent });
26095
26191
  }
26096
- active.rawAgentText += text;
26097
- const projected = rewriteLocalMediaMarkdown(active.rawAgentText, this.#mediaRoots, {
26098
- holdIncomplete: true
26099
- });
26100
- const delta = projected.startsWith(active.projectedAgentText) ? projected.slice(active.projectedAgentText.length) : text;
26101
- if (delta.length === 0)
26192
+ const delta = active.agentMedia?.append(text) ?? "";
26193
+ this.#publishAgent(active, delta);
26194
+ }
26195
+ #publishAgent(active, delta) {
26196
+ if (!active.agent || !active.agentMedia || !delta)
26102
26197
  return;
26103
- active.projectedAgentText += delta;
26104
- active.agent = { ...active.agent, text: active.projectedAgentText };
26198
+ active.agent = { ...active.agent, text: active.agentMedia.text };
26105
26199
  this.#event({
26106
26200
  type: "item.updated",
26107
26201
  turnId: active.command.turnId,
@@ -26322,25 +26416,12 @@ var GrokHarnessSession = class {
26322
26416
  }
26323
26417
  #completeAgent(active, outcome) {
26324
26418
  const item = active.agent;
26325
- if (item && active.rawAgentText.length > 0) {
26326
- const flushed = rewriteLocalMediaMarkdown(active.rawAgentText, this.#mediaRoots);
26327
- const delta = flushed.startsWith(item.text) ? flushed.slice(item.text.length) : "";
26328
- if (delta.length > 0) {
26329
- active.projectedAgentText = flushed;
26330
- active.agent = { ...item, text: flushed };
26331
- this.#event({
26332
- type: "item.updated",
26333
- turnId: active.command.turnId,
26334
- itemId: item.itemId,
26335
- update: { type: "text.append", text: delta }
26336
- });
26337
- }
26338
- }
26419
+ if (item && active.agentMedia)
26420
+ this.#publishAgent(active, active.agentMedia.flush());
26339
26421
  const completed = active.agent ?? item;
26340
26422
  active.agent = null;
26341
26423
  active.agentMessageId = null;
26342
- active.rawAgentText = "";
26343
- active.projectedAgentText = "";
26424
+ active.agentMedia = null;
26344
26425
  if (completed)
26345
26426
  this.#completeItem(active, completed, outcome);
26346
26427
  }
@@ -26590,7 +26671,7 @@ var GrokAdapter = class {
26590
26671
  async inspect(input = {}) {
26591
26672
  if (this.#closePromise)
26592
26673
  return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
26593
- const cwd = path15.resolve(input.cwd ?? process.cwd());
26674
+ const cwd = path16.resolve(input.cwd ?? process.cwd());
26594
26675
  if (!input.refresh) {
26595
26676
  const cached2 = this.#inspectionCache.get(cwd);
26596
26677
  if (cached2)
@@ -26652,7 +26733,7 @@ var GrokAdapter = class {
26652
26733
  }
26653
26734
  };
26654
26735
  }
26655
- const cwd = path15.resolve(input.cwd);
26736
+ const cwd = path16.resolve(input.cwd);
26656
26737
  const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
26657
26738
  if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
26658
26739
  return {