@cortexkit/pi-magic-context 0.49.86 → 0.49.89

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 (41) hide show
  1. package/dist/auto-search-worker.js +13 -7
  2. package/dist/chunk-embedding-write-worker.js +6 -6
  3. package/dist/{compartment-chunk-embedding-avkyp2df.js → compartment-chunk-embedding-7pzb51r4.js} +3 -1
  4. package/dist/{embedding-backfill-7a01ns95.js → embedding-backfill-yydkxhrp.js} +8 -8
  5. package/dist/{embedding-cache-7rp4gqzr.js → embedding-cache-xft42rsb.js} +5 -1
  6. package/dist/embedding-worker.js +2 -2
  7. package/dist/{index-cxczethe.js → index-464qhgjp.js} +4 -4
  8. package/dist/{index-hpbdnbtf.js → index-68tyan5e.js} +8 -2
  9. package/dist/{index-7yz95h83.js → index-6x595qtk.js} +76 -13
  10. package/dist/{index-29nw7n1r.js → index-70sw39ck.js} +1 -1
  11. package/dist/{index-53fgdt6n.js → index-7xsbhw6m.js} +1 -1
  12. package/dist/{index-ex9te7tc.js → index-aahd8x9s.js} +1 -1
  13. package/dist/{index-rqdjb6j3.js → index-fsjsvq78.js} +1 -1
  14. package/dist/{index-fvfq9gva.js → index-hp320128.js} +1 -1
  15. package/dist/{index-yhzhdp3m.js → index-hrwc50n3.js} +48 -1
  16. package/dist/{index-fd57gfnn.js → index-hs862sjk.js} +3 -3
  17. package/dist/{index-7thk2cwt.js → index-jhsypxe9.js} +3 -0
  18. package/dist/{index-94z1xzmr.js → index-kezt62gs.js} +1 -1
  19. package/dist/{index-wy6h2wn2.js → index-kn83b37d.js} +5 -5
  20. package/dist/{index-5n3bqhp9.js → index-ndprcb9x.js} +25 -16
  21. package/dist/{index-0t9xfj3x.js → index-qpdh2aff.js} +1 -1
  22. package/dist/{index-bjr11ay6.js → index-qtfp61mq.js} +4 -4
  23. package/dist/{index-8x8wtn3t.js → index-rrm9ce0j.js} +108 -13
  24. package/dist/{index-gbc29ysq.js → index-rzwcmbww.js} +1 -1
  25. package/dist/{index-sqp84q6s.js → index-w48rf3j6.js} +2 -2
  26. package/dist/{index-8631kxcp.js → index-z2bdsba1.js} +14 -14
  27. package/dist/index.js +397 -135
  28. package/dist/{message-index-bounded-sra4jpac.js → message-index-bounded-vxf4ez55.js} +2 -2
  29. package/dist/migration-worker.js +4 -4
  30. package/dist/{project-embedding-registry-agkd7egh.js → project-embedding-registry-f9tzr12g.js} +7 -7
  31. package/dist/raw-ordinal-warmup-worker.js +3 -3
  32. package/dist/{read-session-chunk-wek7gb7j.js → read-session-chunk-tec7t4vy.js} +1 -1
  33. package/dist/{render-rphfegr8.js → render-mr2bb4yf.js} +9 -9
  34. package/dist/{rpc-notifications-889zvhn2.js → rpc-notifications-qc5ha504.js} +1 -1
  35. package/dist/{search-archive-7p43e77j.js → search-archive-abtztrw5.js} +3 -3
  36. package/dist/{search-rdvsnxky.js → search-rdqrskte.js} +14 -14
  37. package/dist/{storage-memory-0ndn65fm.js → storage-memory-2sed597w.js} +2 -2
  38. package/dist/subagent-entry.js +19 -19
  39. package/dist/tag-snapshot-worker-pi.js +4 -4
  40. package/dist/{v2-archive-reader-qc4c9wrp.js → v2-archive-reader-qaecyb4y.js} +1 -1
  41. package/package.json +1 -1
