@cortexkit/pi-magic-context 0.49.85 → 0.49.87

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 (34) hide show
  1. package/dist/auto-search-worker.js +13 -7
  2. package/dist/chunk-embedding-write-worker.js +2 -2
  3. package/dist/{compartment-chunk-embedding-avkyp2df.js → compartment-chunk-embedding-7pzb51r4.js} +3 -1
  4. package/dist/{embedding-backfill-7a01ns95.js → embedding-backfill-za59jg6b.js} +4 -4
  5. package/dist/{embedding-cache-7rp4gqzr.js → embedding-cache-xft42rsb.js} +5 -1
  6. package/dist/{index-cxczethe.js → index-464qhgjp.js} +4 -4
  7. package/dist/{index-ty0tvxhm.js → index-4c48169d.js} +9 -9
  8. package/dist/{index-hpbdnbtf.js → index-68tyan5e.js} +8 -2
  9. package/dist/{index-29nw7n1r.js → index-70sw39ck.js} +1 -1
  10. package/dist/{index-wy6h2wn2.js → index-8qdebv92.js} +2 -2
  11. package/dist/{index-sqp84q6s.js → index-affz2pyv.js} +2 -2
  12. package/dist/{index-bjr11ay6.js → index-bkagkxm5.js} +2 -2
  13. package/dist/{index-fvfq9gva.js → index-hp320128.js} +1 -1
  14. package/dist/{index-yhzhdp3m.js → index-hrwc50n3.js} +48 -1
  15. package/dist/{index-7thk2cwt.js → index-jhsypxe9.js} +3 -0
  16. package/dist/{index-0t9xfj3x.js → index-qpdh2aff.js} +1 -1
  17. package/dist/{index-7v0z62ek.js → index-s3s4px1q.js} +19 -11
  18. package/dist/{index-7yz95h83.js → index-wd5xfz8m.js} +1 -1
  19. package/dist/{index-fd57gfnn.js → index-xemjzc1v.js} +3 -3
  20. package/dist/index.js +135 -38
  21. package/dist/{message-index-bounded-sra4jpac.js → message-index-bounded-vxf4ez55.js} +2 -2
  22. package/dist/migration-worker.js +1 -1
  23. package/dist/{project-embedding-registry-agkd7egh.js → project-embedding-registry-4kwf0m7j.js} +3 -3
  24. package/dist/raw-ordinal-warmup-worker.js +3 -3
  25. package/dist/{read-session-chunk-wek7gb7j.js → read-session-chunk-tec7t4vy.js} +1 -1
  26. package/dist/{render-rphfegr8.js → render-2jzjgetc.js} +5 -5
  27. package/dist/{rpc-notifications-889zvhn2.js → rpc-notifications-qc5ha504.js} +1 -1
  28. package/dist/{search-pwafh0v5.js → search-8dyn724d.js} +8 -8
  29. package/dist/{search-archive-7p43e77j.js → search-archive-ze1567mj.js} +3 -3
  30. package/dist/{storage-memory-0ndn65fm.js → storage-memory-2sed597w.js} +2 -2
  31. package/dist/subagent-entry.js +13 -13
  32. package/dist/tag-snapshot-worker-pi.js +1 -1
  33. package/dist/{v2-archive-reader-qc4c9wrp.js → v2-archive-reader-vq596vh8.js} +1 -1
  34. 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-pwafh0v5.js"),
35
- import("./compartment-chunk-embedding-avkyp2df.js"),
30
+ import("./embedding-backfill-za59jg6b.js"),
31
+ import("./embedding-cache-xft42rsb.js"),
32
+ import("./storage-memory-2sed597w.js"),
33
+ import("./project-embedding-registry-4kwf0m7j.js"),
34
+ import("./search-8dyn724d.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,7 +24,7 @@ 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,
@@ -36,7 +36,7 @@ import"./index-94z1xzmr.js";
36
36
  import {
37
37
  LATEST_SUPPORTED_VERSION,
38
38
  enforceSchemaFence
39
- } from "./index-7yz95h83.js";
39
+ } from "./index-wd5xfz8m.js";
40
40
  import"./index-3bb24eb6.js";
41
41
  import"./index-53fgdt6n.js";
42
42
  import"./index-jhmz9tgv.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,12 +1,12 @@
1
1
  import {
2
2
  ensureMemoryEmbeddings2
3
- } from "./index-sqp84q6s.js";
4
- import"./index-wy6h2wn2.js";
3
+ } from "./index-affz2pyv.js";
4
+ import"./index-8qdebv92.js";
5
5
  import"./index-9p40dgkm.js";
6
6
  import"./index-hgd00nas.js";
7
- import"./index-yhzhdp3m.js";
7
+ import"./index-hrwc50n3.js";
8
8
  import"./index-ex9te7tc.js";
9
- import"./index-cxczethe.js";
9
+ import"./index-464qhgjp.js";
10
10
  import"./index-rqdjb6j3.js";
11
11
  import"./index-5rcjs14a.js";
12
12
  import"./index-vcegxfwg.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
@@ -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 };
@@ -71,10 +71,10 @@ import {
71
71
  renderMessageByOrdinal2,
72
72
  renderVerboseRange2,
73
73
  renderItemByTag2
74
- } from "./index-bjr11ay6.js";
74
+ } from "./index-bkagkxm5.js";
75
75
  import {
76
76
  getLastIndexedOrdinal
77
- } from "./index-0t9xfj3x.js";
77
+ } from "./index-qpdh2aff.js";
78
78
  import {
79
79
  TODO_STATUSES,
80
80
  TODO_PRIORITIES,
@@ -111,11 +111,11 @@ import {
111
111
  supersededMemory2,
112
112
  mergeMemoryStats2,
113
113
  archiveMemory2
114
- } from "./index-29nw7n1r.js";
114
+ } from "./index-70sw39ck.js";
115
115
  import {
116
116
  saveEmbedding,
117
117
  invalidateMemory2
118
- } from "./index-yhzhdp3m.js";
118
+ } from "./index-hrwc50n3.js";
119
119
  import {
120
120
  preflightLocalEmbeddingPooling
121
121
  } from "./index-rqdjb6j3.js";
