@cortexkit/pi-magic-context 0.49.34 → 0.49.35
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 +11 -6
- package/dist/chunk-embedding-write-worker.js +16 -13
- package/dist/{compaction-marker-candidates-p1kqkqhq.js → compaction-marker-candidates-hk2frhac.js} +3 -2
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-8c85ebce.js → compartment-chunk-embedding-5j1d1e3v.js} +8 -7
- package/dist/embedding-backfill-jt459ady.js +26 -0
- package/dist/embedding-worker-process.js +2 -1
- package/dist/embedding-worker.js +5 -4
- package/dist/expand-attachments-8sxeyj26.js +21 -0
- package/dist/historian-calibration-extension.js +2 -1
- package/dist/{index-0mc0vv97.js → index-0rvn6vhq.js} +3 -3
- package/dist/{index-hqw0rt9k.js → index-0wtm7g7f.js} +1 -1
- package/dist/{index-np9ryr8y.js → index-11knwv2h.js} +20 -240
- package/dist/{index-0gymvr5j.js → index-2p691ayw.js} +19 -8
- package/dist/{index-wqpjhx1p.js → index-2qqsnh1b.js} +2 -2
- package/dist/index-3bb24eb6.js +229 -0
- package/dist/{index-48twbev2.js → index-6pk49fc3.js} +37 -51
- package/dist/index-6y6v2wvn.js +194 -0
- package/dist/{index-e61zxfts.js → index-8m82cez2.js} +4 -4
- package/dist/{index-xn5yh0pn.js → index-a11nmw5t.js} +29 -128
- package/dist/index-by1bzjcd.js +24 -0
- package/dist/index-c6wbq66z.js +168 -0
- package/dist/{index-jn44h81p.js → index-cq71g4dk.js} +1 -1
- package/dist/{index-6wdwv3a6.js → index-d0w84hy5.js} +1 -1
- package/dist/{index-pb3ea2tq.js → index-d107f484.js} +5 -5
- package/dist/index-d21rhpbd.js +4171 -0
- package/dist/index-dnp1jjar.js +222 -0
- package/dist/index-ea37qn4x.js +777 -0
- package/dist/{index-f4fz95fy.js → index-fzm8fm4z.js} +303 -4980
- package/dist/{index-fgs78jyd.js → index-gymgz20n.js} +5 -222
- package/dist/index-hgd00nas.js +113 -0
- package/dist/{index-cj3bkd16.js → index-m68qfjte.js} +2 -2
- package/dist/{index-6981g1xv.js → index-mkh1cm5k.js} +1 -1
- package/dist/{index-4zemngt7.js → index-mp0gh04g.js} +2 -2
- package/dist/{index-23t8ryqw.js → index-n0zjvs3h.js} +1 -168
- package/dist/{index-bvpar0bg.js → index-rgvqh5x7.js} +2 -2
- package/dist/{index-gwxaz0z5.js → index-rzfr7wdv.js} +2 -2
- package/dist/{index-eenxm3t3.js → index-svqk0701.js} +40 -29
- package/dist/{index-9xd7qveg.js → index-vgfk2xa5.js} +4 -4
- package/dist/index-w26zvs1q.js +528 -0
- package/dist/index-wrr9rp9a.js +16 -0
- package/dist/{index-my0dn413.js → index-wt7vmyj4.js} +1 -1
- package/dist/{index-c474g0gj.js → index-yacs388s.js} +1 -1
- package/dist/{index-g2tfayfc.js → index-yg42q9bc.js} +95 -550
- package/dist/{index-eqw9t2ty.js → index-yhsmjvqa.js} +3 -3
- package/dist/index.js +523 -236
- package/dist/{logger-shetp43v.js → logger-2j70hhz4.js} +2 -1
- package/dist/{message-fts-rowid-map-3mbvdgn9.js → message-fts-rowid-map-aw4xa05a.js} +5 -4
- package/dist/{message-index-bounded-a6na71rg.js → message-index-bounded-da34vhs4.js} +12 -10
- package/dist/{message-time-backfill-e3r8ddh1.js → message-time-backfill-x45573rs.js} +3 -2
- package/dist/migration-worker.js +13 -10
- package/dist/{project-embedding-registry-acqb6be4.js → project-embedding-registry-davzvsz9.js} +13 -11
- package/dist/raw-ordinal-warmup-worker.js +12 -7
- package/dist/{read-session-chunk-2xcp6f40.js → read-session-chunk-nbcznexm.js} +14 -8
- package/dist/{read-session-raw-g9b1zdn5.js → read-session-raw-zb8kpa2y.js} +3 -2
- package/dist/render-d931g2vv.js +41 -0
- package/dist/{safe-notification-target-zcpchea6.js → safe-notification-target-jk69jxwp.js} +3 -2
- package/dist/search-archive-a76pp30g.js +24 -0
- package/dist/{search-b6hp64hc.js → search-atp7g95j.js} +24 -20
- package/dist/{storage-tags-6409qq18.js → storage-tags-jy8b0xsy.js} +5 -4
- package/dist/store-kabezr25.js +453 -0
- package/dist/store-reader-2m80zs5z.js +14 -0
- package/dist/subagent-entry.js +31 -23
- package/dist/tag-snapshot-worker-pi.js +15 -12
- package/dist/v2-archive-reader-wcjcfdzq.js +11 -0
- package/package.json +1 -1
- package/dist/embedding-backfill-rwfmyvze.js +0 -24
- package/dist/search-archive-jate39w5.js +0 -21
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getHarness2
|
|
3
3
|
} from "./index-0h2mkab2.js";
|
|
4
|
+
import {
|
|
5
|
+
sanitizeDiagnosticText,
|
|
6
|
+
sanitizeConfigValue
|
|
7
|
+
} from "./index-dnp1jjar.js";
|
|
4
8
|
|
|
5
9
|
// ../plugin/src/shared/logger.ts
|
|
6
10
|
import * as fs from "node:fs";
|
|
@@ -147,227 +151,6 @@ function getLegacyOpenCodeMagicContextStorageDir() {
|
|
|
147
151
|
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
// ../plugin/src/shared/redaction.ts
|
|
151
|
-
import { homedir as homedir2, userInfo } from "node:os";
|
|
152
|
-
function escapeRegex(value) {
|
|
153
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
154
|
-
}
|
|
155
|
-
var SECRET_WORDS = [
|
|
156
|
-
"key",
|
|
157
|
-
"token",
|
|
158
|
-
"secret",
|
|
159
|
-
"password",
|
|
160
|
-
"auth",
|
|
161
|
-
"authorization",
|
|
162
|
-
"bearer",
|
|
163
|
-
"credential"
|
|
164
|
-
];
|
|
165
|
-
var SECRET_SEGMENT_PATTERN = new RegExp(`^(?:${SECRET_WORDS.map((w) => `${w}s?`).join("|")})$`, "i");
|
|
166
|
-
var TRAILING_DESCRIPTORS = new Set(["id", "ids", "value", "values", "header", "headers"]);
|
|
167
|
-
function redactionTypeForKey(key) {
|
|
168
|
-
const normalized = key.trim().toLowerCase().replace(/[^a-z0-9_.-]+/g, "_");
|
|
169
|
-
const suffix = normalized.split(".").filter(Boolean).at(-1) ?? normalized;
|
|
170
|
-
return suffix || "secret";
|
|
171
|
-
}
|
|
172
|
-
function isNonSecretScalarValue(value) {
|
|
173
|
-
const v = value.trim();
|
|
174
|
-
if (v === "true" || v === "false" || v === "null" || v === "undefined")
|
|
175
|
-
return true;
|
|
176
|
-
return /^[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(v);
|
|
177
|
-
}
|
|
178
|
-
var SECRET_QUALIFIERS = new Set([
|
|
179
|
-
"api",
|
|
180
|
-
"access",
|
|
181
|
-
"private",
|
|
182
|
-
"client",
|
|
183
|
-
"auth",
|
|
184
|
-
"authorization",
|
|
185
|
-
"secret",
|
|
186
|
-
"bearer",
|
|
187
|
-
"session",
|
|
188
|
-
"refresh",
|
|
189
|
-
"service",
|
|
190
|
-
"x",
|
|
191
|
-
"openai",
|
|
192
|
-
"anthropic",
|
|
193
|
-
"google",
|
|
194
|
-
"github",
|
|
195
|
-
"huggingface",
|
|
196
|
-
"aws",
|
|
197
|
-
"azure",
|
|
198
|
-
"id"
|
|
199
|
-
]);
|
|
200
|
-
var UNQUALIFIED_SECRET_SEGMENT_PATTERN = /^(?:password|secret|credential|bearer|authorization)s?$/;
|
|
201
|
-
function isSecretKey(key) {
|
|
202
|
-
const segments = key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().split(/[._-]+/).filter(Boolean);
|
|
203
|
-
if (segments.length === 0)
|
|
204
|
-
return false;
|
|
205
|
-
if (segments.length === 1) {
|
|
206
|
-
const first = segments[0];
|
|
207
|
-
return Boolean(first && SECRET_SEGMENT_PATTERN.test(first));
|
|
208
|
-
}
|
|
209
|
-
for (let i = 0;i < segments.length; i++) {
|
|
210
|
-
const seg = segments[i];
|
|
211
|
-
if (!seg || !SECRET_SEGMENT_PATTERN.test(seg))
|
|
212
|
-
continue;
|
|
213
|
-
let trailingOk = true;
|
|
214
|
-
for (let j = i + 1;j < segments.length; j++) {
|
|
215
|
-
const tail = segments[j];
|
|
216
|
-
if (!tail)
|
|
217
|
-
continue;
|
|
218
|
-
if (TRAILING_DESCRIPTORS.has(tail))
|
|
219
|
-
continue;
|
|
220
|
-
if (SECRET_SEGMENT_PATTERN.test(tail))
|
|
221
|
-
continue;
|
|
222
|
-
trailingOk = false;
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
if (!trailingOk)
|
|
226
|
-
continue;
|
|
227
|
-
if (UNQUALIFIED_SECRET_SEGMENT_PATTERN.test(seg))
|
|
228
|
-
return true;
|
|
229
|
-
for (let k = i - 1;k >= 0; k--) {
|
|
230
|
-
const lead = segments[k];
|
|
231
|
-
if (lead && SECRET_QUALIFIERS.has(lead))
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
function sanitizePathString(value) {
|
|
238
|
-
const home = process.env.HOME || process.env.USERPROFILE || homedir2();
|
|
239
|
-
const username = userInfo().username;
|
|
240
|
-
let sanitized = value;
|
|
241
|
-
if (home) {
|
|
242
|
-
sanitized = sanitized.replace(new RegExp(escapeRegex(home), "g"), "~");
|
|
243
|
-
}
|
|
244
|
-
sanitized = sanitized.replace(/\/Users\/[^/]+\//g, "/Users/<USER>/");
|
|
245
|
-
sanitized = sanitized.replace(/\/home\/[^/]+\//g, "/home/<USER>/");
|
|
246
|
-
sanitized = sanitized.replace(/C:\\Users\\[^\\]+\\/g, "C:\\Users\\<USER>\\");
|
|
247
|
-
if (username) {
|
|
248
|
-
sanitized = sanitized.replace(new RegExp(escapeRegex(username), "g"), "<USER>");
|
|
249
|
-
}
|
|
250
|
-
return sanitized;
|
|
251
|
-
}
|
|
252
|
-
var SECRET_TEXT_PATTERNS = [
|
|
253
|
-
{
|
|
254
|
-
pattern: /\bsk-ant-(?:api03-)?[A-Za-z0-9_-]{32,}/g,
|
|
255
|
-
replacement: "<ANTHROPIC_API_KEY_REDACTED>"
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
pattern: /\bsk-(?:proj-)?[A-Za-z0-9_-]{12,}/g,
|
|
259
|
-
replacement: "<OPENAI_API_KEY_REDACTED>"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
pattern: /\bgithub_pat_[A-Za-z0-9_]{20,}/g,
|
|
263
|
-
replacement: "<GITHUB_PAT_REDACTED>"
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
pattern: /\b(?:gh[opsu]|ghr)_[A-Za-z0-9_-]{30,}/g,
|
|
267
|
-
replacement: "<GITHUB_TOKEN_REDACTED>"
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
pattern: /\bhf_[A-Za-z0-9]{30,}/g,
|
|
271
|
-
replacement: "<HUGGINGFACE_TOKEN_REDACTED>"
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
275
|
-
replacement: "<AWS_ACCESS_KEY_ID_REDACTED>"
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
pattern: /\bxox[abprsuvc]-[A-Za-z0-9-]{10,}/g,
|
|
279
|
-
replacement: "<SLACK_TOKEN_REDACTED>"
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
pattern: /\bAIza[A-Za-z0-9_-]{35}\b/g,
|
|
283
|
-
replacement: "<GOOGLE_API_KEY_REDACTED>"
|
|
284
|
-
},
|
|
285
|
-
{
|
|
286
|
-
pattern: /\b(Authorization\s*:\s*Bearer\s+)([A-Za-z0-9._~+/=-]{8,})/gi,
|
|
287
|
-
replacement: (_full, prefix) => `${prefix}<REDACTED:bearer>`
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
pattern: /\b((?:Proxy-)?Authorization\s*:\s*(?:Basic|Digest|Token|Negotiate|NTLM)\s+)([A-Za-z0-9._~+/=-]{4,})/gi,
|
|
291
|
-
replacement: (_full, prefix) => `${prefix}<REDACTED:authorization>`
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
pattern: /\b((?:x-)?(?:api-?key|api-?token|auth-?token|access-?token)\s*:\s*)([^\s'"`,;<>]{6,})/gi,
|
|
295
|
-
replacement: (full, prefix, value) => isNonSecretScalarValue(value) ? full : `${prefix}<REDACTED:api_key>`
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
pattern: /\b((?:api[_-]?key|client[_-]?secret|access[_-]?token|token|secret|password|passwd|pwd)\s*:\s*)([^\s'"`,;<>]{6,})/gi,
|
|
299
|
-
replacement: (full, prefix, value) => isNonSecretScalarValue(value) ? full : `${prefix}<REDACTED:credential>`
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
pattern: /\b([a-z][a-z0-9+.-]*:\/\/[^\s/:@]+:)([^\s/@]+)(@)/gi,
|
|
303
|
-
replacement: (_full, prefix, _password, at) => `${prefix}<REDACTED:password>${at}`
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
pattern: /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
307
|
-
replacement: "<JWT_REDACTED>"
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
pattern: /(["'])([^"']*(?:key|token|secret|password|auth|bearer|credential)[^"']*)\1(\s*:\s*)(["'])([^"']*)\4/gi,
|
|
311
|
-
replacement: (full, quote, key, separator, valueQuote, value) => isNonSecretScalarValue(value) ? full : `${quote}${key}${quote}${separator}${valueQuote}<REDACTED:${redactionTypeForKey(key)}>${valueQuote}`
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
pattern: /\b([A-Za-z0-9_.-]*(?:key|token|secret|password|auth|bearer|credential)[A-Za-z0-9_.-]*)\s*=\s*([^\s'"`]+)/gi,
|
|
315
|
-
replacement: (full, key, value) => isNonSecretScalarValue(value) ? full : `${key}=<REDACTED:${redactionTypeForKey(key)}>`
|
|
316
|
-
}
|
|
317
|
-
];
|
|
318
|
-
function redactSecretText(value) {
|
|
319
|
-
let redacted = value;
|
|
320
|
-
for (const { pattern, replacement } of SECRET_TEXT_PATTERNS) {
|
|
321
|
-
if (typeof replacement === "string") {
|
|
322
|
-
redacted = redacted.replace(pattern, replacement);
|
|
323
|
-
} else {
|
|
324
|
-
redacted = redacted.replace(pattern, replacement);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return redacted;
|
|
328
|
-
}
|
|
329
|
-
function sanitizeDiagnosticText(value) {
|
|
330
|
-
return redactSecretText(sanitizePathString(value));
|
|
331
|
-
}
|
|
332
|
-
var SHAREABILITY_SENSITIVE_PATTERNS = [
|
|
333
|
-
/\bC:\/Users\/[^/\s]+/i,
|
|
334
|
-
/(?:^|\s)~\/[^\s]+/,
|
|
335
|
-
/\b(?:api[_-]?key|secret|token|password|passwd|pwd|client[_-]?secret|access[_-]?key)\b\s*[:=]\s*\S+/i,
|
|
336
|
-
/\b(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(?::\d+)?\b/i,
|
|
337
|
-
/\b(?:10|127)\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/,
|
|
338
|
-
/\b192\.168\.\d{1,3}\.\d{1,3}\b/,
|
|
339
|
-
/\b172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}\b/
|
|
340
|
-
];
|
|
341
|
-
function hasShareabilitySensitiveText(text) {
|
|
342
|
-
try {
|
|
343
|
-
if (sanitizeDiagnosticText(text) !== text)
|
|
344
|
-
return true;
|
|
345
|
-
return SHAREABILITY_SENSITIVE_PATTERNS.some((pattern) => pattern.test(text));
|
|
346
|
-
} catch {
|
|
347
|
-
return true;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
function sanitizeConfigValue(value, keyPath = []) {
|
|
351
|
-
if (value === null || typeof value === "number" || typeof value === "boolean")
|
|
352
|
-
return value;
|
|
353
|
-
const key = keyPath.at(-1) ?? "";
|
|
354
|
-
if (key && isSecretKey(key)) {
|
|
355
|
-
return `<REDACTED:${redactionTypeForKey(key)}>`;
|
|
356
|
-
}
|
|
357
|
-
if (typeof value === "string")
|
|
358
|
-
return sanitizeDiagnosticText(value);
|
|
359
|
-
if (Array.isArray(value)) {
|
|
360
|
-
return value.map((entry, index) => sanitizeConfigValue(entry, [...keyPath, String(index)]));
|
|
361
|
-
}
|
|
362
|
-
if (value && typeof value === "object") {
|
|
363
|
-
return Object.fromEntries(Object.entries(value).map(([entryKey, entry]) => [
|
|
364
|
-
entryKey,
|
|
365
|
-
sanitizeConfigValue(entry, [...keyPath, entryKey])
|
|
366
|
-
]));
|
|
367
|
-
}
|
|
368
|
-
return value;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
154
|
// ../plugin/src/shared/stale-plugin-build.ts
|
|
372
155
|
import { posix } from "node:path";
|
|
373
156
|
import { fileURLToPath } from "node:url";
|
|
@@ -696,4 +479,4 @@ if (!isTestEnv) {
|
|
|
696
479
|
process.on("exit", flush);
|
|
697
480
|
}
|
|
698
481
|
|
|
699
|
-
export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, isMagicContextStorageOutsideEngram, claimStorageBackupWarningCheck, getLegacyOpenCodeMagicContextStorageDir,
|
|
482
|
+
export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, isMagicContextStorageOutsideEngram, claimStorageBackupWarningCheck, getLegacyOpenCodeMagicContextStorageDir, registerStalePluginBuildHost, classifyStalePluginBuild, importPluginModule, setLogLineForwarder2, writeForwardedLogLine2, log2, sessionLog2, getLoggerDiagnostics2, flushLogger2, getLogFilePath2 };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withSqliteBackgroundWriter2,
|
|
3
|
+
withoutSqliteTransformPass2,
|
|
4
|
+
isTransientSqliteError2
|
|
5
|
+
} from "./index-2qtx0q6h.js";
|
|
6
|
+
|
|
7
|
+
// ../plugin/src/hooks/magic-context/embed-session-state.ts
|
|
8
|
+
var embedPauseBySession = new Set;
|
|
9
|
+
var embedRunStateBySession = new Map;
|
|
10
|
+
var activeEmbeddingSessions = new Map;
|
|
11
|
+
var autoEmbedAttemptedBySession = new Set;
|
|
12
|
+
var autoEmbedIdentityBySession = new Map;
|
|
13
|
+
var autoEmbedRetryAfterBySession = new Map;
|
|
14
|
+
function invalidateAutoEmbedSession(sessionId) {
|
|
15
|
+
autoEmbedAttemptedBySession.delete(sessionId);
|
|
16
|
+
autoEmbedIdentityBySession.delete(sessionId);
|
|
17
|
+
autoEmbedRetryAfterBySession.delete(sessionId);
|
|
18
|
+
}
|
|
19
|
+
function getEmbedDrainUiStatus(sessionId, progress) {
|
|
20
|
+
if (embedPauseBySession.has(sessionId)) {
|
|
21
|
+
return { status: "paused" };
|
|
22
|
+
}
|
|
23
|
+
const activeRun = embedRunStateBySession.get(sessionId);
|
|
24
|
+
if (activeRun && !activeRun.signal.aborted || progress?.kind === "embed" && progress.phase === "recomp") {
|
|
25
|
+
return { status: "running" };
|
|
26
|
+
}
|
|
27
|
+
if (progress?.kind === "embed" && (progress.phase === "failed" || progress.phase === "skipped") && progress.message) {
|
|
28
|
+
if (/provider/i.test(progress.message)) {
|
|
29
|
+
return { status: "stopped", detail: progress.message };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { status: "idle" };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ../plugin/src/shared/background-batch-drain.ts
|
|
36
|
+
async function drainBackgroundBatches(step, options = {}) {
|
|
37
|
+
const now = options.now ?? (() => performance.now());
|
|
38
|
+
const deadline = now() + (options.budgetMs ?? 2000);
|
|
39
|
+
const yieldFn = options.yieldFn ?? (() => new Promise((resolve) => setTimeout(resolve, 0)));
|
|
40
|
+
let batches = 0;
|
|
41
|
+
while (now() < deadline) {
|
|
42
|
+
try {
|
|
43
|
+
if (!withoutSqliteTransformPass2(() => withSqliteBackgroundWriter2(step)))
|
|
44
|
+
break;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (isTransientSqliteError2(error))
|
|
47
|
+
break;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
batches++;
|
|
51
|
+
await yieldFn();
|
|
52
|
+
}
|
|
53
|
+
return batches;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ../plugin/src/features/magic-context/storage-embedding-measurements.ts
|
|
57
|
+
import { createHash } from "node:crypto";
|
|
58
|
+
function normalizedQueryHash(query) {
|
|
59
|
+
const normalized = query.trim().replace(/\s+/g, " ").toLowerCase();
|
|
60
|
+
return createHash("sha256").update(normalized).digest("hex");
|
|
61
|
+
}
|
|
62
|
+
var MEASUREMENT_CORPUS_SESSION_ROW_CAP = 2000;
|
|
63
|
+
function recordEmbeddingMeasurement(db, input, cap = MEASUREMENT_CORPUS_SESSION_ROW_CAP) {
|
|
64
|
+
const queryTextHash = normalizedQueryHash(input.queryText);
|
|
65
|
+
const dedupKey = queryTextHash;
|
|
66
|
+
const result = db.prepare(`INSERT OR IGNORE INTO embedding_measurement_corpus
|
|
67
|
+
(session_id, project_path, dedup_key, cohort_key, query_text_hash,
|
|
68
|
+
primary_result_ids_json, shadow_result_ids_json, primary_latency_ms, shadow_latency_ms,
|
|
69
|
+
primary_failed, shadow_failed, primary_model_id, shadow_model_id,
|
|
70
|
+
primary_fingerprint, shadow_fingerprint, primary_epoch, shadow_epoch,
|
|
71
|
+
corpus_hash, coverage_json, created_at)
|
|
72
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(input.sessionId, input.projectPath, dedupKey, input.cohortKey, queryTextHash, JSON.stringify(input.primaryResultIds.slice(0, 10)), JSON.stringify(input.shadowResultIds.slice(0, 10)), input.primaryLatencyMs, input.shadowLatencyMs, input.primaryFailed ? 1 : 0, input.shadowFailed ? 1 : 0, input.primaryModelId, input.shadowModelId, input.primaryFingerprint, input.shadowFingerprint, input.primaryEpoch, input.shadowEpoch, input.corpusHash, JSON.stringify(input.coverage), Date.now());
|
|
73
|
+
if (result.changes > 0) {
|
|
74
|
+
const rowCount = db.prepare("SELECT COUNT(*) AS count FROM embedding_measurement_corpus WHERE session_id = ?").get(input.sessionId).count;
|
|
75
|
+
const overflow = rowCount - cap;
|
|
76
|
+
if (overflow > 0) {
|
|
77
|
+
db.prepare(`DELETE FROM embedding_measurement_corpus
|
|
78
|
+
WHERE session_id = ?
|
|
79
|
+
AND id IN (
|
|
80
|
+
SELECT id FROM embedding_measurement_corpus
|
|
81
|
+
WHERE session_id = ?
|
|
82
|
+
ORDER BY id ASC
|
|
83
|
+
LIMIT ?
|
|
84
|
+
)`).run(input.sessionId, input.sessionId, overflow);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result.changes > 0;
|
|
88
|
+
}
|
|
89
|
+
function beginSynapseBatchLedger(db, input, now = Date.now()) {
|
|
90
|
+
db.prepare(`INSERT INTO synapse_batch_ledger
|
|
91
|
+
(session_id, project_path, scope, manifest_json, request_key, status, created_at, updated_at)
|
|
92
|
+
VALUES (?, ?, ?, ?, ?, 'pending', ?, ?)
|
|
93
|
+
ON CONFLICT(session_id, request_key) DO UPDATE SET
|
|
94
|
+
manifest_json = excluded.manifest_json,
|
|
95
|
+
updated_at = excluded.updated_at`).run(input.sessionId, input.projectPath, input.scope, JSON.stringify(input.manifest), input.requestKey, now, now);
|
|
96
|
+
}
|
|
97
|
+
function finishSynapseBatchLedger(db, sessionId, requestKey, status, now = Date.now()) {
|
|
98
|
+
db.prepare("UPDATE synapse_batch_ledger SET status = ?, updated_at = ? WHERE session_id = ? AND request_key = ?").run(status, now, sessionId, requestKey);
|
|
99
|
+
}
|
|
100
|
+
var SYNAPSE_BATCH_LEDGER_TTL_MS = 14 * 24 * 60 * 60 * 1000;
|
|
101
|
+
function pruneSynapseBatchLedgerForProject(db, projectIdentity, ttlMs = SYNAPSE_BATCH_LEDGER_TTL_MS) {
|
|
102
|
+
const ledgerTable = db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = 'synapse_batch_ledger'").get();
|
|
103
|
+
if (!ledgerTable)
|
|
104
|
+
return 0;
|
|
105
|
+
const shadow = `shadow:${projectIdentity}`;
|
|
106
|
+
const cutoff = Date.now() - ttlMs;
|
|
107
|
+
const predicate = "session_id IN (?, ?) AND updated_at < ?";
|
|
108
|
+
if (!db.prepare(`SELECT 1 FROM synapse_batch_ledger WHERE ${predicate} LIMIT 1`).get(projectIdentity, shadow, cutoff))
|
|
109
|
+
return 0;
|
|
110
|
+
return db.prepare(`DELETE FROM synapse_batch_ledger WHERE ${predicate}`).run(projectIdentity, shadow, cutoff).changes;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { embedPauseBySession, embedRunStateBySession, activeEmbeddingSessions, autoEmbedAttemptedBySession, autoEmbedIdentityBySession, autoEmbedRetryAfterBySession, invalidateAutoEmbedSession, getEmbedDrainUiStatus, drainBackgroundBatches, recordEmbeddingMeasurement, beginSynapseBatchLedger, finishSynapseBatchLedger, pruneSynapseBatchLedgerForProject };
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./index-1cvyaw9a.js";
|
|
4
4
|
import {
|
|
5
5
|
estimateTokens
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-wt7vmyj4.js";
|
|
7
7
|
import {
|
|
8
8
|
readRawSessionMessageIdOrdinalsForRange2
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-svqk0701.js";
|
|
10
10
|
|
|
11
11
|
// ../plugin/src/tools/ctx-expand/search-archive.ts
|
|
12
12
|
var archiveReadsOnThisThread = 0;
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./index-0h2mkab2.js";
|
|
4
4
|
import {
|
|
5
5
|
isUserHomeDirectory
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-6pk49fc3.js";
|
|
7
7
|
import {
|
|
8
8
|
logSlowWriteTransaction
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-0wtm7g7f.js";
|
|
10
10
|
|
|
11
11
|
// ../plugin/src/features/magic-context/session-project-storage.ts
|
|
12
12
|
var SESSION_CHUNK_REPAIR_BATCH_SIZE = 100;
|
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
// ../plugin/src/shared/bounded-session-map.ts
|
|
2
|
-
class BoundedSessionMap {
|
|
3
|
-
maxEntries;
|
|
4
|
-
store = new Map;
|
|
5
|
-
constructor(maxEntries) {
|
|
6
|
-
if (!Number.isFinite(maxEntries) || maxEntries < 1) {
|
|
7
|
-
throw new Error(`BoundedSessionMap: maxEntries must be >= 1, got ${maxEntries}`);
|
|
8
|
-
}
|
|
9
|
-
this.maxEntries = maxEntries;
|
|
10
|
-
}
|
|
11
|
-
get(sessionId) {
|
|
12
|
-
const value = this.store.get(sessionId);
|
|
13
|
-
if (value === undefined)
|
|
14
|
-
return;
|
|
15
|
-
this.store.delete(sessionId);
|
|
16
|
-
this.store.set(sessionId, value);
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
peek(sessionId) {
|
|
20
|
-
return this.store.get(sessionId);
|
|
21
|
-
}
|
|
22
|
-
has(sessionId) {
|
|
23
|
-
return this.store.has(sessionId);
|
|
24
|
-
}
|
|
25
|
-
set(sessionId, value) {
|
|
26
|
-
if (this.store.has(sessionId)) {
|
|
27
|
-
this.store.delete(sessionId);
|
|
28
|
-
} else if (this.store.size >= this.maxEntries) {
|
|
29
|
-
const oldest = this.store.keys().next().value;
|
|
30
|
-
if (oldest !== undefined)
|
|
31
|
-
this.store.delete(oldest);
|
|
32
|
-
}
|
|
33
|
-
this.store.set(sessionId, value);
|
|
34
|
-
}
|
|
35
|
-
delete(sessionId) {
|
|
36
|
-
return this.store.delete(sessionId);
|
|
37
|
-
}
|
|
38
|
-
clear() {
|
|
39
|
-
this.store.clear();
|
|
40
|
-
}
|
|
41
|
-
get size() {
|
|
42
|
-
return this.store.size;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
1
|
// ../plugin/src/shared/opencode-db-path.ts
|
|
47
2
|
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
48
3
|
import { homedir } from "node:os";
|
|
@@ -220,126 +175,4 @@ function claimOpenCodeDbDiagnosticOnce(surface, resolution) {
|
|
|
220
175
|
return true;
|
|
221
176
|
}
|
|
222
177
|
|
|
223
|
-
|
|
224
|
-
var ACTIVITY_WINDOW_MS = 10 * 60000;
|
|
225
|
-
var MAX_ACTIVITY_GAP_MS = 60000;
|
|
226
|
-
var WINDOWED_SINCE_KEY = "tool_definition_measurements:windowed_since";
|
|
227
|
-
var routes = new Map;
|
|
228
|
-
var sessionFlights = new BoundedSessionMap(1000);
|
|
229
|
-
var persistenceDb = null;
|
|
230
|
-
var windowedSince;
|
|
231
|
-
var boundAt = 0;
|
|
232
|
-
var cachedInsertStmt = null;
|
|
233
|
-
var cachedDeleteStmt = null;
|
|
234
|
-
function agentKey(agentName) {
|
|
235
|
-
return agentName && agentName.length > 0 ? agentName : "default";
|
|
236
|
-
}
|
|
237
|
-
function keyFor(providerID, modelID, agentName) {
|
|
238
|
-
return `${providerID}/${modelID}/${agentKey(agentName)}`;
|
|
239
|
-
}
|
|
240
|
-
function routeFor(providerID, modelID, agentName) {
|
|
241
|
-
const key = keyFor(providerID, modelID, agentName);
|
|
242
|
-
let route = routes.get(key);
|
|
243
|
-
if (!route) {
|
|
244
|
-
route = {
|
|
245
|
-
providerID,
|
|
246
|
-
modelID,
|
|
247
|
-
agentName: agentKey(agentName),
|
|
248
|
-
tools: new Map,
|
|
249
|
-
live: false,
|
|
250
|
-
clock: 0,
|
|
251
|
-
lastWallAt: Date.now(),
|
|
252
|
-
oldestFireAt: Number.POSITIVE_INFINITY,
|
|
253
|
-
retired: new Map,
|
|
254
|
-
legacyRows: new Set
|
|
255
|
-
};
|
|
256
|
-
routes.set(key, route);
|
|
257
|
-
}
|
|
258
|
-
return { key, route };
|
|
259
|
-
}
|
|
260
|
-
function advanceClock(route) {
|
|
261
|
-
const now = Date.now();
|
|
262
|
-
const gap = Math.min(Math.max(now - route.lastWallAt, 0), MAX_ACTIVITY_GAP_MS);
|
|
263
|
-
route.clock += gap;
|
|
264
|
-
route.lastWallAt = Math.max(route.lastWallAt, now);
|
|
265
|
-
return route.clock;
|
|
266
|
-
}
|
|
267
|
-
function readWindowedSince(db) {
|
|
268
|
-
try {
|
|
269
|
-
const row = db.prepare("SELECT value FROM schema_migrations_meta WHERE key = ?").get(WINDOWED_SINCE_KEY);
|
|
270
|
-
if (!row)
|
|
271
|
-
return;
|
|
272
|
-
const value = Number(row.value);
|
|
273
|
-
return Number.isFinite(value) ? value : undefined;
|
|
274
|
-
} catch {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
function markWindowed() {
|
|
279
|
-
if (windowedSince !== undefined || !persistenceDb)
|
|
280
|
-
return;
|
|
281
|
-
try {
|
|
282
|
-
persistenceDb.prepare("INSERT OR IGNORE INTO schema_migrations_meta (key, value) VALUES (?, ?)").run(WINDOWED_SINCE_KEY, String(boundAt));
|
|
283
|
-
windowedSince = readWindowedSince(persistenceDb);
|
|
284
|
-
} catch {}
|
|
285
|
-
}
|
|
286
|
-
function setDatabase(db) {
|
|
287
|
-
const rebound = persistenceDb !== null && persistenceDb !== db;
|
|
288
|
-
persistenceDb = db;
|
|
289
|
-
boundAt = Date.now();
|
|
290
|
-
cachedInsertStmt = null;
|
|
291
|
-
cachedDeleteStmt = null;
|
|
292
|
-
if (rebound) {
|
|
293
|
-
for (const route of routes.values()) {
|
|
294
|
-
for (const slot of route.tools.values()) {
|
|
295
|
-
slot.persisted = false;
|
|
296
|
-
slot.writeFailedAt = undefined;
|
|
297
|
-
}
|
|
298
|
-
for (const retired of route.retired.values())
|
|
299
|
-
retired.rowKept = false;
|
|
300
|
-
route.legacyRows.clear();
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
windowedSince = readWindowedSince(db);
|
|
304
|
-
if (windowedSince !== undefined)
|
|
305
|
-
return;
|
|
306
|
-
try {
|
|
307
|
-
if (!db.prepare("SELECT 1 FROM tool_definition_measurements LIMIT 1").get())
|
|
308
|
-
markWindowed();
|
|
309
|
-
} catch {}
|
|
310
|
-
}
|
|
311
|
-
function loadToolDefinitionMeasurements(db) {
|
|
312
|
-
let rows = [];
|
|
313
|
-
try {
|
|
314
|
-
rows = db.prepare("SELECT provider_id, model_id, agent_name, tool_id, token_count, recorded_at FROM tool_definition_measurements").all();
|
|
315
|
-
} catch {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
const since = readWindowedSince(db);
|
|
319
|
-
const loadedAt = new Map;
|
|
320
|
-
for (const row of rows) {
|
|
321
|
-
const { route } = routeFor(row.provider_id, row.model_id, row.agent_name);
|
|
322
|
-
if (route.live)
|
|
323
|
-
continue;
|
|
324
|
-
let now = loadedAt.get(route);
|
|
325
|
-
if (now === undefined) {
|
|
326
|
-
now = advanceClock(route);
|
|
327
|
-
loadedAt.set(route, now);
|
|
328
|
-
}
|
|
329
|
-
const legacy = since === undefined || !(Number(row.recorded_at) >= since);
|
|
330
|
-
route.tools.set(row.tool_id, {
|
|
331
|
-
tokens: row.token_count,
|
|
332
|
-
fingerprint: undefined,
|
|
333
|
-
lastFireAt: now,
|
|
334
|
-
legacy,
|
|
335
|
-
persisted: !legacy
|
|
336
|
-
});
|
|
337
|
-
route.oldestFireAt = Math.min(route.oldestFireAt, now);
|
|
338
|
-
if (legacy)
|
|
339
|
-
route.legacyRows.add(row.tool_id);
|
|
340
|
-
else
|
|
341
|
-
route.legacyRows.delete(row.tool_id);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
export { BoundedSessionMap, resolveOpenCodeDbPath, hasV1MessageTables, assertOpenCodeStoreGeneration, openCodeDbPathExists, getOpenCodeDbProbeDescriptions, recordOpenCodeDbReadFailure, clearOpenCodeDbReadFailure, claimOpenCodeDbDiagnosticOnce, setDatabase, loadToolDefinitionMeasurements };
|
|
178
|
+
export { resolveOpenCodeDbPath, hasV1MessageTables, assertOpenCodeStoreGeneration, openCodeDbPathExists, getOpenCodeDbProbeDescriptions, recordOpenCodeDbReadFailure, clearOpenCodeDbReadFailure, claimOpenCodeDbDiagnosticOnce };
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
} from "./index-2qtx0q6h.js";
|
|
6
6
|
import {
|
|
7
7
|
runSessionWarmupWorker
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-mkh1cm5k.js";
|
|
9
9
|
import {
|
|
10
10
|
logSlowWriteTransaction
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-0wtm7g7f.js";
|
|
12
12
|
|
|
13
13
|
// ../plugin/src/features/magic-context/message-fts-rowid-map.ts
|
|
14
14
|
import { createHash } from "node:crypto";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
estimateTokens
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-wt7vmyj4.js";
|
|
4
4
|
import {
|
|
5
5
|
getHarness2
|
|
6
6
|
} from "./index-0h2mkab2.js";
|
|
7
7
|
import {
|
|
8
8
|
log2
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-gymgz20n.js";
|
|
10
10
|
import {
|
|
11
11
|
inRootAsyncContext2
|
|
12
12
|
} from "./index-2qtx0q6h.js";
|