@codexhost/cli-linux-x64 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/app/codexhost-distribution.json +1 -1
- package/app/host-runtime.mjs +347 -226
- package/app/renderer-extension.js +67 -10
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
package/app/host-runtime.mjs
CHANGED
|
@@ -773,10 +773,10 @@ function mergeDefs(...defs) {
|
|
|
773
773
|
function cloneDef(schema) {
|
|
774
774
|
return mergeDefs(schema._zod.def);
|
|
775
775
|
}
|
|
776
|
-
function getElementAtPath(obj,
|
|
777
|
-
if (!
|
|
776
|
+
function getElementAtPath(obj, path19) {
|
|
777
|
+
if (!path19)
|
|
778
778
|
return obj;
|
|
779
|
-
return
|
|
779
|
+
return path19.reduce((acc, key) => acc?.[key], obj);
|
|
780
780
|
}
|
|
781
781
|
function promiseAllObject(promisesObj) {
|
|
782
782
|
const keys = Object.keys(promisesObj);
|
|
@@ -1185,11 +1185,11 @@ function explicitlyAborted(x2, startIndex = 0) {
|
|
|
1185
1185
|
}
|
|
1186
1186
|
return false;
|
|
1187
1187
|
}
|
|
1188
|
-
function prefixIssues(
|
|
1188
|
+
function prefixIssues(path19, issues) {
|
|
1189
1189
|
return issues.map((iss) => {
|
|
1190
1190
|
var _a4;
|
|
1191
1191
|
(_a4 = iss).path ?? (_a4.path = []);
|
|
1192
|
-
iss.path.unshift(
|
|
1192
|
+
iss.path.unshift(path19);
|
|
1193
1193
|
return iss;
|
|
1194
1194
|
});
|
|
1195
1195
|
}
|
|
@@ -1336,16 +1336,16 @@ function flattenError(error52, mapper = (issue2) => issue2.message) {
|
|
|
1336
1336
|
}
|
|
1337
1337
|
function formatError(error52, mapper = (issue2) => issue2.message) {
|
|
1338
1338
|
const fieldErrors = { _errors: [] };
|
|
1339
|
-
const processError = (error53,
|
|
1339
|
+
const processError = (error53, path19 = []) => {
|
|
1340
1340
|
for (const issue2 of error53.issues) {
|
|
1341
1341
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1342
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1342
|
+
issue2.errors.map((issues) => processError({ issues }, [...path19, ...issue2.path]));
|
|
1343
1343
|
} else if (issue2.code === "invalid_key") {
|
|
1344
|
-
processError({ issues: issue2.issues }, [...
|
|
1344
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1345
1345
|
} else if (issue2.code === "invalid_element") {
|
|
1346
|
-
processError({ issues: issue2.issues }, [...
|
|
1346
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1347
1347
|
} else {
|
|
1348
|
-
const fullpath = [...
|
|
1348
|
+
const fullpath = [...path19, ...issue2.path];
|
|
1349
1349
|
if (fullpath.length === 0) {
|
|
1350
1350
|
fieldErrors._errors.push(mapper(issue2));
|
|
1351
1351
|
} else {
|
|
@@ -1372,17 +1372,17 @@ function formatError(error52, mapper = (issue2) => issue2.message) {
|
|
|
1372
1372
|
}
|
|
1373
1373
|
function treeifyError(error52, mapper = (issue2) => issue2.message) {
|
|
1374
1374
|
const result = { errors: [] };
|
|
1375
|
-
const processError = (error53,
|
|
1375
|
+
const processError = (error53, path19 = []) => {
|
|
1376
1376
|
var _a4, _b2;
|
|
1377
1377
|
for (const issue2 of error53.issues) {
|
|
1378
1378
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1379
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1379
|
+
issue2.errors.map((issues) => processError({ issues }, [...path19, ...issue2.path]));
|
|
1380
1380
|
} else if (issue2.code === "invalid_key") {
|
|
1381
|
-
processError({ issues: issue2.issues }, [...
|
|
1381
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1382
1382
|
} else if (issue2.code === "invalid_element") {
|
|
1383
|
-
processError({ issues: issue2.issues }, [...
|
|
1383
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1384
1384
|
} else {
|
|
1385
|
-
const fullpath = [...
|
|
1385
|
+
const fullpath = [...path19, ...issue2.path];
|
|
1386
1386
|
if (fullpath.length === 0) {
|
|
1387
1387
|
result.errors.push(mapper(issue2));
|
|
1388
1388
|
continue;
|
|
@@ -1414,8 +1414,8 @@ function treeifyError(error52, mapper = (issue2) => issue2.message) {
|
|
|
1414
1414
|
}
|
|
1415
1415
|
function toDotPath(_path) {
|
|
1416
1416
|
const segs = [];
|
|
1417
|
-
const
|
|
1418
|
-
for (const seg of
|
|
1417
|
+
const path19 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1418
|
+
for (const seg of path19) {
|
|
1419
1419
|
if (typeof seg === "number")
|
|
1420
1420
|
segs.push(`[${seg}]`);
|
|
1421
1421
|
else if (typeof seg === "symbol")
|
|
@@ -14107,13 +14107,13 @@ function resolveRef(ref, ctx) {
|
|
|
14107
14107
|
if (!ref.startsWith("#")) {
|
|
14108
14108
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14109
14109
|
}
|
|
14110
|
-
const
|
|
14111
|
-
if (
|
|
14110
|
+
const path19 = ref.slice(1).split("/").filter(Boolean);
|
|
14111
|
+
if (path19.length === 0) {
|
|
14112
14112
|
return ctx.rootSchema;
|
|
14113
14113
|
}
|
|
14114
14114
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14115
|
-
if (
|
|
14116
|
-
const key =
|
|
14115
|
+
if (path19[0] === defsKey) {
|
|
14116
|
+
const key = path19[1];
|
|
14117
14117
|
if (!key || !ctx.defs[key]) {
|
|
14118
14118
|
throw new Error(`Reference not found: ${ref}`);
|
|
14119
14119
|
}
|
|
@@ -44838,16 +44838,16 @@ var AbstractApiClient = class {
|
|
|
44838
44838
|
* Shared POST leg of both C→S carriers (callUnary/respond): JSON body,
|
|
44839
44839
|
* optional default timeout merged with the caller's external signal, non-2xx → transport throw.
|
|
44840
44840
|
*/
|
|
44841
|
-
async postJson(
|
|
44841
|
+
async postJson(path19, body, signal, timeoutPolicy = "default") {
|
|
44842
44842
|
const requestSignal = timeoutPolicy === "default" ? signal === void 0 ? AbortSignal.timeout(this.timeoutMs) : AbortSignal.any([AbortSignal.timeout(this.timeoutMs), signal]) : signal;
|
|
44843
|
-
const response = await this.doFetch(new URL(
|
|
44843
|
+
const response = await this.doFetch(new URL(path19, this.resolveBase()), {
|
|
44844
44844
|
method: "POST",
|
|
44845
44845
|
headers: { "content-type": "application/json" },
|
|
44846
44846
|
body: JSON.stringify(body),
|
|
44847
44847
|
...requestSignal === void 0 ? {} : { signal: requestSignal }
|
|
44848
44848
|
});
|
|
44849
44849
|
if (!response.ok)
|
|
44850
|
-
throw new Error(`transport failure for ${
|
|
44850
|
+
throw new Error(`transport failure for ${path19}: HTTP ${response.status}`);
|
|
44851
44851
|
return response;
|
|
44852
44852
|
}
|
|
44853
44853
|
/**
|
|
@@ -44883,10 +44883,10 @@ var AbstractApiClient = class {
|
|
|
44883
44883
|
* either parse level is reported and skipped (one corrupt frame must not kill the stream; the
|
|
44884
44884
|
* client's gap detection covers whatever the frame carried).
|
|
44885
44885
|
*/
|
|
44886
|
-
async *readSse(
|
|
44887
|
-
const response = await this.doFetch(new URL(
|
|
44886
|
+
async *readSse(path19, signal, frameSchema, onOpen) {
|
|
44887
|
+
const response = await this.doFetch(new URL(path19, this.resolveBase()), { signal });
|
|
44888
44888
|
if (!response.ok || response.body === null)
|
|
44889
|
-
throw new Error(`transport failure for ${
|
|
44889
|
+
throw new Error(`transport failure for ${path19}: HTTP ${response.status}`);
|
|
44890
44890
|
onOpen?.();
|
|
44891
44891
|
const reader = response.body.getReader();
|
|
44892
44892
|
const decoder2 = new TextDecoder();
|
|
@@ -44910,7 +44910,7 @@ var AbstractApiClient = class {
|
|
|
44910
44910
|
full = serverRequestSchema.parse(JSON.parse(data));
|
|
44911
44911
|
frame = frameSchema.parse(full.payload);
|
|
44912
44912
|
} catch (error52) {
|
|
44913
|
-
console.error(`[apiproxy] dropping malformed SSE frame on ${
|
|
44913
|
+
console.error(`[apiproxy] dropping malformed SSE frame on ${path19}:`, error52);
|
|
44914
44914
|
continue;
|
|
44915
44915
|
}
|
|
44916
44916
|
this.onEnvelope(full);
|
|
@@ -45485,16 +45485,16 @@ var Diff = class {
|
|
|
45485
45485
|
}
|
|
45486
45486
|
}
|
|
45487
45487
|
}
|
|
45488
|
-
addToPath(
|
|
45489
|
-
const last =
|
|
45488
|
+
addToPath(path19, added, removed, oldPosInc, options) {
|
|
45489
|
+
const last = path19.lastComponent;
|
|
45490
45490
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
45491
45491
|
return {
|
|
45492
|
-
oldPos:
|
|
45492
|
+
oldPos: path19.oldPos + oldPosInc,
|
|
45493
45493
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
45494
45494
|
};
|
|
45495
45495
|
} else {
|
|
45496
45496
|
return {
|
|
45497
|
-
oldPos:
|
|
45497
|
+
oldPos: path19.oldPos + oldPosInc,
|
|
45498
45498
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
45499
45499
|
};
|
|
45500
45500
|
}
|
|
@@ -47246,7 +47246,7 @@ var packageMetadata3 = {
|
|
|
47246
47246
|
|
|
47247
47247
|
// packages/adapters/grok/dist/grok-adapter.js
|
|
47248
47248
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
47249
|
-
import
|
|
47249
|
+
import path11 from "node:path";
|
|
47250
47250
|
|
|
47251
47251
|
// packages/adapters/grok/dist/acp-transport.js
|
|
47252
47252
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
@@ -51877,6 +51877,81 @@ var GrokAcpTransport = class {
|
|
|
51877
51877
|
}
|
|
51878
51878
|
};
|
|
51879
51879
|
|
|
51880
|
+
// packages/adapters/grok/dist/grok-file-change.js
|
|
51881
|
+
import { Buffer as Buffer4 } from "node:buffer";
|
|
51882
|
+
import path9 from "node:path";
|
|
51883
|
+
var DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT = 4 * 1024 * 1024;
|
|
51884
|
+
var MAX_GROK_FILE_CHANGES_PER_TOOL = 32;
|
|
51885
|
+
function isRecord10(value) {
|
|
51886
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51887
|
+
}
|
|
51888
|
+
function validAbsolutePath(value) {
|
|
51889
|
+
return typeof value === "string" && path9.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
|
|
51890
|
+
}
|
|
51891
|
+
function displayPath2(nativePath, cwd) {
|
|
51892
|
+
const resolvedCwd = path9.resolve(cwd);
|
|
51893
|
+
const resolvedPath = path9.resolve(nativePath);
|
|
51894
|
+
const relative = path9.relative(resolvedCwd, resolvedPath);
|
|
51895
|
+
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path9.sep}`);
|
|
51896
|
+
const selected = inside ? relative : resolvedPath;
|
|
51897
|
+
const normalized = selected.replaceAll("\\", "/");
|
|
51898
|
+
if (normalized.length === 0 || normalized === ".")
|
|
51899
|
+
return null;
|
|
51900
|
+
return { path: normalized, absolute: !inside };
|
|
51901
|
+
}
|
|
51902
|
+
function projectDiff(value, cwd, remainingTextBytes) {
|
|
51903
|
+
if (!validAbsolutePath(value.path) || typeof value.oldText !== "string" && value.oldText !== null || typeof value.newText !== "string") {
|
|
51904
|
+
return null;
|
|
51905
|
+
}
|
|
51906
|
+
const oldText = value.oldText;
|
|
51907
|
+
const newText = value.newText;
|
|
51908
|
+
if (typeof oldText === "string" && oldText === newText || oldText === null && newText === "") {
|
|
51909
|
+
return null;
|
|
51910
|
+
}
|
|
51911
|
+
const textBytes = Buffer4.byteLength(oldText ?? "", "utf8") + Buffer4.byteLength(newText, "utf8");
|
|
51912
|
+
if (textBytes > remainingTextBytes)
|
|
51913
|
+
return null;
|
|
51914
|
+
const displayed = displayPath2(value.path, cwd);
|
|
51915
|
+
if (!displayed)
|
|
51916
|
+
return null;
|
|
51917
|
+
const kind = oldText === null ? "add" : "update";
|
|
51918
|
+
const oldHeader = kind === "add" ? "/dev/null" : displayed.absolute ? displayed.path : `a/${displayed.path}`;
|
|
51919
|
+
const newHeader = displayed.absolute ? displayed.path : `b/${displayed.path}`;
|
|
51920
|
+
return {
|
|
51921
|
+
change: {
|
|
51922
|
+
path: displayed.path,
|
|
51923
|
+
kind,
|
|
51924
|
+
unifiedDiff: createTwoFilesPatch(oldHeader, newHeader, oldText ?? "", newText, "", "", {
|
|
51925
|
+
context: 3
|
|
51926
|
+
})
|
|
51927
|
+
},
|
|
51928
|
+
textBytes
|
|
51929
|
+
};
|
|
51930
|
+
}
|
|
51931
|
+
function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT) {
|
|
51932
|
+
if (!Number.isSafeInteger(textLimit) || textLimit <= 0 || !Array.isArray(content))
|
|
51933
|
+
return null;
|
|
51934
|
+
const candidates2 = [];
|
|
51935
|
+
for (const entry of content) {
|
|
51936
|
+
if (isRecord10(entry) && entry.type === "diff")
|
|
51937
|
+
candidates2.push(entry);
|
|
51938
|
+
}
|
|
51939
|
+
if (candidates2.length === 0 || candidates2.length > MAX_GROK_FILE_CHANGES_PER_TOOL)
|
|
51940
|
+
return null;
|
|
51941
|
+
const changes = [];
|
|
51942
|
+
const paths = /* @__PURE__ */ new Set();
|
|
51943
|
+
let textBytes = 0;
|
|
51944
|
+
for (const candidate of candidates2) {
|
|
51945
|
+
const projected = projectDiff(candidate, cwd, textLimit - textBytes);
|
|
51946
|
+
if (!projected || paths.has(projected.change.path))
|
|
51947
|
+
return null;
|
|
51948
|
+
textBytes += projected.textBytes;
|
|
51949
|
+
paths.add(projected.change.path);
|
|
51950
|
+
changes.push(projected.change);
|
|
51951
|
+
}
|
|
51952
|
+
return changes;
|
|
51953
|
+
}
|
|
51954
|
+
|
|
51880
51955
|
// packages/adapters/grok/dist/grok-history.js
|
|
51881
51956
|
function jsonValue(value) {
|
|
51882
51957
|
try {
|
|
@@ -51910,7 +51985,7 @@ function isSyntheticGrokUserText(text) {
|
|
|
51910
51985
|
function isSyntheticGrokTurnKey(nativeTurnKey3) {
|
|
51911
51986
|
return taskCompletedTurnKeyPattern.test(nativeTurnKey3);
|
|
51912
51987
|
}
|
|
51913
|
-
function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
51988
|
+
function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = []) {
|
|
51914
51989
|
const knownByNativeKey = new Map(knownTurnRefs.filter((ref) => ref.harnessId === harnessId && ref.nativeSessionId === sessionId).map((ref) => [ref.nativeTurnKey, ref]));
|
|
51915
51990
|
const turns = [];
|
|
51916
51991
|
let input = "";
|
|
@@ -51939,6 +52014,32 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
51939
52014
|
}
|
|
51940
52015
|
tools.clear();
|
|
51941
52016
|
};
|
|
52017
|
+
const completeTool = (callId, status, content) => {
|
|
52018
|
+
const tool = tools.get(callId);
|
|
52019
|
+
if (!tool)
|
|
52020
|
+
return;
|
|
52021
|
+
tools.delete(callId);
|
|
52022
|
+
const outcome = status === "failed" ? {
|
|
52023
|
+
status: "failed",
|
|
52024
|
+
error: {
|
|
52025
|
+
code: "nativeFailure",
|
|
52026
|
+
message: `Grok Tool '${tool.toolName}' failed`,
|
|
52027
|
+
retryable: false
|
|
52028
|
+
}
|
|
52029
|
+
} : { status: "succeeded" };
|
|
52030
|
+
items.push({ item: tool, outcome });
|
|
52031
|
+
if (status !== "completed")
|
|
52032
|
+
return;
|
|
52033
|
+
const changes = projectGrokFileChanges(content, cwd);
|
|
52034
|
+
if (!changes)
|
|
52035
|
+
return;
|
|
52036
|
+
const fileItem = {
|
|
52037
|
+
type: "fileChange",
|
|
52038
|
+
itemId: stableId("file-change", turnIndex, ++messageIndex),
|
|
52039
|
+
changes
|
|
52040
|
+
};
|
|
52041
|
+
items.push({ item: fileItem, outcome: { status: "succeeded" } });
|
|
52042
|
+
};
|
|
51942
52043
|
const completeTurn = (outcome, terminalKey) => {
|
|
51943
52044
|
if (input.length === 0)
|
|
51944
52045
|
return;
|
|
@@ -52021,6 +52122,9 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
52021
52122
|
namespace: "grok",
|
|
52022
52123
|
arguments: jsonValue(event.rawInput)
|
|
52023
52124
|
});
|
|
52125
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52126
|
+
completeTool(event.callId, event.status, event.content);
|
|
52127
|
+
}
|
|
52024
52128
|
} else if (event.type === "tool.update") {
|
|
52025
52129
|
const tool = tools.get(event.callId);
|
|
52026
52130
|
if (tool && event.rawOutput !== void 0) {
|
|
@@ -52029,6 +52133,9 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
52029
52133
|
output: { content: [{ type: "text", text: String(event.rawOutput) }] }
|
|
52030
52134
|
});
|
|
52031
52135
|
}
|
|
52136
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52137
|
+
completeTool(event.callId, event.status, event.content);
|
|
52138
|
+
}
|
|
52032
52139
|
}
|
|
52033
52140
|
}
|
|
52034
52141
|
completeTurn({ status: "unknown", reason: "Grok Native history has no terminal signal" });
|
|
@@ -52036,7 +52143,7 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
52036
52143
|
}
|
|
52037
52144
|
|
|
52038
52145
|
// packages/adapters/grok/dist/grok-models.js
|
|
52039
|
-
function
|
|
52146
|
+
function isRecord11(value) {
|
|
52040
52147
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52041
52148
|
}
|
|
52042
52149
|
function nonBlank(value) {
|
|
@@ -52048,7 +52155,7 @@ function thinkingOptions(value) {
|
|
|
52048
52155
|
const seen = /* @__PURE__ */ new Set();
|
|
52049
52156
|
const options = [];
|
|
52050
52157
|
for (const candidate of value) {
|
|
52051
|
-
if (!
|
|
52158
|
+
if (!isRecord11(candidate) || !nonBlank(candidate.label))
|
|
52052
52159
|
continue;
|
|
52053
52160
|
const id2 = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
52054
52161
|
if (!id2.success || seen.has(id2.data))
|
|
@@ -52059,7 +52166,7 @@ function thinkingOptions(value) {
|
|
|
52059
52166
|
return options;
|
|
52060
52167
|
}
|
|
52061
52168
|
function parseGrokModelState(value) {
|
|
52062
|
-
if (!
|
|
52169
|
+
if (!isRecord11(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
52063
52170
|
return null;
|
|
52064
52171
|
}
|
|
52065
52172
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -52070,12 +52177,12 @@ function parseGrokModelState(value) {
|
|
|
52070
52177
|
const models = [];
|
|
52071
52178
|
let currentThinkingOptionId;
|
|
52072
52179
|
for (const candidate of value.availableModels) {
|
|
52073
|
-
if (!
|
|
52180
|
+
if (!isRecord11(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
52074
52181
|
continue;
|
|
52075
52182
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
52076
52183
|
if (!ref.success)
|
|
52077
52184
|
continue;
|
|
52078
|
-
const metadata =
|
|
52185
|
+
const metadata = isRecord11(candidate._meta) ? candidate._meta : {};
|
|
52079
52186
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
52080
52187
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
52081
52188
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
@@ -52110,10 +52217,10 @@ function parseGrokModelState(value) {
|
|
|
52110
52217
|
};
|
|
52111
52218
|
}
|
|
52112
52219
|
function modelStateFromInitialize(response) {
|
|
52113
|
-
return parseGrokModelState(
|
|
52220
|
+
return parseGrokModelState(isRecord11(response._meta) ? response._meta.modelState : void 0);
|
|
52114
52221
|
}
|
|
52115
52222
|
function modelStateFromSessionResponse(response) {
|
|
52116
|
-
return parseGrokModelState(
|
|
52223
|
+
return parseGrokModelState(isRecord11(response) ? response.models : void 0);
|
|
52117
52224
|
}
|
|
52118
52225
|
function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId) {
|
|
52119
52226
|
const selectedModel = model;
|
|
@@ -52133,10 +52240,10 @@ function stateForGrokModel(modelState, nativeState, model = modelState.currentMo
|
|
|
52133
52240
|
// packages/adapters/grok/dist/grok-credits.js
|
|
52134
52241
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
52135
52242
|
import os4 from "node:os";
|
|
52136
|
-
import
|
|
52243
|
+
import path10 from "node:path";
|
|
52137
52244
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
52138
52245
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
52139
|
-
function
|
|
52246
|
+
function isRecord12(value) {
|
|
52140
52247
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52141
52248
|
}
|
|
52142
52249
|
function finitePercent(value) {
|
|
@@ -52150,7 +52257,7 @@ function nonNegativeNumber(value) {
|
|
|
52150
52257
|
return value;
|
|
52151
52258
|
}
|
|
52152
52259
|
function grokHome(environment) {
|
|
52153
|
-
return environment.GROK_HOME ??
|
|
52260
|
+
return environment.GROK_HOME ?? path10.join(environment.HOME ?? environment.USERPROFILE ?? os4.homedir(), ".grok");
|
|
52154
52261
|
}
|
|
52155
52262
|
function periodTypeFrom(value) {
|
|
52156
52263
|
if (typeof value !== "string")
|
|
@@ -52166,7 +52273,7 @@ function productUsageFrom(value) {
|
|
|
52166
52273
|
if (!Array.isArray(value))
|
|
52167
52274
|
return void 0;
|
|
52168
52275
|
const products = value.flatMap((entry) => {
|
|
52169
|
-
if (!
|
|
52276
|
+
if (!isRecord12(entry) || typeof entry.product !== "string")
|
|
52170
52277
|
return [];
|
|
52171
52278
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
52172
52279
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -52174,13 +52281,13 @@ function productUsageFrom(value) {
|
|
|
52174
52281
|
return products.length > 0 ? products : void 0;
|
|
52175
52282
|
}
|
|
52176
52283
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
52177
|
-
if (!
|
|
52284
|
+
if (!isRecord12(value) || !isRecord12(value.config))
|
|
52178
52285
|
return null;
|
|
52179
52286
|
const config2 = value.config;
|
|
52180
|
-
const period =
|
|
52287
|
+
const period = isRecord12(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
52181
52288
|
const resetsAt = (typeof period?.end === "string" && period.end.length > 0 ? period.end : void 0) ?? (typeof config2.billingPeriodEnd === "string" && config2.billingPeriodEnd.length > 0 ? config2.billingPeriodEnd : void 0);
|
|
52182
|
-
const onDemandCap =
|
|
52183
|
-
const onDemandUsed =
|
|
52289
|
+
const onDemandCap = isRecord12(config2.onDemandCap) ? nonNegativeNumber(config2.onDemandCap.val) : void 0;
|
|
52290
|
+
const onDemandUsed = isRecord12(config2.onDemandUsed) ? nonNegativeNumber(config2.onDemandUsed.val) : void 0;
|
|
52184
52291
|
const usedPercent = finitePercent(config2.creditUsagePercent) ?? (onDemandCap !== void 0 && onDemandCap > 0 && onDemandUsed !== void 0 ? Math.min(100, Math.max(0, onDemandUsed / onDemandCap * 100)) : resetsAt ? 0 : void 0);
|
|
52185
52292
|
if (usedPercent === void 0)
|
|
52186
52293
|
return null;
|
|
@@ -52194,11 +52301,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
52194
52301
|
};
|
|
52195
52302
|
}
|
|
52196
52303
|
function selectAccessToken(auth, now) {
|
|
52197
|
-
if (!
|
|
52304
|
+
if (!isRecord12(auth))
|
|
52198
52305
|
return null;
|
|
52199
|
-
const entries = Object.entries(auth).filter(([, value]) =>
|
|
52306
|
+
const entries = Object.entries(auth).filter(([, value]) => isRecord12(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
|
|
52200
52307
|
for (const [, value] of entries) {
|
|
52201
|
-
if (!
|
|
52308
|
+
if (!isRecord12(value) || typeof value.key !== "string")
|
|
52202
52309
|
continue;
|
|
52203
52310
|
if (typeof value.expires_at === "string") {
|
|
52204
52311
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -52213,7 +52320,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
52213
52320
|
try {
|
|
52214
52321
|
const environment = input.environment ?? process.env;
|
|
52215
52322
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
52216
|
-
const authPath =
|
|
52323
|
+
const authPath = path10.join(grokHome(environment), "auth.json");
|
|
52217
52324
|
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile2(authPath, "utf8");
|
|
52218
52325
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
52219
52326
|
if (!token)
|
|
@@ -52238,7 +52345,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
52238
52345
|
|
|
52239
52346
|
// packages/adapters/grok/dist/grok-usage.js
|
|
52240
52347
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
52241
|
-
function
|
|
52348
|
+
function isRecord13(value) {
|
|
52242
52349
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52243
52350
|
}
|
|
52244
52351
|
function optionalToken(value) {
|
|
@@ -52255,7 +52362,7 @@ function combineUsage(base, next) {
|
|
|
52255
52362
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
52256
52363
|
}
|
|
52257
52364
|
function usageFromNative(value) {
|
|
52258
|
-
if (!
|
|
52365
|
+
if (!isRecord13(value))
|
|
52259
52366
|
return null;
|
|
52260
52367
|
const inputTokens = optionalToken(value.inputTokens);
|
|
52261
52368
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -52282,7 +52389,7 @@ function usageFromPrompt(response) {
|
|
|
52282
52389
|
return response.usage ? usageFromNative(response.usage) : null;
|
|
52283
52390
|
}
|
|
52284
52391
|
function usageFromSignals(value) {
|
|
52285
|
-
if (!
|
|
52392
|
+
if (!isRecord13(value))
|
|
52286
52393
|
return null;
|
|
52287
52394
|
try {
|
|
52288
52395
|
return parseHostUsage({
|
|
@@ -52302,7 +52409,7 @@ var summedUsageFields = [
|
|
|
52302
52409
|
"totalTokens"
|
|
52303
52410
|
];
|
|
52304
52411
|
function nativeCostTicks(value) {
|
|
52305
|
-
if (!
|
|
52412
|
+
if (!isRecord13(value))
|
|
52306
52413
|
return void 0;
|
|
52307
52414
|
const ticks = value.costUsdTicks;
|
|
52308
52415
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -52366,7 +52473,7 @@ function sessionUsageFromHistory(events) {
|
|
|
52366
52473
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
52367
52474
|
try {
|
|
52368
52475
|
if (update?.sessionUpdate === "usage_update") {
|
|
52369
|
-
const cost =
|
|
52476
|
+
const cost = isRecord13(update.cost) ? update.cost : null;
|
|
52370
52477
|
return parseHostUsage({
|
|
52371
52478
|
contextUsedTokens: update.used,
|
|
52372
52479
|
contextWindowTokens: update.size,
|
|
@@ -52400,7 +52507,7 @@ function capabilitiesForModels(modelState) {
|
|
|
52400
52507
|
}
|
|
52401
52508
|
var DEFAULT_CLOSE_TIMEOUT_MS3 = 2e3;
|
|
52402
52509
|
var DEFAULT_TOOL_OUTPUT_LIMIT3 = 64e3;
|
|
52403
|
-
function
|
|
52510
|
+
function isRecord14(value) {
|
|
52404
52511
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52405
52512
|
}
|
|
52406
52513
|
function invalidState3(message3) {
|
|
@@ -52432,10 +52539,10 @@ function jsonValue2(value) {
|
|
|
52432
52539
|
return parsed.success ? parsed.data : {};
|
|
52433
52540
|
}
|
|
52434
52541
|
function contentText2(content) {
|
|
52435
|
-
if (!content)
|
|
52542
|
+
if (!Array.isArray(content))
|
|
52436
52543
|
return "";
|
|
52437
52544
|
return content.flatMap((entry) => {
|
|
52438
|
-
if (!
|
|
52545
|
+
if (!isRecord14(entry) || entry.type !== "content" || !isRecord14(entry.content))
|
|
52439
52546
|
return [];
|
|
52440
52547
|
return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
|
|
52441
52548
|
}).join("\n");
|
|
@@ -52515,7 +52622,7 @@ var GrokHarnessSession = class {
|
|
|
52515
52622
|
this.#state = stateForGrokModel(modelState, { nativeRef: nativeRef(opened.sessionId) });
|
|
52516
52623
|
this.initialState = this.#state;
|
|
52517
52624
|
this.#snapshot = {
|
|
52518
|
-
...mapGrokReplay(options.history, this.harnessId, opened.sessionId, options.knownTurnRefs),
|
|
52625
|
+
...mapGrokReplay(options.history, this.harnessId, opened.sessionId, cwd, options.knownTurnRefs),
|
|
52519
52626
|
state: this.#state
|
|
52520
52627
|
};
|
|
52521
52628
|
this.outputs = this.#channel.outputs;
|
|
@@ -52625,7 +52732,7 @@ var GrokHarnessSession = class {
|
|
|
52625
52732
|
async #refreshSnapshot() {
|
|
52626
52733
|
const history = await this.#transport.getHistory();
|
|
52627
52734
|
const knownTurnRefs = this.#snapshot.turns.map((turn) => turn.nativeTurnRef);
|
|
52628
|
-
const refreshed = mapGrokReplay(history, this.harnessId, this.#transport.sessionId, knownTurnRefs);
|
|
52735
|
+
const refreshed = mapGrokReplay(history, this.harnessId, this.#transport.sessionId, this.#cwd, knownTurnRefs);
|
|
52629
52736
|
this.#snapshot.turns = refreshed.turns;
|
|
52630
52737
|
return history;
|
|
52631
52738
|
}
|
|
@@ -52834,8 +52941,9 @@ var GrokHarnessSession = class {
|
|
|
52834
52941
|
};
|
|
52835
52942
|
active.tools.set(event.callId, { item, ...event.status ? { status: event.status } : {} });
|
|
52836
52943
|
this.#event({ type: "item.started", turnId: active.command.turnId, item });
|
|
52837
|
-
if (event.status === "completed" || event.status === "failed")
|
|
52838
|
-
this.#completeTool(active, event.callId, event.status);
|
|
52944
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52945
|
+
this.#completeTool(active, event.callId, event.status, event.content);
|
|
52946
|
+
}
|
|
52839
52947
|
}
|
|
52840
52948
|
#updateTool(active, event) {
|
|
52841
52949
|
const tool = active.tools.get(event.callId);
|
|
@@ -52853,10 +52961,11 @@ var GrokHarnessSession = class {
|
|
|
52853
52961
|
}
|
|
52854
52962
|
if (event.status)
|
|
52855
52963
|
tool.status = event.status;
|
|
52856
|
-
if (event.status === "completed" || event.status === "failed")
|
|
52857
|
-
this.#completeTool(active, event.callId, event.status);
|
|
52964
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52965
|
+
this.#completeTool(active, event.callId, event.status, event.content);
|
|
52966
|
+
}
|
|
52858
52967
|
}
|
|
52859
|
-
#completeTool(active, callId, status) {
|
|
52968
|
+
#completeTool(active, callId, status, content) {
|
|
52860
52969
|
const tool = active.tools.get(callId);
|
|
52861
52970
|
if (!tool)
|
|
52862
52971
|
return;
|
|
@@ -52870,6 +52979,18 @@ var GrokHarnessSession = class {
|
|
|
52870
52979
|
}
|
|
52871
52980
|
} : { status: "succeeded" };
|
|
52872
52981
|
this.#completeItem(active, tool.item, outcome);
|
|
52982
|
+
if (status !== "completed")
|
|
52983
|
+
return;
|
|
52984
|
+
const changes = projectGrokFileChanges(content, this.#cwd);
|
|
52985
|
+
if (!changes)
|
|
52986
|
+
return;
|
|
52987
|
+
const fileItem = {
|
|
52988
|
+
type: "fileChange",
|
|
52989
|
+
itemId: hostItemIdSchema.parse(this.#randomUUID()),
|
|
52990
|
+
changes
|
|
52991
|
+
};
|
|
52992
|
+
this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
|
|
52993
|
+
this.#completeItem(active, fileItem, { status: "succeeded" });
|
|
52873
52994
|
}
|
|
52874
52995
|
#completeAgent(active, outcome) {
|
|
52875
52996
|
const item = active.agent;
|
|
@@ -53043,7 +53164,7 @@ var GrokAdapter = class {
|
|
|
53043
53164
|
async inspect(input = {}) {
|
|
53044
53165
|
if (this.#closePromise)
|
|
53045
53166
|
return { status: "unavailable", error: invalidState3("Grok Adapter is closed") };
|
|
53046
|
-
const cwd =
|
|
53167
|
+
const cwd = path11.resolve(input.cwd ?? process.cwd());
|
|
53047
53168
|
if (!input.refresh) {
|
|
53048
53169
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
53049
53170
|
if (cached2)
|
|
@@ -53102,7 +53223,7 @@ var GrokAdapter = class {
|
|
|
53102
53223
|
}
|
|
53103
53224
|
};
|
|
53104
53225
|
}
|
|
53105
|
-
const cwd =
|
|
53226
|
+
const cwd = path11.resolve(input.cwd);
|
|
53106
53227
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
53107
53228
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
53108
53229
|
return {
|
|
@@ -53290,7 +53411,7 @@ function normalizePiModelCatalog(nativeModels, effectiveModel, thinkingLevels, e
|
|
|
53290
53411
|
|
|
53291
53412
|
// packages/adapters/pi/dist/pi-history.js
|
|
53292
53413
|
var piHarnessId = harnessIdSchema.parse("pi");
|
|
53293
|
-
function
|
|
53414
|
+
function isRecord15(value) {
|
|
53294
53415
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53295
53416
|
}
|
|
53296
53417
|
function textContent(value) {
|
|
@@ -53298,12 +53419,12 @@ function textContent(value) {
|
|
|
53298
53419
|
return value;
|
|
53299
53420
|
if (!Array.isArray(value))
|
|
53300
53421
|
return "";
|
|
53301
|
-
return value.filter((part) =>
|
|
53422
|
+
return value.filter((part) => isRecord15(part) && part.type === "text" && typeof part.text === "string").map((part) => part.text).join("");
|
|
53302
53423
|
}
|
|
53303
53424
|
function thinkingContent(value) {
|
|
53304
53425
|
if (!Array.isArray(value))
|
|
53305
53426
|
return "";
|
|
53306
|
-
return value.filter((part) =>
|
|
53427
|
+
return value.filter((part) => isRecord15(part) && part.type === "thinking" && typeof part.thinking === "string").map((part) => part.thinking).join("");
|
|
53307
53428
|
}
|
|
53308
53429
|
function validatedEntry(value) {
|
|
53309
53430
|
if (typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
|
|
@@ -53334,7 +53455,7 @@ function activePiEntries(history) {
|
|
|
53334
53455
|
return reversed.reverse();
|
|
53335
53456
|
}
|
|
53336
53457
|
function message(entry) {
|
|
53337
|
-
return entry.type === "message" &&
|
|
53458
|
+
return entry.type === "message" && isRecord15(entry.message) ? entry.message : null;
|
|
53338
53459
|
}
|
|
53339
53460
|
function messageRole(entry) {
|
|
53340
53461
|
const value = message(entry)?.role;
|
|
@@ -53396,7 +53517,7 @@ function snapshotItems(entries, outcome) {
|
|
|
53396
53517
|
let projectedText = false;
|
|
53397
53518
|
let projectedReasoning = false;
|
|
53398
53519
|
for (const [ordinal, part] of content.entries()) {
|
|
53399
|
-
if (!
|
|
53520
|
+
if (!isRecord15(part))
|
|
53400
53521
|
continue;
|
|
53401
53522
|
if (part.type === "thinking" && !projectedReasoning && reasoning.length > 0) {
|
|
53402
53523
|
const item2 = {
|
|
@@ -53588,12 +53709,12 @@ async function rollbackPiLastTurn(transport, sourceSessionId, cwd) {
|
|
|
53588
53709
|
// packages/adapters/pi/dist/pi-rpc-session.js
|
|
53589
53710
|
import { spawn as spawn4, spawnSync as spawnSync2 } from "node:child_process";
|
|
53590
53711
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
53591
|
-
import
|
|
53712
|
+
import path13 from "node:path";
|
|
53592
53713
|
|
|
53593
53714
|
// packages/adapters/pi/dist/command.js
|
|
53594
53715
|
import { accessSync as accessSync2, constants as constants2, readdirSync as readdirSync2, statSync as statSync3 } from "node:fs";
|
|
53595
53716
|
import os5 from "node:os";
|
|
53596
|
-
import
|
|
53717
|
+
import path12 from "node:path";
|
|
53597
53718
|
function environmentValue2(environment, name) {
|
|
53598
53719
|
return Object.entries(environment).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
53599
53720
|
}
|
|
@@ -53606,7 +53727,7 @@ function isExecutable3(filePath, platform) {
|
|
|
53606
53727
|
}
|
|
53607
53728
|
}
|
|
53608
53729
|
function pathCandidates(command, platform, environment) {
|
|
53609
|
-
const targetPath = platform === "win32" ?
|
|
53730
|
+
const targetPath = platform === "win32" ? path12.win32 : path12.posix;
|
|
53610
53731
|
if (targetPath.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
53611
53732
|
return [command];
|
|
53612
53733
|
}
|
|
@@ -53622,7 +53743,7 @@ function nvmCandidates2(homeDirectory, executableName, targetPath) {
|
|
|
53622
53743
|
}
|
|
53623
53744
|
}
|
|
53624
53745
|
function userInstallCandidates2(platform, environment, homeDirectory) {
|
|
53625
|
-
const targetPath = platform === "win32" ?
|
|
53746
|
+
const targetPath = platform === "win32" ? path12.win32 : path12.posix;
|
|
53626
53747
|
if (platform === "win32") {
|
|
53627
53748
|
const appData = environment.APPDATA ?? targetPath.join(homeDirectory, "AppData", "Roaming");
|
|
53628
53749
|
return [
|
|
@@ -53654,7 +53775,7 @@ function resolvePiExecutable(input, dependencies = {}) {
|
|
|
53654
53775
|
function withNodeRuntimeOnPath2(environment, runtimeExecutable = process.execPath, platform = process.platform) {
|
|
53655
53776
|
const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
|
|
53656
53777
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
53657
|
-
const runtimeDirectory =
|
|
53778
|
+
const runtimeDirectory = path12.dirname(runtimeExecutable);
|
|
53658
53779
|
const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
|
|
53659
53780
|
const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
|
|
53660
53781
|
if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
|
|
@@ -53664,14 +53785,14 @@ function withNodeRuntimeOnPath2(environment, runtimeExecutable = process.execPat
|
|
|
53664
53785
|
}
|
|
53665
53786
|
|
|
53666
53787
|
// packages/adapters/pi/dist/pi-usage.js
|
|
53667
|
-
function
|
|
53788
|
+
function isRecord16(value) {
|
|
53668
53789
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53669
53790
|
}
|
|
53670
53791
|
function nonNegativeSafeInteger2(value) {
|
|
53671
53792
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
53672
53793
|
}
|
|
53673
53794
|
function optionalPiCacheHitRatePercent(value) {
|
|
53674
|
-
if (!
|
|
53795
|
+
if (!isRecord16(value) || value.role !== "assistant" || !isRecord16(value.usage))
|
|
53675
53796
|
return null;
|
|
53676
53797
|
const input = nonNegativeSafeInteger2(value.usage.input);
|
|
53677
53798
|
const cacheRead = nonNegativeSafeInteger2(value.usage.cacheRead);
|
|
@@ -53684,20 +53805,20 @@ function optionalPiCacheHitRatePercent(value) {
|
|
|
53684
53805
|
function latestPiCacheHitRatePercent(history) {
|
|
53685
53806
|
let latest = null;
|
|
53686
53807
|
for (const entry of activePiEntries(history)) {
|
|
53687
|
-
if (entry.type === "message" &&
|
|
53808
|
+
if (entry.type === "message" && isRecord16(entry.message) && entry.message.role === "assistant") {
|
|
53688
53809
|
latest = optionalPiCacheHitRatePercent(entry.message);
|
|
53689
53810
|
}
|
|
53690
53811
|
}
|
|
53691
53812
|
return latest;
|
|
53692
53813
|
}
|
|
53693
53814
|
function responseData(response, operation) {
|
|
53694
|
-
if (!
|
|
53815
|
+
if (!isRecord16(response.data)) {
|
|
53695
53816
|
throw new Error(`Pi RPC ${operation} response has no data`);
|
|
53696
53817
|
}
|
|
53697
53818
|
return response.data;
|
|
53698
53819
|
}
|
|
53699
53820
|
function contextUsage(value) {
|
|
53700
|
-
if (!
|
|
53821
|
+
if (!isRecord16(value))
|
|
53701
53822
|
throw new Error("Pi RPC context Usage is invalid");
|
|
53702
53823
|
return parseHostUsage({
|
|
53703
53824
|
contextUsedTokens: value.tokens,
|
|
@@ -53707,15 +53828,15 @@ function contextUsage(value) {
|
|
|
53707
53828
|
function parsePiSessionUsage(response) {
|
|
53708
53829
|
const data = responseData(response, "Session stats");
|
|
53709
53830
|
const tokens = data.tokens;
|
|
53710
|
-
if (tokens !== void 0 && !
|
|
53831
|
+
if (tokens !== void 0 && !isRecord16(tokens)) {
|
|
53711
53832
|
throw new Error("Pi RPC Session stats tokens are invalid");
|
|
53712
53833
|
}
|
|
53713
53834
|
return parseHostUsage({
|
|
53714
|
-
...
|
|
53715
|
-
...
|
|
53716
|
-
...
|
|
53717
|
-
...
|
|
53718
|
-
...
|
|
53835
|
+
...isRecord16(tokens) && tokens.input !== void 0 ? { inputTokens: tokens.input } : {},
|
|
53836
|
+
...isRecord16(tokens) && tokens.cacheRead !== void 0 ? { cachedInputTokens: tokens.cacheRead } : {},
|
|
53837
|
+
...isRecord16(tokens) && tokens.cacheWrite !== void 0 ? { cacheWriteInputTokens: tokens.cacheWrite } : {},
|
|
53838
|
+
...isRecord16(tokens) && tokens.output !== void 0 ? { outputTokens: tokens.output } : {},
|
|
53839
|
+
...isRecord16(tokens) && tokens.total !== void 0 ? { totalTokens: tokens.total } : {},
|
|
53719
53840
|
...data.cost !== void 0 ? { totalCostUsd: data.cost } : {},
|
|
53720
53841
|
...data.contextUsage !== void 0 ? contextUsage(data.contextUsage) : {}
|
|
53721
53842
|
});
|
|
@@ -53738,7 +53859,7 @@ function optionalPiStateContextUsage(value) {
|
|
|
53738
53859
|
import { open, realpath } from "node:fs/promises";
|
|
53739
53860
|
var MAX_SESSION_HEADER_BYTES = 64 * 1024;
|
|
53740
53861
|
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
53741
|
-
function
|
|
53862
|
+
function isRecord17(value) {
|
|
53742
53863
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53743
53864
|
}
|
|
53744
53865
|
async function readPiSessionHeader(sessionFile) {
|
|
@@ -53758,7 +53879,7 @@ async function readPiSessionHeader(sessionFile) {
|
|
|
53758
53879
|
} catch {
|
|
53759
53880
|
throw new Error("Pi Session header is not valid JSON");
|
|
53760
53881
|
}
|
|
53761
|
-
if (!
|
|
53882
|
+
if (!isRecord17(parsed) || parsed.type !== "session" || typeof parsed.id !== "string" || parsed.id.length === 0 || typeof parsed.cwd !== "string" || parsed.cwd.length === 0) {
|
|
53762
53883
|
throw new Error("Pi Session header is invalid");
|
|
53763
53884
|
}
|
|
53764
53885
|
return { type: "session", id: parsed.id, cwd: parsed.cwd };
|
|
@@ -53800,7 +53921,7 @@ var PiRpcUnsupportedCommandError = class extends Error {
|
|
|
53800
53921
|
}
|
|
53801
53922
|
};
|
|
53802
53923
|
var textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
53803
|
-
function
|
|
53924
|
+
function isRecord18(value) {
|
|
53804
53925
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53805
53926
|
}
|
|
53806
53927
|
function message2(value) {
|
|
@@ -53812,13 +53933,13 @@ function nonBlankString2(value) {
|
|
|
53812
53933
|
function parseNativeModel(value, context) {
|
|
53813
53934
|
if (value === null || value === void 0)
|
|
53814
53935
|
return null;
|
|
53815
|
-
if (!
|
|
53936
|
+
if (!isRecord18(value) || !nonBlankString2(value.provider) || !nonBlankString2(value.id)) {
|
|
53816
53937
|
throw new PiRpcFaultError("protocolError", `Pi RPC returned an invalid ${context} Model`);
|
|
53817
53938
|
}
|
|
53818
53939
|
return { provider: value.provider, id: value.id };
|
|
53819
53940
|
}
|
|
53820
53941
|
function sessionStateData(response) {
|
|
53821
|
-
const data =
|
|
53942
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53822
53943
|
if (!data)
|
|
53823
53944
|
throw new PiRpcFaultError("protocolError", "Pi RPC state response has no data");
|
|
53824
53945
|
return data;
|
|
@@ -53850,13 +53971,13 @@ function parseSessionStreaming(response) {
|
|
|
53850
53971
|
return isStreaming;
|
|
53851
53972
|
}
|
|
53852
53973
|
function parseSessionHistory(response) {
|
|
53853
|
-
const data =
|
|
53974
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53854
53975
|
if (!data || !Array.isArray(data.entries)) {
|
|
53855
53976
|
throw new PiRpcFaultError("protocolError", "Pi RPC entries response has no Entries");
|
|
53856
53977
|
}
|
|
53857
53978
|
const entries = data.entries.map((entry) => {
|
|
53858
53979
|
const parsed = jsonValueSchema.safeParse(entry);
|
|
53859
|
-
if (!parsed.success || !
|
|
53980
|
+
if (!parsed.success || !isRecord18(parsed.data)) {
|
|
53860
53981
|
throw new PiRpcFaultError("protocolError", "Pi RPC entries response contains an invalid Entry");
|
|
53861
53982
|
}
|
|
53862
53983
|
return parsed.data;
|
|
@@ -53867,7 +53988,7 @@ function parseSessionHistory(response) {
|
|
|
53867
53988
|
return { entries, leafId: data.leafId };
|
|
53868
53989
|
}
|
|
53869
53990
|
function parseAvailableThinkingLevels(response) {
|
|
53870
|
-
const data =
|
|
53991
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53871
53992
|
if (!data || !Array.isArray(data.levels) || data.levels.length === 0) {
|
|
53872
53993
|
throw new PiRpcFaultError("protocolError", "Pi RPC Thinking catalog response has no levels");
|
|
53873
53994
|
}
|
|
@@ -53884,35 +54005,35 @@ function parseAvailableThinkingLevels(response) {
|
|
|
53884
54005
|
return levels;
|
|
53885
54006
|
}
|
|
53886
54007
|
function parseAvailableModels(response) {
|
|
53887
|
-
const data =
|
|
54008
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53888
54009
|
if (!data || !Array.isArray(data.models)) {
|
|
53889
54010
|
throw new PiRpcFaultError("protocolError", "Pi RPC Model catalog response has no models");
|
|
53890
54011
|
}
|
|
53891
54012
|
return data.models.map((model) => {
|
|
53892
54013
|
const parsed = parseNativeModel(model, "catalog");
|
|
53893
|
-
if (!parsed || !
|
|
54014
|
+
if (!parsed || !isRecord18(model) || typeof model.reasoning !== "boolean") {
|
|
53894
54015
|
throw new PiRpcFaultError("protocolError", "Pi RPC catalog contains a Model without reasoning capability");
|
|
53895
54016
|
}
|
|
53896
54017
|
return { ...parsed, reasoning: model.reasoning };
|
|
53897
54018
|
});
|
|
53898
54019
|
}
|
|
53899
54020
|
function assistantText2(value) {
|
|
53900
|
-
if (!
|
|
54021
|
+
if (!isRecord18(value) || value.role !== "assistant" || !Array.isArray(value.content))
|
|
53901
54022
|
return null;
|
|
53902
|
-
return value.content.filter((content) =>
|
|
54023
|
+
return value.content.filter((content) => isRecord18(content) && content.type === "text" && typeof content.text === "string").map((content) => content.text).join("");
|
|
53903
54024
|
}
|
|
53904
54025
|
function assistantMessageId(value) {
|
|
53905
|
-
if (!
|
|
54026
|
+
if (!isRecord18(value) || value.role !== "assistant")
|
|
53906
54027
|
return null;
|
|
53907
54028
|
return nonBlankString2(value.responseId) ? value.responseId : null;
|
|
53908
54029
|
}
|
|
53909
54030
|
function assistantReasoning(value) {
|
|
53910
|
-
if (!
|
|
54031
|
+
if (!isRecord18(value) || value.role !== "assistant" || !Array.isArray(value.content))
|
|
53911
54032
|
return null;
|
|
53912
|
-
return value.content.filter((content) =>
|
|
54033
|
+
return value.content.filter((content) => isRecord18(content) && content.type === "thinking" && typeof content.thinking === "string").map((content) => content.thinking).join("");
|
|
53913
54034
|
}
|
|
53914
54035
|
function assistantFailure(value) {
|
|
53915
|
-
if (!
|
|
54036
|
+
if (!isRecord18(value) || value.role !== "assistant")
|
|
53916
54037
|
return void 0;
|
|
53917
54038
|
if (value.stopReason !== "error" && value.stopReason !== "aborted")
|
|
53918
54039
|
return null;
|
|
@@ -53932,7 +54053,7 @@ function signalProcessTree2(child, signal) {
|
|
|
53932
54053
|
try {
|
|
53933
54054
|
process.kill(-child.pid, signal);
|
|
53934
54055
|
} catch (error52) {
|
|
53935
|
-
if (!
|
|
54056
|
+
if (!isRecord18(error52) || error52.code !== "ESRCH")
|
|
53936
54057
|
throw error52;
|
|
53937
54058
|
}
|
|
53938
54059
|
}
|
|
@@ -53963,7 +54084,7 @@ function piRpcProcessCommand(options, dependencies = {}) {
|
|
|
53963
54084
|
const sessionArguments = options.forkSessionFile ? ["--fork", options.forkSessionFile] : options.sessionFile ? ["--session", options.sessionFile] : [];
|
|
53964
54085
|
const modelArguments = options.model ? ["--provider", options.model.provider, "--model", options.model.id] : [];
|
|
53965
54086
|
const arguments_2 = ["--mode", "rpc", ...modelArguments, ...sessionArguments];
|
|
53966
|
-
const extension =
|
|
54087
|
+
const extension = path13.win32.extname(command).toLowerCase();
|
|
53967
54088
|
if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
|
|
53968
54089
|
return { command, arguments: arguments_2, windowsVerbatimArguments: false };
|
|
53969
54090
|
}
|
|
@@ -54046,7 +54167,7 @@ var PiRpcSession = class {
|
|
|
54046
54167
|
});
|
|
54047
54168
|
child.stderr.resume();
|
|
54048
54169
|
child.once("error", (error52) => {
|
|
54049
|
-
const kind =
|
|
54170
|
+
const kind = isRecord18(error52) && error52.code === "ENOENT" ? "notInstalled" : "unavailable";
|
|
54050
54171
|
this.#fail(new PiRpcFaultError(kind, `Pi RPC failed to start: ${error52.message}`));
|
|
54051
54172
|
});
|
|
54052
54173
|
child.once("exit", (code, signal) => {
|
|
@@ -54298,7 +54419,7 @@ var PiRpcSession = class {
|
|
|
54298
54419
|
this.#buffer = this.#buffer.subarray(newline3 + 1);
|
|
54299
54420
|
try {
|
|
54300
54421
|
const value = JSON.parse(textDecoder.decode(frame));
|
|
54301
|
-
if (!
|
|
54422
|
+
if (!isRecord18(value) || typeof value.type !== "string") {
|
|
54302
54423
|
throw new PiRpcFaultError("protocolError", "Pi RPC returned an invalid envelope");
|
|
54303
54424
|
}
|
|
54304
54425
|
this.#handle(value);
|
|
@@ -54337,7 +54458,7 @@ var PiRpcSession = class {
|
|
|
54337
54458
|
}
|
|
54338
54459
|
compactionTurn?.onEvent({
|
|
54339
54460
|
type: "compaction.completed",
|
|
54340
|
-
outcome: value.aborted === true ? "cancelled" :
|
|
54461
|
+
outcome: value.aborted === true ? "cancelled" : isRecord18(value.result) ? "succeeded" : "failed",
|
|
54341
54462
|
...nonBlankString2(value.errorMessage) ? { errorMessage: value.errorMessage } : {}
|
|
54342
54463
|
});
|
|
54343
54464
|
return;
|
|
@@ -54357,7 +54478,7 @@ var PiRpcSession = class {
|
|
|
54357
54478
|
this.#startAssistantMessage(active, value.message);
|
|
54358
54479
|
return;
|
|
54359
54480
|
}
|
|
54360
|
-
if (value.type === "message_update" &&
|
|
54481
|
+
if (value.type === "message_update" && isRecord18(value.assistantMessageEvent)) {
|
|
54361
54482
|
const event = value.assistantMessageEvent;
|
|
54362
54483
|
if (event.type === "text_delta" && typeof event.delta === "string") {
|
|
54363
54484
|
const messageId = this.#ensureAssistantMessage(active, value.message);
|
|
@@ -54751,7 +54872,7 @@ var PiRpcSession = class {
|
|
|
54751
54872
|
// packages/adapters/pi/dist/pi-adapter.js
|
|
54752
54873
|
var piHarnessId2 = harnessIdSchema.parse("pi");
|
|
54753
54874
|
var DEFAULT_TOOL_OUTPUT_LIMIT4 = 64e3;
|
|
54754
|
-
function
|
|
54875
|
+
function isRecord19(value) {
|
|
54755
54876
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
54756
54877
|
}
|
|
54757
54878
|
function errorMessage(error52) {
|
|
@@ -54825,7 +54946,7 @@ function nativeModelForHistory(state) {
|
|
|
54825
54946
|
return nativeModelFromState(state);
|
|
54826
54947
|
}
|
|
54827
54948
|
function sessionFileFromRef(ref) {
|
|
54828
|
-
if (ref.harnessId !== piHarnessId2 || !
|
|
54949
|
+
if (ref.harnessId !== piHarnessId2 || !isRecord19(ref.locator) || typeof ref.locator.sessionFile !== "string" || ref.locator.sessionFile.length === 0) {
|
|
54829
54950
|
throw new Error("Pi Native Session Ref has no resumable Session file");
|
|
54830
54951
|
}
|
|
54831
54952
|
return ref.locator.sessionFile;
|
|
@@ -54840,9 +54961,9 @@ function toolFailure2(toolName) {
|
|
|
54840
54961
|
function nativeText(value) {
|
|
54841
54962
|
if (typeof value === "string")
|
|
54842
54963
|
return value;
|
|
54843
|
-
if (!
|
|
54964
|
+
if (!isRecord19(value) || !Array.isArray(value.content))
|
|
54844
54965
|
return "";
|
|
54845
|
-
return value.content.filter((content) =>
|
|
54966
|
+
return value.content.filter((content) => isRecord19(content) && content.type === "text" && typeof content.text === "string").map(({ text }) => text).join("");
|
|
54846
54967
|
}
|
|
54847
54968
|
function boundedOutput(value, limit) {
|
|
54848
54969
|
const text = nativeText(value);
|
|
@@ -54858,19 +54979,19 @@ function outputText2(output) {
|
|
|
54858
54979
|
return output?.content.filter((content) => content.type === "text").map(({ text }) => text).join("") ?? "";
|
|
54859
54980
|
}
|
|
54860
54981
|
function stringField2(value, key) {
|
|
54861
|
-
return
|
|
54982
|
+
return isRecord19(value) && typeof value[key] === "string" ? value[key] : void 0;
|
|
54862
54983
|
}
|
|
54863
54984
|
function numberField(value, key) {
|
|
54864
|
-
if (!
|
|
54985
|
+
if (!isRecord19(value))
|
|
54865
54986
|
return void 0;
|
|
54866
54987
|
const field = value[key];
|
|
54867
54988
|
return typeof field === "number" || field === null ? field : void 0;
|
|
54868
54989
|
}
|
|
54869
|
-
function stripDiffPrefix(
|
|
54870
|
-
return
|
|
54990
|
+
function stripDiffPrefix(path19) {
|
|
54991
|
+
return path19.startsWith("a/") || path19.startsWith("b/") ? path19.slice(2) : path19;
|
|
54871
54992
|
}
|
|
54872
54993
|
function reliableFileChange(result) {
|
|
54873
|
-
if (!
|
|
54994
|
+
if (!isRecord19(result) || !isRecord19(result.details) || typeof result.details.patch !== "string") {
|
|
54874
54995
|
return null;
|
|
54875
54996
|
}
|
|
54876
54997
|
const patch = result.details.patch;
|
|
@@ -54886,10 +55007,10 @@ function reliableFileChange(result) {
|
|
|
54886
55007
|
const oldFile = file2.oldFileName;
|
|
54887
55008
|
const newFile = file2.newFileName;
|
|
54888
55009
|
const kind = oldFile === "/dev/null" ? "add" : newFile === "/dev/null" ? "delete" : "update";
|
|
54889
|
-
const
|
|
54890
|
-
if (!
|
|
55010
|
+
const path19 = stripDiffPrefix(kind === "delete" ? oldFile : newFile);
|
|
55011
|
+
if (!path19 || path19 === "/dev/null")
|
|
54891
55012
|
return null;
|
|
54892
|
-
return [{ path:
|
|
55013
|
+
return [{ path: path19, kind, unifiedDiff: patch }];
|
|
54893
55014
|
}
|
|
54894
55015
|
function delay3(milliseconds) {
|
|
54895
55016
|
return new Promise((resolve2) => setTimeout(resolve2, milliseconds));
|
|
@@ -56133,7 +56254,7 @@ import { execFileSync } from "node:child_process";
|
|
|
56133
56254
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
56134
56255
|
import { constants as constants3 } from "node:fs";
|
|
56135
56256
|
import { copyFile, mkdir, open as open2, readFile as readFile3, readdir, rename, rm as rm2, stat } from "node:fs/promises";
|
|
56136
|
-
import
|
|
56257
|
+
import path14 from "node:path";
|
|
56137
56258
|
|
|
56138
56259
|
// packages/mapping-store/dist/records.js
|
|
56139
56260
|
var nonBlankTextSchema3 = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
@@ -56350,11 +56471,11 @@ var MappingStore = class {
|
|
|
56350
56471
|
#initialized = false;
|
|
56351
56472
|
#lockHandle = null;
|
|
56352
56473
|
constructor(options) {
|
|
56353
|
-
this.#directory =
|
|
56354
|
-
this.#threadsDirectory =
|
|
56355
|
-
this.#backupsDirectory =
|
|
56356
|
-
this.#quarantineDirectory =
|
|
56357
|
-
this.#lockPath =
|
|
56474
|
+
this.#directory = path14.resolve(options.directory);
|
|
56475
|
+
this.#threadsDirectory = path14.join(this.#directory, "threads");
|
|
56476
|
+
this.#backupsDirectory = path14.join(this.#directory, "backups");
|
|
56477
|
+
this.#quarantineDirectory = path14.join(this.#directory, "quarantine");
|
|
56478
|
+
this.#lockPath = path14.join(this.#directory, "store.lock");
|
|
56358
56479
|
this.#instanceId = options.instanceId ?? randomUUID6();
|
|
56359
56480
|
this.#now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
56360
56481
|
this.#beforeReplace = options.beforeReplace;
|
|
@@ -56372,8 +56493,8 @@ var MappingStore = class {
|
|
|
56372
56493
|
await this.#cleanupTemps();
|
|
56373
56494
|
const names = (await readdir(this.#threadsDirectory)).filter((name) => name.endsWith(".json"));
|
|
56374
56495
|
for (const name of names) {
|
|
56375
|
-
const primary =
|
|
56376
|
-
const backup =
|
|
56496
|
+
const primary = path14.join(this.#threadsDirectory, name);
|
|
56497
|
+
const backup = path14.join(this.#backupsDirectory, name);
|
|
56377
56498
|
let record3 = null;
|
|
56378
56499
|
try {
|
|
56379
56500
|
record3 = await this.#readRecord(primary, name);
|
|
@@ -56382,7 +56503,7 @@ var MappingStore = class {
|
|
|
56382
56503
|
record3 = await this.#readRecord(backup, name);
|
|
56383
56504
|
await this.#replaceFile(primary, record3, false);
|
|
56384
56505
|
} catch (backupError) {
|
|
56385
|
-
const quarantine =
|
|
56506
|
+
const quarantine = path14.join(this.#quarantineDirectory, `${name}.${this.#now().getTime()}.invalid`);
|
|
56386
56507
|
await rename(primary, quarantine).catch(() => void 0);
|
|
56387
56508
|
void primaryError;
|
|
56388
56509
|
void backupError;
|
|
@@ -56665,7 +56786,7 @@ var MappingStore = class {
|
|
|
56665
56786
|
}
|
|
56666
56787
|
async #cleanupTemps() {
|
|
56667
56788
|
const names = await readdir(this.#threadsDirectory);
|
|
56668
|
-
await Promise.all(names.filter((name) => name.includes(".tmp-")).map((name) => rm2(
|
|
56789
|
+
await Promise.all(names.filter((name) => name.includes(".tmp-")).map((name) => rm2(path14.join(this.#threadsDirectory, name), { force: true })));
|
|
56669
56790
|
}
|
|
56670
56791
|
async #acquireLock() {
|
|
56671
56792
|
const attempt = async () => {
|
|
@@ -56758,10 +56879,10 @@ var MappingStore = class {
|
|
|
56758
56879
|
}
|
|
56759
56880
|
}
|
|
56760
56881
|
#recordPath(hostThreadId) {
|
|
56761
|
-
return
|
|
56882
|
+
return path14.join(this.#threadsDirectory, `${hostThreadId}.json`);
|
|
56762
56883
|
}
|
|
56763
56884
|
#backupPath(hostThreadId) {
|
|
56764
|
-
return
|
|
56885
|
+
return path14.join(this.#backupsDirectory, `${hostThreadId}.json`);
|
|
56765
56886
|
}
|
|
56766
56887
|
#requireInitialized() {
|
|
56767
56888
|
if (!this.#initialized) {
|
|
@@ -56780,7 +56901,7 @@ var packageMetadata5 = {
|
|
|
56780
56901
|
var TITLE_MAX_LENGTH = 120;
|
|
56781
56902
|
var DESCRIPTION_MAX_LENGTH = 500;
|
|
56782
56903
|
var SERVER_NAME_MAX_LENGTH = 80;
|
|
56783
|
-
function
|
|
56904
|
+
function isRecord20(value) {
|
|
56784
56905
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56785
56906
|
}
|
|
56786
56907
|
function boundedText(value, field, maxLength) {
|
|
@@ -56824,7 +56945,7 @@ function responseError(message3) {
|
|
|
56824
56945
|
function responsePersist(value) {
|
|
56825
56946
|
if (value === void 0 || value === null)
|
|
56826
56947
|
return null;
|
|
56827
|
-
if (!
|
|
56948
|
+
if (!isRecord20(value) || Object.keys(value).length !== 1 || value.persist !== "session" && value.persist !== "always") {
|
|
56828
56949
|
throw responseError("contains malformed persist metadata");
|
|
56829
56950
|
}
|
|
56830
56951
|
return value.persist;
|
|
@@ -56867,7 +56988,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
56867
56988
|
},
|
|
56868
56989
|
denyResponse,
|
|
56869
56990
|
parseResponse(result) {
|
|
56870
|
-
if (!
|
|
56991
|
+
if (!isRecord20(result) || typeof result.action !== "string") {
|
|
56871
56992
|
throw responseError("missing action");
|
|
56872
56993
|
}
|
|
56873
56994
|
if (Object.keys(result).some((key) => key !== "action" && key !== "content" && key !== "_meta")) {
|
|
@@ -56875,7 +56996,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
56875
56996
|
}
|
|
56876
56997
|
const selectedPersist = responsePersist(result._meta);
|
|
56877
56998
|
if (result.action === "accept") {
|
|
56878
|
-
if ("content" in result && (!
|
|
56999
|
+
if ("content" in result && (!isRecord20(result.content) || Object.keys(result.content).length !== 0)) {
|
|
56879
57000
|
throw responseError("contains non-empty accepted content");
|
|
56880
57001
|
}
|
|
56881
57002
|
if (selectedPersist === "session") {
|
|
@@ -56902,7 +57023,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
56902
57023
|
}
|
|
56903
57024
|
|
|
56904
57025
|
// packages/protocol-core/dist/codex-question.js
|
|
56905
|
-
function
|
|
57026
|
+
function isRecord21(value) {
|
|
56906
57027
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56907
57028
|
}
|
|
56908
57029
|
function responseError2(message3) {
|
|
@@ -56971,7 +57092,7 @@ function projectCodexQuestionRequest(input) {
|
|
|
56971
57092
|
}
|
|
56972
57093
|
},
|
|
56973
57094
|
parseResponse(result) {
|
|
56974
|
-
if (!
|
|
57095
|
+
if (!isRecord21(result) || !isRecord21(result.answers)) {
|
|
56975
57096
|
throw responseError2("missing answers object");
|
|
56976
57097
|
}
|
|
56977
57098
|
const rawAnswers = result.answers;
|
|
@@ -56984,7 +57105,7 @@ function projectCodexQuestionRequest(input) {
|
|
|
56984
57105
|
const question = interaction.questions.find(({ id: id2 }) => id2 === questionId);
|
|
56985
57106
|
if (!question)
|
|
56986
57107
|
throw responseError2("contains an unknown Question ID");
|
|
56987
|
-
if (!
|
|
57108
|
+
if (!isRecord21(answerValue) || !Array.isArray(answerValue.answers)) {
|
|
56988
57109
|
throw responseError2("answer entry has no answers array");
|
|
56989
57110
|
}
|
|
56990
57111
|
const values = answerValue.answers;
|
|
@@ -57130,8 +57251,8 @@ function projectItem(item, outcome, defaultCwd, includeCommandOutput = true) {
|
|
|
57130
57251
|
return {
|
|
57131
57252
|
id: item.itemId,
|
|
57132
57253
|
type: "fileChange",
|
|
57133
|
-
changes: item.changes.map(({ path:
|
|
57134
|
-
path:
|
|
57254
|
+
changes: item.changes.map(({ path: path19, kind, unifiedDiff }) => ({
|
|
57255
|
+
path: path19,
|
|
57135
57256
|
kind,
|
|
57136
57257
|
diff: unifiedDiff
|
|
57137
57258
|
})),
|
|
@@ -57548,8 +57669,8 @@ var CodexTurnProjector = class {
|
|
|
57548
57669
|
return messages;
|
|
57549
57670
|
}
|
|
57550
57671
|
#fileChangeUpdates(itemId3, changes) {
|
|
57551
|
-
const projectedChanges = changes.map(({ path:
|
|
57552
|
-
path:
|
|
57672
|
+
const projectedChanges = changes.map(({ path: path19, kind, unifiedDiff }) => ({
|
|
57673
|
+
path: path19,
|
|
57553
57674
|
kind,
|
|
57554
57675
|
diff: unifiedDiff
|
|
57555
57676
|
}));
|
|
@@ -57594,7 +57715,7 @@ var CodexTurnProjector = class {
|
|
|
57594
57715
|
};
|
|
57595
57716
|
|
|
57596
57717
|
// packages/protocol-core/dist/thread-fork.js
|
|
57597
|
-
function
|
|
57718
|
+
function isRecord22(value) {
|
|
57598
57719
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
57599
57720
|
}
|
|
57600
57721
|
function optionalText(params, name, options = {}) {
|
|
@@ -57617,7 +57738,7 @@ function optionalBoolean(params, name) {
|
|
|
57617
57738
|
function decodeThreadForkRequest(request) {
|
|
57618
57739
|
if (request.method !== "thread/fork")
|
|
57619
57740
|
return null;
|
|
57620
|
-
if (!
|
|
57741
|
+
if (!isRecord22(request.params))
|
|
57621
57742
|
throw new Error("thread/fork params must be an object");
|
|
57622
57743
|
const params = request.params;
|
|
57623
57744
|
const threadId2 = optionalText(params, "threadId");
|
|
@@ -57632,13 +57753,13 @@ function decodeThreadForkRequest(request) {
|
|
|
57632
57753
|
if (runtimeWorkspaceRoots !== void 0 && runtimeWorkspaceRoots !== null && (!Array.isArray(runtimeWorkspaceRoots) || runtimeWorkspaceRoots.some((root) => typeof root !== "string" || root.length === 0))) {
|
|
57633
57754
|
throw new Error("thread/fork params.runtimeWorkspaceRoots must be text paths or null");
|
|
57634
57755
|
}
|
|
57635
|
-
const
|
|
57756
|
+
const path19 = optionalText(params, "path", { allowEmpty: true });
|
|
57636
57757
|
const ephemeral = optionalBoolean(params, "ephemeral");
|
|
57637
57758
|
return {
|
|
57638
57759
|
threadId: threadId2,
|
|
57639
57760
|
...lastTurnText ? { lastTurnId: hostTurnIdSchema.parse(lastTurnText) } : {},
|
|
57640
57761
|
...beforeTurnText ? { beforeTurnId: hostTurnIdSchema.parse(beforeTurnText) } : {},
|
|
57641
|
-
...
|
|
57762
|
+
...path19 ? { path: path19 } : {},
|
|
57642
57763
|
...optionalField(params, "model"),
|
|
57643
57764
|
...optionalField(params, "modelProvider"),
|
|
57644
57765
|
...optionalField(params, "cwd"),
|
|
@@ -57653,7 +57774,7 @@ function decodeThreadForkRequest(request) {
|
|
|
57653
57774
|
function decodeThreadRollbackRequest(request) {
|
|
57654
57775
|
if (request.method !== "thread/rollback")
|
|
57655
57776
|
return null;
|
|
57656
|
-
if (!
|
|
57777
|
+
if (!isRecord22(request.params))
|
|
57657
57778
|
throw new Error("thread/rollback params must be an object");
|
|
57658
57779
|
const { threadId: threadId2, numTurns } = request.params;
|
|
57659
57780
|
if (typeof threadId2 !== "string" || threadId2.length === 0) {
|
|
@@ -57747,13 +57868,13 @@ var THREAD_SOURCE_KINDS = /* @__PURE__ */ new Set([
|
|
|
57747
57868
|
"subAgentOther",
|
|
57748
57869
|
"unknown"
|
|
57749
57870
|
]);
|
|
57750
|
-
function
|
|
57871
|
+
function isRecord23(value) {
|
|
57751
57872
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
57752
57873
|
}
|
|
57753
57874
|
function paramsObject(request, method) {
|
|
57754
57875
|
if (request.params === void 0 && method === "thread/list")
|
|
57755
57876
|
return {};
|
|
57756
|
-
if (!
|
|
57877
|
+
if (!isRecord23(request.params))
|
|
57757
57878
|
throw new Error(`${method} params must be an object`);
|
|
57758
57879
|
return request.params;
|
|
57759
57880
|
}
|
|
@@ -57825,7 +57946,7 @@ function cursorPayload(value) {
|
|
|
57825
57946
|
};
|
|
57826
57947
|
}
|
|
57827
57948
|
function parseCursorPayload(value) {
|
|
57828
|
-
if (!
|
|
57949
|
+
if (!isRecord23(value) || value.formatVersion !== 1)
|
|
57829
57950
|
throw new Error("Host cursor is invalid");
|
|
57830
57951
|
const { queryFingerprint: fingerprint, sortDirection: sortDirection2, officialCursor, officialDone } = value;
|
|
57831
57952
|
const { externalAnchor: externalAnchor2, externalDone } = value;
|
|
@@ -57834,7 +57955,7 @@ function parseCursorPayload(value) {
|
|
|
57834
57955
|
}
|
|
57835
57956
|
let anchor = null;
|
|
57836
57957
|
if (externalAnchor2 !== null) {
|
|
57837
|
-
if (!
|
|
57958
|
+
if (!isRecord23(externalAnchor2) || !Number.isSafeInteger(externalAnchor2.timestamp) || typeof externalAnchor2.threadId !== "string" || externalAnchor2.threadId.length === 0) {
|
|
57838
57959
|
throw new Error("Host cursor is invalid");
|
|
57839
57960
|
}
|
|
57840
57961
|
anchor = {
|
|
@@ -57954,7 +58075,7 @@ function decodeThreadMetadataUpdateRequest(request) {
|
|
|
57954
58075
|
if (params.gitInfo === null) {
|
|
57955
58076
|
gitInfo = null;
|
|
57956
58077
|
} else if (params.gitInfo !== void 0) {
|
|
57957
|
-
if (!
|
|
58078
|
+
if (!isRecord23(params.gitInfo)) {
|
|
57958
58079
|
throw new Error("thread/metadata/update params.gitInfo must be an object or null");
|
|
57959
58080
|
}
|
|
57960
58081
|
gitInfo = {};
|
|
@@ -57982,7 +58103,7 @@ function optionalCursor(value, name) {
|
|
|
57982
58103
|
return value;
|
|
57983
58104
|
}
|
|
57984
58105
|
function decodeOfficialThreadListPage(value) {
|
|
57985
|
-
if (!
|
|
58106
|
+
if (!isRecord23(value) || !Array.isArray(value.data) || value.data.some((row) => !isRecord23(row))) {
|
|
57986
58107
|
throw new Error("Official thread/list response is invalid");
|
|
57987
58108
|
}
|
|
57988
58109
|
return {
|
|
@@ -58304,7 +58425,7 @@ var packageMetadata6 = {
|
|
|
58304
58425
|
// packages/host-runtime/src/external-thread-repository.ts
|
|
58305
58426
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
58306
58427
|
import os6 from "node:os";
|
|
58307
|
-
import
|
|
58428
|
+
import path15 from "node:path";
|
|
58308
58429
|
function nativeTurnKey2(ref) {
|
|
58309
58430
|
return `${ref.harnessId}\0${ref.nativeSessionId}\0${ref.nativeTurnKey}\0${ref.formatVersion}`;
|
|
58310
58431
|
}
|
|
@@ -58313,8 +58434,8 @@ function sameMapping(left, right) {
|
|
|
58313
58434
|
}
|
|
58314
58435
|
function defaultMappingStoreDirectory(environment) {
|
|
58315
58436
|
const dataDirectory = environment.CODEXHOST_DATA_DIR;
|
|
58316
|
-
return
|
|
58317
|
-
dataDirectory ?
|
|
58437
|
+
return path15.join(
|
|
58438
|
+
dataDirectory ? path15.resolve(dataDirectory) : path15.join(os6.homedir(), ".codexhost"),
|
|
58318
58439
|
"mapping-store"
|
|
58319
58440
|
);
|
|
58320
58441
|
}
|
|
@@ -59388,7 +59509,7 @@ var ExternalThreadRuntime = class {
|
|
|
59388
59509
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
59389
59510
|
var INTERNAL_REQUEST_PREFIX = "codexhost:official:";
|
|
59390
59511
|
var MAX_RETIRED_IDS = 1024;
|
|
59391
|
-
function
|
|
59512
|
+
function isRecord24(value) {
|
|
59392
59513
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59393
59514
|
}
|
|
59394
59515
|
var OfficialRequestBroker = class {
|
|
@@ -59431,7 +59552,7 @@ var OfficialRequestBroker = class {
|
|
|
59431
59552
|
});
|
|
59432
59553
|
}
|
|
59433
59554
|
handle(value) {
|
|
59434
|
-
if (!
|
|
59555
|
+
if (!isRecord24(value) || typeof value.id !== "string") return false;
|
|
59435
59556
|
const pending = this.#pending.get(value.id);
|
|
59436
59557
|
if (!pending) return this.#retired.has(value.id);
|
|
59437
59558
|
clearTimeout(pending.timeout);
|
|
@@ -59460,11 +59581,11 @@ var OfficialRequestBroker = class {
|
|
|
59460
59581
|
};
|
|
59461
59582
|
|
|
59462
59583
|
// packages/host-runtime/src/route-observation.ts
|
|
59463
|
-
function
|
|
59584
|
+
function isRecord25(value) {
|
|
59464
59585
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59465
59586
|
}
|
|
59466
59587
|
function classifyThreadPurpose(request) {
|
|
59467
|
-
return
|
|
59588
|
+
return isRecord25(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
|
|
59468
59589
|
}
|
|
59469
59590
|
var RequestRouteObservationTracker = class {
|
|
59470
59591
|
#nextCreateOrdinal = 0;
|
|
@@ -59489,13 +59610,13 @@ var RequestRouteObservationTracker = class {
|
|
|
59489
59610
|
this.#createByThreadId.set(threadId2, tracked);
|
|
59490
59611
|
}
|
|
59491
59612
|
bindOfficialResponse(response) {
|
|
59492
|
-
if (!
|
|
59613
|
+
if (!isRecord25(response) || !("id" in response)) return;
|
|
59493
59614
|
const tracked = this.#pendingByRequestId.get(response.id);
|
|
59494
59615
|
if (!tracked) return;
|
|
59495
59616
|
this.#pendingByRequestId.delete(response.id);
|
|
59496
59617
|
const result = response.result;
|
|
59497
|
-
const thread =
|
|
59498
|
-
if (
|
|
59618
|
+
const thread = isRecord25(result) ? result.thread : null;
|
|
59619
|
+
if (isRecord25(thread) && typeof thread.id === "string") {
|
|
59499
59620
|
this.#createByThreadId.set(thread.id, tracked);
|
|
59500
59621
|
}
|
|
59501
59622
|
}
|
|
@@ -59592,25 +59713,25 @@ function resolveExternalSessionTreeIds(records) {
|
|
|
59592
59713
|
const resolve2 = (start) => {
|
|
59593
59714
|
const cached2 = resolved.get(start.hostThreadId);
|
|
59594
59715
|
if (cached2) return cached2;
|
|
59595
|
-
const
|
|
59716
|
+
const path19 = [];
|
|
59596
59717
|
const visited = /* @__PURE__ */ new Set();
|
|
59597
59718
|
let current = start;
|
|
59598
59719
|
while (true) {
|
|
59599
59720
|
const known = resolved.get(current.hostThreadId);
|
|
59600
59721
|
if (known) {
|
|
59601
|
-
for (const record3 of
|
|
59722
|
+
for (const record3 of path19) resolved.set(record3.hostThreadId, known);
|
|
59602
59723
|
return known;
|
|
59603
59724
|
}
|
|
59604
59725
|
if (visited.has(current.hostThreadId)) {
|
|
59605
59726
|
throw new Error("External Thread Fork tree contains a cycle");
|
|
59606
59727
|
}
|
|
59607
59728
|
visited.add(current.hostThreadId);
|
|
59608
|
-
|
|
59729
|
+
path19.push(current);
|
|
59609
59730
|
const sourceId = current.forkSource?.hostThreadId;
|
|
59610
59731
|
const source = sourceId ? byId.get(sourceId) : void 0;
|
|
59611
59732
|
if (!source) {
|
|
59612
59733
|
const root = current.hostThreadId;
|
|
59613
|
-
for (const record3 of
|
|
59734
|
+
for (const record3 of path19) resolved.set(record3.hostThreadId, root);
|
|
59614
59735
|
return root;
|
|
59615
59736
|
}
|
|
59616
59737
|
current = source;
|
|
@@ -59661,11 +59782,11 @@ var OfficialThreadListError = class extends Error {
|
|
|
59661
59782
|
}
|
|
59662
59783
|
rpcError;
|
|
59663
59784
|
};
|
|
59664
|
-
function
|
|
59785
|
+
function isRecord26(value) {
|
|
59665
59786
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59666
59787
|
}
|
|
59667
59788
|
function officialThreadListPageFromResponse(response) {
|
|
59668
|
-
if (
|
|
59789
|
+
if (isRecord26(response.error)) {
|
|
59669
59790
|
if (!Number.isSafeInteger(response.error.code) || typeof response.error.message !== "string") {
|
|
59670
59791
|
throw new Error("Official thread/list error response is invalid");
|
|
59671
59792
|
}
|
|
@@ -59825,14 +59946,14 @@ async function aggregateThreadList(input) {
|
|
|
59825
59946
|
}
|
|
59826
59947
|
|
|
59827
59948
|
// packages/host-runtime/src/app-server-host.ts
|
|
59828
|
-
function
|
|
59949
|
+
function isRecord27(value) {
|
|
59829
59950
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59830
59951
|
}
|
|
59831
59952
|
function isCreditsAdapter(adapter) {
|
|
59832
59953
|
return typeof adapter.credits === "function" && typeof adapter.refreshCredits === "function";
|
|
59833
59954
|
}
|
|
59834
59955
|
function projectAccountCredits(value) {
|
|
59835
|
-
if (!
|
|
59956
|
+
if (!isRecord27(value)) return null;
|
|
59836
59957
|
const rest = { ...value };
|
|
59837
59958
|
delete rest.fetchedAt;
|
|
59838
59959
|
const parsed = accountCreditsSnapshotSchema.safeParse(rest);
|
|
@@ -59932,12 +60053,12 @@ function classifyCreateRequestRoute(request, defaultAgent2) {
|
|
|
59932
60053
|
};
|
|
59933
60054
|
}
|
|
59934
60055
|
function requestObject(request) {
|
|
59935
|
-
if (!
|
|
60056
|
+
if (!isRecord27(request.params)) throw new Error(`${request.method} params must be an object`);
|
|
59936
60057
|
return request.params;
|
|
59937
60058
|
}
|
|
59938
60059
|
function requestText(params) {
|
|
59939
60060
|
if (!Array.isArray(params.input)) throw new Error("turn/start input must be an array");
|
|
59940
|
-
const text = params.input.filter((item) =>
|
|
60061
|
+
const text = params.input.filter((item) => isRecord27(item) && item.type === "text").map((item) => item.text).filter((value) => typeof value === "string").join("\n");
|
|
59941
60062
|
if (!text) throw new Error("turn/start must contain text input");
|
|
59942
60063
|
return text;
|
|
59943
60064
|
}
|
|
@@ -60211,7 +60332,7 @@ var AppServerHost = class {
|
|
|
60211
60332
|
continue;
|
|
60212
60333
|
}
|
|
60213
60334
|
if (request.method === "thread/fork") {
|
|
60214
|
-
const params =
|
|
60335
|
+
const params = isRecord27(request.params) ? request.params : {};
|
|
60215
60336
|
const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
|
|
60216
60337
|
if (resolution.kind === "error") {
|
|
60217
60338
|
await this.#writer.json(
|
|
@@ -60234,7 +60355,7 @@ var AppServerHost = class {
|
|
|
60234
60355
|
}
|
|
60235
60356
|
}
|
|
60236
60357
|
if (request.method === "thread/rollback") {
|
|
60237
|
-
const params =
|
|
60358
|
+
const params = isRecord27(request.params) ? request.params : {};
|
|
60238
60359
|
const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
|
|
60239
60360
|
if (resolution.kind === "error") {
|
|
60240
60361
|
await this.#writer.json(
|
|
@@ -60374,7 +60495,7 @@ var AppServerHost = class {
|
|
|
60374
60495
|
continue;
|
|
60375
60496
|
}
|
|
60376
60497
|
}
|
|
60377
|
-
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) &&
|
|
60498
|
+
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) && isRecord27(request.params) && typeof request.params.threadId === "string") {
|
|
60378
60499
|
const location = await this.#locateExternalThread(request.params.threadId);
|
|
60379
60500
|
if (await this.#writeResolutionError(request, location)) continue;
|
|
60380
60501
|
if (location.kind === "external") {
|
|
@@ -61197,10 +61318,10 @@ var AppServerHost = class {
|
|
|
61197
61318
|
...typeof params.serviceTier === "string" ? { serviceTier: params.serviceTier } : {}
|
|
61198
61319
|
});
|
|
61199
61320
|
try {
|
|
61200
|
-
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !
|
|
61321
|
+
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !isRecord27(params.initialTurnsPage)) {
|
|
61201
61322
|
throw new ExternalHistoryRequestError("initialTurnsPage must be an object");
|
|
61202
61323
|
}
|
|
61203
|
-
const initialPageParams =
|
|
61324
|
+
const initialPageParams = isRecord27(params.initialTurnsPage) ? params.initialTurnsPage : null;
|
|
61204
61325
|
const initialTurnsPage = initialPageParams ? listExternalTurns(turns, initialPageParams) : null;
|
|
61205
61326
|
const paginated = thread.record.historyMode === "paginated";
|
|
61206
61327
|
const turnsBackwardsCursor = paginated ? listExternalTurns(turns, { limit: 1, itemsView: "notLoaded" }).backwardsCursor : null;
|
|
@@ -61452,7 +61573,7 @@ var AppServerHost = class {
|
|
|
61452
61573
|
}
|
|
61453
61574
|
}
|
|
61454
61575
|
async #handleDesktopApprovalResponse(value) {
|
|
61455
|
-
if (!
|
|
61576
|
+
if (!isRecord27(value) || !isHostApprovalRequestId(value.id)) return false;
|
|
61456
61577
|
const pending = this.#pendingDesktopApprovals.get(value.id);
|
|
61457
61578
|
if (!pending) return true;
|
|
61458
61579
|
this.#pendingDesktopApprovals.delete(value.id);
|
|
@@ -61574,7 +61695,7 @@ var AppServerHost = class {
|
|
|
61574
61695
|
}
|
|
61575
61696
|
}
|
|
61576
61697
|
async #handleDesktopQuestionResponse(value) {
|
|
61577
|
-
if (!
|
|
61698
|
+
if (!isRecord27(value) || !isHostQuestionRequestId(value.id)) return false;
|
|
61578
61699
|
const pending = this.#pendingDesktopQuestions.get(value.id);
|
|
61579
61700
|
if (!pending) return true;
|
|
61580
61701
|
this.#pendingDesktopQuestions.delete(value.id);
|
|
@@ -61686,7 +61807,7 @@ var AppServerHost = class {
|
|
|
61686
61807
|
|
|
61687
61808
|
// packages/update-manager/dist/distribution.js
|
|
61688
61809
|
import { lstat, readFile as readFile4 } from "node:fs/promises";
|
|
61689
|
-
import
|
|
61810
|
+
import path16 from "node:path";
|
|
61690
61811
|
|
|
61691
61812
|
// packages/update-manager/dist/status.js
|
|
61692
61813
|
var STATUS_SCHEMA_VERSION = 1;
|
|
@@ -61773,9 +61894,9 @@ function parseDistributionMetadata(value) {
|
|
|
61773
61894
|
}
|
|
61774
61895
|
function absoluteEnvironmentPath(environment, name) {
|
|
61775
61896
|
const value = environment[name];
|
|
61776
|
-
if (!value || !
|
|
61897
|
+
if (!value || !path16.isAbsolute(value))
|
|
61777
61898
|
throw new Error(`${name} must be an absolute path`);
|
|
61778
|
-
return
|
|
61899
|
+
return path16.normalize(value);
|
|
61779
61900
|
}
|
|
61780
61901
|
function positiveEnvironmentInteger(environment, name) {
|
|
61781
61902
|
const value = Number(environment[name]);
|
|
@@ -61799,29 +61920,29 @@ function expectedTarget(platform, architecture) {
|
|
|
61799
61920
|
function defaultUpdateStateDirectory(platform = process.platform, environment = process.env) {
|
|
61800
61921
|
if (platform === "win32") {
|
|
61801
61922
|
const root = environment.LOCALAPPDATA;
|
|
61802
|
-
if (!root || !
|
|
61923
|
+
if (!root || !path16.isAbsolute(root))
|
|
61803
61924
|
throw new Error("LOCALAPPDATA is unavailable");
|
|
61804
|
-
return
|
|
61925
|
+
return path16.join(root, "codexhost", "updates");
|
|
61805
61926
|
}
|
|
61806
61927
|
const home = environment.HOME;
|
|
61807
|
-
if (!home || !
|
|
61928
|
+
if (!home || !path16.isAbsolute(home))
|
|
61808
61929
|
throw new Error("HOME is unavailable");
|
|
61809
|
-
return platform === "darwin" ?
|
|
61930
|
+
return platform === "darwin" ? path16.join(home, "Library", "Application Support", "codexhost", "updates") : path16.join(home, ".codexhost", "updates");
|
|
61810
61931
|
}
|
|
61811
61932
|
async function resolveInstalledUpdateContext(options) {
|
|
61812
61933
|
const environment = options.environment ?? process.env;
|
|
61813
61934
|
const platform = options.platform ?? process.platform;
|
|
61814
61935
|
const architecture = options.architecture ?? process.arch;
|
|
61815
|
-
if (!
|
|
61936
|
+
if (!path16.isAbsolute(options.hostRuntimePath)) {
|
|
61816
61937
|
throw new Error("Host Runtime path must be absolute");
|
|
61817
61938
|
}
|
|
61818
|
-
const hostRuntimePath =
|
|
61939
|
+
const hostRuntimePath = path16.normalize(options.hostRuntimePath);
|
|
61819
61940
|
const runtimeMetadata = await lstat(hostRuntimePath);
|
|
61820
61941
|
if (!runtimeMetadata.isFile() || runtimeMetadata.isSymbolicLink()) {
|
|
61821
61942
|
throw new Error("Host Runtime must be a regular file");
|
|
61822
61943
|
}
|
|
61823
|
-
const appDirectory =
|
|
61824
|
-
const metadata = parseDistributionMetadata(JSON.parse(await readFile4(
|
|
61944
|
+
const appDirectory = path16.dirname(hostRuntimePath);
|
|
61945
|
+
const metadata = parseDistributionMetadata(JSON.parse(await readFile4(path16.join(appDirectory, "codexhost-distribution.json"), "utf8")));
|
|
61825
61946
|
const target = expectedTarget(platform, architecture);
|
|
61826
61947
|
if (metadata.target !== target) {
|
|
61827
61948
|
throw new Error(`installed target ${metadata.target} does not match ${target}`);
|
|
@@ -61829,10 +61950,10 @@ async function resolveInstalledUpdateContext(options) {
|
|
|
61829
61950
|
const launcherPid = positiveEnvironmentInteger(environment, UPDATE_RUNTIME_ENV.launcherPid);
|
|
61830
61951
|
const launcherExecutable = absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.launcherExecutable);
|
|
61831
61952
|
const runtimeDescriptorPath = absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.runtimeDescriptorPath);
|
|
61832
|
-
const stateDirectory =
|
|
61833
|
-
const resourcesRoot =
|
|
61834
|
-
const installationRoot = platform === "darwin" ?
|
|
61835
|
-
const updaterExecutable =
|
|
61953
|
+
const stateDirectory = path16.normalize(options.stateDirectory ?? defaultUpdateStateDirectory(platform, environment));
|
|
61954
|
+
const resourcesRoot = path16.dirname(appDirectory);
|
|
61955
|
+
const installationRoot = platform === "darwin" ? path16.dirname(path16.dirname(resourcesRoot)) : resourcesRoot;
|
|
61956
|
+
const updaterExecutable = path16.join(resourcesRoot, "libexec", platform === "win32" ? "codexhost-updater.exe" : "codexhost-updater");
|
|
61836
61957
|
const common = {
|
|
61837
61958
|
version: metadata.version,
|
|
61838
61959
|
launcherPid,
|
|
@@ -61856,7 +61977,7 @@ async function resolveInstalledUpdateContext(options) {
|
|
|
61856
61977
|
npmLauncherPath: absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmLauncherPath),
|
|
61857
61978
|
packageRoot: absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmPackageRoot)
|
|
61858
61979
|
};
|
|
61859
|
-
if (
|
|
61980
|
+
if (path16.normalize(npmOptions.packageRoot) !== resourcesRoot) {
|
|
61860
61981
|
throw new Error("npm platform package root does not own the Host Runtime");
|
|
61861
61982
|
}
|
|
61862
61983
|
return { metadata, common, controller, installation: { kind: "npm", options: npmOptions } };
|
|
@@ -62019,7 +62140,7 @@ function selectInstallerReleaseArtifact(release, target) {
|
|
|
62019
62140
|
|
|
62020
62141
|
// packages/update-manager/dist/operation-state.js
|
|
62021
62142
|
import { lstat as lstat2, mkdir as mkdir2, open as open3, readFile as readFile5, readdir as readdir2, rm as rm3, writeFile } from "node:fs/promises";
|
|
62022
|
-
import
|
|
62143
|
+
import path17 from "node:path";
|
|
62023
62144
|
var LOCK_FILE = "active-update-v1.lock";
|
|
62024
62145
|
var STATUS_FILE = "status-v1.json";
|
|
62025
62146
|
var TERMINAL_PHASES = /* @__PURE__ */ new Set(["succeeded", "failed"]);
|
|
@@ -62034,12 +62155,12 @@ async function regularFile(filePath) {
|
|
|
62034
62155
|
}
|
|
62035
62156
|
}
|
|
62036
62157
|
async function isUpdateOperationActive(stateDirectory) {
|
|
62037
|
-
if (!
|
|
62158
|
+
if (!path17.isAbsolute(stateDirectory))
|
|
62038
62159
|
throw new Error("update state directory must be absolute");
|
|
62039
|
-
return regularFile(
|
|
62160
|
+
return regularFile(path17.join(stateDirectory, LOCK_FILE));
|
|
62040
62161
|
}
|
|
62041
62162
|
async function discoverLatestUpdateStatus(stateDirectory) {
|
|
62042
|
-
if (!
|
|
62163
|
+
if (!path17.isAbsolute(stateDirectory))
|
|
62043
62164
|
throw new Error("update state directory must be absolute");
|
|
62044
62165
|
let entries;
|
|
62045
62166
|
try {
|
|
@@ -62053,7 +62174,7 @@ async function discoverLatestUpdateStatus(stateDirectory) {
|
|
|
62053
62174
|
for (const entry of entries) {
|
|
62054
62175
|
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith("update-"))
|
|
62055
62176
|
continue;
|
|
62056
|
-
const statusPath =
|
|
62177
|
+
const statusPath = path17.join(stateDirectory, entry.name, STATUS_FILE);
|
|
62057
62178
|
if (!await regularFile(statusPath))
|
|
62058
62179
|
continue;
|
|
62059
62180
|
try {
|
|
@@ -62081,8 +62202,8 @@ async function cleanupTerminalUpdateState(stateDirectory, options = {}) {
|
|
|
62081
62202
|
for (const entry of entries) {
|
|
62082
62203
|
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith("update-"))
|
|
62083
62204
|
continue;
|
|
62084
|
-
const directory =
|
|
62085
|
-
const statusPath =
|
|
62205
|
+
const directory = path17.join(stateDirectory, entry.name);
|
|
62206
|
+
const statusPath = path17.join(directory, STATUS_FILE);
|
|
62086
62207
|
try {
|
|
62087
62208
|
const status = parseUpdateStatus(JSON.parse(await readFile5(statusPath, "utf8")));
|
|
62088
62209
|
if (TERMINAL_PHASES.has(status.phase) && now - status.updatedAt > retentionSeconds) {
|
|
@@ -62093,10 +62214,10 @@ async function cleanupTerminalUpdateState(stateDirectory, options = {}) {
|
|
|
62093
62214
|
}
|
|
62094
62215
|
}
|
|
62095
62216
|
async function acquireUpdateOperationLock(stateDirectory) {
|
|
62096
|
-
if (!
|
|
62217
|
+
if (!path17.isAbsolute(stateDirectory))
|
|
62097
62218
|
throw new Error("update state directory must be absolute");
|
|
62098
62219
|
await mkdir2(stateDirectory, { recursive: true, mode: 448 });
|
|
62099
|
-
const lockPath =
|
|
62220
|
+
const lockPath = path17.join(stateDirectory, LOCK_FILE);
|
|
62100
62221
|
let handle;
|
|
62101
62222
|
try {
|
|
62102
62223
|
handle = await open3(lockPath, "wx", 384);
|
|
@@ -62115,9 +62236,9 @@ async function acquireUpdateOperationLock(stateDirectory) {
|
|
|
62115
62236
|
async setStatusPath(statusPath) {
|
|
62116
62237
|
if (released)
|
|
62117
62238
|
throw new Error("update operation lock is released");
|
|
62118
|
-
if (!
|
|
62239
|
+
if (!path17.isAbsolute(statusPath))
|
|
62119
62240
|
throw new Error("update status path must be absolute");
|
|
62120
|
-
await writeFile(lockPath, `${JSON.stringify({ ownerPid: process.pid, statusPath:
|
|
62241
|
+
await writeFile(lockPath, `${JSON.stringify({ ownerPid: process.pid, statusPath: path17.normalize(statusPath) })}
|
|
62121
62242
|
`, { encoding: "utf8", mode: 384 });
|
|
62122
62243
|
},
|
|
62123
62244
|
async release() {
|
|
@@ -62139,7 +62260,7 @@ function processIsAlive(processId) {
|
|
|
62139
62260
|
}
|
|
62140
62261
|
}
|
|
62141
62262
|
async function recoverUpdateOperationLock(stateDirectory) {
|
|
62142
|
-
const lockPath =
|
|
62263
|
+
const lockPath = path17.join(stateDirectory, LOCK_FILE);
|
|
62143
62264
|
if (!await regularFile(lockPath))
|
|
62144
62265
|
return;
|
|
62145
62266
|
let ownerPid;
|
|
@@ -62151,7 +62272,7 @@ async function recoverUpdateOperationLock(stateDirectory) {
|
|
|
62151
62272
|
} catch {
|
|
62152
62273
|
return;
|
|
62153
62274
|
}
|
|
62154
|
-
if (typeof statusPath !== "string" || !
|
|
62275
|
+
if (typeof statusPath !== "string" || !path17.isAbsolute(statusPath))
|
|
62155
62276
|
return;
|
|
62156
62277
|
try {
|
|
62157
62278
|
const status = parseUpdateStatus(JSON.parse(await readFile5(statusPath, "utf8")));
|
|
@@ -62166,7 +62287,7 @@ async function recoverUpdateOperationLock(stateDirectory) {
|
|
|
62166
62287
|
import { spawn as spawn6 } from "node:child_process";
|
|
62167
62288
|
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
62168
62289
|
import { chmod, copyFile as copyFile2, lstat as lstat4, mkdir as mkdir3, readFile as readFile6, rename as rename2, rm as rm4, writeFile as writeFile2 } from "node:fs/promises";
|
|
62169
|
-
import
|
|
62290
|
+
import path18 from "node:path";
|
|
62170
62291
|
|
|
62171
62292
|
// packages/update-manager/dist/artifact.js
|
|
62172
62293
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -62287,9 +62408,9 @@ async function replaceStatusFile(temporaryPath, statusPath) {
|
|
|
62287
62408
|
}
|
|
62288
62409
|
}
|
|
62289
62410
|
function requireAbsolutePath(value, label) {
|
|
62290
|
-
if (!
|
|
62411
|
+
if (!path18.isAbsolute(value))
|
|
62291
62412
|
throw new Error(`${label} must be an absolute path`);
|
|
62292
|
-
return
|
|
62413
|
+
return path18.normalize(value);
|
|
62293
62414
|
}
|
|
62294
62415
|
async function requireRegularFile(value, label) {
|
|
62295
62416
|
const filePath = requireAbsolutePath(value, label);
|
|
@@ -62332,7 +62453,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62332
62453
|
const now = dependencies.now ?? Date.now;
|
|
62333
62454
|
const preparedRequests = /* @__PURE__ */ new Set();
|
|
62334
62455
|
async function writeStatusSnapshot(statusPath, status) {
|
|
62335
|
-
const temporaryPath =
|
|
62456
|
+
const temporaryPath = path18.join(path18.dirname(statusPath), `.update-status-${randomId()}.tmp`);
|
|
62336
62457
|
try {
|
|
62337
62458
|
await writeFile2(temporaryPath, `${JSON.stringify(status)}
|
|
62338
62459
|
`, {
|
|
@@ -62392,15 +62513,15 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62392
62513
|
const updaterExecutable = await requireRegularFile(options.updaterExecutable, "Updater executable");
|
|
62393
62514
|
const stateDirectory = requireAbsolutePath(options.stateDirectory, "update state directory");
|
|
62394
62515
|
await mkdir3(stateDirectory, { recursive: true, mode: 448 });
|
|
62395
|
-
const workDirectory =
|
|
62516
|
+
const workDirectory = path18.join(stateDirectory, `update-${version2}-${randomId()}`);
|
|
62396
62517
|
await mkdir3(workDirectory, { recursive: false, mode: 448 });
|
|
62397
62518
|
const executableSuffix = platform === "win32" ? ".exe" : "";
|
|
62398
|
-
const helperPath =
|
|
62519
|
+
const helperPath = path18.join(workDirectory, `codexhost-updater${executableSuffix}`);
|
|
62399
62520
|
await copyFile2(updaterExecutable, helperPath);
|
|
62400
62521
|
if (platform !== "win32")
|
|
62401
62522
|
await chmod(helperPath, 448);
|
|
62402
|
-
const requestPath =
|
|
62403
|
-
const statusPath =
|
|
62523
|
+
const requestPath = path18.join(workDirectory, "request-v1.json");
|
|
62524
|
+
const statusPath = path18.join(workDirectory, "status-v1.json");
|
|
62404
62525
|
await writePrivateJson(statusPath, preparedStatus(version2, installation, now()));
|
|
62405
62526
|
await options.onPrepared?.({ version: version2, installation, statusPath });
|
|
62406
62527
|
return {
|
|
@@ -62416,8 +62537,8 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62416
62537
|
}
|
|
62417
62538
|
async function prepareArtifact(common, installation, sourceValue, fileName) {
|
|
62418
62539
|
const source = validateArtifact(sourceValue);
|
|
62419
|
-
const temporaryPath =
|
|
62420
|
-
const artifactPath =
|
|
62540
|
+
const temporaryPath = path18.join(common.workDirectory, `.${fileName}.download`);
|
|
62541
|
+
const artifactPath = path18.join(common.workDirectory, fileName);
|
|
62421
62542
|
const progress = progressReporter(common.statusPath, common.version, installation, source.size);
|
|
62422
62543
|
try {
|
|
62423
62544
|
const result = await download(source, temporaryPath, progress.update);
|
|
@@ -62491,7 +62612,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62491
62612
|
throw new Error("macOS DMG updates require macOS");
|
|
62492
62613
|
const common = await prepareCommon(options, "macos-dmg");
|
|
62493
62614
|
const appPath = requireAbsolutePath(options.appPath, "macOS application path");
|
|
62494
|
-
if (
|
|
62615
|
+
if (path18.extname(appPath) !== ".app") {
|
|
62495
62616
|
throw new Error("macOS application path must end in .app");
|
|
62496
62617
|
}
|
|
62497
62618
|
const artifact = await prepareArtifact(common, "macos-dmg", options.artifact, "update.dmg");
|