@cortexkit/opencode-magic-context 0.49.31 → 0.49.32

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 (53) hide show
  1. package/dist/auto-search-worker.js +4 -4
  2. package/dist/chunk-embedding-write-worker.js +1 -1
  3. package/dist/{compartment-chunk-embedding-qgp0tbf7.js → compartment-chunk-embedding-5q5gj67r.js} +1 -1
  4. package/dist/{context-9a0f8mzh.js → context-n27jdyyh.js} +12 -10
  5. package/dist/{embedding-backfill-mms9nb0h.js → embedding-backfill-0jgtqxen.js} +3 -3
  6. package/dist/features/magic-context/chunk-scope-repair-revision.d.ts +4 -0
  7. package/dist/features/magic-context/chunk-scope-repair-revision.d.ts.map +1 -0
  8. package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
  9. package/dist/features/magic-context/dreamer/task-gates.d.ts +2 -0
  10. package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
  11. package/dist/features/magic-context/message-index-async.d.ts +3 -0
  12. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  13. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  14. package/dist/features/magic-context/search.d.ts.map +1 -1
  15. package/dist/hooks/magic-context/auto-search-branch-index.fixture.d.ts +2 -0
  16. package/dist/hooks/magic-context/auto-search-branch-index.fixture.d.ts.map +1 -0
  17. package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
  18. package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
  19. package/dist/{index-gxkhzmjq.js → index-2743x98y.js} +65 -2
  20. package/dist/{index-y6ynjghv.js → index-2agkcr3y.js} +2 -2
  21. package/dist/{index-22e7khnr.js → index-3drcgsnf.js} +56 -372
  22. package/dist/index-94ef0qe2.js +429 -0
  23. package/dist/{index-pe6b4bhs.js → index-as2amvn3.js} +1 -1
  24. package/dist/{index-kmayq4kq.js → index-bzwh06cp.js} +3 -3
  25. package/dist/{index-qathsvz2.js → index-g0kqnc6y.js} +11 -4
  26. package/dist/{index-vtz789ex.js → index-qr2mb02j.js} +16 -5
  27. package/dist/{index-vnn5405n.js → index-rfxzazzy.js} +1 -1
  28. package/dist/{index-0bjktrjt.js → index-t6b3px80.js} +2 -2
  29. package/dist/{index-mm93m7y6.js → index-v7287tzq.js} +47 -7
  30. package/dist/index.js +16 -14
  31. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  32. package/dist/{project-embedding-registry-cg281d9j.js → project-embedding-registry-6yex0r9f.js} +2 -2
  33. package/dist/{recomp-orchestrator-ynehxbya.js → recomp-orchestrator-6ncc6wrw.js} +6 -6
  34. package/dist/{search-fbaz1m8r.js → search-040pac3a.js} +6 -5
  35. package/dist/{transform-postprocess-phase-50h70ft8.js → transform-postprocess-phase-wvt1k03d.js} +7 -6
  36. package/dist/v2/auto-search-worker.js +4 -4
  37. package/dist/v2/chunk-embedding-write-worker.js +1 -1
  38. package/dist/v2/{compartment-chunk-embedding-63dzs31c.js → compartment-chunk-embedding-rc31e6md.js} +1 -1
  39. package/dist/v2/{context-cdqw9jex.js → context-ehews84p.js} +71 -264
  40. package/dist/v2/{embedding-backfill-35k6czrr.js → embedding-backfill-f43hd8y6.js} +3 -3
  41. package/dist/v2/{project-embedding-registry-p1p10ks7.js → project-embedding-registry-1x5qe2fy.js} +2 -2
  42. package/dist/v2/{recomp-orchestrator-kdxr4tx8.js → recomp-orchestrator-3r9kcs61.js} +5 -5
  43. package/dist/v2/{search-q3jjw6zp.js → search-q3wkpe8t.js} +5 -5
  44. package/dist/v2/{server-p0snacz3.js → server-2aasmpsp.js} +1 -1
  45. package/dist/v2/{server-rdjgz95f.js → server-4n176b5m.js} +3 -3
  46. package/dist/v2/{server-zh3esb0z.js → server-ab8017gw.js} +65 -2
  47. package/dist/v2/{server-4sn3at8p.js → server-h1byrhwx.js} +47 -7
  48. package/dist/v2/{server-42nebt63.js → server-n14edf07.js} +336 -25
  49. package/dist/v2/{server-ph300d6m.js → server-tkdabx8q.js} +1 -1
  50. package/dist/v2/server.js +2 -2
  51. package/dist/v2/{wrapup-orchestrator-prfvyqbb.js → wrapup-orchestrator-ddmvbkra.js} +5 -5
  52. package/dist/{wrapup-orchestrator-4zhkcsz0.js → wrapup-orchestrator-fyvyzcbm.js} +7 -7
  53. package/package.json +1 -1
@@ -304,7 +304,7 @@ import {
304
304
  startCompartmentAgent,
305
305
  setRecompStarting2,
306
306
  setRecompTerminal2
307
- } from "./server-rdjgz95f.js";
307
+ } from "./server-4n176b5m.js";
308
308
  import {
309
309
  resolveHistorianModel2
310
310
  } from "./server-5kym00ag.js";
