@cortexkit/pi-magic-context 0.49.11 → 0.49.13

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.
Files changed (50) hide show
  1. package/dist/auto-search-worker.js +4 -4
  2. package/dist/chunk-embedding-write-worker.js +87 -0
  3. package/dist/{compaction-marker-candidates-n4dphyz4.js → compaction-marker-candidates-k4tqg4jb.js} +2 -2
  4. package/dist/compaction-marker-candidates-worker.js +1 -1
  5. package/dist/embedding-backfill-7kj16fh9.js +21 -0
  6. package/dist/embedding-worker-process.js +1 -1
  7. package/dist/embedding-worker.js +5 -5
  8. package/dist/historian-calibration-extension.js +2 -2
  9. package/dist/{index-ta0ed2nc.js → index-1k729e4f.js} +15 -15
  10. package/dist/index-1mrvw9en.js +225 -0
  11. package/dist/{index-g13fb2sj.js → index-3cnarwf8.js} +4 -4
  12. package/dist/{index-729kkhmf.js → index-46q4e104.js} +1 -1
  13. package/dist/{index-m8aaepft.js → index-53xdqb3d.js} +7 -7
  14. package/dist/{index-szh001qb.js → index-6dz2ed1v.js} +2 -2
  15. package/dist/{index-gqxsds3q.js → index-6ex901g3.js} +187 -27
  16. package/dist/{index-gycf3sp7.js → index-7bqrfyny.js} +46 -2
  17. package/dist/{index-drah07tf.js → index-7qc73yk5.js} +64 -7
  18. package/dist/{index-s9kwv5pp.js → index-7wagp5jp.js} +5 -5
  19. package/dist/{index-8yjhda46.js → index-9jvktm7k.js} +3 -3
  20. package/dist/{index-3veejgp8.js → index-apgwdby5.js} +1 -1
  21. package/dist/{index-0vq6ebae.js → index-aypx5h57.js} +58 -64
  22. package/dist/{index-43zqh10z.js → index-d4dt19md.js} +1 -1
  23. package/dist/{index-fdxzpnbj.js → index-djxc8w8c.js} +1 -1
  24. package/dist/{index-x7426vy4.js → index-ed9d2ded.js} +18 -5
  25. package/dist/{index-kh3jt7t9.js → index-f18ec69t.js} +1 -1
  26. package/dist/{index-4pxydwvg.js → index-g4jf772p.js} +1 -1
  27. package/dist/{index-4vj37yw9.js → index-he9s4qsj.js} +16 -6
  28. package/dist/{index-ttxsmaj5.js → index-jrap43gc.js} +1 -1
  29. package/dist/{index-78c864c8.js → index-nwbhe6qv.js} +324 -254
  30. package/dist/{index-9azmm7cg.js → index-t27xk4r7.js} +10 -10
  31. package/dist/{index-s3c9dskk.js → index-vv1j5cak.js} +8 -8
  32. package/dist/{index-2df03yc3.js → index-wp9q91kn.js} +8 -8
  33. package/dist/{index-xmdkde4v.js → index-y29y2j2w.js} +12 -1
  34. package/dist/index.js +854 -369
  35. package/dist/{logger-qg51hmp7.js → logger-dygt96rn.js} +1 -1
  36. package/dist/{message-index-5zjmsg57.js → message-index-7w179p64.js} +13 -13
  37. package/dist/{message-index-bounded-chgr6dn3.js → message-index-bounded-80n96ehp.js} +13 -13
  38. package/dist/{message-time-backfill-q9s88zdv.js → message-time-backfill-r2ar1qvk.js} +2 -2
  39. package/dist/migration-worker.js +9 -9
  40. package/dist/{project-embedding-registry-dk5axctd.js → project-embedding-registry-52zwmtbn.js} +11 -10
  41. package/dist/raw-ordinal-warmup-worker.js +12 -7
  42. package/dist/{read-session-chunk-3kb7r5pq.js → read-session-chunk-83864b37.js} +8 -8
  43. package/dist/{read-session-raw-hm7ptnrh.js → read-session-raw-azkqjgzg.js} +6 -2
  44. package/dist/{safe-notification-target-62ty6rvp.js → safe-notification-target-2rkvkmw8.js} +2 -2
  45. package/dist/{search-8pczyejh.js → search-hffb8xht.js} +20 -19
  46. package/dist/{storage-tags-zh23ynsh.js → storage-tags-zmf30zqp.js} +6 -4
  47. package/dist/subagent-entry.js +23 -22
  48. package/package.json +2 -2
  49. package/dist/embedding-backfill-1tknh2jn.js +0 -20
  50. /package/dist/{index-69vas84q.js → index-e6xnpach.js} +0 -0
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  getMagicContextStorageDir,
3
3
  log2
