@liberseek/boft-cli-win32-arm64 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/host-runtime.mjs +182 -127
- package/app/plugins/claude-code/plugin.mjs +664 -229
- package/app/plugins/deepseek-harness/plugin.mjs +82 -17
- package/app/plugins/grok/plugin.mjs +6 -0
- package/app/plugins/kiro-cli/plugin.mjs +77 -61
- package/app/plugins/omp/plugin.mjs +6 -0
- package/app/plugins/opencode/plugin.mjs +292 -142
- package/app/plugins/pi/plugin.mjs +1489 -1304
- package/app/renderer-extension.js +17 -23
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
|
@@ -5,529 +5,9 @@ var __export = (target, all) => {
|
|
|
5
5
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let callback;
|
|
12
|
-
if (typeof options === "function") {
|
|
13
|
-
callback = options;
|
|
14
|
-
options = {};
|
|
15
|
-
} else if ("callback" in options) {
|
|
16
|
-
callback = options.callback;
|
|
17
|
-
}
|
|
18
|
-
const oldString = this.castInput(oldStr, options);
|
|
19
|
-
const newString = this.castInput(newStr, options);
|
|
20
|
-
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
21
|
-
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
22
|
-
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
23
|
-
}
|
|
24
|
-
diffWithOptionsObj(oldTokens, newTokens, options, callback) {
|
|
25
|
-
var _a3;
|
|
26
|
-
const done = (value) => {
|
|
27
|
-
value = this.postProcess(value, options);
|
|
28
|
-
if (callback) {
|
|
29
|
-
setTimeout(function() {
|
|
30
|
-
callback(value);
|
|
31
|
-
}, 0);
|
|
32
|
-
return void 0;
|
|
33
|
-
} else {
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
38
|
-
let editLength = 1;
|
|
39
|
-
let maxEditLength = newLen + oldLen;
|
|
40
|
-
if (options.maxEditLength != null) {
|
|
41
|
-
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
42
|
-
}
|
|
43
|
-
const maxExecutionTime = (_a3 = options.timeout) !== null && _a3 !== void 0 ? _a3 : Infinity;
|
|
44
|
-
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
45
|
-
const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
|
|
46
|
-
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
47
|
-
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
48
|
-
return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
49
|
-
}
|
|
50
|
-
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
51
|
-
const execEditLength = () => {
|
|
52
|
-
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
53
|
-
let basePath;
|
|
54
|
-
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
55
|
-
if (removePath) {
|
|
56
|
-
bestPath[diagonalPath - 1] = void 0;
|
|
57
|
-
}
|
|
58
|
-
let canAdd = false;
|
|
59
|
-
if (addPath) {
|
|
60
|
-
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
61
|
-
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
62
|
-
}
|
|
63
|
-
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
64
|
-
if (!canAdd && !canRemove) {
|
|
65
|
-
bestPath[diagonalPath] = void 0;
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
69
|
-
basePath = this.addToPath(addPath, true, false, 0, options);
|
|
70
|
-
} else {
|
|
71
|
-
basePath = this.addToPath(removePath, false, true, 1, options);
|
|
72
|
-
}
|
|
73
|
-
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
74
|
-
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
75
|
-
return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
76
|
-
} else {
|
|
77
|
-
bestPath[diagonalPath] = basePath;
|
|
78
|
-
if (basePath.oldPos + 1 >= oldLen) {
|
|
79
|
-
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
80
|
-
}
|
|
81
|
-
if (newPos + 1 >= newLen) {
|
|
82
|
-
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
editLength++;
|
|
87
|
-
};
|
|
88
|
-
if (callback) {
|
|
89
|
-
(function exec() {
|
|
90
|
-
setTimeout(function() {
|
|
91
|
-
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
92
|
-
return callback(void 0);
|
|
93
|
-
}
|
|
94
|
-
if (!execEditLength()) {
|
|
95
|
-
exec();
|
|
96
|
-
}
|
|
97
|
-
}, 0);
|
|
98
|
-
})();
|
|
99
|
-
} else {
|
|
100
|
-
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
101
|
-
const ret = execEditLength();
|
|
102
|
-
if (ret) {
|
|
103
|
-
return ret;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
addToPath(path6, added, removed, oldPosInc, options) {
|
|
109
|
-
const last = path6.lastComponent;
|
|
110
|
-
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
111
|
-
return {
|
|
112
|
-
oldPos: path6.oldPos + oldPosInc,
|
|
113
|
-
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
114
|
-
};
|
|
115
|
-
} else {
|
|
116
|
-
return {
|
|
117
|
-
oldPos: path6.oldPos + oldPosInc,
|
|
118
|
-
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
|
|
123
|
-
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
124
|
-
let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
125
|
-
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
|
|
126
|
-
newPos++;
|
|
127
|
-
oldPos++;
|
|
128
|
-
commonCount++;
|
|
129
|
-
if (options.oneChangePerToken) {
|
|
130
|
-
basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (commonCount && !options.oneChangePerToken) {
|
|
134
|
-
basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
135
|
-
}
|
|
136
|
-
basePath.oldPos = oldPos;
|
|
137
|
-
return newPos;
|
|
138
|
-
}
|
|
139
|
-
equals(left, right, options) {
|
|
140
|
-
if (options.comparator) {
|
|
141
|
-
return options.comparator(left, right);
|
|
142
|
-
} else {
|
|
143
|
-
return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
removeEmpty(array2) {
|
|
147
|
-
const ret = [];
|
|
148
|
-
for (let i = 0; i < array2.length; i++) {
|
|
149
|
-
if (array2[i]) {
|
|
150
|
-
ret.push(array2[i]);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return ret;
|
|
154
|
-
}
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
156
|
-
castInput(value, options) {
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
160
|
-
tokenize(value, options) {
|
|
161
|
-
return Array.from(value);
|
|
162
|
-
}
|
|
163
|
-
join(chars) {
|
|
164
|
-
return chars.join("");
|
|
165
|
-
}
|
|
166
|
-
postProcess(changeObjects, options) {
|
|
167
|
-
return changeObjects;
|
|
168
|
-
}
|
|
169
|
-
get useLongestToken() {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
buildValues(lastComponent, newTokens, oldTokens) {
|
|
173
|
-
const components = [];
|
|
174
|
-
let nextComponent;
|
|
175
|
-
while (lastComponent) {
|
|
176
|
-
components.push(lastComponent);
|
|
177
|
-
nextComponent = lastComponent.previousComponent;
|
|
178
|
-
delete lastComponent.previousComponent;
|
|
179
|
-
lastComponent = nextComponent;
|
|
180
|
-
}
|
|
181
|
-
components.reverse();
|
|
182
|
-
const componentLen = components.length;
|
|
183
|
-
let componentPos = 0, newPos = 0, oldPos = 0;
|
|
184
|
-
for (; componentPos < componentLen; componentPos++) {
|
|
185
|
-
const component = components[componentPos];
|
|
186
|
-
if (!component.removed) {
|
|
187
|
-
if (!component.added && this.useLongestToken) {
|
|
188
|
-
let value = newTokens.slice(newPos, newPos + component.count);
|
|
189
|
-
value = value.map(function(value2, i) {
|
|
190
|
-
const oldValue = oldTokens[oldPos + i];
|
|
191
|
-
return oldValue.length > value2.length ? oldValue : value2;
|
|
192
|
-
});
|
|
193
|
-
component.value = this.join(value);
|
|
194
|
-
} else {
|
|
195
|
-
component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
196
|
-
}
|
|
197
|
-
newPos += component.count;
|
|
198
|
-
if (!component.added) {
|
|
199
|
-
oldPos += component.count;
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
203
|
-
oldPos += component.count;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return components;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
// ../../../node_modules/diff/libesm/diff/line.js
|
|
211
|
-
var LineDiff = class extends Diff {
|
|
212
|
-
constructor() {
|
|
213
|
-
super(...arguments);
|
|
214
|
-
this.tokenize = tokenize;
|
|
215
|
-
}
|
|
216
|
-
equals(left, right, options) {
|
|
217
|
-
if (options.ignoreWhitespace) {
|
|
218
|
-
if (!options.newlineIsToken || !left.includes("\n")) {
|
|
219
|
-
left = left.trim();
|
|
220
|
-
}
|
|
221
|
-
if (!options.newlineIsToken || !right.includes("\n")) {
|
|
222
|
-
right = right.trim();
|
|
223
|
-
}
|
|
224
|
-
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
225
|
-
if (left.endsWith("\n")) {
|
|
226
|
-
left = left.slice(0, -1);
|
|
227
|
-
}
|
|
228
|
-
if (right.endsWith("\n")) {
|
|
229
|
-
right = right.slice(0, -1);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return super.equals(left, right, options);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
var lineDiff = new LineDiff();
|
|
236
|
-
function diffLines(oldStr, newStr, options) {
|
|
237
|
-
return lineDiff.diff(oldStr, newStr, options);
|
|
238
|
-
}
|
|
239
|
-
function tokenize(value, options) {
|
|
240
|
-
if (options.stripTrailingCr) {
|
|
241
|
-
value = value.replace(/\r\n/g, "\n");
|
|
242
|
-
}
|
|
243
|
-
const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
244
|
-
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
245
|
-
linesAndNewlines.pop();
|
|
246
|
-
}
|
|
247
|
-
for (let i = 0; i < linesAndNewlines.length; i++) {
|
|
248
|
-
const line = linesAndNewlines[i];
|
|
249
|
-
if (i % 2 && !options.newlineIsToken) {
|
|
250
|
-
retLines[retLines.length - 1] += line;
|
|
251
|
-
} else {
|
|
252
|
-
retLines.push(line);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return retLines;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// ../../../node_modules/diff/libesm/patch/parse.js
|
|
259
|
-
function parsePatch(uniDiff) {
|
|
260
|
-
const diffstr = uniDiff.split(/\n/), list = [];
|
|
261
|
-
let i = 0;
|
|
262
|
-
function parseIndex() {
|
|
263
|
-
const index = {};
|
|
264
|
-
list.push(index);
|
|
265
|
-
while (i < diffstr.length) {
|
|
266
|
-
const line = diffstr[i];
|
|
267
|
-
if (/^(---|\+\+\+|@@)\s/.test(line)) {
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
const header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
|
|
271
|
-
if (header) {
|
|
272
|
-
index.index = header[1];
|
|
273
|
-
}
|
|
274
|
-
i++;
|
|
275
|
-
}
|
|
276
|
-
parseFileHeader(index);
|
|
277
|
-
parseFileHeader(index);
|
|
278
|
-
index.hunks = [];
|
|
279
|
-
while (i < diffstr.length) {
|
|
280
|
-
const line = diffstr[i];
|
|
281
|
-
if (/^(Index:\s|diff\s|---\s|\+\+\+\s|===================================================================)/.test(line)) {
|
|
282
|
-
break;
|
|
283
|
-
} else if (/^@@/.test(line)) {
|
|
284
|
-
index.hunks.push(parseHunk());
|
|
285
|
-
} else if (line) {
|
|
286
|
-
throw new Error("Unknown line " + (i + 1) + " " + JSON.stringify(line));
|
|
287
|
-
} else {
|
|
288
|
-
i++;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function parseFileHeader(index) {
|
|
293
|
-
const fileHeader = /^(---|\+\+\+)\s+(.*)\r?$/.exec(diffstr[i]);
|
|
294
|
-
if (fileHeader) {
|
|
295
|
-
const data = fileHeader[2].split(" ", 2), header = (data[1] || "").trim();
|
|
296
|
-
let fileName = data[0].replace(/\\\\/g, "\\");
|
|
297
|
-
if (/^".*"$/.test(fileName)) {
|
|
298
|
-
fileName = fileName.substr(1, fileName.length - 2);
|
|
299
|
-
}
|
|
300
|
-
if (fileHeader[1] === "---") {
|
|
301
|
-
index.oldFileName = fileName;
|
|
302
|
-
index.oldHeader = header;
|
|
303
|
-
} else {
|
|
304
|
-
index.newFileName = fileName;
|
|
305
|
-
index.newHeader = header;
|
|
306
|
-
}
|
|
307
|
-
i++;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
function parseHunk() {
|
|
311
|
-
var _a3;
|
|
312
|
-
const chunkHeaderIndex = i, chunkHeaderLine = diffstr[i++], chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|
313
|
-
const hunk = {
|
|
314
|
-
oldStart: +chunkHeader[1],
|
|
315
|
-
oldLines: typeof chunkHeader[2] === "undefined" ? 1 : +chunkHeader[2],
|
|
316
|
-
newStart: +chunkHeader[3],
|
|
317
|
-
newLines: typeof chunkHeader[4] === "undefined" ? 1 : +chunkHeader[4],
|
|
318
|
-
lines: []
|
|
319
|
-
};
|
|
320
|
-
if (hunk.oldLines === 0) {
|
|
321
|
-
hunk.oldStart += 1;
|
|
322
|
-
}
|
|
323
|
-
if (hunk.newLines === 0) {
|
|
324
|
-
hunk.newStart += 1;
|
|
325
|
-
}
|
|
326
|
-
let addCount = 0, removeCount = 0;
|
|
327
|
-
for (; i < diffstr.length && (removeCount < hunk.oldLines || addCount < hunk.newLines || ((_a3 = diffstr[i]) === null || _a3 === void 0 ? void 0 : _a3.startsWith("\\"))); i++) {
|
|
328
|
-
const operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? " " : diffstr[i][0];
|
|
329
|
-
if (operation === "+" || operation === "-" || operation === " " || operation === "\\") {
|
|
330
|
-
hunk.lines.push(diffstr[i]);
|
|
331
|
-
if (operation === "+") {
|
|
332
|
-
addCount++;
|
|
333
|
-
} else if (operation === "-") {
|
|
334
|
-
removeCount++;
|
|
335
|
-
} else if (operation === " ") {
|
|
336
|
-
addCount++;
|
|
337
|
-
removeCount++;
|
|
338
|
-
}
|
|
339
|
-
} else {
|
|
340
|
-
throw new Error(`Hunk at line ${chunkHeaderIndex + 1} contained invalid line ${diffstr[i]}`);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (!addCount && hunk.newLines === 1) {
|
|
344
|
-
hunk.newLines = 0;
|
|
345
|
-
}
|
|
346
|
-
if (!removeCount && hunk.oldLines === 1) {
|
|
347
|
-
hunk.oldLines = 0;
|
|
348
|
-
}
|
|
349
|
-
if (addCount !== hunk.newLines) {
|
|
350
|
-
throw new Error("Added line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
351
|
-
}
|
|
352
|
-
if (removeCount !== hunk.oldLines) {
|
|
353
|
-
throw new Error("Removed line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
354
|
-
}
|
|
355
|
-
return hunk;
|
|
356
|
-
}
|
|
357
|
-
while (i < diffstr.length) {
|
|
358
|
-
parseIndex();
|
|
359
|
-
}
|
|
360
|
-
return list;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// ../../../node_modules/diff/libesm/patch/create.js
|
|
364
|
-
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
365
|
-
let optionsObj;
|
|
366
|
-
if (!options) {
|
|
367
|
-
optionsObj = {};
|
|
368
|
-
} else if (typeof options === "function") {
|
|
369
|
-
optionsObj = { callback: options };
|
|
370
|
-
} else {
|
|
371
|
-
optionsObj = options;
|
|
372
|
-
}
|
|
373
|
-
if (typeof optionsObj.context === "undefined") {
|
|
374
|
-
optionsObj.context = 4;
|
|
375
|
-
}
|
|
376
|
-
const context = optionsObj.context;
|
|
377
|
-
if (optionsObj.newlineIsToken) {
|
|
378
|
-
throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
|
|
379
|
-
}
|
|
380
|
-
if (!optionsObj.callback) {
|
|
381
|
-
return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
|
|
382
|
-
} else {
|
|
383
|
-
const { callback } = optionsObj;
|
|
384
|
-
diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
|
|
385
|
-
const patch = diffLinesResultToPatch(diff);
|
|
386
|
-
callback(patch);
|
|
387
|
-
} }));
|
|
388
|
-
}
|
|
389
|
-
function diffLinesResultToPatch(diff) {
|
|
390
|
-
if (!diff) {
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
diff.push({ value: "", lines: [] });
|
|
394
|
-
function contextLines(lines) {
|
|
395
|
-
return lines.map(function(entry) {
|
|
396
|
-
return " " + entry;
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
const hunks = [];
|
|
400
|
-
let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
|
|
401
|
-
for (let i = 0; i < diff.length; i++) {
|
|
402
|
-
const current = diff[i], lines = current.lines || splitLines(current.value);
|
|
403
|
-
current.lines = lines;
|
|
404
|
-
if (current.added || current.removed) {
|
|
405
|
-
if (!oldRangeStart) {
|
|
406
|
-
const prev = diff[i - 1];
|
|
407
|
-
oldRangeStart = oldLine;
|
|
408
|
-
newRangeStart = newLine;
|
|
409
|
-
if (prev) {
|
|
410
|
-
curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
|
|
411
|
-
oldRangeStart -= curRange.length;
|
|
412
|
-
newRangeStart -= curRange.length;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
for (const line of lines) {
|
|
416
|
-
curRange.push((current.added ? "+" : "-") + line);
|
|
417
|
-
}
|
|
418
|
-
if (current.added) {
|
|
419
|
-
newLine += lines.length;
|
|
420
|
-
} else {
|
|
421
|
-
oldLine += lines.length;
|
|
422
|
-
}
|
|
423
|
-
} else {
|
|
424
|
-
if (oldRangeStart) {
|
|
425
|
-
if (lines.length <= context * 2 && i < diff.length - 2) {
|
|
426
|
-
for (const line of contextLines(lines)) {
|
|
427
|
-
curRange.push(line);
|
|
428
|
-
}
|
|
429
|
-
} else {
|
|
430
|
-
const contextSize = Math.min(lines.length, context);
|
|
431
|
-
for (const line of contextLines(lines.slice(0, contextSize))) {
|
|
432
|
-
curRange.push(line);
|
|
433
|
-
}
|
|
434
|
-
const hunk = {
|
|
435
|
-
oldStart: oldRangeStart,
|
|
436
|
-
oldLines: oldLine - oldRangeStart + contextSize,
|
|
437
|
-
newStart: newRangeStart,
|
|
438
|
-
newLines: newLine - newRangeStart + contextSize,
|
|
439
|
-
lines: curRange
|
|
440
|
-
};
|
|
441
|
-
hunks.push(hunk);
|
|
442
|
-
oldRangeStart = 0;
|
|
443
|
-
newRangeStart = 0;
|
|
444
|
-
curRange = [];
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
oldLine += lines.length;
|
|
448
|
-
newLine += lines.length;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
for (const hunk of hunks) {
|
|
452
|
-
for (let i = 0; i < hunk.lines.length; i++) {
|
|
453
|
-
if (hunk.lines[i].endsWith("\n")) {
|
|
454
|
-
hunk.lines[i] = hunk.lines[i].slice(0, -1);
|
|
455
|
-
} else {
|
|
456
|
-
hunk.lines.splice(i + 1, 0, "\");
|
|
457
|
-
i++;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return {
|
|
462
|
-
oldFileName,
|
|
463
|
-
newFileName,
|
|
464
|
-
oldHeader,
|
|
465
|
-
newHeader,
|
|
466
|
-
hunks
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function formatPatch(patch) {
|
|
471
|
-
if (Array.isArray(patch)) {
|
|
472
|
-
return patch.map(formatPatch).join("\n");
|
|
473
|
-
}
|
|
474
|
-
const ret = [];
|
|
475
|
-
if (patch.oldFileName == patch.newFileName) {
|
|
476
|
-
ret.push("Index: " + patch.oldFileName);
|
|
477
|
-
}
|
|
478
|
-
ret.push("===================================================================");
|
|
479
|
-
ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
|
|
480
|
-
ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
|
|
481
|
-
for (let i = 0; i < patch.hunks.length; i++) {
|
|
482
|
-
const hunk = patch.hunks[i];
|
|
483
|
-
if (hunk.oldLines === 0) {
|
|
484
|
-
hunk.oldStart -= 1;
|
|
485
|
-
}
|
|
486
|
-
if (hunk.newLines === 0) {
|
|
487
|
-
hunk.newStart -= 1;
|
|
488
|
-
}
|
|
489
|
-
ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
|
|
490
|
-
for (const line of hunk.lines) {
|
|
491
|
-
ret.push(line);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
return ret.join("\n") + "\n";
|
|
495
|
-
}
|
|
496
|
-
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
497
|
-
if (typeof options === "function") {
|
|
498
|
-
options = { callback: options };
|
|
499
|
-
}
|
|
500
|
-
if (!(options === null || options === void 0 ? void 0 : options.callback)) {
|
|
501
|
-
const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
502
|
-
if (!patchObj) {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
return formatPatch(patchObj);
|
|
506
|
-
} else {
|
|
507
|
-
const { callback } = options;
|
|
508
|
-
structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
|
|
509
|
-
if (!patchObj) {
|
|
510
|
-
callback(void 0);
|
|
511
|
-
} else {
|
|
512
|
-
callback(formatPatch(patchObj));
|
|
513
|
-
}
|
|
514
|
-
} }));
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
function splitLines(text) {
|
|
518
|
-
const hasTrailingNl = text.endsWith("\n");
|
|
519
|
-
const result = text.split("\n").map((line) => line + "\n");
|
|
520
|
-
if (hasTrailingNl) {
|
|
521
|
-
result.pop();
|
|
522
|
-
} else {
|
|
523
|
-
result.push(result.pop().slice(0, -1));
|
|
524
|
-
}
|
|
525
|
-
return result;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
// dist/pi-adapter.js
|
|
529
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
530
|
-
import path5 from "node:path";
|
|
8
|
+
// dist/pi-empty-session.js
|
|
9
|
+
import { createReadStream } from "node:fs";
|
|
10
|
+
import { createInterface } from "node:readline";
|
|
531
11
|
|
|
532
12
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
533
13
|
var external_exports = {};
|
|
@@ -1295,10 +775,10 @@ function mergeDefs(...defs) {
|
|
|
1295
775
|
function cloneDef(schema) {
|
|
1296
776
|
return mergeDefs(schema._zod.def);
|
|
1297
777
|
}
|
|
1298
|
-
function getElementAtPath(obj,
|
|
1299
|
-
if (!
|
|
778
|
+
function getElementAtPath(obj, path7) {
|
|
779
|
+
if (!path7)
|
|
1300
780
|
return obj;
|
|
1301
|
-
return
|
|
781
|
+
return path7.reduce((acc, key) => acc?.[key], obj);
|
|
1302
782
|
}
|
|
1303
783
|
function promiseAllObject(promisesObj) {
|
|
1304
784
|
const keys = Object.keys(promisesObj);
|
|
@@ -1707,11 +1187,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1707
1187
|
}
|
|
1708
1188
|
return false;
|
|
1709
1189
|
}
|
|
1710
|
-
function prefixIssues(
|
|
1190
|
+
function prefixIssues(path7, issues) {
|
|
1711
1191
|
return issues.map((iss) => {
|
|
1712
1192
|
var _a3;
|
|
1713
1193
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1714
|
-
iss.path.unshift(
|
|
1194
|
+
iss.path.unshift(path7);
|
|
1715
1195
|
return iss;
|
|
1716
1196
|
});
|
|
1717
1197
|
}
|
|
@@ -1858,16 +1338,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1858
1338
|
}
|
|
1859
1339
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1860
1340
|
const fieldErrors = { _errors: [] };
|
|
1861
|
-
const processError = (error52,
|
|
1341
|
+
const processError = (error52, path7 = []) => {
|
|
1862
1342
|
for (const issue2 of error52.issues) {
|
|
1863
1343
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1864
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1344
|
+
issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
|
|
1865
1345
|
} else if (issue2.code === "invalid_key") {
|
|
1866
|
-
processError({ issues: issue2.issues }, [...
|
|
1346
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1867
1347
|
} else if (issue2.code === "invalid_element") {
|
|
1868
|
-
processError({ issues: issue2.issues }, [...
|
|
1348
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1869
1349
|
} else {
|
|
1870
|
-
const fullpath = [...
|
|
1350
|
+
const fullpath = [...path7, ...issue2.path];
|
|
1871
1351
|
if (fullpath.length === 0) {
|
|
1872
1352
|
fieldErrors._errors.push(mapper(issue2));
|
|
1873
1353
|
} else {
|
|
@@ -1894,17 +1374,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1894
1374
|
}
|
|
1895
1375
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1896
1376
|
const result = { errors: [] };
|
|
1897
|
-
const processError = (error52,
|
|
1377
|
+
const processError = (error52, path7 = []) => {
|
|
1898
1378
|
var _a3, _b;
|
|
1899
1379
|
for (const issue2 of error52.issues) {
|
|
1900
1380
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1901
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1381
|
+
issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
|
|
1902
1382
|
} else if (issue2.code === "invalid_key") {
|
|
1903
|
-
processError({ issues: issue2.issues }, [...
|
|
1383
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1904
1384
|
} else if (issue2.code === "invalid_element") {
|
|
1905
|
-
processError({ issues: issue2.issues }, [...
|
|
1385
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1906
1386
|
} else {
|
|
1907
|
-
const fullpath = [...
|
|
1387
|
+
const fullpath = [...path7, ...issue2.path];
|
|
1908
1388
|
if (fullpath.length === 0) {
|
|
1909
1389
|
result.errors.push(mapper(issue2));
|
|
1910
1390
|
continue;
|
|
@@ -1936,8 +1416,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1936
1416
|
}
|
|
1937
1417
|
function toDotPath(_path) {
|
|
1938
1418
|
const segs = [];
|
|
1939
|
-
const
|
|
1940
|
-
for (const seg of
|
|
1419
|
+
const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1420
|
+
for (const seg of path7) {
|
|
1941
1421
|
if (typeof seg === "number")
|
|
1942
1422
|
segs.push(`[${seg}]`);
|
|
1943
1423
|
else if (typeof seg === "symbol")
|
|
@@ -14629,13 +14109,13 @@ function resolveRef(ref, ctx) {
|
|
|
14629
14109
|
if (!ref.startsWith("#")) {
|
|
14630
14110
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14631
14111
|
}
|
|
14632
|
-
const
|
|
14633
|
-
if (
|
|
14112
|
+
const path7 = ref.slice(1).split("/").filter(Boolean);
|
|
14113
|
+
if (path7.length === 0) {
|
|
14634
14114
|
return ctx.rootSchema;
|
|
14635
14115
|
}
|
|
14636
14116
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14637
|
-
if (
|
|
14638
|
-
const key =
|
|
14117
|
+
if (path7[0] === defsKey) {
|
|
14118
|
+
const key = path7[1];
|
|
14639
14119
|
if (!key || !ctx.defs[key]) {
|
|
14640
14120
|
throw new Error(`Reference not found: ${ref}`);
|
|
14641
14121
|
}
|
|
@@ -15725,721 +15205,1411 @@ var externalThreadForkResultSchema = external_exports.object({
|
|
|
15725
15205
|
threadId: hostThreadIdSchema
|
|
15726
15206
|
}).strict();
|
|
15727
15207
|
|
|
15728
|
-
// ../../shared-contracts/dist/harness-commands.js
|
|
15729
|
-
var commandIdSchema = external_exports.string().trim().min(1).max(128).regex(/^[A-Za-z0-9._:-]+$/u).brand();
|
|
15730
|
-
var commandInvocationSchema = external_exports.string().min(1).max(128);
|
|
15731
|
-
var commandLabelSchema = external_exports.string().trim().min(1).max(128);
|
|
15732
|
-
var commandDescriptionSchema = external_exports.string().trim().min(1).max(512);
|
|
15733
|
-
var harnessCommandDescriptorSchema = external_exports.object({
|
|
15734
|
-
id: commandIdSchema,
|
|
15735
|
-
invocation: commandInvocationSchema,
|
|
15736
|
-
label: commandLabelSchema,
|
|
15737
|
-
description: commandDescriptionSchema.optional(),
|
|
15738
|
-
argumentMode: external_exports.enum(["none", "text"])
|
|
15739
|
-
}).strict();
|
|
15740
|
-
var harnessCommandCatalogSchema = external_exports.object({
|
|
15741
|
-
commands: external_exports.array(harnessCommandDescriptorSchema)
|
|
15742
|
-
}).strict().superRefine((catalog, context) => {
|
|
15743
|
-
const ids = /* @__PURE__ */ new Set();
|
|
15744
|
-
for (const [index, command] of catalog.commands.entries()) {
|
|
15745
|
-
if (ids.has(command.id)) {
|
|
15746
|
-
context.addIssue({
|
|
15747
|
-
code: "custom",
|
|
15748
|
-
message: "Harness command IDs must be unique",
|
|
15749
|
-
path: ["commands", index, "id"]
|
|
15750
|
-
});
|
|
15208
|
+
// ../../shared-contracts/dist/harness-commands.js
|
|
15209
|
+
var commandIdSchema = external_exports.string().trim().min(1).max(128).regex(/^[A-Za-z0-9._:-]+$/u).brand();
|
|
15210
|
+
var commandInvocationSchema = external_exports.string().min(1).max(128);
|
|
15211
|
+
var commandLabelSchema = external_exports.string().trim().min(1).max(128);
|
|
15212
|
+
var commandDescriptionSchema = external_exports.string().trim().min(1).max(512);
|
|
15213
|
+
var harnessCommandDescriptorSchema = external_exports.object({
|
|
15214
|
+
id: commandIdSchema,
|
|
15215
|
+
invocation: commandInvocationSchema,
|
|
15216
|
+
label: commandLabelSchema,
|
|
15217
|
+
description: commandDescriptionSchema.optional(),
|
|
15218
|
+
argumentMode: external_exports.enum(["none", "text"])
|
|
15219
|
+
}).strict();
|
|
15220
|
+
var harnessCommandCatalogSchema = external_exports.object({
|
|
15221
|
+
commands: external_exports.array(harnessCommandDescriptorSchema)
|
|
15222
|
+
}).strict().superRefine((catalog, context) => {
|
|
15223
|
+
const ids = /* @__PURE__ */ new Set();
|
|
15224
|
+
for (const [index, command] of catalog.commands.entries()) {
|
|
15225
|
+
if (ids.has(command.id)) {
|
|
15226
|
+
context.addIssue({
|
|
15227
|
+
code: "custom",
|
|
15228
|
+
message: "Harness command IDs must be unique",
|
|
15229
|
+
path: ["commands", index, "id"]
|
|
15230
|
+
});
|
|
15231
|
+
}
|
|
15232
|
+
ids.add(command.id);
|
|
15233
|
+
}
|
|
15234
|
+
});
|
|
15235
|
+
var harnessCommandsInspectParamsSchema = external_exports.object({ harnessId: harnessIdSchema }).strict();
|
|
15236
|
+
var threadCommandsInspectParamsSchema = external_exports.object({
|
|
15237
|
+
threadId: hostThreadIdSchema
|
|
15238
|
+
}).strict();
|
|
15239
|
+
var threadCommandExecuteParamsSchema = external_exports.object({
|
|
15240
|
+
threadId: hostThreadIdSchema,
|
|
15241
|
+
commandId: commandIdSchema,
|
|
15242
|
+
turnId: hostTurnIdSchema.optional(),
|
|
15243
|
+
arguments: jsonObjectSchema.optional()
|
|
15244
|
+
}).strict();
|
|
15245
|
+
var threadCommandExecuteResultSchema = external_exports.object({
|
|
15246
|
+
accepted: external_exports.literal(true),
|
|
15247
|
+
turnId: hostTurnIdSchema
|
|
15248
|
+
}).strict();
|
|
15249
|
+
|
|
15250
|
+
// ../../shared-contracts/dist/json-rpc.js
|
|
15251
|
+
var jsonRpcVersionSchema = external_exports.literal("2.0").optional();
|
|
15252
|
+
var absentSchema = external_exports.never().optional();
|
|
15253
|
+
var methodSchema = external_exports.string().min(1);
|
|
15254
|
+
var jsonRpcIdSchema = external_exports.union([external_exports.string(), external_exports.number().int()]);
|
|
15255
|
+
var jsonRpcErrorSchema = external_exports.object({
|
|
15256
|
+
code: external_exports.number().int(),
|
|
15257
|
+
message: external_exports.string(),
|
|
15258
|
+
data: jsonValueSchema.optional()
|
|
15259
|
+
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["data"]));
|
|
15260
|
+
var jsonRpcRequestSchema = external_exports.object({
|
|
15261
|
+
jsonrpc: jsonRpcVersionSchema,
|
|
15262
|
+
id: jsonRpcIdSchema,
|
|
15263
|
+
method: methodSchema,
|
|
15264
|
+
params: jsonValueSchema.optional(),
|
|
15265
|
+
result: absentSchema,
|
|
15266
|
+
error: absentSchema
|
|
15267
|
+
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["jsonrpc", "params", "result", "error"]));
|
|
15268
|
+
var jsonRpcNotificationSchema = external_exports.object({
|
|
15269
|
+
jsonrpc: jsonRpcVersionSchema,
|
|
15270
|
+
id: absentSchema,
|
|
15271
|
+
method: methodSchema,
|
|
15272
|
+
params: jsonValueSchema.optional(),
|
|
15273
|
+
result: absentSchema,
|
|
15274
|
+
error: absentSchema
|
|
15275
|
+
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["jsonrpc", "id", "params", "result", "error"]));
|
|
15276
|
+
var jsonRpcSuccessResponseSchema = external_exports.object({
|
|
15277
|
+
jsonrpc: jsonRpcVersionSchema,
|
|
15278
|
+
id: jsonRpcIdSchema,
|
|
15279
|
+
method: absentSchema,
|
|
15280
|
+
params: absentSchema,
|
|
15281
|
+
result: jsonValueSchema,
|
|
15282
|
+
error: absentSchema
|
|
15283
|
+
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["jsonrpc", "method", "params", "error"]));
|
|
15284
|
+
var jsonRpcErrorResponseSchema = external_exports.object({
|
|
15285
|
+
jsonrpc: jsonRpcVersionSchema,
|
|
15286
|
+
id: jsonRpcIdSchema,
|
|
15287
|
+
method: absentSchema,
|
|
15288
|
+
params: absentSchema,
|
|
15289
|
+
result: absentSchema,
|
|
15290
|
+
error: jsonRpcErrorSchema
|
|
15291
|
+
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["jsonrpc", "method", "params", "result"]));
|
|
15292
|
+
var jsonRpcEnvelopeSchema = external_exports.union([
|
|
15293
|
+
jsonRpcRequestSchema,
|
|
15294
|
+
jsonRpcNotificationSchema,
|
|
15295
|
+
jsonRpcSuccessResponseSchema,
|
|
15296
|
+
jsonRpcErrorResponseSchema
|
|
15297
|
+
]);
|
|
15298
|
+
|
|
15299
|
+
// ../../shared-contracts/dist/native-refs.js
|
|
15300
|
+
var nativeIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
15301
|
+
message: "Native identifier must not be empty or whitespace"
|
|
15302
|
+
});
|
|
15303
|
+
var nativeSessionRefV1RuntimeSchema = external_exports.strictObject({
|
|
15304
|
+
harnessId: harnessIdSchema,
|
|
15305
|
+
nativeSessionId: nativeIdSchema,
|
|
15306
|
+
locator: jsonValueSchema.optional(),
|
|
15307
|
+
formatVersion: external_exports.literal(1)
|
|
15308
|
+
}).superRefine(rejectExplicitUndefined(["locator"]));
|
|
15309
|
+
var nativeSessionRefV1Schema = nativeSessionRefV1RuntimeSchema;
|
|
15310
|
+
var nativeSessionRefSchema = nativeSessionRefV1Schema;
|
|
15311
|
+
var nativeTurnRefV1Schema = external_exports.strictObject({
|
|
15312
|
+
harnessId: harnessIdSchema,
|
|
15313
|
+
nativeSessionId: nativeIdSchema,
|
|
15314
|
+
nativeTurnKey: nativeIdSchema,
|
|
15315
|
+
formatVersion: external_exports.literal(1)
|
|
15316
|
+
});
|
|
15317
|
+
var nativeTurnRefSchema = nativeTurnRefV1Schema;
|
|
15318
|
+
var nativeCheckpointRefV1RuntimeSchema = external_exports.strictObject({
|
|
15319
|
+
harnessId: harnessIdSchema,
|
|
15320
|
+
nativeSessionId: nativeIdSchema,
|
|
15321
|
+
checkpointId: nativeIdSchema,
|
|
15322
|
+
locator: jsonValueSchema.optional(),
|
|
15323
|
+
formatVersion: external_exports.literal(1)
|
|
15324
|
+
}).superRefine(rejectExplicitUndefined(["locator"]));
|
|
15325
|
+
var nativeCheckpointRefV1Schema = nativeCheckpointRefV1RuntimeSchema;
|
|
15326
|
+
var nativeCheckpointRefSchema = nativeCheckpointRefV1Schema;
|
|
15327
|
+
|
|
15328
|
+
// ../../shared-contracts/dist/updates.js
|
|
15329
|
+
var UPDATE_ERROR_MAX_LENGTH = 500;
|
|
15330
|
+
var UPDATE_SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;
|
|
15331
|
+
var updateSemanticVersionSchema = external_exports.string().regex(UPDATE_SEMVER_PATTERN);
|
|
15332
|
+
var updateInstallationSchema = external_exports.enum(["npm", "windows-installer", "macos-dmg"]);
|
|
15333
|
+
var updatePhaseSchema = external_exports.enum([
|
|
15334
|
+
"prepared",
|
|
15335
|
+
"downloading",
|
|
15336
|
+
"waiting-for-exit",
|
|
15337
|
+
"installing",
|
|
15338
|
+
"restarting",
|
|
15339
|
+
"succeeded",
|
|
15340
|
+
"failed"
|
|
15341
|
+
]);
|
|
15342
|
+
var updateStatusSchema = external_exports.strictObject({
|
|
15343
|
+
version: updateSemanticVersionSchema,
|
|
15344
|
+
installation: updateInstallationSchema,
|
|
15345
|
+
phase: updatePhaseSchema,
|
|
15346
|
+
updatedAt: external_exports.number().int().nonnegative(),
|
|
15347
|
+
downloadedBytes: external_exports.number().int().nonnegative().optional(),
|
|
15348
|
+
totalBytes: external_exports.number().int().positive().optional(),
|
|
15349
|
+
error: external_exports.string().min(1).max(UPDATE_ERROR_MAX_LENGTH).nullable()
|
|
15350
|
+
}).superRefine((status, context) => {
|
|
15351
|
+
if (status.downloadedBytes !== void 0 && status.totalBytes !== void 0 && status.downloadedBytes > status.totalBytes) {
|
|
15352
|
+
context.addIssue({
|
|
15353
|
+
code: "custom",
|
|
15354
|
+
path: ["downloadedBytes"],
|
|
15355
|
+
message: "downloadedBytes must not exceed totalBytes"
|
|
15356
|
+
});
|
|
15357
|
+
}
|
|
15358
|
+
});
|
|
15359
|
+
var updateEmptyParamsSchema = external_exports.strictObject({});
|
|
15360
|
+
var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/LiberSeek\/BOFT-CLI\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
|
|
15361
|
+
var updateCheckResultSchema = external_exports.strictObject({
|
|
15362
|
+
currentVersion: updateSemanticVersionSchema,
|
|
15363
|
+
installation: updateInstallationSchema.nullable(),
|
|
15364
|
+
latestVersion: updateSemanticVersionSchema.nullable(),
|
|
15365
|
+
updateAvailable: external_exports.boolean(),
|
|
15366
|
+
installationAvailable: external_exports.boolean(),
|
|
15367
|
+
releaseNotes: external_exports.string().min(1).max(2e4).nullable(),
|
|
15368
|
+
releaseNotesUrl: githubReleaseNotesUrlSchema.nullable(),
|
|
15369
|
+
status: updateStatusSchema.nullable(),
|
|
15370
|
+
error: external_exports.string().min(1).max(UPDATE_ERROR_MAX_LENGTH).nullable()
|
|
15371
|
+
});
|
|
15372
|
+
var updateStartResultSchema = external_exports.strictObject({
|
|
15373
|
+
status: updateStatusSchema
|
|
15374
|
+
});
|
|
15375
|
+
var updateStatusResultSchema = external_exports.strictObject({
|
|
15376
|
+
status: updateStatusSchema.nullable()
|
|
15377
|
+
});
|
|
15378
|
+
|
|
15379
|
+
// ../../shared-contracts/dist/index.js
|
|
15380
|
+
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
15381
|
+
|
|
15382
|
+
// dist/pi-empty-session.js
|
|
15383
|
+
import { randomUUID } from "node:crypto";
|
|
15384
|
+
import { link, open as open2, rm } from "node:fs/promises";
|
|
15385
|
+
import path from "node:path";
|
|
15386
|
+
|
|
15387
|
+
// dist/pi-model-catalog.js
|
|
15388
|
+
var PI_MODEL_REF_PREFIX = "pi-model-v1.";
|
|
15389
|
+
var PI_DRAFT_THINKING_OPTION_IDS = [
|
|
15390
|
+
"off",
|
|
15391
|
+
"minimal",
|
|
15392
|
+
"low",
|
|
15393
|
+
"medium",
|
|
15394
|
+
"high",
|
|
15395
|
+
"xhigh",
|
|
15396
|
+
"max"
|
|
15397
|
+
].map((id) => harnessThinkingOptionIdSchema.parse(id));
|
|
15398
|
+
var PI_THINKING_LABELS = {
|
|
15399
|
+
off: "Off",
|
|
15400
|
+
minimal: "Minimal",
|
|
15401
|
+
low: "Low",
|
|
15402
|
+
medium: "Medium",
|
|
15403
|
+
high: "High",
|
|
15404
|
+
xhigh: "Extra High",
|
|
15405
|
+
max: "Max"
|
|
15406
|
+
};
|
|
15407
|
+
function compareText(left, right) {
|
|
15408
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
15409
|
+
}
|
|
15410
|
+
function assertNativePart(value, name) {
|
|
15411
|
+
if (value.trim().length === 0)
|
|
15412
|
+
throw new Error(`Pi ${name} must not be empty`);
|
|
15413
|
+
}
|
|
15414
|
+
function encodePiModelRef(model) {
|
|
15415
|
+
assertNativePart(model.provider, "Model provider");
|
|
15416
|
+
assertNativePart(model.id, "Model id");
|
|
15417
|
+
const encoded = Buffer.from(JSON.stringify([model.provider, model.id]), "utf8").toString("base64url");
|
|
15418
|
+
return harnessModelRefSchema.parse({ id: `${PI_MODEL_REF_PREFIX}${encoded}` });
|
|
15419
|
+
}
|
|
15420
|
+
function decodePiModelRef(ref) {
|
|
15421
|
+
const parsedRef = harnessModelRefSchema.parse(ref);
|
|
15422
|
+
if (!parsedRef.id.startsWith(PI_MODEL_REF_PREFIX)) {
|
|
15423
|
+
throw new Error("Model Ref does not belong to PiAdapter");
|
|
15424
|
+
}
|
|
15425
|
+
const encoded = parsedRef.id.slice(PI_MODEL_REF_PREFIX.length);
|
|
15426
|
+
let decoded;
|
|
15427
|
+
try {
|
|
15428
|
+
decoded = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
|
|
15429
|
+
} catch {
|
|
15430
|
+
throw new Error("Pi Model Ref is malformed");
|
|
15431
|
+
}
|
|
15432
|
+
if (!Array.isArray(decoded) || decoded.length !== 2 || typeof decoded[0] !== "string" || typeof decoded[1] !== "string") {
|
|
15433
|
+
throw new Error("Pi Model Ref has an invalid native identity");
|
|
15434
|
+
}
|
|
15435
|
+
const native = { provider: decoded[0], id: decoded[1] };
|
|
15436
|
+
assertNativePart(native.provider, "Model provider");
|
|
15437
|
+
assertNativePart(native.id, "Model id");
|
|
15438
|
+
if (encodePiModelRef(native).id !== parsedRef.id) {
|
|
15439
|
+
throw new Error("Pi Model Ref is not canonical");
|
|
15440
|
+
}
|
|
15441
|
+
return native;
|
|
15442
|
+
}
|
|
15443
|
+
function samePiModel(left, right) {
|
|
15444
|
+
return left === null ? right === null : right !== null && left.provider === right.provider && left.id === right.id;
|
|
15445
|
+
}
|
|
15446
|
+
function fallbackThinkingLabel(id) {
|
|
15447
|
+
const label = id.split(/[._~-]+/u).filter((part) => part.length > 0).map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`).join(" ");
|
|
15448
|
+
return label || id;
|
|
15449
|
+
}
|
|
15450
|
+
function normalizePiThinkingOptions(levels) {
|
|
15451
|
+
return levels.map((id) => harnessThinkingOptionSchema.parse({
|
|
15452
|
+
id,
|
|
15453
|
+
label: PI_THINKING_LABELS[id] ?? fallbackThinkingLabel(id)
|
|
15454
|
+
}));
|
|
15455
|
+
}
|
|
15456
|
+
function normalizePiModelCatalog(nativeModels, effectiveModel, thinkingLevels, effectiveThinkingOptionId) {
|
|
15457
|
+
const byRef = /* @__PURE__ */ new Map();
|
|
15458
|
+
for (const native of nativeModels) {
|
|
15459
|
+
const ref = encodePiModelRef(native);
|
|
15460
|
+
const existing = byRef.get(ref.id);
|
|
15461
|
+
if (existing) {
|
|
15462
|
+
if (existing.reasoning !== native.reasoning) {
|
|
15463
|
+
throw new Error("Pi duplicate Model entries disagree on reasoning capability");
|
|
15464
|
+
}
|
|
15465
|
+
continue;
|
|
15466
|
+
}
|
|
15467
|
+
byRef.set(ref.id, {
|
|
15468
|
+
model: {
|
|
15469
|
+
ref,
|
|
15470
|
+
label: `${native.provider} / ${native.id}`
|
|
15471
|
+
},
|
|
15472
|
+
reasoning: native.reasoning
|
|
15473
|
+
});
|
|
15474
|
+
}
|
|
15475
|
+
const defaultModel = effectiveModel ? encodePiModelRef(effectiveModel) : void 0;
|
|
15476
|
+
if (defaultModel && !byRef.has(defaultModel.id)) {
|
|
15477
|
+
throw new Error("Pi effective Model is absent from the available Model catalog");
|
|
15478
|
+
}
|
|
15479
|
+
if (thinkingLevels && effectiveThinkingOptionId && !thinkingLevels.includes(effectiveThinkingOptionId)) {
|
|
15480
|
+
throw new Error("Pi effective Thinking option is absent from the available option catalog");
|
|
15481
|
+
}
|
|
15482
|
+
if (thinkingLevels && !effectiveThinkingOptionId) {
|
|
15483
|
+
throw new Error("Pi did not report an effective Thinking option");
|
|
15484
|
+
}
|
|
15485
|
+
const thinkingOptions = thinkingLevels ? normalizePiThinkingOptions(PI_DRAFT_THINKING_OPTION_IDS) : [];
|
|
15486
|
+
const allThinkingOptionIds = thinkingOptions.map(({ id }) => id);
|
|
15487
|
+
const offThinkingOptionId = thinkingOptions.find(({ id }) => id === "off")?.id;
|
|
15488
|
+
const models = [...byRef.values()].map(({ model, reasoning }) => ({
|
|
15489
|
+
...model,
|
|
15490
|
+
supportedThinkingOptionIds: reasoning ? allThinkingOptionIds : offThinkingOptionId ? [offThinkingOptionId] : []
|
|
15491
|
+
})).sort((left, right) => compareText(left.label, right.label) || compareText(left.ref.id, right.ref.id));
|
|
15492
|
+
const defaultThinkingOptionId = thinkingOptions.find(({ id }) => id === effectiveThinkingOptionId)?.id;
|
|
15493
|
+
return harnessModelCatalogSchema.parse({
|
|
15494
|
+
models,
|
|
15495
|
+
...defaultModel ? { defaultModel } : {},
|
|
15496
|
+
thinkingOptions,
|
|
15497
|
+
...defaultThinkingOptionId ? { defaultThinkingOptionId } : {}
|
|
15498
|
+
});
|
|
15499
|
+
}
|
|
15500
|
+
|
|
15501
|
+
// dist/pi-history.js
|
|
15502
|
+
var piHarnessId = harnessIdSchema.parse("pi");
|
|
15503
|
+
function isRecord(value) {
|
|
15504
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15505
|
+
}
|
|
15506
|
+
function textContent(value) {
|
|
15507
|
+
if (typeof value === "string")
|
|
15508
|
+
return value;
|
|
15509
|
+
if (!Array.isArray(value))
|
|
15510
|
+
return "";
|
|
15511
|
+
return value.filter((part) => isRecord(part) && part.type === "text" && typeof part.text === "string").map((part) => part.text).join("");
|
|
15512
|
+
}
|
|
15513
|
+
function thinkingContent(value) {
|
|
15514
|
+
if (!Array.isArray(value))
|
|
15515
|
+
return "";
|
|
15516
|
+
return value.filter((part) => isRecord(part) && part.type === "thinking" && typeof part.thinking === "string").map((part) => part.thinking).join("");
|
|
15517
|
+
}
|
|
15518
|
+
function validatedEntry(value) {
|
|
15519
|
+
if (typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
|
|
15520
|
+
throw new Error("Pi history contains an invalid Entry identity");
|
|
15521
|
+
}
|
|
15522
|
+
return value;
|
|
15523
|
+
}
|
|
15524
|
+
function activePiEntries(history) {
|
|
15525
|
+
if (history.leafId === null)
|
|
15526
|
+
return [];
|
|
15527
|
+
const byId = new Map(history.entries.map((value) => {
|
|
15528
|
+
const entry = validatedEntry(value);
|
|
15529
|
+
return [entry.id, entry];
|
|
15530
|
+
}));
|
|
15531
|
+
const reversed = [];
|
|
15532
|
+
const visited = /* @__PURE__ */ new Set();
|
|
15533
|
+
let current = history.leafId;
|
|
15534
|
+
while (current !== null) {
|
|
15535
|
+
if (visited.has(current))
|
|
15536
|
+
throw new Error("Pi history active branch contains a cycle");
|
|
15537
|
+
visited.add(current);
|
|
15538
|
+
const entry = byId.get(current);
|
|
15539
|
+
if (!entry)
|
|
15540
|
+
throw new Error("Pi history active branch references a missing Entry");
|
|
15541
|
+
reversed.push(entry);
|
|
15542
|
+
current = entry.parentId;
|
|
15543
|
+
}
|
|
15544
|
+
return reversed.reverse();
|
|
15545
|
+
}
|
|
15546
|
+
function message(entry) {
|
|
15547
|
+
return entry.type === "message" && isRecord(entry.message) ? entry.message : null;
|
|
15548
|
+
}
|
|
15549
|
+
function messageRole(entry) {
|
|
15550
|
+
const value = message(entry)?.role;
|
|
15551
|
+
return typeof value === "string" ? value : null;
|
|
15552
|
+
}
|
|
15553
|
+
function itemId(entryId, kind, ordinal) {
|
|
15554
|
+
return hostItemIdSchema.parse(`pi-item-v1-${entryId}-${kind}-${ordinal}`);
|
|
15555
|
+
}
|
|
15556
|
+
function assistantOutcome(entries) {
|
|
15557
|
+
const assistants = entries.map((entry) => message(entry)).filter((value) => value?.role === "assistant");
|
|
15558
|
+
const final = assistants.at(-1);
|
|
15559
|
+
if (!final)
|
|
15560
|
+
return { status: "unknown", reason: "Pi history has no Assistant terminal" };
|
|
15561
|
+
const stopReason = final.stopReason;
|
|
15562
|
+
if (stopReason === "aborted") {
|
|
15563
|
+
return { status: "cancelled", reason: "Pi Assistant was aborted" };
|
|
15564
|
+
}
|
|
15565
|
+
if (stopReason === "error") {
|
|
15566
|
+
return {
|
|
15567
|
+
status: "failed",
|
|
15568
|
+
error: {
|
|
15569
|
+
code: "nativeFailure",
|
|
15570
|
+
message: typeof final.errorMessage === "string" && final.errorMessage.length > 0 ? final.errorMessage : "Pi Assistant failed",
|
|
15571
|
+
retryable: false
|
|
15572
|
+
}
|
|
15573
|
+
};
|
|
15574
|
+
}
|
|
15575
|
+
if (typeof stopReason === "string" || textContent(final.content).length > 0) {
|
|
15576
|
+
return { status: "succeeded" };
|
|
15577
|
+
}
|
|
15578
|
+
return { status: "unknown", reason: "Pi Assistant terminal is not classifiable" };
|
|
15579
|
+
}
|
|
15580
|
+
function itemOutcome(outcome) {
|
|
15581
|
+
if (outcome.status === "failed")
|
|
15582
|
+
return { status: "failed", error: outcome.error };
|
|
15583
|
+
if (outcome.status === "cancelled") {
|
|
15584
|
+
return {
|
|
15585
|
+
status: "cancelled",
|
|
15586
|
+
...outcome.reason ? { reason: outcome.reason } : {}
|
|
15587
|
+
};
|
|
15588
|
+
}
|
|
15589
|
+
return { status: "succeeded" };
|
|
15590
|
+
}
|
|
15591
|
+
function toolOutput(value) {
|
|
15592
|
+
const text = textContent(value);
|
|
15593
|
+
return text.length > 0 ? { content: [{ type: "text", text }] } : void 0;
|
|
15594
|
+
}
|
|
15595
|
+
function snapshotItems(entries, outcome) {
|
|
15596
|
+
const snapshots = [];
|
|
15597
|
+
const toolCalls = /* @__PURE__ */ new Map();
|
|
15598
|
+
for (const entry of entries) {
|
|
15599
|
+
const nativeMessage = message(entry);
|
|
15600
|
+
if (!nativeMessage)
|
|
15601
|
+
continue;
|
|
15602
|
+
const content = Array.isArray(nativeMessage.content) ? nativeMessage.content : [];
|
|
15603
|
+
if (nativeMessage.role === "assistant") {
|
|
15604
|
+
const text = textContent(content);
|
|
15605
|
+
const reasoning = thinkingContent(content);
|
|
15606
|
+
let projectedText = false;
|
|
15607
|
+
let projectedReasoning = false;
|
|
15608
|
+
for (const [ordinal, part] of content.entries()) {
|
|
15609
|
+
if (!isRecord(part))
|
|
15610
|
+
continue;
|
|
15611
|
+
if (part.type === "thinking" && !projectedReasoning && reasoning.length > 0) {
|
|
15612
|
+
const item2 = {
|
|
15613
|
+
type: "reasoning",
|
|
15614
|
+
itemId: itemId(entry.id, "reasoning", 0),
|
|
15615
|
+
text: reasoning
|
|
15616
|
+
};
|
|
15617
|
+
snapshots.push({ item: item2, outcome: itemOutcome(outcome) });
|
|
15618
|
+
projectedReasoning = true;
|
|
15619
|
+
continue;
|
|
15620
|
+
}
|
|
15621
|
+
if (part.type === "text" && !projectedText && text.length > 0) {
|
|
15622
|
+
const item2 = {
|
|
15623
|
+
type: "agentMessage",
|
|
15624
|
+
itemId: itemId(entry.id, "assistant", 0),
|
|
15625
|
+
text
|
|
15626
|
+
};
|
|
15627
|
+
snapshots.push({ item: item2, outcome: itemOutcome(outcome) });
|
|
15628
|
+
projectedText = true;
|
|
15629
|
+
continue;
|
|
15630
|
+
}
|
|
15631
|
+
if (part.type !== "toolCall" || typeof part.id !== "string" || typeof part.name !== "string") {
|
|
15632
|
+
continue;
|
|
15633
|
+
}
|
|
15634
|
+
const parsedArguments = jsonValueSchema.safeParse(part.arguments);
|
|
15635
|
+
if (!parsedArguments.success)
|
|
15636
|
+
continue;
|
|
15637
|
+
toolCalls.set(part.id, {
|
|
15638
|
+
entryId: entry.id,
|
|
15639
|
+
ordinal,
|
|
15640
|
+
name: part.name,
|
|
15641
|
+
arguments: parsedArguments.data
|
|
15642
|
+
});
|
|
15643
|
+
}
|
|
15644
|
+
continue;
|
|
15751
15645
|
}
|
|
15752
|
-
|
|
15646
|
+
if (nativeMessage.role !== "toolResult" || typeof nativeMessage.toolCallId !== "string" || typeof nativeMessage.toolName !== "string") {
|
|
15647
|
+
continue;
|
|
15648
|
+
}
|
|
15649
|
+
const call = toolCalls.get(nativeMessage.toolCallId);
|
|
15650
|
+
if (!call || call.name !== nativeMessage.toolName)
|
|
15651
|
+
continue;
|
|
15652
|
+
const output = toolOutput(nativeMessage.content);
|
|
15653
|
+
const item = {
|
|
15654
|
+
type: "toolExecution",
|
|
15655
|
+
itemId: itemId(call.entryId, "tool", call.ordinal),
|
|
15656
|
+
toolName: call.name,
|
|
15657
|
+
arguments: call.arguments,
|
|
15658
|
+
...output ? { output } : {}
|
|
15659
|
+
};
|
|
15660
|
+
const toolFailed = nativeMessage.isError === true;
|
|
15661
|
+
snapshots.push({
|
|
15662
|
+
item,
|
|
15663
|
+
outcome: toolFailed ? {
|
|
15664
|
+
status: "failed",
|
|
15665
|
+
error: {
|
|
15666
|
+
code: "nativeFailure",
|
|
15667
|
+
message: `Pi Tool '${call.name}' failed`,
|
|
15668
|
+
retryable: false
|
|
15669
|
+
}
|
|
15670
|
+
} : { status: "succeeded" }
|
|
15671
|
+
});
|
|
15753
15672
|
}
|
|
15754
|
-
|
|
15755
|
-
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
}
|
|
15759
|
-
|
|
15760
|
-
|
|
15761
|
-
|
|
15762
|
-
|
|
15763
|
-
|
|
15764
|
-
|
|
15765
|
-
|
|
15766
|
-
|
|
15767
|
-
|
|
15768
|
-
|
|
15769
|
-
|
|
15770
|
-
|
|
15771
|
-
|
|
15772
|
-
|
|
15773
|
-
|
|
15774
|
-
|
|
15775
|
-
|
|
15776
|
-
|
|
15777
|
-
|
|
15778
|
-
|
|
15779
|
-
|
|
15780
|
-
|
|
15781
|
-
|
|
15782
|
-
|
|
15783
|
-
|
|
15784
|
-
|
|
15785
|
-
|
|
15786
|
-
|
|
15787
|
-
|
|
15788
|
-
|
|
15789
|
-
|
|
15790
|
-
|
|
15791
|
-
|
|
15792
|
-
params: jsonValueSchema.optional(),
|
|
15793
|
-
result: absentSchema,
|
|
15794
|
-
error: absentSchema
|
|
15795
|
-
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["jsonrpc", "id", "params", "result", "error"]));
|
|
15796
|
-
var jsonRpcSuccessResponseSchema = external_exports.object({
|
|
15797
|
-
jsonrpc: jsonRpcVersionSchema,
|
|
15798
|
-
id: jsonRpcIdSchema,
|
|
15799
|
-
method: absentSchema,
|
|
15800
|
-
params: absentSchema,
|
|
15801
|
-
result: jsonValueSchema,
|
|
15802
|
-
error: absentSchema
|
|
15803
|
-
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["jsonrpc", "method", "params", "error"]));
|
|
15804
|
-
var jsonRpcErrorResponseSchema = external_exports.object({
|
|
15805
|
-
jsonrpc: jsonRpcVersionSchema,
|
|
15806
|
-
id: jsonRpcIdSchema,
|
|
15807
|
-
method: absentSchema,
|
|
15808
|
-
params: absentSchema,
|
|
15809
|
-
result: absentSchema,
|
|
15810
|
-
error: jsonRpcErrorSchema
|
|
15811
|
-
}).catchall(jsonValueSchema).superRefine(rejectExplicitUndefined(["jsonrpc", "method", "params", "result"]));
|
|
15812
|
-
var jsonRpcEnvelopeSchema = external_exports.union([
|
|
15813
|
-
jsonRpcRequestSchema,
|
|
15814
|
-
jsonRpcNotificationSchema,
|
|
15815
|
-
jsonRpcSuccessResponseSchema,
|
|
15816
|
-
jsonRpcErrorResponseSchema
|
|
15817
|
-
]);
|
|
15818
|
-
|
|
15819
|
-
// ../../shared-contracts/dist/native-refs.js
|
|
15820
|
-
var nativeIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
15821
|
-
message: "Native identifier must not be empty or whitespace"
|
|
15822
|
-
});
|
|
15823
|
-
var nativeSessionRefV1RuntimeSchema = external_exports.strictObject({
|
|
15824
|
-
harnessId: harnessIdSchema,
|
|
15825
|
-
nativeSessionId: nativeIdSchema,
|
|
15826
|
-
locator: jsonValueSchema.optional(),
|
|
15827
|
-
formatVersion: external_exports.literal(1)
|
|
15828
|
-
}).superRefine(rejectExplicitUndefined(["locator"]));
|
|
15829
|
-
var nativeSessionRefV1Schema = nativeSessionRefV1RuntimeSchema;
|
|
15830
|
-
var nativeSessionRefSchema = nativeSessionRefV1Schema;
|
|
15831
|
-
var nativeTurnRefV1Schema = external_exports.strictObject({
|
|
15832
|
-
harnessId: harnessIdSchema,
|
|
15833
|
-
nativeSessionId: nativeIdSchema,
|
|
15834
|
-
nativeTurnKey: nativeIdSchema,
|
|
15835
|
-
formatVersion: external_exports.literal(1)
|
|
15836
|
-
});
|
|
15837
|
-
var nativeTurnRefSchema = nativeTurnRefV1Schema;
|
|
15838
|
-
var nativeCheckpointRefV1RuntimeSchema = external_exports.strictObject({
|
|
15839
|
-
harnessId: harnessIdSchema,
|
|
15840
|
-
nativeSessionId: nativeIdSchema,
|
|
15841
|
-
checkpointId: nativeIdSchema,
|
|
15842
|
-
locator: jsonValueSchema.optional(),
|
|
15843
|
-
formatVersion: external_exports.literal(1)
|
|
15844
|
-
}).superRefine(rejectExplicitUndefined(["locator"]));
|
|
15845
|
-
var nativeCheckpointRefV1Schema = nativeCheckpointRefV1RuntimeSchema;
|
|
15846
|
-
var nativeCheckpointRefSchema = nativeCheckpointRefV1Schema;
|
|
15847
|
-
|
|
15848
|
-
// ../../shared-contracts/dist/updates.js
|
|
15849
|
-
var UPDATE_ERROR_MAX_LENGTH = 500;
|
|
15850
|
-
var UPDATE_SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;
|
|
15851
|
-
var updateSemanticVersionSchema = external_exports.string().regex(UPDATE_SEMVER_PATTERN);
|
|
15852
|
-
var updateInstallationSchema = external_exports.enum(["npm", "windows-installer", "macos-dmg"]);
|
|
15853
|
-
var updatePhaseSchema = external_exports.enum([
|
|
15854
|
-
"prepared",
|
|
15855
|
-
"downloading",
|
|
15856
|
-
"waiting-for-exit",
|
|
15857
|
-
"installing",
|
|
15858
|
-
"restarting",
|
|
15859
|
-
"succeeded",
|
|
15860
|
-
"failed"
|
|
15861
|
-
]);
|
|
15862
|
-
var updateStatusSchema = external_exports.strictObject({
|
|
15863
|
-
version: updateSemanticVersionSchema,
|
|
15864
|
-
installation: updateInstallationSchema,
|
|
15865
|
-
phase: updatePhaseSchema,
|
|
15866
|
-
updatedAt: external_exports.number().int().nonnegative(),
|
|
15867
|
-
downloadedBytes: external_exports.number().int().nonnegative().optional(),
|
|
15868
|
-
totalBytes: external_exports.number().int().positive().optional(),
|
|
15869
|
-
error: external_exports.string().min(1).max(UPDATE_ERROR_MAX_LENGTH).nullable()
|
|
15870
|
-
}).superRefine((status, context) => {
|
|
15871
|
-
if (status.downloadedBytes !== void 0 && status.totalBytes !== void 0 && status.downloadedBytes > status.totalBytes) {
|
|
15872
|
-
context.addIssue({
|
|
15873
|
-
code: "custom",
|
|
15874
|
-
path: ["downloadedBytes"],
|
|
15875
|
-
message: "downloadedBytes must not exceed totalBytes"
|
|
15673
|
+
return snapshots;
|
|
15674
|
+
}
|
|
15675
|
+
function modelChange(entry) {
|
|
15676
|
+
return entry.type === "model_change" && typeof entry.provider === "string" && typeof entry.modelId === "string" ? { provider: entry.provider, id: entry.modelId } : null;
|
|
15677
|
+
}
|
|
15678
|
+
function mapPiSnapshot(history, state) {
|
|
15679
|
+
const active = activePiEntries(history);
|
|
15680
|
+
const turns = [];
|
|
15681
|
+
let effectiveModel = state.model;
|
|
15682
|
+
for (let index = 0; index < active.length; ) {
|
|
15683
|
+
const model = modelChange(active[index]);
|
|
15684
|
+
if (model) {
|
|
15685
|
+
effectiveModel = model;
|
|
15686
|
+
index += 1;
|
|
15687
|
+
continue;
|
|
15688
|
+
}
|
|
15689
|
+
const user = active[index];
|
|
15690
|
+
if (messageRole(user) !== "user") {
|
|
15691
|
+
index += 1;
|
|
15692
|
+
continue;
|
|
15693
|
+
}
|
|
15694
|
+
let end = index + 1;
|
|
15695
|
+
while (end < active.length && messageRole(active[end]) !== "user")
|
|
15696
|
+
end += 1;
|
|
15697
|
+
const entries = active.slice(index, end);
|
|
15698
|
+
const outcome = assistantOutcome(entries);
|
|
15699
|
+
const userText = textContent(message(user)?.content);
|
|
15700
|
+
const nativeTurnRef = nativeTurnRefSchema.parse({
|
|
15701
|
+
harnessId: piHarnessId,
|
|
15702
|
+
nativeSessionId: state.sessionId,
|
|
15703
|
+
nativeTurnKey: user.id,
|
|
15704
|
+
formatVersion: 1
|
|
15705
|
+
});
|
|
15706
|
+
const checkpoint = nativeCheckpointRefSchema.parse({
|
|
15707
|
+
harnessId: piHarnessId,
|
|
15708
|
+
nativeSessionId: state.sessionId,
|
|
15709
|
+
checkpointId: user.id,
|
|
15710
|
+
formatVersion: 1
|
|
15876
15711
|
});
|
|
15712
|
+
turns.push({
|
|
15713
|
+
nativeTurnRef,
|
|
15714
|
+
checkpoint,
|
|
15715
|
+
input: [{ type: "text", text: userText }],
|
|
15716
|
+
items: snapshotItems(entries, outcome),
|
|
15717
|
+
outcome,
|
|
15718
|
+
...effectiveModel ? { model: encodePiModelRef(effectiveModel) } : {}
|
|
15719
|
+
});
|
|
15720
|
+
for (const entry of entries) {
|
|
15721
|
+
const changed = modelChange(entry);
|
|
15722
|
+
if (changed)
|
|
15723
|
+
effectiveModel = changed;
|
|
15724
|
+
}
|
|
15725
|
+
index = end;
|
|
15726
|
+
}
|
|
15727
|
+
return { turns };
|
|
15728
|
+
}
|
|
15729
|
+
function resolvePiLastTurnBoundary(history) {
|
|
15730
|
+
const users = activePiEntries(history).filter((entry) => messageRole(entry) === "user");
|
|
15731
|
+
const last = users.at(-1);
|
|
15732
|
+
return last ? { lastUserEntryId: last.id, sourceTurnCount: users.length } : null;
|
|
15733
|
+
}
|
|
15734
|
+
function resolvePiForkBoundary(history, checkpointId) {
|
|
15735
|
+
const active = activePiEntries(history);
|
|
15736
|
+
const users = active.filter((entry) => messageRole(entry) === "user");
|
|
15737
|
+
const targetTurnIndex = users.findIndex((entry) => entry.id === checkpointId);
|
|
15738
|
+
if (targetTurnIndex < 0)
|
|
15739
|
+
throw new Error("Pi Checkpoint is not on the active branch");
|
|
15740
|
+
return {
|
|
15741
|
+
targetTurnIndex,
|
|
15742
|
+
nextUserEntryId: users[targetTurnIndex + 1]?.id ?? null
|
|
15743
|
+
};
|
|
15744
|
+
}
|
|
15745
|
+
|
|
15746
|
+
// dist/pi-session-file.js
|
|
15747
|
+
import { open, realpath } from "node:fs/promises";
|
|
15748
|
+
var MAX_SESSION_HEADER_BYTES = 64 * 1024;
|
|
15749
|
+
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
15750
|
+
function isRecord2(value) {
|
|
15751
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15752
|
+
}
|
|
15753
|
+
async function readPiSessionHeader(sessionFile) {
|
|
15754
|
+
const handle = await open(sessionFile, "r");
|
|
15755
|
+
try {
|
|
15756
|
+
const buffer = Buffer.allocUnsafe(MAX_SESSION_HEADER_BYTES);
|
|
15757
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
15758
|
+
const contents = buffer.subarray(0, bytesRead);
|
|
15759
|
+
const newline = contents.indexOf(10);
|
|
15760
|
+
if (newline < 0 && bytesRead === buffer.length) {
|
|
15761
|
+
throw new Error("Pi Session header exceeds the supported size");
|
|
15762
|
+
}
|
|
15763
|
+
const headerText = utf8Decoder.decode(newline < 0 ? contents : contents.subarray(0, newline));
|
|
15764
|
+
let parsed;
|
|
15765
|
+
try {
|
|
15766
|
+
parsed = JSON.parse(headerText);
|
|
15767
|
+
} catch {
|
|
15768
|
+
throw new Error("Pi Session header is not valid JSON");
|
|
15769
|
+
}
|
|
15770
|
+
if (!isRecord2(parsed) || parsed.type !== "session" || typeof parsed.id !== "string" || parsed.id.length === 0 || typeof parsed.cwd !== "string" || parsed.cwd.length === 0) {
|
|
15771
|
+
throw new Error("Pi Session header is invalid");
|
|
15772
|
+
}
|
|
15773
|
+
return {
|
|
15774
|
+
type: "session",
|
|
15775
|
+
id: parsed.id,
|
|
15776
|
+
cwd: parsed.cwd,
|
|
15777
|
+
...typeof parsed.version === "number" ? { version: parsed.version } : {}
|
|
15778
|
+
};
|
|
15779
|
+
} finally {
|
|
15780
|
+
await handle.close();
|
|
15781
|
+
}
|
|
15782
|
+
}
|
|
15783
|
+
async function verifyPiSessionCwd(input) {
|
|
15784
|
+
if (!input.sessionFile)
|
|
15785
|
+
throw new Error("Pi Fork Session has no persisted Session file");
|
|
15786
|
+
const header = await readPiSessionHeader(input.sessionFile);
|
|
15787
|
+
if (header.id !== input.sessionId) {
|
|
15788
|
+
throw new Error("Pi Fork Session header identity does not match RPC state");
|
|
15877
15789
|
}
|
|
15878
|
-
|
|
15879
|
-
|
|
15880
|
-
|
|
15881
|
-
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
|
|
15885
|
-
|
|
15886
|
-
installationAvailable: external_exports.boolean(),
|
|
15887
|
-
releaseNotes: external_exports.string().min(1).max(2e4).nullable(),
|
|
15888
|
-
releaseNotesUrl: githubReleaseNotesUrlSchema.nullable(),
|
|
15889
|
-
status: updateStatusSchema.nullable(),
|
|
15890
|
-
error: external_exports.string().min(1).max(UPDATE_ERROR_MAX_LENGTH).nullable()
|
|
15891
|
-
});
|
|
15892
|
-
var updateStartResultSchema = external_exports.strictObject({
|
|
15893
|
-
status: updateStatusSchema
|
|
15894
|
-
});
|
|
15895
|
-
var updateStatusResultSchema = external_exports.strictObject({
|
|
15896
|
-
status: updateStatusSchema.nullable()
|
|
15897
|
-
});
|
|
15898
|
-
|
|
15899
|
-
// ../../shared-contracts/dist/index.js
|
|
15900
|
-
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
15790
|
+
const [actualCwd, expectedCwd] = await Promise.all([
|
|
15791
|
+
realpath(header.cwd),
|
|
15792
|
+
realpath(input.expectedCwd)
|
|
15793
|
+
]);
|
|
15794
|
+
if (actualCwd !== expectedCwd) {
|
|
15795
|
+
throw new Error("Pi Fork Session did not bind the requested cwd");
|
|
15796
|
+
}
|
|
15797
|
+
}
|
|
15901
15798
|
|
|
15902
|
-
//
|
|
15903
|
-
function
|
|
15904
|
-
|
|
15799
|
+
// dist/pi-empty-session.js
|
|
15800
|
+
async function persistEmptyPiSession(input) {
|
|
15801
|
+
const { state, history, sourceSessionFile, sourceSessionId, cwd } = input;
|
|
15802
|
+
const destination = state.sessionFile;
|
|
15803
|
+
if (!destination || !path.isAbsolute(destination) || path.resolve(destination) === path.resolve(sourceSessionFile) || state.sessionId === sourceSessionId || mapPiSnapshot(history, { sessionId: state.sessionId, model: null }).turns.length !== 0)
|
|
15804
|
+
throw new Error("Pi empty Session is not an independent empty native fork");
|
|
15805
|
+
await verifyPiSessionCwd({
|
|
15806
|
+
sessionFile: sourceSessionFile,
|
|
15807
|
+
sessionId: sourceSessionId,
|
|
15808
|
+
expectedCwd: cwd
|
|
15809
|
+
});
|
|
15810
|
+
const sourceHeader = await readPiSessionHeader(sourceSessionFile);
|
|
15811
|
+
if (sourceHeader.type !== "session" || sourceHeader.version !== 3) {
|
|
15812
|
+
throw new Error("Pi empty Session persistence requires native v3 history");
|
|
15813
|
+
}
|
|
15814
|
+
const entries = history.entries;
|
|
15815
|
+
const active = activePiEntries(history);
|
|
15816
|
+
if (active.length !== entries.length || active.some((entry, index) => entry.id !== entries[index]?.id)) {
|
|
15817
|
+
throw new Error("Pi empty Session must expose its complete active branch");
|
|
15818
|
+
}
|
|
15819
|
+
const header = {
|
|
15820
|
+
type: "session",
|
|
15821
|
+
version: 3,
|
|
15822
|
+
id: state.sessionId,
|
|
15823
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15824
|
+
cwd,
|
|
15825
|
+
parentSession: sourceSessionFile
|
|
15826
|
+
};
|
|
15827
|
+
const temporary = path.join(path.dirname(destination), `.codexhost-${randomUUID()}.tmp`);
|
|
15828
|
+
try {
|
|
15829
|
+
const file2 = await open2(temporary, "wx", 384);
|
|
15830
|
+
try {
|
|
15831
|
+
await file2.writeFile([header, ...entries].map((entry) => JSON.stringify(entry)).join("\n") + "\n");
|
|
15832
|
+
await file2.sync();
|
|
15833
|
+
} finally {
|
|
15834
|
+
await file2.close();
|
|
15835
|
+
}
|
|
15836
|
+
await link(temporary, destination);
|
|
15837
|
+
if (process.platform !== "win32") {
|
|
15838
|
+
const directory = await open2(path.dirname(destination), "r");
|
|
15839
|
+
try {
|
|
15840
|
+
await directory.sync();
|
|
15841
|
+
} finally {
|
|
15842
|
+
await directory.close();
|
|
15843
|
+
}
|
|
15844
|
+
}
|
|
15845
|
+
} finally {
|
|
15846
|
+
await rm(temporary, { force: true });
|
|
15847
|
+
}
|
|
15905
15848
|
}
|
|
15906
|
-
function
|
|
15907
|
-
|
|
15908
|
-
|
|
15909
|
-
|
|
15849
|
+
async function readPiEmptySessionConfiguration(sessionFile) {
|
|
15850
|
+
let header;
|
|
15851
|
+
try {
|
|
15852
|
+
header = await readPiSessionHeader(sessionFile);
|
|
15853
|
+
} catch (error51) {
|
|
15854
|
+
if (error51.code === "ENOENT")
|
|
15855
|
+
return void 0;
|
|
15856
|
+
throw error51;
|
|
15910
15857
|
}
|
|
15911
|
-
|
|
15912
|
-
|
|
15913
|
-
|
|
15858
|
+
if (header.version !== 3)
|
|
15859
|
+
return void 0;
|
|
15860
|
+
const stream = createReadStream(sessionFile, { encoding: "utf8" });
|
|
15861
|
+
const lines = createInterface({ input: stream, crlfDelay: Infinity });
|
|
15862
|
+
let readFailure;
|
|
15863
|
+
stream.on("error", (error51) => {
|
|
15864
|
+
readFailure = error51;
|
|
15865
|
+
lines.close();
|
|
15866
|
+
});
|
|
15867
|
+
let model;
|
|
15868
|
+
let thinkingLevel;
|
|
15869
|
+
let previous = null;
|
|
15870
|
+
let first = true;
|
|
15871
|
+
try {
|
|
15872
|
+
for await (const line of lines) {
|
|
15873
|
+
if (first) {
|
|
15874
|
+
first = false;
|
|
15875
|
+
continue;
|
|
15876
|
+
}
|
|
15877
|
+
if (!line.trim())
|
|
15878
|
+
continue;
|
|
15879
|
+
const entry = jsonValueSchema.parse(JSON.parse(line));
|
|
15880
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
15881
|
+
return void 0;
|
|
15882
|
+
if (entry.type === "message" || typeof entry.id !== "string" || entry.parentId !== previous)
|
|
15883
|
+
return void 0;
|
|
15884
|
+
previous = entry.id;
|
|
15885
|
+
if (entry.type === "model_change" && typeof entry.provider === "string" && typeof entry.modelId === "string") {
|
|
15886
|
+
model = { provider: entry.provider, id: entry.modelId };
|
|
15887
|
+
}
|
|
15888
|
+
if (entry.type === "thinking_level_change") {
|
|
15889
|
+
thinkingLevel = harnessThinkingOptionIdSchema.parse(entry.thinkingLevel);
|
|
15890
|
+
}
|
|
15914
15891
|
}
|
|
15892
|
+
} finally {
|
|
15893
|
+
lines.close();
|
|
15894
|
+
stream.destroy();
|
|
15915
15895
|
}
|
|
15916
|
-
|
|
15917
|
-
|
|
15918
|
-
|
|
15919
|
-
|
|
15896
|
+
if (readFailure)
|
|
15897
|
+
throw readFailure;
|
|
15898
|
+
return model && thinkingLevel ? { model, thinkingLevel } : void 0;
|
|
15899
|
+
}
|
|
15900
|
+
|
|
15901
|
+
// ../../../node_modules/diff/libesm/diff/base.js
|
|
15902
|
+
var Diff = class {
|
|
15903
|
+
diff(oldStr, newStr, options = {}) {
|
|
15904
|
+
let callback;
|
|
15905
|
+
if (typeof options === "function") {
|
|
15906
|
+
callback = options;
|
|
15907
|
+
options = {};
|
|
15908
|
+
} else if ("callback" in options) {
|
|
15909
|
+
callback = options.callback;
|
|
15920
15910
|
}
|
|
15921
|
-
|
|
15922
|
-
|
|
15923
|
-
|
|
15911
|
+
const oldString = this.castInput(oldStr, options);
|
|
15912
|
+
const newString = this.castInput(newStr, options);
|
|
15913
|
+
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
15914
|
+
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
15915
|
+
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
15916
|
+
}
|
|
15917
|
+
diffWithOptionsObj(oldTokens, newTokens, options, callback) {
|
|
15918
|
+
var _a3;
|
|
15919
|
+
const done = (value) => {
|
|
15920
|
+
value = this.postProcess(value, options);
|
|
15921
|
+
if (callback) {
|
|
15922
|
+
setTimeout(function() {
|
|
15923
|
+
callback(value);
|
|
15924
|
+
}, 0);
|
|
15925
|
+
return void 0;
|
|
15926
|
+
} else {
|
|
15927
|
+
return value;
|
|
15924
15928
|
}
|
|
15925
|
-
|
|
15929
|
+
};
|
|
15930
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
15931
|
+
let editLength = 1;
|
|
15932
|
+
let maxEditLength = newLen + oldLen;
|
|
15933
|
+
if (options.maxEditLength != null) {
|
|
15934
|
+
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
15926
15935
|
}
|
|
15927
|
-
|
|
15928
|
-
|
|
15936
|
+
const maxExecutionTime = (_a3 = options.timeout) !== null && _a3 !== void 0 ? _a3 : Infinity;
|
|
15937
|
+
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
15938
|
+
const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
|
|
15939
|
+
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
15940
|
+
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
15941
|
+
return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
15942
|
+
}
|
|
15943
|
+
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
15944
|
+
const execEditLength = () => {
|
|
15945
|
+
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
15946
|
+
let basePath;
|
|
15947
|
+
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
15948
|
+
if (removePath) {
|
|
15949
|
+
bestPath[diagonalPath - 1] = void 0;
|
|
15950
|
+
}
|
|
15951
|
+
let canAdd = false;
|
|
15952
|
+
if (addPath) {
|
|
15953
|
+
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
15954
|
+
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
15955
|
+
}
|
|
15956
|
+
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
15957
|
+
if (!canAdd && !canRemove) {
|
|
15958
|
+
bestPath[diagonalPath] = void 0;
|
|
15959
|
+
continue;
|
|
15960
|
+
}
|
|
15961
|
+
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
15962
|
+
basePath = this.addToPath(addPath, true, false, 0, options);
|
|
15963
|
+
} else {
|
|
15964
|
+
basePath = this.addToPath(removePath, false, true, 1, options);
|
|
15965
|
+
}
|
|
15966
|
+
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
15967
|
+
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
15968
|
+
return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
15969
|
+
} else {
|
|
15970
|
+
bestPath[diagonalPath] = basePath;
|
|
15971
|
+
if (basePath.oldPos + 1 >= oldLen) {
|
|
15972
|
+
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
15973
|
+
}
|
|
15974
|
+
if (newPos + 1 >= newLen) {
|
|
15975
|
+
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
15976
|
+
}
|
|
15977
|
+
}
|
|
15978
|
+
}
|
|
15979
|
+
editLength++;
|
|
15980
|
+
};
|
|
15981
|
+
if (callback) {
|
|
15982
|
+
(function exec() {
|
|
15983
|
+
setTimeout(function() {
|
|
15984
|
+
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
15985
|
+
return callback(void 0);
|
|
15986
|
+
}
|
|
15987
|
+
if (!execEditLength()) {
|
|
15988
|
+
exec();
|
|
15989
|
+
}
|
|
15990
|
+
}, 0);
|
|
15991
|
+
})();
|
|
15992
|
+
} else {
|
|
15993
|
+
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
15994
|
+
const ret = execEditLength();
|
|
15995
|
+
if (ret) {
|
|
15996
|
+
return ret;
|
|
15997
|
+
}
|
|
15998
|
+
}
|
|
15999
|
+
}
|
|
16000
|
+
}
|
|
16001
|
+
addToPath(path7, added, removed, oldPosInc, options) {
|
|
16002
|
+
const last = path7.lastComponent;
|
|
16003
|
+
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
16004
|
+
return {
|
|
16005
|
+
oldPos: path7.oldPos + oldPosInc,
|
|
16006
|
+
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
16007
|
+
};
|
|
16008
|
+
} else {
|
|
16009
|
+
return {
|
|
16010
|
+
oldPos: path7.oldPos + oldPosInc,
|
|
16011
|
+
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
16012
|
+
};
|
|
16013
|
+
}
|
|
16014
|
+
}
|
|
16015
|
+
extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
|
|
16016
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
16017
|
+
let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
16018
|
+
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
|
|
16019
|
+
newPos++;
|
|
16020
|
+
oldPos++;
|
|
16021
|
+
commonCount++;
|
|
16022
|
+
if (options.oneChangePerToken) {
|
|
16023
|
+
basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
16024
|
+
}
|
|
16025
|
+
}
|
|
16026
|
+
if (commonCount && !options.oneChangePerToken) {
|
|
16027
|
+
basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
16028
|
+
}
|
|
16029
|
+
basePath.oldPos = oldPos;
|
|
16030
|
+
return newPos;
|
|
16031
|
+
}
|
|
16032
|
+
equals(left, right, options) {
|
|
16033
|
+
if (options.comparator) {
|
|
16034
|
+
return options.comparator(left, right);
|
|
16035
|
+
} else {
|
|
16036
|
+
return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
16037
|
+
}
|
|
16038
|
+
}
|
|
16039
|
+
removeEmpty(array2) {
|
|
16040
|
+
const ret = [];
|
|
16041
|
+
for (let i = 0; i < array2.length; i++) {
|
|
16042
|
+
if (array2[i]) {
|
|
16043
|
+
ret.push(array2[i]);
|
|
16044
|
+
}
|
|
16045
|
+
}
|
|
16046
|
+
return ret;
|
|
16047
|
+
}
|
|
16048
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16049
|
+
castInput(value, options) {
|
|
16050
|
+
return value;
|
|
16051
|
+
}
|
|
16052
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16053
|
+
tokenize(value, options) {
|
|
16054
|
+
return Array.from(value);
|
|
16055
|
+
}
|
|
16056
|
+
join(chars) {
|
|
16057
|
+
return chars.join("");
|
|
16058
|
+
}
|
|
16059
|
+
postProcess(changeObjects, options) {
|
|
16060
|
+
return changeObjects;
|
|
16061
|
+
}
|
|
16062
|
+
get useLongestToken() {
|
|
16063
|
+
return false;
|
|
16064
|
+
}
|
|
16065
|
+
buildValues(lastComponent, newTokens, oldTokens) {
|
|
16066
|
+
const components = [];
|
|
16067
|
+
let nextComponent;
|
|
16068
|
+
while (lastComponent) {
|
|
16069
|
+
components.push(lastComponent);
|
|
16070
|
+
nextComponent = lastComponent.previousComponent;
|
|
16071
|
+
delete lastComponent.previousComponent;
|
|
16072
|
+
lastComponent = nextComponent;
|
|
15929
16073
|
}
|
|
15930
|
-
|
|
15931
|
-
|
|
15932
|
-
|
|
16074
|
+
components.reverse();
|
|
16075
|
+
const componentLen = components.length;
|
|
16076
|
+
let componentPos = 0, newPos = 0, oldPos = 0;
|
|
16077
|
+
for (; componentPos < componentLen; componentPos++) {
|
|
16078
|
+
const component = components[componentPos];
|
|
16079
|
+
if (!component.removed) {
|
|
16080
|
+
if (!component.added && this.useLongestToken) {
|
|
16081
|
+
let value = newTokens.slice(newPos, newPos + component.count);
|
|
16082
|
+
value = value.map(function(value2, i) {
|
|
16083
|
+
const oldValue = oldTokens[oldPos + i];
|
|
16084
|
+
return oldValue.length > value2.length ? oldValue : value2;
|
|
16085
|
+
});
|
|
16086
|
+
component.value = this.join(value);
|
|
16087
|
+
} else {
|
|
16088
|
+
component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
16089
|
+
}
|
|
16090
|
+
newPos += component.count;
|
|
16091
|
+
if (!component.added) {
|
|
16092
|
+
oldPos += component.count;
|
|
16093
|
+
}
|
|
16094
|
+
} else {
|
|
16095
|
+
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
16096
|
+
oldPos += component.count;
|
|
16097
|
+
}
|
|
15933
16098
|
}
|
|
16099
|
+
return components;
|
|
15934
16100
|
}
|
|
15935
|
-
|
|
15936
|
-
}
|
|
16101
|
+
};
|
|
15937
16102
|
|
|
15938
|
-
//
|
|
15939
|
-
var
|
|
15940
|
-
outputs;
|
|
15941
|
-
#consumerCreated = false;
|
|
15942
|
-
#ended = false;
|
|
15943
|
-
#pending = [];
|
|
15944
|
-
#values = [];
|
|
16103
|
+
// ../../../node_modules/diff/libesm/diff/line.js
|
|
16104
|
+
var LineDiff = class extends Diff {
|
|
15945
16105
|
constructor() {
|
|
15946
|
-
|
|
15947
|
-
|
|
15948
|
-
|
|
15949
|
-
|
|
15950
|
-
|
|
15951
|
-
|
|
15952
|
-
|
|
15953
|
-
next: () => this.#next()
|
|
15954
|
-
};
|
|
16106
|
+
super(...arguments);
|
|
16107
|
+
this.tokenize = tokenize;
|
|
16108
|
+
}
|
|
16109
|
+
equals(left, right, options) {
|
|
16110
|
+
if (options.ignoreWhitespace) {
|
|
16111
|
+
if (!options.newlineIsToken || !left.includes("\n")) {
|
|
16112
|
+
left = left.trim();
|
|
15955
16113
|
}
|
|
15956
|
-
|
|
16114
|
+
if (!options.newlineIsToken || !right.includes("\n")) {
|
|
16115
|
+
right = right.trim();
|
|
16116
|
+
}
|
|
16117
|
+
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
16118
|
+
if (left.endsWith("\n")) {
|
|
16119
|
+
left = left.slice(0, -1);
|
|
16120
|
+
}
|
|
16121
|
+
if (right.endsWith("\n")) {
|
|
16122
|
+
right = right.slice(0, -1);
|
|
16123
|
+
}
|
|
16124
|
+
}
|
|
16125
|
+
return super.equals(left, right, options);
|
|
15957
16126
|
}
|
|
15958
|
-
|
|
15959
|
-
|
|
15960
|
-
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
return true;
|
|
16127
|
+
};
|
|
16128
|
+
var lineDiff = new LineDiff();
|
|
16129
|
+
function diffLines(oldStr, newStr, options) {
|
|
16130
|
+
return lineDiff.diff(oldStr, newStr, options);
|
|
16131
|
+
}
|
|
16132
|
+
function tokenize(value, options) {
|
|
16133
|
+
if (options.stripTrailingCr) {
|
|
16134
|
+
value = value.replace(/\r\n/g, "\n");
|
|
15967
16135
|
}
|
|
15968
|
-
|
|
15969
|
-
|
|
15970
|
-
|
|
15971
|
-
this.#ended = true;
|
|
15972
|
-
if (this.#values.length !== 0)
|
|
15973
|
-
return;
|
|
15974
|
-
for (const resolve of this.#pending.splice(0))
|
|
15975
|
-
resolve({ done: true, value: void 0 });
|
|
16136
|
+
const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
16137
|
+
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
16138
|
+
linesAndNewlines.pop();
|
|
15976
16139
|
}
|
|
15977
|
-
|
|
15978
|
-
const
|
|
15979
|
-
if (
|
|
15980
|
-
|
|
15981
|
-
|
|
15982
|
-
|
|
15983
|
-
|
|
16140
|
+
for (let i = 0; i < linesAndNewlines.length; i++) {
|
|
16141
|
+
const line = linesAndNewlines[i];
|
|
16142
|
+
if (i % 2 && !options.newlineIsToken) {
|
|
16143
|
+
retLines[retLines.length - 1] += line;
|
|
16144
|
+
} else {
|
|
16145
|
+
retLines.push(line);
|
|
16146
|
+
}
|
|
15984
16147
|
}
|
|
15985
|
-
|
|
15986
|
-
|
|
15987
|
-
// ../../harness-adapter/dist/diagnostics.js
|
|
15988
|
-
var DIAGNOSTIC_TAIL_MAX_LENGTH = 8e3;
|
|
15989
|
-
var SENSITIVE_VALUE_PATTERN = /(api[_-]?key|access[_-]?token|auth(?:orization)?|password|secret)(\s*[:=]\s*)([^\s,;]+)/giu;
|
|
15990
|
-
var BEARER_PATTERN = /\bBearer\s+[A-Za-z0-9._~+/=-]+/giu;
|
|
15991
|
-
function sanitizeDiagnosticTail(value) {
|
|
15992
|
-
const redacted = value.replace(BEARER_PATTERN, "Bearer [redacted]").replace(SENSITIVE_VALUE_PATTERN, "$1$2[redacted]");
|
|
15993
|
-
return redacted.length <= DIAGNOSTIC_TAIL_MAX_LENGTH ? redacted : redacted.slice(-DIAGNOSTIC_TAIL_MAX_LENGTH);
|
|
16148
|
+
return retLines;
|
|
15994
16149
|
}
|
|
15995
16150
|
|
|
15996
|
-
//
|
|
15997
|
-
|
|
15998
|
-
|
|
15999
|
-
|
|
16000
|
-
|
|
16001
|
-
|
|
16002
|
-
|
|
16003
|
-
|
|
16004
|
-
|
|
16005
|
-
|
|
16006
|
-
|
|
16007
|
-
|
|
16008
|
-
|
|
16009
|
-
|
|
16010
|
-
|
|
16011
|
-
|
|
16012
|
-
|
|
16013
|
-
|
|
16014
|
-
|
|
16015
|
-
|
|
16016
|
-
];
|
|
16017
|
-
|
|
16018
|
-
|
|
16019
|
-
|
|
16020
|
-
|
|
16021
|
-
|
|
16022
|
-
|
|
16023
|
-
|
|
16024
|
-
|
|
16025
|
-
|
|
16026
|
-
|
|
16027
|
-
}
|
|
16028
|
-
function parseHostUsage(value) {
|
|
16029
|
-
if (!isRecord(value))
|
|
16030
|
-
throw new Error("Harness Usage must be an object");
|
|
16031
|
-
const keys = Object.keys(value);
|
|
16032
|
-
if (keys.length === 0)
|
|
16033
|
-
throw new Error("Harness Usage must contain a reliable field");
|
|
16034
|
-
for (const key of keys) {
|
|
16035
|
-
if (!usageFields.has(key)) {
|
|
16036
|
-
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
16151
|
+
// ../../../node_modules/diff/libesm/patch/parse.js
|
|
16152
|
+
function parsePatch(uniDiff) {
|
|
16153
|
+
const diffstr = uniDiff.split(/\n/), list = [];
|
|
16154
|
+
let i = 0;
|
|
16155
|
+
function parseIndex() {
|
|
16156
|
+
const index = {};
|
|
16157
|
+
list.push(index);
|
|
16158
|
+
while (i < diffstr.length) {
|
|
16159
|
+
const line = diffstr[i];
|
|
16160
|
+
if (/^(---|\+\+\+|@@)\s/.test(line)) {
|
|
16161
|
+
break;
|
|
16162
|
+
}
|
|
16163
|
+
const header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
|
|
16164
|
+
if (header) {
|
|
16165
|
+
index.index = header[1];
|
|
16166
|
+
}
|
|
16167
|
+
i++;
|
|
16168
|
+
}
|
|
16169
|
+
parseFileHeader(index);
|
|
16170
|
+
parseFileHeader(index);
|
|
16171
|
+
index.hunks = [];
|
|
16172
|
+
while (i < diffstr.length) {
|
|
16173
|
+
const line = diffstr[i];
|
|
16174
|
+
if (/^(Index:\s|diff\s|---\s|\+\+\+\s|===================================================================)/.test(line)) {
|
|
16175
|
+
break;
|
|
16176
|
+
} else if (/^@@/.test(line)) {
|
|
16177
|
+
index.hunks.push(parseHunk());
|
|
16178
|
+
} else if (line) {
|
|
16179
|
+
throw new Error("Unknown line " + (i + 1) + " " + JSON.stringify(line));
|
|
16180
|
+
} else {
|
|
16181
|
+
i++;
|
|
16182
|
+
}
|
|
16037
16183
|
}
|
|
16038
16184
|
}
|
|
16039
|
-
|
|
16040
|
-
const
|
|
16041
|
-
if (
|
|
16042
|
-
|
|
16185
|
+
function parseFileHeader(index) {
|
|
16186
|
+
const fileHeader = /^(---|\+\+\+)\s+(.*)\r?$/.exec(diffstr[i]);
|
|
16187
|
+
if (fileHeader) {
|
|
16188
|
+
const data = fileHeader[2].split(" ", 2), header = (data[1] || "").trim();
|
|
16189
|
+
let fileName = data[0].replace(/\\\\/g, "\\");
|
|
16190
|
+
if (/^".*"$/.test(fileName)) {
|
|
16191
|
+
fileName = fileName.substr(1, fileName.length - 2);
|
|
16192
|
+
}
|
|
16193
|
+
if (fileHeader[1] === "---") {
|
|
16194
|
+
index.oldFileName = fileName;
|
|
16195
|
+
index.oldHeader = header;
|
|
16196
|
+
} else {
|
|
16197
|
+
index.newFileName = fileName;
|
|
16198
|
+
index.newHeader = header;
|
|
16199
|
+
}
|
|
16200
|
+
i++;
|
|
16043
16201
|
}
|
|
16044
16202
|
}
|
|
16045
|
-
|
|
16046
|
-
|
|
16047
|
-
|
|
16048
|
-
|
|
16203
|
+
function parseHunk() {
|
|
16204
|
+
var _a3;
|
|
16205
|
+
const chunkHeaderIndex = i, chunkHeaderLine = diffstr[i++], chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
|
16206
|
+
const hunk = {
|
|
16207
|
+
oldStart: +chunkHeader[1],
|
|
16208
|
+
oldLines: typeof chunkHeader[2] === "undefined" ? 1 : +chunkHeader[2],
|
|
16209
|
+
newStart: +chunkHeader[3],
|
|
16210
|
+
newLines: typeof chunkHeader[4] === "undefined" ? 1 : +chunkHeader[4],
|
|
16211
|
+
lines: []
|
|
16212
|
+
};
|
|
16213
|
+
if (hunk.oldLines === 0) {
|
|
16214
|
+
hunk.oldStart += 1;
|
|
16215
|
+
}
|
|
16216
|
+
if (hunk.newLines === 0) {
|
|
16217
|
+
hunk.newStart += 1;
|
|
16218
|
+
}
|
|
16219
|
+
let addCount = 0, removeCount = 0;
|
|
16220
|
+
for (; i < diffstr.length && (removeCount < hunk.oldLines || addCount < hunk.newLines || ((_a3 = diffstr[i]) === null || _a3 === void 0 ? void 0 : _a3.startsWith("\\"))); i++) {
|
|
16221
|
+
const operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? " " : diffstr[i][0];
|
|
16222
|
+
if (operation === "+" || operation === "-" || operation === " " || operation === "\\") {
|
|
16223
|
+
hunk.lines.push(diffstr[i]);
|
|
16224
|
+
if (operation === "+") {
|
|
16225
|
+
addCount++;
|
|
16226
|
+
} else if (operation === "-") {
|
|
16227
|
+
removeCount++;
|
|
16228
|
+
} else if (operation === " ") {
|
|
16229
|
+
addCount++;
|
|
16230
|
+
removeCount++;
|
|
16231
|
+
}
|
|
16232
|
+
} else {
|
|
16233
|
+
throw new Error(`Hunk at line ${chunkHeaderIndex + 1} contained invalid line ${diffstr[i]}`);
|
|
16234
|
+
}
|
|
16235
|
+
}
|
|
16236
|
+
if (!addCount && hunk.newLines === 1) {
|
|
16237
|
+
hunk.newLines = 0;
|
|
16238
|
+
}
|
|
16239
|
+
if (!removeCount && hunk.oldLines === 1) {
|
|
16240
|
+
hunk.oldLines = 0;
|
|
16049
16241
|
}
|
|
16050
|
-
|
|
16051
|
-
|
|
16052
|
-
throw new Error("Harness Usage 'outputTokensPerSecond' must be a finite non-negative number");
|
|
16053
|
-
}
|
|
16054
|
-
if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
|
|
16055
|
-
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
16056
|
-
}
|
|
16057
|
-
for (const field of ["totalCredits", "contextUsagePercent"]) {
|
|
16058
|
-
const candidate = value[field];
|
|
16059
|
-
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
16060
|
-
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
16242
|
+
if (addCount !== hunk.newLines) {
|
|
16243
|
+
throw new Error("Added line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
16061
16244
|
}
|
|
16062
|
-
|
|
16063
|
-
|
|
16064
|
-
const candidate = value[field];
|
|
16065
|
-
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
|
|
16066
|
-
throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
|
|
16245
|
+
if (removeCount !== hunk.oldLines) {
|
|
16246
|
+
throw new Error("Removed line count did not match for hunk at line " + (chunkHeaderIndex + 1));
|
|
16067
16247
|
}
|
|
16248
|
+
return hunk;
|
|
16068
16249
|
}
|
|
16069
|
-
|
|
16070
|
-
|
|
16071
|
-
if (hasContextUsed !== hasContextWindow) {
|
|
16072
|
-
throw new Error("Harness Usage context fields must be provided together");
|
|
16073
|
-
}
|
|
16074
|
-
if (hasContextWindow && value.contextWindowTokens === 0) {
|
|
16075
|
-
throw new Error("Harness Usage 'contextWindowTokens' must be greater than zero");
|
|
16076
|
-
}
|
|
16077
|
-
if (value.planFiveHourResetsAtUnix !== void 0 && value.planFiveHourUsedPercent === void 0) {
|
|
16078
|
-
throw new Error("Harness Usage 'planFiveHourResetsAtUnix' must be provided with 'planFiveHourUsedPercent'");
|
|
16079
|
-
}
|
|
16080
|
-
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
16081
|
-
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
16250
|
+
while (i < diffstr.length) {
|
|
16251
|
+
parseIndex();
|
|
16082
16252
|
}
|
|
16083
|
-
return
|
|
16253
|
+
return list;
|
|
16084
16254
|
}
|
|
16085
16255
|
|
|
16086
|
-
//
|
|
16087
|
-
|
|
16088
|
-
|
|
16089
|
-
|
|
16090
|
-
|
|
16091
|
-
"
|
|
16092
|
-
|
|
16093
|
-
|
|
16094
|
-
|
|
16095
|
-
"max"
|
|
16096
|
-
].map((id) => harnessThinkingOptionIdSchema.parse(id));
|
|
16097
|
-
var PI_THINKING_LABELS = {
|
|
16098
|
-
off: "Off",
|
|
16099
|
-
minimal: "Minimal",
|
|
16100
|
-
low: "Low",
|
|
16101
|
-
medium: "Medium",
|
|
16102
|
-
high: "High",
|
|
16103
|
-
xhigh: "Extra High",
|
|
16104
|
-
max: "Max"
|
|
16105
|
-
};
|
|
16106
|
-
function compareText(left, right) {
|
|
16107
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
16108
|
-
}
|
|
16109
|
-
function assertNativePart(value, name) {
|
|
16110
|
-
if (value.trim().length === 0)
|
|
16111
|
-
throw new Error(`Pi ${name} must not be empty`);
|
|
16112
|
-
}
|
|
16113
|
-
function encodePiModelRef(model) {
|
|
16114
|
-
assertNativePart(model.provider, "Model provider");
|
|
16115
|
-
assertNativePart(model.id, "Model id");
|
|
16116
|
-
const encoded = Buffer.from(JSON.stringify([model.provider, model.id]), "utf8").toString("base64url");
|
|
16117
|
-
return harnessModelRefSchema.parse({ id: `${PI_MODEL_REF_PREFIX}${encoded}` });
|
|
16118
|
-
}
|
|
16119
|
-
function decodePiModelRef(ref) {
|
|
16120
|
-
const parsedRef = harnessModelRefSchema.parse(ref);
|
|
16121
|
-
if (!parsedRef.id.startsWith(PI_MODEL_REF_PREFIX)) {
|
|
16122
|
-
throw new Error("Model Ref does not belong to PiAdapter");
|
|
16256
|
+
// ../../../node_modules/diff/libesm/patch/create.js
|
|
16257
|
+
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
16258
|
+
let optionsObj;
|
|
16259
|
+
if (!options) {
|
|
16260
|
+
optionsObj = {};
|
|
16261
|
+
} else if (typeof options === "function") {
|
|
16262
|
+
optionsObj = { callback: options };
|
|
16263
|
+
} else {
|
|
16264
|
+
optionsObj = options;
|
|
16123
16265
|
}
|
|
16124
|
-
|
|
16125
|
-
|
|
16126
|
-
try {
|
|
16127
|
-
decoded = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
|
|
16128
|
-
} catch {
|
|
16129
|
-
throw new Error("Pi Model Ref is malformed");
|
|
16266
|
+
if (typeof optionsObj.context === "undefined") {
|
|
16267
|
+
optionsObj.context = 4;
|
|
16130
16268
|
}
|
|
16131
|
-
|
|
16132
|
-
|
|
16269
|
+
const context = optionsObj.context;
|
|
16270
|
+
if (optionsObj.newlineIsToken) {
|
|
16271
|
+
throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
|
|
16133
16272
|
}
|
|
16134
|
-
|
|
16135
|
-
|
|
16136
|
-
|
|
16137
|
-
|
|
16138
|
-
|
|
16273
|
+
if (!optionsObj.callback) {
|
|
16274
|
+
return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
|
|
16275
|
+
} else {
|
|
16276
|
+
const { callback } = optionsObj;
|
|
16277
|
+
diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
|
|
16278
|
+
const patch = diffLinesResultToPatch(diff);
|
|
16279
|
+
callback(patch);
|
|
16280
|
+
} }));
|
|
16139
16281
|
}
|
|
16140
|
-
|
|
16141
|
-
|
|
16142
|
-
|
|
16143
|
-
|
|
16144
|
-
}
|
|
16145
|
-
function
|
|
16146
|
-
|
|
16147
|
-
|
|
16148
|
-
}
|
|
16149
|
-
|
|
16150
|
-
|
|
16151
|
-
|
|
16152
|
-
|
|
16153
|
-
|
|
16154
|
-
|
|
16155
|
-
|
|
16156
|
-
|
|
16157
|
-
|
|
16158
|
-
|
|
16159
|
-
|
|
16160
|
-
|
|
16161
|
-
|
|
16162
|
-
|
|
16282
|
+
function diffLinesResultToPatch(diff) {
|
|
16283
|
+
if (!diff) {
|
|
16284
|
+
return;
|
|
16285
|
+
}
|
|
16286
|
+
diff.push({ value: "", lines: [] });
|
|
16287
|
+
function contextLines(lines) {
|
|
16288
|
+
return lines.map(function(entry) {
|
|
16289
|
+
return " " + entry;
|
|
16290
|
+
});
|
|
16291
|
+
}
|
|
16292
|
+
const hunks = [];
|
|
16293
|
+
let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
|
|
16294
|
+
for (let i = 0; i < diff.length; i++) {
|
|
16295
|
+
const current = diff[i], lines = current.lines || splitLines(current.value);
|
|
16296
|
+
current.lines = lines;
|
|
16297
|
+
if (current.added || current.removed) {
|
|
16298
|
+
if (!oldRangeStart) {
|
|
16299
|
+
const prev = diff[i - 1];
|
|
16300
|
+
oldRangeStart = oldLine;
|
|
16301
|
+
newRangeStart = newLine;
|
|
16302
|
+
if (prev) {
|
|
16303
|
+
curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
|
|
16304
|
+
oldRangeStart -= curRange.length;
|
|
16305
|
+
newRangeStart -= curRange.length;
|
|
16306
|
+
}
|
|
16307
|
+
}
|
|
16308
|
+
for (const line of lines) {
|
|
16309
|
+
curRange.push((current.added ? "+" : "-") + line);
|
|
16310
|
+
}
|
|
16311
|
+
if (current.added) {
|
|
16312
|
+
newLine += lines.length;
|
|
16313
|
+
} else {
|
|
16314
|
+
oldLine += lines.length;
|
|
16315
|
+
}
|
|
16316
|
+
} else {
|
|
16317
|
+
if (oldRangeStart) {
|
|
16318
|
+
if (lines.length <= context * 2 && i < diff.length - 2) {
|
|
16319
|
+
for (const line of contextLines(lines)) {
|
|
16320
|
+
curRange.push(line);
|
|
16321
|
+
}
|
|
16322
|
+
} else {
|
|
16323
|
+
const contextSize = Math.min(lines.length, context);
|
|
16324
|
+
for (const line of contextLines(lines.slice(0, contextSize))) {
|
|
16325
|
+
curRange.push(line);
|
|
16326
|
+
}
|
|
16327
|
+
const hunk = {
|
|
16328
|
+
oldStart: oldRangeStart,
|
|
16329
|
+
oldLines: oldLine - oldRangeStart + contextSize,
|
|
16330
|
+
newStart: newRangeStart,
|
|
16331
|
+
newLines: newLine - newRangeStart + contextSize,
|
|
16332
|
+
lines: curRange
|
|
16333
|
+
};
|
|
16334
|
+
hunks.push(hunk);
|
|
16335
|
+
oldRangeStart = 0;
|
|
16336
|
+
newRangeStart = 0;
|
|
16337
|
+
curRange = [];
|
|
16338
|
+
}
|
|
16339
|
+
}
|
|
16340
|
+
oldLine += lines.length;
|
|
16341
|
+
newLine += lines.length;
|
|
16163
16342
|
}
|
|
16164
|
-
continue;
|
|
16165
16343
|
}
|
|
16166
|
-
|
|
16167
|
-
|
|
16168
|
-
|
|
16169
|
-
|
|
16170
|
-
|
|
16171
|
-
|
|
16172
|
-
|
|
16173
|
-
|
|
16174
|
-
|
|
16175
|
-
|
|
16176
|
-
|
|
16177
|
-
|
|
16178
|
-
|
|
16179
|
-
|
|
16180
|
-
|
|
16181
|
-
|
|
16182
|
-
|
|
16183
|
-
}
|
|
16184
|
-
const thinkingOptions = thinkingLevels ? normalizePiThinkingOptions(PI_DRAFT_THINKING_OPTION_IDS) : [];
|
|
16185
|
-
const allThinkingOptionIds = thinkingOptions.map(({ id }) => id);
|
|
16186
|
-
const offThinkingOptionId = thinkingOptions.find(({ id }) => id === "off")?.id;
|
|
16187
|
-
const models = [...byRef.values()].map(({ model, reasoning }) => ({
|
|
16188
|
-
...model,
|
|
16189
|
-
supportedThinkingOptionIds: reasoning ? allThinkingOptionIds : offThinkingOptionId ? [offThinkingOptionId] : []
|
|
16190
|
-
})).sort((left, right) => compareText(left.label, right.label) || compareText(left.ref.id, right.ref.id));
|
|
16191
|
-
const defaultThinkingOptionId = thinkingOptions.find(({ id }) => id === effectiveThinkingOptionId)?.id;
|
|
16192
|
-
return harnessModelCatalogSchema.parse({
|
|
16193
|
-
models,
|
|
16194
|
-
...defaultModel ? { defaultModel } : {},
|
|
16195
|
-
thinkingOptions,
|
|
16196
|
-
...defaultThinkingOptionId ? { defaultThinkingOptionId } : {}
|
|
16197
|
-
});
|
|
16198
|
-
}
|
|
16199
|
-
|
|
16200
|
-
// dist/pi-history.js
|
|
16201
|
-
var piHarnessId = harnessIdSchema.parse("pi");
|
|
16202
|
-
function isRecord2(value) {
|
|
16203
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16204
|
-
}
|
|
16205
|
-
function textContent(value) {
|
|
16206
|
-
if (typeof value === "string")
|
|
16207
|
-
return value;
|
|
16208
|
-
if (!Array.isArray(value))
|
|
16209
|
-
return "";
|
|
16210
|
-
return value.filter((part) => isRecord2(part) && part.type === "text" && typeof part.text === "string").map((part) => part.text).join("");
|
|
16211
|
-
}
|
|
16212
|
-
function thinkingContent(value) {
|
|
16213
|
-
if (!Array.isArray(value))
|
|
16214
|
-
return "";
|
|
16215
|
-
return value.filter((part) => isRecord2(part) && part.type === "thinking" && typeof part.thinking === "string").map((part) => part.thinking).join("");
|
|
16216
|
-
}
|
|
16217
|
-
function validatedEntry(value) {
|
|
16218
|
-
if (typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
|
|
16219
|
-
throw new Error("Pi history contains an invalid Entry identity");
|
|
16344
|
+
for (const hunk of hunks) {
|
|
16345
|
+
for (let i = 0; i < hunk.lines.length; i++) {
|
|
16346
|
+
if (hunk.lines[i].endsWith("\n")) {
|
|
16347
|
+
hunk.lines[i] = hunk.lines[i].slice(0, -1);
|
|
16348
|
+
} else {
|
|
16349
|
+
hunk.lines.splice(i + 1, 0, "\");
|
|
16350
|
+
i++;
|
|
16351
|
+
}
|
|
16352
|
+
}
|
|
16353
|
+
}
|
|
16354
|
+
return {
|
|
16355
|
+
oldFileName,
|
|
16356
|
+
newFileName,
|
|
16357
|
+
oldHeader,
|
|
16358
|
+
newHeader,
|
|
16359
|
+
hunks
|
|
16360
|
+
};
|
|
16220
16361
|
}
|
|
16221
|
-
return value;
|
|
16222
16362
|
}
|
|
16223
|
-
function
|
|
16224
|
-
if (
|
|
16225
|
-
return
|
|
16226
|
-
const byId = new Map(history.entries.map((value) => {
|
|
16227
|
-
const entry = validatedEntry(value);
|
|
16228
|
-
return [entry.id, entry];
|
|
16229
|
-
}));
|
|
16230
|
-
const reversed = [];
|
|
16231
|
-
const visited = /* @__PURE__ */ new Set();
|
|
16232
|
-
let current = history.leafId;
|
|
16233
|
-
while (current !== null) {
|
|
16234
|
-
if (visited.has(current))
|
|
16235
|
-
throw new Error("Pi history active branch contains a cycle");
|
|
16236
|
-
visited.add(current);
|
|
16237
|
-
const entry = byId.get(current);
|
|
16238
|
-
if (!entry)
|
|
16239
|
-
throw new Error("Pi history active branch references a missing Entry");
|
|
16240
|
-
reversed.push(entry);
|
|
16241
|
-
current = entry.parentId;
|
|
16363
|
+
function formatPatch(patch) {
|
|
16364
|
+
if (Array.isArray(patch)) {
|
|
16365
|
+
return patch.map(formatPatch).join("\n");
|
|
16242
16366
|
}
|
|
16243
|
-
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
|
|
16251
|
-
|
|
16252
|
-
|
|
16253
|
-
|
|
16367
|
+
const ret = [];
|
|
16368
|
+
if (patch.oldFileName == patch.newFileName) {
|
|
16369
|
+
ret.push("Index: " + patch.oldFileName);
|
|
16370
|
+
}
|
|
16371
|
+
ret.push("===================================================================");
|
|
16372
|
+
ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
|
|
16373
|
+
ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
|
|
16374
|
+
for (let i = 0; i < patch.hunks.length; i++) {
|
|
16375
|
+
const hunk = patch.hunks[i];
|
|
16376
|
+
if (hunk.oldLines === 0) {
|
|
16377
|
+
hunk.oldStart -= 1;
|
|
16378
|
+
}
|
|
16379
|
+
if (hunk.newLines === 0) {
|
|
16380
|
+
hunk.newStart -= 1;
|
|
16381
|
+
}
|
|
16382
|
+
ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
|
|
16383
|
+
for (const line of hunk.lines) {
|
|
16384
|
+
ret.push(line);
|
|
16385
|
+
}
|
|
16386
|
+
}
|
|
16387
|
+
return ret.join("\n") + "\n";
|
|
16254
16388
|
}
|
|
16255
|
-
function
|
|
16256
|
-
|
|
16257
|
-
|
|
16258
|
-
if (!final)
|
|
16259
|
-
return { status: "unknown", reason: "Pi history has no Assistant terminal" };
|
|
16260
|
-
const stopReason = final.stopReason;
|
|
16261
|
-
if (stopReason === "aborted") {
|
|
16262
|
-
return { status: "cancelled", reason: "Pi Assistant was aborted" };
|
|
16389
|
+
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
16390
|
+
if (typeof options === "function") {
|
|
16391
|
+
options = { callback: options };
|
|
16263
16392
|
}
|
|
16264
|
-
if (
|
|
16265
|
-
|
|
16266
|
-
|
|
16267
|
-
|
|
16268
|
-
|
|
16269
|
-
|
|
16270
|
-
|
|
16393
|
+
if (!(options === null || options === void 0 ? void 0 : options.callback)) {
|
|
16394
|
+
const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
|
|
16395
|
+
if (!patchObj) {
|
|
16396
|
+
return;
|
|
16397
|
+
}
|
|
16398
|
+
return formatPatch(patchObj);
|
|
16399
|
+
} else {
|
|
16400
|
+
const { callback } = options;
|
|
16401
|
+
structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
|
|
16402
|
+
if (!patchObj) {
|
|
16403
|
+
callback(void 0);
|
|
16404
|
+
} else {
|
|
16405
|
+
callback(formatPatch(patchObj));
|
|
16271
16406
|
}
|
|
16272
|
-
};
|
|
16273
|
-
}
|
|
16274
|
-
if (typeof stopReason === "string" || textContent(final.content).length > 0) {
|
|
16275
|
-
return { status: "succeeded" };
|
|
16407
|
+
} }));
|
|
16276
16408
|
}
|
|
16277
|
-
return { status: "unknown", reason: "Pi Assistant terminal is not classifiable" };
|
|
16278
16409
|
}
|
|
16279
|
-
function
|
|
16280
|
-
|
|
16281
|
-
|
|
16282
|
-
if (
|
|
16283
|
-
|
|
16284
|
-
|
|
16285
|
-
|
|
16286
|
-
};
|
|
16410
|
+
function splitLines(text) {
|
|
16411
|
+
const hasTrailingNl = text.endsWith("\n");
|
|
16412
|
+
const result = text.split("\n").map((line) => line + "\n");
|
|
16413
|
+
if (hasTrailingNl) {
|
|
16414
|
+
result.pop();
|
|
16415
|
+
} else {
|
|
16416
|
+
result.push(result.pop().slice(0, -1));
|
|
16287
16417
|
}
|
|
16288
|
-
return
|
|
16418
|
+
return result;
|
|
16289
16419
|
}
|
|
16290
|
-
|
|
16291
|
-
|
|
16292
|
-
|
|
16420
|
+
|
|
16421
|
+
// dist/pi-adapter.js
|
|
16422
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
16423
|
+
import path6 from "node:path";
|
|
16424
|
+
|
|
16425
|
+
// ../../harness-adapter/dist/question.js
|
|
16426
|
+
function invalidRequest(message3) {
|
|
16427
|
+
return { code: "invalidRequest", message: message3, retryable: false };
|
|
16293
16428
|
}
|
|
16294
|
-
function
|
|
16295
|
-
const
|
|
16296
|
-
|
|
16297
|
-
|
|
16298
|
-
|
|
16299
|
-
|
|
16300
|
-
|
|
16301
|
-
|
|
16302
|
-
|
|
16303
|
-
|
|
16304
|
-
|
|
16305
|
-
|
|
16306
|
-
|
|
16307
|
-
|
|
16308
|
-
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
type: "reasoning",
|
|
16313
|
-
itemId: itemId(entry.id, "reasoning", 0),
|
|
16314
|
-
text: reasoning
|
|
16315
|
-
};
|
|
16316
|
-
snapshots.push({ item: item2, outcome: itemOutcome(outcome) });
|
|
16317
|
-
projectedReasoning = true;
|
|
16318
|
-
continue;
|
|
16319
|
-
}
|
|
16320
|
-
if (part.type === "text" && !projectedText && text.length > 0) {
|
|
16321
|
-
const item2 = {
|
|
16322
|
-
type: "agentMessage",
|
|
16323
|
-
itemId: itemId(entry.id, "assistant", 0),
|
|
16324
|
-
text
|
|
16325
|
-
};
|
|
16326
|
-
snapshots.push({ item: item2, outcome: itemOutcome(outcome) });
|
|
16327
|
-
projectedText = true;
|
|
16328
|
-
continue;
|
|
16329
|
-
}
|
|
16330
|
-
if (part.type !== "toolCall" || typeof part.id !== "string" || typeof part.name !== "string") {
|
|
16331
|
-
continue;
|
|
16332
|
-
}
|
|
16333
|
-
const parsedArguments = jsonValueSchema.safeParse(part.arguments);
|
|
16334
|
-
if (!parsedArguments.success)
|
|
16335
|
-
continue;
|
|
16336
|
-
toolCalls.set(part.id, {
|
|
16337
|
-
entryId: entry.id,
|
|
16338
|
-
ordinal,
|
|
16339
|
-
name: part.name,
|
|
16340
|
-
arguments: parsedArguments.data
|
|
16341
|
-
});
|
|
16429
|
+
function validateHostQuestionResponse(interaction, response) {
|
|
16430
|
+
const questionIds = new Set(interaction.questions.map(({ id }) => id));
|
|
16431
|
+
if (response.cancelled) {
|
|
16432
|
+
return Object.keys(response.answers).length === 0 ? null : invalidRequest("Cancelled Question Response must not contain answers");
|
|
16433
|
+
}
|
|
16434
|
+
for (const answerId of Object.keys(response.answers)) {
|
|
16435
|
+
if (!questionIds.has(answerId)) {
|
|
16436
|
+
return invalidRequest("Question Response contains an unknown Question ID");
|
|
16437
|
+
}
|
|
16438
|
+
}
|
|
16439
|
+
for (const question of interaction.questions) {
|
|
16440
|
+
const answers = response.answers[question.id] ?? [];
|
|
16441
|
+
if (!question.optional && answers.length === 0) {
|
|
16442
|
+
return invalidRequest("Question Response omits a required answer");
|
|
16443
|
+
}
|
|
16444
|
+
if (question.type === "text") {
|
|
16445
|
+
if (answers.length > 1) {
|
|
16446
|
+
return invalidRequest("Text Question accepts at most one answer");
|
|
16342
16447
|
}
|
|
16343
16448
|
continue;
|
|
16344
16449
|
}
|
|
16345
|
-
if (
|
|
16346
|
-
|
|
16450
|
+
if (!question.multiple && answers.length > 1) {
|
|
16451
|
+
return invalidRequest("Single-choice Question accepts at most one answer");
|
|
16347
16452
|
}
|
|
16348
|
-
const
|
|
16349
|
-
if (!
|
|
16350
|
-
|
|
16351
|
-
|
|
16352
|
-
|
|
16353
|
-
|
|
16354
|
-
|
|
16355
|
-
|
|
16356
|
-
|
|
16357
|
-
|
|
16358
|
-
|
|
16359
|
-
|
|
16360
|
-
|
|
16361
|
-
|
|
16362
|
-
|
|
16363
|
-
|
|
16364
|
-
|
|
16365
|
-
|
|
16366
|
-
|
|
16367
|
-
|
|
16453
|
+
const declared = new Set(question.options.map(({ value }) => value));
|
|
16454
|
+
if (!question.allowOther && answers.some((answer) => !declared.has(answer))) {
|
|
16455
|
+
return invalidRequest("Question Response contains an undeclared choice");
|
|
16456
|
+
}
|
|
16457
|
+
}
|
|
16458
|
+
return null;
|
|
16459
|
+
}
|
|
16460
|
+
|
|
16461
|
+
// ../../harness-adapter/dist/output-channel.js
|
|
16462
|
+
var HarnessOutputChannel = class {
|
|
16463
|
+
outputs;
|
|
16464
|
+
#consumerCreated = false;
|
|
16465
|
+
#ended = false;
|
|
16466
|
+
#pending = [];
|
|
16467
|
+
#values = [];
|
|
16468
|
+
constructor() {
|
|
16469
|
+
this.outputs = {
|
|
16470
|
+
[Symbol.asyncIterator]: () => {
|
|
16471
|
+
if (this.#consumerCreated) {
|
|
16472
|
+
throw new Error("Harness outputs allow only one consumer");
|
|
16368
16473
|
}
|
|
16369
|
-
|
|
16370
|
-
|
|
16474
|
+
this.#consumerCreated = true;
|
|
16475
|
+
return {
|
|
16476
|
+
next: () => this.#next()
|
|
16477
|
+
};
|
|
16478
|
+
}
|
|
16479
|
+
};
|
|
16480
|
+
}
|
|
16481
|
+
emit(value) {
|
|
16482
|
+
if (this.#ended)
|
|
16483
|
+
return false;
|
|
16484
|
+
const resolve = this.#pending.shift();
|
|
16485
|
+
if (resolve)
|
|
16486
|
+
resolve({ done: false, value });
|
|
16487
|
+
else
|
|
16488
|
+
this.#values.push(value);
|
|
16489
|
+
return true;
|
|
16490
|
+
}
|
|
16491
|
+
end() {
|
|
16492
|
+
if (this.#ended)
|
|
16493
|
+
return;
|
|
16494
|
+
this.#ended = true;
|
|
16495
|
+
if (this.#values.length !== 0)
|
|
16496
|
+
return;
|
|
16497
|
+
for (const resolve of this.#pending.splice(0))
|
|
16498
|
+
resolve({ done: true, value: void 0 });
|
|
16371
16499
|
}
|
|
16372
|
-
|
|
16500
|
+
#next() {
|
|
16501
|
+
const value = this.#values.shift();
|
|
16502
|
+
if (value !== void 0)
|
|
16503
|
+
return Promise.resolve({ done: false, value });
|
|
16504
|
+
if (this.#ended)
|
|
16505
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
16506
|
+
return new Promise((resolve) => this.#pending.push(resolve));
|
|
16507
|
+
}
|
|
16508
|
+
};
|
|
16509
|
+
|
|
16510
|
+
// ../../harness-adapter/dist/diagnostics.js
|
|
16511
|
+
var DIAGNOSTIC_TAIL_MAX_LENGTH = 8e3;
|
|
16512
|
+
var SENSITIVE_VALUE_PATTERN = /(api[_-]?key|access[_-]?token|auth(?:orization)?|password|secret)(\s*[:=]\s*)([^\s,;]+)/giu;
|
|
16513
|
+
var BEARER_PATTERN = /\bBearer\s+[A-Za-z0-9._~+/=-]+/giu;
|
|
16514
|
+
function sanitizeDiagnosticTail(value) {
|
|
16515
|
+
const redacted = value.replace(BEARER_PATTERN, "Bearer [redacted]").replace(SENSITIVE_VALUE_PATTERN, "$1$2[redacted]");
|
|
16516
|
+
return redacted.length <= DIAGNOSTIC_TAIL_MAX_LENGTH ? redacted : redacted.slice(-DIAGNOSTIC_TAIL_MAX_LENGTH);
|
|
16373
16517
|
}
|
|
16374
|
-
|
|
16375
|
-
|
|
16518
|
+
|
|
16519
|
+
// ../../harness-adapter/dist/usage.js
|
|
16520
|
+
var tokenFields = [
|
|
16521
|
+
"inputTokens",
|
|
16522
|
+
"cachedInputTokens",
|
|
16523
|
+
"cacheWriteInputTokens",
|
|
16524
|
+
"outputTokens",
|
|
16525
|
+
"outputTokensPerSecond",
|
|
16526
|
+
"reasoningOutputTokens",
|
|
16527
|
+
"totalTokens",
|
|
16528
|
+
"contextWindowTokens",
|
|
16529
|
+
"contextUsedTokens"
|
|
16530
|
+
];
|
|
16531
|
+
var safeIntegerFields = [
|
|
16532
|
+
"planFiveHourResetsAtUnix",
|
|
16533
|
+
"planSevenDayResetsAtUnix"
|
|
16534
|
+
];
|
|
16535
|
+
var percentFields = [
|
|
16536
|
+
"cacheHitRatePercent",
|
|
16537
|
+
"planFiveHourUsedPercent",
|
|
16538
|
+
"planSevenDayUsedPercent"
|
|
16539
|
+
];
|
|
16540
|
+
var usageFields = /* @__PURE__ */ new Set([
|
|
16541
|
+
...tokenFields,
|
|
16542
|
+
...safeIntegerFields,
|
|
16543
|
+
...percentFields,
|
|
16544
|
+
"totalCostUsd",
|
|
16545
|
+
"totalCredits",
|
|
16546
|
+
"contextUsagePercent"
|
|
16547
|
+
]);
|
|
16548
|
+
function isRecord3(value) {
|
|
16549
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16376
16550
|
}
|
|
16377
|
-
function
|
|
16378
|
-
|
|
16379
|
-
|
|
16380
|
-
|
|
16381
|
-
|
|
16382
|
-
|
|
16383
|
-
|
|
16384
|
-
|
|
16385
|
-
|
|
16386
|
-
continue;
|
|
16551
|
+
function parseHostUsage(value) {
|
|
16552
|
+
if (!isRecord3(value))
|
|
16553
|
+
throw new Error("Harness Usage must be an object");
|
|
16554
|
+
const keys = Object.keys(value);
|
|
16555
|
+
if (keys.length === 0)
|
|
16556
|
+
throw new Error("Harness Usage must contain a reliable field");
|
|
16557
|
+
for (const key of keys) {
|
|
16558
|
+
if (!usageFields.has(key)) {
|
|
16559
|
+
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
16387
16560
|
}
|
|
16388
|
-
|
|
16389
|
-
|
|
16390
|
-
|
|
16391
|
-
|
|
16561
|
+
}
|
|
16562
|
+
for (const field of ["totalCredits", "contextUsagePercent"]) {
|
|
16563
|
+
const candidate = value[field];
|
|
16564
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
16565
|
+
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
16392
16566
|
}
|
|
16393
|
-
|
|
16394
|
-
|
|
16395
|
-
|
|
16396
|
-
|
|
16397
|
-
|
|
16398
|
-
const userText = textContent(message(user)?.content);
|
|
16399
|
-
const nativeTurnRef = nativeTurnRefSchema.parse({
|
|
16400
|
-
harnessId: piHarnessId,
|
|
16401
|
-
nativeSessionId: state.sessionId,
|
|
16402
|
-
nativeTurnKey: user.id,
|
|
16403
|
-
formatVersion: 1
|
|
16404
|
-
});
|
|
16405
|
-
const checkpoint = nativeCheckpointRefSchema.parse({
|
|
16406
|
-
harnessId: piHarnessId,
|
|
16407
|
-
nativeSessionId: state.sessionId,
|
|
16408
|
-
checkpointId: user.id,
|
|
16409
|
-
formatVersion: 1
|
|
16410
|
-
});
|
|
16411
|
-
turns.push({
|
|
16412
|
-
nativeTurnRef,
|
|
16413
|
-
checkpoint,
|
|
16414
|
-
input: [{ type: "text", text: userText }],
|
|
16415
|
-
items: snapshotItems(entries, outcome),
|
|
16416
|
-
outcome,
|
|
16417
|
-
...effectiveModel ? { model: encodePiModelRef(effectiveModel) } : {}
|
|
16418
|
-
});
|
|
16419
|
-
for (const entry of entries) {
|
|
16420
|
-
const changed = modelChange(entry);
|
|
16421
|
-
if (changed)
|
|
16422
|
-
effectiveModel = changed;
|
|
16567
|
+
}
|
|
16568
|
+
for (const field of tokenFields) {
|
|
16569
|
+
const candidate = value[field];
|
|
16570
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16571
|
+
throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
|
|
16423
16572
|
}
|
|
16424
|
-
index = end;
|
|
16425
16573
|
}
|
|
16426
|
-
|
|
16427
|
-
|
|
16428
|
-
|
|
16429
|
-
|
|
16430
|
-
|
|
16431
|
-
|
|
16432
|
-
|
|
16433
|
-
|
|
16434
|
-
|
|
16435
|
-
|
|
16436
|
-
|
|
16437
|
-
|
|
16438
|
-
|
|
16439
|
-
|
|
16440
|
-
|
|
16441
|
-
|
|
16442
|
-
|
|
16574
|
+
for (const field of safeIntegerFields) {
|
|
16575
|
+
const candidate = value[field];
|
|
16576
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16577
|
+
throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
|
|
16578
|
+
}
|
|
16579
|
+
}
|
|
16580
|
+
if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
|
|
16581
|
+
throw new Error("Harness Usage 'outputTokensPerSecond' must be a finite non-negative number");
|
|
16582
|
+
}
|
|
16583
|
+
if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
|
|
16584
|
+
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
16585
|
+
}
|
|
16586
|
+
for (const field of ["totalCredits", "contextUsagePercent"]) {
|
|
16587
|
+
const candidate = value[field];
|
|
16588
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
16589
|
+
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
16590
|
+
}
|
|
16591
|
+
}
|
|
16592
|
+
for (const field of percentFields) {
|
|
16593
|
+
const candidate = value[field];
|
|
16594
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
|
|
16595
|
+
throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
|
|
16596
|
+
}
|
|
16597
|
+
}
|
|
16598
|
+
const hasContextUsed = value.contextUsedTokens !== void 0;
|
|
16599
|
+
const hasContextWindow = value.contextWindowTokens !== void 0;
|
|
16600
|
+
if (hasContextUsed !== hasContextWindow) {
|
|
16601
|
+
throw new Error("Harness Usage context fields must be provided together");
|
|
16602
|
+
}
|
|
16603
|
+
if (hasContextWindow && value.contextWindowTokens === 0) {
|
|
16604
|
+
throw new Error("Harness Usage 'contextWindowTokens' must be greater than zero");
|
|
16605
|
+
}
|
|
16606
|
+
if (value.planFiveHourResetsAtUnix !== void 0 && value.planFiveHourUsedPercent === void 0) {
|
|
16607
|
+
throw new Error("Harness Usage 'planFiveHourResetsAtUnix' must be provided with 'planFiveHourUsedPercent'");
|
|
16608
|
+
}
|
|
16609
|
+
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
16610
|
+
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
16611
|
+
}
|
|
16612
|
+
return { ...value };
|
|
16443
16613
|
}
|
|
16444
16614
|
|
|
16445
16615
|
// dist/pi-last-turn-rollback.js
|
|
@@ -16490,16 +16660,23 @@ async function rollbackPiLastTurn(transport, sourceSessionId, cwd) {
|
|
|
16490
16660
|
if (snapshot.turns.length !== boundary.sourceTurnCount - 1 || actualTurnKeys.some((key, index) => key !== expectedTurnKeys[index])) {
|
|
16491
16661
|
throw new Error("Pi last-Turn rollback did not produce the exact retained history prefix");
|
|
16492
16662
|
}
|
|
16493
|
-
|
|
16494
|
-
|
|
16663
|
+
try {
|
|
16664
|
+
await transport.verifySessionCwd(cwd);
|
|
16665
|
+
return { ok: true, unpersisted: false };
|
|
16666
|
+
} catch (error51) {
|
|
16667
|
+
if (snapshot.turns.length === 0 && error51?.code === "ENOENT") {
|
|
16668
|
+
return { ok: true, unpersisted: true };
|
|
16669
|
+
}
|
|
16670
|
+
throw error51;
|
|
16671
|
+
}
|
|
16495
16672
|
}
|
|
16496
16673
|
|
|
16497
16674
|
// dist/pi-session-import.js
|
|
16498
|
-
import { createReadStream } from "node:fs";
|
|
16499
|
-
import { opendir, realpath, stat } from "node:fs/promises";
|
|
16675
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
16676
|
+
import { opendir, realpath as realpath2, stat } from "node:fs/promises";
|
|
16500
16677
|
import os from "node:os";
|
|
16501
|
-
import
|
|
16502
|
-
import { createInterface } from "node:readline";
|
|
16678
|
+
import path2 from "node:path";
|
|
16679
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
16503
16680
|
var PiSessionChangedError = class extends Error {
|
|
16504
16681
|
constructor() {
|
|
16505
16682
|
super("Pi Session changed during discovery; refresh and retry");
|
|
@@ -16508,14 +16685,14 @@ var PiSessionChangedError = class extends Error {
|
|
|
16508
16685
|
function sameFile(left, right) {
|
|
16509
16686
|
return left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs && left.ino === right.ino && left.dev === right.dev;
|
|
16510
16687
|
}
|
|
16511
|
-
function
|
|
16688
|
+
function isRecord4(value) {
|
|
16512
16689
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16513
16690
|
}
|
|
16514
16691
|
function missing(error51) {
|
|
16515
|
-
return
|
|
16692
|
+
return isRecord4(error51) && error51.code === "ENOENT";
|
|
16516
16693
|
}
|
|
16517
16694
|
function expandDirectory(value, home) {
|
|
16518
|
-
return
|
|
16695
|
+
return path2.resolve(value === "~" ? home : value.startsWith(`~${path2.sep}`) || value.startsWith("~/") ? path2.join(home, value.slice(2)) : value);
|
|
16519
16696
|
}
|
|
16520
16697
|
function piSessionImportDirectory(environment) {
|
|
16521
16698
|
const home = (process.platform === "win32" ? environment.USERPROFILE : environment.HOME) || os.homedir();
|
|
@@ -16524,7 +16701,7 @@ function piSessionImportDirectory(environment) {
|
|
|
16524
16701
|
return { directory: expandDirectory(custom2, home), flat: true };
|
|
16525
16702
|
const agent = environment.PI_CODING_AGENT_DIR;
|
|
16526
16703
|
return {
|
|
16527
|
-
directory:
|
|
16704
|
+
directory: path2.join(agent ? expandDirectory(agent, home) : path2.join(home, ".pi", "agent"), "sessions"),
|
|
16528
16705
|
flat: false
|
|
16529
16706
|
};
|
|
16530
16707
|
}
|
|
@@ -16542,9 +16719,9 @@ async function sessionFiles(directory, flat, signal) {
|
|
|
16542
16719
|
for await (const entry of entries) {
|
|
16543
16720
|
signal.throwIfAborted();
|
|
16544
16721
|
if (projectLevel && entry.isDirectory())
|
|
16545
|
-
await visit(
|
|
16722
|
+
await visit(path2.join(dir, entry.name), false);
|
|
16546
16723
|
else if (!projectLevel && entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
16547
|
-
files.push(
|
|
16724
|
+
files.push(path2.join(dir, entry.name));
|
|
16548
16725
|
}
|
|
16549
16726
|
}
|
|
16550
16727
|
};
|
|
@@ -16555,8 +16732,8 @@ async function readCandidate(file2, signal) {
|
|
|
16555
16732
|
const before = await stat(file2);
|
|
16556
16733
|
if (!before.isFile() || before.size === 0)
|
|
16557
16734
|
return null;
|
|
16558
|
-
const stream =
|
|
16559
|
-
const lines =
|
|
16735
|
+
const stream = createReadStream2(file2, { encoding: "utf8", signal, end: before.size - 1 });
|
|
16736
|
+
const lines = createInterface2({ input: stream, crlfDelay: Infinity });
|
|
16560
16737
|
let header;
|
|
16561
16738
|
let name = null;
|
|
16562
16739
|
let firstMessage = null;
|
|
@@ -16574,20 +16751,20 @@ async function readCandidate(file2, signal) {
|
|
|
16574
16751
|
} catch {
|
|
16575
16752
|
return null;
|
|
16576
16753
|
}
|
|
16577
|
-
if (!
|
|
16754
|
+
if (!isRecord4(entry))
|
|
16578
16755
|
return null;
|
|
16579
16756
|
if (!header) {
|
|
16580
|
-
if (entry.type !== "session" || entry.version !== 3 || typeof entry.id !== "string" || typeof entry.cwd !== "string" || !
|
|
16757
|
+
if (entry.type !== "session" || entry.version !== 3 || typeof entry.id !== "string" || typeof entry.cwd !== "string" || !path2.isAbsolute(entry.cwd))
|
|
16581
16758
|
return null;
|
|
16582
16759
|
header = entry;
|
|
16583
16760
|
continue;
|
|
16584
16761
|
}
|
|
16585
16762
|
if (typeof entry.id !== "string" || entry.id.length === 0 || entries.has(entry.id) || entry.parentId !== null && (typeof entry.parentId !== "string" || !entries.has(entry.parentId)))
|
|
16586
16763
|
return null;
|
|
16587
|
-
const message3 =
|
|
16764
|
+
const message3 = isRecord4(entry.message) ? entry.message : null;
|
|
16588
16765
|
if (!firstMessage && entry.type === "message" && message3?.role === "user") {
|
|
16589
16766
|
const content = message3.content;
|
|
16590
|
-
const text = typeof content === "string" ? content : Array.isArray(content) ? content.filter((block) =>
|
|
16767
|
+
const text = typeof content === "string" ? content : Array.isArray(content) ? content.filter((block) => isRecord4(block) && block.type === "text" && typeof block.text === "string").map((block) => block.text).join(" ") : "";
|
|
16591
16768
|
firstMessage = text.replaceAll("\0", "").trim().slice(0, HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) || null;
|
|
16592
16769
|
}
|
|
16593
16770
|
hasUser = entry.type === "message" && message3?.role === "user" || typeof entry.parentId === "string" && entries.get(entry.parentId) === true;
|
|
@@ -16611,13 +16788,13 @@ async function readCandidate(file2, signal) {
|
|
|
16611
16788
|
const after = await stat(file2);
|
|
16612
16789
|
if (!sameFile(before, after))
|
|
16613
16790
|
throw new PiSessionChangedError();
|
|
16614
|
-
const cwd = await
|
|
16791
|
+
const cwd = await realpath2(String(header.cwd));
|
|
16615
16792
|
if (!(await stat(cwd)).isDirectory())
|
|
16616
16793
|
return null;
|
|
16617
16794
|
const nativeRef = nativeSessionRefSchema.safeParse({
|
|
16618
16795
|
harnessId: "pi",
|
|
16619
16796
|
nativeSessionId: header.id,
|
|
16620
|
-
locator: { sessionFile: await
|
|
16797
|
+
locator: { sessionFile: await realpath2(file2) },
|
|
16621
16798
|
formatVersion: 1
|
|
16622
16799
|
});
|
|
16623
16800
|
const candidate = harnessSessionImportCandidateSchema.safeParse({
|
|
@@ -16630,8 +16807,8 @@ async function readCandidate(file2, signal) {
|
|
|
16630
16807
|
return candidate.success && nativeRef.success ? { candidate: candidate.data, nativeRef: nativeRef.data } : null;
|
|
16631
16808
|
}
|
|
16632
16809
|
async function readIdentity(file2, signal) {
|
|
16633
|
-
const stream =
|
|
16634
|
-
const lines =
|
|
16810
|
+
const stream = createReadStream2(file2, { encoding: "utf8", signal });
|
|
16811
|
+
const lines = createInterface2({ input: stream, crlfDelay: Infinity });
|
|
16635
16812
|
try {
|
|
16636
16813
|
for await (const line of lines) {
|
|
16637
16814
|
signal.throwIfAborted();
|
|
@@ -16643,7 +16820,7 @@ async function readIdentity(file2, signal) {
|
|
|
16643
16820
|
} catch {
|
|
16644
16821
|
return null;
|
|
16645
16822
|
}
|
|
16646
|
-
return
|
|
16823
|
+
return isRecord4(header) && header.type === "session" && header.version === 3 && typeof header.id === "string" ? header.id : null;
|
|
16647
16824
|
}
|
|
16648
16825
|
return null;
|
|
16649
16826
|
} finally {
|
|
@@ -16727,14 +16904,14 @@ var PiSessionImportIndex = class {
|
|
|
16727
16904
|
|
|
16728
16905
|
// dist/pi-rpc-session.js
|
|
16729
16906
|
import { spawn, spawnSync } from "node:child_process";
|
|
16730
|
-
import { randomUUID } from "node:crypto";
|
|
16731
|
-
import
|
|
16907
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
16908
|
+
import path5 from "node:path";
|
|
16732
16909
|
|
|
16733
16910
|
// ../../harness-discovery/dist/environment.js
|
|
16734
16911
|
import fs from "node:fs";
|
|
16735
|
-
import
|
|
16912
|
+
import path3 from "node:path";
|
|
16736
16913
|
function targetPath(platform) {
|
|
16737
|
-
return platform === "win32" ?
|
|
16914
|
+
return platform === "win32" ? path3.win32 : path3.posix;
|
|
16738
16915
|
}
|
|
16739
16916
|
function environmentValue(environment, name) {
|
|
16740
16917
|
const lowered = name.toLowerCase();
|
|
@@ -16777,11 +16954,11 @@ function newestFirst(names) {
|
|
|
16777
16954
|
}
|
|
16778
16955
|
|
|
16779
16956
|
// ../../harness-discovery/dist/node-runtime.js
|
|
16780
|
-
import
|
|
16957
|
+
import path4 from "node:path";
|
|
16781
16958
|
function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
|
|
16782
16959
|
const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
|
|
16783
16960
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
16784
|
-
const runtimeDirectory =
|
|
16961
|
+
const runtimeDirectory = path4.dirname(runtimeExecutable);
|
|
16785
16962
|
const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
|
|
16786
16963
|
const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
|
|
16787
16964
|
if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
|
|
@@ -16980,14 +17157,14 @@ function resolvePiExecutable(input, dependencies = {}) {
|
|
|
16980
17157
|
}
|
|
16981
17158
|
|
|
16982
17159
|
// dist/pi-usage.js
|
|
16983
|
-
function
|
|
17160
|
+
function isRecord5(value) {
|
|
16984
17161
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16985
17162
|
}
|
|
16986
17163
|
function nonNegativeSafeInteger(value) {
|
|
16987
17164
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
16988
17165
|
}
|
|
16989
17166
|
function optionalPiCacheHitRatePercent(value) {
|
|
16990
|
-
if (!
|
|
17167
|
+
if (!isRecord5(value) || value.role !== "assistant" || !isRecord5(value.usage))
|
|
16991
17168
|
return null;
|
|
16992
17169
|
const input = nonNegativeSafeInteger(value.usage.input);
|
|
16993
17170
|
const cacheRead = nonNegativeSafeInteger(value.usage.cacheRead);
|
|
@@ -17000,20 +17177,20 @@ function optionalPiCacheHitRatePercent(value) {
|
|
|
17000
17177
|
function latestPiCacheHitRatePercent(history) {
|
|
17001
17178
|
let latest = null;
|
|
17002
17179
|
for (const entry of activePiEntries(history)) {
|
|
17003
|
-
if (entry.type === "message" &&
|
|
17180
|
+
if (entry.type === "message" && isRecord5(entry.message) && entry.message.role === "assistant") {
|
|
17004
17181
|
latest = optionalPiCacheHitRatePercent(entry.message);
|
|
17005
17182
|
}
|
|
17006
17183
|
}
|
|
17007
17184
|
return latest;
|
|
17008
17185
|
}
|
|
17009
17186
|
function responseData(response, operation) {
|
|
17010
|
-
if (!
|
|
17187
|
+
if (!isRecord5(response.data)) {
|
|
17011
17188
|
throw new Error(`Pi RPC ${operation} response has no data`);
|
|
17012
17189
|
}
|
|
17013
17190
|
return response.data;
|
|
17014
17191
|
}
|
|
17015
17192
|
function contextUsage(value) {
|
|
17016
|
-
if (!
|
|
17193
|
+
if (!isRecord5(value))
|
|
17017
17194
|
throw new Error("Pi RPC context Usage is invalid");
|
|
17018
17195
|
return parseHostUsage({
|
|
17019
17196
|
contextUsedTokens: value.tokens,
|
|
@@ -17023,15 +17200,15 @@ function contextUsage(value) {
|
|
|
17023
17200
|
function parsePiSessionUsage(response) {
|
|
17024
17201
|
const data = responseData(response, "Session stats");
|
|
17025
17202
|
const tokens = data.tokens;
|
|
17026
|
-
if (tokens !== void 0 && !
|
|
17203
|
+
if (tokens !== void 0 && !isRecord5(tokens)) {
|
|
17027
17204
|
throw new Error("Pi RPC Session stats tokens are invalid");
|
|
17028
17205
|
}
|
|
17029
17206
|
return parseHostUsage({
|
|
17030
|
-
...
|
|
17031
|
-
...
|
|
17032
|
-
...
|
|
17033
|
-
...
|
|
17034
|
-
...
|
|
17207
|
+
...isRecord5(tokens) && tokens.input !== void 0 ? { inputTokens: tokens.input } : {},
|
|
17208
|
+
...isRecord5(tokens) && tokens.cacheRead !== void 0 ? { cachedInputTokens: tokens.cacheRead } : {},
|
|
17209
|
+
...isRecord5(tokens) && tokens.cacheWrite !== void 0 ? { cacheWriteInputTokens: tokens.cacheWrite } : {},
|
|
17210
|
+
...isRecord5(tokens) && tokens.output !== void 0 ? { outputTokens: tokens.output } : {},
|
|
17211
|
+
...isRecord5(tokens) && tokens.total !== void 0 ? { totalTokens: tokens.total } : {},
|
|
17035
17212
|
...data.cost !== void 0 ? { totalCostUsd: data.cost } : {},
|
|
17036
17213
|
...data.contextUsage !== void 0 ? contextUsage(data.contextUsage) : {}
|
|
17037
17214
|
});
|
|
@@ -17050,54 +17227,6 @@ function optionalPiStateContextUsage(value) {
|
|
|
17050
17227
|
}
|
|
17051
17228
|
}
|
|
17052
17229
|
|
|
17053
|
-
// dist/pi-session-file.js
|
|
17054
|
-
import { open, realpath as realpath2 } from "node:fs/promises";
|
|
17055
|
-
var MAX_SESSION_HEADER_BYTES = 64 * 1024;
|
|
17056
|
-
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
17057
|
-
function isRecord5(value) {
|
|
17058
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17059
|
-
}
|
|
17060
|
-
async function readPiSessionHeader(sessionFile) {
|
|
17061
|
-
const handle = await open(sessionFile, "r");
|
|
17062
|
-
try {
|
|
17063
|
-
const buffer = Buffer.allocUnsafe(MAX_SESSION_HEADER_BYTES);
|
|
17064
|
-
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
17065
|
-
const contents = buffer.subarray(0, bytesRead);
|
|
17066
|
-
const newline = contents.indexOf(10);
|
|
17067
|
-
if (newline < 0 && bytesRead === buffer.length) {
|
|
17068
|
-
throw new Error("Pi Session header exceeds the supported size");
|
|
17069
|
-
}
|
|
17070
|
-
const headerText = utf8Decoder.decode(newline < 0 ? contents : contents.subarray(0, newline));
|
|
17071
|
-
let parsed;
|
|
17072
|
-
try {
|
|
17073
|
-
parsed = JSON.parse(headerText);
|
|
17074
|
-
} catch {
|
|
17075
|
-
throw new Error("Pi Session header is not valid JSON");
|
|
17076
|
-
}
|
|
17077
|
-
if (!isRecord5(parsed) || parsed.type !== "session" || typeof parsed.id !== "string" || parsed.id.length === 0 || typeof parsed.cwd !== "string" || parsed.cwd.length === 0) {
|
|
17078
|
-
throw new Error("Pi Session header is invalid");
|
|
17079
|
-
}
|
|
17080
|
-
return { type: "session", id: parsed.id, cwd: parsed.cwd };
|
|
17081
|
-
} finally {
|
|
17082
|
-
await handle.close();
|
|
17083
|
-
}
|
|
17084
|
-
}
|
|
17085
|
-
async function verifyPiSessionCwd(input) {
|
|
17086
|
-
if (!input.sessionFile)
|
|
17087
|
-
throw new Error("Pi Fork Session has no persisted Session file");
|
|
17088
|
-
const header = await readPiSessionHeader(input.sessionFile);
|
|
17089
|
-
if (header.id !== input.sessionId) {
|
|
17090
|
-
throw new Error("Pi Fork Session header identity does not match RPC state");
|
|
17091
|
-
}
|
|
17092
|
-
const [actualCwd, expectedCwd] = await Promise.all([
|
|
17093
|
-
realpath2(header.cwd),
|
|
17094
|
-
realpath2(input.expectedCwd)
|
|
17095
|
-
]);
|
|
17096
|
-
if (actualCwd !== expectedCwd) {
|
|
17097
|
-
throw new Error("Pi Fork Session did not bind the requested cwd");
|
|
17098
|
-
}
|
|
17099
|
-
}
|
|
17100
|
-
|
|
17101
17230
|
// dist/pi-rpc-session.js
|
|
17102
17231
|
var PiRpcFaultError = class extends Error {
|
|
17103
17232
|
kind;
|
|
@@ -17279,6 +17408,9 @@ function piRpcProcessCommand(options, dependencies = {}) {
|
|
|
17279
17408
|
if (options.model && (options.sessionFile || options.forkSessionFile)) {
|
|
17280
17409
|
throw new Error("Pi RPC cannot combine a startup Model with Session restore or Fork");
|
|
17281
17410
|
}
|
|
17411
|
+
if (options.emptySessionConfiguration && (!options.sessionFile || options.model || options.forkSessionFile)) {
|
|
17412
|
+
throw new Error("Pi empty Session configuration requires an exclusive Session resume");
|
|
17413
|
+
}
|
|
17282
17414
|
const platform = dependencies.platform ?? process.platform;
|
|
17283
17415
|
const command = resolvePiExecutable({
|
|
17284
17416
|
...options.command ? { command: options.command } : {},
|
|
@@ -17289,9 +17421,17 @@ function piRpcProcessCommand(options, dependencies = {}) {
|
|
|
17289
17421
|
...dependencies.isExecutable ? { isExecutable: dependencies.isExecutable } : {}
|
|
17290
17422
|
});
|
|
17291
17423
|
const sessionArguments = options.forkSessionFile ? ["--fork", options.forkSessionFile] : options.sessionFile ? ["--session", options.sessionFile] : [];
|
|
17292
|
-
const
|
|
17293
|
-
const
|
|
17294
|
-
const
|
|
17424
|
+
const startupModel = options.emptySessionConfiguration?.model ?? options.model;
|
|
17425
|
+
const modelArguments = startupModel ? ["--provider", startupModel.provider, "--model", startupModel.id] : [];
|
|
17426
|
+
const thinkingArguments = options.emptySessionConfiguration ? ["--thinking", options.emptySessionConfiguration.thinkingLevel] : [];
|
|
17427
|
+
const arguments_ = [
|
|
17428
|
+
"--mode",
|
|
17429
|
+
"rpc",
|
|
17430
|
+
...modelArguments,
|
|
17431
|
+
...thinkingArguments,
|
|
17432
|
+
...sessionArguments
|
|
17433
|
+
];
|
|
17434
|
+
const extension = path5.win32.extname(command).toLowerCase();
|
|
17295
17435
|
if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
|
|
17296
17436
|
return { command, arguments: arguments_, windowsVerbatimArguments: false };
|
|
17297
17437
|
}
|
|
@@ -17324,6 +17464,7 @@ var PiRpcSession = class {
|
|
|
17324
17464
|
#buffer = Buffer.alloc(0);
|
|
17325
17465
|
#child = null;
|
|
17326
17466
|
#closed = false;
|
|
17467
|
+
#closePromise = null;
|
|
17327
17468
|
#compactionActive = false;
|
|
17328
17469
|
#compactionTurn = null;
|
|
17329
17470
|
#compactionTimeout = null;
|
|
@@ -17374,7 +17515,8 @@ var PiRpcSession = class {
|
|
|
17374
17515
|
}),
|
|
17375
17516
|
...this.#options.sessionFile ? { sessionFile: this.#options.sessionFile } : {},
|
|
17376
17517
|
...this.#options.forkSessionFile ? { forkSessionFile: this.#options.forkSessionFile } : {},
|
|
17377
|
-
...this.#options.model ? { model: this.#options.model } : {}
|
|
17518
|
+
...this.#options.model ? { model: this.#options.model } : {},
|
|
17519
|
+
...this.#options.emptySessionConfiguration ? { emptySessionConfiguration: this.#options.emptySessionConfiguration } : {}
|
|
17378
17520
|
});
|
|
17379
17521
|
this.#child = child;
|
|
17380
17522
|
child.stdout.on("data", (chunk) => this.#push(chunk));
|
|
@@ -17631,12 +17773,13 @@ var PiRpcSession = class {
|
|
|
17631
17773
|
this.#fail(fault);
|
|
17632
17774
|
void this.close().catch(() => void 0);
|
|
17633
17775
|
}
|
|
17634
|
-
|
|
17635
|
-
if (this.#closed)
|
|
17636
|
-
|
|
17637
|
-
|
|
17638
|
-
|
|
17639
|
-
|
|
17776
|
+
close() {
|
|
17777
|
+
if (!this.#closed) {
|
|
17778
|
+
this.#closed = true;
|
|
17779
|
+
this.#rejectAll(new Error("Pi RPC Session closed"));
|
|
17780
|
+
}
|
|
17781
|
+
this.#closePromise ??= this.#stopProcess();
|
|
17782
|
+
return this.#closePromise;
|
|
17640
17783
|
}
|
|
17641
17784
|
async #stopProcess() {
|
|
17642
17785
|
const child = this.#child;
|
|
@@ -17800,7 +17943,7 @@ var PiRpcSession = class {
|
|
|
17800
17943
|
const active = {
|
|
17801
17944
|
origin: "autonomous",
|
|
17802
17945
|
autonomousEvents: events,
|
|
17803
|
-
nativeTurnKey: assistantMessageId(value) ??
|
|
17946
|
+
nativeTurnKey: assistantMessageId(value) ?? randomUUID2(),
|
|
17804
17947
|
nativeCancellationObserved: false,
|
|
17805
17948
|
text: "",
|
|
17806
17949
|
assistantMessageId: null,
|
|
@@ -18063,7 +18206,7 @@ var PiRpcSession = class {
|
|
|
18063
18206
|
if (active.assistantMessageId !== null && active.reasoningMessageOpen) {
|
|
18064
18207
|
active.onEvent({ type: "reasoning.completed", messageId: active.assistantMessageId });
|
|
18065
18208
|
}
|
|
18066
|
-
const messageId = assistantMessageId(value) ??
|
|
18209
|
+
const messageId = assistantMessageId(value) ?? randomUUID2();
|
|
18067
18210
|
active.assistantMessageId = messageId;
|
|
18068
18211
|
active.sawStreamedMessageText = false;
|
|
18069
18212
|
active.sawStreamedMessageReasoning = false;
|
|
@@ -18124,7 +18267,7 @@ var PiRpcSession = class {
|
|
|
18124
18267
|
if (!child?.stdin.writable || this.#closed || this.#failed) {
|
|
18125
18268
|
return Promise.reject(new Error("Pi RPC stdin is unavailable"));
|
|
18126
18269
|
}
|
|
18127
|
-
const id = `codexhost-${
|
|
18270
|
+
const id = `codexhost-${randomUUID2()}`;
|
|
18128
18271
|
return new Promise((resolve, reject) => {
|
|
18129
18272
|
const pending = {
|
|
18130
18273
|
command: type,
|
|
@@ -18176,7 +18319,7 @@ var PiRpcSession = class {
|
|
|
18176
18319
|
}
|
|
18177
18320
|
let finalFault = fault;
|
|
18178
18321
|
try {
|
|
18179
|
-
await this
|
|
18322
|
+
await this.close();
|
|
18180
18323
|
} catch (error51) {
|
|
18181
18324
|
finalFault = new PiRpcFaultError("processExited", `Pi RPC timed-out Prompt cleanup failed: ${message2(error51)}`);
|
|
18182
18325
|
}
|
|
@@ -18387,10 +18530,10 @@ function stripDiffPrefix(pathString) {
|
|
|
18387
18530
|
return pathString.startsWith("a/") || pathString.startsWith("b/") ? pathString.slice(2) : pathString;
|
|
18388
18531
|
}
|
|
18389
18532
|
function displayPath(nativePath, cwd) {
|
|
18390
|
-
const resolvedCwd =
|
|
18391
|
-
const resolvedPath =
|
|
18392
|
-
const relative =
|
|
18393
|
-
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
18533
|
+
const resolvedCwd = path6.resolve(cwd);
|
|
18534
|
+
const resolvedPath = path6.isAbsolute(nativePath) ? path6.resolve(nativePath) : path6.resolve(cwd, nativePath);
|
|
18535
|
+
const relative = path6.relative(resolvedCwd, resolvedPath);
|
|
18536
|
+
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path6.sep}`);
|
|
18394
18537
|
const selected = inside ? relative : resolvedPath;
|
|
18395
18538
|
const normalized = selected.replaceAll("\\", "/");
|
|
18396
18539
|
if (normalized.length === 0 || normalized === ".")
|
|
@@ -19206,7 +19349,7 @@ var PiHarnessSession = class {
|
|
|
19206
19349
|
}));
|
|
19207
19350
|
return;
|
|
19208
19351
|
}
|
|
19209
|
-
const turnId = hostTurnIdSchema.parse(
|
|
19352
|
+
const turnId = hostTurnIdSchema.parse(randomUUID3());
|
|
19210
19353
|
let resolveCompletion = () => void 0;
|
|
19211
19354
|
const completion = new Promise((resolve) => {
|
|
19212
19355
|
resolveCompletion = resolve;
|
|
@@ -19368,7 +19511,7 @@ var PiHarnessSession = class {
|
|
|
19368
19511
|
if (active.interactionByNativeId.has(request.requestId)) {
|
|
19369
19512
|
throw new Error("Pi Interaction started more than once");
|
|
19370
19513
|
}
|
|
19371
|
-
const interactionId = hostInteractionIdSchema.parse(
|
|
19514
|
+
const interactionId = hostInteractionIdSchema.parse(randomUUID3());
|
|
19372
19515
|
const question = request.method === "select" ? {
|
|
19373
19516
|
id: "answer",
|
|
19374
19517
|
type: "choice",
|
|
@@ -19707,7 +19850,7 @@ var PiHarnessSession = class {
|
|
|
19707
19850
|
this.#channel.emit({ kind: "event", event });
|
|
19708
19851
|
}
|
|
19709
19852
|
#newItemId() {
|
|
19710
|
-
return hostItemIdSchema.parse(
|
|
19853
|
+
return hostItemIdSchema.parse(randomUUID3());
|
|
19711
19854
|
}
|
|
19712
19855
|
};
|
|
19713
19856
|
var PiAdapter = class {
|
|
@@ -19922,8 +20065,11 @@ var PiAdapter = class {
|
|
|
19922
20065
|
});
|
|
19923
20066
|
}
|
|
19924
20067
|
}
|
|
20068
|
+
const emptySessionConfiguration = input.kind === "resume" ? await readPiEmptySessionConfiguration(sourceSessionFile) : void 0;
|
|
19925
20069
|
transport = this.#createTransport({
|
|
19926
20070
|
cwd: input.cwd,
|
|
20071
|
+
...input.environment ? { environment: input.environment } : {},
|
|
20072
|
+
...emptySessionConfiguration ? { emptySessionConfiguration } : {},
|
|
19927
20073
|
...input.kind === "resume" ? { sessionFile: sourceSessionFile } : { forkSessionFile: sourceSessionFile },
|
|
19928
20074
|
onFault: (error51) => session?.handleTransportFault(error51)
|
|
19929
20075
|
});
|
|
@@ -19975,6 +20121,45 @@ var PiAdapter = class {
|
|
|
19975
20121
|
retryable: false
|
|
19976
20122
|
});
|
|
19977
20123
|
}
|
|
20124
|
+
if (rolledBack.unpersisted) {
|
|
20125
|
+
const state = transport.state;
|
|
20126
|
+
const history = await transport.getEntries();
|
|
20127
|
+
await transport.close();
|
|
20128
|
+
await persistEmptyPiSession({
|
|
20129
|
+
state,
|
|
20130
|
+
history,
|
|
20131
|
+
sourceSessionFile,
|
|
20132
|
+
sourceSessionId: sourceRef.nativeSessionId,
|
|
20133
|
+
cwd: input.cwd
|
|
20134
|
+
});
|
|
20135
|
+
if (!state.sessionFile)
|
|
20136
|
+
throw new Error("Pi empty fork has no Session file");
|
|
20137
|
+
const configuration = await readPiEmptySessionConfiguration(state.sessionFile);
|
|
20138
|
+
if (!configuration)
|
|
20139
|
+
throw new Error("Pi empty fork has no restorable configuration");
|
|
20140
|
+
transport = this.#createTransport({
|
|
20141
|
+
cwd: input.cwd,
|
|
20142
|
+
...input.environment ? { environment: input.environment } : {},
|
|
20143
|
+
sessionFile: state.sessionFile,
|
|
20144
|
+
emptySessionConfiguration: configuration,
|
|
20145
|
+
onFault: (error51) => session?.handleTransportFault(error51)
|
|
20146
|
+
});
|
|
20147
|
+
await transport.start();
|
|
20148
|
+
if (transport.state.sessionId !== state.sessionId) {
|
|
20149
|
+
throw new Error("Pi empty fork resumed with a different identity");
|
|
20150
|
+
}
|
|
20151
|
+
const model = nativeModelFromState(state);
|
|
20152
|
+
if (model && !samePiModel(nativeModelFromState(transport.state), model)) {
|
|
20153
|
+
await transport.selectModel(model);
|
|
20154
|
+
}
|
|
20155
|
+
if (state.thinkingLevel && transport.state.thinkingLevel !== state.thinkingLevel) {
|
|
20156
|
+
await transport.selectThinkingOption(state.thinkingLevel);
|
|
20157
|
+
}
|
|
20158
|
+
if (!samePiModel(nativeModelFromState(transport.state), model) || transport.state.thinkingLevel !== state.thinkingLevel) {
|
|
20159
|
+
throw new Error("Pi empty fork could not restore its configuration");
|
|
20160
|
+
}
|
|
20161
|
+
await transport.verifySessionCwd(input.cwd);
|
|
20162
|
+
}
|
|
19978
20163
|
}
|
|
19979
20164
|
const startedThinkingLevels = await transport.getAvailableThinkingLevels();
|
|
19980
20165
|
this.#thinkingSelectionSupported = startedThinkingLevels !== null;
|