@@ -712,13 +712,34 @@ import {
712
712
  import {
713
713
  cleanSearchText,
714
714
  matchedSearchSnippet,
715
- getLastIndexedOrdinal,
716
- getMessageIndexReconciliationStartOrdinal,
717
- isMessageIndexReconciledThrough,
718
- clearIndexedMessages,
719
- indexMessagesAfterOrdinal
715
+ getLastIndexedOrdinal
720
716
  } from "./server-hwag0khr.js";
721
717
  import"./server-awr8qa4c.js";
718
+ import {
719
+ getMessageIndexEpoch,
720
+ isMessageIndexSearchable,
721
+ scheduleReconciliation,
722
+ scheduleClearAndReindex,
723
+ getMessageIndexQueueHeapStats,
724
+ renderSingleStoreMigrationRequiredRefusal,
725
+ SingleStoreMigrationRequiredError,
726
+ singleStoreMigrationRequiredFailure,
727
+ projectNeedsSingleStoreMigration,
728
+ STORE_AHEAD_OF_BINARY_CODE,
729
+ storeAheadOfBinaryFailure,
730
+ TRANSFORM_PAGE_UPLOAD_TIMEOUT_MS,
731
+ transformColdStartExecuteTimeoutMs,
732
+ getDefaultSubcConnectionFile,
733
+ isModuleTransportGenerationChangedResult,
734
+ SubcModuleTransport,
735
+ indexCommitsForProject,
736
+ embedUnembeddedCommits,
737
+ createUnifiedSearchDiagnostics2,
738
+ parseIdShapedQuery2,
739
+ resolveMemoriesByIdsForSearch2,
740
+ unifiedSearch2,
741
+ formatSearchResults2
742
+ } from "./server-n14edf07.js";
722
743
  import {
723
744
  embedPauseBySession,
724
745
  embedRunStateBySession,
@@ -748,7 +769,7 @@ import {
748
769
  embedSessionCompartmentChunks2,
749
770
  getEmbeddingCoverageStatus2,
750
771
  getAutoEmbeddingSessionCoverage2
751
- } from "./server-zh3esb0z.js";
772
+ } from "./server-ab8017gw.js";
752
773
  import {
753
774
  SubcClient,
754
775
  connectionFileExists,
@@ -759,7 +780,7 @@ import {
759
780
  } from "./server-ab1g0wn9.js";
760
781
  import {
761
782
  deleteChunkEmbedBackoffForSession2
762
- } from "./server-4sn3at8p.js";
783
+ } from "./server-h1byrhwx.js";
763
784
  import {
764
785
  registerOwnRpcServerInstance,
765
786
  rpcPortDir,
@@ -825,7 +846,7 @@ import {
825
846
  readGitFileChangeTimesSince,
826
847
  verificationFileExists,
827
848
  normalizeVerificationFiles
828
- } from "./server-ph300d6m.js";
849
+ } from "./server-tkdabx8q.js";
829
850
  import {
830
851
  deriveTriggerBudget2,
831
852
  deriveHistorianChunkTokens2,
@@ -859,7 +880,7 @@ import {
859
880
  } from "./server-vr4szghm.js";
860
881
  import {
861
882
  cosineSimilarity
862
- } from "./server-p0snacz3.js";
883
+ } from "./server-2aasmpsp.js";
863
884
  import {
864
885
  computeCueContentHash,
865
886
  hasMuralCueColumns,
@@ -897,26 +918,6 @@ import {
897
918
  flushIgnoredMessages2,
898
919
  sendStatusNotification2
899
920
  } from "./server-qc915kw2.js";
900
- import {
901
- renderSingleStoreMigrationRequiredRefusal,
902
- SingleStoreMigrationRequiredError,
903
- singleStoreMigrationRequiredFailure,
904
- projectNeedsSingleStoreMigration,
905
- STORE_AHEAD_OF_BINARY_CODE,
906
- storeAheadOfBinaryFailure,
907
- TRANSFORM_PAGE_UPLOAD_TIMEOUT_MS,
908
- transformColdStartExecuteTimeoutMs,
909
- getDefaultSubcConnectionFile,
910
- isModuleTransportGenerationChangedResult,
911
- SubcModuleTransport,
912
- indexCommitsForProject,
913
- embedUnembeddedCommits,
914
- createUnifiedSearchDiagnostics2,
915
- parseIdShapedQuery2,
916
- resolveMemoriesByIdsForSearch2,
917
- unifiedSearch2,
918
- formatSearchResults2
919
- } from "./server-42nebt63.js";
920
921
  import {
921
922
  resolvePromptContext2
922
923
  } from "./server-fmsr7v69.js";
@@ -1739,234 +1740,6 @@ function summarizeManualDream(summary) {
1739
1740
  `);
1740
1741
  }
1741
1742
 
1742
- // src/features/magic-context/message-index-async.ts
1743
- var indexCancellations = new Map;
1744
- var sessionEpochs = new Map;
1745
- var workerMeasurements = new WeakMap;
1746
- function isDatabaseLockedError(error) {
1747
- if (!error || typeof error !== "object")
1748
- return false;
1749
- const e = error;
1750
- if (typeof e.code === "string") {
1751
- if (e.code === "SQLITE_BUSY" || e.code === "SQLITE_LOCKED")
1752
- return true;
1753
- }
1754
- if (typeof e.message === "string") {
1755
- if (/database is locked/i.test(e.message))
1756
- return true;
1757
- if (/sqlite_(busy|locked)/i.test(e.message))
1758
- return true;
1759
- }
1760
- return false;
1761
- }
1762
- var RECONCILIATION_BATCH_SIZE = 100;
1763
-
1764
- class MagicContextMessageIndexHeapHolder {
1765
- reconciledSessions = new Set;
1766
- reconciledSnapshots = new Map;
1767
- stalledSessions = new Set;
1768
- reconciliationScheduledSessions = new Set;
1769
- clearAndReindexScheduledSessions = new Map;
1770
- sessionLocks = new Map;
1771
- incrementalTimers = new Map;
1772
- pendingIncrementalKeys = new Set;
1773
- completedIncrementalKeys = new Set;
1774
- activeReconcilerBuffers = new Map;
1775
- }
1776
- var heapHolder = new MagicContextMessageIndexHeapHolder;
1777
- function clearCompletedIncrementalKeys(sessionId) {
1778
- const prefix = `${sessionId}\x00`;
1779
- for (const key of heapHolder.completedIncrementalKeys) {
1780
- if (key.startsWith(prefix))
1781
- heapHolder.completedIncrementalKeys.delete(key);
1782
- }
1783
- }
1784
- var PREPARE_RETRY_MS = 60000;
1785
- async function sourceReady(source, sessionId) {
1786
- const prepare = source?.prepare;
1787
- return typeof prepare === "function" ? prepare(sessionId) : true;
1788
- }
1789
- function defer(fn) {
1790
- const immediate = globalThis.setImmediate;
1791
- if (typeof immediate === "function") {
1792
- inRootAsyncContext2(() => immediate(fn));
1793
- return;
1794
- }
1795
- inRootAsyncContext2(() => setTimeout(fn, 0));
1796
- }
1797
- function yieldToEventLoop() {
1798
- return new Promise((resolve) => defer(resolve));
1799
- }
1800
- function runWithSessionLock(sessionId, operation) {
1801
- const previous = heapHolder.sessionLocks.get(sessionId) ?? Promise.resolve();
1802
- const run = previous.catch(() => {
1803
- return;
1804
- }).then(async () => {
1805
- await operation();
1806
- });
1807
- heapHolder.sessionLocks.set(sessionId, run);
1808
- run.finally(() => {
1809
- if (heapHolder.sessionLocks.get(sessionId) === run) {
1810
- heapHolder.sessionLocks.delete(sessionId);
1811
- }
1812
- }).catch(() => {
1813
- return;
1814
- });
1815
- return run;
1816
- }
1817
- function logIndexingError(sessionId, action, error) {
1818
- if (isDatabaseLockedError(error)) {
1819
- sessionLog2(sessionId, `message FTS async ${action} skipped (database busy; will retry on next reconciliation)`);
1820
- return;
1821
- }
1822
- sessionLog2(sessionId, `message FTS async ${action} failed: ${error instanceof Error ? error.message : String(error)}`);
1823
- log2(`[message-index-async] ${action} failed for ${sessionId}:`, error);
1824
- }
1825
- function serializedMessageBytes(messages) {
1826
- try {
1827
- return Buffer.byteLength(JSON.stringify(messages));
1828
- } catch {
1829
- return 0;
1830
- }
1831
- }
1832
- function logReconciliationStall(sessionId, reason) {
1833
- if (heapHolder.stalledSessions.has(sessionId))
1834
- return;
1835
- heapHolder.stalledSessions.add(sessionId);
1836
- sessionLog2(sessionId, `message FTS reconciliation stalled: ${reason}; will retry`);
1837
- }
1838
- async function reconcileSessionIndex(db, sessionId, readMessages) {
1839
- if (!await sourceReady(readMessages, sessionId)) {
1840
- logReconciliationStall(sessionId, "raw message reader is not ready");
1841
- return false;
1842
- }
1843
- await runWithSessionLock(sessionId, async () => {
1844
- if (!readMessages.getRevision && heapHolder.reconciledSessions.has(sessionId))
1845
- return;
1846
- let fallbackSnapshot = null;
1847
- try {
1848
- const fullReader = typeof readMessages === "function" ? readMessages : null;
1849
- const revision = readMessages.getRevision?.(sessionId);
1850
- const previous = heapHolder.reconciledSnapshots.get(sessionId);
1851
- const finalWatermark = previous && revision === previous.revision ? previous.count : revision !== undefined && readMessages.getCountAfterRevision ? previous && revision > previous.revision ? previous.count + readMessages.getCountAfterRevision(sessionId, previous.revision, revision) : readMessages.getCountAfterRevision(sessionId, -1, revision) : readMessages.getCount ? readMessages.getCount(sessionId) : (fallbackSnapshot = fullReader?.(sessionId) ?? []).length;
1852
- let cursor = getMessageIndexReconciliationStartOrdinal(db, sessionId);
1853
- let after = cursor === previous?.count ? previous.after : undefined;
1854
- while (cursor < finalWatermark) {
1855
- const pageEnd = Math.min(finalWatermark, cursor + RECONCILIATION_BATCH_SIZE);
1856
- const messages = readMessages.readPage ? readMessages.readPage(sessionId, cursor, RECONCILIATION_BATCH_SIZE, finalWatermark, after) : (fallbackSnapshot ?? []).filter((message) => message.ordinal > cursor && message.ordinal <= pageEnd);
1857
- const retainedMessages = fallbackSnapshot ?? messages;
1858
- heapHolder.activeReconcilerBuffers.set(sessionId, retainedMessages);
1859
- withSqliteBackgroundWriter2(() => indexMessagesAfterOrdinal(db, sessionId, messages, cursor, pageEnd));
1860
- const nextCursor = getMessageIndexReconciliationStartOrdinal(db, sessionId);
1861
- if (nextCursor <= cursor)
1862
- break;
1863
- cursor = nextCursor;
1864
- const last = messages.at(-1);
1865
- after = last?.ordinal === cursor && typeof last.createdAt === "number" ? { timeCreated: last.createdAt, id: last.id } : undefined;
1866
- if (cursor < finalWatermark) {
1867
- await yieldToEventLoop();
1868
- }
1869
- }
1870
- if (isMessageIndexReconciledThrough(db, sessionId, finalWatermark)) {
1871
- heapHolder.reconciledSessions.add(sessionId);
1872
- if (revision !== undefined) {
1873
- if (!after && finalWatermark > 0 && readMessages.readPage) {
1874
- const last = readMessages.readPage(sessionId, finalWatermark - 1, 1, finalWatermark).at(-1);
1875
- if (last?.ordinal === finalWatermark && typeof last.createdAt === "number")
1876
- after = { timeCreated: last.createdAt, id: last.id };
1877
- }
1878
- heapHolder.reconciledSnapshots.set(sessionId, {
1879
- revision,
1880
- count: finalWatermark,
1881
- after
1882
- });
1883
- }
1884
- } else {
1885
- logReconciliationStall(sessionId, `gap after ordinal ${cursor} (store count ${finalWatermark})`);
1886
- }
1887
- } finally {
1888
- heapHolder.activeReconcilerBuffers.delete(sessionId);
1889
- }
1890
- });
1891
- return true;
1892
- }
1893
- function scheduleReconciliation(db, sessionId, readMessages) {
1894
- if (!readMessages.getRevision && heapHolder.reconciledSessions.has(sessionId) || heapHolder.reconciliationScheduledSessions.has(sessionId)) {
1895
- return;
1896
- }
1897
- heapHolder.reconciliationScheduledSessions.add(sessionId);
1898
- scheduleAfterBootQuiet(() => {
1899
- defer(() => {
1900
- let appendedDuringReconciliation = false;
1901
- const previousSnapshot = heapHolder.reconciledSnapshots.get(sessionId);
1902
- reconcileSessionIndex(db, sessionId, readMessages).then((ran) => {
1903
- if (ran) {
1904
- const snapshot = heapHolder.reconciledSnapshots.get(sessionId);
1905
- appendedDuringReconciliation = snapshot !== undefined && snapshot !== previousSnapshot && readMessages.getRevision !== undefined && readMessages.getRevision(sessionId) !== snapshot.revision;
1906
- return;
1907
- }
1908
- inRootAsyncContext2(() => setTimeout(() => {
1909
- heapHolder.reconciliationScheduledSessions.delete(sessionId);
1910
- scheduleReconciliation(db, sessionId, readMessages);
1911
- }, PREPARE_RETRY_MS)).unref?.();
1912
- }).catch((error) => {
1913
- logReconciliationStall(sessionId, error instanceof Error ? error.message : String(error));
1914
- if (isDatabaseLockedError(error))
1915
- inRootAsyncContext2(() => setTimeout(() => scheduleReconciliation(db, sessionId, readMessages), 1000)).unref();
1916
- }).finally(() => {
1917
- heapHolder.reconciliationScheduledSessions.delete(sessionId);
1918
- if (appendedDuringReconciliation)
1919
- scheduleReconciliation(db, sessionId, readMessages);
1920
- });
1921
- });
1922
- });
1923
- }
1924
- function scheduleClearAndReindex(db, sessionId, readMessages) {
1925
- heapHolder.reconciledSessions.delete(sessionId);
1926
- heapHolder.reconciledSnapshots.delete(sessionId);
1927
- heapHolder.reconciliationScheduledSessions.delete(sessionId);
1928
- clearCompletedIncrementalKeys(sessionId);
1929
- const existing = heapHolder.clearAndReindexScheduledSessions.get(sessionId);
1930
- if (existing) {
1931
- existing.source = readMessages;
1932
- return;
1933
- }
1934
- const pending = { source: readMessages };
1935
- heapHolder.clearAndReindexScheduledSessions.set(sessionId, pending);
1936
- scheduleAfterBootQuiet(() => {
1937
- defer(() => {
1938
- let cleared = false;
1939
- runWithSessionLock(sessionId, () => {
1940
- if (heapHolder.clearAndReindexScheduledSessions.get(sessionId) !== pending)
1941
- return;
1942
- heapHolder.clearAndReindexScheduledSessions.delete(sessionId);
1943
- heapHolder.reconciledSessions.delete(sessionId);
1944
- heapHolder.reconciledSnapshots.delete(sessionId);
1945
- clearCompletedIncrementalKeys(sessionId);
1946
- clearIndexedMessages(db, sessionId);
1947
- cleared = true;
1948
- }).then(() => cleared ? reconcileSessionIndex(db, sessionId, pending.source) : undefined).catch((error) => {
1949
- heapHolder.reconciledSessions.delete(sessionId);
1950
- if (heapHolder.clearAndReindexScheduledSessions.get(sessionId) === pending)
1951
- heapHolder.clearAndReindexScheduledSessions.delete(sessionId);
1952
- logIndexingError(sessionId, "clear and reindex", error);
1953
- });
1954
- });
1955
- });
1956
- }
1957
- function getMessageIndexQueueHeapStats() {
1958
- return {
1959
- queueLength: heapHolder.reconciliationScheduledSessions.size + heapHolder.incrementalTimers.size + heapHolder.pendingIncrementalKeys.size,
1960
- reconciliationScheduled: heapHolder.reconciliationScheduledSessions.size,
1961
- incrementalTimers: heapHolder.incrementalTimers.size,
1962
- pendingIncremental: heapHolder.pendingIncrementalKeys.size,
1963
- activeSessionLocks: heapHolder.sessionLocks.size,
1964
- completedIncrementalKeys: heapHolder.completedIncrementalKeys.size,
1965
- activeBufferMessages: [...heapHolder.activeReconcilerBuffers.values()].reduce((sum, messages) => sum + messages.length, 0),
1966
- activeBufferBytes: [...heapHolder.activeReconcilerBuffers.values()].reduce((sum, messages) => sum + serializedMessageBytes(messages), 0)
1967
- };
1968
- }
1969
-
1970
1743
  // src/shared/model-cache-ttl.ts
1971
1744
  var MODEL_CACHE_LIFETIMES = [
1972
1745
  {
@@ -4328,6 +4101,8 @@ class AutoSearchBusyError extends Error {
4328
4101
  }
4329
4102
  }
4330
4103
  async function searchAutoHint(db, sessionId, projectPath, query, options, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./auto-search-worker.ts" : "./auto-search-worker.js", import.meta.url)) {
4104
+ const messageIndexEpoch = getMessageIndexEpoch(sessionId);
4105
+ const messageIndexWasSearchable = isMessageIndexSearchable(sessionId);
4331
4106
  const {
4332
4107
  rerankConfig: _rerankConfig,
4333
4108
  rerankClient: _rerankClient,
@@ -4336,7 +4111,8 @@ async function searchAutoHint(db, sessionId, projectPath, query, options, entry
4336
4111
  captureRerankLanes: _captureRerankLanes,
4337
4112
  ...hintOptions
4338
4113
  } = options;
4339
- return executeAutoSearchWorker(db, sessionId, projectPath, query, { ...hintOptions, explicitSearch: false, rerank: false }, entry, "search");
4114
+ const results = await executeAutoSearchWorker(db, sessionId, projectPath, query, { ...hintOptions, explicitSearch: false, rerank: false }, entry, "search");
4115
+ return messageIndexWasSearchable && isMessageIndexSearchable(sessionId) && getMessageIndexEpoch(sessionId) === messageIndexEpoch ? results : results.filter((result) => result.source !== "message");
4340
4116
  }
4341
4117
  var pendingBackfills = new WeakMap;
4342
4118
  var searchWorkers = new WeakMap;
@@ -5812,16 +5588,47 @@ function getDreamTaskBacklog(db, projectPath, task, options = {}) {
5812
5588
  }
5813
5589
  }
5814
5590
  var backlogCaches = new WeakMap;
5591
+ var displayBacklogCaches = new WeakMap;
5592
+ var DISPLAY_BACKLOG_MAX_AGE_MS = 60000;
5815
5593
  function getDreamTaskBacklogs(db, projectPath, tasks = CANONICAL_DREAM_TASKS, options = {}) {
5816
5594
  if (tasks.length === 0)
5817
5595
  return {};
5818
5596
  if (!isKnownAutocommit(db)) {
5819
5597
  backlogCaches.delete(db);
5598
+ displayBacklogCaches.delete(db);
5820
5599
  const result = {};
5821
5600
  for (const task of tasks)
5822
5601
  result[task] = getDreamTaskBacklog(db, projectPath, task, options);
5823
5602
  return result;
5824
5603
  }
5604
+ if (options.display) {
5605
+ let entries = displayBacklogCaches.get(db);
5606
+ if (!entries) {
5607
+ entries = new Map;
5608
+ displayBacklogCaches.set(db, entries);
5609
+ }
5610
+ const optionKey = (value) => value === undefined ? "omitted" : value === null ? "null" : `number:${value}`;
5611
+ const key = JSON.stringify([
5612
+ projectPath,
5613
+ tasks,
5614
+ optionKey(options.lastRunAt),
5615
+ optionKey(options.retrospectiveWatermarkMs)
5616
+ ]);
5617
+ const now = Date.now();
5618
+ const cached = entries.get(key);
5619
+ if (cached && now < cached.expiresAt && now >= cached.expiresAt - DISPLAY_BACKLOG_MAX_AGE_MS)
5620
+ return structuredClone(cached.value);
5621
+ const value = {};
5622
+ for (const task of tasks)
5623
+ value[task] = getDreamTaskBacklog(db, projectPath, task, options);
5624
+ if (entries.size >= 256)
5625
+ entries.delete(entries.keys().next().value);
5626
+ entries.set(key, {
5627
+ expiresAt: now + DISPLAY_BACKLOG_MAX_AGE_MS,
5628
+ value: structuredClone(value)
5629
+ });
5630
+ return value;
5631
+ }
5825
5632
  let cache = backlogCaches.get(db);
5826
5633
  if (!cache) {
5827
5634
  cache = {
@@ -13433,7 +13240,7 @@ var MODULE_PAGE_MAX_BYTES = SUBC_MAX_FRAME_BODY_BYTES - MODULE_PAGE_ENVELOPE_HEA
13433
13240
  var MODULE_ITEM_CONTINUATION_CHUNK_BYTES = 64 * 1024;
13434
13241
  var MODULE_ITEM_CONTINUATION_KEY = "__shadow_item_continuation";
13435
13242
  var MODULE_ORDINAL_PAGE_SIZE = 500;
13436
- function yieldToEventLoop2() {
13243
+ function yieldToEventLoop() {
13437
13244
  return new Promise((resolve) => setTimeout(resolve, 0));
13438
13245
  }
13439
13246
  function canonicalJson(value) {
@@ -13523,7 +13330,7 @@ async function resolveOrdinalsForModule(args) {
13523
13330
  pageEnds.push({ anchor: pageAnchor, entryCount: entries.length });
13524
13331
  if (page.length < MODULE_ORDINAL_PAGE_SIZE)
13525
13332
  break;
13526
- await yieldToEventLoop2();
13333
+ await yieldToEventLoop();
13527
13334
  }
13528
13335
  return { entries, end: pageAnchor, pageEnds };
13529
13336
  };
@@ -23270,7 +23077,7 @@ function buildSidebarSnapshot(db, sessionId, directory, liveSessionState, inject
23270
23077
  const dreamerProgress = projectIdentity ? liveSessionState?.dreamerProgressByProject?.get(projectIdentity) ?? null : null;
23271
23078
  if (projectIdentity) {
23272
23079
  try {
23273
- dreamerBacklog = getDreamTaskBacklogs(db, projectIdentity, CANONICAL_DREAM_TASKS.filter((task) => smartNotesEnabled || task !== "evaluate-smart-notes"));
23080
+ dreamerBacklog = getDreamTaskBacklogs(db, projectIdentity, CANONICAL_DREAM_TASKS.filter((task) => smartNotesEnabled || task !== "evaluate-smart-notes"), { display: true });
23274
23081
  } catch {}
23275
23082
  }
23276
23083
  if (projectIdentity) {
@@ -24022,7 +23829,7 @@ function registerRpcHandlers(rpcServer, args) {
24022
23829
  const db = readDatabase();
24023
23830
  if (!db)
24024
23831
  return { ok: false, error: "db unavailable" };
24025
- const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-kdxr4tx8.js"));
23832
+ const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-3r9kcs61.js"));
24026
23833
  const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-x5nzy34v.js"));
24027
23834
  log2(`[rpc] recomp requested for session ${sessionId}`);
24028
23835
  if (!args.client && !args.hiddenCompletionExecutor) {
@@ -24107,7 +23914,7 @@ function registerRpcHandlers(rpcServer, args) {
24107
23914
  const db = readDatabase();
24108
23915
  if (!db)
24109
23916
  return { ok: false, error: "db unavailable" };
24110
- const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-prfvyqbb.js"));
23917
+ const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-ddmvbkra.js"));
24111
23918
  const model = liveSessionState.liveModelBySession.get(sessionId);
24112
23919
  const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
24113
23920
  const ctx = {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  ensureMemoryEmbeddings2
3
- } from "./server-p0snacz3.js";
4
- import"./server-zh3esb0z.js";
3
+ } from "./server-2aasmpsp.js";
4
+ import"./server-ab8017gw.js";
5
5
  import"./server-4dhv7mqz.js";
6
6
  import"./server-qt1qqasc.js";
7
7
  import"./server-vr4szghm.js";
8
8
  import"./server-24g8r2d0.js";
9
9
  import"./server-bsgd4dk1.js";
10
- import"./server-4sn3at8p.js";
10
+ import"./server-h1byrhwx.js";
11
11
  import"./server-ab1g0wn9.js";
12
12
  import"./server-qjvk4a9t.js";
13
13
  import"./server-awr8qa4c.js";
@@ -35,13 +35,13 @@ import {
35
35
  sweepAllRegisteredProjects2,
36
36
  _setTestProviderFactoryForProject2,
37
37
  _resetProjectEmbeddingRegistryForTests2
38
- } from "./server-zh3esb0z.js";
38
+ } from "./server-ab8017gw.js";
39
39
  import"./server-4dhv7mqz.js";
40
40
  import"./server-qt1qqasc.js";
41
41
  import"./server-vr4szghm.js";
42
42
  import"./server-24g8r2d0.js";
43
43
  import"./server-bsgd4dk1.js";
44
- import"./server-4sn3at8p.js";
44
+ import"./server-h1byrhwx.js";
45
45
  import"./server-ab1g0wn9.js";
46
46
  import"./server-qjvk4a9t.js";
47
47
  import"./server-awr8qa4c.js";
@@ -7,13 +7,13 @@ import {
7
7
  setRecompTerminal2,
8
8
  buildRecompDeps2,
9
9
  runManagedRecomp2
10
- } from "./server-rdjgz95f.js";
10
+ } from "./server-4n176b5m.js";
11
11
  import"./server-806rzhs6.js";
12
- import"./server-ph300d6m.js";
12
+ import"./server-tkdabx8q.js";
13
13
  import"./server-hwag0khr.js";
14
- import"./server-p0snacz3.js";
14
+ import"./server-2aasmpsp.js";
15
15
  import"./server-jjvbk92s.js";
16
- import"./server-zh3esb0z.js";
16
+ import"./server-ab8017gw.js";
17
17
  import"./server-4dhv7mqz.js";
18
18
  import"./server-53eh1r8r.js";
19
19
  import"./server-qc915kw2.js";
@@ -29,7 +29,7 @@ import"./server-x8a7jmkh.js";
29
29
  import"./server-vr4szghm.js";
30
30
  import"./server-24g8r2d0.js";
31
31
  import"./server-bsgd4dk1.js";
32
- import"./server-4sn3at8p.js";
32
+ import"./server-h1byrhwx.js";
33
33
  import"./server-ab1g0wn9.js";
34
34
  import"./server-d01pe8q5.js";
35
35
  import"./server-fb3zxn06.js";
@@ -5,13 +5,13 @@ import {
5
5
  resolveMemoriesByIdsForSearch2,
6
6
  unifiedSearch2,
7
7
  formatSearchResults2
8
- } from "./server-42nebt63.js";
8
+ } from "./server-n14edf07.js";
9
9
  import"./server-kaqs6h31.js";
10
- import"./server-ph300d6m.js";
10
+ import"./server-tkdabx8q.js";
11
11
  import"./server-hwag0khr.js";
12
- import"./server-p0snacz3.js";
12
+ import"./server-2aasmpsp.js";
13
13
  import"./server-jjvbk92s.js";
14
- import"./server-zh3esb0z.js";
14
+ import"./server-ab8017gw.js";
15
15
  import"./server-4dhv7mqz.js";
16
16
  import"./server-qt1qqasc.js";
17
17
  import"./server-rb8m4vry.js";
@@ -21,7 +21,7 @@ import"./server-a7x00tw8.js";
21
21
  import"./server-vr4szghm.js";
22
22
  import"./server-24g8r2d0.js";
23
23
  import"./server-bsgd4dk1.js";
24
- import"./server-4sn3at8p.js";
24
+ import"./server-h1byrhwx.js";
25
25
  import"./server-ab1g0wn9.js";
26
26
  import"./server-6g98c227.js";
27
27
  import"./server-fr0wbhdn.js";
@@ -15,7 +15,7 @@ import {
15
15
  OpenAICompatibleEmbeddingProvider,
16
16
  getProjectEmbeddingSnapshot2,
17
17
  embedBatchForProject2
18
- } from "./server-zh3esb0z.js";
18
+ } from "./server-ab8017gw.js";
19
19
  import {
20
20
  isEmbeddingHostBusy2
21
21
  } from "./server-qt1qqasc.js";
@@ -42,7 +42,7 @@ import {
42
42
  getProjectChunkEmbeddingModelId2,
43
43
  getProjectEmbeddingMaxInputTokens2,
44
44
  embedItemsForProject2
45
- } from "./server-zh3esb0z.js";
45
+ } from "./server-ab8017gw.js";
46
46
  import {
47
47
  hasMeaningfulUserText2,
48
48
  estimateTokens,
@@ -77,7 +77,7 @@ import {
77
77
  replaceCompartmentChunkEmbeddings2,
78
78
  deleteChunkEmbedBackoffForSession2,
79
79
  chunkWindowSourceKey2
80
- } from "./server-4sn3at8p.js";
80
+ } from "./server-h1byrhwx.js";
81
81
  import {
82
82
  isPidAlive,
83
83
  readProcessStartTime
@@ -264,7 +264,7 @@ import {
264
264
  userFacingFailureCode,
265
265
  promoteSessionFactsDurable,
266
266
  embedPromotedFacts
267
- } from "./server-ph300d6m.js";
267
+ } from "./server-tkdabx8q.js";
268
268
  import {
269
269
  isMarkerCandidateBasisCurrent2,
270
270
  invalidateMarkerCandidateBasis2,
@@ -50,7 +50,7 @@ import {
50
50
  countSessionCompartmentEmbedCoverage2,
51
51
  countSessionCompartmentEmbedCoveragePolite2,
52
52
  countUnembeddedSessionCompartmentsPolite2
53
- } from "./server-4sn3at8p.js";
53
+ } from "./server-h1byrhwx.js";
54
54
  import {
55
55
  acquireGitSweepLease,
56
56
  renewGitSweepLease,
@@ -74,6 +74,9 @@ import {
74
74
  getEmbeddingProviderIdentity,
75
75
  LocalEmbeddingProvider
76
76
  } from "./server-vr4szghm.js";
77
+ import {
78
+ isKnownAutocommit
79
+ } from "./server-8ajstryz.js";
77
80
  import {
78
81
  logSlowWriteTransaction
79
82
  } from "./server-gyy4k6mf.js";
@@ -276,6 +279,51 @@ function createChunkEmbeddingWriter(db) {
276
279
  };
277
280
  }
278
281
 
282
+ // src/features/magic-context/chunk-scope-repair-revision.ts
283
+ var revisions = new WeakMap;
284
+ var KEY = "chunk_scope_repair_revision";
285
+ function readChunkScopeRepairRevision(db) {
286
+ if (!isKnownAutocommit(db))
287
+ return null;
288
+ let state = revisions.get(db);
289
+ if (!state) {
290
+ if (!db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'schema_migrations_meta'").get())
291
+ return null;
292
+ const bump = `INSERT INTO schema_migrations_meta(key, value) VALUES ('${KEY}', lower(hex(randomblob(16))))
293
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value;`;
294
+ db.exec(`CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_binding_bi
295
+ BEFORE INSERT ON main.session_projects
296
+ WHEN NOT EXISTS (SELECT 1 FROM session_projects WHERE session_id = NEW.session_id
297
+ AND harness = NEW.harness AND project_path = NEW.project_path)
298
+ BEGIN ${bump} END;
299
+ CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_binding_au
300
+ AFTER UPDATE ON main.session_projects
301
+ WHEN OLD.session_id IS NOT NEW.session_id OR OLD.harness IS NOT NEW.harness
302
+ OR OLD.project_path IS NOT NEW.project_path
303
+ BEGIN ${bump} END;
304
+ CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_rows_bi
305
+ BEFORE INSERT ON main.compartment_chunk_embeddings BEGIN ${bump} END;
306
+ CREATE TEMP TRIGGER IF NOT EXISTS mc_chunk_scope_rows_au
307
+ AFTER UPDATE OF project_path, session_id, harness ON main.compartment_chunk_embeddings
308
+ WHEN NOT EXISTS (SELECT 1 FROM session_projects WHERE session_id = NEW.session_id
309
+ AND harness = NEW.harness AND project_path = NEW.project_path)
310
+ BEGIN ${bump} END;`);
311
+ const statement = db.prepare(`SELECT
312
+ (SELECT value FROM schema_migrations_meta WHERE key = '${KEY}') AS local,
313
+ (SELECT data_version FROM pragma_data_version) AS external,
314
+ (SELECT schema_version FROM pragma_schema_version) AS schemaVersion`);
315
+ state = { statement };
316
+ revisions.set(db, state);
317
+ }
318
+ const row = state.statement.get();
319
+ if (state.schemaVersion !== undefined && state.schemaVersion !== row.schemaVersion) {
320
+ revisions.delete(db);
321
+ return readChunkScopeRepairRevision(db);
322
+ }
323
+ state.schemaVersion = row.schemaVersion;
324
+ return JSON.stringify(row);
325
+ }
326
+
279
327
  // src/features/magic-context/git-commits/storage-git-commit-embeddings.ts
280
328
  var saveStatements = new WeakMap;
281
329
  var loadProjectStatements = new WeakMap;
@@ -1465,6 +1513,7 @@ function recordScopeActiveIdentity(db, projectIdentity, scope, modelId, now) {
1465
1513
  getUpsertActiveIdentityStatement(db).run(projectIdentity, scope, modelId, now);
1466
1514
  }
1467
1515
  var legacyDiscoveryComplete = new WeakMap;
1516
+ var chunkScopeRepairComplete = new WeakMap;
1468
1517
  function recordActiveEmbeddingIdentity(db, projectIdentity, currentProviderIdentity, currentChunkIdentity, features) {
1469
1518
  if (currentProviderIdentity === OFF_PROVIDER_IDENTITY) {
1470
1519
  return false;
@@ -1486,7 +1535,21 @@ function recordActiveEmbeddingIdentity(db, projectIdentity, currentProviderIdent
1486
1535
  model,
1487
1536
  rows: getBackfillActiveIdentityStatement(db, scope).all(projectIdentity, projectIdentity, scope)
1488
1537
  }));
1489
- const repairIds = findMisScopedCompartmentChunkEmbeddingIdsForProject(db, projectIdentity);
1538
+ const repairKey = JSON.stringify([projectIdentity, currentChunkIdentity]);
1539
+ const repairRevision = readChunkScopeRepairRevision(db);
1540
+ let completed = chunkScopeRepairComplete.get(db);
1541
+ if (!completed) {
1542
+ completed = new Map;
1543
+ chunkScopeRepairComplete.set(db, completed);
1544
+ }
1545
+ if (repairRevision === null)
1546
+ completed.clear();
1547
+ const repairIds = repairRevision !== null && completed.get(repairKey) === repairRevision ? [] : findMisScopedCompartmentChunkEmbeddingIdsForProject(db, projectIdentity);
1548
+ if (repairIds.length === 0 && repairRevision !== null) {
1549
+ if (completed.size >= 256)
1550
+ completed.delete(completed.keys().next().value);
1551
+ completed.set(repairKey, repairRevision);
1552
+ }
1490
1553
  if (legacy.every(({ rows }) => rows.length === 0) && scopes.every(([scope, model]) => active.get(projectIdentity, scope, model)) && repairIds.length === 0) {
1491
1554
  for (const { scope, model } of legacy)
1492
1555
  discovered.add(discoveryKey(scope, model));