4
- } from "./index-gycf3sp7.js";
4
+ } from "./index-7bqrfyny.js";
5
5
  import {
6
6
  inRootAsyncContext2
7
7
  } from "./index-asrxgdt4.js";
8
8
  import {
9
9
  projectDirectoryKey
10
- } from "./index-fdxzpnbj.js";
10
+ } from "./index-djxc8w8c.js";
11
11
  import {
12
12
  writeStorageFileAtomicSync
13
13
  } from "./index-81nthk8j.js";
@@ -15,9 +15,9 @@ import {
15
15
  // ../plugin/src/features/magic-context/memory/project-identity.ts
16
16
  import { execFileSync } from "node:child_process";
17
17
  import { createHash as createHash2 } from "node:crypto";
18
- import { existsSync, realpathSync, statSync } from "node:fs";
18
+ import { existsSync, realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
19
19
  import { homedir } from "node:os";
20
- import path2 from "node:path";
20
+ import path3 from "node:path";
21
21
 
22
22
  // ../plugin/src/features/magic-context/memory/project-identity-cache.ts
23
23
  import { createHash } from "node:crypto";
@@ -42,6 +42,162 @@ function readRememberedGitIdentity(directory, storageDir) {
42
42
  return;
43
43
  }
44
44
 
45
+ // ../plugin/src/features/magic-context/memory/unborn-head.ts
46
+ import { readFileSync as readFileSync2, realpathSync, statSync } from "node:fs";
47
+ import path2 from "node:path";
48
+ var GIT_LOCATION_ENV_VARS = [
49
+ "GIT_DIR",
50
+ "GIT_COMMON_DIR",
51
+ "GIT_WORK_TREE",
52
+ "GIT_CEILING_DIRECTORIES"
53
+ ];
54
+ function errorCode(error) {
55
+ if (error === null || typeof error !== "object" || !("code" in error))
56
+ return;
57
+ const code = error.code;
58
+ return typeof code === "string" ? code : undefined;
59
+ }
60
+ function readText(file) {
61
+ try {
62
+ return { ok: true, text: readFileSync2(file, "utf8") };
63
+ } catch (error) {
64
+ return { ok: false, missing: errorCode(error) === "ENOENT" };
65
+ }
66
+ }
67
+ function entryKind(entry) {
68
+ try {
69
+ const stat = statSync(entry);
70
+ if (stat.isFile())
71
+ return "file";
72
+ if (stat.isDirectory())
73
+ return "directory";
74
+ return "other";
75
+ } catch (error) {
76
+ return errorCode(error) === "ENOENT" ? "missing" : "error";
77
+ }
78
+ }
79
+ function stripLineEnding(text) {
80
+ return text.replace(/\r?\n$/u, "");
81
+ }
82
+ function resolveMetadataPath(baseDirectory, value) {
83
+ return path2.resolve(baseDirectory, value);
84
+ }
85
+ function isPlainBranchName(name) {
86
+ if (name.length === 0 || name.endsWith("/") || name.endsWith("."))
87
+ return false;
88
+ if (name.includes("..") || name.includes("//") || name.includes("@{"))
89
+ return false;
90
+ for (const character of name) {
91
+ const code = character.charCodeAt(0);
92
+ if (code <= 32 || code === 127 || "~^:?*[\\".includes(character))
93
+ return false;
94
+ }
95
+ return name.split("/").every((component) => !component.startsWith(".") && !component.endsWith(".lock"));
96
+ }
97
+ function findGitDirectory(start) {
98
+ let current = start;
99
+ while (true) {
100
+ const dotGit = path2.join(current, ".git");
101
+ const kind = entryKind(dotGit);
102
+ if (kind === "directory")
103
+ return dotGit;
104
+ if (kind === "file") {
105
+ const read = readText(dotGit);
106
+ if (!read.ok)
107
+ return;
108
+ const match = /^gitdir: (.+)$/u.exec(stripLineEnding(read.text));
109
+ if (!match?.[1] || match[1].includes(`
110
+ `))
111
+ return;
112
+ return resolveMetadataPath(current, match[1]);
113
+ }
114
+ if (kind !== "missing")
115
+ return;
116
+ const parent = path2.dirname(current);
117
+ if (parent === current)
118
+ return;
119
+ current = parent;
120
+ }
121
+ }
122
+ function packedRefsList(text, ref) {
123
+ for (const rawLine of text.split(`
124
+ `)) {
125
+ const line = rawLine.replace(/\r$/u, "");
126
+ if (line === "" || line.startsWith("#") || line.startsWith("^"))
127
+ continue;
128
+ const match = /^[0-9a-f]{40,64} (\S+)$/u.exec(line);
129
+ if (!match)
130
+ return;
131
+ if (match[1] === ref)
132
+ return true;
133
+ }
134
+ return false;
135
+ }
136
+ function isUnbornHeadInLayout(directory) {
137
+ const gitDirectory = findGitDirectory(directory);
138
+ if (gitDirectory === undefined)
139
+ return false;
140
+ let commonDirectory = gitDirectory;
141
+ const commondir = readText(path2.join(gitDirectory, "commondir"));
142
+ if (commondir.ok) {
143
+ const value = stripLineEnding(commondir.text);
144
+ if (value === "" || value.includes(`
145
+ `))
146
+ return false;
147
+ commonDirectory = resolveMetadataPath(gitDirectory, value);
148
+ } else if (!commondir.missing) {
149
+ return false;
150
+ }
151
+ if (entryKind(path2.join(gitDirectory, "HEAD")) !== "file")
152
+ return false;
153
+ if (entryKind(path2.join(commonDirectory, "objects")) !== "directory")
154
+ return false;
155
+ if (entryKind(path2.join(commonDirectory, "refs")) !== "directory")
156
+ return false;
157
+ if (entryKind(path2.join(commonDirectory, "reftable")) !== "missing")
158
+ return false;
159
+ const config = readText(path2.join(commonDirectory, "config"));
160
+ if (config.ok) {
161
+ if (/refstorage/iu.test(config.text))
162
+ return false;
163
+ } else if (!config.missing) {
164
+ return false;
165
+ }
166
+ const head = readText(path2.join(gitDirectory, "HEAD"));
167
+ if (!head.ok)
168
+ return false;
169
+ const headMatch = /^ref: (refs\/heads\/(.+))$/u.exec(head.text.replace(/\s+$/u, ""));
170
+ const ref = headMatch?.[1];
171
+ const branch = headMatch?.[2];
172
+ if (!ref || branch === undefined || !isPlainBranchName(branch))
173
+ return false;
174
+ const refSegments = ref.split("/");
175
+ for (const base of new Set([commonDirectory, gitDirectory])) {
176
+ if (entryKind(path2.join(base, ...refSegments)) !== "missing")
177
+ return false;
178
+ }
179
+ const packed = readText(path2.join(commonDirectory, "packed-refs"));
180
+ if (packed.ok) {
181
+ if (packedRefsList(packed.text, ref) !== false)
182
+ return false;
183
+ } else if (!packed.missing) {
184
+ return false;
185
+ }
186
+ return true;
187
+ }
188
+ function isUnbornHeadOnDisk(directory, env = process.env) {
189
+ if (GIT_LOCATION_ENV_VARS.some((name) => env[name] !== undefined && env[name] !== "")) {
190
+ return false;
191
+ }
192
+ let realDirectory;
193
+ try {
194
+ realDirectory = realpathSync.native(path2.resolve(directory));
195
+ } catch {
196
+ return false;
197
+ }
198
+ return isUnbornHeadInLayout(realDirectory);
199
+ }
200
+
45
201
  // ../plugin/src/features/magic-context/memory/project-identity.ts
46
202
  var GIT_TIMEOUT_MS = 5000;
47
203
  var TRANSIENT_FAILURE_COOLDOWN_MS = 5 * 60 * 1000;
@@ -62,6 +218,7 @@ function setHomeProjectPermission(allowed) {
62
218
  homeProjectPermission = allowed;
63
219
  }
64
220
  var execFileSyncForIdentity = execFileSync;
221
+ var gitTimeoutMs = GIT_TIMEOUT_MS;
65
222
  var userHomeDirectoryForIdentity = () => homedir();
66
223
  var nowMs = () => Date.now();
67
224
  var filesystemProbeObserverForTests;
@@ -116,7 +273,7 @@ function getErrorStderr(error) {
116
273
  return "";
117
274
  }
118
275
  function directoryFallback(directory) {
119
- const canonical = path2.resolve(directory);
276
+ const canonical = path3.resolve(directory);
120
277
  const hash = createHash2("md5").update(canonical, "utf8").digest("hex").slice(0, 12);
121
278
  return `dir:${hash}`;
122
279
  }
@@ -125,7 +282,7 @@ function rememberedIdentityOrDirectoryFallback(canonical) {
125
282
  }
126
283
  function assertDirectoryUsable(canonicalDirectory, rawDirectory) {
127
284
  try {
128
- const stat = statSync(canonicalDirectory);
285
+ const stat = statSync2(canonicalDirectory);
129
286
  if (!stat.isDirectory()) {
130
287
  throw new ProjectIdentityError("unknown", rawDirectory, `Project path is not a directory: ${canonicalDirectory}`);
131
288
  }
@@ -151,7 +308,7 @@ function hasUnbornHead(directory) {
151
308
  encoding: "utf8",
152
309
  env: { ...process.env, LC_ALL: "C", LANG: "C" },
153
310
  stdio: ["ignore", "pipe", "pipe"],
154
- timeout: GIT_TIMEOUT_MS,
311
+ timeout: gitTimeoutMs,
155
312
  windowsHide: true
156
313
  };
157
314
  try {
@@ -168,7 +325,7 @@ function hasUnbornHead(directory) {
168
325
  }
169
326
  function classifyGitError(error, rawDirectory) {
170
327
  if (isGitTimeoutError(error)) {
171
- return new ProjectIdentityError("git_timeout", rawDirectory, `git rev-list timed out after ${GIT_TIMEOUT_MS}ms`, asError(error));
328
+ return new ProjectIdentityError("git_timeout", rawDirectory, `git rev-list timed out after ${gitTimeoutMs}ms`, asError(error));
172
329
  }
173
330
  const code = getErrorCode(error);
174
331
  if (code === "ENOENT") {
@@ -188,7 +345,7 @@ function classifyGitError(error, rawDirectory) {
188
345
  }
189
346
  function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectPermission, options = {}) {
190
347
  assertProjectAllowed(directory, allowHomeProject);
191
- const canonical = path2.resolve(directory);
348
+ const canonical = path3.resolve(directory);
192
349
  const cached = options.cache === false ? undefined : identityCache.get(canonical);
193
350
  if (cached !== undefined) {
194
351
  return cached;
@@ -197,6 +354,9 @@ function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectP
197
354
  if (!hasGitDir(canonical)) {
198
355
  throw new ProjectIdentityError("not_git_repo", directory, "Directory has no git metadata; caller may use directory fallback");
199
356
  }
357
+ if (isUnbornHeadOnDisk(canonical)) {
358
+ throw new ProjectIdentityError("no_commits", directory, "Git repository has no commits yet");
359
+ }
200
360
  let output;
201
361
  try {
202
362
  output = execFileSyncForIdentity("git", ["rev-list", "--max-parents=0", "HEAD"], {
@@ -204,7 +364,7 @@ function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectP
204
364
  encoding: "utf8",
205
365
  env: { ...process.env, LC_ALL: "C", LANG: "C" },
206
366
  stdio: ["ignore", "pipe", "pipe"],
207
- timeout: GIT_TIMEOUT_MS,
367
+ timeout: gitTimeoutMs,
208
368
  windowsHide: true
209
369
  });
210
370
  } catch (error) {
@@ -257,9 +417,9 @@ function nearestLastKnownGitIdentity(canonical) {
257
417
  const cached = lastKnownGitIdentity(current);
258
418
  if (cached !== undefined)
259
419
  return { identity: cached, source: current };
260
- if (existsSync(path2.join(current, ".git")))
420
+ if (existsSync(path3.join(current, ".git")))
261
421
  break;
262
- const parent = path2.dirname(current);
422
+ const parent = path3.dirname(current);
263
423
  if (parent === current)
264
424
  break;
265
425
  current = parent;
@@ -270,7 +430,7 @@ function nearestLastKnownGitIdentity(canonical) {
270
430
  if (exactOrAncestor)
271
431
  return exactOrAncestor;
272
432
  try {
273
- const realCanonical = realpathSync.native(canonical);
433
+ const realCanonical = realpathSync2.native(canonical);
274
434
  if (realCanonical !== canonical)
275
435
  return walk(realCanonical);
276
436
  } catch {}
@@ -300,7 +460,7 @@ function recordDubiousOwnershipFallback(canonical) {
300
460
  function canonicalUserHomeDirectory() {
301
461
  const homeDirectory = userHomeDirectoryForIdentity();
302
462
  try {
303
- return realpathSync.native(homeDirectory);
463
+ return realpathSync2.native(homeDirectory);
304
464
  } catch {
305
465
  return homeDirectory;
306
466
  }
@@ -309,20 +469,20 @@ function isUserHomeDirectory(directory) {
309
469
  if (projectDirectoryKey(directory) === projectDirectoryKey(userHomeDirectoryForIdentity()))
310
470
  return true;
311
471
  try {
312
- return projectDirectoryKey(realpathSync.native(path2.resolve(directory))) === projectDirectoryKey(canonicalUserHomeDirectory());
472
+ return projectDirectoryKey(realpathSync2.native(path3.resolve(directory))) === projectDirectoryKey(canonicalUserHomeDirectory());
313
473
  } catch {
314
474
  return false;
315
475
  }
316
476
  }
317
477
  function assertProjectAllowed(directory, allowHomeProject) {
318
- const canonical = path2.resolve(directory);
478
+ const canonical = path3.resolve(directory);
319
479
  if (!allowHomeProject && (isUserHomeDirectory(directory) || isUserHomeDirectory(gitRootDirectory(canonical) ?? canonical))) {
320
480
  throw new ProjectIdentityError("home_project_disabled", directory, "Home project memory is disabled; set allow_home_project to opt in");
321
481
  }
322
482
  }
323
483
  function resolveProjectIdentity(directory, allowHomeProject = homeProjectPermission) {
324
484
  assertProjectAllowed(directory, allowHomeProject);
325
- const canonical = path2.resolve(directory);
485
+ const canonical = path3.resolve(directory);
326
486
  const cachedFallback = directoryFallbackCache.get(canonical);
327
487
  if (cachedFallback !== undefined) {
328
488
  if (!hasGitDir(canonical)) {
@@ -370,7 +530,7 @@ function resolveProjectIdentityOrFallback(directory, allowHomeProject = homeProj
370
530
  try {
371
531
  return resolveProjectIdentity(directory, allowHomeProject);
372
532
  } catch (error) {
373
- const canonical = path2.resolve(directory);
533
+ const canonical = path3.resolve(directory);
374
534
  if (hasGitDir(canonical) || error instanceof ProjectIdentityError && error.errorClass === "home_project_disabled")
375
535
  throw error;
376
536
  const fallback = rememberedIdentityOrDirectoryFallback(canonical);
@@ -384,7 +544,7 @@ function hasGitDir(canonical) {
384
544
  return true;
385
545
  }
386
546
  try {
387
- const realCanonical = realpathSync.native(canonical);
547
+ const realCanonical = realpathSync2.native(canonical);
388
548
  return realCanonical !== canonical && hasGitDirInAncestorChain(realCanonical);
389
549
  } catch {
390
550
  return false;
@@ -393,14 +553,14 @@ function hasGitDir(canonical) {
393
553
  function gitRootInAncestorChain(startDirectory) {
394
554
  let current = startDirectory;
395
555
  while (true) {
396
- if (existsSync(path2.join(current, ".git"))) {
556
+ if (existsSync(path3.join(current, ".git"))) {
397
557
  try {
398
- return realpathSync.native(current);
558
+ return realpathSync2.native(current);
399
559
  } catch {
400
- return path2.resolve(current);
560
+ return path3.resolve(current);
401
561
  }
402
562
  }
403
- const parent = path2.dirname(current);
563
+ const parent = path3.dirname(current);
404
564
  if (parent === current) {
405
565
  return null;
406
566
  }
@@ -415,20 +575,20 @@ function gitRootDirectory(canonical) {
415
575
  if (direct)
416
576
  return direct;
417
577
  try {
418
- const realCanonical = realpathSync.native(canonical);
578
+ const realCanonical = realpathSync2.native(canonical);
419
579
  return realCanonical === canonical ? null : gitRootInAncestorChain(realCanonical);
420
580
  } catch {
421
581
  return null;
422
582
  }
423
583
  }
424
584
  function directoryHasGitMetadata(directory) {
425
- return gitRootDirectory(path2.resolve(directory)) !== null;
585
+ return gitRootDirectory(path3.resolve(directory)) !== null;
426
586
  }
427
587
  function isUsableProjectIdentity(identity) {
428
588
  return typeof identity === "string" && identity.trim().length > 0;
429
589
  }
430
590
  function resolveProjectIdentityForSession(directory, allowHomeProject = homeProjectPermission) {
431
- const resolvedDirectory = path2.resolve(directory);
591
+ const resolvedDirectory = path3.resolve(directory);
432
592
  const cacheKey = `${allowHomeProject ? "1" : "0"}\x00${resolvedDirectory}`;
433
593
  const cached = sessionIdentityCache.get(cacheKey);
434
594
  if (cached && (cached.revalidateAt === null || nowMs() < cached.revalidateAt) && !(cached.identity?.startsWith("dir:") && hasGitDir(resolvedDirectory))) {
@@ -439,7 +599,7 @@ function resolveProjectIdentityForSession(directory, allowHomeProject = homeProj
439
599
  const canonicalDirectory = (() => {
440
600
  try {
441
601
  filesystemProbeObserverForTests?.();
442
- return realpathSync.native(resolvedDirectory);
602
+ return realpathSync2.native(resolvedDirectory);
443
603
  } catch {
444
604
  return resolvedDirectory;
445
605
  }
@@ -7,7 +7,15 @@ import * as fs from "node:fs";
7
7
  import * as path2 from "node:path";
8
8
 
9
9
  // ../plugin/src/shared/data-path.ts
10
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
10
+ import {
11
+ existsSync,
12
+ lstatSync,
13
+ mkdirSync,
14
+ readFileSync,
15
+ readlinkSync,
16
+ realpathSync,
17
+ writeFileSync
18
+ } from "node:fs";
11
19
  import * as os from "node:os";
12
20
  import * as path from "node:path";
13
21
 
@@ -99,6 +107,42 @@ function getMagicContextStorageResolution() {
99
107
  function getMagicContextStorageDir() {
100
108
  return getMagicContextStorageResolution().path;
101
109
  }
110
+ function canonicalizeStoragePath(value, seen = new Set) {
111
+ const absolute = path.resolve(value);
112
+ if (seen.has(absolute))
113
+ return absolute;
114
+ seen.add(absolute);
115
+ try {
116
+ return realpathSync.native(absolute);
117
+ } catch {
118
+ try {
119
+ if (lstatSync(absolute).isSymbolicLink()) {
120
+ const target = readlinkSync(absolute);
121
+ const resolvedTarget = path.isAbsolute(target) ? target : path.resolve(path.dirname(absolute), target);
122
+ return canonicalizeStoragePath(resolvedTarget, seen);
123
+ }
124
+ } catch {}
125
+ const parent = path.dirname(absolute);
126
+ if (parent === absolute)
127
+ return absolute;
128
+ const resolvedParent = canonicalizeStoragePath(parent, seen);
129
+ return path.resolve(resolvedParent, path.basename(absolute));
130
+ }
131
+ }
132
+ function isMagicContextStorageOutsideEngram(storageDir = getMagicContextStorageDir(), backupDir = path.join(os.homedir(), ".local", "share", "cortexkit", "magic-context")) {
133
+ const resolvedStorageDir = canonicalizeStoragePath(storageDir);
134
+ const resolvedBackupDir = canonicalizeStoragePath(backupDir);
135
+ const relative2 = path.relative(resolvedBackupDir, resolvedStorageDir);
136
+ return path.isAbsolute(relative2) || relative2 === ".." || relative2.startsWith(`..${path.sep}`);
137
+ }
138
+ var STORAGE_BACKUP_WARNING_CHECKED = Symbol.for("magic-context.storage-backup-warning-checked");
139
+ function claimStorageBackupWarningCheck() {
140
+ const processState = globalThis;
141
+ if (processState[STORAGE_BACKUP_WARNING_CHECKED])
142
+ return false;
143
+ processState[STORAGE_BACKUP_WARNING_CHECKED] = true;
144
+ return true;
145
+ }
102
146
  function getLegacyOpenCodeMagicContextStorageDir() {
103
147
  return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
104
148
  }
@@ -655,4 +699,4 @@ if (!isTestEnv) {
655
699
  process.on("exit", flush);
656
700
  }
657
701
 
658
- export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, getLegacyOpenCodeMagicContextStorageDir, sanitizeDiagnosticText, hasShareabilitySensitiveText, registerStalePluginBuildHost, classifyStalePluginBuild, importPluginModule, setLogLineForwarder2, writeForwardedLogLine2, log2, sessionLog2, getLoggerDiagnostics2, flushLogger2, getLogFilePath2 };
702
+ export { getDataDir, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getMagicContextStorageDir, isMagicContextStorageOutsideEngram, claimStorageBackupWarningCheck, getLegacyOpenCodeMagicContextStorageDir, sanitizeDiagnosticText, hasShareabilitySensitiveText, registerStalePluginBuildHost, classifyStalePluginBuild, importPluginModule, setLogLineForwarder2, writeForwardedLogLine2, log2, sessionLog2, getLoggerDiagnostics2, flushLogger2, getLogFilePath2 };
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  getTokenEstimatorFingerprint,
3
3
  estimateTokens
4
- } from "./index-4pxydwvg.js";
4
+ } from "./index-g4jf772p.js";
5
5
  import {
6
6
  getHarness2
7
7
  } from "./index-0h2mkab2.js";
8
8
  import {
9
9
  log2
10
- } from "./index-gycf3sp7.js";
10
+ } from "./index-7bqrfyny.js";
11
11
  import {
12
12
  isSynapseEmbeddingTruncated
13
- } from "./index-szh001qb.js";
13
+ } from "./index-6dz2ed1v.js";
14
14
  import {
15
15
  messageFtsOrdinalRangeIsMapped
16
- } from "./index-fdxzpnbj.js";
16
+ } from "./index-djxc8w8c.js";
17
17
 
18
18
  // ../plugin/src/features/magic-context/compartment-chunk-embedding.ts
19
19
  import { createHash } from "node:crypto";
@@ -858,13 +858,17 @@ function loadUnembeddedShadowChunkCandidates(db, projectPath, primaryModelId, sh
858
858
  const rows = getShadowBackfillCandidateStatement(db).all(projectPath, projectPath, primaryModelId);
859
859
  return selectHashIncompleteChunkCandidates(db, projectPath, shadowModelId, mapBackfillCandidateRows(rows), Math.max(1, limit), shadowMaxInputTokens);
860
860
  }
861
- async function loadUnembeddedCompartmentChunkCandidatesPolite(db, projectPath, modelId, limit, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS, leaseHeldRenumber = false) {
861
+ async function loadUnembeddedCompartmentChunkCandidatesPolite(db, projectPath, modelId, limit, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS, leaseHeldRenumber = false, isEligible) {
862
862
  const rows = getBackfillCandidateStatement(db).all(projectPath);
863
863
  const candidates = mapBackfillCandidateRows(rows);
864
864
  const missing = [];
865
865
  const stale = [];
866
866
  let sliceStarted = performance.now();
867
867
  for (const candidate of candidates) {
868
+ if (isEligible && !isEligible(candidate)) {
869
+ sliceStarted = await yieldCoverageSlice(sliceStarted);
870
+ continue;
871
+ }
868
872
  const classification = classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens);
869
873
  if (classification.defect === "missing")
870
874
  missing.push(candidate);
@@ -1019,7 +1023,7 @@ function memoizedCoverageWindows(candidate, canonicalText, sourceKey, modelId, m
1019
1023
  return windows;
1020
1024
  }
1021
1025
  async function yieldCoverageSlice(started) {
1022
- if (performance.now() - started < 35)
1026
+ if (performance.now() - started < 8)
1023
1027
  return started;
1024
1028
  await new Promise((resolve) => setTimeout(resolve, 0));
1025
1029
  return performance.now();
@@ -1093,6 +1097,47 @@ function selectHashIncompleteChunkCandidates(db, projectPath, modelId, candidate
1093
1097
  return [...missing, ...stale].slice(0, limit);
1094
1098
  }
1095
1099
  var sessionBackfillCandidateStatements = new WeakMap;
1100
+ function loadUnembeddedSessionChunkCandidates(db, projectPath, sessionId, modelId, limit, excludeIds, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS, leaseHeldRenumber = false) {
1101
+ const exclusions = excludeIds && excludeIds.length > 0 ? excludeIds : [];
1102
+ const exclusionSql = exclusions.length > 0 ? `AND c.id NOT IN (${exclusions.map(() => "?").join(", ")})` : "";
1103
+ const stmt = exclusions.length > 0 ? db.prepare(`SELECT c.id AS id,
1104
+ c.session_id AS sessionId,
1105
+ c.start_message AS startMessage,
1106
+ c.end_message AS endMessage,
1107
+ c.title AS title
1108
+ FROM compartments c
1109
+ JOIN session_projects sp
1110
+ ON sp.session_id = c.session_id
1111
+ AND sp.harness = c.harness
1112
+ AND sp.project_path = ?
1113
+ WHERE c.session_id = ?
1114
+ AND c.start_message IS NOT NULL
1115
+ AND c.end_message IS NOT NULL
1116
+ ${exclusionSql}
1117
+ ORDER BY c.start_message ASC, c.id ASC`) : (() => {
1118
+ let cached = sessionBackfillCandidateStatements.get(db);
1119
+ if (!cached) {
1120
+ cached = db.prepare(`SELECT c.id AS id,
1121
+ c.session_id AS sessionId,
1122
+ c.start_message AS startMessage,
1123
+ c.end_message AS endMessage,
1124
+ c.title AS title
1125
+ FROM compartments c
1126
+ JOIN session_projects sp
1127
+ ON sp.session_id = c.session_id
1128
+ AND sp.harness = c.harness
1129
+ AND sp.project_path = ?
1130
+ WHERE c.session_id = ?
1131
+ AND c.start_message IS NOT NULL
1132
+ AND c.end_message IS NOT NULL
1133
+ ORDER BY c.start_message ASC, c.id ASC`);
1134
+ sessionBackfillCandidateStatements.set(db, cached);
1135
+ }
1136
+ return cached;
1137
+ })();
1138
+ const rows = stmt.all(projectPath, sessionId, ...exclusions);
1139
+ return selectHashIncompleteChunkCandidates(db, projectPath, modelId, mapBackfillCandidateRows(rows), Math.max(1, limit), maxInputTokens, leaseHeldRenumber);
1140
+ }
1096
1141
  async function loadUnembeddedSessionChunkCandidatesPolite(db, projectPath, sessionId, modelId, limit, excludeIds = [], maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS, leaseHeldRenumber = false) {
1097
1142
  const excluded = new Set(excludeIds);
1098
1143
  const missing = [];
@@ -1109,10 +1154,22 @@ async function loadUnembeddedSessionChunkCandidatesPolite(db, projectPath, sessi
1109
1154
  else if (leaseHeldRenumber) {
1110
1155
  applyLeaseHeldCoverageRepair(db, candidate, projectPath, modelId, classification);
1111
1156
  }
1157
+ if (missing.length >= Math.max(1, limit))
1158
+ return missing;
1112
1159
  started = await yieldCoverageSlice(started);
1113
1160
  }
1114
1161
  return [...missing, ...stale].slice(0, Math.max(1, limit));
1115
1162
  }
1163
+ function countUnembeddedSessionCompartments(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS) {
1164
+ const rows = getSessionBackfillRows(db, projectPath, sessionId);
1165
+ let count = 0;
1166
+ for (const candidate of rows) {
1167
+ const { defect } = classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens);
1168
+ if (defect === "missing" || defect === "stale")
1169
+ count++;
1170
+ }
1171
+ return count;
1172
+ }
1116
1173
  function countSessionCompartmentEmbedCoverage(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS) {
1117
1174
  const candidates = getSessionBackfillRows(db, projectPath, sessionId);
1118
1175
  let embedded = 0;
@@ -1165,4 +1222,4 @@ async function countUnembeddedSessionCompartmentsPolite(db, projectPath, session
1165
1222
  return count;
1166
1223
  }
1167
1224
 
1168
- export { CHUNK_WINDOW_SAFETY_RATIO, normalizeCompartmentChunkMaxInputTokens, buildCanonicalChunkTextFromFts, buildCompartmentSummaryFallbackText, canonicalizeInMemoryChunkTextForEmbedding, chunkCanonicalText, chunkEmbeddingWindowsAreCurrent, replaceCompartmentChunkEmbeddings, loadCompartmentChunkEmbeddingsForSearch, loadUnembeddedShadowChunkCandidates, loadUnembeddedCompartmentChunkCandidatesPolite, deleteChunkEmbedBackoffForSession, recordChunkEmbedBackoff, chunkWindowSourceKey, loadUnembeddedSessionChunkCandidatesPolite, countSessionCompartmentEmbedCoverage, countSessionCompartmentEmbedCoveragePolite, countUnembeddedSessionCompartmentsPolite };
1225
+ export { DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS, CHUNK_WINDOW_SAFETY_RATIO, normalizeCompartmentChunkMaxInputTokens, buildCanonicalChunkTextFromFts, buildCompartmentSummaryFallbackText, canonicalizeInMemoryChunkTextForEmbedding, chunkCanonicalText, chunkEmbeddingWindowsAreCurrent, replaceCompartmentChunkEmbeddings, loadCompartmentChunkEmbeddingsForSearch, loadUnembeddedShadowChunkCandidates, loadUnembeddedCompartmentChunkCandidatesPolite, deleteChunkEmbedBackoffForSession, recordChunkEmbedBackoff, chunkWindowSourceKey, loadUnembeddedSessionChunkCandidates, loadUnembeddedSessionChunkCandidatesPolite, countUnembeddedSessionCompartments, countSessionCompartmentEmbedCoverage, countSessionCompartmentEmbedCoveragePolite, countUnembeddedSessionCompartmentsPolite };
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  DEFAULT_LOCAL_EMBEDDING_MODEL
3
- } from "./index-ta0ed2nc.js";
3
+ } from "./index-1k729e4f.js";
4
4
  import {
5
5
  log2
6
- } from "./index-gycf3sp7.js";
6
+ } from "./index-7bqrfyny.js";
7
7
  import {
8
8
  isSynapseEmbeddingTruncated,
9
9
  SynapseEmbeddingProvider
10
- } from "./index-szh001qb.js";
10
+ } from "./index-6dz2ed1v.js";
11
11
  import {
12
12
  LocalEmbeddingProvider
13
- } from "./index-8yjhda46.js";
13
+ } from "./index-9jvktm7k.js";
14
14
  import {
15
15
  OpenAICompatibleEmbeddingProvider,
16
16
  getProjectEmbeddingSnapshot2,
17
17
  embedBatchForProject2
18
- } from "./index-78c864c8.js";
18
+ } from "./index-nwbhe6qv.js";
19
19
  import {
20
20
  isEmbeddingHostBusy2
21
21
  } from "./index-9p40dgkm.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  DEFAULT_LOCAL_EMBEDDING_MODEL
3
- } from "./index-ta0ed2nc.js";
3
+ } from "./index-1k729e4f.js";
4
4
  import {
5
5
  getSynapseLaneIdentity
6
- } from "./index-szh001qb.js";
6
+ } from "./index-6dz2ed1v.js";
7
7
  import {
8
8
  getHarness2
9
9
  } from "./index-0h2mkab2.js";
@@ -11,7 +11,7 @@ import {
11
11
  getMagicContextStorageDir,
12
12
  importPluginModule,
13
13
  log2
14
- } from "./index-gycf3sp7.js";
14
+ } from "./index-7bqrfyny.js";
15
15
  import {
16
16
  inRootAsyncContext2
17
17
  } from "./index-asrxgdt4.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  log2
3
- } from "./index-gycf3sp7.js";
3
+ } from "./index-7bqrfyny.js";
4
4
 
5
5
  // ../plugin/src/shared/rpc-utils.ts
6
6
  import { execFile, execFileSync } from "node:child_process";