@cortexkit/pi-magic-context 0.49.16 → 0.49.17
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/dist/auto-search-worker.js +76 -63
- package/dist/chunk-embedding-write-worker.js +10 -10
- package/dist/{compaction-marker-candidates-k4tqg4jb.js → compaction-marker-candidates-wjzqbspm.js} +2 -2
- package/dist/compaction-marker-candidates-worker.js +2 -2
- package/dist/embedding-backfill-vwag34t0.js +23 -0
- package/dist/embedding-worker-process.js +1 -1
- package/dist/embedding-worker.js +4 -4
- package/dist/historian-calibration-extension.js +4 -1
- package/dist/{index-g4jf772p.js → index-1kcfwk9c.js} +22 -2
- package/dist/{index-657xh9w4.js → index-2mmy81qt.js} +2 -2
- package/dist/{index-v8d4vgam.js → index-469ttgzv.js} +6 -6
- package/dist/index-4knyh1kt.js +1387 -0
- package/dist/{index-44h64qza.js → index-5k2mshvq.js} +9 -9
- package/dist/{index-fhyy4ave.js → index-8r2t8fv2.js} +842 -73
- package/dist/{index-xmzhrht0.js → index-9j809q6f.js} +29 -18
- package/dist/{index-6dz2ed1v.js → index-d8gc0112.js} +2 -2
- package/dist/{index-x3k1530z.js → index-dvbjsh98.js} +3 -3
- package/dist/{index-hy44m6jc.js → index-e1rza8gp.js} +1 -1
- package/dist/{index-dne4ja7a.js → index-ej4eak9d.js} +2 -2
- package/dist/{index-4178cbfw.js → index-es03azap.js} +121 -2038
- package/dist/{index-ajfpyk0x.js → index-fa485mqs.js} +59 -1
- package/dist/{index-y5c73caa.js → index-g7p75667.js} +32 -3
- package/dist/{index-tympym62.js → index-gdjv1nnd.js} +2 -2
- package/dist/{index-46q4e104.js → index-qpq6w67c.js} +1 -1
- package/dist/{index-asrxgdt4.js → index-rrwv9y2k.js} +8 -0
- package/dist/{index-mx59cve4.js → index-svgkv4g2.js} +1 -1
- package/dist/{index-qqxqwqhp.js → index-vktahpdj.js} +1 -1
- package/dist/{index-n3r2d2pr.js → index-vmcgew7x.js} +10 -7
- package/dist/{index-afy3dzf9.js → index-xnch62s6.js} +12 -6
- package/dist/{index-s1xn8qfw.js → index-yygsh681.js} +6 -3
- package/dist/{index-p3evwech.js → index-z2rkv0mb.js} +3 -3
- package/dist/{index-ja1c33qa.js → index-z7kbck29.js} +2 -2
- package/dist/index.js +523 -227
- package/dist/{message-fts-rowid-map-mbanfkt1.js → message-fts-rowid-map-cvpy2dmb.js} +5 -3
- package/dist/{message-index-easvmz22.js → message-index-2g23b7fe.js} +11 -11
- package/dist/{message-index-bounded-xzerjxmp.js → message-index-bounded-d6zj2tn5.js} +15 -15
- package/dist/{message-time-backfill-3q4kemfc.js → message-time-backfill-ssshbdy8.js} +1 -1
- package/dist/migration-worker.js +7 -7
- package/dist/{project-embedding-registry-xwnmqmx8.js → project-embedding-registry-vf1ncptn.js} +10 -10
- package/dist/raw-ordinal-warmup-worker.js +10 -10
- package/dist/{read-session-chunk-1sb5n7zs.js → read-session-chunk-2ky7mbqp.js} +5 -5
- package/dist/{read-session-raw-jz5e9jz0.js → read-session-raw-9s3xn7fc.js} +2 -2
- package/dist/{search-archive-3ma5n0wr.js → search-archive-9akqcr90.js} +6 -6
- package/dist/{search-x3fa0561.js → search-zjyc65g1.js} +17 -17
- package/dist/{sqlite-adjpy399.js → sqlite-fsp0sf3r.js} +1 -1
- package/dist/{storage-memory-axnsk5t1.js → storage-memory-yxxc5v4n.js} +2 -2
- package/dist/{storage-tags-jtessrec.js → storage-tags-cx6ccsv1.js} +3 -3
- package/dist/subagent-entry.js +22 -21
- package/dist/tag-snapshot-worker-pi.js +9 -9
- package/package.json +1 -1
- package/dist/embedding-backfill-c4bdw8pp.js +0 -23
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createScanner,
|
|
3
|
+
parse,
|
|
4
|
+
parseTree,
|
|
5
|
+
findNodeAtLocation,
|
|
6
|
+
getNodeValue,
|
|
7
|
+
printParseErrorCode,
|
|
8
|
+
modify,
|
|
9
|
+
applyEdits
|
|
10
|
+
} from "./index-4knyh1kt.js";
|
|
1
11
|
import {
|
|
2
12
|
getHarness2,
|
|
3
13
|
harnessOwnsOpenCodeStore2
|
|
@@ -55,7 +65,7 @@ import {
|
|
|
55
65
|
visitRawSessionMessages2,
|
|
56
66
|
readRawSessionMessageById2,
|
|
57
67
|
readSessionChunk2
|
|
58
|
-
} from "./index-
|
|
68
|
+
} from "./index-5k2mshvq.js";
|
|
59
69
|
import {
|
|
60
70
|
isRecord,
|
|
61
71
|
providerVisibleMessage,
|
|
@@ -69,28 +79,21 @@ import {
|
|
|
69
79
|
getTagNumberByMessageId2,
|
|
70
80
|
getTagsBySession2,
|
|
71
81
|
getTagById2
|
|
72
|
-
} from "./index-
|
|
82
|
+
} from "./index-ej4eak9d.js";
|
|
73
83
|
import {
|
|
74
84
|
estimateTokens
|
|
75
|
-
} from "./index-
|
|
85
|
+
} from "./index-1kcfwk9c.js";
|
|
76
86
|
import {
|
|
77
87
|
inRootAsyncContext2,
|
|
78
88
|
Database2,
|
|
79
89
|
withSqliteBackgroundWriter2,
|
|
80
90
|
withoutSqliteTransformPass2
|
|
81
|
-
} from "./index-
|
|
91
|
+
} from "./index-rrwv9y2k.js";
|
|
82
92
|
import {
|
|
83
93
|
stableStringify,
|
|
84
94
|
closeQuietly,
|
|
85
95
|
getTableColumnNames
|
|
86
96
|
} from "./index-jrap43gc.js";
|
|
87
|
-
import {
|
|
88
|
-
resolveOpenCodeDbPath,
|
|
89
|
-
assertOpenCodeStoreGeneration
|
|
90
|
-
} from "./index-8976mezv.js";
|
|
91
|
-
import {
|
|
92
|
-
noteRawSessionSummaryRowWritten2
|
|
93
|
-
} from "./index-qqxqwqhp.js";
|
|
94
97
|
import {
|
|
95
98
|
piHarnessKindFromExecutable,
|
|
96
99
|
isPidAlive
|
|
@@ -100,16 +103,25 @@ import {
|
|
|
100
103
|
clearLkgFenceProcessState,
|
|
101
104
|
commitLkgWithRecoveryFence,
|
|
102
105
|
clearLkgRecoveryFence,
|
|
106
|
+
gaDatabasePath,
|
|
107
|
+
V2StoreReader,
|
|
103
108
|
deleteSessionScopedRows,
|
|
104
109
|
getLastIndexedOrdinal2
|
|
105
|
-
} from "./index-
|
|
110
|
+
} from "./index-8r2t8fv2.js";
|
|
111
|
+
import {
|
|
112
|
+
resolveOpenCodeDbPath,
|
|
113
|
+
assertOpenCodeStoreGeneration
|
|
114
|
+
} from "./index-8976mezv.js";
|
|
115
|
+
import {
|
|
116
|
+
noteRawSessionSummaryRowWritten2
|
|
117
|
+
} from "./index-vktahpdj.js";
|
|
106
118
|
import {
|
|
107
119
|
SubcClient,
|
|
108
120
|
connectionFileExists,
|
|
109
121
|
SYNAPSE_DEFAULT_MODEL,
|
|
110
122
|
toSynapseLaneDescriptor,
|
|
111
123
|
SynapseEmbeddingProvider
|
|
112
|
-
} from "./index-
|
|
124
|
+
} from "./index-d8gc0112.js";
|
|
113
125
|
import {
|
|
114
126
|
invalidateAutoEmbedSession,
|
|
115
127
|
drainBackgroundBatches,
|
|
@@ -122,10 +134,10 @@ import {
|
|
|
122
134
|
unregisterProjectEmbedding2,
|
|
123
135
|
getProjectEmbeddingSnapshot2,
|
|
124
136
|
embedTextForProject2
|
|
125
|
-
} from "./index-
|
|
137
|
+
} from "./index-vmcgew7x.js";
|
|
126
138
|
import {
|
|
127
139
|
getErrorMessage
|
|
128
|
-
} from "./index-
|
|
140
|
+
} from "./index-469ttgzv.js";
|
|
129
141
|
import {
|
|
130
142
|
V2_MEMORY_CATEGORIES,
|
|
131
143
|
CATEGORY_PRIORITY,
|
|
@@ -139,13 +151,13 @@ import {
|
|
|
139
151
|
expandWorkspaceIdentitySetWithAliases,
|
|
140
152
|
resolveStoredPathWorkspaceIdentity,
|
|
141
153
|
storedPathBelongsToWorkspace
|
|
142
|
-
} from "./index-
|
|
154
|
+
} from "./index-gdjv1nnd.js";
|
|
143
155
|
import {
|
|
144
156
|
directoryHasGitMetadata,
|
|
145
157
|
resolveProjectIdentityForSession,
|
|
146
158
|
normalizeStoredProjectPath,
|
|
147
159
|
storedPathBelongsToIdentity
|
|
148
|
-
} from "./index-
|
|
160
|
+
} from "./index-g7p75667.js";
|
|
149
161
|
import {
|
|
150
162
|
getNoteByIdInScope,
|
|
151
163
|
getNotes,
|
|
@@ -161,7 +173,7 @@ import {
|
|
|
161
173
|
resolveMemoriesByIdsForSearch2,
|
|
162
174
|
unifiedSearch2,
|
|
163
175
|
formatSearchResults2
|
|
164
|
-
} from "./index-
|
|
176
|
+
} from "./index-9j809q6f.js";
|
|
165
177
|
import {
|
|
166
178
|
computeCueContentHash,
|
|
167
179
|
getMuralCueState,
|
|
@@ -177,7 +189,7 @@ import {
|
|
|
177
189
|
supersededMemory2,
|
|
178
190
|
mergeMemoryStats2,
|
|
179
191
|
archiveMemory2
|
|
180
|
-
} from "./index-
|
|
192
|
+
} from "./index-e1rza8gp.js";
|
|
181
193
|
import {
|
|
182
194
|
saveEmbedding,
|
|
183
195
|
invalidateMemory2
|
|
@@ -186,16 +198,13 @@ import {
|
|
|
186
198
|
isMarkerCandidateBasisCurrent2,
|
|
187
199
|
invalidateMarkerCandidateBasis2,
|
|
188
200
|
readMarkerCandidateBasis2
|
|
189
|
-
} from "./index-
|
|
201
|
+
} from "./index-qpq6w67c.js";
|
|
190
202
|
import {
|
|
191
203
|
renderSearchArchive2
|
|
192
|
-
} from "./index-
|
|
204
|
+
} from "./index-z7kbck29.js";
|
|
193
205
|
import {
|
|
194
206
|
computeNormalizedHash
|
|
195
207
|
} from "./index-9x1f96r8.js";
|
|
196
|
-
import {
|
|
197
|
-
sameProjectDirectory
|
|
198
|
-
} from "./index-wrr9rp9a.js";
|
|
199
208
|
import {
|
|
200
209
|
logSlowWriteTransaction
|
|
201
210
|
} from "./index-d4dt19md.js";
|
|
@@ -282,1394 +291,6 @@ function claimConfigParseFailuresOnce(surface, failures) {
|
|
|
282
291
|
|
|
283
292
|
// ../plugin/src/shared/jsonc-parser.ts
|
|
284
293
|
import { existsSync, readFileSync } from "node:fs";
|
|
285
|
-
|
|
286
|
-
// ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
287
|
-
function createScanner(text, ignoreTrivia = false) {
|
|
288
|
-
const len = text.length;
|
|
289
|
-
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
290
|
-
function scanHexDigits(count, exact) {
|
|
291
|
-
let digits = 0;
|
|
292
|
-
let value = 0;
|
|
293
|
-
while (digits < count || !exact) {
|
|
294
|
-
let ch = text.charCodeAt(pos);
|
|
295
|
-
if (ch >= 48 && ch <= 57) {
|
|
296
|
-
value = value * 16 + ch - 48;
|
|
297
|
-
} else if (ch >= 65 && ch <= 70) {
|
|
298
|
-
value = value * 16 + ch - 65 + 10;
|
|
299
|
-
} else if (ch >= 97 && ch <= 102) {
|
|
300
|
-
value = value * 16 + ch - 97 + 10;
|
|
301
|
-
} else {
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
pos++;
|
|
305
|
-
digits++;
|
|
306
|
-
}
|
|
307
|
-
if (digits < count) {
|
|
308
|
-
value = -1;
|
|
309
|
-
}
|
|
310
|
-
return value;
|
|
311
|
-
}
|
|
312
|
-
function setPosition(newPosition) {
|
|
313
|
-
pos = newPosition;
|
|
314
|
-
value = "";
|
|
315
|
-
tokenOffset = 0;
|
|
316
|
-
token = 16;
|
|
317
|
-
scanError = 0;
|
|
318
|
-
}
|
|
319
|
-
function scanNumber() {
|
|
320
|
-
let start = pos;
|
|
321
|
-
if (text.charCodeAt(pos) === 48) {
|
|
322
|
-
pos++;
|
|
323
|
-
} else {
|
|
324
|
-
pos++;
|
|
325
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
326
|
-
pos++;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
330
|
-
pos++;
|
|
331
|
-
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
332
|
-
pos++;
|
|
333
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
334
|
-
pos++;
|
|
335
|
-
}
|
|
336
|
-
} else {
|
|
337
|
-
scanError = 3;
|
|
338
|
-
return text.substring(start, pos);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
let end = pos;
|
|
342
|
-
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
343
|
-
pos++;
|
|
344
|
-
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
345
|
-
pos++;
|
|
346
|
-
}
|
|
347
|
-
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
348
|
-
pos++;
|
|
349
|
-
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
350
|
-
pos++;
|
|
351
|
-
}
|
|
352
|
-
end = pos;
|
|
353
|
-
} else {
|
|
354
|
-
scanError = 3;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return text.substring(start, end);
|
|
358
|
-
}
|
|
359
|
-
function scanString() {
|
|
360
|
-
let result = "", start = pos;
|
|
361
|
-
while (true) {
|
|
362
|
-
if (pos >= len) {
|
|
363
|
-
result += text.substring(start, pos);
|
|
364
|
-
scanError = 2;
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
const ch = text.charCodeAt(pos);
|
|
368
|
-
if (ch === 34) {
|
|
369
|
-
result += text.substring(start, pos);
|
|
370
|
-
pos++;
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
if (ch === 92) {
|
|
374
|
-
result += text.substring(start, pos);
|
|
375
|
-
pos++;
|
|
376
|
-
if (pos >= len) {
|
|
377
|
-
scanError = 2;
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
const ch2 = text.charCodeAt(pos++);
|
|
381
|
-
switch (ch2) {
|
|
382
|
-
case 34:
|
|
383
|
-
result += '"';
|
|
384
|
-
break;
|
|
385
|
-
case 92:
|
|
386
|
-
result += "\\";
|
|
387
|
-
break;
|
|
388
|
-
case 47:
|
|
389
|
-
result += "/";
|
|
390
|
-
break;
|
|
391
|
-
case 98:
|
|
392
|
-
result += "\b";
|
|
393
|
-
break;
|
|
394
|
-
case 102:
|
|
395
|
-
result += "\f";
|
|
396
|
-
break;
|
|
397
|
-
case 110:
|
|
398
|
-
result += `
|
|
399
|
-
`;
|
|
400
|
-
break;
|
|
401
|
-
case 114:
|
|
402
|
-
result += "\r";
|
|
403
|
-
break;
|
|
404
|
-
case 116:
|
|
405
|
-
result += "\t";
|
|
406
|
-
break;
|
|
407
|
-
case 117:
|
|
408
|
-
const ch3 = scanHexDigits(4, true);
|
|
409
|
-
if (ch3 >= 0) {
|
|
410
|
-
result += String.fromCharCode(ch3);
|
|
411
|
-
} else {
|
|
412
|
-
scanError = 4;
|
|
413
|
-
}
|
|
414
|
-
break;
|
|
415
|
-
default:
|
|
416
|
-
scanError = 5;
|
|
417
|
-
}
|
|
418
|
-
start = pos;
|
|
419
|
-
continue;
|
|
420
|
-
}
|
|
421
|
-
if (ch >= 0 && ch <= 31) {
|
|
422
|
-
if (isLineBreak(ch)) {
|
|
423
|
-
result += text.substring(start, pos);
|
|
424
|
-
scanError = 2;
|
|
425
|
-
break;
|
|
426
|
-
} else {
|
|
427
|
-
scanError = 6;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
pos++;
|
|
431
|
-
}
|
|
432
|
-
return result;
|
|
433
|
-
}
|
|
434
|
-
function scanNext() {
|
|
435
|
-
value = "";
|
|
436
|
-
scanError = 0;
|
|
437
|
-
tokenOffset = pos;
|
|
438
|
-
lineStartOffset = lineNumber;
|
|
439
|
-
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
440
|
-
if (pos >= len) {
|
|
441
|
-
tokenOffset = len;
|
|
442
|
-
return token = 17;
|
|
443
|
-
}
|
|
444
|
-
let code = text.charCodeAt(pos);
|
|
445
|
-
if (isWhiteSpace(code)) {
|
|
446
|
-
do {
|
|
447
|
-
pos++;
|
|
448
|
-
value += String.fromCharCode(code);
|
|
449
|
-
code = text.charCodeAt(pos);
|
|
450
|
-
} while (isWhiteSpace(code));
|
|
451
|
-
return token = 15;
|
|
452
|
-
}
|
|
453
|
-
if (isLineBreak(code)) {
|
|
454
|
-
pos++;
|
|
455
|
-
value += String.fromCharCode(code);
|
|
456
|
-
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
457
|
-
pos++;
|
|
458
|
-
value += `
|
|
459
|
-
`;
|
|
460
|
-
}
|
|
461
|
-
lineNumber++;
|
|
462
|
-
tokenLineStartOffset = pos;
|
|
463
|
-
return token = 14;
|
|
464
|
-
}
|
|
465
|
-
switch (code) {
|
|
466
|
-
case 123:
|
|
467
|
-
pos++;
|
|
468
|
-
return token = 1;
|
|
469
|
-
case 125:
|
|
470
|
-
pos++;
|
|
471
|
-
return token = 2;
|
|
472
|
-
case 91:
|
|
473
|
-
pos++;
|
|
474
|
-
return token = 3;
|
|
475
|
-
case 93:
|
|
476
|
-
pos++;
|
|
477
|
-
return token = 4;
|
|
478
|
-
case 58:
|
|
479
|
-
pos++;
|
|
480
|
-
return token = 6;
|
|
481
|
-
case 44:
|
|
482
|
-
pos++;
|
|
483
|
-
return token = 5;
|
|
484
|
-
case 34:
|
|
485
|
-
pos++;
|
|
486
|
-
value = scanString();
|
|
487
|
-
return token = 10;
|
|
488
|
-
case 47:
|
|
489
|
-
const start = pos - 1;
|
|
490
|
-
if (text.charCodeAt(pos + 1) === 47) {
|
|
491
|
-
pos += 2;
|
|
492
|
-
while (pos < len) {
|
|
493
|
-
if (isLineBreak(text.charCodeAt(pos))) {
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
pos++;
|
|
497
|
-
}
|
|
498
|
-
value = text.substring(start, pos);
|
|
499
|
-
return token = 12;
|
|
500
|
-
}
|
|
501
|
-
if (text.charCodeAt(pos + 1) === 42) {
|
|
502
|
-
pos += 2;
|
|
503
|
-
const safeLength = len - 1;
|
|
504
|
-
let commentClosed = false;
|
|
505
|
-
while (pos < safeLength) {
|
|
506
|
-
const ch = text.charCodeAt(pos);
|
|
507
|
-
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
508
|
-
pos += 2;
|
|
509
|
-
commentClosed = true;
|
|
510
|
-
break;
|
|
511
|
-
}
|
|
512
|
-
pos++;
|
|
513
|
-
if (isLineBreak(ch)) {
|
|
514
|
-
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
515
|
-
pos++;
|
|
516
|
-
}
|
|
517
|
-
lineNumber++;
|
|
518
|
-
tokenLineStartOffset = pos;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (!commentClosed) {
|
|
522
|
-
pos++;
|
|
523
|
-
scanError = 1;
|
|
524
|
-
}
|
|
525
|
-
value = text.substring(start, pos);
|
|
526
|
-
return token = 13;
|
|
527
|
-
}
|
|
528
|
-
value += String.fromCharCode(code);
|
|
529
|
-
pos++;
|
|
530
|
-
return token = 16;
|
|
531
|
-
case 45:
|
|
532
|
-
value += String.fromCharCode(code);
|
|
533
|
-
pos++;
|
|
534
|
-
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
535
|
-
return token = 16;
|
|
536
|
-
}
|
|
537
|
-
case 48:
|
|
538
|
-
case 49:
|
|
539
|
-
case 50:
|
|
540
|
-
case 51:
|
|
541
|
-
case 52:
|
|
542
|
-
case 53:
|
|
543
|
-
case 54:
|
|
544
|
-
case 55:
|
|
545
|
-
case 56:
|
|
546
|
-
case 57:
|
|
547
|
-
value += scanNumber();
|
|
548
|
-
return token = 11;
|
|
549
|
-
default:
|
|
550
|
-
while (pos < len && isUnknownContentCharacter(code)) {
|
|
551
|
-
pos++;
|
|
552
|
-
code = text.charCodeAt(pos);
|
|
553
|
-
}
|
|
554
|
-
if (tokenOffset !== pos) {
|
|
555
|
-
value = text.substring(tokenOffset, pos);
|
|
556
|
-
switch (value) {
|
|
557
|
-
case "true":
|
|
558
|
-
return token = 8;
|
|
559
|
-
case "false":
|
|
560
|
-
return token = 9;
|
|
561
|
-
case "null":
|
|
562
|
-
return token = 7;
|
|
563
|
-
}
|
|
564
|
-
return token = 16;
|
|
565
|
-
}
|
|
566
|
-
value += String.fromCharCode(code);
|
|
567
|
-
pos++;
|
|
568
|
-
return token = 16;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
function isUnknownContentCharacter(code) {
|
|
572
|
-
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
573
|
-
return false;
|
|
574
|
-
}
|
|
575
|
-
switch (code) {
|
|
576
|
-
case 125:
|
|
577
|
-
case 93:
|
|
578
|
-
case 123:
|
|
579
|
-
case 91:
|
|
580
|
-
case 34:
|
|
581
|
-
case 58:
|
|
582
|
-
case 44:
|
|
583
|
-
case 47:
|
|
584
|
-
return false;
|
|
585
|
-
}
|
|
586
|
-
return true;
|
|
587
|
-
}
|
|
588
|
-
function scanNextNonTrivia() {
|
|
589
|
-
let result;
|
|
590
|
-
do {
|
|
591
|
-
result = scanNext();
|
|
592
|
-
} while (result >= 12 && result <= 15);
|
|
593
|
-
return result;
|
|
594
|
-
}
|
|
595
|
-
return {
|
|
596
|
-
setPosition,
|
|
597
|
-
getPosition: () => pos,
|
|
598
|
-
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
599
|
-
getToken: () => token,
|
|
600
|
-
getTokenValue: () => value,
|
|
601
|
-
getTokenOffset: () => tokenOffset,
|
|
602
|
-
getTokenLength: () => pos - tokenOffset,
|
|
603
|
-
getTokenStartLine: () => lineStartOffset,
|
|
604
|
-
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
605
|
-
getTokenError: () => scanError
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
function isWhiteSpace(ch) {
|
|
609
|
-
return ch === 32 || ch === 9;
|
|
610
|
-
}
|
|
611
|
-
function isLineBreak(ch) {
|
|
612
|
-
return ch === 10 || ch === 13;
|
|
613
|
-
}
|
|
614
|
-
function isDigit(ch) {
|
|
615
|
-
return ch >= 48 && ch <= 57;
|
|
616
|
-
}
|
|
617
|
-
var CharacterCodes;
|
|
618
|
-
(function(CharacterCodes) {
|
|
619
|
-
CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
|
|
620
|
-
CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
|
|
621
|
-
CharacterCodes[CharacterCodes["space"] = 32] = "space";
|
|
622
|
-
CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
|
|
623
|
-
CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
|
|
624
|
-
CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
|
|
625
|
-
CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
|
|
626
|
-
CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
|
|
627
|
-
CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
|
|
628
|
-
CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
|
|
629
|
-
CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
|
|
630
|
-
CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
|
|
631
|
-
CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
|
|
632
|
-
CharacterCodes[CharacterCodes["a"] = 97] = "a";
|
|
633
|
-
CharacterCodes[CharacterCodes["b"] = 98] = "b";
|
|
634
|
-
CharacterCodes[CharacterCodes["c"] = 99] = "c";
|
|
635
|
-
CharacterCodes[CharacterCodes["d"] = 100] = "d";
|
|
636
|
-
CharacterCodes[CharacterCodes["e"] = 101] = "e";
|
|
637
|
-
CharacterCodes[CharacterCodes["f"] = 102] = "f";
|
|
638
|
-
CharacterCodes[CharacterCodes["g"] = 103] = "g";
|
|
639
|
-
CharacterCodes[CharacterCodes["h"] = 104] = "h";
|
|
640
|
-
CharacterCodes[CharacterCodes["i"] = 105] = "i";
|
|
641
|
-
CharacterCodes[CharacterCodes["j"] = 106] = "j";
|
|
642
|
-
CharacterCodes[CharacterCodes["k"] = 107] = "k";
|
|
643
|
-
CharacterCodes[CharacterCodes["l"] = 108] = "l";
|
|
644
|
-
CharacterCodes[CharacterCodes["m"] = 109] = "m";
|
|
645
|
-
CharacterCodes[CharacterCodes["n"] = 110] = "n";
|
|
646
|
-
CharacterCodes[CharacterCodes["o"] = 111] = "o";
|
|
647
|
-
CharacterCodes[CharacterCodes["p"] = 112] = "p";
|
|
648
|
-
CharacterCodes[CharacterCodes["q"] = 113] = "q";
|
|
649
|
-
CharacterCodes[CharacterCodes["r"] = 114] = "r";
|
|
650
|
-
CharacterCodes[CharacterCodes["s"] = 115] = "s";
|
|
651
|
-
CharacterCodes[CharacterCodes["t"] = 116] = "t";
|
|
652
|
-
CharacterCodes[CharacterCodes["u"] = 117] = "u";
|
|
653
|
-
CharacterCodes[CharacterCodes["v"] = 118] = "v";
|
|
654
|
-
CharacterCodes[CharacterCodes["w"] = 119] = "w";
|
|
655
|
-
CharacterCodes[CharacterCodes["x"] = 120] = "x";
|
|
656
|
-
CharacterCodes[CharacterCodes["y"] = 121] = "y";
|
|
657
|
-
CharacterCodes[CharacterCodes["z"] = 122] = "z";
|
|
658
|
-
CharacterCodes[CharacterCodes["A"] = 65] = "A";
|
|
659
|
-
CharacterCodes[CharacterCodes["B"] = 66] = "B";
|
|
660
|
-
CharacterCodes[CharacterCodes["C"] = 67] = "C";
|
|
661
|
-
CharacterCodes[CharacterCodes["D"] = 68] = "D";
|
|
662
|
-
CharacterCodes[CharacterCodes["E"] = 69] = "E";
|
|
663
|
-
CharacterCodes[CharacterCodes["F"] = 70] = "F";
|
|
664
|
-
CharacterCodes[CharacterCodes["G"] = 71] = "G";
|
|
665
|
-
CharacterCodes[CharacterCodes["H"] = 72] = "H";
|
|
666
|
-
CharacterCodes[CharacterCodes["I"] = 73] = "I";
|
|
667
|
-
CharacterCodes[CharacterCodes["J"] = 74] = "J";
|
|
668
|
-
CharacterCodes[CharacterCodes["K"] = 75] = "K";
|
|
669
|
-
CharacterCodes[CharacterCodes["L"] = 76] = "L";
|
|
670
|
-
CharacterCodes[CharacterCodes["M"] = 77] = "M";
|
|
671
|
-
CharacterCodes[CharacterCodes["N"] = 78] = "N";
|
|
672
|
-
CharacterCodes[CharacterCodes["O"] = 79] = "O";
|
|
673
|
-
CharacterCodes[CharacterCodes["P"] = 80] = "P";
|
|
674
|
-
CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
|
|
675
|
-
CharacterCodes[CharacterCodes["R"] = 82] = "R";
|
|
676
|
-
CharacterCodes[CharacterCodes["S"] = 83] = "S";
|
|
677
|
-
CharacterCodes[CharacterCodes["T"] = 84] = "T";
|
|
678
|
-
CharacterCodes[CharacterCodes["U"] = 85] = "U";
|
|
679
|
-
CharacterCodes[CharacterCodes["V"] = 86] = "V";
|
|
680
|
-
CharacterCodes[CharacterCodes["W"] = 87] = "W";
|
|
681
|
-
CharacterCodes[CharacterCodes["X"] = 88] = "X";
|
|
682
|
-
CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
|
|
683
|
-
CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
|
|
684
|
-
CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
|
|
685
|
-
CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
|
|
686
|
-
CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
|
|
687
|
-
CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
|
|
688
|
-
CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
|
|
689
|
-
CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
|
|
690
|
-
CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
|
|
691
|
-
CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
|
|
692
|
-
CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
|
|
693
|
-
CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
|
|
694
|
-
CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
|
|
695
|
-
CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
|
|
696
|
-
CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
|
|
697
|
-
CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
|
|
698
|
-
CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
|
|
699
|
-
})(CharacterCodes || (CharacterCodes = {}));
|
|
700
|
-
|
|
701
|
-
// ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
702
|
-
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
703
|
-
return " ".repeat(index);
|
|
704
|
-
});
|
|
705
|
-
var maxCachedValues = 200;
|
|
706
|
-
var cachedBreakLinesWithSpaces = {
|
|
707
|
-
" ": {
|
|
708
|
-
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
709
|
-
return `
|
|
710
|
-
` + " ".repeat(index);
|
|
711
|
-
}),
|
|
712
|
-
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
713
|
-
return "\r" + " ".repeat(index);
|
|
714
|
-
}),
|
|
715
|
-
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
716
|
-
return `\r
|
|
717
|
-
` + " ".repeat(index);
|
|
718
|
-
})
|
|
719
|
-
},
|
|
720
|
-
"\t": {
|
|
721
|
-
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
722
|
-
return `
|
|
723
|
-
` + "\t".repeat(index);
|
|
724
|
-
}),
|
|
725
|
-
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
726
|
-
return "\r" + "\t".repeat(index);
|
|
727
|
-
}),
|
|
728
|
-
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
729
|
-
return `\r
|
|
730
|
-
` + "\t".repeat(index);
|
|
731
|
-
})
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
var supportedEols = [`
|
|
735
|
-
`, "\r", `\r
|
|
736
|
-
`];
|
|
737
|
-
|
|
738
|
-
// ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
739
|
-
function format(documentText, range, options) {
|
|
740
|
-
let initialIndentLevel;
|
|
741
|
-
let formatText;
|
|
742
|
-
let formatTextStart;
|
|
743
|
-
let rangeStart;
|
|
744
|
-
let rangeEnd;
|
|
745
|
-
if (range) {
|
|
746
|
-
rangeStart = range.offset;
|
|
747
|
-
rangeEnd = rangeStart + range.length;
|
|
748
|
-
formatTextStart = rangeStart;
|
|
749
|
-
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
750
|
-
formatTextStart--;
|
|
751
|
-
}
|
|
752
|
-
let endOffset = rangeEnd;
|
|
753
|
-
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
754
|
-
endOffset++;
|
|
755
|
-
}
|
|
756
|
-
formatText = documentText.substring(formatTextStart, endOffset);
|
|
757
|
-
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
758
|
-
} else {
|
|
759
|
-
formatText = documentText;
|
|
760
|
-
initialIndentLevel = 0;
|
|
761
|
-
formatTextStart = 0;
|
|
762
|
-
rangeStart = 0;
|
|
763
|
-
rangeEnd = documentText.length;
|
|
764
|
-
}
|
|
765
|
-
const eol = getEOL(options, documentText);
|
|
766
|
-
const eolFastPathSupported = supportedEols.includes(eol);
|
|
767
|
-
let numberLineBreaks = 0;
|
|
768
|
-
let indentLevel = 0;
|
|
769
|
-
let indentValue;
|
|
770
|
-
if (options.insertSpaces) {
|
|
771
|
-
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
772
|
-
} else {
|
|
773
|
-
indentValue = "\t";
|
|
774
|
-
}
|
|
775
|
-
const indentType = indentValue === "\t" ? "\t" : " ";
|
|
776
|
-
let scanner = createScanner(formatText, false);
|
|
777
|
-
let hasError = false;
|
|
778
|
-
function newLinesAndIndent() {
|
|
779
|
-
if (numberLineBreaks > 1) {
|
|
780
|
-
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
781
|
-
}
|
|
782
|
-
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
783
|
-
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
784
|
-
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
785
|
-
}
|
|
786
|
-
if (amountOfSpaces <= 0) {
|
|
787
|
-
return eol;
|
|
788
|
-
}
|
|
789
|
-
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
790
|
-
}
|
|
791
|
-
function scanNext() {
|
|
792
|
-
let token = scanner.scan();
|
|
793
|
-
numberLineBreaks = 0;
|
|
794
|
-
while (token === 15 || token === 14) {
|
|
795
|
-
if (token === 14 && options.keepLines) {
|
|
796
|
-
numberLineBreaks += 1;
|
|
797
|
-
} else if (token === 14) {
|
|
798
|
-
numberLineBreaks = 1;
|
|
799
|
-
}
|
|
800
|
-
token = scanner.scan();
|
|
801
|
-
}
|
|
802
|
-
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
803
|
-
return token;
|
|
804
|
-
}
|
|
805
|
-
const editOperations = [];
|
|
806
|
-
function addEdit(text, startOffset, endOffset) {
|
|
807
|
-
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
808
|
-
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
let firstToken = scanNext();
|
|
812
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
813
|
-
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
814
|
-
}
|
|
815
|
-
if (firstToken !== 17) {
|
|
816
|
-
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
817
|
-
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
818
|
-
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
819
|
-
}
|
|
820
|
-
while (firstToken !== 17) {
|
|
821
|
-
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
822
|
-
let secondToken = scanNext();
|
|
823
|
-
let replaceContent = "";
|
|
824
|
-
let needsLineBreak = false;
|
|
825
|
-
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
826
|
-
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
827
|
-
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
828
|
-
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
829
|
-
needsLineBreak = secondToken === 12;
|
|
830
|
-
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
831
|
-
secondToken = scanNext();
|
|
832
|
-
}
|
|
833
|
-
if (secondToken === 2) {
|
|
834
|
-
if (firstToken !== 1) {
|
|
835
|
-
indentLevel--;
|
|
836
|
-
}
|
|
837
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
838
|
-
replaceContent = newLinesAndIndent();
|
|
839
|
-
} else if (options.keepLines) {
|
|
840
|
-
replaceContent = cachedSpaces[1];
|
|
841
|
-
}
|
|
842
|
-
} else if (secondToken === 4) {
|
|
843
|
-
if (firstToken !== 3) {
|
|
844
|
-
indentLevel--;
|
|
845
|
-
}
|
|
846
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
847
|
-
replaceContent = newLinesAndIndent();
|
|
848
|
-
} else if (options.keepLines) {
|
|
849
|
-
replaceContent = cachedSpaces[1];
|
|
850
|
-
}
|
|
851
|
-
} else {
|
|
852
|
-
switch (firstToken) {
|
|
853
|
-
case 3:
|
|
854
|
-
case 1:
|
|
855
|
-
indentLevel++;
|
|
856
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
857
|
-
replaceContent = newLinesAndIndent();
|
|
858
|
-
} else {
|
|
859
|
-
replaceContent = cachedSpaces[1];
|
|
860
|
-
}
|
|
861
|
-
break;
|
|
862
|
-
case 5:
|
|
863
|
-
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
864
|
-
replaceContent = newLinesAndIndent();
|
|
865
|
-
} else {
|
|
866
|
-
replaceContent = cachedSpaces[1];
|
|
867
|
-
}
|
|
868
|
-
break;
|
|
869
|
-
case 12:
|
|
870
|
-
replaceContent = newLinesAndIndent();
|
|
871
|
-
break;
|
|
872
|
-
case 13:
|
|
873
|
-
if (numberLineBreaks > 0) {
|
|
874
|
-
replaceContent = newLinesAndIndent();
|
|
875
|
-
} else if (!needsLineBreak) {
|
|
876
|
-
replaceContent = cachedSpaces[1];
|
|
877
|
-
}
|
|
878
|
-
break;
|
|
879
|
-
case 6:
|
|
880
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
881
|
-
replaceContent = newLinesAndIndent();
|
|
882
|
-
} else if (!needsLineBreak) {
|
|
883
|
-
replaceContent = cachedSpaces[1];
|
|
884
|
-
}
|
|
885
|
-
break;
|
|
886
|
-
case 10:
|
|
887
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
888
|
-
replaceContent = newLinesAndIndent();
|
|
889
|
-
} else if (secondToken === 6 && !needsLineBreak) {
|
|
890
|
-
replaceContent = "";
|
|
891
|
-
}
|
|
892
|
-
break;
|
|
893
|
-
case 7:
|
|
894
|
-
case 8:
|
|
895
|
-
case 9:
|
|
896
|
-
case 11:
|
|
897
|
-
case 2:
|
|
898
|
-
case 4:
|
|
899
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
900
|
-
replaceContent = newLinesAndIndent();
|
|
901
|
-
} else {
|
|
902
|
-
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
903
|
-
replaceContent = cachedSpaces[1];
|
|
904
|
-
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
905
|
-
hasError = true;
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
break;
|
|
909
|
-
case 16:
|
|
910
|
-
hasError = true;
|
|
911
|
-
break;
|
|
912
|
-
}
|
|
913
|
-
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
914
|
-
replaceContent = newLinesAndIndent();
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
if (secondToken === 17) {
|
|
918
|
-
if (options.keepLines && numberLineBreaks > 0) {
|
|
919
|
-
replaceContent = newLinesAndIndent();
|
|
920
|
-
} else {
|
|
921
|
-
replaceContent = options.insertFinalNewline ? eol : "";
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
925
|
-
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
926
|
-
firstToken = secondToken;
|
|
927
|
-
}
|
|
928
|
-
return editOperations;
|
|
929
|
-
}
|
|
930
|
-
function repeat(s, count) {
|
|
931
|
-
let result = "";
|
|
932
|
-
for (let i = 0;i < count; i++) {
|
|
933
|
-
result += s;
|
|
934
|
-
}
|
|
935
|
-
return result;
|
|
936
|
-
}
|
|
937
|
-
function computeIndentLevel(content, options) {
|
|
938
|
-
let i = 0;
|
|
939
|
-
let nChars = 0;
|
|
940
|
-
const tabSize = options.tabSize || 4;
|
|
941
|
-
while (i < content.length) {
|
|
942
|
-
let ch = content.charAt(i);
|
|
943
|
-
if (ch === cachedSpaces[1]) {
|
|
944
|
-
nChars++;
|
|
945
|
-
} else if (ch === "\t") {
|
|
946
|
-
nChars += tabSize;
|
|
947
|
-
} else {
|
|
948
|
-
break;
|
|
949
|
-
}
|
|
950
|
-
i++;
|
|
951
|
-
}
|
|
952
|
-
return Math.floor(nChars / tabSize);
|
|
953
|
-
}
|
|
954
|
-
function getEOL(options, text) {
|
|
955
|
-
for (let i = 0;i < text.length; i++) {
|
|
956
|
-
const ch = text.charAt(i);
|
|
957
|
-
if (ch === "\r") {
|
|
958
|
-
if (i + 1 < text.length && text.charAt(i + 1) === `
|
|
959
|
-
`) {
|
|
960
|
-
return `\r
|
|
961
|
-
`;
|
|
962
|
-
}
|
|
963
|
-
return "\r";
|
|
964
|
-
} else if (ch === `
|
|
965
|
-
`) {
|
|
966
|
-
return `
|
|
967
|
-
`;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
return options && options.eol || `
|
|
971
|
-
`;
|
|
972
|
-
}
|
|
973
|
-
function isEOL(text, offset) {
|
|
974
|
-
return `\r
|
|
975
|
-
`.indexOf(text.charAt(offset)) !== -1;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
// ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
979
|
-
var ParseOptions;
|
|
980
|
-
(function(ParseOptions) {
|
|
981
|
-
ParseOptions.DEFAULT = {
|
|
982
|
-
allowTrailingComma: false
|
|
983
|
-
};
|
|
984
|
-
})(ParseOptions || (ParseOptions = {}));
|
|
985
|
-
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
986
|
-
let currentProperty = null;
|
|
987
|
-
let currentParent = [];
|
|
988
|
-
const previousParents = [];
|
|
989
|
-
function onValue(value) {
|
|
990
|
-
if (Array.isArray(currentParent)) {
|
|
991
|
-
currentParent.push(value);
|
|
992
|
-
} else if (currentProperty !== null) {
|
|
993
|
-
currentParent[currentProperty] = value;
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
const visitor = {
|
|
997
|
-
onObjectBegin: () => {
|
|
998
|
-
const object = {};
|
|
999
|
-
onValue(object);
|
|
1000
|
-
previousParents.push(currentParent);
|
|
1001
|
-
currentParent = object;
|
|
1002
|
-
currentProperty = null;
|
|
1003
|
-
},
|
|
1004
|
-
onObjectProperty: (name) => {
|
|
1005
|
-
currentProperty = name;
|
|
1006
|
-
},
|
|
1007
|
-
onObjectEnd: () => {
|
|
1008
|
-
currentParent = previousParents.pop();
|
|
1009
|
-
},
|
|
1010
|
-
onArrayBegin: () => {
|
|
1011
|
-
const array = [];
|
|
1012
|
-
onValue(array);
|
|
1013
|
-
previousParents.push(currentParent);
|
|
1014
|
-
currentParent = array;
|
|
1015
|
-
currentProperty = null;
|
|
1016
|
-
},
|
|
1017
|
-
onArrayEnd: () => {
|
|
1018
|
-
currentParent = previousParents.pop();
|
|
1019
|
-
},
|
|
1020
|
-
onLiteralValue: onValue,
|
|
1021
|
-
onError: (error, offset, length) => {
|
|
1022
|
-
errors.push({ error, offset, length });
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
visit(text, visitor, options);
|
|
1026
|
-
return currentParent[0];
|
|
1027
|
-
}
|
|
1028
|
-
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1029
|
-
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: undefined };
|
|
1030
|
-
function ensurePropertyComplete(endOffset) {
|
|
1031
|
-
if (currentParent.type === "property") {
|
|
1032
|
-
currentParent.length = endOffset - currentParent.offset;
|
|
1033
|
-
currentParent = currentParent.parent;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
function onValue(valueNode) {
|
|
1037
|
-
currentParent.children.push(valueNode);
|
|
1038
|
-
return valueNode;
|
|
1039
|
-
}
|
|
1040
|
-
const visitor = {
|
|
1041
|
-
onObjectBegin: (offset) => {
|
|
1042
|
-
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
1043
|
-
},
|
|
1044
|
-
onObjectProperty: (name, offset, length) => {
|
|
1045
|
-
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
1046
|
-
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
1047
|
-
},
|
|
1048
|
-
onObjectEnd: (offset, length) => {
|
|
1049
|
-
ensurePropertyComplete(offset + length);
|
|
1050
|
-
currentParent.length = offset + length - currentParent.offset;
|
|
1051
|
-
currentParent = currentParent.parent;
|
|
1052
|
-
ensurePropertyComplete(offset + length);
|
|
1053
|
-
},
|
|
1054
|
-
onArrayBegin: (offset, length) => {
|
|
1055
|
-
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
1056
|
-
},
|
|
1057
|
-
onArrayEnd: (offset, length) => {
|
|
1058
|
-
currentParent.length = offset + length - currentParent.offset;
|
|
1059
|
-
currentParent = currentParent.parent;
|
|
1060
|
-
ensurePropertyComplete(offset + length);
|
|
1061
|
-
},
|
|
1062
|
-
onLiteralValue: (value, offset, length) => {
|
|
1063
|
-
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
1064
|
-
ensurePropertyComplete(offset + length);
|
|
1065
|
-
},
|
|
1066
|
-
onSeparator: (sep, offset, length) => {
|
|
1067
|
-
if (currentParent.type === "property") {
|
|
1068
|
-
if (sep === ":") {
|
|
1069
|
-
currentParent.colonOffset = offset;
|
|
1070
|
-
} else if (sep === ",") {
|
|
1071
|
-
ensurePropertyComplete(offset);
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
},
|
|
1075
|
-
onError: (error, offset, length) => {
|
|
1076
|
-
errors.push({ error, offset, length });
|
|
1077
|
-
}
|
|
1078
|
-
};
|
|
1079
|
-
visit(text, visitor, options);
|
|
1080
|
-
const result = currentParent.children[0];
|
|
1081
|
-
if (result) {
|
|
1082
|
-
delete result.parent;
|
|
1083
|
-
}
|
|
1084
|
-
return result;
|
|
1085
|
-
}
|
|
1086
|
-
function findNodeAtLocation(root, path) {
|
|
1087
|
-
if (!root) {
|
|
1088
|
-
return;
|
|
1089
|
-
}
|
|
1090
|
-
let node = root;
|
|
1091
|
-
for (let segment of path) {
|
|
1092
|
-
if (typeof segment === "string") {
|
|
1093
|
-
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
1094
|
-
return;
|
|
1095
|
-
}
|
|
1096
|
-
let found = false;
|
|
1097
|
-
for (const propertyNode of node.children) {
|
|
1098
|
-
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
1099
|
-
node = propertyNode.children[1];
|
|
1100
|
-
found = true;
|
|
1101
|
-
break;
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
if (!found) {
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
} else {
|
|
1108
|
-
const index = segment;
|
|
1109
|
-
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
1110
|
-
return;
|
|
1111
|
-
}
|
|
1112
|
-
node = node.children[index];
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
return node;
|
|
1116
|
-
}
|
|
1117
|
-
function getNodeValue(node) {
|
|
1118
|
-
switch (node.type) {
|
|
1119
|
-
case "array":
|
|
1120
|
-
return node.children.map(getNodeValue);
|
|
1121
|
-
case "object":
|
|
1122
|
-
const obj = Object.create(null);
|
|
1123
|
-
for (let prop of node.children) {
|
|
1124
|
-
const valueNode = prop.children[1];
|
|
1125
|
-
if (valueNode) {
|
|
1126
|
-
obj[prop.children[0].value] = getNodeValue(valueNode);
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
return obj;
|
|
1130
|
-
case "null":
|
|
1131
|
-
case "string":
|
|
1132
|
-
case "number":
|
|
1133
|
-
case "boolean":
|
|
1134
|
-
return node.value;
|
|
1135
|
-
default:
|
|
1136
|
-
return;
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
1140
|
-
const _scanner = createScanner(text, false);
|
|
1141
|
-
const _jsonPath = [];
|
|
1142
|
-
let suppressedCallbacks = 0;
|
|
1143
|
-
function toNoArgVisit(visitFunction) {
|
|
1144
|
-
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1145
|
-
}
|
|
1146
|
-
function toOneArgVisit(visitFunction) {
|
|
1147
|
-
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1148
|
-
}
|
|
1149
|
-
function toOneArgVisitWithPath(visitFunction) {
|
|
1150
|
-
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1151
|
-
}
|
|
1152
|
-
function toBeginVisit(visitFunction) {
|
|
1153
|
-
return visitFunction ? () => {
|
|
1154
|
-
if (suppressedCallbacks > 0) {
|
|
1155
|
-
suppressedCallbacks++;
|
|
1156
|
-
} else {
|
|
1157
|
-
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
1158
|
-
if (cbReturn === false) {
|
|
1159
|
-
suppressedCallbacks = 1;
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
} : () => true;
|
|
1163
|
-
}
|
|
1164
|
-
function toEndVisit(visitFunction) {
|
|
1165
|
-
return visitFunction ? () => {
|
|
1166
|
-
if (suppressedCallbacks > 0) {
|
|
1167
|
-
suppressedCallbacks--;
|
|
1168
|
-
}
|
|
1169
|
-
if (suppressedCallbacks === 0) {
|
|
1170
|
-
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
1171
|
-
}
|
|
1172
|
-
} : () => true;
|
|
1173
|
-
}
|
|
1174
|
-
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
1175
|
-
const disallowComments = options && options.disallowComments;
|
|
1176
|
-
const allowTrailingComma = options && options.allowTrailingComma;
|
|
1177
|
-
function scanNext() {
|
|
1178
|
-
while (true) {
|
|
1179
|
-
const token = _scanner.scan();
|
|
1180
|
-
switch (_scanner.getTokenError()) {
|
|
1181
|
-
case 4:
|
|
1182
|
-
handleError(14);
|
|
1183
|
-
break;
|
|
1184
|
-
case 5:
|
|
1185
|
-
handleError(15);
|
|
1186
|
-
break;
|
|
1187
|
-
case 3:
|
|
1188
|
-
handleError(13);
|
|
1189
|
-
break;
|
|
1190
|
-
case 1:
|
|
1191
|
-
if (!disallowComments) {
|
|
1192
|
-
handleError(11);
|
|
1193
|
-
}
|
|
1194
|
-
break;
|
|
1195
|
-
case 2:
|
|
1196
|
-
handleError(12);
|
|
1197
|
-
break;
|
|
1198
|
-
case 6:
|
|
1199
|
-
handleError(16);
|
|
1200
|
-
break;
|
|
1201
|
-
}
|
|
1202
|
-
switch (token) {
|
|
1203
|
-
case 12:
|
|
1204
|
-
case 13:
|
|
1205
|
-
if (disallowComments) {
|
|
1206
|
-
handleError(10);
|
|
1207
|
-
} else {
|
|
1208
|
-
onComment();
|
|
1209
|
-
}
|
|
1210
|
-
break;
|
|
1211
|
-
case 16:
|
|
1212
|
-
handleError(1);
|
|
1213
|
-
break;
|
|
1214
|
-
case 15:
|
|
1215
|
-
case 14:
|
|
1216
|
-
break;
|
|
1217
|
-
default:
|
|
1218
|
-
return token;
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
1223
|
-
onError(error);
|
|
1224
|
-
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
1225
|
-
let token = _scanner.getToken();
|
|
1226
|
-
while (token !== 17) {
|
|
1227
|
-
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
1228
|
-
scanNext();
|
|
1229
|
-
break;
|
|
1230
|
-
} else if (skipUntil.indexOf(token) !== -1) {
|
|
1231
|
-
break;
|
|
1232
|
-
}
|
|
1233
|
-
token = scanNext();
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
function parseString(isValue) {
|
|
1238
|
-
const value = _scanner.getTokenValue();
|
|
1239
|
-
if (isValue) {
|
|
1240
|
-
onLiteralValue(value);
|
|
1241
|
-
} else {
|
|
1242
|
-
onObjectProperty(value);
|
|
1243
|
-
_jsonPath.push(value);
|
|
1244
|
-
}
|
|
1245
|
-
scanNext();
|
|
1246
|
-
return true;
|
|
1247
|
-
}
|
|
1248
|
-
function parseLiteral() {
|
|
1249
|
-
switch (_scanner.getToken()) {
|
|
1250
|
-
case 11:
|
|
1251
|
-
const tokenValue = _scanner.getTokenValue();
|
|
1252
|
-
let value = Number(tokenValue);
|
|
1253
|
-
if (isNaN(value)) {
|
|
1254
|
-
handleError(2);
|
|
1255
|
-
value = 0;
|
|
1256
|
-
}
|
|
1257
|
-
onLiteralValue(value);
|
|
1258
|
-
break;
|
|
1259
|
-
case 7:
|
|
1260
|
-
onLiteralValue(null);
|
|
1261
|
-
break;
|
|
1262
|
-
case 8:
|
|
1263
|
-
onLiteralValue(true);
|
|
1264
|
-
break;
|
|
1265
|
-
case 9:
|
|
1266
|
-
onLiteralValue(false);
|
|
1267
|
-
break;
|
|
1268
|
-
default:
|
|
1269
|
-
return false;
|
|
1270
|
-
}
|
|
1271
|
-
scanNext();
|
|
1272
|
-
return true;
|
|
1273
|
-
}
|
|
1274
|
-
function parseProperty() {
|
|
1275
|
-
if (_scanner.getToken() !== 10) {
|
|
1276
|
-
handleError(3, [], [2, 5]);
|
|
1277
|
-
return false;
|
|
1278
|
-
}
|
|
1279
|
-
parseString(false);
|
|
1280
|
-
if (_scanner.getToken() === 6) {
|
|
1281
|
-
onSeparator(":");
|
|
1282
|
-
scanNext();
|
|
1283
|
-
if (!parseValue()) {
|
|
1284
|
-
handleError(4, [], [2, 5]);
|
|
1285
|
-
}
|
|
1286
|
-
} else {
|
|
1287
|
-
handleError(5, [], [2, 5]);
|
|
1288
|
-
}
|
|
1289
|
-
_jsonPath.pop();
|
|
1290
|
-
return true;
|
|
1291
|
-
}
|
|
1292
|
-
function parseObject() {
|
|
1293
|
-
onObjectBegin();
|
|
1294
|
-
scanNext();
|
|
1295
|
-
let needsComma = false;
|
|
1296
|
-
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1297
|
-
if (_scanner.getToken() === 5) {
|
|
1298
|
-
if (!needsComma) {
|
|
1299
|
-
handleError(4, [], []);
|
|
1300
|
-
}
|
|
1301
|
-
onSeparator(",");
|
|
1302
|
-
scanNext();
|
|
1303
|
-
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1304
|
-
break;
|
|
1305
|
-
}
|
|
1306
|
-
} else if (needsComma) {
|
|
1307
|
-
handleError(6, [], []);
|
|
1308
|
-
}
|
|
1309
|
-
if (!parseProperty()) {
|
|
1310
|
-
handleError(4, [], [2, 5]);
|
|
1311
|
-
}
|
|
1312
|
-
needsComma = true;
|
|
1313
|
-
}
|
|
1314
|
-
onObjectEnd();
|
|
1315
|
-
if (_scanner.getToken() !== 2) {
|
|
1316
|
-
handleError(7, [2], []);
|
|
1317
|
-
} else {
|
|
1318
|
-
scanNext();
|
|
1319
|
-
}
|
|
1320
|
-
return true;
|
|
1321
|
-
}
|
|
1322
|
-
function parseArray() {
|
|
1323
|
-
onArrayBegin();
|
|
1324
|
-
scanNext();
|
|
1325
|
-
let isFirstElement = true;
|
|
1326
|
-
let needsComma = false;
|
|
1327
|
-
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1328
|
-
if (_scanner.getToken() === 5) {
|
|
1329
|
-
if (!needsComma) {
|
|
1330
|
-
handleError(4, [], []);
|
|
1331
|
-
}
|
|
1332
|
-
onSeparator(",");
|
|
1333
|
-
scanNext();
|
|
1334
|
-
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1335
|
-
break;
|
|
1336
|
-
}
|
|
1337
|
-
} else if (needsComma) {
|
|
1338
|
-
handleError(6, [], []);
|
|
1339
|
-
}
|
|
1340
|
-
if (isFirstElement) {
|
|
1341
|
-
_jsonPath.push(0);
|
|
1342
|
-
isFirstElement = false;
|
|
1343
|
-
} else {
|
|
1344
|
-
_jsonPath[_jsonPath.length - 1]++;
|
|
1345
|
-
}
|
|
1346
|
-
if (!parseValue()) {
|
|
1347
|
-
handleError(4, [], [4, 5]);
|
|
1348
|
-
}
|
|
1349
|
-
needsComma = true;
|
|
1350
|
-
}
|
|
1351
|
-
onArrayEnd();
|
|
1352
|
-
if (!isFirstElement) {
|
|
1353
|
-
_jsonPath.pop();
|
|
1354
|
-
}
|
|
1355
|
-
if (_scanner.getToken() !== 4) {
|
|
1356
|
-
handleError(8, [4], []);
|
|
1357
|
-
} else {
|
|
1358
|
-
scanNext();
|
|
1359
|
-
}
|
|
1360
|
-
return true;
|
|
1361
|
-
}
|
|
1362
|
-
function parseValue() {
|
|
1363
|
-
switch (_scanner.getToken()) {
|
|
1364
|
-
case 3:
|
|
1365
|
-
return parseArray();
|
|
1366
|
-
case 1:
|
|
1367
|
-
return parseObject();
|
|
1368
|
-
case 10:
|
|
1369
|
-
return parseString(true);
|
|
1370
|
-
default:
|
|
1371
|
-
return parseLiteral();
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
scanNext();
|
|
1375
|
-
if (_scanner.getToken() === 17) {
|
|
1376
|
-
if (options.allowEmptyContent) {
|
|
1377
|
-
return true;
|
|
1378
|
-
}
|
|
1379
|
-
handleError(4, [], []);
|
|
1380
|
-
return false;
|
|
1381
|
-
}
|
|
1382
|
-
if (!parseValue()) {
|
|
1383
|
-
handleError(4, [], []);
|
|
1384
|
-
return false;
|
|
1385
|
-
}
|
|
1386
|
-
if (_scanner.getToken() !== 17) {
|
|
1387
|
-
handleError(9, [], []);
|
|
1388
|
-
}
|
|
1389
|
-
return true;
|
|
1390
|
-
}
|
|
1391
|
-
function getNodeType(value) {
|
|
1392
|
-
switch (typeof value) {
|
|
1393
|
-
case "boolean":
|
|
1394
|
-
return "boolean";
|
|
1395
|
-
case "number":
|
|
1396
|
-
return "number";
|
|
1397
|
-
case "string":
|
|
1398
|
-
return "string";
|
|
1399
|
-
case "object": {
|
|
1400
|
-
if (!value) {
|
|
1401
|
-
return "null";
|
|
1402
|
-
} else if (Array.isArray(value)) {
|
|
1403
|
-
return "array";
|
|
1404
|
-
}
|
|
1405
|
-
return "object";
|
|
1406
|
-
}
|
|
1407
|
-
default:
|
|
1408
|
-
return "null";
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
// ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
1413
|
-
function setProperty(text, originalPath, value, options) {
|
|
1414
|
-
const path = originalPath.slice();
|
|
1415
|
-
const errors = [];
|
|
1416
|
-
const root = parseTree(text, errors);
|
|
1417
|
-
let parent = undefined;
|
|
1418
|
-
let lastSegment = undefined;
|
|
1419
|
-
while (path.length > 0) {
|
|
1420
|
-
lastSegment = path.pop();
|
|
1421
|
-
parent = findNodeAtLocation(root, path);
|
|
1422
|
-
if (parent === undefined && value !== undefined) {
|
|
1423
|
-
if (typeof lastSegment === "string") {
|
|
1424
|
-
value = { [lastSegment]: value };
|
|
1425
|
-
} else {
|
|
1426
|
-
value = [value];
|
|
1427
|
-
}
|
|
1428
|
-
} else {
|
|
1429
|
-
break;
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
if (!parent) {
|
|
1433
|
-
if (value === undefined) {
|
|
1434
|
-
throw new Error("Can not delete in empty document");
|
|
1435
|
-
}
|
|
1436
|
-
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
1437
|
-
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1438
|
-
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1439
|
-
if (existing !== undefined) {
|
|
1440
|
-
if (value === undefined) {
|
|
1441
|
-
if (!existing.parent) {
|
|
1442
|
-
throw new Error("Malformed AST");
|
|
1443
|
-
}
|
|
1444
|
-
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1445
|
-
let removeBegin;
|
|
1446
|
-
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1447
|
-
if (propertyIndex > 0) {
|
|
1448
|
-
let previous = parent.children[propertyIndex - 1];
|
|
1449
|
-
removeBegin = previous.offset + previous.length;
|
|
1450
|
-
} else {
|
|
1451
|
-
removeBegin = parent.offset + 1;
|
|
1452
|
-
if (parent.children.length > 1) {
|
|
1453
|
-
let next = parent.children[1];
|
|
1454
|
-
removeEnd = next.offset;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
1458
|
-
} else {
|
|
1459
|
-
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
1460
|
-
}
|
|
1461
|
-
} else {
|
|
1462
|
-
if (value === undefined) {
|
|
1463
|
-
return [];
|
|
1464
|
-
}
|
|
1465
|
-
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1466
|
-
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1467
|
-
let edit;
|
|
1468
|
-
if (index > 0) {
|
|
1469
|
-
let previous = parent.children[index - 1];
|
|
1470
|
-
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1471
|
-
} else if (parent.children.length === 0) {
|
|
1472
|
-
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1473
|
-
} else {
|
|
1474
|
-
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
1475
|
-
}
|
|
1476
|
-
return withFormatting(text, edit, options);
|
|
1477
|
-
}
|
|
1478
|
-
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1479
|
-
const insertIndex = lastSegment;
|
|
1480
|
-
if (insertIndex === -1) {
|
|
1481
|
-
const newProperty = `${JSON.stringify(value)}`;
|
|
1482
|
-
let edit;
|
|
1483
|
-
if (parent.children.length === 0) {
|
|
1484
|
-
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1485
|
-
} else {
|
|
1486
|
-
const previous = parent.children[parent.children.length - 1];
|
|
1487
|
-
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1488
|
-
}
|
|
1489
|
-
return withFormatting(text, edit, options);
|
|
1490
|
-
} else if (value === undefined && parent.children.length >= 0) {
|
|
1491
|
-
const removalIndex = lastSegment;
|
|
1492
|
-
const toRemove = parent.children[removalIndex];
|
|
1493
|
-
let edit;
|
|
1494
|
-
if (parent.children.length === 1) {
|
|
1495
|
-
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
1496
|
-
} else if (parent.children.length - 1 === removalIndex) {
|
|
1497
|
-
let previous = parent.children[removalIndex - 1];
|
|
1498
|
-
let offset = previous.offset + previous.length;
|
|
1499
|
-
let parentEndOffset = parent.offset + parent.length;
|
|
1500
|
-
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
1501
|
-
} else {
|
|
1502
|
-
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
1503
|
-
}
|
|
1504
|
-
return withFormatting(text, edit, options);
|
|
1505
|
-
} else if (value !== undefined) {
|
|
1506
|
-
let edit;
|
|
1507
|
-
const newProperty = `${JSON.stringify(value)}`;
|
|
1508
|
-
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1509
|
-
const toModify = parent.children[lastSegment];
|
|
1510
|
-
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1511
|
-
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1512
|
-
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
1513
|
-
} else {
|
|
1514
|
-
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1515
|
-
const previous = parent.children[index - 1];
|
|
1516
|
-
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1517
|
-
}
|
|
1518
|
-
return withFormatting(text, edit, options);
|
|
1519
|
-
} else {
|
|
1520
|
-
throw new Error(`Can not ${value === undefined ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1521
|
-
}
|
|
1522
|
-
} else {
|
|
1523
|
-
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
function withFormatting(text, edit, options) {
|
|
1527
|
-
if (!options.formattingOptions) {
|
|
1528
|
-
return [edit];
|
|
1529
|
-
}
|
|
1530
|
-
let newText = applyEdit(text, edit);
|
|
1531
|
-
let begin = edit.offset;
|
|
1532
|
-
let end = edit.offset + edit.content.length;
|
|
1533
|
-
if (edit.length === 0 || edit.content.length === 0) {
|
|
1534
|
-
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
1535
|
-
begin--;
|
|
1536
|
-
}
|
|
1537
|
-
while (end < newText.length && !isEOL(newText, end)) {
|
|
1538
|
-
end++;
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
1542
|
-
for (let i = edits.length - 1;i >= 0; i--) {
|
|
1543
|
-
const edit = edits[i];
|
|
1544
|
-
newText = applyEdit(newText, edit);
|
|
1545
|
-
begin = Math.min(begin, edit.offset);
|
|
1546
|
-
end = Math.max(end, edit.offset + edit.length);
|
|
1547
|
-
end += edit.content.length - edit.length;
|
|
1548
|
-
}
|
|
1549
|
-
const editLength = text.length - (newText.length - end) - begin;
|
|
1550
|
-
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
1551
|
-
}
|
|
1552
|
-
function applyEdit(text, edit) {
|
|
1553
|
-
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
// ../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
|
|
1557
|
-
var createScanner2 = createScanner;
|
|
1558
|
-
var ScanError;
|
|
1559
|
-
(function(ScanError) {
|
|
1560
|
-
ScanError[ScanError["None"] = 0] = "None";
|
|
1561
|
-
ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1562
|
-
ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1563
|
-
ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1564
|
-
ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1565
|
-
ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1566
|
-
ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1567
|
-
})(ScanError || (ScanError = {}));
|
|
1568
|
-
var SyntaxKind;
|
|
1569
|
-
(function(SyntaxKind) {
|
|
1570
|
-
SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1571
|
-
SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1572
|
-
SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1573
|
-
SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1574
|
-
SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
|
|
1575
|
-
SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
|
|
1576
|
-
SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
|
|
1577
|
-
SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1578
|
-
SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1579
|
-
SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
|
|
1580
|
-
SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1581
|
-
SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1582
|
-
SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1583
|
-
SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1584
|
-
SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
|
|
1585
|
-
SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
|
|
1586
|
-
SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
|
|
1587
|
-
})(SyntaxKind || (SyntaxKind = {}));
|
|
1588
|
-
var parse2 = parse;
|
|
1589
|
-
var parseTree2 = parseTree;
|
|
1590
|
-
var findNodeAtLocation2 = findNodeAtLocation;
|
|
1591
|
-
var getNodeValue2 = getNodeValue;
|
|
1592
|
-
var ParseErrorCode;
|
|
1593
|
-
(function(ParseErrorCode) {
|
|
1594
|
-
ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1595
|
-
ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1596
|
-
ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1597
|
-
ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
|
|
1598
|
-
ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
|
|
1599
|
-
ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
|
|
1600
|
-
ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1601
|
-
ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1602
|
-
ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1603
|
-
ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1604
|
-
ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1605
|
-
ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1606
|
-
ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1607
|
-
ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1608
|
-
ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1609
|
-
ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1610
|
-
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1611
|
-
function printParseErrorCode(code) {
|
|
1612
|
-
switch (code) {
|
|
1613
|
-
case 1:
|
|
1614
|
-
return "InvalidSymbol";
|
|
1615
|
-
case 2:
|
|
1616
|
-
return "InvalidNumberFormat";
|
|
1617
|
-
case 3:
|
|
1618
|
-
return "PropertyNameExpected";
|
|
1619
|
-
case 4:
|
|
1620
|
-
return "ValueExpected";
|
|
1621
|
-
case 5:
|
|
1622
|
-
return "ColonExpected";
|
|
1623
|
-
case 6:
|
|
1624
|
-
return "CommaExpected";
|
|
1625
|
-
case 7:
|
|
1626
|
-
return "CloseBraceExpected";
|
|
1627
|
-
case 8:
|
|
1628
|
-
return "CloseBracketExpected";
|
|
1629
|
-
case 9:
|
|
1630
|
-
return "EndOfFileExpected";
|
|
1631
|
-
case 10:
|
|
1632
|
-
return "InvalidCommentToken";
|
|
1633
|
-
case 11:
|
|
1634
|
-
return "UnexpectedEndOfComment";
|
|
1635
|
-
case 12:
|
|
1636
|
-
return "UnexpectedEndOfString";
|
|
1637
|
-
case 13:
|
|
1638
|
-
return "UnexpectedEndOfNumber";
|
|
1639
|
-
case 14:
|
|
1640
|
-
return "InvalidUnicode";
|
|
1641
|
-
case 15:
|
|
1642
|
-
return "InvalidEscapeCharacter";
|
|
1643
|
-
case 16:
|
|
1644
|
-
return "InvalidCharacter";
|
|
1645
|
-
}
|
|
1646
|
-
return "<unknown ParseErrorCode>";
|
|
1647
|
-
}
|
|
1648
|
-
function modify(text, path, value, options) {
|
|
1649
|
-
return setProperty(text, path, value, options);
|
|
1650
|
-
}
|
|
1651
|
-
function applyEdits(text, edits) {
|
|
1652
|
-
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1653
|
-
const diff = a.offset - b.offset;
|
|
1654
|
-
if (diff === 0) {
|
|
1655
|
-
return a.length - b.length;
|
|
1656
|
-
}
|
|
1657
|
-
return diff;
|
|
1658
|
-
});
|
|
1659
|
-
let lastModifiedOffset = text.length;
|
|
1660
|
-
for (let i = sortedEdits.length - 1;i >= 0; i--) {
|
|
1661
|
-
let e = sortedEdits[i];
|
|
1662
|
-
if (e.offset + e.length <= lastModifiedOffset) {
|
|
1663
|
-
text = applyEdit(text, e);
|
|
1664
|
-
} else {
|
|
1665
|
-
throw new Error("Overlapping edit");
|
|
1666
|
-
}
|
|
1667
|
-
lastModifiedOffset = e.offset;
|
|
1668
|
-
}
|
|
1669
|
-
return text;
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
// ../plugin/src/shared/jsonc-parser.ts
|
|
1673
294
|
function stripJsonComments(content) {
|
|
1674
295
|
let result = "";
|
|
1675
296
|
let inString = false;
|
|
@@ -1829,7 +450,7 @@ function normalizeJsoncParserObjects(value, options, path = []) {
|
|
|
1829
450
|
}
|
|
1830
451
|
function parseJsoncRecovering(content, options = {}) {
|
|
1831
452
|
const errors = [];
|
|
1832
|
-
const parsed =
|
|
453
|
+
const parsed = parse(content, errors, {
|
|
1833
454
|
allowTrailingComma: true,
|
|
1834
455
|
disallowComments: false,
|
|
1835
456
|
allowEmptyContent: false
|
|
@@ -2272,17 +893,17 @@ var TOKEN_COMMA = 5;
|
|
|
2272
893
|
var TOKEN_EOF = 17;
|
|
2273
894
|
function parseDocument(text) {
|
|
2274
895
|
const errors = [];
|
|
2275
|
-
const root =
|
|
896
|
+
const root = parseTree(text, errors, { allowTrailingComma: true });
|
|
2276
897
|
if (!root || errors.length > 0) {
|
|
2277
898
|
throw new Error("Cannot edit invalid JSONC");
|
|
2278
899
|
}
|
|
2279
900
|
return root;
|
|
2280
901
|
}
|
|
2281
902
|
function findNode(text, path) {
|
|
2282
|
-
return
|
|
903
|
+
return findNodeAtLocation(parseDocument(text), path);
|
|
2283
904
|
}
|
|
2284
905
|
function findComma(text, start, end) {
|
|
2285
|
-
const scanner =
|
|
906
|
+
const scanner = createScanner(text, false);
|
|
2286
907
|
scanner.setPosition(start);
|
|
2287
908
|
for (;; ) {
|
|
2288
909
|
const kind = scanner.scan();
|
|
@@ -2301,7 +922,7 @@ function findComma(text, start, end) {
|
|
|
2301
922
|
function setJsoncValue(text, path, value) {
|
|
2302
923
|
const node = findNode(text, path);
|
|
2303
924
|
if (node) {
|
|
2304
|
-
if (Object.is(
|
|
925
|
+
if (Object.is(getNodeValue(node), value))
|
|
2305
926
|
return text;
|
|
2306
927
|
const serialized = JSON.stringify(value);
|
|
2307
928
|
return text.slice(0, node.offset) + serialized + text.slice(node.offset + node.length);
|
|
@@ -2322,7 +943,7 @@ function removeObjectProperty(text, object, key) {
|
|
|
2322
943
|
const properties = object.children ?? [];
|
|
2323
944
|
const index = properties.findIndex((property) => {
|
|
2324
945
|
const propertyKey = property.children?.[0];
|
|
2325
|
-
return propertyKey !== undefined &&
|
|
946
|
+
return propertyKey !== undefined && getNodeValue(propertyKey) === key;
|
|
2326
947
|
});
|
|
2327
948
|
if (index === -1)
|
|
2328
949
|
return text;
|
|
@@ -4192,579 +2813,6 @@ function cancelAutoSearchWork(sessionId) {
|
|
|
4192
2813
|
}
|
|
4193
2814
|
}
|
|
4194
2815
|
|
|
4195
|
-
// ../plugin/src/v2/store-reader.ts
|
|
4196
|
-
import { createHash } from "node:crypto";
|
|
4197
|
-
import { statSync as statSync3 } from "node:fs";
|
|
4198
|
-
import { hostname } from "node:os";
|
|
4199
|
-
import { resolve as resolve2 } from "node:path";
|
|
4200
|
-
function gaDatabasePath(dataHome, channel = "latest", env = process.env) {
|
|
4201
|
-
return resolveOpenCodeDbPath("v2", { dataHome, channel, env }).path;
|
|
4202
|
-
}
|
|
4203
|
-
var RAW_MESSAGE_TYPES = [
|
|
4204
|
-
"user",
|
|
4205
|
-
"synthetic",
|
|
4206
|
-
"assistant",
|
|
4207
|
-
"skill",
|
|
4208
|
-
"shell",
|
|
4209
|
-
"system"
|
|
4210
|
-
];
|
|
4211
|
-
var RAW_MESSAGE_TYPE_PARAMETERS = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4212
|
-
var V2_MESSAGE_PAGE_SQL = `WITH bounds AS (
|
|
4213
|
-
SELECT
|
|
4214
|
-
CASE WHEN ? = 0 THEN -1 ELSE COALESCE((
|
|
4215
|
-
SELECT seq FROM session_message
|
|
4216
|
-
WHERE session_id = ? AND type IN (${RAW_MESSAGE_TYPE_PARAMETERS})
|
|
4217
|
-
ORDER BY seq ASC LIMIT 1 OFFSET ?
|
|
4218
|
-
), (SELECT MAX(seq) FROM session_message WHERE session_id = ?), -1) END AS after_seq,
|
|
4219
|
-
COALESCE((
|
|
4220
|
-
SELECT seq FROM session_message
|
|
4221
|
-
WHERE session_id = ? AND type IN (${RAW_MESSAGE_TYPE_PARAMETERS})
|
|
4222
|
-
ORDER BY seq ASC LIMIT 1 OFFSET ?
|
|
4223
|
-
), ?) AS watermark_seq
|
|
4224
|
-
)
|
|
4225
|
-
SELECT id, session_id, type, seq, time_created, data FROM session_message, bounds
|
|
4226
|
-
WHERE session_id = ?
|
|
4227
|
-
AND type IN (${RAW_MESSAGE_TYPE_PARAMETERS})
|
|
4228
|
-
AND seq > bounds.after_seq
|
|
4229
|
-
AND seq <= bounds.watermark_seq
|
|
4230
|
-
ORDER BY seq ASC LIMIT ?`;
|
|
4231
|
-
var V2_STORE_READER_DEBUG_COUNTER_KEY = "magic-context.v2.store-reader-debug";
|
|
4232
|
-
var debugSymbol = Symbol.for(V2_STORE_READER_DEBUG_COUNTER_KEY);
|
|
4233
|
-
var debugGlobal = globalThis;
|
|
4234
|
-
var QUERY_STATEMENTS = {
|
|
4235
|
-
messagePage: V2_MESSAGE_PAGE_SQL,
|
|
4236
|
-
messageCount: "SELECT COUNT(*) AS count FROM session_message WHERE session_id = ? AND type IN (?)",
|
|
4237
|
-
storedMessageCount: "SELECT COUNT(*) AS count FROM session_message WHERE session_id = ?",
|
|
4238
|
-
messageById: "SELECT id, session_id, type, seq, time_created, data FROM session_message WHERE session_id = ? AND id = ? AND type IN (?) LIMIT 1",
|
|
4239
|
-
messageExistsById: "SELECT 1 FROM session_message WHERE id = ? AND session_id = ? AND type IN (?) LIMIT 1",
|
|
4240
|
-
messageOrdinalById: `WITH target AS (
|
|
4241
|
-
SELECT seq FROM session_message WHERE session_id = ? AND id = ? AND type IN (?) LIMIT 1
|
|
4242
|
-
)
|
|
4243
|
-
SELECT (SELECT COUNT(*) FROM session_message WHERE session_id = ? AND type IN (?) AND seq <= target.seq) AS ordinal FROM target`,
|
|
4244
|
-
messageIdOrdinals: "SELECT id FROM session_message WHERE session_id = ? AND type IN (?) ORDER BY seq ASC LIMIT ? OFFSET ?",
|
|
4245
|
-
messageOrdinalPage: "SELECT id, type, seq, json_valid(data) AS valid FROM session_message WHERE session_id = ? AND seq > ? ORDER BY seq ASC, id ASC LIMIT ?",
|
|
4246
|
-
rawRowsThrough: "SELECT id, session_id, type, seq, time_created, data FROM session_message WHERE session_id = ? AND type IN (?) AND seq <= ? ORDER BY seq DESC LIMIT ?"
|
|
4247
|
-
};
|
|
4248
|
-
function debugCounters() {
|
|
4249
|
-
const counters = debugGlobal[debugSymbol] ??= {
|
|
4250
|
-
decodedRows: 0,
|
|
4251
|
-
operations: {},
|
|
4252
|
-
openReaders: 0,
|
|
4253
|
-
maxOpenReaders: 0,
|
|
4254
|
-
readersOpened: 0,
|
|
4255
|
-
readersClosed: 0
|
|
4256
|
-
};
|
|
4257
|
-
counters.openReaders ??= 0;
|
|
4258
|
-
counters.maxOpenReaders ??= 0;
|
|
4259
|
-
counters.readersOpened ??= 0;
|
|
4260
|
-
counters.readersClosed ??= 0;
|
|
4261
|
-
return counters;
|
|
4262
|
-
}
|
|
4263
|
-
function returnedRowCount(value) {
|
|
4264
|
-
if (Array.isArray(value))
|
|
4265
|
-
return value.length;
|
|
4266
|
-
if (value === null || value === undefined || value === false)
|
|
4267
|
-
return 0;
|
|
4268
|
-
return 1;
|
|
4269
|
-
}
|
|
4270
|
-
function trackDecodeOperation(name, operation) {
|
|
4271
|
-
const counters = debugCounters();
|
|
4272
|
-
const before = counters.decodedRows;
|
|
4273
|
-
const started = performance.now();
|
|
4274
|
-
let value;
|
|
4275
|
-
try {
|
|
4276
|
-
value = operation();
|
|
4277
|
-
return value;
|
|
4278
|
-
} finally {
|
|
4279
|
-
const decodedRows = counters.decodedRows - before;
|
|
4280
|
-
const current = counters.operations[name] ?? {
|
|
4281
|
-
calls: 0,
|
|
4282
|
-
decodedRows: 0,
|
|
4283
|
-
maxDecodedRows: 0
|
|
4284
|
-
};
|
|
4285
|
-
current.calls += 1;
|
|
4286
|
-
current.decodedRows += decodedRows;
|
|
4287
|
-
current.maxDecodedRows = Math.max(current.maxDecodedRows, decodedRows);
|
|
4288
|
-
counters.operations[name] = current;
|
|
4289
|
-
const statement = QUERY_STATEMENTS[name];
|
|
4290
|
-
if (counters.captureQueries && statement) {
|
|
4291
|
-
(counters.queries ??= []).push({
|
|
4292
|
-
operation: name,
|
|
4293
|
-
statement,
|
|
4294
|
-
rows: returnedRowCount(value),
|
|
4295
|
-
elapsedMs: performance.now() - started
|
|
4296
|
-
});
|
|
4297
|
-
}
|
|
4298
|
-
}
|
|
4299
|
-
}
|
|
4300
|
-
function decode(row) {
|
|
4301
|
-
debugCounters().decodedRows += 1;
|
|
4302
|
-
const data = JSON.parse(row.data);
|
|
4303
|
-
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
4304
|
-
throw new Error(`Invalid session_message data at seq ${row.seq}`);
|
|
4305
|
-
}
|
|
4306
|
-
if (row.type === "idle" && !["succeeded", "failed", "interrupted"].includes(String(data.outcome))) {
|
|
4307
|
-
throw new Error(`Invalid idle outcome at seq ${row.seq}`);
|
|
4308
|
-
}
|
|
4309
|
-
return { ...row, data };
|
|
4310
|
-
}
|
|
4311
|
-
function connect(path, identity = "") {
|
|
4312
|
-
const stat = statSync3(path);
|
|
4313
|
-
const acquiredIdentity = identity || `${stat.dev}:${stat.ino}:${stat.birthtimeMs}`;
|
|
4314
|
-
const db = new Database2(path, { readonly: true, fileMustExist: true });
|
|
4315
|
-
try {
|
|
4316
|
-
assertOpenCodeStoreGeneration(db, "v2", path);
|
|
4317
|
-
} catch (error) {
|
|
4318
|
-
db.close();
|
|
4319
|
-
throw error;
|
|
4320
|
-
}
|
|
4321
|
-
const counters = debugCounters();
|
|
4322
|
-
counters.openReaders += 1;
|
|
4323
|
-
counters.readersOpened += 1;
|
|
4324
|
-
counters.maxOpenReaders = Math.max(counters.maxOpenReaders, counters.openReaders);
|
|
4325
|
-
return { db, statements: new Map, identity: acquiredIdentity, leases: 0, retired: false };
|
|
4326
|
-
}
|
|
4327
|
-
function closeConnection(connection) {
|
|
4328
|
-
connection.statements.clear();
|
|
4329
|
-
try {
|
|
4330
|
-
connection.db.close();
|
|
4331
|
-
} finally {
|
|
4332
|
-
const counters = debugCounters();
|
|
4333
|
-
counters.openReaders = Math.max(0, counters.openReaders - 1);
|
|
4334
|
-
counters.readersClosed += 1;
|
|
4335
|
-
}
|
|
4336
|
-
}
|
|
4337
|
-
class V2StoreReader {
|
|
4338
|
-
path;
|
|
4339
|
-
pool;
|
|
4340
|
-
db;
|
|
4341
|
-
connection;
|
|
4342
|
-
closed = false;
|
|
4343
|
-
constructor(path, pool) {
|
|
4344
|
-
this.path = path;
|
|
4345
|
-
this.pool = pool;
|
|
4346
|
-
this.connection = pool ? pool.acquire(path) : connect(path);
|
|
4347
|
-
this.db = this.connection.db;
|
|
4348
|
-
}
|
|
4349
|
-
hostIdentity() {
|
|
4350
|
-
return createHash("sha256").update(JSON.stringify([hostname(), resolve2(this.path), this.connection.identity])).digest("hex");
|
|
4351
|
-
}
|
|
4352
|
-
prepare(sql) {
|
|
4353
|
-
if (this.closed)
|
|
4354
|
-
throw new Error("Store reader is closed");
|
|
4355
|
-
const statements = this.connection.statements;
|
|
4356
|
-
let statement = statements.get(sql);
|
|
4357
|
-
if (!statement) {
|
|
4358
|
-
statement = this.db.prepare(sql);
|
|
4359
|
-
if (statements.size >= 128)
|
|
4360
|
-
statements.clear();
|
|
4361
|
-
statements.set(sql, statement);
|
|
4362
|
-
}
|
|
4363
|
-
return statement;
|
|
4364
|
-
}
|
|
4365
|
-
close() {
|
|
4366
|
-
if (this.closed)
|
|
4367
|
-
return;
|
|
4368
|
-
this.closed = true;
|
|
4369
|
-
if (this.pool)
|
|
4370
|
-
this.pool.release(this.connection);
|
|
4371
|
-
else
|
|
4372
|
-
closeConnection(this.connection);
|
|
4373
|
-
}
|
|
4374
|
-
page(sessionID, options = {}) {
|
|
4375
|
-
return trackDecodeOperation("page", () => {
|
|
4376
|
-
const limit = options.limit ?? 100;
|
|
4377
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e4)
|
|
4378
|
-
throw new Error("Invalid page limit");
|
|
4379
|
-
const after = options.after ?? -1;
|
|
4380
|
-
if (!Number.isSafeInteger(after))
|
|
4381
|
-
throw new Error("Invalid seq cursor");
|
|
4382
|
-
if (options.through !== undefined && !Number.isSafeInteger(options.through))
|
|
4383
|
-
throw new Error("Invalid seq upper bound");
|
|
4384
|
-
const predicates = ["session_id = ?", "seq > ?"];
|
|
4385
|
-
const parameters = [sessionID, after];
|
|
4386
|
-
if (options.through !== undefined) {
|
|
4387
|
-
predicates.push("seq <= ?");
|
|
4388
|
-
parameters.push(options.through);
|
|
4389
|
-
}
|
|
4390
|
-
if (options.type) {
|
|
4391
|
-
predicates.push("type = ?");
|
|
4392
|
-
parameters.push(options.type);
|
|
4393
|
-
}
|
|
4394
|
-
const rows = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4395
|
-
WHERE ${predicates.join(" AND ")}
|
|
4396
|
-
ORDER BY seq ASC LIMIT ?`).all(...parameters, limit).map(decode);
|
|
4397
|
-
return { rows, cursor: rows.at(-1)?.seq };
|
|
4398
|
-
});
|
|
4399
|
-
}
|
|
4400
|
-
messagePage(sessionID, afterOrdinal, limit, finalWatermark, after) {
|
|
4401
|
-
return trackDecodeOperation("messagePage", () => {
|
|
4402
|
-
if (!Number.isSafeInteger(afterOrdinal) || afterOrdinal < 0)
|
|
4403
|
-
throw new Error("Invalid raw-message ordinal cursor");
|
|
4404
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e4)
|
|
4405
|
-
throw new Error("Invalid page limit");
|
|
4406
|
-
if (!Number.isSafeInteger(finalWatermark) || finalWatermark < 0)
|
|
4407
|
-
throw new Error("Invalid raw-message watermark");
|
|
4408
|
-
const pageSize = Math.min(limit, finalWatermark - afterOrdinal);
|
|
4409
|
-
if (pageSize <= 0)
|
|
4410
|
-
return [];
|
|
4411
|
-
if (after) {
|
|
4412
|
-
const anchor = this.prepare("SELECT seq FROM session_message WHERE session_id = ? AND id = ?").get(sessionID, after.id);
|
|
4413
|
-
if (anchor) {
|
|
4414
|
-
return this.prepare(`SELECT id, session_id, type, seq, time_created, data
|
|
4415
|
-
FROM session_message WHERE session_id = ? AND seq > ?
|
|
4416
|
-
AND type IN (${RAW_MESSAGE_TYPE_PARAMETERS}) ORDER BY seq ASC LIMIT ?`).all(sessionID, anchor.seq, ...RAW_MESSAGE_TYPES, pageSize).map(decode);
|
|
4417
|
-
}
|
|
4418
|
-
}
|
|
4419
|
-
const maximumSeq = Number.MAX_SAFE_INTEGER;
|
|
4420
|
-
const rows = this.prepare(V2_MESSAGE_PAGE_SQL).all(afterOrdinal, sessionID, ...RAW_MESSAGE_TYPES, Math.max(0, afterOrdinal - 1), sessionID, sessionID, ...RAW_MESSAGE_TYPES, finalWatermark - 1, maximumSeq, sessionID, ...RAW_MESSAGE_TYPES, pageSize);
|
|
4421
|
-
return rows.map(decode);
|
|
4422
|
-
});
|
|
4423
|
-
}
|
|
4424
|
-
messageCount(sessionID) {
|
|
4425
|
-
return trackDecodeOperation("messageCount", () => {
|
|
4426
|
-
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4427
|
-
const row = this.prepare(`SELECT COUNT(*) AS count FROM session_message
|
|
4428
|
-
WHERE session_id = ? AND type IN (${rawTypes})`).get(sessionID, ...RAW_MESSAGE_TYPES);
|
|
4429
|
-
return typeof row?.count === "number" ? row.count : 0;
|
|
4430
|
-
});
|
|
4431
|
-
}
|
|
4432
|
-
sessionDirectoryPage(afterSessionID, limit) {
|
|
4433
|
-
const rows = this.prepare(`SELECT id, COALESCE(directory, '') AS directory FROM session_v2
|
|
4434
|
-
WHERE id > ? ORDER BY id ASC LIMIT ?`).all(afterSessionID ?? "", limit);
|
|
4435
|
-
return rows.map((row) => ({ sessionId: row.id, directory: row.directory }));
|
|
4436
|
-
}
|
|
4437
|
-
latestMessageTime(sessionID) {
|
|
4438
|
-
const row = this.prepare("SELECT MAX(time_created) AS time FROM session_message WHERE session_id = ?").get(sessionID);
|
|
4439
|
-
return row?.time ?? undefined;
|
|
4440
|
-
}
|
|
4441
|
-
isSubagent(sessionID) {
|
|
4442
|
-
const row = this.prepare("SELECT parent_id FROM session_v2 WHERE id = ?").get(sessionID);
|
|
4443
|
-
if (!row)
|
|
4444
|
-
return null;
|
|
4445
|
-
return typeof row.parent_id === "string" && row.parent_id.length > 0;
|
|
4446
|
-
}
|
|
4447
|
-
latestRootSessionInDirectory(directory) {
|
|
4448
|
-
const columns = new Set(this.prepare("PRAGMA table_info(session_v2)").all().map((column) => column.name));
|
|
4449
|
-
const archived = columns.has("time_archived") ? " AND time_archived IS NULL" : "";
|
|
4450
|
-
const order = columns.has("time_updated") ? "time_updated DESC, id DESC" : "id DESC";
|
|
4451
|
-
const page = this.prepare(`SELECT id, COALESCE(directory, '') AS directory FROM session_v2
|
|
4452
|
-
WHERE parent_id IS NULL${archived}
|
|
4453
|
-
AND COALESCE(json_extract(metadata, '$.magic_context'), '') <> 'hidden-run'
|
|
4454
|
-
ORDER BY ${order} LIMIT ? OFFSET ?`);
|
|
4455
|
-
const pageSize = 500;
|
|
4456
|
-
for (let offset = 0;; offset += pageSize) {
|
|
4457
|
-
const rows = page.all(pageSize, offset);
|
|
4458
|
-
const match = rows.find((row) => sameProjectDirectory(row.directory, directory));
|
|
4459
|
-
if (match)
|
|
4460
|
-
return match.id;
|
|
4461
|
-
if (rows.length < pageSize)
|
|
4462
|
-
return;
|
|
4463
|
-
}
|
|
4464
|
-
}
|
|
4465
|
-
rootSessionActivity(sessionIDs) {
|
|
4466
|
-
const roots = new Map;
|
|
4467
|
-
for (let offset = 0;offset < sessionIDs.length; offset += 500) {
|
|
4468
|
-
const chunk = sessionIDs.slice(offset, offset + 500);
|
|
4469
|
-
const rows = this.prepare(`SELECT id, (
|
|
4470
|
-
SELECT MAX(time_created) FROM session_message
|
|
4471
|
-
WHERE session_id = session_v2.id AND type = 'user'
|
|
4472
|
-
) AS time FROM session_v2
|
|
4473
|
-
WHERE parent_id IS NULL
|
|
4474
|
-
AND COALESCE(json_extract(metadata, '$.magic_context'), '') <> 'hidden-run'
|
|
4475
|
-
AND id IN (${chunk.map(() => "?").join(",")})`).all(...chunk);
|
|
4476
|
-
for (const row of rows)
|
|
4477
|
-
if (row.time !== null)
|
|
4478
|
-
roots.set(row.id, row.time);
|
|
4479
|
-
}
|
|
4480
|
-
return roots;
|
|
4481
|
-
}
|
|
4482
|
-
oldestUserMessageTimesSince(sessionIDs, sinceMs) {
|
|
4483
|
-
const result = new Map;
|
|
4484
|
-
for (let offset = 0;offset < sessionIDs.length; offset += 500) {
|
|
4485
|
-
const chunk = sessionIDs.slice(offset, offset + 500);
|
|
4486
|
-
const rows = this.prepare(`SELECT session_id, MIN(time_created) AS time FROM session_message
|
|
4487
|
-
WHERE type = 'user' AND time_created > ? AND session_id IN (${chunk.map(() => "?").join(",")})
|
|
4488
|
-
GROUP BY session_id`).all(sinceMs, ...chunk);
|
|
4489
|
-
for (const row of rows)
|
|
4490
|
-
result.set(row.session_id, row.time);
|
|
4491
|
-
}
|
|
4492
|
-
return result;
|
|
4493
|
-
}
|
|
4494
|
-
retrospectiveUserPage(sessionID, options) {
|
|
4495
|
-
const { boundaryMs, before, limit, maxChars, truncationMarker } = options;
|
|
4496
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e4)
|
|
4497
|
-
throw new Error("Invalid page limit");
|
|
4498
|
-
if (!Number.isSafeInteger(maxChars) || maxChars <= truncationMarker.length)
|
|
4499
|
-
throw new Error("Invalid text limit");
|
|
4500
|
-
const direction = before ? "DESC" : "ASC";
|
|
4501
|
-
const head = Math.floor((maxChars - truncationMarker.length) / 2);
|
|
4502
|
-
const tail = maxChars - truncationMarker.length - head;
|
|
4503
|
-
return this.prepare(`WITH users AS (
|
|
4504
|
-
SELECT session_id, seq, time_created, data FROM session_message
|
|
4505
|
-
WHERE session_id = ? AND type = 'user' AND time_created ${before ? "<=" : ">"}
|
|
4506
|
-
?
|
|
4507
|
-
ORDER BY time_created ${direction}, seq ${direction} LIMIT ?
|
|
4508
|
-
), texts AS (
|
|
4509
|
-
SELECT session_id, seq, time_created, CASE
|
|
4510
|
-
WHEN json_extract(data, '$.synthetic') = 1 OR json_extract(data, '$.ignored') = 1 THEN ''
|
|
4511
|
-
WHEN json_type(data, '$.text') = 'text' THEN json_extract(data, '$.text')
|
|
4512
|
-
ELSE COALESCE((SELECT group_concat(json_extract(value, '$.text'), char(10))
|
|
4513
|
-
FROM json_each(users.data, '$.content')
|
|
4514
|
-
WHERE json_extract(value, '$.type') IN ('text', 'input_text')
|
|
4515
|
-
AND COALESCE(json_extract(value, '$.synthetic'), 0) <> 1
|
|
4516
|
-
AND COALESCE(json_extract(value, '$.ignored'), 0) <> 1), '') END AS text
|
|
4517
|
-
FROM users WHERE json_valid(data)
|
|
4518
|
-
) SELECT seq, time_created, CASE WHEN length(text) > ?
|
|
4519
|
-
THEN substr(text, 1, ?) || ? || substr(text, -?) ELSE text END AS text,
|
|
4520
|
-
EXISTS (
|
|
4521
|
-
SELECT 1 FROM session_message assistant_reply
|
|
4522
|
-
WHERE assistant_reply.session_id = texts.session_id
|
|
4523
|
-
AND assistant_reply.type = 'assistant'
|
|
4524
|
-
AND assistant_reply.seq < texts.seq
|
|
4525
|
-
AND EXISTS (
|
|
4526
|
-
SELECT 1 FROM session_message prior_user
|
|
4527
|
-
WHERE prior_user.session_id = texts.session_id
|
|
4528
|
-
AND prior_user.type = 'user'
|
|
4529
|
-
AND prior_user.seq < assistant_reply.seq
|
|
4530
|
-
)
|
|
4531
|
-
) AS follows_assistant_reply
|
|
4532
|
-
FROM texts ORDER BY time_created ${direction}, seq ${direction}`).all(sessionID, boundaryMs, limit, maxChars, head, truncationMarker, tail);
|
|
4533
|
-
}
|
|
4534
|
-
storedRowsAfter(sessionID, after) {
|
|
4535
|
-
const row = this.prepare("SELECT COUNT(*) AS count FROM session_message WHERE session_id = ? AND seq > ?").get(sessionID, after);
|
|
4536
|
-
return row.count;
|
|
4537
|
-
}
|
|
4538
|
-
storedMessageCount(sessionID) {
|
|
4539
|
-
return trackDecodeOperation("storedMessageCount", () => {
|
|
4540
|
-
const row = this.prepare("SELECT COUNT(*) AS count FROM session_message WHERE session_id = ?").get(sessionID);
|
|
4541
|
-
return typeof row?.count === "number" ? row.count : 0;
|
|
4542
|
-
});
|
|
4543
|
-
}
|
|
4544
|
-
messageById(sessionID, id) {
|
|
4545
|
-
return trackDecodeOperation("messageById", () => {
|
|
4546
|
-
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4547
|
-
const row = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4548
|
-
WHERE session_id = ? AND id = ? AND type IN (${rawTypes}) LIMIT 1`).get(sessionID, id, ...RAW_MESSAGE_TYPES);
|
|
4549
|
-
return row ? decode(row) : null;
|
|
4550
|
-
});
|
|
4551
|
-
}
|
|
4552
|
-
messageTimes(sessionID, ids) {
|
|
4553
|
-
const times = new Map;
|
|
4554
|
-
for (let offset = 0;offset < ids.length; offset += 500) {
|
|
4555
|
-
const batch = ids.slice(offset, offset + 500);
|
|
4556
|
-
const rows = this.prepare(`SELECT id, COALESCE(time_created, json_extract(data, '$.time.created')) AS created,
|
|
4557
|
-
json_extract(data, '$.time.completed') AS completed
|
|
4558
|
-
FROM session_message WHERE session_id = ? AND id IN (${batch.map(() => "?").join(",")})`).all(sessionID, ...batch);
|
|
4559
|
-
for (const row of rows)
|
|
4560
|
-
times.set(row.id, {
|
|
4561
|
-
created: typeof row.created === "number" ? row.created : undefined,
|
|
4562
|
-
completed: typeof row.completed === "number" ? row.completed : undefined
|
|
4563
|
-
});
|
|
4564
|
-
}
|
|
4565
|
-
return times;
|
|
4566
|
-
}
|
|
4567
|
-
messageExistsById(sessionID, id) {
|
|
4568
|
-
return trackDecodeOperation("messageExistsById", () => {
|
|
4569
|
-
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4570
|
-
const row = this.prepare(`SELECT 1 FROM session_message
|
|
4571
|
-
WHERE id = ? AND session_id = ? AND type IN (${rawTypes}) LIMIT 1`).get(id, sessionID, ...RAW_MESSAGE_TYPES);
|
|
4572
|
-
return row != null;
|
|
4573
|
-
});
|
|
4574
|
-
}
|
|
4575
|
-
messageOrdinalById(sessionID, id) {
|
|
4576
|
-
return trackDecodeOperation("messageOrdinalById", () => {
|
|
4577
|
-
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4578
|
-
const row = this.prepare(`WITH target AS (
|
|
4579
|
-
SELECT seq FROM session_message
|
|
4580
|
-
WHERE session_id = ? AND id = ? AND type IN (${rawTypes})
|
|
4581
|
-
LIMIT 1
|
|
4582
|
-
)
|
|
4583
|
-
SELECT (
|
|
4584
|
-
SELECT COUNT(*) FROM session_message
|
|
4585
|
-
WHERE session_id = ?
|
|
4586
|
-
AND type IN (${rawTypes})
|
|
4587
|
-
AND seq <= target.seq
|
|
4588
|
-
) AS ordinal
|
|
4589
|
-
FROM target`).get(sessionID, id, ...RAW_MESSAGE_TYPES, sessionID, ...RAW_MESSAGE_TYPES);
|
|
4590
|
-
return typeof row?.ordinal === "number" ? row.ordinal : null;
|
|
4591
|
-
});
|
|
4592
|
-
}
|
|
4593
|
-
messageIdOrdinals(sessionID, fromOrdinal, toOrdinal) {
|
|
4594
|
-
return trackDecodeOperation("messageIdOrdinals", () => {
|
|
4595
|
-
if (!Number.isSafeInteger(fromOrdinal) || fromOrdinal < 1)
|
|
4596
|
-
throw new Error("Invalid raw-message range start");
|
|
4597
|
-
if (!Number.isSafeInteger(toOrdinal) || toOrdinal < fromOrdinal)
|
|
4598
|
-
throw new Error("Invalid raw-message range end");
|
|
4599
|
-
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4600
|
-
const rows = this.prepare(`SELECT id FROM session_message
|
|
4601
|
-
WHERE session_id = ? AND type IN (${rawTypes})
|
|
4602
|
-
ORDER BY seq ASC LIMIT ? OFFSET ?`).all(sessionID, ...RAW_MESSAGE_TYPES, toOrdinal - fromOrdinal + 1, fromOrdinal - 1);
|
|
4603
|
-
return new Map(rows.map((row, index) => [row.id, fromOrdinal + index]));
|
|
4604
|
-
});
|
|
4605
|
-
}
|
|
4606
|
-
messageOrdinalPage(sessionID, after, limit) {
|
|
4607
|
-
return trackDecodeOperation("messageOrdinalPage", () => {
|
|
4608
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e4)
|
|
4609
|
-
throw new Error("Invalid page limit");
|
|
4610
|
-
const rows = after ? this.prepare(`SELECT id, type, seq, json_valid(data) AS valid
|
|
4611
|
-
FROM session_message
|
|
4612
|
-
WHERE session_id = ? AND (seq > ? OR (seq = ? AND id > ?))
|
|
4613
|
-
ORDER BY seq ASC, id ASC LIMIT ?`).all(sessionID, after.timeCreated, after.timeCreated, after.id, limit) : this.prepare(`SELECT id, type, seq, json_valid(data) AS valid
|
|
4614
|
-
FROM session_message
|
|
4615
|
-
WHERE session_id = ?
|
|
4616
|
-
ORDER BY seq ASC, id ASC LIMIT ?`).all(sessionID, limit);
|
|
4617
|
-
const rawTypes = new Set(RAW_MESSAGE_TYPES);
|
|
4618
|
-
return rows.map((row) => ({
|
|
4619
|
-
id: row.id,
|
|
4620
|
-
timeCreated: row.seq,
|
|
4621
|
-
contributesOrdinal: rawTypes.has(row.type),
|
|
4622
|
-
hasValidInfo: row.valid === 1
|
|
4623
|
-
}));
|
|
4624
|
-
});
|
|
4625
|
-
}
|
|
4626
|
-
range(sessionID, after, through) {
|
|
4627
|
-
return trackDecodeOperation("range", () => through <= after ? [] : this.all(sessionID, after, undefined, through));
|
|
4628
|
-
}
|
|
4629
|
-
spanRowStamps(sessionID, after, through) {
|
|
4630
|
-
if (!Number.isSafeInteger(after) || !Number.isSafeInteger(through))
|
|
4631
|
-
throw new Error("Invalid seq span");
|
|
4632
|
-
const rows = this.prepare(`SELECT seq, id, time_updated AS updated, length(CAST(data AS BLOB)) AS bytes
|
|
4633
|
-
FROM session_message WHERE session_id = ? AND seq > ? AND seq <= ?
|
|
4634
|
-
ORDER BY seq ASC`).all(sessionID, after, through);
|
|
4635
|
-
const stamps = new Map;
|
|
4636
|
-
for (const row of rows)
|
|
4637
|
-
stamps.set(row.seq, `${row.id}\x00${row.updated ?? ""}\x00${row.bytes ?? ""}`);
|
|
4638
|
-
return stamps;
|
|
4639
|
-
}
|
|
4640
|
-
rawRowsThrough(sessionID, throughSeq, limit) {
|
|
4641
|
-
return trackDecodeOperation("rawRowsThrough", () => {
|
|
4642
|
-
if (!Number.isSafeInteger(throughSeq))
|
|
4643
|
-
throw new Error("Invalid seq upper bound");
|
|
4644
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e4)
|
|
4645
|
-
throw new Error("Invalid page limit");
|
|
4646
|
-
const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
|
|
4647
|
-
return this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4648
|
-
WHERE session_id = ? AND type IN (${rawTypes}) AND seq <= ?
|
|
4649
|
-
ORDER BY seq DESC LIMIT ?`).all(sessionID, ...RAW_MESSAGE_TYPES, throughSeq, limit).map(decode);
|
|
4650
|
-
});
|
|
4651
|
-
}
|
|
4652
|
-
sequenceForId(sessionID, id) {
|
|
4653
|
-
if (!id)
|
|
4654
|
-
return;
|
|
4655
|
-
const row = this.prepare("SELECT seq FROM session_message WHERE session_id = ? AND id = ? LIMIT 1").get(sessionID, id);
|
|
4656
|
-
return typeof row?.seq === "number" ? row.seq : undefined;
|
|
4657
|
-
}
|
|
4658
|
-
syntheticMessageIDs(sessionID) {
|
|
4659
|
-
const rows = this.prepare("SELECT id FROM session_message WHERE session_id = ? AND type = 'synthetic'").all(sessionID);
|
|
4660
|
-
return new Set(rows.map((row) => row.id));
|
|
4661
|
-
}
|
|
4662
|
-
forkOrigin(sessionID) {
|
|
4663
|
-
const columns = new Set(this.prepare("PRAGMA table_info(session_v2)").all().map((column) => column.name));
|
|
4664
|
-
if (!columns.has("fork_session_id") || !columns.has("fork_boundary"))
|
|
4665
|
-
return null;
|
|
4666
|
-
const row = this.prepare("SELECT fork_session_id, fork_boundary FROM session_v2 WHERE id = ?").get(sessionID);
|
|
4667
|
-
if (!row?.fork_session_id || !row.fork_boundary)
|
|
4668
|
-
return null;
|
|
4669
|
-
try {
|
|
4670
|
-
const boundary = JSON.parse(row.fork_boundary);
|
|
4671
|
-
if (boundary.type !== "before" && boundary.type !== "through" || typeof boundary.messageID !== "string" || boundary.messageID.length === 0)
|
|
4672
|
-
return null;
|
|
4673
|
-
return {
|
|
4674
|
-
parentSessionID: row.fork_session_id,
|
|
4675
|
-
boundary: { type: boundary.type, messageID: boundary.messageID }
|
|
4676
|
-
};
|
|
4677
|
-
} catch {
|
|
4678
|
-
return null;
|
|
4679
|
-
}
|
|
4680
|
-
}
|
|
4681
|
-
sessionExists(sessionID) {
|
|
4682
|
-
return this.prepare("SELECT 1 FROM session_v2 WHERE id = ?").get(sessionID) != null;
|
|
4683
|
-
}
|
|
4684
|
-
rowStampsThrough(sessionID, throughSeq) {
|
|
4685
|
-
return this.prepare(`SELECT id, type, seq, time_created FROM session_message
|
|
4686
|
-
WHERE session_id = ? AND seq <= ? ORDER BY seq ASC`).all(sessionID, throughSeq);
|
|
4687
|
-
}
|
|
4688
|
-
latestSequenceForIds(sessionID, ids) {
|
|
4689
|
-
let latest = -1;
|
|
4690
|
-
for (let offset = 0;offset < ids.length; offset += 500) {
|
|
4691
|
-
const chunk = ids.slice(offset, offset + 500);
|
|
4692
|
-
const row = this.prepare(`SELECT MAX(seq) AS seq FROM session_message
|
|
4693
|
-
WHERE session_id = ? AND id IN (${chunk.map(() => "?").join(", ")})`).get(sessionID, ...chunk);
|
|
4694
|
-
if (typeof row?.seq === "number")
|
|
4695
|
-
latest = Math.max(latest, row.seq);
|
|
4696
|
-
}
|
|
4697
|
-
return latest;
|
|
4698
|
-
}
|
|
4699
|
-
compactionByStatus(sessionID, status) {
|
|
4700
|
-
const row = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4701
|
-
WHERE session_id = ? AND type = 'compaction'
|
|
4702
|
-
AND json_extract(data, '$.status') = ?
|
|
4703
|
-
ORDER BY seq DESC LIMIT 1`).get(sessionID, status);
|
|
4704
|
-
return row ? decode(row) : undefined;
|
|
4705
|
-
}
|
|
4706
|
-
latestCompaction(sessionID) {
|
|
4707
|
-
return trackDecodeOperation("latestCompaction", () => this.compactionByStatus(sessionID, "completed"));
|
|
4708
|
-
}
|
|
4709
|
-
latestRunningCompaction(sessionID) {
|
|
4710
|
-
return trackDecodeOperation("latestRunningCompaction", () => this.compactionByStatus(sessionID, "running"));
|
|
4711
|
-
}
|
|
4712
|
-
idleRows(sessionID, after = -1) {
|
|
4713
|
-
return trackDecodeOperation("idleRows", () => this.all(sessionID, after, "idle"));
|
|
4714
|
-
}
|
|
4715
|
-
earliestSequence(sessionID) {
|
|
4716
|
-
const row = this.prepare("SELECT MIN(seq) AS seq FROM session_message WHERE session_id = ?").get(sessionID);
|
|
4717
|
-
return typeof row?.seq === "number" ? row.seq : undefined;
|
|
4718
|
-
}
|
|
4719
|
-
latestSequence(sessionID) {
|
|
4720
|
-
const row = this.prepare("SELECT MAX(seq) AS seq FROM session_message WHERE session_id = ?").get(sessionID);
|
|
4721
|
-
return typeof row?.seq === "number" ? row.seq : -1;
|
|
4722
|
-
}
|
|
4723
|
-
assistantSince(sessionID, afterSeq) {
|
|
4724
|
-
return trackDecodeOperation("assistantSince", () => {
|
|
4725
|
-
const rows = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4726
|
-
WHERE session_id = ? AND type = 'assistant' AND seq > ?
|
|
4727
|
-
ORDER BY seq ASC`).all(sessionID, afterSeq);
|
|
4728
|
-
return rows.map((row) => decode(row));
|
|
4729
|
-
});
|
|
4730
|
-
}
|
|
4731
|
-
latestAssistant(sessionID) {
|
|
4732
|
-
return trackDecodeOperation("latestAssistant", () => {
|
|
4733
|
-
const row = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4734
|
-
WHERE session_id = ? AND type = 'assistant'
|
|
4735
|
-
ORDER BY seq DESC LIMIT 1`).get(sessionID);
|
|
4736
|
-
return row ? decode(row) : undefined;
|
|
4737
|
-
});
|
|
4738
|
-
}
|
|
4739
|
-
latestIdle(sessionID) {
|
|
4740
|
-
return trackDecodeOperation("latestIdle", () => {
|
|
4741
|
-
const row = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
4742
|
-
WHERE session_id = ? AND type = 'idle'
|
|
4743
|
-
ORDER BY seq DESC LIMIT 1`).get(sessionID);
|
|
4744
|
-
return row ? decode(row) : undefined;
|
|
4745
|
-
});
|
|
4746
|
-
}
|
|
4747
|
-
window(sessionID) {
|
|
4748
|
-
return trackDecodeOperation("window", () => this.db.transaction(() => {
|
|
4749
|
-
const cut = this.latestCompaction(sessionID);
|
|
4750
|
-
return this.all(sessionID, cut ? cut.seq - 1 : -1);
|
|
4751
|
-
}).deferred());
|
|
4752
|
-
}
|
|
4753
|
-
history(sessionID) {
|
|
4754
|
-
return trackDecodeOperation("history", () => this.all(sessionID, -1));
|
|
4755
|
-
}
|
|
4756
|
-
all(sessionID, after, type, through) {
|
|
4757
|
-
const rows = [];
|
|
4758
|
-
for (;; ) {
|
|
4759
|
-
const page = this.page(sessionID, { after, through, type });
|
|
4760
|
-
rows.push(...page.rows);
|
|
4761
|
-
if (page.rows.length < 100 || page.cursor === undefined)
|
|
4762
|
-
return rows;
|
|
4763
|
-
after = page.cursor;
|
|
4764
|
-
}
|
|
4765
|
-
}
|
|
4766
|
-
}
|
|
4767
|
-
|
|
4768
2816
|
// ../plugin/src/features/magic-context/resolve-subagent-fallback.ts
|
|
4769
2817
|
function resolveIsSubagentFromOpenCodeDb(sessionId) {
|
|
4770
2818
|
try {
|
|
@@ -4844,17 +2892,48 @@ function findSessionMeta(db, sessionId) {
|
|
|
4844
2892
|
function readSessionMeta(db, sessionId) {
|
|
4845
2893
|
return findSessionMeta(db, sessionId) ?? getDefaultSessionMeta(sessionId);
|
|
4846
2894
|
}
|
|
2895
|
+
var parentReadRetries = new WeakMap;
|
|
2896
|
+
var PARENT_READ_ATTEMPTS = 5;
|
|
2897
|
+
var PARENT_READ_COOLDOWN_MS = 30000;
|
|
4847
2898
|
function getOrCreateSessionMeta(db, sessionId) {
|
|
4848
2899
|
const existing = findSessionMeta(db, sessionId);
|
|
4849
|
-
if (existing)
|
|
4850
|
-
return existing;
|
|
4851
|
-
const defaults = getDefaultSessionMeta(sessionId);
|
|
4852
2900
|
const harness = getHarness2();
|
|
2901
|
+
if (existing) {
|
|
2902
|
+
if (harness !== "opencode2")
|
|
2903
|
+
return existing;
|
|
2904
|
+
const row = db.prepare("SELECT is_subagent FROM session_meta WHERE session_id = ?").get(sessionId);
|
|
2905
|
+
if (row.is_subagent !== null)
|
|
2906
|
+
return existing;
|
|
2907
|
+
}
|
|
2908
|
+
const defaults = existing ?? getDefaultSessionMeta(sessionId);
|
|
2909
|
+
let retries = parentReadRetries.get(db);
|
|
2910
|
+
if (harness === "opencode2") {
|
|
2911
|
+
if (!retries) {
|
|
2912
|
+
retries = new BoundedSessionMap(1000);
|
|
2913
|
+
parentReadRetries.set(db, retries);
|
|
2914
|
+
}
|
|
2915
|
+
const retry = retries.get(sessionId);
|
|
2916
|
+
if (retry && retry.attempts >= PARENT_READ_ATTEMPTS && Date.now() - retry.at < PARENT_READ_COOLDOWN_MS)
|
|
2917
|
+
return defaults;
|
|
2918
|
+
}
|
|
4853
2919
|
const fallbackSubagent = harness === "opencode" ? resolveIsSubagentFromOpenCodeDb(sessionId) : harness === "opencode2" ? resolveIsSubagentFromOpenCode2Db(sessionId) : null;
|
|
4854
2920
|
if (fallbackSubagent === true) {
|
|
4855
2921
|
defaults.isSubagent = true;
|
|
4856
2922
|
}
|
|
4857
|
-
|
|
2923
|
+
if (harness === "opencode2") {
|
|
2924
|
+
if (fallbackSubagent === null) {
|
|
2925
|
+
const previous = retries?.get(sessionId);
|
|
2926
|
+
const attempts = previous && Date.now() - previous.at < PARENT_READ_COOLDOWN_MS ? previous.attempts + 1 : 1;
|
|
2927
|
+
retries?.set(sessionId, { attempts, at: Date.now() });
|
|
2928
|
+
ensureSessionMetaRow(db, sessionId, null);
|
|
2929
|
+
return defaults;
|
|
2930
|
+
}
|
|
2931
|
+
retries?.delete(sessionId);
|
|
2932
|
+
ensureSessionMetaRow(db, sessionId, fallbackSubagent);
|
|
2933
|
+
db.prepare("UPDATE session_meta SET is_subagent = ? WHERE session_id = ? AND is_subagent IS NULL").run(fallbackSubagent ? 1 : 0, sessionId);
|
|
2934
|
+
return defaults;
|
|
2935
|
+
}
|
|
2936
|
+
ensureSessionMetaRow(db, sessionId);
|
|
4858
2937
|
if (harness === "opencode" && fallbackSubagent === true) {
|
|
4859
2938
|
db.prepare("UPDATE session_meta SET is_subagent = 1 WHERE session_id = ?").run(sessionId);
|
|
4860
2939
|
}
|
|
@@ -4950,14 +3029,18 @@ function clearSession(db, sessionId, rustModuleCleanupAcknowledged = false, perm
|
|
|
4950
3029
|
cancelAutoSearchWork(sessionId);
|
|
4951
3030
|
let transactionStartedAt = 0;
|
|
4952
3031
|
let clearedMarker = null;
|
|
3032
|
+
let eligibleSessions = 0;
|
|
4953
3033
|
withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(() => db.transaction(() => {
|
|
4954
3034
|
transactionStartedAt = performance.now();
|
|
4955
3035
|
clearedMarker = getPendingPiCompactionMarkerState(db, sessionId);
|
|
4956
|
-
deleteSessionScopedRows(db, [sessionId], undefined, {
|
|
3036
|
+
eligibleSessions = deleteSessionScopedRows(db, [sessionId], undefined, {
|
|
4957
3037
|
rustModuleCleanupAcknowledged,
|
|
4958
|
-
preserveTagRevisionTombstones: !permanentlyDeleted
|
|
3038
|
+
preserveTagRevisionTombstones: !permanentlyDeleted,
|
|
3039
|
+
deferRecoveryFenceCleanup: true
|
|
4959
3040
|
});
|
|
4960
3041
|
}).immediate()));
|
|
3042
|
+
if (eligibleSessions > 0)
|
|
3043
|
+
clearLkgRecoveryFence(sessionId);
|
|
4961
3044
|
if (clearedMarker)
|
|
4962
3045
|
logPiCompactionMarkerClear(sessionId, clearedMarker, "session-reset");
|
|
4963
3046
|
clearUnpublishedAutoSearchNoHints(sessionId);
|
|
@@ -5291,8 +3374,8 @@ function isPartialCompartmentEnd(db, sessionId, messageId) {
|
|
|
5291
3374
|
return Boolean(db.prepare("SELECT 1 FROM compartments WHERE session_id=? AND end_message_id=? AND end_block_index IS NOT NULL LIMIT 1").get(sessionId, messageId));
|
|
5292
3375
|
}
|
|
5293
3376
|
// ../plugin/src/features/magic-context/project-docs-hash.ts
|
|
5294
|
-
import { createHash
|
|
5295
|
-
import { lstatSync, readFileSync as readFileSync6, statSync as
|
|
3377
|
+
import { createHash } from "node:crypto";
|
|
3378
|
+
import { lstatSync, readFileSync as readFileSync6, statSync as statSync3 } from "node:fs";
|
|
5296
3379
|
import path from "node:path";
|
|
5297
3380
|
var PROJECT_DOC_FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
5298
3381
|
var PROJECT_DOCS_DELIMITER = `
|
|
@@ -5324,7 +3407,7 @@ function fingerprintFile(filePath) {
|
|
|
5324
3407
|
}
|
|
5325
3408
|
function readDirectoryMtimeMs(projectDirectory) {
|
|
5326
3409
|
try {
|
|
5327
|
-
return
|
|
3410
|
+
return statSync3(projectDirectory).mtimeMs;
|
|
5328
3411
|
} catch {
|
|
5329
3412
|
return 0;
|
|
5330
3413
|
}
|
|
@@ -5390,7 +3473,7 @@ function hashCanonicalPieces(hashPieces) {
|
|
|
5390
3473
|
if (hashPieces.length === 0) {
|
|
5391
3474
|
return "";
|
|
5392
3475
|
}
|
|
5393
|
-
return
|
|
3476
|
+
return createHash("sha256").update(hashPieces.join(PROJECT_DOCS_DELIMITER), "utf8").digest("hex");
|
|
5394
3477
|
}
|
|
5395
3478
|
function readProjectDocsCanonical(projectDirectory) {
|
|
5396
3479
|
canonicalReadCountForTests += 1;
|
|
@@ -5416,7 +3499,7 @@ function readProjectDocsCanonical(projectDirectory) {
|
|
|
5416
3499
|
return { renderedBlock, canonicalHash };
|
|
5417
3500
|
}
|
|
5418
3501
|
// ../plugin/src/hooks/magic-context/lkg-slot.ts
|
|
5419
|
-
import { createHash as
|
|
3502
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
5420
3503
|
|
|
5421
3504
|
// ../plugin/src/shared/provider-response-completion.ts
|
|
5422
3505
|
function providerResponseFailed(input) {
|
|
@@ -5584,7 +3667,7 @@ function clearCapturedLkgMeasurement(sessionId) {
|
|
|
5584
3667
|
}
|
|
5585
3668
|
|
|
5586
3669
|
// ../plugin/src/hooks/magic-context/lkg-persist.ts
|
|
5587
|
-
import { createHash as
|
|
3670
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
5588
3671
|
function parseStringArray(value) {
|
|
5589
3672
|
if (typeof value !== "string")
|
|
5590
3673
|
return null;
|
|
@@ -5698,7 +3781,7 @@ function rememberFingerprint(db, sessionId, fingerprint) {
|
|
|
5698
3781
|
saved.set(sessionId, fingerprint);
|
|
5699
3782
|
}
|
|
5700
3783
|
function slotFingerprint(slot) {
|
|
5701
|
-
return
|
|
3784
|
+
return createHash2("sha256").update(JSON.stringify([
|
|
5702
3785
|
slot.jsonPrefix,
|
|
5703
3786
|
slot.inputIdSeq,
|
|
5704
3787
|
slot.inputContentDigests,
|
|
@@ -6362,7 +4445,7 @@ var DIGEST_CHUNK_BYTES = 64 * 1024;
|
|
|
6362
4445
|
var digestChunk;
|
|
6363
4446
|
function lkgContentDigestFromFields(fields) {
|
|
6364
4447
|
lkgDigestsComputed += 1;
|
|
6365
|
-
const hash =
|
|
4448
|
+
const hash = createHash3("sha256");
|
|
6366
4449
|
digestChunk ??= Buffer.allocUnsafe(DIGEST_CHUNK_BYTES);
|
|
6367
4450
|
const chunk = digestChunk;
|
|
6368
4451
|
let offset = 0;
|
|
@@ -6425,7 +4508,7 @@ function legacyLkgDigestFromFields(fields) {
|
|
|
6425
4508
|
const value = typeof field === "symbol" ? field.description ?? "" : String(field);
|
|
6426
4509
|
key += `${typeof field}:${value.length}:${value}\x00`;
|
|
6427
4510
|
}
|
|
6428
|
-
return
|
|
4511
|
+
return createHash3("sha256").update(key).digest("base64url");
|
|
6429
4512
|
}
|
|
6430
4513
|
function legacyLkgContentDigest(message) {
|
|
6431
4514
|
const fields = flattenContentFields(withoutEmptyUserDiffSummary(message));
|
|
@@ -7978,9 +6061,9 @@ function formatNoteNudge(args) {
|
|
|
7978
6061
|
}
|
|
7979
6062
|
|
|
7980
6063
|
// ../plugin/src/shared/prompt-surface-runtime.ts
|
|
7981
|
-
import { createHash as
|
|
7982
|
-
import { existsSync as existsSync5, readFileSync as readFileSync7, statSync as
|
|
7983
|
-
import { dirname as dirname4, isAbsolute as isAbsolute3, resolve as
|
|
6064
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
6065
|
+
import { existsSync as existsSync5, readFileSync as readFileSync7, statSync as statSync4 } from "node:fs";
|
|
6066
|
+
import { dirname as dirname4, isAbsolute as isAbsolute3, resolve as resolve2 } from "node:path";
|
|
7984
6067
|
|
|
7985
6068
|
// ../plugin/src/tools/light-descriptions.ts
|
|
7986
6069
|
var CTX_REDUCE_LIGHT_DESCRIPTION = `Stamp an item as no longer needed for the work ahead. Not a delete: stamping QUEUES it, the item stays readable until Magic Context clears stamped items in one sweep, newest tags are protected, and a cleared item goes to the archive (recent: a [dropped §N§] placeholder; older: removed) recoverable via ctx_expand(tag=N). The question is "does this need to stay on my desk for what comes next?" — a file you keep editing stays, the grep that found it goes. Stamp used reads/searches/outputs, acted-on build/test output, redundant dumps, extracted pasted payloads; keep user messages, your own text, unresolved errors, raw evidence, exact wording that may matter. Look at each tag; never blanket-stamp "1-50". Grammar: "3-5", "1,2,9", "1-5,8,12-15".`;
|
|
@@ -8011,12 +6094,12 @@ function promptSurfaceHashMaterial(systemContent, preset = "full") {
|
|
|
8011
6094
|
\x00magic-context-prompt-surface:${preset}`;
|
|
8012
6095
|
}
|
|
8013
6096
|
function systemPromptFingerprint(systemContent, preset = "full") {
|
|
8014
|
-
return
|
|
6097
|
+
return createHash4("md5").update(promptSurfaceHashMaterial(systemContent, preset)).digest("hex");
|
|
8015
6098
|
}
|
|
8016
6099
|
var PROMPT_SURFACE_TOOL_ID_SET = new Set(ACTIVE_TOOL_IDS);
|
|
8017
6100
|
function resolveUserConfigDirectory(options) {
|
|
8018
6101
|
if (options.userConfigDirectory)
|
|
8019
|
-
return
|
|
6102
|
+
return resolve2(options.userConfigDirectory);
|
|
8020
6103
|
const sharedBase = cortexKitUserConfigBasePath();
|
|
8021
6104
|
const shared = detectConfigFile(sharedBase);
|
|
8022
6105
|
if (shared.format !== "none")
|
|
@@ -8043,10 +6126,10 @@ function createPromptSurfaceRuntime(options) {
|
|
|
8043
6126
|
const readGuidanceOverride = (configuredPath) => {
|
|
8044
6127
|
if (!configuredPath)
|
|
8045
6128
|
return;
|
|
8046
|
-
const path = isAbsolute3(configuredPath) ? configuredPath :
|
|
6129
|
+
const path = isAbsolute3(configuredPath) ? configuredPath : resolve2(userConfigDirectory, configuredPath);
|
|
8047
6130
|
let content;
|
|
8048
6131
|
try {
|
|
8049
|
-
if (!
|
|
6132
|
+
if (!statSync4(path).isFile()) {
|
|
8050
6133
|
warnOnce(`guidance-not-file:${path}`, `prompt_surface.guidance_override_path (${path}) is not a file; using built-in guidance.`);
|
|
8051
6134
|
return;
|
|
8052
6135
|
}
|
|
@@ -8125,7 +6208,7 @@ function createPromptSurfaceGuidanceEpochCache(runtime) {
|
|
|
8125
6208
|
}
|
|
8126
6209
|
|
|
8127
6210
|
// src/read-session-pi.ts
|
|
8128
|
-
import { createHash as
|
|
6211
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
8129
6212
|
var SYNTH_USER_ID_PREFIX = "synth-user-";
|
|
8130
6213
|
function resolvePiStableId(msg, index, entryIds, entryIdByRef) {
|
|
8131
6214
|
if (!msg || typeof msg !== "object")
|
|
@@ -8164,7 +6247,7 @@ function piContentFallbackIds(messages, resolveReal) {
|
|
|
8164
6247
|
return;
|
|
8165
6248
|
const m = message;
|
|
8166
6249
|
const role = typeof m.role === "string" ? m.role : "unknown";
|
|
8167
|
-
const digest =
|
|
6250
|
+
const digest = createHash5("sha256").update(stableStringify([
|
|
8168
6251
|
typeof m.responseId === "string" ? m.responseId : null,
|
|
8169
6252
|
typeof m.timestamp === "number" || typeof m.timestamp === "string" ? m.timestamp : null,
|
|
8170
6253
|
role,
|
|
@@ -9115,7 +7198,7 @@ function compareMemorySelectionPriority(left, right) {
|
|
|
9115
7198
|
}
|
|
9116
7199
|
|
|
9117
7200
|
// ../plugin/src/features/magic-context/mural/render-trigger.ts
|
|
9118
|
-
import { createHash as
|
|
7201
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
9119
7202
|
|
|
9120
7203
|
// ../plugin/src/features/magic-context/mural/mural-selection.ts
|
|
9121
7204
|
var DEFAULT_MURAL_MEMORY_BUDGET = 8000;
|
|
@@ -9804,7 +7887,7 @@ function ensureMuralRendered(db, projectIdentity, budgetTokens = DEFAULT_MURAL_M
|
|
|
9804
7887
|
return { ...cached.result };
|
|
9805
7888
|
}
|
|
9806
7889
|
const plan = planMuralRender(entries);
|
|
9807
|
-
const textHash =
|
|
7890
|
+
const textHash = createHash6("sha256").update(plan.layout.text).digest("hex");
|
|
9808
7891
|
if (existing && existing.contentHash === textHash && existing.width === plan.width && existing.height === plan.height) {
|
|
9809
7892
|
return rememberRender(db, projectIdentity, key, existing.image, {
|
|
9810
7893
|
hasMural: true,
|
|
@@ -9861,14 +7944,14 @@ function resolveMuralWire(db, projectIdentity, modelKey, enabled, budgetTokens =
|
|
|
9861
7944
|
}
|
|
9862
7945
|
|
|
9863
7946
|
// ../plugin/src/features/magic-context/compaction-marker.ts
|
|
9864
|
-
import { createHash as
|
|
9865
|
-
import { existsSync as existsSync6, statSync as
|
|
7947
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
7948
|
+
import { existsSync as existsSync6, statSync as statSync5 } from "node:fs";
|
|
9866
7949
|
var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
9867
7950
|
var ID_PREFIX_HEX_LENGTH = 12;
|
|
9868
7951
|
var ID_SUFFIX_LENGTH = 14;
|
|
9869
7952
|
var ID_PREFIX_MASK = (1n << BigInt(ID_PREFIX_HEX_LENGTH * 4)) - 1n;
|
|
9870
7953
|
function deterministicBase62(seed, length) {
|
|
9871
|
-
let value = BigInt(`0x${
|
|
7954
|
+
let value = BigInt(`0x${createHash7("sha256").update(seed).digest("hex")}`);
|
|
9872
7955
|
const chars = Array(length);
|
|
9873
7956
|
for (let index = length - 1;index >= 0; index -= 1) {
|
|
9874
7957
|
chars[index] = BASE62_CHARS[Number(value % 62n)];
|
|
@@ -9931,7 +8014,7 @@ function runMarkerWriteTransaction(db, site, operation) {
|
|
|
9931
8014
|
function markerWalPages(db) {
|
|
9932
8015
|
try {
|
|
9933
8016
|
const row = db.prepare("PRAGMA page_size").get();
|
|
9934
|
-
const bytes =
|
|
8017
|
+
const bytes = statSync5(`${getOpenCodeDbPath()}-wal`).size;
|
|
9935
8018
|
return Math.max(0, Math.floor((bytes - 32) / (row.page_size + 24)));
|
|
9936
8019
|
} catch {
|
|
9937
8020
|
return null;
|
|
@@ -11117,10 +9200,10 @@ async function wakePlaneStatus() {
|
|
|
11117
9200
|
}
|
|
11118
9201
|
|
|
11119
9202
|
// src/embedding-bootstrap.ts
|
|
11120
|
-
import { statSync as
|
|
9203
|
+
import { statSync as statSync6 } from "node:fs";
|
|
11121
9204
|
|
|
11122
9205
|
// ../plugin/src/plugin/embedding-bootstrap-helpers.ts
|
|
11123
|
-
import { createHash as
|
|
9206
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
11124
9207
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
11125
9208
|
"embedding.api_key",
|
|
11126
9209
|
"embedding.endpoint",
|
|
@@ -11168,7 +9251,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
11168
9251
|
];
|
|
11169
9252
|
var loggedFailureSignatures = new Map;
|
|
11170
9253
|
function sha256Prefix(value, length = 16) {
|
|
11171
|
-
return
|
|
9254
|
+
return createHash8("sha256").update(value).digest("hex").slice(0, length);
|
|
11172
9255
|
}
|
|
11173
9256
|
function warningLooksEmbeddingRelated(message) {
|
|
11174
9257
|
const lower = message.toLowerCase();
|
|
@@ -11829,7 +9912,7 @@ function configCandidatePaths(directory, loadedPaths) {
|
|
|
11829
9912
|
function configFingerprint(paths) {
|
|
11830
9913
|
return paths.map((path) => {
|
|
11831
9914
|
try {
|
|
11832
|
-
const stat =
|
|
9915
|
+
const stat = statSync6(path);
|
|
11833
9916
|
return `${path}:${stat.size}:${stat.mtimeMs}`;
|
|
11834
9917
|
} catch {
|
|
11835
9918
|
return `${path}:missing`;
|
|
@@ -11901,7 +9984,7 @@ async function ensureProjectRegisteredFromPiDirectory(directory, db) {
|
|
|
11901
9984
|
|
|
11902
9985
|
// src/pi-harness-kind.ts
|
|
11903
9986
|
import { existsSync as existsSync8, readFileSync as readFileSync8, realpathSync as realpathSync2 } from "node:fs";
|
|
11904
|
-
import { dirname as dirname5, join as join5, parse as
|
|
9987
|
+
import { dirname as dirname5, join as join5, parse as parse2, resolve as resolve3 } from "node:path";
|
|
11905
9988
|
import { pathToFileURL } from "node:url";
|
|
11906
9989
|
var OMP_UTILS_MODULE = "@oh-my-pi/pi-utils";
|
|
11907
9990
|
var OMP_HOST_PACKAGE = "@oh-my-pi/pi-coding-agent";
|
|
@@ -11917,7 +10000,7 @@ function hostEntries() {
|
|
|
11917
10000
|
for (const candidate of [process.argv[1], process.execPath]) {
|
|
11918
10001
|
if (!candidate)
|
|
11919
10002
|
continue;
|
|
11920
|
-
const requestedPath =
|
|
10003
|
+
const requestedPath = resolve3(candidate);
|
|
11921
10004
|
let resolvedPath;
|
|
11922
10005
|
try {
|
|
11923
10006
|
resolvedPath = realpathSync2(requestedPath);
|
|
@@ -11940,7 +10023,7 @@ function readPackageJson(path) {
|
|
|
11940
10023
|
}
|
|
11941
10024
|
function nearestPackageName(entryPath) {
|
|
11942
10025
|
let directory = dirname5(entryPath);
|
|
11943
|
-
const root =
|
|
10026
|
+
const root = parse2(directory).root;
|
|
11944
10027
|
while (true) {
|
|
11945
10028
|
const packagePath = join5(directory, "package.json");
|
|
11946
10029
|
if (existsSync8(packagePath)) {
|
|
@@ -11967,7 +10050,7 @@ function packageNameDetection(entries) {
|
|
|
11967
10050
|
function dependencyPackageRoot(entryPath, moduleName) {
|
|
11968
10051
|
const moduleParts = moduleName.split("/");
|
|
11969
10052
|
let directory = dirname5(entryPath);
|
|
11970
|
-
const root =
|
|
10053
|
+
const root = parse2(directory).root;
|
|
11971
10054
|
while (true) {
|
|
11972
10055
|
const packageRoot = join5(directory, "node_modules", ...moduleParts);
|
|
11973
10056
|
if (existsSync8(join5(packageRoot, "package.json")))
|
|
@@ -11997,7 +10080,7 @@ function hostModuleImportUrl(entryPath) {
|
|
|
11997
10080
|
const target = importTarget(packageJson?.exports) ?? (typeof packageJson?.module === "string" ? packageJson.module : typeof packageJson?.main === "string" ? packageJson.main : undefined);
|
|
11998
10081
|
if (!target?.startsWith("./"))
|
|
11999
10082
|
return;
|
|
12000
|
-
return pathToFileURL(
|
|
10083
|
+
return pathToFileURL(resolve3(packageRoot, target)).href;
|
|
12001
10084
|
}
|
|
12002
10085
|
async function appNameDetection(entries) {
|
|
12003
10086
|
for (const entry of entries) {
|
|
@@ -12420,7 +10503,7 @@ function resolveCtxExpandMode(args, domain) {
|
|
|
12420
10503
|
}
|
|
12421
10504
|
|
|
12422
10505
|
// ../plugin/src/tools/ctx-expand/render.ts
|
|
12423
|
-
import { createHash as
|
|
10506
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
12424
10507
|
function isRecord3(value) {
|
|
12425
10508
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12426
10509
|
}
|
|
@@ -12644,7 +10727,7 @@ function renderItemByTag(db, sessionId, number, textIndexDomain = "part") {
|
|
|
12644
10727
|
const index = scoped ? Number(scoped[2]) : 0;
|
|
12645
10728
|
const piText = message.parts.filter((part) => isRecord3(part) && part.type === "text");
|
|
12646
10729
|
const part = message.parts[index];
|
|
12647
|
-
const matching = derived ? piText.filter((part) => isRecord3(part) && typeof part.text === "string" &&
|
|
10730
|
+
const matching = derived ? piText.filter((part) => isRecord3(part) && typeof part.text === "string" && createHash9("sha256").update(part.text).digest("hex") === derived[3]) : [];
|
|
12648
10731
|
const selected = derived ? matching[Number(derived[4])] : textIndexDomain === "text" ? piText[index] : part;
|
|
12649
10732
|
return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
|
|
12650
10733
|
}
|
|
@@ -13737,7 +11820,7 @@ import { isAbsolute as isAbsolute5 } from "node:path";
|
|
|
13737
11820
|
// ../retina-local-fs/src/path-fence.ts
|
|
13738
11821
|
import { lstat, realpath } from "node:fs/promises";
|
|
13739
11822
|
import { homedir as homedir3 } from "node:os";
|
|
13740
|
-
import { basename as basename3, dirname as dirname6, isAbsolute as isAbsolute4, join as join6, relative, resolve as
|
|
11823
|
+
import { basename as basename3, dirname as dirname6, isAbsolute as isAbsolute4, join as join6, relative, resolve as resolve4, sep } from "node:path";
|
|
13741
11824
|
|
|
13742
11825
|
// ../retina-local-fs/src/errors.ts
|
|
13743
11826
|
class ProviderError extends Error {
|
|
@@ -13753,7 +11836,7 @@ class ProviderError extends Error {
|
|
|
13753
11836
|
async function resolveAndFenceProviderPath(configuredPath, options) {
|
|
13754
11837
|
const { home, dataDirectory, aliases } = await resolveFenceRoots(options);
|
|
13755
11838
|
const expanded = configuredPath.startsWith("~/") ? join6(home, configuredPath.slice(2)) : configuredPath === "~" ? home : configuredPath;
|
|
13756
|
-
const absolute = isAbsolute4(expanded) ?
|
|
11839
|
+
const absolute = isAbsolute4(expanded) ? resolve4(expanded) : resolve4(options.cwd ?? process.cwd(), expanded);
|
|
13757
11840
|
const canonical = await canonicalPath(absolute, options.allowMissing);
|
|
13758
11841
|
if (fenceCandidates(canonical, aliases).some((candidate) => isFencedPath(candidate, home, dataDirectory))) {
|
|
13759
11842
|
throw new ProviderError("fenced_path", `Refusing fenced path: ${canonical}`);
|
|
@@ -13762,14 +11845,14 @@ async function resolveAndFenceProviderPath(configuredPath, options) {
|
|
|
13762
11845
|
}
|
|
13763
11846
|
var FENCED_CORTEXKIT_ROOTS = ["plexus", "claustrum", "staging", "run", "magic-context"];
|
|
13764
11847
|
async function resolveFenceRoots(options) {
|
|
13765
|
-
const configuredHomePath =
|
|
11848
|
+
const configuredHomePath = resolve4(options.homeDirectory ?? process.env.HOME ?? homedir3());
|
|
13766
11849
|
let home;
|
|
13767
11850
|
try {
|
|
13768
11851
|
home = await realpath(configuredHomePath);
|
|
13769
11852
|
} catch (error) {
|
|
13770
11853
|
throw fsError(configuredHomePath, error);
|
|
13771
11854
|
}
|
|
13772
|
-
const configuredDataDirectory =
|
|
11855
|
+
const configuredDataDirectory = resolve4(options.dataDirectory ?? process.env.XDG_DATA_HOME ?? join6(home, ".local", "share"));
|
|
13773
11856
|
const dataDirectory = await canonicalPath(configuredDataDirectory, true);
|
|
13774
11857
|
const aliases = [];
|
|
13775
11858
|
const logicalCortexkit = join6(dataDirectory, "cortexkit");
|
|
@@ -13829,8 +11912,8 @@ async function canonicalPath(path, allowMissing) {
|
|
|
13829
11912
|
}
|
|
13830
11913
|
}
|
|
13831
11914
|
}
|
|
13832
|
-
function isFencedPath(canonicalPath, homeDirectory, dataDirectory = process.env.XDG_DATA_HOME ?? join6(
|
|
13833
|
-
const cortexkitRoot = join6(
|
|
11915
|
+
function isFencedPath(canonicalPath, homeDirectory, dataDirectory = process.env.XDG_DATA_HOME ?? join6(resolve4(homeDirectory), ".local", "share")) {
|
|
11916
|
+
const cortexkitRoot = join6(resolve4(dataDirectory), "cortexkit");
|
|
13834
11917
|
const relativeToCortexkit = relative(cortexkitRoot, canonicalPath);
|
|
13835
11918
|
const insideCortexkit = relativeToCortexkit !== "" && relativeToCortexkit !== ".." && !relativeToCortexkit.startsWith(`..${sep}`) && !isAbsolute4(relativeToCortexkit);
|
|
13836
11919
|
const parts = insideCortexkit ? relativeToCortexkit.split(sep) : [];
|