@cortexkit/pi-magic-context 0.49.20 → 0.49.22

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 (48) hide show
  1. package/dist/auto-search-worker.js +6 -6
  2. package/dist/chunk-embedding-write-worker.js +9 -9
  3. package/dist/{compaction-marker-candidates-fnm47jat.js → compaction-marker-candidates-p1kqkqhq.js} +2 -2
  4. package/dist/compaction-marker-candidates-worker.js +2 -2
  5. package/dist/{compartment-chunk-embedding-81qesfjs.js → compartment-chunk-embedding-y01m95c2.js} +5 -5
  6. package/dist/{embedding-backfill-56e871c6.js → embedding-backfill-2vh6m3bg.js} +11 -11
  7. package/dist/embedding-worker-process.js +1 -1
  8. package/dist/embedding-worker.js +4 -4
  9. package/dist/{index-dzem6gn9.js → index-29nw7n1r.js} +1 -1
  10. package/dist/{index-jt0g3hn0.js → index-2bx7ge3x.js} +60 -18
  11. package/dist/{index-hws5f0z9.js → index-2qtx0q6h.js} +213 -4
  12. package/dist/{index-5vgt1zeh.js → index-3c3ztwgc.js} +2 -2
  13. package/dist/{index-rgfb753z.js → index-579m1751.js} +2 -2
  14. package/dist/{index-kqb3d8bs.js → index-5j6vwg4z.js} +148 -11
  15. package/dist/{index-6kb2xpw7.js → index-6wdwv3a6.js} +1 -1
  16. package/dist/{index-rfyvax95.js → index-at6py2k3.js} +1 -1
  17. package/dist/{index-bxmf4dhr.js → index-ccanzg8p.js} +2367 -1243
  18. package/dist/{index-mtvvhcw4.js → index-dbgg6hsf.js} +24 -10
  19. package/dist/{index-af9t637y.js → index-ftvm2acc.js} +121 -38
  20. package/dist/{index-zhwwp8zz.js → index-gqjxy2p7.js} +14 -4
  21. package/dist/{index-jxjr7kz9.js → index-gwxaz0z5.js} +2 -4
  22. package/dist/{index-p63nwn5v.js → index-hxp6q5f8.js} +1 -1
  23. package/dist/{index-qerzchrs.js → index-j3pz3a1b.js} +1 -1
  24. package/dist/{index-bttctq07.js → index-n8e5e9fp.js} +6 -3
  25. package/dist/{index-b8am7tns.js → index-pe5gz5c4.js} +4 -4
  26. package/dist/{index-tb3d9trm.js → index-st4gwt64.js} +1 -1
  27. package/dist/{index-5n5zxs8e.js → index-vx6f7wff.js} +2 -2
  28. package/dist/{index-v2epyzbm.js → index-w1twp2kp.js} +9 -7
  29. package/dist/{index-vdy273xw.js → index-wgmhk91m.js} +10 -4
  30. package/dist/{index-e19qtjj0.js → index-wqpjhx1p.js} +35 -4
  31. package/dist/index.js +239 -209
  32. package/dist/{message-fts-rowid-map-bpexnsdj.js → message-fts-rowid-map-59y476bk.js} +3 -3
  33. package/dist/{message-index-mvag9crh.js → message-index-3snxf11x.js} +9 -9
  34. package/dist/{message-index-bounded-d4r3weh0.js → message-index-bounded-4ngt600v.js} +9 -9
  35. package/dist/{message-time-backfill-kc10yrcj.js → message-time-backfill-e3r8ddh1.js} +1 -1
  36. package/dist/migration-worker.js +6 -6
  37. package/dist/{project-embedding-registry-cfrg952x.js → project-embedding-registry-hfyzs654.js} +10 -10
  38. package/dist/raw-ordinal-warmup-worker.js +8 -8
  39. package/dist/{read-session-chunk-7g4zvpd8.js → read-session-chunk-5dmc77q2.js} +5 -5
  40. package/dist/{read-session-raw-0fsjh10f.js → read-session-raw-yxv2fv34.js} +2 -2
  41. package/dist/{search-archive-qbhp7e89.js → search-archive-3daj5ttc.js} +6 -6
  42. package/dist/{search-hp4g3g9v.js → search-jhfh3tsj.js} +17 -17
  43. package/dist/{sqlite-d67n6dtr.js → sqlite-v89bj0yy.js} +7 -1
  44. package/dist/{storage-memory-9g882j7a.js → storage-memory-0ndn65fm.js} +2 -2
  45. package/dist/{storage-tags-m2qcp1g2.js → storage-tags-r48vxthe.js} +2 -2
  46. package/dist/subagent-entry.js +22 -21
  47. package/dist/tag-snapshot-worker-pi.js +8 -8
  48. package/package.json +5 -2