@@ -131,7 +131,7 @@ import {
131
131
  unregisterProjectEmbedding2,
132
132
  getProjectEmbeddingSnapshot2,
133
133
  embedTextForProject2
134
- } from "./index-wy6h2wn2.js";
134
+ } from "./index-8qdebv92.js";
135
135
  import {
136
136
  directoryHasGitMetadata,
137
137
  resolveProjectIdentityForSession,
@@ -144,10 +144,10 @@ import {
144
144
  resolveMemoriesByIdsForSearch2,
145
145
  unifiedSearch2,
146
146
  formatSearchResults2
147
- } from "./index-7v0z62ek.js";
147
+ } from "./index-s3s4px1q.js";
148
148
  import {
149
149
  getErrorMessage
150
- } from "./index-7yz95h83.js";
150
+ } from "./index-wd5xfz8m.js";
151
151
  import {
152
152
  resolveOpenCodeDbPath,
153
153
  assertOpenCodeStoreGeneration
@@ -156,7 +156,7 @@ import {
156
156
  hasRawMessageProvider2,
157
157
  setRawMessageProvider2,
158
158
  readSessionChunk2
159
- } from "./index-hpbdnbtf.js";
159
+ } from "./index-68tyan5e.js";
160
160
  import {
161
161
  resolveWorkspaceShareCategories,
162
162
  resolveWorkspaceIdentitySet,
@@ -189,7 +189,7 @@ import {
189
189
  } from "./index-3s39a1md.js";
190
190
  import {
191
191
  renderSearchArchive2
192
- } from "./index-fvfq9gva.js";
192
+ } from "./index-hp320128.js";
193
193
  import {
194
194
  computeNormalizedHash
195
195
  } from "./index-9x1f96r8.js";
@@ -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);
@@ -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";
@@ -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";
@@ -83,7 +83,7 @@ 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";
@@ -10,10 +10,10 @@ import {
10
10
  readSearchBackfillCursor2,
11
11
  writeSearchBackfillCursor2,
12
12
  embedItemsWindowBounded2
13
- } from "./index-wy6h2wn2.js";
13
+ } from "./index-8qdebv92.js";
14
14
  import {
15
15
  saveEmbeddingIfHashMatches
16
- } from "./index-yhzhdp3m.js";
16
+ } from "./index-hrwc50n3.js";
17
17
 
18
18
  // ../plugin/src/features/magic-context/memory/embedding-backfill.ts
19
19
  var SEARCH_BACKFILL_LIMIT = 50;
@@ -72,7 +72,7 @@ import {
72
72
  expandToolPart,
73
73
  visitRawSessionMessages2,
74
74
  readRawSessionMessageById2
75
- } from "./index-hpbdnbtf.js";
75
+ } from "./index-68tyan5e.js";
76
76
  import {
77
77
  gaDatabasePath2,
78
78
  V2StoreReader2
@@ -82,7 +82,7 @@ import {
82
82
  } from "./index-ghp32f9m.js";
83
83
  import {
84
84
  deleteChunkEmbedBackoffForSession2
85
- } from "./index-cxczethe.js";
85
+ } from "./index-464qhgjp.js";
86
86
  import {
87
87
  invalidateAutoEmbedSession,
88
88
  drainBackgroundBatches
@@ -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 };
@@ -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 };
@@ -9,7 +9,7 @@ import {
9
9
  } from "./index-pefn1gt5.js";
10
10
  import {
11
11
  cleanUserText2
12
- } from "./index-hpbdnbtf.js";
12
+ } from "./index-68tyan5e.js";
13
13
  import {
14
14
  recordMessageFtsRowid2,
15
15
  recordIndexedMessageTime2,
@@ -33,9 +33,10 @@ import {
33
33
  import {
34
34
  buildCanonicalChunkTextFromFts2,
35
35
  loadCompartmentChunkEmbeddingsForSearch2,
36
+ trackCompartmentChunkSearchPool2,
36
37
  peekCompartmentChunkSearchPool2,
37
38
  warmCompartmentChunkSearchPool2
38
- } from "./index-cxczethe.js";
39
+ } from "./index-464qhgjp.js";
39
40
  import {
40
41
  LocalEmbeddingProvider
41
42
  } from "./index-rqdjb6j3.js";
@@ -56,7 +57,7 @@ import {
56
57
  getProjectEmbeddingSnapshot2,
57
58
  embedTextForProject2,
58
59
  embedItemsForProject2
59
- } from "./index-wy6h2wn2.js";
60
+ } from "./index-8qdebv92.js";
60
61
  import {
61
62
  recordEmbeddingMeasurement
62
63
  } from "./index-hgd00nas.js";
@@ -66,10 +67,10 @@ import {
66
67
  import {
67
68
  saveEmbeddingIfHashMatches,
68
69
  getProjectEmbeddings2
69
- } from "./index-yhzhdp3m.js";
70
+ } from "./index-hrwc50n3.js";
70
71
  import {
71
72
  ensureMemoryEmbeddings2
72
- } from "./index-sqp84q6s.js";
73
+ } from "./index-affz2pyv.js";
73
74
  import {
74
75
  getMemorySelectColumns2,
75
76
  isMemoryRow2,
@@ -83,7 +84,7 @@ import {
83
84
  getMemoryById2,
84
85
  updateMemorySeenCount2,
85
86
  updateMemoryRetrievalCount2
86
- } from "./index-29nw7n1r.js";
87
+ } from "./index-70sw39ck.js";
87
88
  import {
88
89
  cleanSearchText,
89
90
  hintKeywordRelevance,
@@ -97,7 +98,7 @@ import {
97
98
  clearIndexedMessages,
98
99
  indexSingleMessage,
99
100
  indexMessagesAfterOrdinal
100
- } from "./index-0t9xfj3x.js";
101
+ } from "./index-qpdh2aff.js";
101
102
  import {
102
103
  MESSAGE_FTS_SESSION_FILTER_SQL,
103
104
  withMessageFtsSessionFilter
@@ -877,6 +878,7 @@ async function readGitFileChangeTimesSince(cwd, sinceMs, knownGitRoot) {
877
878
  }
878
879
  return times;
879
880
  }
