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