@@ -12,14 +12,16 @@ import {
12
12
  registerSqliteDiagnosticSink2,
13
13
  detectSqliteRuntime2,
14
14
  Database2,
15
+ createSqliteTurnDatabase2,
16
+ hasSqliteTurnDeadlineRouting2,
15
17
  withSqliteBackgroundWriter2,
16
18
  withoutSqliteTransformPass2,
17
19
  isTransientSqliteError2,
18
20
  withPrivilegedWriter2
19
- } from "./index-hws5f0z9.js";
21
+ } from "./index-2qtx0q6h.js";
20
22
  import {
21
23
  scheduleAfterBootQuiet
22
- } from "./index-p63nwn5v.js";
24
+ } from "./index-hxp6q5f8.js";
23
25
  import {
24
26
  getHarness2,
25
27
  harnessOwnsOpenCodeStore2
@@ -40,7 +42,7 @@ import {
40
42
  } from "./index-fapenpch.js";
41
43
  import {
42
44
  startMessageFtsRowidMapBackfill2
43
- } from "./index-rgfb753z.js";
45
+ } from "./index-579m1751.js";
44
46
  import {
45
47
  LKG_SLOT_CHUNKS_DDL,
46
48
  SESSION_REPLAY_DECISIONS_DDL,
@@ -50,7 +52,7 @@ import {
50
52
  hasPendingMigrations,
51
53
  getMainThreadMigrationBodyCount,
52
54
  runMigrations
53
- } from "./index-5vgt1zeh.js";
55
+ } from "./index-3c3ztwgc.js";
54
56
  import {
55
57
  closeQuietly,
56
58
  ensureColumn,
@@ -1305,8 +1307,8 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1305
1307
  state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
1306
1308
  if (signal.aborted || !readsOpenCodeStore)
1307
1309
  return;
1308
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-7g4zvpd8.js"));
1309
- const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-kc10yrcj.js"));
1310
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-5dmc77q2.js"));
1311
+ const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-e3r8ddh1.js"));
1310
1312
  if (signal.aborted)
1311
1313
  return;
1312
1314
  await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
@@ -2611,6 +2613,10 @@ function openDatabase(dbPathOrOptions) {
2611
2613
  return null;
2612
2614
  }
2613
2615
  if (existing) {
2616
+ if (options?.nativeTurnDeadlines && !hasSqliteTurnDeadlineRouting2(existing)) {
2617
+ log2("[magic-context] storage unavailable: native turn deadlines must be selected on the first open; restart the host");
2618
+ return null;
2619
+ }
2614
2620
  if (!enforceSchemaFence(existing, dbPath, latestSupportedVersion)) {
2615
2621
  return null;
2616
2622
  }
@@ -2635,7 +2641,7 @@ function openDatabase(dbPathOrOptions) {
2635
2641
  throw error;
2636
2642
  }
2637
2643
  }
2638
- db = new Database2(dbPath);
2644
+ db = options?.nativeTurnDeadlines ? createSqliteTurnDatabase2(dbPath) : new Database2(dbPath);
2639
2645
  installBootBusyTimeout(db, dbPath, busyTimeoutMs, options?.onBootBusyTimeout);
2640
2646
  if (!enforceSchemaFence(db, dbPath, latestSupportedVersion)) {
2641
2647
  closeQuietly(db);
@@ -2682,6 +2688,10 @@ async function openDatabaseAsync(dbPathOrOptions) {
2682
2688
  lastMigrationOnOpenRefusal = null;
2683
2689
  const existing = databases.get(dbPath);
2684
2690
  if (existing) {
2691
+ if (options?.nativeTurnDeadlines && !hasSqliteTurnDeadlineRouting2(existing)) {
2692
+ log2("[magic-context] storage unavailable: native turn deadlines must be selected on the first open; restart the host");
2693
+ return null;
2694
+ }
2685
2695
  const startedAt = performance.now();
2686
2696
  const accepted = enforceSchemaFence(existing, dbPath, latestSupportedVersion);
2687
2697
  if (accepted) {
@@ -2697,8 +2707,12 @@ async function openDatabaseAsync(dbPathOrOptions) {
2697
2707
  return accepted ? existing : null;
2698
2708
  }
2699
2709
  const pending = pendingAsyncOpens.get(dbPath);
2700
- if (pending)
2701
- return pending;
2710
+ if (pending) {
2711
+ if (!options?.nativeTurnDeadlines)
2712
+ return pending;
2713
+ const opened = await pending;
2714
+ return opened && hasSqliteTurnDeadlineRouting2(opened) ? opened : null;
2715
+ }
2702
2716
  if (!isFileBackedPath(dbPath)) {
2703
2717
  throw new Error("async migration requires a file-backed database; use the explicit synchronous opener for in-memory or URI test databases");
2704
2718
  }
@@ -2724,7 +2738,7 @@ async function openDatabaseAsync(dbPathOrOptions) {
2724
2738
  throw error;
2725
2739
  }
2726
2740
  }
2727
- db = new Database2(dbPath);
2741
+ db = options?.nativeTurnDeadlines ? createSqliteTurnDatabase2(dbPath) : new Database2(dbPath);
2728
2742
  installBootBusyTimeout(db, dbPath, busyTimeoutMs, options?.onBootBusyTimeout);
2729
2743
  openMs = performance.now() - openStartedAt;
2730
2744
  guardStartedAt = performance.now();
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  inRootAsyncContext2,
6
6
  isTransientSqliteError2
7
- } from "./index-hws5f0z9.js";
7
+ } from "./index-2qtx0q6h.js";
8
8
  import {
9
9
  PROMOTABLE_CATEGORIES,
10
10
  CATEGORY_DEFAULT_TTL
@@ -22,19 +22,19 @@ import {
22
22
  resolveStoredPathWorkspaceIdentity,
23
23
  sourceNameForMemory,
24
24
  managedAuthorityNoteRow
25
- } from "./index-5vgt1zeh.js";
25
+ } from "./index-3c3ztwgc.js";
26
26
  import {
27
27
  isKnownAutocommit
28
28
  } from "./index-w1avzkdt.js";
29
29
  import {
30
30
  SubcClient
31
- } from "./index-jxjr7kz9.js";
31
+ } from "./index-gwxaz0z5.js";
32
32
  import {
33
33
  buildCanonicalChunkTextFromFts2,
34
34
  loadCompartmentChunkEmbeddingsForSearch2,
35
35
  peekCompartmentChunkSearchPool2,
36
36
  warmCompartmentChunkSearchPool2
37
- } from "./index-5n5zxs8e.js";
37
+ } from "./index-vx6f7wff.js";
38
38
  import {
39
39
  recordEmbeddingMeasurement,
40
40
  saveCommitEmbedding,
@@ -52,7 +52,7 @@ import {
52
52
  getProjectEmbeddingSnapshot2,
53
53
  embedTextForProject2,
54
54
  embedItemsForProject2
55
- } from "./index-v2epyzbm.js";
55
+ } from "./index-w1twp2kp.js";
56
56
  import {
57
57
  saveEmbeddingIfHashMatches,
58
58
  getProjectEmbeddings2
@@ -62,7 +62,7 @@ import {
62
62
  isEmbeddingEnabled,
63
63
  embedText,
64
64
  ensureMemoryEmbeddings2
65
- } from "./index-b8am7tns.js";
65
+ } from "./index-pe5gz5c4.js";
66
66
  import {
67
67
  getMemorySelectColumns2,
68
68
  isMemoryRow2,
@@ -76,13 +76,13 @@ import {
76
76
  getMemoryById2,
77
77
  updateMemorySeenCount2,
78
78
  updateMemoryRetrievalCount2
79
- } from "./index-dzem6gn9.js";
79
+ } from "./index-29nw7n1r.js";
80
80
  import {
81
81
  cleanSearchText,
82
82
  keywordRelevance,
83
83
  matchedSearchSnippet,
84
84
  getIndexedMessageCorpusSize2
85
- } from "./index-vdy273xw.js";
85
+ } from "./index-wgmhk91m.js";
86
86
  import {
87
87
  MESSAGE_FTS_SESSION_FILTER_SQL,
88
88
  withMessageFtsSessionFilter
@@ -1970,6 +1970,7 @@ function getDefaultSubcConnectionFile() {
1970
1970
  var RERANK_MODEL = "gte-reranker-modernbert-base-f32";
1971
1971
  var RERANK_LANE_LIMIT = 25;
1972
1972
  var DEADLINE_MS = 1500;
1973
+ var DOCUMENT_BYTES = 1024;
1973
1974
  function isProseQuery(query) {
1974
1975
  const text = query.trim();
1975
1976
  if (!text || /[\n;]|^["'`]|["'`]$/.test(text))
@@ -2049,7 +2050,7 @@ function candidateText(location, title, body) {
2049
2050
  ${truncateUtf8(title.replaceAll(`
2050
2051
  `, " "), 120)}
2051
2052
  `;
2052
- return header + truncateUtf8(body, 1024 - Buffer.byteLength(header));
2053
+ return header + truncateUtf8(body, DOCUMENT_BYTES - Buffer.byteLength(header));
2053
2054
  }
2054
2055
 
2055
2056
  class RerankFailure extends Error {
@@ -2119,7 +2120,79 @@ async function connect(connectionFile) {
2119
2120
  }
2120
2121
  return bounded(connection);
2121
2122
  }
2122
- async function prepareReranker(projectRoot, sessionId, connectionFile, injectedClient) {
2123
+ async function remoteScores(config, query, documents, signal) {
2124
+ const controller = new AbortController;
2125
+ let timer;
2126
+ let onAbort;
2127
+ try {
2128
+ const cancelled = new Promise((_, reject) => {
2129
+ const cancel = (reason) => {
2130
+ reject(new RerankFailure(reason));
2131
+ controller.abort();
2132
+ };
2133
+ onAbort = () => cancel("aborted");
2134
+ if (signal?.aborted)
2135
+ onAbort();
2136
+ else
2137
+ signal?.addEventListener("abort", onAbort, { once: true });
2138
+ timer = setTimeout(() => cancel("timeout"), Math.max(50, Math.min(15000, config.timeout_ms ?? DEADLINE_MS)));
2139
+ });
2140
+ const request = async () => {
2141
+ const tei = config.endpoint?.startsWith("tei+");
2142
+ const endpoint = (tei ? config.endpoint?.slice(4) : config.endpoint)?.replace(/\/+$/, "");
2143
+ if (!endpoint || !/^https?:\/\//.test(endpoint))
2144
+ throw new RerankFailure("invalid_endpoint");
2145
+ const response = await fetch(`${endpoint}/rerank`, {
2146
+ method: "POST",
2147
+ headers: {
2148
+ "Content-Type": "application/json",
2149
+ ...config.api_key ? { Authorization: `Bearer ${config.api_key}` } : {}
2150
+ },
2151
+ body: JSON.stringify(tei ? { query, texts: documents } : {
2152
+ model: config.model,
2153
+ query,
2154
+ documents,
2155
+ top_n: documents.length
2156
+ }),
2157
+ signal: controller.signal,
2158
+ redirect: "error"
2159
+ });
2160
+ if (!response.ok)
2161
+ throw new RerankFailure(`http_${response.status}`);
2162
+ const body = await response.json();
2163
+ const rows = tei ? body : body?.results;
2164
+ if (!Array.isArray(rows) || rows.length !== documents.length)
2165
+ throw new RerankFailure("invalid_reply");
2166
+ const scores = new Array(documents.length);
2167
+ const seen = new Set;
2168
+ for (const row of rows) {
2169
+ const index = row?.index;
2170
+ const score = tei ? row?.score : row?.relevance_score;
2171
+ if (!Number.isInteger(index) || index < 0 || index >= documents.length || seen.has(index) || typeof score !== "number" || !Number.isFinite(score))
2172
+ throw new RerankFailure("invalid_reply");
2173
+ seen.add(index);
2174
+ scores[index] = score;
2175
+ }
2176
+ return scores;
2177
+ };
2178
+ return await Promise.race([cancelled, request()]);
2179
+ } finally {
2180
+ clearTimeout(timer);
2181
+ if (onAbort)
2182
+ signal?.removeEventListener("abort", onAbort);
2183
+ }
2184
+ }
2185
+ function remoteRerankSkipped(reason, onSkipped) {
2186
+ const safe = /^(?:invalid_reply|invalid_endpoint|validation|timeout|aborted|candidate_validation|http_\d{3})$/.test(reason) ? reason : "remote_error";
2187
+ const line = `Reranking skipped: ${safe}`;
2188
+ logRerankFallback(safe);
2189
+ onSkipped?.(line);
2190
+ }
2191
+ async function prepareReranker(projectRoot, sessionId, connectionFile, injectedClient, config) {
2192
+ if (config?.provider === "off")
2193
+ return null;
2194
+ if (config?.provider === "remote")
2195
+ return { remote: config };
2123
2196
  try {
2124
2197
  if (injectedClient === null)
2125
2198
  throw new RerankFailure("missing_synapse");
@@ -2136,36 +2209,43 @@ async function prepareReranker(projectRoot, sessionId, connectionFile, injectedC
2136
2209
  return null;
2137
2210
  }
2138
2211
  }
2139
- async function rerankSearchResults(session, query, baseline, pool, texts, limit) {
2212
+ async function rerankSearchResults(session, query, baseline, pool, texts, limit, signal, onSkipped) {
2140
2213
  if (!pool.length)
2141
2214
  return baseline;
2142
2215
  try {
2143
- if (pool.length > 20 || texts.length !== pool.length || texts.some((text) => Buffer.byteLength(text) > 1024))
2144
- throw new RerankFailure("validation");
2145
- const body = unwrap(await bounded(session.client.call("synapse", "rerank.score", {
2146
- model: RERANK_MODEL,
2147
- query,
2148
- candidates: texts,
2149
- required_fingerprint: session.lane.fingerprint,
2150
- allow_equivalent: false,
2151
- accept_declared: false,
2152
- max_queue_ms: 100,
2153
- deadline_ms: DEADLINE_MS
2154
- }, {
2155
- timeoutMs: DEADLINE_MS,
2156
- targetKind: "management_surface",
2157
- identity: session.identity
2158
- })));
2159
- if (body.fingerprint !== session.lane.fingerprint)
2160
- throw new RerankFailure("fingerprint_mismatch");
2161
- if (body.table_epoch !== session.lane.tableEpoch)
2162
- throw new RerankFailure("epoch_mismatch");
2163
- if (!Array.isArray(body.scores) || body.scores.length !== pool.length || body.scores.some((score) => typeof score !== "number" || !Number.isFinite(score)))
2216
+ if (pool.length > 20 || texts.length !== pool.length || texts.some((text) => Buffer.byteLength(text) > DOCUMENT_BYTES))
2164
2217
  throw new RerankFailure("validation");
2165
- const scores = body.scores;
2218
+ let scores;
2219
+ if ("remote" in session) {
2220
+ scores = await remoteScores(session.remote, query, texts, signal);
2221
+ } else {
2222
+ const body = unwrap(await bounded(session.client.call("synapse", "rerank.score", {
2223
+ model: RERANK_MODEL,
2224
+ query,
2225
+ candidates: texts,
2226
+ required_fingerprint: session.lane.fingerprint,
2227
+ allow_equivalent: false,
2228
+ max_queue_ms: 100,
2229
+ deadline_ms: DEADLINE_MS
2230
+ }, {
2231
+ timeoutMs: DEADLINE_MS,
2232
+ targetKind: "management_surface",
2233
+ identity: session.identity
2234
+ })));
2235
+ if (body.fingerprint !== session.lane.fingerprint)
2236
+ throw new RerankFailure("fingerprint_mismatch");
2237
+ if (body.table_epoch !== session.lane.tableEpoch)
2238
+ throw new RerankFailure("epoch_mismatch");
2239
+ if (!Array.isArray(body.scores) || body.scores.length !== pool.length || body.scores.some((score) => typeof score !== "number" || !Number.isFinite(score)))
2240
+ throw new RerankFailure("validation");
2241
+ scores = body.scores;
2242
+ }
2166
2243
  return pool.map((hit, index) => ({ hit, index, score: scores[index] })).sort((a, b) => b.score - a.score || a.index - b.index).slice(0, limit).map((row) => row.hit);
2167
2244
  } catch (error) {
2168
- logRerankFallback(reasonOf(error));
2245
+ if ("remote" in session)
2246
+ remoteRerankSkipped(error instanceof RerankFailure ? error.reason : "remote_error", onSkipped);
2247
+ else
2248
+ logRerankFallback(reasonOf(error));
2169
2249
  return baseline;
2170
2250
  }
2171
2251
  }
@@ -3486,7 +3566,7 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
3486
3566
  return [];
3487
3567
  }
3488
3568
  const limit = normalizeLimit(options.limit);
3489
- const reranker = options.explicitSearch && options.rerank !== false && isProseQuery(trimmedQuery) ? await prepareReranker(projectPath, sessionId, options.rerankConnectionFile, options.rerankClient) : null;
3569
+ const reranker = options.explicitSearch && options.rerank !== false && isProseQuery(trimmedQuery) ? await prepareReranker(projectPath, sessionId, options.rerankConnectionFile, options.rerankClient, options.rerankConfig) : null;
3490
3570
  const lanes = reranker || options.captureRerankLanes ? emptySearchLanes() : undefined;
3491
3571
  const dateRange = normalizeDateRange(options.from, options.to);
3492
3572
  const tierLimit = Math.max(limit * 3, DEFAULT_UNIFIED_SEARCH_LIMIT);
@@ -3656,11 +3736,14 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
3656
3736
  options.captureRerankLanes?.(lanes);
3657
3737
  }
3658
3738
  if (reranker && lanes) {
3659
- const pool = fuseSearchLanes(lanes);
3739
+ const pool = fuseSearchLanes(lanes).slice(0, "remote" in reranker ? reranker.remote.top_n : 20);
3660
3740
  try {
3661
- results = await rerankSearchResults(reranker, trimmedQuery, results, pool, candidateTexts(db, sessionId, projectPath, pool), limit);
3741
+ results = await rerankSearchResults(reranker, trimmedQuery, results, pool, candidateTexts(db, sessionId, projectPath, pool), limit, options.signal, options.onRerankSkipped);
3662
3742
  } catch {
3663
- logRerankFallback("candidate_validation");
3743
+ if ("remote" in reranker)
3744
+ remoteRerankSkipped("candidate_validation", options.onRerankSkipped);
3745
+ else
3746
+ logRerankFallback("candidate_validation");
3664
3747
  }
3665
3748
  }
3666
3749
  if (!options.measurementDisabled) {
@@ -4,7 +4,7 @@ import {
4
4
  renderToolTemplate,
5
5
  resolveModelConfigValue,
6
6
  deriveDefaultProtectedTokens
7
- } from "./index-bxmf4dhr.js";
7
+ } from "./index-ccanzg8p.js";
8
8
  import {
9
9
  getHarness2,
10
10
  harnessOwnsOpenCodeStore2
@@ -23,7 +23,7 @@ import {
23
23
  TAG_SELECT_COLUMNS2,
24
24
  getCandidateToolOwners2,
25
25
  pickNearestPriorOwner2
26
- } from "./index-bttctq07.js";
26
+ } from "./index-n8e5e9fp.js";
27
27
  import {
28
28
  OMO_INTERNAL_INITIATOR_MARKER,
29
29
  isSystemDirective,
@@ -43,7 +43,7 @@ import {
43
43
  import {
44
44
  Database2,
45
45
  prepareCachedStatement2
46
- } from "./index-hws5f0z9.js";
46
+ } from "./index-2qtx0q6h.js";
47
47
  import {
48
48
  stableStringify,
49
49
  closeQuietly
@@ -72,7 +72,7 @@ import {
72
72
  hasRawSessionMessageByIdFromDb2,
73
73
  readRawSeedTailFromDb2,
74
74
  readRawSessionBoundaryEndpointsFromDb2
75
- } from "./index-rfyvax95.js";
75
+ } from "./index-at6py2k3.js";
76
76
  import {
77
77
  logSlowWriteTransaction
78
78
  } from "./index-hqw0rt9k.js";
@@ -2578,6 +2578,13 @@ function loadPostprocessReplaySnapshot(db, sessionId) {
2578
2578
  const todoPermissionDenied = row?.todo_permission_denied === 1 ? true : row?.todo_permission_denied === 0 ? false : null;
2579
2579
  const thinkingBindingRecoveryTarget = row?.thinking_binding_recovery_target;
2580
2580
  return {
2581
+ servedShapeRepair: (() => {
2582
+ try {
2583
+ return parseReplayDocument(row?.trailing_blank_decisions).servedShapeRepair;
2584
+ } catch {
2585
+ return;
2586
+ }
2587
+ })(),
2581
2588
  executeReclaim: executeReclaimFromReplay(row?.trailing_blank_decisions),
2582
2589
  staleReduceStrippedIds: new Set(parseStrippedBlob(row?.stale_reduce_stripped_ids)),
2583
2590
  processedImageStrippedIds: new Set(parseProcessedImageMarkers(row?.processed_image_stripped_ids).keys()),
@@ -3949,6 +3956,9 @@ function hasAnthropicReasoning(messages) {
3949
3956
  });
3950
3957
  }
3951
3958
 
3959
+ // ../plugin/src/hooks/magic-context/served-shape-repair.ts
3960
+ var sources = new WeakMap;
3961
+
3952
3962
  // ../plugin/src/hooks/magic-context/strip-content.ts
3953
3963
  var METADATA_PART_TYPES = new Set([
3954
3964
  "step-start",
@@ -9,7 +9,7 @@ import {
9
9
  } from "./index-fgs78jyd.js";
10
10
  import {
11
11
  inRootAsyncContext2
12
- } from "./index-hws5f0z9.js";
12
+ } from "./index-2qtx0q6h.js";
13
13
 
14
14
  // ../plugin/src/features/magic-context/memory/embedding-synapse.ts
15
15
  import { createHash } from "node:crypto";
@@ -1788,7 +1788,6 @@ function getSynapseBatchRequestKey(args) {
1788
1788
  required_fingerprint: args.fingerprint,
1789
1789
  required_epoch: args.tableEpoch,
1790
1790
  allow_equivalent: false,
1791
- accept_declared: false,
1792
1791
  ids: args.items.map((item) => item.id),
1793
1792
  content_sha256: args.items.map((item) => item.contentSha256),
1794
1793
  ...args.purpose === "query" ? { purpose: args.purpose } : {}
@@ -2177,8 +2176,7 @@ class SynapseEmbeddingProvider {
2177
2176
  model: metadata.model,
2178
2177
  required_fingerprint: metadata.fingerprint,
2179
2178
  required_epoch: metadata.table_epoch,
2180
- allow_equivalent: false,
2181
- accept_declared: false
2179
+ allow_equivalent: false
2182
2180
  };
2183
2181
  }
2184
2182
  batchRequest(items, requestKey, purpose) {
@@ -4,7 +4,7 @@ import {
4
4
  } from "./index-fgs78jyd.js";
5
5
  import {
6
6
  inRootAsyncContext2
7
- } from "./index-hws5f0z9.js";
7
+ } from "./index-2qtx0q6h.js";
8
8
  import {
9
9
  projectDirectoryKey
10
10
  } from "./index-wrr9rp9a.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-0h2mkab2.js";
4
4
  import {
5
5
  isUserHomeDirectory
6
- } from "./index-p63nwn5v.js";
6
+ } from "./index-hxp6q5f8.js";
7
7
  import {
8
8
  logSlowWriteTransaction
9
9
  } from "./index-hqw0rt9k.js";
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  getTagIdentityWriteGeneration2,
12
12
  getSqliteDatabasePath2
13
- } from "./index-hws5f0z9.js";
13
+ } from "./index-2qtx0q6h.js";
14
14
  import {
15
15
  jsonHashSink,
16
16
  tagOrderConstraintIndex,
@@ -591,13 +591,16 @@ function stripDanglingTagNotationGlobally(value) {
591
591
  function stripTagSectionCharacters(value) {
592
592
  return value.replace(STRAY_SECTION_CHAR_REGEX, "");
593
593
  }
594
- function stripPersistedAssistantText(value) {
594
+ function stripPersistedAssistantText(value, acceptsEmpty = true) {
595
+ if (!acceptsEmpty && !value.includes("§") && !value.trim())
596
+ return value;
595
597
  let text = stripWellFormedLeadingTagPrefix(value);
596
598
  text = stripCompleteTagPairsGlobally(text);
597
599
  text = stripMalformedTagNotationGlobally(text);
598
600
  text = stripDanglingTagNotationGlobally(text);
599
601
  text = stripTagSectionCharacters(text);
600
- return text.trim();
602
+ const stripped = text.trim();
603
+ return !acceptsEmpty && value.trim().length > 0 && stripped.length === 0 ? value : stripped;
601
604
  }
602
605
  function byteSize(value) {
603
606
  return encoder.encode(value).length;
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  DEFAULT_LOCAL_EMBEDDING_MODEL
3
- } from "./index-bxmf4dhr.js";
3
+ } from "./index-ccanzg8p.js";
4
4
  import {
5
5
  log2
6
6
  } from "./index-fgs78jyd.js";
7
7
  import {
8
8
  isSynapseEmbeddingTruncated,
9
9
  SynapseEmbeddingProvider
10
- } from "./index-jxjr7kz9.js";
10
+ } from "./index-gwxaz0z5.js";
11
11
  import {
12
12
  LocalEmbeddingProvider
13
- } from "./index-e19qtjj0.js";
13
+ } from "./index-wqpjhx1p.js";
14
14
  import {
15
15
  OpenAICompatibleEmbeddingProvider,
16
16
  getProjectEmbeddingSnapshot2,
17
17
  embedBatchForProject2
18
- } from "./index-v2epyzbm.js";
18
+ } from "./index-w1twp2kp.js";
19
19
  import {
20
20
  isEmbeddingHostBusy2
21
21
  } from "./index-9p40dgkm.js";
@@ -6,7 +6,7 @@ import {
6
6
  } from "./index-my0dn413.js";
7
7
  import {
8
8
  readRawSessionMessageIdOrdinalsForRange2
9
- } from "./index-zhwwp8zz.js";
9
+ } from "./index-gqjxy2p7.js";
10
10
 
11
11
  // ../plugin/src/tools/ctx-expand/search-archive.ts
12
12
  var archiveReadsOnThisThread = 0;
@@ -10,10 +10,10 @@ import {
10
10
  } from "./index-fgs78jyd.js";
11
11
  import {
12
12
  isSynapseEmbeddingTruncated
13
- } from "./index-jxjr7kz9.js";
13
+ } from "./index-gwxaz0z5.js";
14
14
  import {
15
15
  messageFtsOrdinalRangeIsMapped2
16
- } from "./index-rgfb753z.js";
16
+ } from "./index-579m1751.js";
17
17
 
18
18
  // ../plugin/src/features/magic-context/compartment-chunk-embedding.ts
19
19
  import { createHash } from "node:crypto";
@@ -4,7 +4,7 @@ import {
4
4
  withSqliteBackgroundWriter2,
5
5
  withoutSqliteTransformPass2,
6
6
  isTransientSqliteError2
7
- } from "./index-hws5f0z9.js";
7
+ } from "./index-2qtx0q6h.js";
8
8
  import {
9
9
  estimateTokens
10
10
  } from "./index-my0dn413.js";
@@ -20,7 +20,7 @@ import {
20
20
  isSynapseEmbeddingTruncated,
21
21
  getSynapseBatchRequestKey,
22
22
  SynapseEmbeddingProvider
23
- } from "./index-jxjr7kz9.js";
23
+ } from "./index-gwxaz0z5.js";
24
24
  import {
25
25
  createWorkerShutdown
26
26
  } from "./index-54wmg4rj.js";
@@ -41,10 +41,10 @@ import {
41
41
  countSessionCompartmentEmbedCoverage2,
42
42
  countSessionCompartmentEmbedCoveragePolite2,
43
43
  countUnembeddedSessionCompartmentsPolite2
44
- } from "./index-5n5zxs8e.js";
44
+ } from "./index-vx6f7wff.js";
45
45
  import {
46
46
  DEFAULT_LOCAL_EMBEDDING_MODEL
47
- } from "./index-bxmf4dhr.js";
47
+ } from "./index-ccanzg8p.js";
48
48
  import {
49
49
  embeddingModelsMatch,
50
50
  resolveEmbeddingTextPrefixes,
@@ -54,10 +54,10 @@ import {
54
54
  getEmbeddingProviderIdentity,
55
55
  dominantEmbeddingFailure,
56
56
  LocalEmbeddingProvider
57
- } from "./index-e19qtjj0.js";
57
+ } from "./index-wqpjhx1p.js";
58
58
  import {
59
59
  setBootQuietPeriodForTests
60
- } from "./index-p63nwn5v.js";
60
+ } from "./index-hxp6q5f8.js";
61
61
  import {
62
62
  isEmbeddingHostBusy2
63
63
  } from "./index-9p40dgkm.js";
@@ -68,7 +68,7 @@ import {
68
68
  acquireGitSweepLease,
69
69
  renewGitSweepLease,
70
70
  releaseGitSweepLease
71
- } from "./index-qerzchrs.js";
71
+ } from "./index-j3pz3a1b.js";
72
72
  import {
73
73
  saveEmbeddingIfHashMatches,
74
74
  getMemoryEmbedCoverage,
@@ -1059,6 +1059,7 @@ var EMBED_SLICE_RETRY_BASE_MS = 250;
1059
1059
  var EMBED_SLOW_FAILURE_NO_RETRY_MS = 1e4;
1060
1060
  var MAX_CONSECUTIVE_FAILED_BATCHES = 3;
1061
1061
  var projectRegistrations = new Map;
1062
+ var projectContextUsers = new Map;
1062
1063
  var shadowRegistrations = new Map;
1063
1064
  var shadowQueue = [];
1064
1065
  var shadowWorker = null;
@@ -3101,6 +3102,7 @@ function _resetProjectEmbeddingRegistryForTests2() {
3101
3102
  disposeProvider(registration.provider);
3102
3103
  }
3103
3104
  projectRegistrations.clear();
3105
+ projectContextUsers.clear();
3104
3106
  shadowRegistrations.clear();
3105
3107
  shadowQueue.length = 0;
3106
3108
  pendingShadowBackfills.clear();
@@ -18,7 +18,7 @@ import {
18
18
  prepareCachedStatement2,
19
19
  withSqliteBackgroundWriter2,
20
20
  withoutSqliteTransformPass2
21
- } from "./index-hws5f0z9.js";
21
+ } from "./index-2qtx0q6h.js";
22
22
  import {
23
23
  removeSystemReminders,
24
24
  removeNestedBlocks,
@@ -31,10 +31,10 @@ import {
31
31
  messageFtsOrdinalRangeIsMapped2,
32
32
  getMessageFtsRowidMapBackfillProgress2,
33
33
  deleteUnmappedMessageFtsRows2
34
- } from "./index-rgfb753z.js";
34
+ } from "./index-579m1751.js";
35
35
  import {
36
36
  deleteChunkEmbedBackoffForSession2
37
- } from "./index-5n5zxs8e.js";
37
+ } from "./index-vx6f7wff.js";
38
38
  import {
39
39
  closeQuietly,
40
40
  TAG_TOMBSTONE_OWNER_PREFIX,
@@ -46,7 +46,7 @@ import {
46
46
  } from "./index-w1avzkdt.js";
47
47
  import {
48
48
  cleanUserText2
49
- } from "./index-zhwwp8zz.js";
49
+ } from "./index-gqjxy2p7.js";
50
50
  import {
51
51
  sameProjectDirectory
52
52
  } from "./index-wrr9rp9a.js";
@@ -791,6 +791,12 @@ class V2StoreReader {
791
791
  return typeof row?.count === "number" ? row.count : 0;
792
792
  });
793
793
  }
794
+ messageCountAfterSequence(sessionID, after, through) {
795
+ const rawTypes = RAW_MESSAGE_TYPES.map(() => "?").join(", ");
796
+ const row = this.prepare(`SELECT COUNT(*) AS count FROM session_message
797
+ WHERE session_id = ? AND seq > ? AND seq <= ? AND type IN (${rawTypes})`).get(sessionID, after, through, ...RAW_MESSAGE_TYPES);
798
+ return typeof row?.count === "number" ? row.count : 0;
799
+ }
794
800
  sessionDirectoryPage(afterSessionID, limit) {
795
801
  const rows = this.prepare(`SELECT id, COALESCE(directory, '') AS directory FROM session_v2
796
802
  WHERE id > ? ORDER BY id ASC LIMIT ?`).all(afterSessionID ?? "", limit);