881
+ var TRACKED_FILES_ARGS = ["ls-files", "--recurse-submodules", "-z", "--full-name"];
880
882
  async function gitTrackedPath(gitRoot, repoRelativePath) {
881
883
  const stdout = await runGit(gitRoot, [
882
884
  "ls-files",
@@ -886,7 +888,7 @@ async function gitTrackedPath(gitRoot, repoRelativePath) {
886
888
  "--",
887
889
  repoRelativePath
888
890
  ]);
889
- const fallbackStdout = stdout === null ? await runGit(gitRoot, ["ls-files", "-z", "--full-name"]) : null;
891
+ const fallbackStdout = stdout === null ? await runGit(gitRoot, TRACKED_FILES_ARGS) : null;
890
892
  if (stdout === null && fallbackStdout === null)
891
893
  return null;
892
894
  const matches = (stdout ?? fallbackStdout ?? "").split("\x00").filter(Boolean);
@@ -953,7 +955,7 @@ async function normalizeVerificationFiles(args) {
953
955
  if (!trackedPaths) {
954
956
  let trackedOutput = null;
955
957
  try {
956
- trackedOutput = await runGit(gitRoot, ["ls-files", "-z", "--full-name"]);
958
+ trackedOutput = await runGit(gitRoot, TRACKED_FILES_ARGS);
957
959
  } catch {}
958
960
  trackedPaths = new Set(trackedOutput?.split("\x00").filter(Boolean) ?? []);
959
961
  }
@@ -3307,8 +3309,12 @@ async function searchCompartmentChunks(args) {
3307
3309
  if (args.diagnostics)
3308
3310
  args.diagnostics.pool = "no-vector";
3309
3311
  args.reportDiagnostics?.();
3310
- if (args.warmOnly)
3311
- warmCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId);
3312
+ if (args.warmOnly) {
3313
+ if (args.deferWarmup)
3314
+ trackCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId);
3315
+ else
3316
+ warmCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId);
3317
+ }
3312
3318
  return [];
3313
3319
  }
3314
3320
  const cutoff = args.maxOrdinal != null && args.maxOrdinal >= 0 ? args.maxOrdinal : null;
@@ -3323,7 +3329,8 @@ async function searchCompartmentChunks(args) {
3323
3329
  args.diagnostics.poolRows = 0;
3324
3330
  }
3325
3331
  args.reportDiagnostics?.();
3326
- warmCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId);
3332
+ if (!args.deferWarmup)
3333
+ warmCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId);
3327
3334
  return [];
3328
3335
  }
3329
3336
  if (args.timings)
@@ -3733,6 +3740,7 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
3733
3740
  modelId: chunkModelId && chunkModelId !== "off" ? chunkModelId : null,
3734
3741
  dateRange,
3735
3742
  warmOnly: options.chunkPoolWarmOnly,
3743
+ deferWarmup: options.deferChunkPoolWarmup,
3736
3744
  signal: options.signal,
3737
3745
  timings,
3738
3746
  diagnostics: options.autoSearchDiagnostics,
@@ -1089,7 +1089,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1089
1089
  state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1090
1090
  if (signal.aborted || !readsOpenCodeStore)
1091
1091
  return;
1092
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-wek7gb7j.js"));
1092
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-tec7t4vy.js"));
1093
1093
  const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-8zwv9byv.js"));
1094
1094
  if (signal.aborted)
1095
1095
  return;
@@ -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-2jzjgetc.js"),
144
+ import("./search-archive-ze1567mj.js"),
145
145
  import("./expand-attachments-8sxeyj26.js")
146
146
  ]);
147
147
  const pool = new V2StoreReaderPool;
package/dist/index.js CHANGED
@@ -166,7 +166,7 @@ import {
166
166
  registerTodoStateLifecycle,
167
167
  syncCtxMemoryToolEnabled,
168
168
  registerMagicContextTools
169
- } from "./index-ty0tvxhm.js";
169
+ } from "./index-4c48169d.js";
170
170
  import"./index-4knyh1kt.js";
171
171
  import {
172
172
  piHarnessKindFromExecutable,
@@ -593,7 +593,7 @@ import {
593
593
  getSourceContents,
594
594
  recordSubagentInvocation,
595
595
  getLatestHistorianInvocationId
596
- } from "./index-bjr11ay6.js";
596
+ } from "./index-bkagkxm5.js";
597
597
  import {
598
598
  resolveOpenCodeDbPath,
599
599
  assertOpenCodeStoreGeneration,
@@ -659,7 +659,7 @@ import {
659
659
  getRawSessionTagKeysThrough2,
660
660
  getLegacyProtectedTailStartOrdinal2,
661
661
  readSessionChunk2
662
- } from "./index-hpbdnbtf.js";
662
+ } from "./index-68tyan5e.js";
663
663
  import"./index-ddfjg278.js";