@@ -17,7 +17,7 @@ serveWorkerJobs(async (initial, port) => {
17
17
  }
18
18
  const [
19
19
  { ensureMemoryEmbeddings },
20
- { getProjectEmbeddings },
20
+ { getProjectEmbeddings, keepWorkerMemoryEmbeddings, maintainKeptWorkerMemoryEmbeddings },
21
21
  { getMemoriesByProject },
22
22
  { installProjectEmbeddingSearchBridge },
23
23
  { searchMessageHistory, unifiedSearch },
@@ -27,12 +27,12 @@ serveWorkerJobs(async (initial, port) => {
27
27
  { Database, registerSqliteDiagnosticSink },
28
28
  { log }
29
29
  ] = await Promise.all([
30
- import("./embedding-backfill-7a01ns95.js"),
31
- import("./embedding-cache-7rp4gqzr.js"),
32
- import("./storage-memory-0ndn65fm.js"),
33
- import("./project-embedding-registry-agkd7egh.js"),
34
- import("./search-rdvsnxky.js"),
35
- import("./compartment-chunk-embedding-avkyp2df.js"),
30
+ import("./embedding-backfill-yydkxhrp.js"),
31
+ import("./embedding-cache-xft42rsb.js"),
32
+ import("./storage-memory-2sed597w.js"),
33
+ import("./project-embedding-registry-f9tzr12g.js"),
34
+ import("./search-rdqrskte.js"),
35
+ import("./compartment-chunk-embedding-7pzb51r4.js"),
36
36
  import("./embedding-activity-ew6dshfd.js"),
37
37
  import("./harness-9872e0ym.js"),
38
38
  import("./sqlite-v89bj0yy.js"),
@@ -64,6 +64,8 @@ serveWorkerJobs(async (initial, port) => {
64
64
  }
65
65
  db = new Database(input.path, input.job === "backfill" ? undefined : { readonly: true });
66
66
  db.exec("PRAGMA busy_timeout = 250");
67
+ if (persistent && input.job === "search")
68
+ keepWorkerMemoryEmbeddings(db);
67
69
  const { closePort } = exitOnWorkerClose(port, () => db.close());
68
70
  const CHUNK_POOL_MAINTENANCE_INTERVAL_MS = 5000;
69
71
  let maintenanceTimer;
@@ -72,6 +74,9 @@ serveWorkerJobs(async (initial, port) => {
72
74
  if (maintaining)
73
75
  return;
74
76
  maintaining = true;
77
+ try {
78
+ maintainKeptWorkerMemoryEmbeddings(db);
79
+ } catch {}
75
80
  maintainCompartmentChunkSearchPools(db).catch(() => {}).finally(() => {
76
81
  maintaining = false;
77
82
  });
@@ -135,6 +140,7 @@ serveWorkerJobs(async (initial, port) => {
135
140
  const diagnostics = input.options.autoSearchDiagnostics;
136
141
  const results = await unifiedSearch(db, input.sessionId, input.projectPath, input.query, {
137
142
  ...input.options,
143
+ deferChunkPoolWarmup: persistent,
138
144
  backfillMemoryEmbeddings: false,
139
145
  countRetrievals: false,
140
146
  measurementDisabled: true,
@@ -24,21 +24,21 @@ import {
24
24
  recordChunkEmbedBackoff2,
25
25
  loadUnembeddedSessionChunkCandidates2,
26
26
  countUnembeddedSessionCompartments2
27
- } from "./index-cxczethe.js";
27
+ } from "./index-464qhgjp.js";
28
28
  import {
29
29
  recordSessionProjectIdentity,
30
30
  acquireGitSweepLease,
31
31
  renewGitSweepLease,
32
32
  releaseGitSweepLease
33
- } from "./index-ex9te7tc.js";
34
- import"./index-8x8wtn3t.js";
35
- import"./index-94z1xzmr.js";
33
+ } from "./index-aahd8x9s.js";
34
+ import"./index-rrm9ce0j.js";
35
+ import"./index-kezt62gs.js";
36
36
  import {
37
37
  LATEST_SUPPORTED_VERSION,
38
38
  enforceSchemaFence
39
- } from "./index-7yz95h83.js";
39
+ } from "./index-6x595qtk.js";
40
40
  import"./index-3bb24eb6.js";
41
- import"./index-53fgdt6n.js";
41
+ import"./index-7xsbhw6m.js";
42
42
  import"./index-jhmz9tgv.js";
43
43
  import"./index-135e8hvg.js";
44
44
  import"./index-n0zjvs3h.js";
@@ -9,6 +9,7 @@ import {
9
9
  chunkEmbeddingWindowsAreCurrent2,
10
10
  replaceCompartmentChunkEmbeddings2,
11
11
  loadCompartmentChunkEmbeddingsForSearch2,
12
+ trackCompartmentChunkSearchPool2,
12
13
  getLastCompartmentChunkPoolWarm2,
13
14
  peekCompartmentChunkSearchPool2,
14
15
  warmCompartmentChunkSearchPool2,
@@ -24,7 +25,7 @@ import {
24
25
  countSessionCompartmentEmbedCoverage2,
25
26
  countSessionCompartmentEmbedCoveragePolite2,
26
27
  countUnembeddedSessionCompartmentsPolite2
27
- } from "./index-cxczethe.js";
28
+ } from "./index-464qhgjp.js";
28
29
  import"./index-5rcjs14a.js";
29
30
  import"./index-ghp32f9m.js";
30
31
  import"./index-xjhq27z9.js";
@@ -62,5 +63,6 @@ export {
62
63
  peekCompartmentChunkSearchPool2 as peekCompartmentChunkSearchPool,
63
64
  recordChunkEmbedBackoff2 as recordChunkEmbedBackoff,
64
65
  replaceCompartmentChunkEmbeddings2 as replaceCompartmentChunkEmbeddings,
66
+ trackCompartmentChunkSearchPool2 as trackCompartmentChunkSearchPool,
65
67
  warmCompartmentChunkSearchPool2 as warmCompartmentChunkSearchPool
66
68
  };
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  ensureMemoryEmbeddings2
3
- } from "./index-sqp84q6s.js";
4
- import"./index-wy6h2wn2.js";
3
+ } from "./index-w48rf3j6.js";
4
+ import"./index-kn83b37d.js";
5
5
  import"./index-9p40dgkm.js";
6
6
  import"./index-hgd00nas.js";
7
- import"./index-yhzhdp3m.js";
8
- import"./index-ex9te7tc.js";
9
- import"./index-cxczethe.js";
10
- import"./index-rqdjb6j3.js";
7
+ import"./index-hrwc50n3.js";
8
+ import"./index-aahd8x9s.js";
9
+ import"./index-464qhgjp.js";
10
+ import"./index-fsjsvq78.js";
11
11
  import"./index-5rcjs14a.js";
12
12
  import"./index-vcegxfwg.js";
13
- import"./index-94z1xzmr.js";
13
+ import"./index-kezt62gs.js";
14
14
  import"./index-ghp32f9m.js";
15
15
  import"./index-xjhq27z9.js";
16
16
  import"./index-wfqysrwq.js";
17
17
  import"./index-8sqebjzk.js";
18
18
  import"./index-1ts77n1b.js";
19
- import"./index-8x8wtn3t.js";
19
+ import"./index-rrm9ce0j.js";
20
20
  import"./index-pefn1gt5.js";
21
21
  import"./index-2qtx0q6h.js";
22
22
  import"./index-tm11k42a.js";
@@ -1,15 +1,19 @@
1
1
  import {
2
+ keepWorkerMemoryEmbeddings2,
3
+ maintainKeptWorkerMemoryEmbeddings2,
2
4
  getProjectEmbeddings2,
3
5
  peekProjectEmbeddings2,
4
6
  invalidateProject2,
5
7
  invalidateMemory2,
6
8
  resetEmbeddingCacheForTests2,
7
9
  setEmbeddingCacheTtlForTests2
8
- } from "./index-yhzhdp3m.js";
10
+ } from "./index-hrwc50n3.js";
9
11
  export {
10
12
  getProjectEmbeddings2 as getProjectEmbeddings,
11
13
  invalidateMemory2 as invalidateMemory,
12
14
  invalidateProject2 as invalidateProject,
15
+ keepWorkerMemoryEmbeddings2 as keepWorkerMemoryEmbeddings,
16
+ maintainKeptWorkerMemoryEmbeddings2 as maintainKeptWorkerMemoryEmbeddings,
13
17
  peekProjectEmbeddings2 as peekProjectEmbeddings,
14
18
  resetEmbeddingCacheForTests2 as resetEmbeddingCacheForTests,
15
19
  setEmbeddingCacheTtlForTests2 as setEmbeddingCacheTtlForTests
@@ -8,7 +8,7 @@ import {
8
8
  import"./index-dnp1jjar.js";
9
9
  import {
10
10
  setStoragePrivatePermissionEnforcement
11
- } from "./index-8x8wtn3t.js";
11
+ } from "./index-rrm9ce0j.js";
12
12
  import"./index-vcegxfwg.js";
13
13
  import"./index-5rcjs14a.js";
14
14
  import"./index-pefn1gt5.js";
@@ -18,7 +18,7 @@ import {
18
18
  resolveLocalEmbeddingWorkerRuntime,
19
19
  getLocalEmbeddingNativeMemoryStats,
20
20
  LocalEmbeddingProvider
21
- } from "./index-rqdjb6j3.js";
21
+ } from "./index-fsjsvq78.js";
22
22
 
23
23
  // ../plugin/src/features/magic-context/memory/embedding-worker.ts
24
24
  import { parentPort, workerData } from "node:worker_threads";
@@ -954,7 +954,7 @@ async function loadCompartmentChunkEmbeddingsForSearch2(db, sessionId, projectPa
954
954
  var CHUNK_POOL_FULL_PROBE_INTERVAL_MS = 60000;
955
955
  var TRACKED_SEARCH_POOL_LIMIT = 8;
956
956
  var trackedSearchPools = new WeakMap;
957
- function trackSearchPool(db, sessionId, projectPath, modelId) {
957
+ function trackCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId) {
958
958
  let tracked = trackedSearchPools.get(db);
959
959
  if (!tracked) {
960
960
  tracked = new Map;
@@ -981,7 +981,7 @@ function peekCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId, da
981
981
  diagnostic.peek = "no-model";
982
982
  return null;
983
983
  }
984
- trackSearchPool(db, sessionId, projectPath, modelId);
984
+ trackCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId);
985
985
  const entry = getDecodedSearchPool(db).get(searchPoolKey(sessionId, projectPath, modelId));
986
986
  if (!entry || searchPoolInTransaction(db)) {
987
987
  if (diagnostic)
@@ -1009,7 +1009,7 @@ async function warmCompartmentChunkSearchPool2(db, sessionId, projectPath, model
1009
1009
  });
1010
1010
  if (!modelId)
1011
1011
  return report("current");
1012
- trackSearchPool(db, sessionId, projectPath, modelId);
1012
+ trackCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId);
1013
1013
  const key = searchPoolKey(sessionId, projectPath, modelId);
1014
1014
  try {
1015
1015
  if (pendingSearchPools.get(db)?.has(key))
@@ -1466,4 +1466,4 @@ async function countUnembeddedSessionCompartmentsPolite2(db, projectPath, sessio
1466
1466
  return count;
1467
1467
  }
1468
1468
 
1469
- export { DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2, CHUNK_WINDOW_SAFETY_RATIO2, normalizeCompartmentChunkMaxInputTokens2, buildCanonicalChunkTextFromFts2, buildCompartmentSummaryFallbackText2, canonicalizeInMemoryChunkTextForEmbedding2, chunkCanonicalText2, chunkEmbeddingWindowsAreCurrent2, replaceCompartmentChunkEmbeddings2, loadCompartmentChunkEmbeddingsForSearch2, getLastCompartmentChunkPoolWarm2, peekCompartmentChunkSearchPool2, warmCompartmentChunkSearchPool2, maintainCompartmentChunkSearchPools2, loadUnembeddedShadowChunkCandidates2, loadUnembeddedCompartmentChunkCandidatesPolite2, deleteChunkEmbedBackoffForSession2, recordChunkEmbedBackoff2, chunkWindowSourceKey2, loadUnembeddedSessionChunkCandidates2, loadUnembeddedSessionChunkCandidatesPolite2, countUnembeddedSessionCompartments2, countSessionCompartmentEmbedCoverage2, countSessionCompartmentEmbedCoveragePolite2, countUnembeddedSessionCompartmentsPolite2 };
1469
+ export { DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2, CHUNK_WINDOW_SAFETY_RATIO2, normalizeCompartmentChunkMaxInputTokens2, buildCanonicalChunkTextFromFts2, buildCompartmentSummaryFallbackText2, canonicalizeInMemoryChunkTextForEmbedding2, chunkCanonicalText2, chunkEmbeddingWindowsAreCurrent2, replaceCompartmentChunkEmbeddings2, loadCompartmentChunkEmbeddingsForSearch2, trackCompartmentChunkSearchPool2, getLastCompartmentChunkPoolWarm2, peekCompartmentChunkSearchPool2, warmCompartmentChunkSearchPool2, maintainCompartmentChunkSearchPools2, loadUnembeddedShadowChunkCandidates2, loadUnembeddedCompartmentChunkCandidatesPolite2, deleteChunkEmbedBackoffForSession2, recordChunkEmbedBackoff2, chunkWindowSourceKey2, loadUnembeddedSessionChunkCandidates2, loadUnembeddedSessionChunkCandidatesPolite2, countUnembeddedSessionCompartments2, countSessionCompartmentEmbedCoverage2, countSessionCompartmentEmbedCoveragePolite2, countUnembeddedSessionCompartmentsPolite2 };
@@ -989,8 +989,14 @@ class DreamTokenBudgetExceeded extends Error {
989
989
  var TOKEN_BUDGET_FINALIZE_MESSAGE = "You're out of token budget. Stop investigating: make no more tool calls and output your result now, covering only what you've already checked; leave the rest out.";
990
990
  var TOKEN_BUDGET_TOOL_REFUSAL = "Out of token budget: no more tool calls. Output your result now.";
991
991
  var finalizingChildren = new Map;
992
- function registerBudgetFinalizeChild(sessionId, guard) {
993
- finalizingChildren.set(sessionId, guard);
992
+ function registerBudgetFinalizeChild(sessionId, budget) {
993
+ const child = { budget, refusedBeforeSubmission: new Set };
994
+ finalizingChildren.set(sessionId, child);
995
+ return (inFlightAtAbort) => {
996
+ for (const id of child.refusedBeforeSubmission)
997
+ inFlightAtAbort.delete(id);
998
+ child.inFlightAtAbort = inFlightAtAbort;
999
+ };
994
1000
  }
995
1001
  function releaseBudgetFinalizeChild(sessionId) {
996
1002
  finalizingChildren.delete(sessionId);
@@ -13,7 +13,7 @@ import {
13
13
  } from "./index-2qtx0q6h.js";
14
14
  import {
15
15
  scheduleAfterBootQuiet
16
- } from "./index-94z1xzmr.js";
16
+ } from "./index-kezt62gs.js";
17
17
  import {
18
18
  getHarness2,
19
19
  harnessOwnsOpenCodeStore2
@@ -41,7 +41,7 @@ import {
41
41
  copyStorageFileSync,
42
42
  copyStorageTreeSync,
43
43
  tightenStorageTreeSync
44
- } from "./index-8x8wtn3t.js";
44
+ } from "./index-rrm9ce0j.js";
45
45
  import {
46
46
  configureContextDatabasePragmas2
47
47
  } from "./index-fapenpch.js";
@@ -63,7 +63,7 @@ import {
63
63
  hasPendingMigrations,
64
64
  getMainThreadMigrationBodyCount,
65
65
  runMigrations
66
- } from "./index-53fgdt6n.js";
66
+ } from "./index-7xsbhw6m.js";
67
67
  import {
68
68
  setDatabase,
69
69
  loadToolDefinitionMeasurements,
@@ -104,6 +104,7 @@ function ensureContextStoreUuid(db) {
104
104
  // ../plugin/src/features/magic-context/storage-db.ts
105
105
  import {
106
106
  existsSync as existsSync2,
107
+ lstatSync,
107
108
  readdirSync,
108
109
  readFileSync,
109
110
  rmdirSync,
@@ -651,11 +652,73 @@ function getMigrationOnOpenRefusal() {
651
652
  }
652
653
  var LATEST_SUPPORTED_VERSION = 95;
653
654
  var BOOT_SQLITE_BUSY_TIMEOUT_MS = 5000;
654
- function ensureSecureStorageDir(dir) {
655
- ensureStorageDirectorySync(dir);
655
+ function isLinkedStorageRoot(dir) {
656
+ if (process.platform === "win32")
657
+ return false;
658
+ try {
659
+ return lstatSync(dir).isSymbolicLink();
660
+ } catch {
661
+ return false;
662
+ }
656
663
  }
657
- function tightenStorageTree(dbPath) {
658
- const { failures } = tightenStorageTreeSync(dirname(dbPath), dbPath);
664
+ function ensureSecureStorageDir(dir, dbPath) {
665
+ try {
666
+ ensureStorageDirectorySync(dir);
667
+ } catch (error) {
668
+ if (shouldEnforcePrivateStoragePermissions() && isLinkedStorageRoot(dir)) {
669
+ tightenStorageTree(dbPath, true);
670
+ }
671
+ throw error;
672
+ }
673
+ }
674
+ function describeLinkedStorageSkip(reason) {
675
+ switch (reason) {
676
+ case "filesystem-root":
677
+ return "it is a filesystem root";
678
+ case "home-folder":
679
+ return "it is your home folder";
680
+ case "mount-point":
681
+ return "it is a mount point";
682
+ default: {
683
+ const entries = reason === 1 ? "entry" : "entries";
684
+ return `it holds ${reason} ${entries} that Magic Context did not create`;
685
+ }
686
+ }
687
+ }
688
+ function describeLinkedStorageFailure(failure, nonDirectoryPath) {
689
+ if (nonDirectoryPath !== undefined)
690
+ return `${nonDirectoryPath} is not a directory`;
691
+ switch (failure) {
692
+ case "ENOENT":
693
+ return "ENOENT";
694
+ case "ELOOP":
695
+ return "ELOOP";
696
+ case "EACCES":
697
+ return "EACCES";
698
+ case "EPERM":
699
+ return "EPERM";
700
+ case "ENOTDIR":
701
+ return "ENOTDIR";
702
+ default:
703
+ return "could not resolve or inspect the linked target";
704
+ }
705
+ }
706
+ function tightenStorageTree(dbPath, reportResolvedLink = false) {
707
+ const { failures, rootLink } = tightenStorageTreeSync(dirname(dbPath), dbPath);
708
+ if (rootLink && "failure" in rootLink) {
709
+ log2(`[magic-context] storage permission tightening failures=${failures}: storage root link ${rootLink.path}: ${describeLinkedStorageFailure(rootLink.failure, rootLink.nonDirectoryTarget)}`);
710
+ return;
711
+ }
712
+ if (rootLink?.skipped !== undefined) {
713
+ if (reportResolvedLink) {
714
+ const { path: linkPath, target: targetPath } = rootLink;
715
+ log2(`[magic-context] linked storage folder ${linkPath} -> ${targetPath} was not made private because ${describeLinkedStorageSkip(rootLink.skipped)}. Move the store to a folder of its own so Magic Context can protect it.`);
716
+ }
717
+ return;
718
+ }
719
+ if (rootLink && reportResolvedLink) {
720
+ log2(`[magic-context] resolved storage root link ${rootLink.path} -> ${rootLink.target}`);
721
+ }
659
722
  log2(`[magic-context] storage permission tightening failures=${failures}`);
660
723
  }
661
724
  function resolveBootBusyTimeoutMs(value) {
@@ -691,7 +754,7 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
691
754
  if (!existsSync2(legacyDbPath))
692
755
  return;
693
756
  log2(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
694
- ensureSecureStorageDir(targetDbDir);
757
+ ensureSecureStorageDir(targetDbDir, targetDbPath);
695
758
  try {
696
759
  const legacyDb = new Database2(legacyDbPath);
697
760
  try {
@@ -1089,7 +1152,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1089
1152
  state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1090
1153
  if (signal.aborted || !readsOpenCodeStore)
1091
1154
  return;
1092
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-wek7gb7j.js"));
1155
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-tec7t4vy.js"));
1093
1156
  const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-8zwv9byv.js"));
1094
1157
  if (signal.aborted)
1095
1158
  return;
@@ -2414,8 +2477,8 @@ function openDatabase(dbPathOrOptions) {
2414
2477
  if (!explicitDbPath) {
2415
2478
  migrateLegacyStorageIfNeeded(dbPath, dbDir);
2416
2479
  }
2417
- ensureSecureStorageDir(dbDir);
2418
- tightenStorageTree(dbPath);
2480
+ ensureSecureStorageDir(dbDir, dbPath);
2481
+ tightenStorageTree(dbPath, true);
2419
2482
  if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
2420
2483
  try {
2421
2484
  writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
@@ -2511,8 +2574,8 @@ async function openDatabaseAsync(dbPathOrOptions) {
2511
2574
  try {
2512
2575
  if (!explicitDbPath)
2513
2576
  migrateLegacyStorageIfNeeded(dbPath, dbDir);
2514
- ensureSecureStorageDir(dbDir);
2515
- tightenStorageTree(dbPath);
2577
+ ensureSecureStorageDir(dbDir, dbPath);
2578
+ tightenStorageTree(dbPath, true);
2516
2579
  if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
2517
2580
  try {
2518
2581
  writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  invalidateProject2,
9
9
  invalidateMemory2
10
- } from "./index-yhzhdp3m.js";
10
+ } from "./index-hrwc50n3.js";
11
11
  import {
12
12
  computeNormalizedHash
13
13
  } from "./index-9x1f96r8.js";
@@ -20,7 +20,7 @@ import {
20
20
  import {
21
21
  normalizeStoredProjectPath,
22
22
  storedPathBelongsToIdentity
23
- } from "./index-94z1xzmr.js";
23
+ } from "./index-kezt62gs.js";
24
24
  import {
25
25
  logSlowWriteTransaction
26
26
  } from "./index-1ts77n1b.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-0h2mkab2.js";
4
4
  import {
5
5
  isUserHomeDirectory
6
- } from "./index-94z1xzmr.js";
6
+ } from "./index-kezt62gs.js";
7
7
  import {
8
8
  logSlowWriteTransaction
9
9
  } from "./index-1ts77n1b.js";
@@ -22,7 +22,7 @@ import {
22
22
  writeStorageFileAsync,
23
23
  writeStorageFileHandleAsync,
24
24
  createStorageFileHandleAsync
25
- } from "./index-8x8wtn3t.js";
25
+ } from "./index-rrm9ce0j.js";
26
26
  import {
27
27
  computeNormalizedHash
28
28
  } from "./index-9x1f96r8.js";
@@ -6,7 +6,7 @@ import {
6
6
  } from "./index-pefn1gt5.js";
7
7
  import {
8
8
  readRawSessionMessageIdOrdinalsForRange2
9
- } from "./index-hpbdnbtf.js";
9
+ } from "./index-68tyan5e.js";
10
10
 
11
11
  // ../plugin/src/tools/ctx-expand/search-archive.ts
12
12
  var archiveReadsOnThisThread = 0;
@@ -84,6 +84,41 @@ function getMemoryEmbedCoverage(db, projectPath, modelId) {
84
84
  var DEFAULT_EMBEDDING_CACHE_TTL_MS = 60000;
85
85
  var projectEmbeddingCache = new Map;
86
86
  var embeddingCacheTtlMs = DEFAULT_EMBEDDING_CACHE_TTL_MS;
87
+ var keptWorkerCaches = new WeakMap;
88
+ function keepWorkerMemoryEmbeddings2(db) {
89
+ keptWorkerCaches.set(db, {
90
+ entries: new Map,
91
+ lastBackgroundReloadAt: -Infinity
92
+ });
93
+ }
94
+ function readDataVersion(db, cache) {
95
+ cache.version ??= db.prepare("PRAGMA data_version");
96
+ return Number(cache.version.get().data_version);
97
+ }
98
+ function loadKeptWorkerEntry(db, cache, projectPath, modelId, version, loadedAt) {
99
+ const embeddings = loadAllEmbeddings(db, projectPath, modelId);
100
+ cache.entries.set(projectPath, {
101
+ projectPath,
102
+ modelId,
103
+ version,
104
+ loadedAt,
105
+ embeddings
106
+ });
107
+ return embeddings;
108
+ }
109
+ function maintainKeptWorkerMemoryEmbeddings2(db) {
110
+ const cache = keptWorkerCaches.get(db);
111
+ const now = Date.now();
112
+ if (!cache?.entries.size || now - cache.lastBackgroundReloadAt < DEFAULT_EMBEDDING_CACHE_TTL_MS)
113
+ return;
114
+ const version = readDataVersion(db, cache);
115
+ for (const entry of cache.entries.values()) {
116
+ if (entry.version === version || now - entry.loadedAt < DEFAULT_EMBEDDING_CACHE_TTL_MS)
117
+ continue;
118
+ cache.lastBackgroundReloadAt = now;
119
+ loadKeptWorkerEntry(db, cache, entry.projectPath, entry.modelId, version, now);
120
+ }
121
+ }
87
122
  function cacheKey(projectPath, modelId) {
88
123
  return `${projectPath}\x00${modelId}`;
89
124
  }
@@ -99,6 +134,18 @@ function getValidCacheEntry(projectPath, modelId) {
99
134
  return entry;
100
135
  }
101
136
  function getProjectEmbeddings2(db, projectPath, modelId) {
137
+ const kept = keptWorkerCaches.get(db);
138
+ if (kept) {
139
+ const now = Date.now();
140
+ const cached = kept.entries.get(projectPath);
141
+ const entry = cached?.modelId === modelId ? cached : undefined;
142
+ if (entry && now - entry.loadedAt < DEFAULT_EMBEDDING_CACHE_TTL_MS)
143
+ return entry.embeddings;
144
+ const version = readDataVersion(db, kept);
145
+ if (entry?.version === version)
146
+ return entry.embeddings;
147
+ return loadKeptWorkerEntry(db, kept, projectPath, modelId, version, now);
148
+ }
102
149
  const cached = getValidCacheEntry(projectPath, modelId);
103
150
  if (cached) {
104
151
  return cached.embeddings;
@@ -140,4 +187,4 @@ function setEmbeddingCacheTtlForTests2(ttlMs) {
140
187
  embeddingCacheTtlMs = Math.max(0, Math.floor(ttlMs));
141
188
  }
142
189
 
143
- export { saveEmbedding, saveEmbeddingIfHashMatches, getMemoryEmbedCoverage, getProjectEmbeddings2, peekProjectEmbeddings2, invalidateProject2, invalidateMemory2, resetEmbeddingCacheForTests2, setEmbeddingCacheTtlForTests2 };
190
+ export { saveEmbedding, saveEmbeddingIfHashMatches, getMemoryEmbedCoverage, keepWorkerMemoryEmbeddings2, maintainKeptWorkerMemoryEmbeddings2, getProjectEmbeddings2, peekProjectEmbeddings2, invalidateProject2, invalidateMemory2, resetEmbeddingCacheForTests2, setEmbeddingCacheTtlForTests2 };
@@ -139,9 +139,9 @@ async function serveV2ArchiveReads2(port, openConnections) {
139
139
  import("./sqlite-v89bj0yy.js"),
140
140
  import("./store-reader-vwphd51b.js"),
141
141
  import("./store-ekaexkvc.js"),
142
- import("./read-session-chunk-wek7gb7j.js"),
143
- import("./render-rphfegr8.js"),
144
- import("./search-archive-7p43e77j.js"),
142
+ import("./read-session-chunk-tec7t4vy.js"),
143
+ import("./render-mr2bb4yf.js"),
144
+ import("./search-archive-abtztrw5.js"),
145
145
  import("./expand-attachments-8sxeyj26.js")
146
146
  ]);
147
147
  const pool = new V2StoreReaderPool;
@@ -17,13 +17,16 @@ function notificationMatchesSink(notification, sink) {
17
17
  }
18
18
  function pushLiveNotification2(type, payload, sessionId) {
19
19
  const notification = { id: nextNotificationId++, type, payload, sessionId };
20
+ let delivered = false;
20
21
  for (const sink of sinks) {
21
22
  if (sink.sessionId !== sessionId)
22
23
  continue;
23
24
  try {
24
25
  sink.send(notification);
26
+ delivered = true;
25
27
  } catch {}
26
28
  }
29
+ return delivered;
27
30
  }
28
31
  function pushNotification2(type, payload, sessionId, options) {
29
32
  const notification = { id: nextNotificationId++, type, payload, sessionId };
@@ -4,7 +4,7 @@ import {
4
4
  } from "./index-tm11k42a.js";
5
5
  import {
6
6
  writeStorageFileAtomicSync
7
- } from "./index-8x8wtn3t.js";
7
+ } from "./index-rrm9ce0j.js";
8
8
  import {
9
9
  inRootAsyncContext2
10
10
  } from "./index-2qtx0q6h.js";
@@ -43,7 +43,7 @@ import {
43
43
  countSessionCompartmentEmbedCoverage2,
44
44
  countSessionCompartmentEmbedCoveragePolite2,
45
45
  countUnembeddedSessionCompartmentsPolite2
46
- } from "./index-cxczethe.js";
46
+ } from "./index-464qhgjp.js";
47
47
  import {
48
48
  DEFAULT_LOCAL_EMBEDDING_MODEL
49
49
  } from "./index-vcegxfwg.js";
@@ -56,7 +56,7 @@ import {
56
56
  getEmbeddingProviderIdentity,
57
57
  dominantEmbeddingFailure,
58
58
  LocalEmbeddingProvider
59
- } from "./index-rqdjb6j3.js";
59
+ } from "./index-fsjsvq78.js";
60
60
  import {
61
61
  embedPauseBySession,
62
62
  activeEmbeddingSessions,
@@ -67,7 +67,7 @@ import {
67
67
  } from "./index-hgd00nas.js";
68
68
  import {
69
69
  setBootQuietPeriodForTests
70
- } from "./index-94z1xzmr.js";
70
+ } from "./index-kezt62gs.js";
71
71
  import {
72
72
  isEmbeddingHostBusy2
73
73
  } from "./index-9p40dgkm.js";
@@ -78,12 +78,12 @@ import {
78
78
  acquireGitSweepLease,
79
79
  renewGitSweepLease,
80
80
  releaseGitSweepLease
81
- } from "./index-ex9te7tc.js";
81
+ } from "./index-aahd8x9s.js";
82
82
  import {
83
83
  saveEmbeddingIfHashMatches,
84
84
  getMemoryEmbedCoverage,
85
85
  invalidateProject2
86
- } from "./index-yhzhdp3m.js";
86
+ } from "./index-hrwc50n3.js";
87
87
  import {
88
88
  isKnownAutocommit
89
89
  } from "./index-nrzkqte4.js";