664
664
  import {
665
665
  formatSynapseLaneDescriptor
@@ -674,7 +674,7 @@ import {
674
674
  replaceCompartmentChunkEmbeddings2,
675
675
  deleteChunkEmbedBackoffForSession2,
676
676
  chunkWindowSourceKey2
677
- } from "./index-cxczethe.js";
677
+ } from "./index-464qhgjp.js";
678
678
  import {
679
679
  recordSessionProjectIdentity,
680
680
  GIT_SWEEP_LEASE_RENEWAL_MS,
@@ -699,7 +699,7 @@ import {
699
699
  clearCompressionDepthRange,
700
700
  cleanSearchText,
701
701
  matchedSearchSnippet
702
- } from "./index-0t9xfj3x.js";
702
+ } from "./index-qpdh2aff.js";
703
703
  import {
704
704
  getErrorMessage,
705
705
  describeError,
@@ -716,7 +716,7 @@ import {
716
716
  openCurrentDatabase,
717
717
  openDatabaseAsync,
718
718
  closeDatabase
719
- } from "./index-7yz95h83.js";
719
+ } from "./index-wd5xfz8m.js";
720
720
  import {
721
721
  rememberV1HiddenRun
722
722
  } from "./index-6x556c2q.js";
@@ -782,13 +782,13 @@ import {
782
782
  archiveMemory2,
783
783
  getMemoryCount2,
784
784
  getMemoryCountsByStatus2
785
- } from "./index-29nw7n1r.js";
785
+ } from "./index-70sw39ck.js";
786
786
  import {
787
787
  invalidateMemory2
788
- } from "./index-yhzhdp3m.js";
788
+ } from "./index-hrwc50n3.js";
789
789
  import {
790
790
  pushNotification2
791
- } from "./index-7thk2cwt.js";
791
+ } from "./index-jhsypxe9.js";
792
792
  import {
793
793
  describeShadowBackfillWriteRefusal2,
794
794
  contentSha2562,
@@ -806,7 +806,7 @@ import {
806
806
  embedSessionCompartmentChunks2,
807
807
  getEmbeddingCoverageStatus2,
808
808
  getAutoEmbeddingSessionCoverage2
809
- } from "./index-wy6h2wn2.js";
809
+ } from "./index-8qdebv92.js";
810
810
  import {
811
811
  USER_FACING_FAILURES,
812
812
  renderUserFacingFailure,
@@ -841,8 +841,8 @@ import {
841
841
  scheduleClearAndReindex,
842
842
  clearSessionTracking,
843
843
  createAutoSearchDiagnostics
844
- } from "./index-7v0z62ek.js";
845
- import"./index-sqp84q6s.js";
844
+ } from "./index-s3s4px1q.js";
845
+ import"./index-affz2pyv.js";
846
846
  import"./index-3s39a1md.js";
847
847
  import {
848
848
  DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
@@ -875,8 +875,8 @@ import {
875
875
  } from "./index-pdrberjp.js";
876
876
  import"./index-71rg8j43.js";
877
877
  import"./index-8d2z6503.js";
878
- import"./index-fd57gfnn.js";
879
- import"./index-fvfq9gva.js";
878
+ import"./index-xemjzc1v.js";
879
+ import"./index-hp320128.js";
880
880
  import {
881
881
  __toESM
882
882
  } from "./index-22jkk6wg.js";
@@ -3623,7 +3623,7 @@ function startHostStallProfilerSwitch() {
3623
3623
  // package.json
3624
3624
  var package_default = {
3625
3625
  name: "@cortexkit/pi-magic-context",
3626
- version: "0.49.85",
3626
+ version: "0.49.87",
3627
3627
  type: "module",
3628
3628
  description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
3629
3629
  main: "dist/index.js",
@@ -5167,6 +5167,10 @@ function hasLengthCappedOutput(value) {
5167
5167
  }
5168
5168
  return Object.values(value).some((item) => hasLengthCappedOutput(item));
5169
5169
  }
5170
+ function isLatestAssistantLengthCapped(messages) {
5171
+ const latest = getLatestAssistantMessage(messages);
5172
+ return hasLengthCappedOutput(latest?.info?.finish ? { finish: latest.info.finish } : null) || Array.isArray(latest?.parts) && latest.parts.some((part) => isRecord(part) && part.type === "step-finish" && hasLengthCappedOutput(part));
5173
+ }
5170
5174
  function describeAssistantSettlement(output) {
5171
5175
  if (isRecord(output) && isRecord(output.tokenLog)) {
5172
5176
  return `finish=${String(output.tokenLog.finish_reason ?? "unknown")}, reasoning=${typeof output.reasoning === "string" && output.reasoning.length > 0}`;
@@ -6177,6 +6181,24 @@ function messageId(message) {
6177
6181
  const id = infoOf(message).id;
6178
6182
  return typeof id === "string" ? id : null;
6179
6183
  }
6184
+ function inFlightAtAbort(messages, initialBaseline) {
6185
+ const reply = messages.slice().reverse().find((message) => {
6186
+ const id = messageId(message);
6187
+ return id !== null && !initialBaseline.has(id) && infoOf(message).role === "assistant";
6188
+ });
6189
+ const parts = reply?.parts;
6190
+ const ids = new Set;
6191
+ if (Array.isArray(parts)) {
6192
+ for (const part of parts) {
6193
+ if (part?.type !== "tool" || typeof part.callID !== "string")
6194
+ continue;
6195
+ const state = part.state;
6196
+ if (state?.status === "pending" || state?.status === "running" || state?.status === "error" && state.error === "Tool execution aborted" && state.metadata?.interrupted === true)
6197
+ ids.add(part.callID);
6198
+ }
6199
+ }
6200
+ return ids;
6201
+ }
6180
6202
  function recordedAssistantError(message) {
6181
6203
  const info = infoOf(message);
6182
6204
  if (info.error != null)
@@ -6401,7 +6423,7 @@ async function promptAsyncAndWaitForIdle(client, request, options = {}) {
6401
6423
  finalizing = true;
6402
6424
  sessionLog2(sessionId, "dreamer token budget: finalize fired", budget.snapshot());
6403
6425
  budgetAbortedSessions.add(sessionId);
6404
- registerBudgetFinalizeChild(sessionId, budget);
6426
+ const countRefusals = registerBudgetFinalizeChild(sessionId, budget);
6405
6427
  if (!session.abort)
6406
6428
  throw new DreamTokenBudgetExceeded(sessionId, budget.snapshot().spent);
6407
6429
  await session.abort({ path: { id: sessionId } });
@@ -6415,7 +6437,14 @@ async function promptAsyncAndWaitForIdle(client, request, options = {}) {
6415
6437
  if (await readStatus(session, sessionId, dir, signal) !== "idle") {
6416
6438
  throw new DreamTokenBudgetExceeded(sessionId, budget.snapshot().spent);
6417
6439
  }
6418
- completionBaseline = new Set((await readMessages(session, sessionId, dir, signal)).map(messageId).filter((value) => value !== null));
6440
+ const cancelled = await readMessages(session, sessionId, dir, signal);
6441
+ completionBaseline = new Set((cancelled.length ? cancelled : messages).map(messageId).filter((value) => value !== null));
6442
+ const exemptCallIds = inFlightAtAbort(cancelled, initialBaseline);
6443
+ countRefusals(exemptCallIds);
6444
+ sessionLog2(sessionId, "dreamer token budget: counting tool refusals", {
6445
+ snapshot: cancelled.length ? "read" : "unreadable",
6446
+ exemptCallIds: [...exemptCallIds]
6447
+ });
6419
6448
  const finalizeResponse = await session.promptAsync?.({
6420
6449
  ...request,
6421
6450
  body: {
@@ -19193,7 +19222,11 @@ async function runRetrospectiveTask(config, ctx, helpers) {
19193
19222
  });
19194
19223
  },
19195
19224
  validateOutput: (outputMessages) => {
19196
- const text = hiddenHandle ? outputMessages.text : extractLatestAssistantText(outputMessages);
19225
+ const completion = hiddenHandle ? outputMessages : null;
19226
+ if (completion ? completion.lengthCapped : isLatestAssistantLengthCapped(outputMessages)) {
19227
+ throw new Error("Retrospective child returned length-capped output");
19228
+ }
19229
+ const text = completion ? completion.text : extractLatestAssistantText(outputMessages);
19197
19230
  if (!text)
19198
19231
  throw new Error("Retrospective child returned no output.");
19199
19232
  return text;
@@ -21778,6 +21811,9 @@ class PiSubagentRunner {
21778
21811
  let lastEventTimestamp = 0;
21779
21812
  const accumulatedMessages = [];
21780
21813
  accountingMessages = accumulatedMessages;
21814
+ let finalizeDelivered = false;
21815
+ let exemptRepliesRemaining = 2;
21816
+ let preSteerToolCalls;
21781
21817
  const captureFinalAssistant = (messages) => {
21782
21818
  const result = extractFinalAssistant(messages);
21783
21819
  finalAssistantText = result.text;
@@ -21809,9 +21845,9 @@ class PiSubagentRunner {
21809
21845
  if (e.type === "agent_end" && Array.isArray(e.messages))
21810
21846
  mappingMessages = e.messages;
21811
21847
  }
21812
- if (rpcBudget && e.type === "response" && event.success === false) {
21848
+ if (rpcBudget && e.type === "response") {
21813
21849
  const reply = event;
21814
- if (reply.command === "prompt" || reply.command === "steer" && !sawAgentEnd) {
21850
+ if (reply.success === false && (reply.command === "prompt" || reply.command === "steer" && !sawAgentEnd)) {
21815
21851
  terminateChild(child);
21816
21852
  settle({
21817
21853
  ok: false,
@@ -21821,6 +21857,9 @@ class PiSubagentRunner {
21821
21857
  });
21822
21858
  return;
21823
21859
  }
21860
+ if (reply.success === true && reply.command === "steer" && reply.id === "dreamer-finalize" && reply.data?.disposition === "handled") {
21861
+ sessionLog2(options.accountingSessionId ?? "subagent", "Pi dreamer finalize: steer was handled by an input extension");
21862
+ }
21824
21863
  }
21825
21864
  telemetry.observe(event);
21826
21865
  if (budget && e.type === "message_end") {
@@ -21843,6 +21882,9 @@ class PiSubagentRunner {
21843
21882
  });
21844
21883
  return;
21845
21884
  }
21885
+ if (decision === "finalize" || preSteerToolCalls) {
21886
+ preSteerToolCalls = finalizeDelivered || exemptRepliesRemaining-- === 0 ? undefined : extractToolInvocations([message]);
21887
+ }
21846
21888
  if (decision === "finalize" && rpcBudget) {
21847
21889
  try {
21848
21890
  if (!budgetGuardFile)
@@ -21865,21 +21907,30 @@ class PiSubagentRunner {
21865
21907
  })}
21866
21908
  `);
21867
21909
  }
21910
+ } else if (preSteerToolCalls && message?.role === "user" && Array.isArray(message.content) && message.content.some((part) => {
21911
+ const text = part;
21912
+ return text?.type === "text" && text.text === TOKEN_BUDGET_FINALIZE_MESSAGE;
21913
+ })) {
21914
+ finalizeDelivered = true;
21868
21915
  }
21869
21916
  }
21870
21917
  const resultParts = event.result?.content;
21871
21918
  if (budget?.snapshot().finalizeFired && e.type === "tool_execution_end" && resultParts?.some((part) => part.text === TOKEN_BUDGET_TOOL_REFUSAL)) {
21872
- const refusal = budget.refuseTool();
21873
- if (refusal?.hardStopped) {
21874
- terminateChild(child);
21875
- settle({
21876
- ok: false,
21877
- reason: "token_budget",
21878
- error: "MC-D11: Pi dreamer made two calls after finalize",
21879
- durationMs: Date.now() - startTime,
21880
- meta: { tokenBudget: budget.snapshot() }
21881
- });
21882
- return;
21919
+ if (e.toolCallId && preSteerToolCalls?.has(e.toolCallId)) {
21920
+ sessionLog2(options.accountingSessionId ?? "subagent", "Pi dreamer finalize: refusal spared for a call issued before steer delivery was confirmed", { toolCallId: e.toolCallId });
21921
+ } else {
21922
+ const refusal = budget.refuseTool();
21923
+ if (refusal?.hardStopped) {
21924
+ terminateChild(child);
21925
+ settle({
21926
+ ok: false,
21927
+ reason: "token_budget",
21928
+ error: "MC-D11: Pi dreamer made two calls after finalize",
21929
+ durationMs: Date.now() - startTime,
21930
+ meta: { tokenBudget: budget.snapshot() }
21931
+ });
21932
+ return;
21933
+ }
21883
21934
  }
21884
21935
  }
21885
21936
  if (cap !== undefined && telemetry.steps > cap) {
@@ -27582,9 +27633,11 @@ function outgoingContextRefusal(estimate, limit, protectedToolTokens = 0) {
27582
27633
  }
27583
27634
  class EmergencyFailClosedError extends Error {
27584
27635
  code;
27636
+ noticeHandled;
27585
27637
  constructor(message, options) {
27586
27638
  super(message, options);
27587
27639
  this.code = options?.code ?? "EMERGENCY_FAIL_CLOSED";
27640
+ this.noticeHandled = options?.noticeHandled;
27588
27641
  this.name = "EmergencyFailClosedError";
27589
27642
  }
27590
27643
  }
@@ -30240,6 +30293,43 @@ var searchWorkers = new WeakMap;
30240
30293
  var liveSearchWorkers = new Set;
30241
30294
  var MAX_IDLE_SEARCH_WORKERS = 4;
30242
30295
  var SEARCH_WORKER_IDLE_MS = 5 * 60000;
30296
+ var MAX_SEARCH_WORKER_CACHE_TTL_MS = 60 * 60000;
30297
+ function scheduleSearchWorkerExpiry(db, slot) {
30298
+ const arm = (delay) => {
30299
+ slot.idleTimer = setTimeout(check, delay);
30300
+ slot.idleTimer.unref?.();
30301
+ };
30302
+ const check = () => {
30303
+ const now = Date.now();
30304
+ let expires = now;
30305
+ try {
30306
+ const read = db.prepare("SELECT cache_ttl, last_response_time FROM session_meta WHERE session_id = ?");
30307
+ for (const session of slot.searchedSessions) {
30308
+ const row = read.get(session);
30309
+ if (!row) {
30310
+ slot.searchedSessions.delete(session);
30311
+ continue;
30312
+ }
30313
+ if (!row.cache_ttl || !row.last_response_time || row.last_response_time > now)
30314
+ continue;
30315
+ let ttl;
30316
+ try {
30317
+ ttl = Math.min(parseCacheTtl(row.cache_ttl), MAX_SEARCH_WORKER_CACHE_TTL_MS);
30318
+ } catch {
30319
+ continue;
30320
+ }
30321
+ if (ttl <= SEARCH_WORKER_IDLE_MS)
30322
+ continue;
30323
+ expires = Math.max(expires, row.last_response_time + ttl);
30324
+ }
30325
+ } catch {}
30326
+ if (expires > now)
30327
+ arm(expires - now);
30328
+ else
30329
+ slot.dispose();
30330
+ };
30331
+ arm(SEARCH_WORKER_IDLE_MS);
30332
+ }
30243
30333
  var DETACHED_SEARCH_LIMIT_MS = 30000;
30244
30334
  var AUTO_SEARCH_WORKER_CLOSE_DEADLINE_MS = 2000;
30245
30335
  var workersCreated = 0;
@@ -30274,6 +30364,7 @@ async function acquireSearchWorker(db, key, entry, input, signal) {
30274
30364
  const shutdown = createWorkerShutdown(worker, "auto-search", AUTO_SEARCH_WORKER_CLOSE_DEADLINE_MS);
30275
30365
  slot = {
30276
30366
  worker,
30367
+ searchedSessions: new Set,
30277
30368
  dispose() {
30278
30369
  this.disposed = true;
30279
30370
  clearTimeout(this.idleTimer);
@@ -30442,8 +30533,8 @@ async function executeAutoSearchWorker(db, sessionId, projectPath, query, option
30442
30533
  if (dispose || !detachable)
30443
30534
  slot.dispose();
30444
30535
  else if (!slot.disposed) {
30445
- slot.idleTimer = setTimeout(() => slot.dispose(), SEARCH_WORKER_IDLE_MS);
30446
- slot.idleTimer.unref?.();
30536
+ slot.searchedSessions.add(sessionId);
30537
+ scheduleSearchWorkerExpiry(db, slot);
30447
30538
  }
30448
30539
  const free = slot.release;
30449
30540
  slot.busy = undefined;
@@ -34457,13 +34548,19 @@ function extractToastTitle(text) {
34457
34548
  }
34458
34549
  async function sendStatusNotification(_client, sessionId, text, params) {
34459
34550
  try {
34460
- const { pushNotification } = await importPluginModule(() => import("./rpc-notifications-889zvhn2.js"));
34461
- pushNotification("toast", {
34462
- title: extractToastTitle(text),
34551
+ const { pushLiveNotification, pushNotification } = await importPluginModule(() => import("./rpc-notifications-qc5ha504.js"));
34552
+ const toast = {
34553
+ title: params.toastTitle ?? extractToastTitle(text),
34463
34554
  message: text,
34464
- variant: inferToastVariant(text),
34555
+ variant: params.toastVariant ?? inferToastVariant(text),
34465
34556
  duration: params.toastDurationMs ?? 5000
34466
- }, sessionId);
34557
+ };
34558
+ if (params.liveOnly) {
34559
+ if (!pushLiveNotification("toast", toast, sessionId))
34560
+ return "skipped";
34561
+ } else {
34562
+ pushNotification("toast", toast, sessionId);
34563
+ }
34467
34564
  notifyDelivered(sessionId, params);
34468
34565
  return "sent";
34469
34566
  } catch (error) {
@@ -15,7 +15,7 @@ import"./index-wfqysrwq.js";
15
15
  import"./index-x2n261wp.js";
16
16
  import"./index-xjhq27z9.js";
17
17
  import"./index-n0zjvs3h.js";
18
- import"./index-hpbdnbtf.js";
18
+ import"./index-68tyan5e.js";
19
19
  import"./index-6x556c2q.js";
20
20
  import {
21
21
  MESSAGE_INDEX_MAX_FTS_BYTES,
@@ -24,7 +24,7 @@ import {
24
24
  markMessageIndexDirty,
25
25
  getIndexableContent,
26
26
  indexSingleMessage
27
- } from "./index-0t9xfj3x.js";
27
+ } from "./index-qpdh2aff.js";
28
28
  import"./index-ghp32f9m.js";
29
29
  import"./index-1ts77n1b.js";
30
30
 
@@ -19,7 +19,7 @@ import"./index-fapenpch.js";
19
19
  import {
20
20
  setSqlitePragmaConfig,
21
21
  initializeDatabase
22
- } from "./index-7yz95h83.js";
22
+ } from "./index-wd5xfz8m.js";
23
23
  import"./index-3bb24eb6.js";
24
24
  import"./index-8sqebjzk.js";
25
25
  import"./index-wfqysrwq.js";
@@ -37,12 +37,12 @@ import {
37
37
  sweepAllRegisteredProjects2,
38
38
  _setTestProviderFactoryForProject2,
39
39
  _resetProjectEmbeddingRegistryForTests2
40
- } from "./index-wy6h2wn2.js";
40
+ } from "./index-8qdebv92.js";
41
41
  import"./index-9p40dgkm.js";
42
42
  import"./index-hgd00nas.js";
43
- import"./index-yhzhdp3m.js";
43
+ import"./index-hrwc50n3.js";
44
44
  import"./index-ex9te7tc.js";
45
- import"./index-cxczethe.js";
45
+ import"./index-464qhgjp.js";
46
46
  import"./index-rqdjb6j3.js";
47
47
  import"./index-5rcjs14a.js";
48
48
  import"./index-vcegxfwg.js";
@@ -19,7 +19,7 @@ serveWorkerJobs(async (input, port) => {
19
19
  await main();
20
20
  async function main() {
21
21
  if (input.v2ArchiveReader) {
22
- const { serveV2ArchiveReads } = await import("./v2-archive-reader-qc4c9wrp.js");
22
+ const { serveV2ArchiveReads } = await import("./v2-archive-reader-vq596vh8.js");
23
23
  await serveV2ArchiveReads(port, openConnections);
24
24
  return;
25
25
  }
@@ -51,7 +51,7 @@ serveWorkerJobs(async (input, port) => {
51
51
  await runMessageFtsRowidMapBackfill(db);
52
52
  reply = { kind: "fts-rowid-backfill" };
53
53
  } else if (input.searchArchive) {
54
- const { renderSearchArchive } = await import("./search-archive-7p43e77j.js");
54
+ const { renderSearchArchive } = await import("./search-archive-ze1567mj.js");
55
55
  const { readRawSessionMessageIdOrdinalsForRangeFromDb } = await import("./read-session-raw-0tytrjye.js");
56
56
  const archive = input.searchArchive;
57
57
  let raw;
@@ -81,7 +81,7 @@ serveWorkerJobs(async (input, port) => {
81
81
  const { setHarness } = await import("./harness-9872e0ym.js");
82
82
  setHarness(input.harness ?? "opencode");
83
83
  const [{ indexMessageInShortChunks }, { configureContextDatabasePragmas }] = await Promise.all([
84
- import("./message-index-bounded-sra4jpac.js"),
84
+ import("./message-index-bounded-vxf4ez55.js"),
85
85
  import("./sqlite-context-pragmas-gcgch6qz.js")
86
86
  ]);
87
87
  configureContextDatabasePragmas(db);
@@ -38,7 +38,7 @@ import {
38
38
  readSessionChunk2,
39
39
  getRawSessionMessageIdsThrough2,
40
40
  readRawSessionSeedTail2
41
- } from "./index-hpbdnbtf.js";
41
+ } from "./index-68tyan5e.js";
42
42
  import"./index-nh4srq1p.js";
43
43
  import"./index-6x556c2q.js";
44
44
  import"./index-vcegxfwg.js";
@@ -3,18 +3,18 @@ import {
3
3
  renderVerboseRange2,
4
4
  renderVerboseRangeForTool2,
5
5
  renderItemByTag2
6
- } from "./index-bjr11ay6.js";
6
+ } from "./index-bkagkxm5.js";
7
7
  import"./index-gbc29ysq.js";
8
- import"./index-0t9xfj3x.js";
8
+ import"./index-qpdh2aff.js";
9
9
  import"./index-hgd00nas.js";
10
10
  import"./index-ddfjg278.js";
11
- import"./index-cxczethe.js";
12
- import"./index-hpbdnbtf.js";
11
+ import"./index-464qhgjp.js";
12
+ import"./index-68tyan5e.js";
13
13
  import"./index-nh4srq1p.js";
14
14
  import"./index-6x556c2q.js";
15
15
  import"./index-5rcjs14a.js";
16
16
  import"./index-vcegxfwg.js";
17
- import"./index-7yz95h83.js";
17
+ import"./index-wd5xfz8m.js";
18
18
  import"./index-fapenpch.js";
19
19
  import"./index-53fgdt6n.js";
20
20
  import"./index-135e8hvg.js";
@@ -6,7 +6,7 @@ import {
6
6
  __resetNotificationStateForTests2,
7
7
  drainNotifications2,
8
8
  isTuiConnected2
9
- } from "./index-7thk2cwt.js";
9
+ } from "./index-jhsypxe9.js";
10
10
  export {
11
11
  __resetNotificationStateForTests2 as __resetNotificationStateForTests,
12
12
  acknowledgeNotifications2 as acknowledgeNotifications,
@@ -5,19 +5,19 @@ import {
5
5
  resolveMemoriesByIdsForSearch2,
6
6
  unifiedSearch2,
7
7
  formatSearchResults2
8
- } from "./index-7v0z62ek.js";
8
+ } from "./index-s3s4px1q.js";
9
9
  import"./index-gbc29ysq.js";
10
- import"./index-0t9xfj3x.js";
10
+ import"./index-qpdh2aff.js";
11
11
  import"./index-8d2z6503.js";
12
- import"./index-sqp84q6s.js";
13
- import"./index-29nw7n1r.js";
14
- import"./index-wy6h2wn2.js";
12
+ import"./index-affz2pyv.js";
13
+ import"./index-70sw39ck.js";
14
+ import"./index-8qdebv92.js";
15
15
  import"./index-9p40dgkm.js";
16
16
  import"./index-hgd00nas.js";
17
- import"./index-yhzhdp3m.js";
17
+ import"./index-hrwc50n3.js";
18
18
  import"./index-ex9te7tc.js";
19
- import"./index-cxczethe.js";
20
- import"./index-hpbdnbtf.js";
19
+ import"./index-464qhgjp.js";
20
+ import"./index-68tyan5e.js";
21
21
  import"./index-nh4srq1p.js";
22
22
  import"./index-6x556c2q.js";
23
23
  import"./index-rqdjb6j3.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  renderSearchArchive2
3
- } from "./index-fvfq9gva.js";
4
- import"./index-fd57gfnn.js";
3
+ } from "./index-hp320128.js";
4
+ import"./index-xemjzc1v.js";
5
5
  import"./index-8d2z6503.js";
6
- import"./index-hpbdnbtf.js";
6
+ import"./index-68tyan5e.js";
7
7
  import"./index-nh4srq1p.js";
8
8
  import"./index-6x556c2q.js";
9
9
  import"./index-vcegxfwg.js";
@@ -31,8 +31,8 @@ import {
31
31
  deleteMemory2,
32
32
  getMemoryCount2,
33
33
  getMemoryCountsByStatus2
34
- } from "./index-29nw7n1r.js";
35
- import"./index-yhzhdp3m.js";
34
+ } from "./index-70sw39ck.js";
35
+ import"./index-hrwc50n3.js";
36
36
  import"./index-135e8hvg.js";
37
37
  import"./index-2qtx0q6h.js";
38
38
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TOKEN_BUDGET_TOOL_REFUSAL
3
- } from "./index-hpbdnbtf.js";
3
+ } from "./index-68tyan5e.js";
4
4
  import {
5
5
  setHarness2
6
6
  } from "./index-0h2mkab2.js";
@@ -18,7 +18,7 @@ import"./index-2qtx0q6h.js";
18
18
  import"./index-fapenpch.js";
19
19
  import {
20
20
  openDatabase
21
- } from "./index-7yz95h83.js";
21
+ } from "./index-wd5xfz8m.js";
22
22
  import"./index-3bb24eb6.js";
23
23
  import"./index-8sqebjzk.js";
24
24
  import"./index-wfqysrwq.js";
@@ -37,28 +37,28 @@ import {
37
37
  resolvePiHarnessKind,
38
38
  reportSubagentStartupError,
39
39
  registerMagicContextTools
40
- } from "./index-ty0tvxhm.js";
40
+ } from "./index-4c48169d.js";
41
41
  import"./index-vcegxfwg.js";
42
42
  import"./index-5rcjs14a.js";
43
- import"./index-cxczethe.js";
43
+ import"./index-464qhgjp.js";
44
44
  import"./index-rqdjb6j3.js";
45
- import"./index-wy6h2wn2.js";
45
+ import"./index-8qdebv92.js";
46
46
  import"./index-hgd00nas.js";
47
47
  import"./index-9p40dgkm.js";
48
48
  import"./index-ex9te7tc.js";
49
- import"./index-yhzhdp3m.js";
50
- import"./index-7v0z62ek.js";
51
- import"./index-bjr11ay6.js";
52
- import"./index-0t9xfj3x.js";
49
+ import"./index-hrwc50n3.js";
50
+ import"./index-s3s4px1q.js";
51
+ import"./index-bkagkxm5.js";
52
+ import"./index-qpdh2aff.js";
53
53
  import"./index-nh4srq1p.js";
54
54
  import"./index-6x556c2q.js";
55
55
  import"./index-ddfjg278.js";
56
56
  import"./index-gbc29ysq.js";
57
57
  import"./index-8d2z6503.js";
58
- import"./index-fd57gfnn.js";
59
- import"./index-fvfq9gva.js";
60
- import"./index-sqp84q6s.js";
61
- import"./index-29nw7n1r.js";
58
+ import"./index-xemjzc1v.js";
59
+ import"./index-hp320128.js";
60
+ import"./index-affz2pyv.js";
61
+ import"./index-70sw39ck.js";
62
62
  import"./index-3s39a1md.js";
63
63
  import"./index-1ts77n1b.js";
64
64
 
@@ -10,7 +10,7 @@ import"./index-fapenpch.js";
10
10
  import {
11
11
  LATEST_SUPPORTED_VERSION,
12
12
  getPersistedSchemaVersion
13
- } from "./index-7yz95h83.js";
13
+ } from "./index-wd5xfz8m.js";
14
14
  import"./index-3bb24eb6.js";
15
15
  import"./index-8sqebjzk.js";
16
16
  import"./index-wfqysrwq.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  readV2ArchiveOffThread2,
3
3
  serveV2ArchiveReads2
4
- } from "./index-fd57gfnn.js";
4
+ } from "./index-xemjzc1v.js";
5
5
  import"./index-8sqebjzk.js";
6
6
  import"./index-2qtx0q6h.js";
7
7
  import"./index-x2n261wp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-magic-context",
3
- "version": "0.49.85",
3
+ "version": "0.49.87",
4
4
  "type": "module",
5
5
  "description": "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
6
6
  "main": "dist/index.js",